//--------------------------------------------------------
//    AJAX ZIP CODE FINDER
//--------------------------------------------------------

var xmlHttp;
function zipXML(id) {
    var id;
    //alert(id);

    switch (id) {
        case "bill":
            var zip_code = "postalcode";
            var zip = document.getElementById(zip_code).value;
            var url = "zip_find_ajax.asp?zip=" + zip;
            //alert(url);
            xmlHttp = GetXMLHTTP();
            xmlHttp.open("GET", url, true);
            xmlHttp.onreadystatechange = Callbill;
            break;
        case "ship":
            var zip_code = "ship_postalcode";
            var zip = document.getElementById(zip_code).value;
            var url = "zip_find_ajax.asp?zip=" + zip;
            //alert(url);
            xmlHttp = GetXMLHTTP();
            xmlHttp.open("GET", url, true);
            xmlHttp.onreadystatechange = Callship;
            break;
        case "a_ship":
            var zip_code = "a_ship_postalcode";
            var zip = document.getElementById(zip_code).value;
            var url = "zip_find_ajax.asp?zip=" + zip;
            //alert(url);
            xmlHttp = GetXMLHTTP();
            xmlHttp.open("GET", url, true);
            xmlHttp.onreadystatechange = CallshipA;
            break;
        case "b_ship":
            var zip_code = "b_ship_postalcode";
            //alert(zip_code);
            var zip = document.getElementById(zip_code).value;
            var url = "zip_find_ajax.asp?zip=" + zip;
            //alert(url);
            xmlHttp = GetXMLHTTP();
            xmlHttp.open("GET", url, true);
            xmlHttp.onreadystatechange = CallshipB;
            break;
        default:
            var zip_code = "postalcode";
            break;
    }

    xmlHttp.send(null);
}

function Callbill() {
    if (xmlHttp.readyState == 4) {
        if (xmlHttp.status == 200) {
            var data = xmlHttp.responseText;
            var info = data.split("|");
            //alert(data);
            document.getElementById("city").value = info[0];
            document.getElementById("state").value = info[1];
            document.getElementById("country").value = info[2];
                   
        }
        else {
            var zip_code = "postalcode";
            document.getElementById(zip_code).style.color = "red";
        }
    }
}

function Callship() {
    if (xmlHttp.readyState == 4) {
        if (xmlHttp.status == 200) {
            var data = xmlHttp.responseText;
            var info = data.split("|");
            //alert(data);
            document.getElementById("ship_city").value = info[0];
            document.getElementById("ship_state").value = info[1];
            document.getElementById("ship_country").value = info[2];
                    
        }
        else {
            var zip_code = "ship_postalcode";
            document.getElementById(zip_code).style.color = "red";
        }
    }
}

function CallshipA() {
    if (xmlHttp.readyState == 4) {
        if (xmlHttp.status == 200) {
            var data = xmlHttp.responseText;
            var info = data.split("|");
            //alert(data);
            document.getElementById("a_ship_city").value = info[0];
            document.getElementById("a_ship_state").value = info[1];
            document.getElementById("a_ship_country").value = info[2];
        }
        else {
            var zip_code = "a_ship_postalcode";
            document.getElementById(zip_code).style.color = "red";
        }
    }
}

function CallshipB() {
    if (xmlHttp.readyState == 4) {
        if (xmlHttp.status == 200) {
            var data = xmlHttp.responseText;
            var info = data.split("|");
            //alert(data);
            if (document.getElementById("b_ship_city") != null)
                document.getElementById("b_ship_city").value = info[0];
            document.getElementById("b_ship_state").value = info[1];
            document.getElementById("b_ship_country").value = info[2];
        }
        else {
            var zip_code = "b_ship_postalcode";
            document.getElementById(zip_code).style.color = "red";
        }
    }
}

function countXML() {
   
    var url = "/common/log/page_count.asp";
    //alert(url);
    xmlHttp = GetXMLHTTP();
    xmlHttp.open("GET", url, true);
    xmlHttp.onreadystatechange = Count_page;

    xmlHttp.send(null); 
}


function logXML(previous_page,current_url,root_url,version,promotion,web_idx) {


    var previous_page;
    var current_url;
    var root_url;
    var version;
    var promotion;
    var web_idx;

    var url = "/common/log/db_log.asp?previous_page=" + previous_page + "&current_url=" + current_url + "&root_url=" + root_url + "&version=" + version + "&promotion=" + promotion + "&web_idx=" + web_idx;
    //alert(url);
    xmlHttp = GetXMLHTTP();
    xmlHttp.open("GET", url, true);
    xmlHttp.onreadystatechange = Count_page;

    xmlHttp.send(null);
}

function Count_page() {
    if (xmlHttp.readyState == 4) {
        if (xmlHttp.status == 200) {
            var data = xmlHttp.responseText;
            //var info = data.split("|");
            //alert(data);
            if (document.getElementById("page_count") != null)
                document.getElementById("page_count").innerHTML = data;
        }
    }
}

function cart_update(product_code,web_idx){
    
    var qty = product_code+"_qty"
    var count =  document.getElementById(qty).value;
    var product_code;
    var web_idx;
    var url = "cart_cal_ajax.asp?qty=" + count + "&product_code=" + product_code + "&web_idx=" + web_idx;

    xmlHttp = GetXMLHTTP();
    xmlHttp.open("GET",url, true);
    xmlHttp.onreadystatechange = Callcart;
        
    xmlHttp.send(null);
}
    
function Callcart()
{
    if(xmlHttp.readyState ==4)
    {
        if(xmlHttp.status == 200)
        {
            var data = xmlHttp.responseText;
            var cart_data = data.split("|");
            //alert(data);
            document.getElementById("product20_qty").value = cart_data[0];
            document.getElementById("Carrying_Case_qty").value = cart_data[0];
            document.getElementById("Two_Year_Warranty_qty").value = cart_data[0];
            document.getElementById("One_Year_Warranty_qty").value = cart_data[0];
            document.getElementById("card_set_qty").value = cart_data[0];
            document.getElementById("Cooking_Guide_qty").value = cart_data[0];
            document.getElementById("Cook_Book_qty").value = cart_data[0];
            document.getElementById("dvd_qty").value = cart_data[0];
            document.getElementById("Main_White_Oven_amt").value = cart_data[1];
            document.getElementById("product20_amt").value = cart_data[2];
            document.getElementById("tax_total").value = cart_data[3];
            document.getElementById("snp_total").value = cart_data[4];
            document.getElementById("order_total").value = cart_data[5];
        }
        else
        {
            document.getElementById("postalcode").style.color= "red";
        }
    }
}


function cartXML(web_idx, id) {
    var web_idx;
    var qty = document.getElementById(id).value;
    //alert(qty);
    var product_code = id;
    var url = "cart_view_ajax.asp?web_idx=" + web_idx + "&product_code=" + product_code + "&qty=" + qty;
    //alert(url);
    xmlHttp = GetXMLHTTP();
    xmlHttp.open("GET", url, true);
    xmlHttp.onreadystatechange = Callcart;

    xmlHttp.send(null);
}

function Callcart() {
    if (xmlHttp.readyState == 4) {
        //alert(xmlHttp.status);
        if (xmlHttp.status == 200) {
            var data = xmlHttp.responseText;
            //alert(data);
            var info = data.split("|");
            document.getElementById("cart_product_total").value = info[0];
            document.getElementById("cart_snp_total").value = info[1];
            document.getElementById("cart_order_total").value = info[2];
        }
    }
}


function GetXMLHTTP() {
    if (window.XMLHttpRequest) return new XMLHttpRequest();
    var versions = [
                "MSXML2.XMLHTTP.5.0",
                "MSXML2.XMLHTTP.4.0",
                "MSXML2.XMLHTTP.3.0",
                "MSXML2.XMLHTTP",
                "Microsoft.XMLHTTP"
            ];

    for (var i = 0; i < versions.length; i++) {
        try {
            var oXMLHTTP = new ActiveXObject(versions[i]);
            return oXMLHTTP;
        }
        catch (e) { }
    }

    throw new Error("No XMLHTTP");

}
//-------------------------------------------------

function embed(src, width, height, vars) {
    var codebase = "http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0";
    var pluginspage = "http://www.macromedia.com/go/getflashplayer";

    if (document.location.protocol == "https:") {
        codebase = codebase.replace(/http:/, "https:");
        pluginspage = pluginspage.replace(/http:/, "https:");
    }

    document.write('\
    <OBJECT classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="' + codebase + '" WIDTH="' + width + '" HEIGHT="' + height + '">\
        <PARAM NAME=movie VALUE="' + src + '">\
        <PARAM NAME=quality VALUE=high>\
        <PARAM NAME=wmode VALUE=transparent>\
        <PARAM NAME=bgcolor VALUE=#FFFFFF>\
        <param name=flashvars value="' + vars + '">\
        <EMBED src="' + src + '" quality=high bgcolor=#FFFFFF WIDTH="' + width + '" HEIGHT="' + height + '" TYPE="application/x-shockwave-flash" PLUGINSPAGE="' + pluginspage + '" flashvars="' + vars + '"></EMBED>\
    </OBJECT>\
    ');
}

function waitPreloadPage() { //DOM
    if (document.getElementById) {
        document.getElementById('loading').style.visibility = 'hidden';
    } else {
        if (document.layers) { //NS4
            document.loading.visibility = 'hidden';
        }
        else { //IE4
            document.all.loading.style.visibility = 'hidden';
        }
    }
}

function button_change(object, event) {

    var orgin_image_src = object.src;
    var change_image_src = orgin_image_src;

    if (orgin_image_src != null) {
        if (orgin_image_src.indexOf("_normal.") != -1)
            change_image_src = orgin_image_src.replace("_normal.", "_" + event + ".");
        if (orgin_image_src.indexOf("_over.") != -1)
            change_image_src = orgin_image_src.replace("_over.", "_" + event + ".");
        if (orgin_image_src.indexOf("_down.") != -1)
            change_image_src = orgin_image_src.replace("_down.", "_" + event + ".");

        object.src = change_image_src;
    }

    //alert(change_image_src);
}

function bluring(){
    if(event.srcElement.tagName=="A"||event.srcElement.tagName=="IMG")document.body.focus();
}
document.onfocusin=bluring; 

/* testimonial iframe size setting    */
function updateHeight() {
    var the_height = document.getElementById('testimonialIframe').contentWindow.document.body.scrollHeight;
    /*
    alert(the_height);
    if (the_height < 250) {
        the_height = 7817;
    }
    */
    document.getElementById('testimonialIframe').height = the_height;
}

function payment_option(id)
{
    if (id=='3')
    {
        document.getElementById("one_payment").style.visibility = "hidden";
        document.getElementById("one_payment").style.display = "none";
        document.getElementById("tree_payment").style.visibility = "visible";
        document.getElementById("tree_payment").style.display = "block";
    }else{
        document.getElementById("tree_payment").style.visibility = "hidden";
        document.getElementById("tree_payment").style.display = "none";
        document.getElementById("one_payment").style.visibility = "visible";
        document.getElementById("one_payment").style.display = "block";
    }
}

function flash_off()
{
    document.getElementById("flash").style.visibility = "hidden";
    document.getElementById("flash").style.display = "none";
}

function flash_on()
{
    document.getElementById("flash").style.visibility = "visible";
    document.getElementById("flash").style.display = "block";
}

function free_gift_over(id)
{
    var img;

    document.getElementById("free_gift_div").style.visibility = "visible";
    document.getElementById("free_gift_div").style.display = "block";
    document.images.free_gift_img.src = id;	
}

function free_gift_out()
{
    
    document.getElementById("free_gift_div").style.visibility = "hidden";
    document.getElementById("free_gift_div").style.display = "none";
}

function cart_shopping_on()
{
    document.getElementById("cart_shop_view").style.visibility = "visible";
    document.getElementById("cart_shop_view").style.display = "block";
}

function cart_shopping_off()
{
    document.getElementById("cart_shop_view").style.visibility = "hidden";
    document.getElementById("cart_shop_view").style.display = "none";
}

function cart_items_on(id)
{
    document.getElementById(id).style.visibility = "visible";
    document.getElementById(id).style.display = "block";
}

function cart_items_off(id)
{
    document.getElementById(id).style.visibility = "hidden";
    document.getElementById(id).style.display = "none";
}


function display_on(id)
{
    if (document.getElementById(id) != null) {
        document.getElementById(id).style.visibility = "visible";
        document.getElementById(id).style.display = "block";
    }
}

function display_off(id)
{
    if (document.getElementById(id) != null) {
        document.getElementById(id).style.visibility = "hidden";
        document.getElementById(id).style.display = "none";
    }
}

function banner_on()
{	
    //flash_off();
    //document.getElementById("flash").style.visibility = "hidden";
    //document.getElementById("flash").style.display = "none";
}

function banner_off()
{
    document.getElementById("promotion_banner").style.visibility = "hidden";
    document.getElementById("promotion_banner").style.display = "none";
}

function shopping_item_over(id)
{
    var id;
    document.images.big_image.src = id;	
}


function popupWindow(url, w, h) {
    window.open(url, '', 'toolbar=no,location=no,directories=no status=no,menubar=no,scrollbars=yes,resizable=no,copyhistory=no,width=' + w + ',height=' + h + ',screenX=150,screenY=150,top=150,left=150')
}

function popupWindow2(url, sw, sh) {
    //alert(1);
    window.open(url, "", "menubar=yes,scrollbars=yes,width=" + sw + ",height=" + sh + ",left=50%,top=50%");
}

function bigimgset(imgpath) {
    var img = imgpath;
    document.images.bigimg.src=img;
}

function date_maxday()
{
    var mVal = document.getElementById('date_month');
    //alert(mVal);
    switch (mVal)
    {
    case 1,3,5,7,8,10,12:
        max_day = 31;
        break;
    case 4,6,9,11:
        max_day = 30;
        break;
    case 2:
        max_day = 29;
        break;
    default :
        max_day = 31;
    }	
    
    var date_day = document.getElementById('date_day');
    //alert(max_day);
    if (date_day != null)
    {
        var dayValue = document.frmReg.date_day.options[document.frmReg.date_day.selectedIndex].value;
        //alert(adderkValue);
        while(document.frmReg.date_day.length > 0)
        {
            document.frmReg.date_day.options[0] = null;
        }
        //alert(addoven);
        for (i=0;i<=Number(max_day) ;i++ )
        {
            var oOption = document.createElement("OPTION");
            oOption.text = i;
            oOption.value = i;
            document.frmReg.date_day.options.add(oOption);
        }

    }
} 

function writeText(id,txt)
{
    //alert(txt);
    document.getElementById(id).innerHTML=txt;
}

function message_display(id)
{
    document.getElementById(id).style.display='block';
}


var isNN = (navigator.appName.indexOf("Netscape") != -1);
function autoTab(input, len, e) {
    var keyCode = (isNN) ? e.which : e.keyCode;
    var filter = (isNN) ? [0, 8, 9] : [0, 8, 9, 16, 17, 18, 37, 38, 39, 40, 46];
    if (input.value.length >= len && !containsElement(filter, keyCode)) {
        input.value = input.value.slice(0, len);
        input.form[(getIndex(input) + 1) % input.form.length].focus();
    }
    function containsElement(arr, ele) {
        var found = false, index = 0;
        while (!found && index < arr.length)
            if (arr[index] == ele)
                found = true;
            else
                index++;
        return found;
    }
    function getIndex(input) {
        var index = -1, i = 0, found = false;
        while (i < input.form.length && index == -1)
            if (input.form[i] == input) index = i;
            else i++;
        return index;
    }
    return true;
}


function WriteLayer(ID,parentID,sText) { 
 if (document.layers) { 
   var oLayer; 
   if(parentID){ 
     oLayer = eval('document.' + parentID + '.document.' + ID + '.document'); 
   }else{ 
     oLayer = document.layers[ID].document; 
   } 
   oLayer.open(); 
   oLayer.write(sText); 
   oLayer.close(); 
 } 
 else if (parseInt(navigator.appVersion)>=5&&navigator.appName=="Netscape") { 
   document.getElementById(ID).innerHTML = sText; 
 } 
 else if (document.all) document.all[ID].innerHTML = sText 
} 

function topmenu_show(id) {
    var id;
    topmenu_product.style.display = "none";
    topmenu_product.style.display = "none";
    topmenu_aboutus.style.display = "none";
    topmenu_aboutus.style.visibility = "hidden";
    topmenu_features.style.visibility = "hidden";
    topmenu_features.style.visibility = "hidden";    
    
    switch(id){
        case "products":
            topmenu_product.style.display = "block";
            topmenu_product.style.visibility = "visible";
            break;
        case "features":
            topmenu_features.style.display = "block";
            topmenu_features.style.visibility = "visible";
            break;
        case "hearthware":
            topmenu_aboutus.style.display = "block";
            topmenu_aboutus.style.visibility = "visible";
            break;
        default:
            break;
    }
}

function show(id) {
    document.getElementById(id).style.visibility = "visible";
    document.getElementById(id).style.display = "block";
}

function hide(id) {
    document.getElementById(id).style.visibility = "hidden";
    document.getElementById(id).style.display = "none";
}


