﻿function JSInit(){
		loadJs("config");
		loadJs("string");
		loadJs("collection");
		loadJs("object");
		loadJs("event");
		loadJs("Common");
};JSInit();
function loadJs(url){
	  url=url.replace(/\./g,"/");
	  url="http://www.hzins.com/js/"+url+".js";
	  var strScript="<script language=\"javascript\" type=\"text/javascript\" src=\"" +url+ "\"></" + "script>" + "\n";
	  document.write(strScript);
};
function loadCss(url){
	  url=url.replace(/\./g,"/");
	  url="http://www.hzins.com/css/"+url+".css";
			var strCss="<link rel=\"stylesheet\" type=\"text/css\" href=\""+url+"\" /> \n";
	  document.write(strCss);
};
function loadEvent(fn){
	  var f = window.onload; 
			if(typeof f != 'function'){ window.onload = fn; }
			else{ window.onload = function(){f(); fn();}}
};
function setCopy(_sTxt)
{
    try
    {
        clipboardData.setData('Text',_sTxt);
    }
    catch(e)
    {}
};
function GetUrlParam(paramName)
{
  var sValue = location.search.match(new RegExp("[\?\&]" + paramName + "=([^\&]*)(\&?)","i"));
  return sValue ? sValue[1] : sValue;
};
function ConvertDayToYearShow(day)
{
    var d;
    var re;
    re=/天/g;
    d=parseInt(day.toString().replace(re,""));
    if(d == 365 || d == 366)
    {
        return "1年";
    }
    else
    {
        return day;//单位“天”不在这里加
    }
}
//显示缩略图
function DrawImage(ImgD,width_s,height_s)
{
    var image=new Image();
    image.src=ImgD.src;
    if(image.width>0 && image.height>0)
    {
        flag=true;
        if(image.width/image.height>=width_s/height_s)
        {
            if(image.width>width_s)
            {
                ImgD.width=width_s;
                ImgD.height=(image.height*width_s)/image.width;
            }
            else
            {
                ImgD.width=image.width;
                ImgD.height=image.height;
            }
        }
        else
        {
            if(image.height>height_s)
            {
                ImgD.height=height_s;
                ImgD.width=(image.width*height_s)/image.height;
            }
            else
            {
                ImgD.width=image.width;
                ImgD.height=image.height;
            }
        }
    }
};
/*  
*    ForDight(Dight,How):数值格式化函数，Dight要  
*    格式化的  数字，How要保留的小数位数。  
*/  
function  ForDight(Dight,How)  
{  
           Dight  =  Math.round  (Dight*Math.pow(10,How))/Math.pow(10,How);  
           return  Dight;  
}
// 自动替换页面失效图片
function DispErrImg()
{
    var imgs=document.getElementsByTagName("img");
    for(var i=0;i<imgs.length;i++)
        imgs[i].onError=imgs[i].src="/Images/notice.gif"
}
//DispErrImg();
//写入 cookie
//不区分 cookieName 的大小写
//不考虑子键
function ResponseCookiess(cookieName, cookieValue, expires)
{
    if (expires)
    {
        //指定了 expires
        document.cookie = ResponseCookies_GetCookieNames(cookieName) + "=" + escape(cookieValue) + "; expires=" + expires.toGMTString();
    }
    else
    {
        document.cookie = ResponseCookies_GetCookieNames(cookieName) + "=" + escape(cookieValue);
    }
}

//获取并返回与 cookieName 同名的 cookie 名称，允许大小写不同
//如果不存在这样的 cookie，就返回 cookieName
function ResponseCookies_GetCookieNames(cookieName)
{
    var lowerCookieName = cookieName.toLowerCase();
    var cookieStr = document.cookie;
  
    if (cookieStr == "")
    {
        return cookieName;
    }
    var cookieArr = cookieStr.split("; ");
    var pos = -1;
    for (var i=0; i<cookieArr.length; i++)
    {
        pos = cookieArr[i].indexOf("=");
        if (pos > 0)
        {
            if (cookieArr[i].substring(0, pos).toLowerCase() == lowerCookieName)
            {
                return cookieArr[i].substring(pos+1,pos.length);
            }
        }
    }
    
    return cookieName;
}

//获取并返回 cookie 值
//不区分 cookieName 的大小写
//dfltValue 为默认返回值
//不考虑子键
function RequestCookiess(cookieName, dfltValue)
{
    var lowerCookieName = cookieName.toLowerCase();
    var cookieStr = document.cookie;
    
    if (cookieStr == "")
    {
        return dfltValue;
    }
    
    var cookieArr = cookieStr.split("; ");
    var pos = -1;
    for (var i=0; i<cookieArr.length; i++)
    {
        pos = cookieArr[i].indexOf("=");
        if (pos > 0)
        {
            if (cookieArr[i].substring(0, pos).toLowerCase() == lowerCookieName)
            {
                return unescape(cookieArr[i].substring(pos+1, cookieArr[i].length));
            }
        }
    }
    
    return dfltValue;
}

