﻿String.prototype.endsWith=function(str)
{
	return(this.substring(this.length-str.length)==str);
}

String.prototype.trim=function()
{
	return this.replace(/(\s*$)|(^\s*)/g, "");
}

function fileTypecheck()
{
	var uploadFilePath=document.forms[0].HtmlInputFile1.value.trim();
	if(uploadFilePath=="") 
	{
		document.all.btnUpload.disabled=true;
		return false;
	}
	if(!uploadFilePath.toLowerCase().endsWith("jpg"))
	{
	msg.innerHTML="请上传文件类型为jpg的文件！";
	document.all.btnUpload.disabled=true;
	return false;
	}
	else
	{
	msg.innerHTML="";
	document.all.btnUpload.disabled=false;
	}
}

//数据验证
function ifnull(s)
{
    if (s.value == "")
    {
      s.focus();
	  alert("有重要数据项没有填写,请填写后在进行保存！");
      return false;
    }
}

function trim(str)
{
    if(typeof(str)!="string") return "";
    var rexp=/\s*$/;
    var lexp=/^\s*/;
    return str.replace(rexp,"").replace(lexp,"");
}

function isInt(s,info)  //整数输入判断
{
   if (s.value == "") return true;
   var chk=parseInt(s.value,10);
   if(chk!=s.value || chk<0)
     {
       alert(info+"应是正整数！");
       s.focus();
       return false;
      }
   return true;
}

function isZH(bb)
{
	var num=0;
	var aa=bb.value.trim();
	if(aa=="") return true;
	/////////////
	var chk=parseInt(bb.value,10);
    if(chk!=bb.value || chk<0)
     {
       alert("该字段应是正整数！");
       bb.focus();
       return false;
      }
	/////////////
	for(var i=0; i<aa.length;i++)
	{
		if(aa.charCodeAt(i)>255)
		{
			num=num+2;
		}
		else
		{
			num=num+1;
		}
	}
	if(num!=19)
	{
		alert("身份证证号码不正确，应为19位！")
		bb.focus();
		return false;
	}
	else
	{
		return true;
	}
}

function isAge(s)  //年龄输入判断!
{
   if (s.value == "") return true;
   var chk=parseInt(s.value,10);
   if(chk!=s.value || chk<0 || chk>100)
     {
       alert("该字段应是正整数！");
       s.focus();
       return false;
      }
   return true;
}

function isFloat(s)  //浮点数输入判断
{
  if (s.value == "") return true;
  
   var chk=parseFloat(s.value);
   if(chk!=s.value)
     {
	  alert("该字段应是整数或小数！");
      s.focus();
      return false;
      }
   return true;
}


function isDate(obj) //时间输入判断
{
	var m,str,exp,d;
	str=trim(obj.value);
	if(str=="") return true;
	str=str.replace(/-0/g,"-");
	exp=/\d{4}-\d{1,2}-\d{1,2}/;
	if(str.match(exp)!=null)
    {
        m=str.split("-");
		d=new Date(Date.parse(m[1]+'-'+m[2]+'-'+m[0]));
		if(d>=new Date(1800,1,1) && d<=new Date(2070,6,6) && d.getFullYear()==parseInt(m[0]) && (d.getMonth()+1)==parseInt(m[1]) && d.getDate()==parseInt(m[2]))
		{
            return true;
		}
    }
	alert("该字段应是正确的日期值：YYYY-MM-DD！");
	obj.focus();
    return false;
}


function getDate(obj)
{
	 var aa=window.showModalDialog("../script/calen.htm",null,"dialogwidth:140pt;dialogheight:110pt;status:0");
	  
    if(aa==null) return;
	obj.value=aa; 
    return;
}

function is4Forder(obj)
{
    var forder=trim(obj.value)
    if(forder.length>4)
    {
        alert('序号必须是4位！');
        obj.focus();
        return false;
    }
    return true;
 }
 
function CheckSFZHM(bb)
{
	var num=0;
	var aa=bb.value.trim();
	if(aa=="") return true;
	for(var i=0; i<aa.length;i++)
	{
		if(aa.charCodeAt(i)>255)
		{
			num=num+2;
		}
		else
		{
			num=num+1;
		}
	}
	if(num!=15 && num!=18)
	{
		alert("身份证证号码不正确，应为15位或18位！")
		bb.focus();
		return false;
	}
	else
	{
		return true;
	}
}


			
var win=null;
function OpenWin(url)
{
	if(win==null)
	{
		win=window.open(url,'','fullscreen=0,toolbar=no,width='+(screen.availWidth-10)+',height='+(screen.availHeight-50)+',location=0,directories=0,status=1,menubar=no,scrollbars=1,resizable=1');
	}
	else if(win.closed)
	{
		win=window.open(url,'','fullscreen=0,toolbar=no,width='+(screen.availWidth-10)+',height='+(screen.availHeight-50)+',location=0,directories=0,status=1,menubar=no,scrollbars=1,resizable=1');
	}
	else
	{
		win.location.replace(url);
	}
	win.moveTo(0,0);
	win.outerWidth=screen.availWidth;
	win.outerHeight=screen.availHeight;
	win.focus();
}

function OpenWinSmall(url)
{
	if(win==null)
	{
		win=window.open(url,'','fullscreen=0,toolbar=no,width='+(screen.availWidth-200)+',height='+(screen.availHeight-100)+',location=0,directories=0,status=1,menubar=no,scrollbars=1,resizable=1');
	}
	else if(win.closed)
	{
		win=window.open(url,'','fullscreen=0,toolbar=no,width='+(screen.availWidth-200)+',height='+(screen.availHeight-100)+',location=0,directories=0,status=1,menubar=no,scrollbars=1,resizable=1');
	}
	else
	{
		win.location.replace(url);
	}
	win.outerWidth=screen.availWidth;
	win.outerHeight=screen.availHeight;
	win.focus();
}


function OpenDown(url,width,height)
{
	var down=window.open(url,'','fullscreen=0,toolbar=no,width='+width+',height='+height+',location=0,directories=0,status=1,menubar=no,scrollbars=1,resizable=1');
	down.moveTo(-100,-100);
}

 //设页面全部文本框为只读
function changeReadOnly()
{   
   var form=document.forms[0];  
    for (var i=0; i<form.elements.length; i++) 
	      {
	           if(form.elements[i]. type=="text" || form.elements[i]. type=="textarea")
	           {                      
		                  var e = form.elements[i];	                  
			               e.readOnly="disabled";			      
			   }
			   if(form.elements[i].type=="submit")
			   {
			      var e = form.elements[i];	  
			      if(e.id.indexOf('Del')>-1 || e.id.indexOf('add')>-1 || e.id.indexOf('save')>-1)
			      {      
			               e. disabled=true;
			      }	
			   }
			    if(form.elements[i].type=="button")
			   {
			      var e = form.elements[i];	  
			      if(e.id.indexOf('Del')>-1 || e.id.indexOf('add')>-1 || e.id.indexOf('save')>-1)
			      {      
			               e. disabled=true;
			      }	
			   }
			    if(form.elements[i].tagName=="SELECT")
	           {                      
		                  var e = form.elements[i];	        
			               e. disabled=true;			    
			   }
			    
			                
			               
	      }    
}        
  //清空页面
function clearPage()
{   
  var form=document.forms[0];  
  for (var i=0; i<form.elements.length; i++) 
  {
       if(form.elements[i]. type=="text" || form.elements[i]. type=="textarea")
       {                      
                  var e = form.elements[i];	                  
	               e.value="";			      
	   }
	   
	    if(form.elements[i].tagName=="SELECT")
       {               
          
                  var e = form.elements[i];	        
	               e.selectedIndex=0;			    
	  }              
  }    
}    
  
function checkAll(chk) 
{
	      var form = chk.form;
	      for (var i=0; i<form.elements.length; i++) 
	      {
	           if(form.elements[i]. type=="checkbox" && !form.elements[i].disabled)
	           {
	                if(form.elements[i].id.indexOf('CheckItem')>-1)
	                 {	      
		                  var e = form.elements[i];
		                  if (e.name != chk.name)
			               e.checked = chk.checked;
			         }
			   }
	      }
}

 var checkedCount=0;
//统计选中项
function checkCount()
{
     checkedCount=0;
     var form=document.forms[0];  
    for(var i=0;i<form.elements.length;i++)
    {
        if(form.elements[i].type=="checkbox" && form.elements[i].checked==true)
        {
             if(form.elements[i].id.indexOf('CheckItem')>-1)
	           {checkedCount++;}	
        }
     }
}
function mouseOver(con)
{
 if (!con.contains(event.fromElement)) {
	 con.bgColor='#E5E7F7';
	}
}
function mouseOut(con)
{

	 con.bgColor='#ffffff';
	
}     
function setfo(x)
{
  var range=x.createTextRange();
  range.moveStart("character",x.value.length);
  //range.moveEnd("character",0);
  range.select();
}
    

function hidControl(obj)
{
    obj.style.display="none";
}

function showControl(obj)
{
    obj.style.display="";
}



function showApproveWindow(sUrl,width,height)
{  
    var idvalue=window.showModalDialog(sUrl+'&rid='+Math.random(),window,'dialogWidth:'+width+'px; dialogHeight:'+height+'px; center:yes; resizable:yes; status:no; help:no;scroll:auto;');
     
    if(idvalue!=null&&idvalue=="1")
    {
       
        if(document.getElementById("btnQuery")!=null)
        {
            document.getElementById("btnQuery").click();
        }
    }
}

function showWindow(sUrl,width,height)
{  
    var sValue = window.showModalDialog(sUrl+'&rid='+Math.random(),'','dialogWidth:'+width+'px; dialogHeight:'+height+'px; center:yes; resizable:yes; status:no; help:no;scroll:auto;'); 
    return sValue;
}

function ifSaveOk()
{ 
    if(document.getElementById("HSaveResult")!=null&&document.getElementById("HSaveResult").value=="1")
    { 
        window.returnValue="1";
        window.close();
    }
    else
    {
        window.close();
    }
}
 
function showQueryWindow(sUrl,width,height,obj)
{  
    var idvalue=window.showModalDialog(sUrl+'&rid='+Math.random(),'','dialogWidth:'+width+'px; dialogHeight:'+height+'px; center:yes; resizable:yes; status:no; help:no;scroll:auto;');
    if(idvalue!=null&&idvalue!="")
    {
        
        obj.value = idvalue;
        
    }
    else
    {
        obj.value = '';
    }
    document.getElementById("btnQuery").click();
}
 

    function showLeft() 
    {
     if (parent.trleft.cols != "190,*") 
     {
        parent.trleft.cols = "190,*";
     } 
    }

    function hidLeft() 
    {
     if (parent.trleft.cols == "190,*") 
     {
        parent.trleft.cols = "0,*";
     } 
    }

    function exitSystem()
    {
        document.all.btnExit.click();
    }
   
    function pageReload()
    {
        parent.frames["left"].document.location.reload();
    }
   
   
  function showSelectWindow(sUrl,width,height,con,colcount)
  { 
    var idvalue=window.showModalDialog(sUrl+'&rid='+Math.random(),'','dialogWidth:'+width+'px; dialogHeight:'+height+'px; center:yes; resizable:yes; status:no; help:no;scroll:no;');
    if(idvalue==null||idvalue=="")
    {
        return;
    } 
     
    var htmlCode = "";
    var tempArray = new Array();
    tempArray = idvalue.split('^');
    htmlCode="<table width='90%' cellspacing='0' cellpadding='0' align='center' class='txt7'>";
    for(var i=0;i<tempArray.length;i++)
    {
        if(tempArray[i]=="")
        {
            continue;
        }
        if(i%colcount==0)
        {
            htmlCode+="<tr>";
        }
        htmlCode+="<td>";
        htmlCode+=tempArray[i];
        htmlCode+="</td>";
        if((i+1)%colcount==0)
        {
            htmlCode+="</tr>";
        }
    } 
    htmlCode+="</table>"; 
   con.value  = htmlCode;
  }
  function selectWindowReturnValue(obj)
  {
    window.returnValue = obj;
    window.close();
  }
 
   

function ChangeBanner(img1,img2)
{
     if(document.getElementById("HDetpNumber")!=null&&document.getElementById("HDetpNumber").value!="")
    {   
        if(document.getElementById("HDetpNumber").value=="52")
        {
            document.getElementById('tdBanner1').style.backgroundImage = "url('"+img1+"')";
             
        }
        if(document.getElementById("HDetpNumber").value=="61")
        {
           
            document.getElementById('tdBanner1').style.backgroundImage = "url('"+img2+"')";
        }
    }
}


function ChangeUrl(url1,url2)
{
     if(document.getElementById("HDetpNumber")!=null&&document.getElementById("HDetpNumber").value!="")
    {   
        if(document.getElementById("HDetpNumber").value=="52")
        {
            document.getElementById('aReturn').href=url1;
             
        }
        if(document.getElementById("HDetpNumber").value=="61")
        {
           
             document.getElementById('aReturn').href=url2;
        }
    }
}

function calculate_byte( sTargetStr ) {
        var sTmpStr, sTmpChar;
        var nOriginLen = 0;
        var nStrLength = 0;
         
        sTmpStr = new String(sTargetStr);
        nOriginLen = sTmpStr.length;

        for ( var i=0 ; i < nOriginLen ; i++ ) {
                sTmpChar = sTmpStr.charAt(i);

                if (escape(sTmpChar).length > 4) {
                        nStrLength += 2;
                } else if (sTmpChar!='\r') {
                        nStrLength ++;
                }
        }
        return nStrLength;  
}

function clen(con,len)
{ 
    
    if(calculate_byte(con.value)>len)
    {
        con.focus(); 
        return false;
    }
    return true;
}


function showQueryTable(con,queryTableId)
{
    if(document.getElementById(queryTableId)==null)
    {
        return;
    }
    with(document.getElementById(queryTableId))
    {  
        var otherClassName = "";
        otherClassName = className.replace('cHidden','');
        otherClassName = otherClassName.replace('cShow','');
        
        if(className.indexOf('cHidden')!=-1)
        {
            con.value='隐藏查询';
            className='cShow '+otherClassName;
        }
        else
        {
            con.value='显示查询';
            className='cHidden '+otherClassName;
        }
    }
}

function showcolor(con)
{ 
   rValue=showModalDialog("SelectColor.htm","","dialogWidth=225px;dialogHeight=195px");
   con.style.backgroundColor=rValue;
   con.style.color = rValue;
   con.value = rValue;
   return  rValue;
}
function showpic(con1,con2,con3)
{ 
    
    rValue=showModalDialog("SelectPic.aspx?e=0","","dialogWidth=430px;dialogHeight=300px");
    if(rValue!=null&&rValue!="")
    {  
        if(con3!=null)
        {    
             con3.style.display='none';
        }
        con1.style.display='';
        con1.src = rValue;
        con2.value = rValue;
    }
    else
    {   
        con3.style.display='';
        con1.style.display='none';
        con1.src = "";
        con2.value = "";
    }
}




