function showhide(idtag)
{
	el = document.getElementById(idtag)
	if (el)
	{
		if (el.style.display=='none')
		{
			el.style.display='block'
			icon=document.getElementById(idtag+'icon')
			if (icon)
			{
				icon.src='images/minus.gif'
			}
			
		}
		else
		{
			el.style.display='none'
			icon=document.getElementById(idtag+'icon')
			if (icon)
			{
				icon.src='images/plus.gif'
			}
		}
	}
}

function ratingmodal(type,level)
{
	/*This function opens a modal in IE, or a popup in front in other browsers*/
	url='ratingmodal.php?t='+type+'&a='+level
	if (window.showModalDialog&&navigator.userAgent.indexOf('Chrome')<0)
	{
		window.showModalDialog(url,"Track King ratings table", "dialogWidth:400px;dialogHeight:450px")
	} 
	else 
	{
		window.open(url,'Track King ratings table','height=450,width=400,toolbar=no,directories=no,status=no, continued from previous linemenubar=no,scrollbars=yes,resizable=yes,modal=yes')
	}
}

function helpmodeless(step)
{
	/*This function opens a modeless window to guide a tutorial in IE, or a popup in front in other browsers*/
	url='helptext.php?step='+step
	if (document.all&&window.print) //if ie5
		eval('var openwin=window.showModelessDialog(url,"","help:0;resizable:1;dialogWidth:470px;dialogHeight:520px;dialogLeft:200;dialogTop:150")')
	else
	{
			eval('var openwin=window.open(url,"","width=470px,height=520px,resizable=1,scrollbars=1")')
			openwin.moveTo(200,150)
	}
	if (openwin==null || typeof(openwin)=="undefined")
	{
		alert ("Please allow Track King to open pop-up windows, in order to view the Track King tutorial")
	}
}

function ajphp(source,elementdest) 
{
	if (source>'' && elementdest>'')
	{
		if (document.getElementById(elementdest))
		{
			document.getElementById(elementdest).innerHTML="<p class='ajap'>Retrieving data, please wait</p>"
			//this defines the javascript bit to insert
			var jsinsert = document.createElement('SCRIPT')
			jsinsert.type = 'text/javascript'
			jsinsert.src = "http://www.trackking.org/"+source+"&dest="+elementdest
			// this triggers the PHP-constructed html to be built by JS onto the page
			document.body.appendChild(jsinsert)
		}
	}
}

function switchtab(active)
{
	for (check=1;check<6;check++ )
	{
		divid="Div"+check
		tabid="Tab"+check
		if (document.getElementById(divid))
		{
			if (divid==active)
			{
				document.getElementById(tabid).className='active'
				if (document.getElementById(divid).style.display=='none')
				{
					showhide(divid)
				}
			}
			else
			{
				document.getElementById(tabid).className='inactive'
				if (document.getElementById(divid).style.display!='none')
				{
					showhide(divid)
				}
			}
		}
	}
}

function racevision(cont,track,race,h,w)
{
	/*This function opens a modal in IE, or a popup in front in other browsers, to the race vision*/
	url='racevision.php?c='+cont+'&t='+track+'&r='+race
	if (window.showModalDialog&&navigator.userAgent.indexOf('Chrome')<0)
	{
		window.showModalDialog(url,"Track King Race Vision", "dialogWidth:"+w+"px;dialogHeight:"+h+"px")
	} 
	else 
	{
		window.open(url,'Track King Race Vision','height='+h+',width='+w+',toolbar=no,directories=no,status=no, continued from previous linemenubar=no,scrollbars=yes,resizable=yes,modal=yes')
	}
}

function loadresults(clid,objid,start,currs,endat)
{
	if (restable==false)
	{
		url="restable.php?c="+clid+"&id="+objid+"&st="+start+"&cs="+currs
		if (endat!==undefined)
		{
			url=url+"&ed="+endat
		}
		dest="resultinsert"
		ajphp(url,dest)
		restable=true
	}
}

function loadexjocks(stabid,since)
{
	if (exjocks==false)
	{
		url="exjocks.php?sid="+stabid+"&st="+since
		dest="apprenticeinfo"
		ajphp(url,dest)
		exjocks=true
	}
}

function racehome(tabid)
{
	if ((tabid==2)&&(racerec==false))
	{
		url="racehometabs.php?tid="+tabid
		dest="recentraces"
		ajphp(url,dest)
		racerec=true
	}
	else
	{
		if ((tabid==3)&&(raceup==false))
		{
			url="racehometabs.php?tid="+tabid
			dest="upcomraces"
			ajphp(url,dest)
			raceup=true
		}
		else
		{
			if ((tabid==4)&&(rdworld==false))
			{
				url="racehometabs.php?tid="+tabid
				dest="rdaworld"
				ajphp(url,dest)
				rdworld=true
			}
		}
	}
}

function highlight(infoclass)
{
	el=document.getElementById(infoclass)
	maxloop=num[infoclass]+1
	for (loop=1;loop<maxloop;loop++)
	{
		thing=infoclass+loop.toString()
		if (el.checked==true)
		{
			document.getElementById(thing).className="sel"+infoclass
		}
		else
		{
			document.getElementById(thing).className="null"
		}
	}
}

function placetext(div,tx,col)
{
	document.getElementById(div).innerHTML=tx
	if(col=="r")
	{
		step=1
	}
	else
	{
		if (col=="g")
		{
			step=17
		}
		else
		{
			if (col=="b")
			{
				step=33
			}
			else
			{
				if (col=="y")
				{
					step=49
				}
			}
		}
	}
	newdatafade(step,div)
}

function getclass(clname,objtype)
{
	list = []
	els = document.getElementsByTagName(objtype)
	for(loop=0;loop<els.length; loop++)
	{
		if(els[loop].className==clname)
			list.push(els[loop])
	}
	return list
}

function newdatafade(step,id)
{
	var fadeSteps = new Array();
	/*fade upwards to red*/
	fadeSteps[1] = "fffe07"
	fadeSteps[2] = "fffb44"
	fadeSteps[3] = "fffa51"
	fadeSteps[4] = "fff963"
	fadeSteps[5] = "fff871"
	fadeSteps[6] = "fff77f"
	fadeSteps[7] = "fff78f"
	fadeSteps[8] = "fff6a0"
	fadeSteps[9] = "fff5ad"
	fadeSteps[10] = "fff4be"
	fadeSteps[11] = "fff3cc"
	fadeSteps[12] = "fff3db"
	fadeSteps[13] = "fff2ea"
	fadeSteps[14] = "fff2f2"
	/*fade upwards to green*/
	fadeSteps[17] = "fffe07"
	fadeSteps[18] = "f7ff15"
	fadeSteps[19] = "f3ff33"
	fadeSteps[20] = "eeff42"
	fadeSteps[21] = "e9ff50"
	fadeSteps[22] = "e5ff65"
	fadeSteps[23] = "e0ff70"
	fadeSteps[24] = "ddff84"
	fadeSteps[25] = "daff92"
	fadeSteps[26] = "d7ff9c"
	fadeSteps[27] = "d4ffac"
	fadeSteps[28] = "d0ffb8"
	fadeSteps[29] = "cdffc4"
	fadeSteps[30] = "ccffcc"
	/*fade upwards to blue */
	fadeSteps[33] = "fffe07"
	fadeSteps[34] = "fefe28"
	fadeSteps[35] = "fcfd38"
	fadeSteps[36] = "fafc49"
	fadeSteps[37] = "f8fb69"
	fadeSteps[38] = "f5fa7a"
	fadeSteps[39] = "f3f98a"
	fadeSteps[40] = "f0f89b"
	fadeSteps[41] = "edf7ab"
	fadeSteps[42] = "eaf6bc"
	fadeSteps[43] = "e8f5cd"
	fadeSteps[44] = "e5f4dd"
	fadeSteps[45] = "e3f3ee"
	fadeSteps[46] = "e0f2ff"
	/*fade upwards to yellow */
	fadeSteps[49] = "fffe07"
	fadeSteps[50] = "fffe0f"
	fadeSteps[51] = "fffe17"
	fadeSteps[52] = "fffe27"
	fadeSteps[53] = "fffe37"
	fadeSteps[54] = "ffee47"
	fadeSteps[55] = "fffe57"
	fadeSteps[56] = "ffff67"
	fadeSteps[57] = "ffff78"
	fadeSteps[58] = "ffff88"
	fadeSteps[59] = "ffff98"
	fadeSteps[60] = "ffffa8"
	fadeSteps[61] = "ffffb8"
	fadeSteps[62] = "ffffC8"
	if (step%16 < 15 ) 
	{
		document.getElementById(id).style.backgroundColor = "#" + fadeSteps[step]
		step=step+1
		setTimeout("newdatafade("+step+",'"+id+"')", 60)
	}
	else
	{
		document.getElementById(id).style.backgroundColor = "transparent"
	}
}
	