var smp_window = null;

function closePopup() {
	if (smp_window != null)
		{
			smp_window.close();
		}
	}

function CheckEmpty(Field, FieldTitle)
{
	if (Field.value == "")
	{
		alert("请正确填写\"" + FieldTitle + "\".");
		Field.focus();
		return false;
	}
		
	return true;
}
	
function CheckInteger(Field, FieldTitle)
{
	if (Field.value != "")
	{
		for (i = 0; i < Field.value.length; i++)
		{
			ch = Field.value.charAt(i);
				
			if ( (ch < '0' || ch > '9') && ch != '-' && ch!= ',') {
				alert("\"" + FieldTitle + "\"中只能输入数字.");
				Field.focus();
				return	false;
			}
		}
	}
		
	return true;
}

function CheckPass(Field1,Field2)
{
	if (Field1.value != "" && Field2.value!="")
	{
		if(Field1.value != Field2.value)
		{
		alert('两次输入的密码不一样，请检查！')
		Field1.focus();
		return false;
		}
		return true;
	}

}

function CheckEmail2(Field1,Field2)
{
	if (Field1.value != "" && Field2.value!="")
	{
		if(Field1.value != Field2.value)
		{
		alert('两次输入的电子邮件不一样，请检查！')
		Field1.focus();
		return false;
		}
		return true;
	}

}

function CheckReal(Field, FieldTitle)
{
	if (Field.value != "")
	{
		DotNum = 0;
		for (i = 0; i < Field.value.length;  i++)
		{
			ch = Field.value.charAt(i);
				
			if ((ch < '0' || ch > '9') && ch != '.') 
			{
				alert("\"" + FieldTitle + "\"中只能输入数字.");
				Field.focus();
				return false;
			}
				
			if (ch == '.')
			{
				if (DotNum > 0) 
				{
					alert("\"" + FieldTitle + "\"中只能输入一个小数点.");
					Field.focus();
					DotNum++;
					return false;
				}
			}
		}
	}
		
	return	true;
}

function CheckLetter(Field, FieldTitle)
{
	var NoLetter = 0
	if (Field.value != "")
	{
		DotNum = 0;
		for (i = 0; i < Field.value.length;  i++)
		{
			ch = Field.value.charAt(i);
				
			if ((ch < 'a' || ch > 'z') && ch != '_') 
			{
				if ((ch < 'A' || ch > 'Z') && ch != '_') 
				
				{
					if ((ch < '0' || ch > '9') && ch != '_') 
				
					{
						alert("\"" + FieldTitle + "\"只能由英文、数字和\"\_\"组成.");
						Field.focus();
						return false;
					}
				}
				else
				NoLetter+=1;
			}
			else
			NoLetter+=1;
				
		}
	}
	
	
	if(NoLetter==0){
		alert("为安全起见，\"" + FieldTitle + "\"不能完全使用数字.");
		Field.focus();
		return false;
	}	
	return	true;
}

function CheckMaxLength(Field, MaxLength, FieldTitle)  
{  
	if (Field.value != "")  
	{  
		if (Field.value.length > MaxLength)  
		{  
			alert("\"" + FieldTitle + "\"中输入的字符请不要超过" + MaxLength + "字符.\n 现在字符：" + Field.value.length);  
			Field.focus();
			return false; 
		}  
	}  
			  
	return true;  
}
	  
function CheckMinLength(Field, MinLength, FieldTitle)  
{  
	if (Field.value != "")  
	{  
		if (Field.value.length < MinLength)  
		{  
			alert("\"" + FieldTitle + "\"请不要少于" + MinLength + "个字符.");  
			Field.focus();  
			return false;  
		}  
	}  
			  
	return true;  
}  
	
function CheckOption(Field, FieldTitle) 
{
	if (Field.value == 0)
	{
		
		alert("请选择\"" + FieldTitle + "\".");
		Field.focus();  
		return false;
	}
	return true;
}
	//此函数用于判断Email地址是否正确
function CheckEmail(Field)
{
   // there must be >= 1 character before @, so we
   // start looking at character position 1
   // (i.e. second character)
   var i = 1;
   var len = Field.value.length;
	if (len > 50)
	{
		window.alert("email地址长度不能超过50位!");
		Field.focus();
		return false;
	}
	pos1 = Field.value.indexOf("@");
	pos2 = Field.value.indexOf(".");
	pos3 = Field.value.lastIndexOf("@");
	pos4 = Field.value.lastIndexOf(".");
	//check '@' and '.' is not first or last character
	if ((pos1 <= 0)||(pos1 == len-1)||(pos2 <= 0)||(pos2 == len-1))  
	{
		window.alert("请正确填写E-mail地址！");
		Field.focus();
		return false;
	}
	else
	{
		//check @. or .@
		if( (pos1 == pos2 - 1) || (pos1 == pos2 + 1) 
		  || ( pos1 != pos3 )  //find two @
		  || ( pos4 < pos3 ) ) //. should behind the '@'  		
		{
			window.alert("请正确填写E-mail地址！");
			Field.focus();
			return false;
		}
	}
	return true;
}
	
function CheckMustLength(Field, MustLength, FieldTitle)  
{  
	if (Field.value != "")  
	{  
		if (Field.value.length != MustLength)  
		{  
			alert("\"" + FieldTitle + "\"中必须包含至少" + MustLength + "位字符.");  
			Field.focus();  
			return false;  
		}  
	}  
			  
	return true;  
}  
	  
function CheckIntRange(field,prompt,min,max) {  
	if ( ! CheckInteger(field,prompt) )  
		return	false;  
	ival = parseInt(field.value);  
	if ( ival < min || ival > max ) {  
		alert(prompt + " 只能为 " + min + " 到 " + max + " 之间的数字");  
		field.focus();  
		return	false;  
	}  
	return	true;  
}  

function CheckUrl(field) {  

  nRet = validateCnsUrl(field.value);
  if(nRet != 0)
  {
    switch(nRet) {
      case 1 : alert('请正确填写英文网址URL。');break;
      case 2 : alert('网址URL前面必须包含http://。');break;
      case 3 : alert('网址URL格式有错误，请重新填写。');break;
      case 4 : alert('请正确填写网址URL。');break;
      case 5 : alert('网址URL中不能有‘@’号。');break;
    }
    field.focus();
    return false;
	}  
	return	true; 
}

function validateCnsUrl(cns_url)
{
  var i;

  if(cns_url == "") return 1;  // cns_url can not be empty
  if(cns_url == "http://") return 1;
  cns_url = cns_url.toLowerCase();
  i = cns_url.indexOf("http://");
  if(i==-1) return 2;
  if(i!=0) return 3;
  if(cns_url.length<8) return 4;
  if( -1 == cns_url.indexOf(".")) return 3;
  if(0 < cns_url.indexOf("@")) return 5 ;
  if(cns_url.length == cns_url.indexOf(".")+1) return 3; 
  return 0;
}