﻿function HZW_CreateHTTPObject()
{
var xmlHttp = false;
try {
  xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
  try {
    xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
  } catch (e2) {
    xmlHttp = false;
  }
}
if (!xmlHttp && typeof XMLHttpRequest != 'undefined') {
  xmlHttp = new XMLHttpRequest();
}
if (!xmlHttp && window.createRequest)
    {
        try
        {
            xmlHttp = window.createRequest();
        }
        catch (e)
        {
            xmlHttp=false;
        }
    }
    
return xmlHttp;	
}

function HZW_callServer(obj,url,strv,rty)//加载对象
{
 
  var xmlHttp = HZW_CreateHTTPObject();
    //alert(xmlhttp);
    if (!xmlHttp)
    {
        return; //无法创建 xmlhttp 对象
    }
  xmlHttp.open("post", url, true);
  xmlHttp.onreadystatechange = function (){HZW_updatePage(obj,strv,xmlHttp,url,rty);};
  xmlHttp.send(null);  
}
function HZW_updatePage(obj,strv,xmlHttp,url,rty) {
  if (xmlHttp.readyState < 4) {
	document.getElementById(obj).innerHTML=strv;
  }
  if (xmlHttp.readyState == 4) {
  
  
          if (xmlHttp.status == 200)
        {
        if (rty==1){setTimeout("HZW_callServer('"+obj+"','"+url+"','"+strv+"','"+rty+"')", 5000);}
		
		var response = xmlHttp.responseText;
		document.getElementById(obj).innerHTML=response;
		
        }
        else
        {
           // alert("HTTP 错误，状态码：" + xmlHttp.status);
        }
    
  }
}

//---------------------------------------用于设置对象背景----------------------------------------------------------------
function HZW_BgColor(obj,rtype,strv)//对象,类别(1背景图,2颜色),值
{
if(rtype==1){document.getElementById(obj).background=strv;}
else
{document.getElementById(obj).bgColor=strv}
}

//---------------------------------------用于显示对象------------------------------------------------------------------
function HZW_show(obj)
{
document.getElementById(obj).style.display='block';
}
//---------------------------------------用于隐藏对象------------------------------------------------------------------
function HZW_hidden(obj)
{
document.getElementById(obj).style.display='none';
}
//---------------------------------------用于判断记录有没有选中的函数----------------------------------------------
function HZW_obj_del(obj,url,str)
{ 
var flag=true; 
var temp=""; 
var tmp; 
if((document.getElementById(obj).length+"")=="undefined") {tmp=1}else{tmp=document.getElementById(obj).length} 
if (tmp==1){ 
if (document.getElementById(obj).checked){ 
flag=false; 
temp=document.getElementById(obj).value 
} 
}else{ 
for (i=0;i<document.getElementById(obj).length;i++) { 
if (document.getElementById(obj[i]).checked){ 
if (temp==""){ 
flag=false; 
temp="'"+document.getElementById(obj[i]).value+"'"
}else{ 
flag=false; 
temp = temp +","+ "'"+document.getElementById(obj[i]).value+"'"
} 
} 
} 
} 
if (flag){ alert("对不起，你还没有选择！")} 
else{
//alert(name) 
if (confirm("确实要删除？")){ 
window.location=url+"?str="+temp; 
} 
} 
return !flag; 
} 
//---------------------------------------用于判断全选记录的函数--------------------------------------------
function HZW_checkall(all,obj) 
{
var a = document.getElementsByName(obj); 
for (var i=0; i<a.length; i++) a[i].checked = all.checked; 
}
//---------------------------------------图片缩放百份比------------------------------------------
function  HZW_SetPicSize(obj,maxWidth,maxHeight)
 {
     var img = document.getElementById(obj);
     if(maxWidth < 1)
     {
         if(img.height > maxHeight)
         {
             img.height = maxHeight;
         }
         return true;
     }
     if(maxHeight < 1)
     {
       if(img.width > maxWidth)
        {
             img.width = maxWidth;
         }
         return true;
     }
     if(img.height > maxHeight || img.width > maxWidth)
     {
         if((img.height / maxHeight) > (img.width / maxWidth))
         {
             img.height = maxHeight;
        }
        else
       {
           img.width = maxWidth;
       }
        return true;
    }
 } 
//---------------------------------------mail邮箱校检-------------------------------------------- 
function HZW_Mailcheck(obj)
{
var strm = document.getElementById(obj).value;  
 var regm = /^[a-zA-Z0-9_-]+@[a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)+$/;//验证Mail的正则表达式,^[a-zA-Z0-9_-]:开头必须为字母,下划线,数字,
 if (!strm.match(regm) && strm!="")
   {
     alert("邮箱地址格式错误或含有非法字符!\n请检查！");

  return false;
    }  
}

//---------------------------------------网址校检-------------------------------------------- 
function HZW_IsURL(str_url){
  var strRegex = "^((https|http|ftp|rtsp|mms)?://)" 
  + "?(([0-9a-z_!~*'().&=+$%-]+: )?[0-9a-z_!~*'().&=+$%-]+@)?" //ftp的user@ 
        + "(([0-9]{1,3}\.){3}[0-9]{1,3}" // IP形式的URL- 199.194.52.184 
        + "|" // 允许IP和DOMAIN（域名）
        + "([0-9a-z_!~*'()-]+\.)*" // 域名- www. 
        + "([0-9a-z][0-9a-z-]{0,61})?[0-9a-z]\." // 二级域名 
        + "[a-z]{2,6})" // first level domain- .com or .museum 
        + "(:[0-9]{1,4})?" // 端口- :80 
        + "((/?)|" // a slash isn't required if there is no file name 
        + "(/[0-9a-z_!~*'().;?:@&=+$,%#-]+)+/?)$"; 
        var re=new RegExp(strRegex); 
  //re.test()
        if (re.test(str_url)){
            return (true); 
        }else{ 
            return (false); 
        }
    }

//---------------------------------------弹出窗体-------------------------------------------- 
function HZW_ShowModal(Rty,Url,MaxWidth,MaxHeight)
{
	if(Rty==1){
window.showModalDialog(Url,window,'dialogWidth:'+MaxWidth+'px;status:no;dialogHeight:'+MaxHeight+'px'); 
}
else
{
	window.showModelessDialog(Url,window,'dialogWidth:'+MaxWidth+'px;status:no;dialogHeight:'+MaxHeight+'px'); 
	}
}
//---------------------------------------返回值到主窗体-------------------------------------------- 
function HZW_DialogArg(Obj,Rtype,Obj1)
{
if(Rtype==0){window.dialogArguments.document.getElementById(Obj).value=Obj1;}
if(Rtype==1){window.dialogArguments.document.getElementById(Obj).innerHTML=Obj1;}
}

//---------------------------------------判断日期格式为:####-##-##--------------------------------------------
function HZW_CheckThisday(a)
{
var dat=a.split("-");
if(dat.length<3){return true;}
if(dat[1].length==1){return true;}
if(dat[2].length==1){return true;}
}
//---------------------------------------判断日期--------------------------------------------
function HZW_smalCheckDate(DateA,DateB,Rtype)//DateA去日期 DateB回日期  Rtype 类型1对比今天 2AB对比
{
 var Today = new Date();
 var y,m,d,t;
 y = Today.getFullYear();
 m = Today.getMonth() + 1;
 if(m<10) m = "0"+m;
 d = Today.getDate();
 if(d<10) d = "0"+d;
 t = y + "-" + m + "-" + d;//今天
 if(Rtype==1)
  {return(t>DateA)}
else
  {return(DateA>DateB)}
}



function HZW_CanelBookNo(url,msg)
{aa=confirm(msg);
if(aa==true)
  {location.href=url;}
}

function  HZW_DateAdd(strInterval,  NumDay,  dtDate)  {  
           var  dtTmp  =  new  Date(dtDate);  
           if  (isNaN(dtTmp))  dtTmp  =  new  Date();  
           switch  (strInterval)  {  
                       case  "s":return  new  Date(Date.parse(dtTmp)  +  (1000  *  NumDay));  
                       case  "n":return  new  Date(Date.parse(dtTmp)  +  (60000  *  NumDay));  
                       case  "h":return  new  Date(Date.parse(dtTmp)  +  (3600000  *  NumDay));  
                       case  "d":return  new  Date(Date.parse(dtTmp)  +  (86400000  *  NumDay));  
                       case  "w":return  new  Date(Date.parse(dtTmp)  +  ((86400000  *  7)  *  NumDay));  
                       case  "m":return  new  Date(dtTmp.getFullYear(),  (dtTmp.getMonth())  +  NumDay,  dtTmp.getDate(),  dtTmp.getHours(),  dtTmp.getMinutes(),  dtTmp.getSeconds());  
                       case  "y":return  new  Date((dtTmp.getFullYear()  +  NumDay),  dtTmp.getMonth(),  dtTmp.getDate(),  dtTmp.getHours(),  dtTmp.getMinutes(),  dtTmp.getSeconds());  
           }  
}  


function HZW_better_time(strDateStart,strDateEnd)//日期相差天数
{
   var strSeparator = "-"; //日期分隔符
   var strDateArrayStart;
   var strDateArrayEnd;
   var intDay;
   strDateArrayStart = strDateStart.split(strSeparator);
   strDateArrayEnd = strDateEnd.split(strSeparator);
   var strDateS = new Date(strDateArrayStart[0] + "/" + strDateArrayStart[1] + "/" + strDateArrayStart[2]);
   var strDateE = new Date(strDateArrayEnd[0] + "/" + strDateArrayEnd[1] + "/" + strDateArrayEnd[2]);
   intDay = (strDateE-strDateS)/(1000*3600*24);
   return intDay;
}

function HZW_Disable(obj)
{  
document.getElementById(obj).value="Loading......";
document.getElementById(obj).disabled="disabled";
}

function HZW_OnKeyUp(obj)
{
obj.value=obj.value.replace(/\D/gi,'')
obj.focus();
}

function HZW_Alert(str,msgw,msgh,titleheight,bordercolor,titlecolor){  
//提示内容,窗口宽度,高度,标语高度,窗口边框颜色,标题颜色 
        var msgw,msgh,bordercolor;   
           
        var sWidth,sHeight;   
        sWidth=screen.width;   
        sHeight=screen.height;   
  
        var bgObj=document.createElement("div");   
        bgObj.setAttribute('id','bgDiv');   
        bgObj.style.position="absolute";   
        bgObj.style.top="0";   
        bgObj.style.background="#cccccc";   
        bgObj.style.filter="progid:DXImageTransform.Microsoft.Alpha(style=3,opacity=25,finishOpacity=75";   
        bgObj.style.opacity="0.6";   
        bgObj.style.left="0";   
        bgObj.style.width=sWidth + "px";   
        bgObj.style.height=sHeight + "px";   
        bgObj.style.zIndex = "10000";   
        document.body.appendChild(bgObj);   
           
        var msgObj=document.createElement("div")   
        msgObj.setAttribute("id","msgDiv");   
        msgObj.setAttribute("align","center");   
        msgObj.style.background="white";   
        msgObj.style.border="1px solid " + bordercolor;   
        msgObj.style.position = "absolute";   
        msgObj.style.left = "50%";   
        msgObj.style.top = "50%";   
        msgObj.style.font="12px/1.6em Verdana, Geneva, Arial, Helvetica, sans-serif";   
        msgObj.style.marginLeft = "-225px" ;   
        msgObj.style.marginTop = -75+document.documentElement.scrollTop+"px";   
        msgObj.style.width = msgw + "px";   
        msgObj.style.height =msgh + "px";   
        msgObj.style.textAlign = "center";   
        msgObj.style.lineHeight ="25px";   
        msgObj.style.zIndex = "10001";   
  
       var title=document.createElement("h4");   
       title.setAttribute("id","msgTitle");   
       title.setAttribute("align","right");   
       title.style.margin="0";   
       title.style.padding="3px";   
       title.style.background=bordercolor;   
       title.style.filter="progid:DXImageTransform.Microsoft.Alpha(startX=20, startY=20, finishX=100, finishY=100,style=1,opacity=75,finishOpacity=100);";   
       title.style.opacity="0.75";   
       title.style.border="1px solid " + bordercolor;   
       title.style.height="18px";   
       title.style.font="12px Verdana, Geneva, Arial, Helvetica, sans-serif";   
       title.style.color="white";   
       title.style.cursor="pointer";   
       title.innerHTML="关闭";   
       title.onclick=function(){   
    document.body.removeChild(bgObj);   
    document.getElementById("msgDiv").removeChild(title);   
document.body.removeChild(msgObj);   
            }   
       document.body.appendChild(msgObj);   
       document.getElementById("msgDiv").appendChild(title);   
       var txt=document.createElement("p");   
       txt.style.margin="1em 0"  
       txt.setAttribute("id","msgTxt");   
       txt.innerHTML=str;   
       document.getElementById("msgDiv").appendChild(txt);   
        }  
		
function SelectImg(obj,url)
{
	document.getElementById(obj).src=url;
	}		
