<!--
/*
s: string value
bag: char array

isEmpty(s) : null
isWhitespace (s) : " \t\n\r"
isUserName(s) 
isName(s)
isEmail (s)
isTelNumber(s)
isCardNumber(s) 
isAddress(s)
isCharsInBag (s, bag)
isKeyword(s)
isItemNum(s)
isPassword(s)
isInt(s, item)
isIntEx(s, item, len， bCompare)

isCharsInBagEx (s, bag) : return a bad char

isUserNameOld(s) 
*/

function isEmpty(s)
{  
	return ((s == null) || (s.length == 0))
}

function isWhitespace (s)
{  
  var whitespace = " \t\n\r";
  var i;
  // Is s empty?
  //if (isEmpty(s)) return true;

   // Search through string's characters one by one
   // until we find a non-whitespace character.
   // When we do, return false; if we don't, return true.
   for (i = 0; i < s.length; i++)
   {   
       // Check that current character isn't whitespace.
       var c = s.charAt(i);
       if (whitespace.indexOf(c) >= 0) 
	   {
		  return true;
	   }
   }

   // All characters are whitespace.
   return false;
}

function isCharsInBagEx (s, bag)
{  
  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 isCharsInBag (s, bag)
{  
  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 isRegisterUserName(s)
{
 	var errorChar;
	var badChar = "><,[]{}?/+=|\\'\":;~!@#$%^&()`"; 
 	if (isEmpty(s))
 	{
 		alert("请输入用户名！");
 		return false;
 	}
 	//is s contain whitespace
   	if ( isWhitespace(s) )
	{
		alert("输入的用户名中不能包含空格符，请重新输入！");	
		return false;
	}
	//is s contain invalid characters
	//Validate the user name
	errorChar = isCharsInBagEx( s, badChar)
    	if (errorChar != "" )
	{
		alert("您输入的用户名" + s+"是无效的用户名,\n\n请不要在用户名中输入字符" + errorChar + "!\n\n请重新输入合法的用户名！" );
		return false;
	} 	
	
	return true;
}

function isEmail (s)
{
   	// is s Empty?
    if (isEmpty(s))
	{
		alert("输入的E-mail地址不能为空，请输入！");	
		return false;
	}
	//is s contain whitespace
    if (isWhitespace(s))
	{
		alert("输入的E-mail地址中不能包含空格符，请重新输入！");	
		return false;
	}

   // there must be >= 1 character before @, so we
   // start looking at character position 1
   // (i.e. second character)
   var i = 1;
   var len = s.length;

	if (len > 30)
	{
		alert("email地址长度不能超过30位!");
		return false;
	}
	
	pos1 = s.indexOf("@");
	pos2 = s.indexOf(".");
	pos3 = s.lastIndexOf("@");
	pos4 = s.lastIndexOf(".");
	//check '@' and '.' is not first or last character
	if ((pos1 <= 0)||(pos1 == len)||(pos2 <= 0)||(pos2 == len))  
	{
		alert("请输入有效的E-mail地址！");
		return false;
	}
	else
	{
		//check @. or .@
		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;
	}
	//is s contain invalid characters
	/*
	var badChar = "><,[]{}?/+=|\\'\":;!#$%^&()`"; 
	if ( isCharsInBag( s, badChar))
	{
		alert("请不要在email地址中输入字符 " + badChar + "\n" );
		alert("请重新输入" );
		return false;
	}
	*/
	return true;
}
function isTelNumber(s, item)
{

	//is s contain invalid characters
	var goodChar = "0123456789-*()"; 
   //Validate the user name
   if (isEmpty(s))
   {    alert("电话号码不能为空！");
		return false;
   }

   if ( !isCharsInBag( s, goodChar))
	{  
	    alert(item+"号码里只能有0123456789-*()！");
		return false;
	}
	//check user length 
	if ((s.length>12)||(s.length<6))
	{
		alert(item+"号码不能超过12位也不能少于6位！");
		return false;
	}
	return true;
}

function isMPNumber(s)
{
	//is s contain invalid characters
	var goodChar = "0123456789-*()"; 
   //Validate the user name
   if (!isEmpty(s)){
		if ( !isCharsInBag( s, goodChar)){  
			alert("移动电话号码里只能有0123456789-*()！");
			return false;
		}
		//check user length 
		if (s.length!=11){
			alert("移动电话号码位数不对！");
			return false;
		}
   }
   return true;
}

function isAddress(s)
{
   	// is s Empty?
   	if ( isEmpty(s) )
	{
		alert("联系地址不能为空，请重新输入！");	
		return false;
	}
	//is s contain invalid characters
	var badChar = "><,[]{}?/+=|\\'\":;~!@$%^&`"; 
	var len = s.length;
	var errorChar

   	errorChar = isCharsInBagEx( s, badChar)
   	if (errorChar != "" )
	{
	    alert("联系地址中不能含有字符 "+badChar + " !");
		return false;
	}
	//check user length 
	if ((len>100)||(len<5))
	{
		alert("联系地址不能超过50个汉字也不能少于五个汉字！");
		return false;
	}
	return true;
}

function isInt(s, item)
{
  if (isEmpty(s))
  {
	alert(item + "不能为空，请输入！");
	return false;
  }
      	
  var validChar = "0123456789"; 
  if (!isCharsInBag(s, validChar))
  {
	alert("您输入的" + item + s +"是无效的" + item + "，\n\n请输入合法的" + item + "！");
	return false;
  }

  return true;
}


 function isKeyword(s)
 {
 	var a, errorChar;
	var badChar = "><,[]{}?/+=|\\'\":;~!@#$%^&()`"; 
	// is s Empty?
   	if ( isEmpty(s) )
	{
		a = confirm("如果您不输入任何查询关键字，您可能会得到太多的查询结果。\n\n您确定要进行查询吗？");	
		if (a == false)
			return false;
	}
	else
	{
		//is s contain invalid characters
		//Validate the user name
		errorChar = isCharsInBagEx( s, badChar)
	    	if (errorChar != "" )
		{
			alert("请不要在查询关键字中输入字符" + errorChar + "\n\n请重新输入！" );
			return false;
		} 	
	}
	return true;
 }
 
 function isItemNum(s)
 {
 	if (isEmpty(s))
	{
		alert("请输入物品编号进行查询！");
 		return false;
	}
	var validChar = "0123456789"; 
	if (!isCharsInBag(s, validChar))
	{
		alert("您输入的物品编号" + s +"是无效的物品编号，\n\n请输入合法的物品编号！");
 		return false;
	}
	return true;		
 }
 
 function isUserName(s)
 {
 	var errorChar;
	var badChar = "><,[]{}?/+=|\\'\":;~!#$%()`"; 
 	if (isEmpty(s))
 	{
 		alert("请输入用户名！");
 		return false;
 	}

    if ((s.length<2)||(s.length>18))
    {
	   	alert("用户名长度为2-18位！");
 		return false;
    }
 	//is s contain whitespace
   	if ( isWhitespace(s) )
	{
		alert("输入的用户名中不能包含空格符，请重新输入！");	
		return false;
	}
	//is s contain invalid characters
	//Validate the user name
	errorChar = isCharsInBagEx( s, badChar)
    	if (errorChar != "" )
	{
		alert("您输入的用户名" + s+"是无效的用户名,\n\n请不要在用户名中输入字符" + errorChar + "!\n\n请重新输入合法的用户名！" );
		return false;
	} 	
	
	return true;
 }
 
 function isName(s)
 {
 	var errorChar;
	var badChar = "><,[]{}?/+=|\\'\":;~!#$%()`"; 
 	if (isEmpty(s))
 	{
 		alert("请输入姓名！");
 		return false;
 	}

    if ((s.length<=1)||(s.length>21))
    {
	   	alert("姓名长度要大于1位小于20位！");
 		return false;
    }
 	//is s contain whitespace
   	if ( isWhitespace(s) )
	{
		alert("输入的姓名中不能包含空格符，请重新输入！");	
		return false;
	}
	//is s contain invalid characters
	//Validate the user name
	errorChar = isCharsInBagEx( s, badChar)
    	if (errorChar != "" )
	{
		alert("您输入的姓名" + s+"是无效的姓名,\n\n请不要在姓名中输入字符" + errorChar + "!\n\n请重新输入合法的姓名！" );
		return false;
	} 	
	
	return true;
 }

function isSource(s)
{
   if (s=='选择')
   {
      alert("信息来源不能为空，请你选择");
      return false;
   }
   return true;
}

function isSex(s)
{
   if (s=='选')
   {
      alert("性别信息不能为空，请你选择");
      return false;
   }
   return true;
}


function isCity(s)
{
   if (s=='选择')
   {
      alert("城市信息不能为空，请你选择");
      return false;
   }
   return true;
}

function isPassword (s)
{
  if (isEmpty(s))
  {
	alert("密码不能为空，请输入！");
	return false;
  }
//is s contain whitespace
  if ( isWhitespace(s) )
  {
	alert("密码中不能包含空格符，请重新输入！");	
	return false;
  }

  if ((s.length>16)||(s.length<4))
  {
 	alert("口令不能超过16位也不能少于4位！");
	return false;
  }
  return true;
}


function isIntEx(s, item, len, bCompare)
{
  if (isEmpty(s))
  {
	alert(item + "不能为空，请输入！");
	return false;
  }
      	
  var validChar = "0123456789"; 
  if (!isCharsInBag(s, validChar))
  {
	alert("您输入的" + item + s +"是无效的" + item + "，\n\n请输入合法的" + item + "！");
	return false;
  }
  
  if (bCompare == "=") 
  {
    if (s.length != len)
    {
	alert("您输入的" + item + s +"是无效的" + item + "，\n\n必须等于" + len + "位！");
	return false;
    }
  }
  else if (bCompare == "<")
  {
    if (s.length >= len) 
    {
	alert("您输入的" + item + s +"是无效的" + item + "，\n\n必须小于" + len + "位！");
	return false;
    }
  }
    
  return true;
}

function isRealnumber(s,item)
{
    if (isEmpty(s))
  {
	alert(item + "不能为空，请输入！");
	return false;
  }
      	
  var validChar = "0123456789."; 
  if (!isCharsInBag(s, validChar))
  {
	alert("您输入的" + item + s +"是无效的" + item + "，\n\n请输入合法的" + item + "！");
	return false;
  }

 return true;
}
function isValidString(s, des)
{
 	var errorChar;
	var badChar = "><,[]{}?/+=|\\'\":;~!@#$%^&()`"; 
 	if (isEmpty(s))
 	{
 		alert("请输入"+ des +"！");
 		return false;
 	}
	//is s contain invalid characters
	//Validate the user name
	errorChar = isCharsInBagEx( s, badChar)
    	if (errorChar != "" )
	{
		alert("您输入的" + des +"是无效的"+des +",\n\n请不要在"+des+"中输入字符" + errorChar + "!\n\n请重新输入合法的"+des+"！" );
		return false;
	} 	
	
	return true;
 }
 
function isPrice(s, item)
{
  if (isEmpty(s))
  {
	alert(item + "不能为空，请输入！");
	return false;
  }
      	
  var validChar = "0123456789."; 
  if (!isCharsInBag(s, validChar))
  {
	alert("您输入的" + item + s +"是无效的" + item + "，\n\n请输入合法的" + item + "！");
	return false;
  }
  if (s.indexOf(".") == -1)
  	return true;
  	
  if (s.indexOf(".") != s.lastIndexOf("."))
  {
	alert("您输入的" + item + s +"是无效的" + item + "，\n\n请输入合法的" + item + "！");
	return false;
  }
  var opart = s.substr(s.indexOf(".")+1)
  if (parseInt(opart) != 0)
  {
	alert(item+"的最小单位是1元！");
	return false;
  }
  return true;
}

function checkContent(strInput,length,Item){
    if (isEmpty(strInput))
 	{
 		alert("您输入的"+Item+"为空！");
 		return false;
 	}
 	
    if (strInput.length > length) {
        alert("您输入的"+Item+"超过了"+length+"位");
      return false;
  }

   //ind2=isCharsInBagEx(strInput, "/");
   ind3=isCharsInBagEx(strInput, "<");
   ind4=isCharsInBagEx(strInput, ">");
   ind5=isCharsInBagEx(strInput, "'");
   if (ind3 || ind4 || ind5) {
      alert("请勿使用 <, >, '等特殊字符 ");
      return false;
  }
  return true;
} 

function NewWindow(url,windowName,width,height)
{ 
	var windowFeature="width="+width+",height="+height+",toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=1";
	var popup = window.open(url, windowName, windowFeature);
	popup.focus();
}

function AddToCart(quantity,pieceCode,action)
{
	if (!isInt(quantity,"数量")) 
	   return false;
	if (quantity=="0"){
		alert ("定购数量需要大于0");
		return false;
	}
	alert("您已经把商品号为"+pieceCode+"的商品添加进购物车了");
//	var strHref="mycart.asp?quantity="+quantity+"&piececode="+pieceCode+"&act="+action;
//	NewWindow('','cart',580,400);
}

 function isRightInput(s)
 {
 	var a, errorChar;
	var badChar = "><,[]{}?/+=|\\'\":;~!@$%^&()`"; 
	// is s Empty?
		//is s contain invalid characters
		//Validate the user name
		errorChar = isCharsInBagEx( s, badChar)
	    	if (errorChar != "" )
		{
			alert("请不要输入字符" + errorChar + "\n\n请重新输入！" );
			return false;
		} 	

	return true;
 }

function CheckLogin(WhichForm){
	if (WhichForm.usercode.value==""){
		alert("请输入用户名");
		WhichForm.usercode.focus();
		return false;
	}
	if (WhichForm.password.value==""){
		alert("请输入密码");
		WhichForm.password.focus();
		return false;
	}
	return true;
}

/*
'---------------------------本文件说明------------------------------------------------------------
' Projectname: DisplayPageCount
' Filename: DisplayPageCount
' File version: v1.0
' Author : Little Yu
' Start date: 2000-5-28
' LastEdit date : 2005-1-1
' Purpose :  
' Include file : no
' Input parameters :
'		CurrentPage-----------
'		TotalPage-------------
'		StrUrl--------
' -------------------------------文件说明结束--------------------------------------------------
*/
function DisplayPageCount(CurrentPage,TotalPage,StrUrl){
	var i ;
	var strHref ;
	if (StrUrl.indexOf("?")<0)
		strHref="?Page=" ;
	else
		strHref = StrUrl + "&Page=" ;
	if (CurrentPage<1) CurrentPage=1;
	if (CurrentPage>TotalPage) CurrentPage=TotalPage;
	if (CurrentPage > 1){
		document.write ("<a href='" + strHref + "1'><font face='webdings' title='首页'>9</font></a>&nbsp;");
		document.write ("<a href='" + strHref + (TotalPage-1) +"'><font face='webdings' title='上页'>7</font></a>&nbsp;");
	}
	else{
		document.write ("<font face='webdings' title='首页'>9</font>&nbsp;") ;
		document.write ("<font face='webdings' title='上页'>7</font>&nbsp;") ;
	}

	if (TotalPage <= 15){
		for (i=1; i<=TotalPage; i++){
			if (i!=CurrentPage) document.write ("<a href='" + strHref + i + "'>"+i+"</a>&nbsp;")
			else document.write ("["+i+"]&nbsp;") ;
		}

	}
	else{
		if (CurrentPage<9){
			for (i=1; i<=15; i++){
			if (i!=CurrentPage) document.write ("<a href='"+strHref+i+"'>"+i+"</a>&nbsp;");
			else document.write ("["+i+"]&nbsp;");
			}
			document.write ("... ");
		}
		if (CurrentPage>TotalPage-8){
			document.write ("... ");
			for (i=TotalPage-15;i<=TotalPage;i++){
			if (i!=CurrentPage) document.write ("<a href='"+strHref+i+"'>"+i+"</a>&nbsp;");
			else document.write ("["+i+"]&nbsp;");
			}
		}

		if (CurrentPage-7>0 && CurrentPage+7<TotalPage && CurrentPage>8 && CurrentPage<TotalPage-7){
			document.write ("... ");
			for (i=CurrentPage-7;i<=CurrentPage+7;i++){
			if (i!=CurrentPage) document.write ("<a href='"+strHref+i+"'>"+i+"</a>&nbsp;");
			else document.write ("["+i+"]&nbsp;");
			}
			document.write ("... ");
		}
	}
	if (CurrentPage<TotalPage){
		document.write ("<a href='"+ strHref + (CurrentPage+1) +"'><font face='webdings' title='下页'>8</font></a>");
		document.write ("<a href='"+ strHref + (TotalPage) +"'><font face='webdings' title='未页'>:</font></a>");
	}
	if (TotalPage>0) document.write ("&nbsp;<font color='Red'>"+ CurrentPage+"</font>/"+TotalPage+"");
}

function checkEmail(emailStr)
{
	var re = /^(([^()<>@,;:\\\"".[\]\ ]+)|(\""[^\r\""]+\""))((\.[^()<>@,;:\\\"".[\]\ ]+)|(\.\""[^\r\""]+\""))*@((([a-zA-Z0-9\-]+\.)*([a-zA-Z0-9][a-zA-Z0-9\-]+)*[a-zA-Z0-9]+\.[a-zA-Z]{2,})|(\[(25[0-4]|2[0-4]\d|1\d{2}|[1-9]\d?)(\.(25[0-4]|2[0-4]\d|1\d{2}|[1-9]\d|\d)){2}(\.(25[0-4]|2[0-4]\d|1\d{2}|[1-9]\d?)))\])$/
	if (!re.test(emailStr)){
		alert("Email address format is not valid.")
		
	}
	return re.test(emailStr);
}
//-->

