// 显示无模式对话框
function ShowDialog(url, width, height, optValidate) {
	var arr = showModalDialog(url, window, "dialogWidth:" + width + "px;dialogHeight:" + height + "px;help:no;scroll:no;status:no");
}

function checkstring(name,data,allowednull)
{
var datastr = data;
var lefttrim = datastr.search(/\S/gi);

if (lefttrim == -1) {
    if (allowednull) {
      return 1;
    } else {
      alert("请输入" + name + "！");
      return -2;
    }
  }
  
  if (datastr.search(/[<>]/gi) != -1) {
    alert("" + name + "中包含非法字符<>");
    return -1;
  }
  return 0;
}

function checkemail(name, data, allowednull)
{
  var datastr = data;
  var lefttrim = datastr.search(/\S/gi);
  
  if (lefttrim == -1) {
    if (allowednull) {
      return 1;
    } else {
      alert("请输入一个正确的E-mail地址！");
      return -1;
    }
  }
  var myRegExp = /[a-z0-9](([a-z0-9]|[_\-\.][a-z0-9])*)@([a-z0-9]([a-z0-9]|[_\-][a-z0-9])*)((\.[a-z0-9]([a-z0-9]|[_\-][a-z0-9])*)*)/gi;
  var answerind = datastr.search(myRegExp);
  var answerarr = datastr.match(myRegExp);
  
  if (answerind == 0 && answerarr[0].length == datastr.length)
  {
    return 0;
  }
  
  alert("请输入一个正确的E-mail地址！");
  return -1;
}
function parseNum(theNum){
  if (theNum.substring(0,1)==0)
    theNum=theNum.substring(1)
  return theNum
}
function parseYMD(theYear,theMonth,theDay) {
  theYear=parseNum(theYear)
  theMonth=parseNum(theMonth)
  theDay=parseNum(theDay)
  if ((theYear < 1900) || (theYear > 3000)){
    return 1
  }
  if (theMonth < 1 || theMonth > 12){
    return 2
  }
  if ((theMonth==1 || theMonth==3 || theMonth==5 || theMonth==7 || theMonth==8 || theMonth==10 || theMonth==12) &&
      (theDay <1 || theDay > 31)
     ){
    return 3
  }
  if ((theMonth==4 || theMonth==6 || theMonth==9 || theMonth==11) &&
      (theDay <1 || theDay > 30)
     ){
    return 3
  }
  if (theYear%400==0 || (theYear%4==0 && theYear%100!=0)){  //闰年
    if (theMonth==2 && (theDay <1 || theDay > 29) )
      return 3
  }
  else  //平年
    if (theMonth==2 && (theDay <1 || theDay > 28) )
      return 3
  return 0
}
function isInvalidDate(theDate,separator){
  default_style=1
  if (theDate.length>10 || theDate.length<8)
    return true
  idx1=theDate.indexOf(separator)
  if (idx1==-1)
    return true
  idx2=theDate.indexOf(separator,idx1+1)
  if (idx2==-1)
    return true
  if (isInvalidDate.arguments.length>2)
  	default_style=isInvalidDate.arguments[2]
  if (default_style<1 || default_style>9){
  	alert("传入参数有误！请检查。")
	return true
  }
  if (default_style==1){
  theYear=theDate.substring(0,idx1)
  theMonth=theDate.substring(idx1+1,idx2)
  theDay=theDate.substring(idx2+1)
  }
  if (default_style==2){
  theMonth=theDate.substring(0,idx1)
  theDay=theDate.substring(idx1+1,idx2)
  theYear=theDate.substring(idx2+1)
  }
  if (theDay.length>2)
    return true
  if (parseYMD(theYear,theMonth,theDay)>0)
    return true
  else
    return false
}

//禁止右键开始
//document.onselectstart=document.ondragstart=document.oncontextmenu=function(){return false;};
//禁止右键结束

function openwin(url,winName,width,height) {
	xposition=0; yposition=0;
	if ((parseInt(navigator.appVersion) >= 4 ))	{
		xposition = (screen.width - width) / 2;
		yposition = (screen.height - height) / 2;
	}
	theproperty= "width=" + width + "," 
	+ "height=" + height + "," 
	+ "location=0," 
	+ "menubar=0,"
	+ "resizable=0,"
	+ "scrollbars=0,"
	+ "status=0," 
	+ "titlebar=0,"
	+ "toolbar=0,"
	+ "hotkeys=0,"
	+ "screenx=" + xposition + "," //仅适用于Netscape
	+ "screeny=" + yposition + "," //仅适用于Netscape
	+ "left=" + xposition + "," //IE
	+ "top=" + yposition; //IE 
	//window.open( url,winName,theproperty );
	newwin=window.open('','',theproperty );
	newwin.location.href =url;
	
	return false;
}	



function CheckString(valname,val,valimode,limitlen)
{
   	if(valimode==1)
   	{
		if(isblank(val.value))
		{
			alert(valname+"不能为空！");
			val.focus();
			val.select();	
        	return false;
        }
        tmp=new String(val.value)
		if(istoolong(tmp,limitlen))
		{
			alert(valname+"不能超过"+limitlen+"个字符！");
			val.focus();
			val.select();	
            		return false;
        	}
	}
    else{
		tmp=new String(val.value)
        if(istoolong(tmp,limitlen)){
			alert(valname+"不能超过"+limitlen+"个字符！");
			val.focus();
			val.select();	
        	return false;
        }
    }
    return true;
}

function isblank(str)
{
    var i;
    var len=str.length;
    for(i=0;i<len;++i)
    {
		if(str.charAt(i)!=" ")
			return false;
    }
    return true;
}

function istoolong(str,i)
{
    var len=str.length;
    if(i==0)
		return false;
    else
    {   
        if(len>i)
		return true;
        else
		return false;
    }
}

function CheckLoginName(val,min,max)
{
	var len = val.value.length;
	if (len<min || len>max)
	{
		alert("用户登录名长度不正确，应为"+min+"-"+max+"个英文字母、数字！");
		val.focus();
		val.select();	
		return false;
	}
	for (i=0;i<val.value.length;i++)
	{
		var ch = val.value.charAt(i);
		if ( (ch<"0" || ch>"9") && (ch<"a" || ch >"z") && (ch<"A" || ch >"Z"))
		{
			alert("用户登录名必须由字母或数字组成！");
			val.focus();
			val.select();	
			return false;
		}
	}
	return true;
}

function CheckPassWord(val,min,max)
{
	var len = val.value.length;
	if (len<min || len>max)
	{
		alert("用户登录密码长度不正确，应为"+min+"-"+max+"个英文字母、数字！");
		val.focus();
		val.select();	
		return false;
	}
	for (i=0;i<val.value.length;i++){
		var ch = val.value.charAt(i);
		if ( (ch<"0" || ch>"9") && (ch<"a" || ch >"z") && (ch<"A" || ch >"Z"))
		{
			alert("用户登录密码必须由字母或数字组成！");
			val.focus();
			val.select();	
			return false;
		}
	}
	return true;
}

function IsSame(val1,val2)
{
	if (val1.value != val2.value )
	{
		alert("两次输入的密码不相同，请确认！");
		val2.focus();
		val2.select();	
		return false;
	}
	else
		return true;
}

function CheckEmail(val,mode)
{
	if((mode==0) && (val.value==""))
	{
		return true;
	}

	var etext
	var elen
	var i
	var aa
	etext=val.value
	elen=etext.length
	if (elen<5)
	{
		alert("请输入正确的Email！");
		val.focus();
		val.select();	
		return false;
	}
	i= etext.indexOf("@",0)
	if (i==0 || i==-1 || i==elen-1)
	{
		alert("请输入正确的Email！");
		val.focus();
		val.select();	
		return false;
	}
	else{
		if (etext.indexOf("@",i+1)!=-1)
		{
			alert("请输入正确的Email！");
			val.focus();
			val.select();	
			return false;
		}
	}
	if (etext.indexOf("..",i+1)!=-1)
	{
		alert("请输入正确的Email！");
		val.focus();
		val.select();	
		return false;
	}
	i=etext.indexOf(".",0)
	if (i==0 || i==-1 || etext.charAt(elen-1)=='.')
	{
		alert("请输入正确的Email！");
		alert("Emai必须包含字符.但是首位字符不得为.");
		val.focus();
		val.select();	
		return false;
	}
	if ( etext.charAt(0)=='-' ||  etext.charAt(elen-1)=='-')
	{
		alert("请输入正确的Email！");
		alert("首位字符不得为-");
		val.focus();
		val.select();	
		return false;
	}
	if ( etext.charAt(0)=='_' ||  etext.charAt(elen-1)=='_')
	{
		alert("请输入正确的Email！");
		alert("首位字符不得为_");
		val.focus();
		val.select();	
		return false;
	}
	for (i=0;i<=elen-1;i++)
	{
		aa=etext.charAt(i)
		if (!((aa=='.') || (aa=='@') || (aa=='-') ||(aa=='_') || (aa>='0' && aa<='9') || (aa>='a' && aa<='z') || (aa>='A' && aa<='Z')))
		{
			alert("请输入正确的Email！");
			alert("包含非法字符");
			val.focus();
			val.select();	
			return false;
		}
	}
	return true;
}

function CheckValHeight(val,min,max,mode){
	if((mode==0) && (val.value=="")){
		return true;
	}
	
	var len = val.value.length;
	if (val.value<min || val.value>max){
		alert("请输入正确的身高数据！");
		val.focus();
		val.select();	
		return false;
	}
	var val2 = val.value;
	for (i=0;i<val2.length;i++){
		var ch = val2.charAt(i);
		if ( (ch<"0" || ch>"9") ){
			alert("身高数据必须由有效数字组成！");
			val.focus();
			val.select();	
			return false;
		}
	}
	if (isNaN(val2)){	
		alert("身高数据必须由有效数字组成！");
		val.focus();
		val.select();	
		return false;
	}
	else if (parseInt(val2)<=0){
		alert("身高数据必须由有效数字组成！");
		val.focus();
		val.select();	
		return false;
	}
	else if (val2.indexOf('0')==0){
		alert("身高数据必须由有效数字组成！");
		val.focus();
		val.select();	
		return false;
	}
	return true;
}

function Isinteger(sNum) {
	var	num
	num=new RegExp('[^0-9_]','')
	if (isNaN(sNum)) {
		return false
	}
	else {
		if (sNum.search(num)>=0) {
			return false
		}
		else {
			return true
		}
	}
}

function CheckInteger(val,min,max,mode){
	var value = val.value;
	if((mode==0) && (value=="")){
		return true;
	}
	if(!isNaN(value)){
		if((value<min) || (value>max)){
			val.focus();
			val.select();	
			return false;
		}	
		else
			return true;						
	}		
	else{
		val.focus();
		val.select();		
		return false;	
	}	
}

function isValidDate(iY, iM, iD) {
  var undefined									
  if ( iY != undefined && !isNaN(iY) && iY >=0 && iY<=9999 &&						
       iM != undefined && !isNaN(iM) && iM >=1   && iM<=12   &&					
       iD != undefined && !isNaN(iD) && iD >=1   && iD<=31  )  {						       					
       if (iY<50) iY = 2000+iY; else if (iY<100) iY=1900+iY;						
    if (iM == 2  && (isLeapYear(iY)  && iD > 29 || !isLeapYear(iY) && iD>28) ||	
        iD == 31 && (iM<7 && iM%2==0 || iM>7 && iM%2==1) )							
		return false																
	else	return true   
 }														
 else  return false
}	

function isLeapYear(iYear) {
  var undefined						
  if ( iYear != undefined && !isNaN(iYear) && iYear > 0 &&		
       (iYear%4==0 && iYear%100 !=0 || iYear%400==0)   )		
      return true												
	else return false;
}											

function CheckPositive(valname,val,min,max,mode){
	if((mode==0) && (val.value=="")){
		return true;
	}
	
	if(!CheckNumber(valname,val,min,max,mode)){
		val.focus();
		val.select();	
		return false;
	}
	if (parseInt(val.value)<=0){
		//alert(valname+"为正数值类型，数据必须为有效的正整数！");
		val.focus();
		val.select();	
		return false;
	}

	return true;
}

function CheckNumber(valname,val,min,max,mode){
	if((mode==0) && (val.value=="")){
		return true;
	}
	
	var len = val.value.length;
	if (len<min || len>max){
		//alert(valname+"为数值类型，请输入正确的数值！");
		val.focus();
		val.select();	
		return false;
	}
	var val2 = val.value;
	for (i=1;i<val2.length;i++){
		var ch = val2.charAt(i);
		if ( (ch<"0" || ch>"9" ) ){
			//alert(valname+"为数值类型，请输入正确的数值！");
			val.focus();
			val.select();	
			return false;
		}
	}
	if (isNaN(val2)){	
		//alert(valname+"为数值类型，请输入正确的数值！");
		val.focus();
		val.select();	
		return false;
	}
	else if (val2.indexOf('0')==0 && len>1){
		//alert(valname+"为数值类型，请输入正确的数值！");
		val.focus();
		val.select();	
		return false;
	}
	else if (val2.indexOf('-')==0 && val2.indexOf('0')==1){
		//alert(valname+"为数值类型，请输入正确的数值！");
		val.focus();
		val.select();	
		return false;
	}
	return true;
}

function isValidDateString(sDateTime) {
	var asDateTime = new Array()
	asDateTime = sDateTime.value.split('-')
	if (asDateTime.length != 3){
 		sDateTime.focus();
		sDateTime.select();	  
		return false;
	}
	if(asDateTime[0].length!=4){
		alert("请输入四位整数的年份！");
 		sDateTime.focus();
		sDateTime.select();	
		return false;
	}	
	if(!isValidDate(asDateTime[0], asDateTime[1], asDateTime[2])){
 		sDateTime.focus();
		sDateTime.select();	
		return false;
	}	
			
	return true;
}	