﻿var COOKIENAME = "myCity";  // the cookie that will hold the city name
var EXPIREDAYS = 14;        // "myCity" cookie will expire in 2 weeks

function hoverlink(link, hover) 
{
	if (hover == true)
	{
		link.className = "homeStory-hover";
		window.status = link.id;
	}
    else
    {
		link.className = "homeStory";
		window.status = "";
	}
}
function hoverlinkfooter(link, hover) 
{
	if (hover == true)
	{
		link.className = "homeStoryFooter-hover";
		window.status = link.id;
	}
    else
    {
		link.className = "homeStoryFooter";
		window.status = "";
	}
}
// sets the user's preferred City
function SetCityCookie(cityName)
{
    if (GetCookie(COOKIENAME) != "")
        DeleteCookie(COOKIENAME);

    var expiryDate = new Date();
    expiryDate.setDate(expiryDate.getDate() + EXPIREDAYS);
    document.cookie = COOKIENAME + '=' + escape(cityName) + ";expires=" + expiryDate.toGMTString();
}

// get the cookie, if it exists
function GetCookie(cookieName)
{
    var myCity     = "", 
        cookies    = document.cookie,
        startIndex = cookies.indexOf(COOKIENAME),
        endIndex;

    if (startIndex != -1)
    {
        startIndex += (COOKIENAME.length + 1);
        endIndex = cookies.indexOf(';',startIndex);
        myCity = (endIndex == -1 ? cookies.substring(startIndex) : cookies.substring(startIndex, endIndex));
    }
    
    return myCity;
}

// remove the cookie
function DeleteCookie(cookieName)
{
    var expiryDate = new Date();
    expiryDate.setDate(expiryDate.getDate() - 1);
    document.cookie = cookieName += "=;expires=" + expiryDate.toGMTString();
}

// check if a cookie has been set for this user; if so
// redirect the user to that city's page
function CheckCityRedirect()
{
    var myCity = GetCookie(COOKIENAME);
    if (myCity != "")
        window.location = "/" + myCity;
}
function CheckCityRedirect(rurl)
{
    var myCity = GetCookie(COOKIENAME);
    if (myCity != "")
        window.location = "/" + myCity+rurl;
}
function ChangeCity()
{
    DeleteCookie(COOKIENAME);
    window.location = "/";
}
