﻿$(window).load(function(ent) {
    //    InitPage();

    //    $(window).resize(InitPage);
    //    $("#content_div").resize(InitPage);
    $("#div_topMenus").find("li").mouseenter(function() {
        SubMenuExpand(this);
    });

    $("#div_topMenus").find("li").mouseleave(function() {
        SubMenuCollapse(this);
    });

    var height = $("#div_content3_left").height();
    if (height < $("#div_content3_right").height())
    {
        height = $("#div_content3_right").height();
    }

    if (height < 450)
    {
        height = 450;
    }

    $("#div_spliter").css({
        "height": height
    });
});

function SubMenuExpand(obj) {
    var id = obj.id;
    
    $("#sub_" + id).css({
        position: "absolute",
        left: $(obj).offset().left,
        top: $(obj).offset().top + 29
    });

    $("#sub_" + id).stop(true, true).slideDown("slow");
}

function SubMenuShowing(obj) {
    $(obj).css({
        display: "block"
    });
}

function SubMenuCollapse(obj) {
    var id = obj.id;
    $("#sub_" + id).stop(true, true).slideUp("fast");
}

//for get shipping info
function GetShippingInfo(obj) {
    var no = obj.id.split("_")[1];
    var divID = $("#jsnResult_" + no);
    var zipCode = $("#queryZipCode_" + no).attr("value");
    var skuid = $("#hideSKUID_" + no).html();

    divID.html("<img alt='loading' src='../../content/images/loading.gif' style='width: 25px; height: 25px;' />");

    $.getJSON("/jsondata?skuid=" + skuid + "&zipcode=" + zipCode,
        function(data) {
    divID.html("<span><span style='color: Green; font-weight: bold;'>$"
        + data[0].sqftPrice + "</span> sqft.</span><br />"
        + "Delivered Price <span style='color: Green; font-weight: bold;'>$"
        + data[0].price + "</span><br />Total cost to zipcode <span style='color: Green; font-weight: bold;'>"
                + zipCode + "</span> " + data[0].location);
        });
}

//
function SKUShippingInfo(obj) {
    var skuid = $(obj).parent().find("input")[0].value;
    var zipcode = $(obj).parent().find("input")[1].value;

    window.location.href = "/shippinginforrpt1?zipcode="
        + zipcode + "&skuid=" + skuid;
}

//
function SKUShippingInfo2(obj) {
    
    var no = obj.id.split("_")[1];
    var zipCode = $("#queryZipCode_" + no).attr("value");
    var skuid = $("#hideSKUID_" + no).html();
    
    window.location.href = "/shippinginforrpt1?zipcode="
        + zipCode + "&skuid=" + skuid;
}

//
function SKUShippingInfo3(obj) {

    var no = obj.id.split("_")[1];
    var zipCode = $("#original_zip").html();
    var skuid = $("#hideSKUID_" + no).html();

    window.location.href = "/shippinginforrpt1?zipcode="
        + zipCode + "&skuid=" + skuid;
}

//
function ShippingReportChangeZIP(url, id) {
    var zipCode = $("#" + id).val();

    var args = getArgs();

    window.location.href = url + "?zipcode="
        + zipCode + "&skuid=" + args["skuid"];
}

//
function ShippingReportChangeZIP_OneTab(id) {
    var zipCode = $("#" + id).val();

    var args = getArgs();

    window.location.href = "/shippinginforrptonetab?zipcode="
        + zipCode + "&skuid=" + args["skuid"];
}

//
function EmailTheReport(obj) {
    var div = $(obj).parent().parent().parent();
    //div.find(".intresting_result").find("img").show();
    ajaxPopupHint("pop", "");
    var args = getArgs();
    var skuid = args["skuid"];
    var zipcode = args["zipcode"];
    $.getJSON("/InterestedMail?skuid=" + skuid + "&zipcode=" + zipcode
        + "&time=" + new Date(),
        function(data) {
            //div.find(".intresting_result").find("img").hide();
            //div.find(".intresting_result").html(data[0].message);
            $("#pop").find("img").hide();
            $("#pop").find("div[class!=button]").html(data[0].message);
            $("#pop").find(".button").show();
        });
}

function SaveLookup(obj, url) {
    var div = $(obj).parent().parent().parent();
    //div.find(".intresting_result").find("img").show();
    ajaxPopupHint("pop", "");
    var args = getArgs();
    var skuid = args["skuid"];
    var zipcode = args["zipcode"];
    $.getJSON("/SaveLookUp?lookup_skuid=" + skuid + "&lookup_zip=" + zipcode + "&url=" + url
        + "&time=" + new Date(),
        function(data) {
            //div.find(".intresting_result").find("img").hide();
            //div.find(".intresting_result").html(data[0].message);
            $("#pop").find("img").hide();
            $("#pop").find("div[class!=button]").html(data[0].message);
            $("#pop").find(".button").show();
        });
}

//
function getArgs() {
    var args = new Object();
    var query = location.search.substring(1); //获取查询串
    var pairs = query.split("&"); //在&处断开

    for (var i = 0; i < pairs.length; i++) {
        var pos = pairs[i].indexOf('='); //查找name=value   
        if (pos == -1) continue; //如果没有找到就跳过   
        var argname = pairs[i].substring(0, pos); //提取name   
        var value = pairs[i].substring(pos + 1); //提取value   
        args[argname] = unescape(value); //存为属性   
    }
 
    return args; //返回对象   
}

function getArgs_ByURL(url) {
    var args = new Object();
    var query = url.substring(url.indexOf("?") + 1); //获取查询串
    var pairs = query.split("&"); //在&处断开

    for (var i = 0; i < pairs.length; i++) {
        var pos = pairs[i].indexOf('='); //查找name=value   
        if (pos == -1) continue; //如果没有找到就跳过   
        var argname = pairs[i].substring(0, pos); //提取name   
        var value = pairs[i].substring(pos + 1); //提取value   
        args[argname] = unescape(value); //存为属性   
    }
 
    return args; //返回对象   
}

//
function showAllRoutes(obj) {
    if ($(obj).text() == "show top 10 routes") {
        $("#allRoutesTxt").css({
            display: "block"
        });
        $("#rows_Show1").text("show lowest-cost route");
        $("#rows_Show2").text("show lowest-cost route");

        $(".shippinginfoList1 table tr").show();
    } else{
        $("#allRoutesTxt").css({
            display: "none"
        });

        sortTable("tb_shippingList", 12, "float", true);
        var ths = $("#tb_shippingList").find("img");
        ths.hide();
        ths.attr("src", "");
        $("#tb_shippingList").find("img:eq(12)").attr("src", "../content/images/sortUp.jpg");
        
        $("#rows_Show1").text("show top 10 routes");
        $("#rows_Show2").text("show top 10 routes");
        $(".shippinginfoList1 table tr:gt(1)").hide();
    }
}

//
function showAllRoutes_Init() {
    var args = getArgs();
    var shipid = args["shipid"];

    if (shipid == undefined) {

        $("#allRoutesTxt").css({
            display: "none"
        });

        sortTable("tb_shippingList", 12, "float", true);
        var ths = $("#tb_shippingList").find("img");
        ths.hide();
        ths.attr("src", "");
        $("#tb_shippingList").find("img:eq(12)").attr("src", "../content/images/sortUp.jpg");

        $("#rows_Show").text("See All Routes");
        $("#tb_shippingList tr:gt(1)").hide();
    } else {
        $("#allRoutesTxt").css({
            display: "block"
        });
        $("#rows_Show").text("See Lowest-Cost Route");

        $("#tb_shippingList tr").show();
    }

    $("#tb_shippingList tr:gt(1)").each(function() {
        var s = $(this).find("input").val();
        if (s == shipid) {
            $(this).css("background-color", "#FFA500");
        }
    });
}

//for selector
function FoldDiv(divid, imgid) {
    if ($("#" + divid).css("display") == "none") {
        $("#" + divid).css("display", "block");
        $("#" + imgid).attr("src", "../../Content/images/arrow2.jpg");
    }
    else {
        $("#" + divid).css("display", "none");
        $("#" + imgid).attr("src", "../../Content/images/arrow1.jpg");
    }

}

//for shipping table sorting
function SortTable(obj, colIndex, dataType) {
    if ($("#rows_Show").text() != "See All Routes") {
        var tableID = $(obj).parent().parent().parent().attr("id");
        sortTable(tableID, colIndex, dataType);
        ChangeSortPic(obj);
    }
}

//state filter
function StateFilter(i) {
    var pos1 = 0;
    var pos2 = 60;
    var pos3 = 103;
    var pos4 = 117;
    var pos5 = 128;
    var pos6 = 144;
    var pos7 = 164;
    
    

    //USA: 473 pos1
    //UK: 472 pos2
    //Canada: 278 pos3
    //Australia: 252 pos4
    //New Zealand: 397 pos5
    //Hong Kong: 338 pos6

    var args = new Object();
    args["473-start"] = pos1 + 1;
    args["473-end"] = pos2;

    /*args["472-start"] = pos2 + 1;
    args["472-end"] = pos3;

    args["278-start"] = pos3 + 1;
    args["278-end"] = pos4;

    args["252-start"] = pos4 + 1;
    args["252-end"] = pos5;

    args["397-start"] = pos5 + 1;
    args["397-end"] = pos6;

    args["338-start"] = pos6 + 1;
    args["338-end"] = pos7;*/

    var country = $("#countryList");
    var state = $("#stateList");
    var stateInput = $("#stateInput");
    var hiddenState = $("#hiddenstateList");

    state.find("option").remove();
    if (country.val() == "473")
        state.append(hiddenState.find("option").slice(args[country.val() + "-start"]
                , args[country.val() + "-end"]).clone());

    if (state.find("option").length == 0) {
        //state.append("<option value=''>Unknown</option>");
        state.hide();
        stateInput.show();
        
        if (i == 1)
            stateInput.val("");
    }
    else {
        state.show();
        stateInput.hide();
        state.trigger("change");
    }  
}

//state change
function StateChange() {
    var state = $("#stateList");
    var stateInput = $("#stateInput");
    stateInput.val(state.val());
}

//state filter
function StateFilter_1(i, countryid, stateid, hiddenstateid, inputid) {
    var pos1 = 0;
    var pos2 = 60;
    var pos3 = 103;
    var pos4 = 117;
    var pos5 = 128;
    var pos6 = 144;
    var pos7 = 164;

    var args = new Object();
    args["473-start"] = pos1 + 1;
    args["473-end"] = pos2;

    var country = $("#" + countryid);
    var state = $("#" + stateid);
    var stateInput = $("#" + inputid);
    var hiddenState = $("#" + hiddenstateid);

    state.find("option").remove();
    if (country.val() == "473")
        state.append(hiddenState.find("option").slice(args[country.val() + "-start"]
                , args[country.val() + "-end"]).clone());

    if (state.find("option").length == 0) {
        state.hide();
        stateInput.show();
        
        if (i == 1)
            stateInput.val("");
    }
    else {
        state.show();
        stateInput.hide();
        state.trigger("change");
    }  
}

function StateChange_1(stateid, inputid) {
    var state = $("#" + stateid);
    var stateInput = $("#" + inputid);
    stateInput.val(state.val());
}


// for price calc
function CountUp(vid, minnum, maxnum) {

    var num = parseInt(document.getElementById(vid).value);

    document.getElementById(vid).value = num + 1;

    if (parseInt(document.getElementById(vid).value) > maxnum)
        document.getElementById(vid).value = maxnum;
}

function CountDown(vid, minnum, maxnum) {

    var num = parseInt(document.getElementById(vid).value);

    document.getElementById(vid).value = num - 1;
    if (parseInt(document.getElementById(vid).value) < minnum)
        document.getElementById(vid).value = minnum;
}

function DecimalOnly(vid) {

    var reg = /^\d+(\.\d{2})?$/;
    if (reg.test(document.getElementById(vid).value) == false)
        document.getElementById(vid).value = "0";
}

function NumberOnly(vid, minnum, maxnum) {

    var reg = /^[0-9]*$/;

    if (reg.test(document.getElementById(vid).value) == false) {
        document.getElementById(vid).value = "0";
        return false;
    }
    else if (parseInt(document.getElementById(vid).value) > maxnum) {
        document.getElementById(vid).value = maxnum;
        return true;
    }
    else if (parseInt(document.getElementById(vid).value) < minnum) {


        document.getElementById(vid).value = minnum;
        return true;
    }
    else
        return true;

}

function GetTotal(totalid, cuttingid, cuttingnumid, totalplusid, sqftperbox, price, passdoc) {


    var total = parseInt(passdoc.getElementById(totalid).value);
    var cutting = parseInt(passdoc.getElementById(cuttingid).value);

    var cuttingnum = Math.round((total * cutting * 0.01) * 100) / 100;

    passdoc.getElementById(cuttingnumid).innerHTML = cuttingnum;

    passdoc.getElementById(totalplusid).innerHTML = total + cuttingnum;

    var totalsqft = total + cuttingnum;

    passdoc.getElementById("resultspan").innerHTML = "";

    GetBoxesNum(totalsqft, sqftperbox, price, passdoc);
}

function GetBoxesNum(totalsqft, sqftperbox, price, passdoc) {

    if (passdoc == "undefined" || passdoc == null)
        passdoc = document;

    var unitperbox = passdoc.getElementById(sqftperbox).value;

    var unitprices = passdoc.getElementById(price).value;

    var totalbox = 0;

    if (totalsqft == 0) {

        passdoc.getElementById("boxnum").innerHTML = "0";
    }
    else {

        passdoc.getElementById("boxnum").innerHTML = Math.round((totalsqft / unitperbox) * 100) / 100;

        if ((totalsqft % unitperbox) > 0) {
            totalbox = parseInt(totalsqft / unitperbox) + 1;
        }
        else {
            totalbox = parseInt(totalsqft / unitperbox);
        }
    }

    passdoc.getElementById("adjustboxnum").value = totalbox;


    CalculatePrice(unitperbox, unitprices, passdoc);
}


function GetSqft(vid) {

    var totalrooms = 0;

    var room = 0;

    var feetx = 0;
    var feety = 0;

    var feet = 0;

    for (var i = 1; i < 7; i++) {

        feetx = 0;
        feety = 0;

        if (document.getElementById("feetx" + i.toString()).value != "" && document.getElementById("feety" + i.toString()).value != "") {
            feetx = parseInt(document.getElementById("feetx" + i.toString()).value);
            feety = parseInt(document.getElementById("feety" + i.toString()).value);
        }

        if (document.getElementById("inchesx" + i.toString()).value != "" && document.getElementById("inchesx" + i.toString()).value != "0") {
            feetx += parseFloat(document.getElementById("inchesx" + i.toString()).value / 12);
        }

        if (document.getElementById("inchesy" + i.toString()).value != "" && document.getElementById("inchesy" + i.toString()).value != "0") {
            feety += parseFloat(document.getElementById("inchesy" + i.toString()).value / 12);
        }


        room = Math.round(feetx * feety * 100) / 100;

        document.getElementById("room" + i.toString()).innerHTML = room;

        totalrooms += room;

    }

    document.getElementById(vid).innerHTML = totalrooms;
}


function NextStep(previd, nextid) {

    document.getElementById(nextid).style.display = "block";
    document.getElementById(previd).style.display = "none";

    document.getElementById("process1").style.width = "50%";
    document.getElementById("step2").style.color = "#BE1E2D";
}

function CalculatePrice(sqftperbox, price, passdoc) {

    if (passdoc == "undefined" || passdoc == null)
        passdoc = document;

    var totalbox = parseInt(passdoc.getElementById("adjustboxnum").value);
    var totalsqft = Math.round(totalbox * sqftperbox * 100) / 100;

    var totalprice = Math.round(totalbox * sqftperbox * price * 100) / 100;

    passdoc.getElementById("adjusttotalsqft").innerHTML = totalsqft;
    passdoc.getElementById("quantity").innerHTML = totalsqft.toString() + "," + document.getElementById("unitprice").value + "," + document.getElementById("shipwhscode").value;
    //alert(passdoc.getElementById("quantity").innerHTML);

    passdoc.getElementById("boxesprice").innerHTML = totalprice;

    passdoc.getElementById("productprice").innerHTML = totalprice;

    passdoc.getElementById("grandtotal").innerHTML = totalprice;

    passdoc.getElementById("total").innerHTML = totalprice;

}

function GoPrev(previd, nextid) {

    document.getElementById(previd).style.display = "block";
    document.getElementById(nextid).style.display = "none";

    document.getElementById("process1").style.width = "25%";
    document.getElementById("step2").style.color = "#72320F";
    document.getElementById("step3").style.color = "#72320F";
    document.getElementById("step4").style.color = "#72320F";
}

function Reset(vid, totalid) {
    var divContainer = document.getElementById(vid);
    var objs = divContainer.getElementsByTagName('INPUT');
    for (var i = 0; i < objs.length; i++) {
        if (objs[i].type == "text")
            objs[i].value = "0";
    }

    for (var i = 1; i <= 6; i++) {
        document.getElementById("room" + i.toString()).innerHTML = "0.0";
    }

    document.getElementById(totalid).innerHTML = "0.0";

}

function GetResult(vid, sqftperbox, price, passdoc) {

    if (passdoc == null || passdoc == "undefined")
        passdoc = document;

    var total = 0;

    if (passdoc.getElementById(vid).value != "") {

        total = parseFloat(passdoc.getElementById(vid).value);

        passdoc.getElementById("sqfts").value = total;
        //passdoc.getElementById("resultspan").innerHTML = "Calculate result is <b style='color:Red;'>" + total + " sqft.</b>";
    }
    // alert(total);

    GetTotal('sqfts', 'cutting', 'cuttingnum', 'totalsqft', 'unitsqft', 'unitprice', passdoc);
    // GetBoxesNum(total, sqftperbox, price,passdoc);
}

function ReturnResult(resultid, returnid) {

    if (document.getElementById(resultid).innerHTML != "" && document.getElementById(resultid).innerHTML != "0.0" && document.getElementById(resultid).innerHTML != "0") {

        window.opener.document.getElementById(returnid).value = document.getElementById(resultid).innerHTML;
        window.opener.document.getElementById("sqfts").value = document.getElementById(resultid).innerHTML;
        GetResult('calculateresult', 'unitsqft', 'unitprice', window.opener.document);


        //    window.opener.document.getElementById("cuttingnum").innerHTML="0";
        //    window.opener.document.getElementById("totalsqft").innerHTML="0";

        window.close();
    }
}

function Cal() {

    var destZip = $('#zipcodebox').val();

    if (destZip != "") {

        var weight = $('#weight').val();
        var quantity = $('#quantityperbox').val();
        var box = $('#adjustboxnum').val();
        var commodityclass = $('#commodityclass').val();
        var totalsqft = quantity * box;

        var totalweight = Math.round(weight * quantity * box);

        if (totalweight <= 0 || commodityclass == "") {

            $('#noweight').attr("innerHTML", "No Weight");
            return;
        }

        $('#noweight').attr("innerHTML", "");
        document.getElementById("loading").style.display = "block";
        var insidecharge = 0;
        var residential = 0;

        var skuid = $('#ctl_hid_skuid').val();
        var skutype = $('#ctl_hid_skutype').val();

        $.ajax({
            url: "/AJAXSelectData/GetInfo?zipcode=" + destZip + "&totalweight=" + totalweight + "&commodityclass=" + commodityclass + "&totalsqft=" + totalsqft + "&skuid=" + skuid + "&skutype=" + skutype,
            type: "post",
            dataType: 'json',
            success: function(data, status) {

                $.each(data, function(index, item) {

                    if (item == null) {

                        document.getElementById("loading").style.display = "none";
                        $('#noweight').attr("innerHTML", "Invalid Zipcode");
                    }
                    else {

                        if (item.charge == "WhsCode") {
                            //alert(item.currentvalue);
                            document.getElementById("quantity").innerHTML = document.getElementById("adjusttotalsqft").innerHTML + "," + document.getElementById("unitprice").value + "," + item.currentvalue;
                        }

                        if (item.charge == "CONSTRUCTIONDELIVERY") {
                            $('#method2').attr("innerHTML", item.currentvalue);
                        }
                        if (item.charge == "RESIDENTIALDELIVERY") {
                            $('#method3').attr("innerHTML", item.currentvalue);
                            residential = item.currentvalue;
                        }
                        if (item.charge == "LIFTGATEGROUNDDELIVERY") {
                            $('#method4').attr("innerHTML", item.currentvalue);
                        }
                        if (item.charge == "INSIDEDELIVERY") {
                            insidecharge = item.currentvalue;
                        }
                    }

                });

                $('#method5').attr("innerHTML", Math.round((parseFloat(insidecharge) + parseFloat(residential)) * 100) / 100);

                document.getElementById("loading").style.display = "none";


            }

        });

    }
}


function NoDelivery(vid) {

    if (document.getElementById(vid).checked == true) {
        var objs = document.getElementsByTagName('INPUT');
        for (var i = 0; i < objs.length; i++) {
            if (objs[i].type == "checkbox")
                objs[i].checked = false;
        }

        document.getElementById(vid).checked = true;

        var product = parseFloat(document.getElementById("productprice").innerHTML);
        var delivery = 0;
        document.getElementById("deliveryprice").innerHTML = delivery;
        document.getElementById("shippingfee").innerHTML = delivery;
        document.getElementById("grandtotal").innerHTML = (product + delivery);
    }
    else {

        document.getElementById(vid).checked == false;

        document.getElementById("deliveryprice").innerHTML = "0";
        document.getElementById("shippingfee").innerHTML = delivery;
        document.getElementById("grandtotal").innerHTML = document.getElementById("productprice").innerHTML;
        document.getElementById("total").innerHTML = product;
    }


    //    var totalbox = parseInt(document.getElementById("adjustboxnum").value);
    //    var totalprice = parseFloat(document.getElementById("grandtotal").innerHTML);
    document.getElementById("total").innerHTML = product;

}

function AddDelivery(vid, optionid) {

    if (document.getElementById(vid).checked == true) {
        var objs = document.getElementsByTagName('INPUT');
        for (var i = 0; i < objs.length; i++) {
            if (objs[i].type == "checkbox")
                objs[i].checked = false;
        }

        document.getElementById("process1").style.width = "75%";
        document.getElementById("step3").style.color = "#BE1E2D";
        document.getElementById("step4").style.color = "#72320F";
        document.getElementById(vid).checked = true;

        var product = parseFloat(document.getElementById("productprice").innerHTML);
        var delivery = parseFloat(document.getElementById(optionid).innerHTML);

        document.getElementById("deliveryprice").innerHTML = delivery;
        document.getElementById("shippingfee").innerHTML = delivery;
        document.getElementById("grandtotal").innerHTML = (Math.round((product + delivery) * 100) / 100);

    }
    else {

        document.getElementById(vid).checked == false;

        document.getElementById("process1").style.width = "50%";
        document.getElementById("step3").style.color = "#72320F";
        document.getElementById("step4").style.color = "#72320F";

        document.getElementById("deliveryprice").innerHTML = "0";
        document.getElementById("shippingfee").innerHTML = delivery;
        document.getElementById("grandtotal").innerHTML = document.getElementById("productprice").innerHTML;
        //document.getElementById("total").innerHTML = document.getElementById("grandtotal").innerHTML;

    }
    //    var totalbox = parseInt(document.getElementById("adjustboxnum").value);
    //    var totalprice = parseFloat(document.getElementById("grandtotal").innerHTML);
    document.getElementById("total").innerHTML = product;
}

function GoCheckOut() {
    document.getElementById("process1").style.width = "100%";
    document.getElementById("step4").style.color = "#BE1E2D";
    document.getElementById("step3").style.color = "#BE1E2D";
}

function showPicDiv(obj) {
    var src = $(obj).find("img").attr("src").toString().replace('small', 'large');
    var windowWidth = document.body.scrollWidth;
    var windowHeight = document.body.scrollHeight;

    var popupHeight = 600;
    var popupWidth = 800;
    
    //
    $("<div class='MaskDiv'></div>").addClass("mask")
                                  .width(windowWidth)
                                  .height(windowHeight)
                                  //.click(function() { hideDiv(); })
                                  .appendTo("body")
                                  .fadeIn(200);


    $("<div class='PicDiv'><img src='" + src + "' style='border: none;' /></div>")
               .css({ "position": "absolute", 
                    "left": windowWidth / 2 - popupWidth / 2,
                    "top": windowHeight / 2 - popupHeight / 2, })   
               .click(function() { hideDiv(); })
               .appendTo("body")
}

function hideDiv() {
    $(".MaskDiv").remove();
    $(".PicDiv").remove();
} 

function ProdDetailTabChange(obj, num) { 
    if ($(obj).hasClass("notselected"))
    {
        $(obj).siblings().each(function() {
            if ($(this).hasClass("selected"))
            {
                $(this).removeClass("selected");
                $(this).addClass("notselected");
            }
        });
        
        $(obj).removeClass("notselected");
        $(obj).addClass("selected");
        
        $("#tab-t1").hide();
        $("#tab-t2").hide();
        $("#tab-t3").hide();
        $("#tab-t4").hide();
        $("#tab-t5").hide();
        
        $("#tab-t" + num).show();
    }
  
}


function toggleCondList(obj) {
    $(obj).parent().next("div").toggle();
    var img = $(obj).find("img");

    if (img.attr("src") == "../content/images/selector-arrow-open.png") {
        img.attr("src", "../content/images/selector-arrow-closed.png");
    } else {
    img.attr("src", "../content/images/selector-arrow-open.png");
    }
}

function condCheck(param, url) {
    $(".psel_ck_1").attr("disabled", true);
    $(".psel_ck_2").attr("disabled", true);

    var a1 = $(".psel_ck_1:checked").map(function() {
                return $(this).val();
            }).get();

    var args = new Object();
    for (var i = 0; i < a1.length; i++) {
        var name = a1[i].split("*****")[0];
        var value = a1[i].split("*****")[1];

        if (args[name] != undefined) {
            args[name] = args[name] + "||" + value;
        } else {
            args[name] = name + "=" + value;
        }
    }

    var sParam = "";
    for (key in args) { 
        if (args[key].toString().indexOf("SKUGROUPID=-1") < 0)
            sParam += args[key] + "&"
    }

    url = url + "?" + sParam + param;

    var viewKind = "";
    if ($("#div_listview:visible").length > 0)
    {
        viewKind = "l";
    }

    var args1 = getArgs_ByURL(url);
    if (args1["viewKind"] == null){
        url += "viewKind=" + viewKind;
    }
    else
    {
        url = url.replace("viewKind=" + args1["viewKind"], "viewKind=" + viewKind);
    }

    //alert(sParam);

    window.location.href = url;
}

function condCheck2(a, param, url) {
    $(".psel_ck_1").attr("disabled", true);
    $(".psel_ck_2").attr("disabled", true);

    var a1 = $(".psel_ck_2").map(function() {
        if ($(this).attr("name") != $(a).attr("name"))
            return $(this).attr("name");
    }).get();

    var args = new Object();
    for (var i = 0; i < a1.length; i++) {
        var name = a1[i].split("*****")[0];
        var value = a1[i].split("*****")[1];

        if (args[name] != undefined) {
            args[name] = args[name] + "||" + value;
        } else {
            args[name] = name + "=" + value;
        }
    }

    var sParam = "";
    for (key in args) {
        sParam += args[key] + "&"
    }

    //alert(sParam);

    url = url + "?" + sParam + param;

    var viewKind = "";
    if ($("#div_listview:visible").length > 0)
    {
        viewKind = "l";
    }

    var args1 = getArgs_ByURL(url);
    if (args1["viewKind"] == null){
        url += "viewKind=" + viewKind;
    }
    else
    {
        url = url.replace("viewKind=" + args1["viewKind"], "viewKind=" + viewKind);
    }
    
    window.location.href = url;
}

function ProdListViewChangeZIP(zipcodeID)
{
    var zipcode = $("#" + zipcodeID).val();

    var args = getArgs();
    args["zipcode"] = zipcode;

    var query = ""; 

    for (var key in args) {
        query = query + key + "=" + args[key] + "&"; 
    }
    
   //alert(query); 
   window.location.href = "/products?" + query;
}

function ProdListViewChangeZIP_1(obj, skuid)
{
    var zipcode = $(obj).parent().parent().prev("input").val();
    
   //alert(query); 
   window.location.href = "/shippinginforrpt1?skuid=" + skuid + "&zipcode=" + zipcode;
}

function changeView(classname)
{
    var listview = $("#div_listview");
    var thumbview = $("#div_thumbview");
    listview.toggle();
    thumbview.toggle();
    
    var otherclassname = "btn_showthumbview";
    if (classname == "btn_showthumbview")
    {
        otherclassname = "btn_showlistview";
    }
    
    $("." + otherclassname).attr("style", "color: #ffffff");
    $("." + otherclassname).parent().parent().attr("style", "background: #FE7620");
    $("." + classname).attr("style", "color: #000000");
    $("." + classname).parent().parent().attr("style", "background: #ffffff");

    var viewKind = "";
    if ($("#div_listview:visible").length > 0)
    {
        viewKind = "l";
    }

    var as = $(".pagerdiv a");

    if (as.length > 0){
        var src = as.attr("href");
        var args = getArgs_ByURL(src);

        if (args["viewKind"] == null){
            as.attr("href", as.attr("href") + "&viewKind=" + viewKind);
        }
        else{ 
            as.attr("href", as.attr("href").replace("viewKind=" + args["viewKind"], 
                "viewKind=" + viewKind));
        }
    }
}

function ShowViewSelect(obj, url)
{
    var selValue = url + "?" + $(obj).val();
    
    var args = getArgs();
    var viewKind = "";
    if ($("#div_listview:visible").length > 0)
    {
        viewKind = "l";
    }
    
    if (args["viewKind"] == null){
        selValue += "&viewKind=" + viewKind;
    }
    else
    {
        selValue = selValue.replace("viewKind=" + args["viewKind"], "viewKind=" + viewKind);
    }
    
    window.location.href = selValue;
}

function InitChangeView()
{
    var params = getArgs();
    
    var listview = $("#div_listview");
    var thumbview = $("#div_thumbview");
    
    if (params["pageNum"] == "10")
    {
        $(".dl_viewselect").each(function(){
            $(this).find("option").eq(0).attr("selected", true);
        });
    }
    else if (params["pageNum"] == "20")
    {
        $(".dl_viewselect").each(function(){
            $(this).find("option").eq(1).attr("selected", true);
        });
    }
    else if (params["pageNum"] == "50")
    {
        $(".dl_viewselect").each(function(){
            $(this).find("option").eq(2).attr("selected", true);
        });
    }
    
    if (params["viewKind"] == "l")
    {
        listview.show();
        thumbview.hide();
        
        $(".btn_showthumbview").attr("style", "color: #ffffff");
        $(".btn_showthumbview").parent().parent().attr("style", "background: #FE7620");
        $(".btn_showlistview").attr("style", "color: #000000");
        $(".btn_showlistview").parent().parent().attr("style", "background: #ffffff");
    }
    else
    {
        listview.hide();
        thumbview.show();
        
        $(".btn_showlistview").attr("style", "color: #ffffff");
        $(".btn_showlistview").parent().parent().attr("style", "background: #FE7620");
        $(".btn_showthumbview").attr("style", "color: #000000");
        $(".btn_showthumbview").parent().parent().attr("style", "background: #ffffff");
    }
}

//--------------------------------------------------------------------------------------
//show documents
function ShowDocuments_Web(kind, id){
    if (kind == "Maintenance"){
            window.open("/documentview?dockind=Maintenance&skuid=" + id, "MaintenanceView", "left=100, top=100, width=1100, height=800, toolbar=no, location=no, scrollbars=yes, resizable=yes");
            return false;
    }
}

// end of show documents


//
function showProdPicDiv(obj) {
    var src = $(obj).attr("src");
    
    var scrollWidth = document.body.scrollWidth;
    var scrollHeight = document.body.scrollHeight;
    
    var windowWidth = $(window).width();
    var windowHeight = $(window).height();

    var offsetLeft = $(document).scrollLeft();
    var offsetTop = $(document).scrollTop();

    var popupHeight = 600;
    var popupWidth = 600;

    //
    $("<div class='MaskDiv'></div>").addClass("mask")
                                  .width(scrollWidth)
                                  .height(scrollHeight)
                                  //.click(function() { hideDiv(); })
                                  .appendTo("body")
                                  .fadeIn(200);


    $("<div class='PicDiv'><img src='" + src + "' style='border: none; width: 600px; height: 600px;' /></div>")
               .css({ "position": "absolute", 
                    "left": (windowWidth - popupWidth) / 2 + offsetLeft,
                    "top": (windowHeight - popupHeight) / 2 + offsetTop, })   
               .click(function() { hideDiv(); })
               .appendTo("body");
}
//

function ajaxPopupHint(id, text) {
    var scrollWidth = document.body.scrollWidth;
    var scrollHeight = document.body.scrollHeight;
    
    var windowWidth = $(window).width();
    var windowHeight = $(window).height();

    var offsetLeft = $(document).scrollLeft();
    var offsetTop = $(document).scrollTop();

    var popupHeight = 270;
    var popupWidth = 370;

    //
    $("<div class='MaskDiv'></div>").addClass("mask")
                                  .width(scrollWidth)
                                  .height(scrollHeight)
                                  //.click(function() { hideDiv(); })
                                  .appendTo("body")
                                  .fadeIn(200);


    $("<div class='PicDiv'><div style='text-align: left; width:310px; height: 150px; margin:20px; border:10px solid #C9C6B9; padding-top: 60px;'><div id='" + id + "' style='text-align: center;'><img src='../content/images/loading.gif' /><div></div><br/><br/><div class='button' style='width: 80px; display: none;' onclick='hideDiv();'><a href='#' >OK</a></div></div><div></div>")
               .css({ "position": "absolute", 
                    "left": (windowWidth - popupWidth) / 2 + offsetLeft,
                    "top": (windowHeight - popupHeight) / 2 + offsetTop, 
                    "width": popupWidth, "height":popupHeight,})   
               //.click(function() { hideDiv(); })
               .appendTo("body");
}

function doPrint() {
        bdhtml = document.body.innerHTML;
        sprnstr = "<!--startprint-->";
        eprnstr = "<!--endprint-->";
        prnhtml = bdhtml.substr(bdhtml.indexOf(sprnstr) + 17);
        prnhtml = prnhtml.substring(0, prnhtml.indexOf(eprnstr));
        window.document.body.innerHTML = prnhtml;
        window.print();
        //window.document.body.innerHTML = bdhtml;
    } 

function ajaxSubmitFormBind(button, form, checkRediUrl)
{
    $("#" + button).click(function () {
        ajaxPopupHint("pop", "");
        
        $("#" + form).ajaxSubmit(function (data) {
            if (data[0].message == "fail") {
                window.location.href = checkRediUrl;
            }
            else {
                $("#pop").find("img").hide();
                $("#pop").find("div[class!=button]").html(data[0].message);
                $("#pop").find(".button").show();

                if (data[0].message == "Update Successful"){
                    $("#" + button).attr("disabled", true);
                }
            }
        });
    });
}

function ajaxSubmitFormBind_S(button, form, checkRediUrl, before)
{
    $("#" + button).click(function () {
        ajaxPopupHint("pop", "");
        before();
        $("#" + form).ajaxSubmit(function (data) {
            $("#pop").find("img").hide();
            $("#pop").find("div[class!=button]").html(data[0].message);
            $("#pop").find(".button").show();

            if (data[1].message == "success") {
                $("#pop").find(".button").attr("onclick", "").bind("click", function (){
                    window.location.href = checkRediUrl;
                    //hideDiv();
                });
                $("#pop").find("a").bind("click", function (){
                    window.location.href = checkRediUrl;
                    //hideDiv();
                });             
            }
        });
    });
}

function ajaxSubmitCallback(data) {
    if (data[0].message == "fail") {
        window.location.href = checkRediUrl;
    }
    else {
        $("#pop").find("img").hide();
        $("#pop").find("div[class!=button]").html(data[0].message);
        $("#pop").find(".button").show();

        if (data[0].message == "Update Successful"){
            $("#" + button).attr("disabled", true);
        }
    }
}

///////// admin use

function MakeSaLikeBa(obj, baID, saID){
    if ($(obj).attr("checked") == true)
    {
        var selects1 = $("#" + baID).find("select").toArray();
        var selects2 = $("#" + saID).find("select").toArray();
        for (var i=selects1.length - 1; i>=0; i--)
        {
            $(selects2[i]).val($(selects1[i]).val());
            $(selects2[i]).trigger("change");
            $(selects2[i]).css("display", $(selects1[i]).css("display"));
        }

        var textboxs1 = $("#" + baID).find("input[type='text']").toArray();
        var textboxs2 = $("#" + saID).find("input[type='text']").toArray();

        for (var i=0; i<textboxs1.length; i++)
        {
            $(textboxs2[i]).val($(textboxs1[i]).val());
            $(textboxs2[i]).css("display", $(textboxs1[i]).css("display"));
        }     
    }
}

//
