﻿var req;
function GetXmlHttpObject() {
    var xmlHttp = null;
    try {
        xmlHttp = new XMLHttpRequest();
    }
    catch (e) {
        try {
            xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
        }
        catch (e) {
            xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
        }
    }
    return xmlHttp;
}

function billingSendZip(zip) {
    if (zip.length + 1 > 5) {
        
        req = GetXmlHttpObject();
        var siteroot;
        if (document.location.href.indexOf("localhost") == -1) {
            var v1 = document.location.href.substring(document.location.href.indexOf("//") + 2);
            siteroot = v1.substring(0, v1.indexOf("/"));
        }
        else {
            var v1 = document.location.href.substring(document.location.href.indexOf("//") + 2);
            var v2 = v1.substring(v1.indexOf("/") + 1); siteroot = v1.substring(0, v2.indexOf("/") + 1 + v1.indexOf("/"));
        }
        var protocol = document.location.href.substring(0, document.location.href.indexOf("//") - 1);
        var url = protocol + "://" + siteroot + "/AjaxComplete.aspx?cmd=CAZipdata&zip=" + zip + "&id=1811660";
		 document.getElementById("BillingCity").value = url;
        if (req != null) {
            req.onreadystatechange = function() {
                if (req.readyState == 4) {
                    if (req.status == 200) {
                        if (req.responseText == "")
                        { }
                        else {
                            if (req.responseText.indexOf("#*false*#") != 0) {
                                var result = req.responseText.split("*$#");
                                document.getElementById("BillingCity").value = result[0];
                                document.getElementById("BillingState").value = result[1];
                                document.getElementById("BillingCity").disabled = false;
                                document.getElementById("BillingState").disabled = false;
								document.getElementById('BillingCountry').disabled = false;

                            } else {
                            document.getElementById('divbillingajaxmove').style.display = 'none';
                            document.getElementById("BillingCity").value = "INVALID ZIP";
                            document.getElementById("BillingState").value = "INVALID ZIP";
                             }
                        }
                        document.getElementById('divbillingajaxmove').style.display = 'none';
                    }
                    else {
                        document.getElementById('divbillingajaxmove').style.display = 'none';
                    }
                }
            };
            req.open("GET", url, true);
            req.send(null);
            document.getElementById('divbillingajaxmove').style.display = 'block';
			document.getElementById("BillingCity").disabled = false;
        document.getElementById("BillingState").disabled = false;
		document.getElementById('BillingCountry').disabled = false;
       
        }
    }
    else {
        document.getElementById('divbillingajaxmove').style.display = 'none';
        document.getElementById("BillingCity").value = "INVALID ZIP";
        document.getElementById("BillingState").value = "INVALID ZIP";
        
    }
}

function shippingSendZip(zip) {
    if (zip.length + 1 > 5) {
        req = GetXmlHttpObject();
        var siteroot;
        if (document.location.href.indexOf("localhost") == -1) {
            var v1 = document.location.href.substring(document.location.href.indexOf("//") + 2);
            siteroot = v1.substring(0, v1.indexOf("/"));
        }
        else {
            var v1 = document.location.href.substring(document.location.href.indexOf("//") + 2);
            var v2 = v1.substring(v1.indexOf("/") + 1); siteroot = v1.substring(0, v2.indexOf("/") + 1 + v1.indexOf("/"));
        }
        var protocol = document.location.href.substring(0, document.location.href.indexOf("//") - 1);
        var url = protocol + "://" + siteroot + "/AjaxComplete.aspx?cmd=CAZipdata&zip=" + zip + "&id=1811660";
        
        if (req != null) {
            req.onreadystatechange = function() {
                if (req.readyState == 4) {
                    if (req.status == 200) {
                        if (req.responseText == "")
                        { }
                        else {
                            if (req.responseText.indexOf("#*false*#") != 0) {
                                var result = req.responseText.split("*$#");
                                document.getElementById("ShippingCity").value = result[0];
                                document.getElementById("ShippingState").value = result[1];
                                document.getElementById("ShippingCity").disabled = false;
                                document.getElementById("ShippingState").disabled = false;
								document.getElementById('ShippingCountry').disabled = false;

                            }
                            else {
                                document.getElementById('divshippingajaxmove').style.display = 'none';
                                document.getElementById("ShippingCity").value = "INVALID ZIP";
                                document.getElementById("ShippingState").value = "#";
                             }
                        }
                        document.getElementById('divshippingajaxmove').style.display = 'none';
                    }
                    else {
                        document.getElementById('divshippingajaxmove').style.display = 'none';
                    }
                }
                
            };
            req.open("GET", url, true); req.send(null);
            document.getElementById('divshippingajaxmove').style.display = 'block';
            document.getElementById("ShippingCity").disabled = false;
            document.getElementById("ShippingState").disabled = false;
			document.getElementById('ShippingCountry').disabled = false;
            document.getElementById("ShippingCity").value = "INVALID ZIP";
            document.getElementById("ShippingState").value = "INVALID ZIP";
            
        }
    }
    else
    {
        document.getElementById('divshippingajaxmove').style.display = 'none';
        document.getElementById("ShippingCity").value = "INVALID ZIP";
        document.getElementById("ShippingState").value = "#";
    }
}

function GetShipping() 
{
        req = GetXmlHttpObject();
        var siteroot;
        if (document.location.href.indexOf("localhost") == -1) {
            var v1 = document.location.href.substring(document.location.href.indexOf("//") + 2);
            siteroot = v1.substring(0, v1.indexOf("/"));
        }
        else {
            var v1 = document.location.href.substring(document.location.href.indexOf("//") + 2);
            var v2 = v1.substring(v1.indexOf("/") + 1); siteroot = v1.substring(0, v2.indexOf("/") + 1 + v1.indexOf("/"));
        }
        var protocol = document.location.href.substring(0, document.location.href.indexOf("//") - 1);
        var Gzip = document.getElementById("zipcode").value;
        var url = protocol + "://" + siteroot + "/MiniCart/ShippingEstimation.aspx?Zip=" + Gzip;
        if (req != null) {
            req.onreadystatechange = function() {
                if (req.readyState == 4) {
                    if (req.status == 200) {
                        if (req.responseText == "") {
                        }
                        else {
                            if (req.responseText.indexOf("#*false*#") != 0) {
                                var prep = req.responseText.split("#");
                                document.getElementById("quote").value = prep[0];
                                document.getElementById("zipcode").disabled = false;
                            }
                            else {
                                document.getElementById('divshippingajaxmove').style.display = 'none';
                                document.getElementById("zipcode").disabled = false;
                            }
                        }
                    }
                    document.getElementById('divshippingajaxmove').style.display = 'none';
                    document.getElementById("zipcode").disabled = false;
                }
                else {
                    document.getElementById('divshippingajaxmove').style.display = 'none';

                }

            };
            req.open("GET", url, true); req.send(null);
            document.getElementById('divshippingajaxmove').style.display = 'block';
        }

    
}


var CAsecs; var CAtimerID = null;
var CAtimerRunning = false;
var CAdelay = 1000;
var CAval1;

function CAInitializeTimer(value) {
    CAval1 = value;
    CAsecs = 1;
    CAStopTheClock();
    CAStartTheTimer();
}
function CAStopTheClock() {
    if (CAtimerRunning)
        clearTimeout(CAtimerID);

    CAtimerRunning = false;
}
function CAStartTheTimer() {
    if (CAsecs == 0) {
        CAStopTheClock();
        billingSendZip(CAval1);
    }
    else {
        self.status = CAsecs;
        CAsecs = CAsecs - 1;
        CAtimerRunning = true;
        CAtimerID = self.setTimeout("CAStartTheTimer()", CAdelay);
    }
}
var SCAsecs;
var SCAtimerID = null;
var SCAtimerRunning = false;
var SCAdelay = 1000;
var SCAval1;

function SCAInitializeTimer(value) {
    SCAval1 = value;
    SCAsecs = 1;
    SCAStopTheClock();
    SCAStartTheTimer();
}

function SCAStopTheClock() {
    if (SCAtimerRunning)
        clearTimeout(SCAtimerID);
    SCAtimerRunning = false;
}

function SCAStartTheTimer() {
    if (SCAsecs == 0) {
        SCAStopTheClock();
        shippingSendZip(SCAval1);
    }
    else {
        self.status = SCAsecs;
        SCAsecs = SCAsecs - 1;
        SCAtimerRunning = true;
        SCAtimerID = self.setTimeout("SCAStartTheTimer()", SCAdelay);
    }
}
var Minisecs;
var MinitimerID = null;
var MinitimerRunning = false;
var Minidelay = 2000;
var Minival1;

function MiniInitializeTimer(value) {
    Minival1 = value;
    Minisecs = 1;
    MiniStopTheClock();
    MiniStartTheTimer();
}

function MiniStopTheClock() {
    if (MinitimerRunning)
        clearTimeout(MinitimerID);
    MinitimerRunning = false;
}
function MiniStartTheTimer() {
    if (Minisecs == 0) {
        MiniStopTheClock();
        GetShipping();
    }
    else {
        self.status = Minisecs;
        Minisecs = Minisecs - 1;
        MinitimerRunning = true;
        MinitimerID = self.setTimeout("MiniStartTheTimer()", Minidelay);
    }
}

function hideshipdetail1() {

    document.getElementById('billingzipajax').src = "../images/bigrotation2.gif";
    document.getElementById('divbillingajaxmove').style.display = 'none';
    document.getElementById('shippingajaxmove').src = "../images/bigrotation2.gif";
    document.getElementById('divshippingajaxmove').style.display = 'none';
};