/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */



//function productdetail(thisForm) {
//    haschild = thisForm.haschildren.value
//
//    if(!haschild) {
//        return true
//    }
//    else {
//        flag = false
//        if(thisForm.child_product.length==undefined) {
//            if(thisForm.child_product.checked) {
//                flag = true;
//            }
//        }
//        else {
//            for(var i=0; i<thisForm.child_product.length; i++) {
//                if(thisForm.child_product[i].checked) {
//                    flag = true;
//                    break;
//                }
//            }
//        }
//
//        if(!flag) {
//            alert("Please select product option")
//        }
//
//        return flag;
//    }
//}

function productdetail(productoption)
{

    haschild = productoption.haschildren.value
    childproductcount=productoption.childproductcount.value
    allInputs = document.getElementsByTagName("input");
    var last = "NameUnlikelyToBeUsedAsAnElementName";
    if(!haschild) {
        return true
    }
    else
    {
        // walk through the array
        for (i = 0; i< allInputs.length; i++)
        {
            var input = allInputs[i];
            if (input.name == last) continue; // if this object name is the same as the last checked radio, go to next iteration


            // checks to see if any  one of  similarly named radiobuttons is checked
            else if (input.type == "radio" )
            {
                last = input.name;
                var radios = document.getElementsByName(input.name);

                var radioSelected=false;

                //iterate over question options
                for (j=0; j < radios.length; j++)

                {
                        if(radios[j].checked)
                        {
                            radioSelected=true;
                            break; // Found it, proceed to next question
                        }

                    }

                if (!radioSelected ) // no option selected
                {       // warn user, focus question

                    alert("Please select the option");
                    input.focus();
                    return false;

                }
            }

        }
    }
}

function isValidEmail(email){
    var RegExp = /^((([a-z]|[0-9]|!|#|$|%|&|'|\*|\+|\-|\/|=|\?|\^|_|`|\{|\||\}|~)+(\.([a-z]|[0-9]|!|#|$|%|&|'|\*|\+|\-|\/|=|\?|\^|_|`|\{|\||\}|~)+)*)@((((([a-z]|[0-9])([a-z]|[0-9]|\-){0,61}([a-z]|[0-9])\.))*([a-z]|[0-9])([a-z]|[0-9]|\-){0,61}([a-z]|[0-9])\.)[\w]{2,4}|(((([0-9]){1,3}\.){3}([0-9]){1,3}))|(\[((([0-9]){1,3}\.){3}([0-9]){1,3})\])))$/
    if(RegExp.test(email)){
        return true;
    }else{
        return false;
    }
} 

var xmlHttp;
function createXmlHttpRequest() {

    try
    {
        // Firefox, Opera 8.0+, Safari
        xmlHttp=new XMLHttpRequest();
    }
    catch (e)
    {
        // Internet Explorer
        try
        {
            xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
        }
        catch (e)
        {
            try
            {
                xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
            }
            catch (e)
            {
                alert("Your browser does not support AJAX!" + e);
                return false;
            }
        }
    }
//    return xmlHttp;
}
var step = 0;
function checkout_billing_step() {
   
    createXmlHttpRequest();
    // var actionUrl="";
    //    var queryString="";
    //    queryString="editcurl="+Categoryurl;
    //     queryString="editcurl="+Categoryurl+'&'+"excurl="+excurl;
    //    //actionUrl="/shipping/loadStateList"
    //    actionUrl="/productsku/editcategoryurl"
    //
    //    actionUrl+="?"+queryString;

    // var authenticity_token=token;
    // var queryString="authenticity_token="+token;
    var actionUrl = "/checkout/plantwo_checkout_step_billing";
    // actionUrl+="?"+queryString;
    var params = "";

    xmlHttp.open("POST", actionUrl, true);
    xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    xmlHttp.setRequestHeader("Content-length", params.length);
    xmlHttp.setRequestHeader("Connection", "close");
    xmlHttp.setRequestHeader("If-Modified-Since", "Thu, 1 Jan 1970 00:00:00 GMT");
    xmlHttp.setRequestHeader("Cache-Control", "no-cache");

    xmlHttp.onreadystatechange = function() {//Call a function when the state changes.
        
        if(xmlHttp.readyState == 4 && xmlHttp.status==200) {

            step = 1;
            document.getElementById("billing-info").innerHTML = xmlHttp.responseText;
            document.getElementById("billing-info").style.display = "";
            hideothers("billing-info")
        }
    }
    xmlHttp.send(params);

}

var step = 0;
function postcomment(blogId) {

    createXmlHttpRequest();
    // var actionUrl="";
    //    var queryString="";
    //    queryString="editcurl="+Categoryurl;
    //     queryString="editcurl="+Categoryurl+'&'+"excurl="+excurl;
    //    //actionUrl="/shipping/loadStateList"
    //    actionUrl="/productsku/editcategoryurl"
    //
    //    actionUrl+="?"+queryString;
    // alert(blogId);
    var blogPageId=blogId;
    var queryString="blogPageId="+blogId;
    var actionUrl = "/blog/blogpagecommentsave";
    actionUrl+="?"+queryString;
    
    var params = "";

    xmlHttp.open("POST", actionUrl, true);
   
    xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
     
    xmlHttp.setRequestHeader("Content-length", params.length);
   
    xmlHttp.setRequestHeader("Connection", "close");
   
    xmlHttp.setRequestHeader("If-Modified-Since", "Thu, 1 Jan 1970 00:00:00 GMT");
    
    xmlHttp.setRequestHeader("Cache-Control", "no-cache");
     
    xmlHttp.onreadystatechange = function() {//Call a function when the state changes.

        if(xmlHttp.readyState == 4 && xmlHttp.status==200) {
            step = 1;
            document.getElementById("comments").innerHTML = xmlHttp.responseText;
            document.getElementById("comments").style.display = "";
            hideothers("comments");
        }
    }
    xmlHttp.send(params);

}



function billing_save()
{

    createXmlHttpRequest();

    // Get Params
    var billingform = document.co_billing_form
    var billto_firstname = billingform.billto_firstname.value;
    var billto_lastname = billingform.billto_lastname.value;
    var billto_company = billingform.billto_company.value;
    var billto_email = billingform.billto_email.value;
    var billto_address1 = billingform.billto_address1.value;
    var billto_address2 = billingform.billto_address2.value;
    var billto_city = billingform.billto_city.value;
    var billto_state = billingform.billto_state.value;
    var billto_state_name = billingform.billto_state_name.value;
    var billto_zipcode = billingform.billto_zipcode.value;
    var billto_country = billingform.billto_country.value;
    // var billto_areacode=billingform.billto_areacode.value;
    var billto_phone = billingform.billto_phone.value;
    var billto_fax = billingform.billto_fax.value;



    // Validating form fields
    errcount = 0
    errmsg = ""
    if(trimString(billto_firstname).length == 0) {
        errcount ++
        errmsg += "<div class=\"er-msg\">First name is missing</div>"
    //billingform.billto_firstname.style.borderColor = "#ff0000"
    } else {
        billingform.billto_firstname.style.borderColor = ""
    }

    if(trimString(billto_lastname).length == 0) {
        errcount ++
        errmsg += "<div class=\"er-msg\">Last name is missing</div>"

    } else {
        billingform.billto_lastname.style.borderColor = ""
    }

    if(trimString(billto_email).length == 0) {
        errcount ++;
        errmsg += "<div class=\"er-msg\">Email is missing</div>";
    //billingform.billto_email.style.className = "checkout-error";


    } else {
        billingform.billto_email.style.borderColor = ""
    }

    if(trimString(billto_email).length > 0)
    {
           
        if(isValidEmail(billto_email)!= true)
        {
            errcount ++;
            errmsg += "<div class=\"er-msg\">Improper Emailaddress  </div>";
        }
    }
    else
    {
        billingform.billto_email.style.borderColor = ""
    }

    if(trimString(billto_address1).length == 0) {
        errcount ++
        errmsg += "<div class=\"er-msg\">Address 1 is missing</div>"
    //billingform.billto_address1.style.borderColor = "#ff0000"
    } else {
        billingform.billto_address1.style.borderColor = ""
    }

    if(trimString(billto_city).length == 0) {
        errcount ++
        errmsg += "<div class=\"er-msg\">City is missing</div>"

    } else {
        billingform.billto_city.style.borderColor = ""
    }
    //    if(trimString(billto_city).length > 0) {
    //        if(!fnIsNumeric2(billto_city))
    //        {
    //            errcount ++
    //            errmsg += "<div class=\"er-msg\">Enter only character</div>"
    //        }
    //    }
    //    else {
    //        billingform.billto_city.style.borderColor = ""
    //    }
    if(trimString(billto_zipcode).length == 0) {
        errcount ++
        errmsg += "<div class=\"er-msg\">Zipcode is missing</div>"
    //billingform.billto_address1.style.borderColor = "#ff0000"
    } else {
        billingform.billto_zipcode.style.borderColor = ""
    }

    //    if(trimString(billto_areacode).length == 0) {
    //        errcount ++
    //        errmsg += "<div class=\"er-msg\">Area Code is missing</div>"
    //
    //    } else {
    //        billingform.billto_areacode.style.borderColor = ""
    //    }

    if(trimString(billto_phone).length == 0) {
        errcount ++
        errmsg += "<div class=\"er-msg\">Phone is missing</div>"
    //billingform.billto_address1.style.borderColor = "#ff0000"
    } else {
        //        if(!isNumber(billto_phone))
        //           {
        //               errcount ++
        //               errmsg += "<div class=\"er-msg\">Please enter the valid phone number</div>"
        //           }
        billingform.billto_phone.style.borderColor = ""
    }

    if(document.getElementById("billto_state_name").style.display == "") {
        if(trimString(billto_state_name).length == 0) {
            errcount ++
            errmsg += "<div class=\"er-msg\">State is missing</div>"
        //billingform.billto_address1.style.borderColor = "#ff0000"
        } else {
            billingform.billto_phone.style.borderColor = ""
        }
    } else {

    }


    if(errcount > 0) {
        errmsg = "<div class=\"tit\">Below Error(s) prevent your checkout</div>"+errmsg
        document.getElementById("checkout-step-billing-err").innerHTML = errmsg
        document.getElementById("checkout-step-billing-err").style.display = ""

        return false;
    } else {
        document.getElementById("checkout-step-billing-err").style.display = "none"
    }








    //    var billto_shipto_option;
    //
    //    for(var l=0; l<billingform.use_for_shipping.length; l++) {
    //        if(billingform.use_for_shipping[l].checked == true) {
    //            billto_shipto_option = billingform.use_for_shipping[l].value
    //        }
    //    }

    // POST Request
    //var url = "/checkout/savebilling";
    var url = "/checkout/savebilling";
    var params = "billto_firstname="+billto_firstname+"&billto_lastname="+billto_lastname+"&billto_company="+billto_company+"&billto_email="+billto_email+"&billto_address1="+billto_address1+"&billto_address2="+billto_address2+"&billto_city="+billto_city+"&billto_state="+billto_state+"&billto_state_name="+billto_state_name+"&billto_zipcode="+billto_zipcode+"&billto_country="+billto_country+"&billto_phone="+billto_phone+"&billto_fax="+billto_fax+"";
    //alert (params)
    xmlHttp.open("POST", url, true);
    xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    xmlHttp.setRequestHeader("Content-length", params.length);
    xmlHttp.setRequestHeader("Connection", "close");
    xmlHttp.setRequestHeader("If-Modified-Since", "Thu, 1 Jan 1970 00:00:00 GMT");
    xmlHttp.setRequestHeader("Cache-Control", "no-cache");

    xmlHttp.onreadystatechange = function() {//Call a function when the state changes.
        //alert (xmlHttp.readyState + " " + xmlHttp.status)
        if(xmlHttp.readyState == 4 && xmlHttp.status==200) {
            //alert("response xml is \n" + xmlHttp.responseText);
            var response = xmlHttp.responseXML;
            var result = response.documentElement.getElementsByTagName("result")[0].childNodes[0].nodeValue;

            var ret_billto_state = ""
            var ret_billto_state_name = ""
            var ret_billto_country = ""
            if(response.documentElement.getElementsByTagName("ret-billto-state")[0].childNodes[0]!=undefined) {
                ret_billto_state = response.documentElement.getElementsByTagName("ret-billto-state")[0].childNodes[0].nodeValue;
            }
            if(response.documentElement.getElementsByTagName("ret-billto-state-name")[0].childNodes[0]!=undefined) {
                ret_billto_state_name = response.documentElement.getElementsByTagName("ret-billto-state-name")[0].childNodes[0].nodeValue;
            }
            if(response.documentElement.getElementsByTagName("ret-billto-country")[0].childNodes[0]!=undefined) {
                ret_billto_country = response.documentElement.getElementsByTagName("ret-billto-country")[0].childNodes[0].nodeValue;
            }


            if(result == "true") {
                //alert("start shipping")
                document.getElementById("edit_billing_content").innerHTML = "<address>"+billto_firstname+" " +billto_lastname +"<br/>"+billto_email+"<br/>"+billto_address1+"<br/>"+billto_city+"<br/>"+ret_billto_state + ret_billto_state_name +"<br/>"+ret_billto_country+"<br/>"+billto_phone+"</address>";
                document.getElementById("a-billing-info").style.display = "";
                document.getElementById("edit_billing_content").style.display="";
                //checkout_shipping_step();
                checkout_shipping_method_step();
            }
        }
    }
    xmlHttp.send(params);
}

function billing_save_ls()
{

    createXmlHttpRequest();

    // Get Params
    var billingform = document.co_billing_form
    var billto_firstname = billingform.billto_firstname.value;
    var billto_lastname = billingform.billto_lastname.value;
    var billto_company = billingform.billto_company.value;
    var billto_email = billingform.billto_email.value;
    var billto_address1 = billingform.billto_address1.value;
    var billto_address2 = billingform.billto_address2.value;
    var billto_city = billingform.billto_city.value;
    var billto_state = billingform.billto_state.value;
    var billto_state_name = billingform.billto_state_name.value;
    var billto_zipcode = billingform.billto_zipcode.value;
    var billto_country = billingform.billto_country.value;
    // var billto_areacode=billingform.billto_areacode.value;
    var billto_phone = billingform.billto_phone.value;
    var billto_fax = billingform.billto_fax.value;



    // Validating form fields
    errcount = 0
    errmsg = ""
    if(trimString(billto_firstname).length == 0) {
        errcount ++
        errmsg += "<div class=\"er-msg\">First name is missing</div>"
    //billingform.billto_firstname.style.borderColor = "#ff0000"
    } else {
        billingform.billto_firstname.style.borderColor = ""
    }

    if(trimString(billto_lastname).length == 0) {
        errcount ++
        errmsg += "<div class=\"er-msg\">Last name is missing</div>"

    } else {
        billingform.billto_lastname.style.borderColor = ""
    }

    if(trimString(billto_email).length == 0) {
        errcount ++;
        errmsg += "<div class=\"er-msg\">Email is missing</div>";
    //billingform.billto_email.style.className = "checkout-error";


    } else {
        billingform.billto_email.style.borderColor = ""
    }

    if(trimString(billto_email).length > 0)
    {

        if(isValidEmail(billto_email)!= true)
        {
            errcount ++;
            errmsg += "<div class=\"er-msg\">Improper Emailaddress  </div>";
        }
    }
    else
    {
        billingform.billto_email.style.borderColor = ""
    }

    if(trimString(billto_address1).length == 0) {
        errcount ++
        errmsg += "<div class=\"er-msg\">Address 1 is missing</div>"
    //billingform.billto_address1.style.borderColor = "#ff0000"
    } else {
        billingform.billto_address1.style.borderColor = ""
    }

    if(trimString(billto_city).length == 0) {
        errcount ++
        errmsg += "<div class=\"er-msg\">City is missing</div>"

    } else {
        billingform.billto_city.style.borderColor = ""
    }
    //    if(trimString(billto_city).length > 0) {
    //        if(!fnIsNumeric2(billto_city))
    //        {
    //            errcount ++
    //            errmsg += "<div class=\"er-msg\">Enter only character</div>"
    //        }
    //    }
    //    else {
    //        billingform.billto_city.style.borderColor = ""
    //    }
    if(trimString(billto_zipcode).length == 0) {
        errcount ++
        errmsg += "<div class=\"er-msg\">Zipcode is missing</div>"
    //billingform.billto_address1.style.borderColor = "#ff0000"
    } else {
        billingform.billto_zipcode.style.borderColor = ""
    }

    if(trimString(billto_phone).length == 0) {
        errcount ++
        errmsg += "<div class=\"er-msg\">Phone is missing</div>"

    //billingform.billto_address1.style.borderColor = "#ff0000"
    } else {
        //        if(!isNumber(billto_phone))
        //           {
        //                 errcount ++
        //               errmsg += "<div class=\"er-msg\">Please enter the valid phone number</div>"
        //           }
        billingform.billto_phone.style.borderColor = ""
    }


    //    if(trimString(billto_areacode).length == 0) {
    //        errcount ++
    //        errmsg += "<div class=\"er-msg\">Area Code is missing</div>"
    //
    //    } else {
    //        billingform.billto_areacode.style.borderColor = ""
    //    }

    if(document.getElementById("billto_state_name").style.display == "") {
        if(trimString(billto_state_name).length == 0) {
            errcount ++
            errmsg += "<div class=\"er-msg\">State is missing</div>"
        //billingform.billto_address1.style.borderColor = "#ff0000"
        } else {
            billingform.billto_phone.style.borderColor = ""
        }
    } else {

    }


    if(errcount > 0) {
        errmsg = "<div class=\"tit\">Below Error(s) prevent your checkout</div>"+errmsg
        document.getElementById("checkout-step-billing-err").innerHTML = errmsg
        document.getElementById("checkout-step-billing-err").style.display = ""

        return false;
    } else {
        document.getElementById("checkout-step-billing-err").style.display = "none"
    }








    var billto_shipto_option;

    //    for(var l=0; l<billingform.use_for_shipping.length; l++) {
    //        if(billingform.use_for_shipping[l].checked == true) {
    //            billto_shipto_option = billingform.use_for_shipping[l].value
    //        }
    //    }

    // POST Request
    //var url = "/checkout/savebilling";
    var url = "/checkout/savebilling";
    var params = "billto_firstname="+billto_firstname+"&billto_lastname="+billto_lastname+"&billto_company="+billto_company+"&billto_email="+billto_email+"&billto_address1="+billto_address1+"&billto_address2="+billto_address2+"&billto_city="+billto_city+"&billto_state="+billto_state+"&billto_state_name="+billto_state_name+"&billto_zipcode="+billto_zipcode+"&billto_country="+billto_country+"&billto_phone="+billto_phone+"&billto_fax="+billto_fax+"";
    //alert (params)
    xmlHttp.open("POST", url, true);
    xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    xmlHttp.setRequestHeader("Content-length", params.length);
    xmlHttp.setRequestHeader("Connection", "close");
    xmlHttp.setRequestHeader("If-Modified-Since", "Thu, 1 Jan 1970 00:00:00 GMT");
    xmlHttp.setRequestHeader("Cache-Control", "no-cache");

    xmlHttp.onreadystatechange = function() {//Call a function when the state changes.
        // alert (xmlHttp.status);
        if(xmlHttp.readyState == 4 && xmlHttp.status==200) {
            //alert("response xml is \n" + xmlHttp.responseText);
            var response = xmlHttp.responseXML;
            var result = response.documentElement.getElementsByTagName("result")[0].childNodes[0].nodeValue;

            var ret_billto_state = ""
            var ret_billto_state_name = ""
            var ret_billto_country = ""
            if(response.documentElement.getElementsByTagName("ret-billto-state")[0].childNodes[0]!=undefined) {
                ret_billto_state = response.documentElement.getElementsByTagName("ret-billto-state")[0].childNodes[0].nodeValue;
            }
            if(response.documentElement.getElementsByTagName("ret-billto-state-name")[0].childNodes[0]!=undefined) {
                ret_billto_state_name = response.documentElement.getElementsByTagName("ret-billto-state-name")[0].childNodes[0].nodeValue;
            }
            if(response.documentElement.getElementsByTagName("ret-billto-country")[0].childNodes[0]!=undefined) {
                ret_billto_country = response.documentElement.getElementsByTagName("ret-billto-country")[0].childNodes[0].nodeValue;
            }


            if(result == "true") {
                // alert("start shipping")
                document.getElementById("edit_billing_content").innerHTML = "<address>"+billto_firstname+" " +billto_lastname +"<br/>"+billto_email+"<br/>"+billto_address1+"<br/>"+billto_city+"<br/>"+ret_billto_state + ret_billto_state_name +"<br/>"+ret_billto_country+"<br/>"+billto_phone+"</address>";
                document.getElementById("a-billing-info").style.display = "";
                document.getElementById("edit_billing_content").style.display="";
                //checkout_shipping_step();
                checkout_shipping_method_step();
            }
        }
    }
    // alert("after shippingmethodcall");
    xmlHttp.send(params);

}

function checkout_shipping_step() {
    createXmlHttpRequest();

    var url = "/checkout/plantwo_checkout_step_shipping";
    var params = "";
    //alert(url)
    xmlHttp.open("POST", url, true);
    xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    xmlHttp.setRequestHeader("Content-length", params.length);
    xmlHttp.setRequestHeader("Connection", "close");
    xmlHttp.setRequestHeader("If-Modified-Since", "Thu, 1 Jan 1970 00:00:00 GMT");
    xmlHttp.setRequestHeader("Cache-Control", "no-cache");

    xmlHttp.onreadystatechange = function() {//Call a function when the state changes.
        if(xmlHttp.readyState == 4 && xmlHttp.status==200) {
            //document.getElementById("billing-info").style.display = "none";
            //alert("load ship " + xmlHttp.responseText)
            step = 2;
            document.getElementById("billing-info").innerHTML="<a href=\"javascript:showstep('billing-info');\"> <div class=\"head\" onclick=\"\"><h3><span class=\"step-count\">1</span> &nbsp;Billing Information</h3></div></a>"
            document.getElementById("shipping-info").innerHTML = xmlHttp.responseText;
            document.getElementById("shipping-info").style.display = "";
            hideothers("shipping-info")
        }
    }
    xmlHttp.send(params);

}

function shipping_save() {

    createXmlHttpRequest();
    var shippingform = document.co_shipping_form;
    var shipto_firstname = shippingform.shipto_first_name.value;
    var shipto_lastname = shippingform.shipto_last_name.value;
    var shipto_company = shippingform.shipto_company_name.value;
    var shipto_email = shippingform.shipto_email.value;
    var shipto_address1 = shippingform.shipto_address1.value;
    var shipto_address2 = shippingform.shipto_address2.value;
    var shipto_city = shippingform.shipto_city.value;
    var shipto_state = shippingform.shipto_state.value;
    var shipto_state_name = shippingform.shipto_state_name.value;
    var shipto_zipcode = shippingform.shipto_zip_code.value;
    var shipto_country = shippingform.shipto_country.value;
    //var shipto_areacode = shippingform.shipto_areacode.value;
    var shipto_phone = shippingform.shipto_phone.value;
    var shipto_fax = shippingform.shipto_fax.value;


    // Validating form fields
    errcount = 0
    errmsg = ""
    if(trimString(shipto_firstname).length == 0) {
        errcount ++
        errmsg += "<div class=\"er-msg\">First name is missing</div>"
    //billingform.billto_firstname.style.borderColor = "#ff0000"
    } else {
        shippingform.shipto_first_name.style.borderColor = ""
    }

    if(trimString(shipto_lastname).length == 0) {
        errcount ++
        errmsg += "<div class=\"er-msg\">Last name is missing</div>"

    } else {
        shippingform.shipto_last_name.style.borderColor = ""
    }

    if(trimString(shipto_email).length == 0) {
        errcount ++;
        errmsg += "<div class=\"er-msg\">Email is missing</div>";
    //billingform.billto_email.style.className = "checkout-error";


    } else {
        shippingform.shipto_email.style.borderColor = ""
    }

    if(trimString(shipto_email).length > 0)
    {
        //alert('inside trimstring')
        if(isValidEmail(shipto_email)!= true)
        {
            errcount ++;
            errmsg += "<div class=\"er-msg\">Improper Emailaddress  </div>";
        }
    }
    else
    {
        shippingform.shipto_email.style.borderColor = ""
    }
    if(trimString(shipto_address1).length == 0) {
        errcount ++
        errmsg += "<div class=\"er-msg\">Address 1 is missing</div>"
    //billingform.billto_address1.style.borderColor = "#ff0000"
    } else {
        shippingform.shipto_address1.style.borderColor = ""
    }

    if(trimString(shipto_city).length == 0) {
        errcount ++
        errmsg += "<div class=\"er-msg\">City is missing</div>"

    } else {
        shippingform.shipto_city.style.borderColor = ""
    }
    //    if(trimString(shipto_city).length > 0) {
    //        if(!fnIsNumeric2(shipto_city))
    //        {
    //            errcount ++
    //            errmsg += "<div class=\"er-msg\">Enter only character</div>"
    //        }
    //    }
    //    else {
    //        shippingform.shipto_city.style.borderColor = ""
    //    }
    if(trimString(shipto_zipcode).length == 0) {
        errcount ++
        errmsg += "<div class=\"er-msg\">Zipcode is missing</div>"
    //billingform.billto_address1.style.borderColor = "#ff0000"
    } else {
        shippingform.shipto_zip_code.style.borderColor = ""
    }

    //    if(trimString(shipto_areacode).length == 0) {
    //        errcount ++
    //        errmsg += "<div class=\"er-msg\">Area Code is missing</div>"
    //
    //    } else {
    //        shippingform.shipto_areacode.style.borderColor = ""
    //    }

    if(trimString(shipto_phone).length == 0) {
        errcount ++
        errmsg += "<div class=\"er-msg\">Phone is missing</div>"
    //billingform.billto_address1.style.borderColor = "#ff0000"
    } else {
        //        if(!isNumber(shipto_phone))
        //           {
        //                 errcount ++
        //               errmsg += "<div class=\"er-msg\">Please enter the valid phone number</div>"
        //           }
        shippingform.shipto_phone.style.borderColor = ""
    }

    if(document.getElementById("shipto_state_name").style.display == "") {
        if(trimString(shipto_state_name).length == 0) {
            errcount ++
            errmsg += "<div class=\"er-msg\">State is missing</div>"
        //billingform.billto_address1.style.borderColor = "#ff0000"
        } else {
            shippingform.shipto_phone.style.borderColor = ""
        }
    } else {

    }


    if(errcount > 0) {
        errmsg = "<div class=\"tit\">Below Error(s) prevent your checkout</div>"+errmsg
        document.getElementById("checkout-step-shipping-err").innerHTML = errmsg
        document.getElementById("checkout-step-shipping-err").style.display = ""

        return false;
    } else {
        document.getElementById("checkout-step-shipping-err").style.display = "none"
    }

    // POST Request
    //var url = "/checkout/savebilling";
    var url = "/checkout/saveshipping";
    var params = "shipto_firstname="+shipto_firstname+"&shipto_lastname="+shipto_lastname+"&shipto_company="+shipto_company+"&shipto_email="+shipto_email+"&shipto_address1="+shipto_address1+"&shipto_address2="+shipto_address2+"&shipto_city="+shipto_city+"&shipto_state="+shipto_state+"&shipto_state_name="+shipto_state_name+"&shipto_zipcode="+shipto_zipcode+"&shipto_country="+shipto_country+"&shipto_phone="+shipto_phone+"&shipto_fax="+shipto_fax+"";
    //alert (params)
    xmlHttp.open("POST", url, true);
    xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    xmlHttp.setRequestHeader("Content-length", params.length);
    xmlHttp.setRequestHeader("Connection", "close");
    xmlHttp.setRequestHeader("If-Modified-Since", "Thu, 1 Jan 1970 00:00:00 GMT");
    xmlHttp.setRequestHeader("Cache-Control", "no-cache");

    xmlHttp.onreadystatechange = function() {//Call a function when the state changes.
        //alert(xmlHttp.status)
        if(xmlHttp.readyState == 4 && xmlHttp.status==200) {
            var response = xmlHttp.responseXML;
            var result = xmlHttp.responseXML.documentElement.getElementsByTagName("result")[0].childNodes[0].nodeValue
            //alert("Result " + result)
            var ret_shipto_state = ""
            var ret_shipto_state_name = ""
            var ret_shipto_country = ""
            if(response.documentElement.getElementsByTagName("ret-shipto-state")[0].childNodes[0]!=undefined) {
                ret_shipto_state = response.documentElement.getElementsByTagName("ret-shipto-state")[0].childNodes[0].nodeValue;
            }
            if(response.documentElement.getElementsByTagName("ret-shipto-state-name")[0].childNodes[0]!=undefined) {
                ret_shipto_state_name = response.documentElement.getElementsByTagName("ret-shipto-state-name")[0].childNodes[0].nodeValue;
            }
            if(response.documentElement.getElementsByTagName("ret-shipto-country")[0].childNodes[0]!=undefined) {
                ret_shipto_country = response.documentElement.getElementsByTagName("ret-shipto-country")[0].childNodes[0].nodeValue;
            }
            if(result == "true") {
                //alert("start shipping method");
                document.getElementById("edit_shipping_content").innerHTML = "<address>"+shipto_firstname+" " +shipto_lastname +"<br/>"+shipto_email+"<br/>"+shipto_address1+"<br/>"+shipto_city+"<br/>"+ret_shipto_state+ret_shipto_state_name+"<br/>"+ret_shipto_country+"<br/>"+shipto_phone+"</address>";
                document.getElementById("edit_shipping_content").style.display="";
                document.getElementById("a-shipping-info").style.display = "";
                checkout_shipping_method_step();

            }
        }
    }
    xmlHttp.send(params);
}

function shipping_save_ls(optionvalue) {

    createXmlHttpRequest();
    var shippingform = document.co_shipping_form;
    var shipto_firstname = shippingform.shipto_first_name.value;
    var shipto_lastname = shippingform.shipto_last_name.value;
    var shipto_company = shippingform.shipto_company_name.value;
    var shipto_email = shippingform.shipto_email.value;
    var shipto_address1 = shippingform.shipto_address1.value;
    var shipto_address2 = shippingform.shipto_address2.value;
    var shipto_city = shippingform.shipto_city.value;
    var shipto_state = shippingform.shipto_state.value;
    var shipto_state_name = shippingform.shipto_state_name.value;
    var shipto_zipcode = shippingform.shipto_zip_code.value;
    var shipto_country = shippingform.shipto_country.value;
    // var shipto_areacode = shippingform.shipto_areacode.value;
    var shipto_phone = shippingform.shipto_phone.value;
    var shipto_fax = shippingform.shipto_fax.value;


    // Validating form fields
    errcount = 0
    errmsg = ""
    if(trimString(shipto_firstname).length == 0) {
        errcount ++
        errmsg += "<div class=\"er-msg\">First name is missing</div>"
    //billingform.billto_firstname.style.borderColor = "#ff0000"
    } else {
        shippingform.shipto_first_name.style.borderColor = ""
    }

    if(trimString(shipto_lastname).length == 0) {
        errcount ++
        errmsg += "<div class=\"er-msg\">Last name is missing</div>"

    } else {
        shippingform.shipto_last_name.style.borderColor = ""
    }

    if(trimString(shipto_email).length == 0) {
        errcount ++;
        errmsg += "<div class=\"er-msg\">Email is missing</div>";
    //billingform.billto_email.style.className = "checkout-error";


    } else {
        shippingform.shipto_email.style.borderColor = ""
    }

    if(trimString(shipto_email).length > 0)
    {
        //alert('inside trimstring')
        if(isValidEmail(shipto_email)!= true)
        {
            errcount ++;
            errmsg += "<div class=\"er-msg\">Improper Emailaddress  </div>";
        }
    }
    else
    {
        shippingform.shipto_email.style.borderColor = ""
    }
    if(trimString(shipto_address1).length == 0) {
        errcount ++
        errmsg += "<div class=\"er-msg\">Address 1 is missing</div>"
    //billingform.billto_address1.style.borderColor = "#ff0000"
    } else {
        shippingform.shipto_address1.style.borderColor = ""
    }

    if(trimString(shipto_city).length == 0) {
        errcount ++
        errmsg += "<div class=\"er-msg\">City is missing</div>"

    } else {
        shippingform.shipto_city.style.borderColor = ""
    }
    //    if(trimString(shipto_city).length > 0) {
    //        if(!fnIsNumeric2(shipto_city))
    //        {
    //            errcount ++
    //            errmsg += "<div class=\"er-msg\">Enter only character</div>"
    //        }
    //    }
    //    else {
    //        shippingform.shipto_city.style.borderColor = ""
    //    }
    if(trimString(shipto_zipcode).length == 0) {
        errcount ++
        errmsg += "<div class=\"er-msg\">Zipcode is missing</div>"
    //billingform.billto_address1.style.borderColor = "#ff0000"
    } else {
        shippingform.shipto_zip_code.style.borderColor = ""
    }

    //    if(trimString(shipto_areacode).length == 0) {
    //        errcount ++
    //        errmsg += "<div class=\"er-msg\">Area Code is missing</div>"
    //
    //    } else {
    //        shippingform.shipto_areacode.style.borderColor = ""
    //    }

    if(trimString(shipto_phone).length == 0) {
        errcount ++
        errmsg += "<div class=\"er-msg\">Phone is missing</div>"
    //billingform.billto_address1.style.borderColor = "#ff0000"
    } else {
        //         if(!isNumber(shipto_phone))
        //           {
        //                 errcount ++
        //               errmsg += "<div class=\"er-msg\">Please enter the valid phone number</div>"
        //           }
        shippingform.shipto_phone.style.borderColor = ""
    }

    if(document.getElementById("shipto_state_name").style.display == "") {
        if(trimString(shipto_state_name).length == 0) {
            errcount ++
            errmsg += "<div class=\"er-msg\">State is missing</div>"
        //billingform.billto_address1.style.borderColor = "#ff0000"
        } else {
            shippingform.shipto_phone.style.borderColor = ""
        }
    } else {

    }


    if(errcount > 0) {
        errmsg = "<div class=\"tit\">Below Error(s) prevent your checkout</div>"+errmsg
        document.getElementById("checkout-step-shipping-err").innerHTML = errmsg
        document.getElementById("checkout-step-shipping-err").style.display = ""
        document.getElementById("shipping-errpick").style.display = "none"

        return false;
    } else {
        document.getElementById("checkout-step-shipping-err").style.display = "none"
        document.getElementById("shipping-errpick").style.display = "none"
    }

    // POST Request
    //var url = "/checkout/savebilling";
    var url = "/checkout/saveshipping";
    var params = "shipto_firstname="+shipto_firstname+"&shipto_lastname="+shipto_lastname+"&shipto_company="+shipto_company+"&shipto_email="+shipto_email+"&shipto_address1="+shipto_address1+"&shipto_address2="+shipto_address2+"&shipto_city="+shipto_city+"&shipto_state="+shipto_state+"&shipto_state_name="+shipto_state_name+"&shipto_zipcode="+shipto_zipcode+"&shipto_country="+shipto_country+"&shipto_phone="+shipto_phone+"&shipto_fax="+shipto_fax+"&shippoption="+optionvalue;
    // alert (params);
    xmlHttp.open("POST", url, true);
    xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    xmlHttp.setRequestHeader("Content-length", params.length);
    xmlHttp.setRequestHeader("Connection", "close");
    xmlHttp.setRequestHeader("If-Modified-Since", "Thu, 1 Jan 1970 00:00:00 GMT");
    xmlHttp.setRequestHeader("Cache-Control", "no-cache");

    xmlHttp.onreadystatechange = function() {//Call a function when the state changes.
        //alert(xmlHttp.status)
        if(xmlHttp.readyState == 4 && xmlHttp.status==200) {
            var response = xmlHttp.responseXML;
            var result = xmlHttp.responseXML.documentElement.getElementsByTagName("result")[0].childNodes[0].nodeValue
            //alert("Result " + result)
            var ret_shipto_state = ""
            var ret_shipto_state_name = ""
            var ret_shipto_country = ""
            if(response.documentElement.getElementsByTagName("ret-shipto-state")[0].childNodes[0]!=undefined) {
                ret_shipto_state = response.documentElement.getElementsByTagName("ret-shipto-state")[0].childNodes[0].nodeValue;
            }
            if(response.documentElement.getElementsByTagName("ret-shipto-state-name")[0].childNodes[0]!=undefined) {
                ret_shipto_state_name = response.documentElement.getElementsByTagName("ret-shipto-state-name")[0].childNodes[0].nodeValue;
            }
            if(response.documentElement.getElementsByTagName("ret-shipto-country")[0].childNodes[0]!=undefined) {
                ret_shipto_country = response.documentElement.getElementsByTagName("ret-shipto-country")[0].childNodes[0].nodeValue;
            }
            if(result == "true") {
                //alert("start shipping method");
                document.getElementById("edit_shipping_method_content").innerHTML = "<address>"+shipto_firstname+" " +shipto_lastname +"<br/>"+shipto_email+"<br/>"+shipto_address1+"<br/>"+shipto_city+"<br/>"+ret_shipto_state+ret_shipto_state_name+"<br/>"+ret_shipto_country+"<br/>"+shipto_phone+"</address>";
                document.getElementById("edit_shipping_method_content").style.display="";
                document.getElementById("a-shipping-info").style.display = "";
                checkout_payment_method_step();

            }
        }
    }

    xmlHttp.send(params);
}





function checkout_shipping_method_step() {
    createXmlHttpRequest();
    var url = "/checkout/plantwo_shipping_method_ls";
    var params = "";
    //alert(url)
    xmlHttp.open("POST", url, true);
    xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    xmlHttp.setRequestHeader("Content-length", params.length);
    xmlHttp.setRequestHeader("Connection", "close");
    xmlHttp.setRequestHeader("If-Modified-Since", "Thu, 1 Jan 1970 00:00:00 GMT");
    xmlHttp.setRequestHeader("Cache-Control", "no-cache");

    xmlHttp.onreadystatechange = function() {//Call a function when the state changes.
        if(xmlHttp.readyState == 4 && xmlHttp.status==200) {

            step = 3;

            document.getElementById("shipping-info").innerHTML="<a href=\"javascript:showstep('shipping-info');\"> <div class=\"head\"><h3><span class=\"step-count\">2</span> &nbsp;Shipping Information</h3></div></a>"
            //document.getElementById("shipping-info").style.display="inline"
            document.getElementById("opc-shipping_method").innerHTML = xmlHttp.responseText;
            document.getElementById("opc-shipping_method").style.display = "";
            hideothers("opc-shipping_method")
        }
    }
    xmlHttp.send(params);
}

checkout_steps = new Array("billing-info", "shipping-info", "opc-shipping_method", "opc-payment");
function showstep(id) {
    var k = 0;

    //for(var j = 0; j<checkout_steps.length; j++) {
    if(id == "billing-info") {
        //alert("loading checkout billing step" );
        checkout_billing_step();
    }
    //    else if (id == "shipping-info") {
    //        checkout_shipping_step();
    //    }
    else if (id == "opc-shipping_method") {
        checkout_shipping_method_step();
    }
//}



//alert(id)


}

function hideothers(id) {

    for(var i = 0; i<checkout_steps.length; i++) {

        if(id==checkout_steps[i]) {



        } else {


            switch(step) {
                case 1:
                    //                    if(checkout_steps[i] == "shipping-info") {
                    //                        document.getElementById(checkout_steps[i]).innerHTML="<a href=\"#\" onclick=\"return false;\" class=\"empty\"> <div class=\"head\"><h3><span class=\"step-count\">2</span> &nbsp;Shipping Information</h3></div></a>";
                    //                    }

                    if(checkout_steps[i] == "opc-shipping_method") {
                        document.getElementById(checkout_steps[i]).innerHTML="<a href=\"#\" onclick=\"return false;\" class=\"empty\"><div class=\"head\" ><h3><span class=\"step-count\">2</span> &nbsp;Shipping Method</h3></div></a>";
                    }

                    if(checkout_steps[i] == "opc-payment") {
                        document.getElementById(checkout_steps[i]).innerHTML="<a href=\"#\" onclick=\"return false;\" class=\"empty\"><div class=\"head\"><h3><span class=\"step-count\">3</span> &nbsp;Payment Information</h3></div></a>";
                    }
                    break;
                case 2:
                    if(checkout_steps[i] == "billing-info") {
                        document.getElementById(checkout_steps[i]).innerHTML="<a href=\"javascript:showstep('billing-info');\"> <div class=\"head\" onclick=\"\"><h3><span class=\"step-count\">1</span> &nbsp;Billing Information</h3></div></a>";
                    }
                    if(checkout_steps[i] == "opc-shipping_method") {
                        document.getElementById(checkout_steps[i]).innerHTML="<a href=\"#\" class=\"empty\" onclick=\"return false;\"><div class=\"head\" ><h3><span class=\"step-count\">2</span> &nbsp;Shipping Method</h3></div></a>";
                    }

                    if(checkout_steps[i] == "opc-payment") {
                        document.getElementById(checkout_steps[i]).innerHTML="<a href=\"#\" class=\"empty\" onclick=\"return false;\"><div class=\"head\"><h3><span class=\"step-count\">3</span> &nbsp;Payment Information</h3></div></a>";
                    }
                    break;
                case 3:
                    if(checkout_steps[i] == "billing-info") {
                        document.getElementById(checkout_steps[i]).innerHTML="<a href=\"javascript:showstep('billing-info');\"> <div class=\"head\" onclick=\"\"><h3><span class=\"step-count\">1</span> &nbsp;Billing Information</h3></div></a>";
                    }
                    //                    if(checkout_steps[i] == "shipping-info") {
                    //                        document.getElementById(checkout_steps[i]).innerHTML="<a href=\"javascript:showstep('shipping-info');\"> <div class=\"head\"><h3><span class=\"step-count\">2</span> &nbsp;Shipping Information</h3></div></a>";
                    //                    }
                    if(checkout_steps[i] == "opc-payment") {
                        document.getElementById(checkout_steps[i]).innerHTML="<a href=\"#\" class=\"empty\" onclick=\"return false;\"><div class=\"head\"><h3><span class=\"step-count\">3</span> &nbsp;Payment Information</h3></div></a>";
                    }
                    break;
                case 4:
                    if(checkout_steps[i] == "billing-info") {
                        document.getElementById(checkout_steps[i]).innerHTML="<a href=\"javascript:showstep('billing-info');\"> <div class=\"head\" onclick=\"\"><h3><span class=\"step-count\">1</span> &nbsp;Billing Information</h3></div></a>";
                    }
                    //                    if(checkout_steps[i] == "shipping-info") {
                    //                        document.getElementById(checkout_steps[i]).innerHTML="<a href=\"javascript:showstep('shipping-info');\"> <div class=\"head\"><h3><span class=\"step-count\">2</span> &nbsp;Shipping Information</h3></div></a>";
                    //                    }
                    if(checkout_steps[i] == "opc-shipping_method") {
                        document.getElementById(checkout_steps[i]).innerHTML="<a href=\"javascript:showstep('opc-shipping_method');\"><div class=\"head\" ><h3><span class=\"step-count\">2</span> &nbsp;Shipping Method</h3></div></a>";
                    }
                    break;
                default:
                    if(checkout_steps[i] == "billing-info") {
                        document.getElementById(checkout_steps[i]).innerHTML="<a href=\"#\" class=\"empty\" onclick=\"return false;\"> <div class=\"head\" onclick=\"\"><h3><span class=\"step-count\">1</span> &nbsp;Billing Information</h3></div></a>";
                    }

                    //                    if(checkout_steps[i] == "shipping-info") {
                    //                        document.getElementById(checkout_steps[i]).innerHTML="<a href=\"#\" class=\"empty\" onclick=\"return false;\"> <div class=\"head\"><h3><span class=\"step-count\">2</span> &nbsp;Shipping Information</h3></div></a>";
                    //                    }

                    if(checkout_steps[i] == "opc-shipping_method") {
                        document.getElementById(checkout_steps[i]).innerHTML="<a href=\"#\" class=\"empty\" onclick=\"return false;\"><div class=\"head\" ><h3><span class=\"step-count\">2</span> &nbsp;Shipping Method</h3></div></a>";
                    }

                    if(checkout_steps[i] == "opc-payment") {
                        document.getElementById(checkout_steps[i]).innerHTML="<a href=\"#\" class=\"empty\" onclick=\"return false;\"><div class=\"head\"><h3><span class=\"step-count\">3</span> &nbsp;Payment Information</h3></div></a>";
                    }
            }


        }

    }
}

function getbillingstate(country) {
    createXmlHttpRequest();
    var url = "/checkout/getbillingstate";
    var params = "country=" + country;

    xmlHttp.open("POST", url, true);
    xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    xmlHttp.setRequestHeader("Content-length", params.length);
    xmlHttp.setRequestHeader("Connection", "close");
    xmlHttp.setRequestHeader("If-Modified-Since", "Thu, 1 Jan 1970 00:00:00 GMT");
    xmlHttp.setRequestHeader("Cache-Control", "no-cache");

    xmlHttp.onreadystatechange = function() {

        if(xmlHttp.readyState == 4 && xmlHttp.status==200) {

            result = xmlHttp.responseXML;

            var status = result.documentElement.getElementsByTagName("result")[0].childNodes[0].nodeValue;
            var states = result.documentElement.getElementsByTagName("states")[0].childNodes[0].nodeValue;

            var active_id = 0
            if(result.documentElement.getElementsByTagName("activeid")[0].childNodes[0] != undefined) {
                active_id = result.documentElement.getElementsByTagName("activeid")[0].childNodes[0].nodeValue;
            }

            var active_name = ""
            if(result.documentElement.getElementsByTagName("activename")[0].childNodes[0] != undefined) {
                active_name = result.documentElement.getElementsByTagName("activename")[0].childNodes[0].nodeValue;
            }

            var statenames = "";
            var statevalues = "";
            var statedefault = "";
            if(result.documentElement.getElementsByTagName("statenames")[0].childNodes[0] != undefined) {
                statenames = result.documentElement.getElementsByTagName("statenames")[0].childNodes[0].nodeValue;
            }
            if(result.documentElement.getElementsByTagName("statevalues")[0].childNodes[0] != undefined) {
                statevalues = result.documentElement.getElementsByTagName("statevalues")[0].childNodes[0].nodeValue;
            }
            if(result.documentElement.getElementsByTagName("statedefault")[0].childNodes[0] != undefined) {
                statedefault = result.documentElement.getElementsByTagName("statedefault")[0].childNodes[0].nodeValue;
            }


            if(status == "false") {
                document.getElementById("billto_state").style.display="none";
                document.getElementById("billto_state_name").value=active_name;
                document.getElementById("billto_state").value="";
                document.getElementById("billto_state_name").style.display="";
            } else if (status == "true") {
                document.getElementById("billto_state_name").style.display="none";
                document.getElementById("billto_state_name").value = "";
                var statearray = statenames.split(",")
                var valuesarray = statevalues.split(",")

                var option = null
                for(var s=0; s<valuesarray.length;s++) {
                    option = new Option(statearray[s],valuesarray[s])
                    if(statedefault == parseFloat(valuesarray[s])) {
                        option.selected = "1"
                    }
                    document.getElementById("billto_state").options[s] = option
                }
                document.getElementById("billto_state").style.display="";
            }
        }
    }
    xmlHttp.send(params);
}

function trimString(sInString) {
    if(sInString!=undefined) {
        sInString = sInString.replace( /^\s+/g, "" );// strip leading
        return sInString.replace( /\s+$/g, "" );// strip trailing
    }
    return ""
}


function getshippingstate(country) {
    createXmlHttpRequest();
    var url = "/checkout/getshippingstate";
    var params = "country=" + country;
    xmlHttp.open("POST", url, true);
    xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    xmlHttp.setRequestHeader("Content-length", params.length);
    xmlHttp.setRequestHeader("Connection", "close");
    xmlHttp.setRequestHeader("If-Modified-Since", "Thu, 1 Jan 1970 00:00:00 GMT");
    xmlHttp.setRequestHeader("Cache-Control", "no-cache");

    xmlHttp.onreadystatechange = function() {

        if(xmlHttp.readyState == 4 && xmlHttp.status==200) {

            result = xmlHttp.responseXML;
            var status = result.documentElement.getElementsByTagName("result")[0].childNodes[0].nodeValue;
            states = ""
            if(result.documentElement.getElementsByTagName("states")[0].childNodes[0]!=undefined) {
                states = result.documentElement.getElementsByTagName("states")[0].childNodes[0].nodeValue;
            }

            active_id = 0
            if(result.documentElement.getElementsByTagName("activeid")[0].childNodes[0] != undefined) {
                active_id = result.documentElement.getElementsByTagName("activeid")[0].childNodes[0].nodeValue;
            }

            active_name = ""
            if(result.documentElement.getElementsByTagName("activename")[0].childNodes[0] != undefined) {
                active_name = result.documentElement.getElementsByTagName("activename")[0].childNodes[0].nodeValue;
            }

            var statenames = "";
            var statevalues = "";
            var statedefault = "";
            if(result.documentElement.getElementsByTagName("statenames")[0].childNodes[0] != undefined) {
                statenames = result.documentElement.getElementsByTagName("statenames")[0].childNodes[0].nodeValue;
            }
            if(result.documentElement.getElementsByTagName("statevalues")[0].childNodes[0] != undefined) {
                statevalues = result.documentElement.getElementsByTagName("statevalues")[0].childNodes[0].nodeValue;
            }
            if(result.documentElement.getElementsByTagName("statedefault")[0].childNodes[0] != undefined) {
                statedefault = result.documentElement.getElementsByTagName("statedefault")[0].childNodes[0].nodeValue;
            }



            if(status == "false") {
                document.getElementById("shipto_state").style.display="none";
                document.getElementById("shipto_state_name").value=active_name;
                document.getElementById("shipto_state_name").style.display="";
                document.getElementById("shipto_state").value = "";

            } else if (status == "true") {
                document.getElementById("shipto_state_name").style.display="none";
                document.getElementById("shipto_state_name").value=""
                var statearray = statenames.split(",")
                var valuesarray = statevalues.split(",")

                var option = null
                for(var s=0; s<valuesarray.length;s++) {
                    option = new Option(statearray[s],valuesarray[s])
                    if(statedefault == parseFloat(valuesarray[s])) {
                        option.selected = "1"
                    }
                    document.getElementById("shipto_state").options[s] = option
                }
                document.getElementById("shipto_state").style.display="";
            }

        }
    }
    xmlHttp.send(params);
}

function shipping_method_save() {
    //alert(1);
    createXmlHttpRequest();
    var shippingmethodform = document.co_shipping_method_form;
    var shipping_method_id = shippingmethodform.shipping_method_id.value;
    //alert(2);

    // POST Request

    var url = "/checkout/saveshippingmethod";
    var params = "shipping_method_id="+shipping_method_id;

    xmlHttp.open("POST", url, true);
    xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    xmlHttp.setRequestHeader("Content-length", params.length);
    xmlHttp.setRequestHeader("Connection", "close");
    xmlHttp.setRequestHeader("If-Modified-Since", "Thu, 1 Jan 1970 00:00:00 GMT");
    xmlHttp.setRequestHeader("Cache-Control", "no-cache");
    //alert(3);
    xmlHttp.onreadystatechange = function() {//Call a function when the state changes.
        //alert(4);
        if(xmlHttp.readyState == 4 && xmlHttp.status==200) {//alert(5);
            var response = xmlHttp.responseXML;
            var result = xmlHttp.responseXML.documentElement.getElementsByTagName("result")[0].childNodes[0].nodeValue

            var shipping_total = ""
            var tax_total = ""
            var grand_total = ""
            var mini_cart = ""
            var shipping_method = ""
            if(response.documentElement.getElementsByTagName("shipping-total")[0].childNodes[0]!=undefined) {
                shipping_total = response.documentElement.getElementsByTagName("shipping-total")[0].childNodes[0].nodeValue;
            }
            if(response.documentElement.getElementsByTagName("tax-total")[0].childNodes[0]!=undefined) {
                tax_total = response.documentElement.getElementsByTagName("tax-total")[0].childNodes[0].nodeValue;
            }
            if(response.documentElement.getElementsByTagName("grand-total")[0].childNodes[0]!=undefined) {
                grand_total = response.documentElement.getElementsByTagName("grand-total")[0].childNodes[0].nodeValue;
            }
            if(response.documentElement.getElementsByTagName("mini-cart")[0].childNodes[0]!=undefined) {
                mini_cart = response.documentElement.getElementsByTagName("mini-cart")[0].childNodes[0].nodeValue;
            }
            if(response.documentElement.getElementsByTagName("shipping-method")[0].childNodes[0]!=undefined) {
                shipping_method = response.documentElement.getElementsByTagName("shipping-method")[0].childNodes[0].nodeValue;
            }

            if(result == "true") {
                document.getElementById("minicart").innerHTML = mini_cart;
                document.getElementById("edit_shipping_method_content").innerHTML = "<address>"+shipping_method+" - $" +shipping_total+"</address>";
                document.getElementById("edit_shipping_method_content").style.display="";
                document.getElementById("a-opc-shipping_method").style.display = "";
                checkout_payment_method_step();
            }
        }
    }
    xmlHttp.send(params);
}
function shipping_method_save_ls(optionvalue) {

    createXmlHttpRequest();

    var shippingmethodform = document.co_shipping_method_form;
    var pickup_cond;
    var pickup_time = shippingmethodform.pickup_time.value;
    var notify_method = shippingmethodform.notify_method.value;

    errcount = 0
    errmsg = ""

    fl = 0;
    for(var i=0; i<shippingmethodform.pickup_cond.length; i++) {
        if(shippingmethodform.pickup_cond[i].checked) {
            fl = 1;
            break;
        }
    }
    //    if(fl == 0) {
    //        errcount ++;
    //        errmsg += "<div class=\"er-msg\">Please select the option</div>";
    //    } else {
    //    //shippingmethodform.pickup_cond.style.borderColor = "";
    //    }

    if(trimString(pickup_time).length == 0) {
        errcount ++
        errmsg += "<div class=\"er-msg\">Pickup time  is missing</div>"
    } else {
        shippingmethodform.pickup_time.style.borderColor = ""
    }



    if(errcount > 0) {
        errmsg = "<div class=\"tit\">Below Error(s) prevent your checkout</div>"+errmsg
        document.getElementById("shipping-errpick").innerHTML = errmsg
        document.getElementById("shipping-errpick").style.display = "block"
        document.getElementById("checkout-step-shipping-err").style.display = "none"

        return false;
    } else {
        document.getElementById("shipping-errpick").style.display = "none"
        document.getElementById("checkout-step-shipping-err").style.display = "none"
    }




    var cond = shippingmethodform.pickup_cond;
    for(var i=0; i<cond.length; i++) {
        if(shippingmethodform.pickup_cond[i].checked) {
            pickup_cond = shippingmethodform.pickup_cond[i].value;
        }
    }

    var notify = shippingmethodform.notify_method;
    for(var j=0; j<notify.length; j++) {
        if(shippingmethodform.notify_method[j].checked) {
            notify_method = shippingmethodform.notify_method[j].value;
        }
    }



    // POST Request

    var url = "/checkout/saveshippingmethod_ls";
    var params = "pickup_cond="+pickup_cond+"&pickup_time="+pickup_time+"&notify_method="+notify_method+"&shippoption="+optionvalue;
    //alert(params);
    xmlHttp.open("POST", url, true);
    xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    xmlHttp.setRequestHeader("Content-length", params.length);
    xmlHttp.setRequestHeader("Connection", "close");
    xmlHttp.setRequestHeader("If-Modified-Since", "Thu, 1 Jan 1970 00:00:00 GMT");
    xmlHttp.setRequestHeader("Cache-Control", "no-cache");


    xmlHttp.onreadystatechange = function() {//Call a function when the state changes.

        if(xmlHttp.readyState == 4 && xmlHttp.status==200) {

            var response = xmlHttp.responseXML;
            var result = xmlHttp.responseXML.documentElement.getElementsByTagName("result")[0].childNodes[0].nodeValue

            var shipping_total = ""
            var tax_total = ""
            var grand_total = ""
            var mini_cart = ""
            var shipping_method = ""
            if(response.documentElement.getElementsByTagName("shipping-total")[0].childNodes[0]!=undefined) {
                shipping_total = response.documentElement.getElementsByTagName("shipping-total")[0].childNodes[0].nodeValue;
            }
            if(response.documentElement.getElementsByTagName("tax-total")[0].childNodes[0]!=undefined) {
                tax_total = response.documentElement.getElementsByTagName("tax-total")[0].childNodes[0].nodeValue;
            }
            if(response.documentElement.getElementsByTagName("grand-total")[0].childNodes[0]!=undefined) {
                grand_total = response.documentElement.getElementsByTagName("grand-total")[0].childNodes[0].nodeValue;
            }
            if(response.documentElement.getElementsByTagName("mini-cart")[0].childNodes[0]!=undefined) {
                mini_cart = response.documentElement.getElementsByTagName("mini-cart")[0].childNodes[0].nodeValue;
            }
            if(response.documentElement.getElementsByTagName("shipping-method")[0].childNodes[0]!=undefined) {
                shipping_method = response.documentElement.getElementsByTagName("shipping-method")[0].childNodes[0].nodeValue;
            }

            if(result == "true") {
                document.getElementById("minicart").innerHTML = mini_cart;
                document.getElementById("edit_shipping_method_content").innerHTML = "<address>"+pickup_time+"</address>";
                document.getElementById("edit_shipping_method_content").style.display="";
                document.getElementById("a-opc-shipping_method").style.display = "";
                checkout_payment_method_step();
            }
        }
    }
    xmlHttp.send(params);
}



function checkout_payment_method_step() {
    //alert('inside checkout_payment')
    createXmlHttpRequest();
    var url = "/checkout/plantwo_payment_method";
    var params = "";

    xmlHttp.open("POST", url, true);
    xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    xmlHttp.setRequestHeader("Content-length", params.length);
    xmlHttp.setRequestHeader("Connection", "close");
    xmlHttp.setRequestHeader("If-Modified-Since", "Thu, 1 Jan 1970 00:00:00 GMT");
    xmlHttp.setRequestHeader("Cache-Control", "no-cache");

    xmlHttp.onreadystatechange = function() {

        if(xmlHttp.readyState == 4 && xmlHttp.status==200) {

            step = 4;

            document.getElementById("opc-shipping_method").innerHTML="<a href=\"javascript:showstep('opc-shipping_method');\"><div class=\"head\" ><h3><span class=\"step-count\">3</span> &nbsp;Shipping Method</h3></div></a>"
            //alert(xmlHttp.responseText);
            document.getElementById("opc-payment").innerHTML = xmlHttp.responseText;

            document.getElementById("opc-payment").style.display = "";
            hideothers("opc-payment")
        }
    }
    xmlHttp.send(params);
}
function checkout_payment_method_step1(msg) {
   
    createXmlHttpRequest();
    var errormsg=msg;

    var queryString="m="+errormsg;

    //actionUrl+="?"+queryString;
    var url = "/checkout/plantwo_payment_method";
    url+="?"+queryString
    // alert(url);
    var params = "";

    xmlHttp.open("POST", url, true);
    xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    xmlHttp.setRequestHeader("Content-length", params.length);
    xmlHttp.setRequestHeader("Connection", "close");
    xmlHttp.setRequestHeader("If-Modified-Since", "Thu, 1 Jan 1970 00:00:00 GMT");
    xmlHttp.setRequestHeader("Cache-Control", "no-cache");

    xmlHttp.onreadystatechange = function() {

        if(xmlHttp.readyState == 4 && xmlHttp.status==200) {

            step = 4;

            document.getElementById("opc-shipping_method").innerHTML="<a href=\"javascript:showstep('opc-shipping_method');\"><div class=\"head\" ><h3><span class=\"step-count\">3</span> &nbsp;Shipping Method</h3></div></a>"
            //alert(xmlHttp.responseText);
            document.getElementById("opc-payment").innerHTML = xmlHttp.responseText;
            document.getElementById("opc-payment").style.display = "";
            document.getElementById("checkout-button").style.display = "block";
            hideothers("opc-payment")
        }
    }
    xmlHttp.send(params);
}
function checktrans(paymenttypeId) {
  
    
    paymenttype=paymenttypeId
    var transform = document.co_payment_form
    // alert("transform"+document.co_payment_form);
    if(paymenttype==1)
    {
        return true;

    }



    else
    {
        cc_type = transform.cc_type.value
        cc_number = transform.cc_number.value
        cc_expiration_month = transform.cc_expiration_month.value
        cc_expiration_year = transform.cc_expiration_year.value
        cc_security_code = transform.cc_security_code.value

        errcount = 0
        errmsg = ""
        if(trimString(cc_number).length == 0) {
            errcount++;
            errmsg+= "Credit card number is required. "
        }
        if(trimString(cc_security_code).length == 0) {
            errcount++;
            errmsg+= "Security code is required."
        }

        if(errcount > 0) {
            alert(errmsg);
            document.getElementById('checkout-button').style.display = "block"
            return false;
        } else {
            document.getElementById('checkout-button').style.display = "none"
            document.getElementById('loading').style.display = "block"
            return true;
        }

    }
   

}

function dotrans() {
    createXmlHttpRequest();
    var transform = document.co_payment_form
    cc_type = transform.cc_type.value
    cc_number = transform.cc_number.value
    cc_expiration_month = transform.cc_expiration_month.value
    cc_expiration_year = transform.cc_expiration_year.value
    cc_security_code = transform.cc_security_code.value
    var url = "/checkout/dotrans";
    var params = "cc_type="+cc_type+"&cc_number="+cc_number+"&cc_expiration_month="+cc_expiration_month+"&cc_expiration_year="+cc_expiration_year+"&cc_security_code="+cc_security_code+"";

    xmlHttp.open("POST", url, true);
    xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    xmlHttp.setRequestHeader("Content-length", params.length);
    xmlHttp.setRequestHeader("Connection", "close");
    xmlHttp.setRequestHeader("If-Modified-Since", "Thu, 1 Jan 1970 00:00:00 GMT");
    xmlHttp.setRequestHeader("Cache-Control", "no-cache");

    xmlHttp.onreadystatechange = function() {

        if(xmlHttp.readyState == 4 && xmlHttp.status==200) {
            var response = xmlHttp.responseXML;
            var trans = response.documentElement.getElementsByTagName("trans")[0].childNodes[0].nodeValue
            var result = response.documentElement.getElementsByTagName("result")[0].childNodes[0].nodeValue
            // alert(result)
            if(trans == "true") {
                document.co_payment_form.submit();

            } else if(trans == "false") {
                alert(result);


            }

        }
    }
    xmlHttp.send(params);
}
// ================== plan 1 only ==========================

function getstateforcountry(country) {

    createXmlHttpRequest();
    var url = "/checkout/getstateforcountry";
    var params = "country=" + country;
    xmlHttp.open("POST", url, true);
    xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    xmlHttp.setRequestHeader("Content-length", params.length);
    xmlHttp.setRequestHeader("Connection", "close");
    xmlHttp.setRequestHeader("If-Modified-Since", "Thu, 1 Jan 1970 00:00:00 GMT");
    xmlHttp.setRequestHeader("Cache-Control", "no-cache");

    xmlHttp.onreadystatechange = function() {

        if(xmlHttp.readyState == 4 && xmlHttp.status==200) {

            result = xmlHttp.responseXML;
            var status = result.documentElement.getElementsByTagName("result")[0].childNodes[0].nodeValue;
            states = ""
            if(result.documentElement.getElementsByTagName("states")[0].childNodes[0]!=undefined) {
                states = result.documentElement.getElementsByTagName("states")[0].childNodes[0].nodeValue;
            }





            var statenames = "";
            var statevalues = "";
            var statedefault = "";
            if(result.documentElement.getElementsByTagName("statenames")[0].childNodes[0] != undefined) {
                statenames = result.documentElement.getElementsByTagName("statenames")[0].childNodes[0].nodeValue;
            }
            if(result.documentElement.getElementsByTagName("statevalues")[0].childNodes[0] != undefined) {
                statevalues = result.documentElement.getElementsByTagName("statevalues")[0].childNodes[0].nodeValue;
            }
            if(result.documentElement.getElementsByTagName("statedefault")[0].childNodes[0] != undefined) {
                statedefault = result.documentElement.getElementsByTagName("statedefault")[0].childNodes[0].nodeValue;
            }



            if(status == "false") {
                document.getElementById("state_id").style.display="none";

                document.getElementById("state_name").style.display="";
                document.getElementById("state_id").value = "";

            } else if (status == "true") {
                document.getElementById("state_name").style.display="none";
                document.getElementById("state_name").value=""
                var statearray = statenames.split(", ")
                var valuesarray = statevalues.split(", ")

                var option = null
                for(var s=0; s<valuesarray.length;s++) {
                    option = new Option(statearray[s],valuesarray[s])
                    if(statedefault == parseFloat(valuesarray[s])) {
                        option.selected = "1"
                    }
                    document.getElementById("state_id").options[s] = option
                }
                document.getElementById("state_id").style.display="";
            }

        }
    }
    xmlHttp.send(params);
}

function fnIsNumeric2(strString)
//  check for valid numeric strings
{
    // alert('inside fnisnue2')
    //alert(strString);
    var strValidChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz.";
    var strChar;
    var blnResult = true;

    if (strString.length == 0) return false;

    //  test strString consists of valid characters listed above
    for (i = 0; i < strString.length && blnResult == true; i++)
    {
        strChar = strString.charAt(i);

        if (strValidChars.indexOf(strChar) == -1)
        {

            blnResult = false;
        }
    }
    return blnResult;
}

function yesno()
{
    document.getElementById("yes").style.display="";
    document.getElementById("no").style.display="none";
}
function noyes()
{

    document.getElementById("yes").style.display="none";
    document.getElementById("no").style.display="";
}
function paymentcash()
{
    //alert('inside js');
    var stock=document.getElementById('cash').value;
    //alert(stock);
    if(stock==2)
    {
        fnShowDiv('creditcard');
    // fnHiddenDiv('brandOtherEmpty');
    // document.getElementById('otherbrandName').value="";
    }
    else
    {
        fnHiddenDiv('creditcard');
    }
}

function fnShowDiv(id)
{

    document.getElementById(id).style.display="block";
}

function fnHiddenDiv(id)
{
    document.getElementById(id).style.display="none";
}
function feedbackformvalidation(d,m,y)
{
    // alert('inside js')
    //    var femail="";
    //    var fitems="";
    var cday="";
    var cmonth="";
    var cyear="";
    var  fcusname="";
    var fphoneno="";
    var fcomments="";
    var fsuggestions="";
    var flocation="";
    var errorLength=0;
    femail=trimString(document.getElementById('email').value);
    fitems=trimString(document.getElementById('items').value);
    cday=document.getElementById('day');
    cmonth=document.getElementById('month');
    cyear=document.getElementById('year');
    fcusname=trimString(document.getElementById('cusname').value);
    fphoneno=trimString(document.getElementById('phoneno').value);
    fcomments=trimString(document.getElementById('comments').value);
    fsuggestions=trimString(document.getElementById('suggestions').value);
    flocation=trimString(document.getElementById('location').value);


    if(cday.value >d  || cmonth.value > m ||cyear.value  > y )
    {
        alert('selected date should not be greater than current date');
        errorLength++;
    }


    if(femail.length==0)
    {
        fnShowDiv('errorfemail');

        errorLength++;

    }
    else
    {
        fnHiddenDiv('errorfemail');

    }
    if(femail.length>0)
    {
        if(!isValidEmail(femail))
        {
            fnShowDiv('errorfinvalidemail');

            errorLength++;
        }
        else
        {
            fnHiddenDiv('errorfinvalidemail');
        }
    }
    //    //    if(fcusname.value!="" &   fcusname.value.length>0)
    //    //    {
    //    //        // alert('insidefi')
    //    //        fnHiddenDiv('errorfname');
    //    //    }
    //    //    else
    //    //    {
    //    //
    //    //        fnShowDiv('errorfname');
    //    //        if(errorLength==0)
    //    //            fname.focus();
    //    //        errorLength++;
    //    //    }
    if(fcusname.length==0)
    {

        fnShowDiv('errorfname');

        errorLength++;
    }
    else
    {
        fnHiddenDiv('errorfname');

    }
    if(fitems.length==0)
    {

        fnShowDiv('errorfitems');

        errorLength++;
    }
    else
    {
        fnHiddenDiv('errorfitems');

    }
    //
    ////    if(fcusname.length>0)
    ////    {
    ////
    ////
    ////        if (fnIsNumeric1(fcusname)==false)
    ////        {
    ////            fnShowDiv('numericfname');
    ////
    ////            errorLength++;
    ////
    ////        }
    ////        else
    ////        {
    ////            fnHiddenDiv('numericfname');
    ////
    ////        }
    ////    }
    ////    if(fitems.length>0)
    ////    {
    ////
    ////
    ////        if (fnIsNumeric1(fitems)==false)
    ////        {
    ////            fnShowDiv('numericfitems');
    ////
    ////            errorLength++;
    ////
    ////        }
    ////        else
    ////        {
    ////            fnHiddenDiv('numericfitems');
    ////
    ////        }
    ////    }
    if(fphoneno.length>0)
    {


        if(checkInternationalPhone(fphoneno)==false)
        {
            fnShowDiv('numericfphoneno');

            errorLength++;

        }
        else
        {
            fnHiddenDiv('numericfphoneno');

        }
    }
    //    if(fcomments.length>0)
    //    {
    //
    //
    //        if (fnIsNumeric1(fcomments)==false)
    //        {
    //            fnShowDiv('numericfcomments');
    //
    //            errorLength++;
    //
    //        }
    //        else
    //        {
    //            fnHiddenDiv('numericfcomments');
    //
    //        }
    //    }
    //    if(fsuggestions.length>0)
    //    {
    //
    //
    //        if (fnIsNumeric1(fsuggestions)==false)
    //        {
    //            fnShowDiv('numericfsuggestions');
    //
    //            errorLength++;
    //
    //        }
    //        else
    //        {
    //            fnHiddenDiv('numericfsuggestions');
    //
    //        }
    //    }


    //    if(flocation.length>0)
    //    {
    //
    //
    //        if (fnIsNumeric1(flocation)==false)
    //        {
    //            fnShowDiv('numericflocation');
    //
    //            errorLength++;
    //
    //        }
    //        else
    //        {
    //            fnHiddenDiv('numericflocation');
    //
    //        }
    //    }

    
    
    
    if (errorLength>0)
    {
        return false;
    }

    else
    {
        return true;
   



    }

}


function savevalidation()
{


    var Lfirstname="";
    var Llastname="";
    var Lemail="";
    var Laddress1="";
    var Lcity="";
    var Lcountry="";
    var Lzip="";
    var Lphone="";
    var Lusername="";
    var Lpassword="";
    var Lconfirmpassword="";
    var Lstate="";
    var errorLength=0;
    Lfirstname=document.getElementById('firstname');
    Llastname=document.getElementById('lastname');
    Lemail=document.getElementById('emailaddress');
    Laddress1=document.getElementById('address1');
    Lusername=document.getElementById('username');
    Lcity=document.getElementById('city');
    Lcountry=document.getElementById('country');
    Lzip=document.getElementById('postalcode');
    Lphone=document.getElementById('phone');
    Lpassword=document.getElementById('password');
    Lconfirmpassword=document.getElementById('confirmpassword');
    Lstate=document.getElementById('state');


    if(Lstate.value!="" &  Lstate.value.length>0)
    {

        fnHiddenDiv('errorLstate');
    }
    else
    {

        fnShowDiv('errorLstate');
        if(errorLength==0)
            Lstate.focus();
        errorLength++;
    }

    if(Lusername.value!="" &  Lusername.value.length>0)
    {

        fnHiddenDiv('errorLusername');
    }
    else
    {

        fnShowDiv('errorLusername');
        if(errorLength==0)
            Lusername.focus();
        errorLength++;
    }

    if(Lpassword.value!="" & Lpassword.value.length>0)
    {

        fnHiddenDiv('errorLpassword');
    }
    else
    {

        fnShowDiv('errorLpassword');
        if(errorLength==0)
            Llastname.focus();
        errorLength++;
    }
    if(Lpassword.value.length>0 && Lconfirmpassword.value.length>0)
    {
        if(Lpassword.value!=Lconfirmpassword.value)
        {
            fnShowDiv('errorinvalidpassword');
            if(errorLength==0)
                Lpassword.focus();
            errorLength++;
        }
        else
        {
            fnHiddenDiv('errorinvalidpassword');
        }
    }
    

    if(Lfirstname.value!="" & Lfirstname.value.length>0)
    {

        fnHiddenDiv('errorLfirstname');
    }
    else
    {

        fnShowDiv('errorLfirstname');
        if(errorLength==0)
            Lfirstname.focus();

        errorLength++;
    }
    if(Llastname.value!="" & Llastname.value.length>0)
    {

        fnHiddenDiv('errorLlastname');
    }
    else
    {

        fnShowDiv('errorLlastname');
        if(errorLength==0)
            Llastname.focus();
        errorLength++;
    }
    if(Laddress1.value!="" &   Laddress1.value.length>0)
    {

        fnHiddenDiv('errorLaddress1');
    }
    else
    {

        fnShowDiv('errorLaddress1');
        if(errorLength==0)
            Laddress1.focus();
        errorLength++;
    }

    if(Lemail.value.length>0)
    {
        if(!isValidEmail(Lemail.value))
        {
            fnShowDiv('errorinvalidemail');
            if(errorLength==0)
                Lemail.focus();
            errorLength++;
        }
        else
        {
            fnHiddenDiv('errorinvalidemail');
        }
    }

    if(Lemail.value!="" & Lemail.value.length>0)
    {

        fnHiddenDiv('errorLemail');
    }
    else
    {

        fnShowDiv('errorLemail');
        if(errorLength==0)
            Lemail.focus();
        errorLength++;
    }


    if(Lcity.value!="" & Lcity.value.length>0)
    {

        fnHiddenDiv('errorLcity');
    }
    else
    {

        fnShowDiv('errorLcity');
        if(errorLength==0)
            Lcity.focus();
        errorLength++;
    }
    //
    if(Lcountry.value!="" & Lcountry.value.length>0)
    {

        fnHiddenDiv('errorLcountry');
    }
    else
    {

        fnShowDiv('errorLcountry');
        if(errorLength==0)
            Lcountry.focus();
        errorLength++;
    }

    if(Lzip.value!="" & Lzip.value.length>0)
    {

        fnHiddenDiv('errorLzip');
    }
    else
    {

        fnShowDiv('errorLzip');
        if(errorLength==0)
            Lzip.focus();
        errorLength++;
    }

    if(Lphone.value!="" & Lphone.value.length>0)
    {

        fnHiddenDiv('errorLphone');
    }
    else
    {

        fnShowDiv('errorLphone');
        if(errorLength==0)
            Lphone.focus();
        errorLength++;
    }


    if (errorLength>0)
    {
        return false;
    }

    else
    {
        return true;
    // var url="/about/savecontactdetails"
    // var params="firstname" +firstname;



    }



}

function blogpagecommentvalidation()
{
  

    var errorLength=0;
    var Eblogpagename="";
    var Eblogpageemail="";
    // var Eblogpagecomments="";
    Eblogpagename=document.getElementById('username');
    Eblogpageemail=document.getElementById('email');
    // Eblogpagecomments=document.getElementById('comments');
    if(Eblogpagename.value!="" & Eblogpagename.value.length>0)
    {

        fnHiddenDiv('errorEblogpagename');


    }
    else
    {

        fnShowDiv('errorEblogpagename');
        if(errorLength==0)
            Eblogpagename.focus();
    
        errorLength++;
    }


    if(Eblogpageemail.value!="" && Eblogpageemail.value.length>0)
    {
        fnHiddenDiv('errorEblogpageemail');

    }
    else
    {
        fnShowDiv('errorEblogpageemail');
        if(errorLength==0)
            Eblogpageemail.focus();
      
        errorLength++;
    }
    if(Eblogpageemail.value.length>0)
    {
        if(!isValidEmail(Eblogpageemail.value))
        {
            fnShowDiv('validemailaddress');
            if(errorLength==0)
                Eblogpageemail.focus();
            errorLength++;
        }
        else
        {
            fnHiddenDiv('validemailaddress');
        }
    }


    //    if(Eblogpagecomments.value!="" && Eblogpagecomments.value.length>0)
    //    {
    //            fnHiddenDiv('errorEblogpagecomments');
    //
    //     }
    //     else
    //     {
    //             fnShowDiv('errorEblogpagecomments');
    //             if(errorLength==0)
    //              Eblogpagecomments.focus();
    //
    //              errorLength++;
    //       }



    if (errorLength>0)
    {
        return false;
    }

    else
    {
        return true;
    }



}
function addblogvalidation()
{
    var errorLength=0;
    var Eblogtitle="";
    var Eblogpageauthor="";
    var Eblogpagecomment="";
    Eblogtitle=document.getElementById('pagetitle');
    Eblogpageauthor=document.getElementById('pageauthor');
    Eblogpagecomment=document.getElementById('textarea1');
  
    if(Eblogtitle.value!="" & Eblogtitle.value.length>0)
    {

        fnHiddenDiv('errorEblogtitle');


    }
    else
    {

        fnShowDiv('errorEblogtitle');
        if(errorLength==0)
            Eblogtitle.focus();

        errorLength++;
    }


    if(Eblogpageauthor.value!="" && Eblogpageauthor.value.length>0)
    {
        fnHiddenDiv('errorEblogpageauthor');

    }
    else
    {
        fnShowDiv('errorEblogpageauthor');
        if(errorLength==0)
            Eblogpageauthor.focus();

        errorLength++;
    }
  


    if(Eblogpagecomment.value!="" && Eblogpagecomment.value.length>0)
    {
        fnHiddenDiv('errorEblogcomment');

    }
    else
    {
        fnShowDiv('errorEblogcomment');
        if(errorLength==0)
            Eblogpagecomment.focus();

        errorLength++;
    }



    if (errorLength>0)
    {
        return false;
    }

    else
    {
        return true;
    }



}

function blogcategory(id)
{
    if((id!="" && id.length>0))
    {
        var actionURL="/blog/blogcategorydisplay?id="+id
        window.location=actionURL;





    //     var queryString="";
    //
    //    queryString="id="+id+'&'+"name="+name;
    //    //actionUrl="/shipping/loadStateList"
    //   var  actionUrl="/blog/blogcategorydisplay"
    //    actionUrl+="?"+queryString;
    // window.location=actionUrl;

    }
}

function fnShowDiv(id)
{

    document.getElementById(id).style.display="block";
}

function fnHiddenDiv(id)
{
    document.getElementById(id).style.display="none";
}


function fnfirst()
{
    alert('inside js')
    var stock=document.getElementById('postcomment');
    alert(stock);
    if(stock==0)
    {
        fnHiddenDiv('comments');
    // fnHiddenDiv('brandOtherEmpty');
    // document.getElementById('otherbrandName').value="";
    }
    else
    {
        fnShowDiv('comments');
    }
}

function toggle( targetId ){
    if (document.getElementById){
        target = document.getElementById( targetId );
        if (target.style.display == "none"){
            target.style.display = "";
        } else {
            target.style.display = "none";
        }
    }
}



function commentshow(blogpageId,targetId)
{
    if (document.getElementById){
        target = document.getElementById( targetId );
        if (target.style.display == "none"){
            target.style.display = "";
        } else {
            target.style.display = "none";
        }
    }
}

function searchvalidation(thisform)
{
	
    key = thisform.keyword.value;
    if (key.length == 0) {
        return false;
    } else
{
        return true;
    }
}
function updatevalidation()
{
    var errorLength=0;
    
    var  emailaddress=trimString(document.getElementById('emailid').value);
    
    if(emailaddress.length==0 )
    {

        fnShowDiv('erroremailaddress');

        errorLength++;
    }
    else
    {
        fnHiddenDiv('erroremailaddress');

    }

    if(emailaddress.length>0)
    {
        if(!isValidEmail(emailaddress))
        {
            fnShowDiv('erroreinvalidemail');

            errorLength++;
        }
        else
        {
            fnHiddenDiv('erroreinvalidemail');
        }
    }

    //    alert('inside u');
    //    key = thisform.email.value;
    //    if (key.length == 0) {
    //        return false;
    //    } else
    //    {
    //        return true;
    //    }


    if (errorLength>0)
    {
        return false;
    }

    else
    {
        return true;
    }
}

function blockNonNumbers(obj, e, allowDecimal, allowNegative)
{
    var key;
    var isCtrl = false;
    var keychar;
    var reg;

    if(window.event) {
        key = e.keyCode;
        isCtrl = window.event.ctrlKey
    }
    else if(e.which) {
        key = e.which;
        isCtrl = e.ctrlKey;
    }
    if (isNaN(key)) return true;
    keychar = String.fromCharCode(key);

    // check for backspace or delete, or if Ctrl was pressed
    if (key == 8 || isCtrl)
    {
        return true;
    }
    reg = /\d/;
    var isFirstN = allowNegative ? keychar == '-' && obj.value.indexOf('-') == -1 : false;
    var isFirstD = allowDecimal ? keychar == '.' && obj.value.indexOf('.') == -1 : false;
    return isFirstN || isFirstD || reg.test(keychar);
}



function correctPNG() // correctly handle PNG transparency in Win IE 5.5 & 6.
{

    var arVersion = navigator.appVersion.split("MSIE")
    var version = parseFloat(arVersion[1])
    if ((version >= 5.5) && (document.body.filters))
    {
        for(var i=0; i<document.images.length; i++)
        {
            var img = document.images[i]
            var imgName = img.src.toUpperCase()
            if (imgName.substring(imgName.length-3, imgName.length) == "PNG")
            {
                var imgID = (img.id) ? "id='" + img.id + "' " : ""
                var imgClass = (img.className) ? "class='" + img.className + "' " : ""
                var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' "
                var imgStyle = "display:inline-block;" + img.style.cssText
                if (img.align == "left") imgStyle = "float:left;" + imgStyle
                if (img.align == "right") imgStyle = "float:right;" + imgStyle
                if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle
                var strNewHTML = "<span " + imgID + imgClass + imgTitle
                + " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"
                + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
                + "(src=\'" + img.src + "\', sizingMethod='image');\"></span>"

                img.outerHTML = strNewHTML
                i = i-1

            }
        }
    }
}
if (window.addEventListener)
    window.addEventListener("load",correctPNG,false);
else if (window.attachEvent)
    window.attachEvent("onload",correctPNG);
else
    window.onload = correctPNG;


// Declaring required variables
var digits = "0123456789";
// non-digit characters which are allowed in phone numbers
var phoneNumberDelimiters = "( ) - ";
// characters which are allowed in international phone numbers
// (a leading + is OK)
var validWorldPhoneChars = phoneNumberDelimiters + "+";
// Minimum no of digits in an international phone no.
var minDigitsInIPhoneNumber = 10;

function isInteger(s)
{
    var i;
    for (i = 0; i < s.length; i++)
    {
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}


function trim(s)
{
    var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not a whitespace, append to returnString.
    for (i = 0; i < s.length; i++)
    {
        // Check that current character isn't whitespace.
        var c = s.charAt(i);
        if (c != " ") returnString += c;
    }
    return returnString;
}
function stripCharsInBag(s, bag)
{
    var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++)
    {
        // Check that current character isn't whitespace.
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

function checkInternationalPhone(strPhone){
    var bracket=3
    strPhone=trim(strPhone)
    if(strPhone.indexOf("+")>1) return false
    if(strPhone.indexOf("-")!=-1)bracket=bracket+1
    if(strPhone.indexOf("(")!=-1 && strPhone.indexOf("(")>bracket)return false
    var brchr=strPhone.indexOf("(")
    if(strPhone.indexOf("(")!=-1 && strPhone.charAt(brchr+2)!=")")return false
    if(strPhone.indexOf("(")==-1 && strPhone.indexOf(")")!=-1)return false
    s=stripCharsInBag(strPhone,validWorldPhoneChars);
    return (isInteger(s) && s.length >= minDigitsInIPhoneNumber);
}

function fnIsNumeric1(strString)
//  check for valid numeric strings
{

    var strValidChars = "a-zA-Z0-9.-";
    var strChar;
    var blnResult = true;

    if (strString.length == 0) return false;

    //  test strString consists of valid characters listed above
    for (i = 0; i < strString.length && blnResult == true; i++)
    {
        strChar = strString.charAt(i);
        if (strValidChars.indexOf(strChar) == -1)
        {
            blnResult = false;
        }
    }
   
    return blnResult;
}
function careerformvalidation()
{
    var errorLength=0;
    emailaddress=trimString(document.getElementById('app_email').value);
   
    if(emailaddress.length==0 )
    {

        fnShowDiv('errorcareeremailaddress');

        errorLength++;
    }
    else
    {
        fnHiddenDiv('errorcareeremailaddress');

    }

    if(emailaddress.length>0)
    {
        if(!isValidEmail(emailaddress))
        {
            fnShowDiv('errorcareerinvalidemail');

            errorLength++;
        }
        else
        {
            fnHiddenDiv('errorcareerinvalidemail');
        }
    }

    if (errorLength>0)
    {
        return false;
    }

    else
    {
        return true;
    }
}
function preorderformvalidation()
{
    var errorLength=0;
    var emailaddress="";
    var first_name="";
    var last_name="";
    var  Address="";
    var city="";
    var cnumber="";
    var cname="";
    var securitynumber="";
    var dd="";
    var phonenumb="";
    emailaddress=trimString(document.getElementById('email').value);
    first_name=trimString(document.getElementById('firstname').value);
    last_name=trimString(document.getElementById('lastname').value);
    Address=trimString(document.getElementById('address1').value);
    city=trimString(document.getElementById('city').value);
    zipcode=trimString(document.getElementById('postcode').value);
    phonenumb=trimString(document.getElementById('phonenum').value);
    cnumber=trimString(document.getElementById('cc_number').value);
    cname=trimString(document.getElementById('cc_name').value);
    securitynumber=trimString(document.getElementById('secrity').value);
    dd=trimString(document.getElementById('testinput').value);

    if(first_name.length==0 )
    {

        fnShowDiv('errorfirst_name');

        errorLength++;
    }
    else
    {
        fnHiddenDiv('errorfirst_name');

    }
    if(last_name.length==0 )
    {

        fnShowDiv('errorlast_name');

        errorLength++;
    }
    else
    {
        fnHiddenDiv('errorlast_name');

    }
    if(Address.length==0 )
    {

        fnShowDiv('errorAddress');

        errorLength++;
    }
    else
    {
        fnHiddenDiv('errorAddress');

    }
    if(city.length==0 )
    {

        fnShowDiv('errorcity');

        errorLength++;
    }
    else
    {
        fnHiddenDiv('errorcity');

    }
    if(zipcode.length==0 )
    {

        fnShowDiv('errorzipcode');

        errorLength++;
    }
    else
    {
        fnHiddenDiv('errorzipcode');

    }
    if(phonenumb.length==0 )
    {

        fnShowDiv('errorphonenum');

        errorLength++;
    }
    else
    {
        fnHiddenDiv('errorphonenum');

    }
    if(dd.length==0 )
    {

        fnShowDiv('errordd');

        errorLength++;
    }
    else
    {
        fnHiddenDiv('errordd');

    }
    //    if(emailaddress.length==0 )
    //    {
    //
    //        fnShowDiv('erroremailaddress');
    //
    //        errorLength++;
    //    }
    //    else
    //    {
    //        fnHiddenDiv('erroremailaddress');
    //
    //    }

    if(emailaddress.length>0)
    {
        if(!isValidEmail(emailaddress))
        {
            fnShowDiv('errorinvalidemail');

            errorLength++;
        }
        else
        {
            fnHiddenDiv('errorinvalidemail');
        }
    }
    var checkvalue="";
    if (document.testform.chkaddress[0].checked)
    {
        checkvalue=document.testform.chkaddress[0].value
    }


    if (checkvalue=='yes')

    {
        if(cnumber.length==0 )
        {

            fnShowDiv('errorcnumber');

            errorLength++;
        }
        else
        {
            fnHiddenDiv('errorcnumber');

        }
        if(cname.length==0 )
        {

            fnShowDiv('errorcname');

            errorLength++;
        }
        else
        {
            fnHiddenDiv('errorcname');

        }
        if(securitynumber.length==0 )
        {

            fnShowDiv('errorsecuritynumber');

            errorLength++;
        }
        else
        {
            fnHiddenDiv('errorsecuritynumber');

        }
        if(dd.length==0 )
        {

            fnShowDiv('errordd');

            errorLength++;
        }
        else
        {
            fnHiddenDiv('errordd');

        }
    }
    else
    {

    }
    
    if (errorLength>0)
    {
        return false;
    }

    else
    {
        return true;
    }
}


function isNumber(sText) {
    if (sText=="") return false;
    var ValidChars = "0123456789-()";
    var IsNumber=true;
    var Char;
    var dotCnt = 0;

    for (i = 0; i < sText.length && IsNumber == true; i++)
    {
        Char = sText.charAt(i);
        if (Char==".") dotCnt = dotCnt +1;
        if (ValidChars.indexOf(Char) == -1 || dotCnt>1)
        {
            IsNumber = false;
        }
    }
    return IsNumber;

}

function checkcomments()
{
    var couponcode = "";
    var errorLength=0;
    var commentform = document.comment
    var commentform_value = commentform.comments.value;


    errcount = 0
    errmsg = ""
    if(trimString(commentform_value).length == 0) {
        errcount ++
        errmsg += "<div class=\"er-msg\">Please Enter the Comments </div>"

    } else {
        commentform.commentform_value.style.borderColor = ""
    }

    if(errcount > 0) {

        document.getElementById("comment-err").innerHTML = errmsg
        document.getElementById("comment-err").style.display = ""

        return false;
    } else {
        document.getElementById("comment-err").style.display = "none"
    }
}

function hidesubmitorderbutton()
{
    document.getElementById('checkout-button').style.display = "none"

}

function hidesubmitorderbuttonerror()
{

    document.getElementById('checkout-buttonerror').style.display = "none"
}

function disableEnterKey(e)
{
    var key;
    if(window.event)
        key = window.event.keyCode; //IE
    else
        key = e.which; //firefox
    return (key != 13);
}

//function billing_save()
//{
//
//    createXmlHttpRequest();
//
//    // Get Params
//    var billingform = document.co_billing_form
//    var billto_firstname = billingform.billto_firstname.value;
//    var billto_lastname = billingform.billto_lastname.value;
//    var billto_company = billingform.billto_company.value;
//    var billto_email = billingform.billto_email.value;
//    var billto_address1 = billingform.billto_address1.value;
//    var billto_address2 = billingform.billto_address2.value;
//    var billto_city = billingform.billto_city.value;
//    var billto_state = billingform.billto_state.value;
//    var billto_state_name = billingform.billto_state_name.value;
//    var billto_zipcode = billingform.billto_zipcode.value;
//    var billto_country = billingform.billto_country.value;
//   // var billto_areacode=billingform.billto_areacode.value;
//    var billto_phone = billingform.billto_phone.value;
//    var billto_fax = billingform.billto_fax.value;
//
//
//
//    // Validating form fields
//    errcount = 0
//    errmsg = ""
//    if(trimString(billto_firstname).length == 0) {
//        errcount ++
//        errmsg += "<div class=\"er-msg\">First name is missing</div>"
//    //billingform.billto_firstname.style.borderColor = "#ff0000"
//    } else {
//        billingform.billto_firstname.style.borderColor = ""
//    }
//
//    if(trimString(billto_lastname).length == 0) {
//        errcount ++
//        errmsg += "<div class=\"er-msg\">Last name is missing</div>"
//
//    } else {
//        billingform.billto_lastname.style.borderColor = ""
//    }
//
//    if(trimString(billto_email).length == 0) {
//        errcount ++;
//        errmsg += "<div class=\"er-msg\">Email is missing</div>";
//    //billingform.billto_email.style.className = "checkout-error";
//
//
//    } else {
//        billingform.billto_email.style.borderColor = ""
//    }
//
//    if(trimString(billto_email).length > 0)
//    {
//
//        if(isValidEmail(billto_email)!= true)
//        {
//            errcount ++;
//            errmsg += "<div class=\"er-msg\">Improper Emailaddress  </div>";
//        }
//    }
//    else
//    {
//        billingform.billto_email.style.borderColor = ""
//    }
//
//    if(trimString(billto_address1).length == 0) {
//        errcount ++
//        errmsg += "<div class=\"er-msg\">Address 1 is missing</div>"
//    //billingform.billto_address1.style.borderColor = "#ff0000"
//    } else {
//        billingform.billto_address1.style.borderColor = ""
//    }
//
//    if(trimString(billto_city).length == 0) {
//        errcount ++
//        errmsg += "<div class=\"er-msg\">City is missing</div>"
//
//    } else {
//        billingform.billto_city.style.borderColor = ""
//    }
////    if(trimString(billto_city).length > 0) {
////        if(!fnIsNumeric2(billto_city))
////        {
////            errcount ++
////            errmsg += "<div class=\"er-msg\">Enter only character</div>"
////        }
////    }
////    else {
////        billingform.billto_city.style.borderColor = ""
////    }
//    if(trimString(billto_zipcode).length == 0) {
//        errcount ++
//        errmsg += "<div class=\"er-msg\">Zipcode is missing</div>"
//    //billingform.billto_address1.style.borderColor = "#ff0000"
//    } else {
//        billingform.billto_zipcode.style.borderColor = ""
//    }
//
////    if(trimString(billto_areacode).length == 0) {
////        errcount ++
////        errmsg += "<div class=\"er-msg\">Area Code is missing</div>"
////
////    } else {
////        billingform.billto_areacode.style.borderColor = ""
////    }
//
//    if(trimString(billto_phone).length == 0) {
//        errcount ++
//        errmsg += "<div class=\"er-msg\">Phone is missing</div>"
//    //billingform.billto_address1.style.borderColor = "#ff0000"
//    } else {
////        if(!isNumber(billto_phone))
////           {
////               errcount ++
////               errmsg += "<div class=\"er-msg\">Please enter the valid phone number</div>"
////           }
//        billingform.billto_phone.style.borderColor = ""
//    }
//
//    if(document.getElementById("billto_state_name").style.display == "") {
//        if(trimString(billto_state_name).length == 0) {
//            errcount ++
//            errmsg += "<div class=\"er-msg\">State is missing</div>"
//        //billingform.billto_address1.style.borderColor = "#ff0000"
//        } else {
//            billingform.billto_phone.style.borderColor = ""
//        }
//    } else {
//
//    }
//
//
//    if(errcount > 0) {
//        errmsg = "<div class=\"tit\">Below Error(s) prevent your checkout</div>"+errmsg
//        document.getElementById("checkout-step-billing-err").innerHTML = errmsg
//        document.getElementById("checkout-step-billing-err").style.display = ""
//
//        return false;
//    } else {
//        document.getElementById("checkout-step-billing-err").style.display = "none"
//    }
//
//
//
//
//
//
//
//
//    var billto_shipto_option;
//
//    for(var l=0; l<billingform.use_for_shipping.length; l++) {
//        if(billingform.use_for_shipping[l].checked == true) {
//            billto_shipto_option = billingform.use_for_shipping[l].value
//        }
//    }
//
//    // POST Request
//    //var url = "/checkout/savebilling";
//    var url = "/checkout/savebilling";
//    var params = "billto_firstname="+billto_firstname+"&billto_lastname="+billto_lastname+"&billto_company="+billto_company+"&billto_email="+billto_email+"&billto_address1="+billto_address1+"&billto_address2="+billto_address2+"&billto_city="+billto_city+"&billto_state="+billto_state+"&billto_state_name="+billto_state_name+"&billto_zipcode="+billto_zipcode+"&billto_country="+billto_country+"&billto_phone="+billto_phone+"&billto_fax="+billto_fax+"&billto_shipto_option="+billto_shipto_option+"";
//    //alert (params)
//    xmlHttp.open("POST", url, true);
//    xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
//    xmlHttp.setRequestHeader("Content-length", params.length);
//    xmlHttp.setRequestHeader("Connection", "close");
//    xmlHttp.setRequestHeader("If-Modified-Since", "Thu, 1 Jan 1970 00:00:00 GMT");
//    xmlHttp.setRequestHeader("Cache-Control", "no-cache");
//
//    xmlHttp.onreadystatechange = function() {//Call a function when the state changes.
//        //alert (xmlHttp.readyState + " " + xmlHttp.status)
//        if(xmlHttp.readyState == 4 && xmlHttp.status==200) {
//            //alert("response xml is \n" + xmlHttp.responseText);
//            var response = xmlHttp.responseXML;
//            var result = response.documentElement.getElementsByTagName("result")[0].childNodes[0].nodeValue;
//
//            var ret_billto_state = ""
//            var ret_billto_state_name = ""
//            var ret_billto_country = ""
//            if(response.documentElement.getElementsByTagName("ret-billto-state")[0].childNodes[0]!=undefined) {
//                ret_billto_state = response.documentElement.getElementsByTagName("ret-billto-state")[0].childNodes[0].nodeValue;
//            }
//            if(response.documentElement.getElementsByTagName("ret-billto-state-name")[0].childNodes[0]!=undefined) {
//                ret_billto_state_name = response.documentElement.getElementsByTagName("ret-billto-state-name")[0].childNodes[0].nodeValue;
//            }
//            if(response.documentElement.getElementsByTagName("ret-billto-country")[0].childNodes[0]!=undefined) {
//                ret_billto_country = response.documentElement.getElementsByTagName("ret-billto-country")[0].childNodes[0].nodeValue;
//            }
//
//
//            if(result == "true") {
//                //alert("start shipping")
//                document.getElementById("edit_billing_content").innerHTML = "<address>"+billto_firstname+" " +billto_lastname +"<br/>"+billto_email+"<br/>"+billto_address1+"<br/>"+billto_city+"<br/>"+ret_billto_state + ret_billto_state_name +"<br/>"+ret_billto_country+"<br/>"+billto_phone+"</address>";
//                document.getElementById("a-billing-info").style.display = "";
//                document.getElementById("edit_billing_content").style.display="";
//                checkout_shipping_step();
//            }
//        }
//    }
//    xmlHttp.send(params);
//}
