var report=new String()

function isEnglish(s)
{
	if(isEmpty(s))
	{
		report=report+"用户名不能为空！\n";
		return false;
	}
	for(i=0;i<s.length;i++)
	{
		var c=s.charAt(i);
		if((c>='A'&&c<='Z')||(c>='a'&&c<='z')||(c>='0'&&c<='9')||c=='_')
		{
			continue;
		}
		else
		{
			report=report+"用户名必须为英文、下划线或数字！\n";
			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 isCharsInBagEx (s, bag)
{
  var i,c;
  for (i = 0; i < s.length; i++)
  {
        c = s.charAt(i);
	if (bag.indexOf(c) > -1)
        return c;
  }
  return "";
}

function BadCharsInBag(s,bag)
{
 var i,c;
  for (i = 0; i < s.length; i++)
  {
        c = s.charAt(i);
	if (bag.indexOf(c) > -1)
        return false;
  }
  return true;
}

function isCharsInBag (s, bag)
{
  var i;

  for (i = 0; i < s.length; i++)
  {

      var c = s.charAt(i);
      if (bag.indexOf(c) == -1) return false;
  }
  return true;
}


function checkspace(s)
{
	var i;
	var t;
	if(s==null)
		return true;
	t="";
	for (i = 0; i < s.length; i++)
		t=t+" ";
	if(t==s)
		return true;
	else
		return false;
}


function isUserName(s)
{
 	var errorChar;
	var badChar = "><,[]{}?/+=|\\'\":;~!#$%()`";
 	if (isEmpty(s))
 	{
 		report=report+"请输入用户名！\n";
 		return false;
 	}
 	//is s contain whitespace
   	if ( isWhitespace(s) )
	{
		report=report+"输入的用户名中不能包含空格符，请重新输入！\n";
		return false;
	}
	//is s contain invalid characters
	//Validate the user name
	errorChar = isCharsInBagEx( s, badChar)
    	if (errorChar != "" )
	{
		report=report+"您输入的用户名" + s+"是无效的用户名,请不要在用户名中输入字符" + errorChar + "!请重新输入合法的用户名！\n";
		return false;
	}

	return true;
 }



function isPassword (s)
{
if (isEmpty(s))
  {
	report=report+"密码不能为空，请输入！\n";
	return false;
  }
//is s contain whitespace
  if ( isWhitespace(s) )
  {
	report=report+"密码中不能包含空格符，请重新输入！\n";
	return false;
  }

  if ((s.length>12)||(s.length<6))
  {
 	report=report+"口令不能超过12位也不能少于6位！\n";
	return false;
  }
  return true;
}


function JudgePassword(s1,s2)
{
	if (s1==s2)
		return true;
	else
	{
		report=report+"密码输入不一致！请重新输入！\n";
		return false;
	}
}

function isEmail (s)
{
	if(!isEmpty(s))
	{
		if (isWhitespace(s))
		{
			report=report+"输入的E-mail地址中不能包含空格符，请重新输入！\n";
			return false;
		}

		var i = 1;
		var len = s.length;

		if (len > 30)
		{
			report=report+"email地址长度不能超过30位!\n";
			return false;
		}

		pos1 = s.indexOf("@");
		pos2 = s.indexOf(".");
		pos3 = s.lastIndexOf("@");
		pos4 = s.lastIndexOf(".");
		if ((pos1 <= 0)||(pos1 == len)||(pos2 <= 0)||(pos2 == len))
		{
			report=report+"请输入有效的E-mail地址！\n";
			return false;
		}
		else
		{
			if( (pos1 == pos2 - 1) || (pos1 == pos2 + 1)
			  || ( pos1 != pos3 )  //find two @
			  || ( pos4 < pos3 ) ) //. should behind the '@'
			{
				report=report+"请输入有效的E-mail地址！\n";
				return false;
			}
		}

		if ( !isCharsInBag( s, "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789.-_@"))
		{
			report=report+"email地址中只能包含字符ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789.-_@请重新输入\n" ;
			return false;
		}
	}
	else
	{
		report=report+"请输入您的E-mail地址！\n";
		return false;
	}

	return true;
}


function isInt(s, item)
{
  if (isEmpty(s))
  {
	report=report+item + "不能为空，请输入！\n";
	return false;
  }

  var validChar = "0123456789";
  if (!isCharsInBag(s, validChar))
  {
	report=report+"您输入的" + item + s +"是无效的" + item + "，请输入合法的" + item + "！\n";
	return false;
  }

  return true;
}

function isIntEx(s, item, len, bCompare)
{
  if (isEmpty(s))
  {
	report=report+item + "不能为空，请输入！\n";
	return false;
  }

  var validChar = "0123456789";
  if (!isCharsInBag(s, validChar))
  {
	report=report+"您输入的" + item + s +"是无效的" + item + "，请输入合法的" + item + "！\n";
	return false;
  }

  if (bCompare == "=")
  {
    if (s.length != len)
    {
	report=report+"您输入的" + item + s +"是无效的" + item + "，必须等于" + len + "位！\n";
	return false;
    }
  }
  else if (bCompare == "<")
  {
    if (s.length >= len)
    {
	report=report+"您输入的" + item + s +"是无效的" + item + "，必须小于" + len + "位！\n";
	return false;
    }
  }

  return true;
}


function isValidString(s, des)
{
 	var errorChar;
	var badChar = "><,[]{}?/+=|\\'\":;~!@#$%^&()`";
 	if (isEmpty(s))
 	{
 		report=report+"请输入"+ des +"！\n";
 		return false;
 	}
	//is s contain invalid characters
	//Validate the user name
	errorChar = isCharsInBagEx( s, badChar)
    	if (errorChar != "" )
	{
		report=report+"您输入的" + des +"是无效的"+des +",请不要在"+des+"中输入字符" + errorChar + "!请重新输入合法的"+des+"！\n" ;
		return false;
	}

	return true;
 }


function LTrim(s)
{
	for(var i=0;i<s.length;i++)
		if(s.charAt(i)!=' ')
		 return s.substring(i,s.length);
	 return "";
}

function RTrim(s)
{
	for(var i=s.length-1;i>=0;i--)
		if(s.charAt(i)!=' ')
			return s.substring(0,i+1);
		return "";
}

function Trim(s)
	{
	return RTrim(LTrim(s));
	}

function isTelNumber(s)
{
	//is s contain invalid characters
	var badChar = "><,[]{}?/+=|\\'\":;~!@#$%^&`";
	var len = s.length;
	//Validate the user name
	if(!isEmpty(s))
	{
		if ( isCharsInBag( s, badChar))
		{
			report=report+"联系电话中不能含有以下字符：><,[]{}?/+=|\\'\":;~!@#$%^&`\n"
			return false;
		}
		//check user length
		if ((len>18)||(len<6))
		{
			report=report+"联系电话不能超过18位也不能少于6位！\n";
			return false;
		}
		if(!isCharsInBag (s, "0123456789-()"))
		{
			report=report+"请检查联系电话是否全为以下字符:0123456789-()！\n";
			return false;
		}
	}
	else
	{
		report=report+"请输入您的联系电话！\n";
		return false;
	}
	return true;
}

function isAddress(s)
{
   	// is s Empty?
   	if ( isEmpty(s) )
	{
		report=report+"联系地址不能为空，请重新输入！\n";
		return false;
	}
	//is s contain whitespace
   	if ( isWhitespace(s) )
	{
		report=report+"输入的联系地址中不能包含空格符，请重新输入！\n";
		return false;
	}
	//is s contain invalid characters
	var badChar = "><,[]{}?/+=|\\'\":;~!@$%^&`*";
	var len = s.length;
	//Validate the user name
	if (!BadCharsInBag(s,badChar))
	{
		report=report+"联系地址中不能含有字符 "+badChar+ " !\n";
		return false;
	}
	//check user length
	if ((len>200)||(len<5))
	{
		report=report+"联系地址不能超过100个汉字也不能少于五个汉字！\n";
		return false;
	}
	return true;
}

function isName(s)
{
 	var errorChar;
	var badChar = "><,[]{}?/+=|\\'\":;~!#$%()`_";
 	if (isEmpty(s))
 	{
 		report=report+"请输入姓名！\n";
 		return false;
 	}
	//is s contain invalid characters
	//Validate the user name
	errorChar = isCharsInBagEx( s, badChar)
    	if (errorChar != "" )
	{
		report=report+"您输入的姓名" + s +"是无效的姓名,请不要在姓名中输入字符" + errorChar + "!请重新输入合法的姓名！\n";
		return false;
	}
	var user_country="中国";
	if (user_country == "中国")
	{
	 	//is s contain whitespace
		if ( isWhitespace(s) )
		{
			report=report+"输入的姓名中不能包含空格符，请重新输入！\n";
			return false;
		}
		for(i=0;i<s.length;i++)
		{
			var c=s.charAt(i);
			if((c>='A'&&c<='Z')||(c>='a'&&c<='z')||(c>='0'&&c<='9'))
			{
				report=report+"您必须输入您的中文姓名，请重新输入！\n";
				return false;
			}
		}
	}
	return true;
 }

function isZipCode(s)
{
	if(!isEmpty(s))
	{
		if(s.length!=6)
		{
			report=report+"邮政编码必须为六位！请重新输入！\n";
			return false;
		}
		if(!isCharsInBag(s,"0123456789"))
		{
			report=report+"邮政编码必须为数字！请重新输入！\n";
			return false;
		}
	}
	else
	{
		report=report+"请输入邮政编码！\n";
		return false;
	}
	return true;
}


function isBorn(year,month,day)
{
	var tempyear;
	tempyear=parseInt(year);
	if(isEmpty(year)||isEmpty(month)||isEmpty(day)||year.length!=4)
	{
		report=report+"出生日期不能为空！请重新输入！\n"
		return false;
	}
	if(!(isCharsInBag(year,"0123456789")&&isCharsInBag(month,"0123456789")&&isCharsInBag(day,"0123456789")))
	{
		report=report+"请输入合法的年月日！\n";
		return false;
	}
	else
	{
		if (parseInt(month)>12||parseInt(day)>31)
		{
			report=report+"请输入合法的年月日！\n";
			return false;
		}
		else
			switch(parseInt(month))
			{
				case 4:
				case 6:
				case 9:
				case 11:
					if(parseInt(day)>30)
					{
						report=report+"请输入合法的年月日！\n";
						return false;
					}
					break;
				case 2:
					if(parseInt(day)>29)
					{
						report=report+"请输入合法的年月日！\n";
						return false;
					}
					if( (parseInt(day) == 29) && ((tempyear%400 && !(tempyear%100)) || (tempyear%4)) )
					{
						report=report+"请输入合法的年月日！\n";
						return false;
					}
					break;
			}
	}
	var dateCurrent = new Date();
	var yearCurrent = dateCurrent.getYear();
	var yearDif = yearCurrent-tempyear;
	if (yearDif<16 || yearDif>100)
	{
		report=report+"您的年龄必须在16岁至100岁之间！\n";
		return false;
	}

	//document.register_1.born.value=tempyear+"/"+month+"/"+day;

	return true;
}

function isIDCard(s){
	if (isEmpty(s))
 	{
 		report=report+"请输入身份证号，以便日后查询订单！\n";
 		return false;
 	}
 	if (!(isInt(s, "身份证号码"))){
 		return false;
 	}
 	if(s.length<15 || s.length>18){
	 	report=report+"你的身份证号码位数不对！\n";
	 	return false;
 	}
 	return true;
}

function refresh(url){
	if(url == location.pathname){
		location.reload();
	}else{
		location = url;
	}
}

function popUp(url) {
sealWin=window.open(url,"win",'toolbar=0,location=0,directories=0,status=1,menubar=1,scrollbars=1,resizable=1,width=700,height=600');
self.name = "mainWin"; }

function nw(url,handle,width,height)
{
var tt
tt = "toolbar=yes,menubar=no,scrollbars=yes,resizable=yes,statusbar=no,width="+width+",height="+height;
window.open(url,handle,tt)
}
