function popUpWin(thisUrl, thisName, theseParams) {
  remote = open(thisUrl, thisName, theseParams);
}
var remote = null;
function help(f, n, w, h, t) {
  remote = window.open("/helppopup.htm?tab=" + t + "&file=" + f, n, 'width=' + w + ',height=' + h + ',resizable=yes,scrollbars=yes,status=yes');
  if (window.focus) {
    remote.focus()
  }
  if (remote != null) {
    if (remote.opener == null) remote.opener = self;
    window.name = 'store';
  }
}
function change_parent(url) {
  parent.opener.location = url;
  parent.window.close();
}
function forgotPassword(thisUrl, thisName, theseParams) {
  remote = open(thisUrl, thisName, theseParams);
}
// 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 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 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;
    }
}

/** 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();
}

/**
 * SWFObject v1.5.1: Flash Player detection and embed - http://blog.deconcept.com/swfobject/
 *
 * SWFObject is (c) 2007 Geoff Stearns and is released under the MIT License:
 * http://www.opensource.org/licenses/mit-license.php
 *
 */
if(typeof deconcept == "undefined") var deconcept = {};
if(typeof deconcept.util == "undefined") deconcept.util = {};
if(typeof deconcept.SWFObjectUtil == "undefined") deconcept.SWFObjectUtil = {};
deconcept.SWFObject = function(swf, id, w, h, ver, c, quality, xiRedirectUrl, redirectUrl, detectKey) {
	if (!document.getElementById) { return; }
	this.DETECT_KEY = detectKey ? detectKey : 'detectflash';
	this.skipDetect = deconcept.util.getRequestParameter(this.DETECT_KEY);
	this.params = {};
	this.variables = {};
	this.attributes = [];
	if(swf) { this.setAttribute('swf', swf); }
	if(id) { this.setAttribute('id', id); }
	if(w) { this.setAttribute('width', w); }
	if(h) { this.setAttribute('height', h); }
	if(ver) { this.setAttribute('version', new deconcept.PlayerVersion(ver.toString().split("."))); }
	this.installedVer = deconcept.SWFObjectUtil.getPlayerVersion();
	if (!window.opera && document.all && this.installedVer.major > 7) {
		// only add the onunload cleanup if the Flash Player version supports External Interface and we are in IE
		// fixes bug in some fp9 versions see http://blog.deconcept.com/2006/07/28/swfobject-143-released/
		if (!deconcept.unloadSet) {
			deconcept.SWFObjectUtil.prepUnload = function() {
				__flash_unloadHandler = function(){};
				__flash_savedUnloadHandler = function(){};
				window.attachEvent("onunload", deconcept.SWFObjectUtil.cleanupSWFs);
			}
			window.attachEvent("onbeforeunload", deconcept.SWFObjectUtil.prepUnload);
			deconcept.unloadSet = true;
		}
	}
	if(c) { this.addParam('bgcolor', c); }
	var q = quality ? quality : 'high';
	this.addParam('quality', q);
	this.setAttribute('useExpressInstall', false);
	this.setAttribute('doExpressInstall', false);
	var xir = (xiRedirectUrl) ? xiRedirectUrl : window.location;
	this.setAttribute('xiRedirectUrl', xir);
	this.setAttribute('redirectUrl', '');
	if(redirectUrl) { this.setAttribute('redirectUrl', redirectUrl); }
}
deconcept.SWFObject.prototype = {
	useExpressInstall: function(path) {
		this.xiSWFPath = !path ? "expressinstall.swf" : path;
		this.setAttribute('useExpressInstall', true);
	},
	setAttribute: function(name, value){
		this.attributes[name] = value;
	},
	getAttribute: function(name){
		return this.attributes[name] || "";
	},
	addParam: function(name, value){
		this.params[name] = value;
	},
	getParams: function(){
		return this.params;
	},
	addVariable: function(name, value){
		this.variables[name] = value;
	},
	getVariable: function(name){
		return this.variables[name] || "";
	},
	getVariables: function(){
		return this.variables;
	},
	getVariablePairs: function(){
		var variablePairs = [];
		var key;
		var variables = this.getVariables();
		for(key in variables){
			variablePairs[variablePairs.length] = key +"="+ variables[key];
		}
		return variablePairs;
	},
	getSWFHTML: function() {
		var swfNode = "";
		if (navigator.plugins && navigator.mimeTypes && navigator.mimeTypes.length) { // netscape plugin architecture
			if (this.getAttribute("doExpressInstall")) {
				this.addVariable("MMplayerType", "PlugIn");
				this.setAttribute('swf', this.xiSWFPath);
			}
			swfNode = '<embed type="application/x-shockwave-flash" src="'+ this.getAttribute('swf') +'" width="'+ this.getAttribute('width') +'" height="'+ this.getAttribute('height') +'" style="'+ (this.getAttribute('style') || "") +'"';
			swfNode += ' id="'+ this.getAttribute('id') +'" name="'+ this.getAttribute('id') +'" ';
			var params = this.getParams();
			 for(var key in params){ swfNode += [key] +'="'+ params[key] +'" '; }
			var pairs = this.getVariablePairs().join("&");
			 if (pairs.length > 0){ swfNode += 'flashvars="'+ pairs +'"'; }
			swfNode += '/>';
		} else { // PC IE
			if (this.getAttribute("doExpressInstall")) {
				this.addVariable("MMplayerType", "ActiveX");
				this.setAttribute('swf', this.xiSWFPath);
			}
			swfNode = '<object id="'+ this.getAttribute('id') +'" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="'+ this.getAttribute('width') +'" height="'+ this.getAttribute('height') +'" style="'+ (this.getAttribute('style') || "") +'">';
			swfNode += '<param name="movie" value="'+ this.getAttribute('swf') +'" />';
			var params = this.getParams();
			for(var key in params) {
			 swfNode += '<param name="'+ key +'" value="'+ params[key] +'" />';
			}
			var pairs = this.getVariablePairs().join("&");
			if(pairs.length > 0) {swfNode += '<param name="flashvars" value="'+ pairs +'" />';}
			swfNode += "</object>";
		}
		return swfNode;
	},
	write: function(elementId){
		if(this.getAttribute('useExpressInstall')) {
			// check to see if we need to do an express install
			var expressInstallReqVer = new deconcept.PlayerVersion([6,0,65]);
			if (this.installedVer.versionIsValid(expressInstallReqVer) && !this.installedVer.versionIsValid(this.getAttribute('version'))) {
				this.setAttribute('doExpressInstall', true);
				this.addVariable("MMredirectURL", escape(this.getAttribute('xiRedirectUrl')));
				document.title = document.title.slice(0, 47) + " - Flash Player Installation";
				this.addVariable("MMdoctitle", document.title);
			}
		}
		if(this.skipDetect || this.getAttribute('doExpressInstall') || this.installedVer.versionIsValid(this.getAttribute('version'))){
			var n = (typeof elementId == 'string') ? document.getElementById(elementId) : elementId;
			n.innerHTML = this.getSWFHTML();
			return true;
		}else{
			if(this.getAttribute('redirectUrl') != "") {
				document.location.replace(this.getAttribute('redirectUrl'));
			}
		}
		return false;
	}
}

/* ---- detection functions ---- */
deconcept.SWFObjectUtil.getPlayerVersion = function(){
	var PlayerVersion = new deconcept.PlayerVersion([0,0,0]);
	if(navigator.plugins && navigator.mimeTypes.length){
		var x = navigator.plugins["Shockwave Flash"];
		if(x && x.description) {
			PlayerVersion = new deconcept.PlayerVersion(x.description.replace(/([a-zA-Z]|\s)+/, "").replace(/(\s+r|\s+b[0-9]+)/, ".").split("."));
		}
	}else if (navigator.userAgent && navigator.userAgent.indexOf("Windows CE") >= 0){ // if Windows CE
		var axo = 1;
		var counter = 3;
		while(axo) {
			try {
				counter++;
				axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash."+ counter);
//				document.write("player v: "+ counter);
				PlayerVersion = new deconcept.PlayerVersion([counter,0,0]);
			} catch (e) {
				axo = null;
			}
		}
	} else { // Win IE (non mobile)
		// do minor version lookup in IE, but avoid fp6 crashing issues
		// see http://blog.deconcept.com/2006/01/11/getvariable-setvariable-crash-internet-explorer-flash-6/
		try{
			var axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.7");
		}catch(e){
			try {
				var axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.6");
				PlayerVersion = new deconcept.PlayerVersion([6,0,21]);
				axo.AllowScriptAccess = "always"; // error if player version < 6.0.47 (thanks to Michael Williams @ Adobe for this code)
			} catch(e) {
				if (PlayerVersion.major == 6) {
					return PlayerVersion;
				}
			}
			try {
				axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash");
			} catch(e) {}
		}
		if (axo != null) {
			PlayerVersion = new deconcept.PlayerVersion(axo.GetVariable("$version").split(" ")[1].split(","));
		}
	}
	return PlayerVersion;
}
deconcept.PlayerVersion = function(arrVersion){
	this.major = arrVersion[0] != null ? parseInt(arrVersion[0]) : 0;
	this.minor = arrVersion[1] != null ? parseInt(arrVersion[1]) : 0;
	this.rev = arrVersion[2] != null ? parseInt(arrVersion[2]) : 0;
}
deconcept.PlayerVersion.prototype.versionIsValid = function(fv){
	if(this.major < fv.major) return false;
	if(this.major > fv.major) return true;
	if(this.minor < fv.minor) return false;
	if(this.minor > fv.minor) return true;
	if(this.rev < fv.rev) return false;
	return true;
}
/* ---- get value of query string param ---- */
deconcept.util = {
	getRequestParameter: function(param) {
		var q = document.location.search || document.location.hash;
		if (param == null) { return q; }
		if(q) {
			var pairs = q.substring(1).split("&");
			for (var i=0; i < pairs.length; i++) {
				if (pairs[i].substring(0, pairs[i].indexOf("=")) == param) {
					return pairs[i].substring((pairs[i].indexOf("=")+1));
				}
			}
		}
		return "";
	}
}
/* fix for video streaming bug */
deconcept.SWFObjectUtil.cleanupSWFs = function() {
	var objects = document.getElementsByTagName("OBJECT");
	for (var i = objects.length - 1; i >= 0; i--) {
		objects[i].style.display = 'none';
		for (var x in objects[i]) {
			if (typeof objects[i][x] == 'function') {
				objects[i][x] = function(){};
			}
		}
	}
}
/* add document.getElementById if needed (mobile IE < 5) */
if (!document.getElementById && document.all) { document.getElementById = function(id) { return document.all[id]; }}

/* add some aliases for ease of use/backwards compatibility */
var getQueryParamValue = deconcept.util.getRequestParameter;
var FlashObject = deconcept.SWFObject; // for legacy support
var SWFObject = deconcept.SWFObject;

//standard.js
String.prototype.trim = function() {
	return this.replace( /^\s+|\s+$/, "" );
}

function removeCSSClass(elem, className) {
	elem.className = elem.className.replace(className, "").trim();
}

function addCSSClass(elem, className) {
	removeCSSClass(elem, className);
	elem.className = (elem.className + " " + className).trim();
}

function startList() {
	if(bw.ie6){
		if (document.getElementById && document.all) {
			createRollover("navShop");
			createRollover("navMeta");
		}
	}
}

/*
function setMenuPositions(id){
	//todo add sniffer for IE6
	var parentNav=document.getElementById(id);
	var divElements=parentNav.getElementsByTagName("div");
	for(i=0;i<divElements.length;i++){
		if(divElements[i].className=="wrapperDiv"){
			divElements[i].style.width=(document.body.offsetWidth-2)+"px";
		}
	}
}*/
function createRollover(id){
	navRoot = document.getElementById(id);
		for (i=0; i<navRoot.childNodes.length; i++) {
			  node = navRoot.childNodes[i];
			  if (node.nodeName=="LI") {
					node.onmouseover=mouseOver;
				  	node.onmouseout=mouseOut;
			   }
		}
}

function mouseOver() {
    addCSSClass(this, "over");
}
function mouseOut() {
	removeCSSClass(this, "over");
}

/* start dropdown scripts */

var mouseOffTimer;
var originalWidth=0;
var menuBuilt=false;

function showCategories(){
	createMenu();
	document.getElementById("categoryListDummy").style.display='block';
	document.getElementById("categoryList").blur();
	cleartimeout();
}
function hideCategoryList(){
	document.getElementById("categoryListDummy").style.display='none';
	//document.onkeydown = unregisterKeystrokes;
}
/* when the user selects an option things need to happen*/
function setFilters(listValue,liElement){
	//turn off div because option has been selected
	document.getElementById("categoryListDummy").style.display='none';
	ddElement=document.getElementById("categoryList");
	//need to unselect all to clear previously selected option
	unselectall();
	//set selected class for selected option
	liElement.className="selected";

	//sets original dropdown box value by adding an option to the list
	var option=new Option( liElement.innerHTML, listValue);
	ddElement.options[ddElement.options.length]=option;
	ddElement.value=listValue;

	var selectElement=document.getElementById("categoryList");
	var thisText="";
	for (i=0; i<selectElement.options.length; i++) {
		if(listValue==selectElement.options[i].value){
		  	thisText=selectElement.options[i].text;
		}
	}
	document.getElementById("selectText").innerHTML=thisText;

}
// removes all "selected" classnames from eveyr option
function unselectall(){
	ulElement=document.getElementById("categoryListDummy");
	for (i=0; i<ulElement.childNodes.length; i++) {
		ulElement.childNodes[i].className="";
	}
}
//programtically set some additional attributes for li elements
function setAttributes(){
	var ulElement=document.getElementById("categoryListDummy");
	var liElements=ulElement.getElementsByTagName("li");
	for (i=0; i<liElements.length; i++) {
		var liElement=liElements[i];
		liElement.onmouseout = function(){
          this.className="normal";
		  mouseOffTimer=setTimeout('hideCategoryList()',750)
        };
		liElement.onmouseover = function(){
          this.className="selected";
		  cleartimeout();
        };
		liElement.onclick = function(){
          //need to find appropriate option in select box to get Value
			var selectElement=document.getElementById("categoryList");
			var thisValue=0;
			for (i=0; i<selectElement.options.length; i++) {
				if(this.innerHTML==selectElement.options[i].text){
			  		thisValue=selectElement.options[i].value;
				}
			}
			//we now have the value of the corresponding item
			setFilters(thisValue,this);

        };

	}
	ulElement.onmouseover = function(){
		  cleartimeout();
    };

	//one time set so we don't keep recreating the dropdown when the select box is clicked
	menuBuilt=true;
}
//creates the initial DHTML drop down menu based on the options for the standard <select> drop
function createMenu(){
	if(!menuBuilt){
		var selectElement=document.getElementById("categoryList");
		var ul=document.getElementById("categoryListDummy");
		for (i=0; i<selectElement.options.length; i++) {
			//don't show default value which is typically set to ""
			if(selectElement.options[i].value!=""){
				var li = document.createElement('li');
				var txt = document.createTextNode(selectElement.options[i].text);
				li.appendChild(txt);
				ul.appendChild(li);
			}
		}
		setAttributes();
	}
}
function cleartimeout(){
	clearTimeout(mouseOffTimer)
}
function registerKeystrokes(e){
	if (!e) e = window.event;
	//38=up arrow
	//40=down arrow
	//13=enter button
	if (e['keyCode']==38) {
		selectionAction("up");
		return false;
	}
	if (e['keyCode']==40) {
		selectionAction("down");
		return false;
	}
	if (e['keyCode']==13) {
		selectionAction("select");
		return false;
	}
}
function unregisterKeystrokes(e){
	//no need to do anything
}
//use the mouse cursor to select upwards
function selectionAction(action){
	var ulElement=document.getElementById("categoryListDummy");
	var liElements=ulElement.getElementsByTagName("li");
	var isAlreadySelected=false;
	var itemSelected=0;
	//need to check and see if there is already an option selected
	for (i=0; i<liElements.length; i++) {
		if(liElements[i].className=="selected"){
			isAlreadySelected=true;
			itemSelected=i;
		}
	}
	//if there is an object selected, then we need to move relatively from that element
	if(isAlreadySelected){
		//make sure not to go over the amount of items in list
		if(action=="up"){
			if(itemSelected>0){
				unselectall();
				liElements[itemSelected-1].className="selected";
			}
		} else if (action=="down"){
			if(itemSelected+1<liElements.length){
				unselectall();
				liElements[itemSelected+1].className="selected";
			}
		} else if (action=="select"){
			setSelectedValue(liElements[itemSelected]);
		}
	} else {
		//start at  first position
		if(action=="up"){
			liElements[liElements.length-1].className="selected";
		} else if (action=="down"){
			liElements[0].className="selected";
		}
	}
}
/* function to retrieve the value from the onclick attribute */
function setSelectedValue(listElement){
	var onclickValue=listElement.onclick;
	alert(onclickValue);
}


//browser sniffing to load in dummy box
var bw = new lib_bwcheck();
function lib_bwcheck(){
	this.ver=navigator.appVersion;
	//this.vender = navigator.vender;
	this.product=navigator.product;
	this.moz= navigator.product == 'Gecko';
	this.agent=navigator.userAgent;
	this.dom=document.getElementById?1:0;
	this.mac=this.agent.indexOf("Mac")>-1;
	this.opera5=window.opera?1:0;
	this.ie5=(this.ver.indexOf("MSIE 5")>-1 && this.dom && !this.opera5)?1:0;
	this.ie6=(this.ver.indexOf("MSIE 6")>-1 && this.dom && !this.opera5)?1:0;
	this.ie7=(this.ver.indexOf("MSIE 7")>-1 && this.dom && !this.opera5)?1:0;
	this.ie5mac=(this.ver.indexOf("MSIE 5.23")>-1 && !this.opera5 && this.mac)?1:0;
	this.ie4=(document.all && !this.dom && !this.opera5)?1:0;
	this.ie=this.ie4||this.ie5||this.ie6||this.ie7;
	this.saf=this.agent.indexOf("Safari")>-1;
	this.ns6=(this.dom && parseInt(this.ver) >= 5) ?1:0;
	this.ns4=(document.layers && !this.dom)?1:0;
	this.bw=(this.moz||this.ie5mac||this.saf||this.ie7||this.ie6||this.ie5||this.ie4||this.ns4||this.ns6||this.opera5);
	return this;
}
