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_showHideLayers() { //v6.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
    obj.visibility=v; }
}

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_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];}
}

function setFrameHeights( strElmId ){
    if (document.getElementById  ){
        var trackListFrame = document.getElementById( 'track-list-frame' );
        var eventInfoFrame = document.getElementById( 'event-info-frame' );
        //var mainCol = document.getElementById('mainColumn');
       
        var trackList = trackListFrame.contentWindow.document.getElementById( 'horses-track-list' );
        var eventInfo = eventInfoFrame.contentWindow.document.getElementById( 'horses-event-info' );
        
        
        
        var tlH = ( trackList )?trackList.offsetHeight:0;
        var eiH = ( eventInfo )?eventInfo.offsetHeight:0;
        
        var h = Math.max( ( tlH + 30 ), eiH );
      
        trackListFrame.style.height =  ( h ) + 'px';
        eventInfoFrame.style.height =  h + 'px';
        
            
        //mainCol.style.height = ( h ) + 'px';
    }
}

var horseTicketWindow;
var printWindow;

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 videoWindow1;
var videoWindow2;
var videoWindowGH;

function openVideo1(){
    //var hostname = window.location.hostname;
    
    if( videoWindow1 == null || videoWindow1.closed ){
        videoWindow1 = window.open('/video.jsp', 'Video1', 'toolbar=no,menubar=no,location=no,scrollbars=no,resizable=no,width=344,height=346');
        //videoWindow1 = window.open('/video.jsp', 'Video1', 'toolbar=no,menubar=no,location=no,scrollbars=no,resizable=no');
	} else{
		videoWindow1.focus();
	}
}

function openVideo2(){
    //var hostname = window.location.hostname;
    
    if( videoWindow2 == null || videoWindow2.closed ){
        videoWindow2 = window.open('/video.jsp', 'Video2', 'toolbar=no,menubar=no,location=no,scrollbars=no,resizable=no,width=344,height=346');
        //videoWindow2 = window.open('/video.jsp', 'Video2', 'toolbar=no,menubar=no,location=no,scrollbars=no,resizable=no');
	} else{
		videoWindow2.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=no,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 selectRace(){
    var opts = document.frmRaces.races.options;
    var i = opts.selectedIndex;
    if ( i > 0 ){
        var opts = document.frmRaces.races.options;
        window.location="handicapping.jsp?" + opts[i].value;
    }
}

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 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 show_menu(id,x,y){
				menu = document.getElementById(id);
				menu.style.left = x+"px";
				menu.style.top = y+"px";
				menu.style.display = "block";
			}
			
			function _hide_menu(id){
				menu = document.getElementById(id);
				menu.style.left = "-999px";
				menu.style.top = "-999px";
				menu.style.display = "none";
			}
 
 function hide_menu(obj, e) {
  var toEl;
  if (window.event){
	   toEl = window.event.toElement;
  }else if (e.relatedTarget){
	   toEl = e.relatedTarget;
   }
  if ( obj != toEl && !contained(toEl, obj) ){
	obj.style.left = "-999px";
	obj.style.top = "-999px";
	obj.style.display = "none";
   }
}
			
  function getObj(name) {
	if (document.getElementById) {
		return document.getElementById(name);
	}else if (document.all) {
		return document.all[name];
	}else if (document.layers) {
		return document.layers[name];
	}else{
		return false;
	}
 }

// returns true of oNode is contained by oCont (container)
function contained(oNode, oCont) {
  if (!oNode) return; // in case alt-tab away while hovering (prevent error)
  while ( oNode.parentNode ) {
    oNode = oNode.parentNode;
    if ( oNode == oCont ) return true;
  }
  return false;
}

function getGrossOffsetLeft(elem) {
	var offset = 0
	while (elem.offsetParent) {
	elem = elem.offsetParent
	offset += elem.offsetLeft
	}
	return offset;
}

function getGrossOffsetTop(elem) {
	var offset = 0
	while (elem.offsetParent) {
	elem = elem.offsetParent
	offset += elem.offsetTop
	}
	return offset;
}

var Type = 'Z';
function StartFloat(myWidth) {
	if(document.all) {
		//alert("StartFloat: A");
		//document.all.Floater.style.pixelLeft = document.body.clientWidth - document.all.Floater.offsetWidth;
		document.all.Floater.style.pixelLeft = 820;
		document.all.Floater.style.visibility = 'visible';
		Type = 'A';
	} else if(document.layers) {
		//alert("StartFloat: B");
		document.Floater.left = window.innerWidth - document.Floater.clip.width - 16;
		document.Floater.visibility = 'show';
		Type = 'B';
	} else if(document.getElementById) {
		//alert("StartFloat: C");
		//document.getElementById('Floater').style.left = (window.innerWidth - 35) + 'px';
		document.getElementById('Floater').style.left = myWidth + 'px';
		document.getElementById('Floater').style.visibility = 'visible';
		Type = 'C';
	}
	//alert("Type: "+Type);
	if (document.all) { 
		window.onscroll = Float; 
	} else { 
		setInterval('Float()', 100); 
	}
}

function Float() {
	if (Type == 'A') { 
		document.all.Floater.style.pixelTop = document.body.scrollTop; 
	} else if (Type == 'B') { 
		document.Floater.top = window.pageYOffset; 
	} else if (Type == 'C') { 
		document.getElementById('Floater').style.top = window.pageYOffset + 'px'; 
	}
	
	}function setMsg(msg) {
		window.status = msg;
		return true;
	}
	
	// pass the HTML element return the x, y position
	function getElementPos(elem){
		elft=elem.offsetLeft;
		etop=elem.offsetTop;
		while(elem.offsetParent != null){
			epar=elem.offsetParent;
			elft+=epar.offsetLeft;
			etop+=epar.offsetTop;
			elem=epar;
		}
		return [elft,etop];
	}
	
	function getFlashMovieObject(movieName){
		  if (window.document[movieName]) 
		  {
			return window.document[movieName];
		  }
		  if (navigator.appName.indexOf("Microsoft Internet")==-1)
		  {
			if (document.embeds && document.embeds[movieName])
			  return document.embeds[movieName]; 
		  }
		  else // if (navigator.appName.indexOf("Microsoft Internet")!=-1)
		  {
			return document.getElementById(movieName);
		  }
	}
	
var win=null;
function NewWindow(mypage,myname,w,h,scroll,pos){
if(pos=="random"){LeftPosition=(screen.width)?Math.floor(Math.random()*(screen.width-w)):100;TopPosition=(screen.height)?Math.floor(Math.random()*((screen.height-h)-75)):100;}
if(pos=="center"){LeftPosition=(screen.width)?(screen.width-w)/2:100;TopPosition=(screen.height)?(screen.height-h)/2:100;}
else if((pos!="center" && pos!="random") || pos==null){LeftPosition=0;TopPosition=20}
settings='width='+w+',height='+h+',top='+TopPosition+',left='+LeftPosition+',scrollbars='+scroll+',location=no,directories=no,status=no,menubar=no,toolbar=no,resizable=no';
win=window.open(mypage,myname,settings);}