	//
	//Need to define this variable in the page that uses this script
	//var cName="porkmodel_model1"; // cookie name
	//
	// usage in forms:
	//<input type="button" value="Save To Cookie" onClick="saveToCookie(this.parentNode)"/> 
    //<input type="button" value="Load From Cookie" onClick="loadFromCookie(this.parentNode)"/>
	//

	function saveToCookie(f){
	   cValue = "";
	   for(var i=0; i<f.length; i++){
	      if (i != 0) cValue += "??"; // separator 
	      cValue += f[i].value;
	   }
	   cExp = new Date();
	   cExp.setYear(cExp.getYear()+1);
	   document.cookie = cName+"="+escape(cValue)+";"+cExp;
	   alert("Form data have been saved to cookie.");
	}
	function loadFromCookie(f){
	   cookies = document.cookie.split(';');
	   cValue="";
	   for(var i=0; i<cookies.length; i++){
	      var c = unescape(trim(cookies[i]));
	      //alert(cName.length + ":" + c.substring(0, cName.length));
	      if (c.indexOf(cName) >= 0){
	         cValue = unescape(c.substring(cName.length+1,c.length));
	         break;
	      }
	   }
	   if (cValue==""){
	    alert("Cookie not found.");
	   } else {
	   	values = cValue.split("??");
	   	for(var i=0; i<values.length; i++){
	        f[i].value = values[i];
	   	}
	   	alert("Succesfully loaded data saved in cookie.");
	   }
	}

	function trim(str, chars) {
    	return ltrim(rtrim(str, chars), chars);
	}

	function ltrim(str, chars) {
    	chars = chars || "\\s";
    	return str.replace(new RegExp("^[" + chars + "]+", "g"), "");
	}	

	function rtrim(str, chars) {
    	chars = chars || "\\s";
    	return str.replace(new RegExp("[" + chars + "]+$", "g"), "");
	}