/*	Drop Down Function 
---------------------------------------------*/
navHover = function() {
	var navElement = document.getElementById("nav").getElementsByTagName("li");
	for (var i=0; i<navElement.length; i++) {
		navElement[i].onmouseover=function() {
			this.className+=" navHover";
			hideSelect();
		}
		navElement[i].onmouseout=function() {
			//this.className=this.className.replace(new RegExp(" navHover\\b"), "");
		    for (var j=0; j<navElement.length; j++) {
			    navElement[j].className=navElement[j].className.replace(new RegExp(" navHover\\b"), "");
			}
			unhideSelect();
		}
	}
}
if (window.attachEvent) window.attachEvent("onload", navHover);

	
/*	Hide Select Function for Dropdown
---------------------------------------------*/

hideID = ["recordsPerPage","ddlTrack","ddlRace","ddlAnnouncer","hideNavigation"];
	//"ctl00_ContentPlaceHolder1_SuffixDropDownList_NameSuffixDropList",

function hideSelect(){
	
		var i=0;
		for (i=0; i<hideID.length; i++) {
			if (document.getElementById(hideID[i]) != null) {
					document.getElementById(hideID[i]).style.visibility="hidden";} 
		}
}

function unhideSelect(){
	
		var i=0;
		for (i=0; i<hideID.length; i++) {
			if (document.getElementById(hideID[i]) != null) {
					document.getElementById(hideID[i]).style.visibility="visible";} 
		}
}


/*	MouseOver Tab Function 
----------------------------------------------------------------*/

function tabSwitch(id,onOff) {

	var tabName = id + 'Tab';
	var tabNameEnd = id + 'EndTab';
	var tab = document.getElementById(tabName);
	var tabEnd = document.getElementById(tabNameEnd);
	if (onOff == "on")
	{
	    
	    if(tab != null)
	        tab.className = "tabOn";
	    if (tabNameEnd != "navOddsEndTab" && tabNameEnd != "navBetNowEndTab" && tabNameEnd != "navProgramsEndTab")
		{
		    
		    if(tabEnd != null)
	            tabEnd.className = "tabOnEnd";
		}
	}
	
	if (onOff == "off")
	{
		if(tab != null)
	        tab.className = "tabOff";
		if (tabNameEnd != "navOddsEndTab" && tabNameEnd != "navBetNowEndTab" && tabNameEnd != "navProgramsEndTab")
		{
		    if(tabEnd != null)
	            tabEnd.className = "tabOffEnd";
		}
	}
	
}


/*	Empty Function for use with Onclick 
----------------------------------------------------------------*/

/*	usage: 
	href="javascript:voidThis()" onClick="SomeFunction()" */

function voidThis() {}


/*	Empty Function for use with Onclick 
----------------------------------------------------------------*/
function navigatePage(menu,link){
// alert("navigatePage:" + link); Doesn't appear that this function is used. 
}


/*	Opens Pop Up to Handicapping Store
----------------------------------------------------------------*/
function OpenHandicappingStoreMain(){

	//window.open(BaseURLSSL + "Authenticated/equibaseHandiStore.asp","","help=no,toolbar,resizable=yes, status=yes, width=665px, height=480px, scrollbars=yes");
	window.open(BaseURLSSL + "HandicappingStore.aspx","","help=no,toolbar,resizable=yes, status=yes, width=665px, height=480px, scrollbars=yes");
}

function OpenHandicappingProducts(){

	var oTrack = GetSelectedTrack();
	var track_abbr = oTrack.GetAbbr();
	var racedate = oTrack.GetRaceDate();
    
    var RaceType = GetRaceType();
    
    if (RaceType == "H") {
        track_type = "HA"
    } else {
        track_type = "TB"
    }
    
    //var link = BaseURLSSL +  "Authenticated/equibaseHandiStore.asp?track_abbr=" + track_abbr + "&racedate=" + racedate + "&tracktype=" + track_type;
    var link = BaseURLSSL +  "HandicappingStore.aspx?track_abbr=" + track_abbr + "&racedate=" + racedate + "&tracktype=" + track_type;

	window.open(link ,"","help=no,toolbar,resizable=yes, status=yes, width=665px, height=480px, scrollbars=yes");
}


/*	Opens Wager Window and Video Streaming Window
----------------------------------------------------------------*/
function topCallsToNavigation(type){

	if (typeof BaseURL == "undefined") {
		BaseURL = "/";
	}
	var programFrame = BaseURL + 'authenticated/program/default.aspx';
	var link = BaseURL + 'Authenticated/loggedinmain.aspx?direction=';
	var programIsCurrentPage = (top.bottomframe != null && top.bottomframe.location.toString().toLowerCase().indexOf(programFrame) >= 0);
	
	try{
		switch(type){
			case "WAGERWINDOW":
				if (programIsCurrentPage) {
					popWagerWindow();
					return;
				} else {
					link += escape(programFrame + "?popUp=wager");
				}
				break;
			/*
			case "STREAMING":
				if (programIsCurrentPage) {
					popMediaPlayerWindow();
					return;
				} else {
					link += escape(programFrame + "?popUp=video");
				}
				break;
			*/
			case "STREAMING":
			    if (programIsCurrentPage)
			    {
		            popLiveMediaPlayer("", "");
		            return;
		        } 
		        else 
		        {
		            link += escape(programFrame + "?popUp=video");
		        }
			    break;
		}
	}
	catch(ex){}
	top.location=link
}

/*	Opens Program Window
----------------------------------------------------------------*/	
function openProgram(){
	var varStr="'toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=1,width=600,height=700'"
	var target="http://www.winnercomm.com/tvg_programguide/apr03/"
	popWin=window.open(target,"win",varStr);
}

// **************************************************** NOTE *****************************************************
// WARNING: Leave this write and close here to avoid scrolling page causing a refresh until that issue is resolved
document.write('<div style="position:absolute;">&nbsp</div>');
document.close();
// **************************************************** NOTE *****************************************************


/*	Code that writes Login Logout Link
----------------------------------------------------------------*/
function writeLoginLogOutLink() {

	var cookiename1="logouttvg"
	var cookiename2="ID="
	currcookiestring=document.cookie

	if (currcookiestring.indexOf(cookiename2)==-1 || currcookiestring.indexOf(cookiename1)!=-1) {
		loginLogoutLink = '<a target="_top" href="' + BaseURL + 'Login.aspx" target="_top">Login</a>';
	} else {
		loginLogoutLink = '<a target="_top" href="' + BaseURL + 'Logout.aspx" target="_top">Logout</a>';
	}
	
    if (document.getElementById("logoutLink")) {
        document.getElementById("logoutLink").innerHTML = loginLogoutLink;
    } else {
        setTimeout('writeLoginLogOutLink()', 1000);
    }
}

writeLoginLogOutLink();


/*	Print Function
----------------------------------------------------------------*/	
function printit(){  
	if (window.print) {
		window.print() ;  
	} else {
		var WebBrowser = '<OBJECT ID="WebBrowser1" WIDTH=0 HEIGHT=0 CLASSID="CLSID:8856F961-340A-11D0-A96B-00C04FD705A2"></OBJECT>';
		document.body.insertAdjacentHTML('beforeEnd', WebBrowser);
		WebBrowser1.ExecWB(6, 2);//Use a 1 vs. a 2 for a prompting dialog box    WebBrowser1.outerHTML = "";  
	}
}

/*	Redirect to Legacy Site
----------------------------------------------------------------*/
function returnToOld(){
	//link= BaseURL + '/default.asp?staylegacy'
	//top.window.location=link
	alert("The original site is no longer available. Please go to www.tvg.com");
}
