//check correct mail address
function check_email(msg,obj)
{
	 if ((/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(obj.value)) == false)
 		{
			alert(msg);
		    obj.focus();
		    //obj.select();
			return false;
		}
}

function show_cat()
{
	document.getElementById("p_cat").style.display="";	
	
}
//check for blank
function checkblank(msg,obj)
{
	if(obj.value == "")
		{
		alert(msg);
		obj.focus();
		return false ;
		}
}

function check_username(msg,obj)
{		
		var string1="qazwsxedcrfvtgbyhnujmikolpQAZWSXEDCRFVTGBYHNUJMIKOLP._ ";
		var val=obj.value;
		var op=new String();
	    op.value=val;
	     	 for(var i=0;i<op.value.length;i++)
			   {
		    	 if(string1.indexOf(op.value.charAt(i))==-1)
			   		{
						alert(msg);
						obj.focus();
						return false;
			        }
			   }
}


function check_amout(msg,obj)
{		
		var string1="qazwsxedcrfvtgbyhnujmikolpQAZWSXEDCRFVTGBYHNUJMIKOLP._ ";
		var val=obj.value;
		var op=new String();
	    op.value=val;
	     	 for(var i=0;i<op.value.length;i++)
			   {
		    	 if(string1.indexOf(op.value.charAt(i))==-1)
			   		{
						alert(msg);
						obj.focus();
						return false;
			        }
			   }
}

function check_number(msg ,obj)
{
		var string1="1234567890- *x()+";
		var val=obj.value;
		var op=new String();
	    op.value=val;
		//alert(op.val);
	     	 for(var i=0;i<op.value.length;i++)
			   {
		    	 if(string1.indexOf(op.value.charAt(i))==-1)
			   		{
						alert(msg);
						obj.focus();
						return false;
			        }
			   }//for
		
		var len;
		n=obj.value;
		len=n.length;
		var i=0;
		if(!(len>=8 && len<=11))
		{
			obj.focus();
			alert("Please enter telephone number between 8 to 11 length!");
			return false;
		}		 
}

function amount_check(msg,obj)
{
		var string1="1234567890";
		var val=obj.value;
		var op=new String();
	    op.value=val;
		var len = op.value.length ;
		//var i = new int() ;
	    for(var i=0 ; i < op.value.length ; i++)
			  {
		    	 if(string1.indexOf(op.value.charAt(i))==-1)
			   		{
						alert(msg)
						obj.focus();
						return false;
			        }
			   }//for
}

function check_length(msg ,obj)
{
	var len;
	n=obj.value;
	len=n.length;
	if(!(len>=5&&len<=15))
		{
			obj.focus();
			alert(msg);
			return false;
		}
}

function check_rpassward(msg,obj1,obj2)
{
    var len1,len2;
	var passward = new Array();
	var rpassward = new Array();
	
	n1=obj1.value;
	lenpass=n1.length;
	passward = n1;
	
	n2=obj2.value;
	lenrpass=n2.length;
	rpassward=n2;
	if(lenrpass != lenpass)
		{
		obj2.focus();
		alert(msg);
		return false;
		}
	var i=0;
	while(i<lenpass)
		{//myRange1.isEqual(myRange2
		if(passward[i]!=rpassward[i])
			{
			obj2.focus();
			alert(msg);
			return false;
			}
	   i=i+1;
	   }
}
function eselect()
{
		//alert("hello");
		if(document.getElementById("e").checked)
		{
		document.getElementById("1").style.display = "none"; 
		document.getElementById("2").style.display = "none"; 
		}
		else
		{
		document.getElementById("1").style.display = ""; 
		document.getElementById("2").style.display = ""; 
		}
}

//day difference
function DaysDiff(D1, D2) 
{ // Date Objects, with similar times
return Math.round((D1-D2)/864e5) 
}

function ParseDate(S) { // Permit ISO DateSeps
return new Date( S.replace(/-/g, "/") ) 
}


function validateedit()
{
	
	
	flag = checkblank("Please enter first name",document.form1.fname);
	if(flag==false) { return false; }
	flag = checkblank("Please enter last name",document.form1.lname);
	if(flag==false) { return false; }
	flag =checkblank("Please enter personal mail id1",document.form1.personal_mail_id1);
	if(flag==false) { return false; }
	flag =check_email("Please enter proper personal mail id1",document.form1.personal_mail_id1);
	if(flag==false) { return false; }
	
	flag = checkblank("Please enter password",document.form1.password);
	if(flag==false) { return false; }
	
	flag = checkblank("Please enter Date of birth.",document.form1.dob);
	if(flag==false) { return false; }
	flag = checkblank("Please enter address1.",document.form1.address1);
	if(flag==false) { return false; }
	flag = checkblank("Please enter city.",document.form1.city);
	if(flag==false) { return false; }
	flag = checkblank("Please enter state.",document.form1.state);
	if(flag==false) { return false; }
	flag = checkblank("Please enter residential telephone1.",document.form1.res_tel1);
	if(flag==false) { return false; }
	flag = checkblank("Please enter mobile1.",document.form1.mobile1);
	if(flag==false) { return false; }
	/*if(document.form1.personal_mail_id2.value!=" ")
	{
		flag=check_email("Please enter proper personal mail id2",document.form1.personal_mail_id2);
		if(flag==false) { return false; }
	}
	if(document.form1.office_mailid.value!=" ")
	{
		flag=check_email("Please enter proper office_mailid",document.form1.office_mailid);
		if(flag==false) { return false; }
	}*/	
}


function validateregister()
{
	validCode = 0;
	if(document.form1.gm_id[document.form1.gm_id.selectedIndex].value!="0")
	{
		if(document.form1.gm_registration.value=="")
		{
			alert("Please enter registration code");
			return false;
		}
		else if(document.form1.gm_registration.value!="")
		{
			if(document.form1.gm_code.value!=document.form1.gm_registration.value)
			{
				
				alert("Please enter valid registration code");
				return false;
			}
			else
			{
				validCode = 1;
			}
		}
	}
	
	flag = checkblank("Please enter first name",document.form1.fname);
	if(flag==false) { return false; }
	flag = checkblank("Please enter last name",document.form1.lname);
	if(flag==false) { return false; }
	flag =checkblank("Please enter personal email id",document.form1.personal_mail_id1);
	if(flag==false) { return false; }
	flag =check_email("Please enter proper personal email id 2",document.form1.personal_mail_id1);
	if(flag==false) { return false; }
	
	flag = checkblank("Please enter password",document.form1.password);
	if(flag==false) { return false; }
	
	flag = checkblank("Please enter Date of birth.",document.form1.dob);
	if(flag==false) { return false; }
	flag = checkblank("Please enter address.",document.form1.address1);
	if(flag==false) { return false; }
	flag = checkblank("Please enter city.",document.form1.city);
	if(flag==false) { return false; }
	flag = checkblank("Please enter state.",document.form1.state);
	if(flag==false) { return false; }
	flag = checkblank("Please enter pincode.",document.form1.pincode);
	if(flag==false) { return false; }	
	flag = checkblank("Please enter residential telephone no.",document.form1.res_tel1);
	if(flag==false) { return false; }
	flag = checkblank("Please enter mobile no.",document.form1.mobile1);
	if(flag==false) { return false; }
	/*if(document.form1.personal_mail_id2.value!=" ")
	{
		flag=check_email("Please enter proper personal mail id2",document.form1.personal_mail_id2);
		if(flag==false) { return false; }
	}
	if(document.form1.office_mailid.value!=" ")
	{
		flag=check_email("Please enter proper office_mailid",document.form1.office_mailid);
		if(flag==false) { return false; }
	}*/
	
	if(validCode == 1)
	{
		flag = checkblank("Please enter company name.",document.form1.company_name);
		if(flag==false) { return false; }	
		flag = checkblank("Please enter office address.",document.form1.office_address1);
		if(flag==false) { return false; }	
		flag = checkblank("Please enter office city.",document.form1.office_city);
		if(flag==false) { return false; }	
		flag = checkblank("Please enter office state.",document.form1.office_state);
		if(flag==false) { return false; }	
		flag = checkblank("Please enter office telephone no.",document.form1.office_tel1);
		if(flag==false) { return false; }	
	}
}

function validatedelivery()
{
	flag = checkblank("Please enter first name",document.delivery.fname1);
	if(flag==false) { return false; }
	flag = check_username("Please enter alphabets only in first name", document.delivery.fname1);
	if(flag==false) { return false; }
	flag = checkblank("Please enter last name",document.delivery.lname1);
	if(flag==false) { return false; }
	flag = check_username("Please enter alphabets only in last name", document.delivery.lname1);
	if(flag==false) { return false; }	
	flag =checkblank("Please enter personal mail id1",document.delivery.personal_mail_id11);
	if(flag==false) { return false; }
	flag =check_email("Please enter proper personal mail id1",document.delivery.personal_mail_id11);
	if(flag==false) { return false; }
	flag = checkblank("Please enter address1.",document.delivery.address11);
	if(flag==false) { return false; }
	flag = checkblank("Please enter recidential telephone1.",document.delivery.res_tel11);
	if(flag==false) { return false; }
	flag = checkblank("Please enter city.",document.delivery.city1);
	if(flag==false) { return false; }
	flag = checkblank("Please enter state.",document.delivery.state1);
	if(flag==false) { return false; }
}

function validatebilling()
{

	flag = checkblank("Please enter first name",document.billing.fname);
	if(flag==false) { return false; }
	flag = check_username("Please enter alphabets only in first name", document.billing.fname);
	if(flag==false) { return false; }	
	flag = checkblank("Please enter last name",document.billing.lname);
	if(flag==false) { return false; }
	flag = check_username("Please enter alphabets only in last name", document.billing.lname);
	if(flag==false) { return false; }	
	flag =checkblank("Please enter personal mail id.",document.billing.personal_mail_id1);
	if(flag==false) { return false; }
	flag =check_email("Please enter proper personal mail id.",document.billing.personal_mail_id1);
	if(flag==false) { return false; }
	flag = checkblank("Please enter address1.",document.billing.address1);
	if(flag==false) { return false; }
	
	flag = checkblank("Please enter residential telephone.",document.billing.res_tel1);
	if(flag==false) { return false; }
	flag = check_number("Please enter residential no. in digit",document.billing.res_tel1);
	if(flag==false) { return false; }	
	
	flag = checkblank("Please enter office no.",document.billing.off_phone1);
	if(flag==false) { return false; }
	flag = check_number("Please enter office no. in digit",document.billing.off_phone1);
	if(flag==false) { return false; }	
	
	flag = checkblank("Please enter mobile no.",document.billing.mobile1);
	if(flag==false) { return false; }
	flag = check_number("Please enter mobile no. in digit.",document.billing.mobile1);
	if(flag==false) { return false; }	
	
	if(document.billing.country_name.value=='0'){
		alert("Please select billing country");
		document.billing.country_name.focus();
		return false;
	}
	if(document.billing.state_name.value=='0' || document.billing.state_name.value==''){
		alert("Please enter billing state");
		document.billing.state_name.focus();
		return false;
	}
	if(document.billing.city_name.value=='0' || document.billing.city_name.value==''){
		alert("Please enter billing city");
		document.billing.city_name.focus();
		return false;
	}
	
	
	
	//flag = checkblank("Please enter city.",document.billing.city);
	//if(flag==false) { return false; }
	//flag = checkblank("Please enter state.",document.billing.state);
	//if(flag==false) { return false; }
	flag = checkblank("Please enter pin code.",document.billing.pin);
	if(flag==false) { return false; }	

	flag = checkblank("Delivery Info : Please enter first name",document.billing.fname1);
	if(flag==false) { return false; }
	flag = check_username("Delivery Info : Please enter alphabets only in first name",document.billing.fname1);
	if(flag==false) { return false; }	
	flag = checkblank("Delivery Info : Please enter last name",document.billing.lname1);
	if(flag==false) { return false; }
	flag = check_username("Delivery Info : Please enter alphabets only in last name",document.billing.lname1);
	if(flag==false) { return false; }		
	flag =checkblank("Delivery Info : Please enter personal mail id.",document.billing.personal_mail_id11);
	if(flag==false) { return false; }
	flag =check_email("Delivery Info : Please enter proper personal mail id.",document.billing.personal_mail_id11);
	if(flag==false) { return false; }
	
	
	flag = checkblank("Please enter residential telephone.",document.billing.res_tel11);
	if(flag==false) { return false; }
	flag = check_number("Please enter residential no. in digit",document.billing.res_tel11);
	if(flag==false) { return false; }	
	
	flag = checkblank("Please enter office no.",document.billing.off_phone11);
	if(flag==false) { return false; }
	flag = check_number("Please enter office no. in digit",document.billing.off_phone11);
	if(flag==false) { return false; }	
	
	flag = checkblank("Please enter mobile no.",document.billing.mobile11);
	if(flag==false) { return false; }
	flag = check_number("Please enter mobile no. in digit.",document.billing.mobile11);
	if(flag==false) { return false; }	

	
	//flag = checkblank("Delivery Info : Please enter city.",document.billing.city1);
	//if(flag==false) { return false; }
	
	//flag = checkblank("Delivery Info : Please enter state.",document.billing.state1);
	//if(flag==false) { return false; }

	
	if(document.billing.country_name2.value=='0'){
		alert("Please select delivery country");
		document.billing.country_name.focus();
		return false;
	}
	if(document.billing.state_name1.value=='0' || document.billing.state_name1.value==''){
		alert("Please enter delivery state");
		document.billing.state_name1.focus();
		return false;
	}
	if(document.billing.city_name1.value=='0' || document.billing.city_name1.value==''){
		alert("Please enter delivery city");
		document.billing.city_name1.focus();
		return false;
	}
	
	
	
	
	flag = checkblank("Delivery Info : Please enter pin code.",document.billing.pin1);
	if(flag==false) { return false; }
	
	//if(document.billing.area.value=='Select Area'){
		//alert("Please select delivery area.");	
		//document.billing.area.focus();
		//return false;	
	//}
	
	//if(document.billing.dl_date.value == ""){
		//alert("Please select delivery date")
		//return false;
	//}
	
		
//  if(document.billing.valTOD.value==0)
//  {
//    alert("Please select the type of delivery option");
//	return false;	
//  }	
  
//  if(document.billing.valPAY.value==0)
//  {
//    alert("Please select the payment option");
//	return false;	
//  }	  
}

function validatebillingOffer()
{

	flag = checkblank("Please enter first name",document.billing.fname);
	if(flag==false) { return false; }
	flag = check_username("Please enter alphabets only in first name", document.billing.fname);
	if(flag==false) { return false; }	
	flag = checkblank("Please enter last name",document.billing.lname);
	if(flag==false) { return false; }
	flag = check_username("Please enter alphabets only in last name", document.billing.lname);
	if(flag==false) { return false; }	
	flag =checkblank("Please enter personal mail id.",document.billing.personal_mail_id1);
	if(flag==false) { return false; }
	flag =check_email("Please enter proper personal mail id.",document.billing.personal_mail_id1);
	if(flag==false) { return false; }
	flag = checkblank("Please enter address1.",document.billing.address1);
	if(flag==false) { return false; }
	
	flag = checkblank("Please enter residential telephone.",document.billing.res_tel1);
	if(flag==false) { return false; }
	flag = check_number("Please enter residential no. in digit",document.billing.res_tel1);
	if(flag==false) { return false; }	
	
	flag = checkblank("Please enter office no.",document.billing.off_phone1);
	if(flag==false) { return false; }
	flag = check_number("Please enter office no. in digit",document.billing.off_phone1);
	if(flag==false) { return false; }	
	
	flag = checkblank("Please enter mobile no.",document.billing.mobile1);
	if(flag==false) { return false; }
	flag = check_number("Please enter mobile no. in digit.",document.billing.mobile1);
	if(flag==false) { return false; }	
	
	if(document.billing.country_name.value=='0'){
		alert("Please select billing country");
		document.billing.country_name.focus();
		return false;
	}
	
	if(document.billing.city_name.value==''){
		alert("Please enter billing city");
		document.billing.city_name.focus();
		return false;
	}
	
	
	
	//flag = checkblank("Please enter city.",document.billing.city);
	//if(flag==false) { return false; }
	//flag = checkblank("Please enter state.",document.billing.state);
	//if(flag==false) { return false; }
	flag = checkblank("Please enter pin code.",document.billing.pin);
	if(flag==false) { return false; }	

	flag = checkblank("Delivery Info : Please enter first name",document.billing.fname1);
	if(flag==false) { return false; }
	flag = check_username("Delivery Info : Please enter alphabets only in first name",document.billing.fname1);
	if(flag==false) { return false; }	
	flag = checkblank("Delivery Info : Please enter last name",document.billing.lname1);
	if(flag==false) { return false; }
	flag = check_username("Delivery Info : Please enter alphabets only in last name",document.billing.lname1);
	if(flag==false) { return false; }		
	flag =checkblank("Delivery Info : Please enter personal mail id.",document.billing.personal_mail_id11);
	if(flag==false) { return false; }
	flag =check_email("Delivery Info : Please enter proper personal mail id.",document.billing.personal_mail_id11);
	if(flag==false) { return false; }
	
	
	flag = checkblank("Please enter residential telephone.",document.billing.res_tel11);
	if(flag==false) { return false; }
	flag = check_number("Please enter residential no. in digit",document.billing.res_tel11);
	if(flag==false) { return false; }	
	
	flag = checkblank("Please enter office no.",document.billing.off_phone11);
	if(flag==false) { return false; }
	flag = check_number("Please enter office no. in digit",document.billing.off_phone11);
	if(flag==false) { return false; }	
	
	flag = checkblank("Please enter mobile no.",document.billing.mobile11);
	if(flag==false) { return false; }
	flag = check_number("Please enter mobile no. in digit.",document.billing.mobile11);
	if(flag==false) { return false; }	

	
	//flag = checkblank("Delivery Info : Please enter city.",document.billing.city1);
	//if(flag==false) { return false; }
	
	//flag = checkblank("Delivery Info : Please enter state.",document.billing.state1);
	//if(flag==false) { return false; }

	
	if(document.billing.country_name2.value=='0'){
		alert("Please select delivery country");
		document.billing.country_name.focus();
		return false;
	}
	
	if(document.billing.city_name1.value=='0' || document.billing.city_name1.value==''){
		alert("Please enter delivery city");
		document.billing.city_name1.focus();
		return false;
	}
	
	
	
	
	flag = checkblank("Delivery Info : Please enter pin code.",document.billing.pin1);
	if(flag==false) { return false; }
	
	//if(document.billing.area.value=='Select Area'){
		//alert("Please select delivery area.");	
		//document.billing.area.focus();
		//return false;	
	//}
	
	//if(document.billing.dl_date.value == ""){
		//alert("Please select delivery date")
		//return false;
	//}
	
		
 // if(document.billing.valTOD.value==0)
//  {
//    alert("Please select the type of delivery option");
//	return false;	
//  }	
//  
//  if(document.billing.valPAY.value==0)
//  {
//    alert("Please select the payment option");
//	return false;	
//  }	  
}


function checkVal()
{
    //flag = checkblank("Please select payment by option.",document.billing.pay_by);
	//if(flag==false) { return false; }	

	
	if(document.billing.chk_terms.checked==true){
		//return true;
	}else{ 
		alert("Please accept terms & conditions.");	
		return false; 
	}
	
	
	
}





