﻿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_";

    var StartMonthIndexValue = document.getElementById(str+"cardStartM").selectedIndex;
    var StartMonthVal = document.getElementById(str+"cardStartM").options[StartMonthIndexValue].value;

     var StartYearIndexValue = document.getElementById(str+"cardStartY").selectedIndex;
     var StartYearVal = document.getElementById(str+"cardStartY").options[StartYearIndexValue].value;


     var ExpMonthIndexValue = document.getElementById(str +"cardExpM").selectedIndex;
     var ExpMonthVal = document.getElementById(str +"cardExpM").options[ExpMonthIndexValue].value;



     var ExpYearIndexValue = document.getElementById(str+"cardExpY").selectedIndex;
     var ExpYearVal = document.getElementById(str+"cardExpY").options[ExpYearIndexValue].value;


  
 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(StartYearVal ==ExpYearVal)
        {

           if (StartMonthVal >ExpMonthVal)
            {
               strmsg=strmsg + "Plear select valid start and expiry date \n"
                }
        }
   } 
   }
    if (strmsg=="")
    {
    return true;
    }
    else
    {
     alert(strmsg);
     return false;
    }

}
validateCard1=function() 
{
    
    var strmsg = "";
    var StartMonthIndexValue = document.getElementById("cardStartM").selectedIndex;
    var StartMonthVal = document.getElementById("cardStartM").options[StartMonthIndexValue].value;

    var StartYearIndexValue = document.getElementById("cardStartY").selectedIndex;
    var StartYearVal = document.getElementById("cardStartY").options[StartYearIndexValue].value;


    var ExpMonthIndexValue = document.getElementById("cardExpM").selectedIndex;
    var ExpMonthVal = document.getElementById("cardExpM").options[ExpMonthIndexValue].value;



    var ExpYearIndexValue = document.getElementById("cardExpY").selectedIndex;
    var ExpYearVal = document.getElementById("cardExpY").options[ExpYearIndexValue].value;

    if (document.getElementById("drpcardtype").value == "0") {
        strmsg = strmsg + "Please select the card type \n"
    }
    if (document.getElementById("txtcardnum").value == "") {
        strmsg = strmsg + "Please enter the card number \n"
    }
    if (document.getElementById("txtcardName").value == "") {
        strmsg = strmsg + "Please enter the card name\n"
    }
    if (document.getElementById("cardExpM").value == "0") {
        strmsg = strmsg + "Please select the expiry date month  \n"
    }
    if (document.getElementById("cardExpY").value == "0") {
        strmsg = strmsg + "Please select the expiry date year \n"
    }
    if (document.getElementById("txtcardSecNum").value == 0) {
        strmsg = strmsg + "Please enter the security number \n"
    }

    if (StartYearVal == ExpYearVal) {

        if (StartMonthVal > ExpMonthVal) {
            strmsg = strmsg + "Plear select valid start and expiry date \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 + "hidValid").value == "") {
    strmsg = strmsg + " Please select shipping address \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 + "hidValid").value == "") {
    //        strmsg = strmsg + " Please select Billing details \n"
    //    }
    // ctl00_ContentPlaceHolder1_CheckWizard_UCBilling_grdBilling_ctl02_tblChekBilling
    if (document.getElementById(str + "hidValid").value != "") {

        if (document.getElementById(str + "txtB_FirstName").value == "") {
            strmsg = strmsg + "Billing Name is not available. \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 + "Billing Address1 is not available.  \n"
        }
        //    if (document.getElementById(str + "txtB_Address2").value == "") {
        //        strmsg = strmsg + "Billing Address2 is not available.  \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 + "Billing PostCode is not available. \n"
        }
        if (document.getElementById(str + "txtP_PhoneNumber").value == "") {
            strmsg = strmsg + "Phone Number is not available. \n"
        }
        if (document.getElementById(str + "txtP_Eamil").value == "") {
            strmsg = strmsg + " Email Address is not available."
        }
        else {
            if (ValidateForm(document.getElementById(str + "txtP_Eamil")) == false) {
                strmsg = strmsg + " Please enter Valid email address";
            }
        }

        if (strmsg != "") {
            strmsg = "Please select billing details :\n\n" + strmsg
        }

    }
    else {
        strmsg = "Please select billing details :\n\n";

    }


    var strmsg1 = "";
    var str1 = "ctl00_ContentPlaceHolder1_CheckWizard_UCShipping_";
    // ctl00_ContentPlaceHolder1_CheckWizard_UCShipping_grdvShopping_ctl02_tblChekSipping

    if (document.getElementById(str1 + "hidValid").value != "") {
        //    if (document.getElementById(str1 + "ddlTitle").value=="0")
        //    {
        //        strmsg1 = strmsg1 + " Please select the title \n"
        //    }
        //    if (document.getElementById(str1 + "hidValid").value == "") {
        //        strmsg1 = strmsg1 + " Please select shipping  address  \n"
        //    } 
        if (document.getElementById(str1 + "txtFirstName").value == "") {
            strmsg1 = strmsg1 + "Shipping Name is not available.   \n"
        }



        //    if(document.getElementById(str1 + "txtLastName").value=="")
        //    {
        //        strmsg1 = strmsg1 + " Please enter the last name \n"
        //    } 
        if (document.getElementById(str1 + "txtAddress1").value == "") {
            strmsg1 = strmsg1 + "Shipping Address1 is not available. \n"
        }
        //       if (document.getElementById(str1 + "txtAddress2").value == "") {
        //           strmsg1 = strmsg1 + "Shipping Address2 is not available2.  \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 + "Shipping Post Code is not available. "
        }

        if (strmsg1 != "") {
            strmsg1 = "\nPlease select shipping details :\n\n" + strmsg1
        }

    }
    
    else {
       
            strmsg1 = "\nPlease select shipping details :\n\n" 
      

    }



    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, Address3, Address4, JVSAddNo) {

    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 + "txtAddress3").value = Address3;
    document.getElementById(str + "txtAddress4").value = Address4;
    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();
    document.getElementById(str + "hidValid").value = 1;
    document.getElementById(str + "hidFirstName").value = FirstName;
    document.getElementById(str + "hidAddr1").value = Address1;
    document.getElementById(str + "hidJVSNo").value = JVSAddNo;
    document.getElementById(str + "hidAddr2").value = Address2;
    document.getElementById(str + "hidAddr3").value = Address3;
    document.getElementById(str + "hidAddr4").value = Address4;
    document.getElementById(str + "hidpostcode").value = PostCode;
    // alert(FirstName);
    //alert(document.getElementById(str + "hidFirstName").value);


}
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 + "txtAddress3").value = "";
    document.getElementById(str + "txtAddress4").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,address3,address4)
 {
   
    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;
    document.getElementById(str + "txtAddress3").value = address3; 
    document.getElementById(str + "txtAddress4").value = address4;
    document.getElementById(str + "hidValid").value = 1;



}

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;
    document.getElementById(str + "txtAddress3").value = "";
    document.getElementById(str + "txtAddress4").value = "";
}



SetShipping=function(Title,FirstName,LastName,Address1,Address2,City,County,Country,PostCode,val,Address3,Address4,JvsAddNo)
{

    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 + "txtAddress3").value = Address3;
    document.getElementById(str + "txtAddress4").value = Address4;
    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();

    document.getElementById(str + "hidFirstName").value = FirstName;
    document.getElementById(str + "hidAddr1").value = Address1;
    document.getElementById(str + "hidAddr2").value = Address2;
    document.getElementById(str + "hidAddr3").value = Address3;
    document.getElementById(str + "hidAddr4").value = Address4;
    document.getElementById(str + "hidJVSNo").value = JvsAddNo;
    document.getElementById(str + "hidpostcode").value = PostCode;

    
    
}


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); 
	} 
} 	

