﻿function OpenNewWin(strURL,winName){
 window.open(strURL,"newWin"+winName,"channelmode=no,directories=no,fullscreen=no,location=no,menubar=no,resizable=yes,scrollbars=yes,status=yes,toolbar=no");

}

function OpenNewWinSmall(strURL,winName){
 window.open(strURL,"newWin"+winName,"channelmode=no,directories=no,fullscreen=no,location=no,menubar=no,resizable=yes,scrollbars=yes,status=yes,toolbar=no,width=450,height=450");

}

function OpenNewWinVerySmall(strURL,winName){
window.open(strURL,"newWin"+winName,"channelmode=no,directories=no,fullscreen=no,location=no,menubar=no,resizable=no,scrollbars=no,status=yes,toolbar=no,width=300,height=300");
}

function Openloginwin(strURL,winName){
window.open(strURL,"newWin"+winName,"channelmode=no,directories=no,fullscreen=no,location=no,menubar=no,resizable=no,scrollbars=no,status=no,toolbar=no,width=350,height=220");
}

function OpenPrintCardWin(strURL,winName){
window.open(strURL,"newWin"+winName,"channelmode=no,directories=no,fullscreen=no,location=no,menubar=yes,resizable=no,scrollbars=no,status=no,toolbar=no,width=300,height=150");
}

function OpenNewWinQyrygl(strURL,winName){
 window.open(strURL,"newWin"+winName,"channelmode=no,directories=no,fullscreen=no,location=no,menubar=no,resizable=yes,scrollbars=yes,status=yes,toolbar=no,height=300");

}

function parseCookie(){
  var j;
  cookieList=document.cookie.split(";");
       var cookieArray=new Array();
  for(var i=0;i<cookieList.length;i++){
    cookieList[i]=strTrim(cookieList[i]);
    j=cookieList[i].indexOf("=");
    
    cookieArray[cookieList[i].substring(0,j)]=cookieList[i].substring(j+1,cookieList[i].length);
  }
  return cookieArray;
}

function OpenNewWinWithMenu(strURL,winName){
 window.open(strURL,"newWin"+winName,"channelmode=no,directories=no,fullscreen=no,location=no,menubar=yes,resizable=yes,scrollbars=yes,status=yes,toolbar=no");

}

function strTrim(instr){
  instr+="|";
  var j=instr.length-1;
  var result_str="";
  for(var i=0;i<j;i++)
    if(instr.charAt(i)!=" ") result_str+=instr.charAt(i);
  return result_str;
} //strTrim()

//去除左边空格
function strLTrim(instr){
  instr+="|";
  var j=instr.length-1;
  var result_str="";
  for(var i=0;i<j;i++)
  {
    if(instr.charAt(i)!=" ") 
    {
      result_str=instr.substr(i,j-i);
      break;
    }
  }
  return result_str;
} //strLTrim()

//去除右边空格
function strRTrim(instr){
  instr+="|";
  var j=instr.length-2;
  var result_str="";
  for(var i=j;i>=0;i--)
  {
    if(instr.charAt(i)!=" ") 
    {
        result_str=instr.substring(0,i+1);
        break;
    }
  }
  return result_str;
} //strRTrim()

//去除左右空格
function strLRTrim(instr)
{
   result_str=strLTrim(instr);
   
   result_str=strRTrim(result_str);
   
   return result_str;
}

function isEmpty(str){
  if((str+"|"=="null|")||(str+"|"=="undefined|")) return true;
  for(var i=0;i<str.length;i++)
    if(" "!=str.charAt(i)) return false;
  return true;
}  //isEmpty()

function valid_date(elem){
  var daysInMonth=new Array(31,28,31,30,31,30,31,31,30,31,30,31);
  var index;
  var buffer="";
  var ch;
  var flag=0;

  var instr=strTrim(elem.value);
  if(instr.length==0) return;
  for(index=0;index<instr.length;index++)
  {
    ch=instr.charAt(index);
    if(('0'<=ch)&&(ch<='9')) buffer+=ch;
    else if(flag<2){buffer+="/"; flag++;}
    else{elem.value="1900/01/01"; alert("有效日期格式:yyyy/mm/dd。"); elem.focus();return;}
  }
  if(flag!=2){elem.value="1900/01/01"; alert("有效日期格式:yyyy/mm/dd。"); elem.focus();return;}
  var date_array=buffer.split('/');
  if((date_array[0].length!=2)&&(date_array[0].length!=4)){elem.value="1900/01/01"; alert("无效年份。"); elem.focus();return;}
  if(date_array[1].length==0){elem.value="1900/01/01"; alert("无效月份。"); elem.focus();return;}
  if(date_array[2].length==0){elem.value="1900/01/01"; alert("无效日期。"); elem.focus();return;}
  if(date_array[0].length==2)
  {
    if(date_array[0].charAt(0)!='0') date_array[0]="19"+date_array[0];
    else date_array[0]="20"+date_array[0];
  }
  if(date_array[1].length==1) date_array[1]="0"+date_array[1];
  if(date_array[2].length==1) date_array[2]="0"+date_array[2];
  var year=parseInt(date_array[0],10);   //year
  var month=parseInt(date_array[1],10);  //month
  if((month<1)||(month>12)){elem.value="1900/01/01"; alert("无效月份。"); elem.focus();return;}
  var day=parseInt(date_array[2],10);  //day
  if(month==2)  //February
  {
    index=((0==year%4)&&(0!=(year%100)))||(0==year%400)?29:28;
    if((day<1)||(day>index)){elem.value="1900/01/01"; alert("无效日期。"); elem.focus();return;}
  }
  else
  {
    index=daysInMonth[month-1];
    if((day<1)||(day>index)){elem.value="1900/01/01"; alert("无效日期。"); elem.focus();return;}
  }
  elem.value=date_array[0]+"/"+date_array[1]+"/"+date_array[2];
}  //valid_date()


function valid_dateNew(elem,strSplit){
  var daysInMonth=new Array(31,28,31,30,31,30,31,31,30,31,30,31);
  var index;
  var buffer="";
  var ch;
  var flag=0;

  var instr=strTrim(elem.value);
  if(instr.length==0) return;
  for(index=0;index<instr.length;index++)
  {
    ch=instr.charAt(index);
    if(('0'<=ch)&&(ch<='9')) buffer+=ch;
    else if(flag<2){buffer+=strSplit; flag++;}
    else{elem.value="1900"+strSplit+"01"+strSplit+"01"; alert("有效日期格式:yyyy"+strSplit+"mm"+strSplit+"dd。"); elem.focus();return;}
  }
  if(flag!=2){elem.value="1900"+strSplit+"01"+strSplit+"01"; alert("有效日期格式:yyyy"+strSplit+"mm"+strSplit+"dd。"); elem.focus();return;}
  var date_array=buffer.split(strSplit);
  if((date_array[0].length!=2)&&(date_array[0].length!=4)){elem.value="1900"+strSplit+"01"+strSplit+"01"; alert("无效年份。"); elem.focus();return;}
  if(date_array[1].length==0){elem.value="1900"+strSplit+"01"+strSplit+"01"; alert("无效月份。"); elem.focus();return;}
  if(date_array[2].length==0){elem.value="1900"+strSplit+"01"+strSplit+"01"; alert("无效日期。"); elem.focus();return;}
  if(date_array[0].length==2)
  {
    if(date_array[0].charAt(0)!='0') date_array[0]="19"+date_array[0];
    else date_array[0]="20"+date_array[0];
  }
  if(date_array[1].length==1) date_array[1]="0"+date_array[1];
  if(date_array[2].length==1) date_array[2]="0"+date_array[2];
  var year=parseInt(date_array[0],10);   //year
  var month=parseInt(date_array[1],10);  //month
  if((month<1)||(month>12)){elem.value="1900"+strSplit+"01"+strSplit+"01"; alert("无效月份。"); elem.focus();return;}
  var day=parseInt(date_array[2],10);  //day
  if(month==2)  //February
  {
    index=((0==year%4)&&(0!=(year%100)))||(0==year%400)?29:28;
    if((day<1)||(day>index)){elem.value="1900"+strSplit+"01"+strSplit+"01"; alert("无效日期。"); elem.focus();return;}
  }
  else
  {
    index=daysInMonth[month-1];
    if((day<1)||(day>index)){elem.value="1900"+strSplit+"01"+strSplit+"01"; alert("无效日期。"); elem.focus();return;}
  }
  elem.value=date_array[0]+strSplit+date_array[1]+strSplit+date_array[2];
}  //valid_date()

function valid_yearmonth(elem,strSplit){
  var index;
  var buffer="";
  var ch;
  var flag=0;

  var instr=strTrim(elem.value);
  if(instr.length==0) return;
  for(index=0;index<instr.length;index++)
  {
    ch=instr.charAt(index);
    if(('0'<=ch)&&(ch<='9')) buffer+=ch;
    else if(flag<1){buffer+=strSplit; flag++;}
    else{elem.value="1900"+strSplit+"01"; alert("有效年月格式:yyyy"+strSplit+"mm。"); elem.focus();return;}
  }
  if(flag!=1){elem.value="1900"+strSplit+"01"; alert("有效年月格式:yyyy"+strSplit+"mm。"); elem.focus();return;}
  var date_array=buffer.split(strSplit);
  if((date_array[0].length!=2)&&(date_array[0].length!=4)){elem.value="1900"+strSplit+"01"; alert("无效年份。"); elem.focus();return;}
  if(date_array[1].length==0){elem.value="1900"+strSplit+"01"; alert("无效月份。"); elem.focus();return;}
  if(date_array[0].length==2)
  {
    if(date_array[0].charAt(0)!='0') date_array[0]="19"+date_array[0];
    else date_array[0]="20"+date_array[0];
  }
  if(date_array[1].length==1) date_array[1]="0"+date_array[1];
  var year=parseInt(date_array[0],10);   //year
  var month=parseInt(date_array[1],10);  //month
  if((month<1)||(month>12)){elem.value="1900"+strSplit+"01"; alert("无效月份。"); elem.focus();return;}
  elem.value=date_array[0]+strSplit+date_array[1];
}  //valid_yearmonth()

function stuff(instr,stf_dir,stf_char,stf_len){
  instr+="|";
  var j=stf_len-instr.length+1;
  var result_str;
  var stf_str="";
  for(var i=0;i<j;i++) stf_str+=stf_char;
  instr=instr.substring(0,instr.length-1);
  if(stf_dir=="head") result_str=stf_str+instr;
  else if(stf_dir=="tail") result_str=instr+stf_str;
  return result_str;
} //stuff()

function isDigit(str){
  var num="0123456789";

  for(var i=0;i<str.length;i++)
    if(-1 == num.indexOf(str.charAt(i))) return false;
  return true;
}  //isNumeric()

function strReplace(oldstr,pattern,str){
  var sResult=oldstr;
  while(sResult.indexOf(pattern)>0){
	sResult=sResult.replace(pattern,str);
  }
  
  return sResult;
}  //strReplace()

function strIndexOf(str,pattern,occurence){
  var i=0;
  var index=0;
 
  if(str.indexOf(pattern)==0) i++;
  if(i==occurence) return 0;
  while(index>=0 && index<str.length){
    if((index=str.indexOf(pattern,index+1))>=0) i++;
    else if(index==-1) return -1;
    if(i==occurence) return index;
    if(index==str.length) return -1;
  }
  
  return -1;
}  //strReplace()

function valid_figure(elem,minValue,maxValue){
  if(isEmpty(elem.value)){
    elem.value="00";
    return;
  }
  if(!isDigit(elem.value)||parseInt(elem.value,10)>maxValue||parseInt(elem.value,10)<minValue){
	elem.value="00"; 
	alert("有效数字范围"+minValue+"至"+maxValue+"。"); 
	elem.focus();
	return;
  }
}  //valid_figure

function openHelpWin(strURL,winName){
 screenWidth=screen.width;
 screenHeight=screen.height;
 winTop=0;
 winLeft=screenWidth-210;
 winHeight=screenHeight-200;
 window.open(strURL,"newWin"+winName,"channelmode=no,directories=no,fullscreen=no,location=no,menubar=no,resizable=no,scrollbars=yes,status=no,toolbar=no,left="+winLeft+",top="+winTop+",width=200,height="+winHeight);

}

function ConfirmDel(str){
 if(! window.confirm(str)){window.event.returnValue=false;return} 
}

function openCalendarWin(url,calendarDate)
{

var rtn=window.showModalDialog(url,calendarDate,"dialogHeight: 320px; dialogWidth: 320px;help: No;edge: Raised;resizable: No; status: No;");
return rtn;
}


function dateIsValid(dateValue)
  {
     var d = new Date();
     var currentYear=d.getYear();
     var currentMonth=d.getMonth()+1;
     var currentDate=d.getDate();
     
     if(parseInt(currentYear)<parseInt(dateValue.substring(0,4)))
		return true;
     if(parseInt(currentYear)==parseInt(dateValue.substring(0,4)))
        if(parseInt(currentMonth)<parseInt(dateValue.substring(5,dateValue.indexOf("-",5))))
		   return true;
		else if(parseInt(currentMonth)==parseInt(dateValue.substring(5,dateValue.indexOf("-",5))))
		   if(parseInt(currentDate)<=parseInt(dateValue.substring(dateValue.indexOf("-",5)+1,dateValue.length)))
			   return true;
		   else
			   return false;
		else
		   return false;
     else
        return false;
  }
  
  function compareTwodate(date1Value,date2Value)
  {    
     var date1Year=parseInt(date1Value.substring(0,4));
     var date1Month=parseInt(date1Value.substring(5,date1Value.indexOf("-",5)));
     var date1Date=parseInt(date1Value.substring(date1Value.indexOf("-",5)+1,date1Value.length));
     
     var date2Year=parseInt(date2Value.substring(0,4));
     var date2Month=parseInt(date2Value.substring(5,date2Value.indexOf("-",5)));
     var date2Date=parseInt(date2Value.substring(date2Value.indexOf("-",5)+1,date2Value.length));
     
     if(date1Year<date2Year)
		return -1;
     if(date1Year==date2Year)
     {
        if(date1Month<date2Month)
		   return -1;
		else if(date1Month==date2Month)
		{
		   if(date1Date<date2Date)
			   return -1;
		   else if(date1Date==date2Date)
		       return 0;
		   else
			   return 1;
		}
		else
		   return 1;
	 }
     else
        return 1;
  }
  
  
  function checkDate(elem,nowdate)
	{
		if(elem.value=="")
		return;
		valid_dateNew(elem,"-");
		var rtnVal=compareTwodate(nowdate,elem.value);
		if(rtnVal<0)
		{
		alert("填写日期不得大于今天!");
		elem.value="";
		}
	}
	
	
	var checkClkValid;
        var btnElem;
		function sureToclk()
		{
		
		ctlName=btnElem.CausesValidationCtl;
		var drSource=Page_Validators;
		var dr=new Array();
		var k=0;
		
		var sSpanId;
		var ctlArray=ctlName.split(",");
		
		for(var i=0;i<ctlArray.length;i++)
		{
			var aSpan=document.all.tags("span");
			for(var j=0;j<aSpan.length;j++)
			{
			   if(aSpan[j].controltovalidate!=null)
			   {
					if(aSpan[j].controltovalidate.indexOf(ctlArray[i])!=-1)
					{
						sSpanId=aSpan[j].id+"";
						for(var q=0;q<Page_Validators.length;q++)
						{
							if(Page_Validators[q].id==sSpanId)
							{
								dr[k]=Page_Validators[q];
								k++;
							}
						}
					}
			    }
			}
		}
		Page_Validators=dr;
		if(btnElem.EnableWarning!=null)
		{
		   if(!window.confirm(btnElem.WarningMessage)) 
		   {
		      window.event.returnValue=false;
		      return false;
		   }
		}
		eval("if (typeof(Page_ClientValidate) == 'function') Page_ClientValidate(); ");
		btnElem.onclick="if (typeof(Page_ClientValidate) == 'function') Page_ClientValidate(); ";
		Page_Validators=drSource;
		}
		function changeBtnClk(elem)
		{
		btnElem=elem;
		if(btnElem.onclick!=null)
		{
		    checkSaveValid=btnElem.onclick;
		    checkSaveValid+="";
		    checkSaveValid=checkSaveValid.substring(checkSaveValid.indexOf('{')+1,checkSaveValid.lastIndexOf('}')-1);
		    btnElem.onclick=sureToclk;
		}
		}
		
		
		function valid_PageNumber(elem){
		if(isEmpty(elem.value)){
			elem.value="1";
			return;
		}
		if(!isDigit(elem.value)){
			elem.value="1"; 
			alert("请输入数字型数据。"); 
			elem.focus();
			return;
		}
		}  //valid_PageNumber
		
		
		//convert 15位身份证为18位身份证 参数必须是正确的15位
		function changeSFZ15to18(oldsfz)
		{
			var oldsfz,changeerr;
			var i,SumW=0,partx,last,lastY;
			
			var newsfz=oldsfz.substring(0,6)+'19'+oldsfz.substring(6,15);
			var Wi=new Array(7,9,10,5,8,4,2,1,6,3,7,9,10,5,8,4,2);
			
			for(i=0;i<17;i++)
			{
				partx=newsfz.substring(i,i+1);
				
				SumW+=parseInt(partx)*Wi[i];
			}
			var verifyY=SumW%11;
			switch (verifyY)
			{
				case 0:
					lastY="1";
					break;
				case 1:
					lastY="0";
					break;
				case 2:
					lastY="X";
					break;
				case 3:
					lastY="9";
					break;
				case 4:
					lastY="8";
					break;
				case 5:
					lastY="7";
					break;
				case 6:
					lastY="6";
					break;
				case 7:
					lastY="5";
					break;
				case 8:
					lastY="4";
					break;
				case 9:
					lastY="3";
					break;
				case 10:
					lastY="2";
					break;
				default:
					//err="校验位溢出";
					return "";
			}
			newsfz=newsfz+lastY;
			return newsfz;
		}
		
		var checkBjbhIsUpperChar="";
		
		function BjbhIsUpperChar()
        {  
          //检验输入的报建编号是否为大写字母
          strElem=this;
          var str=strElem.value;
          str+="|";
		  var j=str.length-1;
          var result_str="";
          var flag="n";
          for(var i=0;i<j;i++)
          {
            if(str.charAt(i)<"a"||str.charAt(i)>"z") 
            { 
               result_str+=str.charAt(i);
            }
            else
            {
               flag="y";
            }
           }
          if(flag=="y")
          {
             if(checkBjbhIsUpperChar!=null&&checkBjbhIsUpperChar!="")
                alert(checkBjbhIsUpperChar);
             else
                alert("报建编号中字母必须是大写!");
             strElem.value=result_str;
          }
        }
        
        
        var strLoading="";
        function openLoadWin(winUrl,strMsg)
		{
		    winUrl=winUrl+"shcnsClient/winLoadStatus.htm";
			strLoading=strMsg;
			var winloadhdl=window.showModelessDialog(winUrl,window,"help:no;status:no;dialogWidth:200px;dialogHeight:100px");
			winloadhdl.focus();
			strLoading="";
			return winloadhdl;
		}
