﻿Init=function() 
{ 
	if (window.XMLHttpRequest) { // Non-IE browsers 
		_req = new XMLHttpRequest(); 
	} 
	else if (window.ActiveXObject){ // IE 
		_req = new ActiveXObject("Microsoft.XMLHTTP"); 
	} 
} 

processStateChange=function()
{ 	
	if (_req.readyState == 4)
	{
		if (_req.status == 200) 
		{ 
			if(_req.responseText=="") 
				return false; 
			else
			{      
				eval(_req.responseText);             
			} 
		} 
	} 
} 

SendQuery=function(val,ty) //get data 
{ 				
	frm = document.forms[0];
	Init();   																					 																	
	var url;

	if (ty==1){
	url="getAjaxData.aspx?type=shipping&pk="+val; }
	else if (ty==2)
	 {url="getAjaxData.aspx?type=billing&pk="+val; }
	else if  (ty==3)
	 {url="getAjaxData.aspx?type=samecustomer&pk="+val; 
	   //Use for the gat billing details for shipping 
	 }
    else
      {url="getAjaxData.aspx?type=sameshipping&pk="+val; }
	if(_req!=null) 
	{ 	
     	_req.onreadystatechange = processStateChange; 
		_req.open("GET", url, true); 
		_req.send(null); 
	} 
} 	


validateCard=function()
{ 
  var strmsg="";
  var str ="ctl00_ContentPlaceHolder1_CheckWizard_";
  
 if(document.getElementById("ctl00_ContentPlaceHolder1_hdPayMode").value==3)
  { 
  if (document.getElementById(str + "txtAccountHolderName").value == ""){
    strmsg = strmsg + "Please enter account holder name \n"
    }
    if (document.getElementById(str + "txtBankName").value == ""){
    strmsg = strmsg + "Please enter bank name \n"
    } 
    if(document.getElementById(str + "txtchequeNo").value == ""){
    strmsg = strmsg +"Please enter cheque number \n"
    } 
    if(document.getElementById(str + "txtChqueDate").value == ""){
    strmsg = strmsg + "Please enter cheque date  \n"
    } 
  }
  else if(document.getElementById("ctl00_ContentPlaceHolder1_hdPayMode").value==2)
  {
  if(document.getElementById("ctl00_ContentPlaceHolder1_hdSelect").value==1)
   {
    if (document.getElementById(str + "drpcardtype").value=="0"){
    strmsg=strmsg + "Please select the card type \n"
    }
    if (document.getElementById(str + "txtcardnum").value==""){
    strmsg=strmsg + "Please enter the card number \n"
    } 
    if(document.getElementById(str + "txtcardName").value==""){
    strmsg=strmsg +"Please enter the card name\n"
    } 
    if(document.getElementById(str + "cardExpM").value=="0"){
    strmsg=strmsg + "Please select the expiry date month  \n"
    } 
    if(document.getElementById(str + "cardExpY").value=="0"){
    strmsg=strmsg + "Please select the expiry date year \n"
    } 
    if(document.getElementById(str + "txtcardSecNum").value==0){
    strmsg=strmsg + "Please enter the security number \n"
    } 
   } 
   }
    if (strmsg=="")
    {
    return true;
    }
    else
    {
     alert(strmsg);
     return false;
    }
    
}		


ValidShipping=function()
{
  var strmsg="";
   var str ="ctl00_ContentPlaceHolder1_CheckWizard_UCShipping_";
    if (document.getElementById(str + "ddlTitle").value=="0"){
    strmsg=strmsg + "Please select the title \n"
    }
    if (document.getElementById(str + "txtFirstName").value==""){
    strmsg=strmsg + "Please enter the first name \n"
    } 
    if(document.getElementById(str + "txtLastName").value==""){
    strmsg=strmsg +"Please enter the last name \n"
    } 
    if(document.getElementById(str + "txtAddress1").value==""){
    strmsg=strmsg + "Please enter the address1  \n"
    } 
    
    if(document.getElementById(str + "txtCity").value==""){
    strmsg=strmsg + "Please enter the city \n"
    } 
    if(document.getElementById(str + "ddlCountry").value==0){
    strmsg=strmsg + "Please select the country \n"
    } 
    if(document.getElementById(str + "txtPostCode").value==""){
    strmsg=strmsg + "Please enter the post code"
    }
    
    if (strmsg=="")
    {
    return true;
    }
    else
    {
     alert(strmsg);
     return false;
    }
}


ValidBilling=function()
{  
  var strmsg="";
  
   var str ="ctl00_ContentPlaceHolder1_CheckWizard_UCBilling_";
   
   if (document.getElementById(str + "ddlB_Title").value=="0")
    {
        strmsg = strmsg + " Please select the title \n"
    }
    if (document.getElementById(str + "txtB_FirstName").value=="")
    {
        strmsg = strmsg + " Please enter the first name \n"
    } 
    if(document.getElementById(str + "txtB_LastName").value=="")
    {
        strmsg = strmsg + " Please enter the last name \n"
    } 
    if(document.getElementById(str + "txtB_Address1").value=="")
    {
        strmsg = strmsg + " Please enter the address1  \n"
    } 
    if(document.getElementById(str + "txtB_City").value=="")
    {
        strmsg = strmsg + " Please enter the city \n"
    } 
    if(document.getElementById(str + "ddlB_Country").value==0)
    {
        strmsg = strmsg + " Please select the country \n"
    } 
    if(document.getElementById(str + "txtB_PostCode").value=="")
    {
        strmsg = strmsg + " Please enter the post code \n"
    } 
    if(document.getElementById(str + "txtP_PhoneNumber").value=="")
    {
        strmsg = strmsg + " Please enter the phone number \n"
    } 
    if(document.getElementById(str + "txtP_Eamil").value=="")
    {
        strmsg = strmsg + " Please enter the email address"
    } 
    else
    {
       if (ValidateForm(document.getElementById(str + "txtP_Eamil"))==false)
       {
         strmsg=strmsg + " Please enter Valid email address";
       }
    }
    
    if(strmsg != "")
    {
        strmsg= "Please enter billing details :\n\n" + strmsg 
    }
    
    var strmsg1="";
    var str1 ="ctl00_ContentPlaceHolder1_CheckWizard_UCShipping_";
    
    if (document.getElementById(str1 + "ddlTitle").value=="0")
    {
        strmsg1 = strmsg1 + " Please select the title \n"
    }
    if (document.getElementById(str1 + "txtFirstName").value=="")
    {
        strmsg1 = strmsg1 + " Please enter the first name \n"
    } 
    if(document.getElementById(str1 + "txtLastName").value=="")
    {
        strmsg1 = strmsg1 + " Please enter the last name \n"
    } 
    if(document.getElementById(str1 + "txtAddress1").value=="")
    {
        strmsg1 = strmsg1 + " Please enter the address1  \n"
    } 
    if(document.getElementById(str1 + "txtCity").value=="")
    {
        strmsg1 = strmsg1 + " Please enter the city \n"
    } 
    if(document.getElementById(str1 + "ddlCountry").value==0)
    {
        strmsg1 = strmsg1 + " Please select the country \n"
    } 
    if(document.getElementById(str1 + "txtPostCode").value=="")
    {
        strmsg1 = strmsg1 + " Please enter the post code"
    }
    
    if(strmsg1 != "")
    {
        strmsg1 = "\nPlease enter shipping details :\n\n" + strmsg1 
    }
    
    var strmsg2;
    
    strmsg2 = strmsg + strmsg1;
    if (strmsg2 == "")
    {
    return true;
    }
    else
    {
     alert(strmsg2);
     return false;
    }
}


// shipping information
SetValues=function(Title,FirstName,LastName,Address1,Address2,City,County,Country,PostCode,val1)
{

    var str ="ctl00_ContentPlaceHolder1_CheckWizard_UCShipping_";
    document.getElementById(str + "ddlTitle").value=Title;
    document.getElementById(str + "txtFirstName").value=FirstName; 
    document.getElementById(str + "txtLastName").value=LastName ;
    document.getElementById(str + "txtAddress1").value=Address1 ;
    document.getElementById(str + "txtAddress2").value=Address2 ;
    document.getElementById(str + "txtCity").value=City ;
    document.getElementById(str + "txtCounty").value=County ;
    //document.getElementById(str + "ddlCountry").value= Country;
    document.getElementById(str + "txtPostCode").value=PostCode;
    document.getElementById(str + "hidId").value=val1;
   // document.getElementById(str + "txtPostCode").focus();

}
ClearShippingAll=function()
{
   var str ="ctl00_ContentPlaceHolder1_CheckWizard_UCShipping_";
    document.getElementById(str + "ddlTitle").value="0";
    document.getElementById(str + "txtFirstName").value=""; 
    document.getElementById(str + "txtLastName").value="";
    document.getElementById(str + "txtAddress1").value="";
    document.getElementById(str + "txtAddress2").value="";
    document.getElementById(str + "txtCity").value="";
    document.getElementById(str + "txtCounty").value="";
    //document.getElementById(str + "ddlCountry").value="0";
    document.getElementById(str + "txtPostCode").value="";
    document.getElementById(str + "hidId").value=0;
}

//Billing Info 
SetBillingValues=function(Title,FirstName,LastName,Address1,Address2,City,County,Country,PostCode,val)
{ 
 var str ="ctl00_ContentPlaceHolder1_CheckWizard_UCBilling_";
    document.getElementById(str + "ddlB_Title").value=Title;
    document.getElementById(str + "txtB_FirstName").value=FirstName; 
    document.getElementById(str + "txtB_LastName").value=LastName ;
    document.getElementById(str + "txtB_Address1").value=Address1 ;
    document.getElementById(str + "txtB_Address2").value=Address2 ;
    document.getElementById(str + "txtB_City").value=City ;
    document.getElementById(str + "txtB_County").value=County ;
    document.getElementById(str + "ddlB_Country").value= Country;
    document.getElementById(str + "txtB_PostCode").value=PostCode;
    document.getElementById(str + "hidIdBill").value=val;

}

ClearBillingAll=function()
{
   var str ="ctl00_ContentPlaceHolder1_CheckWizard_UCBilling_";
     document.getElementById(str + "ddlB_Title").value="0";
    document.getElementById(str + "txtB_FirstName").value=""; 
    document.getElementById(str + "txtB_LastName").value="";
    document.getElementById(str + "txtB_Address1").value="";
    document.getElementById(str + "txtB_Address2").value="";
    document.getElementById(str + "txtB_City").value="";
    document.getElementById(str + "txtB_County").value="";
    document.getElementById(str + "ddlB_Country").value="0";
    document.getElementById(str + "txtB_PostCode").value="";
    document.getElementById(str + "hidIdBill").value=0;
}



SetShipping=function(Title,FirstName,LastName,Address1,Address2,City,County,Country,PostCode,val)
{

    var str ="ctl00_ContentPlaceHolder1_CheckWizard_UCShipping_";
    document.getElementById(str + "ddlTitle").value=Title;
    document.getElementById(str + "txtFirstName").value=FirstName;
    document.getElementById(str + "txtLastName").value=LastName;
    document.getElementById(str + "txtAddress1").value=Address1;
    document.getElementById(str + "txtAddress2").value=Address2;
    document.getElementById(str + "txtCity").value=City;
    //document.getElementById(str + "ddlCountry").value=Country;
    document.getElementById(str + "txtCounty").value=County;
    document.getElementById(str + "txtPostCode").value=PostCode;
    document.getElementById(str + "hidId").value=val;
    //document.getElementById(str + "txtPostCode").focus();

    
    
}


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){
		  
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		  
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		   
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		   
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		    
		    return false
		 }

 		 return true					
	}

function ValidateForm(emailID){
	
	if (echeck(emailID.value)==false){
		emailID.value=""
		emailID.focus()
		return false
	}
	return true
 }
 
 
 /// Delivery Type value set
 
 SendQuery1=function(val,txtval) //get data 
{ 	
     frm = document.forms[0];			
	Init();   																					 																	
	var url;
    url="getAjaxData.aspx?type=delivery&pk="+val+ "&txt="+ txtval; 
    //alert(url);
	if(_req!=null) 
	{ 	
     	_req.onreadystatechange = processStateChange; 
		_req.open("GET", url, true); 
		_req.send(null); 
	} 
} 	
