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("||");
		var arrLen = theArr.length;
		for(var i=0; (i<arrLen) && !found; i++){
			if( theArr[i].substring(0,theArr[i].indexOf("="))== name ){
				found = true;
				for (var j=i; j<(arrLen-1); j++){
					theArr[j] = theArr[j+1];
				}
				theArr.length = arrLen -1;
			}
		}
		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=/; expires=" + exp.toGMTString();
}

function strReplace(theStr, findTxt, replaceTxt) {
	if(findTxt == replaceTxt)
		return theStr;

	var pos = 0;
	var len = findTxt.length;
	pos = theStr.indexOf(findTxt);
	while (pos != -1) {
		preStr = theStr.substring(0, pos);
		postStr = theStr.substring(pos+len,theStr.length);
		theStr = preStr + replaceTxt + postStr;
		pos = theStr.indexOf(findTxt);
	}
	return theStr
}