function setCookie(name, value) {
	document.cookie = name + "=" + escape(value) + "; path=/";
}


function updateCookie(cookieName, name, value){
	var cookieVal = getCookie(cookieName);
	var theValue = name + "=" + value;

	if(cookieVal == null){
		setCookie(cookieName,theValue);
	}else{
		var theArr = cookieVal.split("||");
		var found = false;
		for(var i=0; (i<theArr.length) && !found; i++){
			if( theArr[i].substring(0,theArr[i].indexOf("="))== name ){
				theArr[i] = theValue;
				found = true;
			}
		}
		if(found)
			setCookie(cookieName, theArr.join("||"));
		else
			setCookie(cookieName, cookieVal + "||" + theValue);
	}
}

function extractCookie(cookieName, name){
	var cookieVal = getCookie(cookieName);
	if(cookieVal != null){
		var theArr = cookieVal.split("||");
		for(var i=0; i<theArr.length; i++){
			var thePair = theArr[i].split("=");
			if( thePair[0] == name ){
				return thePair[1];
			}
		}
	}
	return null;
}

function dropFromCookie(cookieName, name){
	var cookieVal = getCookie(cookieName);
	if(cookieVal != null){
		var found = false;
		var theArr = cookieVal.split("||");
		for(var i=0; (i<theArr.length) && !found; i++){
			if( theArr[i].substring(0,theArr[i].indexOf("="))== name ){
				theArr[i] = "";
				found = true;
			}
		}
		if(found)
			setCookie(cookieName, theArr.join("||"));
	}
}

function getCookieVal(offset) {
	   var endstr = document.cookie.indexOf (";", offset);
	   if (endstr == -1) endstr = document.cookie.length;
	   return unescape (document.cookie.substring(offset, endstr));
}

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 getCookieVal(j);
		      i = document.cookie.indexOf(" ", i) + 1;
		      if (i == 0) break;
	   }
	   return null;
}

function deleteCookie (name) {
	   var ThreeDays = 3 * 24 * 60 * 60 * 1000;  
	   var exp = new Date();  
	   exp.setTime (exp.getTime() - ThreeDays);  
	   var cval = getCookie (name);  
	   document.cookie = name + "=null; path=/moims; expires=" + exp.toGMTString();
}