﻿
function ValidateMoreEmail(strEmails)
{
	strEmails		= FilterEmailChar(strEmails);
	strEmails		= strEmails.replace(/;/g, ",");
	var arrEmails	= strEmails.split(",");
	for(var i=0; i<arrEmails.length; i++)
	{
		if(!ValidateEmail(arrEmails[i]))
			return false;			
	}
	return true;		
}

function ValidateEmail(strEmail)
{
	strEmail = strEmail.Trim();
	if(strEmail.match(/^[\w-]+(\.[\w-]+)*@[\w-]+(\.[\w-]+)+$/)==null)
		return false;
	return true;		
}

function FilterEmailChar(strEmail)
{
	strEmail = strEmail.Trim();
	if(strEmail.charAt(strEmail.length-1)==';' || strEmail.charAt(strEmail.length-1)==',')
	{
		strEmail =  strEmail.substr(0, strEmail.length-1);
		strEmail =	strEmail.Trim();
	}
	return strEmail;
}

function ValidatePrice(strValue)
{
	var re=new RegExp("^(([1-9][0-9]*)|0)(\.[0-9]{1,2})?$");
	if(strValue.match(re)==null)
		return false;
	else
		return true;
}

var verifyImage;
var targetImage;
var verifyTimer;
var verifyTimer_value = 500;

function RefreshVerifyCode(imageId)
{
	var temp = Math.round(Math.random() * 100000);
	verifyImage	=	document.getElementById(imageId);
	if(!verifyImage)
		return;
	var url		=	verifyImage.src;
	var pos		=	url.indexOf("?");
	if(pos>0)
		url			=	url.substr(0, pos);
	url = url + "?refresh=" + temp;
	targetImage		= new Image;
	targetImage.src = url;
	verifyTimer = setTimeout("WaitForImageLoad();", verifyTimer_value);
}

function WaitForImageLoad()
{
	clearTimeout(verifyTimer);
	if(!targetImage.complete)
	{		
		verifyTimer = setTimeout("WaitForImageLoad();", verifyTimer_value);
	}
	else
	{
		verifyImage.src = targetImage.src;
	}
}

function GetKeyCode(evt)
{
	evt = evt ? evt : (window.event?window.event:null);
	return evt.keyCode ? evt.keyCode : evt.which ? evt.which : evt.charCode;
}