﻿/********* GOLBAL *****************/

function getUrlVars() {
    var vars = [], hash;
    var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
    for (var i = 0; i < hashes.length; i++) {
        hash = hashes[i].split('=');
        vars.push(hash[0]);
        vars[hash[0]] = hash[1];
    }
    var temp = vars[0];
    if (temp.indexOf("http") == 0) {
        return vars;
    } else {
        return '/Default.aspx';
    }
}
function Trim(iStr) {
    while (iStr.charCodeAt(0) <= 32) {
        iStr = iStr.substr(1);
    }

    while (iStr.charCodeAt(iStr.length - 1) <= 32) {
        iStr = iStr.substr(0, iStr.length - 1);
    }

    return iStr;
}
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"), "");
}

//Hungnv - Trả về tên của trình duyệt
function getBrowserName() {
    var browserName = "";

    var ua = navigator.userAgent.toLowerCase();
    if (ua.indexOf("opera") != -1) {
        browserName = "opera";
    } else if (ua.indexOf("msie") != -1) {
        browserName = "msie";
    } else if (ua.indexOf("safari") != -1) {
        browserName = "safari";
    } else if (ua.indexOf("mozilla") != -1) {
        if (ua.indexOf("firefox") != -1) {
            browserName = "firefox";
        } else {
            browserName = "mozilla";
        }
    }

    return browserName;
};

// Hungnv -  Hàm lấy chuỗi đằng sau một ký tự được chỉ định
function Slips(current_str, find_str) {
    var cL = current_str.length;
    var fL = find_str.length;
    var pos = current_str.lastIndexOf(find_str);
    if (pos + fL >= cL)
        return "";
    else if (pos == -1)
        return current_str;
    else
        return current_str.substring(pos + fL, cL);
}

// Hungnv - Hàm trả về giá trị tham số đầu tiên trong chuối URL
function SlipsFirstParam(current_str, find_str) {
    var cL = current_str.length;
    var fL = find_str.length;
    var pos = current_str.indexOf(find_str);

    if (pos + fL >= cL)
        return "";
    else if (pos == -1)
        return current_str;
    else {

        var strTem = current_str.substring(pos + fL, cL);
        var posNew = strTem.indexOf("&");

        return strTem.substring(0, posNew);

    }
}

// Hungnv - Lấy giá trị của Control Radio
function getCheckedValue(radioObj) {
    if (!radioObj)
        return "";
    var radioLength = radioObj.length;
    if (radioLength == undefined)
        if (radioObj.checked)
        return radioObj.value;
    else
        return "";
    for (var i = 0; i < radioLength; i++) {
        if (radioObj[i].checked) {
            return radioObj[i].value;
        }
    }
    return "";
}

function replaceDot(str) {
    var result = "";

    for (i = 0; i < str.length; i++) {
        result += Trim(str[i]).replace(".", "");
    }

    return result;
}

//Hungnv
function validateForm(frm) {
    for (var i = 0; i < 1; i++) {
        try {
            if (document.getElementById("ctl00_MainContent_chkStock_" + i).checked != true) {
                alert("Xin vui lòng chọn kho hàng!");
                return false;
            }
        }
        catch (Error) { }
    }
    //        if (frm.ctl00_MainContent_chkStock_0.checked != true || frm.ctl00_MainContent_chkStock_1.checked != true) {
    //        alert("Xin vui lòng chọn kho hàng!");
    //        return false;
    //    }
    if (frm.ctl00$MainContent$txtProductName != null)
        if (Trim(frm.ctl00$MainContent$txtProductName.value) == "") {
            alert("Xin vui lòng nhập vào tên sản phẩm!");
            frm.ctl00$MainContent$txtProductName.focus();
            return false;
        }
    //    if (document.getElementById("cboCatalog").value == -1) {
    //        alert("Xin vui lòng chọn Chuyên mục đăng bán!");
    //        document.getElementById("cboCatalog").focus();
    //        return false;
    //    }
    try {
        if (Trim(frm.ctl00_MainContent_txtDesc.value) == "" || Trim(frm.ctl00_MainContent_txtDesc.value) == "Thông tin này được hiển thị trong phần listing sản phẩm, bắt buộc phải nhập") {
            alert("Xin vui lòng nhập mô tả vắn tắt!");
            frm.ctl00_MainContent_txtDesc.focus();
            return false;
        }
    } catch (err) { }

    try {
        if (Trim(frm.ctl00$MainContent$txtPrice.value) == "" || Trim(frm.ctl00$MainContent$txtPrice.value) == "Giá bán") {
            alert("Xin vui lòng nhập vào giá bán!");
            frm.ctl00$MainContent$txtPrice.focus();
            return false;
        }
    }
    catch (err) { }
    

    try {
        if (Trim(frm.ctl00$MainContent$txtPrice.value) == "" || Trim(frm.ctl00$MainContent$txtPrice.value) == "Giá bán/Cho thuê") {
            alert("Xin vui lòng nhập vào giá bán!");
            frm.ctl00$MainContent$txtPrice.focus();
            return false;
        }
    }
    catch (err) { }

    try {
        if (Trim(frm.ctl00_MainContent_txtPricePromotion.value) == "" || Trim(frm.ctl00_MainContent_txtPricePromotion.value) == "Giá thị trường") {
            frm.ctl00_MainContent_txtPricePromotion = "0";
        }
    }
    catch (err) { }

    try {
        if (Trim(frm.ctl00$MainContent$txtPrice.value) != "" && Trim(frm.ctl00$MainContent$txtPrice.value) != "Giá bán" && Trim(frm.ctl00_MainContent_txtPricePromotion.value) != "Giá thị trường") {
            //if (parseInt(Trim(frm.ctl00$MainContent$txtPrice.value).replace(".", "")) <= parseInt(Trim(frm.ctl00_MainContent_txtPricePromotion.value).replace(".", ""))) {
            if (parseInt(replaceDot(frm.ctl00$MainContent$txtPrice.value).replace(".", "")) > parseInt(replaceDot(frm.ctl00_MainContent_txtPricePromotion.value).replace(".", ""))) {
                alert("Giá thị trường không hợp lệ!");
                frm.ctl00_MainContent_txtPricePromotion.focus();
                return false;
            }

        }
    }
    catch (err) { }

    try {
        if (Trim(frm.ctl00$MainContent$txtColor.value) == "" || Trim(frm.ctl00$MainContent$txtColor.value) == "Ghi chú (màu/kích thước/...)") {
            alert("Xin vui lòng nhập vào ghi chú màu!");
            frm.ctl00$MainContent$txtColor.focus();
            return false;
        }
    }
    catch (err) { }

    try {
        if (frm.txtPriceOther.length != undefined) {

            for (var i = 1; i < frm.txtPriceOther.length; i++) {
                if (Trim(frm.txtPriceOther[i].value) == "" || Trim(frm.txtPriceOther[i].value) == "Giá bán") {
                    alert("Xin vui lòng nhập đầy đủ giá bán khác!");
                    frm.txtPriceOther[i].focus();
                    return false;
                    break;
                }
                if (Trim(frm.txtPriceOtherPromo[i].value) == "" || Trim(frm.txtPriceOtherPromo[i].value) == "Giá thị trường") {
                    frm.txtPriceOtherPromo[i].value = "0";
                }
                if (Trim(frm.txtPriceDescOther[i].value) == "Ghi chú (màu/kích thước/...)" || Trim(frm.txtPriceDescOther[i].value) == "") {
                    alert("Xin vui lòng nhập đầy đủ ghi chú màu cho giá bán khác!");
                    frm.txtPriceDescOther[i].focus();
                    return false;
                    break;
                }
            }
        }
    }
    catch (err) { }
    //check giá thị trường so với giá bán(1/3/2010) ----25/3/2010
    try {
        for (var i = 1; i < frm.txtPriceOther.length; i++) {
            if (parseInt(frm.txtPriceOther[i].value.replace(".", "")) > parseInt(frm.txtPriceOtherPromo[i].value.replace(".", ""))) {
                alert("Giá thị trường không hợp lệ");
                frm.txtPriceOtherPromo[i].focus();
                return false;
            }
        }

    } catch (err) { }

    try {
        if (Trim(frm.ctl00$MainContent$txtDesc.value) == "") {
            alert("Xin vui lòng nhập vào mô tả vắn tắt!");
            frm.ctl00$MainContent$txtDesc.focus();
            return false;
        }
    }
    catch (err) { }

    try {
        if (Trim(frm.ctl00$MainContent$ddlCateChild.value) == "Chọn chủng loại sản phẩm") {
            alert("Xin vui lòng chọn chủng loại sản phẩm!");
            frm.ctl00$MainContent$ddlCateChild.focus();
            return false;
        }
    }
    catch (err) { }

    try {
        if (Trim(frm.ctl00$MainContent$ddlLocation.value) == "-1") {
            alert("Xin vui lòng chọn tỉnh thành!");
            frm.ctl00$MainContent$ddlLocation.focus();
            return false;
        }
    }
    catch (err) { }

    try {
        var content = document.getElementById("txtContent_ifr").contentWindow.document.body.innerHTML;

        content = content.replace(/<p>/g, "");
        content = content.replace(/<\/p>/g, "");
        content = content.replace(/<br>/g, "");
        content = content.replace(/&nbsp;/g, "");
        content = content.replace(/<br mce_bogus="1"\>/g, "");
        content = content.replace(/<br _moz_editor_bogus_node="TRUE" _moz_dirty=""\>/g, "");

        content = Trim(content);

        if (content == "") {
            alert("Xin vui lòng nhập mô tả sản phẩm!");
            document.getElementById("txtContent_ifr").focus();
            return false;
        }
    }
    catch (err) { }

    //dtnghia check danh muc
    try {
        if (document.getElementById("cboCatalog").value == -1) {
            alert("Xin vui lòng chọn Chuyên mục đăng bán!");
            document.getElementById("cboCatalog").focus();
            return false;
        }
    }
    catch (err) { }

    //dtNghia
    //check file anh co hop le ko de cho phep submit form

    if (getBrowserName() == "msie") {
        for (i = 0; i < parent.frames.length; i++) {
            if (parent.frames[i].document.forms[0] != undefined) {
                //alert(parent.frames[3].document.forms[0].FileName.value);
                if (i != 0 && i != 2) {
                    if (parent.frames[i].document.forms[0].FileName.value.toLowerCase().indexOf(".jpg") == -1 && parent.frames[i].document.forms[0].FileName.value.toLowerCase().indexOf(".png") == -1 && parent.frames[i].document.forms[0].FileName.value.toLowerCase().indexOf(".gif") == -1 && parent.frames[i].document.forms[0].FileName.value.toLowerCase().indexOf(".bmp") == -1) {
                        alert("File ảnh không hợp lệ !");
                        return false;
                        break;
                    }
                }
            }
        }
    }
    else {
        for (i = 0; i < parent.frames.length; i++) {
            if (parent.frames[i].document.forms[0] != undefined) {
                //alert(parent.frames[3].document.forms[0].FileName.value);
                if (i != 1 && i != 2) {
                    if (parent.frames[i].document.forms[0].FileName.value.toLowerCase().indexOf(".jpg") == -1 && parent.frames[i].document.forms[0].FileName.value.toLowerCase().indexOf(".png") == -1 && parent.frames[i].document.forms[0].FileName.value.toLowerCase().indexOf(".gif") == -1 && parent.frames[i].document.forms[0].FileName.value.toLowerCase().indexOf(".bmp") == -1) {
                        alert("File ảnh không hợp lệ !");
                        return false;
                        break;
                    }
                }
            }
        }
    }

    for (i = 0; i < parent.frames.length; i++) {
        if (parent.frames[i].document.forms[0] != undefined) {
            if (i != 1 && i != 2) {
                if (parent.frames[i].document.forms[0].hddUploadSucsess.value == 0) {
                    if (parent.frames[i].document.forms[0].file.value == "") {
                        alert("Xin vui lòng chọn ảnh minh họa cho sản phẩm!");
                        return false;
                        break;
                    }
                }
            }
        }
    }


    //    if (Trim(frm.ctl00_MainContent_txtPayInfo.value) == "") {
    //        alert("Xin vui lòng thông tin hướng dẫn thanh toán!");
    //        frm.ctl00_MainContent_txtPayInfo.focus();
    //        return false;
    //    }

    var flgRedirect = true;
    for (i = 0; i < parent.frames.length; i++) {
        if (parent.frames[i].document.forms[0] != undefined) {
            if (i != 1 && i != 2) {
                if (parent.frames[i].document.forms[0].hddUploadSucsess.value == 0) {
                    alert("Hệ thống đang thực hiện tải file! \n Xin vui lòng chờ trong giây lát.");
                    flgRedirect = false;
                    return false;
                    break;
                }
            }
        }
    }

    if (getBrowserName() == "msie") {
        if (flgRedirect) {
            var listFile = "";
            for (i = 0; i < parent.frames.length; i++) {
                if (parent.frames[i].document.forms[0] != undefined) {
                    if (i != 0 && i != 2) {
                        if (parent.frames[i].document.forms[0].FileName.value != "") {
                            listFile += parent.frames[i].document.forms[0].FileName.value + ";";
                        }
                    }
                }
            }

            if (frm.ctl00$MainContent$hddImageList != null)
                frm.ctl00$MainContent$hddImageList.value = listFile;
        }
    }
    else {
        if (flgRedirect) {
            var listFile = "";
            for (i = 0; i < parent.frames.length; i++) {
                if (parent.frames[i].document.forms[0] != undefined) {
                    if (i != 1 && i != 2) {
                        if (parent.frames[i].document.forms[0].FileName.value != "") {
                            listFile += parent.frames[i].document.forms[0].FileName.value + ";";
                        }
                    }
                }
            }

            if (frm.ctl00$MainContent$hddImageList != null)
                frm.ctl00$MainContent$hddImageList.value = listFile;
        }
    }


    if (frm.ctl00$MainContent$txtWeight != undefined) {
        if (Trim(frm.ctl00$MainContent$txtWeight.value) == "") {
            alert("Xin vui lòng nhập vào trọng lượng sản phẩm!");
            frm.ctl00$MainContent$txtWeight.focus();
            return false;
        }

        //        if (frm.chkStockHN.checked != true && frm.chkStockHCM.checked != true) {
        //            alert("Xin vui lòng chọn kho lưu sản phẩm!");
        //            frm.chkStockHCM.focus();
        //            return false;
        //        }
        //        if (frm.chkStockHN.checked) {
        //            if (frm.hddActionHN.value == 2) {
        //                if (Trim(frm.txtHNAddress.value) == "") {
        //                    alert("Xin vui lòng nhập vào địa chỉ kho hàng tại Hà Nội!");
        //                    frm.txtHNAddress.focus();
        //                    return false;
        //                }
        //            }
        //        }
        //        if (frm.chkStockHCM.checked) {
        //            if (frm.hddActionHCM.value == 2) {
        //                if (Trim(frm.txtHCMAddress.value) == "") {
        //                    alert("Xin vui lòng nhập vào địa chỉ kho hàng tại Hồ Chí Minh!");
        //                    frm.txtHCMAddress.focus();
        //                    return false;
        //                }
        //            }
        //        }
    }

    return true;
}

//Hungnv 
// validate update form
function validateFormE(frm) {
    for (var i = 0; i < 1; i++) {
        try {
            if (document.getElementById("ctl00_MainContent_chkStock_" + i).checked != true) {
                alert("Xin vui lòng chọn một kho hàng!");
                return false;
            }
        }
        catch (Error) { }
    }
    
    if (Trim(frm.ctl00$MainContent$txtProductName.value) == "") {
        alert("Xin vui lòng nhập vào tên sản phẩm!");
        frm.ctl00$MainContent$txtProductName.focus();
        return false;
    }

    try {
        if (Trim(frm.ctl00_MainContent_txtDesc.value) == "" || Trim(frm.ctl00_MainContent_txtDesc.value) == "Thông tin này được hiển thị trong phần listing sản phẩm, bắt buộc phải nhập") {
            alert("Xin vui lòng nhập mô tả vắn tắt!");
            frm.ctl00_MainContent_txtDesc.focus();
            return false;
        }
    } catch (err) { }

    try {
        if (document.getElementById("cboCatalog").value == -1) {
            alert("Xin vui lòng chọn Chuyên mục đăng bán!");
            document.getElementById("cboCatalog").focus();
            return false;
        }
    }
    catch (err) { }

    try {
        if (Trim(frm.ctl00$MainContent$txtPrice.value) == "" || Trim(frm.ctl00$MainContent$txtPrice.value) == "Giá bán") {
            alert("Xin vui lòng nhập vào giá bán!");
            frm.ctl00$MainContent$txtPrice.focus();
            return false;
        }
    }
    catch (err) { }

    try {
        if (Trim(frm.ctl00_MainContent_txtPricePromotion.value) == "" || Trim(frm.ctl00_MainContent_txtPricePromotion.value) == "Giá thị trường") {
            frm.ctl00_MainContent_txtPricePromotion = "0";
        }
    }
    catch (err) { }

    try {
        if (Trim(frm.ctl00$MainContent$txtPrice.value) != "" && Trim(frm.ctl00$MainContent$txtPrice.value) != "Giá bán" && Trim(frm.ctl00_MainContent_txtPricePromotion.value) != "Giá thị trường" && Trim(frm.ct100_MainContent_txtPricePromotion.value) != "0") {
            if (parseInt(replaceDot(frm.ctl00$MainContent$txtPrice.value).replace(".", "")) > parseInt(replaceDot(frm.ctl00_MainContent_txtPricePromotion.value).replace(".", ""))) {
                alert("Giá thị trường không hợp lệ!");
                frm.ctl00_MainContent_txtPricePromotion.focus();
                return false;
            }
        }
    }
    catch (err) { }

    try {
        if (Trim(frm.ctl00$MainContent$txtColor.value) == "" || Trim(frm.ctl00$MainContent$txtColor.value) == "Ghi chú (màu/kích thước/...)") {
            alert("Xin vui lòng nhập vào ghi chú màu!");
            frm.ctl00$MainContent$txtColor.focus();
            return false;
        }
    }
    catch (err) { }

    try {
        if (frm.txtPriceOther.length != undefined) {

            for (var i = 1; i < frm.txtPriceOther.length; i++) {
                if (Trim(frm.txtPriceOther[i].value) == "" || Trim(frm.txtPriceOther[i].value) == "Giá bán") {
                    alert("Xin vui lòng nhập đầy đủ giá bán khác!");
                    frm.txtPriceOther[i].focus();
                    return false;
                    break;
                }
                //validate giá thị trường với giá bán
                try {
                    for (var i = 1; i < frm.txtPriceOther.length; i++) {
                        if (parseInt(frm.txtPriceOther[i].value.replace(".", "")) > parseInt(frm.txtPriceOtherPromo[i].value.replace(".", ""))) {
                            alert("Giá thị trường không hợp lệ");
                            frm.txtPriceOtherPromo[i].focus();
                            return false;
                        }
                    }

                } catch (err) { }

                //------------------------------------- 

                if (Trim(frm.txtPriceOtherPromo[i].value) == "" || Trim(frm.txtPriceOtherPromo[i].value) == "Giá thị trường") {
                    frm.txtPriceOtherPromo[i].value = "0";
                }
                if (Trim(frm.txtPriceDescOther[i].value) == "Ghi chú (màu/kích thước/...)" || Trim(frm.txtPriceDescOther[i].value) == "") {
                    alert("Xin vui lòng nhập đầy đủ ghi chú màu cho giá bán khác!");
                    frm.txtPriceDescOther[i].focus();
                    return false;
                    break;
                }
            }
        }
    }
    catch (err) { }

    try {
        if (Trim(frm.ctl00$MainContent$txtDesc.value) == "") {
            alert("Xin vui lòng nhập vào mô tả vắn tắt!");
            frm.ctl00$MainContent$txtDesc.focus();
            return false;
        }
    }
    catch (err) { }

    try {
        if (Trim(frm.ctl00$MainContent$txtDesc.value) == "Thông tin này được hiển thị trong phần listing sản phẩm, bắt buộc phải nhập") {
            alert("Xin vui lòng nhập vào mô tả vắn tắt!");
            frm.ctl00$MainContent$txtDesc.focus();
            return false;
        }
    }
    catch (err) { }

    try {
        var content = document.getElementById("txtContent_ifr").contentWindow.document.body.innerHTML;

        content = content.replace(/<p>/g, "");
        content = content.replace(/<\/p>/g, "");
        content = content.replace(/<br>/g, "");
        content = content.replace(/&nbsp;/g, "");
        content = content.replace(/<br mce_bogus="1"\>/g, "");
        content = content.replace(/<br _moz_editor_bogus_node="TRUE" _moz_dirty=""\>/g, "");

        content = Trim(content);

        if (content == "") {
            alert("Xin vui lòng nhập mô tả sản phẩm!");
            document.getElementById("txtContent_ifr").focus();
            return false;
        }
    }
    catch (err) { }

    try {
        //dtNghia
        //check file anh
        for (i = 0; i < parent.frames.length; i++) {
            if (parent.frames[i].document.forms[0] != undefined) {
                if (i != 1) {
                    //alert(parent.frames[i].document.forms[0].FileName);
                    //minhdv 5/3/2010
                    if (parent.frames[i].document.forms[0].FileName.value != "" && parent.frames[i].document.forms[0].FileName.value.toLowerCase().indexOf(".jpg") == -1 && parent.frames[i].document.forms[0].FileName.value.toLowerCase().indexOf(".png") == -1 && parent.frames[i].document.forms[0].FileName.value.toLowerCase().indexOf(".gif") == -1 && parent.frames[i].document.forms[0].FileName.value.toLowerCase().indexOf(".bmp") == -1 && parent.frames[i].document.forms[0].FileName.value.toLowerCase().indexOf(".jpeg") == -1) {
                        alert("File ảnh không hợp lệ ! " + parent.frames[i].document.forms[0].FileName.value.toLowerCase());
                        return false;
                        break;
                    }
                }
            }
        }
    }
    catch (err) { }

    try {
        for (i = 0; i < parent.frames.length; i++) {
            if (parent.frames[i].document.forms[0] != undefined) {
                if (i != 1) {
                    if (parent.frames[i].document.forms[0].hddUploadSucsess.value == 0) {
                        if (parent.frames[i].document.forms[0].FileName.value == "") {
                            alert("Xin vui lòng chọn ảnh minh họa cho sản phẩm!");
                            return false;
                            break;
                        }
                    }
                }
            }
        }
    } catch (err) { }


    //    if (Trim(frm.ctl00_MainContent_txtPayInfo.value) == "") {
    //        alert("Xin vui lòng thông tin hướng dẫn thanh toán!");
    //        frm.ctl00_MainContent_txtPayInfo.focus();
    //        return false;
    //    }

    var flgRedirect = true;

    try {

        for (i = 0; i < parent.frames.length - 1; i++) {
            if (parent.frames[i].document.forms[0] != undefined) {
                if (i != 1) {
                    if (parent.frames[i].document.forms[0].hddUploadSucsess.value == 0) {
                        alert("Hệ thống đang thực hiện tải file! \n Xin vui lòng chờ trong giây lát.");
                        flgRedirect = false;
                        return false;
                        break;
                    }
                }
            }
        }

        if (flgRedirect) {
            var listFile = "";
            for (i = 0; i < parent.frames.length; i++) {
                if (parent.frames[i].document.forms[0] != undefined) {
                    if (i != 1) {
                        if (parent.frames[i].document.forms[0].FileName.value != "") {
                            listFile += parent.frames[i].document.forms[0].FileName.value + ";";
                        }
                    }
                }
            }
            //alert(listFile);
            frm.ctl00$MainContent$hddImageList.value = listFile;
        }
    } catch (err) { }

    if (frm.ctl00$MainContent$txtWeight != undefined) {
        if (Trim(frm.ctl00$MainContent$txtWeight.value) == "") {
            alert("Xin vui lòng nhập vào trọng lượng sản phẩm!");
            frm.ctl00$MainContent$txtWeight.focus();
            return false;
        }

        //        if (frm.chkStockHN.checked != true && frm.chkStockHCM.checked != true) {
        //            alert("Xin vui lòng chọn kho lưu sản phẩm!");
        //            frm.chkStockHCM.focus();
        //            return false;
        //        }
        //        if (frm.chkStockHN.checked) {
        //            if (frm.hddActionHN.value == 2) {
        //                if (Trim(frm.txtHNAddress.value) == "") {
        //                    alert("Xin vui lòng nhập vào địa chỉ kho hàng tại Hà Nội!");
        //                    frm.txtHNAddress.focus();
        //                    return false;
        //                }
        //            }
        //        }
        //        if (frm.chkStockHCM.checked) {
        //            if (frm.hddActionHCM.value == 2) {
        //                if (Trim(frm.txtHCMAddress.value) == "") {
        //                    alert("Xin vui lòng nhập vào địa chỉ kho hàng tại Hồ Chí Minh!");
        //                    frm.txtHCMAddress.focus();
        //                    return false;
        //                }
        //            }
        //        }
    }

    return true;
}

function addEvent(obj, evType, fn) {
    if (obj.addEventListener) {
        obj.addEventListener(evType, fn, false);
        return true;
    } else if (obj.attachEvent) {
        var r = obj.attachEvent("on" + evType, fn);
        return r;
    } else {
        return false;
    }
}


function CharReplace(iStr) {
    var r1 = /%26/g;
    var r2 = /%20/g;
    var r3 = /%22/g;
    iStr = iStr.replace(r1, '&');
    iStr = iStr.replace(r2, ' ');
    iStr = iStr.replace(r3, '"');
    return iStr;
}
//Hungnv 
function CheckEnter(e) {
    var flag = false;
    if (window.event) {
        if (e.keyCode == 13) {
            flag = true;
        }
    }
    else if (e.which) {
        if (e.which == 13) {
            flag = true;
        }
    }
    if (flag) {
        CheckSubmit(document.form1.txtSearch);
    }
}

// Hungnv
function GoPage(url) {
    window.location.href = url;
}
function getNodeValue(o) {
    if (o.item(0)) {
        if (o.item(0).firstChild) {
            return o.item(0).firstChild.nodeValue;
        }
        else {
            return '';
        }
    }
    else {
        return '';
    }
}

//Hungnv - Check Upload File
function validateFileExtension(fld) {
    if (!/(\.bmp|\.gif|\.jpg|\.jpeg|\.png)$/i.test(fld.value)) {
        alert("Bạn chọn ảnh không hợp lệ. \n Hệ thống chỉ chận các file có phần mở rộng dạng: .jpg, .jpeg, . png, .gif");
        fld.form.reset();
        fld.focus();
        return false;
    }
    return true;
}

function TextOnFocus(obj, tetxtAlert) {
    if (obj.value == "Thông tin này được hiển thị trong phần listing sản phẩm, bắt buộc phải nhập") {
        obj.setAttribute('style', 'font-family:Arial;color:Black;font-style:normal;font-size:10pt;width:780px;height:65px;');
    }
    if (obj.value == tetxtAlert) {
        obj.value = '';
    }
}

function TextOnBlur(obj, tetxtAlert) {
    if (obj.value == '') { obj.value = tetxtAlert; }
    if (obj.value == "Thông tin này được hiển thị trong phần listing sản phẩm, bắt buộc phải nhập") {
        obj.setAttribute('style', 'font-family:Arial;color:#999999;font-style:italic;font-size:10pt;width:780px;height:65px;');
    }
}
function numberFormat(text) {
    //Reverse string
    //Loop through adding every character
    //If index = 3, add a comma
    //Reverse string
    text = text.split("").reverse().join("");
    var output = "";
    var j = 0;
    for (var i = 0; i < text.length; i++) {
        output += text.charAt(i);
        j++;
        if (j == 3 && i != text.length - 1) {
            output += ",";
            j = 0;
        }
    }
    output = output.split("").reverse().join("");
    return output;
}


//Catalog Product
function getCheckbox(name,type) {
    var productid = '';
    var flgCount = 0;
    for (i = 0; i < document.getElementsByName(name).length; i++) {
        if (document.getElementsByName(name)[i].checked == true) {
            productid = productid + document.getElementsByName(name)[i].id + "|";
            flgCount += 1;
        }
    }
    if (type == 0) {
        if (flgCount <= 0) {
            alert("Vui lòng chọn sản phẩm để so sánh!");
        }
        else {
            if (flgCount < 2) {
                alert("Bạn phải chọn từ 2 sản phẩm trở lên để so sánh!");
            }
            else {
                if (flgCount > 3) {
                    alert("Bạn chỉ được chọn tối đa 3 sản phẩm để so sánh!");
                }
                else {
                    if (productid != '')
                        window.location = "/Shopping/Product/CompareProduct.aspx?Product=" + productid;
                }
            }
        }
    } else { 
        if (flgCount > 3)
            alert("Bạn chỉ được chọn tối đa 3 sản phẩm để so sánh!");
    }
    
}

//=============================================================
//===========================ngocvx============================
//=============================================================
function Anchor(ID, type, num) {
    if (type == 1) {
        if (document.getElementById("hidUserID").value == "") {
            alert("Bạn cần đăng nhập để có thể lưu sản phẩm này.");
        }
    }
    AjaxRequest.get(
            {
                'url': '/Controls/ProductAnchor.aspx?ID=' + ID + '&ty=' + type + '&num=' + num
            , 'onSuccess': function(req) {
                //alert(req.responseText);
                gmobj('divAnchor' + num).innerHTML = req.responseText;
            }
            , 'onError': function(req) { }
            }
        )
}
function goDetail(CatGroup, Id, ProductName) {
    // window.location = "Detail.aspx?PID=" + Id;
    window.location = CatGroup + "detail-" + Id + "/" + ProductName + ".aspx";
}

function goShop(Id, UserName) {
    //window.location = "/Shopping/Member/Shop.aspx?MemberID=" + Id;
    window.location = "/u/" + Id + "/" + UserName + ".aspx";
}
//--------- New Transaction --------------------------------
var arItem = new Array();
var arHotProduct = new Array();

function ajaxHotTran(img) {

    AjaxRequest.get(
            {
                'url': '/Resources/XML/HotProduct.xml'
            , 'onSuccess': function(req) {

                for (var i = 0; i < req.responseXML.getElementsByTagName('Product').length; i++) {
                    with (req.responseXML.getElementsByTagName('Product').item(i)) {
                        arHotProduct[i] = new Array(9);
                        arHotProduct[i][0] = getNodeValue(getElementsByTagName('ProductID'));
                        arHotProduct[i][1] = getNodeValue(getElementsByTagName('ProductName'));

                        arHotProduct[i][2] = getNodeValue(getElementsByTagName('Price'));
                        arHotProduct[i][3] = getNodeValue(getElementsByTagName('PriceMarket'));
                        arHotProduct[i][4] = getNodeValue(getElementsByTagName('ImagePath'));
                        arHotProduct[i][5] = getNodeValue(getElementsByTagName('UserID'));
                        arHotProduct[i][6] = getNodeValue(getElementsByTagName('UserName'));
                        arHotProduct[i][7] = getNodeValue(getElementsByTagName('ProductNamePlain'));
                        arHotProduct[i][8] = getNodeValue(getElementsByTagName('CategoryGroup'));
                    }
                }
                getHotTran(i, img);

            }
            , 'onError': function(req) { document.getElementById("divHotTran").innerHTML = "Alo9"; }
            }
        )

}

function getHotTran(c, img) {
    var i;
    var j;
    var sHTML = '';
    var sHTML1 = '';


    if (c > 4) {
        sHTML = sHTML.concat('<div class="HotTC_left"><ul class="HotFourProduct">');
        for (i = 0; i < 4; i++) {
            if (i % 2 == 0) {
                sHTML = sHTML.concat('    <li class="white">');
                sHTML = sHTML.concat('        <a class="HotImage" onclick="goDetail(\'' + arHotProduct[i][8] + '\',' + arHotProduct[i][0] + ',\'' + arHotProduct[i][7] + '\');" style="cursor:pointer;"><img src="' + arHotProduct[i][4] + img + '" alt=""/></a>');
                sHTML = sHTML.concat('        <div class="HotFPright">');
                sHTML = sHTML.concat('                <p class="HotTitle"><a onclick="goDetail(\'' + arHotProduct[i][8] + '\',' + arHotProduct[i][0] + ',\'' + arHotProduct[i][7] + '\');" style="cursor:pointer;">' + arHotProduct[i][1] + '</a></p>');
                sHTML = sHTML.concat('                <p class="HotPrices">Giá:<span>' + arHotProduct[i][2] + ' Đ</span></p>');
                sHTML = sHTML.concat('                <p class="Saler">Người bán:<a onclick="goShop(' + arHotProduct[i][5] + ',\'' + arHotProduct[i][6] + '\');" style="cursor:pointer;">' + arHotProduct[i][6] + '</a></p>');
                sHTML = sHTML.concat('        </div>');
                sHTML = sHTML.concat('    </li>');
            }
            else {
                sHTML = sHTML.concat('    <li class="yellow">');
                sHTML = sHTML.concat('        <a class="HotImage" onclick="goDetail(\'' + arHotProduct[i][8] + '\',' + arHotProduct[i][0] + ',\'' + arHotProduct[i][7] + '\');" style="cursor:pointer;"><img src="' + arHotProduct[i][4] + img + '" alt=""/></a>');
                sHTML = sHTML.concat('        <div class="HotFPright">');
                sHTML = sHTML.concat('                <p class="HotTitle"><a onclick="goDetail(\'' + arHotProduct[i][8] + '\',' + arHotProduct[i][0] + ',\'' + arHotProduct[i][7] + '\');" style="cursor:pointer;">' + arHotProduct[i][1] + '</a></p>');
                sHTML = sHTML.concat('                <p class="HotPrices">Giá:<span>' + arHotProduct[i][2] + ' Đ</span></p>');
                sHTML = sHTML.concat('                <p class="Saler">Người bán:<a onclick="goShop(' + arHotProduct[i][5] + ',\'' + arHotProduct[i][6] + '\');" style="cursor:pointer;">' + arHotProduct[i][6] + '</a></p>');
                sHTML = sHTML.concat('        </div>');
                sHTML = sHTML.concat('    </li>');
            }
        }
        sHTML = sHTML.concat('</ul></div>');

        sHTML1 = sHTML1.concat('<div class="HotTC_right"><ul class="HotFourProduct">');
        for (i = 4; i < c; i++) {

            if (i % 2 == 0) {
                sHTML1 = sHTML1.concat('    <li class="white">');
                sHTML1 = sHTML1.concat('        <a class="HotImage" onclick="goDetail(\'' + arHotProduct[i][8] + '\',' + arHotProduct[i][0] + ',\'' + arHotProduct[i][7] + '\');" style="cursor:pointer;"><img src="' + arHotProduct[i][4] + img + '" alt=""/></a>');
                sHTML1 = sHTML1.concat('        <div class="HotFPright">');
                sHTML1 = sHTML1.concat('                <p class="HotTitle"><a onclick="goDetail(\'' + arHotProduct[i][8] + '\',' + arHotProduct[i][0] + ',\'' + arHotProduct[i][7] + '\');" style="cursor:pointer;">' + arHotProduct[i][1] + '</a></p>');
                sHTML1 = sHTML1.concat('                <p class="HotPrices">Giá:<span>' + arHotProduct[i][2] + ' Đ</span></p>');
                sHTML1 = sHTML1.concat('                <p class="Saler">Người bán:<a onclick="goShop(' + arHotProduct[i][5] + ',\'' + arHotProduct[i][6] + '\');" style="cursor:pointer;">' + arHotProduct[i][6] + '</a></p>');
                sHTML1 = sHTML1.concat('        </div>');
                sHTML1 = sHTML1.concat('    </li>');
            }
            else {
                sHTML1 = sHTML1.concat('    <li class="yellow">');
                sHTML1 = sHTML1.concat('        <a class="HotImage" onclick="goDetail(\'' + arHotProduct[i][8] + '\',' + arHotProduct[i][0] + ',\'' + arHotProduct[i][7] + '\');" style="cursor:pointer;"><img src="' + arHotProduct[i][4] + img + '" alt=""/></a>');
                sHTML1 = sHTML1.concat('        <div class="HotFPright">');
                sHTML1 = sHTML1.concat('                <p class="HotTitle"><a onclick="goDetail(\'' + arHotProduct[i][8] + '\',' + arHotProduct[i][0] + ',\'' + arHotProduct[i][7] + '\');" style="cursor:pointer;">' + arHotProduct[i][1] + '</a></p>');
                sHTML1 = sHTML1.concat('                <p class="HotPrices">Giá:<span>' + arHotProduct[i][2] + ' Đ</span></p>');
                sHTML1 = sHTML1.concat('                <p class="Saler">Người bán:<a onclick="goShop(' + arHotProduct[i][5] + ',\'' + arHotProduct[i][6] + '\');" style="cursor:pointer;">' + arHotProduct[i][6] + '</a></p>');
                sHTML1 = sHTML1.concat('        </div>');
                sHTML1 = sHTML1.concat('    </li>');
            }
        }
        sHTML1 = sHTML1.concat('</ul></div>');

    }

    document.getElementById("divHotTran").innerHTML = sHTML + sHTML1;

}
function ajax(img, imgH180, iUID, offset) {
    AjaxRequest.get(
            {
                'url': '/Resources/XML/Top5NewTrans.xml'
            , 'onSuccess': function(req) {
                for (var i = 0; i < req.responseXML.getElementsByTagName('Item').length; i++) {
                    with (req.responseXML.getElementsByTagName('Item').item(i)) {
                        arItem[i] = new Array(13);
                        arItem[i][0] = getNodeValue(getElementsByTagName('ProductID'));
                        arItem[i][1] = getNodeValue(getElementsByTagName('CatalogID'));
                        arItem[i][2] = getNodeValue(getElementsByTagName('ProductName'));
                        arItem[i][3] = getNodeValue(getElementsByTagName('Price'));
                        arItem[i][4] = getNodeValue(getElementsByTagName('PriceMarket'));
                        arItem[i][5] = getNodeValue(getElementsByTagName('RATE_CODE'));
                        arItem[i][6] = getNodeValue(getElementsByTagName('Promotion'));
                        arItem[i][7] = getNodeValue(getElementsByTagName('ImagePath'));
                        arItem[i][8] = getNodeValue(getElementsByTagName('ShortDesc'));
                        arItem[i][9] = getNodeValue(getElementsByTagName('CatalogName'));
                        arItem[i][10] = getNodeValue(getElementsByTagName('ProductNamePlain'));
                        arItem[i][11] = getNodeValue(getElementsByTagName('CatalogNamePlain'));
                        arItem[i][12] = getNodeValue(getElementsByTagName('CategoryGroup'));
                    }
                }
                getTop5NewTrans(i, img, imgH180, iUID, offset);
                //getTopDetail(0);
            }
            , 'onError': function(req) { }
            }
        )
}
function getTop5NewTrans(c, img, imgH180, iUID, offset) {
    var i;
    var sHTML = '';
    sHTML = sHTML.concat('<ul class="fiveProduct">');
    for (i = 0; i < c; i++) {
        sHTML = sHTML.concat('    <li>');
        //sHTML=sHTML.concat('        <table cellpadding="0px" cellspacing="0px" class="tblProduct" onmouseover="getTopDetail('+i+');" onclick="goDetail('+arItem[i][0]+')">');
        sHTML = sHTML.concat('        <table id="trPro' + i + '" cellpadding="0px" cellspacing="0px" class="tblProduct" onmouseover="hideDivPro(' + i + ');clearInterval(int1);" onmouseout="" onclick="goDetail(\'' + arItem[i][12] + '\',' + arItem[i][0] + ',\'' + arItem[i][10] + '\')">');
        sHTML = sHTML.concat('            <tr>');
        sHTML = sHTML.concat('                <td class="img"><a href="' + arItem[i][12] + 'detail-' + arItem[i][0] + '/' + arItem[i][10] + '.aspx"><img alt="" src="' + arItem[i][7] + img + '" height="46" width="46" border="0"/></a></td>');
        sHTML = sHTML.concat('                <td class="sep"></td>');
        sHTML = sHTML.concat('                <td class="text"><div style="height:50px;overflow:hidden;padding-top:5px;"><a href="' + arItem[i][12] + 'detail-' + arItem[i][0] + '/' + arItem[i][10] + '.aspx">' + arItem[i][2] + '</a></div></td>');
        sHTML = sHTML.concat('            </tr>');
        sHTML = sHTML.concat('        </table>');
        sHTML = sHTML.concat('    </li>');
        //Anchor(arItem[i][0],0);          
    }
    sHTML = sHTML.concat('</ul>');
    document.getElementById("divTop5").innerHTML = sHTML;
    getTopDetail(i, imgH180, iUID, offset);
}
var j = 0;
function setInter() {
    if (j >= 5) {
        j = 0;
    }
    hideDivPro(j);
    j++;
}

function ObjectPosition(obj) {
    var curleft = 0;
    var curtop = 0;
    if (obj.offsetParent) {
        do {
            curleft += obj.offsetLeft;
            curtop += obj.offsetTop;
        } while (obj = obj.offsetParent);
    }
    return [curleft, curtop];
}
function getTopDetail(id, imgH180, iUID, offset) {
    var sHTML = '';
    var i;
    for (i = 0; i <= id - 1; i++) {
        //alert(offset);        
        if (i == 0) {
//            sHTML = sHTML.concat('<div class="fl" id="divPro' + i + '"  onMouseover="ddrivetip(\'Tên sản phẩm: <span style=font-weight:bold;>' + arItem[i][2] + '</span><br>Giá sản phẩm: <span style=font-weight:bold;>' + arItem[i][4] + '</span>\',\'yellow\', 300)" onMouseout="hideddrivetip()">');
            sHTML = sHTML.concat('<div class="fl" id="divPro' + i + '">');
        } else {
        sHTML = sHTML.concat('<div class="fl" id="divPro' + i + '" style="display:none; ">');
        }
        sHTML = sHTML.concat('         <div class="fl" style="margin:0px 10px 0px 0px;height:280px;width:400px;background-color:White;text-align:center;overflow:hidden;">');
        sHTML = sHTML.concat('             <a href="' + arItem[i][12] + 'detail-' + arItem[i][0] + '/' + arItem[i][10] + '.aspx"><img alt="" src="' + arItem[i][7] + 'thumbProduct.jpg.thumb0x250.ns.jpg" border="0" height="280" /></a>');
        sHTML = sHTML.concat('         </div>');

        sHTML = sHTML.concat('         <a href="' + arItem[i][12] + 'detail-' + arItem[i][0] + '/' + arItem[i][10] + '.aspx">');
        sHTML = sHTML.concat('              <div style="left: ' + (parseInt(offset) - 7) + 'px; right:0px; top: 385px; width: 425px; height: 65px; opacity: 0.5;filter:alpha(opacity=50); background-color:#000; overflow: hidden; position: absolute; z-index: 4; margin:0px; padding:0px;">');
        sHTML = sHTML.concat('                  <div class="fl ArB18 InfoSlideHome" style="color:#D6F451;overflow: hidden;height:18px;width:425px;">' + arItem[i][2] + '</div>');
        sHTML = sHTML.concat('                  <div class="fl InfoSlideHome" style="top: 28px;overflow: hidden;height:18px;width:425px;"><span style="color:#97ffcd;" class="ArB12">Giá: </span><span style="color:#ffffff;" class="ArB18">' + arItem[i][4] + ' VNĐ</span></div>');
        sHTML = sHTML.concat('              </div>');
        sHTML = sHTML.concat('         </a>');


        //        sHTML = sHTML.concat('<p class="branchPro"><a href="/' + arItem[i][11] + '/' + arItem[i][1] + '/default.aspx">' + arItem[i][9] + '</a></p>');
        //        sHTML = sHTML.concat('<div class="DesProduct" style="overflow:hidden;"><a href="' + arItem[i][12] + 'detail-' + arItem[i][0] + '/' + arItem[i][10] + '.aspx">' + arItem[i][2] + '</a> </div>');
        //        sHTML = sHTML.concat('     <div class="ProductInfo">');
        //        sHTML = sHTML.concat('         <div class="fl" style="margin:0px 10px 0px 0px;height:180px;width:180px;border:solid 1px #c6ecee;background-color:White;text-align:center;overflow:hidden;">');
        //        sHTML = sHTML.concat('             <a href="' + arItem[i][12] + 'detail-' + arItem[i][0] + '/' + arItem[i][10] + '.aspx"><img alt="" src="' + arItem[i][7] + imgH180 + '" border="0" height="180" /></a>');
        //        sHTML = sHTML.concat('         </div>');
        //        sHTML = sHTML.concat('         <div class="ProductInfo_right">');
        //        sHTML = sHTML.concat('             <ul>');
        //        sHTML = sHTML.concat('                 <li class="price">');
        //        sHTML = sHTML.concat('                     <span class="Title">Giá</span>');
        //        sHTML = sHTML.concat('                     <p class="priceNumber">' + arItem[i][3] + '<span class="currency"> Đ</span></p>');
        //        sHTML = sHTML.concat('                 </li>');
        //        sHTML = sHTML.concat('                 <li class="saleOffInfo">');
        //        sHTML = sHTML.concat('                     <p class="Title">Thông tin khuyến mãi</p>');
        //        sHTML = sHTML.concat('                     <p class="SaleOffDetail">' + arItem[i][6] + '</p>');
        //        sHTML = sHTML.concat('                 </li>');
        //        sHTML = sHTML.concat('             </ul>');
        //        sHTML = sHTML.concat('             <div class="BuyNSave">');
        //        sHTML = sHTML.concat('                 <div class="fl">');
        //        if (iUID != '' && iUID != 0) {
        //            sHTML = sHTML.concat('                     <a href="/Shopping/Order/Order.aspx?id=' + arItem[i][0] + '&pr=0">');
        //            sHTML = sHTML.concat('                         <table><tr><td><img alt="" src="Images/earthIcon.gif" class="BuySaveEarth1" /></td>');
        //            sHTML = sHTML.concat('                         <td><p class="BuySaveText" style="padding-top:10px;">Mua ngay</p></td></tr></table>');
        //            sHTML = sHTML.concat('                     </a>');
        //        } else {
        //            sHTML = sHTML.concat('                         <a href="/shopping/user/login.aspx?height=270&width=400" class="thickbox">');
        //            sHTML = sHTML.concat('                         <table><tr><td><img alt="" src="Images/earthIcon.gif" class="BuySaveEarth1" /></td>');
        //            sHTML = sHTML.concat('                         <td><p class="BuySaveText" style="padding-top:10px;">Mua ngay</p></td></tr></table>');
        //            sHTML = sHTML.concat('                     </a>');
        //        }
        //        sHTML = sHTML.concat('                 </div>');
        //        sHTML = sHTML.concat('                 <div class="fl BuySaveText hand" style="padding-top:6px;" onclick="Anchor(' + arItem[i][0] + ',1,' + i + ')" id="divAnchor' + i + '">');
        //        //sHTML=sHTML.concat('                     <div class="fl BuySaveText"><img class="BuySaveEarth" alt="" src="Images/SaveIcon.gif" />');
        //        //sHTML=sHTML.concat('                     </div><div class="fl BuySaveText">Lưu sản phẩm</div>');
        //        sHTML = sHTML.concat('                 </div>');
        //        sHTML = sHTML.concat('             </div>');
        //        sHTML = sHTML.concat('         </div>');
        sHTML = sHTML.concat('     </div>');
        sHTML = sHTML.concat('</div>');
    }
    //alert(sHTML);    
    document.getElementById("divTopDetail").innerHTML = sHTML;
    //    for (i = 0; i <= id - 1; i++) {
    //        Anchor(arItem[i][0], 0, i);
    //    }

}


function hideDivPro(v) {
    var i;
    for (i = 0; i < 5; i++) {
        if (i == v) {
            document.getElementById("divPro" + i).style.display = '';
            document.getElementById("trPro" + i).style.background = '#fff';
            j = v;
        } else {
            document.getElementById("divPro" + i).style.display = 'none';
            document.getElementById("trPro" + i).style.background = '#D8EFF0';
        }
    }
}


//------------ Catalog FRM ------------------------------------
var arItemCata = new Array();

function getCatalog(n, m, arr) {
    var i, j;
    var sHTML = '';
    if (n % 2 == 1) {
        sHTML = sHTML.concat('    <li class="left">');
    } else {
        sHTML = sHTML.concat('    <li class="right">');
    }
    if (arItemCata[n][0] != '') {
        sHTML = sHTML.concat('    <a class="BranchLeft" href="' + arItemCata[n][1] + '"><img alt="" src="' + arItemCata[n][0] + '"/></a>');
    } else {
        sHTML = sHTML.concat('    <a class="BranchLeft" href="' + arItemCata[n][1] + '"></a>');
    }
    
    sHTML = sHTML.concat('    <div class="BranchRight">');
    sHTML = sHTML.concat('        <p class="BranchName">' + arItemCata[n][2] + '</p>');
    sHTML = sHTML.concat('        <ul class="ulDetailBranch">');
    for (j = 0; j < m; j++) {
        sHTML = sHTML.concat('    <li><a href="' + arr[j][1] + '">' + arr[j][0] + '</a></li>');
    }
    sHTML = sHTML.concat('        </ul>');
    sHTML = sHTML.concat('    </div>');
    sHTML = sHTML.concat('    </li>');
    //            sHTML=sHTML.concat('</ul>');
    html += sHTML;
}

var html = '<ul class="ulBranchShop">';
function ajaxCata() {

    AjaxRequest.get(
        {
            'url': '/Resources/XML/catalog.xml'
        , 'onSuccess': function(req) {
            for (var i = 0; i < req.responseXML.getElementsByTagName('item').length; i++) {
                with (req.responseXML.getElementsByTagName('item').item(i)) {
                    var arChildCata = new Array()
                    arItemCata[i] = new Array(3);
                    arItemCata[i][0] = getNodeValue(getElementsByTagName('icon'));
                    arItemCata[i][1] = getNodeValue(getElementsByTagName('Link'));
                    arItemCata[i][2] = getNodeValue(getElementsByTagName('NameItem'));
                    for (var j = 0; j < req.responseXML.getElementsByTagName('Child' + i).length; j++) {
                        with (req.responseXML.getElementsByTagName('Child' + i).item(j)) {
                            arChildCata[j] = new Array(2);
                            arChildCata[j][0] = getNodeValue(getElementsByTagName('Name' + i));
                            arChildCata[j][1] = getNodeValue(getElementsByTagName('LinkChild' + i));
                        }
                    }
                    getCatalog(i, j, arChildCata);
                }
            }
            html += '</ul>';
            document.getElementById("catalog").innerHTML = html;
        }
        , 'onError': function(req) { }
        }
    )
}

// -------------- Top User transaction ---------------------------
var arItemTopMember = new Array();
var arItemTopMemberInfo = new Array();

function ajaxTopMember() {

    AjaxRequest.get(
            {
                'url': '/Resources/XML/TopMemberContent.xml'
            , 'onSuccess': function(req) {

                for (var i = 0; i < req.responseXML.getElementsByTagName('Member').length; i++) {
                    with (req.responseXML.getElementsByTagName('Member').item(i)) {

                        arItemTopMember[i] = new Array(4);
                        arItemTopMember[i][0] = getNodeValue(getElementsByTagName('UserID'));
                        arItemTopMember[i][1] = getNodeValue(getElementsByTagName('UserName'));
                        arItemTopMember[i][2] = getNodeValue(getElementsByTagName('TotalTransaction'));
                        arItemTopMember[i][3] = getNodeValue(getElementsByTagName('Avatar'));
                    }
                }
                getTopMemberContent(i);
            }
            , 'onError': function(req) { } //document.getElementById("divHotTran").innerHTML = "Alo9";
            }
        )

}

function ajaxTopMemberInfo() {

    AjaxRequest.get(
            {
                'url': '/Resources/XML/TopMemberInfo.xml'
            , 'onSuccess': function(req) {

                for (var i = 0; i < req.responseXML.getElementsByTagName('Member').length; i++) {
                    with (req.responseXML.getElementsByTagName('Member').item(i)) {

                        arItemTopMemberInfo[i] = new Array(4);
                        arItemTopMemberInfo[i][0] = getNodeValue(getElementsByTagName('UserID'));
                        arItemTopMemberInfo[i][1] = getNodeValue(getElementsByTagName('UserName'));
                        arItemTopMemberInfo[i][2] = getNodeValue(getElementsByTagName('Avatar'));
                        arItemTopMemberInfo[i][3] = getNodeValue(getElementsByTagName('Blast'));
                    }
                }
                getTopMemberInfo(i);
            }
            , 'onError': function(req) { }
            }
        )

}
function getTopMemberContent(c) {
    var i;
    var sHTML = '';

    for (i = 0; i < c; i++) {
        sHTML = sHTML.concat('    <li >');
        sHTML = sHTML.concat('        <div class="licontent">');
        sHTML = sHTML.concat('          <div class="LiContentLeft">');
        if (arItemTopMember[i][3] != '') {
            sHTML = sHTML.concat('              <a onclick="goShop(' + arItemTopMember[i][0] + ',\'' + arItemTopMember[i][1] + '\');" style="cursor:pointer;"><img src="' + arItemTopMember[i][3] + '" alt=""/></a>');
        }
        else {
            sHTML = sHTML.concat('              <a onclick="goShop(' + arItemTopMember[i][0] + ',\'' + arItemTopMember[i][1] + '\');" style="cursor:pointer;"><img src="/Avatar/Noavatar.jpeg" alt=""/></a>');
        }
        sHTML = sHTML.concat('          </div>');
        sHTML = sHTML.concat('          <div class="liContentRight">');
        sHTML = sHTML.concat('             <p class="liNameMember"><a onclick="goShop(' + arItemTopMember[i][0] + ',\'' + arItemTopMember[i][1] + '\');" style="cursor:pointer;">' + arItemTopMember[i][1] + '</a></p>');
        //sHTML = sHTML.concat('             <p class="MemberLevel"></p>');
        sHTML = sHTML.concat('             <div class="LoginTimes"><img src="Images/TopProduct/RoundRow.gif" alt=" "/>' + arItemTopMember[i][2] + ' luot giao dich</div>');
        sHTML = sHTML.concat('          </div>');
        sHTML = sHTML.concat('        </div>');
        sHTML = sHTML.concat('    </li>');

    }
    document.getElementById("ulTopMember").innerHTML = sHTML;
}

function getTopMemberInfo(c) {
    var i;
    var sHTML = '';

    for (i = 0; i < c; i++) {
        sHTML = sHTML.concat('    <li >');
        sHTML = sHTML.concat('        <div class="licontent">');
        sHTML = sHTML.concat('          <div class="LiContentLeft">');
        if (arItemTopMemberInfo[i][2] != '') {
            sHTML = sHTML.concat('              <a onclick="goShop(' + arItemTopMemberInfo[i][0] + ',\'' + arItemTopMemberInfo[i][1] + '\');" style="cursor:pointer;"><img src="' + arItemTopMemberInfo[i][2] + '" alt=""/></a>');
        }
        else {
            sHTML = sHTML.concat('              <a onclick="goShop(' + arItemTopMemberInfo[i][0] + ',\'' + arItemTopMemberInfo[i][1] + '\');" style="cursor:pointer;"><img src="/Avatar/Noavatar.jpeg" alt=""/></a>');
        }
        sHTML = sHTML.concat('          </div>');
        sHTML = sHTML.concat('          <div class="liContentRight">');
        sHTML = sHTML.concat('             <p class="liNameMember"><a onclick="goShop(' + arItemTopMemberInfo[i][0] + ',\'' + arItemTopMemberInfo[i][1] + '\');" style="cursor:pointer;">' + arItemTopMemberInfo[i][1] + '</a></p>');
        if (arItemTopMemberInfo[i][3] == " ") {
            sHTML = sHTML.concat('             <p class="MemberBlast" style="background:url(\'/Images/Blast.gif\') no-repeat;height:40px;">...</p>');
        } else {
            sHTML = sHTML.concat('             <p class="MemberBlast" style="background:url(\'/Images/Blast.gif\') no-repeat;height:40px;">' + arItemTopMemberInfo[i][3].substring(0, 30) + "..." + '</p>');
        }
        sHTML = sHTML.concat('          </div>');
        sHTML = sHTML.concat('        </div>');
        sHTML = sHTML.concat('    </li>');

    }
    document.getElementById("ulTopMemberInfo").innerHTML = sHTML;

}

function Show(Id) {
    if (Id == 0) {
        document.getElementById("ulTopMember").style.display = "block";
        document.getElementById("ulTopMemberInfo").style.display = "none";
        document.getElementById("divTopMember").className = "MembersTopInfoAct";
        document.getElementById("divTopMemberInfo").className = "MembersTranNor";
    }
    else {
        document.getElementById("divTopMemberInfo").className = "MembersTopInfoAct";
        document.getElementById("divTopMember").className = "MembersTranNor";
        document.getElementById("ulTopMember").style.display = "none";
        document.getElementById("ulTopMemberInfo").style.display = "block";
    }
}

// ---------------------------Top Sale Off ------------------
var arItemSaleOff = new Array();

function ajaxSaleOff(img, iUID) {

    AjaxRequest.get(
            {
                'url': '/Resources/XML/SaleOffProduct.xml'
            , 'onSuccess': function(req) {
                for (var i = 0; i < req.responseXML.getElementsByTagName('Product').length; i++) {
                    with (req.responseXML.getElementsByTagName('Product').item(i)) {
                        arItemSaleOff[i] = new Array(9);
                        arItemSaleOff[i][0] = getNodeValue(getElementsByTagName('ProductID'));
                        arItemSaleOff[i][1] = getNodeValue(getElementsByTagName('ProductName'));
                        arItemSaleOff[i][2] = getNodeValue(getElementsByTagName('Price'));
                        arItemSaleOff[i][3] = getNodeValue(getElementsByTagName('PriceMarket'));
                        arItemSaleOff[i][4] = getNodeValue(getElementsByTagName('ImagePath'));
                        arItemSaleOff[i][5] = getNodeValue(getElementsByTagName('UserID'));
                        arItemSaleOff[i][6] = getNodeValue(getElementsByTagName('UserName'));
                        arItemSaleOff[i][7] = getNodeValue(getElementsByTagName('ProductNamePlain'));
                        arItemSaleOff[i][8] = getNodeValue(getElementsByTagName('CategoryGroup'));
                    }
                }
                getSaleOff(i, img, iUID);
            }
            , 'onError': function(req) { document.getElementById("divHotTran").innerHTML = ""; }
            }
        )
}

function getSaleOff(c, img, iUID) {
    var i;
    var j;
    var sHTML = '';
    var sHTML1 = '';

    for (i = 0; i < c; i++) {
        if (i % 2 == 0) {
            sHTML = sHTML.concat('    <li class="light">');
            sHTML = sHTML.concat('        <div class="divImages">');
            sHTML = sHTML.concat('               <a onclick="goDetail(\'' + arItemSaleOff[i][8] + '\',' + arItemSaleOff[i][0] + ',\'' + arItemSaleOff[i][7] + '\');" style="cursor:pointer;"><img src="' + arItemSaleOff[i][4] + img + '" alt=""/></a>');
            sHTML = sHTML.concat('        </div>');
            sHTML = sHTML.concat('        <div class="divRightText">');
            sHTML = sHTML.concat('                <div class="TopSaleRightText"><a class="aRightText" style="cursor:pointer;" onclick="goDetail(\'' + arItemSaleOff[i][8] + '\',' + arItemSaleOff[i][0] + ',\'' + arItemSaleOff[i][7] + '\');">' + arItemSaleOff[i][1] + '</a></div>');
            if (arItemSaleOff[i][3] != 0) {
                //sHTML = sHTML.concat('                <div class="divPriceSaleOff"><div class="PriceSaleOff_left">Giá thị trường:</div><div class="PriceSaleNumber">' + arItemSaleOff[i][2] + ' Đ</div><div class="PriceSaleNumber fr">' + arItemSaleOff[i][3] + ' Đ</div><div class="PriceSaleOff_left fr"> </div></div>');
                sHTML = sHTML.concat('                <div class="divPriceSaleOff"><div class="PriceSaleOff_left">Giá bán:</div><div class="PriceSaleNumber">' + arItemSaleOff[i][3] + ' Đ</div></div>');
            } else {
                sHTML = sHTML.concat('                <div class="divPriceSaleOff"><div class="PriceSaleOff_left">Giá thị trường:</div><div class="PriceSaleNumber">' + arItemSaleOff[i][2] + ' Đ</div></div>');
            }
//            sHTML = sHTML.concat('                <div class="Saler">Người bán:<a onclick="goShop(' + arItemSaleOff[i][5] + ',\'' + arItemSaleOff[i][6] + '\');" style="cursor:pointer;"><span class="name">' + arItemSaleOff[i][6] + '</span></a></div>');
            if (iUID != '' && iUID != 0) {
                sHTML = sHTML.concat('                <div class="BuyNowHome"><a style="cursor:pointer;" onclick="goOrder(' + arItemSaleOff[i][0] + ');"><img src="Images/earthIcon.gif" alt=""/><p> Mua ngay</p></a></div>');
            } else {
            sHTML = sHTML.concat('                <div class="BuyNowHome"><a style="cursor:pointer;" href="/shopping/user/login.aspx?height=270&width=400" class="thickbox"><img src="Images/earthIcon.gif" alt=""/><p> Mua ngay</p></a></div>');
            }
            sHTML = sHTML.concat('        </div>');
            sHTML = sHTML.concat('    </li>');
        }
        else {
            sHTML = sHTML.concat('    <li class="dark">');
            sHTML = sHTML.concat('        <div class="divImages">');
            sHTML = sHTML.concat('        <a onclick="goDetail(\'' + arItemSaleOff[i][8] + '\',' + arItemSaleOff[i][0] + ',\'' + arItemSaleOff[i][7] + '\');" style="cursor:pointer;"><img src="' + arItemSaleOff[i][4] + img + '" alt=""/></a>');
            sHTML = sHTML.concat('        </div>');
            sHTML = sHTML.concat('        <div class="divRightText">');
            sHTML = sHTML.concat('                <div class="TopSaleRightText"><a class="aRightText" style="cursor:pointer;" onclick="goDetail(\'' + arItemSaleOff[i][8] + '\',' + arItemSaleOff[i][0] + ',\'' + arItemSaleOff[i][7] + '\');">' + arItemSaleOff[i][1] + '</a></div>');
            if (arItemSaleOff[i][3] != 0) {
                //sHTML = sHTML.concat('                <div class="divPriceSaleOff"><div class="PriceSaleOff_left">Giá thị trường:</div><div class="PriceSaleNumber">' + arItemSaleOff[i][2] + ' Đ</div><div class="PriceSaleNumber fr">' + arItemSaleOff[i][3] + ' Đ</div><div class="PriceSaleOff_left fr">Giá bán: </div></div>');
                sHTML = sHTML.concat('                <div class="divPriceSaleOff"><div class="PriceSaleOff_left">Giá bán:</div><div class="PriceSaleNumber">' + arItemSaleOff[i][3] + ' Đ</div></div>');
            } else {
                sHTML = sHTML.concat('                <div class="divPriceSaleOff"><div class="PriceSaleOff_left">Giá thị trường:</div><div class="PriceSaleNumber">' + arItemSaleOff[i][2] + ' Đ</div></div>');
            }
//            sHTML = sHTML.concat('                <div class="Saler">Người bán:<a onclick="goShop(' + arItemSaleOff[i][5] + ',\'' + arItemSaleOff[i][6] + '\');" style="cursor:pointer;"><span class="name">' + arItemSaleOff[i][6] + '</span></a></div>');
            if (iUID != '' && iUID != 0) {
                sHTML = sHTML.concat('                <div class="BuyNowHome"><a style="cursor:pointer;" onclick="goOrder(' + arItemSaleOff[i][0] + ');"><img src="Images/earthIcon.gif" alt=""/><p> Mua ngay</p></a></div>');
            } else {
            sHTML = sHTML.concat('                <div class="BuyNowHome"><a style="cursor:pointer;" href="/shopping/user/login.aspx?height=270&width=400" class="thickbox"><img src="Images/earthIcon.gif" alt=""/><p> Mua ngay</p></a></div>');
            }
            sHTML = sHTML.concat('        </div>');
            sHTML = sHTML.concat('    </li>');
        }
    }

    document.getElementById("ulTop").innerHTML = sHTML;
}

function goOrder(Id) {
    window.location = "/Shopping/Order/Order.aspx?id=" + Id + "&pr=0";  //"/order/" + Id+"/default.aspx";
}

// Control header

function GotoSearch() {
    document.getElementById("aspnetForm").method = "post"
    document.getElementById("aspnetForm").name = "frmSearch"
    document.getElementById("aspnetForm").action = "/Shopping/Product/Search.aspx"
    document.getElementById("aspnetForm").submit()
}

//=============================================================
//===========================/ngocvx===========================
//=============================================================
function PressEnter(e) {
    var keynum;

    if (window.event) // IE
    {
        keynum = e.keyCode;
    }
    else if (e.which) // Netscape/Firefox/Opera
    {
        keynum = e.which;
    }
    if (keynum == 13) {
        document.getElementById("aspnetForm").method = "post"
        document.getElementById("aspnetForm").name = "frmSearch"
        document.getElementById("aspnetForm").action = "/Shopping/Product/Search.aspx"
        document.getElementById("aspnetForm").submit()
    }
}
function Logout() {
    window.location = "/Shopping/User/Logout.aspx";
    return false;
}
function Dangban() {
    document.cookie = "URLDangBan=" + "/Shopping/Sell" + ";path=/";    
}

//			    var altKey = false;
//			    var keyCode = 0;

//			    function closeSession(evt) {

//			        evt = (evt) ? evt : event;

//			        clickY = evt.clientY;
//			        altKey = evt.altKey;
//			        keyCode = evt.keyCode;

//			        if (!evt.clientY) {
//			            // Window Closing in FireFox
//			            // capturing ALT + F4
//			            keyVals = document.getElementById('ffKeyTrap');			            
//			            if (keyVals.value == 'true115') {
//			                keyVals.value = '';			                			                    
//			                window.open(document.getElementById('<%= hidLogout.ClientID %>').value + '?Closed=true');			                
//			            }

////			            if (keyVals.value == '') {
////			                // capturing a window close by "X" ?
////			                // we have no keycodes
////			                window.open(document.getElementById('<%= hidLogout.ClientID %>').value + '?Closed=true');
//			            //			            }
//			            //alert('mot hai ba');
//			        } else{
//			            // Window Closing in IE
//			            // capturing ALT + F4			            
//			            if (altKey == true && keyCode == 115) {
//			                window.open(document.getElementById('<%= hidLogout.ClientID %>').value + '?Closed=true');
//			                // capturing a window close by "X"
//			            } else if (clickY < 0) {
//			                window.open(document.getElementById('<%= hidLogout.ClientID %>').value + '?Closed=true');
//			                // simply leaving the page via a link
//			            } else {
//			                //alert('close 3');
//			                return void (0);
//			            }
//			        }
//			    }

//			    function whatKey(evt) {
//			        evt = (evt) ? evt : event;
//			        keyVals = document.getElementById('ffKeyTrap');
//			        altKey = evt.altKey;
//			        keyCode = evt.keyCode;
//			        if (altKey && keyCode == 115) {
//			            keyVals.value = String(altKey) + String(keyCode);
//			        }
//			    }
//			    window.onkeydown = whatKey;
//			    window.onbeforeunload = closeSession;
function SetDisplay(divID) {
    if (divID == 3) {
        document.getElementById("divPays").style.display = "block";
        document.getElementById("divShip").style.display = "none";
    }
    else {
        document.getElementById("divPays").style.display = "none";
        document.getElementById("divShip").style.display = "block";
    }
}

//Stock Address
function ajaxGetData(url, divObjID, obj) {
    if (obj.checked) {
        AjaxRequest.get(
        {
            'url': url
        , 'onSuccess': function(req) {
            document.getElementById(divObjID).innerHTML = req.responseText;
        }
        , 'onError': function(req) { }
        }
    )
    }
    else {

        if (obj.value == 11) {
            document.getElementById("txtHNAddress").readonly = "readonly";
            document.getElementById("txtHNAddress").className = "StockTextAddDisable";
            document.getElementById("txtHNAddress").value = "";
        }
        if (obj.value == 95) {
            document.getElementById("txtHCMAddress").readonly = "readonly";
            document.getElementById("txtHCMAddress").className = "StockTextAddDisable";
            document.getElementById("txtHCMAddress").value = "";
        }
    }
}
function popupWindow(mypage, myname, w, h, scroll, resiza) {
    var winl = (screen.width - w) / 2;
    var wint = (screen.height - h) / 2;
    winprops = 'height=' + h + ',width=' + w + ',top=' + wint + ',left=' + winl + ',scrollbars=' + scroll + ',resizable=' + resiza + ''
    win = window.open(mypage, myname, winprops)
    if (parseInt(navigator.appVersion) >= 4) {
        win.window.focus();
    }
}

function popupWindowSingle(mypage, myname, w, h, scroll) {
    var listenWindow;
    if (listenWindow != null) {
        listenWindow.close();
    }
    listenWindow = popupWindow(mypage, myname, w, h, scroll);
}

// Quản lý sản phẩm
function ConfirmDelete() {
    var flgCheck = false;

    try {
        if (document.forms[0].chkItem.length == undefined) {
            if (document.forms[0].chkItem.checked == true) {
                flgCheck = true;
            }
        }
        else {
            for (i = 0; i < document.forms[0].chkItem.length; i++) {
                if (document.forms[0].chkItem[i].checked == true) {
                    flgCheck = true;
                    break;
                }
            }
        }
    }
    catch (err) { }


    if (flgCheck) {
        return confirm("Bạn có thật sự muốn xóa sản phẩm này không?");
    }
    else {
        alert("Bạn chưa chọn sản phẩm muốn xóa!");
        return false;
    }
}

function ajaxGet(url, divObjID) {
    AjaxRequest.get(
    {
        'url': url
    , 'onSuccess': function(req) {
        //document.getElementById(divObjID).innerHTML = req.responseText;
    }
    , 'onError': function(req) { }
    }
    )
}

function processAddCart(url, divObjID, ProductID) {
    AjaxRequest.get(
    {
        'url': url
    , 'onSuccess': function(req) {
        var result;

        result = req.responseText;

        if (result >= 0) {
            document.getElementById(divObjID).innerHTML = result;
            alert("Bạn vừa đặt mua sản phẩm mã số " + ProductID);
        }
        else if (result == -1) {
            alert("Bạn không thể đặt mua sản phẩm này. \nXin vui lòng đăng nhập để có thể đặt mua!");
        }
        else if (result == -2) {
            alert("Bạn không được phép mua hàng của nhiều nguời bán. \nNếu bạn muốn mua của người này, xin vui lòng hoàn thành hoặc hủy đơn hàng hiện có!");
        }
        else if (result == -4) {
            alert("Bạn không được phép mua hàng của chính mình!");
        }
        else {
            alert("Bạn không thể đặt mua sản phẩm này. \nThông tin sản phẩm không đầy đủ, xin vui lòng liên hệ với nguời bán để biết thêm thông tin!");
        }
    }
    , 'onError': function(req) { alert("Có lỗi xẩy ra. Vui lòng liên hệ với ban quản trị để biết thêm thông tin!"); }
    }
    )
}


function AddProductToCart(ProductID, PriceOtherID) {
    processAddCart('/Shopping/Order/AddProductToCart.aspx?id=' + ProductID + '&pr=' + PriceOtherID, "ctl00_Header_lblShoppingCart", ProductID);
}

function validFrmUserInfo(frm) {
    if (Trim(frm.ctl00_MainContent_txtName.value) == "") {
        alert("Xin vui lòng nhập vào Họ tên đầy đủ!");
        frm.ctl00_MainContent_txtName.focus();
        return false;
    }

    if (Trim(frm.ctl00_MainContent_txtAddress.value) == "") {
        alert("Xin vui lòng nhập vào địa chỉ liên hệ!");
        frm.ctl00_MainContent_txtAddress.focus();
        return false;
    }

    if (Trim(frm.ctl00_MainContent_txtTelephone.value) == "" && Trim(frm.ctl00_MainContent_txtCellphone.value) == "") {
        alert("Xin vui lòng nhập vào số điện thoại cố định hoặc di động!");
        frm.ctl00_MainContent_txtTelephone.focus();
        return false;
    }

    return true;
}

function validFormOrder(frm, sellerProvince) {
    if (Trim(frm.ct100_MainContent_txtFullName.value) == "") {
        alert("Xin vui lòng nhập tên người nhận!");
        frm.ct100_MainContent_txtFullName.focus();
        return false;
    }
    if (Trim(frm.ct100_MainContent_txtHomeTel.value) == "") {
        alert("Xin vui lòng nhập số điện thoại người nhận!");
        frm.ct100_MainContent_txtHomeTel.focus();
        return false;
    }
    if (Trim(frm.ct100_MainContent_txtMobile.value) == "") {
        alert("Xin vui lòng nhập số di động của người nhận!");
        frm.ct100_MainContent_txtMobile.focus();
        return false;
    }
    if (Trim(frm.ct100_MainContent_txtAddress.value) == "") {
        alert("Xin vui lòng nhập địa chỉ người nhận!");
        frm.ct100_MainContent_txtAddress.focus();
        return false;
    }
    if (Trim(frm.ct100_MainContent_ddlProvince.value) == sellerProvince) {
        if (Trim(frm.ct100_MainContent_ddlDistricts.value) == "0") {
            alert("Xin vui lòng nhập Quận/Huyện của người nhận!");
            frm.ct100_MainContent_ddlDistricts.focus();
            return false;
        }
    }
    if (Trim(frm.ct100_MainContent_ddlProvince.value) == "0") {
        alert("Xin vui lòng nhập Tỉnh/Thành của người nhận!");
        frm.ct100_MainContent_ddlProvince.focus();
        return false;
    }
}

function validFrmStore(frm) {
    if (frm.ctl00_MainContent_chkHN1.checked == true) {
        if (Trim(frm.ctl00_MainContent_txtAddressHN.value) == "") {
            alert("Xin vui lòng nhập vào địa chỉ kho hàng tại Hà Nội!");
            frm.ctl00_MainContent_txtAddressHN.focus();
            return false;
        }
    }

    if (frm.ctl00_MainContent_chkHCM1.checked == true) {
        if (Trim(frm.ctl00_MainContent_txtAddressHCM.value) == "") {
            alert("Xin vui lòng nhập vào địa chỉ kho hàng tại Hồ Chí Minh!");
            frm.ctl00_MainContent_txtAddressHCM.focus();
            return false;
        }
    }

    return true;
}

function CheckConfirm(alerts) {
    if (confirm(alerts)) {
        return true;
    }
    else {
        return false;
    }
}

function setCheckAll(checkName, objChkBox) {
    var bChecked = (objChkBox.checked) ? true : false;

    if (checkName == undefined) {
        return;
    } else if (checkName.length) {
        for (var i = 0; i < checkName.length; i++) {
            checkName[i].checked = bChecked;
        }
    } else {
        checkName.checked = bChecked;
    }
}

function SubmitUpdate(alert) {
    if (CheckConfirm(alert)) {
        theForm.submit(); //aspnetForm                                                
    }
}

function validateDesc(oSrc, args) {
    args.IsValid = (Trim(args.Value) != "Thông tin này được hiển thị trong phần listing sản phẩm, bắt buộc phải nhập");
}

function RemoveUpload(obj, maxUploads, fileFieldName) {
    try {

        removeFile2(maxUploads, fileFieldName);
    }
    catch (err) { }
}

function Test() {
    frm = document.aspnetForm;
    try {

        var flgRedirect = true;

        for (i = 0; i < parent.frames.length; i++) {
            if (i != 1 && i != 2) {
                if (parent.frames[i].document.forms[0].hddUploadSucsess.value == 0) {
                    alert("Hệ thống đang thực hiện tải file! \n Xin vui lòng chờ trong giây lát.");
                    flgRedirect = false;
                    return false;
                    break;
                }
            }
        }
    }
    catch (err) { alert(err.message); }
    try {

        if (flgRedirect) {
            var listFile = "";
            for (i = 0; i < parent.frames.length; i++) {
                if (i != 1 && i != 2) {
                    if (parent.frames[i].document.forms[0].FileName.value != "") {
                        listFile += parent.frames[i].document.forms[0].FileName.value + ";";
                    }
                }
            }

            frm.ctl00$MainContent$hddImageList.value = listFile;
        }
    }
    catch (err) { }
}

function RemoveUploadE(obj, maxUploads, fileFieldName) {
    try {
        if (top.frames[obj].document != null) {
            if (top.frames[obj].document.forms[0].FileName.value != "") {
                top.frames[obj].document.forms[0].PathUpload.value = document.forms[0].ctl00_MainContent_hddPathUpload.value;
                top.frames[obj].document.forms[0].hddCommand.value = "2";
                top.frames[obj].document.forms[0].submit();
            }
        }

        removeFile2(maxUploads, fileFieldName);
    }
    catch (err) { }
}
//Taskbar
var f = 0;
var numb = 1;
var flag = 0;
function shalert(v) {
    numb = v;
    var i = 0;
    if (flag != v) {
        f = 0;
    }
    if (f % 2 == 0) {
        for (i = 1; i <= 3; i++) {
            if (i == v) {
                gmobj("divAlert" + v).className = "presence_block clearfix";
                gmobj("divHeadAlert" + v).className = "presence_block clearfix";
                gmobj("divComment" + v).className = "fl ArB12 rev_pad_task hand";
                resizealert();
            } else {
                gmobj("divAlert" + i).className = "presence_block rev_clearfix";
                gmobj("divHeadAlert" + i).className = "presence_block rev_clearfix";
                gmobj("divComment" + i).className = "fl ArB12 pad_task hand";
                gmobj("divAlert" + i).style.height = "auto";
            }
        }
    } else {
        gmobj("divAlert" + v).className = "presence_block rev_clearfix";
        gmobj("divHeadAlert" + v).className = "presence_block rev_clearfix";
        gmobj("divComment" + v).className = "fl ArB12 pad_task hand";
        gmobj("divAlert" + v).style.height = "auto";
    }
    if ((flag == v) || (f == 0)) {
        f++;
        flag = v;
    }
}
function resizealert() {
    if (numb != null) {
        var _ha = gmobj("divAlert" + numb).offsetHeight + "px";
        var _hw = parseInt(window.innerHeight - 70) + "px";
        if (window.innerHeight <= gmobj("divAlert" + numb).offsetHeight) {
            gmobj("divAlert" + numb).style.height = _hw;
        } else {
            gmobj("divAlert" + numb).style.height = "auto";
        }
    }
}
//End Taskbar

function OrderAlertIsShip(address) {
    alert(address);
}
function OrderAlertIsTrans() {
    alert("Bạn không thể đặt hàng! \n\nHiện nay chúng tôi chưa giao hàng tới tỉnh thành này. Có thể do người bán hàng chưa chọn nhà vận chuyển cho Shop của mình. \n\n Vui lòng liên hệ với nguời bán để biết thêm thông tin!");
    //window.history.back();
}

function OrderAlertIsPayType(address) {
    alert("Bạn không thể đặt hàng! \n\nHiện nay chúng tôi chưa áp dụng hình thức Trả sau (thu tiền mặt khi giao hàng) tới tỉnh thành này. \n\nDanh sách các tỉnh thành được phép trả sau của người bán này: \n" + address);
}
function OrderAlertPayTypeNull() {
    alert("Bạn không thể đặt hàng! \n\nHiện nay chúng tôi chưa áp dùng hình thức Trả sau (thu tiền mặt khi giao hàng) tới tỉnh thành này. \n\nVui lòng chọn địa chỉ giao hàng khác hoặc liên hệ với nguời bán để biết thêm thông tin!");
    //window.history.back();
}
function OrderAlertDistrictNull() {
    alert("Bạn không thể đặt hàng! \n\nBạn chưa nhập Quận huyện nơi trả hàng. \n\nMời bạn nhập Quận huyện nơi trả hàng hoặc liên hệ với nguời bán để biết thêm thông tin!");

}

//Check Form Order
function validateFrmOrder(frm, flag) {
    if (flag == 0) {
        confirm("Bạn có muốn đặt hàng không?");
        if (frm.ctl00_MainContent_txtQuantity != undefined) {
            if (Trim(frm.ctl00_MainContent_txtQuantity.value) == "") {
                alert("Xin vui lòng nhập vào số lượng sản phẩm đặt mua!");
                frm.ctl00_MainContent_txtQuantity.focus();
                return false;
            }
        }
        if (frm.txtQuantity != undefined) {
            if (Trim(frm.txtQuantity.value) == "") {
                alert("Xin vui lòng nhập vào số lượng sản phẩm đặt mua!");
                frm.txtQuantity.focus();
                return false;
            }
        }
        if (Trim(frm.ctl00_MainContent_txtFullName.value) == "") {
            alert("Xin vui lòng nhập vào họ tên người nhận hàng!");
            frm.ctl00_MainContent_txtFullName.focus();
            return false;
        }

        if (Trim(frm.ctl00_MainContent_txtAddress.value) == "") {
            alert("Xin vui lòng nhập vào địa chỉ nhận hàng!");
            frm.ctl00_MainContent_txtAddress.focus();
            return false;
        }

        //    if (Trim(frm.ctl00$MainContent$ddlProvince.value) == "" || Trim(frm.ctl00$MainContent$ddlProvince.value) == "0") {
        //        alert("Xin vui lòng chọn Tỉnh/Thành phố giao hàng!");
        //        frm.ctl00$MainContent$ddlProvince.focus();
        //        return false;
        //    }

        //    if (Trim(frm.ctl00$MainContent$ddlDistricts.value) == "" || Trim(frm.ctl00$MainContent$ddlDistricts.value) == "0") {
        //        alert("Xin vui lòng chọn Quận/Huyện giao hàng!");
        //        frm.ctl00$MainContent$ddlDistricts.focus();
        //        return false;
        //    }

        if (Trim(frm.ctl00_MainContent_txtHomeTel.value) == "" && Trim(frm.ctl00_MainContent_txtMobile.value) == "") {
            alert("Xin vui lòng nhập vào một trong các số điện thoại liên hệ!");
            frm.ctl00_MainContent_txtMobile.focus();
            return false;
        }

        if (Trim(frm.ctl00$MainContent$hddCheckShip.value) == "1") {
            alert("Bạn không thể đặt hàng!\n\n Hiện nay chúng tôi chưa giao hàng tới địa chỉ này. Hiện tại bạn chỉ được chọn giao hàng tại các tỉnh thành phố sau: \n\n" + frm.ctl00$MainContent$hddCheckShipAdd.value);
            frm.ctl00$MainContent$ddlProvince.focus();
            return false;
        }

        if (Trim(frm.ctl00$MainContent$hddCheckOrderType.value) == "1") {
            alert("Bạn không thể đặt hàng!\n\n Hiện nay chúng tôi chưa áp dụng hình thức thanh toán Trả sau (thu tiền khi giao hàng) ở địa chỉ này. \n\nHiện tại bạn chỉ được chọn Trả sau tại các tỉnh thành phố sau: \n\n" + frm.ctl00$MainContent$hddCheckOrderTypeAdd.value);
            frm.ctl00$MainContent$ddlProvince.focus();
            return false;
        }
    }
    return true;
}

function resetFrmOrder(frm) {
    if (frm.ctl00_MainContent_rdoShippingAddNew.checked) {
        frm.ctl00_MainContent_txtQuantity.value = "1";
        frm.ctl00_MainContent_txtFullName.value = "";
        frm.ctl00_MainContent_txtAddress.value = "";
        frm.ctl00_MainContent_txtHomeTel.value = "";
        frm.ctl00_MainContent_txtMobile.value = "";
        frm.ctl00_MainContent_txtNote.value = "";
    }
    return false;
}

function checkFContact(frm) {
    if (Trim(frm.ctl00$MainContent$txtFulname.value) == "") {
        alert("Xin vui lòng nhập Họ tên!");
        frm.ctl00$MainContent$txtFulname.focus();
        return false;
    }
    if (Trim(frm.ctl00$MainContent$txtAdd.value) == "") {
        alert("Xin vui lòng nhập Địa chỉ!");
        frm.ctl00$MainContent$txtAdd.focus();
        return false;
    }
    if (Trim(frm.ctl00$MainContent$txtEmail.value) == "") {
        alert("Xin vui lòng nhập Email!");
        frm.ctl00$MainContent$txtEmail.focus();
        return false;
    }
    if (Trim(frm.ctl00$MainContent$txtMobile.value) == "") {
        alert("Xin vui lòng nhập Số điện thoại!");
        frm.ctl00$MainContent$txtMobile.focus();
        return false;
    }

    return true;
}

