
/* Validates a submitted e-mail address */
function validEmailAddress(emailAddress, emailAddressStatusLabel) 
{			
	re = /^[_a-zA-Z0-9][_a-zA-Z0-9'\.\-\+\&\/]*@[a-zA-Z_0-9][a-zA-Z0-9\-]*([\.]+[a-zA-Z0-9\-]+)*[.]([a-zA-Z]{2,4})$/;
	
	var check = re.exec(emailAddress);
	var dot_dot = emailAddress.indexOf("..") ;      // checking for '..' within an email
	var dot_at  = emailAddress.indexOf(".@") ;      // checking for '.@' within an email
	
	if ( (check) && (dot_dot == -1) && (dot_at == -1) )
	{   
		emailAddressStatusLabel.style.display = 'none';
		return true;
	}
	else
	{   
		emailAddressStatusLabel.style.display = 'block';
	}
		
	return false;
}

/* Validates a submitted postal code */
function validPostalCode(postalCode, tzLocaleCode, postalCodeStatusLabel, newsflashMessageLabel)
{
	var re;
	
	// Let no entry go through
	if (postalCode == '')
	{
		newsflashMessageLabel.style.display = 'block';
		postalCodeStatusLabel.style.display = 'none';
		return true;
	}
		
	switch(tzLocaleCode) 
	{
		case 'US':
			re = /^[0-9]{5}([ |-][0-9]{4})?$/;
			break;
		case 'UK':
			re = /^[a-zA-Z][a-zA-Z0-9]{1,3}[ ]{0,1}[0-9][a-zA-Z][a-zA-Z]$|^BFPO$/;
			break;	
		case 'DE':
			re = /^[0-9]{5}$/;
			break;
		case 'FR':
			re = /^[0-9]{5}([ |-][0-9]{4})?$/;
			break;
		case 'CA':
			re = /^[a-zA-Z][0-9][a-zA-Z][ |-]?[0-9][a-zA-Z][0-9]$/;
			break;
		case 'JP':
			re = /^[0-9]{3}-[0-9]{4}$/;
			break;
		case 'CN':
			re = /^.*$/;
			break;
		default:
			re = /^[- a-zA-Z0-9]+$/;
	}
	
	var check = re.exec(postalCode);
	
	if (check)
	{
		postalCodeStatusLabel.style.display = 'none';
		return true;
	}
	else
	{
		postalCodeStatusLabel.style.display = 'block';
		newsflashMessageLabel.style.display = 'none';
	}
	
	return false;
}

/* Checks if a string is of numeric nature */
function isNumeric(str)
{
	var strValidChars = "0123456789.-";
	var strChar;
	var result = true;

	if (str.length == 0) return false;

	// test strString consists of valid characters listed above
	for (i = 0; i < str.length && result == true; i++)
	{
		strChar = str.charAt(i);
		
		if (strValidChars.indexOf(strChar) == -1)
		{
			result = false;
        }
   }
   
   return result;
}
