
/* Last Modified $Date: 7/20/07 9:31a $ by $Author: Ksirota $ (Version history stored in Source Control) */

// set up browser detect vars
var isNS4 = (navigator.appName.indexOf("Netscape") != -1 && navigator.appVersion.charAt(0) == "4");
var isMOZ = (navigator.appName.indexOf("Netscape") != -1 && parseInt(navigator.appVersion.charAt(0)) >= 5);
var isIE = (navigator.appName.indexOf("Microsoft") != -1);

function openWindow(url, name, options) {
	var win = window.open(url,name,options);
    if (win != null) {
        win.focus();
    }
    return win;
}

function openSizedWindow(url, w, h, name) {
	if (!name) name = 'newWindow';
	var win = window.open(url,name,'toolbar=no,menubar=no,scrollbars=no,resizable=no,width=' + w + ',height=' + h);
    if (win != null) {
        win.focus();
    }
    return win;
}

function openReSizableWindow(url, w, h, name) {
	if (!name) name = 'newWindow';
	var win = window.open(url,name,'toolbar=no,menubar=no,resizable=yes,scrollbars=yes,width=' + w + ',height=' + h);
    if (win != null) {
        win.focus();
    }
    return win;
}

function openSizedWindowWithSB(url, w, h, name) {
	if (!name) name = 'newWindow';
	var win = window.open(url,name,'toolbar=no,menubar=no,resizable=no,scrollbars=yes,width=' + w + ',height=' + h);
    if (win != null) {
        win.focus();
    }
    return win;
}

function jumpTo(selectBox) {
	var url = selectBox.options[selectBox.selectedIndex].value;
	if (url != "") window.location.href = url;
}

function smWindow(url, name) {
    if (!name) name = 'newWindow';
    openReSizableWindow(url, 480, 220, name);
}

function openLocation(clubNumber) {
    openReSizableWindow('/locations/clubs/' + clubNumber + '.shtml', 500, 600, 'club' + clubNumber);
}

function gotoPartner(partnerURL) {
    var returnURL = escape(window.location);
    openSizedWindowWithSB('/services/exit_pop.shtml?returnURL=' + returnURL, 480, 220, 'partnerWarning');
    return true;
}

function openFAQs(url, name) {
	return openReSizableWindow(url, 466, 490, name);
}

function pinShopNav(shopPin) {
	var shopNavElem = bgGetElementById(shopPin);
	if (shopNavElem != null) {
		shopNavElem.className = "pin";
	}
}

/**
 * This function returns a random number in the specified range
 *
 * @param	range- max integer value of the random number
 */
function pickRandom(range) {
	if (Math.random) {
		return Math.round(Math.random() * (range-1));
	}
	else {
		var now = new Date();
		return (now.getTime() / 1000) % range;
	}
}

/** Return the cookie value by its name. Returns null if no such cookie found.*/
function getCookie(cookieName)
{
	var results = document.cookie.match(cookieName + '=(.*?)(;|$)');

	if( results )
	{
		return (unescape(results[1]));
	}
  	else
  	{
    	return null;
    }
}

function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

/** find object on the page, by ID */
function bgGetElementById(id) {
	var elem = null;
	if (document.all) {
		elem = document.all[id];
	}
	else if (document.getElementById) {
		elem = document.getElementById(id);
	}
	return elem;
}


/** DEPRECATED FUNCTIONS **/

function deprecated() {
    alert("ERROR: The link you have clicked is using a deprecated function, please report this to the webmaster.");
}
function whatRewards() {
	deprecated();
}
function whatFHM() {
	deprecated();
}
function whatSupplemental() {
	deprecated();
}
function whatCID() {
	deprecated();
}
function changeName() {
    deprecated();
}

