// DCLK variables, required for every page
var axel = Math.random() + "";
var ord = axel * 1000000000000000000;
var NS4 = (document.layers) ? 1 : 0;
var IE4 = ((document.all) && (!document.getElementById)) ? 1 : 0;
var IE5 = ((document.all) && (!document.fireEvent) && (!window.opera)) ? 1 : 0;
var DOM = (document.getElementById) ? 1 : 0;  // ns6+ and ie5+ and mozilla
var NS6 = ((!document.all) && (document.getElementById)) ? 1 : 0;  // ns6+ and mozilla, not ie6
var IE = (navigator.appName == "Microsoft Internet Explorer") ? 1 : 0;
var PC = (navigator.platform == "Win32") ? 1 : 0;
var MAC = ((navigator.appVersion.indexOf("PPC") >0) || (navigator.appVersion.indexOf("Mac") >0)) ? 1 : 0;
var ff = new Object();

//Layer switch functions using the display property
function layerSwitchDisplay(theDivs, divId) {
// Layer switching functions
  for (var i = 0; i < theDivs.length; i++) {
    if (theDivs[i] == divId) {
      showLayerDisplay(theDivs[i]);
    }
    else {
      hideLayerDisplay(theDivs[i]);
    }
  }
}
function hideLayerDisplay(whichEl) {
  document.getElementById(whichEl).style.display = "none";
}
function showLayerDisplay(whichEl) {
  document.getElementById(whichEl).style.display = "";
}

function ToggleStyleDisplay(elId, state) {
    if (typeof(elId) != "object") {
        var el = document.getElementById(elId);
    }
    else {
        var el = elId;
    }

    if (!el) {
        return;
    }
    var displayValue = el.style.display;

    if (arguments.length > 1) {
        if (state) {
            displayValue = 'none';
        }
        else {
            displayValue = 'block';
        }
    }
    var block = 'block';
    if (NS6) {
        if (el.tagName == 'TR') block = 'table-row';
        if (el.tagName == 'TABLE') block = 'table';
        if (el.tagName == 'TD' || el.tagName == 'TH') block = 'table-cell';
    }
    if ((displayValue == '') || (displayValue == 'none')) {
        el.style.display = block;
    }
    else {
        el.style.display = 'none';
    }
}


function userState(type) {
  if (arguments.length == 0) {
    if (typeof(user) != 'object') return false;
    if (typeof(user.USER_ID) != 'string') return false;
    if (user.USER_ID == 0) return false;
    return true;
  }
  else {
    if (userState()) {
      if (type == 'players') {
        if (typeof(userPlayers) != 'object') return false;
        if (typeof(userPlayers.length) != 'number') return false;
        if (userPlayers.length == 0) return false;
        return true;
      }
      else if (type == 'teams') {
        if (typeof(userTeams) != 'object') return false;
        if (typeof(userTeams.length) != 'number') return false;
        if (userTeams.length == 0) return false;
        return true;
      }
    }
    else {
      return false;
    }
  }
}

function findX(el) {
  var x = 0;
  var obj = document.getElementById(el);
  while (obj.offsetParent) {
  x += obj.offsetLeft;
  obj = obj.offsetParent;
  }
  return x;
}
function findY(el) {
  var y = 0;
  var obj = document.getElementById(el);
  while (obj.offsetParent) {
  y += obj.offsetTop;
  obj = obj.offsetParent;
  }
  return y;
}

function Redirect(url) {
location.replace(url);
}

/*
  This will turn on the debugInfo area at the bottom of the page then append the message passed in.  The function will work if the
	user is on dev or passes in a key value pair in the querystring where the key is debug with any value.
*/
function DebugInfo(message) {
    try {
        var args = GetArgs();
        if (typeof(args.debug) != "undefined" || location.hostname.indexOf("dmz.foxsports.com") != -1 || location.hostname.indexOf("dtn.foxsports.com") != -1) {
            document.getElementById("debugHeader").style.display = "block";
            var obj = document.getElementById("debugInfo");
            obj.style.display = "block";
            obj.innerHTML = "<li>" + message + obj.innerHTML;
        }
    }
    catch(e) {
    }
}

// used on story pages
var months = new Array ("Jan.", "Feb.", "Mar.", "Apr.", "May.", "Jun.", "Jul.", "Aug.", "Sep.", "Oct.", "Nov.", "Dec");

function formatDate(seconds) {
  var d = new Date(seconds * 1000);
  var y = d.getYear();
  var h = d.getHours();
  var m = d.getMinutes();
  var p;

  if (h >= 12) {
    p = "p.m.";
  } else {
    p = "a.m.";
  }
  if (h > 12) {
    h -=12;
  } else if (!h) {
    h = 12;
  }
  if (m < 10) {
    m = "0" + m;
  }
  if (y < 1000) {
    y += 1900;
  }
  return months[d.getMonth()] + " " + d.getDate() + ", " + y +
    " " + h + ":" + m + " " + p;
}

// Image swapping function
function imageSwap(imageName, imageSource) {
  // Don't do anything if images aren't supported in DOM
  if (document.images) {
    // Change the source of the image
    // Both of these are passed in the function arguments
    imageName.src = imageSource;
  }
}

function validate5DigitZIP(f) {
	var temp = '';
	var valid = "0123456789";
	var formZIP = f.zipcode.value;
	if (formZIP.length != 5) {
		alert("Please enter a 5 digit zip code.  Thank you.");
		return false;
	}
	for (var i=0; i < formZIP.length; i++) {
		temp = "" + formZIP.substring(i, i+1);
		if (valid.indexOf(temp) == "-1") {
			alert("Your zip code must be five numerals.  Please try again.");
			return false;
		}
	}
	return true;
}

//Generic Window Opener function
function openWin(winURL, winName, winWidth, winHeight) {
  var winTop = 25;
  var winLeft = 25;
  if (screen.availWidth <= 800) {
    var winLeft = screen.availWidth - winWidth;
  }
  if (arguments.length == 2) {  //open generic window
    var theWin = window.open(winURL, winName);
  }
  else { // open standard pop-up window with tool bars disabled
    var theWin = window.open(winURL, winName, "width=" + winWidth + ",height=" + winHeight + ",top=" + winTop + ",left=" + winLeft + ",screenY=" + winTop + ",screenY=" + winLeft + ",toolbar=no,location=no,directories=no,status=no,menubar=no,resizable=1,scrollbars=no");
  }
}

//Flash Detection
if (typeof(requiredVersion)=="undefined") {
  var requiredVersion = 6;
}
var flash5Installed = false;
var flash6Installed = false;
var actualVersion = 0;
var useFlash = false;
if(IE && PC){
  document.writeln('<SCR' + 'IPT LANGUAGE=VBScript\>');
  document.writeln('on error resume next');
  document.writeln('flash6Installed  = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.6")))');
  document.writeln('If (flash6Installed) then');
  document.writeln('  flash5Installed  = True');
  document.writeln('Else');
  document.writeln('  flash5Installed  = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.5")))');
  document.writeln('End If');
  document.writeln('</SCR' + 'IPT\>');
}
function detectFlash() {
  if (navigator.plugins) {
    if (navigator.plugins["Shockwave Flash"]) {
      var flashDescription = navigator.plugins["Shockwave Flash"].description;
      //alert("Flash plugin description: " + flashDescription);
      var actualVersion = parseInt(flashDescription.charAt(flashDescription.indexOf(".") - 1));
    }
  }
  //alert("version detected: " + actualVersion);
  if (flash5Installed) {
    var actualVersion = 5;
  }
  if (flash6Installed) {
    var actualVersion = 6;
  }
  if (actualVersion >= requiredVersion) {
    useFlash = true;
    var url = document.URL;
    if (url.indexOf("flash=0") != -1) useFlash = false; //debug code so user can add flash=0 to url string and see what the site looks like w/o flash
  }
}
detectFlash();

// Stuff for Plugin Detection
    // this is where we write out the VBScript for MSIE Windows
    var WM_startTagFix = '</';
    var msie_windows = 0;
    if ((navigator.userAgent.indexOf('MSIE') != -1) && (navigator.userAgent.indexOf('Win') != -1)){
        msie_windows = 1;
        document.writeln('<script language="VBscript">');
        document.writeln('\'This will scan for plugins for all versions of Internet Explorer that have a VBscript engine version 2 or greater.');
        document.writeln('\'This includes all versions of IE4 and beyond and some versions of IE 3.');
        document.writeln('Dim WM_detect_through_vb');
        document.writeln('WM_detect_through_vb = 0');
        document.writeln('If ScriptEngineMajorVersion >= 2 then');
        document.writeln('  WM_detect_through_vb = 1');
        document.writeln('End If');
        document.writeln('Function WM_activeXDetect(activeXname)');
        document.writeln('  on error resume next');
        document.writeln('  If ScriptEngineMajorVersion >= 2 then');
        document.writeln('     WM_activeXDetect = False');
        document.writeln('     WM_activeXDetect = IsObject(CreateObject(activeXname))');
        document.writeln('     If (err) then');
        document.writeln('        WM_activeXDetect = False');
        document.writeln('     End If');
        document.writeln('   Else');
        document.writeln('     WM_activeXDetect = False');
        document.writeln('   End If');
        document.writeln('End Function');
        document.writeln(WM_startTagFix+'script>');
    }

function WM_pluginDetect(plugindescription, pluginxtension, pluginmime, activeXname){
        //This script block will test all user agents that have a real plug-in array
        //(i.e. Netscape) and set the variables, otherwise it directs the routine
        // to WM_activeXDetect to detect the activeX control.
        // First define some variables
        var i,plugin_undetectable=0,detected=0, daPlugin=new Object();
        // Then we check to see if it's an MSIE browser that you can actually
        // check for the plugin in question.
        if (msie_windows && WM_detect_through_vb){
            plugin_undetectable = 0;
        } else {
            plugin_undetectable = 1;
        }
        // If it has a real plugins or mimetypes array, we look there for the plugin first
        if(navigator.plugins) {
            numPlugins = navigator.plugins.length;
            if (numPlugins > 1) {
                if (navigator.mimeTypes && navigator.mimeTypes[pluginmime] && navigator.mimeTypes[pluginmime].enabledPlugin && (navigator.mimeTypes[pluginmime].suffixes.indexOf(pluginxtension) != -1)) { // seems like we have it, let's just make sure and check the version (if specified)
                    if ((navigator.appName == 'Netscape') && (navigator.appVersion.indexOf('4.0') != -1)) { // stupid, stupid Netscape can't handle the references to navigator.plugins by number, sooo...
                        for(i in navigator.plugins) {
                            if ((navigator.plugins[i].description.indexOf(plugindescription) != -1) || (i.indexOf(plugindescription) != -1)) { // some versions of quicktime have no description. feh!
                                detected=1;
                                break;
                            }
                        }
                    } else {
                        for (i = 0; i < numPlugins; i++) {
                            daPlugin = navigator.plugins[i];
                            if ((daPlugin.description.indexOf(plugindescription) != -1) || (daPlugin.name.indexOf(plugindescription) != -1)) {
                                detected=1;
                                break;
                            }
                        }
                    }
                    // Mac weirdness
                    if (navigator.mimeTypes[pluginmime] == null) {
                        detected = 0;
                    }
                }
                return detected;
            } else if((msie_windows == 1) && !plugin_undetectable){
                return WM_activeXDetect(activeXname);
            } else {
                return 0;
            }
        } else {
            return 0;
        }
    }

// retrieve arguments from url query string
function GetArgs() {
	var args = new Object();
	var query = location.search.substring(1);
	var pairs = query.split("&");
	for (var i = 0; i < pairs.length; i++) {
		var pos = pairs[i].indexOf('=');
		if (pos == -1) continue;
		var argname = pairs[i].substring(0,pos);
		var value = pairs[i].substring(pos+1);
		args[argname] = unescape(value);
	}
	return args;
}


function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

// Popup and Ajax
//
//

var newwindow = '';
function popitup(url,y,x)
{
	if (!newwindow.closed && newwindow.location)
	{ newwindow.location.href = url; newwindow.focus();
	} else {
		newwindow=window.open(url,'submenu','height='+y+',width='+x+'toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=0,help=0,modal=1');
		if (!newwindow.opener) newwindow.opener = self;
	}
	if (window.focus) {newwindow.focus()}
	return false;
}

function expand(elementTag){
	styleObj=document.getElementById(elementTag).style;
	if(styleObj.display=='none'){styleObj.display='';}
}

function collapse(elementTag){
	styleObj=document.getElementById(elementTag).style;
	if(styleObj.display!='none'){styleObj.display='none';}
}

function toggleCollapse(elementTag){
	styleObj=document.getElementById(elementTag).style;
	if(styleObj.display=='none'){styleObj.display='';}
	else {styleObj.display='none';}
}

function isHidden(elementTag){
	styleObj=document.getElementById(elementTag).style;
	return(styleObj.display=='none');
}

function showPopup_wh(id, width, heightx) {
	offset = window.pageYOffset||document.body.scrollTop||document.documentElement.scrollTop;
	docwidth = document.body.offsetWidth||document.documentElement.offsetWidth;
	height = document.documentElement.clientHeight||document.body.clientHeight;
	c=document.getElementById('popup_cover').style;
//	c.top = offset + 'px';
//	c.height = height + 'px';
	w=document.getElementById(id).style;
	w.top = 100 + offset + 'px';
	w.width = width + 'px';
	w.height = heightx + 'px';
	w.left = ((docwidth - width) / 2) + 'px';
	expand('popup_cover');
	expand(id);
}

function hidePopup(id) {
	collapse('popup_cover');
	collapse(id);
}

/* Simple AJAX Code-Kit (SACK) v1.6.1 */
/* c2005 Gregory Wild-Smith */
/* www.twilightuniverse.com */
/* Software licenced under a modified X11 licence,
   see documentation or authors website for more details */

function sack(file) {
	this.xmlhttp = null;

	this.resetData = function() {
		this.method = "POST";
		this.queryStringSeparator = "?";
		this.argumentSeparator = "&";
		this.URLString = "";
		this.encodeURIString = true;
		this.execute = false;
		this.element = null;
		this.elementObj = null;
		this.requestFile = file;
		this.vars = new Object();
		this.responseStatus = new Array(2);
	};

	this.resetFunctions = function() {
		this.onLoading = function() { };
		this.onLoaded = function() { };
		this.onInteractive = function() { };
		this.onCompletion = function() { };
		this.onError = function() { };
		this.onFail = function() { };
	};

	this.reset = function() {
		this.resetFunctions();
		this.resetData();
	};

	this.createAJAX = function() {
		try {
			this.xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e1) {
			try {
				this.xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e2) {
				this.xmlhttp = null;
			}
		}

		if (! this.xmlhttp) {
			if (typeof XMLHttpRequest != "undefined") {
				this.xmlhttp = new XMLHttpRequest();
			} else {
				this.failed = true;
			}
		}
	};

	this.setVar = function(name, value){
		this.vars[name] = Array(value, false);
	};

	this.encVar = function(name, value, returnvars) {
		if (true == returnvars) {
			return Array(encodeURIComponent(name), encodeURIComponent(value));
		} else {
			this.vars[encodeURIComponent(name)] = Array(encodeURIComponent(value), true);
		}
	}

	this.processURLString = function(string, encode) {
		encoded = encodeURIComponent(this.argumentSeparator);
		regexp = new RegExp(this.argumentSeparator + "|" + encoded);
		varArray = string.split(regexp);
		for (i = 0; i < varArray.length; i++){
			urlVars = varArray[i].split("=");
			if (true == encode){
				this.encVar(urlVars[0], urlVars[1]);
			} else {
				this.setVar(urlVars[0], urlVars[1]);
			}
		}
	}

	this.createURLString = function(urlstring) {
		if (this.encodeURIString && this.URLString.length) {
			this.processURLString(this.URLString, true);
		}

		if (urlstring) {
			if (this.URLString.length) {
				this.URLString += this.argumentSeparator + urlstring;
			} else {
				this.URLString = urlstring;
			}
		}

		// prevents caching of URLString
		this.setVar("rndval", new Date().getTime());

		urlstringtemp = new Array();
		for (key in this.vars) {
			if (false == this.vars[key][1] && true == this.encodeURIString) {
				encoded = this.encVar(key, this.vars[key][0], true);
				delete this.vars[key];
				this.vars[encoded[0]] = Array(encoded[1], true);
				key = encoded[0];
			}

			urlstringtemp[urlstringtemp.length] = key + "=" + this.vars[key][0];
		}
		if (urlstring){
			this.URLString += this.argumentSeparator + urlstringtemp.join(this.argumentSeparator);
		} else {
			this.URLString += urlstringtemp.join(this.argumentSeparator);
		}
	}

	this.runResponse = function() {
		eval(this.response);
	}

	this.runAJAX = function(urlstring) {
		if (this.failed) {
			this.onFail();
		} else {
			this.createURLString(urlstring);
			if (this.element) {
				this.elementObj = document.getElementById(this.element);
			}
			if (this.xmlhttp) {
				var self = this;
				if (this.method == "GET") {
					totalurlstring = this.requestFile + this.queryStringSeparator + this.URLString;
					this.xmlhttp.open(this.method, totalurlstring, true);
				} else {
					this.xmlhttp.open(this.method, this.requestFile, true);
					try {
						this.xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded")
					} catch (e) { }
				}

				this.xmlhttp.onreadystatechange = function() {
					switch (self.xmlhttp.readyState) {
						case 1:
							self.onLoading();
							break;
						case 2:
							self.onLoaded();
							break;
						case 3:
							self.onInteractive();
							break;
						case 4:
							self.response = self.xmlhttp.responseText;
							self.responseXML = self.xmlhttp.responseXML;
							self.responseStatus[0] = self.xmlhttp.status;
							self.responseStatus[1] = self.xmlhttp.statusText;

							if (self.execute) {
								self.runResponse();
							}

							if (self.elementObj) {
								elemNodeName = self.elementObj.nodeName;
								elemNodeName.toLowerCase();
								if (elemNodeName == "input"
								|| elemNodeName == "select"
								|| elemNodeName == "option"
								|| elemNodeName == "textarea") {
									self.elementObj.value = self.response;
								} else {
									self.elementObj.innerHTML = self.response;
								}
							}
							if (self.responseStatus[0] == "200") {
								self.onCompletion();
							} else {
								self.onError();
							}

							self.URLString = "";
							break;
					}
				};

				this.xmlhttp.send(this.URLString);
			}
		}
	};

	this.reset();
	this.createAJAX();
}

/* Others */

function whenLoading(){
	var e = document.getElementById('replaceme');
	e.innerHTML = "<p>Getting Search Response...</p>";
}

function whenCompleted(){
	var e = document.getElementById('replaceme');
	if (ajax.responseStatus){
		var string = ajax.response;
	} else {
		var string = "Error Registering Subscription";
	}
	if ( string == 'OK') {SendEmailOK(); } else {	e.innerHTML = string;	}
}

function askmikescript() {
hidePopup('askmike');
showPopup_wh('searchnow',480,350);
Sendask('askmikeform');
}

function checkcontactus() {
var f = document.getElementById('contactusform');

if (f.c_Email.value == '') {
  alert('Need to enter valid email');
	return false;
} else {
	hidePopup('contactus');
	return true;

}



}


function searchscript() {
showPopup_wh('searchnow',480,350);
Sendsearch('searchguestform');
}

function showvideo(desc,video,vid){
var e = document.getElementById('mypopupvideo');
e.innerHTML = "<p>"+video+"</p>"+"<p>"+desc+"</p>";
showPopup_wh('popupvideo',480,350);
}

function changeIframeSrc(id, url) {
    if (!document.getElementById) return;
    var el = document.getElementById(id);
    if (el && el.src) {
        el.src = url;
        return false;
    }
    return true;
}

//
// additional


function Sendask(formname){
	var randomnumber=Math.floor(Math.random()*1000);
	var form = document.getElementById(formname);
	var search= form.ask.value;
	var name = form.name.value;
	var email= form.email.value;
	ajax.encVar("q", search);
	ajax.encVar("n", name);
	ajax.encVar("e", email);
  ajax.encVar("submit", "Y");
  ajax.encVar("act", "a");
  ajax.encVar("ran", randomnumber);
	ajax.requestFile = 'search.php';
	ajax.method = 'POST';
	ajax.element = 'answerask';
	ajax.onLoading = whenLoading;
	ajax.onCompletion = whenCompleted;
	ajax.runAJAX();
}

function clearquestion() {
	var form = document.getElementById('askmikeform');
	form.ask.value  = '';
	form.name.value = '';
	form.email.value = '';

}

function Sendsearch(formname){
	var randomnumber=Math.floor(Math.random()*1000);
	var form = document.getElementById(formname);
	var search= form.search.value;
  var completeshow= form.complete.checked;
	ajax.encVar("q", search);
	ajax.encVar("complete", completeshow);
  ajax.encVar("submit", "Y");
  ajax.encVar("act", "s");
  ajax.encVar("ran", randomnumber);
	ajax.requestFile = 'search.php';
	ajax.method = 'POST';
	ajax.element = 'answersearch';
	ajax.onLoading = whenLoading;
	ajax.onCompletion = whenCompleted;
	ajax.runAJAX();
}

function jumptostation() {
hidePopup('station_time');
showPopup_wh('station',450,500);
}

function jumptostation_time() {
hidePopup('station');
showPopup_wh('station_time',450,500);
}

//


function showmymenu(id) {
collapse('submenu1');
collapse('submenu2');
collapse('submenu3');
collapse('submenu4');
collapse('submenu5');
expand('submenu'+id);
}

//

var ajax=new sack();
offset = window.pageYOffset||document.body.scrollTop||document.documentElement.scrollTop;
docwidth = document.body.offsetWidth||document.documentElement.offsetWidth;
height = document.documentElement.clientHeight||document.body.clientHeight;
c=document.getElementById('popup_cover').style;
c.top ='100%';
c.height = '200%';