
// Functions to gain min-width control over IE
function P7_limit(a,b){ //v1.1.2 by PVII-www.projectseven.com
	document.p7limit=a;document.p7min=b;
	if(document.getElementById&&navigator.appVersion.indexOf("MSIE")>-1&&!window.opera){
	if(window.attachEvent){window.attachEvent("onresize",P7_setMinWidth);
	window.attachEvent("onload",P7_setMinWidth);}else{onload=P7_setMinWidth;
	onresize=P7_setMinWidth;}}}

function P7_setMinWidth(){ //v1.1.2 by PVII-www.projectseven.com
	var cw,w,pl,pr,ml,mr,br,bl,ad,theDiv=document.p7limit;
	var g=document.getElementById(theDiv);w=parseInt(document.p7min);
	if(g&&document.body&&document.body.clientWidth){gs=g.currentStyle;
	cw=parseInt(document.body.clientWidth);pl=parseInt(gs.paddingLeft);
	pr=parseInt(gs.paddingRight);ml=parseInt(gs.marginLeft);mr=parseInt(gs.marginRight);
	bl=parseInt(gs.borderLeftWidth);br=parseInt(gs.borderRightWidth);ml=ml?ml:0;
	mr=mr?mr:0;pl=pl?pl:0;pr=pr?pr:0;bl=bl?bl:0;br=br?br:0;ad=pl+pr+ml+mr+bl+br;
	if(cw<=w){w-=ad;g.style.width=w+"px";}else{g.style.width="auto";}}
}
//P7_limit('pageWrap',770);
function lib_bwcheck(){ //Browsercheck (needed)
	this.ver=navigator.appVersion
	this.agent=navigator.userAgent
	this.dom=document.getElementById?1:0
	this.opera5=(navigator.userAgent.indexOf("Opera")>-1 && document.getElementById)?1:0
	this.ie5=(this.ver.indexOf("MSIE 5")>-1 && this.dom && !this.opera5)?1:0; 
	this.ie6=(this.ver.indexOf("MSIE 6")>-1 && this.dom && !this.opera5)?1:0;
	this.ie4=(document.all && !this.dom && !this.opera5)?1:0;
	this.ie=this.ie4||this.ie5||this.ie6
	this.mac=this.agent.indexOf("Mac")>-1
	this.ns6=(this.dom && parseInt(this.ver) >= 5) ?1:0; 
	this.ns4=(document.layers && !this.dom)?1:0;
	this.bw=(this.ie6 || this.ie5 || this.ie4 || this.ns4 || this.ns6 || this.opera5)
	return this
}
var bw=lib_bwcheck()



function NavOver(strID,strColour){

	getObj(strID).style.backgroundColor=strColour;
	
}

function NavOut(strID,strColour){

	getObj(strID).style.backgroundColor=strColour;
	
}



function QuickLinks(strURL){
	if(strURL !='0'){
		if(strURL.substring(0,4)=="http"){
			window.open(strURL,'')
		}else{
			document.location.href=strURL
		}
	}
}







/**********************************************************************************   
ScrollText 
*   Copyright (C) 2001 Thomas Brattli
*   This script was released at DHTMLCentral.com
*   Visit for more great scripts!
*   This may be used and changed freely as long as this msg is intact!
*   We will also appreciate any links you could give us.
*
*   Made by Thomas Brattli
*
*   Script date: 09/23/2001 (keep this date to check versions) 
*********************************************************************************/

/*****************
You set the width and height of the divs inside the style tag, you only have to
change the divScrollTextCont, Remember to set the clip the same as the width and height.
You can remove the divUp and divDown layers if you want. 
This script should also work if you make the divScrollTextCont position:relative.
Then you should be able to place this inside a table or something. Just remember
that Netscape crash very easily with relative positioned divs and tables.

Updated with a fix for error if moving over layer before pageload.

****************/


//If you want it to move faster you can set this lower, it's the timeout:
var speed = 30

//Sets variables to keep track of what's happening
var loop, timer

//Object constructor
function makeObj(obj,nest){
    nest=(!nest) ? "":'document.'+nest+'.'
	this.el=bw.dom?document.getElementById(obj):bw.ie4?document.all[obj]:bw.ns4?eval(nest+'document.'+obj):0;
  	this.css=bw.dom?document.getElementById(obj).style:bw.ie4?document.all[obj].style:bw.ns4?eval(nest+'document.'+obj):0;
	this.scrollHeight=bw.ns4?this.css.document.height:this.el.offsetHeight
	this.clipHeight=bw.ns4?this.css.clip.height:this.el.offsetHeight
	this.up=goUp;this.down=goDown;
	this.moveIt=moveIt; this.x=0; this.y=0;
    this.obj = obj + "Object"

    eval(this.obj + "=this")
    return this
}

// A unit of measure that will be added when setting the position of a layer.
var px = bw.ns4||window.opera?"":"px";

function moveIt(x,y){
	this.x = x
	this.y = y
	this.css.left = this.x+px
	this.css.top = this.y+px
}

//Makes the object go up
function goDown(move){
	if (this.y>-this.scrollHeight+oCont.clipHeight){
		this.moveIt(0,this.y-move)
			if (loop) setTimeout(this.obj+".down("+move+")",speed)
	}
}
//Makes the object go down
function goUp(move){
	if (this.y<0){
		this.moveIt(0,this.y-move)
		if (loop) setTimeout(this.obj+".up("+move+")",speed)
	}
}

//Calls the scrolling functions. Also checks whether the page is loaded or not.
function scroll(speed){
	if (scrolltextLoaded){
		loop = true;
		if (speed>0) oScroll.down(speed)
		else oScroll.up(speed)
	}
}

//Stops the scrolling (called on mouseout)
function noScroll(){
	loop = false
	if (timer) clearTimeout(timer)
}
//Makes the object
var scrolltextLoaded = false
function scrolltextInit(){
	oCont = new makeObj('divScrollTextCont')
	oScroll = new makeObj('divText','divScrollTextCont')
	oScroll.moveIt(0,0)
	oCont.css.visibility = "visible"
	scrolltextLoaded = true
}
//Call the init on page load if the browser is ok...

function ScrollUP(){
	scroll(10);
}
function ScrollDOWN(){
	scroll(-10);
	//setTimeout("noScroll()",250);
}
function ScrollStop(){
	noScroll()
}


// PHOTO GALLERIES MOUDULE  //
function NewArrayItem(strHtml){
	this.strHtml = strHtml
}

function displayContent(strHTML, objHTML){
	//alert(strHTML);
	objHTML.innerHTML = unescape(strHTML)
}


// ROTATING NEWS BANNER //
// Scripts for the Rotating News stuff....
var intSecondBetweenItems = 5
var intPreviousItem = 0
function DisplayContent(strID){	
	if(intPreviousItem!=0)SwapButton(intPreviousItem,""); 			///aru/css/images/HomeNewsNumberGrey.gif
	SwapButton(strID,"/aru/css/images/onside/HomeNewsNumberActive.gif");	///aru/css/images/HomeNewsNumberGreen.gif
	displayObj = getObj("newsContent");
	displayObj.innerHTML = ""
	displayObj.innerHTML = unescape(arrHomeNews[strID].strHtml)	
	if(intTotalItems == parseInt(strID)){
		intNextNewsID = 1	
	}else{
		intNextNewsID = parseInt(strID) + 1	
	}		
	intPreviousItem = strID
}

function cycleNewsItems(strID){
	if(blnCycleNews){
		DisplayContent(strID)
		setTimeout("cycleNewsItems(intNextNewsID)", intSecondBetweenItems*1000)
	}
}

function DisplayNewsItem(strID){
	blnCycleNews = false
	DisplayContent(strID);
}

function PauseNews(){
	blnCycleNews = false
}
function restartNews(){
	if(!blnCycleNews){
		blnCycleNews = true
		cycleNewsItems(intNextNewsID);
	}
}	

function GoBackOne(){
	blnCycleNews = false
	intNextNewsID = intNextNewsID - 2
	if(intNextNewsID < 1){
		intNextNewsID = intNextNewsID + intTotalItems	
	}	
	DisplayContent(intNextNewsID);	
}
function GoForwardOne(){
	blnCycleNews = false
	DisplayContent(intNextNewsID);
}	
function initNews(){
	cycleNewsItems(1)
}

function SwapButton(strID,strImageAndPath){
	objButton = getObj("news_" + strID)
	if(strImageAndPath==""){
		objButton.style.background='none'
	}else{
		objButton.style.background='url('+ strImageAndPath +') no-repeat'
	}
}

function getObj(id){
	if(document.getElementById){
		return document.getElementById(id);
	}else{
		return document.all[id];
	} 
}

function externalLinksByHref() {

  //var base_url = (document.URL ? document.URL : document.location.href).substr(0,(document.URL ? document.URL : document.location.href).indexOf('/',8));
  if (document.getElementsByTagName) {
    var anchors = document.getElementsByTagName('a');
    for (var i=0; i<anchors.length; i++) {
      var anchor = anchors[i];
      if ((anchor.getAttribute('href').indexOf('http:\/\/')==0 || anchor.getAttribute('href').indexOf('https:\/\/')==0) && (anchor.getAttribute('href').indexOf('rugby.')<0 && anchor.getAttribute('href').indexOf('aru.')<0)) {
		    //alert(anchor.getAttribute('href'))
		    anchor.target = '_blank';
      }
      //alert(anchor.getAttribute('href'));
      if (anchor.getAttribute('href') == 'http://www.aru.pickthescore.com.au/') {
		    //alert(anchor.getAttribute('href'));
		    anchor.target = '_blank';
      }     
    }
  }
  else if (document.links) {
    var anchors = document.links;
    for (var i=anchors.length-1; i>=0; i--) {
      var anchor = anchors[i];
      if ((anchor.href.indexOf('http:\/\/')==0 || anchor.href.indexOf('https:\/\/')==0) && (anchor.href.indexOf('rugby.')<0 || anchor.getAttribute('href').indexOf('aru.')<0)) {
	      anchor.target = '_blank';
      }
      if ((anchor.href.indexOf('http:\/\/')==0 || anchor.href.indexOf('https:\/\/')==0) && (anchor.href.indexOf('aru.pickthescore.com.au')>0)) {
		    anchor.target = '_blank';
      }
    } 
  }
}

function setRowColor(id, strColour){
	// -- get element (the table), TBODY tag, children of (TR tags)
	var r=document.getElementById(id).getElementsByTagName('tr');
	 // - total number of TR tags
	var l=r.length
	for (i=0;i<l;i++){
		if (i%2 == 0){r[i].style.backgroundColor=strColour;}
		else {}
	}
}


// -----------------------------------------------------------------------------------------------------------------------------------------
/// Flash UFO functions
// -----------------------------------------------------------------------------------------------------------------------------------------

function FixHomeFlash(strFlashPath){
	var FO = { movie:strFlashPath, width:"554px", height:"210px", wmode:"transparent", majorversion:"6", build:"40"};
	UFO.create(FO, "homeHero");	
}


// -----------------------------------------------------------------------------------------------------------------------------------------
/// Popup functions
// -----------------------------------------------------------------------------------------------------------------------------------------

function PhotoPop(id,sectiodID){
	if(id!=""){
		var strURL = "/aru/photo.asp?id=" + id + "&section=" + sectiodID
		var objPhotoWindow = window.open(strURL,'photo','height=500,width=550,left=10,top=10,directories=0,fullscreen=0,location=0,menubar=0,scrollbars=1,resizable=0,status=0,toolbar=0');
	}
}

function OnlineGamesPop(id){
	if(id!=""){
		var strURL = "/clubwallaby/playgame.asp?game=" + id
		var objGamesWindow = window.open(strURL,'games','height=450,width=650,left=10,top=10,directories=0,fullscreen=0,location=0,menubar=0,scrollbars=0,resizable=0,status=0,toolbar=0');
		//objGamesWindow.opener = self;
	}
}

function eCardPop(id){
	if(id!=""){
		var strURL = "/aru/ecard.asp?ecard=" + id
		var objeCardWindow = window.open(strURL,'ecard','height=400,width=500,left=10,top=10,directories=0,fullscreen=0,location=0,menubar=0,scrollbars=0,resizable=0,status=0,toolbar=0');
	}
}

function eQuizPop(strURL){
		var objeQuizWindow = window.open(strURL,'equiz','height=480,width=700,left=10,top=10,directories=0,fullscreen=0,location=0,menubar=0,scrollbars=0,resizable=0,status=0,toolbar=0');
}

function FindSchoolPop(){
	var strURL = "/functions/form/aru_find_school.asp";
	var objFindSchoolWindow = window.open(strURL,'find_school','height=450,width=650,left=10,top=10,directories=0,fullscreen=0,location=0,menubar=0,scrollbars=1,resizable=0,status=0,toolbar=0');
}
function getRandomNumber(intCeiling){
	return Math.ceil(Math.random()*intCeiling)
}

// -----------------------------------------------------------------------------------------------------------------------------------------
/// Form validation functions
// -----------------------------------------------------------------------------------------------------------------------------------------
function strTrim(strText) {
	for (i=0; i<strText.length; ++i) {
		if (strText.charAt(i) != ' ') break;
	}
	if (i >= strText.length) return ('');
	if (i > 0) strText = strText.substring(i, strText.length);
	for (j=strText.length-1; j > i; --j) {
		if (strText.charAt(j) != ' ') break;
	}
	if (j < strText.length -1)
		strText = strText.substring(0, j+1);
	return strText;
}
function ValidEmail(email){
  var result = false
  var theStr = new String(email)
  var index = theStr.indexOf("@");
  if (index > 0){
    var pindex = theStr.indexOf(".",index);
    if ((pindex > index+1) && (theStr.length > pindex+1))
	result = true;
  }
  if (theStr.indexOf(" ") > 0 )  return false;  
  if (theStr.indexOf("@", index + 1) > 0 ) return false;
  return result;
}

function isInteger(s){   
	var i;
    for (i = 0; i < s.length; i++){   
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}

function stripCharsInBag(s, bag){   
	var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++){   
        // Check that current character isn't whitespace.
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

function ValidPhone(strPhone, minDigitsInIPhoneNumber){
	var phoneNumberDelimiters = "()- ";
	var validWorldPhoneChars = phoneNumberDelimiters + "+";
	s=stripCharsInBag(strPhone, validWorldPhoneChars);
	return (isInteger(s) && s.length >= minDigitsInIPhoneNumber);
}

function ValidPhoneStripped(strPhone, minDigitsInIPhoneNumber){
	var phoneNumberDelimiters = "()- ";
	var validWorldPhoneChars = phoneNumberDelimiters + "+";
	s=stripCharsInBag(strPhone, validWorldPhoneChars);
	if ((isInteger(s) && s.length >= minDigitsInIPhoneNumber)){
		return stripCharsInBag(strPhone, phoneNumberDelimiters);
	}else{
		return false;
	}
}

function ValidText(strText, intMin){
	if (strText == "" || strText.length < intMin){
		return false;
	}else{
		return true;
	}
}

function TextStartNumber(strText){   
	// Check if first character is a number
	if ((strText.charAt(0) < "0") || (strText.charAt(0) > "9")){	
		return false;
	}else{
		return true;
	}
}	
function ValidChecked(objField) {
// This can be used for both checkboxes and radio buttons
	if(objField.length) {
		for (var i=0 ; i<objField.length ; i++) {
			if (objField[i].checked)
				return true;
		}
	}else{
		//only one item
		if(objField.checked)
			return true;
	}
}



function IsValidDate(intDay, strMonth, intYear) {
	var blnLeapYear = false;
	var blnRet = false;

	if ((intDay>0) && (intDay<32) && (intYear>1900)) {
		switch (strMonth.toLowerCase()) {
		case "4":
		case "6":
		case "9":
		case "11":
		case "apr":
		case "jun":
		case "sep":
		case "nov":
			if (intDay < 31) blnRet = true;
			break;
		case "2":
		case "feb":
			if (intYear % 100 == 0) {
				if (intYear % 400 == 0)
					blnLeapYear = true;
			}
			else {
				if (intYear % 4 == 0)
					blnLeapYear = true;
			}

			if (blnLeapYear) {
				if (intDay < 30)
					blnRet = true;
			}
			else {
				if (intDay < 29)
					blnRet = true;
			}
			break;
		default:
			blnRet = true;
		}
	}
	return blnRet
}

var MONTH_NAMES=new Array('January','February','March','April','May','June','July','August','September','October','November','December','Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec');
var DAY_NAMES=new Array('Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday','Sun','Mon','Tue','Wed','Thu','Fri','Sat');
function LZ(x) {return(x<0||x>9?"":"0")+x}

// ------------------------------------------------------------------
// isDate ( date_string, format_string )
// Returns formated date if date string matches format of format string and
// is a valid date. Else returns false.
// It is recommended that you trim whitespace around the value before
// passing it to this function, as whitespace is NOT ignored!
// ------------------------------------------------------------------
function isDate(val,format) {
	// Convert the date
	val = parseDate(val, true);
	if (val == null) { return false; }
	// Format the date
	val = formatDate(val, format);
	if (val == null) { return false; }
	// Check if it is a valid date
	var date=getDateFromFormat(val,format);
	if (date==0) { return false; }
	return val;
}
// -------------------------------------------------------------------
// compareDates(date1,date1format,date2,date2format)
//   Compare two date strings to see which is greater.
//   Returns:
//   1 if date1 is greater than date2
//   0 if date2 is greater than date1 of if they are the same
//  -1 if either of the dates is in an invalid format
// -------------------------------------------------------------------
function compareDates(date1,dateformat1,date2,dateformat2) {
	var d1=getDateFromFormat(date1,dateformat1);
	var d2=getDateFromFormat(date2,dateformat2);
	if (d1==0 || d2==0) {
		return -1;
		}
	else if (d1 > d2) {
		return 1;
		}
	return 0;
	}

// ------------------------------------------------------------------
// formatDate (date_object, format)
// Returns a date in the output format specified.
// The format string uses the same abbreviations as in getDateFromFormat()
// ------------------------------------------------------------------
function formatDate(date,format) {
	format=format+"";
	var result="";
	var i_format=0;
	var c="";
	var token="";
	var y=date.getYear()+"";
	var M=date.getMonth()+1;
	var d=date.getDate();
	var E=date.getDay();
	var H=date.getHours();
	var m=date.getMinutes();
	var s=date.getSeconds();
	var yyyy,yy,MMM,MM,dd,hh,h,mm,ss,ampm,HH,H,KK,K,kk,k;
	// Convert real date parts into formatted versions
	var value=new Object();
	if (y.length < 4) {y=""+(y-0+1900);}
	value["y"]=""+y;
	value["yyyy"]=y;
	value["yy"]=y.substring(2,4);
	value["M"]=M;
	value["MM"]=LZ(M);
	value["MMM"]=MONTH_NAMES[M-1];
	value["NNN"]=MONTH_NAMES[M+11];
	value["d"]=d;
	value["dd"]=LZ(d);
	value["E"]=DAY_NAMES[E+7];
	value["EE"]=DAY_NAMES[E];
	value["H"]=H;
	value["HH"]=LZ(H);
	if (H==0){value["h"]=12;}
	else if (H>12){value["h"]=H-12;}
	else {value["h"]=H;}
	value["hh"]=LZ(value["h"]);
	if (H>11){value["K"]=H-12;} else {value["K"]=H;}
	value["k"]=H+1;
	value["KK"]=LZ(value["K"]);
	value["kk"]=LZ(value["k"]);
	if (H > 11) { value["a"]="PM"; }
	else { value["a"]="AM"; }
	value["m"]=m;
	value["mm"]=LZ(m);
	value["s"]=s;
	value["ss"]=LZ(s);
	while (i_format < format.length) {
		c=format.charAt(i_format);
		token="";
		while ((format.charAt(i_format)==c) && (i_format < format.length)) {
			token += format.charAt(i_format++);
			}
		if (value[token] != null) { result=result + value[token]; }
		else { result=result + token; }
		}
	return result;
	}
	
// ------------------------------------------------------------------
// Utility functions for parsing in getDateFromFormat()
// ------------------------------------------------------------------
function _isInteger(val) {
	var digits="1234567890";
	for (var i=0; i < val.length; i++) {
		if (digits.indexOf(val.charAt(i))==-1) { return false; }
		}
	return true;
	}
	
function _getInt(str,i,minlength,maxlength) {
	for (var x=maxlength; x>=minlength; x--) {
		var token=str.substring(i,i+x);
		if (token.length < minlength) { return null; }
		if (_isInteger(token)) { return token; }
		}
	return null;
	}
	
// ------------------------------------------------------------------
// getDateFromFormat( date_string , format_string )
//
// This function takes a date string and a format string. It matches
// If the date string matches the format string, it returns the 
// getTime() of the date. If it does not match, it returns 0.
// ------------------------------------------------------------------
function getDateFromFormat(val,format) {
	val=val+"";
	format=format+"";
	var i_val=0;
	var i_format=0;
	var c="";
	var token="";
	var token2="";
	var x,y;
	var now=new Date();
	var year=now.getYear();
	var month=now.getMonth()+1;
	var date=1;
	var hh=now.getHours();
	var mm=now.getMinutes();
	var ss=now.getSeconds();
	var ampm="";
	
	while (i_format < format.length) {
		// Get next token from format string
		c=format.charAt(i_format);
		token="";
		while ((format.charAt(i_format)==c) && (i_format < format.length)) {
			token += format.charAt(i_format++);
			}
		// Extract contents of value based on format token
		if (token=="yyyy" || token=="yy" || token=="y") {
			if (token=="yyyy") { x=4;y=4; }
			if (token=="yy")   { x=2;y=2; }
			if (token=="y")    { x=2;y=4; }
			year=_getInt(val,i_val,x,y);
			if (year==null) { return 0; }
			i_val += year.length;
			if (year.length==2) {
				if (year > 70) { year=1900+(year-0); }
				else { year=2000+(year-0); }
				}
			}
		else if (token=="MMM"||token=="NNN"){
			month=0;
			for (var i=0; i<MONTH_NAMES.length; i++) {
				var month_name=MONTH_NAMES[i];
				if (val.substring(i_val,i_val+month_name.length).toLowerCase()==month_name.toLowerCase()) {
					if (token=="MMM"||(token=="NNN"&&i>11)) {
						month=i+1;
						if (month>12) { month -= 12; }
						i_val += month_name.length;
						break;
						}
					}
				}
			if ((month < 1)||(month>12)){return 0;}
			}
		else if (token=="EE"||token=="E"){
			for (var i=0; i<DAY_NAMES.length; i++) {
				var day_name=DAY_NAMES[i];
				if (val.substring(i_val,i_val+day_name.length).toLowerCase()==day_name.toLowerCase()) {
					i_val += day_name.length;
					break;
					}
				}
			}
		else if (token=="MM"||token=="M") {
			month=_getInt(val,i_val,token.length,2);
			if(month==null||(month<1)||(month>12)){return 0;}
			i_val+=month.length;}
		else if (token=="dd"||token=="d") {
			date=_getInt(val,i_val,token.length,2);
			if(date==null||(date<1)||(date>31)){return 0;}
			i_val+=date.length;}
		else if (token=="hh"||token=="h") {
			hh=_getInt(val,i_val,token.length,2);
			if(hh==null||(hh<1)||(hh>12)){return 0;}
			i_val+=hh.length;}
		else if (token=="HH"||token=="H") {
			hh=_getInt(val,i_val,token.length,2);
			if(hh==null||(hh<0)||(hh>23)){return 0;}
			i_val+=hh.length;}
		else if (token=="KK"||token=="K") {
			hh=_getInt(val,i_val,token.length,2);
			if(hh==null||(hh<0)||(hh>11)){return 0;}
			i_val+=hh.length;}
		else if (token=="kk"||token=="k") {
			hh=_getInt(val,i_val,token.length,2);
			if(hh==null||(hh<1)||(hh>24)){return 0;}
			i_val+=hh.length;hh--;}
		else if (token=="mm"||token=="m") {
			mm=_getInt(val,i_val,token.length,2);
			if(mm==null||(mm<0)||(mm>59)){return 0;}
			i_val+=mm.length;}
		else if (token=="ss"||token=="s") {
			ss=_getInt(val,i_val,token.length,2);
			if(ss==null||(ss<0)||(ss>59)){return 0;}
			i_val+=ss.length;}
		else if (token=="a") {
			if (val.substring(i_val,i_val+2).toLowerCase()=="am") {ampm="AM";}
			else if (val.substring(i_val,i_val+2).toLowerCase()=="pm") {ampm="PM";}
			else {return 0;}
			i_val+=2;}
		else {
			if (val.substring(i_val,i_val+token.length)!=token) {return 0;}
			else {i_val+=token.length;}
			}
		}
	// If there are any trailing characters left in the value, it doesn't match
	if (i_val != val.length) { return 0; }
	// Is date valid for month?
	if (month==2) {
		// Check for leap year
		if ( ( (year%4==0)&&(year%100 != 0) ) || (year%400==0) ) { // leap year
			if (date > 29){ return 0; }
			}
		else { if (date > 28) { return 0; } }
		}
	if ((month==4)||(month==6)||(month==9)||(month==11)) {
		if (date > 30) { return 0; }

		}
	// Correct hours value
	if (hh<12 && ampm=="PM") { hh=hh-0+12; }
	else if (hh>11 && ampm=="AM") { hh-=12; }
	var newdate=new Date(year,month-1,date,hh,mm,ss);
	return newdate.getTime();
	}

function CoachConfirmDelete(strURL){
	if (confirm('Are you sure you want to delete this session? This can not be undone!')){
		window.location.href=strURL;
	}
}

function CoachLoadSession(strURL){
	if (confirm('Are you sure you want to edit this session? \nThis Session will be loaded into your Clipboard. Any unsaved \nactivities in your clipboard will be lost.')){
		window.location.href=strURL;
	}
}
function CheckSession(blnOK, intCoachID, objForm){
	var strSessionName = objForm.SessionName.value
	
	if(blnOK && intCoachID!='' && strSessionName!=''){
		return true;

	}else if(!blnOK){
		alert("This session cant be saved as it does not contain at least one \nof each Warm-Up, Physical and Warm-Down activity types");
		return false;
	}else if(strSessionName==''){
		alert("Please enter a session name.");
		return false;
	}else if(intCoachID==''){
		alert("You must login or register to save your sessions.\nYou will now be redirected to our login/register page.");
		return true;
	}
}
function NewClipboard(strURL){
	if (confirm('Are you sure you want to end this session and clear your clipboard? \nAny unsaved activities in your clipboard will be lost.')){
		window.location.href=strURL;
	}
}
function PrintSession(intID){
		var objPrintSession = window.open("/aru/printsession.asp?id=" + intID,'printSession','height=600,width=700,left=10,top=10,directories=0,fullscreen=0,location=0,menubar=1,scrollbars=1,resizable=0,status=0,toolbar=0');
}


// Toggle Panel for Homepage Leaderboard
var strPrevId
var strPrevImgOffSrc
var objPrevPanel = ""
var objPrevMenu = ""
var objPrevMenuImg = ""
function togglePanel(id,newImgSrc,newImgOffSrc) {
		
		var objNewPanel = xDOM('ladder_' + id,0);
		var objNewMenu = xDOM('ladder_' + id,0);
		var objNewMenuImg = xDOM('ladderimg_' + id,0);
		
		if(strPrevId != ""){
			objPrevPanel = xDOM('ladder_' + strPrevId,0);
			objPrevMenu = xDOM('ladder_' + strPrevId,0);
			objPrevMenuImg = xDOM('ladderimg_' + strPrevId,0);
		}
		if(objPrevPanel != "" & id == strPrevId){
			objPrevPanel.style.display = "block";
			objPrevMenu.blur();
			objPrevPanel = id;
			strPrevId = id;
		} else if(objPrevPanel != "" & id != strPrevId){
			objPrevPanel.style.display = "none";
			objPrevMenu.className = 'inactive';
			objPrevMenuImg.src = strPrevImgOffSrc;
			objNewPanel.style.display = "block";
			objNewMenu.className = 'active';
			objNewMenuImg.src = newImgSrc;
			objNewMenu.blur();
			objPrevPanel = objNewPanel;
			strPrevId = id;
			strPrevImgOffSrc = newImgOffSrc;
		} 
		
	}
	
// Toggle Panel for Homepage Matches
var strPrevMatchesPanel
var strPrevMatchesTabImgOffSrc
var objPrevPanel = ""
var objPrevMenu = ""
var objPrevMenuImg = ""
function toggleHomeMatches(id,newImgSrc,newImgOffSrc) {
		
		var objNewPanel = xDOM('items_' + id,0);
		var objNewMenu = xDOM('menu_' + id,0);
		var objNewMenuImg = xDOM('matchesTab_' + id,0);
		
		if(strPrevMatchesPanel != ""){
			objPrevPanel = xDOM('items_' + strPrevMatchesPanel,0);
			objPrevMenu = xDOM('menu_' + strPrevMatchesPanel,0);
			objPrevMenuImg = xDOM('matchesTab_' + strPrevMatchesPanel,0);
		}
		if(objPrevPanel != "" & id == strPrevMatchesPanel){
			objPrevPanel.style.display = "block";
			objPrevMenu.blur();
			objPrevPanel = id;
			strPrevMatchesPanel = id;
		} else if(objPrevPanel != "" & id != strPrevMatchesPanel){
			objPrevPanel.style.display = "none";
			objPrevMenu.className = 'inactive';
			objPrevMenuImg.src = strPrevMatchesTabImgOffSrc;
			objNewPanel.style.display = "block";
			objNewMenu.className = 'active';
			objNewMenuImg.src = newImgSrc;
			objNewMenu.blur();
			objPrevPanel = objNewPanel;
			strPrevMatchesPanel = id;
			strPrevMatchesTabImgOffSrc = newImgOffSrc;
		} 
		scrolltextInit();  //initialize scrolling div
	}

// Toggle Match for Homepage Feature Match
var strPrevFeature = ""
var strPrevClassname = ""
var objPrevFeature = ""
var objPrevItem = ""

function toggleFeatureMatch(id,prevclass) {
		
		var objNewFeature = xDOM('featureMatch_' + id,0);
		var objNewItem = xDOM('matchItem_' + id,0);
		
		if(strPrevFeature != ""){
			objPrevFeature = xDOM('featureMatch_' + strPrevFeature,0);
			objPrevItem = xDOM('matchItem_' + strPrevFeature,0);
		}
		if(objPrevFeature != "" & id == strPrevFeature){
			objPrevFeature.style.display = "block";
			objPrevItem.blur();
			objPrevFeature = id;
			strPrevFeature = id;
		} else if(objPrevFeature != "" & id != strPrevFeature){
			objPrevFeature.style.display = "none";
			objPrevItem.className = strPrevClassname;
			objNewFeature.style.display = "block";
			objNewItem.className = 'active ' + prevclass;
			objNewItem.blur();
			objPrevFeature = objNewFeature;
			strPrevFeature = id;
			strPrevClassname = prevclass;
		} 
}
	


// Cross Browser DOM Functions used to create objects and get top / left coords
// copyright Stephen Chapman, 4th Jan 2005
// you may copy this code but please keep the copyright notice as well
var aDOM = 0, ieDOM = 0, nsDOM = 0
var stdDOM = document.getElementById;
if (stdDOM) aDOM = 1; else {
  ieDOM = document.all;
  if (ieDOM) aDOM = 1; else {
    var nsDOM = (
      (navigator.appName.indexOf('Netscape') != -1)
      && (parseInt(navigator.appVersion) ==4));
    if (nsDOM) aDOM = 1;
  }
}
function xDOM(objectId, withStyle) {
var st = ''; if (withStyle) st = '.style';
if (stdDOM) return (eval('document.getElementById(objectId)'+st));
if (ieDOM) return (eval('document.all[objectId]'+st));
if (nsDOM) return (document.layers[objectId]);
}


function LoginWait()
{
	if(document.getElementById('globalLogin')) {document.getElementById('globalLogin').style.display="none";}
	if(document.getElementById('globalLoginWait')) {document.getElementById('globalLoginWait').style.display="block";}
}

function LogoutWait()
{
	if(document.getElementById('globalLoginMessage')) {document.getElementById('globalLoginMessage').style.display="none";}
	if(document.getElementById('globalLogoutWait')) {document.getElementById('globalLogoutWait').style.display="block";}
}


function PCTTag(strID)
{
	var dd = new Date();
	var ord = Math.round(Math.abs(Math.sin(dd.getTime()))*1000000000)%10000000;
	var adsfac_image = new Image(1,1);
	adsfac_image.src = 'http://adsfac.net/pct_mx.asp?L=' + strID + '&amp;ref='+escape(top.document.referrer)+'&amp;url='+escape(top.document.URL)+'&amp;ord='+ord;
}

