﻿var _hy = _hy || {};//命名空间
_hy.VerificatType = _hy.VerificatType || {}
_hy.VerificatType.LoginName = {Msg:"用户名只能输入5-20个以字母开头、可带数字、“_”、“.”的字串。",Pattern:/^[a-zA-Z]{1}([a-zA-Z0-9]|[._]){4,19}$/};
_hy.VerificatType.Tel = {Msg:"电话、传真号码：可以“+”开头，除数字外，可含有“-”",Pattern:/^[+]{0,1}(\d){0,3}[ ]?([-]?((\d)|[ ]){0,12})+$/};
_hy.VerificatType.Password = {Msg:"密码只能输入6-20个字母、数字、下划线 ",Pattern:/^(\w){6,20}$/};
_hy.VerificatType.QQ = {Msg:"QQ号只能输入0-9个数字 ",Pattern:/^[0-9]{0,9}$/};
_hy.VerificatType.Msn = {Msg:"无效的Msn帐号格式。 ",Pattern:/^([\w-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([\w-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/};
_hy.VerificatType.Email = {Msg:"邮箱格式无效，请输入xxxxx@xxxx.xxx!",Pattern:/^([\w-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([\w-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/};
_hy.WaiteStr = "<div style='color:red;margin:10px;'><img src='../../Content/Default/images/loading.gif' alt='loading' width='20px' height='20px' style='float:left;'/><div style='height:20px;line-height:20px;'>&nbsp;正在加载数据，请等待。。</div></div>";

_hy.SetCookie = function(name,value,x_expires,x_path,x_domain,x_secure)
{  //设置一个Cookie值函数
//alert(name)
  var argv = _hy.SetCookie.arguments;
  //alert(this.argv);
  var argc = _hy.SetCookie.arguments.length;
  var expires = (argc > 2) ? x_expires : null;
  var path = (argc > 3) ? x_path : null;
  var domain = (argc > 4) ? x_domain : null;
  var secure = (argc > 5) ? x_secure : false;
  document.cookie = name + "=" + escape (value) + 
  ((expires == null) ? "" : ("; expires=" + expires.toGMTString())) + 
  ((path == null) ? "" : ("; path=" + path)) +  
  ((domain == null) ? "" : ("; domain=" + domain)) +    
  ((secure == true) ? "; secure" : "");
}
_hy.GetCookie = function(name) 
{//读取指定名称的cookie值函数
// alert(document.cookie)
  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 _hy.GetCookieVal(j);
    }
    i = document.cookie.indexOf(";", i);
    if (i == -1) break;
    i+=2;
  }
  return null;
}

_hy.GetCookieVal = function(offset) {   
  var endstr = document.cookie.indexOf (";", offset);  
  if (endstr == -1)    
    endstr = document.cookie.length;  
  return unescape(document.cookie.substring(offset, endstr));
}
_hy.Redirect = function(url) 
{
    if(url == -1)
    {
        top.window.location = _hy.GetCookie("UrlPagePreview");
    }
    else
    {
        _hy.SetCookie("UrlPagePreview",top.window.location,null,"/");
        top.window.location = url;
    }
}
_hy.DeleteCookie = function (name) 
{ //删除Cookie值函数
  var exp = new Date();
  exp.setTime (exp.getTime() - 1);
  var cval = GetCookie (name);
  document.cookie = name + "=" + cval + "; expires=" + exp.toGMTString();
} 

_hy.GetScrollXY =function()
{
    var x,y;
    if(document.body.scrollTop)
    {
      x=document.body.scrollLeft;
      y=document.body.scrollTop;
    }
    else
    {
      x=document.documentElement.scrollLeft;
      y=document.documentElement.scrollTop;
    }
    return {x:x,y:y};
} 

_hy.GetScrollWH =function()
{
    var x,y;
    if(document.body.scrollTop)
    {
      x=document.body.scrollWidth;
      y=document.body.scrollHeight;
    }
    else
    {
      x=document.documentElement.scrollWidth;
      y=document.documentElement.scrollHeight;
    }
    return {W:x,H:y};
} 

_hy.GetId = function (id) 
{
    return document.getElementById(id);
}
_hy.GetName = function (name) 
{
    return document.getElementsByName(name);
}
_hy.GetDate = function (str) {
    str = str.substr(1,str.length-2);
    return eval("new "+str);
}
//解析模板。并将数据源中对应该的值填入。dataSource 是一个Array,rowsIndex 是索引值。
//模板格式为：<a href=''>#=Name# #=ar[0].Name#</a>
_hy.GetDataFromTemplet = function (str,rowsIndex,dataSource) 
{
   var reg = RegExp("#=[A-z0-9\.\(\)]{1,}#");
   var temp =str.match(reg);
   if(temp == null)
        return str;
   else
   {
        var tempField = temp[0].substr(2,temp[0].length-3); 
        var tempData = "";
        if(tempField == "CurrentIndex")
            tempData = rowsIndex;
        else
            tempData = eval("dataSource["+rowsIndex+"]."+tempField);
        var str = str.replace(reg,tempData);
        return _hy.GetDataFromTemplet(str,rowsIndex,dataSource);
   }
}
_hy.GetErrorFromTemplet = function (str,data) 
{
   var reg = RegExp("#=[A-z0-9\.\(\)]{1,}#");
   var temp =str.match(reg);
   if(temp == null)
        return str;
   else
   {
        var tempField = temp[0].substr(2,temp[0].length-3); 
        var tempData = eval("data."+tempField);
        var str = str.replace(reg,tempData);
        return _hy.GetDataFromTemplet(str,data);
   }
}


_hy.GetPageSize = function () 
{
    var xScroll, yScroll;
    if (window.innerHeight && window.scrollMaxY)
    {
        xScroll = document.body.scrollWidth;
        yScroll = window.innerHeight + window.scrollMaxY;
    } 
    else if (document.body.scrollHeight > document.body.offsetHeight) 
    {
        xScroll = document.body.scrollWidth;
        yScroll = document.body.scrollHeight;
    } 
    else 
    {
        xScroll = document.body.offsetWidth;
        yScroll = document.body.offsetHeight;
    }
    var windowWidth, windowHeight;
    if (self.innerHeight) 
    {
        windowWidth = self.innerWidth;
        windowHeight = self.innerHeight;
    } 
    else if (document.documentElement && document.documentElement.clientHeight) 
    {
        windowWidth = document.documentElement.clientWidth;
        windowHeight = document.documentElement.clientHeight;
    } 
    else if (document.body) 
    {
        windowWidth = document.body.clientWidth;
        windowHeight = document.body.clientHeight;
    }
    if (yScroll < windowHeight) 
    {
        pageHeight = windowHeight;
    } 
    else 
    {
        pageHeight = yScroll;
    }
    if (xScroll < windowWidth) 
    {
        pageWidth = windowWidth;
    } 
    else 
    {
        pageWidth = xScroll;
    }
    arrayPageSize = new Array(pageWidth, pageHeight, windowWidth, windowHeight);
    return arrayPageSize;
}

_hy.Validation = function (sender,strTemplte,er,panel) 
{
    if(!er.Pattern.exec(sender.value))
    {
        sender.IsValidation = false;
        panel.innerHTML = _hy.GetErrorFromTemplet(strTemplte,er);
    }
    else
    {
        sender.IsValidation = true;
        panel.innerHTML = "";
    }
}


_hy.ParamManager =  function ()
{
    this.Location = window.location;
    this.ParamArray = new Array();
    this.onInit();
}
_hy.ParamManager.prototype.onInit=function()
{
    var l = new String(this.Location);
    var paramstring = new String(l.substring(l.lastIndexOf('?')+1,l.length));
    this.ParamArray = paramstring.split('&');
    for(var i = 0;i<this.ParamArray.length;i++)
    {
        this.ParamArray[i] = this.ParamArray[i].toString().split('=');
    }
}
_hy.ParamManager.prototype.GetValue=function(key)
{
   for(var i=0;i<this.ParamArray.length;i++)
   {
        if(this.ParamArray[i][0] == key)
        {
            return this.ParamArray[i][1];
        }
   }
   return "null";
}

_hy.GetUrlParam = function (key) 
{
    var p = new _hy.ParamManager();
    return p.GetValue(key);
}
