function MqCookies(blnWriteAltPaths)
{
	var arrCookies;
	var m_strMainVD="";
	var m_blnWriteAltPaths=true;
    
    var MAIN_COOKIE_NAME="MqMain";
	var REG_COOKIE_POSTFIX="1";
	var LCASE_COOKIE_POSTFIX="2";
	
    var m_strMainCookieValue="";
    var m_strMainCookieName="";
    
    var COOKIE_PROP_VAL_DELIM="=";
    var COOKIE_PROPERTY_DELIM="; ";
    
    var objMqStr=g_MqRef.MqStr;
		
	if (typeof(blnWriteAltPaths)!="undefined"){
		m_blnWriteAltPaths=blnWriteAltPaths;
	}
  
	arrCookies=new Array();

	function getCookie(strCookieName)
	{
		var strReturn=isCached(strCookieName);
		
		if (!strReturn){
			strReturn=objMqStr.MqDecodeURIComponent(getCookieValue(objMqStr.MqEncodeURIComponent(strCookieName)));	
			writeToCache(strCookieName,strReturn);
		}
		
		return strReturn;
	}
	
	function setCookie(strCookieName,strValue,intExpireSecs)
	{
		var blnReturn;
		var expire = new Date();
		
		var strCookieExpireDate=GetCookieExpiryDate(intExpireSecs, expire);
		
		var strVirtualDir=GetVirtualDirName(this);

				
		var strEncodedCookieName=objMqStr.MqEncodeURIComponent(strCookieName);
		var strEncodedCookieValue=objMqStr.MqEncodeURIComponent(strValue);

		SetDocumentCookie(strEncodedCookieName, strEncodedCookieValue, strCookieExpireDate, expire, strVirtualDir);

		if (m_blnWriteAltPaths){
			if(strVirtualDir!=strVirtualDir.toLowerCase()){
				SetDocumentCookie(strEncodedCookieName, strEncodedCookieValue, strCookieExpireDate, expire, strVirtualDir.toLowerCase());
			}
		}
    
		if (isCached(strCookieName)){
			blnReturn=updateCache(strCookieName,strValue);
		}else{
			blnReturn=writeToCache(strCookieName,strValue);
		}
		
		return blnReturn;
	}

	function GetCookieProp(strMainCookieName, strPropName)
	{
		var strReturn;
		
		strReturn=GetCookieValueFromString(strPropName, COOKIE_PROP_VAL_DELIM, objMqStr.MqDecodeURIComponent(GetMainCookieValue(strMainCookieName)), COOKIE_PROPERTY_DELIM)
		
		//strReturn=objMqStr.MqDecodeURIComponent(strReturn);	
		
		if(strReturn!=""){
			strReturn=objMqStr.MqDecodeURIComponent(strReturn);
		}
		return strReturn;
	}
	
	function SetCookieProp(strMainCookieName, strPropName, strPropValue, intExpireSecs)
	{
		var expire = new Date();
		
		var strCookieExpireDate=GetCookieExpiryDate(intExpireSecs, expire);
		
		var strVirtualDir=GetVirtualDirName(this);
		
		var strEncodedPropName=objMqStr.MqEncodeURIComponent(strPropName);
		var strEncodedPropValue=objMqStr.MqEncodeURIComponent(strPropValue);
		
		var strMainCookieValue=AddPropertyToMainCookieString(strMainCookieName, strEncodedPropName, strEncodedPropValue);
				
		m_strMainCookieValue=strMainCookieValue;

		SetDocumentCookie(GetMainCookieName() + REG_COOKIE_POSTFIX, strMainCookieValue, strCookieExpireDate, expire, strVirtualDir);

		if (m_blnWriteAltPaths){
			if(strVirtualDir!=strVirtualDir.toLowerCase()){
				SetDocumentCookie(GetMainCookieName() + LCASE_COOKIE_POSTFIX, strMainCookieValue, strCookieExpireDate, expire, strVirtualDir.toLowerCase());
			}
		}
	}
	
	//*************From Cookies.Inc File*********************
	
	//this function will register the cookies
	function registerCookie(name,value)
	{
	   this.setCookie(name, value);
	} 
	
	function CookiesEnabled()
	{
		if (navigator.appName == "Netscape" ){
			return true;
		}else{
			return window.navigator.cookieEnabled;
		}
	}
	
	function getFieldValue(fieldName, strToSearchIn)
	{
	    var varParsString = "";
	    var pos = strToSearchIn.indexOf(fieldName);
	    var pos2;

	    if (pos != -1){
			pos2 = strToSearchIn.indexOf("&", pos + fieldName.length + 1);
			if (pos2 != -1) {
				varParsString= strToSearchIn.substr(pos + fieldName.length + 1, pos2 - (pos + fieldName.length + 1));
				return (unescape(varParsString));
			}
		}else{
			return ("");
		}
	}
	
	function GetMainCookieName()
	{
		var strReturn;
		
		if(m_strMainCookieName=="" || typeof(m_strMainCookieName)=="undefined"){
			m_strMainCookieName=MAIN_COOKIE_NAME;
		}

		return m_strMainCookieName;
	}

	function SetMainCookieName(strName)
	{
		m_strMainCookieName=strName;
	}
	
	function SetMainCookieValue(strValue)
	{
		m_strMainCookieValue=strValue;
	}
	
	this.MainVD=m_strMainVD;
	this.getCookie=getCookie;
	this.setCookie=setCookie;
	this.registerCookie=registerCookie;
	this.CookiesEnabled=CookiesEnabled;
	this.getFieldValue=getFieldValue;
	this.GetMainCookieName=GetMainCookieName;
	this.SetMainCookieName=SetMainCookieName;
	this.GetCookieProp=GetCookieProp;
	this.SetCookieProp=SetCookieProp;
	this.SetMainCookieValue=SetMainCookieValue;
	
	//private
	function isCached(strName)
	{
		var strReturn;
		var intCount;
		
		strReturn=false;
		for(intCount=0;intCount<arrCookies.length;intCount++){
			if (arrCookies[intCount][0]==strName){
				strReturn=arrCookies[intCount][1];
			}
		}
		return strReturn;
	}
	
	function updateCache(strName,strValue)
	{
		var intCount;
		var blnReturn;
		
		blnReturn=false;
		for(intCount=0;intCount<arrCookies.length;intCount++){
			if (arrCookies[intCount][0]==strName){
				arrCookies[intCount][1]=strValue;
				blnReturn=true;
			}
		}
		return blnReturn;
	}

	function writeToCache(strName,strValue)
	{
		arrCookies[arrCookies.length]=[strName,strValue];	
		return true;
	}
	
	function getCookieValue(strName)
	{	
		var strReturn="";
		if(strName==objMqStr.MqEncodeURIComponent(GetMainCookieName())){
			strReturn=GetMainCookieValue(strName);
		}else{
			var strCookieString=document.cookie;
			strReturn=GetCookieValueFromString(strName, COOKIE_PROP_VAL_DELIM, strCookieString, COOKIE_PROPERTY_DELIM)
		}
		return strReturn;
	}

	function GetCookieValueFromString(strName, strPropValDelim, strCookieString, strPropertyDelim)
	{
		var lngFirstChar, lngLastChar;
		var strReturn="";
		
		strName+=strPropValDelim;
		
		lngFirstChar = strCookieString.indexOf(strName);

		if(lngFirstChar != -1){
			lngFirstChar += strName.length;
			lngLastChar = strCookieString.indexOf(strPropertyDelim, lngFirstChar);
	    	
	    	if(lngLastChar == -1){
	    		lngLastChar = strCookieString.length;
	    	}	
	    	strReturn=strCookieString.substring(lngFirstChar, lngLastChar);
		}

		return strReturn;
	}
	
	function GetMainCookieValue(strMainCookieName)
	{
		var strReturn="";

		if(m_strMainCookieValue==""){
			
			if(strMainCookieName=="" || typeof(strMainCookieName)=="undefined"){
				strMainCookieName=GetMainCookieName();
			}
		
			strReturn = getCookieValue(strMainCookieName + REG_COOKIE_POSTFIX);
		
			if (strReturn.length==0){
				strReturn = getCookieValue(strMainCookieName + LCASE_COOKIE_POSTFIX);
			}
						
			m_strMainCookieValue=strReturn;
		}else{
			strReturn=m_strMainCookieValue;
		}
		
		return strReturn;
	}
	
	function GetCookieExpiryDate(intExpireSecs, expire)
	{
		var today = new Date();
    
		if (isNaN(intExpireSecs)){
		    expire.setTime(today.getTime() + 1000*60*60*24*365);
		}else{
		    expire.setTime(today.getTime() + 1000*intExpireSecs);
		}
		return expire.toGMTString();
	}

	function GetVirtualDirName(objThis)
	{
		var strVirtualDir="";
		var strSlash="/";

		if (objThis.MainVD!=="") {
			strVirtualDir= objThis.MainVD;
		} else {
			strVirtualDir = window.location.pathname;
			if (strVirtualDir.indexOf(strSlash) === 0){ 
		        strVirtualDir = strVirtualDir.substring(strSlash.length, strVirtualDir.length);
		    }
		 	if (strVirtualDir.indexOf(strSlash) > 0){
		        strVirtualDir = strVirtualDir.substring(0, strVirtualDir.indexOf(strSlash));
		    }
		}	
		return strVirtualDir;	
	}
	
	function SetDocumentCookie(strCookieName, strCookieValue, strCookieExpireDate, expire, strPath)
	{
		document.cookie=strCookieName + COOKIE_PROP_VAL_DELIM + strCookieValue + ((expire == null) ? "" : ("; expires=" + strCookieExpireDate))+ ";Path=/" + strPath + "/";
	}
	
	function AddPropertyToMainCookieString(strMainCookieName, strEncodedPropertyName, strEncodedPropertyValue)
	{
		var strMainDocCookie=objMqStr.MqDecodeURIComponent(GetMainCookieValue(strMainCookieName));
			
		if(objMqStr.PropertyExists(strMainDocCookie, strEncodedPropertyName, COOKIE_PROPERTY_DELIM, COOKIE_PROP_VAL_DELIM)>=0){									
			strMainDocCookie=objMqStr.ReplacePropertyValue(strMainDocCookie, strEncodedPropertyName, strEncodedPropertyValue, COOKIE_PROPERTY_DELIM, COOKIE_PROP_VAL_DELIM); 
		}else{
			if(strMainDocCookie!=""){
				strMainDocCookie+=COOKIE_PROPERTY_DELIM;
			}
			strMainDocCookie+=strEncodedPropertyName + COOKIE_PROP_VAL_DELIM + strEncodedPropertyValue;
		}
		strMainDocCookie=objMqStr.MqEncodeURIComponent(strMainDocCookie);
		
		return strMainDocCookie;
	}
}