  function setCookie(name, value){
    if (testcookie()) {
      var exp = new Date();
      var sixmonthslater = exp.getTime() + (180 * 24 * 60 * 60 * 1000);
      exp.setTime(sixmonthslater);
      document.cookie = name + "=" + escape(value) + "; expires=" + exp.toGMTString() + "; path=/;";
    } 
  }
  
  function getCookie(strCookieName) {
    if (testcookie()) {
      var pos = document.cookie.indexOf(strCookieName + '=');
      if (pos != -1) {
        var startpos = pos + strCookieName.length + 1;
        var endpos = document.cookie.indexOf(";",startpos);
        if(endpos == -1){
	  endpos = document.cookie.length;
        }
        var cookieValue = unescape(document.cookie.substring(startpos, endpos));
        return cookieValue;
      } else {
       return '';
      }
    }  
  }
  
  function replacedata(str1,str2,str3) {
    var sArray;
    var s = "";
    if(str1 != "" && str2 != ""){
      sArray = str1.split(str2);
      if(sArray.length > 0) {
        for(var i=0;i<sArray.length;i++){
          s = s + sArray[i] 
          if(i != sArray.length - 1) {
	    s = s + str3;
	  }  
	}
	return s;
      }else{
        return str1;
      }
    }else{ 
      return str1;
    }
  }
  
  function testcookie() {
    var a;
    window.document.cookie = "test";
    a = window.document.cookie;
    window.document.cookie = "";
    if(a.length == 0){
      alert("您的瀏覽器不支援Cookie，無法使用本服務!!");
      return false;
    }else{
      return true;
    }
  }
  
  function addintojobcar(JOBID) {
	  if (JOBID.length != 0) {
	    var s1;
	    var addok;
	    s1 = getCookie("WEBJOBID");
	    sArray = s1.split(",");
	    addok = true;
	    if(sArray.length > 0) {
	      for(var i=0;i<sArray.length;i++){
	        if(sArray[i] == "'" + JOBID + "'") {
	          addok = false;
	        }  
	      }
	    }	
	    if (addok == true) {
	      if (s1.length != 0) {
	        s1 = s1 + ",";
	      }
	      s1 = s1 + "'" + JOBID + "'";
	      setCookie("WEBJOBID", s1);
	      alert("這個商品加入購物車完畢");
	    }else{
	      alert("這個商品已經存在購物車中，所以不加入");
	    }
	  }else{  
	    alert("沒有這個商品喔");
	  }
  }
  
  testcookie();
  
