MSIE = (navigator.appName=="Microsoft Internet Explorer")?-1:0;

maxwks = 5; firstyr = 1897;

function page(pgnum){
 var str= document.URL
 var newurl = (str.replace(/pg=\d+/, "pg="+pgnum));

 if(newurl==str){
	add = "?";
	if(str.search(/\?/) > 0)add="&";
	newurl = str + add + "pg=" + pgnum
 }
 window.location = newurl
}

function runtest(event,loaddoc){
 if (MSIE) src = window.event.srcElement; 
 else src = event.target;
 par = document.getElementById("item"+src.id)
 ifr = document.getElementById('iframe');
 ifr.src = loaddoc
}

function iframeloaded(event) {

try{
 if (MSIE) doc = document.frames["iframe"].document
 else doc = document.getElementById("iframe").contentDocument
 //showprop(doc)
 updpg = doc.getElementById("mydata"); 
 b = updpg.innerHTML
 a = document.getElementById("item1")
 a.innerHTML = b
 setup()
}
catch (e){}


} 
function changeyrto(){
}

function changeyrto2(){
 yrrd1 = new Array (1907, 1915, 1916, 1917, 1918, 1924, 1925, 1941, 1943, 1944, 1945, 1949, 1951, 1952, 1967, 1969, 1990, 1992, 2010)
 yrrd2 = new Array (14, 18, 12, 15, 14, 18, 17, 18, 16, 18, 20, 19, 18, 19, 18, 20, 22, 24, 22)
 noofrds = 22;
 yrtoopt = document.getElementById("yrtoopt")

 for(x=yrrd1.length;x>-1;x--)if(yrtoopt.value <= yrrd1[x])noofrds=yrrd2[x]
 if (yrtoopt.value==curyr)noofrds = currd

try{
 rdbox = document.getElementById("rdfmopt"); rdboxval = rdbox.value;
 rdbox.options.length = 0
 for (x=1;x<noofrds+1;x++)rdbox.options[rdbox.options.length] = new Option(x,x);
 if (yrtoopt.value!=curyr||currd>22)rdbox.options[rdbox.options.length] = new Option('Finals',99);
 rdbox.value = rdboxval;
}
catch(e){}

}

teams = new Array("Adelaide","Bris Bears","Bris Lions","Carlton","Collingwood","Essendon","Fitzroy","Fremantle","Geelong","Hawthorn","Melbourne","Nth Melb","Port Adel","Richmond","St Kilda","Sydney","University","W Bulldogs","West Coast");
tmsab = new Array("Adel","BriB","Bris","Carl","Coll","Ess","Fitz","Frem","Geel","Haw","Melb","NM","Port","Rich","St K","Syd","Univ","WB","WC");
tmsfn = new Array("Adelaide","Brisbane Bears","Brisbane Lions","Carlton","Collingwood","Essendon","Fitzroy","Fremantle","Geelong","Hawthorn","Nth Melb","Melbourne","Port Adelaide","Richmond","St Kilda","Sydney","University","Western Bulldogs","West Coast Eagles");

gndsa = new Array   ('ALL','AAMI', 'Alb', 'ANZ', 'AP', 'AS', 'Aur', 'BS', 'BSC', 'BXG', 'Car', 'CO', 'Cob', 'EM', 'Eti', 'Eur', 'Gabba', 'GO', 'JO', 'Man', 'Mar', 'MCG', 'Mor', 'Mot', 'NHO', 'OO', 'PR', 'Pra', 'SCG', 'SS', 'Sub',  'VP', 'WACA', 'Wav', 'WH', 'WO', 'Yal', 'Yvl', '---', 'VIC','SA','WA','TAS', 'NSW', 'QLD','ACT', 'NT'); 
gndsvala = new Array (0, 1, 3, 28, 2, 4, 37, 8, 7, 6, 9, 11, 10, 12, 27, 13, 5, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 29, 26, 24, 25, 30, 32, 31, 34, 33, 35, 36,'999',100,101,102,103,104,105,106,107);

citya = new Array('Adelaide','Brisbane','Geelong','Melbourne','Perth','Sydney');
statea = new Array("ACT","NSW","NT","Qld","SA","Tas","Vic","WA"); 

inpd = new Array("","at 1/4 time", "at 1/2 time", "at 3/4 time","at Full Time", "in 2nd Quarter", "in 3rd Quarter", "in 4th Quarter", "in the 2nd Half", "Last 3 Qtrs")

fmqtr = new Array("3/4 time","1/2 time", "1/4 time")

gmsarr = new Array("All","Home/Away","Finals", "Rd 1","Rd 2","Rd 3","Rd 4","Rd 5","Rd 6","Rd 7","Rd 8","Rd 9", "Rd 10", "Rd 11", "Rd 12", "Rd 13","Rd 14", "Rd 15", "Rd 16", "Rd 17", "Rd 18", "Rd 19", "Rd 20", "Rd 21", "Rd 22", "Rd 23", "Rd 24", "RR", "EF", "QF", "SF", "PF", "GF" )


xtrahed = ""; xtrainp = "";





function doform(itms){

 vars = itms.split("//")
 numofcols = 0;
 if (itms == "all")itms="t1t2yrfmyrtoinatgndsrdfmwhentygms";

 txt1 = "<form action='' type='get'>"

 if(itms.indexOf("ty")>-1)txt1 += "<input name='ty' type='hidden' value='" + ty + "' />"
 
 if(itms.indexOf("recs")>-1){
//	txt1 += "<input name='recs' type='hidden' value='" + recs + "' />"
	txt1 += "<b>Record:</b> <select name='recs'>";
	reca = new Array("Highest Scores","Lowest Scores","Greatest Margins","Most Goals","Least Goals", "Most Behinds", "Least Behinds", "Most Scoring Shots", "Least Scoring Shots", "Best Accuracy", "Worst Accuracy","Highest Aggregate Scores","Lowest Aggregate Scores", "Highest Losing Scores", "Lowest Winning Scores" ,"Biggest Upsets");
	for(x=0;x<reca.length;x++){
		xtxt = ""; if(x==recs)xtxt=" SELECTED"
		txt1 += "<option" + xtxt + " value='" + x + "'>"+reca[x]+"</option>";
	}
	txt1 += "</select>";

 }

 txt1 += "<table class='blank'><tr>";
 txt2 = "</tr><tr>";

 if(itms.indexOf("t1")>-1){
  numofcols ++
  txt1 += "<th>Team 1</th>"
  txt2 += "<td><select name='t1'><option value=''>All</option>"
  for (x=0;x<teams.length;x++){
   nx = x; if(nx==10)nx=11; else if(nx==11)nx=10;
   xtxt = ""; if(nx==t1)xtxt = "SELECTED ";
   txt2 += "<option " + xtxt + "value='" + nx + "'>" + teams[x] + "</option>"
  }
  txt2 += "</select></td>"
 }



 if(itms.indexOf("t2")>-1){
  numofcols ++
  txt1 += "<th>Team 2</th>"
  txt2 += "<td><select name='t2'><option value=''>All</option>"
  for (x=0;x<teams.length;x++){
   nx = x; if(nx==10)nx=11; else if(nx==11)nx=10;
   xtxt = ""; if(nx==t2)xtxt = "SELECTED ";
   txt2 += "<option " + xtxt + "value='" + nx + "'>" + teams[x] + "</option>"
  }
  txt2 += "</select></td>"
 }


 if(itms.indexOf("yrfm")>-1){
  numofcols ++
  txt1 += "<th>From</th>"
  txt2 += "<td><select id='yrfmopt' name='yrfm' onchange=''>"
  for (x=1897;x<curyr+1;x++){
   if(x>=firstyr){
    xtxt = ""; if(x==yrfm)xtxt = "SELECTED ";
    txt2 += "<option " + xtxt + "value='" + x + "'>" + x + "</option>"
   }
  }
  txt2 += "</select>";
  if(itms.indexOf("yrfm+-")>-1)txt2 += "<br /><div id='ypm'><b onclick=\"document.getElementById('yrfmopt').value --;\">-</b> &nbsp; &nbsp; <b onclick=\"document.getElementById('yrfmopt').value ++;\">+</b>";
  txt2 += "</div></td>"
 }


 if(itms.indexOf("rdfm")>-1){
  numofcols ++
  txt1 += "<th>Rnd</th>"
  txt2 += "<td><select id='rdfmopt' style='width:70px' name='rdfm'>"
  for (x=1;x<25;x++){
   xtxt = ""; if(x==rdfm)xtxt = "SELECTED ";
   txt2 += "<option " + xtxt + "value='" + x + "'>" + x + "</option>"
  }
  xtxt = ""; if(rdfm==99)xtxt="SELECTED ";
  txt2 += "<option "+ xtxt + "value='99'>Finals</option>"
  txt2 += "</select></td>"
 }

 if(itms.indexOf("yrto")>-1){
  numofcols ++
  txt1 += "<th>To</th>"
  txt2 += "<td><select onchange='changeyrto()' id='yrtoopt' name='yrto'>"
  for (x=1897;x<curyr+1;x++){
   if(x>=firstyr){
    xtxt = ""; if(x==yrto)xtxt = "SELECTED ";
    txt2 += "<option " + xtxt + "value='" + x + "'>" + x + "</option>"
   }
  }
  txt2 += "</select></td>"
 }


 if(itms.indexOf("rd2fm")>-1){
  numofcols ++
  txt1 += "<th>Rnd</th>"
  txt2 += "<td><select name='rdfm'>"
  for (x=1;x<25;x++){
   xtxt = ""; if(x==rdfm)xtxt = "SELECTED ";
   txt2 += "<option " + xtxt + "value='" + x + "'>" + x + "</option>"
  }
  txt2 += "</select></td>"
 }




 if(itms.indexOf("gnds")>-1){
  numofcols ++
  txt1 += "<th>located</th>"
  txt2 += "<td><select name='gnd'>"
  xx = gndsa.length;
  if(itms.indexOf("nostate")>-1)xx=38;
  for (x=0;x<xx;x++){
   xtxt = ""; if(gndsvala[x]==gnd)xtxt = "SELECTED ";
   txt2 += "<option " + xtxt  + "value='" + gndsvala[x] + "'>" + gndsa[x] + "</option>"
  }
  txt2 += "</select></td>"
 }


 if(itms.indexOf("city")>-1){
  numofcols ++
  txt1 += "<th>City</th>"
  txt2 += "<td><select name='city'>"
  for (x=0;x<citya.length;x++){
   xtxt = ""; if(citya[x]==city)xtxt = "SELECTED ";
   txt2 += "<option " + xtxt  + "value='" + x + "'>" + citya[x] + "</option>"
  }
  txt2 += "</select></td>"
 }

 if(itms.indexOf("inat")>-1){
  numofcols ++
  txt1 += "<th>in / at</th>"
  txt2 += "<td><select name='inat'>"
  for (x=0;x<inpd.length;x++){
   xtxt = ""; if(x==inat)xtxt = "SELECTED ";
   txt2 += "<option " + xtxt + "value='" + x + "'>" + inpd[x] + "</option>"
  }
  txt2 += "</select></td>"
 }

 if(itms.indexOf("gms")>-1){
  numofcols ++
  txt1 += "<th>Round</th>"
  txt2 += "<td><select name='gms'>"
  gmsto = gmsarr.length;  
  if(itms.indexOf("lessrds")>-1){gmsto=3;}
  for (x=0;x<gmsto;x++){
   xtxt = ""; if(x==gms)xtxt = "SELECTED ";
   txt2 += "<option " + xtxt + "value='" + x + "'>" + gmsarr[x] + "</option>"
  }
  txt2 += "</select></td>"
 }

 if(itms.indexOf("hafinals")>-1){
  gmstyarr = new Array ("All Games","Not Finals","Just Finals");
  numofcols ++
  txt1 += "<th>H&amp;A/Finals</th>"
  txt2 += "<td><select name='gmstype'>"
  gmsty = gmstyarr.length;  
  for (x=0;x<gmsty;x++){
   xtxt = ""; if(x==gmstype)xtxt = "SELECTED ";
   txt2 += "<option " + xtxt + "value='" + x + "'>" + gmstyarr[x] + "</option>"
  }
  txt2 += "</select></td>"
 }


 if(itms.indexOf("fmqtr")>-1){
  numofcols ++
  txt1 += "<th>From</th>"
  txt2 += "<td><select name='inat'>"
  for (x=0;x<fmqtr.length;x++){
   xtxt = ""; if(x==inat)xtxt = "SELECTED ";
   txt2 += "<option " + xtxt + "value='" + x + "'>" + fmqtr[x] + "</option>"
  }
  txt2 += "</select></td>"
 }




 if(itms.indexOf("nwks")>-1){
  numofcols ++
  txt1 += "<th>Consec Weeks</th>"
  txt2 += "<td style='text-align:center'><select name='nwks'>"
  for (x=2;x<maxwks+1;x++){
   xtxt = ""; if(x==nwks)xtxt = "SELECTED ";
   txt2 += "<option " + xtxt + "value='" + x + "'>" + x + "</option>"
  }
  txt2 += "</select></td>"
 }

 for(x=1;x<vars.length;x+=2){ re = vars[x]; wi = vars[x+1];  txt1 = txt1.replace(re, wi); }

 numofcols ++

 if(xtrahed != ""){
	numofcols++;
	txt1 += xtrahed
	txt2 += xtrainp
 }


 if(itms.indexOf("hideok")==-1){
  txt1 += "<td></td>";
  txt2 += "<td><input type='submit' value='OK' style='margin:0;padding:0' /> ";
  txt2 += "<a id='thelink' onmouseover='updatethelink(event)' href='' title='Link to selected items'><img src='../styles/allthestats/imageset/_newwin.gif' /></a></td>"
 }

 txt = txt1 + txt2;


 if(itms.indexOf("when")>-1){
  txt += "<td><input type='hidden' id='when' name='when' value='" + when + "' /></td>"
 }
 txt += "</tr>";

 txt += "</table>";

 if(itms.indexOf("plid")>-1){
	txt += "<input type='hidden' id='plid' name='plid' value='" + plid + "' />";
 }

 txt += "</form>"

 if(itms.indexOf("when")>-1){
  txt += "<table class='blank'><tr><td colspan='" + numofcols + "'><b>When: </b><input type='text' size='80' onchange='chgwhenval()' id='whenval' value='" + w2 + "' /> <a href='/misc/usingwhen.php' title='How to use the WHEN parameter'>*</a></td></tr></table>"
 }

 document.write(txt)
 if(itms.indexOf("rdfm")>-1)changeyrto()
}


function chgwhenval(){
 v = document.getElementById('whenval');
 v.value = v.value.replace(/\bt\b/g,"trailing");
 v.value = v.value.replace(/\bl\b/g,"leading");
 v.value = v.value.replace(/\> /g,"by more than ");
 v.value = v.value.replace(/\< /g,"by less than ");

 v = document.getElementById('whenval').value
 wtxts = v.split(" and "); whentxt = "";
 for(x=0;x<wtxts.length;x++){
  vartxt = "";
  if(wtxts[x].indexOf("trailing")>-1)vartxt += "tr";
  else if(wtxts[x].indexOf("leading")>-1)vartxt += "le";
  else if(wtxts[x].indexOf("kicked")>-1)vartxt += "ki";
  else if(wtxts[x].indexOf("margin")>-1)vartxt += "ma";

  if(wtxts[x].indexOf("1/4")>-1)vartxt += "1";
  else if(wtxts[x].indexOf("1/2")>-1)vartxt += "2";
  else if(wtxts[x].indexOf("3/4")>-1)vartxt += "3";
  else if(wtxts[x].indexOf("full t")>-1)vartxt += "4";
  else if(wtxts[x].indexOf("1st q")>-1)vartxt += "1";
  else if(wtxts[x].indexOf("2nd q")>-1)vartxt += "5";
  else if(wtxts[x].indexOf("3rd q")>-1)vartxt += "6";
  else if(wtxts[x].indexOf("4th q")>-1)vartxt += "7";
  else if(wtxts[x].indexOf("2nd h")>-1)vartxt += "8";

  if(wtxts[x].indexOf("more than")>-1)vartxt += "mt";
  else if(wtxts[x].indexOf("less than")>-1)vartxt += "lt";
  re = /(\d+) p/; num=0; num = re.exec(wtxts[x]);
  if(num)vartxt += num[num.length-1];
  re = /(\d+) g/; num=0; num = re.exec(wtxts[x]);
  if(num)vartxt += num[num.length-1]+"g";
  re = /(\d+) b/; num=0; num = re.exec(wtxts[x]);
  if(num)vartxt += num[num.length-1]+"b";
  if(wtxts[x].indexOf("(show wins)")>-1){vartxt += ",SW";}
  if(wtxts[x].indexOf("(show losses)")>-1){vartxt += ",SL";}
  if(vartxt.length !=""){whentxt += vartxt + ",";}

 }
  document.getElementById('when').value = whentxt;
}


function updatethelink (event){
 if (MSIE) src = window.event.srcElement;
 else src = event.target;
 if(src.id=="")src = src.parentNode;
 a = document.getElementsByTagName("INPUT")
 txt11 = "";
 for (x=0;x<a.length;x++){
	elmn = a[x].name; elmv = a[x].value
	if(elmn!=""&&elmv!="") txt11 += elmn + "=" + elmv + "&";

 }
 a = document.getElementsByTagName("SELECT")
 for (x=0;x<a.length;x++){
	elmn = a[x].name; elmv = a[x].value
	if(elmn!=""&&elmv!="") txt11 += elmn + "=" + elmv + "&";
 }

 txt11 = txt11.substr(0,txt11.length-1)

 src.href = "?" + txt11

}



function opacity(id, opacStart, opacEnd, millisec) {
	//speed for each frame
	var speed = Math.round(millisec / 100);
	var timer = 0;

	//determine the direction for the blending, if start and end are the same nothing happens
	if(opacStart > opacEnd) {
		for(i = opacStart; i >= opacEnd; i--) {
			setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
			timer++;
		}
	} else if(opacStart < opacEnd) {
		for(i = opacStart; i <= opacEnd; i++)
			{
			setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
			timer++;
		}
	}
}

//change the opacity for different browsers
function changeOpac(opacity, id) {
	var object = document.getElementById(id).style; 
	object.opacity = (opacity / 100);
	object.MozOpacity = (opacity / 100);
	object.KhtmlOpacity = (opacity / 100);
	object.filter = "alpha(opacity=" + opacity + ")";
}

function shiftOpacity(id, millisec) {
	//if an element is invisible, make it visible, else make it ivisible
	if(document.getElementById(id).style.opacity == 0) {
		opacity(id, 0, 100, millisec);
	} else {
		opacity(id, 100, 0, millisec);
	}
}

function blendimage(divid, imageid, imagefile, millisec) {
	var speed = Math.round(millisec / 100);
	var timer = 0;
	
	//set the current image as background
	document.getElementById(divid).style.backgroundImage = "url(" + document.getElementById(imageid).src + ")";
	
	//make image transparent
	changeOpac(0, imageid);
	
	//make new image
	document.getElementById(imageid).src = imagefile;

	//fade in image
	for(i = 0; i <= 100; i++) {
		setTimeout("changeOpac(" + i + ",'" + imageid + "')",(timer * speed));
		timer++;
	}
}

function currentOpac(id, opacEnd, millisec) {
	//standard opacity is 100
	var currentOpac = 100;
	
	//if the element has an opacity set, get it
	if(document.getElementById(id).style.opacity < 100) {
		currentOpac = document.getElementById(id).style.opacity * 100;
	}

	//call for the function that changes the opacity
	opacity(id, currentOpac, opacEnd, millisec)
}


function chglink (event){
 tn = document.getElementById('selteam').value;
 if(tn!=""){
  if (MSIE) src = window.event.srcElement;
  else src = event.target;
  srcid = src.id;
  srcid =  srcid.replace("t1=-1","t1=" + tn);
  srcid =  srcid.replace("t1=-1","t1=" + tn);
  if(src.className=="CC"){
	if(tn==16){
	   srcid =  srcid.replace("2007","1913");
	   srcid =  srcid.replace("2007","1913");
	   srcid =  srcid.replace("2008","1914");
	   srcid =  srcid.replace("2008","1914");
	}	
	if(tn==6||tn==1){
	   srcid =  srcid.replace("2007","1995");
	   srcid =  srcid.replace("2007","1995");
	   srcid =  srcid.replace("2008","1996");
	   srcid =  srcid.replace("2008","1996");
	}
  }
 src.href = srcid;
 }

}


var notmoving = -1;
function domove2(itm,movby){
 alert(movby)
}


function domove(itm, movby){
if (notmoving){
 notmoving = 0;
 a = document.getElementById(itm)
 noofitms = a.rows[0].cells.length
 curpos = parseInt(a.style.left);
 colwidths = new Array();
 colwidths[0] = 0;
 curcol=0;
 for(x=0;x<a.rows[0].cells.length-1;x++){
	tt=0; if (x<3)tt=x+2;
  colwidths[1+x] = colwidths[x] - a.rows[0].cells[x].scrollWidth - tt 
  if(colwidths[1+x] == curpos) curcol = x+1
 }

 if(movby > 99){
    curcol = movby-100;
 }
  else {
   curcol = curcol + movby; 
   if(curcol > noofitms-1) curcol = 0;
   if(curcol < 0) curcol = noofitms - 1;
  }

 moveitm(itm, curpos, colwidths[curcol], 500);
}
}

function moveitm(iditm, startpos, endpos, length){
 // how many qtr of a secs
 fwds = 1; fin = 0;
 if (endpos < startpos) fwds = 0;
 timesteps = Math.floor(length / 50) + 1
 movesteps = (endpos - startpos) / timesteps
 a = document.getElementById(iditm)
 curpos = parseInt(a.style.left);
 newpos = curpos + movesteps;
 if(fwds)if (newpos >= endpos){newpos=endpos; fin=-1;  notmoving = -1;}
 if(!fwds)if(newpos <= endpos){newpos=endpos; fin=-1;  notmoving = -1;}
 a.style.left = newpos + "px";
 if(!fin) setTimeout("moveitm('" +iditm+ "'," +startpos+ "," +endpos+ "," +length+ ")" , 50);
}
