//函数名：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;
	}
}



//========ecall================
var dOpa = "50";
var offHeight;

function ecall_login(){
	offHeight = window.screen.height;
	var div = document.createElement("DIV");
	div.id = "errMsg";
	div.style.left = 0;
	div.style.top = 0;
	div.style.width=document.body.scrollWidth;
	div.style.height = document.body.scrollHeight;
	div.style.position = "absolute";
	div.style.display = "";
	div.style.zIndex = "999";
	div.style.filter = "progid:DXImageTransform.Microsoft.Alpha(Opacity=50)";
	div.style.backgroundColor="#2A4A6B";
	document.body.appendChild(div);
	focusDiv();
	
}

function focusDiv(){
	var loginDiv = document.getElementById("loginForm");
	//alert(document.body.scrollTop+document.body.clientHeight/3*2);
	loginDiv.style.left = (document.body.offsetWidth-410)/2;
	loginDiv.style.top = document.body.scrollTop+document.body.clientHeight/3*2;
	//loginDiv.style.top = 100;
	loginDiv.style.display = "block";
	
}

window.onload = function(){
	var div = document.createElement("DIV");
	div.id = "loginForm";
	div.style.position = "absolute";
	div.style.zIndex="1000";
	div.style.height = "364px";
	div.style.display = "none";
	div.innerHTML = getHtml();
	document.body.appendChild(div);
}

function getHtmls(){
	var sHtml = "";
	sHtml += '<a href="javascript:hiddenFlashLoginWindow()">1??à??????¨2</a>';
	return sHtml;
}
function getHtml(){
	var sHtml = "";
	//sHtml += '<div id="loginForm" style="position:absolute; height: 364px;border:1px #666 solid; background-color:#666666;display:none">';
	sHtml += '<table width="508" border="0" cellspacing="0" cellpadding="0">';
    sHtml += '<tr>';
      sHtml += '<td colspan="3"><object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" width="508" height="13">';
       sHtml += ' <param name="movie" value="http://www.book3721.cn/ecall/images/top.swf">';
        sHtml += '<param name="quality" value="high">';
	sHtml += '<param name="wmode" value="transparent"/>';
       sHtml += ' <embed src="http://www.book3721.cn/ecall/images/top.swf" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="508" height="13"></embed>';
      sHtml += '</object></td>';
   sHtml += ' </tr>';
    sHtml += '<tr>';
     sHtml += ' <td><object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" width="13" height="332">';
       sHtml += ' <param name="movie" value="http://www.book3721.cn/ecall/images/left.swf">';
       sHtml += ' <param name="quality" value="high">';
	sHtml += '<param name="wmode" value="transparent"/>';
       sHtml += ' <embed src="http://www.book3721.cn/ecall/images/left.swf" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="13" height="332"></embed>';
      sHtml += '</object></td>';
      sHtml += '<td width="480" height="332" background="http://www.book3721.cn/ecall/images/11021.jpg"><table width="100%" height="100%"  border="0" cellpadding="0" cellspacing="0">';
         sHtml += ' <tr>';
           sHtml += ' <td height="30">&nbsp;</td>';
            sHtml += '<td>&nbsp;</td>';
            sHtml += '<td align="right"><table width="20"  border="0" cellspacing="0" cellpadding="0">';
             sHtml += ' <tr>';
               sHtml += ' <td align="right"><img src="http://www.book3721.cn/ecall/images/11025.gif" width="17" height="17" style="cursor:hand;" onclick="hiddenFlashLoginWindow();"></td>';
              sHtml += '</tr>';
            sHtml += '</table></td>';
            sHtml += '<td>&nbsp;</td>';
          sHtml += '</tr>';
          sHtml += '<tr>';
            sHtml += '<td width="50" height="90">&nbsp;</td>';
           sHtml += ' <td>&nbsp;</td>';
           sHtml += ' <td>&nbsp;</td>';
           sHtml += ' <td>&nbsp;</td>';
          sHtml += '</tr><form id="frmcall" name="frmcall">';
          sHtml += '<tr>';
            sHtml += '<td height="25">&nbsp;</td>';
            sHtml += '<td width="100">您的联系电话：</td>';
           sHtml += ' <td align="left"><input name="userNum" id="userNum" type="text" maxlength="17"></td>';
            sHtml += '<td>&nbsp;</td>';
          sHtml += '</tr>';
         sHtml += ' <tr>';
            sHtml += '<td rowspan="3">&nbsp;</td>';
            sHtml += '<td height="15" colspan="2"></td>';
            sHtml += '<td rowspan="3">&nbsp;</td>';
          sHtml += '</tr>';
          sHtml += '<tr>';
            sHtml += '<td height="25" colspan="2" valign="top"><table width="100%"  border="0" cellspacing="0" cellpadding="0" height="25">';
            sHtml += '  <tr>';
             sHtml += ' <td valign="top"><INPUT style="BACKGROUND: url(http://www.book3721.cn/ecall/images/11022.gif) no-repeat; WIDTH: 78px;HEIGHT: 30px;BORDER-STYLE: none;cursor:hand;" id=btn onclick="javascript:ecall_callNow();" type=button name=btn>&nbsp;&nbsp;<INPUT style="BACKGROUND: url(http://www.book3721.cn/ecall/images/11023.gif) no-repeat; WIDTH: 78px;HEIGHT: 30px;BORDER-STYLE: none;cursor:hand;" id=hlp onclick="javascript:hiddenFlashLoginWindow();" type=button name=hlp>&nbsp;&nbsp;<a href="http://www.book3721.cn/ecall/minihl.html" target=_blank><img src=http://www.book3721.cn/ecall/images/11024.gif border=0></a></td>';
            sHtml += ' </tr></form>';
	     sHtml += ' <tr>';
             sHtml += ' <td align="center" height="5"></td>';
             sHtml += ' <td>&nbsp;</td>';
           sHtml += ' </tr>';
            sHtml += '</table></td>';
         sHtml += ' </tr>';
          sHtml += '<tr>';
           sHtml += ' <td colspan="2" valign="top" align="left"  height="90"><span name="ecall_msg" id="ecall_msg" style="color:red">温馨说明：<br>&nbsp;&nbsp;&nbsp;&nbsp;输入您的电话（手机号码前加0[西安地区除外]，固定电话输入格式为区号+号码，例如02986698966），我们的客服系统会立即回拨，免去您的电话费，详情请点“说明”。</span></td>';
         sHtml += ' </tr>';
     sHtml += ' </table></td>';
     sHtml += ' <td><object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" width="15" height="332">';
       sHtml += ' <param name="movie" value="http://www.book3721.cn/ecall/images/right.swf">';
      sHtml += '  <param name="quality" value="high">';
		sHtml += '<param name="wmode" value="transparent"/>';
      sHtml += '  <embed src="http://www.book3721.cn/ecall/images/right.swf" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="15" height="332"></embed>';
     sHtml += ' </object></td>';
    sHtml += '</tr>';
    sHtml += '<tr>';
      sHtml += '<td colspan="3"><object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" width="508" height="16">';
      sHtml += '  <param name="movie" value="http://www.book3721.cn/ecall/images/bottom.swf">';
      sHtml += '  <param name="quality" value="high">';
		sHtml += '<param name="wmode" value="transparent"/>';
       sHtml += ' <embed src="http://www.book3721.cn/ecall/images/bottom.swf" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="508" height="16"></embed>';
     sHtml += ' </object></td>';
   sHtml += ' </tr>';
  sHtml += '</table>';
  // sHtml += '</div>';
	return sHtml;
}

//隐藏flash免费电话框
function hiddenFlashLoginWindow()
{
	    //设置flash的那个层为隐藏
	document.all.userNum.value = "";
	//document.getElementById("ecall_Msg").innerHTML = "温馨说明：<br>&nbsp;&nbsp;&nbsp;&nbsp;输入您的电话（手机号码前加0[西安地区除外]，固定电话输入格式为区号+号码，例如02986698966），免去您的电话费，详情请点“说明”。";
	var aa = document.getElementById("loginForm");
	var bb = document.getElementById("errMsg");
	function setDivToNone(){
		aa.style.display = "none";
		document.body.removeChild(bb);
	}
	setDivToNone();
}

function ecall_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;
}

function ecall_exeData()
{
　
　//获取表单对象和用户信息值
　var url = "/execute.asp";
　var postStr = "userNum="+ document.getElementById("userNum").value;
　var ajax = ecall_InitAjax();
　ajax.open("POST", url, true);
　ajax.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
　ajax.send(postStr);　
　ajax.onreadystatechange = function() 
　{
　　if (ajax.readyState == 4 && ajax.status == 200)
　　{
　　　document.getElementById("ecall_Msg").innerHTML = ajax.responseText;
　　　setTimeout("hiddenFlashLoginWindow();",3000);
　　}
　}
}

function ecall_callNow()
{
	if(ecall_valiNum())
	{
		//document.getElementById("frmcall").submit();
		ecall_exeData();
	}
	else
	{
		alert("呼叫失败，请重新呼叫！");
		document.getElementById("userNum").focus();
		return false;
	}
}

function ecall_valiNum()
{
	var txtInput = document.getElementById("userNum");
	var strVali = /(^0{0,1}13[0-9]{9}$)|(^0{0,1}15[8,9]{1}[0-9]{8}$)/;
	if(txtInput.value.length >= 7 || strVali.test(txtInput.value))
	{
		return true;
	}
	else
	{
		alert("请根据以下要求检查您的输入：\n1)手机号码前加0（西安地区除外）。\n2)固定电话输入格式：区号+电话号码(如02986698966)");
		return false;
	}
}
//=========ecall=================


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;
}