﻿
    //lenh tim kiem
    function lenhtimkiem_action(timkiemtrong,chuoitimkiem)
    {
        var chuoiurl = "";
        if(timkiemtrong == "nhasanxuat_vpp")
        {
            chuoiurl = "Defaultnew.aspx?page=timkiem&left=vanphongpham&pagenum=1&timkiemtrong=nhasanxuat";
            chuoiurl += "&chuoitimkiem=" + chuoitimkiem;
            window.location = chuoiurl;
        }
        else{
            chuoiurl = "Defaultnew.aspx?page=timkiem&pagenum=1&timkiemtrong=" + timkiemtrong;
            chuoiurl += "&chuoitimkiem=" + chuoitimkiem;
            window.location = chuoiurl;
        }
    }
    
    
        //script gio hang moi
        function addsp(id,sosp)
        {
            makeRequest_giohang("ajaxsp.aspx?id=" + id + "&add=" + sosp,"sosanpham_tronggiohang");
        }
       
        function setsp(id,sosp)
        {
            if(document.getElementById('sosanpham_canmua').value == '0')
            {
                makeRequest_giohang("ajaxsp.aspx?id=" + id + "&set=1","sosanpham_tronggiohang");
            }
            else{
                makeRequest_giohang("ajaxsp.aspx?id=" + id + "&set=" + sosp,"sosanpham_tronggiohang");
            }
        }
	// private property
	var _keyStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";

	// public method for encoding
	function encode(input) {
		var output = "";
		var chr1, chr2, chr3, enc1, enc2, enc3, enc4;
		var i = 0;

		input = _utf8_encode(input);

		while (i < input.length) {

			chr1 = input.charCodeAt(i++);
			chr2 = input.charCodeAt(i++);
			chr3 = input.charCodeAt(i++);

			enc1 = chr1 >> 2;
			enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
			enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
			enc4 = chr3 & 63;

			if (isNaN(chr2)) {
				enc3 = enc4 = 64;
			} else if (isNaN(chr3)) {
				enc4 = 64;
			}

			output = output +
			_keyStr.charAt(enc1) + _keyStr.charAt(enc2) +
			_keyStr.charAt(enc3) + _keyStr.charAt(enc4);

		}

		return output;
	}

	// public method for decoding
	 function decode(input) {
		var output = "";
		var chr1, chr2, chr3;
		var enc1, enc2, enc3, enc4;
		var i = 0;

		input = input.replace(/[^A-Za-z0-9\+\/\=]/g, "");

		while (i < input.length) {

			enc1 = _keyStr.indexOf(input.charAt(i++));
			enc2 = _keyStr.indexOf(input.charAt(i++));
			enc3 = _keyStr.indexOf(input.charAt(i++));
			enc4 = _keyStr.indexOf(input.charAt(i++));

			chr1 = (enc1 << 2) | (enc2 >> 4);
			chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
			chr3 = ((enc3 & 3) << 6) | enc4;

			output = output + String.fromCharCode(chr1);

			if (enc3 != 64) {
				output = output + String.fromCharCode(chr2);
			}
			if (enc4 != 64) {
				output = output + String.fromCharCode(chr3);
			}

		}

		output = _utf8_decode(output);

		return output;

	}

	// private method for UTF-8 encoding
	 function _utf8_encode(string) {
	    //var hahaha = string
		//string = hahaha.replace(/\r\n/g,"\n");
		var utftext = "";

		for (var n = 0; n < string.length; n++) {

			var c = string.charCodeAt(n);

			if (c < 128) {
				utftext += String.fromCharCode(c);
			}
			else if((c > 127) && (c < 2048)) {
				utftext += String.fromCharCode((c >> 6) | 192);
				utftext += String.fromCharCode((c & 63) | 128);
			}
			else {
				utftext += String.fromCharCode((c >> 12) | 224);
				utftext += String.fromCharCode(((c >> 6) & 63) | 128);
				utftext += String.fromCharCode((c & 63) | 128);
			}

		}

		return utftext;
	}

	// private method for UTF-8 decoding
	 function _utf8_decode(utftext) {
		var string = "";
		var i = 0;
		var c = c1 = c2 = 0;

		while ( i < utftext.length ) {

			c = utftext.charCodeAt(i);

			if (c < 128) {
				string += String.fromCharCode(c);
				i++;
			}
			else if((c > 191) && (c < 224)) {
				c2 = utftext.charCodeAt(i+1);
				string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
				i += 2;
			}
			else {
				c2 = utftext.charCodeAt(i+1);
				c3 = utftext.charCodeAt(i+2);
				string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
				i += 3;
			}

		}

		return string;
	}

    //ham cat chuoi thanh array
    function split(chuoi,split_char)
    {   
        var return_array = new Array();
        var chuoikitudacat = "";
        for (var i = 0;i<chuoi.length;i++)
        {
            if(chuoi.charCodeAt(i) == split_char)
            {
                return_array[return_array.length] = chuoikitudacat;
                chuoikitudacat = "";
            }
            else
            {
                chuoikitudacat = chuoikitudacat + chuoi.charCodeAt(i);
            }
        }
        return_array[return_array.length] = chuoikitudacat;
		return return_array;
    }
   
    //cac ham set get delete cookie
    function Set_Cookie( name, value)
    {
        var returnvalue = true;
        var expires = 1;
        var path = '/';
        var domain = '';
        var secure = '';
        // set time, it's in milliseconds
        var today = new Date();
        today.setTime( today.getTime() );

        /*
        if the expires variable is set, make the correct
        expires time, the current script below will set
        it for x number of days, to make it for hours,
        delete * 24, for minutes, delete * 60 * 24
        */
        if ( expires )
        {
        expires = expires * 1000 * 60 * 60 * 24;
        }
        var expires_date = new Date( cookieexpires );
        //cookieexpires duoc tinh va ghi ta tu` ham page_load cua trang default
        document.cookie = name + "=" +escape( value ) +
        ( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) +
        ( ( path ) ? ";path=" + path : "" ) +
        ( ( domain ) ? ";domain=" + domain : "" ) +
        ( ( secure ) ? ";secure" : "" );
        if(Get_Cookie(name) != value)
        {
            returnvalue = false;
            if(document.cookie != null && document.cookie != "" && document.cookie != " ")
            {
            /*
                //trinh duyet van cho phep cookie nhung ko set cookie duoc
                var valuelogin = Get_Cookie("login");
                var valuegiohang = Get_Cookie("sanphamgiohang");
                //xoa het cookie tru gio hang va login
                var c=document.cookie.split(";");
	            for(var i=0;i<c.length;i++)
	            {
	                if(c[i] != "login" && c[i] != "sanphamgiohang")
	                {
	                    var e=c[i].indexOf("=");
	                    var n=e>-1?c[i].substr(0,e):c[i];
	                    document.cookie=n+"=;expires=Thu, 01 Jan 1970 00:00:00 GMT";
	                }
	            }
	            
                if(valuelogin != null)
                {
                    Set_Cookie_khongkiemtracookie("login",valuelogin);
                }
                if(valuegiohang != null)
                {
                    Set_Cookie_khongkiemtracookie("sanphamgiohang",valuegiohang);
                }
                Set_Cookie_khongkiemtracookie(name,value);
                */
            }
            else
            {
                //trinh duyet khong cho phep cookie
                var r=confirm("Xin lỗi trình duyệt của bạn đã tắt Cookie\n\nNhững chức năng như đăng nhập, mua hàng... của trang web sẽ\nkhông thể hoạt động được\n\nBạn có muốn đến trang hướng dẫn bật Cookie không?")
                if(r==true)
                {
                    window.location = "http://vietnamsach.com.vn/congty.aspx?page=hotrokhachhang&id=8";
                }
            }
        }
        return returnvalue;
    }
    function Set_Cookie_khongkiemtracookie( name, value)
    {
        var expires = 1;
        var path = '/';
        var domain = '';
        var secure = '';
        // set time, it's in milliseconds
        var today = new Date();
        today.setTime( today.getTime() );

        /*
        if the expires variable is set, make the correct
        expires time, the current script below will set
        it for x number of days, to make it for hours,
        delete * 24, for minutes, delete * 60 * 24
        */
        if ( expires )
        {
        expires = expires * 1000 * 60 * 60 * 24;
        }
        var expires_date = new Date( cookieexpires );

        document.cookie = name + "=" +escape( value ) +
        ( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) +
        ( ( path ) ? ";path=" + path : "" ) +
        ( ( domain ) ? ";domain=" + domain : "" ) +
        ( ( secure ) ? ";secure" : "" );
        
    }
    function Set_Cookie_danhriengchocookieexpirte( name, value)
    {
        var expires = 1;
        var path = '/';
        var domain = '';
        var secure = '';
        // set time, it's in milliseconds
        var today = new Date();
        today.setTime( today.getTime() );

        /*
        if the expires variable is set, make the correct
        expires time, the current script below will set
        it for x number of days, to make it for hours,
        delete * 24, for minutes, delete * 60 * 24
        */
        if ( expires )
        {
        expires = expires * 1000 * 60 * 60 * 24;
        }
        var expires_date = new Date( today.getTime() + (expires) );

        document.cookie = name + "=" +escape( value ) +
        ( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) +
        ( ( path ) ? ";path=" + path : "" ) +
        ( ( domain ) ? ";domain=" + domain : "" ) +
        ( ( secure ) ? ";secure" : "" );
        
    }
    var td1 = new Date();
    Set_Cookie_danhriengchocookieexpirte("gettime",td1.getTime());
    function Get_Cookie( check_name ) 
    {
	    // first we'll split this cookie up into name/value pairs
	    // note: document.cookie only returns name=value, not the other components
	    var a_all_cookies = document.cookie.split( ';' );
	    var a_temp_cookie = '';
	    var cookie_name = '';
	    var cookie_value = '';
	    var b_cookie_found = false; // set boolean t/f default f

	    for ( i = 0; i < a_all_cookies.length; i++ )
	    {
		    // now we'll split apart each name=value pair
		    a_temp_cookie = a_all_cookies[i].split( '=' );


		    // and trim left/right whitespace while we're at it
		    cookie_name = a_temp_cookie[0].replace(/^\s+|\s+$/g, '');

		    // if the extracted name matches passed check_name
		    if ( cookie_name == check_name )
		    {
			    b_cookie_found = true;
			    // we need to handle case where cookie has no value but exists (no = sign, that is):
			    if ( a_temp_cookie.length > 1 )
			    {
				    cookie_value = unescape( a_temp_cookie[1].replace(/^\s+|\s+$/g, '') );
			    }
			    // note that in cases where cookie is initialized but no value, null is returned
			    return cookie_value;
			    break;
		    }
		    a_temp_cookie = null;
		    cookie_name = '';
	    }
	    if ( !b_cookie_found )
	    {
		    return null;
	    }
    }
    
    function delall_Cookie() 
    {
	        var c=document.cookie.split(";");
	        for(var i=0;i<c.length;i++)
	        {
	            var e=c[i].indexOf("=");
	            var n=e>-1?c[i].substr(0,e):c[i];
	            document.cookie=n+"=;expires=Thu, 01 Jan 1970 00:00:00 GMT";
	        }
    }
     
    function Delete_Cookie(name) 
    {
        var path = '/';
        var domain = '';
        if ( Get_Cookie( name ) ) document.cookie = name + "=" +
        ( ( path ) ? ";path=" + path : "") +
        ( ( domain ) ? ";domain=" + domain : "" ) +
        ";expires=Thu, 01-Jan-1970 00:00:01 GMT";
    }
    
    function kiemtravadangnhap()
    {
        var emailorusername = document.getElementById('emailorusername').value;
        var pass = document.getElementById('pass').value;
        makeRequest_dangnhap('ajaxdangnhap.aspx?usernam_or_email=' + emailorusername + '&pass=' + pass,'chudangnhap')
    }
    
    function kiemtravadangnhap2()
    {
        document.getElementById('header_Login_emailorusername').value = document.getElementById('tendangnhap_dangnhap').value;
        document.getElementById('header_Login_pass').value = document.getElementById('matkhau_dangnhap').value;
        kiemtravadangnhap3();
        
        //makeRequest_dangnhap('ajaxdangnhap.aspx?usernam_or_email=' + emailorusername + '&pass=' + pass,'chudangnhap')
    }
    function kiemtravadangnhap3()
    {
        var actionstring = document.getElementById('form1').action;
        //kiem tra xem co bien l= chua 
        actionstring = actionstring.split("l=")[0];
        if(actionstring.length >= 13 &&  actionstring.charAt(12) == "?")
        {
            actionstring += "&l=" + encode(escape(document.getElementById('header_Login_emailorusername').value) + "#" + escape(document.getElementById('header_Login_pass').value));
        }
        else{
            actionstring += "?l=" + encode(escape(document.getElementById('header_Login_emailorusername').value) + "#" + escape(document.getElementById('header_Login_pass').value));
       
        }
        document.getElementById('form1').action = actionstring;
        Set_Cookie_khongkiemtracookie('login','dangnhap#' + Get_Cookie('login'))
        document.getElementById('header_Login_Button1').click();
        
    }
    function thoat() 
    {
    
        Delete_Cookie('login');
        gourl("Default.aspx?vns=1");
        /*
        makeRequest_chuan('ajaxlogin.aspx?sads=sad','div_login');
        
        //phan nay danh cho phan thanh toan 
        try
        {
        //document.getElementById('ctl03_td_dadangnhap').innerHTML = "<i style=\"color:black\"> Bạn đang mua hàng với tài khoản: </i><b style=\"color:red\">" + http_request_html_dangnhap + "</b><br>";
        document.getElementById('ctl03_td_dadangnhap').style.display = 'none';
        document.getElementById('ctl03_tr_login').style.display = 'block';
        }
        catch(e)
        {}*/
    }
    function kiemtralogin_va_thaydoi()
    {
        try
        {
            if(document.getElementById('spanlogined').innerHTML != "")
            {
                //da login 
                thaydoitrangweb_login(true);
                return true;
                //document.getElementById('dangkythanhvien1').innerHTML = document.getElementById('dangkythanhvien2').innerHTML = "Thông tin cá nhân";
            }
        }
        catch(e)
        {
            thaydoitrangweb_login(false);
            return false;
        }
    }
    
    function thaydoitrangweb_login(dalogin)
    { 
    /*
        if(dalogin)
        {
            //alert('da login');
            document.getElementById('dangkythanhvien1').innerHTML = document.getElementById('dangkythanhvien2').innerHTML = "Thông tin cá nhân";
        }
        else
        {
            //alert('chua login');
            document.getElementById('dangkythanhvien1').innerHTML = document.getElementById('dangkythanhvien2').innerHTML = "Đăng ký thành viên";
        }*/
    }
    
    //cac ham set get delete cookie<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
    var chophepchay_ham_gourl = false;
    var browser;
        if (navigator.userAgent.indexOf("Firefox") != -1)
        {
            browser = "ff";
        }
        else
        {
            browser = "ie";
        }
    //cac ham cho me nu trang chu o tren cung
    var menutrangchu_nowforcus = 'menu_trangchu';
    function doimaumenu_dangchi(element,bool)
    {
        if(element.id != menutrangchu_nowforcus)
        {
            if(bool)
            {
                element.style.backgroundColor = '#DEEFEA';
            }
            else
            {
                element.style.backgroundColor = '#BAE0DD';
            }
        }
    }
    function setforcus_menutrangchu(id)
    {
        document.getElementById(menutrangchu_nowforcus).style.backgroundColor = '#BAE0DD';
        document.getElementById(id).style.backgroundColor = '#DEEFEA';
        menutrangchu_nowforcus = id;
    }
    //ham nay dung de nhan dien cac trang sach bao bang dia
    //var bienthemcho_gourl = "&left=default";
    
    function gourl(url)
    {
        if(chophepchay_ham_gourl)
        {
            var bientam = url;
            try
            {
                bientam += bienthemcho_gourl_default;
            }
            catch(e){}
            try
            {
                bientam += bienthemcho_gourl_left;
            }
            catch(e){}
            try
            {
                bientam += bienthemcho_gourl_trangchu;
            }
            catch(e){}
            try
            {
                bientam += bienthemcho_gourl_giohang;
            }
            catch(e){}
            try
            {
                bientam += bienthemcho_gourl_default_timkiem;
            }
            catch(e){}
            bientam += "&timkiemtrong=" + string_tiemkiemtrong;
            bientam += "&chuoitimkiem=" + string_texttimkiem;
            var bientam2 = bientam;
            try
            {
                //rut gon link
                var i = 0;var j = 0;var daco =false;var arr3 = new Array();var arr4 = new Array();
                var arr1 = bientam2.split("?");
                bientam2 = arr1[0] + "?";
                var arr2 = new Array();
                arr2 = arr1[1].split("&");
                for(i = 0;i<arr2.length;i++)
                {
                    daco = false;
                    arr3 = arr2[i].split("=");
                    if(arr3.length == 2)
                    {
                        if(arr3[0] != "" && arr3[0] != " " && arr3[1] != "" && arr3[1] != " ")
                        {
                            for(j = i-1;j>=0;j--)
                            {
                                arr4 =  arr2[j].split("=");
                                if(arr4[0] == arr3[0])
                                {   
                                    daco = true;
                                    break
                                }
                            }
                        }
                    }
                    if(daco == false)
                    {
                        //them vao chuoi
                        bientam2 += arr2[i] + "&";
                    }
                    
                }
                window.location= bientam2;
            }
            catch(e)
            {
                window.location= bientam;
            }
            
        }
    }
    //cac ham danh cho menu san pham
    function menusanpham_onclick(element_id)
    {
        if(element_id == "sachbao" || element_id == "vanphongpham")
        {
            window.location =   'Default.aspx?left=' + element_id;
        }
        else
        {
        alert('Hiện chúng tôi đang hoàn thiện phần này mong quý khác quay lại sau');
        }
        
    }
    //chitietsan pham
    function ctsach(IDProduct)
    {
         window.location = 'Defaultnew.aspx?page=chitietsach&IDProduct=' + IDProduct;
    }
    
    function ghimenusanpham(id_sanphamdautien)
    {
        var html_menusanpham = document.getElementById('menusanpham').innerHTML;
        var all_html_menusanpham = "";
        if(id_sanphamdautien=="sachbao")
        {
            all_html_menusanpham += html_menusanpham.replace("$idsanpham$","sachbao").replace("$loaisanpham$","&nbsp;&nbsp;&nbsp;&nbsp;Sách&nbsp;&nbsp;&nbsp;&nbsp;").replace("$styleclass_sanpham$","menusanpham_dangchon1");
            all_html_menusanpham += html_menusanpham.replace("$idsanpham$","bangdia").replace("$loaisanpham$","Phần mềm - băng đĩa").replace("$styleclass_sanpham$","menusanpham_kochon1");
            all_html_menusanpham += html_menusanpham.replace("$idsanpham$","hoatuoi").replace("$loaisanpham$","Hoa tươi").replace("$styleclass_sanpham$","menusanpham_kochon1");
            all_html_menusanpham += html_menusanpham.replace("$idsanpham$","vanphongpham").replace("$loaisanpham$","Văn phòng phẩm").replace("$styleclass_sanpham$","menusanpham_kochon1");
            all_html_menusanpham += html_menusanpham.replace("$idsanpham$","qualuuniem").replace("$loaisanpham$","Đồ chơi & Quà lưu niệm").replace("$styleclass_sanpham$","menusanpham_kochon1");
            
        }
        else if(id_sanphamdautien=="bangdia")
        {
            all_html_menusanpham += html_menusanpham.replace("$idsanpham$","bangdia").replace("$loaisanpham$","Phần mềm - băng đĩa").replace("$styleclass_sanpham$","menusanpham_dangchon1");
            all_html_menusanpham += html_menusanpham.replace("$idsanpham$","hoatuoi").replace("$loaisanpham$","Hoa tươi").replace("$styleclass_sanpham$","menusanpham_kochon1");
            all_html_menusanpham += html_menusanpham.replace("$idsanpham$","vanphongpham").replace("$loaisanpham$","Văn phòng phẩm").replace("$styleclass_sanpham$","menusanpham_kochon1");
            all_html_menusanpham += html_menusanpham.replace("$idsanpham$","qualuuniem").replace("$loaisanpham$","Đồ chơi & Quà lưu niệm").replace("$styleclass_sanpham$","menusanpham_kochon1");
            all_html_menusanpham += html_menusanpham.replace("$idsanpham$","sachbao").replace("$loaisanpham$","Sách").replace("$styleclass_sanpham$","menusanpham_kochon1");
        }
        else if(id_sanphamdautien=="hoatuoi")
        {
            all_html_menusanpham += html_menusanpham.replace("$idsanpham$","hoatuoi").replace("$loaisanpham$","&nbsp;&nbsp;Hoa tươi&nbsp;&nbsp;").replace("$styleclass_sanpham$","menusanpham_dangchon1");
            all_html_menusanpham += html_menusanpham.replace("$idsanpham$","vanphongpham").replace("$loaisanpham$","Văn phòng phẩm").replace("$styleclass_sanpham$","menusanpham_kochon1");
            all_html_menusanpham += html_menusanpham.replace("$idsanpham$","qualuuniem").replace("$loaisanpham$","Đồ chơi & Quà lưu niệm").replace("$styleclass_sanpham$","menusanpham_kochon1");
            all_html_menusanpham += html_menusanpham.replace("$idsanpham$","sachbao").replace("$loaisanpham$","Sách").replace("$styleclass_sanpham$","menusanpham_kochon1");
            all_html_menusanpham += html_menusanpham.replace("$idsanpham$","bangdia").replace("$loaisanpham$","Phần mềm - băng đĩa").replace("$styleclass_sanpham$","menusanpham_kochon1");
        }
        else if(id_sanphamdautien=="vanphongpham")
        {
            all_html_menusanpham += html_menusanpham.replace("$idsanpham$","vanphongpham").replace("$loaisanpham$","Văn phòng phẩm").replace("$styleclass_sanpham$","menusanpham_dangchon1");
            all_html_menusanpham += html_menusanpham.replace("$idsanpham$","qualuuniem").replace("$loaisanpham$","Đồ chơi & Quà lưu niệm").replace("$styleclass_sanpham$","menusanpham_kochon1");
            all_html_menusanpham += html_menusanpham.replace("$idsanpham$","sachbao").replace("$loaisanpham$","Sách").replace("$styleclass_sanpham$","menusanpham_kochon1");
            all_html_menusanpham += html_menusanpham.replace("$idsanpham$","bangdia").replace("$loaisanpham$","Phần mềm - băng đĩa").replace("$styleclass_sanpham$","menusanpham_kochon1");
            all_html_menusanpham += html_menusanpham.replace("$idsanpham$","hoatuoi").replace("$loaisanpham$","Hoa tươi").replace("$styleclass_sanpham$","menusanpham_kochon1");
        }
        else if(id_sanphamdautien=="qualuuniem")
        {
            all_html_menusanpham += html_menusanpham.replace("$idsanpham$","qualuuniem").replace("$loaisanpham$","Đồ chơi & Quà lưu niệm").replace("$styleclass_sanpham$","menusanpham_dangchon1");
            all_html_menusanpham += html_menusanpham.replace("$idsanpham$","vanphongpham").replace("$loaisanpham$","Văn phòng phẩm").replace("$styleclass_sanpham$","menusanpham_kochon1");
            all_html_menusanpham += html_menusanpham.replace("$idsanpham$","sachbao").replace("$loaisanpham$","Sách").replace("$styleclass_sanpham$","menusanpham_kochon1");
            all_html_menusanpham += html_menusanpham.replace("$idsanpham$","bangdia").replace("$loaisanpham$","Phần mềm - băng đĩa").replace("$styleclass_sanpham$","menusanpham_kochon1");
            all_html_menusanpham += html_menusanpham.replace("$idsanpham$","hoatuoi").replace("$loaisanpham$","Hoa tươi").replace("$styleclass_sanpham$","menusanpham_kochon1");
        }
        document.getElementById('menusanpham').innerHTML = all_html_menusanpham;
    }
    // cac ham tim kiem
    var clicktimkiemlandau = true
    var anhhientai_chuyenkieugo = "imagesvns2/bogo_TELEX.gif";
    var chophepgotiengviet_trongotimkiem = true;
    /*
    function chuyenkieugo()
    {
        if(anhhientai_chuyenkieugo == "imagesvns2/bogo_ENG.gif")
        {
            document.getElementById('bogo').setAttribute("src","imagesvns2/bogo_VNI.gif");
            document.getElementById('timkiemtxt').style.paddingLeft = "39px";
            anhhientai_chuyenkieugo = "imagesvns2/bogo_VNI.gif";
            chophepgotiengviet_trongotimkiem = true;
            method = 2;
        }
        else if(anhhientai_chuyenkieugo == "imagesvns2/bogo_VNI.gif")
        {
            document.getElementById('bogo').setAttribute("src","imagesvns2/bogo_TELEX.gif");
            document.getElementById('timkiemtxt').style.paddingLeft = "60px";
            anhhientai_chuyenkieugo = "imagesvns2/bogo_TELEX.gif";
            chophepgotiengviet_trongotimkiem = true;
            method = 1;
        }
        else
        {
            document.getElementById('bogo').setAttribute("src","imagesvns2/bogo_ENG.gif");
            document.getElementById('timkiemtxt').style.paddingLeft = "45px";
            anhhientai_chuyenkieugo = "imagesvns2/bogo_ENG.gif";
            chophepgotiengviet_trongotimkiem = false;
        }
    }
    */
    function batkieugo_choo_timkiem()
    {
        if(chophepgotiengviet_trongotimkiem)
        {
            on_off = 1;
        }
    }
    //cac ham danh cho hien thi tiem kiem
    function hienthi_choncachtimkiem()
    {
        document.getElementById('choncachtimkiem').style.display="block";
        document.getElementById('cachtimkiem').style.display="none";
    }
    function hienthi_cachtimkiem(element)
    {
        //document.getElementById(now_cachtimkiem_id).style.color = "#444E42";
        document.getElementById(now_cachtimkiem_id).style.fontWeight = "normal";
        
        //element.style.color = "#000000";
        element.style.fontWeight = "bold";
        document.getElementById("cachtimkiem").innerHTML = element.innerHTML;
        now_cachtimkiem_id = element.id;
        document.getElementById('cachtimkiem').style.display="block";
        document.getElementById('choncachtimkiem').style.display="none";
    }
    
    
    
    //gio hang>>>>>>>>>>>>>>>>>>>>>Delete_Cookie Get_Cookie Set_Cookie
    //chuoi string danh cho id san pham dung trong truong hop trinh duyet ko cho phep cookie
    //var chuoi string phan nay lam sau !!!!!!!!!!!!!!!
    
    function giohang_suasosanpham(idsanpham)
    {
        if(document.getElementById('sosanpham_canmua_' + idsanpham).style.display == 'block')
        {
            //edit
            var sosanphamnay_dacotronggiohang = Get_Cookie(idsanpham);
            var sosanpham = document.getElementById('sosanpham_canmua_' + idsanpham).value;
            setsanpham_array_giohang(idsanpham,sosanpham);
            //Set_Cookie(idsanpham,sosanpham);
           // Set_Cookie('sosanpham_tronggiohang',(Get_Cookie('sosanpham_tronggiohang')*1 - sosanphamnay_dacotronggiohang*1 + sosanpham*1));
            
            document.getElementById('sosanpham_dachonmua_' + idsanpham).innerHTML = sosanpham;
            document.getElementById('sosanpham_canmua_' + idsanpham).style.display = 'none';
            document.getElementById('sosanpham_dachonmua_' + idsanpham).style.display = 'block';
            
            hienthi_sosanpham_tronggiohang();
        }
        else
        {
            //hien thi phan nhap so
            document.getElementById('sosanpham_canmua_' + idsanpham).style.display = 'block';
            document.getElementById('sosanpham_dachonmua_' + idsanpham).style.display = 'none';
        }
        
    }
    
    function hienthi_sosanpham_tronggiohang()
    {
        var sosanphamtroinggiohang = 0;
        for(var i = 0;i < giohang_sosanpham.length;i++)
        {
            sosanphamtroinggiohang = sosanphamtroinggiohang*1 +  giohang_sosanpham[i]*1;
        }
        document.getElementById('sosanpham_tronggiohang').innerHTML = sosanphamtroinggiohang;
        try
        {
            document.getElementById('sosanpham').style.display = "block";
            makeRequest_chuan('ajaxupdatesotiengiohang.aspx?sadsa=asd','sosanpham');
        }
        catch(e){}
    }
    /*var giohang_idsanpham = new Array();
    var giohang_sosanpham = new Array();
    function getcookiegiohang_and_settoarray()
    {
        var sanphamgiohang = Get_Cookie('sanphamgiohang');
        if(sanphamgiohang != null)
        {
            var array2chuoi = new Array();
            array2chuoi = split(sanphamgiohang,'$');
            giohang_idsanpham = split(array2chuoi[0],'#');
            giohang_sosanpham = split(array2chuoi[1],'#');
            alert(giohang_idsanpham + '\n' + giohang_sosanpham);
        }
    }
    getcookiegiohang_and_settoarray();*/
    function setsanphanvaocookie()
    {
        var chuoiidsanpham = "";
        var chuoisosanpham = "";
        for(var i = 0;i< giohang_idsanpham.length;i++)
        {
            if(giohang_sosanpham[i]*1 != 0)
            {
                if(i == giohang_idsanpham.length - 1)
                {
                    chuoiidsanpham += giohang_idsanpham[i];
                    chuoisosanpham += giohang_sosanpham[i];
                }
                else
                {
                    chuoiidsanpham += giohang_idsanpham[i] + "#";
                    chuoisosanpham += giohang_sosanpham[i] + "#";
                }
            }
        }
        return Set_Cookie('sanphamgiohang',chuoiidsanpham +  '$' + chuoisosanpham);
    }
    function setsanpham_array_giohang(idsanpham,sosanpham)
    {
        for(var i = 0;i<= giohang_idsanpham.length;i++)
        {
            if(i == giohang_idsanpham.length)
            {
                giohang_idsanpham[i] = idsanpham;
                giohang_sosanpham[i] = sosanpham;
                break;
            }
            else if(giohang_idsanpham[i] ==  idsanpham)
            {
                giohang_sosanpham[i] = sosanpham;
                break;
            }
        }
        setsanphanvaocookie();
    }
    function congthemsanpham_array_giohang(idsanpham,sosanpham)
    {
        for(var i = 0;i<= giohang_idsanpham.length;i++)
        {
            if(i == giohang_idsanpham.length)
            {
                giohang_idsanpham[i] = idsanpham;
                giohang_sosanpham[i] = sosanpham;
                break;
            }
            else if(giohang_idsanpham[i] ==  idsanpham)
            {
                giohang_sosanpham[i] = giohang_sosanpham[i]*1 + sosanpham*1;
                break;
            }
        }
        
        return setsanphanvaocookie();
    }
    function themsanpham_vaogiohang(idsanpham)
    {
        themsanpham_vaogiohang_nhieusanpham(idsanpham,'1');
    }
    function themsanpham_vaogiohang_nhieusanpham(idsanpham,sosanpham)
    {
        if(congthemsanpham_array_giohang(idsanpham,sosanpham))
        {
        hienthi_sosanpham_tronggiohang();
        var r=confirm("Bạn đã thêm sản phẩm này vào giỏ hàng. Bạn có muốn vào giỏ hàng ngay không");
        if (r==true)
        {
            gourl('Default.aspx?page=giohang&pagenum=1');
        }
        }
    }
    function xoasanpham_tronggiohang(idsanpham)
    {
          var r=confirm("Bạn thực sự muốn xóa sản phẩm này khỏi giỏ hàng");
          if (r==true)
          { 
              setsanpham_array_giohang(idsanpham,'0');  
              hienthi_sosanpham_tronggiohang();
              window.location.reload();
          }
        
    }
    //thanhtoan
    var mycars = new Array();//cac ten cau cac input trong muc than toan
        mycars[0] = "ctl03_PUserName";
        mycars[1] = "ctl03_PAddress";
        mycars[2] = "ctl03_PPhone";
        mycars[3] = "ctl03_PMail";
        mycars[4] = "ctl03_giong_nguoimauhang";
        mycars[5] = "ctl03_ShipUserName";
        mycars[6] = "ctl03_ShipAddress";
        mycars[7] = "ctl03_ShipPhone";
        mycars[8] = "ctl03_ShipMail";
        mycars[9] = "ctl03$PayMethod";
        mycars[10] = "ctl03$vanchuyen";
        mycars[11] = "ctl03_goiqua";
        mycars[12] = "ctl03_loichuc";
        mycars[13] = "ctl03_xuathoadon";
        mycars[14] = "ctl03_tencongty";
        mycars[15] = "ctl03_diachicongty";
        mycars[16] = "ctl03_masothue";
        var boll_desabe_all_thanhtoan = false;
        function disabe_all_thanhtoan(chophep)
        {
            if(chophep)
            {
                for (x in mycars)
                {
                    if(mycars[x] == "ctl03$PayMethod")
                    {
                        document.getElementById("ctl03_tienmat").setAttribute("disabled",chophep);
                        document.getElementById("ctl03_chuyenkhoan").setAttribute("disabled",chophep);
                        document.getElementById("ctl03_nhanvienbuudienthuho").setAttribute("disabled",chophep);
                        document.getElementById("ctl03_chuyentienquabuudien").setAttribute("disabled",chophep);
                        document.getElementById("ctl03_payoo").setAttribute("disabled",chophep);
                        document.getElementById("ctl03_nganluong").setAttribute("disabled",chophep);
                        document.getElementById("ctl03_mobivi").setAttribute("disabled",chophep);
                    }
                    else if(mycars[x] == "ctl03$vanchuyen")
                    {
                        document.getElementById("ctl03_theoyeucau").setAttribute("disabled",chophep);
                        document.getElementById("ctl03_quabuudien").setAttribute("disabled",chophep);
                        document.getElementById("ctl03_chuyenphatnhanh").setAttribute("disabled",chophep);
                        
                        document.getElementById("ctl03_chuyenphatnhanhDHL").setAttribute("disabled",chophep);
                        document.getElementById("ctl03_maybay").setAttribute("disabled",chophep);
                        document.getElementById("ctl03_thuybo").setAttribute("disabled",chophep);
                        
                    }
                    else
                    {
                        document.getElementById(mycars[x]).setAttribute("disabled",chophep);
                    }
                }
                document.getElementById("ctl03_cboCountry_nguoimua").setAttribute("disabled",chophep);
                document.getElementById("ctl03_cboCity_nguoimua").setAttribute("disabled",chophep);
                document.getElementById("ctl03_cboCountry_nguoinhan").setAttribute("disabled",chophep);
                document.getElementById("ctl03_cboCity_nguoinhan").setAttribute("disabled",chophep);
                document.getElementById("ctl03_masothemuahang").setAttribute("disabled",chophep);
                
                
                
                boll_desabe_all_thanhtoan = chophep;
            }
            else
            {
                for (x in mycars)
                {
                    if(mycars[x] == "ctl03$PayMethod")
                    {
                        document.getElementById("ctl03_tienmat").removeAttribute("disabled");
                        document.getElementById("ctl03_chuyenkhoan").removeAttribute("disabled");
                        document.getElementById("ctl03_nhanvienbuudienthuho").removeAttribute("disabled");
                        document.getElementById("ctl03_chuyentienquabuudien").removeAttribute("disabled");
                        document.getElementById("ctl03_payoo").removeAttribute("disabled");
                        document.getElementById("ctl03_nganluong").removeAttribute("disabled");
                        document.getElementById("ctl03_mobivi").removeAttribute("disabled");
                    }
                    else if(mycars[x] == "ctl03$vanchuyen")
                    {
                        document.getElementById("ctl03_theoyeucau").removeAttribute("disabled");
                        document.getElementById("ctl03_quabuudien").removeAttribute("disabled");
                        document.getElementById("ctl03_chuyenphatnhanh").removeAttribute("disabled");
                        
                        document.getElementById("ctl03_chuyenphatnhanhDHL").removeAttribute("disabled");
                        document.getElementById("ctl03_maybay").removeAttribute("disabled");
                        document.getElementById("ctl03_thuybo").removeAttribute("disabled");
                        
                    }
                    else
                    {
                        document.getElementById(mycars[x]).removeAttribute("disabled");
                    }
                }
                document.getElementById("ctl03_cboCountry_nguoimua").removeAttribute("disabled");
                document.getElementById("ctl03_cboCity_nguoimua").removeAttribute("disabled");
                document.getElementById("ctl03_cboCountry_nguoinhan").removeAttribute("disabled");
                document.getElementById("ctl03_cboCity_nguoinhan").removeAttribute("disabled");
                document.getElementById("ctl03_masothemuahang").removeAttribute("disabled");
                boll_desabe_all_thanhtoan = false;
                disabe_xuathoadon_thanhtoan(true);
                fix_phuongthuocthanhtoanvavanchuyen();
            }
        }
        function disabe_xuathoadon_thanhtoan(chophep)
        {
                if(chophep)
                {
                    document.getElementById("ctl03_tencongty").value = "";
                    document.getElementById("ctl03_diachicongty").value = "";
                    document.getElementById("ctl03_masothue").value = "";
                    document.getElementById("ctl03_tencongty").setAttribute("disabled",chophep);
                    document.getElementById("ctl03_diachicongty").setAttribute("disabled",chophep);
                    document.getElementById("ctl03_masothue").setAttribute("disabled",chophep);
                    
                }
                else
                {
                    document.getElementById("ctl03_tencongty").removeAttribute("disabled");
                    document.getElementById("ctl03_diachicongty").removeAttribute("disabled");
                    document.getElementById("ctl03_masothue").removeAttribute("disabled");
                }
        }
        function reset_all_thanhtoan()
        {
            if(!boll_desabe_all_thanhtoan)
            {
                var r=confirm("Bạn chắc chắn muốn nhập lại");
                if (r==true)
                { 
                    for (x in mycars)
                    {
                        if(mycars[x] == "ctl03_giong_nguoimauhang" || mycars[x] == "ctl03_xuathoadon" || mycars[x] == "ctl03_goiqua")
                        {
                            document.getElementById(mycars[x]).checked = false 
                        }
                        else if(mycars[x] == "ctl03$PayMethod")
                        {
                            document.getElementById("ctl03_tienmat").checked = true
                            document.getElementById("ctl03_chuyenkhoan").checked = false
                        }
                        else if(mycars[x] == "ctl03$vanchuyen")
                        {
                            document.getElementById("ctl03_theoyeucau").checked = true;
                        }
                        else
                        {
                            document.getElementById(mycars[x]).setAttribute("value","");
                        }
                    }
                    document.getElementById("ctl03_masothemuahang").setAttribute("value","");
                }
                fix_phuongthuocthanhtoanvavanchuyen();
            }
        }
        
        var chuoibien_post_thanhtoan = "";
        function kiemtra_hoantat_thanhtoan()
        {
            /*
             mycars[0] = "ctl03_PUserName";
        mycars[1] = "ctl03_PAddress";
        mycars[2] = "ctl03_PPhone";
        mycars[3] = "ctl03_PMail";
        mycars[4] = "ctl03_giong_nguoimauhang";
        mycars[5] = "ctl03_ShipUserName";
        mycars[6] = "ctl03_ShipAddress";
        mycars[7] = "ctl03_ShipPhone";
        mycars[8] = "ctl03_ShipMail";
        mycars[9] = "ctl03$PayMethod";
        mycars[10] = "ctl03$vanchuyen";
        mycars[11] = "ctl03_goiqua";
        mycars[12] = "ctl03_loichuc";
        mycars[13] = "ctl03_xuathoadon";
        mycars[14] = "ctl03_tencongty";
        mycars[15] = "ctl03_diachicongty";
        mycars[16] = "ctl03_masothue";*/
            if(document.getElementById('ctl03_PUserName').value != '' && document.getElementById('ctl03_PAddress').value != '' && document.getElementById('ctl03_PAddress').value != '' && document.getElementById('ctl03_PMail').value != '' && document.getElementById('ctl03_ShipUserName').value != '' && document.getElementById('ctl03_ShipAddress').value != '' && document.getElementById('ctl03_ShipPhone').value != '' && document.getElementById('ctl03_ShipMail').value != '')
            {
                return true;
            }
            else
            {
                return false;
            }
        }
        function hoantat_thanhtoan()
        {
            if(!boll_desabe_all_thanhtoan)
            {
                if(kiemtra_loaivanchuyen_cophuhopvoidiachinhanko())
                {
                    if(kiemtra_loaithanhtoan_cophuhopvoidiachinhanko())
                    {
                        if(kiemtra_hoantat_thanhtoan())
                        {
                            disabe_all_thanhtoan(true);
                            chuoibien_post_thanhtoan = "";
                            for (x in mycars)
                            {
                                if(mycars[x] == "ctl03_giong_nguoimauhang" || mycars[x] == "ctl03_xuathoadon" || mycars[x] == "ctl03_goiqua")
                                {
                                    if(document.getElementById(mycars[x]).checked)
                                    {
                                        chuoibien_post_thanhtoan += "&data_thanhtoan_" + x + "=" + escape(encode('true'));
                                    }
                                    else
                                    {
                                         chuoibien_post_thanhtoan += "&data_thanhtoan_" + x + "=" + escape(encode('false'));
                                    }
                                }
                                else if(mycars[x] == "ctl03$PayMethod")
                                {
                                    if(document.getElementById("ctl03_tienmat").checked)
                                    {
                                        chuoibien_post_thanhtoan += "&data_thanhtoan_" + x + "=" + escape(encode("tienmat"));
                                    }
                                    else if(document.getElementById("ctl03_chuyenkhoan").checked)
                                    {
                                        chuoibien_post_thanhtoan += "&data_thanhtoan_" + x + "=" + escape(encode("chuyenkhoan"));
                                    }
                                    else if(document.getElementById("ctl03_nhanvienbuudienthuho").checked)
                                    {
                                        chuoibien_post_thanhtoan += "&data_thanhtoan_" + x + "=" + escape(encode("nhanvienbuudienthuho"));
                                    }
                                    else
                                    {
                                        chuoibien_post_thanhtoan += "&data_thanhtoan_" + x + "=" + escape(encode("chuyentienquabuudien"));
                                    }
                                }
                                else if(mycars[x] == "ctl03_PAddress")
                                {
                                    chuoibien_post_thanhtoan += "&data_thanhtoan_" + x + "=" + escape(encode(document.getElementById(mycars[x]).value + " " + document.getElementById("ctl03_cboCity_nguoimua").options[document.getElementById("ctl03_cboCity_nguoimua").selectedIndex].text + " " + document.getElementById("ctl03_cboCountry_nguoimua").options[document.getElementById("ctl03_cboCountry_nguoimua").selectedIndex].text));
                                }
                                else if(mycars[x] == "ctl03_ShipAddress")
                                {
                                    chuoibien_post_thanhtoan += "&data_thanhtoan_" + x + "=" + escape(encode(document.getElementById(mycars[x]).value + " " + document.getElementById("ctl03_cboCity_nguoinhan").options[document.getElementById("ctl03_cboCity_nguoinhan").selectedIndex].text + " " + document.getElementById("ctl03_cboCountry_nguoinhan").options[document.getElementById("ctl03_cboCountry_nguoinhan").selectedIndex].text));
                                    //et côkie cho phan tinh tien
                                    Set_Cookie('thanhtoan_cityid',document.getElementById("ctl03_cboCity_nguoinhan").options[document.getElementById("ctl03_cboCity_nguoinhan").selectedIndex].value);
                                    Set_Cookie('thanhtoan_countryid',document.getElementById("ctl03_cboCountry_nguoinhan").options[document.getElementById("ctl03_cboCountry_nguoinhan").selectedIndex].value);
                                    
                                }
                                else if(mycars[x] == "ctl03$vanchuyen")
                                {
                                    if(document.getElementById("ctl03_theoyeucau").checked)//ta noi trong noi thanh
                                    {
                                        chuoibien_post_thanhtoan += "&data_thanhtoan_" + x + "=" + escape(encode("theoyeucau"));
                                        Set_Cookie('thanhtoan_shippid','18');
                                    }
                                    else if(document.getElementById("ctl03_quabuudien").checked) 
                                    {
                                        chuoibien_post_thanhtoan += "&data_thanhtoan_" + x + "=" + escape(encode("quabuudien"));
                                        Set_Cookie('thanhtoan_shippid','11');
                                    }
                                    else if(document.getElementById("ctl03_chuyenphatnhanh").checked)
                                    {
                                        chuoibien_post_thanhtoan += "&data_thanhtoan_" + x + "=" + escape(encode("chuyenphatnhanh"));
                                        Set_Cookie('thanhtoan_shippid','13');
                                    }
                                    else if(document.getElementById("ctl03_chuyenphatnhanhDHL").checked)
                                    {
                                        chuoibien_post_thanhtoan += "&data_thanhtoan_" + x + "=" + escape(encode("chuyenphatnhanhDHL"));
                                        Set_Cookie('thanhtoan_shippid','24');
                                    }
                                    else if(document.getElementById("ctl03_maybay").checked)
                                    {
                                        chuoibien_post_thanhtoan += "&data_thanhtoan_" + x + "=" + escape(encode("maybay"));
                                        Set_Cookie('thanhtoan_shippid','25');
                                    }
                                    else if(document.getElementById("ctl03_thuybo").checked)
                                    {
                                        chuoibien_post_thanhtoan += "&data_thanhtoan_" + x + "=" + escape(encode("thuybo"));
                                        Set_Cookie('thanhtoan_shippid','26');
                                    }
                                }
                                else
                                {
                                    chuoibien_post_thanhtoan += "&data_thanhtoan_" + x + "=" + escape(encode(document.getElementById(mycars[x]).value));
                                }
                            }
                            //Set_Cookie('data',encode(chuoibien_post_thanhtoan));
                            Set_Cookie('masothemuahang_thekhuyenmai',document.getElementById("ctl03_masothemuahang").value);
                            makeRequest('ajaxgiohang.aspx?sads=asd' + chuoibien_post_thanhtoan,'ketnoi_sever');
                        }
                        else
                        {
                            alert('Chú ý các phần có dấu * cần được nhập đầy đủ');
                        }
                    }
                }
            }
            else
            {
                alert('Lệnh thanh toán đã hoặc đang được thực thi');
            }
        }
        var checkbox_vanchuyen = new Array();
        checkbox_vanchuyen[0] = "ctl03_theoyeucau";
        checkbox_vanchuyen[1] = "ctl03_quabuudien";
        checkbox_vanchuyen[2] = "ctl03_chuyenphatnhanh";
        checkbox_vanchuyen[3] = "ctl03_chuyenphatnhanhDHL";
        checkbox_vanchuyen[4] = "ctl03_maybay";
        checkbox_vanchuyen[5] = "ctl03_thuybo";
        
        checkbox_vanchuyen[6] = "ctl03_theoyeucau";
        checkbox_vanchuyen[7] = "ctl03_quabuudien";
        checkbox_vanchuyen[8] = "ctl03_chuyenphatnhanh";
        checkbox_vanchuyen[9] = "ctl03_chuyenphatnhanhDHL";
        checkbox_vanchuyen[10] = "ctl03_maybay";
        checkbox_vanchuyen[11] = "ctl03_thuybo";
        var checkbox_thanhtoan = new Array();
        checkbox_thanhtoan[0] = "ctl03_tienmat";
        checkbox_thanhtoan[1] = "ctl03_chuyenkhoan";
        checkbox_thanhtoan[2] = "ctl03_nhanvienbuudienthuho";
        checkbox_thanhtoan[3] = "ctl03_chuyentienquabuudien";
        
        checkbox_thanhtoan[4] = "ctl03_tienmat";
        checkbox_thanhtoan[5] = "ctl03_chuyenkhoan";
        checkbox_thanhtoan[6] = "ctl03_nhanvienbuudienthuho";
        checkbox_thanhtoan[7] = "ctl03_chuyentienquabuudien";
        function fix_phuongthuocthanhtoanvavanchuyen()
        {   
            var chophep = true;
            document.getElementById("ctl03_tienmat").setAttribute("disabled",chophep);
            document.getElementById("ctl03_chuyenkhoan").setAttribute("disabled",chophep);
            document.getElementById("ctl03_nhanvienbuudienthuho").setAttribute("disabled",chophep);
            document.getElementById("ctl03_chuyentienquabuudien").setAttribute("disabled",chophep);
            /*document.getElementById("ctl03_payoo").setAttribute("disabled",chophep);
            document.getElementById("ctl03_nganluong").setAttribute("disabled",chophep);
            document.getElementById("ctl03_mobivi").setAttribute("disabled",chophep);
        */
            document.getElementById("ctl03_theoyeucau").setAttribute("disabled",chophep);
            document.getElementById("ctl03_quabuudien").setAttribute("disabled",chophep);
            document.getElementById("ctl03_chuyenphatnhanh").setAttribute("disabled",chophep);
            
            document.getElementById("ctl03_chuyenphatnhanhDHL").setAttribute("disabled",chophep);
            document.getElementById("ctl03_maybay").setAttribute("disabled",chophep);
            document.getElementById("ctl03_thuybo").setAttribute("disabled",chophep);
            /*
            document.getElementById("ctl03_tienmat").removeAttribute("disabled");
            document.getElementById("ctl03_chuyenkhoan").removeAttribute("disabled");
            document.getElementById("ctl03_nhanvienbuudienthuho").removeAttribute("disabled");
            document.getElementById("ctl03_chuyentienquabuudien").removeAttribute("disabled");
            document.getElementById("ctl03_payoo").removeAttribute("disabled");
            document.getElementById("ctl03_nganluong").removeAttribute("disabled");
            document.getElementById("ctl03_mobivi").removeAttribute("disabled");
            
            document.getElementById("ctl03_theoyeucau").removeAttribute("disabled");
            document.getElementById("ctl03_quabuudien").removeAttribute("disabled");
            document.getElementById("ctl03_chuyenphatnhanh").removeAttribute("disabled");
            
            document.getElementById("ctl03_chuyenphatnhanhDHL").removeAttribute("disabled");
            document.getElementById("ctl03_maybay").removeAttribute("disabled");
            document.getElementById("ctl03_thuybo").removeAttribute("disabled");
            */
            //fix van chuyen
            if(document.getElementById("ctl03_cboCountry_nguoinhan").options[document.getElementById("ctl03_cboCountry_nguoinhan").selectedIndex].value == 204)
            {
                //document.getElementById("ctl03_quabuudien").checked = true;
                document.getElementById("ctl03_quabuudien").removeAttribute("disabled");
                document.getElementById("ctl03_chuyenphatnhanh").removeAttribute("disabled");
                if(document.getElementById("ctl03_cboCity_nguoinhan").options[document.getElementById("ctl03_cboCity_nguoinhan").selectedIndex].value == 21)
                {
                    document.getElementById("ctl03_theoyeucau").removeAttribute("disabled");
                    //document.getElementById("ctl03_theoyeucau").checked = true;
                }
            }
            else
            {
                document.getElementById("ctl03_chuyenphatnhanhDHL").removeAttribute("disabled");
                //document.getElementById("ctl03_chuyenphatnhanhDHL").checked = true;
                document.getElementById("ctl03_maybay").removeAttribute("disabled");
                document.getElementById("ctl03_thuybo").removeAttribute("disabled");
            }
            for(var i = 0;i<checkbox_vanchuyen.length;i++)
            {
                if(document.getElementById(checkbox_vanchuyen[i]).checked && document.getElementById(checkbox_vanchuyen[i]).getAttribute("disabled"))
                {
                    document.getElementById(checkbox_vanchuyen[i*1 + 1]).checked = true;
                }
            }
            
            //fix thanh toan
            if(document.getElementById("ctl03_theoyeucau").checked)
            {//chuyentan noi trong tp hcm
                document.getElementById("ctl03_tienmat").removeAttribute("disabled");
                //document.getElementById("ctl03_tienmat").checked = true;
                document.getElementById("ctl03_chuyenkhoan").removeAttribute("disabled");
                //document.getElementById("ctl03_nhanvienbuudienthuho").removeAttribute("disabled");
                document.getElementById("ctl03_chuyentienquabuudien").removeAttribute("disabled");
            }
            else if(document.getElementById("ctl03_quabuudien").checked || document.getElementById("ctl03_chuyenphatnhanh").checked)
            {
                //document.getElementById("ctl03_tienmat").removeAttribute("disabled");
                document.getElementById("ctl03_chuyenkhoan").removeAttribute("disabled");
                //document.getElementById("ctl03_chuyenkhoan").checked = true;
                document.getElementById("ctl03_nhanvienbuudienthuho").removeAttribute("disabled");
                document.getElementById("ctl03_chuyentienquabuudien").removeAttribute("disabled");
            }
            else
            {
                //document.getElementById("ctl03_tienmat").removeAttribute("disabled");
                document.getElementById("ctl03_chuyenkhoan").removeAttribute("disabled");
                document.getElementById("ctl03_chuyenkhoan").checked = true;
                //document.getElementById("ctl03_nhanvienbuudienthuho").removeAttribute("disabled");
                document.getElementById("ctl03_chuyentienquabuudien").removeAttribute("disabled");
            }
            for(var i = 0;i<checkbox_thanhtoan.length;i++)
            {
                if(document.getElementById(checkbox_thanhtoan[i]).checked && document.getElementById(checkbox_thanhtoan[i]).getAttribute("disabled"))
                {
                    document.getElementById(checkbox_thanhtoan[i*1 + 1]).checked = true;
                }
            }
        }
        function kiemtra_loaithanhtoan_cophuhopvoidiachinhanko()
        {
            var value_return = true;
            if(document.getElementById("ctl03_tienmat").checked)//
            {
                if(!document.getElementById("ctl03_theoyeucau").checked )
                {
                    value_return = false;
                    alert('Phương thức thanh toán không hợp lệ\n\nGiao tiền trực tiếp cho nhân viên Việt Nam Sách \n(chỉ áp dụng cho phương thức vận chuyển "Chuyển tận nơi trong nội thành TP-HCM" )\n\nQuý khách vui lòng chọn phương thức khác!');
                }
                if(document.getElementById("ctl03_cboCity_nguoinhan").options[document.getElementById("ctl03_cboCity_nguoinhan").selectedIndex].value != 21 || document.getElementById("ctl03_cboCountry_nguoinhan").options[document.getElementById("ctl03_cboCountry_nguoinhan").selectedIndex].value != 204)
                {
                    value_return = false;
                    alert('Phương thức thanh toán không hợp lệ\n\nGiao tiền trực tiếp cho nhân viên Việt Nam Sách \n(chỉ áp dụng cho địa chỉ tại Hồ Chí Minh/Việt Nam)\n\nQuý khách vui lòng chọn phương thức khác!');
                }
            }
            return value_return
        }
        function kiemtra_loaivanchuyen_cophuhopvoidiachinhanko()
        {
            var value_return = true;
            if(document.getElementById("ctl03_theoyeucau").checked)//ta noi trong noi thanh
            {
                if(document.getElementById("ctl03_cboCity_nguoinhan").options[document.getElementById("ctl03_cboCity_nguoinhan").selectedIndex].value != 21 || document.getElementById("ctl03_cboCountry_nguoinhan").options[document.getElementById("ctl03_cboCountry_nguoinhan").selectedIndex].value != 204)
                {
                    value_return = false;
                    alert('Vận chuyển tận nơi trong nội thành chỉ áp dụng cho TP-Hồ Chí Minh !\n Mong quý khách vui lòng chọn hình thức vận chuyển khác.')
                }
            }
            else if(document.getElementById("ctl03_quabuudien").checked) 
            {
                if(document.getElementById("ctl03_cboCountry_nguoinhan").options[document.getElementById("ctl03_cboCountry_nguoinhan").selectedIndex].value != 204)
                {
                    value_return = false;
                    alert('Chuyển thường qua bưu điện chỉ áp dụng trong nước Việt Nam !\n Mong quý khách vui lòng chọn hình thức vận chuyển khác.')
                }
            }
            else if(document.getElementById("ctl03_chuyenphatnhanh").checked)
            {
                if(document.getElementById("ctl03_cboCountry_nguoinhan").options[document.getElementById("ctl03_cboCountry_nguoinhan").selectedIndex].value != 204)
                {
                    value_return = false;
                    alert('Chuyển phát nhanh chỉ áp dụng trong nước Việt Nam !\n Mong quý khách vui lòng chọn hình thức vận chuyển khác.')
                }
            }
            else if(document.getElementById("ctl03_chuyenphatnhanhDHL").checked)
            {
                if(document.getElementById("ctl03_cboCountry_nguoinhan").options[document.getElementById("ctl03_cboCountry_nguoinhan").selectedIndex].value == 204)
                {
                    value_return = false;
                    alert('Chuyển phát nhanh DHL chỉ áp dụng ngoài nước Việt Nam !\n Mong quý khách vui lòng chọn hình thức vận chuyển khác.')
                }
            }
            else if(document.getElementById("ctl03_maybay").checked)
            {
                if(document.getElementById("ctl03_cboCountry_nguoinhan").options[document.getElementById("ctl03_cboCountry_nguoinhan").selectedIndex].value == 204)
                {
                    value_return = false;
                    alert('Vận chuyển bằng máy bay (Air mail) chỉ áp dụng ngoài nước Việt Nam !\n Mong quý khách vui lòng chọn hình thức vận chuyển khác.')
                }
            }
            else if(document.getElementById("ctl03_thuybo").checked)
            {
                if(document.getElementById("ctl03_cboCountry_nguoinhan").options[document.getElementById("ctl03_cboCountry_nguoinhan").selectedIndex].value == 204)
                {
                    value_return = false;
                    alert('Vận chuyển bằng Thủy bộ(Surface mail) chỉ áp dụng ngoài nước Việt Nam !\n Mong quý khách vui lòng chọn hình thức vận chuyển khác.')
                }
            }
            return value_return;
        }
        function fix_tinhthanhvadatnuuoc(element_quocgia,id_tinhthanh,id_combobox)
        {
            if(element_quocgia.selectedIndex != 203)
            {
               // alert(element_quocgia.options[element_quocgia.selectedIndex].text);
                document.getElementById(id_combobox).selectedIndex = 64; 
                document.getElementById(id_tinhthanh).style.display = 'none';
                document.getElementById(id_tinhthanh + '2').style.display = 'none';
            }
            else
            {
                document.getElementById(id_combobox).selectedIndex = 20; 
                document.getElementById(id_tinhthanh).style.display = 'block';
                document.getElementById(id_tinhthanh + '2').style.display = 'block';
            }
        }
        function nguoimua_giong_nguoinhan()
        {
            document.getElementById("ctl03_ShipUserName").value  = document.getElementById("ctl03_PUserName").value
            document.getElementById("ctl03_ShipAddress").value = document.getElementById("ctl03_PAddress").value
            document.getElementById("ctl03_ShipPhone").value = document.getElementById("ctl03_PPhone").value
            document.getElementById("ctl03_ShipMail").value = document.getElementById("ctl03_PMail").value
            
            document.getElementById("ctl03_cboCountry_nguoinhan").selectedIndex = document.getElementById("ctl03_cboCountry_nguoimua").selectedIndex
            document.getElementById("ctl03_cboCity_nguoinhan").selectedIndex = document.getElementById("ctl03_cboCity_nguoimua").selectedIndex
            document.getElementById("td_city_nguoinhan").style.display = document.getElementById("td_city_nguoimua").style.display;
            document.getElementById("td_city_nguoinhan2").style.display = document.getElementById("td_city_nguoimua2").style.display;
            fix_phuongthuocthanhtoanvavanchuyen();
        }
        function dangky_trongphanthanhtoan()
        {
            var chuoibien_post_thanhtoan = "";
            if(kiemtra_hoantat_dangkynhanh())
            {
                chuoibien_post_thanhtoan += "tranhoainamzoha01" + document.getElementById("ctl03_PUserName").value;
                chuoibien_post_thanhtoan += "tranhoainamzoha01" + document.getElementById("ctl03_PAddress").value;
                chuoibien_post_thanhtoan += "tranhoainamzoha01" + document.getElementById("ctl03_cboCity_nguoimua").options[document.getElementById("ctl03_cboCity_nguoimua").selectedIndex].value
                chuoibien_post_thanhtoan += "tranhoainamzoha01" + document.getElementById("ctl03_cboCountry_nguoimua").options[document.getElementById("ctl03_cboCountry_nguoimua").selectedIndex].value
                chuoibien_post_thanhtoan += "tranhoainamzoha01" + document.getElementById("ctl03_PPhone").value;
                chuoibien_post_thanhtoan += "tranhoainamzoha01" + document.getElementById("ctl03_PMail").value;
                chuoibien_post_thanhtoan += "tranhoainamzoha01" + document.getElementById("dangkynhanh_username").value;
                chuoibien_post_thanhtoan += "tranhoainamzoha01" + document.getElementById("dangkynhanh_pass").value;
                chuoibien_post_thanhtoan += "tranhoainamzoha01" + document.getElementById("dangkynhanh_pass2").value;
                Set_Cookie('dangkynhanh',encode(chuoibien_post_thanhtoan));
                makeRequest_dangkynhanh('ajaxdangkynhanh.aspx?sads=asd');
            }
            else
            {
                alert('Bạn cần nhập đầy đủ thông tin người mua hàng và username password trước khi đăng ký');
            }
        }
        function kiemtra_hoantat_dangkynhanh()
        {
            /*
             mycars[0] = "ctl03_PUserName";
        mycars[1] = "ctl03_PAddress";
        mycars[2] = "ctl03_PPhone";
        mycars[3] = "ctl03_PMail";
        mycars[4] = "ctl03_giong_nguoimauhang";
        mycars[5] = "ctl03_ShipUserName";
        mycars[6] = "ctl03_ShipAddress";
        mycars[7] = "ctl03_ShipPhone";
        mycars[8] = "ctl03_ShipMail";
        mycars[9] = "ctl03$PayMethod";
        mycars[10] = "ctl03$vanchuyen";
        mycars[11] = "ctl03_goiqua";
        mycars[12] = "ctl03_loichuc";
        mycars[13] = "ctl03_xuathoadon";
        mycars[14] = "ctl03_tencongty";
        mycars[15] = "ctl03_diachicongty";
        mycars[16] = "ctl03_masothue";*/
            if(document.getElementById('ctl03_PUserName').value != '' && document.getElementById('ctl03_PAddress').value != '' && document.getElementById('ctl03_PAddress').value != '' && document.getElementById('ctl03_PMail').value != '' && document.getElementById('dangkynhanh_username').value != '' && document.getElementById('dangkynhanh_pass').value != '' && document.getElementById('dangkynhanh_pass2').value != '')
            {
                return true;
            }
            else
            {
                return false;
            }
        }
    //gio hang<<<<<<<<<<<<<<<<<<<<<
    
    
    //phan mo cua so moi
    var windowpopup;
    var timer_wd;
    function cusomoi(tencuaso)
    { 
        timer_wd = setTimeout("kiemtraxemcochophep_popup('"+tencuaso+"')","1000");
        if(tencuaso == 'lienhe')
        {
            windowpopup = window.open('Contactvns2.aspx', 'lienhe', 'status=yes,location=no,width=647,height=480,resizable=0');
            windowpopup.focus();
            //alert(windowpopup.closed);alert('asdsad123213123');
        }
        else if(tencuaso == 'dangky')
        {
            windowpopup = window.open ('NewAccountvns2.aspx', 'dangky', 'status=yes,location=no,width=654,height=462,resizable=0'); 
            windowpopup.focus();
        }
        else if(tencuaso == 'dathangtheoyeucau')
        {
            today = new Date();
            windowpopup = window.open ('CustomerIdeavns2.aspx' + '?timer=' + today.getTime(), 'dathangtheoyeucau', 'status=yes,location=no,width=645,height=1000,resizable=0'); 
            windowpopup.focus();
        }
        else if(tencuaso == 'quenmatkhau')
        {
            windowpopup = window.open ('ForgerPassword.aspx', 'quenmatkhau', 'status=yes,location=no,width=600,height=155,resizable=0'); 
            windowpopup.focus();
        }
        else if(tencuaso == 'lichsumuahang')
        {
            windowpopup = window.open ('CustomerIdeavns2.aspx', 'dathangtheoyeucau', 'status=yes,location=no,width=645,height=549,resizable=0'); 
            windowpopup.focus();
        }
       
    }
    function kiemtraxemcochophep_popup(tencuaso)
    {
        timer_wd = window.clearTimeout(timer_wd);
        try
        {
            var haha = windowpopup.closed;//alert('da mo cua so');
        }
        catch(e)
        {
            if(tencuaso == 'lienhe')
            {
                gourl("Contactvns2.aspx?asdsa=asdsa");
            }
            else if(tencuaso == 'dangky')
            {
                gourl("NewAccountvns2.aspx?asdsa=asdsa");
            }
            else if(tencuaso == 'dathangtheoyeucau')
            {
                gourl("CustomerIdeavns2.aspx?asdsa=asdsa");
            }
            baoloipopupblocker();
            //alert('Trình duyệt web của bạn không cho phép mở của sổ mới. \n\nĐể thuận tiện cho những lần sau hãy chọn thanh menu của trình duyệt Tools/Pop-up Blocker/Turn Off Popup Blocker \"Pop-up blocked...\" \ncủa trình duyệt mới hiện ra ở trên đầu trang web và chọn \"Always Allow...\"');
        }
    }
    
    //phancua so moi co chuyen bien
    var windowpopup_cobien;
    var timer_wd_cobien;
    function cusomoi_cobien(tencuaso,stringbien)// stringbien = "haha=asas&sdsd=asd"
    { 
        timer_wd_cobien = setTimeout("kiemtraxemcochophep_popup_cobien('"+tencuaso+"','"+stringbien+"')","1000");
        if(tencuaso == 'intrangnay')
        {
            windowpopup = window.open('Print.aspx?' + stringbien, 'intrangnay', 'status=yes,location=no,scrollbars=1,width=600,height=1000,resizable=1');
            windowpopup.focus();
            //alert(windowpopup.closed);alert('asdsad123213123');
        }
        else if(tencuaso == 'gioithieuvoibanbe')
        {
            //http://vietnamsach.com.vn/vnscu/SendMailFriend.aspx?IdSach=13574&str=/vnscu/BookDetail.aspx?ID=13574&Name=Nhật Ký Bí Mật Của Chúa
            windowpopup = window.open ('SendMailFriend.aspx?' + stringbien, 'gioithieuvoibanbe', 'status=yes,location=no,width=440,height=290,resizable=0'); 
            windowpopup.focus();
        }
        else if(tencuaso == 'dtcongty_htkhachhang')
        {
            //http://vietnamsach.com.vn/vnscu/SendMailFriend.aspx?IdSach=13574&str=/vnscu/BookDetail.aspx?ID=13574&Name=Nhật Ký Bí Mật Của Chúa
            windowpopup = window.open ('congty.aspx?' + stringbien, 'dtcongty_htkhachhang', 'status=yes,location=no,scrollbars=1,width=920,height=1000,resizable=1'); 
            windowpopup.focus();
        }
        else if(tencuaso == 'hoadon')
        {
            //http://vietnamsach.com.vn/vnscu/SendMailFriend.aspx?IdSach=13574&str=/vnscu/BookDetail.aspx?ID=13574&Name=Nhật Ký Bí Mật Của Chúa
            windowpopup = window.open ('OrderEdit.aspx?' + stringbien, 'hoadon', 'status=yes,location=no,scrollbars=1,width=750,height=1000,resizable=1'); 
            windowpopup.focus();
        }
    }
    function kiemtraxemcochophep_popup_cobien(tencuaso,stringbien)
    {
        timer_wd_cobien = window.clearTimeout(timer_wd_cobien);
        try
        {
            var haha = windowpopup.closed;//alert('da mo cua so');
        }
        catch(e)
        {
            if(tencuaso == 'intrangnay')
            {
                window.location =   'http://vietnamsach.com.vn/Print.aspx?' + stringbien;
            }
            else if(tencuaso == 'gioithieuvoibanbe')
            {
                window.location =   'http://vietnamsach.com.vn/SendMailFriend.aspx?' + stringbien;
            }
            else if(tencuaso == 'dtcongty_htkhachhang')
            {
                window.location =   'congty.aspx?' + stringbien;
            }
            baoloipopupblocker();
            //alert('Trình duyệt web của bạn không cho phép mở của sổ mới. \n\nĐể thuận tiện cho những lần sau hãy chọn thanh menu của trình duyệt Tools/Pop-up Blocker/Turn Off Popup Blocker \"Pop-up blocked...\" \ncủa trình duyệt mới hiện ra ở trên đầu trang web và chọn \"Always Allow...\"');
        }
    }
    function baoloipopupblocker()
    {
        //trinh duyet khong cho popup 
        var r=confirm("Trình duyệt web của bạn không cho phép mở của sổ mới. \n\nĐể thuận tiện cho những lần sau vui lòng tắt Pop-up Blocker của trình duyệt\n\nBạn có muốn đến trang hướng dẫn tắt Pop-up Blocker không?")
        if(r==true)
        {
            
            window.location = "http://vietnamsach.com.vn/congty.aspx?page=hotrokhachhang&id=9";
        }    
    }