//Js Include File
//Contains the standard functions, such as form validators

	document.onkeydown = function () {
	if(document.all){
		if(event.keyCode == 116){
			event.keyCode = 0;
			event.returnValue = false;
			event.cancelBubble = true;
			
			//reload the main page
			if(!top.name.length){
				if(top.frames.length){
					top.frames["main"].location.reload();
				}else{
					self.document.location.reload();
				}
			}else{
				self.document.location.reload();
			}
			
			return false;
		}
	}
  }
function Right(str, n){
	if (n <= 0)
		return "";
	else if (n > String(str).length)
		return str;
	else {
		var iLen = String(str).length;
		return String(str).substring(iLen, iLen - n);
	}
}
function isEmpty(value2check){
	if (value2check == "" || value2check == null){
		return true;
	}
	//nice bit of regexp!
	var nonSpaceCharacters = /\w/;
	hasCharacters = nonSpaceCharacters.exec(value2check);
	
	if (hasCharacters == null){
		return( true );
	}
	
	return( false );
}
function integerInRange(checkValue){
	if (checkValue < -2147483648 || checkValue > 2147483647){
		return( false );
	}
	return( true );
}
function isInteger(checkValue){
	if (isNaN(checkValue)){
		return( false );
	}
	if (parseInt(checkValue) != checkValue){
		return( false );
	}
	if (!integerInRange(checkValue)){
		alert("The value is out of acceptable range (-2,147,483,648 to 2,147,483,647)");
		alerted = true;
		return( false );
	}	
	return( true );
}
function isFloat(checkValue){
	if (isNaN(checkValue)){
		return( false );
	}
	if (parseFloat(checkValue) != checkValue){
		return( false );
	}
	return( true );
}
function isPositive(checkValue, integer){
	if (isNaN(checkValue)){
		return( false );
	} 
	if (checkValue < 0){
		return( false );
	}
	if (checkValue.length < 1){
		return( false );
	}
	if (integer){
		if(parseInt(checkValue) != checkValue){
			return( false );
		}
	}
	if (!integerInRange(checkValue)){
		alert("The value is out of acceptable range (-2,147,483,648 to 2,147,483,647)")
		alerted = true;
		return( false );
	}
	return( true );
}
function MM_swapImgRestore(){
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function MM_swapImage(){
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
function MM_findObj(n, d){
  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); return x;
}
function tmt_findObj(n){
	var x,t; if((n.indexOf("?"))>0&&parent.frames.length){t=n.split("?");
	x=eval("parent.frames['"+t[1]+"'].document.getElementById('"+t[0]+"')");
	}else{x=document.getElementById(n)}return x;
}
function MM_showHideLayers(){
  var i,p,v,obj,args=MM_showHideLayers.arguments;if(document.getElementById){
   for (i=0; i<(args.length-2); i+=3){ obj=tmt_findObj(args[i]);v=args[i+2];
   v=(v=='show')?'visible':(v='hide')?'hidden':v;
   if(obj)obj.style.visibility=v;}} else{
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v='hide')?'hidden':v; }
    obj.visibility=v; }}
}
function MM_preloadImages(){
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}
function objectFinder(n, d){
  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); return x;
}

// ---

function coords(){
	this.x;
	this.y;
	this.width;
	this.heigth;
	this.calculate = function(){
		var intWidth = this.width;	
		var intHeight = this.height;
		if (navigator.appName=="Netscape"){
			intTopDiff=(screen.height/10);
			intXPos=(screen.width/2)-(intWidth/2);
			intYPos=((screen.height/2)-(intHeight/2))-intTopDiff;
	
		}else{
			intXPos=(screen.availWidth/2)-(intWidth/2);
			intYPos=(screen.availHeight/2)-(intHeight/2);
		}
		this.x=intXPos>0?intXPos:0;
		this.y=intYPos>0?intYPos:0;
	}
}

function closeWindow(){
	if(top.opener && !top.opener.closed){
		top.opener.location.reload();
	}
	top.window.close();
}

function openWindow(url,height,width,winObj){
	
	var objCoords = new coords();
	objCoords.width = width;
	objCoords.height = height;
	objCoords.calculate();
	
	var intXPos = objCoords.x;
	var intYPos = objCoords.y;

	strProperties="location=no,menubar=no,resizable=yes,status=no,toolbar=no,titlebar=no,";
	strProperties+="directories=no,scrollbars=yes,toolbar=0,screenX="+intXPos+",left="+intXPos;
	strProperties+=",screenY="+intYPos+",top="+intYPos+",width="+width+",height="+height;
	winObj=window.open(url,"" + winObj + "",strProperties);
	winObj.focus();
}
function openWindow800(url,winObj){
	var width = 795;
	var height = 500;
	var objCoords = new coords();
	objCoords.width = width;
	objCoords.height = height;
	objCoords.calculate();
	
	var intXPos = objCoords.x;
	var intYPos = objCoords.y;

	strProperties="location=no,menubar=no,resizable=yes,status=no,toolbar=no,titlebar=no,";
	strProperties+="directories=no,scrollbars=yes,toolbar=0,screenX="+intXPos+",left="+intXPos;
	strProperties+=",screenY="+intYPos+",top="+intYPos+",width="+width+",height="+height;
	winObj=window.open(url,"" + winObj + "",strProperties);
	winObj.focus();
}
function openWindowWithMenu(url,height,width,winObj){
	var objCoords = new coords();
	objCoords.width = width;
	objCoords.height = height;
	objCoords.calculate();
	
	var intXPos = objCoords.x;
	var intYPos = objCoords.y;
	
	strProperties="location=no,menubar=yes,resizable=yes,status=no,toolbar=no,titlebar=no,";
	strProperties+="directories=no,scrollbars=yes,toolbar=0,screenX="+intXPos+",left="+intXPos;
	strProperties+=",screenY="+intYPos+",top="+intYPos+",width="+width+",height="+height;
	winObj=window.open(url,"" + winObj + "",strProperties);
	winObj.focus();
	
}
function openWindowWithMenu800(url,winObj){
	var width = 795;
	var height = 420;
	var objCoords = new coords();
	objCoords.width = width;
	objCoords.height = height;
	objCoords.calculate();
	
	var intXPos = objCoords.x;
	var intYPos = objCoords.y;
	
	strProperties="location=no,menubar=yes,resizable=yes,status=no,toolbar=no,titlebar=no,";
	strProperties+="directories=no,scrollbars=yes,toolbar=0,screenX="+intXPos+",left="+intXPos;
	strProperties+=",screenY="+intYPos+",top="+intYPos+",width="+width+",height="+height;
	winObj=window.open(url,"" + winObj + "",strProperties);
	winObj.focus();
	
}
function openWindow_Return(url,height,width,winObj){
	
	var objCoords = new coords();
	objCoords.width = width;
	objCoords.height = height;
	objCoords.calculate();
	
	var intXPos = objCoords.x;
	var intYPos = objCoords.y;

	strProperties="location=no,menubar=no,resizable=yes,status=no,toolbar=no,titlebar=no,";
	strProperties+="directories=no,scrollbars=yes,toolbar=0,screenX="+intXPos+",left="+intXPos;
	strProperties+=",screenY="+intYPos+",top="+intYPos+",width="+width+",height="+height;
	winObj=window.open(url,"" + winObj + "",strProperties);
	winObj.focus();
	
	return winObj;
}
function openWindowWithMenu_Return(url,height,width,winObj){
	var objCoords = new coords();
	objCoords.width = width;
	objCoords.height = height;
	objCoords.calculate();
	
	var intXPos = objCoords.x;
	var intYPos = objCoords.y;
	
	strProperties="location=no,menubar=yes,resizable=yes,status=no,toolbar=no,titlebar=no,";
	strProperties+="directories=no,scrollbars=yes,toolbar=0,screenX="+intXPos+",left="+intXPos;
	strProperties+=",screenY="+intYPos+",top="+intYPos+",width="+width+",height="+height;
	winObj=window.open(url,"" + winObj + "",strProperties);
	winObj.focus();
	
	return winObj;
	
}
function setStatus(msg){
	status=msg;
	return true;
}

function isLeapYear(year) 
{ 
    return (year % 4 == 0 && (year % 100 !=0 || year % 400 ==0 )); 
} 

function validateDate(dateIn,monthIn,yearIn, strName){
	
	var bValid = true
	
	if (parseInt(yearIn, 10)  < 1753){
		alert("You've entered a year earlier than 1753. Unfortunately we can only support dates after 1753, because this is when the Gregorian and Julian calendars were synchronized! Please re-enter a more recent date.")
		return false;
	}
	if( isNaN(dateIn) || isNaN(monthIn) || isNaN(yearIn)){
		alert("Part of your date " + strName + " is not in the right format (dd/mm/yyyy)");
		return false;
	}
	
	if (dateIn.length==1){
		dateIn = "0" + dateIn;
	}
	if (monthIn.length==1){
		monthIn = "0" + monthIn;
	}
	var textStr = dateIn+"/"+monthIn+"/"+yearIn;
	var chkDate=new Date();
	if(dateIn.indexOf("0") == 0){
		dateIn = dateIn.substring(1);
	}
	if(monthIn.indexOf("0") == 0){
		monthIn = monthIn.substring(1);
	}
	
	chkDate.setMonth((parseInt(monthIn)-1),(parseInt(dateIn)));
	chkDate.setFullYear(parseInt(yearIn));
			
	var chkMonthInt  = chkDate.getMonth()+1;
	var chkMonthStr = chkMonthInt+"/";
	if (chkMonthStr.length == 2){
		chkMonthStr = "0"+chkMonthStr;
	} 
	var chkDateInt = chkDate.getDate();
	var chkDateStr = chkDateInt+"/";
	if (chkDateStr.length == 2){
		chkDateStr = "0"+chkDateStr;
	}
	var cmpDate=chkDateStr+chkMonthStr+(chkDate.getFullYear());
		
	if (cmpDate.length != 10) bValid = false;
	else
	{
		if (textStr!=cmpDate) bValid = false;
		else if (cmpDate=="NaN/NaN/NaN") bValid = false;
	}
	
	//handle 29th feb in a leap year
	if( (dateIn == 29) && (monthIn == 2) && (isLeapYear(yearIn)) ) bValid = true;
	
	if(!bValid)
	{
		alert("You've entered a " + strName + " that does not exist or used an invalid date format.\n\nPlease use the dd/mm/yyyy format.");
		return false;
	}
	else return true;
}

function setValue(formName, formItem, value){
	objField = eval('document.forms["' + formName + '"].elements["' + formItem +'"]');
	if (objField){
		for (i=0; i < objField.options.length; i++){
			if (objField.options[i].value == value){
				objField.options[i].selected = true;	
			}
		}
	}
}
function setDefaultValue(formName, formItem, value){
	objField = eval('document.forms["' + formName + '"].elements["' + formItem +'"]');
	if (objField){
		for (i=0; i < objField.options.length; i++){
			if (objField.options[i].value == value){
				objField.options[i].selected = true;
				objField.options[i].defaultSelected = true;
			}
		}
	}
}
function createSnapShot(formName, ignoreMe){
//
}

// ---

function confirmClose(formName, ignoreMe){
//
}
function formatCurrency(num){
	num = num.toString().replace(/\$|\,/g, "");
	if (isNaN(num)){
		alert(num + " : This is not a valid number");
		return( "0" );
	}
	
	if (num.length < 1){
		return( "" );
	}
	
	sign = (num == (num = Math.abs(num)));
	num = Math.floor(num*100+0.50000000001);
	cents = num%100;
	num = Math.floor(num/100).toString();
	
	if (cents < 10){
		cents = "0" + cents;
	}
	
	return( num + "." + cents );
}
function createImage( s ){
	var objImage = new Image();
		objImage.src = s;

	return( objImage );
}
function showLayer(layerName){
	if (document.getElementById){
		if (check){
			if (what =="none"){
				return;
			}else if (what == "moz"){
				document.getElementById(layerName).style.visibility="visible";
			}else{
				eval(layerRef+'["'+layerName+'"]'+styleSwitch+'.visibility="visible"');
			}
		}else{
			return;
		}
	}
} 
function hideLayer(layerName){
	if (document.getElementById){
		if (check){
			if (what =="none"){
				return;
			}else if (what == "moz"){
				document.getElementById(layerName).style.visibility="hidden";
			}else{
				eval(layerRef+'["'+layerName+'"]'+styleSwitch+'.visibility="hidden"');
			}
		}else{
			return;
		}
	}
	
}

function strReplace(originalString, searchText, replaceText){

	var strLength = originalString.length;
	var txtLength = searchText.length;

	if ((strLength == 0) || (txtLength == 0)){
		return( originalString );
	}
	var i = originalString.indexOf(searchText);
	if ((!i) && (searchText != originalString.substring(0, txtLength)))	{
		return( originalString );
	}
	if (i == -1){
		return( originalString );
	}
	var newStr = originalString.substring(0, i) + replaceText;
	if (i+txtLength < strLength){
		newStr += strReplace(originalString.substring(i+txtLength, strLength), searchText, replaceText);
		return( newStr );
	}

}
//evalutates a passed string as javascript,
//mostly used with select lists n stuff
function performAction(inStr){
	if (inStr != "null"){
		eval(inStr);
	}
}
//hides all select lists when drop down menus are moused over
function hideme(){
//
}
//shows all select lists when drop down menus are moused out
function showme(){
//
}

/*
 * NAME    : isValidFileType( strFileName, arrExt )
 * AUTHOR  : LG [2003-02-07]
 *
 * DESCR   : Returns true if the strFileName variable has
 *           one of the file extensions in the arrExt array
 *
 * EXAMPLE : isValidFileType("upload.doc", new Array(".doc", ".txt")) - returns true
 *           isValidFileType("upload.jpg", new Array(".doc", ".txt")) - returns false
*/	

function isValidFileType( strFileName, arrExt ){
	if (!strFileName.length)	{
		return( false );
	}
	
	strFileName = strFileName.toLowerCase();
	
	for ( var j=0; j<arrExt.length; j++ )	{
		if ( strFileName.substring( strFileName.length, strFileName.indexOf( arrExt[j].toLowerCase() ) ) == arrExt[j].toLowerCase() )		{
			return( true );
		}
	}
	
	return( false );
}
function setFocus( strFormName, strFieldName ){
	var objForm = document.forms[strFormName];
	objForm.elements[strFieldName].focus();
}
function setPointer(targetDoc){ 
//if (targetDoc.all) for (var i=0;i < targetDoc.all.length; i++) targetDoc.all(i).style.cursor = 'wait'; 
} 
function resetPointer(targetDoc) {
//if (targetDoc.all) for (var i=0;i < targetDoc.all.length; i++) targetDoc.all(i).style.cursor = 'default'; 
} 
function selectAction( field ){
	performAction(field.options[field.selectedIndex].value)
	field.selectedIndex = 0
}
function textCounter(objField, intMaxChars){
	if (objField.value.length > intMaxChars){ 
		objField.value = objField.value.substring(0, intMaxChars);
		alert("The maximum character limit (" + intMaxChars + " chars) for this field has been reached.");
		return false;
	}else{
		return true;
	}
	
}
function toggleHelp(){
	var objID = document.getElementById("help");
	objID.style.display = (objID.style.display == "none")?"":"none";
	var now = new Date();
	now.setTime(now.getTime() + 1000 * 60 * 60 * 24 * 365 * 5) 
	setCookie("helpdisplay",objID.style.display, now, "/");
	if(getText("HelpLink")=="Hide Help"){
		changeText("Show Help","HelpLink")
	} else {
		changeText("Hide Help","HelpLink")
	}
}
function changeText(inText, inTarget) {
	  inText = unescape(inText);
	  if (document.getElementById) {
		document.getElementById(inTarget).innerHTML = inText;
	  }
	  else if (document.all) {
		document.all[inTarget].innerHTML = inText;
	  }
}
function getText(inTarget) {
	  if (document.getElementById) {
		return document.getElementById(inTarget).innerHTML;
	  }
	  else if (document.all) {
		return document.all[inTarget].innerHTML
	  }
}
function setCookie(name, value, expires, path, domain, secure){
    document.cookie= name + "=" + escape(value) +
        ((expires) ? "; expires=" + expires.toGMTString() : "") +
        ((path) ? "; path=" + path : "")
        //((domain) ? "; domain=" + domain : "") +
        //((secure) ? "; secure" : "");
}
function toggle(obj){
	var objID = document.getElementById(obj);
	objID.style.display = (objID.style.display == "none")?"":"none";
	var now = new Date();
	now.setTime(now.getTime() + 1000 * 60 * 60 * 24 * 365 * 5) 
	setCookie("helpdisplay",objID.style.display, now, "/");
}		
function getText(inTarget) {			
	  if (document.getElementById) {
		return document.getElementById(inTarget).innerHTML;
	  }
	  else if (document.all) {
		return document.all[inTarget].innerHTML
	  }
}
function setCookie(name, value, expires, path, domain, secure){
    document.cookie= name + "=" + escape(value) +
        ((expires) ? "; expires=" + expires.toGMTString() : "") +
        ((path) ? "; path=" + path : "")
        //((domain) ? "; domain=" + domain : "") +
        //((secure) ? "; secure" : "");
}
function selectAction( field ){
	performAction(field.options[field.selectedIndex].value)
	field.selectedIndex = 0
}
function Trim(sString){
	while (sString.substring(0,1) == ' '){
		sString = sString.substring(1, sString.length);
	}
	while (sString.substring(sString.length-1, sString.length) == ' '){
		sString = sString.substring(0,sString.length-1);
	}
	return sString;
}
function toggleNoCookie(obj){
	var objID = document.getElementById(obj);
	objID.style.display = (objID.style.display == "none")?"":"none";
}	
function getWindowWidth(){
	var myWidth = 0;
	var 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;
			}
		}
	}
	return( myWidth );
}
function getWindowHeight(){
	var myWidth = 0;
	var 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;
			}
		}
	}
	return( myHeight );
}

function singleChoice(selection){
	var checked = selection.checked
	var objField = selection.form.elements[selection.name];
	if(objField){
		if (typeof objField != 'undefined') {
			for (i = 0; i < objField.length; i++) {
				objField[i].checked = false;
			}
		} else {
			objField.checked = false;
		}
	}
	selection.checked = checked;
}

function _disableButtons(disable,myDoc){
	var objForm
	for(i=0;i<myDoc.forms.length;i++){
		objForm = myDoc.forms[i];
		for(j=0;j<objForm.elements.length;j++){
			if(objForm.elements[j].type == "button"){objForm.elements[j].disabled = disable}
			if(objForm.elements[j].type == "submit"){objForm.elements[j].disabled = disable}
		}
	}
}
function close_unlock(id){
	self.location.href="close_unlock.asp?id="+id
}
function setCookie2(keyValue, valueText) {
	deleteCookie(keyValue);
	deleteCookie(keyValue, 'portal/');
	var cookieValue = keyValue + '=' + encodeURIComponent(valueText);
	var expiresDate = new Date();
	expiresDate.setFullYear(expiresDate.getFullYear() + 30);
	cookieValue += '; expires=' + expiresDate.toUTCString() + ';path=/portal/'; ;
	document.cookie = cookieValue;
}

function deleteCookie(keyValue, path) {
	var cookieValue = keyValue + '=; expires=' + (new Date(0)).toUTCString() + ';path=/' + path;
	document.cookie = cookieValue;
}