// JavaScript Document
function validate()
{
	var fld = document.reg_form.vm_contact
	var error = "";
	var stripped = fld.value.replace(/[\(\)\.\-\ ]/g, '');     

	if(document.getElementById('vm_uname').value=="") 
	{
		alert("Please Enter User Name!");
		document.reg_form.vm_uname.focus();
		return false;
	}
	
	if(document.getElementById('vm_passwd').value=="") 
	{
		alert("Please Enter Password!");
		document.reg_form.vm_passwd.focus();
		return false;
	}
	
	if(document.getElementById('vm_passwd').value.length <=6)
	{
		alert("Password atlest 6 chars");
		document.reg_form.vm_passwd.focus();
		return false;
	}
	
	if(document.getElementById('vm_cpasswd').value=="") 
	{
		alert("Enter Confirmation Password!");
		document.reg_form.vm_cpasswd.focus();
		return false;
	}
	
	if((document.getElementById('vm_passwd').value != document.getElementById('vm_cpasswd').value))
	{
		alert("Two Passwords not same");
		return false;
	}
	

	
	
	
	if(document.getElementById('prof_pass').value=="") 
	{
		alert("Please Enter Profile Password!");
		document.reg_form.prof_pass.focus();
		return false;
	}
	
	if(document.getElementById('prof_pass').value.length <=6)
	{
		alert("Profile Password atlest 6 chars");
		document.reg_form.prof_pass.focus();
		return false;
	}
	
	if(document.getElementById('cprof_pass').value=="") 
	{
		alert("Enter Confirm Profile Password!");
		document.reg_form.cprof_pass.focus();
		return false;
	}
	
	if((document.getElementById('prof_pass').value != document.getElementById('cprof_pass').value))
	{
		alert("Two Profile Passwords not same");
		return false;
	}			
	

	
	if(document.getElementById('vm_fname').value=="") 
	{
		alert("Please Enter First Name!");
		document.reg_form.vm_fname.focus();
		return false;
	}
	if(document.getElementById('vm_lname').value=="" ) 
	{
		alert("Please Enter Last Name!");
		document.reg_form.vm_lname.focus();
		return false;
	}
	
	
	var errors = [];
	 if ( !checkRadioArray(document.reg_form.gendar) ) 
	 {
	  errors[errors.length] = "You must choose a male or female.";
	 }
	 
	 if (errors.length > 0) 
	 {
	  reportErrors(errors);
	  return false;
	 }
	
	if(document.getElementById('vm_dob').value=="")
	{
		alert("Plz enter dob");	
		document.reg_form.vm_dob.focus();				
		return false;
	}
	
	var dateStr = document.reg_form.vm_dob.value
	var datePat = /^(\d{1,2})(\/|-)(\d{1,2})\2(\d{2}|\d{4})$/;
	var matchArray = dateStr.match(datePat);
	
	if (matchArray == null) 
	{
		alert("Date is not in a valid format.")
		return false;
	}
	
	month = matchArray[1]; 
	day = matchArray[3];
	year = matchArray[4];

	if (month < 1 || month > 12) 
	{ 
		alert("Month must be between 1 and 12.");
		return false;
	}
	
	if (day < 1 || day > 31) 
	{
		alert("Day must be between 1 and 31.");
		return false;
	}
	
	if ((month==4 || month==6 || month==9 || month==11) && day==31) 
	{
		alert("Month "+month+" doesn't have 31 days!")
		return false
	}
	
	if (month == 2) 
	{ 
		var isleap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));
		if (day>29 || (day==29 && !isleap)) 
		{
			alert("February " + year + " doesn't have " + day + " days!");
			return false;
	   }
	}
	
	

	
	if(document.reg_form.vm_occup.selectedIndex==0)
	{
		alert("Please select an Item.");
		document.reg_form.vm_occup.focus();
		return false;
	}
	
	
	var emailID=document.getElementById('vm_email')
	var emailID1=document.getElementById('vm_aemail')

	if ((emailID.value==null)||(emailID.value==""))
	{
		alert("Please Enter your Email ID")
		emailID.focus()
		return false
	}

	if (echeck(emailID.value)==false)
	{
		emailID.value=""
		emailID.focus()
		return false
	}
	
	if ((emailID1.value==null)||(emailID1.value==""))
	{
		alert("Please Enter Alternative Email ID")
		emailID1.focus()
		return false
	}

	if (echeck(emailID1.value)==false)
	{
		emailID1.value=""
		emailID1.focus()
		return false
	}
	
	
	
	if(document.getElementById('vm_address').value=="") 
	{
		alert("Please Enter Your Address Here!");
		document.reg_form.vm_address.focus();
		return false;
	}
	
		if (fld.value == "") 
		{
			alert("You didn't enter a phone number.\n");
			fld.style.background = 'Yellow';
			fld.focus();
			return false;
		} 
		else if (isNaN(parseInt(stripped))) 
		{
			alert("The phone number contains illegal characters.\n");
			fld.style.background = 'Yellow';
			fld.focus();
			return false;
		} 
		else if (!(stripped.length == 10)) 
		{
			alert("The phone number is the wrong length. Make sure you included an area code.\n");
			fld.style.background = 'Yellow';
			fld.focus();
			return false;
		}
	
	
	if(document.getElementById('vm_state').value=="") 
	{
		alert("Please Enter Your State Here!");
		document.reg_form.vm_state.focus();
		return false;
	}
	
	
	
	if(document.reg_form.vm_country.selectedIndex==0)
	{
		alert("Please select country.");
		document.reg_form.vm_country.focus();
		return false;
	}
	
	
	if(document.reg_form.vm_squestion.selectedIndex==0)
	{
		alert("Please select an secret ques.");
		document.reg_form.vm_squestion.focus();
		return false;
	}

	
	if(document.getElementById('vm_sanswer').value=="") 
	{
		alert("Please Enter Your Answer Here!");
		document.reg_form.vm_sanswer.focus();
		return false;
	}
	
	if(document.getElementById('vm_usercode').value=="") 
	{
		alert("enter code!");
		document.reg_form.vm_usercode.focus();
		return false;
	}
	return true;
}

function echeck(str) 
{
	var at="@"
	var dot="."
	var lat=str.indexOf(at)
	var lstr=str.length
	var ldot=str.indexOf(dot)
	if (str.indexOf(at)==-1){
	   alert("Invalid E-mail ID")
	   return false
	}

	if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
	   alert("Invalid E-mail ID")
	   return false
	}

	if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		alert("Invalid E-mail ID")
		return false
	}

	 if (str.indexOf(at,(lat+1))!=-1){
		alert("Invalid E-mail ID")
		return false
	 }

	 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		alert("Invalid E-mail ID")
		return false
	 }

	 if (str.indexOf(dot,(lat+2))==-1){
		alert("Invalid E-mail ID")
		return false
	 }
	
	 if (str.indexOf(" ")!=-1){
		alert("Invalid E-mail ID")
		return false
	 }
	 
	return true;
}

function checkRadioArray(radioButtons){
for (var i=0; i < radioButtons.length; i++) {
if (radioButtons[i].checked) {
return true;
}
}
return false;
}

function reportErrors(errors){
var msg = "There were some problems...\n";
var numError;
for (var i = 0; i<errors.length; i++) {
numError = i + 1;
msg += "\n" + numError + ". " + errors[i];
}
alert(msg);
}