
function checkEmailPasswd(){
	if (document.getElementById('Login_Email').value == "")
	{ 
		alert("Please provide a valid Email Address.");
		document.getElementById('Login_Email').focus();
		return false;
	}
	if (document.getElementById('Login_Email').value != "")
	{ 
		if(!validateEmail(document.getElementById('Login_Email').value))
			{	
				alert("Please provide a valid Email Address.");
				document.getElementById('Login_Email').focus();
				return false;
			}
	}
	if (document.getElementById('Login_Password').value == "")
	{
		alert("Please provide a Password.");
		document.getElementById('Login_Password').focus();
		return false;
	}
	return true;

}

function checkUserEmail(){
	if (document.getElementById('newUser_Email').value == "")
	{ 
		alert("Please provide a valid Email Address.");
		document.getElementById('newUser_Email').focus();
		return false;
	}
	if (document.getElementById('newUser_Email').value != "")
	{ 
		if(!validateEmail(document.getElementById('newUser_Email').value))
		{	
		alert("Please provide a valid Email Address.");
		document.getElementById('newUser_Email').focus();
		return false;
		}
	}
	return true;
}


function checkEmail(){
	if (document.getElementById('Login_Email').value == "")
	{ 
		alert("Please provide a valid Email Address.");
		document.getElementById('Login_Email').focus();
		return false;
	}
	if (document.getElementById('Login_Email').value != "")
	{ 
		if(!validateEmail(document.getElementById('Login_Email').value))
		{	
		alert("Please provide a valid Email Address.");
		document.getElementById('Login_Email').focus();
		return false;
		}
	}
	return true;
}

function checkProjectName(){
	if (document.getElementById('proj_Name').value == "")
	{ 
		alert("Please provide a name for you project.");
		document.getElementById('proj_Name').focus();
		return false;
	}
	return true;
}

function checkPayment()
	{
	theCardName = document.getElementById('cc_NameonCard').value;
	theCard = document.getElementById('cc_CardType')[document.getElementById('cc_CardType').selectedIndex].value;
	theNum = document.getElementById('cc_CardNumber').value;
	theMnth = document.getElementById('cc_ExpMonth')[document.getElementById('cc_ExpMonth').selectedIndex].value;
	theYr = document.getElementById('cc_ExpYear')[document.getElementById('cc_ExpYear').selectedIndex].value;
	theCVV = document.getElementById('cc_CVV').value;
	
	if(theCardName == "")
		{
		alert("Please provide the name as it appears on your credit card.");
		document.getElementById('cc_NameonCard').focus();
		return false;
		}
		
	if(theNum == "")
		{
		alert("Please provide your credit card number.");
		document.getElementById('cc_CardNumber').focus();
		return false;
		}
	
	// check card number against algorithm
	if(!mod10(theNum))
		{
		alert("Sorry! this is not a valid credit card number.");
		document.getElementById('cc_CardNumber').focus();
		return false;
		}
	
	if(validateCard(theNum,theCard,theMnth,theYr))
		{return true;}
	else
		{return false;}
		
	if(theCVV != "")
		{
		if(!validateInteger(theCVV) || theCVV.length < 3)
			{
			alert("Please provide a valid Security Code (CVV) for your credit card.\n\nIf you can not read the code on your card, please leave the field blank.");
			document.getElementById('cc_CVV').focus();
			return false;
			}
		}
		
	//check the dates	
	if( expired(theMnth, theYr) ) 
		{// check if entered date is already expired.
		alert("Sorry! The expiration date you have entered would make this card invalid.");
		document.getElementById('cc_ExpMonth').focus();
		return false;
		}
	
	} 
//-->

function checkAccount(){
if (document.getElementById('customer_FName').value == "")
	{
	alert("Please provide your First Name.");
	document.getElementById('customer_FName').focus();
	return false;
	}
if (document.getElementById('customer_LName').value == "")
	{
	alert("Please provide your Last Name.");
	document.getElementById('customer_LName').focus();
	return false;
	}
if (document.getElementById('customer_Email').value == "")
{ 
	alert("Please provide a valid Email Address.");
	document.getElementById('customer_Email').focus();
	return false;
}
if (document.getElementById('customer_Email').value != "")
{ 
	if(!validateEmail(document.getElementById('customer_Email').value))
		{	
			alert("Please provide a valid Email Address.");
			document.getElementById('customer_Email').focus();
			return false;
		}
}
if (document.getElementById('customer_Address1').value == "")
	{
	alert("Please provide your Address.");
	document.getElementById('customer_Address1').focus();
	return false;
	}	
if (document.getElementById('customer_City').value == "")
	{
	alert("Please provide your City.");
	document.getElementById('customer_City').focus();
	return false;
	}	
if (document.getElementById('customer_State')[document.getElementById('customer_State').selectedIndex].value == "")
	{
	alert("Please provide your State.");
	document.getElementById('customer_State').focus();
	return false;
	}
if (document.getElementById('customer_Zip').value == "")
	{
	alert("Please provide your Zip Code.");
	document.getElementById('customer_Zip').focus();
	return false;
	}
if (document.getElementById('customer_Country')[document.getElementById('customer_Country').selectedIndex].value == "")
	{
	alert("Please provide your Country.");
	document.getElementById('customer_Country').focus();
	return false;
	}
if (document.getElementById('customer_Type')[document.getElementById('customer_Type').selectedIndex].value == "")
	{
	alert("Please provide your Customer Type.");
	document.getElementById('customer_Type').focus();
	return false;
	}
if (document.getElementById('customer_Password').value == "")
	{
	alert("Please provide a Password.");
	document.getElementById('customer_Password').focus();
	return false;
	}
if (document.getElementById('customer_ConPWord').value == "")
	{
	alert("Please confirm your Password.");
	document.getElementById('customer_ConPWord').focus();
	return false;
	}
if (document.getElementById('customer_Password').value != document.getElementById('customer_ConPWord').value) 
	{
	alert('Your passwords do not match. Re-enter your password.');
	document.getElementById('customer_Password').focus();
	return false;
	}
if (document.getElementById('customer_Email').value != "")
	{ 
	if(!validateEmail(document.getElementById('customer_Email').value))
		{	
		alert("Please provide a valid Email Address.");
		document.getElementById('customer_Email').focus();
		return false;
		}
	}		
	return true;
}


function validateEmail(strValue) 
{
	var objRegExp = /^([0-9a-zA-Z]([-.\w]*[0-9a-zA-Z])*@(([0-9a-zA-Z])+([-\w]*[0-9a-zA-Z])*\.)+[a-zA-Z]{2,9})$/i;
	//check for valid email
	return objRegExp.test(strValue);
}	

function mod10( cardNumber ) 
	{ // LUHN Formula for validation of credit card numbers.
	var ar = new Array( cardNumber.length );
	var i = 0,sum = 0;

	for(i = 0; i < cardNumber.length; ++i ) 
		{ar[i] = parseInt(cardNumber.charAt(i));}
	for(i = ar.length -2; i >= 0; i-=2) { // you have to start from the right, and work back.
		ar[i] *= 2;							 // every second digit starting with the right most (check digit)
		if( ar[i] > 9 ) ar[i]-=9;			 // will be doubled, and summed with the skipped digits.
 	}										 // if the double digit is > 9, ADD those individual digits together 

	for( i = 0; i < ar.length; ++i ) {
			sum += ar[i];						 // if the sum is divisible by 10 mod10 succeeds
		}
		return (((sum%10)==0)?true:false);	 	
	}


function expired( month, year ) 
	{
	var now = new Date();							// this function is designed to be Y2K compliant.
	var expiresIn = new Date(year,month,0,0,0);		// create an expired on date object with valid thru expiration date
	expiresIn.setMonth(expiresIn.getMonth()+1);		// adjust the month, to first day, hour, minute & second of expired month
	if( now.getTime() < expiresIn.getTime() ) return false;
	return true;									// then we get the miliseconds, and do a long integer comparison
	}


function validateCard(cardNumber,cardType,cardMonth,cardYear) 
	{
	
	switch( cardType ) {		
		case 'MC':
			if( cardNumber.length != 16 ) 
				{
				alert("Please enter a valid MasterCard number.");
				document.getElementById('trans_CardNumber').focus();
				return false;
				}
			var prefix = parseInt( cardNumber.substring(0,2));
	
			if( prefix < 51 || prefix > 55) 
				{
				alert("Please enter a valid MasterCard Card number.");
				document.getElementById('trans_CardNumber').focus();
				return false;
				}
			break;
		case 'Visa':
			if( cardNumber.length != 16 && cardNumber.length != 13 ) 
				{
				alert("Please enter a valid Visa Card number.");
				document.getElementById('trans_CardNumber').focus();
				return false;
				}
			var prefix = parseInt( cardNumber.substring(0,1));

			if( prefix != 4 ) 
				{
				alert("Please enter a valid Visa Card number.");
				document.getElementById('trans_CardNumber').focus();
				return false;
				}
			break;
		}
										
	return true; // at this point card has not been proven to be invalid
	}