function setMsg(msg) {
	window.status = msg;
	return true;
}
	
function loadXMLIntro() {
	url = "/engine/ContentManagementServlet?contentType=04&showUnapproved=false&comment=false";
	if (window.XMLHttpRequest) {
		req1 = new XMLHttpRequest();
		req1.onreadystatechange = processIntro2;
		req1.open("GET", url, true);
		req1.send(null);
	} 
	else if (window.ActiveXObject) {
		req1 = new ActiveXObject("Microsoft.XMLHTTP");
		if (req1) {
			req1.onreadystatechange = processIntro2;
			req1.open("GET", url, true);
			req1.send();
		}
	}
}				

function loadXMLPicks() {
	url = "/engine/ContentManagementServlet?contentType=02&showUnapproved=false";
	if (window.XMLHttpRequest) {
		req2 = new XMLHttpRequest();
		req2.onreadystatechange = processPicks;
		req2.open("GET", url, true);
		req2.send(null);
	} 
	else if (window.ActiveXObject) {
		req2 = new ActiveXObject("Microsoft.XMLHTTP");
		if (req2) {
			req2.onreadystatechange = processPicks;
			req2.open("GET", url, true);
			req2.send();
		}
	}
}						

function loadXMLPromo() {
	url = "/engine/ContentManagementServlet?contentType=05&showUnapproved=false";
	if (window.XMLHttpRequest) {
		req7 = new XMLHttpRequest();
		req7.onreadystatechange = processPromo;
		req7.open("GET", url, true);
		req7.send(null);
	} 
	else if (window.ActiveXObject) {
		req7 = new ActiveXObject("Microsoft.XMLHTTP");
		if (req7) {
			req7.onreadystatechange = processPromo;
			req7.open("GET", url, true);
			req7.send();
		}
	}
}		

function loadXMLCarryovers() {
	url = "/engine/ContentManagementServlet?contentType=03&showUnapproved=false";
	if (window.XMLHttpRequest) {
		req3 = new XMLHttpRequest();
		req3.onreadystatechange = processCarryovers;
		req3.open("GET", url, true);
		req3.send(null);
	} 
	else if (window.ActiveXObject) {
		req3 = new ActiveXObject("Microsoft.XMLHTTP");
		if (req3) {
			req3.onreadystatechange = processCarryovers;
			req3.open("GET", url, true);
			req3.send();
		}
	}
}				

function loadXMLCarryovers2() {
	url = "/engine/ContentManagementServlet?contentType=03&showUnapproved=false";
	if (window.XMLHttpRequest) {
		req3 = new XMLHttpRequest();
		req3.onreadystatechange = processCarryovers2;
		req3.open("GET", url, true);
		req3.send(null);
	} 
	else if (window.ActiveXObject) {
		req3 = new ActiveXObject("Microsoft.XMLHTTP");
		if (req3) {
			req3.onreadystatechange = processCarryovers2;
			req3.open("GET", url, true);
			req3.send();
		}
	}
}			

function loadXMLArticles() {
	url = "/engine/ContentManagementServlet?contentType=01&showUnapproved=false";
	if (window.XMLHttpRequest) {
		req4 = new XMLHttpRequest();
		req4.onreadystatechange = processArticles;
		req4.open("GET", url, true);
		req4.send(null);
	} 
	else if (window.ActiveXObject) {
		req4 = new ActiveXObject("Microsoft.XMLHTTP");
		if (req4) {
			req4.onreadystatechange = processArticles;
			req4.open("GET", url, true);
			req4.send();
		}
	}
}				

function processIntro() {
	if (req1.readyState == 4) {
		if (req1.status == 200) {
			for(i=0;i<req1.responseXML.documentElement.childNodes.length;i++){
				n = req1.responseXML.documentElement.childNodes[i].nodeName;
				//alert(n);
				if(n=="#comment"){
document.getElementById('introHtml').innerHTML = req1.responseXML.documentElement.childNodes[i].nodeValue;
break;
				}
			}
		} else {
			setMsg("There was a problem displaying the intro.");
		}
	}
}				

function processIntro2() {
	if (req1.readyState == 4) {
		if (req1.status == 200) {
			var xmlString
			if (jQuery.browser.msie) {
				xmlString = req1.responseXML.xml;
			}  else {
				xmlString = (new XMLSerializer()).serializeToString(req1.responseXML);
			}
			xmlString = xmlString.substring(xmlString.indexOf(">")+1,xmlString.length);
			//alert(xmlString);
			xmlString = xmlString.replace(new RegExp( "\\n", "g" )," ");
			xmlString = xmlString.replace("&gt;",">");
			xmlString = xmlString.replace("&lt;","<");
			while(xmlString.indexOf("  ")!=-1){
				xmlString = xmlString.replace("  "," ");
			}
			//pull out scripts and add to page
			while(xmlString.toLowerCase().indexOf("<script")!=-1){
				var scriptTag = xmlString.substring(xmlString.toLowerCase().indexOf("<script"),xmlString.toLowerCase().indexOf("</script>")+9);
				xmlString = xmlString.substring(0,xmlString.toLowerCase().indexOf("<script"))+xmlString.substring(xmlString.toLowerCase().indexOf("</script>")+9,xmlString.length);
				scriptTag = scriptTag.substring(scriptTag.indexOf(">")+1,scriptTag.length);
				scriptTag = scriptTag.substring(0,scriptTag.toLowerCase().indexOf("</script>"));
				//alert(scriptTag);
				var $s = document.createElement('script'); 
				$s.text=scriptTag; 
				document.body.appendChild($s); 
			}
			document.getElementById('introHtml').innerHTML = xmlString;
			//runScripts(document.getElementById('introHtml'));

		} else {
			setMsg("There was a problem displaying the intro.");
		}
	}
}
 
function runScripts(e) {
	if (e.nodeType != 1) return; //if it's not an element node, return
 
	if (e.tagName.toLowerCase() == 'script') {
		eval(e.text); //run the script
	}
	else {
		var n = e.firstChild;
		while ( n ) {
			if ( n.nodeType == 1 ) runScripts( n ); //if it's an element node, recurse
			n = n.nextSibling;
		}
	}
}

function processPicks() {
	if (req2.readyState == 4) {
		if (req2.status == 200) {
			for(i=0;i<req2.responseXML.documentElement.childNodes.length;i++){
				n = req2.responseXML.documentElement.childNodes[i].nodeName;
				//alert(n);
				if(n=="#comment"){
document.getElementById('picks').innerHTML = req2.responseXML.documentElement.childNodes[i].nodeValue;
break;
				}
			}
		} else {
			setMsg("There was a problem displaying picks.");
		}
	}
}

function processPromo() {
	if (req7.readyState == 4) {
		if (req7.status == 200) {
			response  = req7.responseXML.documentElement;
			xslt = new XML.Transformer("/xml/promo.xsl");
			xslt.transform(req7.responseXML,"promo2");
		} else {
			setMsg("There was a problem displaying promo.");
		}
	}
}

function processCarryovers() {
	if (req3.readyState == 4) {
		if (req3.status == 200) {
			response  = req3.responseXML.documentElement;
			xslt = new XML.Transformer("/xml/carryovers.xsl");
			xslt.transform(req3.responseXML,"carryOvers");
		} else {
			setMsg("There was a problem displaying carryovers.");
		}
	}
}

function processCarryovers2() {
	if (req3.readyState == 4) {
		if (req3.status == 200) {
			response  = req3.responseXML.documentElement;
			xslt = new XML.Transformer("/xml/carryovers.xsl");
			xslt.transform(req3.responseXML,"carryOvers2");
		} else {
			setMsg("There was a problem displaying carryovers.");
		}
	}
}

function processArticles() {
	if (req4.readyState == 4) {
		if (req4.status == 200) {
			response  = req4.responseXML.documentElement;
			xslt = new XML.Transformer("/xml/articles.xsl");
			xslt.transform(req4.responseXML,"articles");
		} else {
			setMsg("There was a problem displaying articles.");
		}
	}
}	

function loadXMLUpcoming(options) {
	if(options!=""){
		url = "/engine/TrackListServlet"+options+"&html=true&nocache="+ new Date().getTime();
	}else{
		url = "/engine/TrackListServlet?html=true&nocache="+ new Date().getTime();
	}
	$('#upcomingRaces').load(url);
}

function _loadXMLUpcoming() {
	url = "/engine/GetXmlDoc?actionCode=schedule";
	//url = "upcoming.php";
	if (window.XMLHttpRequest) {
		req5 = new XMLHttpRequest();
		req5.onreadystatechange = processUpcoming;
		req5.open("GET", url, true);
		req5.send(null);
	} 
	else if (window.ActiveXObject) {
		req5 = new ActiveXObject("Microsoft.XMLHTTP");
		if (req5) {
			req5.onreadystatechange = processUpcoming;
			req5.open("GET", url, true);
			req5.send();
		}
	}
}

function processUpcoming() {
	if (req5.readyState == 4) {
		if (req5.status == 200) {
			response  = req5.responseXML.documentElement;
			xslt = new XML.Transformer("/xml/upcoming.xsl");
			xslt.transform(req5.responseXML,"upcomingRaces");
		} else {
			setMsg("There was a problem displaying upcoming race information.");
		}
	}
}	

function loadXMLMarquee(options) {
	if(options!=""){
		url = "/engine/UsrMessageServlet"+options+"&html=true";
	}else{
		url = "/engine/UsrMessageServlet?html=true";
	}
	$('#banner_msgs').load(url);
}

function loadXMLTracklist(options) {
	if(options!=""){
		url = "/engine/TrackListServlet"+options+"&html=true&nocache="+ new Date().getTime();
	}else{
		url = "/engine/TrackListServlet?html=true&nocache="+ new Date().getTime();
	}
	$('#tracklist').load(url);
}

function loadJSPTracklist(options) {
	if(options!=""){
		url = "/tracks.jsp"+options+"&nocache="+ new Date().getTime();
	}else{
		url = "/tracks.jsp?nocache="+ new Date().getTime();
	}
	$('#tracklist').load(url);
}

function _loadXMLTracklist(options) {
	//alert("loadXMLTracklist("+options+")");
	url = "/engine/TrackListServlet"+options;
	//alert("servlet url: "+url);
	if (window.XMLHttpRequest) {
		req6 = new XMLHttpRequest();
		req6.onreadystatechange = processTracklist;
		req6.open("GET", url, true);
		req6.send(null);
	} else if (window.ActiveXObject) {
		//alert("BBB");
		req6 = new ActiveXObject("Microsoft.XMLHTTP");
		if (req6) {
			req6.onreadystatechange = processTracklist;
			req6.open("GET", url, true);
			req6.send();
		}
	}
}

function processTracklist() {
	//alert("processTracklist()");
	if (req6.readyState == 4) {
		//alert("req6.readyState: "+req6.readyState);
		if (req6.status == 200) {
			//alert("req6.status: "+req6.status);
			response  = req6.responseXML.documentElement;
			//alert("response: "+response);
			try{
				xslt = new XML.Transformer("/xml/tracklist.xsl");
				xslt.transform(req6.responseXML,"tracklist");
			} catch (e) {
				try{
					$('#tracklist').xslt(req6.responseXML, "/xml/tracklist.xsl");
				 } catch(e) {
					//alert("error: "+e.message);
				}
			}
		} else {
			//alert("There was a problem displaying upcoming race information.");
			setMsg("There was a problem displaying upcoming race information.");
		}
	}
}	

function cancelTicket(ticketId,rowType){
	//alert("cancelTicket("+ticketId+","+rowType+")");
if(confirm("Are you sure you want to cancel this ticket?")){
	var xmlDocument = $("<dummy><tickets nocheck='true' action='1'><ticket>"+ticketId+"</ticket></tickets></dummy>")
	$.ajax({
		type: "POST",
		url: "/engine/BamTicketActionServlet",
	    contentType: "text/xml",
	    processData: false,
	    data: "<tickets nocheck='true' action='1'><ticket>"+ticketId+"</ticket></tickets>",
		success: function(html){
			alert(html);
			if(html.indexOf("Ticket " + ticketId + ": Cancelled.")!=-1){
				$("#tcktSts"+ticketId).text("Cancelled");
				$("#tcktCncl"+ticketId).text("");
			}
		}
	});
	}
}		
	
function loadWeather(url) {
	//alert("loadWeather("+url+")");
	$("#weatherFrame").load(url);
}		

function selectRace2(sel){
    var opts = sel.options;
    var i = opts.selectedIndex;
    if ( i >= 0 ){
        var opts = sel.options;
		//alert(opts[i].value);
        window.location="handicapping.jsp?" + opts[i].value;
    }
}

function selectAdvRace2(sel){
    var opts = sel.options;
    var i = opts.selectedIndex;
    if ( i >= 0 ){
        var opts = sel.options;
		//alert(opts[i].value);
        window.location="adv_handicapping.jsp?" + opts[i].value;
    }
}

function selectAdvRace3(sel){
    var opts = sel.options;
    var i = opts.selectedIndex;
    if ( i >= 0 ){
        var opts = sel.options;
		//alert(opts[i].value);
        window.location="harness_handicapping.jsp?" + opts[i].value;
    }
}

function selectAdvRace4(sel){
    var opts = sel.options;
    var i = opts.selectedIndex;
    if ( i >= 0 ){
        var opts = sel.options;
		//alert(opts[i].value);
        window.location="gh_handicapping.jsp?" + opts[i].value;
    }
}

var horseTicketWindow;

var storeWindow;

function launchStore(raceid){
    var hostname = window.location.hostname;
    
    if( storeWindow == null || storeWindow.closed ){
		if(raceid==null){
			storeWindow = window.open('../store.jsp', 'Store', 'toolbar=no,menubar=no,location=no,scrollbars=no,resizable=no,width=930,height=800');
        }else{
			storeWindow = window.open('../store.jsp?raceId='+raceid+'', 'Store', 'toolbar=no,menubar=no,location=no,scrollbars=no,resizable=no,width=930,height=800');
        }
	} else{
		storeWindow.focus();
	}
}

function launchTicket(){
    var hostname = window.location.hostname;
    
    if( horseTicketWindow == null || horseTicketWindow.closed ){
        horseTicketWindow = window.open('../ticketWriter.jsp', 'Ticket', 'toolbar=no,menubar=no,location=no,scrollbars=no,resizable=no,width=670,height=603');
	} else{
		horseTicketWindow.focus();
	}
}

function launchTicketAlt(){
    var hostname = window.location.hostname;
    
    if( horseTicketWindow == null || horseTicketWindow.closed ){
        horseTicketWindow = window.open('/ticketWriter.jsp', 'Ticket', 'toolbar=no,menubar=no,location=no,scrollbars=no,resizable=no,width=670,height=603');
	} else{
		horseTicketWindow.focus();
	}
}
var printWindow;

function launchPrintVersion(){
	var location = window.location;
	
	if( printWindow == null ){
		if(location.toString().indexOf("?") == -1)
		{
		  printWindow = window.open(location+'?print=true', 'Printable_Version', 'toolbar=yes,menubar=yes,location=no,scrollbars=yes,resizable=yes,width=930,height=603');
		}
		else
		{
			printWindow = window.open(window.location+'&print=true', 'Printable_Version', 'toolbar=yes,menubar=yes,location=no,scrollbars=yes,resizable=yes,width=930,height=603');
		}
	        
	}
	else if(printWindow != null && printWindow.closed)
	{
		if(location.toString().indexOf("?") == -1)
		{
			printWindow = window.open(window.location+'?print=true', 'Printable_Version', 'toolbar=yes,menubar=yes,location=no,scrollbars=yes,resizable=yes,width=930,height=603');
		}
		else
		{
		  printWindow = window.open(window.location+'&print=true', 'Printable_Version', 'toolbar=yes,menubar=yes,location=no,scrollbars=yes,resizable=yes,width=930,height=603');
		  
		}
	}
	else{
		printWindow.focus();
	}
}


var videoWindow1;
var videoWindow2;
var videoWindow3;
var videoSWWindow;
var videoWindowReplay;
var videoWindowGH;
var raceReplay;
var racePicks;
var eponies;



function isIpadOrIphone()
{
	var agent=navigator.userAgent.toLowerCase();
	var is_iphone = (agent.indexOf('iphone')!='-1');
	var is_ipad = (agent.indexOf('ipad')!='-1');
	return is_iphone || is_ipad;
}
function getVideoWindowParams()
{
	var window_params_ipad_iphone = 'toolbar=no,menubar=no,location=no,scrollbars=no,resizable=yes';
	var window_params_normal = 'toolbar=no,menubar=no,location=no,scrollbars=no,resizable=yes,width=344,height=346';	
	if (isIpadOrIphone())
	{
		return window_params_ipad_iphone;
	}
	return window_params_normal;
}


function getSwedishVideoWindowParams()
{
	var window_params_ipad_iphone = 'toolbar=no,menubar=no,location=no,scrollbars=no,resizable=yes';
	var window_params_normal = 'toolbar=no,menubar=no,location=no,scrollbars=no,resizable=yes,width=510,height=400';	
	if (isIpadOrIphone())
	{
		return window_params_ipad_iphone;
	}
	return window_params_normal;
}

function openVideo1(){
    //var hostname = window.location.hostname;
    
    if( videoWindow1 == null || videoWindow1.closed ){
		if(arguments.length == 1){
			videoWindow1 = window.open('/video.jsp?page_id='+arguments[0]+'', 'Video1', getVideoWindowParams());
		}else{
			videoWindow1 = window.open('/video.jsp', 'Video1', getVideoWindowParams());
        }
        //videoWindow1 = window.open('/video.jsp', 'Video1', 'toolbar=no,menubar=no,location=no,scrollbars=no,resizable=no');
	} else{
		videoWindow1.focus();
	}
}

function openVideo2(){
    if( videoWindow2 == null || videoWindow2.closed ){
		if(arguments.length == 1){
			videoWindow2 = window.open('/video.jsp?page_id='+arguments[0]+'', 'Video2', getVideoWindowParams());
		}else{
			videoWindow2 = window.open('/video.jsp', 'Video2',getVideoWindowParams());
        }
        //videoWindow2 = window.open('/video.jsp', 'Video2', 'toolbar=no,menubar=no,location=no,scrollbars=no,resizable=no');
	} else{
		videoWindow2.focus();
	}
}

function openVideo3(){
    if( videoWindow3 == null || videoWindow3.closed ){
		if(arguments.length == 1){
			videoWindow3 = window.open('/video.jsp?page_id='+arguments[0]+'', 'Video3', getVideoWindowParams());
		}else{
			videoWindow3 = window.open('/video.jsp', 'Video3', getVideoWindowParams());
        }
	} else{
		videoWindow3.focus();
	}
}


function openVideo4(){
    if( videoSWWindow == null || videoSWWindow.closed ){		
			videoSWWindow = window.open('/video2.jsp', 'Video4',getSwedishVideoWindowParams());        
		
	} else{
		videoSWWindow.focus();
	}
}
function openVideoReplay(filename, trackid){
    //var hostname = window.location.hostname;
    
    if( videoWindowReplay == null || videoWindowReplay.closed ){
    	videoWindowReplay = window.open('/video_replay.jsp?replayFileName='+filename+'&trackId='+trackid+'&action=video', 'Race_Replay', 'toolbar=no,menubar=no,location=no,scrollbars=no,resizable=yes,width=344,height=346');
	} 
    else{
		videoWindowReplay.close();
		videoWindowReplay = window.open('/video_replay.jsp?replayFileName='+filename+'&trackId='+trackid+'&action=video', 'Race_Replay', 'toolbar=no,menubar=no,location=no,scrollbars=no,resizable=yes,width=344,height=346');
		
    }
}

function openRaceReplay(){
    //var hostname = window.location.hostname;
    
    if( raceReplay == null || raceReplay.closed ){
    	raceReplay = window.open('/raceReplay.jsp', 'Race_Replay', 'toolbar=no,menubar=no,location=no,scrollbars=no,resizable=yes,width=421,height=580');
	} else{
		raceReplay.focus();
	}
}

function openRacePicks(raceId){   
    if( racePicks == null || racePicks.closed ){
    	racePicks = window.open('/picks.jsp?race_id='+raceId, 'Race_Picks', 'toolbar=no,menubar=no,location=no,scrollbars=no,resizable=yes,width=350,height=240');
	} else{
		racePicks.location.href='/picks.jsp?race_id='+raceId;
		racePicks.focus();
	}
}

function openEponies(raceId){   
    if( eponies == null || eponies.closed ){
    	eponies = window.open('/eponies.jsp?race_id='+raceId, 'Eponies', 'toolbar=no,menubar=no,location=no,scrollbars=yes,resizable=yes,width=350,height=325');
	} else{
		eponies.location.href='/picks.jsp?race_id='+raceId;
		eponies.focus();
	}
}

function openGHVideo(){
    //var hostname = window.location.hostname;
    
    if( videoWindowGH == null || videoWindowGH.closed ){
        videoWindowGH = window.open('/ghVideo.jsp', 'VideoGH', 'toolbar=no,menubar=no,location=no,scrollbars=no,resizable=yes,width=344,height=346');
        //videoWindowGH = window.open('/video.jsp', 'VideoGH', 'toolbar=no,menubar=no,location=no,scrollbars=no,resizable=no');
	} else{
		videoWindowGH.focus();
	}
}

function doRefresh(){
    setTimeout( "refresh()", 60 * 1000 );
}

function refresh(){
    window.location.href = (location.href);
}

function launchTicketAdv(track,race){
    var hostname = window.location.hostname;
    
    if( horseTicketWindow == null || horseTicketWindow.closed ){
        horseTicketWindow = window.open('ticketWriter.jsp?track_code='+track+'&race_num='+race+'', 'Ticket', 'toolbar=no,menubar=no,location=no,scrollbars=no,resizable=no,width=670,height=603');
	} else{
		horseTicketWindow.focus();
	}
}

function launchPrint(url){
    var hostname = window.location.hostname;
    
    if( printWindow == null || printWindow.closed ){
        printWindow = window.open(''+url+'', 'Print', 'toolbar=no,menubar=no,location=no,scrollbars=yes,resizable=yes,width=1000,height=800');
	} else{
		printWindow.focus();
	}
}

function updateHCTab(selectedTab){
	try{
		var src = $("#hcPoolsTab").attr("src").replace(/-over/, "");
		$("#hcPoolsTab").attr("src",src);
	}catch(e){
	}
	try{
		var src = $("#hcExoticsTab").attr("src").replace("-over", "");
		$("#hcExoticsTab").attr("src",src);
	}catch(e){
	}
	try{
		var src = $("#hcResultsTab").attr("src").replace("-over", "");
		$("#hcResultsTab").attr("src",src);
	}catch(e){
	}
	try{
		var src = $("#hcChangesTab").attr("src").replace("-over", "");
		$("#hcChangesTab").attr("src",src);
	}catch(e){
	}
	try{
		var src = $("#hcWillPayTab").attr("src").replace("-over", "");
		$("#hcWillPayTab").attr("src",src);
	}catch(e){
	}
	if($("#"+selectedTab).attr("src").indexOf("-over")==-1){
		var src = $("#"+selectedTab).attr("src").match(/[^\.]+/) + "-over.gif";
		$("#"+selectedTab).attr("src", src);
    }
}

function showPool(id) {
	pools = new Array("pool_1A","pool_1B","pool_1C","pool_2","pool_3","pool_4","pool_5","no_wps","pool_6");
	for(i=0;i<pools.length;i++){ 
		identity=document.getElementById(pools[i]);
		if(identity != null){
			identity.style.display = "none";
		}						
	}
	$('div.raceInfoPanel').hide();
	identity=document.getElementById(id);
	if(identity != null){
		identity.style.display = "block";
	}
}

function redirect(address){
	window.location.href  = address;

}
function logout() {
	var agree=confirm("Are you sure you wish to logout?");
	if (agree)
		document.getElementById('logoutForm').submit();
}

function _IsNumeric(sText) {
   var ValidChars = "0123456789.";
   var IsNumber=true;
   var Char;
 
   for (i = 0; i < sText.length && IsNumber == true; i++) 
      { 
      Char = sText.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) 
         {
         IsNumber = false;
         }
      }
   return IsNumber;
}

function IsNumeric(input) {
   return (input - 0) == input && input.length > 0;
}

function formatCurrency(obj) {
        userVal=(obj.value.replace(/[^\d\.]/g, "")*1).toFixed(2);
        for(i=userVal.length-6;i>0;i-=3)
        userVal = userVal.substr(0,i)+","+userVal.substr(i)
        return userVal;
}

function formatCurrencyNoComa(obj) {
        userVal=(obj.value.replace(/[^\d\.]/g, "")*1).toFixed(2);
        for(i=userVal.length-6;i>0;i-=3)
        userVal = userVal.substr(0,i)+userVal.substr(i)
        return userVal;
}

var horseWagerWindow;

function launchWagerPad(){
    var hostname = window.location.hostname;
    if( horseWagerWindow == null || horseWagerWindow.closed ){
		if(arguments.length == 1){
			horseWagerWindow = window.open('../wagerPad.jsp?race_id='+arguments[0]+'', 'Wager', 'toolbar=no,menubar=no,location=no,scrollbars=no,resizable=yes,width=670,height=550');
		}else{
			horseWagerWindow = window.open('../wagerPad.jsp', 'Wager', 'toolbar=no,menubar=no,location=no,scrollbars=no,resizable=yes,width=670,height=550');
		}
	} else{
		horseWagerWindow.focus();
	}
}
