//browser dependant checks
var bAgent = navigator.userAgent.toLowerCase()
var NS4 = document.layers;
var NS6 = (document.getElementById && !document.all);
var IE = (bAgent.indexOf("msie") != -1) && (bAgent.indexOf("opera") == -1) && (bAgent.indexOf("omniweb") == -1);
var IE4 = (bAgent.indexOf("msie 4")!=-1 && IE);
var IE5 = (bAgent.indexOf("msie 5")!=-1 && IE);
var IE55 = (bAgent.indexOf("msie 5.5")!=-1 && IE);
var IE6 = (bAgent.indexOf("msie 6")!=-1 && IE);
var IE4UP = (IE4 || IE5 || IE6);
var IE5UP = (IE5 || IE6);
var IE55UP = (IE55 || IE6);

var MAC = (bAgent.indexOf("mac")!=-1);
var MAC_IE4 = (IE4 && MAC);
var MAC_IE51 = MAC && (bAgent.indexOf("msie") != -1) && (bAgent.indexOf("5.1b")!=-1);

if (MAC) {
	platformDT = "undefined";
} else if (IE5) {
	platformDT = "undefined";
} else {
	platformDT = undefined;
}
//replaces getUsername, userRequestHandle
//boolean return based on if queryString matches theSite value object
function matchQueryString (theSite, regString) {
	returnVal = false;
	eval("matchString = /" + regString + "=[_a-zA-Z0-9]+/");
	if(theSite.match(matchString) != null) {
		theParsedUrl = theSite.match(matchString);
		theSiteString = theParsedUrl[0].split("=");
		returnVal = theSiteString[1];
	}
	return returnVal;
}
function getQueryVariable(variable) {
	var query = window.location.search.substring(1);
	var vars = query.split("&");
	for (var i=0;i<vars.length;i++) {
		var pair = vars[i].split("=");
		if (pair[0] == variable) {
		  return pair[1];
		}
	}
}
//depreciated 
function getUsername (siteUrl) {
	userMatch = /username=[a-zA-Z0-9_]+/;
	if(siteUrl.match(userMatch) != null) {
		usernameUrl = siteUrl.match(userMatch);
		usernameSiteString = usernameUrl[0].split("=");
		document.loginform.username.value = usernameSiteString[1];
	}
}
//depreciated 
function userRequestHandle (site) {
	regMatch = /user_request=[a-zA-Z]+/;
	if(site.match(regMatch) != null) {
		parsedUrl = site.match(regMatch);
		siteString = parsedUrl[0].split("=");
		jsUserRequest = siteString[1];
	} else {
		jsUserRequest = "upload";
	}
}

function cookieCheck() {
	document.cookie = "cookietest=yes; path=/; domain=.bet.com";
	var testCookie = document.cookie;
	if (testCookie.indexOf("cookietest=yes") == -1) {
		alert('Your cookies are currently turned off, please enable them.');
		return false;
	}
}
// USE: setCookie('360TV_type','Real Media or Windows Media','Real Media or Windows Media','','','',-1)
function setCookie (name, value, hours, path, domain, evalValue) {
    daValue = value;
	if (evalValue != 'Go') {
	    if ((daValue.indexOf('document.layers[')==0 && document.layers==null)|| (daValue.indexOf('document.all[')==0 && document.all==null)) {
	      daValue = 'document'+daValue.substring(daValue.substring(0,daValue.lastIndexOf('.')).lastIndexOf('.'),daValue.length);
	    }
	    if(evalValue == 1) daValue = eval(daValue + '.value');
	}
    document.cookie = name + '=' + daValue + ((hours)?(';expires=' + ((new Date((new Date()).getTime() + parseInt(hours)*3600000)).toGMTString())):'') + ((path)?';path=' + path:'') + ((domain)?';domain=' + domain:'');
}
// USE: readCookie('360TV_size','document.form1.hiddenField','document.form1.hiddenField','MediaArea',layerText)
function readCookie(name, NS_outputElement, IE_outputElement) {
  if(document.cookie != '') {
    var actualValue, outputElement, firstChar, lastChar;
    var theBigCookie = document.cookie;
    firstChar = theBigCookie.indexOf(name);
    if(firstChar != -1) {
      firstChar += name.length + 1;
      lastChar = theBigCookie.indexOf(';', firstChar);
      if(lastChar == -1) lastChar = theBigCookie.length;
      actualValue = theBigCookie.substring(firstChar, lastChar);
    } else {
      actualValue = false;
    }
  } else {
 	actualValue = "";
	// the following may be used later but for the TV, its not necessary!
    /* outputElement = (navigator.appName == 'Netscape')?NS_outputElement:IE_outputElement;
    if ((outputElement.indexOf('document.layers[')==0 && document.layers==null)|| (outputElement.indexOf('document.all[')   ==0 && document.all   ==null)) {
      outputElement = 'document'+outputElement.substring(outputElement.substring(0,outputElement.lastIndexOf('.')).lastIndexOf('.'),outputElement.length);
    }
    if(outputElement && actualValue) {
      eval(outputElement+".value = '"+actualValue+"'");
    }
	*/
  }
  return actualValue;
}
function killCookie(name, path, domain) {
  var firstChar, lastChar, theValue;
  var theBigCookie = document.cookie;
  firstChar = theBigCookie.indexOf(name);
  if(firstChar != -1) {
    firstChar += name.length + 1;
    lastChar = theBigCookie.indexOf(';', firstChar);
    if(lastChar == -1) lastChar = theBigCookie.length;
    theValue = theBigCookie.substring(firstChar, lastChar);
  } else {
    theValue = false;
  }
  if(theValue) {
    // set an expired cookie, adding 'path' and 'domain' if they were given
    document.cookie = name + '=' + theValue + '; expires=Fri, 13-Apr-1970 00:00:00 GMT' + ((path)?';path=' + path:'') + ((domain)?';domain=' + domain:'');
  }
};

function getTagFlash(w, h, file, version, id, wmode, vars) {
	// may need to update version setting to handle version 7
	var fString = '';
	if (file != "") {
	minorVersion = (version == 6) ? 79 : 30;
	fString += '<OBJECT classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version='+ version +',0,'+ minorVersion +',0"';
	fString += 'WIDTH="'+w+'" HEIGHT="'+h+'" id="'+id+'" ALIGN="">';
	fString += '<PARAM NAME=movie VALUE="'+file+'"> <PARAM NAME=loop VALUE=false> <PARAM NAME=quality VALUE=high> <PARAM NAME=wmode VALUE='+wmode+'>';
	fString += '<PARAM NAME=FlashVars VALUE="'+vars+'">';
	fString += '<EMBED src="'+file+'" loop=false quality=high wmode='+wmode+' WIDTH="'+w+'" HEIGHT="'+h+'" NAME="'+id+'" FlashVars="'+vars+' ALIGN=""';
	fString += 'TYPE="application/x-shockwave-flash" PLUGINSPAGE="http://www.macromedia.com/go/getflashplayer"></EMBED></OBJECT>';
	}
	return fString;
}

// Begin Double Click Ad code
var axel = Math.random() + "";
var ord = axel * 1000000000000000000;
var adTile = 1;
var NSLayers = "";
var jsDartVars = "";
function writeIFad(id, width, height, tile, adSrc) {
	if (jsDartVars != "") {
		adSrc = adSrc + jsDartVars;
	}
	var adString='<nolayer>';
	adString +=	'<iframe id="adi_' + id + '" src="http://ad.doubleclick.net/adi/www.bet.com/' + adSrc +';sz=' + width + 'x' + height + ';tile=' + tile + ';ord=' + ord + '?" width="' + width + '" height="' + height + '" frameborder="0" border="0" marginwidth="0" marginheight="0" align="left" scrolling="no" style="height: ' + height + '; width: ' + width + '>';
	adString +=	'<a href="http://ad.doubleclick.net/jump/www.bet.com/' + adSrc + ';abr=!ie;target=_blank;sz=' + width + 'x' + height + ';tile=' + tile + ';ord=' + ord + '?"><img src="http://ad.doubleclick.net/ad/www.bet.com/' + adSrc + ';abr=!ie;sz=' + width + 'x' + height + ';tile=' + tile + ';ord=' + ord + '?" border=0 height="' + height + '" width="' + width + '" target="_blank"></a>';
	adString +=	'</iframe>';
	adString += '</nolayer>';
	adString += '<ilayer id="ad_' + id + '" visibility="hidden" width=' + width + ' height=' + height + '></ilayer>';
	NSLayers += '<LAYER SRC="http://ad.doubleclick.net/adl/www.bet.com/'+adSrc+' ;target=_blank;sz=' + width + 'x' + height + ';tile=' + tile + ';ord=' + ord + '?" width=' + width + ' height=' + height + 'visibility="hidden" onLoad="moveToAbsolute(ad_' + id + '.pageX,ad_' + id + '.pageY);clip.height=' + height + ';clip.width=' + width + '; visibility=\'show\';"></LAYER>';
	document.write(adString);
	//document.write(NSLayer);	
}
function writeAd(width, height, tile, adSrc) {
	jump= 'http://ad.doubleclick.net/jump/www.bet.com/' + adSrc + ';sz=' + width + 'x' + height + ';tile=' + tile + ';ord=' + ord;
	src= 'http://ad.doubleclick.net/ad/www.bet.com/' + adSrc + ';sz=' + width + 'x' + height + ';tile=' + tile + ';ord=' + ord;
	document.write('<a href="' + jump + '">');
	document.write('<img src="' + src + '" border=0' + ' height=' + height + ' width=' + width + ' ></a>');
}
function getADJad(id, width, height, tile, adSrc) {
 
	var output = '';
	var photoId = getQueryVariable("PhotoID");
	if ((photoId != null)&&((162303<=photoId)&&(photoId<=162322))) {
		adSrc = "shine;sub=240";
	}
	if (jsDartVars != "") {
		adSrc = adSrc + jsDartVars;
	}
	var adS = 'www.bet.com/' + adSrc +';sz=' + width + 'x' + height + ';tile=' + tile + ';ord=' + ord + '?';
	output += '<SCRIPT LANGUAGE="JavaScript1.1" SRC="http://ad.doubleclick.net/adj/' + adS +'" ><\/SCRIPT>';
	if ((!document.images && navigator.userAgent.indexOf("Mozilla/2.") >= 0)  || navigator.userAgent.indexOf("WebTV")>= 0) {
		output += '<A HREF="http://ad.doubleclick.net/jump/' + adS +'" TARGET="_blank">';
		output += '<IMG SRC="http://ad.doubleclick.net/ad/' + adS +'" WIDTH="' + width +'" HEIGHT="' + height +'" BORDER="0" ALT=""></A>';
	}
	//output += '<NOSCRIPT><A HREF="http://ad.doubleclick.net/jump/' + adS +'" TARGET="_blank">';
	//output += '<IMG SRC="http://ad.doubleclick.net/ad/www.bet.com/' + adS +'" WIDTH="' + width +'" HEIGHT="' + height +'" BORDER="0" ALT=""></A></NOSCRIPT>'
	return output;
}
// END Double Click Ad code
function displayOverlay(swf, w, h, t, l) {
	if (IE55UP && !MAC) {
		var swfString = '<div id="overlayDiv" style="position:absolute; left:'+l+'px; top:'+t+'px; width:'+w+'px; height:'+h+'px; z-index:10">'
		swfString += '<OBJECT classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"';
		swfString += ' codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0"';
		swfString += ' WIDTH="' + w + '" HEIGHT="' + h + '" id="flashOverlay" ALIGN="">';
		swfString += ' <PARAM NAME=movie VALUE="' + swf + '"> <PARAM NAME=quality VALUE=high> <PARAM NAME=wmode VALUE=transparent> <PARAM NAME=bgcolor VALUE=#FFFFFF>';
		swfString += ' </OBJECT></div>';
		document.write(swfString);
	};
};
function stdWinOpen(wURL) {
	var winW = arguments[1] || 500;
	var winH = arguments[2] || 400;
	window.open(wURL, "stdWin","width="+winW+",height="+winH+",scrollbars,toolbar=no,directories=no,menubar=no,resizable");
}

function killOverlay() {
	overlayDiv.style.display = "none";
}
// Called by ad in header
function loadMatch() {
	window.document.forms[0].action = "http://www.match.com/qsearch/qsearchdl.aspx?bannerID=000000&trackingID=000000";
	window.document.forms[0].target = "_blank";
	window.document.forms[0].method ="post";
	window.document.forms[0].submit();
}

function toggleVis(name) {
	var theElement = document.getElementById(name);
	var status = theElement.style.display;
	theElement.style.display = (status == "none" || typeof(status) == "undefined") ? "block" : "none";
}
