//version 02/10/06 01:41am
//Phone number now is Numeric input only (no spaces and braces)
function isValidYear(year){
	var yrxp = /^([1-2][0-9][0-9][0-9])$/;
	var currentTime = new Date();
//	var minYr = currentTime.getFullYear()-5;
//	var maxYr = currentTime.getFullYear()+5;

	if(!yrxp.test(year)){
		alert('Wedding Year must be numeric with 4 digits.');
		return false;
	}
	
/*	if(year < minYr || year > maxYr){
		alert("Wedding Year should be within "+minYr+" & "+maxYr+" to be reasonable.");
		return false;
	}
*/
	return true;
}

function isValidDayInMonth(day, month, year){
	var daysInMonth = new Array(0,31,29,31,30,31,30,31,31,30,31,30,31);
	
	if(day > daysInMonth[month]){
		alert('Wedding Day is exceeding the max. # of days in this month');
		return false;
	}
	
	if(month == 2 && day == 29){
		if(!(year%4 == 0)){
			alert('Wedding Day is exceeding 28 of days in the Feb. of '+year+'.');
			return false;
		}
	}
	
	return true;
}

function isValidEmail(email){
	var emailxp = /^(\w+([\.-]?\w+)*@[a-zA-Z]+([-]?[a-zA-Z]+)*\.[a-zA-Z]{2,4}(\.[a-zA-Z]{2})*)$/;
	if(!emailxp.test(email)){
		return false;
	}
	return true;
}


function checkForm(){
	var urlxp = /^(([0-9a-zA-Z]+(\-?[0-9a-zA-z]*)){2,63})$/;
	var numericxp = /^([0-9]+)$/;
	var monthxp = /^([0-1]?[0-9])$/;
	var dayxp = /^([0-3]?[0-9])$/;
	var namexp = /^([a-zA-Z]+(\s[a-zA-Z]+){1,5})$/;
	var alphanumericxp = /^([0-9a-zA-Z]+)$/;

	var domain = document.forms['infoForm'].domain.value;
	var wdDay = document.forms['infoForm'].day.value;
	var wdMonth = document.forms['infoForm'].month.value;
	var wdYear = document.forms['infoForm'].year.value;

	//step 1 site url check
	if (!urlxp.test(domain)) {
		alert('Domain Name must be in 2 to 63 characters and only letters, numbers, and hyphens (-) are allowed.');
		document.forms['infoForm'].domain.focus();
		document.forms['infoForm'].domain.select();
		return false;
	}
		
	//step 3 user info check
	if (!namexp.test(document.forms['infoForm'].bride_name.value)){
		alert('Please enter Bride Name in Alphabet ONLY.');
		document.forms['infoForm'].bride_name.focus();
		document.forms['infoForm'].bride_name.select();
		return false;
	}

	if (!namexp.test(document.forms['infoForm'].groom_name.value)){
		alert('Please enter Groom Name in Alphabet ONLY.');
		document.forms['infoForm'].groom_name.focus();
		document.forms['infoForm'].groom_name.select();
		return false;
	}

	if (!monthxp.test(wdMonth) || (wdMonth < 1 || wdMonth > 12)){
		alert('Please enter a 1-2 digit Month.');
		document.forms['infoForm'].month.focus();
		document.forms['infoForm'].month.select();
		return false;
	}

	if (!dayxp.test(wdDay) || (wdDay < 1 || wdDay > 31)){
		alert('Please enter a 1-2 digit Day.');
		document.forms['infoForm'].day.focus();
		document.forms['infoForm'].day.select();
		return false;
	}
		
	if (!isValidYear(wdYear)) {
		document.forms['infoForm'].year.focus();
		document.forms['infoForm'].year.select();
		return false;
	}

	if(!isValidDayInMonth(wdDay, wdMonth, wdYear)) {
		document.forms['infoForm'].month.focus();
		document.forms['infoForm'].month.select();
		return false;
	}

	if(!isValidEmail(document.forms['infoForm'].email.value)){
		alert('Email address is invalid.');
		document.forms['infoForm'].email.focus();
		document.forms['infoForm'].email.select();
		return false;
	}
	
	if(!numericxp.test(document.forms['infoForm'].contact.value)){
		alert('Phone # must be numerical only (without spaces).');
		document.forms['infoForm'].contact.focus();
		document.forms['infoForm'].contact.select();		
		return false;
	} else if(document.forms['infoForm'].contact.value.length > 20){
		alert('Phone # must be max. 20 digits (without spaces).');
		document.forms['infoForm'].contact.focus();
		document.forms['infoForm'].contact.select();		
		return false;
	}
	
	if(!alphanumericxp.test(document.forms['infoForm'].username.value)){
		alert('Username must be alpha-numeric only.');
		document.forms['infoForm'].username.focus();
		document.forms['infoForm'].username.select();		
		return false;
	}

	if(!alphanumericxp.test(document.forms['infoForm'].passwd.value)){
		alert('Password must be alpha-numeric only.');
		document.forms['infoForm'].passwd.focus();
		document.forms['infoForm'].passwd.select();		
		return false;
	}

	if(document.forms['infoForm'].passwd.value != document.forms['infoForm'].conf_passwd.value){
		alert('Both Passwords do not match, please re-enter again.');
		document.forms['infoForm'].passwd.focus();
		document.forms['infoForm'].passwd.select();		
		return false;
	}

	return true;
}