<!--
/*--- 版权信息 ----
版本：JsFramework.v1.0.0
日期：2005.12.30
作者：张新
e-mail:cmalaya@163.com*/
function JSInit(){
		loadJs("config");
		loadJs("string");
		loadJs("collection");
		loadJs("object");
		loadJs("event");
		loadJs("Common");	
		loadCss("main");
};JSInit();
var G_V_Login;
var G_IsLogin;
G_V_Login=false;//是否已经验证过登录
G_IsLogin=false;//是否已经登录
var sd;//服务器时间
function loadJs(url){
	  url=url.replace(/\./g,"/");
	  url="/js/"+url+".js";
	  var strScript="<script  type=\"text/javascript\" src=\"" +url+ "\"></" + "script>" + "\n";
	  document.write(strScript);
};
function loadCss(url){
if(url.substr(0,2)=='..')
{
      url=url.replace('..','');
	  url=url.replace(/\./g,"/");
	  url="/"+url+".css";
}
else
{
	  url=url.replace(/\./g,"/");
	  url="/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 if (d%365==0) 
    {
       return (d/365)+"年";
    }
   else if (d%366==0) 
    {
       return (d/366)+"年";
    }
    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)  
{           
           if(Dight<1)
           {
            Dight=0;
           }
           else
           {     
            Dight  =  Math.round  (Dight*Math.pow(10,How))/Math.pow(10,How);  
           }
           return  Dight;  
}
function HzInsForDight(Dight)
{
    if(Dight%1!=0)
    {
        Dight=Dight+1;
        Dight=ForDight(Dight,0);
    }
    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;
}

function ShowHidePolicyManagerMobile(v)
{
	if(v)
   {
		$('#SpanPolicyManagerMobile').show();
		$('#TbPolicyManagerMobile').show();
       $('#CkCallPolicyManager').val('1');
   }
   else
   {
       $('#CkCallPolicyManager').val('0');
		$('#SpanPolicyManagerMobile').hide();
		$('#TbPolicyManagerMobile').hide();
   }
}
function include_js(file) {

    var html_doc = document.getElementsByTagName('head')[0];

    js = document.createElement('script');

    js.setAttribute('type', 'text/javascript');

    js.setAttribute('src', file);

    html_doc.appendChild(js);

    js.onreadystatechange = function () {
        if (js.readyState == 'complete') {
            alert('JS onreadystate fired');
        }
    }
    js.onload = function () {
        alert('JS onload fired');
    }
    return false;
}
   function rnd(n)
    {
       return Math.round(Math.random()*n)
    }
function ShowError(html,ErrorControleList)
{
//        html = '<h4>'+html+'</h4>';
//        $.prompt(html,null,ErrorControleList);    
        alert(html); 

	    try
	    {

	    }
	    catch(e)
	    {
	        
	    }           
}
function GetRedioValue(v)
{
    var rad=document.getElementsByName(v); 
    var Rb;
    Rb='';
    for(var i=0;i<rad.length;i++)
    {  
        if(rad[i].checked==true)
        { 
            Rb=rad[i].value;
        }
    }  
    return Rb;
}  
//获取服务器当前时间
function GetServerCurrentDateTime() {
    if(sd==undefined || sd=='undefined')
    {
        var serverDateTime;
        serverDateTime = $.ajax({
        url: "/Service/ServerDateTime.ashx",
            async: false
        }).responseText;    
        sd= new Date(serverDateTime.substr(0,4),serverDateTime.substr(5,2),serverDateTime.substr(8,2),serverDateTime.substr(11,2),serverDateTime.substr(14,2),serverDateTime.substr(17,2));
        sd=sd.dateAdd('m',-1);//因为js的月份是从0开始的，所以从服务器取会的日期需要-1个月
    }
    return sd;
}
/*--验证用户登录开始--*/
function IsLogin()
{
    var islogin ;
    islogin=false;
  if(typeof(G_V_Login)!='undefined' && typeof(G_V_Login)!=undefined)
  {
    if(G_V_Login)
    {
      return G_IsLogin;
    }
    else
    {
       islogin = $.ajax({
        url:"/Service/IsLogin.ashx",
        async: false
        }).responseText;
        G_V_Login=true;
        if(islogin=='True')
        {
            G_IsLogin=true;
            return G_IsLogin;
        }
        else
        {
            G_IsLogin=false;
            return G_IsLogin;
        }
    }
  }
  else
  {
   islogin = $.ajax({
    url:"/Service/IsLogin.ashx",
    async: false
    }).responseText;
    G_V_Login=true;
    if(islogin=='True')
    {
        G_IsLogin=true;
        return G_IsLogin;
    }
    else
    {
        G_IsLogin=false;
        return G_IsLogin;
    }
  }
}
function GetIsLogin()
{
    var isLoggedIn=false;
    if (typeof (G_V_Login) != 'undefined' && typeof (G_V_Login) != undefined) {
        if (G_V_Login) {
            if (typeof (G_IsLogin) != undefined && typeof (G_IsLogin) != 'undefined') {
                isLoggedIn = G_IsLogin;
            }
            else {
                if (typeof (IsLogin) != 'undefined') {
                    isLoggedIn = IsLogin();
                }
            }
        }
        else {
            if (typeof (IsLogin) != 'undefined') {
                isLoggedIn = IsLogin();
            }
        }
    }
    return isLoggedIn;
}
/*--验证用户登录结束--*/
Date.prototype.dateAdd = function(interval,number)
{
    var d = this;
    var k={'y':'FullYear', 'q':'Month', 'm':'Month', 'w':'Date', 'd':'Date', 'h':'Hours', 'n':'Minutes', 's':'Seconds', 'ms':'MilliSeconds'};
    var n={'q':3, 'w':7};
    eval('d.set'+k[interval]+'(d.get'+k[interval]+'()+'+((n[interval]||1)*number)+')');
    return d;
}
Date.prototype.dateDiff = function(interval,objDate2)
{
    var d=this, i={}, t=d.getTime(), t2=objDate2.getTime();
    i['y']=objDate2.getFullYear()-d.getFullYear();
    i['q']=i['y']*4+Math.floor(objDate2.getMonth()/4)-Math.floor(d.getMonth()/4);
    i['m']=i['y']*12+objDate2.getMonth()-d.getMonth();
    i['ms']=objDate2.getTime()-d.getTime();
    i['w']=Math.floor((t2+345600000)/(604800000))-Math.floor((t+345600000)/(604800000));
    i['d']=Math.floor(t2/86400000)-Math.floor(t/86400000);
    i['h']=Math.floor(t2/3600000)-Math.floor(t/3600000);
    i['n']=Math.floor(t2/60000)-Math.floor(t/60000);
    i['s']=Math.floor(t2/1000)-Math.floor(t/1000);
    return i[interval];
} 
/**
* 时间对象的格式化;
*/
Date.prototype.formatDateTime = function(format){
 /*
  * eg:format="YYYY-MM-dd hh:mm:ss";
  */
 var o = {
  "M+" :  this.getMonth()+1,  //month
  "d+" :  this.getDate(),     //day
  "h+" :  this.getHours(),    //hour
      "m+" :  this.getMinutes(),  //minute
      "s+" :  this.getSeconds(), //second
      "q+" :  Math.floor((this.getMonth()+3)/3),  //quarter
      "S"  :  this.getMilliseconds() //millisecond
   }
 
   if(/(y+)/.test(format)) {
    format = format.replace(RegExp.$1, (this.getFullYear()+"").substr(4 - RegExp.$1.length));
   }
 
   for(var k in o) {
    if(new RegExp("("+ k +")").test(format)) {
      format = format.replace(RegExp.$1, RegExp.$1.length==1 ? o[k] : ("00"+ o[k]).substr((""+ o[k]).length));
    }
   }
 return format;
}
function curDateTime(date) 
{
    var d = new Date(date);
    var year = d.getFullYear();
    var month = d.getMonth() + 1;
    var date = d.getDate();
    var curDateTime = year;
    if (month > 9)
        curDateTime = curDateTime + "年" + month;
    else
        curDateTime = curDateTime + "年"+"0" + month;
    if (date > 9)
        curDateTime = curDateTime + "月" + date + '日';
    else
        curDateTime = curDateTime + "月"+"0" + date + '日';
    return curDateTime;
}
function roundNumber(number,decimals) {   
    var newString;// The new rounded number   
    decimals = Number(decimals);   
   if (decimals < 1) {   
       newString = (Math.round(number)).toString();   
    } else {   
       var numString = number.toString();   
       if (numString.lastIndexOf(".") == -1) {// If there is no decimal point   
           numString += ".";// give it one at the end   
       }   
        var cutoff = numString.lastIndexOf(".") + decimals;// The point at which to truncate the number   
       var d1 = Number(numString.substring(cutoff,cutoff+1));// The value of the last decimal place that we'll end up with   
       var d2 = Number(numString.substring(cutoff+1,cutoff+2));// The next decimal, after the last one we want   
        if (d2 >= 5) {// Do we need to round up at all? If not, the string will just be truncated   
           if (d1 == 9 && cutoff > 0) {// If the last digit is 9, find a new cutoff point   
              while (cutoff > 0 && (d1 == 9 || isNaN(d1))) {   
                 if (d1 != ".") {   
                       cutoff -= 1;   
                        d1 = Number(numString.substring(cutoff,cutoff+1));   
                   } else {   
                        cutoff -= 1;   
                  }   
                }   
            }   
           d1 += 1;   
     }    
       if (d1 == 10) {   
            numString = numString.substring(0, numString.lastIndexOf("."));   
          var roundedNum = Number(numString) + 1;   
           newString = roundedNum.toString() + '.';   
       } else {   
            newString = numString.substring(0,cutoff) + d1.toString();   
        }   
    }   
    if (newString.lastIndexOf(".") == -1) {// Do this again, to the new string   
       newString += ".";   
    }   
    var decs = (newString.substring(newString.lastIndexOf(".")+1)).length;   
    for(var i=0;i<decimals-decs;i++) newString += "0";
       //var newNumber = Number(newString);// make it a number if you like   
    return newString; // Output the result to the form field (change for your purposes)   
}
