// Cookies for webaxy
function getCookieHash(cookieName) {
	var search = cookieName + "=";
	var valueOffset = 0;
	var valueEnd = 0;
	var cookieValue='';
	var cookie = document.cookie;
	var cookieHash= new Object();
	valueOffset = cookie.indexOf(search);
	if (valueOffset != -1){// if cookie exists 
		valueOffset += search.length;// set index of beginning of value
		valueEnd = cookie.indexOf(";", valueOffset);// set index of end of cookie value
		if (valueEnd == -1) {valueEnd = cookie.length;}
		cookieValue = decodeURIComponent(cookie.substring(valueOffset, valueEnd));
	}
	if(cookieValue !=''){
		arrTmp=cookieValue.split('&');
		for(var i=0; i<arrTmp.length; i+=2){cookieHash[arrTmp[i]]=arrTmp[i+1]?arrTmp[i+1]:'';}
		return cookieHash;
	}
	else{return '';}
}

//=============================================================================
// Function Name: Name
// Function Parameter: <Parameter Name>:<parameter description>
// Function Parameter: 
// Function Description: <description>
// Function Results: <return value if any>
//=============================================================================
function clearAllCookies() {
	if (!document.cookie) {
		return;
	}
	var allc = document.cookie.toString().split(";");
	for (var a=0; a<allc.length; a++) {
		allc[a] = allc[a].replace(/=.*/,"");
		clearCookie(allc[a]);
	}
}

//------------------------------------------------------------
function clearCookie(cookieName) {
	document.cookie  = cookieName+"=null; path=/; expires=Wed, 16 Jan 2008 01:00:00 UTC";
}
//----------------------------------------------------------------------
function set_cookie(cname,cvalue,expire) {
	document.cookie  = cname+"="+encodeURIComponent(cvalue)+"; path=/"+((expire==null) ? "" : (";expires="+expire.toGMTString()));
}
//-----------------------------
function get_cookie(Name) {
  		var search = Name + "=";
  		if (document.cookie.length > 0) { // if there are any cookies
			 offset = document.cookie.indexOf(search);
 			 if (offset != -1) { // if cookie exists 
    			offset += search.length ;  // set index of beginning of value
   				end = document.cookie.indexOf(";", offset); // set index of end of cookie value
    			if (end == -1) 
       					end = document.cookie.length;
    			return decodeURIComponent(document.cookie.substring(offset, end))
		 	}
  		}
  		return null;
}
//------------------------------
function checkCookie(cname) {
	var gc = get_cookie(cname);
	if (!gc)
		return "";
	return gc;
}	
