  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;
    }
  }