cookieName = "offerId";
  domainName = ".alibaba.com";
  prefix = "";
  bgColor = "FEEEE0";
  
  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+","+ arg;
    }
	cookieValue = cookieName + "=" + value + ";path=/;" + "domain="+domainName;
	document.cookie = cookieValue;
    //alert(document.cookie);
  }

  function delOfferId(arg) {
    arg = arg + prefix;

    if(!hasOfferId(arg)) {
       alert("要删除的商机不存在");
       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 + "," + offerIds[i];
	  	    }
	  	    counter++;
	  }
	}
	cookieValue = cookieName + "=" + result + ";path=/;" + "domain="+domainName;
	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);
	//alert(value + " " + value.indexOf(arg));
	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(",") != -1) {
       var position = value.indexOf(",");
       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(",") != -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()>=20){
        alert('您已经选择了20个供应商，候选供应商不能超过20个');
        box.checked=false;
      }else{
        addOfferId(id);
        var countId = box.id.substring("compareBox".length,box.id.length);
        var trTag = document.getElementById("compareColor"+countId);
        trTag.bgColor=bgColor;
      }
    } else {
      delOfferId(id);
      var countId = box.id.substring("compareBox".length,box.id.length);
      var trTag = document.getElementById("compareColor"+countId);
      if(countId%2!= 0){
        trTag.bgColor="ffffff";
      }else{
        trTag.bgColor="F6F6F6";
      }
    }
  }
  
  function cleanCookie() {
    if(confirm("您确认执行清空操作吗？")){
      var value = "null";
      cookieValue= cookieName + "=" + value + ";path=/;" + "domain="+domainName;
      document.cookie = cookieValue;
      for(var i=1;i<=40;i++){
        var elem = document.getElementById("compareBox"+i);
        if(elem != null && elem.checked){
          elem.checked = false;
          elem = document.getElementById("compareColor"+i);
          if(i%2 != 0){
            elem.bgColor="ffffff";
          }else{
            elem.bgColor="F6F6F6";
          }
        }
      }
	}
  }
  
    ;
  for(var i = 1;i < 41;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){
            cpcolor.bgColor= bgColor;
          }
      }else{
          cpbox.checked = false;
      }
    }
  }