///////////////////////////////////////////////////////////////////////////////
// FUNC: queryStringValue
// DESC: Returns a query string parameter value, given the parameter name.
// ARGS: name - the name of the query string parameter
///////////////////////////////////////////////////////////////////////////////
function queryStringValue(name)
{
    var queryString = "";
    var startIndex = 0;
    var endIndex = 0;
    var value = "";
    
    name = name.toLowerCase();
    queryString = location.search.toLowerCase() + "&";
    
    if (queryString.length > 0)
    {
        if(queryString.indexOf(name + "=") > -1)
        {
            startIndex = queryString.indexOf(name + "=") + name.length + 1;
            endIndex = queryString.indexOf("&",startIndex);
            value = queryString.substring(startIndex,endIndex);        
        }
        return value;
    }
    
} //end function queryStringValue


///////////////////////////////////////////////////////////////////////////////
// FUNC: cookieWrite
// DESC: Writes a cookie using javascript.
// ARGS: name - the name of the cookie
//       value - the value of the cookie
//       daysCount - the days till expiration
///////////////////////////////////////////////////////////////////////////////
function cookieWrite(name,value,daysCount)
{
	if (daysCount)
	{
		var expiresDate = new Date();
		expiresDate.setTime(expiresDate.getTime()+(daysCount*24*60*60*1000));
		var expiresText = "; expires=" + expiresDate.toGMTString();
	}
	else 
	{
	    var expiresText = "";
	}    
	document.cookie = name + "=" + value + expiresText + "; path=/";
} //end function cookieWrite


///////////////////////////////////////////////////////////////////////////////
// FUNC: cookieRead
// DESC: Reads a cookie using javascript.
// ARGS: name - the name of the cookie
// RETV: the value of the cookie
///////////////////////////////////////////////////////////////////////////////
function cookieRead(name)
{
	var nameText = name + "=";
	var chars = document.cookie.split(';');
	for(var i=0;i < chars.length;i++)
	{
		var c = chars[i];
		while (c.charAt(0)==' ')
		{
		    c = c.substring(1,c.length);
		}
		if (c.indexOf(nameText) == 0) 
		{
		    return c.substring(nameText.length,c.length);
		}
	}
	return null;
} //end function cookieRead

///////////////////////////////////////////////////////////////////////////////
// FUNC: MMCCookieWrite
// DESC: Reads the query string for MMC parameter and writes a 
//       cookie with the value
///////////////////////////////////////////////////////////////////////////////
function MMCCookieWrite()
{
    var mmc = unescape(queryStringValue("cm_mmc"));
    if (mmc != "") 
    {
        if (cookieRead("MMC") == null)
                cookieWrite("MMC",mmc,365);
    }
} //function MMCCookieWrite


///////////////////////////////////////////////////////////////////////////////
// FUNC: trackingIframe
// DESC: Creates an iframe with the appropriate url and query string
///////////////////////////////////////////////////////////////////////////////
function trackingIframe(trackingMode)
{
    var queryString = location.search + "xx=1"
    queryString = queryString.substring(1)
    var iframe = "<iframe src='/401k/Utility/Tracking.asp?"
               + queryString + "&Referrer=" + escape(document.referrer) + "&Mode=" + trackingMode + "'"
               + " scrolling='no' width='10' height='10' frameborder='0'></iframe>";
    document.write(iframe);             
}

///////////////////////////////////////////////////////////////////////////////
// FUNC: currentDate
// DESC: Returns the current date as a string in the format: 1/2/2003
// RETV: The current date as a string
///////////////////////////////////////////////////////////////////////////////
function currentDate()
{
    var today = new Date();
    var month = today.getMonth() + 1;
    var day = today.getDate();
    var year = today.getFullYear();
    var slash = "/";
    return month + slash + day + slash + year;
    
}// end currentDate

///////////////////////////////////////////////////////////////////////////////
// FUNC: adActivityCookieWrite
// DESC: Writes a cookie called "AdActivity" with sub cookie names AdCodes, 
//       AdTypes, and ClickDates.  
// ARGS: adCode - a 5 char code that describes what it was that was seen. 
///////////////////////////////////////////////////////////////////////////////
function adActivityCookieWrite(adCode)
{    
    var adActivityValue = "";
    
    adActivityValue = "AdCodes=" + escape(adCode) 
                    + "&AdTypes=VIEW&ClickDates=" 
                    + escape(currentDate());
       
    cookieWrite("AdActivity",adActivityValue,365);
    
}// end adActivityCookieWrite