
// GLOBAL JAVASCRIPT FUNCTIONS
// WorkSafeBC.com 
// August 2005


// CLEAR SEARCH FIELD
function clearFieldDefault(el) {
	if (el.defaultValue==el.value) el.value = ""
	el.className='clearForm'
}	


// POPUP AND CENTER WINDOWS
<!--
function flvFPW1(){//v1.44
// Copyright 2002-2004, Marja Ribbers-de Vroed, FlevOOware (www.flevooware.nl/dreamweaver/)
var v1=arguments,v2=v1[2].split(","),v3=(v1.length>3)?v1[3]:false,v4=(v1.length>4)?parseInt(v1[4]):0,v5=(v1.length>5)?parseInt(v1[5]):0,v6,v7=0,v8,v9,v10,v11,v12,v13,v14,v15,v16;v11=new Array("width,left,"+v4,"height,top,"+v5);for (i=0;i<v11.length;i++){v12=v11[i].split(",");l_iTarget=parseInt(v12[2]);if (l_iTarget>1||v1[2].indexOf("%")>-1){v13=eval("screen."+v12[0]);for (v6=0;v6<v2.length;v6++){v10=v2[v6].split("=");if (v10[0]==v12[0]){v14=parseInt(v10[1]);if (v10[1].indexOf("%")>-1){v14=(v14/100)*v13;v2[v6]=v12[0]+"="+v14;}}if (v10[0]==v12[1]){v16=parseInt(v10[1]);v15=v6;}}if (l_iTarget==2){v7=(v13-v14)/2;v15=v2.length;}else if (l_iTarget==3){v7=v13-v14-v16;}v2[v15]=v12[1]+"="+v7;}}v8=v2.join(",");v9=window.open(v1[0],v1[1],v8);if (v3){v9.focus();}document.MM_returnValue=false;return v9;}
//-->


// show/hide page objects

function hideObj(_objId) {
	var thisObj = document.getElementById(_objId );
	thisObj.style.display = "none";
}
function showObj(_objId){
	var thisObj = document.getElementById(_objId);
	if(thisObj.style.display != "block"){
		thisObj.style.display = "block";
	}
	else {
		hideObj(_objId);
	}
}



// show/hide FAQ objects

function hideFAQ(objID) {
	var thisObj = document.getElementById(objID );
	//var thisState = document.getElementById(_stateId );
	//thisObj.className = "hide";
	thisObj.style.display = "none"
	//thisState.className = "none";
	}
function showFAQ(objID){
	var thisObj = document.getElementById(objID);
	//var thisState = document.getElementById(_stateId);
	//if(thisObj.className != "show"){
	if(thisObj.style.display != "block"){
		//thisObj.className = "show";
		thisObj.style.display = "block"
		//thisState.className = "selected";
		}
	else {
		hideFAQ(objID);
		}
	}




// switch tabs on landing pages

function switchTab(tabContentsID,tabButtonID,totalTabs){	
	hideAllTabs(totalTabs,tabButtonID);
	showTab(tabContentsID,tabButtonID);
}
function hideAllTabs(totalTabs,tabButtonID){
	//loop through the totalTabs and hide each element by id
	for (var i=1;i<=totalTabs;i++){
		tabContentsToHide = 'tabContents' + i;
		buttonToDeSelect = 'tabButton' + i;
		//hideTab(tabToHide);
		hideTab(tabContentsToHide,buttonToDeSelect);
	}		
}
function hideTab(tabContentsID,tabButtonID) {
	if (document.getElementById) {
		document.getElementById(tabContentsID).className = 'hide';
		document.getElementById(tabButtonID).className = 'none';
	}
}
function showTab(tabContentsID,tabButtonID) {
	if (document.getElementById) {
		document.getElementById(tabContentsID).className = 'show';
		document.getElementById(tabButtonID).className = 'selected';
	}
}


// dropdown menus for dashboards

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;
}

function P7_autoShowHide() { //v1.2 by PVII-www.projectseven.com
 var g,b,k,f,ag=arguments,a=parseInt(ag[0]);
 if(!document.p7setc){p7c=new Array();document.p7setc=true;for(var u=0;u<10;u++){
 p7c[u]=new Array();}}for(k=0;k<p7c[a].length;k++){if((g=MM_findObj(p7c[a][k]))!=null){
 b=(document.layers)?g:g.style;b.display="none";}}for(k=1;k<ag.length;k++){
 if((g=MM_findObj(ag[k]))!=null){b=(document.layers)?g:g.style;b.display="block";
 f=false;for(var j=0;j<p7c[a].length;j++){if(ag[k]==p7c[a][j]){f=true;}}
 if(!f){p7c[a][p7c[a].length++]=ag[k];}}}
}

function P7_hideEl(evt) { //v1.5 by PVII-www.projectseven.com
 var b,r,m=false;if(document.layers){b=evt.target;if(b.p7aHide){
 b.display="none";}else{routeEvent(evt);}
 }else if(document.all&&!window.opera){b=event.srcElement;while(b){
 if(b.p7aHide){break;}b=b.parentElement;}if(!b.contains(event.toElement)){
 b.style.display="none";}}else if(document.getElementById){
 b=evt.currentTarget;r=evt.relatedTarget;while(r){if(b==r){m=true;
 break;}r=r.parentNode;}if(!m){b.style.display="none";}}
}

function P7_autoHide() { //v1.5 by PVII-www.projectseven.com
 var i,g;for(i=0;i<arguments.length;i++){
 if((g=MM_findObj(arguments[i]))!=null){g.p7aHide=true;if(document.layers){
 g.captureEvents(Event.MOUSEOUT);}g.onmouseout=P7_hideEl;}}
}



//slide open iFrames used for Help popups

// slide open the layer smoothly at this speed sub-routine
var smooth_timer;
function go2(selID, link) {
  var selOBJ = (document.getElementById) ? document.getElementById(selID) : eval("document.all['" + selID + "']");
  window.location=link + selOBJ.options[selOBJ.selectedIndex].value;
}

// slide open the layer smoothly sub-routine
function smoothHeight(id, curH, targetH, stepH, mode) {
  diff = targetH - curH;
  if (diff != 0) {
    newH = (diff > 0) ? curH + stepH : curH - stepH;
    ((document.getElementById) ? document.getElementById(id) : eval("document.all['" + id + "']")).style.height = newH + "px";
    if (smooth_timer) window.clearTimeout(smooth_timer);
    smooth_timer = window.setTimeout( "smoothHeight('" + id + "'," + newH + "," + targetH + "," + stepH + ",'" + mode + "')", 20 );
  }
  else if (mode != "o") ((document.getElementById) ? document.getElementById(mode) : eval("document.all['" + mode + "']")).style.display="none";
}

// show & hide the iFrame
function showFrame(i, href) {
  var thisObj = (document.getElementById) ? document.getElementById('idShowDiv' + i) : eval("document.all['idShowDiv" + i + "']");
  var frameObj = (document.getElementById) ? document.getElementById('idShowFrame' + i) : eval("document.all['idShowFrame" + i + "']");
  if (thisObj != null) {
    if (thisObj.style.display=="none") {
      thisObj.style.display="";
      if (!frameObj.src) frameObj.src = href;
      smoothHeight('idShowFrame' + i, 0, 210, 42, 'o');  // use the layer slide sub routine
    }
    else {
      smoothHeight('idShowFrame' + i, 210, 0, 42, 'idShowDiv' + i);  // use the layer slide sub routine
    }
  }
}

// BUILD EMAIL ADDRESS FOR DISPLAY
function buildE(recipient, domain, linktext){
	if (linktext == '') {
		document.write('<a href=\"' + 'mail' + 'to' + ':' + recipient + '@' + domain + '\">' + recipient + '@' + domain + '</a>');
	} else {
		document.write('<a href=\"' + 'mail' + 'to' + ':' + recipient + '@' + domain + '\">' + linktext + '</a>');
	}
}

/////////////////////////////////////////////////////////////////////////////////////////
// LEGACY SCRIPTS
/////////////////////////////////////////////////////////////////////////////////////////

// LEGACY WINDOW OPEN FROM DOCUMENT PAGES OF OLD SITE
function MM_openBrWindow(theURL,winName,features) {
  window.open(theURL,winName,features);
}	

// SEND A LINK SCRIPT
//This function gives the user the ability to send a link of the page they are viewing.
// use \n for line breaks.
function sendAlink() {
  // SET MESSAGE VALUES
  var linkurl= window.document.location
  var linktitle= window.document.title 
  var subject = "WorkSafeBC.com";
  var body = 
    "I think you'll be interested in what I found on the WorkSafeBC.com web site.\n\n" + 
	"Click on the URL to view the page: " + linkurl;
	
  // BUILD MAIL MESSAGE COMPONENTS 
  var doc = "mailto:" + 
    "&subject=" + escape(subject) + 
    "&body=" + escape(body); 

  // POP UP EMAIL MESSAGE WINDOW
  	return doc;
}


/*
Re-direct to selected page's URL script
*/
//dropdown menu re-direct to other page's url
function goSelect(newPage) {
	with(newPage) {
	top.window.location=options[selectedIndex].value;       // jump to that option's value
	}
}

//The following functions control the tooltips that are displayed on the timeline charts June 11, 2003
<!--

var ie = document.all ? 1 : 0
var ns = document.layers ? 1 : 0

if(ns){doc = "document."; sty = ""}
if(ie){doc = "document.all."; sty = ".style"}



var initialize = 0
var Ex, Ey, topColor, subColor, ContentInfo

if(ie){
Ex = "event.x"
Ey = "event.y"

topColor = "#6087D5"
subColor = "#efefef"
}

if(ns){
Ex = "e.pageX"
Ey = "e.pageY"
window.captureEvents(Event.MOUSEMOVE)
window.onmousemove=overhere

topColor = "#6087D5"
subColor = "#efefef"
}

function MoveToolTip(layerName, FromTop, FromLeft, e){
if(ie){eval(doc + layerName + sty + ".top = "  + (eval(FromTop) + document.documentElement.scrollTop))} // NPC changed to documentElement for doctype compatibility
if(ns){eval(doc + layerName + sty + ".top = "  +  eval(FromTop))}
eval(doc + layerName + sty + ".left = " + (eval(FromLeft) + 15))
}

function ReplaceContent(layerName){

if(ie){
	document.all[layerName].innerHTML = ContentInfo;
}


if(ns){

with(document.layers[layerName].document) 
{ 
   open(); 
   write(ContentInfo); 
   close(); 
}

}


}

function Activate(){
	initialize=1;
	overhere();
}
function deActivate(){
	initialize=0;
	overhere();
}


function overhere(e){
if(initialize){

MoveToolTip("ToolTip", Ey, Ex, e);
eval(doc + "ToolTip" + sty + ".display = 'block'");
}

else{
MoveToolTip("ToolTip", 0, 0);
eval(doc + "ToolTip" + sty + ".display = 'none'");
}


}

function EnterContent(layerName, TTitle, TContent){

ContentInfo = '<table border="0" width="100%" cellspacing="0" cellpadding="0">'+
'<tr><td width="100%" bgcolor="#000000">'+

'<table border="0" width="100%" cellspacing="1" cellpadding="0">'+
'<tr><td width="100%" bgcolor='+topColor+'>'+

'<table border="0" width="100%" cellspacing="0" cellpadding="0" align="center">'+
'<tr><td width="100%" class="tooltiptitle">'+TTitle+'</td></tr>'+
'</table>'+

'</td></tr>'+

'<tr><td width="100%" bgcolor='+subColor+'>'+

'<table border="0" width="95%" cellpadding="0" cellspacing="1" align="center">'+

'<tr><td width="100%">'+

'<font class="tooltipcontent">'+TContent+'</font>'+

'</td></tr>'+
'</table>'+

'</td></tr>'+
'</table>'+

'</td></tr>'+
'</table>';


ReplaceContent(layerName)

}

//--> End of Timeline functions

//-- Standard Rollover JavaScript
<!--
function MM_swapImgRestore() { //v3.0
  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_preloadImages() { //v3.0
  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 MM_findObj(n, d) { //v4.0
  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 && document.getElementById) x=document.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  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];}
}
//-->


//--End Standard Rollover JavaScript

//--Webcast popup
<!-- Begin
function NewWindow(mypage, myname, w, h, scroll) {
var winl = (screen.width - w) / 2;
var wint = (screen.height - h) / 2;
winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars='+scroll+',resizable'
win = window.open(mypage, myname, winprops)
if (parseInt(navigator.appVersion) >= 4) { win.window.focus(); }
}
//  End -->
  
 //DYNAMIC ALTERNATING ROW COLORS 
//Javascript for the alternating row colors, found in careers page, forms page, etc.

//!---Begin
addEvent(window, "load", alternate_init);

function alternate_init() {
	// Find all tables with class sortable and make them sortable
	if (!document.getElementsByTagName) return;
	tbls = document.getElementsByTagName("table");
	for (ti=0;ti<tbls.length;ti++) {
		thisTbl = tbls[ti];
		if (((' '+thisTbl.className+' ').indexOf("alternate_rows") != -1) && (thisTbl.id)) {
			alternate(thisTbl);
		}
	}
}

function addEvent(elm, evType, fn, useCapture)
// addEvent and removeEvent
// cross-browser event handling for IE5+,	NS6 and Mozilla
// By Scott Andrew
{
	if (elm.addEventListener){
		elm.addEventListener(evType, fn, useCapture);
		return true;
	} else if (elm.attachEvent){
		var r = elm.attachEvent("on"+evType, fn);
		return r;
	} else {
		alert("Handler could not be removed");
	}
} 

function replace(s, t, u) {
  /*
  **  Replace a token in a string
  **    s  string to be processed
  **    t  token to be found and removed
  **    u  token to be inserted
  **  returns new String
  */
  i = s.indexOf(t);
  r = "";
  if (i == -1) return s;
  r += s.substring(0,i) + u;
  if ( i + t.length < s.length)
    r += replace(s.substring(i + t.length, s.length), t, u);
  return r;
}

function alternate(table) {
	// Take object table and get all it's tbodies.
	var tableBodies = table.getElementsByTagName("tbody");
	// Loop through these tbodies
	for (var i = 0; i < tableBodies.length; i++) {
		// Take the tbody, and get all it's rows
		var tableRows = tableBodies[i].getElementsByTagName("tr");
		// Loop through these rows
		for (var j = 0; j < tableRows.length; j++) {
			// Check if j is even, and apply classes for both possible results
			if ( (j % 2) == 0  ) {
				if (tableRows[j].className == 'odd' || !(tableRows[j].className.indexOf('odd') == -1) ) {
					tableRows[j].className = replace(tableRows[j].className, 'odd', 'even');
				} else {
					tableRows[j].className += " even";
				}
			} else {
				if (tableRows[j].className == 'even' || !(tableRows[j].className.indexOf('even') == -1) ) {
					tableRows[j].className = replace(tableRows[j].className, 'even', 'odd');
				}
				tableRows[j].className += " odd";
			} 
		}
	}
}
//  End -->

