// JavaScript Document
function StrCode(str){
  if (encodeURIComponent)
    return encodeURIComponent(str);
  if (escape)
    return escape(str);
}

function UnStrCode(str){
  if (decodeURIComponent)
    return decodeURIComponent(str);
  if (unescape)
    return unescape(str);
}

function Trim(s){
  var m = s.match(/^\s*(\S+(\s+\S+)*)\s*$/);
  return (m == null) ? "" : m[1];
}

function HtmlEncode(text){
  var re = {
    '<': '&lt;', '>': '&gt;', '&': '&amp;', '"': '&quot;'
  };
  for (i in re)
    text = text.replace(new RegExp(i, 'g'), re[i]);
  return text;
}

function HtmlDecode(text){
  var re = {
    '&lt;': '<', '&gt;': '>', '&amp;': '&', '&quot;': '"'
  };
  for (i in re)
    text = text.replace(new RegExp(i, 'g'), re[i]);
  return text;
}

function gid(id){
  return document.getElementById ? document.getElementById(id): null;
}

function gna(id){
  return document.getElementsByName ? document.getElementsByName(id): null;
}

function gname(name){
  return document.getElementsByTagName ? document.getElementsByTagName(name):new Array();
}


/*弹出窗口的函数*/
function windowOpen(theURL,width,height)
{
  var openwindow = window.open(theURL,'弹出窗口','width='+width+',height='+height);
}
/*弹出窗口的函数*/
function windowOpenScrollbars(theURL)
{
  window.open(theURL,'_blank','width=300,height=270,toolbars=0,menubars=0,scrollbars=1,resizable=yes');
}
/*清空一个选择框的记录*/
function emptySelect(oSelect)
{
 while(oSelect.length>0)
 oSelect.remove(0);	
 oSelect.options.add(new Option("请选择","0"));
}

function getSelectText(obj){
 if(obj==null){
 return "";
 }
 var optionlist=obj.options;
 if(optionlist.selectedIndex>0 && optionlist[optionlist.selectedIndex]!=null)
 return optionlist[optionlist.selectedIndex].text;
 return "";
}

/*设置单选框的值*/
function   setRadioValue(whichformvalue,value)
{
   var radiovalue=whichformvalue;
   if(value!=null)
   {
     for(var i=0;i<radiovalue.length;i++)
     {
      if(radiovalue[i].value==value)
	  {
	      radiovalue[i].checked=true;
	  }
     } 
   }
   else
   {
     radiovalue[0].checked=true;
   }   
}
/*从单选框中过来的数据*/
function getRadioValue(rObj){
	
	if(rObj==null)
	return false;
    for(i=0; i<rObj.length; i++)
	{
		if(rObj[i].checked == true)
		{
			return rObj[i].value ;
		}
	}
}
/**/
function deleteNotice(url,notice)
{
     if(notice=='')
	 notice="删除后此信息将不能恢复，您确认执行删除操作吗？";
    var returnvar=confirm(notice);
   if(returnvar==true)
   {
       self.location=url;
   }
}


/*显示网页的头部*/
function showPageHeader()
{document.writeln("<div id=\"PageHead\">   ");
document.writeln("  <div id=\"HeadLogo\"><a href=\"\/index.php\" ><img src=\"\/images\/bbs\/logo.gif\" alt=\"中国汽车电机网\"  border=\"0\"><\/a> ");
document.writeln("  <\/div>");
document.writeln("   <div id=\"HeadRight\">");
document.writeln("     <div id=\"Login\"><\/div> ");
document.writeln("	  <div id=\"Regist\"><\/div> ");
document.writeln("       <div id=\"HeadLink\">");
document.writeln("<a href=\"/user.php\" id=\"naviBBS\" style=\"width:80px\">我的汽电秘书</a>");	 
document.writeln("<a href=\"/bbs.php\" id=\"naviBBS\">电机社区</a>");
document.writeln("<a href=\"/school/index.html\" id=\"naviSchool\" >电机学院</a>");
document.writeln("<a href=\"/top/index.html\" id=\"naviTop\">排行榜</a>");
document.writeln("<a href=\"/buy/index.html\" id=\"naviBuyer\">我要采购</a>");
document.writeln("<a href=\"/sell/index.html\" id=\"naviSeller\">我要销售</a>");
document.writeln("<a href=\"/search.php\" id=\"naviSearch\">搜索引擎</a>");

document.writeln("     <\/div>");
document.writeln("  <\/div>  ");
document.writeln("<\/div> ");
}

/**/
function showPageFooter()
{	   
document.write("<link href=\"/template/css/global.css\" rel=\"stylesheet\" type=\"text/css\">");
document.write("<hr width=\"780\" size=\"1\" color=\"#FF6600\">");
document.write("<div align=\"center\" id=\"PageFooter\" style=\"line-height:20px\"><a href=\"http:\/\/china.amb2b.com\"><img src=\"\/images\/switchlogo_cn.gif\" alt=\"中国站\" width=\"103\" height=\"39\" border=\"0\" \/><\/a>");
document.write("  　<a href=\"http:\/\/www.amb2b.com\"><img src=\"\/images\/switchlogo_en.gif\" alt=\"English Version\" width=\"98\" height=\"39\" border=\"0\" \/><\/a><br \/>");
document.write("<a href=\"\/index.php?name=amb2b&handle=aboutus\" target=\"_blank\">关于我们<\/a>　<a href=\"/static/help/member_service.html\" target=\"_blank\">产品服务</a>　<a href=\"\/static\/other\/changelink.htm\" target=\"_blank\">友情链接<\/a>　<a href=\"\/index.php?name=amb2b&handle=hr\" target=\"_blank\">求贤纳士<\/a>　");
document.write("<a href=\"\/index.php?name=amb2b&handle=contributor\" target=\"_blank\">欢迎投稿<\/a>　<a href=\"\/index.php?name=amb2b&handle=contactus\" target=\"_blank\">联系我们<\/a>　<a href=\"javascript:bugreport()\">建议反馈<\/a>　<a href=\"\/static\/help\/index.html\" target=\"_blank\">帮助中心<\/a>　<a target=blank href=http:\/\/wpa.qq.com\/msgrd?V=1&Uin=394883642&Site=www.amb2b.com&Menu=yes><img src=\"\/images\/index\/qq_logo.gif\" border=\"0\" align=\"absmiddle\" class=\"AlphaPic\" \/><\/a> <a href=\"msnim:chat?contact=cnamnic@hotmail.com\"><img src=\"\/images\/index\/msn_logo.gif\" alt=\"MSN在线客服\" border=\"0\" align=\"absmiddle\" class=\"AlphaPic\" onerror=\"this.onerror=null;this.src=\'\/images\/index\/msn_logo.gif\';\" \/><\/a><br>");
document.write("  服务热线：4006-686-726 服务邮箱：service@amb2b.com <br>");
document.write("  版权所有：中国汽车电机网 2005 - 2010 All rights reserved. <a href=\"\/index.php?name=amb2b&handle=copyright\" target=\"_blank\">版权声明<\/a> <a href=\"\/index.php?name=amb2b&handle=privacy\" target=\"_blank\">隐私声明<\/a><br>");
document.write("  运营商:速转科技  <a href=\"http:\/\/www.miibeian.gov.cn\" target=\"_blank\">沪ICP备06054085号<\/a><\/div>");
document.write("  ");
document.write("  <script language=\"JavaScript\">function bugreport()");
document.write("{");
document.write("   windowOpen(\"/index.php?name=Bug&handle=add&url=$v_get_now_url\",500,250)");
document.write("}");
document.write("  <\/script> ");
document.write("<\/div>");	
}

/*切换标签*/
function switchNavi(naviElement)
{  
 for(var i=0;i<itemArray.length;i++)
   {
     var naviarray=itemArray[i].split("|");	 
	 var divElement=document.getElementById(naviarray[1]);	;
	 var naviClass =(naviElement.className).substr(0,(naviElement.className).indexOf("_"));	 
	 if(naviarray[0]==naviElement.id)
	 { 
	   document.getElementById(naviarray[0]).className=naviClass+"_On";
	   divElement.style.display="block";
	 }else
	 {
	   document.getElementById(naviarray[0]).className=naviClass+"_Off";
	   divElement.style.display="none";
	 }
   }
}

/*翻页*/
function gotoPage(pagename){
var pagenum=document.getElementById('thispage').value;
if(pagenum!=null && pagenum!=''){
 if(!isNaN(pagenum)){
	this.location=pagename+'&page='+pagenum;
 }
}
}

/**/
function setIframeSrc(elementid,url)
{
  document.getElementById(elementid).src=url;
}

function showLoginAjax(){
//var markDiv=document.createElement("div");
//markDiv.id="markDiv";
var loginDiv= document.createElement("div");
loginDiv.id="loginDiv";
//markDiv.appendChild(loginDiv);
//document.body.appendChild(markDiv);
 document.body.appendChild(loginDiv);
 pullToSpanAjax("/ajax.php?name=UserLogin","loginDiv",'');
}

function userLoginAjax(){
    try{
    var loginDiv= document.getElementById("loginDiv");
    var v_uname=loginDiv.getElementById("").value;
    //var v_pwd=loginDiv.getElementById("pwd").value;  
    alert(v_uname+"|"+v_pwd);
    }catch(e){
	alert(e.message);
    }
}

//保存商业条款模板
function saveTmp(form,handle)
{
	var obj = eval("document."+form);		
	var validdate=getRadioValue(document.getElementsByName("validdate"));
	var packing_type_int=document.getElementById("packing_type_int").value;
	var packing_type_ext=document.getElementById("packing_type_ext").value;
	var delivery_type=getRadioValue(document.getElementsByName("delivery_type"));
	var delivery_time=document.getElementById("delivery_time").value;
	var payment_term=document.getElementById("payment_term").value;
	var guarantee=document.getElementById("guarantee").value;
	var freight=document.getElementById("freight").value;
  
    var url = "/ajax.php?name=StatusSet&handle="+handle;
	var postStr="&validdate="+validdate+"&packing_type_int="+packing_type_int+"&packing_type_ext="+packing_type_ext+"&delivery_type="+delivery_type+"&delivery_time="+delivery_time+"&payment_term="+payment_term+"&guarantee="+guarantee+"&freight="+freight;

	pullToSpanAjax(url,'',postStr,'eval');
}

/*得到多选择框的选择个数*/
function getBoxCheckNum(obj){
 if(obj==null){
 return 0;
 }
 var checknum=0;
 //alert(obj);
 for(var i=0;i<obj.length;i++){
   if(obj[i].checked==true){
    checknum++;
   }
 }
 return checknum;
}

//
function getMatchResult(searchKey,SearchType)
{
	var url = "/ajax.php?name=Match_Prod_list&keyWord="+searchKey+"&SearchType="+SearchType;
	pullToSpanAjax(url,"matchList");
}

//
function getProdDetail(prod_no,type,spanId,hrefId)
{
	var url = "/ajax.php?name=Prod_price_detail&prod_no=" + prod_no + "&type=" + type;
	pullToSpanAjax(url,spanId);
	
	if(eval("document.getElementById(\"" + spanId + "\").innerHTML") != "")
	{
		if(eval("document.getElementById(\"" + spanId + "\").style.display") == "block")
		{
			//document.getElementById(spanId).style.display = "none";
			eval("document.getElementById(\"" + spanId + "\").style.display=\"none\"");
			eval("document.getElementById(\"" + hrefId + "\").src=\"/images/icon/add.gif\"");
			//eval("document.getElementById(\"" + hrefId + "\").innerHTML=\"点击查看\"");
		}
		else
		    //(eval("document.getElementById(\"" + spanId + "\").style.display") == "none")
		{
			eval("document.getElementById(\"" + spanId + "\").style.display=\"block\"");
			eval("document.getElementById(\"" + hrefId + "\").src=\"/images/icon/subtract.gif\"");
			//eval("document.getElementById(\"" + hrefId + "\").innerHTML=\"&nbsp;收&nbsp;&nbsp;缩&nbsp;\"");
		}
	}
}

function selectKind2(kind2,kind3)
{	  
        var selectObject=document.getElementById("kind3");
        var phpurl="/ajax.php?name=Kind2_Kind3&kind2="+kind2+"&kind3="+kind3;
        returnValue=getOption(phpurl,selectObject,1,"selectKind3",'');
		emptySelect(document.getElementById("kind4"));
		//document.getElementById('part_detail').style.display='block';		
}	

////
function selectKind3(kind3,kind4)
{	    var selectObject=document.getElementById("kind4");
        var phpurl="/ajax.php?name=Kind3_Kind4&kind3="+kind3+"&kind4="+kind4;
         returnValue=getOption(phpurl,selectObject,1,"",'');
		
		//document.getElementById('part_detail').style.display='block';		
}


function prodErrorClick(ext_prod_no,text){
pullToSpanAjax("/ajax.php?name=ProdError&ext_prod_no="+ext_prod_no+"&text="+text,'','','eval');
}

/*浮动广告*/

function heartBeat(element){  
  if(document.getElementById(element)==null)
  return false;
  var diffY=document.body.scrollTop; //得到离顶部的位置
  var percent=0.1*(diffY-lastScrollY);  //
  if(percent>0){
     percent=Math.ceil(percent); 
  }
  else {
     percent=Math.floor(percent); 
  }  
 
  document.getElementById(element).style.top=parseInt(document.getElementById(element).style.top)+percent+"px"; 
   // alert(parseInt(document.getElementById(element).style.top)+percent+"px");
  lastScrollY+=percent; 
} 
function setElementFloat(element){
  window.setInterval("heartBeat('"+element+"')",1000); 
}
//all select
function toggleAll(e,chkId,formId){
  if(e.checked) {
    checkAll(chkId,formId);
  }
  else{
    clearAll(chkId,formId);
  }
}

function checkAll(chkId,formId){
  var fo = document.getElementById(formId);
  var len = fo.elements.length;
  for(var i = 0; i < len; i++) {
    var e = fo.elements[i];
    if(e.name == chkId) {
      if(!e.checked){
        e.click();
      }
    }
  }
}

function clearAll(chkId,formId){
  var fo = document.getElementById(formId);
  var len = fo.elements.length;
  for (var i = 0; i < len; i++) {
    var e = fo.elements[i];
    if (e.name == chkId) {
        if(e.checked){
        e.click();
        }
    }
  }
}
function isCheck(chkId,formId,message){
	var boolen = false;
	var fo = document.getElementById(formId);
  var len = fo.elements.length;
  for (var i = 0; i < len; i++) {
    var e = fo.elements[i];
    if (e.name == chkId) {
        if(e.checked){
	        boolen=true;
			break;
        }
    }
  }
  if(!boolen){
	  alert(message);
	  return false;
	  }
}
// JavaScript Document