var winTimer = null;

function getCentreCoords(inWinWidth, inWinHeight) {
    
  var newCoords = new Array();
  var newX = (screen.availWidth / 2) - (inWinWidth / 2);
  var newY = (screen.availHeight / 2) - (inWinHeight / 2);
  newCoords[0] = newX;
  newCoords[1] = newY;

  return newCoords;
}

function show(object) {
	if (document.layers && document.layers[object] != null)
	    document.layers[object].visibility = 'visible';
	else if (document.all)
	    document.all[object].style.visibility = 'visible';
}

function hide(object) {
	if (document.layers && document.layers[object] != null)
	    document.layers[object].visibility = 'hidden';
	else if (document.all)
	    document.all[object].style.visibility = 'hidden';
}


function getCentrePos() {

  // Get Window Size
  var myWidth = 0, myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
  } else {
    if( document.documentElement &&
        ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
      //IE 6+ in 'standards compliant mode'
      myWidth = document.documentElement.clientWidth;
      myHeight = document.documentElement.clientHeight;
    } else {
      if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
        //IE 4 compatible
        myWidth = document.body.clientWidth;
        myHeight = document.body.clientHeight;
      }
    }
  }

  var newCoords = new Array();
  var newX = (screen.availWidth / 2) - (myWidth / 2);
  var newY = (screen.availHeight / 2) - (myHeight / 2);
  newCoords[0] = newX;
  newCoords[1] = newY;

  return newCoords;
}


function alertSize() {
  var myWidth = 0, myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
  } else {
    if( document.documentElement &&
        ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
      //IE 6+ in 'standards compliant mode'
      myWidth = document.documentElement.clientWidth;
      myHeight = document.documentElement.clientHeight;
    } else {
      if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
        //IE 4 compatible
        myWidth = document.body.clientWidth;
        myHeight = document.body.clientHeight;
      }
    }
  }
  window.alert( 'Width = ' + myWidth );
  window.alert( 'Height = ' + myHeight );
}

function makelayer(name,vis,left,top,width,height,z) {
	w('<div id="'+name+'" style="position:absolute;visibility:'+vis+';left:'+left+';top:'+top+';width:'+width+';height:'+height+';z-index:'+z+';">');
}

function endlayer() {
	w('</div>');
}

function w(cont) {document.write(cont);}

function startTest2() {
	makelayer('tipText','visible',400,150,100,100,100);
	w('<TABLE BGCOLOR="#FFFFB0">');
	w('<TR><TD>');
	w('<TEXTAREA READONLY=READONLY COLS=30 ROWS=5 CLASS="fieldText2">TEST</TEXTAREA>');
	w('</TD></TR>');
	w('</TABLE>');
	endlayer; 

}


/*
makelayer('movie1','visible',10,10,200,120,50);
w('<embed SRC="movie1.mov" width="200" height="120" cache="true">');
endlayer


<DIV ID="tipText1" STYLE="TOP:150px; HEIGHT:100px; LEFT:480px; position: absolute; visibility: hidden; WIDTH:100%; Z-INDEX:100;">
<TABLE BGCOLOR="#FFFFB0">
<TR><TD>
	<TEXTAREA READONLY=READONLY COLS=30 ROWS=5 CLASS="fieldText2"><c:out value="${conSch2Lbl.label05}"/></TEXTAREA>
</TD></TR>
</TABLE>
</DIV>
*/

function showTimer() {
	var width = 275; var height = 100;
	var coords = getCentreCoords(width, height);
	winTimer = window.open("timer.html","timer","height=" + height + ",width=" + width +",left=" + coords[0] + ",top=" + coords[1]);
	winTimer.focus();
}

function closeTimer() {
	if (winTimer != null)
	{
		winTimer.close();
	}
}

function goMap(postCode, ctry) {
	var width = 700; var height = 500;
	var coords = getCentreCoords(width, height);
	var url = "http://multimap.com/clients/places.cgi?db=" + ctry + "&pc=" + postCode + "&place=&client=public&lang=";
	var win = window.open(url,"","height=" + height + ",width=" + width + ",left=" + coords[0] + ",top=" + coords[1] +",resizable,scrollbars");
	win.focus();
}

 /**
  * This function hides all select guis or combos on the document.
  */
  function hideDropDownBoxes() {
	var elements = document.getElementsByTagName("select");
	if(elements != null) {
		for(var i=0;  i< elements.length;i++) {
			elements[i].style.visibility = "hidden";
		}
	}
  }

 /**
  * This function hides all select guis or combos on the document.
  */
  function showDropDownBoxes() {
	var elements = document.getElementsByTagName("select");
	if(elements != null) {
		for(var i=0;  i< elements.length;i++) {
			elements[i].style.visibility = "visible";
		}
	}
  }

/*
 * Function replaces '£' to '?' and '!' to '&' from a passed url.
 */
function convertURL(iURL) {
	var returnURL = "";

	if (iURL != null && iURL.value != '') {
		returnURL = iURL.replace("£", "?");	
		returnURL = returnURL.replace(/!/g, "&");	
	}
	return returnURL;
}

function beginDrag(elementToDrag,event) {
	var x = parseInt(elementToDrag.style.left);
	var y = parseInt(elementToDrag.style.top);

	var deltaX = event.clientX - x;
	var deltaY = event.clientY - y;

	if (document.addEventListener) {
		document.addEventListener("mousemove", moveHandler, true);
		document.addEventListener("mouseup", upHandler, true);
	}
	else if (document.attachEvent) {
		document.attachEvent("onmousemove", moveHandler);
		document.attachEvent("onmouseup", upHandler);
	}

	if (event.stopPropagation) {
		event.stopPropagation();
	}
	else {
		event.cancelBubble = true;
	}

	if (event.preventDefault) {
		event.preventDefault();
	}
	else {
		event.returnValue = false;
	}

	function moveHandler(e) {

		if (!e) e = window.event;
		
		elementToDrag.style.left = (e.clientX - deltaX) + "px";
		elementToDrag.style.top = (e.clientY - deltaY) + "px";
		
		if (e.stopPropagation) e.stopPropagation();
		else e.cancelBubble = true;
	}	

	function upHandler(e) {

		if (!e) e = window.event;

		if (document.detachEvent) {
			document.detachEvent("onmouseup", upHandler);
			document.detachEvent("onmousemove", moveHandler);
		}

		if (e.stopPropagation) e.stopPropagation();
		else e.cancelBubble = true;

	}
}

//opens the statusHistory.jsp and passes in the required parameters
//used by Header jsps when a user clicks on the status
function showStatusHistory(statusCode, moduleCode, id, ref) {
  var width = 550;
  var height = 250;
  var coords = getCentreCoords(width, height);
  var url = "statusHistory.html?statusCode=" + statusCode + "&moduleCode=" +
	moduleCode + "&id=" + id + "&ref=" + ref;
  window.open(url, "", "height=" + height + ",width=" + width + ",left=" + coords[0] + ",top=" + coords[1]);
}

//trims spaces from text
function trimString(sInString) {
  sInString = sInString.replace( /^\s+/g, "" );// strip leading
  return sInString.replace( /\s+$/g, "" );// strip trailing
}
/*
*								Copyright 2003 Servisional. 
*  All rights reserved in all countries. No part of this program may be reproduced 
*      by any means, be it  transmitted, transcribed, photocopied, stored in a 
*      retrieval system, or translated into any language in any form, without 
*                       the written permission of Servisional. 
* v1.0
*/