// JavaScript Document

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

//去掉字符串头部和尾部的空格
String.prototype.trim=function()
{
    //   用正则表达式将前后空格   
    //   用空字符串替代。   
    return this.replace(/(^\s*)|(\s*$)/g,"");   
}

//判断是否IE浏览器
function isIE(){ //ie?
   if (window.navigator.userAgent.toLowerCase().indexOf("msie")>=1)
    return true;
   else
    return false;
}

//innerText的firefox修正
if(!isIE()){ //firefox innerText define
   HTMLElement.prototype.__defineGetter__(     "innerText",
    function(){
     var anyString = "";
     var childS = this.childNodes;
     for(var i=0; i<childS.length; i++) {
      if(childS[i].nodeType==1)
       anyString += childS[i].tagName=="BR" ? '\n' : childS[i].innerText;
      else if(childS[i].nodeType==3)
       anyString += childS[i].nodeValue;
     }
     return anyString;
    }
   );
   HTMLElement.prototype.__defineSetter__(     "innerText",
    function(sText){
     this.textContent=sText;
    }
   );
}

//首页鼠标上移显示案例层
function ShowCase(n,v){
	//循环隐藏所有层
	for(i=0;i<20;i++)
	{
		str="";
		div="";
		
		if(n.indexOf("case")>-1&&v.indexOf("div")>-1)
		{
			str="case"+i;
			div="div"+i;
		}
		else
		{			
			str="shop"+i;
			div="ds"+i;
		}
		tempObj=MM_findObj(str);
		tempObj1=MM_findObj(div);
		
		if(tempObj!=null&&tempObj1!=null)
		{
			if(i==0)
			{
				tempObj.className="RecommendedCase";
			}
			else
			{
				tempObj.className="CaseAgo";
			}
			tempObj1.style.display="none";
		}
	}
	
	//显示选中层
	if(n.indexOf("0")>-1)
	{
		MM_findObj(n).className="RecommendedCase_on";
	}
	else
	{
		MM_findObj(n).className="CaseAfter";
	}
	MM_findObj(v).style.display="block";
}

//重新获取验证码
function changeCode(objName)
{
	var obj=MM_findObj(objName);
	if(obj!=null)
	{
		var d = new Date();
		obj.src="code.asp?s="+d.getTime();
	}
}

//判断email格式是否正确
function checkEmail(strEmail)
{
	if(strEmail.value.trim().indexOf('@')=="-1"||strEmail.value.trim().indexOf('.')=="-1")
	{
		return false;
	}
	else
		return true;
}

//检查后台用户登录表单
function checkLogin(theform)
{
	if(theform.username.value=="")
	{
		alert("请填写用户名！");
		theform.username.focus();
		return false;
	}
	if(theform.password.value=="")
	{
		alert("请填写密码！");
		theform.password.focus();
		return false;
	}
	if(theform.code.value=="")
	{
		alert("请填写验证码！");
		theform.code.focus();
		return false;
	}
}

var tempCurrpage = "1";

//跳转到第几页
function gotoPage(strURL, strPage, intMaxPage) {
    var intPage = 1;

    intPage = parseInt(strPage);
    
    if (intPage < 1)
        intPage = 1;
    if (intPage > intMaxPage)
        intPage = intMaxPage;

    if (tempCurrpage != strPage)
        window.location.href = strURL.replace('{page}', intPage + "");
}

function checkBookAdd(theform)
{
	if(theform.GuestName.value=="")
	{
		alert("请输入您的称呼！");
		theform.GuestName.focus();
		return false;
	}
	if(theform.E_Mail.value!="")
	{
		if(theform.E_Mail.value.indexOf('@')=="-1"||theform.E_Mail.value.indexOf('.')=="-1")
		{
			alert("您的E_MAIL格式输入错误！");
			theform.E_Mail.focus();
			return false;
		}
	}
	if(theform.Tel.value=="")
	{
		alert("请输入手机或电话！");
		theform.Tel.focus();
		return false;
	}
	if(theform.Question.value=="")
	{
		alert("请输入留言内容");
		theform.Question.focus();
		return false;
	}
	if(theform.code.value=="")
	{
		alert("请输入验证码！");
		theform.code.focus();
		return false;
	}
}
