//函数名：chksafe
//功能介绍：检查是否含有"'",'\\',"/"
//参数说明：要检查的字符串
//返回值：0：是  1：不是
function chksafe(a)
{
	var temp1,temp2
        fibdn = new Array ("'" ,"\\", ",", ";", "/", "&quot;", "%", "|");
	m=fibdn.length;
	n=a.length;
	for (ii=0;ii<m;ii++)
	{	for (jj=0;jj<n;jj++)
		{	temp1=a.charAt(jj);
			temp2=fibdn[ii];
			if (temp1==temp2)
			{	return 0; }
		}
	}
	return 1;

}

//函数名：chkemail
//功能介绍：检查是否为Email Address
//参数说明：要检查的字符串
//返回值：0：不是  1：是
function chkemail(a)
{	var i=a.length;
	var temp = a.indexOf('@');
	var tempd = a.indexOf('.');
	if (temp > 1) {
		if ((i-temp) > 3){

				if ((i-tempd)>0){
					return 1;
				}

		}
	}
	return 0;
}

//函数名：fucPWDchk
//功能介绍：检查是否含有非数字或字母
//参数说明：要检查的字符串
//返回值：0：含有 1：全部为数字或字母
function fucPWDchk(str)
{
  var strSource ="0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_";
  var ch;
  var i;
  var temp;

  for (i=0;i<=(str.length-1);i++)
  {

    ch = str.charAt(i);
    temp = strSource.indexOf(ch);
    if (temp==-1)
    {
     return 0;
    }
  }
  if (strSource.indexOf(ch)==-1)
  {
    return 0;
  }
  else
  {
    return 1;
  }
}

//函数名：fucCheckNUM
//功能介绍：检查是否为数字
//参数说明：要检查的数字
//返回值：1为是数字，0为不是数字
function fucCheckNUM(NUM)
{
	var i,j,strTemp;
	strTemp="0123456789.";
	if ( NUM.length== 0)
		return 0
	for (i=0;i<NUM.length;i++)
	{
		j=strTemp.indexOf(NUM.charAt(i));
		if (j==-1)
		{
		//说明有字符不是数字
			return 0;
		}
	}
	//说明是数字
	return 1;
}

//函数名：chkspc
//功能介绍：检查是否含有空格
//参数说明：要检查的字符串
//返回值：0：是  1：不是
function chkspc(a)
{
	var i=a.length;
	var j = 0;
	var k = 0;
	while (k<i)
	{
		if (a.charAt(k) != " ")
			j = j+1;
		k = k+1;
	}
	if (j==0)
	{
		return 0;
	}

	if (i!=j)
	{ return 2; }
	else
	{
		return 1;
	}
}

//函数名：fucCheckTEL
//功能介绍：检查是否为电话号码
//参数说明：要检查的字符串
//返回值：1为是合法，0为不合法
function fucCheckTEL(TEL)
{
	var i,j,strTemp;
	strTemp="0123456789-()（）#转";
	for (i=0;i<TEL.length;i++)
	{
		j=strTemp.indexOf(TEL.charAt(i));
		if (j==-1)
		{
		//说明有字符不合法
			return 0;
		}
	}
	//说明合法
	return 1;
}

//函数名：fucCheckLength
//功能介绍：检查字符串的长度
//参数说明：要检查的字符串
//返回值：长度值
function fucCheckLength(strTemp)
{
	var i,sum;
	sum=0;
	for(i=0;i<strTemp.length;i++)
	{
		if ((strTemp.charCodeAt(i)>=0) && (strTemp.charCodeAt(i)<=255))
			sum=sum+1;
		else
			sum=sum+2;
	}
	return sum;
}

//函数名：Search_onsubmit
//功能介绍：检查通用搜索框的输入
function Search_onsubmit(b)
{
   if(b.myKeyword.value=="多个关键词可用空格分开，提高搜索命中率")
   {
	   alert("请填写要搜索的书籍名称。");
		b.myKeyword.value="";
		b.myKeyword.focus();
		//document.getElementById("myKeyword").value="";
		//document.getElementById("myKeyword").focus();
		return false;
	}else{
	   if(chksafe(b.myKeyword.value)==0||fucCheckLength(b.myKeyword.value)==0)
		{
			alert("请正确填写要搜索的书籍名称。");
			b.myKeyword.focus();
			return false;
		}
	}
}
function Search3721_onsubmit(a)
{
   if(a.word.value=="多个关键词可用空格分开，提高搜索命中率")
   {
	   alert("请填写要搜索的书籍名称。");
		a.word.value="";
		a.word.focus();
		return false;
	}else{
	   if(chksafe(a.word.value)==0||fucCheckLength(a.word.value)==0)
		{
			alert("请正确填写要搜索的书籍名称。");
			a.word.focus();
			return false;
		}
	}
}



function opennew(newurl,windowName,width,height)
{
var theLeft,theTop
theLeft=(screen.width-width)/2-2
theTop=(screen.height-height)/2
window.open(newurl,windowName,'width='+width+',height='+height+',scrollbars=1,status=0,toolbar=0,resizable=0,left='+theLeft+',top='+theTop+'').focus();
//return true;
}
function opennewfull(newurl,windowName)
{
window.open(newurl,windowName,'width='+screen.width+',height='+(screen.height-55)+',scrollbars=1,toolbar=0,resizable=0,left=0,top=0').focus();
}

function openModal(newUrl,windowName,width,height,controlName){
controlName.value=showModalDialog(newUrl,windowName,"dialogWidth:"+width+";dialogHeight:"+height+";center:1")
}

function openScript(url, width, height){
	var Win = window.open(url,"openScript",'width=' + width + ',height=' + height + ',resizable=1,scrollbars=yes,menubar=no,status=yes' );
}


function onChange(i){
childSort=document.all("child" + i);
//theTd=document.all("td" + i);
	if(childSort.style.display=="none"){
//		theTd.bgcolor="#ffffff";
		childSort.style.display="";}
	else{
//		theTd.bgcolor="#000000";
		childSort.style.display="none";}
}


function textCounter(field, countfield, maxlimit) {
	if (field.value.length > maxlimit) {
		//field.value = field.value.substring(0, maxlimit);
		countfield.value = maxlimit - field.value.length;
	} else {
		countfield.value = maxlimit - field.value.length;
	}
}

function isPhone(item) { 
	var s = item.value;
	var patrn=/^01[3,5]{1}\d{9}$/;
	if(patrn.exec(s)!=null) {
	  //alert("电话号码不允许输入手机号码,请仔细核对！");
	}
	if(isMobil(item))return false;
	patrn=/^0\d{10,11}$/;
	if (patrn.exec(s) == null) {
		//alert("电话号码填写不正确！");
		item.focus();
		return false;
	} 
	return true ;
}
//校验普通电话、传真号码：可以“+”开头，除数字外，可含有“-” 
function isTel(s) 
{ 
//var patrn=/^[+]{0,1}(\d){1,3}[ ]?([-]?(\d){1,12})+$/; 
var patrn=/^[+]{0,1}(\d){1,3}[ ]?([-]?((\d)|[ ]){1,12})+$/; 
if (!patrn.exec(s)) return false 
return true 
}   
  
  
//判断手机号是否正确
function isMobil(item) {   
var s = item.value;
var patrn=/^01[3,5]{1}\d{9}$/;
if (patrn.exec(s) == null) {
	//alert("手机号码填写不正确！");
	item.focus();
	return false;
} 
return true ;
}
//校验手机号码：必须以数字开头，除数字外，可含有“-” 
function isMobil2(s) 
{ 
var patrn=/^[+]{0,1}(\d){1,3}[ ]?([-]?((\d)|[ ]){1,12})+$/; 
if (!patrn.exec(s)) return false 
return true 
}     
    
    
    
//判断IP是否正确    
function isIP(item){
      var s = item.value;
      var patrn = /^[1,2]{1}\d{0,3}\.[1,2]{1}\d{0,3}\.[1,2]{1}\d{0,3}\.[1,2]{1}\d{0,3}$/;	
      if (patrn.exec(s) == null) {
         //alert("IP地址填写不正确！");
         item.focus();
         return false;
       } 
    	return true ;
}
function isIP2(s) //by zergling 
{ 
var patrn=/^[0-9.]{1,20}$/; 
if (!patrn.exec(s)) return false 
return true 
}


//校验密码：只能输入6-15个字母、数字、下划线 
function isPasswd(s) 
{ 
var patrn=/^(\w){6,15}$/; 
if (!patrn.exec(s)) return false 
return true 
} 

//校验邮政编码 
function isPostalCode(s) 
{ 
//var patrn=/^[0-9]{6}$/; 
var patrn=/^[0-9]{6}$/; 
if (!patrn.exec(s)) return false 
return true 
} 

//校验搜索关键字 
function isSearch(s) 
{ 
var patrn=/^[^`~!@#$%^&*()+=|\\\][\]\{\}:;'\,.<>/?]{1}[^`~!@$%^&()+=|\\\][\]\{\}:;'\,.<>?]{0,19}$/; 
if (!patrn.exec(s)) return false 
return true 
} 



//建立XMLHTTP对象  
function InitAjax()
{
　var ajax=false;
　try {
　　ajax = new ActiveXObject("Msxml2.XMLHTTP");
　} catch (e) {
　　try {
　　　ajax = new ActiveXObject("Microsoft.XMLHTTP");
　　} catch (E) {
　　　ajax = false;
　　}
　}
　if (!ajax && typeof XMLHttpRequest!='undefined') {
　　ajax = new XMLHttpRequest();
　}
　return ajax;
}

//输入拼音自动选择pub_id出版社
var   sel="",timer=null,re="";
function   spellList(){
	with(window.event){
		  with(srcElement){
				  if(keyCode<48&&keyCode!=8)return;
				  if(keyCode>95&&keyCode<106)keyCode-=48
				  if(keyCode==8)sel=sel.slice(0,-1)
				  else   sel+=String.fromCharCode(keyCode)
				  window.status=sel
				  for(i=0;i<length;i++){
				  if(document.getElementById("pub_id").options[i].spell.toUpperCase().indexOf(sel)==0){selectedIndex=i;break;}
				  }
		  }
		  returnValue=false;
		  clearTimeout(timer)
		  timer=setTimeout("sel=''",3000);
	}
}

//输入拼音自动选择tradeuserid供货商
var   sel="",timer=null,re="";
function   spellList_tradeuserid(){
	with(window.event){
		  with(srcElement){
				  if(keyCode<48&&keyCode!=8)return;
				  if(keyCode>95&&keyCode<106)keyCode-=48
				  if(keyCode==8)sel=sel.slice(0,-1)
				  else   sel+=String.fromCharCode(keyCode)
				  window.status=sel
				  for(i=0;i<length;i++){
				  if(document.getElementById("tradeuserid").options[i].spell.toUpperCase().indexOf(sel)==0){selectedIndex=i;break;}
				  }
		  }
		  returnValue=false;
		  clearTimeout(timer)
		  timer=setTimeout("sel=''",3000);
	}
}
