// JavaScript Document
var ns4 = document.layers;
var ns6 = document.getElementById && !document.all;
var ie4 = document.all;
var popUpWin=0;
/*******************
  HTTP Header diagnostic FUNCTION
********************/
function getPageHeaders(vURL){
	var result;
	if((!vURL) || (vURL == "")){
		result = "Header diagnostics: No URL entered";
	} else {
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");

 		xmlhttp.open("HEAD", vURL,false);
 		xmlhttp.onreadystatechange=function() {
  			if (xmlhttp.readyState==4) {
   				result = xmlhttp.getAllResponseHeaders();
  			}
 		}
 		xmlhttp.send(null)
	}
	return result;
}
/*******************
  PopUp Window FUNCTION
********************/
function popUpWindow(URLStr, left, top, width, height)
{
  if(popUpWin)
  {
    if(!popUpWin.closed) popUpWin.close();
  }
  popUpWin = open(URLStr, 'popUpWin', 'toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbar=no,resizable=no,copyhistory=yes,width='+width+',height='+height+',left='+left+', top='+top+',screenX='+left+',screenY='+top+'');
  //popUpWin = open(URLStr, 'popUpWin', 'toolbar=no,location=yes,directories=no,status=yes,menubar=no,scrollbar=no,resizable=yes,copyhistory=yes,width='+width+',height='+height+',left='+left+', top='+top+',screenX='+left+',screenY='+top+'');
  popUpWin.focus();
}
/*******************
  Jump Menu FUNCTION
********************/
//drop down navigation menu (Macromedia)
function jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}
/*******************
  Find Object FUNCTION
********************/
//cross browser object locator (Macromedia)
function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

/*******************
  Print Friendly FUNCTIONS
********************/
//Passes page to print proc making 'Print' and 'Close' buttons invisible
function printPage() { 
	if(document.all) { 
		//pWindow.print(); 
		document.all.pButtons.style.visibility = 'hidden'; 
		print(document); 
		document.all.pButtons.style.visibility = 'visible'; 
	} else { 
		document.write('Doc dot else...');
		document.getElementById('pButtons').style.visibility = 'hidden'; 
		print(document); 
		//window.print(); 
		document.getElementById('pButtons').style.visibility = 'visible'; 
	} 
} 
//Returns supplied string 'source' with links & rollovers removed 
function denude(source)
{
	var modified;
	modified = source;
	//var pattern = /(< *font[^>]* *>)(.*)((< *\/ *font[^>]* *>))/gi;
	modified = modified.replace(/rel[\s]*=[\s]*["]?stylesheet[\s]*["]?/gi,'rel="stylesheet" media="print, all"');
	modified = modified.replace(/(onclick *= *")(.*)(")/gi,"");
	modified = modified.replace(/(onmouse[^=]*= *")([^".]*)(")/gi,"");
	modified = modified.replace(/(<[\s]*script)([\w\s\S]*)(script>)/gi,""); //Removes all script
	modified = modified.replace(/(< *a href[^>]* *>)(.*)((< *\/ *a[^>]* *>))/gi,"$2");
	modified = modified.replace(/<[\s]*textarea[\s]*/gi,'<textarea readonly="1" '); //Make text areas readonly
	modified = modified.replace(/(< *input)(.*)(hidden)(.*>)/gi,""); //Removes all hidden fields
	modified = modified.replace(/(< *input)(.*)(button)(.*>)/gi,""); //Removes all form buttons
	modified = modified.replace(/(< *input)(.*)(value *= *)(\w*)(.*>)/gi,"$4"); //Removes all unselected options
	modified = modified.replace(/(< *option)(.*)(selected[^>]* *>)(\w*)(< *\/ *option[^>]* *>)/gi,"$4"); //Removes all unselected options
	modified = modified.replace(/(< *option[^>]* *>)(.*)(< *\/ *option[^>]* *>)/gi,""); //Removes all unselected options
	
	modified = modified.replace(/(< *select[^>]* *>)([\w\s\S]*)(< *\/ *select[^>]* *>)/gi,"$2"); //Removes all unselected options
	
	//modified = modified.replace(/<[\s]*input[\w\s\S]*input>/gi,""); //Removes all input buttons
	//modified = modified.replace(/<[\s]*input[\s]*/gi,'<input readonly="1" '); //Make input boxes readonly
	
	//modified = modified.replace(/<[\s]*select[\s]*/gi,'<select readonly="1" '); //Removes all script
	//	modified = modified.replace(/(< *map[^>]* *>)(.*)(< *\/ *map[^>]* *>)/gi,""); //Removes all unselected options
	//modified = modified.replace(/<map[\w\s\S(^map)]*\/map>/gi,""); //Removes all hotspots
	//modified = modified.replace(/href/gi,"");
	//modified = modified.replace("< *IMG[^>]* *>/g", "");
return modified;
}
//Main print friendly function
//Creates popup window and content
function printDetail()
{
	var width="680", height="500"; //Define the popup window
  	var left = (screen.width/2) - width/2;
  	var top = (screen.height/2) - height/2;
  	var styleStr = 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=no,width='+width+',height='+height+',left='+left+',top='+top+',screenX='+left+',screenY='+top;
  	
	var pWindow = window.open("","pWindow", styleStr);
	if (pWindow) {pWindow.focus();} //Make sure window has focus if it's already open
	
	pWindow.document.open(); //Won't print if document is not closed after a document.write!!	
	var s_sheet = '<link href="'+httproot+'Styles/SB-base.css" type="text/css" media="print, all" rel=stylesheet >';
	s_sheet += '<script language="JavaScript" src="'+httproot+'libjs/SB-java-include.js" type="text/JavaScript" ></script>';
  	var head = '<head><title>Print Page Detail</title>'+s_sheet+'</head>';
  	//pWindow.document.write(head); Don't put this here!!!
	
	var txtElement = document.getElementById("printArea");
	//msg = '<table width="'+(width-30)+'" border="0" cellpadding="0" cellspacing="0"><tr>';
	msg = '<div class="pagedetailbox"> <div class="normal">';
	if (txtElement == null) {
		msg += "Can't print - no page found";}
	else {
  		msg += denude(txtElement.innerHTML);
	}		
	msg += '</DIV></DIV>';
  	var body = msg+'<br><p>';

	var pButtons = '<table id="pButtons" width="'+(width-30)+'" border="0" cellpadding="0" cellspacing="0"><tr>';
	pButtons += '<td>&nbsp;</td>';
	pButtons += '<td width="100"><input type="button" value = "Print" onclick="printPage();"></td>';
	pButtons += '<td width="100"><input type="button" value = "Close" onClick="self.close();"></td>'; 
	pButtons += '<td>&nbsp;</td>';
	pButtons += '</tr></table>';

	var legal = '<table id="legal" width="650" border="0" cellspacing="0" cellpadding="0"><tr>';
	legal += '<td width="60">&nbsp;</td>';
	legal += '<td height="50" valign="bottom"><span class="footnote">';
	legal += 'Information appearing on this page is the copyright of Schoolbacs Limited ';
    legal += ' and must not be reproduced in ';
    legal += 'any medium without licence. For the full copyright statement see ';
	legal += '<A href="'+httproot+'SBgeneralTandC.php" target="_blank">Copyright</A>';
	legal += '</span></td>';
	legal += '<td width="60">&nbsp;</td>';
	legal += '</tr></table>';

	var doctype = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">';
  	
	pWindow.document.write(doctype + '<html>' + head + '<body>' + body + pButtons + legal + '</body></html>');
	pWindow.document.close();
}