// JavaScript Document
function validate(){
	var y=document.newForm.year.value
	var y2=document.newForm.year.length
	var anum=/(^\d+$)|(^\d+\.\d+$)/
	var mon=document.newForm.month.value
	var day=document.newForm.day.value

	if (((document.newForm.state.value == 0)&&(document.newForm.country.value == "US")) 
	|| (document.newForm.firstname.value == "")
	||(document.newForm.lastname.value == "") || (document.newForm.email.value == "") 
	|| (document.newForm.username.value == "") || (document.newForm.password1.value == "") 
	|| (document.newForm.password2.value == "")) {
		msg = "Enter values for required fields!"
		alert(msg);  
		return false;
		
	}
		//check valid date
	if( (!anum.test(y)) || (y <=1915) || (mon==2)&&(day==30) || (mon==2)&&(day==31) || (mon==9)&&(day==31) || (mon==4)&&(day==31) || (mon==6)&&(day==31) || (mon==11)&&(day==31) ){
		alert("Invalid birth date!");
		testresult=false;
		return (testresult);
	}

	if ((document.newForm.password1.value != "") && (document.newForm.password2.value != "")){
		if ((document.newForm.password1.value ) != (document.newForm.password2.value)){
		msg = "Passwords do not match!"
		alert(msg);
	   return false;
		}
		else {
			if ((document.newForm.password1.length <6) && (document.newForm.password2.value<6)){
					msg = "Password must be at least 6 characters!";
					alert(msg);
					return false;
				}
		}
	}
	
	if ((document.newForm.emai1.value != "") && (document.newForm.email2.value != "")){
		if ((document.newForm.emai1.value ) != (document.newForm.email2.value)){
		msg = "Email Addresses do not match!"
		alert(msg);
	   return false;
		}
	}
		
}

function setSubmit(){
	if (document.newForm.agree.checked)
	{ document.newForm.Submit.disabled = false; }
	else document.newForm.Submit.disabled = true;
}

function checkCountry(){
	var country = document.newForm.country.value
	if (country != "US")
	{ document.newForm.state.value="0"; }
}
function checkState(){
	var state = document.newForm.state.value
	if (state != "0")
	{ document.newForm.country.value = "US"; }
}

function checkEMAIL(){
	var email2 = document.newForm.email2.value
	var email = document.newForm.email.value
	if (email == email2)
	{ return true; }
	else alert('Email Address must be the same!');
}

function popUp(URL) {
day = new Date();
id = day.getTime();
eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=1,menubar=0,resizable=0,width=500,height=420,left =0,top =0');");
}
