var genericemail = "you@aol.com";

function getRandomNumber()
{
	var ran = Math.round(Math.random()*50);
	var now=new Date();
	var num=Math.round(Date.UTC(now.getYear(), now.getMonth(), now.getDate(), now.getHours(), now.getMinutes(), now.getSeconds(), now.getMilliseconds())*ran);
	return num;
}


function LTrim(str)
/*
   PURPOSE: Remove leading blanks from our string.
   IN: str - the string we want to LTrim
*/
{
   var whitespace = new String(" \t\n\r");

   var s = new String(str);

   if (whitespace.indexOf(s.charAt(0)) != -1) {
      // We have a string with leading blank(s)...

      var j=0, i = s.length;

      // Iterate from the far left of string until we
      // don't have any more whitespace...
     while (j < i && whitespace.indexOf(s.charAt(j)) != -1)
         j++;

      // Get the substring from the first non-whitespace
      // character to the end of the string...
      s = s.substring(j, i);
   }
   return s;
}


function CheckEmail(sEmailAddress)
{
	var sErrmsg = "Please enter a valid e-mail address. It should include your domain name and contain no spaces." 
	var checkup = true;
	if(LTrim(sEmailAddress.value) == '')
	{
		alert(sErrmsg);
		checkup =  false;
	}
	else if(sEmailAddress.value == genericemail)
	{
		alert("Please enter YOUR email address!");
		checkup =  false;
	}
	else 
	{
		var iDotIndex = sEmailAddress.value.lastIndexOf(".")
		var iAtIndex = sEmailAddress.value.lastIndexOf("@") 
		var iSpaceIndex = sEmailAddress.value.indexOf(" ") 
		if (!((iAtIndex > 0) && (iDotIndex > iAtIndex)) || (iSpaceIndex > -1))
		{
			alert(sErrmsg);
			checkup =  false;
		}
	}
	return checkup;
}

function CheckEmailandZip(sEmailAddress, sZip)
{
	var sErrmxg = "";
	if(LTrim(sEmailAddress.value) == '')
	{
		sErrmxg += "Please enter a valid e-mail address. It should include your domain name and contain no spaces.\n";
	}
	else if (sEmailAddress.value == genericemail)
	{
		sErrmxg += "Please enter YOUR email address.\n";
	}
	else
	{
		var iDotIndex = sEmailAddress.value.lastIndexOf(".")
		var iAtIndex = sEmailAddress.value.lastIndexOf("@") 
		var iSpaceIndex = sEmailAddress.value.indexOf(" ") 
		if (!((iAtIndex > 0) && (iDotIndex > iAtIndex)) || (iSpaceIndex > -1))
		{
			sErrmxg += "Please enter a valid e-mail address. It should include your domain name and contain no spaces.\n";
		}
	}
	
	
	//validate zip
	sZip = Trim(sZip.value);
	if(sZip == '')
	{
		sErrmxg += "Please enter a zip/postal code.\n";
	}
	
	else
	{
		
		if (notValidZip(sZip)) 
		{
			sErrmxg += "Please enter a valid zip/postal code.\n";
		}

	}
	
	
	if (sErrmxg != '')
	{ 
		alert ("Please correct the following:\n\n" + sErrmxg);
		return false;
	}
	else
	{
		return true;
	} 
	
}




/*generic postal code check for canada and US
returns true if not valid
requires postal code as string
added owen t 4-19-05
modified 4/28/05*/
function notValidZip(postalcode)
{
	postalcode = postalcode.toUpperCase()
	//regular 	expression for US zip and Canada zip
	var expression = "^[0-9]{5}-[0-9]{4}$|^[0-9]{5}$|^[A-Z][0-9][A-Z]\\s[0-9][A-Z][0-9]$|^[A-Z][0-9][A-Z][0-9][A-Z][0-9]$" 	
	var varPostalExpression = new RegExp(expression); //instatiate new reg expression object
	var matched = varPostalExpression.test(postalcode) //test the postal code against expression
	
	if(!matched)
	{
		// now test to see if it is a city/state combo
		expression = "^[a-zA-Z\\.\\'\\-\\s]+[\\,\\s]+[a-zA-Z]{2}$"
		varPostalExpression = new RegExp(expression)
		matched = varPostalExpression.test(postalcode)
		if(!matched){
			return true; //not valid postal code
		} 
		else 
		{
			return false;
		}
	}
	else
	{
	return false; //valid postal code
	}
}
 