function popwin(id,path)
{
window.open("/it/down/list.asp?id="+id+"&ppath="+path,"","height=460,width=560,resizable=yes,scrollbars=yes,status=yes");
}

var newwin = null
function newwindow(to,w,h)
{
	if (!newwin || newwin.closed)
	{
   		newwin=window.open(to,"indexww","width="+w+",height="+h+",resizable=yes,scrollbars=yes")
	}
	else
	{
		newwin.close()
   		newwin=window.open(to,"indexww","width="+w+",height="+h+",resizable=yes,scrollbars=yes")
	}
	newwin.focus()
}

function ischar(s)
{
 	var errorChar;
	var badChar = "><,[]{}?/+=|\\'\":;~!@#$%^&()`"; 
 	
    if ( s == "" )
	{
		alert("请您输入内容！")
		return false;
	}
	
	if ( isWhitespace(s) )
	{
		alert("输入的字符中不能包含空格符，请重新输入！");	
		return false;
	}
	errorChar = isCharsInBagEx( s, badChar)
    	if (errorChar != "" )
	{
		alert("您输入的字符" + s+"是无效的,\n\n请不要在字符中输入" + errorChar + "!\n\n请重新输入合法的字符！" );
		return false;
	}
	return true;
}

function isUserName(s)
{
 	var errorChar;
	var badChar = "><,[]{}?/+=|\\'\":;~!@#$%^&()`"; 
 	if (isEmpty(s))
 	{
 		alert("请输入用户名！");
 		return false;
 	}
   	if ( isWhitespace(s) )
	{
		alert("输入的用户名中不能包含空格符，请重新输入！");	
		return false;
	}
	errorChar = isCharsInBagEx( s, badChar)
    	if (errorChar != "" )
	{
		alert("您输入的用户名" + s+"是无效的用户名,\n\n请不要在用户名中输入字符" + errorChar + "!\n\n请重新输入合法的用户名！" );
		return false;
	}
	if (s.length<1 || s.length>20){
		alert("用户名必须在1至20个字符之间")
		return false
	} 
	return true;
}


//公用函数

function isCharsInBag (s, bag)
{  
//字符是否在S中
  var i;
  // Search through string's characters one by one.
  // If character is in bag, append to returnString.

  for (i = 0; i < s.length; i++)
  {   
      // Check that current character isn't whitespace.
      var c = s.charAt(i);
      if (bag.indexOf(c) == -1) return false;
  }
  return true;
}

function isEmpty(s)
{  
       return ((s == null)||(s.length == 0));       
}

function isWhitespace (s)
{  
//空格判断
  var whitespace = " \t\n\r";
  var i;
   for (i = 0; i < s.length; i++)
   {   
        var c = s.charAt(i);
       if (whitespace.indexOf(c) >= 0) 
	   {
		  return true;
	   }
   }

    return false;
}

function isleapyear(thisyear)
{
// 闰年判断
 	return(((thisyear%4==0) && (thisyear%100!=0)) || (thisyear%400==0))

}

function isCharsInBagEx (s, bag)
{  
//除S以外的字符
  var i,c;
  // Search through string's characters one by one.
  // If character is in bag, append to returnString.
  for (i = 0; i < s.length; i++)
  {   
        c = s.charAt(i);
	if (bag.indexOf(c) > -1) 
        return c;
  }
  return "";
}

function radioselected(radioBth)
{
//是否选择单选按钮
	for(i=0;i<radioBth.length;i++)
	{
		if(radioBth[i].checked)
		return true
	}
		return false
}

function isYear(s)
{
	var Today=new Date()
	thisYear=Today.getYear()
	var badChar = "><,[]{}?/+=|\\'\":;~!@#$%^&`"; 
	var len = s.length;
       if (isEmpty(s)){   
	    alert("必须输入年份")
	    return false;
	}
    if ( isCharsInBag( s, badChar)){   
	    alert("年份输入非法")
		return false;
	}
	if ((len!=4)){
		alert("年份是四位！");
		return false;
	}
	if(!isCharsInBag (s, "0123456789")){
        alert("请检查一下您输入的年份是否为数字！");
        return false;
        }
	if (s<1800){
		   alert("年份要大于1800");
		   return false;
			}
//	if ((thisYear-s)<0){
//		alert("年份要不能大于"+thisYear);
//		return false;
//			}
	return true;
}

function isEmail(s)
{
    if (isEmpty(s))
	{
		alert("E-mail地址不能为空，请输入！");	
		return false;
	}
	//is s contain whitespace
    if (isWhitespace(s))
	{
		alert("输入的E-mail地址中不能包含空格符，请重新输入！");	
		return false;
	}
   var i = 1;
   var len = s.length;

	if (len > 40)
	{
		alert("E-mail地址长度不能超过40位!");
		return false;
	}
	
	pos1 = s.indexOf("@");
	pos2 = s.indexOf(".");
	pos3 = s.lastIndexOf("@");
	pos4 = s.lastIndexOf(".");
	if ((pos1 <= 0)||(pos1 == len)||(pos2 <= 0)||(pos2 == len)){
		alert("请输入有效的E-mail地址！");
		return false;
	}
	else{		
		if( (pos1 == pos2 - 1) || (pos1 == pos2 + 1) 
		  || ( pos1 != pos3 )  //find two @
		  || ( pos4 < pos3 ) ) //. should behind the '@'  		
		{
			alert("请输入有效的E-mail地址！");
			return false;
		}
	}

	if ( !isCharsInBag( s, "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789.-_@"))
	{
		alert("email地址中只能包含字符ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789.-_@\n" + "请重新输入" );
		return false;
	}
	return true;
}

function isNum(s)
{
		if(!isCharsInBag (s, "0123456789")){
	        alert("您的QQ不是数字吗？！");
	        return false;
	}
	return true;
}

function isNumber(s,l,u)
{
	if (isEmpty(s)){   
	    alert("必须输入数字")
	    return false;
	}
	if(!isCharsInBag (s, "0123456789")){
	        alert("请检查一下您输入的是否为数字！");
	        return false;
	}
	if (s<l){
		   alert("输入的数字要大于"+l+"！");
		   return false;
	}
	if (s>u){
		alert("输入的数字要小于"+u+"！");
		return false;
	}
	return true;
}

function isCardNum(s){
    if (isEmpty(s)){   
	    alert("必须输入数字")
	    return false;
	}
	if(!isCharsInBag (s, "0123456789")){
        alert("请检查一下您输入的是否为数字！");
        return false;
    }
	if (s.length==15 || s.length==18){
		return true;
	}else{
		   alert("输入的数字长度为15位或者18位！");
		   return false;
	}
}

function isZipCode(s){
	if (!isEmpty(s)){
		if(!isCharsInBag (s, "0123456789")){
    	    alert("请检查一下您输入的是否为数字！");
        	return false;
	    }
		if (s.length==6){
			return true;
		}else{
			alert("输入的邮政编码长度为6！");
			return false;
		}
	} else {
		return true;
	}
}

function chkdate(datestr)
{
       if (isEmpty(datestr)){
	    alert("必须输入日期")
	    return false;
	}
	var lthdatestr
	lthdatestr= datestr.length ;
	var tmpy="";
	var tmpm="";
	var tmpd="";
	//var datestr;
	var status;
	status=0;
	
	for (i=0;i<lthdatestr;i++){
		if (datestr.charAt(i)== '-'){
		 	status++;
		}
		if (status>2){
			alert("请用'-'作为分隔符！");
			return false;
		}
		if ((status==0) && (datestr.charAt(i)!='-')){
			tmpy=tmpy+datestr.charAt(i)
		}
		if ((status==1) && (datestr.charAt(i)!='-')){
			tmpm=tmpm+datestr.charAt(i)
		}
		if ((status==2) && (datestr.charAt(i)!='-')){
			tmpd=tmpd+datestr.charAt(i)
		}
	}
	
	year=new String (tmpy);
	month=new String (tmpm);
	day=new String (tmpd)
	//tempdate= new String (year+month+day);
	//alert(tempdate);
	if ((tmpy.length!=4) || (tmpm.length>2) || (tmpd.length>2))
	{
		alert("请用'-'作为分隔符！");
		//	alert("错误的日期格式！");
		return false;
	}
	if (!((1<=month) && (12>=month) && (31>=day) && (1<=day)) )
	{
		alert ("错误的月份或天数！");
		return false;
	}
	if (!((year % 4)==0) && (month==2) && (day==29))
	{
		alert ("这一年不是闰年！");
		return false;
	}
	if ((month<=7) && ((month % 2)==0) && (day>=31))
	{
		alert ("这个月只有30天！");
		return false;
	}
	if ((month>=8) && ((month % 2)==1) && (day>=31))
	{
		alert ("这个月只有30天！");
		return false;
	}
	if ((month==2) && (day==30))
	{
		alert("2月永远没有这一天！");
		return false;
	}
	
	return true;
}