// JavaScript Document

// JavaScript Document
// JavaScript Document


function  ValidateForm()
{
		//alert("");
		var company_name=document.reg_form.company_name	
		var company_mobile=document.reg_form.company_mobile	
		var company_landline=document.reg_form.company_landline	
		var company_address=document.reg_form.company_address	
		var c_manager_account=document.reg_form.c_manager_account	
		var first_name=document.reg_form.first_name	
		var last_name=document.reg_form.last_name	
		var email_id=document.reg_form.email_id
		var password=document.reg_form.password
		var cpassword=document.reg_form.cpassword
		var address_one=document.reg_form.address_one
		var country=document.reg_form.country
		var state=document.reg_form.state
		var city=document.reg_form.city
		var msn_contact=document.reg_form.msn_contact
		var aol_contact=document.reg_form.aol_contact
		var icq_contact=document.reg_form.icq_contact
		var security_code=document.reg_form.security_code
		
		
		//date validation 
		
		var bday=document.reg_form.date.value;
			var bmonth=document.reg_form.month.value;
			var byear=document.reg_form.year.value;
			var mon=0;
			
		
		
		
		
		
		
	if(company_name.value.length>=60)
		{
			alert("Please Enter  Company Name Less Than 60 Characters");
			company_name.value=""
			company_name.focus()
			return false
		}
		
		if((company_mobile.value.length>=15))
		{
			alert("Please Enter Valid Mobile Number")
			company_mobile.value=""
			company_mobile.focus()
			return false;
		}
		
		
		if(company_address.value.length>=500)
		{
			alert(" Company Address Should Be Less Than 500 Characters");
			company_address.value=""
			company_address.focus()
			return false
		}
		if((c_manager_account.value.length>=50))
		{
			alert("Please Valid Manager Account")
			c_manager_account.value=""
			c_manager_account.focus()
			return false
		}
		
		if(isWhitespace(first_name.value))
		{
			alert("Please Enter First Name")
			first_name.value=""
			first_name.focus()
			return false
		}
		if(isWhitespace(last_name.value))
		{
			alert("Please Enter Last Name")
			last_name.value=""
			last_name.focus()
			return false
		}
			
		
		if(ValidateEmailId(email_id)==false)
		{
			alert("Invalid E-mail ID")
			email_id.value=""
			email_id.focus()
			return false;	
		}
		if(isWhitespace(password.value))
		{
			alert("Please Enter Password")
			password.value=""
			password.focus()
			return false
		}
		if((password.value.length>=50)||(password.value.length<6))
		{
			alert("Password Should Be In Between 6 And 50 Characters")
			password.value=""
			password.focus()
			return false
		}
		if(isWhitespace(cpassword.value))
		{
			alert("Please Enter Confirm Password")
			cpassword.value=""
			cpassword.focus()
			return false
		}
		
		if(cpassword.value!=password.value)
		{
			alert("Password and Confirm Password should be same")
			cpassword.value=""
			cpassword.focus()
			return false
		}
		
			
		if(bday=="")
		{
		  	alert("Please Enter Day");
			document.reg_form.date.focus();
			
			return false;	
			
		}
		if(bmonth=="")
		{
			alert("Please Enter Month");
		  	document.reg_form.month.focus();
			return false;
		}
		if(byear=="")
		{
			alert("Please Enter Year");
		  	document.reg_form.year.focus();
			return false;
		}
		
		
		if(isWhitespace(security_code.value))
		{
			alert("Please Enter Security Code")
			security_code.value=""
			security_code.focus()
			return false
		}
		
		//date  
		
		
	
			if(bmonth=='January')
			mon=1;
			if(bmonth=='February')
			mon=2;
			if(bmonth=='March')
			mon=3;
			if(bmonth=='April')
			mon=4;
			if(bmonth=='May')
			mon=5;
			if(bmonth=='June')
			mon=6;
			if(bmonth=='July')
			mon=7;
			if(bmonth=='August')
			mon=8;
			if(bmonth=='September')
			mon=9;
			if(bmonth=='October')
			mon=10;
			if(bmonth=='November')
			mon=11;
			if(bmonth=='December')
			mon=12;
		
		
			function check2k(a) {
			return (a<1900)?a -= -1900:a;
			}
			
			function addYr(a) {
			return new Date(check2k(1*a.getYear()+1),a.getMonth(),a.getDate());
			}
			
			function addMth(a) {
			return new Date(check2k(a.getYear()),1*a.getMonth()+1,a.getDate());
			}
			
			function addDay(a) {
			return new Date(check2k(a.getYear()),a.getMonth(),1*a.getDate()+1);
			}
			
			var y=new Array();
			var x= new Array();
			var currdate= new Date();
			
			y[0]=currdate.getFullYear();
			y[1]=currdate.getMonth()+1;
			y[2]=currdate.getDate();
			
			
			x[0]=byear;
			x[1]=mon;
			x[2]=bday;
			//	alert('Years: ' + x[0]+ '\nMonths: ' + x[1]+ '\nDays: ' + [2]);
			yrCount = 0,
			mthCount = 0,
			dayCount = 0;
			
			// Convert to dates
			var date0 = new Date(x[0],x[1]-1,x[2]);
			var date1 = new Date(y[0],y[1]-1,y[2]);
			
			// Make the lower one date0
			if (date0 > date1) {
			date0 = date1;
			date1 = new Date(x[0],x[1]-1,x[2]);
			}
			
			// Add years to date0 until after date1
			while (addYr(date0) <= date1) {
			date0 = addYr(date0);
			yrCount++;
			}
			
			// Add months to date0 until after date1
			while (addMth(date0) <= date1) {
			date0 = addMth(date0);
			mthCount++;
			}
			
			// Add days to date0 until after date1
			while (addDay(date0) <= date1) {
			date0 = addDay(date0);
			dayCount++
			}
			
			if(yrCount<13)
			{
			     alert("Only Users above 13 years are allowed to register on the site");
				
			      document.reg_form.date.focus();
			
			       return false;	
				 
			}
			
		return true
	}
