
var colMain='#669900'
var colMainD='#446105'
var colSec='#333399'
var colSecD='#000066'
var colThi='#999999'
var colThiD='#666666'
var colFou='#99C4E4'
var colFouD='#64A6D8'

var colI=new Array(colMain,colMainD,colSec,colThi,colFou,colSecD,colThiD,colFouD)
var buttonId=0
var sideColGlobal='#007BFF'
var sideTableColGlobal='#007BFF'

var gId="guest"
var searchShow=0
var searchImgSrc="images/buttons/plus.gif"
var menuLinkCol='#000099'
var menuLinkHoverCol='#9999ff'
var tabSelectedId=0
var buttonText=new Array
var buttonHref=new Array
var buttonCol='000000'
var buttonColHov='000099'
var buttonColHit='ff0000'

var printInWhiteId=0
var printInBlackId=0

var menuTabSel=0

var expanderGrow=new Array()
var expHeight=new Array()
var expMaxHeight=new Array()
var expContent=new Array()
var currentExpState=new Array()
var expContentDone=new Array()
var expC=0


function writeExpander(title,content,exId,ht){
document.write("<table width='100%' valign='top' cellpadding='0' cellspacing='0'><tr valign='top' id='expandBox"+exId+"' style='height:20px'><td valign='top'><span style='cursor:pointer' onclick='clickExpander("+exId+")'>"+title+"<br/></span><span id='expContent"+exId+"'></span></td></tr></table>")
//document.write("<table width='100%' valign='top' cellpadding='0' cellspacing='0'><tr valign='top' id='expandBox"+exId+"' style='height:20px'><td valign='top'><span style='cursor:pointer'><a onmouseover='clickExpander("+exId+")'>"+title+"<br/></a></span><span id='expContent"+exId+"'></span></td></tr></table>")
expContent[exId]=content
expMaxHeight[exId]=ht
expanderGrow[exId]=0
expHeight[exId]=0
}

function clickOpener(spanId){
var e=document.getElementById(spanId)
if(e.style.position=='absolute')
	{
	e.style.position='relative'
	e.style.top=0
	}
	else
	{
	e.style.position='absolute'
	e.style.top=-10000
	}
}

function clickExpander(eI){
	
	if(expanderGrow[eI]==0){
		expanderGrow[eI]=1
	}else{
		expanderGrow[eI]=0
		var e=document.getElementById("expContent"+eI)
		expContentDone[eI]=0
		e.innerHTML=""
		e.style.height=0
	}
}

function expanderTimer(){
	expC=expHeight[0]
	for(n=0;n<=expanderMax;n++){
		var e=document.getElementById("expandBox"+n)
		if (expanderGrow[n]==1){
			if(expHeight[n]<expMaxHeight[n]){
				expHeight[n]+=20
			}else{
				if (expContentDone[n]!=1){
					var e=document.getElementById("expContent"+n)
					e.innerHTML=expContent[n]
					expContentDone[n]=1
				}
			}
		}else{
			if(expHeight[n]>20){
				expHeight[n]-=20
			}//else{
//				var e=document.getElementById("expContent"+n)
//				e.innerHTML=""
//			}
		}
		e.style.height=expHeight[n]
	}
  setTimeout("expanderTimer(),100")
}

function clickFontButton(bI){
	if(bI!=pageFontSize){
		f=eval("fontButton"+bI)
		fNew=eval("font"+bI+"d.src")
		f.src=fNew//"images/buttons/font"+bI+"d.gif"
	}
}
function unClickFontButton(bI){
	if(bI!=pageFontSize){
		f=eval("fontButton"+bI)
		fNew=eval("font"+bI+".src")
		f.src=fNew//"images/buttons/font"+bI+".gif"
	}
}


function helpRequested(){
alert("help requested")
}


function writeButton(buttonCol,buttonTitle,hRef){
document.write("<span style='cursor:pointer;font-weight:bold' id='button"+buttonId+"' onmouseup=clickButton("+buttonId+") onmousedown=pressButton("+buttonId+") onmouseover=hovButton("+buttonId+") onmouseout=unHovButton("+buttonId+")><img align='absmiddle'name='buttonImg"+buttonId+"' src='images/int/bullet.gif' border='0' alt='"+hRef+"'></img>"+buttonTitle+"</span>")
buttonText[buttonId]=buttonTitle
buttonHref[buttonId]=hRef
buttonId+=1
}
   
function hovButton(bId){
  var bImg=eval("buttonImg"+bId)
  bImg.src=bulletHov.src
  var e=document.getElementById("button"+bId)
  e.style.color=buttonColHov
}

function unHovButton(bId){
  var bImg=eval("buttonImg"+bId)
  bImg.src=bullet.src
  var e=document.getElementById("button"+bId)
  e.style.color=buttonCol
}
function pressButton(bId){
  var bImg=eval("buttonImg"+bId)
  bImg.src=bulletHit.src
  var e=document.getElementById("button"+bId)
  e.style.color=buttonColHit
}
function clickButton(bId){
  document.location=buttonHref[bId]
}

function beginThinTable(wd,ht){
document.write("<table  width='"+wd+"' height='"+ht+"' cellpadding=0 cellspacing=0><tr><td height='10'><img src='images/int/ctl.jpg' width='10' height='10'></img></td><td height='10' width='100%' background='images/int/ct.jpg'></td><td ><img src='images/int/ctr.jpg' width='10' height='10'></img></td></tr><tr valign='top'><td background='images/int/cl.jpg'></td><td width='100%'>")
}

function endThinTable(){ 
document.write("</td><td background='images/int/cr.jpg'></td>  </tr><tr><td height='10'><img src='images/int/cbl.jpg' width='10' height='10'></img></td><td height='10' width='100%' background='images/int/cb.jpg'></td><td height='10'><img src='images/int/cbr.jpg' width='10' height='10'></img></td></tr></table>")
}


function beginTitleTable(titleCol,tableTitle,tWidth){
document.write("<span id='hide0'><table ' width='"+tWidth+"'  cellpadding=0 cellspacing=0><tr id='printInWhite"+printInWhiteId+"' bgcolor='"+titleCol+"'><td ><img name='nonPrint' src='images/int/ttl.gif' width='10' height='10'></img></td><td width='100%'></td><td ><img name='nonPrint' src='images/int/ttr.gif' width='10' height='10'></img></td></tr><tr id='printInWhite"+(printInWhiteId+1)+"' bgcolor='"+titleCol+"'><td></td><td width='100%'><span id='printInBlack"+printInBlackId+"' style='color:#ffffff;font-weight:bold'>"+tableTitle+"</span></td><td></td></tr><tr><td id='printInWhite"+(printInWhiteId+2)+"' bgcolor='"+titleCol+"'><img name='nonPrint' src='images/int/tttl.gif' border='0'></img></td><td width='100%'></td><td id='printInWhite"+(printInWhiteId+3)+"' bgcolor='"+titleCol+"'><img name='nonPrint' src='images/int/tttr.gif' border='0'></img></td></tr><tr><td background='images/int/cl.jpg'></td><td width='100%'></span>")
printInWhiteId+=4
printInBlackId+=4
}
function endTitleTable(){
document.write("<span id='hide1'></td><td id='bk' background='images/int/cr.jpg'></td></tr><tr><td><img name='nonPrint' src='images/int/cbl.jpg' width='10' height='10'></img></td><td width='100%' background='images/int/cb.jpg'></td><td><img name='nonPrint' src='images/int/cbr.jpg' width='10' height='10'></img></td></tr></table></span>")
}

function beginSideTable(sCol,wd,ht){
document.write("<table width='"+wd+"' height='"+ht+"' cellpadding=0 cellspacing=0><tr><td bgcolor="+sCol+" height='10'><img src='images/int/ttl.gif' width='10' height='10'></img></td><td bgcolor="+sCol+"><img src='images/int/tttlst.gif' width='10' height='10'></img></td><td height='10' width='100%' background='images/int/ct.jpg'></td><td ><img src='images/int/ctr.jpg' width='10' height='10'></img></td></tr><tr valign='top'><td bgcolor="+sCol+" ></td><td width='10'></td><td width='100%'>")
sideTableColGlobal=sCol
}

function endSideTable(){ 
sCol=sideTableColGlobal
document.write("</td><td background='images/int/cr.jpg'></td>  </tr><tr><td height='10' bgcolor="+sCol+"><img src='images/int/tbl.gif' width='10' height='10'></img></td><td bgcolor="+sCol+"><img src='images/int/tttlsb.gif' width='10' height='10'></img></td><td height='10' width='100%' background='images/int/cb.jpg'></td><td height='10'><img src='images/int/cbr.jpg' width='10' height='10'></img></td></tr></table>")
}


function writeTabTable(tabs,tabContent,tabCols,tWidth,tHeight){
	  var xTabOffset=10//50
	  document.write("<table cellpadding=0 cellspacing=0><tr>")
	  document.write("<td width='0'></td><td width='"+xTabOffset+"'></td>")
		
	  for(n=0;n<tabContent.length;n++)
		{
			if(tabs[n]!=null && tabs[n]!="")
				{
				document.write("<span>")
				document.write("<td>")
				document.write("<table style='cursor:default' onmouseout='unHoverTab("+n+")' onmouseover='hoverTab("+n+")'  onmouseup='clickTab("+n+")'  cellpadding=0 cellspacing=0><tr  id='tabTableR1"+n+"' bgcolor='"+tabCols[n]+"'>")
				document.write("<td><img src='images/int/ttl.gif' width='10' height='10'></img></td><td></td><td><img src='images/int/ttr.gif' width='10' height='10'></img></td></tr><tr id='tabTableR2"+n+"'  bgcolor='"+tabCols[n]+"'><td></td><td>")
				document.write("<span id='tab"+n+"' style='color:#dddddd;font-weight:bold;font-size:110%'>")
				document.write(tabs[n])
				document.write("</span></td><td></td>")
				document.write("</tr></table>")
				document.write("</td>")
				document.write("</span>")
				}
			else
				{
				document.write("<span>")
				document.write("<td>")
				document.write("<table style='cursor:default' onmouseout='unHoverTab("+n+")' onmouseover='hoverTab("+n+")'  onmouseup='clickTab("+n+")'  cellpadding=0 cellspacing=0><tr  id='tabTableR1"+n+"' bgcolor='"+tabCols[n]+"'>")
				document.write("<td></td><td></td><td></td></tr><tr id='tabTableR2"+n+"'  bgcolor='"+tabCols[n]+"'><td></td><td>")
				document.write("<span id='tab"+n+"' style='color:#dddddd;font-weight:bold;font-size:110%'>")
				//document.write(tabs[n])
				document.write("</span></td><td></td>")
				document.write("</tr></table>")
				document.write("</td>")
				document.write("</span>")
				}
		}
	  document.write("</tr></table>")
	  document.write("<span style='position:absolute;z-index:0'><img src='images/bkAB.jpg'  border='0'></img></span>")
	  document.write("<table  width='"+tWidth+"'  cellpadding=4 cellspacing=0><tr><td width='"+xTabOffset+"'>&nbsp</td><td width='710'>")
	  document.write("<span id='tabTableContent' style='position:absolute;width:710;z-index:1'></span>")
	  document.write("</td></tr></table>")
}

function hoverSubMenu(hovIndex){
	var i=eval("menuarrow"+hovIndex)
	i.src=menuarrowh.src
}
function unHoverSubMenu(hovIndex){
	var i=eval("menuarrow"+hovIndex)
	i.src=menuarrow.src
}


function clickTab(tabI)
	{
	for(t=0;t<contentA.length;t++)
		{
		if(t!=tabI)		
			{
			var e=document.getElementById("tab"+t)
			e.style.color=colSec
			var e=document.getElementById("tabTableR1"+t)
			e.style.backgroundColor=colA[t]
			var e=document.getElementById("tabTableR2"+t)
			e.style.backgroundColor=colA[t]
			}
		}
	var e=document.getElementById("tabTableContent")
	e.innerHTML=contentA[tabI]
	var e=document.getElementById("tab"+tabI)
	e.style.color='#ffffff'
	var e=document.getElementById("tabTableR1"+tabI)
	e.style.backgroundColor=hovColA[tabI]
	var e=document.getElementById("tabTableR2"+tabI)
	e.style.backgroundColor=hovColA[tabI]
	menuTabSel=tabI
	}

function hoverTab(tabI){
  for(t=0;t<contentA.length;t++){
    if(t!=tabI && t!=menuTabSel){
      var e=document.getElementById("tab"+t)
      e.style.color=colSec
      var e=document.getElementById("tabTableR1"+t)
      e.style.backgroundColor=colA[t]
      var e=document.getElementById("tabTableR2"+t)
      e.style.backgroundColor=colA[t]
    }
  }
  if(menuTabSel!=tabI){
	  var e=document.getElementById("tab"+tabI)
	  e.style.color='#ffffff';
	  var e=document.getElementById("tabTableR1"+tabI)
	  e.style.backgroundColor='#ff0000'
	  var e=document.getElementById("tabTableR2"+tabI)
	  e.style.backgroundColor='#ff0000'
  }
}

function unHoverTab(tabI){
	t=tabI
	if(t!=menuTabSel){
		var e=document.getElementById("tab"+t)
		e.style.color=colSec
		var e=document.getElementById("tabTableR1"+t)
		e.style.backgroundColor=colA[t]
		var e=document.getElementById("tabTableR2"+t)
		e.style.backgroundColor=colA[t]
	}
}

function selectTab(tabName)
	{
	//at end of page load for pages not in menu system.
	switch (tabName)
		{
		case 'Main':
			clickTab('0');break
		case 'Departments':
			clickTab('1');break
		case 'Log in':
			clickTab('2');break
		case 'Students':
			clickTab('3');break
		case 'Parents':
			clickTab('4');break
		case 'Staff':
			clickTab('5');break
		case 'Admin':
			clickTab('6');break
		default:
			alert("menu not found in selectTab script")
		}
	}


function beginImageHalf(imgTitle)
	{
	document.write("<table width='100%' cellpadding='0' cellspacing='0' ><tr><td width='250' valign='top'>")
	//beginTitleTable(colI[2],imgTitle,'250')
	beginSideTable(colMain,'250','50')
	}

function beginTextHalf()
	{
	//endTitleTable()
	endSideTable()
	document.write("<td>&nbsp</td></td><td valign='top'>")
	}

function endHalf()
	{
	document.write("</td></tr></table>")
	}

function beginTable(tableWidth,sideCol,fillCol){
document.write("<table border='0' cellpadding='0' cellspacing='0' width="+tableWidth+">")
document.write("  <tr height='4'>")
document.write("    <td width='4' bgcolor='"+sideCol+"'><img border='0' src='images/rules/rulelt.gif' width='4' height='4'></img></td>")
document.write("    <td width='100%' height='4' bgcolor='"+sideCol+"'> </td>")
document.write("    <td width='4' bgcolor='"+sideCol+"'><img border='0' src='images/rules/rulert.gif' width='4' height='4'></td>")
document.write("  </tr>")
document.write("  <tr>")
document.write("    <td width='4' bgcolor='"+sideCol+"'></td>")
document.write("    <td width='100%  bgcolor='"+sideCol+"'>      ")
document.write("     <table bgcolor='#FFFFFF' border='0' cellpadding='4' cellspacing='0' width='100%'>")
document.write("	<tr><td valign='top' bgcolor='"+fillCol+"'>")
sideColGlobal=sideCol
}

function endTable(){
document.write("			</td></tr>")
document.write("		</table>     ")
document.write("      </td>")
document.write("      <td width='4' bgcolor='"+sideColGlobal+"'></td>")
document.write("    </tr>")
document.write("    <tr height='4'>")
document.write("      <td  width='4' bgcolor='"+sideColGlobal+"'><img border='0' src='images/rules/rulelb.gif' width='4' height='4'></img></td>")
document.write("      <td width='100%' height='4' bgcolor='"+sideColGlobal+"' ></td>")
document.write("      <td width='4' bgcolor='"+sideColGlobal+"'><img border='0' src='images/rules/rulerb.gif' width='4' height='4'></td>")
document.write("    </tr>")
document.write("  </table>")
}



function hoverMenu(mCol,mRow){
	hoverColId=mCol
	hoverRowId=mRow
	var imgId=eval("imgMenu"+mCol+mRow)
	imgId.src=hoverButtonGif
	if(mCol>0 && mRow!=0){//set title menu gif
		var imgId=eval("imgMenu"+mCol+0)
		imgId.src=titleButtonGif	
	}
	lastHoverColId=hoverColId
}

function unHoverMenu(mCol,mRow){
	hoverColId=-1
	hoverRowId=-1
	var imgId=eval("imgMenu"+mCol+mRow)
	imgId.src=buttonGif
	if (lastHoverColId!=hoverColId){
		var imgId=eval("imgMenu"+lastHoverColId+0)
		imgId.src=buttonGif		
	}
}

function hoverCustomMenu(cmId){
	imgId=customHoverButtonGif.src
	var customimgId=eval("customMenu"+cmId)
	customimgId.src=imgId	
}

function unHoverCustomMenu(cmId){
	imgId=customButtonGif.src
	var customimgId=eval("customMenu"+cmId)
	customimgId.src=imgId	
}


function upMenu(mCol,mRow){
	var imgId=eval("imgMenu"+mCol+mRow)
	imgId.src=hoverButtonGif
}

function downMenu(mCol,mRow){
	var imgId=eval("imgMenu"+mCol+mRow)
	imgId.src=downButtonGif
}

function writeSearchBox(){
	if(searchShow==0){
		searchShow=1
		searchImgSrc="images/buttons/minus.gif"
	}else{
		searchShow=0
		searchImgSrc="images/buttons/plus.gif"
	}
	var imgId=eval("searchImg")
	imgId.src=searchImgSrc
}





function writeTitleBar(barCol,barTitle)
	{
	titleCol='#ffffff'
	document.write("<table  id='pageTitleBackColour' bgcolor='"+barCol+"' width='100%'  cellpadding=0 cellspacing=0><tr><td ><img src='images/int/ttl.gif' width='10' height='10'></img></td><td  width='100%' colspan='2'></td><td ><img src='images/int/ttr.gif' width='10' height='10'></img></td></tr><tr><td></td><td width='100%'><span id='pageTitle' style='color:"+titleCol+";font-weight:bold;font-size:120%'>"+barTitle+"</span><span id='addToTitle' style='color:"+titleCol+";font-weight:bold;font-size:120%'></span></td><td><span id='pageTitleRightItalic' style='font-family:Garamond;font-size:13pt;font-style:italic;color:"+colFouD+";white-space:nowrap'>Abbot Beyne School and Arts College</span></td><td></td></tr><tr><td><img src='images/int/tbl.gif' width='10' height='10'></img></td><td width='100%' background='images/int/cb.gif' colspan='2'></td><td><img src='images/int/tbr.gif' width='10' height='10'></img></td></tr></table>")
	}

function writeLogos()
	{
	document.write("<img alt='Arts Mark' align='absmiddle' border='0' src='images/artsmarklogo.jpg'></img>&nbsp<img alt='Sportsmark'align='absmiddle' border='0' src='images/sportsmarklogo.jpg'></img>&nbsp<img alt='Investors in people' align='absmiddle' border='0' src='images/iiplogo.gif'></img>&nbsp<img alt='Arts College' align='absmiddle' border='0' src='images/artscolllogo.jpg'></img>&nbsp<img alt='Specialist Schools and Academies Trust' align='absmiddle' border='0' src='images/specialistlogo.jpg'></img>")
	}




function setFontSize(fontSizeSet)
	{
	var pageURL=document.location
	pageURL=pageURL.toString()
	var getPos=pageURL.indexOf("?")
	if(getPos!=-1)
		{
		var joinChr="&"
		}
	else
		{
		var joinChr="?"	
		}
	document.location=pageURL+joinChr+"fontSizeSet="+fontSizeSet
	}

function getFileNameFromURL(longURL){
longURL=longURL.toString()
var l=longURL.split("/")
return l[l.length-1];
}

function toggleInterfaceView(){
	var e=document.getElementById("topInterface")
	if (e.style.visibility=="hidden"){
		document.location=document.location
	}else{
		e.style.visibility="hidden"
		e.style.position="absolute"		
		var e=document.getElementById("nonPrintFooter")
		e.style.visibility="hidden"
		e.style.position="absolute"		
		hideIntBtn.src='images/buttons/showNonPrint.gif'
	}

	for(h=0;h<10;h++)//adhoc page elements
		{
		var trySpan="hideNonPrint"+h
		
		if(document.getElementById(trySpan))
			{
			var e=document.getElementById(trySpan)
			e.style.visibility="hidden"
			e.style.position="absolute"
			}
		}
	for(h=0;h<50;h++)//to white page elements
		{
		var trySpan="printInWhite"+h
		if(document.getElementById(trySpan))
			{
			var e=document.getElementById(trySpan)
			e.style.backgroundColor='#ffffff'
			}
		}
	for(h=0;h<50;h++)//to black page elements
		{
		var trySpan="printInBlack"+h
		if(document.getElementById(trySpan))
			{
			var e=document.getElementById(trySpan)
			e.style.color='#000000'
			}
		}
	
	var e=document.getElementsByName('nonPrint')
	for(i=0;i<e.length-1;i++)
		{
		e[i].src='images/int/white.jpg'
		}
	
	var e=document.getElementById("pageTitle")
	e.style.color='#000000'

	var e=document.getElementById("addToTitle")
	e.style.color='#000000'

	var e=document.getElementById("pageTitleBackColour")
	e.style.backgroundColor='#ffffff'

	var e=document.getElementById("pageTitleRightItalic")
	e.style.color='#000000'

	var fName=getFileNameFromURL(document.location)

}


var xmlHttp
function checkForChatRequests()	
	{ 
	xmlHttp=GetXmlHttpObject()
	if (xmlHttp==null)
		{
		alert ("Browser does not support HTTP Request")
		return
		}
	var url="chatAjaxRequest.php"
	url=url+"&sid="+Math.random()
	xmlHttp.onreadystatechange=chatStateChanged 
	xmlHttp.open("GET",url,true)
	xmlHttp.send(null)
	//setTimeout("checkForChatRequests()",10000)
	}

function stateChanged() 
	{ 
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
		{ 
		var t=xmlHttp.responseText
		document.getElementById("chat").innerHTML=t
		} 
	}


function GetXmlHttpObject()
	{
	var xmlHttp=null;
	try
	{
	// Firefox, Opera 8.0+, Safari
	xmlHttp=new XMLHttpRequest();
	}
	catch (e)
	{
	//Internet Explorer
	try
	{
	xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
	}
	catch (e)
	{
	xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	}
	return xmlHttp;
	}