﻿
//====================Cookie================================
function getCookieVal (offset) {
  var endstr = document.cookie.indexOf (";", offset);
  if (endstr == -1) { endstr = document.cookie.length; }
  return unescape(document.cookie.substring(offset, endstr));
  }

function GetCookie (name) {
  var arg = name + "=";
  var alen = arg.length;
  var clen = document.cookie.length;
  var i = 0;
  while (i < clen) {
    var j = i + alen;
    if (document.cookie.substring(i, j) == arg) {
      return getCookieVal (j);
      }
    i = document.cookie.indexOf(" ", i) + 1;
    if (i == 0) break; 
    }
  return null;
  }

function DeleteCookie (name,path,domain) {
  if (GetCookie(name)) {
    document.cookie = name + "=" +
    ((path) ? "; path=" + path : "") +
    ((domain) ? "; domain=" + domain : "") +
    "; expires=Thu, 01-Jan-70 00:00:01 GMT";
    }
  }

function SetCookie (name,value,path,domain,secure) {
    var today = new Date();
    var expiry = new Date(today.getTime() + 365 * 24 * 60 * 60 * 1000);
    document.cookie = name + "=" + escape (value) +
    ((expiry) ? "; expires=" + expiry.toGMTString() : "") +
    ((path) ? "; path=" + path : "") +
    ((domain) ? "; domain=" + domain : "") +
    ((secure) ? "; secure" : "");
  }
  
//====================Popup================================
function ShowPopup(width, height, header, url){
    var ran = Math.random();
    var reURL = url.indexOf('?')>-1? url + '&ran=' + ran:url+'?ran='+ran;
    Popup.SetSize(width, height);
    Popup.SetHeaderText(header);
    Popup.SetContentUrl(reURL);
    Popup.Show();
}

function ShowPopupAtID(el, elementID, width, height, header, url){
    var ran = Math.random();
    var reURL = url.indexOf('?')>-1? url + '&ran=' + ran:url+'?ran='+ran;
    el.SetSize(width, height);
    el.SetHeaderText(header);
    el.SetContentUrl(reURL);
    el.Hide();
    el.ShowAtElementByID(elementID);
}

function SetImageUrl(Url){ txtImage.SetText(Url); }

//====================San pham================================
function cmdDelete(Params){
    if(confirm('Bạn có muốn xóa không')) grvSP.PerformCallback(Params);
}
function cmdRefresh(Params){
    grvSP.PerformCallback(Params);
}

//An hien Hang Muc
var muci=true;
function AnHienMucI(){
    muci=!muci;
    if(muci)
        document.getElementById("divmuc1").style.display="";
    else
        document.getElementById("divmuc1").style.display="none";
}
var mucii=true;
function AnHienMucII(){
    mucii=!mucii;
    if(mucii)
        document.getElementById("divmuc2").style.display="";
    else
        document.getElementById("divmuc2").style.display="none";
}

var muciii=true;
function AnHienMucIII(){
    muciii=!muciii;
    if(muciii)
        document.getElementById("divmuc3").style.display="";
    else
        document.getElementById("divmuc3").style.display="none";
}
var muciv=true;
function AnHienMucIV(){
    muciv=!muciv;
    if(muciv)
        document.getElementById("divmuc4").style.display="";
    else
        document.getElementById("divmuc4").style.display="none";
}

//Open search
function upgradeClick(){
    var isMSIE = navigator.userAgent.toLowerCase().indexOf("msie") != -1;
    var link = ( isMSIE ) ?  "http://www.microsoft.com/windows/internet-explorer/" : "http://www.getfirefox.com/";
    goParent( link );
}

function goParent( loc ){
	self.opener.location.href = loc;
	self.close();
	return false;
}

//var a = window.external.IsSearchProviderInstalled('mua24h.com.vn');
function addOpenSearch() {
    try { 
        var cook = GetCookie("SearchProvider");
        if(cook == null){
            window.external.AddSearchProvider('http://mua24h.com.vn/opensearch.xml'); 
            SetCookie("SearchProvider", '1');
        }
    }
    catch (e) {
        //alert("Bạn cần sử dụng Internet Explorer (7.0 hoặc mới hơn) hoặc Firefox (2.0 hoặc mới hơn) đển cài đặt tiền ích OpenSearch của Mua24h.");
    }
}

function InstalledOpenSearch() {
    try { 
        window.external.AddSearchProvider('http://mua24h.com.vn/opensearch.xml'); 
    }
    catch (e) {
        alert("Bạn cần sử dụng Internet Explorer (7.0 hoặc mới hơn) hoặc Firefox (2.0 hoặc mới hơn) đển cài đặt tiền ích OpenSearch của Mua24h.");
        var isMSIE = navigator.userAgent.toLowerCase().indexOf("msie") != -1;
        var link = ( isMSIE ) ?  "http://www.microsoft.com/windows/internet-explorer/" : "http://www.getfirefox.com/";
        open(link);
    }
}
