﻿//Pop-it menu- By Dynamic Drive - Modified by Wbird
//For full source code and more DHTML scripts, visit http://www.dynamicdrive.com
//This credit MUST stay intact for use
var menuOffX=0	//菜单距连接文字最左端距离
var menuOffY=18	//菜单距连接文字顶端距离
var vBobjects = new Array();
var fo_shadows=new Array()
var linkset=new Array()
////No need to edit beyond here
var ie4=document.all&&navigator.userAgent.indexOf("Opera")==-1
var ns6=document.getElementById&&!document.all
var ns4=document.layers
var xslDoc;

function MM_findObj(n, d) {
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 fetch_object(idname, forcefetch)
{
	if (typeof(vBobjects[idname]) == "undefined")
	{
		vBobjects[idname] = MM_findObj(idname);
	}
	return vBobjects[idname];
}
//showmenu vmenu:内容，允许为空,vmenuobj DIV数据ID，MOD 0=关闭浏览器自适应，用于版面导航菜单
function showmenu(e,vmenu,vmenuobj,mod){
	if (!document.all&&!document.getElementById&&!document.layers)
		return
	var which=vmenu;
	if (vmenuobj)
	{
		var MenuObj = fetch_object(vmenuobj);
		if (MenuObj)
		{
			which = MenuObj.innerHTML;
		}
	}
	if (!which)
	{
		return
	}
	clearhidemenu();
	ie_clearshadow();
	menuobj=ie4? document.all.popmenu : ns6? document.getElementById("popmenu") : ns4? document.popmenu : ""
	menuobj.thestyle=(ie4||ns6)? menuobj.style : menuobj
	if (ie4||ns6)
		menuobj.innerHTML=which
	else{
		menuobj.document.write('<layer name=gui bgcolor="#FFFFFF" width="165" onmouseover="clearhidemenu()" onmouseout="hidemenu()">'+which+'</layer>')
		menuobj.document.close()
	}
	menuobj.contentwidth=(ie4||ns6)? menuobj.offsetWidth : menuobj.document.gui.document.width
	menuobj.contentheight=(ie4||ns6)? menuobj.offsetHeight : menuobj.document.gui.document.height
	eventX=ie4? event.clientX : ns6? e.clientX : e.x
	eventY=ie4? event.clientY : ns6? e.clientY : e.y
	var rightedge=ie4? document.body.clientWidth-eventX : window.innerWidth-eventX
	var bottomedge=ie4? document.body.clientHeight-eventY : window.innerHeight-eventY
	var getlength
		if (rightedge<menuobj.contentwidth){
			getlength=ie4? document.body.scrollLeft+eventX-menuobj.contentwidth+menuOffX : ns6? window.pageXOffset+eventX-menuobj.contentwidth : eventX-menuobj.contentwidth
		}else{
			getlength=ie4? ie_x(event.srcElement)+menuOffX : ns6? window.pageXOffset+eventX : eventX
		}
		menuobj.thestyle.left=getlength+'px'
		if (bottomedge<menuobj.contentheight&&mod!=0){
			getlength=ie4? document.body.scrollTop+eventY-menuobj.contentheight-event.offsetY+menuOffY-23 : ns6? window.pageYOffset+eventY-menuobj.contentheight-10 : eventY-menuobj.contentheight
		}	else{
			getlength=ie4? ie_y(event.srcElement)+menuOffY : ns6? window.pageYOffset+eventY+10 : eventY
		}
	menuobj.thestyle.top=getlength+'px'
	menuobj.thestyle.visibility="visible"
	ie_dropshadow(menuobj,"#999999",3)
	return false
}

function ie_y(e){  
	var t=e.offsetTop;  
	while(e=e.offsetParent){  
		t+=e.offsetTop;  
	}  
	return t;  
}  
function ie_x(e){  
	var l=e.offsetLeft;  
	while(e=e.offsetParent){  
		l+=e.offsetLeft;  
	}  
	return l;  
}  
function ie_dropshadow(el, color, size)
{
	var i;
	for (i=size; i>0; i--)
	{
		var rect = document.createElement('div');
		var rs = rect.style
		rs.position = 'absolute';
		rs.left = (el.style.posLeft + i) + 'px';
		rs.top = (el.style.posTop + i) + 'px';
		rs.width = el.offsetWidth + 'px';
		rs.height = el.offsetHeight + 'px';
		rs.zIndex = el.style.zIndex - i;
		rs.backgroundColor = color;
		var opacity = 1 - i / (i + 1);
		rs.filter = 'alpha(opacity=' + (100 * opacity) + ')';
		//el.insertAdjacentElement('afterEnd', rect);
		fo_shadows[fo_shadows.length] = rect;
	}
}
function ie_clearshadow()
{
	for(var i=0;i<fo_shadows.length;i++)
	{
		if (fo_shadows[i])
			fo_shadows[i].style.display="none"
	}
	fo_shadows=new Array();
}


function contains_ns6(a, b) {
	while (b.parentNode)
		if ((b = b.parentNode) == a)
			return true;
	return false;
}

function hidemenu(){
	if (window.menuobj)
		menuobj.thestyle.visibility=(ie4||ns6)? "hidden" : "hide"
	ie_clearshadow()
}

function dynamichide(e){
	if (ie4&&!menuobj.contains(e.toElement))
		hidemenu()
	else if (ns6&&e.currentTarget!= e.relatedTarget&& !contains_ns6(e.currentTarget, e.relatedTarget))
		hidemenu()
}

function delayhidemenu(){
	if (ie4||ns6||ns4)
		delayhide=setTimeout("hidemenu()",500)
}

function clearhidemenu(){
	if (window.delayhide)
		clearTimeout(delayhide)
}

function highlightmenu(e,state){
	if (document.all)
		source_el=event.srcElement
	else if (document.getElementById)
		source_el=e.target
	if (source_el.className=="menuitems"){
		source_el.id=(state=="on")? "mouseoverstyle" : ""
	}
	else{
		while(source_el.id!="popmenu"){
			source_el=document.getElementById? source_el.parentNode : source_el.parentElement
			if (source_el.className=="menuitems"){
				source_el.id=(state=="on")? "mouseoverstyle" : ""
			}
		}
	}
}

function suggestion_submitlog()
{
	var frm = document.suggestionlog ;

	if(frm.nameEn.value=="")
	{ alert("请输入用户名!!");
	frm.nameEn.focus();
	return false;
	}
	if(frm.password.value=="")
	{ alert("请输入密码!!");
	frm.password.focus();
	return false;
	}
	return true;

}

function doSearch(stype) {
  if(stype == "supplysearch") {
	  var keyword = trim(document.FormSearch1.keyword.value);
	  document.FormSearch1.keyword.value = keyword;
	    if(keyword == "" || keyword=="请输入信息关键字") {
    alert("请输入关键字！");
    return false;
  }
  	url="search_keywords.php";
  	document.FormSearch1.action = url;
	//pfclick('','?tracelog='+ keyword +'&traceF='+ document.FormSearch1.traceF.value +'');
  	document.FormSearch1.submit();
  }

  if(stype == "buysearch") {
	  var keyword = trim(document.FormSearch2.keyword.value);
	  document.FormSearch2.keyword.value = keyword;
	    if(keyword == "" || keyword=="请输入信息关键字") {
    alert("请输入关键字！");
    return false;
  }
  	url="search_keywords.php";
  	document.FormSearch2.action = url;
  	document.FormSearch2.submit();
  }
  if (stype == "goodssearch") {
  	  var keyword = trim(document.FormSearch3.keyword.value);
	  document.FormSearch3.keyword.value = keyword;
	  if(keyword == "" || keyword=="请输入产品关键字") {
    alert("请输入关键字！");
    return false;
  	}
  	url="search_keywords.php";
  	document.FormSearch3.action = url;
  	document.FormSearch3.submit();
  }
  if (stype == "companysearch") {
  	  var keyword = trim(document.FormSearch4.keyword.value);
	  document.FormSearch4.keyword.value = keyword;
	  if(keyword == ""  || keyword=="请输入公司名关键字") {
    alert("请输入关键字！");
    return false;
  	}
  	url="search_keywords.php";
  	document.FormSearch4.action = url;
	//pfclick('','?tracelog='+ keyword +'&traceF='+ document.FormSearch4.traceF.value +'');
  	document.FormSearch4.submit();
  }
  if (stype == "newssearch") {
  	var keyword = trim(document.FormSearch5.keyword.value);
	  document.FormSearch5.keyword.value = keyword;
	  if(keyword == ""  || keyword=="请输入资讯关键字") {
    alert("请输入关键字！");
    return false;
  	}
  
  	url="search_keywords.php";
  	document.FormSearch5.action = url;
	//pfclick('','?tracelog='+ keyword +'&traceF='+ document.FormSearch5.traceF.value +'');
  	document.FormSearch5.submit();
  }
}

function trim(inputString) {

if (typeof inputString != "string") { return inputString; }
var retValue = inputString;
var ch = retValue.substring(0, 1);
while (ch == " ") {

  retValue = retValue.substring(1, retValue.length);
  ch = retValue.substring(0, 1);
}
ch = retValue.substring(retValue.length-1, retValue.length);
while (ch == " ") {

 retValue = retValue.substring(0, retValue.length-1);
 ch = retValue.substring(retValue.length-1, retValue.length);
}
while (retValue.indexOf("  ") != -1) {

 retValue = retValue.substring(0, retValue.indexOf("  ")) + retValue.substring(retValue.indexOf("  ")+1, retValue.length);
}
return retValue;
}

function doClick(o){
	 o.className="newsearchinsider";
	 var j;
	 var id;
	 var e;
	 for(var i=1;i<=5;i++){
	   id ="v"+i;
	   j = document.getElementById(id);
	   e = document.getElementById("e"+i);
	   if(id != o.id){
	   	 j.className="newsearchinsidew";
	   	 e.style.visibility = "hidden";
	   }else{
			e.style.visibility = "visible";
	   }
	 }
	 
	var id = o.id+""; 
	var dd=id.substring(1,2);
	var curForm = document.getElementById("FormSearch"+dd);
	var inputv ;
	for(var i=1;i<=5;i++){
	var otherForm = document.getElementById("FormSearch"+i);
	var v = otherForm.keyword.value;
	if(v != "" && v.substring(0,3) !="请输入" ){
		inputv = v;
	}
	if( v.substring(0,3) != "请输入" )
	   otherForm.keyword.value="";
	}
	
	if(inputv != null && inputv != "")
		 	curForm.keyword.value=inputv;
}
function doOut(o){
 
}

/*以下为2007-3-7增加的内容*/
var domainName = "www.e-farm.cn";
var cookieName = "offerId";
var prefix = "";
var bgColor = "FEEEE0";
var sid=new Array();

  var categoryId = 10041;
  
  var c = getCookie("categoryId");
  if (c == null || c == "null" ){
      addCookie("categoryId",categoryId); 
      if (categoryId !=null && categoryId!=""){
        clearCookie(cookieName);    
      }
  }else if(c !=categoryId){
      clearCookie("categoryId");  
      clearCookie(cookieName);
  }
     
   function addCookie(name,value) {
     value = value+prefix;
    if(categoryId =="")
        return;
    var Days = 30; //此 cookie 将被保存 30 天
	var exp  = new Date();    //new Date("December 31, 9998");
	exp.setTime(exp.getTime() + Days*24*60*60*1000);
	document.cookie = name + "=" + value +"; expire=" + exp.toGMTString();
   }
   
  function clearCookie(name) {
	  var value = "null";
	  var exp  = new Date();    //new Date("December 31, 9998");
	  exp.setTime(exp.getTime() - 1);
	  cookieValue= name + "=" + value + "; expire=" + exp.toGMTString();
	  document.cookie = cookieValue;
  }

  function addOfferId(arg) {
	arg  = arg + prefix;
	
	if(hasOfferId(arg)) {
		return;
	}
	if(arg == "") {
		return;
	}
	value = getCookie(cookieName);
	if(value == null || value == "null" ) {
		value = arg ;
	} else {
	   value=value+"x"+ arg;
	}
	var Days = 30; //此 cookie 将被保存 30 天
	var exp  = new Date();    //new Date("December 31, 9998");
	exp.setTime(exp.getTime() + Days*24*60*60*1000);
	cookieValue = cookieName + "=" + value + "; expire=" + exp.toGMTString();
	document.cookie = cookieValue;
  }

  function delOfferId(arg) {
	arg = arg + prefix;
	if(!hasOfferId(arg)) {
	   Del(arg);
	   //return;
	}

	value = getCookie(cookieName);
	var offerIds = stringToArray(value);
	var len = offerIds.length;
	var result = "";
	var counter = 0;
	for(var i=0;i<len;i++) {
	  if(offerIds[i] != arg) {
			if(counter == 0) {
			  result = offerIds[i];
			} else {
			  result = result + "x" + offerIds[i];
			}
			counter++;
	  }
	}
	var exp  = new Date();    //new Date("December 31, 9998");
	 exp.setTime(exp.getTime() - 1);
	cookieValue = cookieName + "=" + result + "; expire=" + exp.toGMTString();
	document.cookie = cookieValue;
  }
  
  function Del(arg)
  {
    value = getCookie("BrowseProduct");
    //alert(value+"="+arg);
	var offerIds = stringToArray1(value);
	//alert(offerIds);
	var len = offerIds.length;
	var result = "";
	var counter = 0;
	for(var i=0;i<len;i++) {
	  if(offerIds[i] != arg ) {
			if(counter == 0) {
			  result = offerIds[i];
			} else {
			  result = result + "," + offerIds[i];
			}
			counter++;
	  }
	}
	//alert(result);
	var exp  = new Date();    //new Date("December 31, 9998");
	 exp.setTime(exp.getTime() - 1);
	cookieValue = "BrowseProduct" + "=" + result + "; expire=" + exp.toGMTString();
	document.cookie = cookieValue;
  }
 
 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 www_helpor_net(j);
		i=document.cookie.indexOf(" ",i)+1;if(i==0)
			break;
	}
	return null;
  }

  function www_helpor_net(offset) {
	  var endstr=document.cookie.indexOf(";",offset);
	  if(endstr==-1)
	  endstr=document.cookie.length;
	  return unescape(document.cookie.substring(offset,endstr));
  }

  function hasOfferId(arg) {
	var value = getCookie(cookieName);
	if(value == null || value == "null" || value.indexOf(arg) == -1 ) {
		return false;
	} else {
		return true;
	}
  }

  function getOfferIdCount() {

	value = getCookie(cookieName);
	if(value == null || value == 'null') {
	  return 0;
	}
	
	var count = 1;
	while(value.indexOf("x") != -1) {
	   var position = value.indexOf("x");
	   var len = value.length;
	   value =  value.substring(position+1,len);
	   count++;
	}
	return count;
  }

  function stringToArray(str) {
	   var temp = str;
	   var strArray = new Array();
	   var count = 0;
	   while(temp.indexOf("x") != -1) {

		 var position = temp.indexOf("x");
		 
		 strArray[count] = temp.substring(0,position);
		 //alert( strArray[count] );
		 count++;
		 var len = temp.length;
		 temp =  temp.substring(position+1,len);

	   }
	   strArray[count] = temp;
	   //alert(strArray[count]);
	   return strArray;
  }
  
   function stringToArray1(str) {
	   var temp = str;
	   var strArray = new Array();
	   var count = 0;
	   while(temp.indexOf(",") != -1) {

		 var position = temp.indexOf(",");
		 
		 strArray[count] = temp.substring(0,position);
		 //alert( strArray[count] );
		 count++;
		 var len = temp.length;
		 temp =  temp.substring(position+1,len);

	   }
	   strArray[count] = temp;
	   //alert(strArray[count]);
	   return strArray;
  }

  function clickcompareBox(id,box) {
	if(box.checked){
	  if(getOfferIdCount()>=5){
		alert('您已经选择了5条供应信息，候选供应信息不能超过5个');
		box.checked=false;
	  }else{
		addOfferId(id);
		//var countId = box.id.substring("compareBox".length,box.id.length);
		
		//var trTag = document.getElementById("compareColor"+countId);
		//trTag.style.background=bgColor;
		
	  }
	} else {
	  delOfferId(id);
	 // var countId = box.id.substring("compareBox".length,box.id.length);
	  
	 // var trTag = document.getElementById("compareColor"+countId);
	//	trTag.style.background="ffffff";
	  
	}
  }

/*
商机对比
*/
  function doCompare(){
    if(getOfferIdCount()<=1){
        alert('请至少选择2条信息进行对比!');
    }else{      
		window.open('compare.aspx');
    }
  }

  function cleanCookie() {
	if(confirm("您确认执行清空操作吗？")){
	  var value = "null";
	  var exp  = new Date();    //new Date("December 31, 9998");
	 exp.setTime(exp.getTime() - 1);
	  cookieValue= cookieName + "=" + value + "; expire=" + exp.toGMTString();
	  document.cookie = cookieValue;
	  for(var i=1;i<=30;i++){
		var elem = document.getElementById("compareBox"+i);
		if(elem != null && elem.checked){
		elem.checked = false;
		 //if(i <= 3){
	     //   return;
	     // }
		  elem = document.getElementById("compareColor"+i);
			elem.style.background="ffffff";
		}
	  }
	}
  }
  
    ;
  for(var i = 1;i < 31 ;i++){
	var cpbox = document.getElementById("compareBox"+i);
	var cpcolor = document.getElementById("compareColor"+i);
	if(cpbox!= null){
	  if(hasOfferId(cpbox.name)){
		  cpbox.checked = true;
		  if(cpcolor != null){
		  //if(cpcolor != null && i > 3){
			cpcolor.style.background= bgColor;
		  }
	  }else{
		  cpbox.checked = false;
	  }
	}
  }
  
<!--当800分辨率下offer不显示参数列-->
var screenwidth = screen.width;
if(screenwidth == 800){
		for(i=0;i<33;i++){
		var e = document.getElementById("select_cs_"+i);
		if(e){e.style.display = "none"; }
	}
}

if (ie4||ns6)
document.onclick=hidemenu