<!--
//取cookie函数
function $GetCookie(name){    
 var arr=document.cookie.match(new RegExp("(^| )"+name+"=([^;]*)(;|$)"));   
 if(arr != null) return unescape(arr[2]); return null;   
}; 
//设置cookie，seconds表示多少秒后过期 
function $SetCookie(name,value,seconds){    
 var exp=new Date();   
 exp.setTime(exp.getTime()+seconds*1000);   
 document.cookie=name+"="+escape(value)+";path=/;expires="+exp.toGMTString();   
}; 
    
//下拉菜单
function menu_action(sender) {
   var lis = sender.getElementsByTagName("li");
   for (key in lis) {
    lis[key].onmouseover=onMouseOver;
    lis[key].onMouseDown=onMouseDown;
    lis[key].onMouseUp=onMouseUp;
    lis[key].onmouseout=onMouseOut;
   }
   sender.onmouseover = null;
}
function onMouseOver(){OnMouse(this,"block")}
function onMouseDown(){OnMouse(this,"block")}
function onMouseUp(){OnMouse(this,"none")}
function onMouseOut(){OnMouse(this,"none")}
function OnMouse(Obj,Display){
   var ul = Obj.getElementsByTagName("ul")[0];
   if(ul!=null){
    ul.style.display=Display;
   }
}

function openpic(cats,imgs,url){
    var cat=document.getElementById(cats);
	var img=document.getElementById(imgs);
	if(cat.style.display=="none"){
	cat.style.display="";
	img.src=url+"images/class2.gif";
	}	else {
	cat.style.display="none"; 
	img.src=url+"images/class1.gif";
	}
}


//分类菜单
function opencat(cats,imgs,url){
    var cat=document.getElementById(cats);
	var img=document.getElementById(imgs);
	if(cat.style.display=="none"){
	cat.style.display="";
	img.src=url+"images/class2.gif";
	}	else {
	cat.style.display="none"; 
	img.src=url+"images/class1.gif";
	}
}

// 
function CheckAll(form)
  {
  for (var i=0;i<form.elements.length;i++)
    {
    var e = form.elements[i];
    if (e.Name != "chkAll")
       e.checked = form.chkAll.checked;
    }
  }
  
// 
function showDiv(objId){
   var objDiv=document.getElementById(objId);   
   if(objDiv.style.display=="none"){
      objDiv.style.display="";
    return;
	}else{
   objDiv.style.display="none";
   }
}

function Openwin(url)
{
    //var url='login.asp;  //转向网页的地址;
    var name="Newwin";                            //网页名称，可为空;
    var iWidth=300;                          //弹出窗口的宽度;
    var iHeight=210;                         //弹出窗口的高度;
    //获得窗口的垂直位置
    var iTop = (window.screen.availHeight-iHeight)/2;        
    //获得窗口的水平位置
    var iLeft = (window.screen.availWidth-iWidth)/2;           
    window.open(url,name,'modal=yes,height='+iHeight+',innerHeight='+iHeight+',width='+iWidth+',innerWidth='+iWidth+',top='+iTop+',left='+iLeft+',status=no,toolbar=no,menubar=no,location=no,resizable=no,scrollbars=0,titlebar=no');
}

// 弹出登录窗
function openlogon() 
{
	var iWidth=320;                          //弹出窗口的宽度;
    var iHeight=200;                         //弹出窗口的高度;
	//获得窗口的垂直位置
    var iTop = (window.screen.availHeight-iHeight)/2;        
    //获得窗口的水平位置
    var iLeft = (window.screen.availWidth-iWidth)/2; 
	openwindow=window.open("", "newwin", "modal=yes,height="+iHeight+",width="+iWidth+",top="+iTop+",left="+iLeft+"toolbar=no,scrollbars=no,menubar=no"); 
//写成一行 
	var Openstr="<title>User Login</title>";
	Openstr=Openstr + "<title>User Login</title>";
	Openstr=Openstr + "<body bgcolor=#FFFFFF>";
	Openstr=Openstr + "<form name='form1' method='post' action='userlogin.asp?action=login' onSubmit='return chkLoginForm();'>";
	Openstr=Openstr + "<table border='0' cellspacing='0' cellpadding='5' width='100%'>";
	Openstr=Openstr + "<tr><td colspan='2' align='center'>User Login</td></tr>";
	Openstr=Openstr + "<tr><td width='100' align='right'>Account:</td><td ><input name='account' type='text' id='account'></td></tr>";
	Openstr=Openstr + "<tr><td align='right'>Password:</td><td><input name='password' type='password' id='password'></td></tr>";
	Openstr=Openstr + "<tr><td colspan='2' align='center'><input id='cookies' name='cookies' type='checkbox' value='1'> Remember me </td></tr>";
	Openstr=Openstr + "<tr><td colspan='2' align='center'>";
	Openstr=Openstr + "<input type='submit' name='Submit' value='Sign in'>&nbsp;&nbsp;";
	Openstr=Openstr + "<input type='reset' name='Submit' value='Reset'></td></tr>";
	Openstr=Openstr + "<tr><td colspan='2' align='center'> ";
	Openstr=Openstr + "<a href='User.asp?action=pass'><font size=2>Forget the Password?</font></a> "; 
	Openstr=Openstr + "<a href='javascript:popSignFlow(1);'><font size=2>Create an Account</font></a></td></tr>";
	Openstr=Openstr + "</table></form>";
	Openstr=Openstr + "</body></html>";
	openwindow.document.write(Openstr);
	openwindow.document.close();
} 

function Element(id)
{
	return document.getElementById(id);
}


//验证联系表格
function chkContactForm() {
  if (Element("Title").value=="") { 
		alert('Please input the Subject.'); 
		Element("Title").focus();
		return false;
  }
  if (Element("Content").value==""){ 
       alert('Please input the Content.'); 
	   Element("Content").focus();
	   return false;
  }
  if (Element("FmCountry").value==""){
	  alert('Please select your Country/Region.'); 
	  Element("FmCountry").focus();
	  return false;
  }
  if (Element("FmCoPer").value==""){
	  alert('Please input your Name.'); 
	  Element("FmCoPer").focus();
	  return false;
  }
  if (Element("FmCoName").value==""){ 
      alert('Please input your Company name.'); 
	  Element("FmCoName").focus();
	  return false;
  }
  if (Element("FmCoTel").value==""){
	  alert('Please input your phone number like +86-574-56794707.');
	  Element("FmCoTel").focus();
	  return false;
  }
  if (Element("FmCoEmail").value.length<5 || !Element("FmCoEmail").value.match( /^.+@.+$/ )){
	  alert('Please input your email address like yourname@domain.com.'); 
	  Element("FmCoEmail").focus();
	  return false;
  }
  if (Element("VerifyCode").value=="" || Element("VerifyCode").value.trim()!=$GetCookie("VerifyCode")){
	  alert('Please input the shown code on right.'); 
	  Element("VerifyCode").focus();
	  return false;
  }
  return true; 
}

//验证用户登录表格
function chkLoginForm(){
	if (Element("email").value.indexOf('@')<=0||Element("email").value.indexOf('.')<=0 ) {
		alert("Please input your email.");
		Element("email").focus();
		return false;
	}
	if (Element("password").value=="") {
		alert("Please input your password.");
		Element("password").focus();
		return false;
	}
	if (Element("VerifyCode") && Element("VerifyCode").value=="" || Element("VerifyCode").value.trim()!=$GetCookie("VerifyCode")){
	  alert('Please input the shown code on right.'); 
	  Element("VerifyCode").focus();
	  return false;
    }
	return true;
}


//
function CheckUserForm()
{
	if (Element("email").value.length < 5 || !Element("email").value.match( /^.+@.+$/ ) ) {
	    alert("Please input the correct E-mail, like yourname@rocsun.com");
	    Element("email").focus();
		return false;
	}	
	if (Element("username") && Element("username").value.length < 6) {
		alert("Please input the username. \n6-20 letters are required.");
		Element("username").focus();
		return false;
	}	
	if (Element("password").value.length < 6) {
		alert("Please input the correct password.\n6-20 letters/numbers are required.");
		Element("password").focus();
		return false;
	}
	if (Element("pwdconfirm") && Element("password").value != Element("pwdconfirm").value) {
		alert("Please input the same passwords.");
		Element("pwdconfirm").focus();
		return false;
	}
	if (Element("question") && Element("answer") && Element("question").value.length > 0 && Element("answer").value.length == 0) {
		alert("Please input the anwser.\nThe right answer is helpful to recall the password.");
		Element("answer").focus();
		return false;
	}
	if (Element("realname") && Element("realname").value.length == 0) {
		alert("Please input your real name.");
		Element("realname").focus();
		return false;
	}
	if (Element("phone") && Element("phone").value.length == 0) {
		alert("Please input your phone number.");
		Element("phone").focus();
		return false;
	}
	if (Element("company") && Element("company").value.length == 0) {
		alert("Please input your company name.");
		Element("company").focus();
		return false;
	}
	if (Element("remarks") && Element("remarks").value.length == 0) {
		alert("Please input your company brief introduction.\ne.g. the history, main line, annual turnover, etc.");
		Element("company").focus();
		return false;
	}
	if (Element("VerifyCode") && Element("VerifyCode").value=="" || Element("VerifyCode").value.trim()!=$GetCookie("VerifyCode")){
	  alert('Please input the shown code on right.'); 
	  Element("VerifyCode").focus();
	  return false;
    }
	return true;
}

function createAjax() {   //该函数将返回XMLHTTP对象实例
var _xmlhttp;
try {
_xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
catch (e) {
try {
   _xmlhttp=new XMLHttpRequest();
}
catch (e) {
   _xmlhttp=false;
}
}
return _xmlhttp;
}

function CheckExist(model,id,SpanId) { //该函数用来获取数据
var xmlhttp1=createAjax();
if (xmlhttp1) {
var span=document.getElementById(SpanId); // 获取显示节点
if (model==null || model=="") {
	span.innerHTML="<font color='#ff0000'> * "+span.alt+" is required. </font>";
}else{
xmlhttp1.open("get","UserCheck.asp?model="+model+"&id="+id+"&n="+Math.random(),true);
xmlhttp1.onreadystatechange=function() {
   if (xmlhttp1.readyState==4 && xmlhttp1.status==200) {
    span.innerHTML=xmlhttp1.responseText;
    }
   else {
    span.innerHTML="<font color='#000066'>xmlhttp对象正在初始化......</font>";
   }
}
xmlhttp1.send(null);
}
}
}

function checkfield(field){
	if (field.value.length==0){
		var spanid=field.name.replace("Cn","");
		spanid=spanid.replace("En","");
		var span=document.getElementById(spanid);
		span.innerHTML="<font color='#ff0000'> * " + field.alt + "不能为空 </font>";
	}
}


//图片按比例缩放
var flag=false;
function DrawImg(Img,iwidth,iheight){
//参数(图片,允许的宽度,允许的高度)
var image=new Image();
image.src=Img.src;

if(image.width>0 && image.height>0){
    flag=true;
if (image.width/image.height >= iwidth/iheight){
    if(image.width>iwidth){ 
        Img.width=iwidth;
        Img.height=(image.height*iwidth)/image.width;
       }
	else{
        Img.width=image.width; 
        Img.height=image.height;
       }
    }
else{
    if(image.height>iheight){ 
        Img.height=iheight;
        Img.width=(image.width*iheight)/image.height; 
    }else{
        Img.width=image.width; 
        Img.height=image.height;
        }
      }
    } 
  }

/*按比例生成缩略图*/
function DrawImage(MyPic,W,H){
  var flag=false;
  var image=new Image();
  image.src=MyPic.src;
  if(image.width>0 && image.height>0){
    flag=true;
    if(image.width/image.height>= W/H){
      if(image.width>W){  
        MyPic.width=W;
        MyPic.height=(image.height*W)/image.width;
      }
	  else{
        MyPic.width=image.width;  
        MyPic.height=image.height;
      }
    }
    else{
      if(image.height>H){  
        MyPic.height=H;
        MyPic.width=(image.width*H)/image.height;     
      }
	  else{
        MyPic.width=image.width;  
        MyPic.height=image.height;
      }
    }
  }
} 


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_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_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];}
}


function CheckSearchEn()
{
if (searchform.sokey.value=="") 
{
alert('Plese input the keyword!');
searchform.sokey.focus();
return false;
}
}

function CheckSearchCh()
{
if (searchform.sokey.value=="") 
{
alert('请输入关键字');
searchform.sokey.focus();
return false;
}
}


//禁止图片右键  
//document.onmousedown
document.onmousedown=function(e) {
    if (!e) e=window.event;
    if (e.button==2) {
        var obj=e.srcElement?e.srcElement:e.target;
		if (obj.tagName=="IMG"){
            alert("Sorry, the picture is only for view!");
		    return false;
		}
		else{
			alert("Welcome to visit our website!");
			return false;
		}
    }
}

//弹出用户登陆框（背景变灰并且功能失效）
//用javascript实现用户登陆，注册，忘记密码；修改密码等页面功能；
function G(id){
    return document.getElementById(id);
};
function GC(t){
   return document.createElement(t);
};
String.prototype.trim = function(){
          return this.replace(/(^\s*)|(\s*$)/g, '');
};
function isIE(){
      return (document.all && window.ActiveXObject && !window.opera) ? true : false;
} 

var loginDivWidth = 300;
var sign_in_flow = '<div style="background:#FF9900;height:20px"><b>User Login</b></div><div> &nbsp; </div>'
        + '<form id="uform" name="uform" method="post" action="User.asp?action=login"><div>E-mail:*</div>'
        + '<div><input type="text" id="sign_email" name="email" maxlength="64" size="30"/></div>'
        + '<div>Password:*</div><div><input type="password" name="password" id="sign_pwd" size="30"/></div>'
	    + '<div> &nbsp; </div>'
        + '<div><input type="button" value="Login" onclick="signFlow(1);" id="sign_button"/> <input type="submit" style="display:none"> '
        + ' &nbsp;  <input type="button" value="Cancel" onclick="cancelSign();"/></div></form>'
        + '<p><a href="javascript:loadSignUpFlow();">Create account</a>   '
        + 'or   <a href="javascript:loadForgetPwdFlow();">Forget password?</a></p>';
function loadSignInFlow(){
   G("sign_div").innerHTML = sign_in_flow;
    G("sign_email").focus();
};
var sign_up_flow = '<div style="background:#CCFF00;">Create New Account</div><div> &nbsp; </div>'
		+ '<form id="uform" name="uform" method="post" action="User.asp?action=save">'
		+ '<div>E-mail:*</div>'
        + '<div><input type="text" id="sign_email" name="email" maxlength="64" size="30"/></div>'
		+ '<div>UserName:*</div>'
        + '<div><input type="text" id="sign_name" name="username" maxlength="30" size="30"/></div>'
        + '<div>Password:*</div><div><input type="password" id="sign_pwd" name="password" size="30"/></div>'
        + '<div>Password again:*</div><div><input type="password" id="sign_repwd" name="pwdconfirm" size="30"/></div>'
		+ '<div> &nbsp; </div>'
        + '<div><input type="button" value="Create account" onclick="signFlow(0);" id="sign_button"/> '
		+ '<input type="submit" style="display:none"> '
        + ' &nbsp; <input type="button" value="Cancel" onclick="cancelSign();"/></div></form>'
        + '<p><a href="javascript:loadSignInFlow();">login</a></p>';
function loadSignUpFlow(){
   G("sign_div").innerHTML = sign_up_flow;
    G("sign_email").focus();
};
function cancelSign(){
    G("sign_div").style.display = 'none';
    G("cover_div").style.display = 'none';
   document.body.style.overflow = '';
};
var forget_pwd_flow = '<div style="background:#FF99FF;">Forget Password</div><div> &nbsp; </div>'
        + '<form id="uform" name="uform" method="post" action="User.asp?action=sendpass">'
		+ '<div>E-mail:*</div>'
        + '<div><input type="text" id="sign_email" name="email" maxlength="64" size="30"/></div>'
		+ '<div> &nbsp; </div>'
        + '<div><input type="button" value="Send pwd to e-mail" onclick="signFlow(2);" id="sign_button"/>   '
		+ '<input type="submit" style="display:none"> '
        + ' &nbsp;  <input type="button" value="Cancel" onclick="cancelSign();"/></div></form>'
		+ '<p><a href="javascript:loadSignInFlow();">login</a></p>';
function loadForgetPwdFlow(){
   G("sign_div").innerHTML = forget_pwd_flow;
    G("sign_email").focus();
};
function checkEmail(){
   if((G("sign_email").value.indexOf('@')<=0)||(G("sign_email").value.indexOf('.')<=0)){
    return '<div style="color:#FF0000";">Sorry, unrecognized e_mail.</div>';
   }
   return '';
}
function checkName(){
   if(G("sign_name").value.trim() == ''){
    return '<div style="color:#FF0000";">Username field is required.</div>';
   }
   return '';
}
function checkPwd(){
   if(G("sign_pwd").value.trim() == ''){
    return '<div style="color:#FF0000";">Password field is required.</div>';
   }
   return '';
}
function checkRePwd(){
   if(G("sign_pwd").value.trim() != G("sign_repwd").value.trim()){
    return '<div style="color:#FF0000";">The specified passwords do not match.</div>';
   }
   return '';
}
function signFlow(isSignIn){
    var error = checkEmail();
    var htmlText = null;
    if (isSignIn == 1) {
     if (error == ''){
      error = checkPwd();
     }
     htmlText = sign_in_flow;
    } else if (isSignIn == 0) {
     if (error== ''){
	  error=checkName(); 
	 }
	 if (error == ''){
      error = checkPwd();
      if (error == ''){
       error = checkRePwd();
      }
     }
     htmlText = sign_up_flow;
    } else if (isSignIn == 2) {
    htmlText = forget_pwd_flow;
    }
    var eMailValue = G("sign_email").value.trim();
	if (G("sign_name")) var NameValue = G("sign_name").value.trim();
   if (error == '') {
	   document.forms["uform"].submit();
    } else {
    G("sign_div").innerHTML = error + htmlText;
    G("sign_email").value = eMailValue;
	if (G("sign_name")) G("sign_name").value = NameValue;
    }
};
function popCoverDiv(){
   if (G("cover_div")) {
    G("cover_div").style.display = '';
   } else {
    var coverDiv = GC('div');
    document.body.appendChild(coverDiv);
    coverDiv.id = 'cover_div';
    with(coverDiv.style) {
     position = 'absolute';
     background = '#CCCCCC';
     left = '0px';
     top = '0px';
     var bodySize = getBodySize();
     width = bodySize[0] + 'px'
     height = bodySize[1] + 'px';
     zIndex = 98;
     if (isIE()) {
      filter = "Alpha(Opacity=60)";
     } else {
      opacity = 0.6;
     }
    }
   }
}
function getBodySize(){
   var bodySize = [];
   with(document.documentElement) {
    bodySize[0] = (scrollWidth>clientWidth)?scrollWidth:clientWidth;
    bodySize[1] = (scrollHeight>clientHeight)?scrollHeight:clientHeight;
   }
   return bodySize;
} 
function popSign(isLogin){
   if (G("sign_div")) {
    G("sign_div").style.display = '';
   } else {
    var signDiv = GC('div');
    document.body.appendChild(signDiv);
    signDiv.id = 'sign_div';
    signDiv.align = "center";
    signDiv.onkeypress = function(evt){
          var e = window.event?window.event:evt;
          if (e.keyCode==13 || e.which==13) {
           if (G("sign_button")) {
            G("sign_div").focus();
            G("sign_button").click();
           }
          }
         };
    with (signDiv.style) {
     position = 'absolute';
     left = (document.documentElement.clientWidth - loginDivWidth)/2 + 'px';
     top = (document.documentElement.clientHeight - 300)/2 + 'px';
     width = loginDivWidth + 'px';
     zIndex = 99;
     background = '#000066';
     border = '#66CCFF solid 1px';
    }
   }
   if(isLogin) {
    G("sign_div").innerHTML = sign_in_flow;
   } else {
    G("sign_div").innerHTML = sign_up_flow;
   }
  
}
function popSignFlow(isLogin) {
   popCoverDiv();  
   popSign(isLogin);  
   document.body.style.overflow = "hidden";
     
      if(isLogin) {
       G("sign_email").focus();
      } else {
       G("sign_email").focus();
	   //G("old_pwd").focus();
      }
}
function changePwd(){
    var error = checkOldPwd();
    if (error == ''){
     error = checkPwd();
    }
   if (error == ''){
    error = checkRePwd();
   }

    var oldPwd = G("old_pwd").value.trim();
    var newPwd = G("sign_pwd").value.trim();
   if (error == '') {
     var url = basePath + "?q=tripuser/tripuser_change_pwd_ajax/" + oldPwd + "/" + newPwd;
     exeRequest(url, getSignText, null);
    } else {
    G("sign_div").innerHTML = error + change_pwd_flow;
    }
};
function checkOldPwd(){
   if(G("old_pwd").value.trim() == ''){
    return '<div style="color:#FF0000";">Old Password field is required.</div>';
   }
   return '';
}
var change_pwd_flow = '<div style="background:#33FFFF;">Change Your Password</div><div> &nbsp; </div>'
        + '<form id="uform" name="uform" method="post" action="User.asp?action=savepass">'
        + '<div>old password:*</div>'
        + '<div><input type="password" id="old_pwd" size="30"/></div>'
        + '<div>new password:*</div><div><input type="password" id="sign_pwd" size="30"/></div>'
        + '<div>new password again:*</div><div><input type="password" id="sign_repwd" size="30"/></div>'
		+ '<div> &nbsp; </div>'
        + '<div><input type="button" value="change password" onclick="changePwd();" id="sign_button"/> '
		+ '<input type="submit" style="display:none"> '
        + ' <input type="button" value="cancel" onclick="cancelSign();"/></div></form>';
// ＝＝＝＝＝＝＝弹出用户信息结束＝＝＝＝＝＝

-->
