
function show(element) {document.getElementById(element).style.display='block';}
function showInline(element) {document.getElementById(element).style.display='inline';}
function hide(element) {document.getElementById(element).style.display='none';}
function disable(element) {document.forms['Form1'].elements[element].disabled=true;}
function enable(element) {document.forms['Form1'].elements[element].disabled=false;}
function clear(element) {document.forms['Form1'].elements[element].value='';}
function zero(element) {document.forms['Form1'].elements[element].value='0.00';}

//GENERAL

function insertStylesheet() {document.write('<link type="text/css" rel="stylesheet" href="../includes/javascriptStyles.css"/>');}
function insertParagraphStart() {document.write('<p>');}
function insertParagraphStartWithClass(className) {document.write('<p class="'+className+'">');}
function insertParagraphEnd() {document.write('</p>');}
function insertInlineDivStart() {document.write('<div class="inlineDiv">');}
function insertDivEnd() {document.write('</div>');}
function insertRating(rating) {document.write('<p class="alignRight"><strong>Your '); insertHelpLink('2','3','current rating','your current rating'); document.write(' is:</strong> <img src="../images/'+rating+'star.gif" alt="'+rating+' stars (out of a maximum of 6)" /></p>');}

var da = (document.all) ? 1 : 0;
var pr = (window.print) ? 1 : 0;
var mac = (navigator.userAgent.indexOf("Mac") != -1); 
var ie = (navigator.userAgent.indexOf("IE") != -1); 

var popupWin = null;

function openWindow(theUrl, name)
{
	if(name=='email')
	{
		popupWin = window.open(theUrl, name, config='height=630,width=555,toolbar=no,menubar=no,scrollbars=yes,resizable=yes,location=no,directories=no,status=yes');
	}
	else if(name=='probsugg')
	{
		popupWin = window.open(theUrl, name, config='height=570,width=650,toolbar=no,menubar=no,scrollbars=yes,resizable=yes,location=no,directories=no,status=yes');
	}
	else if(name=='ticklist')
	{
		popupWin = window.open(theUrl, name, config='height=400,width=250,toolbar=no,menubar=no,scrollbars=yes,resizable=yes,location=no,directories=no,status=yes');
	}
	else if(name=='report')
	{
		popupWin = window.open(theUrl, name, config='height=460,width=650,toolbar=no,menubar=no,scrollbars=yes,resizable=yes,location=no,directories=no,status=yes');
	}
	else if(name=='reassign')
	{
		popupWin = window.open(theUrl, name, config='height=450,width=490,toolbar=no,menubar=no,scrollbars=yes,resizable=yes,location=no,directories=no,status=yes');
	}
	else
	{
		popupWin = window.open(theUrl, name, config='height=600,width=640,toolbar=no,menubar=no,scrollbars=yes,resizable=yes,location=no,directories=no,status=yes');
	}
	event.cancelBubble = true;
	event.returnValue = false;
}

function scram() {
	if (popupWin != null && popupWin.open) popupWin.close();
}

window.name = 'opener';
window.onfocus=scram;

function printPage()
{
	if (pr) // NS4, IE5
		window.print()
	else if (da && !mac) // IE4 (Windows)
		vbPrintPage()
	else // other browsers
		alert("Sorry, your browser doesn't support this feature.");
	return;htm
}
if (da && !pr && !mac) with (document)
{
	writeln('<OBJECT ID="WB" WIDTH="0" HEIGHT="0" CLASSID="clsid:8856F961-340A-11D0-A96B-00C04FD705A2"></OBJECT>');
	writeln('<' + 'SCRIPT LANGUAGE="VBScript">');
	writeln('Sub window_onunload');
	writeln('  On Error Resume Next');
	writeln('  Set WB = nothing');
	writeln('End Sub');
	writeln('Sub vbPrintPage');
	writeln('  OLECMDID_PRINT = 6');
	writeln('  OLECMDEXECOPT_DONTPROMPTUSER = 2');
	writeln('  OLECMDEXECOPT_PROMPTUSER = 1');
	writeln('  On Error Resume Next');
	writeln('  WB.ExecWB OLECMDID_PRINT, OLECMDEXECOPT_DONTPROMPTUSER');
	writeln('End Sub');
	writeln('<' + '/SCRIPT>');
}

//HELP

//get mouse coords
var ymouse=0;
var xmouse=0;
function Move(evt)
{
    var e=evt?evt:event;
    xmouse=e.clientX?e.clientX:e.x 
    ymouse=e.clientY?e.clientY:e.y
}
if (document.layers) document.captureEvents(Event.MOUSEMOVE);
document.onmousemove = Move;

//show / hide tool tips
function ShowTooltip(fArg, vertAlign, horiAlign)
{
 //vertAlign params: n= north of mouse cursor; s = to south of mouse cursor, c = centre of cursor, nc = half-north
 //horiAlign params: e= to east of mouse cursor; w = to west of mouse cursor
 //usual default would be s,e (like a windows tooltip).
 var tooltipOBJ = (document.getElementById) ? document.getElementById('tt' + fArg) : eval("document.all['tt" + fArg + "']");

 if(tooltipOBJ)
 {
  if(!(vertAlign=="n"||vertAlign=="s"||vertAlign=="c"||vertAlign=="nc")){vertAlign="s";}
  if(!(horiAlign=="w"||horiAlign=="e")){horiAlign="e";}

  var xScrollOffset = document.body.scrollLeft;
  var yScrollOffset = document.body.scrollTop;
  if(xScrollOffset==0){xScrollOffset = document.documentElement.scrollLeft;}
  if(yScrollOffset==0){yScrollOffset = document.documentElement.scrollTop;}
  
  var OBJheight = 0;
  var OBJwidth = 5;

  if(vertAlign=="n"){OBJheight=tooltipOBJ.offsetHeight;}
  if(vertAlign=="nc"){OBJheight=tooltipOBJ.offsetHeight*0.75;}
  if(vertAlign=="c"){OBJheight=tooltipOBJ.offsetHeight*0.5;}
  if(horiAlign=="w"){OBJwidth=tooltipOBJ.offsetWidth+20;}

  if(navigator.appName != 'Netscape')
  {
   tooltipOBJ.style.pixelLeft = xmouse+10+xScrollOffset-OBJwidth;
   tooltipOBJ.style.pixelTop = ymouse+10+yScrollOffset-OBJheight;
  }else{
   tooltipOBJ.style.left = xmouse+10+xScrollOffset-OBJwidth+"px";
   tooltipOBJ.style.top = ymouse+10+yScrollOffset-OBJheight+"px";
  }
  tooltipOBJ.style.visibility = "visible";
 }
}

//function ShowTooltip(fArg)
//{
//	ShowTooltipOffset(fArg, 0, 0)
//}
//function ShowTooltipOffset(fArg, XOffset, YOffset)
//{
//	var tooltipOBJ = (document.getElementById) ? document.getElementById('tt' + fArg) : eval("document.all['tt" + fArg + "']");
//	if(tooltipOBJ)
//	{
//		var xScrollOffset = document.body.scrollLeft;
//		var yScrollOffset = document.body.scrollTop;
//		
//		tooltipOBJ.style.left = xmouse+10+xScrollOffset + XOffset+'px';
//		tooltipOBJ.style.top = ymouse+10+yScrollOffset + YOffset+'px';
//		tooltipOBJ.style.visibility = "visible";
//	}
//}

function HideTooltip(fArg)
{
	var tooltipOBJ = (document.getElementById) ? document.getElementById('tt' + fArg) : eval("document.all['tt" + fArg + "']");
	if (tooltipOBJ != null) tooltipOBJ.style.visibility = "hidden";
}

function ShowBubble(fArg)
{
 var bubbleOBJ = (document.getElementById) ? document.getElementById('bub' + fArg) : eval("document.all['bub" + fArg + "']");

 if(bubbleOBJ)
 {
  var xScrollOffset = document.body.scrollLeft;
  var yScrollOffset = document.body.scrollTop;
  if(xScrollOffset==0){xScrollOffset = document.documentElement.scrollLeft;}
  if(yScrollOffset==0){yScrollOffset = document.documentElement.scrollTop;}
  
  var OBJheight = bubbleOBJ.offsetHeight;
  var OBJwidth = 5;

  if(navigator.appName != 'Netscape')
  {
   bubbleOBJ.style.pixelLeft = xmouse+10+xScrollOffset-OBJwidth;
   bubbleOBJ.style.pixelTop = ymouse+10+yScrollOffset-OBJheight;
  }else{
   bubbleOBJ.style.left = xmouse+10+xScrollOffset-OBJwidth+"px";
   bubbleOBJ.style.top = ymouse+10+yScrollOffset-OBJheight+"px";
  }
  bubbleOBJ.style.visibility = "visible";
 }
}

function HideBubble(fArg)
{
 var bubbleOBJ = (document.getElementById) ? document.getElementById('bub' + fArg) : eval("document.all['bub" + fArg + "']");
 if (bubbleOBJ != null)
 {
  if(navigator.appName != 'Netscape')
  {
   bubbleOBJ.style.pixelLeft = 0;
   bubbleOBJ.style.pixelTop = 0;
  }else{
   bubbleOBJ.style.left = 0+"px";
   bubbleOBJ.style.top = 0+"px";
  }
  bubbleOBJ.style.visibility = "hidden";
 }
}

function insertHelpLink(tt,tabindex,linkText,field)
{
 document.write('<a href="javascript: ShowTooltip('+tt+', 0, 0);" tabindex="'+tabindex+'" class="helpLink" title="Click here for more information about '+field+'">'+linkText+'<span class="hidden"> (Click here for more information about '+field+')</span></a>');
}

function insertProfHelpLink(tt,tabindex,field)
	{
		document.write('<p class="profHelp"><a href="javascript: ShowTooltip('+tt+', 0, 0);" tabindex="'+tabindex+'"><img src="../images/littleProf.gif" alt="click here for more information about '+field+'" /></a></p>');
	}
	
function insertSearchTipLink(tt,tabindex,field)
	{
		document.write('<div class="searchTip"><a href="javascript: ShowTooltip('+tt+', 0, 0);" tabindex="'+tabindex+'"><img src="../images/searchTip.gif" alt="Click here for more information about '+field+'" /></a></div>');
	}

function insertCloseLink(tt,tabindex,title)
	{
		document.write('<p><a href="javascript: HideTooltip('+tt+');" class="closeLink" tabindex="'+tabindex+'">close <span class="hidden">'+title+'</span></a></p>');
	}
	
function enableVAT(flag)
	{
		if (flag == 1)
		{
			document.getElementById("txtVatNumber").disabled = false;			
		}
		else if (flag == 0)
		{
			document.getElementById("txtVatNumber").disabled = true;
			document.getElementById("txtVatNumber").value = "";
		}
	}
	
function clearRates(boxIndex)
	{
		 switch(boxIndex)
			{
			 case 1:
			document.getElementById("txtMinHourly").disabled = true;
			document.getElementById("txtMinHourly").value = "0.00";
			document.getElementById("txtMaxHourly").disabled = true;
			document.getElementById("txtMaxHourly").value = "0.00";
			document.getElementById("txtMinDaily").disabled = true;
			document.getElementById("txtMinDaily").value = "0.00";
			document.getElementById("txtMaxDaily").disabled = true;
			document.getElementById("txtMaxDaily").value = "0.00";
			break
			 case 2:
			if (document.getElementById("txtMinHourly").disabled == true)
			{
			document.getElementById("txtMinHourly").disabled = false;
			}
			if (document.getElementById("txtMaxHourly").disabled == true)
			{
			document.getElementById("txtMaxHourly").disabled = false;
			}
			if (document.getElementById("txtMinDaily").disabled == true)
			{
			document.getElementById("txtMinDaily").disabled = false;
			}
			if (document.getElementById("txtMaxDaily").disabled == true)
			{
			document.getElementById("txtMaxDaily").disabled = false;
			}
			break
			}	
	}
function showHideTrainCatDetails()
	{
		if(document.getElementById('chkIncludeDetailsInRecord').checked==true)
			{document.getElementById('htmCategoryDetails').style.display='block';}
		else if(document.getElementById('chkIncludeDetailsInRecord').checked==false)
			{document.getElementById('htmCategoryDetails').style.display='none';}
		if(document.getElementById('chkIncludeContactInRecord').checked==true)
			{document.getElementById('htmContactDetails').style.display='block';}
		else if(document.getElementById('chkIncludeContactInRecord').checked==false)
			{document.getElementById('htmContactDetails').style.display='none';}
	}
		
	
// funky click stuff for the default button keypress javascript
function fcshared_clickButtonOnKeypress(buttonID,keyCode,e)
{
	var key = fcshared_keyCodeValue(e);
	if (key==keyCode)
	{
		fcshared_click(buttonID,e);							
	}
}

function fcshared_click(buttonID,e)
{
	var button = document.getElementById(buttonID);
	if(button!=null) 
	{
		fcshared_cancelKeyPress(e);
		
		var doClick = true;
		
		if(button.enabled && button.enabled == false){doClick = false;}
		if(button.disabled && button.disabled == true){doClick = false;}
		
		if(doClick){
			if(document.createEvent)
			{
				if(button.href && button.href.indexOf("__doPostBack('") != -1)
				{
					//LinkButton, do PostBack
					eval(button.href);
					//__doPostBack(button.id.replace(/_/g,"$"),"");
				}else{
					//Button, raise click event
	        		var evt = document.createEvent("MouseEvents");
					evt.initMouseEvent("click", true, true, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null);
					button.dispatchEvent(evt);
				}            
			}
			else if(button.click)
			{
				button.click();
			}
		}		
	}
}

//Cancel key press event unless backspace
function fcshared_cancelKeyPress(e)
{
	var key = fcshared_keyCodeValue(e);
	if(key != 8){fcshared_cancelEventBubble(e);fcshared_cancelReturnValue(e);}
}

//Cancel the current event and bubbling
function fcshared_cancelEventBubble(e)
{
	if(e!=null)
	{
		if(e.stopPropagation){e.stopPropagation();}
		else{e.cancelBubble=true;}
	}
}

function fcshared_cancelReturnValue(e)
{
	if(e!=null)
	{
		if(e.preventDefault){e.preventDefault();}
		else{e.returnValue=false;}
	}
}

//Get the key code from an event
function fcshared_keyCodeValue(e){if(e==null){return null}else{return window.event ? e.keyCode : e.which;}}

//Training Category Details
function highlightScrollListItem(itemID)
{
 document.getElementById(itemID).style.backgroundColor='#316AC5';
 document.getElementById(itemID).style.color='#FFFFFF';
}

function unhighlightScrollListItem(itemID, contrast)
{
 document.getElementById(itemID).style.backgroundColor='transparent';
 if (contrast==1)
 {
  document.getElementById(itemID).style.color='#FFFF00';
 }
 else
 {
  document.getElementById(itemID).style.color='#000000';
 }
}

//Confirm dialog
function fcshared_returnConfirm(text,e)
{
	if(confirm(text)==true)
		{return true;}
	else
		{fcshared_cancelEventBubble(e);fcshared_cancelReturnValue(e);return false;}
}

//Cancel the current event and bubbling
function fcshared_cancelEventBubble(e)
{

	if(e!=null)
		{
			if(e.stopPropagation){e.stopPropagation();}
			else{e.cancelBubble=true;}
		}
}

function fcshared_cancelReturnValue(e)
{
	if(e!=null)
		{
		if(e.preventDefault){e.preventDefault();}
		else{e.returnValue=false;}
		}
}

// Mutually Exclusive Radio button in repeater

function SetUniqueRadioButton(nameregex, current)
{
   re = new RegExp(nameregex);
   for(i = 0; i < document.forms[0].elements.length; i++)
   {
      elm = document.forms[0].elements[i]
      if (elm.type == 'radio')
      {
         if (re.test(elm.name))
         {
            elm.checked = false;
         }
      }
   }
   current.checked = true;
}
