﻿// JScript File
if(GPD==null){var GPD=function(){}}
GPD.Util = function() { }

//Create any type of element
GPD.Util.CreateElement = function(_type, _id, _class, _pEle) {
        _ele = document.createElement(_type);
        _ele.id = _id;
        _ele.className = _class;
        _pEle.appendChild(_ele);
        return _ele;
    };

//Create Span
    GPD.Util.CreateSpan = function(_pEle,_id,_class) {
        el = document.createElement("span");
        el.id = _id;
        el.className = _class;
        _pEle.appendChild(el);
        return el;
    };
    
//Create Input
    GPD.Util.CreateInput = function(_pEle, _class, _type, _id, _value) {
        el = document.createElement("input");
        el.id = _id;
        el.className = _class;

        if (_type != null)
            el.type = _type;
        if (_value != null)
            el.value = _value;
        _pEle.appendChild(el);
        return el;
    };

//Attach multiple events
GPD.Util.AttachEvents = function(jc, kc) {
        for (var i = 0; i < kc.length; i += 2) { jc.attachEvent(kc[i], kc[i + 1]); }
    };

//Dettach multiple events
GPD.Util.DetachEvents = function(lc, mc) {
        if (Start.Util.IsDefined(lc) && Start.Util.IsDefined(mc) && mc.length)
            for (var i = 0; i < mc.length; i += 2)
        { lc.detachEvent(mc[i], mc[i + 1]); }
    };


GPD.Util.IsDefined = function(P) { return P != null && P != undefined; };


//Create Div
GPD.Util.CreateDiv = function(G, H, I) {
        var el;
        el = GPD.Util.CreateElement("div", "", H, G);

        if (I != null) el.innerHTML = I;
        return el;
    };

//Create A
 GPD.Util.CreateA = function(Mb, Nb, Ob, Pb, Qb, Rb) {
 var el = GPD.Util.CreateElement("a", "", Nb, Mb);
        if (Ob != null) el.href = Ob;
        if (Pb != null) el.target = Pb;
        if (Rb != null) el.innerText = Rb;
        return el;
    };
 

//GetElement by Id
GPD.Util.GetByID=function(strID)
{
    return document.getElementById(strID);
}

//Get object Type
GPD.Util.GetObjectType = function(objClass)
{
    if (objClass != undefined && objClass.constructor)
    {
        var strFun = objClass.constructor.toString();
        var className = strFun.substr(0, strFun.indexOf('('));
        className = className.replace('function', '');
        return className.replace(/(^\s*)|(\s*$)/ig,'');
    }
    return typeof(objClass);
}

//Read one cookie
GPD.Util.ReadCookie = function(strCookieName)
{
    var anyCookies = document.cookie;
    var pos = anyCookies.indexOf(strCookieName + "=");
    var value = "";
    if (pos !=  - 1)
    {
        var start = pos + strCookieName.length + 1;
        var end = anyCookies.indexOf(";", start);
        if (end ==  - 1)
        {
            end = anyCookies.length;
        }
        value = anyCookies.substring(start, end);
        value = decodeURIComponent(value);
    }
    return value;
}

//default is one day
GPD.Util.SetCookie = function(strCookieName, strCookieValue, strExpireDate)
{
    try{
    var strExpires;
    if (strExpireDate)
        strExpires = ";expires=" + strExpireDate;
    else
        strExpires = ";expires=" + (new Date((new Date()).getTime() + 1000 * 60 * 60 * 24)).toGMTString();
    //document.cookie = strCookieName + "=" + escape(strCookieValue) + strExpires + ";path=/";
    document.cookie = strCookieName + "=" + escape(strCookieValue) + strExpires + ";path=/;domain=zll.cn";
    }
    catch(e)
    {
        
    }
}

//default is one day
GPD.Util.DeleteCookie = function(strCookieName)
{
    try{
     GPD.Util.SetCookie(name, "", (new Date((new Date()).getTime() - 1000 * 60 * 60 * 24)).toGMTString()); 
    }
    catch(e)
    {
        
    }
}





//includeJS('../include/mian.js', 'js');
//includeJS('../style/style.css', 'css');
GPD.Util.Include =function(path, type){
 var i, 
      base, 
      src = "common.js", 
      scripts = document.getElementsByTagName("script"); 
 

 for (i = 0; i < scripts.length; i++) {
      if (scripts[i].src.match(src)) {
          base = scripts[i].src.replace(src, "");
          break;
      }
  }
 
  if (type == "css") {
      document.write("<" + "link href=\"" + base + path + "\" rel=\"stylesheet\" type=\"text/css\"></" + "link>");
  } else {
      document.write("<" + "script src=\"" + base + path + "\"></" + "script>");
  }
}







String.prototype.trim = function()
{
    return this.replace(/(^\s*)|(\s*$)/g,"");
}



