// MENU STUFF

var menuNames = new 
Array('queries', 'maintenance', 'subscriptions','help','services');
var menuWidths = new Array(100,110,110,75,110);
var IE = document.all;
var NN4 = document.layers;
var compatable = (IE || parseInt(navigator.appVersion) > 4);
var showingmenu = false;

// Some global horses and gens for replace
var ghorse = '';
var gg = '';
var gid = '';
var gyear = '';

function nothing () {
	return;	
}

function setProperty (objID, sProp) {
	if (!compatable) { return null; }
	if (IE && eval('document.all("' + objID + '")')) eval('document.all("' + objID + '").'+sProp+';');
	else if (NN4 && eval('document.layers["' + objID + '"]')) eval('document.layers["' + objID + '"].'+sProp+';');
	else if (eval('document.getElementById("'+objID+'")')) eval('document.getElementById("'+objID+'").'+sProp+';');
}

function getProperty(objID,sProp) {

	if (!compatable) { return null; }
	return eval('document.getElementById("'+objID+'").'+sProp+';');
}

function hideMenus() {
	if (!compatable) { return null; }
	var i = 0;
	while (i < menuNames.length) {
		setProperty('menu_' + menuNames[i],"style.visibility='hidden'");
		i++;	
	}
}

function showMenu (mnu) {
	hideMenus();
	if (!compatable) { return null; }
	setProperty('menu_' + mnu,"style.visibility='visible'");
}

function getWindowWidth () {
	if (!compatable) { return null; }
	var w;
	if (IE) { w = document.body.clientWidth; }
	else { w = window.innerWidth; }
	return(w);	
}

function setPositions (hd) {
	if (!compatable) { return null; }
	var y = (hd == 'T') ? -11 : 54;
	//var startX = Math.floor((getWindowWidth() / 2) - (740 / 2));
	var startX = -20;
	var totwidths = 0;
	var i = 0;
	while (i < menuNames.length) {
		setProperty('menu_' + menuNames[i],'style.top=' + y);
		setProperty('menu_' + menuNames[i],'style.left=' + (startX + totwidths - 11));
		setProperty('menu_' + menuNames[i],"style.display='block'");
		startX += menuWidths[i];
		i++;	
	}
}

function clickMenu (horse,gens,vis,ev) {
	
	var popitup = 0;
	// Only do this for right click
	if (IE && event.button == 2) {
		popitup = 1;
	}
	else if (ev && ev.which == 3) {
		popitup = 1;
	}
	
	if (!popitup && vis) { return; }
	
	showingmenu = vis ? true : false;
	ghorse = horse;
	gg = gens;
	vis = vis ? 'visible' : 'hidden';
	
	evx = 0;
 	evy = 0;
 	// By default, put it to the right, and above the mouse
 	xbuff = -60;
 	ybuff = -50;
 	
 	// Get offset
 	if (document.all) {
 		offY = document.body.scrollTop;
 	} else {
 		offY = window.pageYOffset;	
 	}
 	
 	if ((document.all || document.layers) && event) {
 		evx = event.x;	
 		evy = event.y; 
 	}
 	else if (ev) {
 		evx = ev.pageX;
 		evy = ev.pageY;
 	}
 	
 	// If too far down, shift it up
 	if (evy) {
 		if (evy > getHeight() - 200) {
 			ybuff = (IE) ? -180 : -160;
		}
	}
	
	if (document.all) {
		document.all('clickmenudiv').style.display = 'block';
 		document.all('clickmenudiv').style.visibility = vis;
 		document.all('clickmenudiv').style.top = evy + ybuff + offY;
 		document.all('clickmenudiv').style.left = evx + xbuff;
 		//alert("Layer top is at: " + (evy + ybuff + offY) + ", Left: " + (evx + xbuff) + " vis: " + vis)
 	}
 	else if (document.layers) {
 		document.layers['clickmenudiv'].style.display = 'block';
 		document.layers['clickmenudiv'].style.visibility = vis;
     	document.layers['clickmenudiv'].style.top = evy + offY;
     	document.layers['clickmenudiv'].style.left = evx + xbuff;
 	}
 	else if (ev) {
 		document.getElementById('clickmenudiv').style.display = 'block';
 		document.getElementById('clickmenudiv').style.visibility = vis;
 		document.getElementById('clickmenudiv').style.top = ev.pageY + ybuff + offY;
 		document.getElementById('clickmenudiv').style.left = ev.pageX + xbuff;
 	}
 	return false;
}

function clickgoto (url) {
	url = url.replace(/h=/,'h='+ghorse);
	url = url.replace(/g=/,'g='+gg);
	url = url.replace(/id=/,'id='+gid);
	url = url.replace(/year=/,'year='+gyear);
	document.location.href = url;
	//alert(url);
}



// Stakes Clicker

function stakesMenu (id,yr,vis,ev) {
	
	var popitup = 0;
	// Only do this for right click
	if (IE && event.button == 2) {
		popitup = 1;
	}
	else if (ev && ev.which == 3) {
		popitup = 1;
	}
	
	if (!popitup && vis) { return; }
	
	showingmenu = vis ? true : false;
	gid = id;
	gyear = yr;
	vis = vis ? 'visible' : 'hidden';
	
	evx = 0;
 	evy = 0;
 	// By default, put it to the right, and above the mouse
 	xbuff = -60;
 	ybuff = -50;
 	
 	// Get offset
 	if (document.all) {
 		offY = document.body.scrollTop;
 	} else {
 		offY = window.pageYOffset;	
 	}
 	
 	if ((document.all || document.layers) && event) {
 		evx = event.x;	
 		evy = event.y; 
 	}
 	else if (ev) {
 		evx = ev.pageX;
 		evy = ev.pageY;
 	}
 	
 	// If too far down, shift it up
 	if (evy) {
 		if (evy > getHeight() - 100) {
 			ybuff = (IE) ? -80 : -60;
		}
	}
	
	if (document.all) {
		document.all('stakesmenudiv').style.display = 'block';
 		document.all('stakesmenudiv').style.visibility = vis;
 		document.all('stakesmenudiv').style.top = evy + ybuff + offY;
 		document.all('stakesmenudiv').style.left = evx + xbuff;
 		//alert("Layer top is at: " + (evy + ybuff + offY) + ", Left: " + (evx + xbuff) + " vis: " + vis)
 	}
 	else if (document.layers) {
 		document.layers['stakesmenudiv'].style.display = 'block';
 		document.layers['stakesmenudiv'].style.visibility = vis;
     	document.layers['stakesmenudiv'].style.top = evy + offY;
     	document.layers['stakesmenudiv'].style.left = evx + xbuff;
 	}
 	else if (ev) {
 		document.getElementById('stakesmenudiv').style.display = 'block';
 		document.getElementById('stakesmenudiv').style.visibility = vis;
 		document.getElementById('stakesmenudiv').style.top = ev.pageY + ybuff + offY;
 		document.getElementById('stakesmenudiv').style.left = ev.pageX + xbuff;
 	}
 	return false;
}

// POPUP STUFF


function changeBox(Lid, htm) {
	
	if (document.all) {
			document.all(Lid).innerHTML = htm;
	}
	else if (document.layers) {
		with(document.layers[Lid].document) {
			open();
			write(htm);
			close();
		}
	}
	else {
		document.getElementById(Lid).innerHTML = htm;
	}
		
}

function getWidth() {
	var w;
	if (IE) { w = document.body.clientWidth; }
	else { w = window.innerWidth; }
	return(w);	
}

function getHeight() {
	var w;
	if (IE) { w = document.body.clientHeight; }
	else { w = window.innerHeight; }
	return(w);	
}

function changeFloat(htm, ev) {
     
 	if (htm) { htm = "<table cellspacing=\"0\" cellpadding=\"10\" style=\"border: 1px solid #202020;\" bgcolor=\"#eaead0\"><tr><td valign=\"top\" class=w>" + htm + "</td></tr></table>"; }
 	vis = htm ? "visible" : "hidden";
 
 	evx = 0;
 	evy = 0;
 	// By default, put it to the right, and above the mouse
 	xbuff = 40;
 	ybuff = -20;
 	
 	// Get offset
 	if (document.all) {
 		offY = document.body.scrollTop;
 	} else {
 		offY = window.pageYOffset;	
 	}
 	
 	if ((document.all || document.layers) && event) {
 		evx = event.x;	
 		evy = event.y; 
 	}
 	else if (ev) {
 		evx = ev.pageX;
 		evy = ev.pageY;
 	}
 	
 	// Position if too far
 	// The windows are like 300 wide, so if the evx is > width - 300
	if (evx > getWidth() - 300) {
		xbuff = -350;	
	}
	// If the mouse is too far down, push the popup up the difference about 250 px
	if (evy > getHeight() - 200) {
		ybuff = -200 - (100 - (getHeight() - evy));
	}
	//alert("Mouse is at: "+ evx + "," + evy);

	changeBox('floatBox',htm);

 	if (document.all) {
 		document.all('floatBox').style.visibility = vis;
 		document.all('floatBox').style.top = evy + ybuff + offY;
 		document.all('floatBox').style.left = evx + xbuff;
 		//alert("Layer top is at: " + (evy + ybuff))
 	}
 	else if (document.layers) {
 		document.layers['floatBox'].style.visibility = vis;
     	document.layers['floatBox'].style.top = evy + offY;
     	document.layers['floatBox'].style.left = evx + xbuff;
 	}
 	else if (ev) {
 		document.getElementById('floatBox').style.visibility = vis;
 		document.getElementById('floatBox').style.top = ev.pageY + ybuff + offY;
 		document.getElementById('floatBox').style.left = ev.pageX + xbuff;
 	}
}




function changeFloat2(divid, vis, ev) {
    
  	vis = vis ? "visible" : "hidden";
 
 	evx = 0;
 	evy = 0;
 	// By default, put it to the left, and above the mouse
 	xbuff = -520;
 	ybuff = 15;
 	
 	// Get offset
 	if (document.all) {
 		offY = document.body.scrollTop;
 	} else {
 		offY = window.pageYOffset;	
 	}
 	
 	if ((document.all || document.layers) && event) {
 		evx = event.x;	
 		evy = event.y; 
 	}
 	else if (ev) {
 		evx = ev.pageX;
 		evy = ev.pageY;
 	}
 	
 	// Position if too far
	// If the mouse is too far down, push the popup up the difference about 250 px
	if (evy > getHeight() - 100) {
		ybuff = -100;
	}
	//alert("Mouse is at: "+ evx + "," + evy);

 	if (document.all) {
 		document.all(divid).style.display = 'block';
 		document.all(divid).style.visibility = vis;
 		document.all(divid).style.top = evy + ybuff + offY;
 		document.all(divid).style.left = evx + xbuff;
 		//alert("Layer top is at: " + (evy + ybuff))
 	}
 	else if (document.layers) {
 		document.layers[divid].style.display = 'block';
 		document.layers[divid].style.visibility = vis;
     	document.layers[divid].style.top = evy + offY;
     	document.layers[divid].style.left = evx + xbuff;
 	}
 	else if (ev) {
 		document.getElementById(divid).style.display = 'block';
 		document.getElementById(divid).style.visibility = vis;
 		document.getElementById(divid).style.top = ev.pageY + ybuff + offY;
 		document.getElementById(divid).style.left = ev.pageX + xbuff;
 	}
}



function nothing() {
	return;
}

function checkContext () {
	return !showingmenu;	
}


// FOR THE BRIS STUFF

function changeLayerText(Lid, htm) {
	
	if (document.all) {
			document.all(Lid).innerHTML = htm;
	}
	else if (document.layers) {
		with(document.layers[Lid].document) {
			open();
			write(htm);
			close();
		}
	}
	else {
		document.getElementById(Lid).innerHTML = htm;
	}
		
}


// Subject horse stuff

function showInfo (vis) {
	if (!compatable) { return null; }
	hideMenus();
	var disp = (vis) ? 'block' : 'none';
	vis = (vis) ? 'visible' : 'hidden';	
	setProperty('subjectinfo',"style.visibility='"+ vis +"'");
	setProperty('subjectinfo',"style.display='"+ disp +"'");
}
