window.onload = function(){
	checkCookie();
	checkBrowser();
}

function setCookie(name, value) { // use: setCookie("name", value);
    var today = new Date();
    var expiry = new Date(today.getTime() + 28 * 24 * 60 * 60 * 1000); // plus 28 days

    document.cookie=name + "=" + escape(value) + "; expires=" + expiry.toGMTString();
}

function getCookie(name) { // use: getCookie("name");
    var index = document.cookie.indexOf(name + "=");
    if (index == -1) return "nothing";
    index = document.cookie.indexOf("=", index) + 1;
    var endstr = document.cookie.indexOf(";", index);
    if (endstr == -1) endstr = document.cookie.length;
    return unescape(document.cookie.substring(index, endstr));
 }
 
 // Deal with turning Movie file on and off
function checkCookie() {
	if(getCookie("TradersHedgeIntro")=="off"){
		turnOff();
	} else {
		if (document.getElementById('movie'))
			document.getElementById('movie').style.display = 'block';
		if (document.getElementById('viewMovieLink'))
			document.getElementById('viewMovieLink').style.display = 'none';
		if (document.getElementById('viewMovieLinkTurnOff'))
			document.getElementById('viewMovieLinkTurnOff').style.display = 'block';
	}
}

function turnOn() {
	// Show the movie and swap movie link graphic
	var turnOn = "on";
	if (document.getElementById('movie'))
		document.getElementById('movie').style.display = 'block';
	if (document.getElementById('viewMovieLink'))
		document.getElementById('viewMovieLink').style.display = 'none';
	if (document.getElementById('viewMovieLinkTurnOff'))
		document.getElementById('viewMovieLinkTurnOff').style.display = 'block';

	setCookie("TradersHedgeIntro",turnOn);
	window.location.reload();
}

function turnOff() {
	// Hide the movie and swap movie link graphic
	var turnOff = "off";
	if (document.getElementById('movie'))
		document.getElementById('movie').style.display = 'none';
	if (document.getElementById('viewMovieLink'))
		document.getElementById('viewMovieLink').style.display = 'block';
	if (document.getElementById('viewMovieLinkTurnOff'))
		document.getElementById('viewMovieLinkTurnOff').style.display = 'none';
	setCookie("TradersHedgeIntro",turnOff);
}

/**
 * Sets a Cookie with the given name and value.
 *
 * name       Name of the cookie
 * value      Value of the cookie
 * [expires]  Expiration date of the cookie (default: end of current session)
 * [path]     Path where the cookie is valid (default: path of calling document)
 * [domain]   Domain where the cookie is valid
 *              (default: domain of calling document)
 * [secure]   Boolean value indicating if the cookie transmission requires a
 *              secure transmission
 */

/** Taken out to use the simpler following function to Set the Cookie
function setCookie(name, value, expires, path, domain, secure)
{
    document.cookie= name + "=" + escape(value) +
        ((expires) ? "; expires=" + expires : "") +
        ((path) ? "; path=" + path : "") +
        ((domain) ? "; domain=" + domain : "") +
        ((secure) ? "; secure" : "");
}*/


/**
 * Gets the value of the specified cookie.
 *
 * name  Name of the desired cookie.
 *
 * Returns a string containing value of specified cookie,
 *   or null if cookie does not exist.
 */
/** Taken out to use simpler version by Nathan Walker
function getCookie(name)
{
    var dc = document.cookie;
    var prefix = name + "=";
    var begin = dc.indexOf("; " + prefix);
    if (begin == -1)
    {
        begin = dc.indexOf(prefix);
        if (begin != 0) return null;
    }
    else
    {
        begin += 2;
    }
    var end = document.cookie.indexOf(";", begin);
    if (end == -1)
    {
        end = dc.length;
    }
    return unescape(dc.substring(begin + prefix.length, end));
}*/

/**
 * Deletes the specified cookie.
 *
 * name      name of the cookie
 * [path]    path of the cookie (must be same as path used to create cookie)
 * [domain]  domain of the cookie (must be same as domain used to create cookie)
 */
function deleteCookie(name, path, domain)
{
    if (getCookie(name))
    {
        document.cookie = name + "=" + 
            ((path) ? "; path=" + path : "") +
            ((domain) ? "; domain=" + domain : "") +
            "; expires=Thu, 01-Jan-70 00:00:01 GMT";
    }
}

