// Strip leading and trailing white-space 
String.prototype.trim = function() { return this.replace(/^\s*|\s*$/g, ""); } 
String.prototype.nocr=function() { return this.replace(/(\r\n|[\r\n])/g,''); }

var aiTab=null;
var aiTabO=null;

function addTab(idx,src) {
	if (aiTab==null) aiTab=new Array();
	if (aiTabO==null) aiTabO=new Array();
	aiTab[idx]=new Image();	aiTab[idx].src=src;
	aiTabO[idx]=new Image(); aiTabO[idx].src=src.replace('.gif','o.gif');
}
function tabOv(idx) { di20('tab'+idx,aiTabO[idx].src); }
function tabOut(idx) { di20('tab'+idx,aiTab[idx].src); }

var bVer = parseInt(navigator.appVersion);
var sOut="";
if (!((navigator.appVersion.indexOf("MSIE") == -1)&&(navigator.appVersion.substring(0,3)-4.8<0))){
	document.write("<style>");
	if (!(navigator.appVersion.indexOf("MSIE") == -1)) {
		// if this is IE, work around width excluding margin
	
	}
	document.write("</style>");
} else {
//netscape <4.8 on PC
	sOut="This site works best with modern browsers. Some features may not work properly with Netscape 4.x. ";			
}

/* Function that swaps images. */
function di20(id, newSrc) {
var theImage = FWFindImage(document, id, 0);
if (theImage) {
theImage.src = newSrc;
}
}
/* Functions that track and set toggle group button states. */
function FWFindImage(doc, name, j) {
var theImage = false;
if (doc.images) {
theImage = doc.images[name];
}
if (theImage) {
return theImage;
}
if (doc.layers) {
for (j = 0; j < doc.layers.length; j++) {
theImage = FWFindImage(doc.layers[j].document, name, 0);
if (theImage) {
return (theImage);
}
}
}
return (false);
}
function getObject(sID) {
if (document.layers) {
return document.layers[sID];
} else if (document.all) {
return document.all(sID).style;
} else if (document.getElementById) {
return document.getElementById(sID).style;
} else {
return null;
}
}

function setCookie(sIn) {
    document.cookie = "wrc=" + sIn;
}
//function readCookie() {
//    return unescape(document.cookie);
//}

function makeCookie(Name,Value,Expiry,Path,Domain,Secure) {
//if you want to save the cookie
if (Expiry != null && !isNaN(Expiry)) {
	var datenow = new Date();
	datenow.setTime(datenow.getTime() + Math.round(86400000*Expiry));
	Expiry = datenow.toGMTString();
}
Expiry = (Expiry) ? '; expires='+Expiry : '';
Path = (Path)?'; path='+Path:'';
Domain = (Domain) ? '; domain='+Domain : '';
Secure = (Secure) ? '; secure' : '';

document.cookie = Name + '=' + escape(Value) + Expiry + Path + Domain + Secure;

}

function readCookie(Name) {

var cookies = ' ' + document.cookie;
if (cookies.indexOf(' ' + Name + '=') == -1) return null;

var start = cookies.indexOf(' ' + Name + '=') + (Name.length + 2);
var finish = cookies.substring(start,cookies.length);
finish = (finish.indexOf(';') == -1) ? cookies.length : start + finish.indexOf(';');

return unescape(cookies.substring(start,finish));
}

function makenumeric(strIn){
	s="";
	for (i=0;i<strIn.length;i++){
		c=strIn.charAt(i);
		if ((c=="1")||(c=="2")||(c=="3")||(c=="4")||(c=="5")||(c=="6")||(c=="7")||(c=="8")||(c=="9")||(c=="0")||(c==".")) s+=c;
	}
	if (s.length==0)s="0";
	return s;
}
function checknumber(sIn,sError){
	sIn.value=makenumeric(sIn.value);
	if (sIn.value==""){
		alert("Please enter "+sError+" then click 'Next' again.");
		return false;
	}
	else if (isNaN(parseFloat(sIn.value))) {
		alert("Please enter "+sError+" as a number ONLY then click 'Next' again.");
		return false;
	}
	return true;
}

function checklimits(sIn,sError,iMin,iMax){
	if (parseFloat(sIn.value)<iMin){
		alert("The "+sError+" must be higher than "+iMin+".");
		return false;
	}
	else if (parseFloat(sIn.value)>iMax) {
		alert("The "+sError+" must be less than "+iMax+".");
		return false;
	}
	return true;
}

function isempty(sIn,sError){
	if (sIn.value==""){
		alert("Please enter "+sError+" then click 'Next' again.");
		return false;
	}
	return true;
}
function checkemail(email){
//	emailpat = /^([a-z0-9_-])+([\.a-z0-9_-])*@([a-z0-9_-])+(\.[a-z0-9_-]+)+$/i;
	emailpat = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/i;
	if (!emailpat.test(email)){
		alert("Your Email address does not appear well-formed. Please fill it in then submit again.");
		return false;
	}
	return true;
}
function checkpostcode(sIn){
	// require a space
	reg=/^[a-z]{1,2}[\da-z]{1,2} \d[a-z][a-z]$/i; 
	if (!reg.test(sIn)){
	    alert("Your postcode does not seem to be well-formed. Remember the space is part of your postcode too.");
		return false;
	}
	return true;
	
}
var fVer = 0;	
var bFlashOK = false;

var isIE = (navigator.appVersion.indexOf("MSIE") != -1) ? true : false;
var isWin = (navigator.appVersion.indexOf("Windows") != -1) ? true : false;

if(isIE && isWin){
	document.write('<SCR' + 'IPT LANGUAGE=VBScript\> \n');
	document.write('on error resume next \n');
	document.write('flash4Installed = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.4"))) \n');
	document.write('flash5Installed = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.5"))) \n');	
	document.write('if (flash5Installed) then \n');	
	document.write('fVer=5 \n');	
	document.write('elseif (flash4Installed) then \n');	
	document.write('fVer=4 \n');	
	document.write('end if \n');	
	document.write('</SCR' + 'IPT\> \n');
}

function detectFlash(){	
	if (navigator.plugins){
		if (navigator.plugins["Shockwave Flash 2.0"]|| navigator.plugins["Shockwave Flash"]){
			var isVersion2 = navigator.plugins["Shockwave Flash 2.0"] ? " 2.0" : "";
			var flashDescription = navigator.plugins["Shockwave Flash" + isVersion2].description;
			fVer = parseInt(flashDescription.charAt(flashDescription.indexOf(".") - 1));
		}
	}
	
	if(navigator.userAgent.indexOf("WebTV") != -1) fVer = 2;	
	if (fVer >= 4) bFlashOK = true;
}

detectFlash();
//bFlashOK = false;
function replaceString(sSrc, sFrom, sTo){
	sReturn=sSrc;
    iFromLen=sFrom.length;
    iToLen=sTo.length;
    iPos=0;
    iEnd=0;
    do {
        iPos=sReturn.indexOf(sFrom,iEnd);
        if (iPos!=-1) {
            sReturn = sReturn.substring(0,iPos)+sTo+sReturn.substring(iPos+iFromLen);
            iEnd=iPos+iToLen;
        }
    } while (iPos!=-1);
	return sReturn;

}
function replaceLast(sIn,sFrom,sTo){
	sReturn=sIn;
    iFromLen=sFrom.length;
    iPos=sReturn.lastIndexOf(sFrom);
    if (iPos!=-1) {
        sReturn = sReturn.substring(0,iPos)+sTo+sReturn.substring(iPos+iFromLen);
        iEnd=iPos+iToLen;
    }
    return sReturn;
}


function GetBrowser()
{
   var agt=navigator.userAgent.toLowerCase();
   if( ((agt.indexOf("msie") != -1) && (agt.indexOf("opera") == -1)) )
       return "IE";
   else if( ((agt.indexOf('mozilla')!=-1) && (agt.indexOf('spoofer')==-1)
         && (agt.indexOf('compatible') == -1) && (agt.indexOf('opera')==-1)
         && (agt.indexOf('webtv')==-1) && (agt.indexOf('hotjava')==-1)) )
       return "Netscape";
   else
       return "unknown";
}
function GetPlayerMajorVer(sIn)
{
	var strVer = new String(sIn);
	s = strVer.split(".");
    return s[0];
}
function setLanguage(s){
	makeCookie("language",s,365,'/','',false);
	window.location.reload();
}
function embedMovie(sPath,w,h,bStart) {
var br = GetBrowser();        // Returns either "IE" or "Netscape"
	if (br=="Netscape") {
		document.write("<div class=\"video\"><embed name=\"vid\" type=\"video/x-ms-asf-plugin\" src=\""+sPath+"\" width=\""+w+"\" height=\""+h+"\" showcontrols=\"1\" autostart=\""+bStart+"\" animationstart=\"0\" autorewind=\"0\" autosize=\"0\" showdisplay=\"0\" showstatusbar=\"1\" sendopenstatechangeevents=\"true\" transparentatstart=\"true\" pluginspage=\"http://www.microsoft.com/Windows/MediaPlayer/\"></embed></div>");
	}
	else {
		document.write("<div class=\"video\"><object id=\"player\" classid=\"CLSID:6BF52A52-394A-11d3-B153-00C04F79FAA6\" width=\""+w+"\" height=\""+h+"\"><param name=\"autoStart\" value=\""+bStart+"\"><param name=\"URL\" value=\""+sPath+"\"><param name=\"uiMode\" value=\"full\"><param name=\"stretchToFit\" value=\"false\"><embed name=\"player\" type=\"video/x-ms-asf-plugin\" src=\""+sPath+"\" width=\""+w+"\" height=\""+h+"\" showcontrols=\"1\" autostart=\""+bStart+"\" animationstart=\"0\" autorewind=\"0\" autosize=\"0\" showdisplay=\"0\" showstatusbar=\"1\" sendopenstatechangeevents=\"true\" transparentatstart=\"true\" pluginspage=\"http://www.microsoft.com/Windows/MediaPlayer/\"></embed></object></div>");
		if (GetPlayerMajorVer(player.versionInfo)!=11 && GetPlayerMajorVer(player.versionInfo)!=10)
			document.write("<p>You do not have the latest version of Windows Media Player. <a href=\"http://www.microsoft.com/windows/windowsmedia/download/alldownloads.aspx\" target=\"_blank\">Please visit Microsoft.com to download it</a>.</p>");
	}
}

function embedMovieNow(sPath,w,h,bStart) {
	var br = GetBrowser();        // Returns either "IE" or "Netscape"
	var vidbox=document.getElementById('videobox');
	if (br=='Netscape') {
		vidbox.innerHTML='<embed name="vid" type="video/x-ms-asf-plugin" src="'+sPath+'" width="'+w+'" height="'+h+'" showcontrols="1" autostart="'+bStart+'" animationstart="0" autorewind="0" autosize="0" showdisplay="0" showstatusbar="1" sendopenstatechangeevents="true" transparentatstart="true" pluginspage="http://www.microsoft.com/Windows/MediaPlayer/"></embed>';
	}
	else {
		vidbox.innerHTML='<object id="player" classid="CLSID:6BF52A52-394A-11d3-B153-00C04F79FAA6" width="'+w+'" height="'+h+'"><param name="autoStart" value="'+bStart+'"><param name="URL" value="'+sPath+'"><param name="uiMode" value="full"><param name="stretchToFit" value="false"><embed name="player" type="video/x-ms-asf-plugin" src="'+sPath+'" width="'+w+'" height="'+h+'" showcontrols="1" autostart="'+bStart+'" animationstart="0" autorewind="0" autosize="0" showdisplay="0" showstatusbar="1" sendopenstatechangeevents="true" transparentatstart="true" pluginspage="http://www.microsoft.com/Windows/MediaPlayer/"></embed></object>';
		if (GetPlayerMajorVer(player.versionInfo)!=11 && GetPlayerMajorVer(player.versionInfo)!=10)
			vidbox.innerHTML='<p>You do not have the latest version of Windows Media Player. <a href="http://www.microsoft.com/windows/windowsmedia/download/alldownloads.aspx" target="_blank">Please visit Microsoft.com to download it</a>.</p>';
	}
}

function embedSLMovie(sPath,w,h,bStart){ // embed a movie using silverlight player
document.write("<div id=\"SilverLightBOX\" align=\"center\"	style=\"width: "+w+"px; height: "+h+"px ;background-position: center center; background-image:url(images/logo.gif); background-repeat:no-repeat;background-color:#000;\"></div>");
document.write('<script language="JavaScript" defer="defer" type="text/javascript">InsertSLPlayer("SilverLightBOX","'+sPath+'",'+w+','+h+',true)<\/scr' + 'ipt>');

}

function embedAudio(sPath,w,h,bStart){
var br = GetBrowser();        // Returns either "IE" or "Netscape"
if (br=="Netscape") {
	document.write("<div class=\"audio\"><embed name=\"vid\" type=\"video/x-ms-asf-plugin\" src=\""+sPath+"\" width=\""+w+"\" height=\""+h+"\" showcontrols=\"1\" autostart=\""+bStart+"\" animationstart=\"1\" autorewind=\"0\" autosize=\"0\" showdisplay=\"0\" showstatusbar=\"1\" sendopenstatechangeevents=\"true\" transparentatstart=\"true\" pluginspage=\"http://www.microsoft.com/Windows/MediaPlayer/\"></embed></div>");
}
else {
	document.write("<div class=\"audio\"><object id=\"player\" classid=\"CLSID:6BF52A52-394A-11d3-B153-00C04F79FAA6\" width=\""+w+"\" height=\""+h+"\"><param name=\"autoStart\" value=\""+bStart+"\"><param name=\"URL\" value=\""+sPath+"\"><param name=\"uiMode\" value=\"full\"><param name=\"stretchToFit\" value=\"false\"><embed name=\"player\" type=\"video/x-ms-asf-plugin\" src=\""+sPath+"\" width=\""+w+"\" height=\""+h+"\" showcontrols=\"1\" autostart=\""+bStart+"\" animationstart=\"1\" autorewind=\"0\" autosize=\"0\" showdisplay=\"0\" showstatusbar=\"1\" sendopenstatechangeevents=\"true\" transparentatstart=\"true\" pluginspage=\"http://www.microsoft.com/Windows/MediaPlayer/\"></embed></object></div>");
	if (GetPlayerMajorVer(player.versionInfo)!=11 && GetPlayerMajorVer(player.versionInfo)!=10)
		document.write("<p>You do not have the latest version of Windows Media Player. <a href=\"http://www.microsoft.com/windows/windowsmedia/download/alldownloads.aspx\" target=\"_blank\">Please visit Microsoft.com to download it</a>.</p>");
}
}

function popTimes(season,rallyid) {
	var w = window.open("","_new","width=420,height=550,scrollbars=yes");
	if (season!=undefined && rallyid!=undefined) 
		w.location.href="popTimes.jsp?season="+season+"&rallyid="+rallyid;
	else
		w.location.href="popTimes.jsp";
	w.focus();
}
// REPLACE WITH "swfobject"
function SWFObject(swf,title,w,h,ver,bg) {
	this.swf=swf;
	this.title=title;
	this.w=w;
	this.h=h;
	this.ver=ver;
	this.bg=bg;
	this.write=function(id) {
		swfobject.embedSWF(this.swf,id,this.w,this.h,this.ver);
	}
}

function Fetcher() {
	var me=this;
	this.fnCB=null;
	this.xmlHttp=null;
	try { this.xmlHttp=new XMLHttpRequest(); }
	catch (trymicrosoft) {
		try { this.xmlHttp=new ActiveXObject("Msxml2.XMLHTTP"); }
		catch (othermicrosoft) {
			try { this.xmlHttp=new ActiveXObject("Microsoft.XMLHTTP"); }
			catch (failed) {
				this.xmlHttp=null;
			}  
		}
	}
	this.now=function(sURL) {
		var sRet="";
		if (this.xmlHttp) {
			this.xmlHttp.open("GET",cacheBust(sURL),false);
			this.xmlHttp.send(null);
  			if (this.xmlHttp.readyState==4)
				sRet=this.xmlHttp.responseText.nocr().trim();
		}
		return sRet;
	}	
	this.whenever=function(sURL,fnCB) {
		if (this.xmlHttp) {
			this.fnCB=fnCB;
			this.xmlHttp.open("GET",cacheBust(sURL),true);
			this.xmlHttp.onreadystatechange=this.loader;
			this.xmlHttp.send(null);
		}
	}
	this.loader=function() {
		if (me.xmlHttp) {
			if (me.xmlHttp.readyState==4 && me.xmlHttp.status==200) {
				me.fnCB(me.xmlHttp.responseText.nocr().trim());
			}
		}
	}
}
function extractXML(sXML,sTag) {
	var iFrom=sXML.indexOf("<"+sTag+">");
	var iTo=sXML.indexOf("</"+sTag+">",iFrom);
	return (iFrom!=-1 && iTo!=-1 ? sXML.substring(iFrom+(sTag.length+2),iTo).nocr().trim() : "");
}
function cacheBust(sURL) {
	return sURL+(sURL.indexOf('?')==-1 ? '?' : '&')+'cbzz='+(new Date()).getTime();
}

function popLiveFeed() {
	var w = window.open("","_new","width=879,height=777,scrollbars=no,location=no");
	w.location.href="jsp/live_feed.htm";
	w.focus();
}

function onloadWRC() {
	if (typeof(goMovieOnLoad)=='function') goMovieOnLoad();
}




