﻿/*Thickbox 3 - One Box To Rule Them All.*/
var tb_pathToImage = "/includes/images/awaiting.gif";
eval(function(p, a, c, k, e, r) { e = function(c) { return (c < a ? '' : e(parseInt(c / a))) + ((c = c % a) > 35 ? String.fromCharCode(c + 29) : c.toString(36)) }; if (!''.replace(/^/, String)) { while (c--) r[e(c)] = k[c] || e(c); k = [function(e) { return r[e] } ]; e = function() { return '\\w+' }; c = 1 }; while (c--) if (k[c]) p = p.replace(new RegExp('\\b' + e(c) + '\\b', 'g'), k[c]); return p } ('$(o).2S(9(){1u(\'a.18, 3n.18, 3i.18\');1w=1p 1t();1w.L=2H});9 1u(b){$(b).s(9(){6 t=X.Q||X.1v||M;6 a=X.u||X.23;6 g=X.1N||P;19(t,a,g);X.2E();H P})}9 19(d,f,g){3m{3(2t o.v.J.2i==="2g"){$("v","11").r({A:"28%",z:"28%"});$("11").r("22","2Z");3(o.1Y("1F")===M){$("v").q("<U 5=\'1F\'></U><4 5=\'B\'></4><4 5=\'8\'></4>");$("#B").s(G)}}n{3(o.1Y("B")===M){$("v").q("<4 5=\'B\'></4><4 5=\'8\'></4>");$("#B").s(G)}}3(1K()){$("#B").1J("2B")}n{$("#B").1J("2z")}3(d===M){d=""}$("v").q("<4 5=\'K\'><1I L=\'"+1w.L+"\' /></4>");$(\'#K\').2y();6 h;3(f.O("?")!==-1){h=f.3l(0,f.O("?"))}n{h=f}6 i=/\\.2s$|\\.2q$|\\.2m$|\\.2l$|\\.2k$/;6 j=h.1C().2h(i);3(j==\'.2s\'||j==\'.2q\'||j==\'.2m\'||j==\'.2l\'||j==\'.2k\'){1D="";1G="";14="";1z="";1x="";R="";1n="";1r=P;3(g){E=$("a[@1N="+g+"]").36();25(D=0;((D<E.1c)&&(R===""));D++){6 k=E[D].u.1C().2h(i);3(!(E[D].u==f)){3(1r){1z=E[D].Q;1x=E[D].u;R="<1e 5=\'1X\'>&1d;&1d;<a u=\'#\'>2T &2R;</a></1e>"}n{1D=E[D].Q;1G=E[D].u;14="<1e 5=\'1U\'>&1d;&1d;<a u=\'#\'>&2O; 2N</a></1e>"}}n{1r=1b;1n="1t "+(D+1)+" 2L "+(E.1c)}}}S=1p 1t();S.1g=9(){S.1g=M;6 a=2x();6 x=a[0]-1M;6 y=a[1]-1M;6 b=S.z;6 c=S.A;3(b>x){c=c*(x/b);b=x;3(c>y){b=b*(y/c);c=y}}n 3(c>y){b=b*(y/c);c=y;3(b>x){c=c*(x/b);b=x}}13=b+30;1a=c+2G;$("#8").q("<a u=\'\' 5=\'1L\' Q=\'1o\'><1I 5=\'2F\' L=\'"+f+"\' z=\'"+b+"\' A=\'"+c+"\' 23=\'"+d+"\'/></a>"+"<4 5=\'2D\'>"+d+"<4 5=\'2C\'>"+1n+14+R+"</4></4><4 5=\'2A\'><a u=\'#\' 5=\'Z\' Q=\'1o\'>1l</a> 1k 1j 1s</4>");$("#Z").s(G);3(!(14==="")){9 12(){3($(o).N("s",12)){$(o).N("s",12)}$("#8").C();$("v").q("<4 5=\'8\'></4>");19(1D,1G,g);H P}$("#1U").s(12)}3(!(R==="")){9 1i(){$("#8").C();$("v").q("<4 5=\'8\'></4>");19(1z,1x,g);H P}$("#1X").s(1i)}o.1h=9(e){3(e==M){I=2w.2v}n{I=e.2u}3(I==27){G()}n 3(I==3k){3(!(R=="")){o.1h="";1i()}}n 3(I==3j){3(!(14=="")){o.1h="";12()}}};16();$("#K").C();$("#1L").s(G);$("#8").r({Y:"T"})};S.L=f}n{6 l=f.2r(/^[^\\?]+\\??/,\'\');6 m=2p(l);13=(m[\'z\']*1)+30||3h;1a=(m[\'A\']*1)+3g||3f;W=13-30;V=1a-3e;3(f.O(\'2j\')!=-1){1E=f.1B(\'3d\');$("#15").C();3(m[\'1A\']!="1b"){$("#8").q("<4 5=\'2f\'><4 5=\'1H\'>"+d+"</4><4 5=\'2e\'><a u=\'#\' 5=\'Z\' Q=\'1o\'>1l</a> 1k 1j 1s</4></4><U 1W=\'0\' 2d=\'0\' L=\'"+1E[0]+"\' 5=\'15\' 1v=\'15"+1f.2c(1f.1y()*2b)+"\' 1g=\'1m()\' J=\'z:"+(W+29)+"p;A:"+(V+17)+"p;\' > </U>")}n{$("#B").N();$("#8").q("<U 1W=\'0\' 2d=\'0\' L=\'"+1E[0]+"\' 5=\'15\' 1v=\'15"+1f.2c(1f.1y()*2b)+"\' 1g=\'1m()\' J=\'z:"+(W+29)+"p;A:"+(V+17)+"p;\'> </U>")}}n{3($("#8").r("Y")!="T"){3(m[\'1A\']!="1b"){$("#8").q("<4 5=\'2f\'><4 5=\'1H\'>"+d+"</4><4 5=\'2e\'><a u=\'#\' 5=\'Z\'>1l</a> 1k 1j 1s</4></4><4 5=\'F\' J=\'z:"+W+"p;A:"+V+"p\'></4>")}n{$("#B").N();$("#8").q("<4 5=\'F\' 3c=\'3b\' J=\'z:"+W+"p;A:"+V+"p;\'></4>")}}n{$("#F")[0].J.z=W+"p";$("#F")[0].J.A=V+"p";$("#F")[0].3a=0;$("#1H").11(d)}}$("#Z").s(G);3(f.O(\'37\')!=-1){$("#F").q($(\'#\'+m[\'26\']).1T());$("#8").24(9(){$(\'#\'+m[\'26\']).q($("#F").1T())});16();$("#K").C();$("#8").r({Y:"T"})}n 3(f.O(\'2j\')!=-1){16();3($.1q.35){$("#K").C();$("#8").r({Y:"T"})}}n{$("#F").34(f+="&1y="+(1p 33().32()),9(){16();$("#K").C();1u("#F a.18");$("#8").r({Y:"T"})})}}3(!m[\'1A\']){o.21=9(e){3(e==M){I=2w.2v}n{I=e.2u}3(I==27){G()}}}}31(e){}}9 1m(){$("#K").C();$("#8").r({Y:"T"})}9 G(){$("#2Y").N("s");$("#Z").N("s");$("#8").2X("2W",9(){$(\'#8,#B,#1F\').2V("24").N().C()});$("#K").C();3(2t o.v.J.2i=="2g"){$("v","11").r({A:"1Z",z:"1Z"});$("11").r("22","")}o.1h="";o.21="";H P}9 16(){$("#8").r({2U:\'-\'+20((13/2),10)+\'p\',z:13+\'p\'});3(!(1V.1q.2Q&&1V.1q.2P<7)){$("#8").r({38:\'-\'+20((1a/2),10)+\'p\'})}}9 2p(a){6 b={};3(!a){H b}6 c=a.1B(/[;&]/);25(6 i=0;i<c.1c;i++){6 d=c[i].1B(\'=\');3(!d||d.1c!=2){39}6 e=2a(d[0]);6 f=2a(d[1]);f=f.2r(/\\+/g,\' \');b[e]=f}H b}9 2x(){6 a=o.2M;6 w=1S.2o||1R.2o||(a&&a.1Q)||o.v.1Q;6 h=1S.1P||1R.1P||(a&&a.2n)||o.v.2n;1O=[w,h];H 1O}9 1K(){6 a=2K.2J.1C();3(a.O(\'2I\')!=-1&&a.O(\'3o\')!=-1){H 1b}}', 62, 211, '|||if|div|id|var||TB_window|function||||||||||||||else|document|px|append|css|click||href|body||||width|height|TB_overlay|remove|TB_Counter|TB_TempArray|TB_ajaxContent|tb_remove|return|keycode|style|TB_load|src|null|unbind|indexOf|false|title|TB_NextHTML|imgPreloader|block|iframe|ajaxContentH|ajaxContentW|this|display|TB_closeWindowButton||html|goPrev|TB_WIDTH|TB_PrevHTML|TB_iframeContent|tb_position||thickbox|tb_show|TB_HEIGHT|true|length|nbsp|span|Math|onload|onkeydown|goNext|Esc|or|close|tb_showIframe|TB_imageCount|Close|new|browser|TB_FoundURL|Key|Image|tb_init|name|imgLoader|TB_NextURL|random|TB_NextCaption|modal|split|toLowerCase|TB_PrevCaption|urlNoQuery|TB_HideSelect|TB_PrevURL|TB_ajaxWindowTitle|img|addClass|tb_detectMacXFF|TB_ImageOff|150|rel|arrayPageSize|innerHeight|clientWidth|self|window|children|TB_prev|jQuery|frameborder|TB_next|getElementById|auto|parseInt|onkeyup|overflow|alt|unload|for|inlineId||100||unescape|1000|round|hspace|TB_closeAjaxWindow|TB_title|undefined|match|maxHeight|TB_iframe|bmp|gif|png|clientHeight|innerWidth|tb_parseQuery|jpeg|replace|jpg|typeof|which|keyCode|event|tb_getPageSize|show|TB_overlayBG|TB_closeWindow|TB_overlayMacFFBGHack|TB_secondLine|TB_caption|blur|TB_Image|60|tb_pathToImage|mac|userAgent|navigator|of|documentElement|Prev|lt|version|msie|gt|ready|Next|marginLeft|trigger|fast|fadeOut|TB_imageOff|hidden||catch|getTime|Date|load|safari|get|TB_inline|marginTop|continue|scrollTop|TB_modal|class|TB_|45|440|40|630|input|188|190|substr|try|area|firefox'.split('|'), 0, {}))


function addCompareList(productId) {
    // alert("Bạn chỉ có thể so sánh tối đa 3 sản phẩm\nDanh sách đã có đủ 3");
    var checked = document.getElementById("compareItem_" + productId).checked;
    var currentList = document.getElementById("productCompareList").value;
    var currentNumItem = currentList.split(";").length - 2;
    var productImageUrl = document.getElementById("productHiddenImage_" + productId).value;
    var iconHtml = "<img src=\"" + productImageUrl + "\" width=30>";
    if (checked) {
        if (currentNumItem > 2) {
            //Cho phep so sánh tối đa 3 sản phẩm
            document.getElementById("compareItem_" + productId).checked = "";
            alert("Bạn chỉ có thể so sánh tối đa 3 sản phẩm\nDanh sách đã có đủ 3");
        }
        else {
            document.getElementById("productCompareList").value = currentList + productId + ";";
            //Thêm tiếp ảnh
            nextContainer = currentNumItem + 1;
            document.getElementById("compareItemContain_" + nextContainer).innerHTML = iconHtml;
            document.getElementById("compareItemContain2_" + nextContainer).innerHTML = iconHtml;
            document.getElementById("productItemContain_" + nextContainer).value = productId;
        }
    } else {
        document.getElementById("productCompareList").value = currentList.replace(";" + productId + ";", ";");
        //Xóa bỏ ảnh
        var containId = 0;
        for (var i = 1; i <= currentNumItem; i++) {
            var productContainer = document.getElementById("productItemContain_" + i).value;
            if (productContainer != "") {
                if (productId == productContainer) {
                    document.getElementById("compareItemContain_" + i).innerHTML = "";
                    document.getElementById("compareItemContain2_" + i).innerHTML = "";
                    document.getElementById("productItemContain_" + i).value = "";
                    containId = i;

                    break;
                }
            }
        }
        //Sắp xếp lại ảnh
        if (containId != 0) {
            arrangeImageContainer(containId, 3);
        }
    }
}

//Sắp xếp lại ảnh trong các container đảm bảo các ảnh từ 1 -> n
//startId là ID của container có ảnh bị remove, do đó cần được bù bằng ảnh khác nằm ở container lớn hơn gần nhất nếu có
//rồi lặp lại quá trình này cho container vừa bị lấy ảnh

function arrangeImageContainer(startId, maxNum) {
    var nextStartId = 0;
    for (var i = startId + 1; i <= maxNum; i++) {
        var contentHtml = document.getElementById("compareItemContain_" + i).innerHTML;
        var productContainer = document.getElementById("productItemContain_" + i).value;
        if (contentHtml.length > 2) {
            document.getElementById("compareItemContain_" + startId).innerHTML = contentHtml;
            document.getElementById("productItemContain_" + startId).value = productContainer;
            document.getElementById("compareItemContain_" + i).innerHTML = "";
            document.getElementById("compareItemContain2_" + i).innerHTML = "";
            document.getElementById("productItemContain_" + i).value = "";
            nextStartId = i;
            arrangeImageContainer(nextStartId, maxNum);
            break;
        }
    }
}

function goComparePage(categoryId) {
    var compareList = document.getElementById("productCompareList").value;
    var numberProduct = compareList.split(';').length;
    if (numberProduct > 3) {
        var re_href = window.location.href;
        re_href = re_href.replace('#&Filter', '&Filter');
        window.location.href = "/ProductCompare.aspx?List=" + compareList + "&CategoryId=" + categoryId + "&ReturnUrl=" + re_href + "";
        // alert(numberProduct);
    } else {
        alert("Bạn cần chọn ít nhất 2 sản phẩm để so sánh\nChọn sản phẩm bằng tích ô dưới ảnh sản phẩm");
    }
}

function showProductImage(imageName) {
    document.getElementById("productImageHolder").innerHTML = "<img src=\"Images/Product/" + imageName + "\">";
}

function saveProduct(productId) {
    $("#save_" + productId).load("ProductSave.aspx?ProductId=" + productId);
}

function choosePaymentOption(option) {
    var checked = document.getElementById(option).checked;
    var instId = document.getElementById(option).value;
    if (checked) {
        document.getElementById("selectPaymentMethod").value = instId;

        //Hide other options
        for (var i in paymentOptionList) {
            if (option != paymentOptionList[i]) {
                document.getElementById("pay_" + paymentOptionList[i]).style.display = "none";
                document.getElementById(paymentOptionList[i]).checked = false;
            }
        }
        //show the instruction
        document.getElementById("block_" + instId).style.display = "block";
    } else {
        document.getElementById("selectPaymentMethod").value = "";
        //Uncheck, show other options again
        for (var i in paymentOptionList) {
            document.getElementById("pay_" + paymentOptionList[i]).style.display = "block";
            document.getElementById(paymentOptionList[i]).checked = false;
            var elt = document.getElementById(paymentOptionList[i]).value;
            document.getElementById("block_" + elt).style.display = "none";
        }
    }
}

function showProductTap(id, tapId) {
    var checkdisplay = document.getElementById(id).style.display;
    var lastOpen = document.getElementById('lastOpenTap').value;
    var lastOpenId = document.getElementById('lastOpenTapId').value;
    //alert(lastOpen + " = " + lastOpenId);
    if (checkdisplay == "none") {
        //Close last open tap if exist       
        document.getElementById(lastOpen).style.display = "none";
        document.getElementById(lastOpenId).className = "product_menu_unselect";
        //Open new
        document.getElementById(id).style.display = "block";
        document.getElementById(tapId).className = "product_menu_select";
        document.getElementById('lastOpenTap').value = id;
        document.getElementById('lastOpenTapId').value = tapId;
    }
}

function showProductHistory() {
    $("#showHistoryProductView").load("ProductViewHistory.aspx");
}

function chooseShippingOption(method_id) {
    document.getElementById('selectShippingMethod').value = method_id;
}

function selectDistrict(province_id) {
    var last = document.getElementById('last_province').value;
    //if(last > 0){
    document.getElementById('district_select_' + last).style.display = "none";
    //}
    document.getElementById('district_select_' + province_id).style.display = "block";
    document.getElementById('last_province').value = province_id;
}

function chooseThisDistrict(dis_id) {
    document.getElementById('select_district').value = dis_id;
}

function showMap(map_name) {
    if (map_name.length > 1) {
        var url = "Media/Map" + map_name + ".html";
        openPopUp(url);
    }
}

//Login home page
function loginAccount() {
    var pass = document.getElementById('pass_login').value;
    var email = document.getElementById('email_login').value;
    //test value
    if (pass.length < 3 || email.length < 4) {
        alert('Vui lòng điền thông tin đăng nhập');
    } else {
        document.getElementById('sending_login').innerHTML = ' ... đang đăng nhập<br />';
        $.post("Login2.aspx", { password: pass, email: email },
       function(data) {
           document.getElementById('sending_login').innerHTML = '';
           if (data != 2) {
               document.getElementById('login_success').style.display = 'block';
               document.getElementById('form_home_login').style.display = 'none';
               document.getElementById('login_name').innerHTML = "<b>" + data + "</b>";

           } else {
               alert('Sai mật khẩu hoặc email');
           }
       });
    }
}

function trim(str, chars) {
    return ltrim(rtrim(str, chars), chars);
}
function ltrim(str, chars) {
    chars = chars || "s";
    return str.replace(new RegExp("^[" + chars + "]+", "g"), "");
}
function rtrim(str, chars) {
    chars = chars || "s";
    return str.replace(new RegExp("[" + chars + "]+$", "g"), "");
}

//Cookie
//kiem tra browser cho dung cookie khong
function checkBrowserEnableCookie() {
    var cookieEnabled = (navigator.cookieEnabled) ? true : false

    //if not IE4+ nor NS6+
    if (typeof navigator.cookieEnabled == "undefined" && !cookieEnabled) {
        document.cookie = "testcookie"
        cookieEnabled = (document.cookie.indexOf("testcookie") != -1) ? true : false
    }

    if (cookieEnabled) return true;
    else return false;

}
//kiem tra browser cho dung cookie khong
function checkBrowserEnableCookie() {
    var cookieEnabled = (navigator.cookieEnabled) ? true : false

    //if not IE4+ nor NS6+
    if (typeof navigator.cookieEnabled == "undefined" && !cookieEnabled) {
        document.cookie = "testcookie"
        cookieEnabled = (document.cookie.indexOf("testcookie") != -1) ? true : false
    }

    if (cookieEnabled) return true;
    else return false;

}

//tao cookie
function createCookie(name, value, days) {
    if (days) {
        var date = new Date();
        date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
        var expires = "; expires=" + date.toGMTString();
    }
    else var expires = "";
    document.cookie = name + "=" + value + expires + "; path=/";
}

//doc cookie
function readCookie(name) {
    var nameEQ = name + "=";
    var ca = document.cookie.split(';');
    for (var i = 0; i < ca.length; i++) {
        var c = ca[i];
        while (c.charAt(0) == ' ') c = c.substring(1, c.length);
        if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length, c.length);
    }
    return "";
}

//xoa bo cookie
function eraseCookie(name) {
    createCookie(name, "", -1);
}

//doc so luong san pham dang co trong gio hang
function countShoppingCart(name) {
    //tao cookie gio hang neu cua co
    if (readCookie(name) == "") {
        //createCookie(name,'',1);
        document.getElementById('count_shopping_cart').innerHTML = "0";
        //document.getElementById('count_shopping_cart_top').innerHTML = "<b>0</b>";
        //alert('create a new cookie shopping cart');
    } else {
        //add gia tri vao shopping cart
        var current_cart = readCookie(name);
        var ca = current_cart.split(',');
        number_product = ca.length - 1;
        document.getElementById('count_shopping_cart').innerHTML = "<b>" + number_product + "</b>";
        //document.getElementById('count_shopping_cart_top').innerHTML = "<b>" + number_product + "</b>";
    }
    //$("#shopping_cart_list").load("Cart/CartItemList.aspx");
}


function emptyShoppingCart(name) {
    createCookie(name, '-', 1);
}

//them san pham vao gio hang
function addToShoppingCart(productId, quantity) {
    if (parseInt(quantity) > 0)
        quantity = parseInt(quantity);
    else
        quantity = 1;

    //tao cookie gio hang neu cua co
    if (readCookie('shopping_cart') == null) {
        createCookie('shopping_cart', '', 1);
        //alert('create a new cookie shopping cart');
    }
    //add gia tri vao shopping cart
    var current_cart = readCookie('shopping_cart');

    //kiem tra xem da duoc them vao cart hay chua
    if (current_cart.search(',' + productId + '-') == -1) {
        var new_cart = current_cart + ',' + productId + '-' + quantity;
        createCookie('shopping_cart', new_cart, 1);
        //doc lai gia tri moi
        //alert(new_cart);
        //document.getElementById('value_shopping_cart').value = new_cart;
        countShoppingCart('shopping_cart');
        document.getElementById('item_' + productId).innerHTML = 'Đã thêm vào giỏ hàng';
    } else {

        alert('Sản phẩm này đã có trong giỏ hàng !');
    }
}

//Thêm sản phẩm giỏ hàng và chuyển tới trang giỏ hàng
function addToCartRedirect(productId, quantity) {
    if (parseInt(quantity) > 0)
        quantity = parseInt(quantity);
    else
        quantity = 1;

    if (readCookie('shopping_cart') == null) {
        createCookie('shopping_cart', '', 1);
    }
    var current_cart = readCookie('shopping_cart');

    if (current_cart.search(',' + productId + '-') == -1) {
        var new_cart = current_cart + ',' + productId + '-' + quantity;
        createCookie('shopping_cart', new_cart, 1);
        //countShoppingCart('shopping_cart');
        window.location = "/Cart/Cart.aspx";
    } else {
        alert('Sản phẩm này đã có trong giỏ hàng !');
    }
}

function checkItemInCart(productId) {
    var current_cart = readCookie('shopping_cart');
    //kiem tra xem da duoc them vao cart hay chua
    if (current_cart.search(',' + productId + '-') != -1) {
        document.write('Đang trong giỏ hàng');
    }
}

//xoa bo item trong cart
function deleteFromCart(productId, quantity) {
    if (confirm('Bạn muốn xóa sản phẩm này khỏi giỏ hàng ? ')) {
        var current_cart = readCookie('shopping_cart');
        new_cart = current_cart.replace("," + productId + '-' + quantity, "");
        new_cart = new_cart.replace("," + productId + '-', "0");
        createCookie('shopping_cart', new_cart, 1);
        countShoppingCart('shopping_cart');
        //ok nhay ve trang gio hang moi
        //window.location.href ='Cart.aspx';

        //load ajax load-ajax-cart
        var _time = new Date().getTime();
        $.get('/Classes/GetCart.ashx?time=' + _time + '', function(data) {
            $("#cart-products-order").html(data);
        });
    }
}

//cap nhat so luong san pham trong cart
function updateCart(productId, quantity) {
    var newquantity = document.getElementById("item_" + productId).value;
    newquantity = parseInt(newquantity);
    if (newquantity < 1) {
        //Nếu cập nhật số lượng < 1 thì coi như là xóa sản phẩm khỏi cart
        deleteFromCart(productId, quantity);
    } else {
        if (newquantity > 99) {
            alert('Bạn chỉ được phép mua tối đa số lượng 99 cho mỗi sản phẩm');
            newquantity = 99;
        }
        var current_cart = readCookie('shopping_cart');
        new_cart = current_cart.replace("," + productId + '-' + quantity, "," + productId + '-' + newquantity);
        createCookie('shopping_cart', new_cart, 1);
        countShoppingCart('shopping_cart');
        //ok nhay ve trang gio hang moi
        //window.location.href ='Cart.aspx';

        //load ajax load-ajax-cart
        var _time = new Date().getTime();
        $.get('/Classes/GetCart.ashx?time=' + _time + '', function(data) {
            $("#cart-products-order").html(data);
        });
    }
}

//Luu danh sach san pham da xem
function addToViewHistory(productId) {
    if (readCookie('product_history') == null) {
        createCookie('product_history', ',', 1);
    }
    var current_list = readCookie('product_history');
    if (current_list.search(',' + productId + ',') == -1) {
        var new_list = "," + productId + current_list;
        createCookie('product_history', new_list, 1);
    }
    ///alert(current_list);
}

//File global
function MM_preloadImages() { //v3.0
    var d = document; if (d.images) {
        if (!d.MM_p) d.MM_p = new Array();
        var i, j = d.MM_p.length, a = MM_preloadImages.arguments; for (i = 0; i < a.length; i++)
            if (a[i].indexOf("#") != 0) { d.MM_p[j] = new Image; d.MM_p[j++].src = a[i]; }
    }
}

function MM_swapImgRestore() { //v3.0
    var i, x, a = document.MM_sr; for (i = 0; a && i < a.length && (x = a[i]) && x.oSrc; i++) x.src = x.oSrc;
}

function MM_findObj(n, d) { //v4.01
    var p, i, x; if (!d) d = document; if ((p = n.indexOf("?")) > 0 && parent.frames.length) {
        d = parent.frames[n.substring(p + 1)].document; n = n.substring(0, p);
    }
    if (!(x = d[n]) && d.all) x = d.all[n]; for (i = 0; !x && i < d.forms.length; i++) x = d.forms[i][n];
    for (i = 0; !x && d.layers && i < d.layers.length; i++) x = MM_findObj(n, d.layers[i].document);
    if (!x && d.getElementById) x = d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
    var i, j = 0, x, a = MM_swapImage.arguments; document.MM_sr = new Array; for (i = 0; i < (a.length - 2); i += 3)
        if ((x = MM_findObj(a[i])) != null) { document.MM_sr[j++] = x; if (!x.oSrc) x.oSrc = x.src; x.src = a[i + 2]; }
}


function searchByBrandRangPrice() {

    var keywork = document.getElementById('iptKeyWork').value;
    if (keywork.length <= 1 || keywork == 'Nhập từ khóa cần tìm kiếm...')
        alert("Bạn chưa nhập từ khóa tìm kiếm!");
    else {
        var url = window.location.toString();
        var brand = document.getElementById('selectBrand').value;
        var min = document.getElementById('selectMinPrice').value;
        var max = document.getElementById('selectMaxPrice').value;
        var RegKeyWord = /&?Keyword=.*&?/i;
        var RegBrand = /&?Brand=[\-0-9]*&?/i;
        var RegMax = /&?Max=[\-0-9]*&?/i;
        var RegMin = /&?Min=[\-0-9]*&?/i;

        var keywordReplaceStr = '?&Keyword=' + keywork;

        var brandReplaceStr = '&Brand=' + brand;

        var minReplaceStr = '&Min=' + min;

        var maxReplaceStr = '&Max=' + max;

        if (url.indexOf("&Keyword=") > -1)
            url = url.replace(RegKeyWord, keywordReplaceStr);
        else url += keywordReplaceStr;

        if (url.indexOf("&Brand=") > -1)
            url = url.replace(RegBrand, brandReplaceStr);
        else if (brand > 0)
            url += brandReplaceStr;
        if (url.indexOf("&Min=") > -1)
            url = url.replace(RegMin, minReplaceStr);
        else if (min > 0)
            url += minReplaceStr;
        if (url.indexOf("&Max=") > -1)
            url = url.replace(RegMax, maxReplaceStr);
        else if (max > 0)
            url += maxReplaceStr;
        window.open(url, "_self", null, true);
    }
}

function showPopupLinkGlobalPopup2(proId, poptype, width, height, relateId) {

    var checked = document.getElementById("ProductListCheckBox_" + proId).checked;
    if (checked) {
        tb_show("<b>Đăng ký đặt hàng online giá rẻ hơn</b>", "/GlobalPopup.aspx?width=" + width + "&height=" + height + "&proId=" + proId + "&type=" + poptype + "&relate=" + relateId, null);

    }
}

function showPopupLinkGlobalPopup(proId, poptype, width, height, relateId) {
    var extratext = null;
    if (poptype == "QickOrder") extratext = "<b>Đăng ký đặt hàng online giá rẻ hơn</b>";
    if (poptype == "mailSend") extratext = "<b>Nhận Mail</b>";
    //tb_show(extratext, "/GlobalPopup.aspx?width=" + width + "&height=" + height + "&proId=" + proId + "&type=" + poptype + "&relate=" + relateId, null);
    tb_show(extratext, "/GlobalPopup.aspx?width=" + width + "&height=" + height + "&proId=" + proId + "&type=" + poptype + "&relate=" + relateId, null);
}

function changeViewType(viewType) {
    //    var RegViewType = /&?keyword=.*&?/i;
    //    var keywordReplaceStr = '&keyword=' + keywork;
    var url = window.location.toString();
    if (viewType == 1) {
        //        if (url.indexOf("&TypeView=thumbnail") == -1) 
        //        {
        url = url.replace('&TypeView=thumbnail', '');
        //        }

    }
    else {
        if (viewType == 2) {

            if (url.indexOf("?&TypeView=thumbnail") == -1) {
                url += '?&TypeView=thumbnail';
            }
        }
    }

    window.open(url, "_self", null, true);
}

function ActivedHotProduct(proId) {
    $.ajax
    (
    {
        type: "POST",
        data: "{productId:" + proId + "}",
        //data: "{productId:1926,customerName:'tran dau',customerNoPhone:89898989,customerEmail:trandau@gmail.com,salesPrice:2514,orderProductCurrency:vnd}",
        contentType: "application/json; charset=utf-8",
        url: "/websevices/Admin.asmx/ActivedHotProduct",
        dataType: "json",
        success: function(data) {
            window.location.reload();
            //            data = data.d;
            //            alert(data);
        }
    }
    );
}

function DisActivedHotProduct(proId) {

    $.ajax
    (
    {
        type: "POST",
        data: "{productId:" + proId + "}",
        //data: "{productId:1926,customerName:'tran dau',customerNoPhone:89898989,customerEmail:trandau@gmail.com,salesPrice:2514,orderProductCurrency:vnd}",
        contentType: "application/json; charset=utf-8",
        url: "/websevices/Admin.asmx/DisActivedHotProduct",
        dataType: "json",
        success: function(data) {
            window.location.reload();
        }
    }
    );
}
function DisActivedHotProduct(proId) {

    $.ajax
    (
    {
        type: "POST",
        data: "{productId:" + proId + "}",
        //data: "{productId:1926,customerName:'tran dau',customerNoPhone:89898989,customerEmail:trandau@gmail.com,salesPrice:2514,orderProductCurrency:vnd}",
        contentType: "application/json; charset=utf-8",
        url: "/websevices/Admin.asmx/DisActivedHotProduct",
        dataType: "json",
        success: function(data) {
            window.location.reload();
        }
    }
    );
}


function ActiveComments(commentId) {
    $.ajax
    (
    {
        type: "POST",
        data: "{commentId:" + commentId + "}",
        //data: "{productId:1926,customerName:'tran dau',customerNoPhone:89898989,customerEmail:trandau@gmail.com,salesPrice:2514,orderProductCurrency:vnd}",
        contentType: "application/json; charset=utf-8",
        url: "/websevices/Admin.asmx/ActiveComments",
        dataType: "json",
        success: function(data) {
            window.location.reload();
        }
    }
    );
}

function DisActiveComments(commentId) {
    $.ajax
    (
    {
        type: "POST",
        data: "{commentId:" + commentId + "}",
        //data: "{productId:1926,customerName:'tran dau',customerNoPhone:89898989,customerEmail:trandau@gmail.com,salesPrice:2514,orderProductCurrency:vnd}",
        contentType: "application/json; charset=utf-8",
        url: "/websevices/Admin.asmx/DisActiveComments",
        dataType: "json",
        success: function(data) {
            window.location.reload();
        }
    }
    );
}

function DisActiveBannerText(Id) {
    $.ajax
    (
    {
        type: "POST",
        data: "{Id:" + Id + "}",
        contentType: "application/json; charset=utf-8",
        url: "/websevices/Admin.asmx/DisActiveBannerText",
        dataType: "json",
        success: function(data) {
            window.location.reload();
        }
    }
    );
}

function ActiveBannerText(Id) {
    $.ajax
    (
    {

        type: "POST",
        data: "{Id:" + Id + "}",
        contentType: "application/json; charset=utf-8",
        url: "/websevices/Admin.asmx/ActiveBannerText",
        dataType: "json",
        success: function(data) {
            window.location.reload();
        }
    }
    );
}

