function KillSpace(x){
while((x.length>0) && (x.charAt(0)==' '))
x = x.substring(1,x.length)
while((x.length>0) && (x.charAt(x.length-1)==' '))
x = x.substring(0,x.length-1)
return x
}
function check_mail(myint)
{
 var checkOk="@";
 var checkStr=myint;
 var allValid=true;
 var decPoints=0;
 var allNum="";
 if(checkStr.charAt(0)=='@')
 return(false);
 if(checkStr.charAt(checkStr.length-1)=='@')
 return(false);
 if(checkStr.charAt(checkStr.length-1)=='.')
 return(false);
 a_valid=0;
 a_count=0;
 d_valid=0;
 for(i=0;i<checkStr.length;i++)
 {
  ch=checkStr.charAt(i);
  if(ch=='@')
  {a_valid=1;a_count++;}
  if(ch=='.')
  {d_valid=1;}
 }
 if(a_count>1)
 return(false);
 if(a_valid==1&&d_valid==1)
 return(true);
 else return(false);
 }
function checkfrm()
{
	var errorMsg = "";
	var errorMsgLong = "";
	document.Guestbook.username.value=KillSpace(document.Guestbook.username.value);
	document.Guestbook.phone.value=KillSpace(document.Guestbook.phone.value);
	document.Guestbook.mobile.value=KillSpace(document.Guestbook.mobile.value);
	document.Guestbook.address.value=KillSpace(document.Guestbook.address.value);
	document.Guestbook.zipcode.value=KillSpace(document.Guestbook.zipcode.value);
	document.Guestbook.content.value=KillSpace(document.Guestbook.content.value);
	document.Guestbook.email.value=KillSpace(document.Guestbook.email.value);
	if (document.Guestbook.username.value.length < 1){
		alert('联系人姓名不能为?);
		document.Guestbook.username.focus();
		return  false;
	}

	if (document.Guestbook.phone.value.length < 1){
		alert('电话不能为空');
		document.Guestbook.phone.focus();
		return  false;
	}
	 else{
		  var Letters = "0123456789()+-１２３４５６７８９０";
		  for (i=0; i< document.Guestbook.phone.value.length; i++){
			 var CheckChar = document.Guestbook.phone.value.charAt(i);
			 if (Letters.indexOf(CheckChar) == -1){
			   alert('电话号码输入错误');
		       document.Guestbook.phone.focus();
		       return  false;
			  }
			}
		  }	
	if(KillSpace(document.Guestbook.phone.value)=="13750252790" || KillSpace(document.Guestbook.mobile.value)=="13750252790") {
		return false;
		}
	if ((0< document.Guestbook.mobile.value.length &&document.Guestbook.mobile.value.length < 11)||(document.Guestbook.mobile.value.length >11)){
		alert('请输入正确的手机号码');
		document.Guestbook.mobile.focus();
		return  false;
	}
	if (document.Guestbook.email.value.length>0)
    {if (!check_mail(document.Guestbook.email.value)) 
	 { alert(' 请输入正确的email地址');
		document.Guestbook.email.focus();
		return  false;
	 }
	}
	if (document.Guestbook.address.value.length < 1){
		alert('地址不能为空');
		document.Guestbook.address.focus();
		return  false; 
	}	
	if (document.Guestbook.zipcode.value.length < 1){
		alert(' 邮编不能为空');
		document.Guestbook.zipcode.focus();
		return  false; 
	    }
	else{
	if (document.Guestbook.zipcode.value.length!=6){
		alert('请输入正确的邮编');
		document.Guestbook.zipcode.focus();
		return  false;
		
	}
	var Letters = "0123456789１２３４５６７８９０";
	for (i=0; i< document.Guestbook.zipcode.value.length; i++){
		var CheckChar = document.Guestbook.zipcode.value.charAt(i);
		if (Letters.indexOf(CheckChar) == -1){
			alert('请输入正确的邮编');
			document.Guestbook.zipcode.focus();
			return false;
		  }
		}
	}
	if (document.Guestbook.content.value.length < 7){
		alert('请详细填写你所关心的项目内?);
		document.Guestbook.content.focus();
		return false;
	}
	return true;
}


function getCookieVal (offset) 
{
var endstr = document.cookie.indexOf (";", offset);
if (endstr == -1)
endstr = document.cookie.length;
return unescape(document.cookie.substring(offset, endstr));
}

function GetCookie (name) 
{
var arg = name + "=";
var alen = arg.length;
var clen = document.cookie.length;
var i = 0;
while (i < clen) 
{
var j = i + alen;
if (document.cookie.substring(i, j) == arg)
return getCookieVal (j);
i = document.cookie.indexOf(" ", i) + 1;
if (i == 0) 
break; 
}
return "";
}

function SetCookie (name, value) 
{
var argv = SetCookie.arguments;
var argc = SetCookie.arguments.length;
var expires = (2 < argc) ? argv[2] : null;
var path = (3 < argc) ? argv[3] : null;
var domain = (4 < argc) ? argv[4] : null;
var secure = (5 < argc) ? argv[5] : false;
document.cookie = name + "=" + escape (value) +
((expires == null) ? "" : ("; expires=" + expires.toGMTString())) +
((path == null) ? "" : ("; path=" + path)) +
((domain == null) ? "" : ("; domain=" + domain)) +
((secure == true) ? "; secure" : "");
}
var expdate = new Date();
expdate.setTime(expdate.getTime() + (24 * 60 * 60 * 1000 * 1)); 

function menuControl()
{
window.event.cancelBubble=true;
var objID=event.srcElement.id;
var index=objID.indexOf("_");
var mainID=objID.substring(0,index);
var numID=Math.floor(Math.random()*3)+1;
eval("showMenu("+"menu_"+numID+")");
SetCookie("gbook1", numID, expdate, "/", null, false);
}

function menuControl2()
{
window.event.cancelBubble=true;
var objID=event.srcElement.id;
var index=objID.indexOf("_");
var mainID=objID.substring(0,index);
gbook = GetCookie("gbook1");
eval("hideMenu("+"menu_"+gbook+")");
}

var nbottom=0,speed=7;
function displayMenu(obj)
{
obj.style.clip="rect(0 100% "+nbottom+"% 0)";
nbottom+=speed;
if(nbottom<=100) 
{
timerID=setTimeout("displayMenu("+obj.id+"),70");
}
else clearTimeout(timerID);
}

function showMenu(obj)
{
obj.style.display="block";
obj.style.clip="rect(0 0 0 0)";
nbottom=5;
displayMenu(obj);
}

function hideMenu(obj)
{
nbottom=0;
obj.style.display="none";
}

function keepMenu(obj)
{
obj.style.display="block";
}

function sel(theinput)
{
  if(document.Guestbook.content.value!="")
     document.Guestbook.content.value+="\n"+theinput
  else
	 document.Guestbook.content.value=theinput
}

//表单判断
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));
}

