﻿


        function $get(id) { return document.getElementById(id); }
        var is_ie = (/msie/i.test(navigator.userAgent) && !/opera/i.test(navigator.userAgent));
        var is_ie5 = (is_ie && /msie 5\.0/i.test(navigator.userAgent));
        var is_ie6 = (is_ie && /msie 6\.0/i.test(navigator.userAgent));
        var is_ie7 = (is_ie && /msie 7\.0/i.test(navigator.userAgent));
        var is_ie8 = (is_ie && /msie 8\.0/i.test(navigator.userAgent));
        function sbmRate(id, star) {
            document.getElementById("ifrating").src = "rating.aspx?t=" + id + "&star=" + star;
        }

        function SubmitOnEnter(myfield, e, click) {
            var evt = e ? e : window.event;

            if (evt.keyCode == 13 || click==1) {

                    var searchText = myfield.value;
                    //if (searchText != strHelp && searchText !="" )
                     if (myfield.className == 'fc' && searchText !="" &&  trim(searchText) )
                     {
                        location.href = "Search.aspx?k=" + encodeURIComponent(myfield.value);
                    }
                }
            }


            
        
        var strHelp = "Nhập sản phẩm cần tìm";
        function init_search() {
            if ($get("txtsearchMas").value == "" || $get("txtsearchMas").value == strHelp) {
                $get("txtsearchMas").className = "s10 i clgr";
                $get("txtsearchMas").value = strHelp;
            }
        }
        function mFocus(obj) {
            if (obj.className == "s10 i clgr") {
                obj.value = "";
                obj.className = "fc";
            }
        }
        function mBlur(obj) {
            if (obj.value == "" && obj.className == "fc") {
                obj.value = strHelp;
                obj.className = "s10 i clgr";
            }
        }
        function LTrim( value ) {var re = /\s*((\S+\s*)*)/;return value.replace(re, "$1");}
function RTrim( value ) {var re = /((\s*\S+)*)\s*/;return value.replace(re, "$1");}
function trim( value ) {return LTrim(RTrim(value));}
         function cht_trim(str, chars) {
        return cht_ltrim(cht_rtrim(str, chars), chars);
        }

        function cht_ltrim(str, chars) {
        chars = chars || "\\s";
        return str.replace(new RegExp("^[" + chars + "]+", "g"), "");
        }

        function cht_rtrim(str, chars) {
        chars = chars || "\\s";
        return str.replace(new RegExp("[" + chars + "]+$", "g"), "");
        }
        
//        function loadimgqc(id, n) {
//            rotateEffectDESC($get("sel_qc").value, 1);
//            $get("sel_qc").value = id;
//        }
//        function rotateEffectASC(image_id, fopa) {
//            fopa += parseFloat('0.2');
//            if (is_ie)
//                document.getElementById("imgqc_" + image_id).style.filter = "alpha(opacity=" + fopa * 100 + ")";
//            else
//                document.getElementById("imgqc_" + image_id).style.opacity = fopa;
//            if (parseFloat(fopa) < 1) {
//                window.setTimeout("rotateEffectASC('" + image_id + "'," + fopa + ")", 10);
//            }
//        }

//        function rotateEffectDESC(image_id, fopa) {
//            fopa -= parseFloat('0.2');
//            if (is_ie)
//                document.getElementById("imgqc_" + image_id).style.filter = "alpha(opacity=" + fopa * 100 + ")";
//            else
//                document.getElementById("imgqc_" + image_id).style.opacity = fopa;
//            if (parseFloat(fopa) > 0) {
//                window.setTimeout("rotateEffectDESC('" + image_id + "'," + fopa + ")", 10);
//            }
//            else {
//                var id = $get("sel_qc").value;
//                document.title = id + "";            
//                $get("imgqc_"+image_id).className = "hid";
//                $get("cham_" + image_id).className = "chamtron fl";

//                $get("imgqc_" + id).className = "p";
//                $get("cham_" + id).className = "chamtronsel fl";
//                rotateEffectASC(id, 0);

//            }
//       }


        function _Delete(id) {
            if (window.confirm("Bạn có muốn xóa không?") == true) {
                __doPostBack('btn_xoa', id);
                return true;
            }
            else {
                return false;
            }
        }
        
         function isNumber(s) {
            var str="0123456789" 
            for (var j=0;j<s.length;j++) {
                if (str.indexOf(s.charAt(j))==-1)
                    return false;
            }
            return true;
        } 
        function _Update(id) {
            if(isNumber($get("txtsl_" + id).value)==false)
            {
            alert("Vui lòng nhập số!");          
            return false;
            }        
        
            if (window.confirm("Bạn có muốn cập nhật lại số lượng không?") == true) {
                id = id + "_" + $get("txtsl_" + id).value;
                __doPostBack('btn_sua', id);
                return true;
            }
            else {
                return false;
            }
        }
        
