//去除左右两端的空格
function trim(s)  
{return  s.replace(/(^\s*)|(\s*$)/g,  "");} 

document.oncontextmenu=new Function("event.returnValue=false;"); 
document.onselectstart=new Function("event.returnValue=false;");

function checksearch()
{
	if (trim(document.Search.Keyword.value)=='')
	{alert('关键字不能为空');
	document.Search.Keyword.focus();
	document.Search.Keyword.value='';
	return false
	}
	if (document.Search.Keyword.value=='请输入关键字')
	{alert('关键字不能为空');
	document.Search.Keyword.focus();
	document.Search.Keyword.value='';
	return false
	}
}

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;
      }
    }
  }
}

var show_checkcode = false;
function get_checkcode() {
	var chkCodeFile = webdir+"Inc/getcode.asp";
	if(!show_checkcode){
		if(document.getElementById("img_checkcode"))
			document.getElementById("img_checkcode").innerHTML = '<img  id="checkcodeimg" src="'+chkCodeFile+'?t='+Math.random()+'" alt="点击刷新验证码" style="cursor:pointer;border:0;vertical-align:middle;height:18px;" onclick="this.src=\''+chkCodeFile+'?t=\'+Math.random()" />'
			show_checkcode = true;

		if(document.getElementById("isok_checkcode"))
			document.getElementById("isok_checkcode").innerHTML = '<a href="javascript://" onclick="setTimeout(function(){ document.getElementById(\'checkcodeimg\').src=\''+chkCodeFile+'?t=\'+Math.random()},100);"> 看不清<\/a>';
	}
}

function setTab(name,cursel,n){
for(i=1;i<=n;i++){
var menu=document.getElementById(name+i);
var con=document.getElementById("con_"+name+"_"+i);
menu.className=i==cursel?"curr":"";
con.style.display=i==cursel?"block":"none";
}
}

function $(id){
    return document.getElementById(id);
}

function TryThese(){
    for (i = 0; i < arguments.length; i++){
        try{
            return arguments[i]();
        }catch(e){}
    }
    return false;
}

function CreateXMLHTTP(){
    return TryThese(
        function() {return new ActiveXObject("Msxml2.XMLHTTP");},
        function() {return new ActiveXObject("Microsoft.XMLHTTP");},
        function() {return new XMLHttpRequest();}
    ) || false;
}

function SendRequest(url, param, method, echofun) {
    var xmlHTTP = CreateXMLHTTP();
    if (xmlHTTP){
        xmlHTTP.onreadystatechange = function()
        {
            if (xmlHTTP.readyState == 4 && xmlHTTP.status == 200){
                if (echofun!= null){
                    echofun(xmlHTTP.responseText);
                }
            }
        }
        xmlHTTP.open(method, url, true);
        xmlHTTP.setRequestHeader("Content-Length",param.length); 
        xmlHTTP.setRequestHeader("CONTENT-TYPE","application/x-www-form-urlencoded");
        xmlHTTP.send(encodeURI(param));    
    }else{
        NoXMLHTTP();
    }
}

function NoXMLHTTP(){
    alert("Sorry, your browser doesn't support XMLHTTP");
}

function GetRadioValue(RadioName){
    var obj;    
    obj=document.getElementsByName(RadioName);
    if(obj!=null){
        var i;
        for(i=0;i<obj.length;i++){
            if(obj[i].checked){
                return obj[i].value;            
            }
        }
    }
    return null;
}


function check_order()
{  
	if (trim(order.OrderName.value)=='')
	{   alert('主题不能为空');
		order.OrderName.focus();
		order.OrderName.value='';
		return false
	}
	if (trim(order.RealName.value)=='')
	{   alert('联系人不能空！');
		order.RealName.focus();
		order.RealName.value='';
		return false
	}
    if (trim(order.Telephone.value)=='')
	{   alert('电话不能空！');
		order.Telephone.focus();
		order.Telephone.value='';
		return false
	}
   if (trim(order.checkcode.value)=='')
	{   alert('验证码不能空！');
		order.checkcode.focus();
		order.checkcode.value='';
		return false
	}
	
    order.Submit.disabled=true;
	var param;
	param=webdir+"Save.asp?action=ordersave";
	param += "&OrderName=" + trim(order.OrderName.value);
	param += "&Remark=" + trim(order.Remark.value);
	param += "&RealName=" + trim(order.RealName.value);
	var Sex;
	param += "&Sex=" + GetRadioValue("Sex");
	param += "&Company=" + trim(order.Company.value);
	param += "&Address=" + trim(order.Address.value);
	param += "&ZipCode=" + trim(order.ZipCode.value);
	param += "&Telephone=" + trim(order.Telephone.value);
	param += "&Fax=" + trim(order.Fax.value);
	param += "&Mobile=" + trim(order.Mobile.value);
	param += "&Email=" + trim(order.Email.value);
	param += "&checkcode=" + trim(order.checkcode.value);
	$("showaddmsg").innerHTML ="提交中...";
    SendRequest(param, param, "POST", 
                function(responseText){
					var f	= responseText.substring(0,1);
					if (f == "1"){
						$("showaddmsg").innerHTML =responseText.substring(1);
						$('showaddmsg').style.display = 'inline'
						return false
					}
					
					else{
                        $("showaddmsg").innerHTML =responseText.substring(1);;
						$("OrderName").value='';
						$("Remark").value='';
						$("RealName").value='';
						$("Sex").value='';
						$("Company").value='';
						$("Address").value='';
						$("ZipCode").value='';
						$("Telephone").value='';
						$("Mobile").value='';
						$("Email").value='';
						$("checkcode").value='';
						setTimeout("$('showaddmsg').innerHTML='';","5000");
					}
                });
	return false
}

function check_msg()
{  
	if (trim(msg.MesName.value)=='')
	{   alert('主题不能为空');
		msg.MesName.focus();
		msg.MesName.value='';
		return false
	}
	if (trim(msg.Content.value)=='')
	{   alert('留言内容不能空！');
		msg.Content.focus();
		msg.Content.value='';
		return false
	}
	if (trim(msg.Linkman.value)=='')
	{   alert('联系人不能空！');
		msg.Linkman.focus();
		msg.Linkman.value='';
		return false
	}
    if (trim(msg.Telephone.value)=='')
	{   alert('电话不能空！');
		msg.Telephone.focus();
		msg.Telephone.value='';
		return false
	}
   if (trim(msg.checkcode.value)=='')
	{   alert('验证码不能空！');
		msg.checkcode.focus();
		msg.checkcode.value='';
		return false
	}
	
    msg.Submit.disabled=true;
	
	var param;
	param=webdir+"Save.asp?action=msgsave";
	param += "&MesName=" + trim(msg.MesName.value);
	param += "&Content=" + trim(msg.Content.value);
	param += "&Linkman=" + trim(msg.Linkman.value);
	var Sex;
	param += "&Sex=" + GetRadioValue("Sex");
	param += "&Company=" + trim(msg.Company.value);
	param += "&Address=" + trim(msg.Address.value);
	param += "&Telephone=" + trim(msg.Telephone.value);
	param += "&Mobile=" + trim(msg.Mobile.value);
	param += "&Email=" + trim(msg.Email.value);
	param += "&checkcode=" + trim(msg.checkcode.value);
	$("showaddmsg").innerHTML ="提交中...";
    SendRequest(param, param, "POST", 
                function(responseText){
					var f	= responseText.substring(0,1);
					if (f == "1"){
						$("showaddmsg").innerHTML =responseText.substring(1);
						$('showaddmsg').style.display = 'inline'
						return false
					}
					
					else{
                        $("showaddmsg").innerHTML =responseText.substring(1);;
						$("MesName").value='';
						$("Content").value='';
						$("Linkman").value='';
						$("Sex").value='';
						$("Company").value='';
						$("Address").value='';
						$("Telephone").value='';
						$("Mobile").value='';
						$("Email").value='';
						$("checkcode").value='';
						setTimeout("location.href=webdir+msgurl","2000");
						loadlist();
					}
                });
	return false
}

function loadlist()
{
	var param;
	param=webdir+"Save.asp";
	$("showmsg").innerHTML="载入中...";
	SendRequest(param, param, "POST", 
                function(responseText){
                        $("showmsg").innerHTML =responseText;   
                });
}

function chanagepage(t0)
{
	var param;
	param=webdir+"Save.asp";
	param += "?page=" + escape(t0);
	$("showmsg").innerHTML="载入中...";
	SendRequest(param, param, "POST", 
                function(responseText){
                        $("showmsg").innerHTML =responseText;   
                });
}

function get_hits(t0,t1)
{
	var param;
	param=webdir+"gethits.asp";
	param += "?id=" + escape(t0);
	param += "&action=" + escape(t1);
	$("show_hits").innerHTML="<img src="+webdir+"Images/loading.gif>";
	SendRequest(param, param, "POST", 
                function(responseText){
					$("show_hits").innerHTML=responseText;
                });
}

function addloadEvent(fun){
    var olonload=window.onload;
    if(typeof window.onload!='function'){
        window.onload=fun;
    }else{
        window.onload=function(){
            olonload();
            fun();
        }
    }
}
function highlightnav(){
    if(!document.getElementsByTagName) return false;
    if(!document.getElementById) return false;
    if(!document.getElementById("nav")) return false;
    var nav=document.getElementById("nav");
    var links = nav.getElementsByTagName("a");
    for(var i=0;i<links.length;i++){
        var linkurl=links[i].getAttribute("href");
        var currenturl= window.location.href;
        if(currenturl.indexOf(linkurl)!=-1){
            links[i].className="on";
        }
    }
}
addloadEvent(highlightnav);

function highlightmenu(){
    if(!document.getElementsByTagName) return false;
    if(!document.getElementById) return false;
    if(!document.getElementById("menu")) return false;
    var nav=document.getElementById("menu");
    var links = nav.getElementsByTagName("a");
    for(var i=0;i<links.length;i++){
        var linkurl=links[i].getAttribute("href");
        var currenturl= window.location.href;
        if(currenturl.indexOf(linkurl)!=-1){
            links[i].className="on";
        }
    }
}
addloadEvent(highlightmenu);


