// JavaScript Document
function validate()
{
var msg="";
var whatever = document.getElementById("customer_login_id").value.replace(/^\s\s*/, '').replace(/\s\s*$/, '').replace(/ {2,}/g," ")
	if(document.user_form.customer_login_id.value=='')
	{
		msg="Must Enter Email/ Login_id\n";
		document.user_form.customer_login_id.focus();
	}
	if (!/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,4})+$/.test(whatever))
	 {
	msg=msg+"Must Enter a valid E-mail Address\n";
	document.getElementById("customer_login_id").focus();
	}
	if(document.user_form.customer_choose_pass.value=='')
	{
		msg=msg+"Must Enter Password\n";
		document.user_form.customer_choose_pass.focus();
	}
	if(document.user_form.customer_choose_pass.value.length > 15)
	{
		msg=msg+"Password should be max 15 characters\n";
		document.user_form.customer_choose_pass.focus();
	}
	if(document.user_form.customer_full_name.value=='')
	{
		msg=msg+"Must Enter Full Name\n";
		document.user_form.customer_full_name.focus();
	}
	if(document.user_form.customer_gender[0].checked==false && document.user_form.customer_gender[1].checked==false)
	{
		msg=msg+"Must Select Gender\n";
	}
	if(document.user_form.customer_dob.value=='')
	{
		msg=msg+"Must Enter Date of Birth\n";
		document.user_form.customer_dob.focus();
	}
	var validformat=/^\d{2}\/\d{2}\/\d{4}$/ //Basic check for format validity 
var returnval=false 
var mydate=document.user_form.customer_dob.value;
if (!validformat.test(mydate)) 
msg=msg+ "Invalid Date Format. Enter as 05/12/2008\n";
else
{ //Detailed check for valid date ranges 
var yearfield=mydate.split("/")[2] 
var monthfield=mydate.split("/")[1] 
var dayfield=mydate.split("/")[0] 
var dayobj = new Date(yearfield,monthfield-1,dayfield) 
if ((dayobj.getMonth()+1!=monthfield)||(dayobj.getDate()!=dayfield)||(dayobj.getFullYear()!=yearfield)) 
msg=msg+ "Invalid Day, Month, or Year range detected\n";
} 
	if(document.user_form.customer_contact_code.value=='')
	{
		msg=msg+"Must Select Contact Code \n";
		document.user_form.customer_contact_code.focus();
	}
	if(document.user_form.customer_contact_number.value=='')
	{
		msg=msg+"Must Enter Contact Number \n";
		document.user_form.customer_contact_number.focus();
	}
	if(document.user_form.customer_contact_number.value.length > 9)
	{
		msg=msg+"Contact Number should be not exceed 9 digits \n";
		document.user_form.customer_contact_number.focus();
	}
	if(isNaN(document.user_form.customer_contact_number.value))
	{
		msg=msg+"Must Enter Valid Contact Number \n";
		document.user_form.customer_contact_number.focus();
	}
	if(document.user_form.customer_address1.value=='')
	{
		msg=msg+"Must Enter Address \n";
		document.user_form.customer_address1.focus();
	}
	if(document.user_form.customer_suburb.value=='')
	{
		msg=msg+"Must Enter Suburb \n";
		document.user_form.customer_suburb.focus();
	}
	if(document.user_form.customer_city.value=='')
	{
		msg=msg+"Must Enter City \n";
		document.user_form.customer_city.focus();
	}
	if(document.user_form.customer_post_code.value=='')
	{
		msg=msg+"Must Enter Post Code \n";
		document.user_form.customer_post_code.focus();
	}
	if(document.user_form.customer_post_code.value.length > 4)
	{
		msg=msg+"Post Code must be 4 digits \n";
		document.user_form.customer_post_code.focus();
	}
	if(isNaN(document.user_form.customer_post_code.value))
	{
		msg=msg+"Must Enter Valid Post Code \n";
		document.user_form.customer_post_code.focus();
	}
	if(document.user_form.customer_town.value=='')
	{
		msg=msg+"Must Select Town \n";
		document.user_form.customer_town.focus();
	}
	if(document.user_form.agree.checked == false)
	{
		msg=msg+"agree to terms and conditions \n";
	}
        if(msg != '')
		{
         alert(msg);
         return false;
        } 
		return true;
}
/*function checkdate(input){ 
var validformat=/^\d{4}\/\d{2}\/\d{2}$/ //Basic check for format validity 
var returnval=false 
if (!validformat.test(input.value)) 
alert("Invalid Date Format. The Correct format is 2005/12/05") 
else{ //Detailed check for valid date ranges 
var yearfield=input.value.split("/")[0] 
var monthfield=input.value.split("/")[1] 
var dayfield=input.value.split("/")[2] 
var dayobj = new Date(yearfield, monthfield-1, dayfield) 
if ((dayobj.getMonth()+1!=monthfield)||(dayobj.getDate()!=dayfield)||(dayobj.getFullYear()!=yearfield)) 
alert("Invalid Day, Month, or Year range detected. Please correct and submit again.") 
else { 
returnval=true } 
} 
if (returnval==false) input.select() 
return returnval; 
} */

