var today=new Date();
//This script is to write the header at the bottom of the MSE Pages
//The Page is called and the function WriteHeader is called specifying the width required.
//If a width is an Odd number like 751/851 etc.. it will be converted as 75%, 85% etc

var linkBase = "http://www.pdo.co.om/hseforcontractors/";

var iPageHits=0;

var strPage = document.URL;
var iTableWidth = '100%';

// menu items...
var menui = new Array();

// menu links...
var menul = new Array();

menui[0] = "PDO Home";
menui[1] = "HSE Home";
menui[2] = "Health";
menui[3] = "Safety";
menui[4] = "Environment";
menui[5] = "Sus. Development";
menui[6] = "Drive to Survive";
menui[7] = "Online Library";

menul[0] = "http://www.pdo.co.om";
menul[1] = linkBase + "default.asp";
menul[2] = linkBase + "health/default.asp";
menul[3] = linkBase + "safety/default.htm";
menul[4] = linkBase + "environment/default.htm";
menul[5] = linkBase + "sd/sdhome.asp";
menul[6] = linkBase + "dts/default.htm";
menul[7] = linkBase + "online_library/default.asp";

strPage = strPage.toUpperCase();

function GetScreenResolution()
{
  if ((screen.width>=1024) && (screen.height>=768))
  {
    document.write('<style>');
    document.write('BODY {background: url("'+linkBase+'images/bginside.gif") center}');
    document.write('</style>');
  }
  else
  {
    document.write('<style>');
    document.write('BODY {background: url("'+linkBase+'images/bginside800600.gif") center }');
    document.write('</style>');
  }
}

function whatsnew(yr,mon,day)
{
 var expire=new Date(yr,mon,day)
 if (today.getTime()<=expire.getTime())
  document.write('<img src="'+linkBase+'images/newanim1.gif" align="middle">')
}

function writemail(e)
{
	var p="mailto:";
	document.write('<a href="'+p+e+'@pdo.co.om">'+e+'@pdo.co.om</a>');
}

function writemailwithname(e,e1,c)
{
	var p="mailto:";
	document.write('<a class="'+c+'" href="'+p+e+'">'+e1+'</a>');
}

function WriteHeader(iWidth)
{
	iTableWidth = iWidth;
	if (iTableWidth % 2 == 0)
	 document.write('<table background="'+linkBase+'images/headerbg.gif" border="0" cellpadding="0" cellspacing="0" width=' + iTableWidth + '">');
	else
	{
		var iWidth1 = Math.floor(iTableWidth/10);
		document.write('<table background="'+linkBase+'images/headerbg.gif" border="0" cellpadding="0" cellspacing="0" width="' + iWidth1 + '%">');
	}
	document.write('<tr>');
 	document.write('<td valign="top" align="left" height="22" class="whitetext">');
 	document.write('<img src="'+linkBase+'images/tl-inside.gif" border="0" height="22">');
    	document.write('</td>');
	for (i=0;i<=menui.length-1;i++)
	{
		var strcurItem = menul[i];
		strcurItem = strcurItem.toUpperCase();
		if (strPage != strcurItem)
		{
	 		if (i>0)
		 	{
			 	document.write('<td valign="middle" align="center" height="22" class="whitetext">');
			 	document.write('<img src="'+linkBase+'images/menusep.gif" border="0">');
			    	document.write('</td>');
		    	}
			document.write('<td valign="middle" align="center" height="22" class="whitetext">');
			document.write('<a class="whitetext" href="' + menul[i] + '">' + menui[i] + '</a>');
			document.write('</td>');
		}
	}
 	document.write('<td valign="top" align="right" height="22" class="whitetext">');
 	document.write('<img src="'+linkBase+'images/tr-inside.gif" border="0" height="22">');
    	document.write('</td>');
	document.write('</tr>');
	document.write('</table>');
}

function WriteHeaderFull(iWidth)
{
	iTableWidth = screen.width-24;
	if (iTableWidth % 2 == 0)
	 document.write('<table background="'+linkBase+'images/headerbg.gif" border="0" cellpadding="0" cellspacing="0" width=' + iTableWidth + '">');
	else
	{
		var iWidth1 = Math.floor(iTableWidth/10);
		document.write('<table background="'+linkBase+'images/headerbg.gif" border="0" cellpadding="0" cellspacing="0" width="' + iWidth1 + '%">');
	}
	document.write('<tr>');
 	document.write('<td valign="top" align="left" height="22" class="whitetext">');
 	document.write('<img src="'+linkBase+'images/tl-inside.gif" border="0" height="22">');
    	document.write('</td>');
	for (i=0;i<=menui.length-1;i++)
	{
		var strcurItem = menul[i];
		strcurItem = strcurItem.toUpperCase();
		if (strPage != strcurItem)
		{
	 		if (i>0)
		 	{
			 	document.write('<td valign="middle" align="center" height="22" class="whitetext">');
			 	document.write('<img src="'+linkBase+'images/menusep.gif" border="0">');
			    	document.write('</td>');
		    	}
			document.write('<td valign="middle" align="center" height="22" class="whitetext">');
			document.write('<a class="whitetext" href="' + menul[i] + '">' + menui[i] + '</a>');
			document.write('</td>');
		}
	}
 	document.write('<td valign="top" align="right" height="22" class="whitetext">');
 	document.write('<img src="'+linkBase+'images/tr-inside.gif" border="0" height="22">');
    	document.write('</td>');
	document.write('</tr>');
	document.write('</table>');
}


function WriteFooter(iWidth)
{
	iTableWidth = iWidth;

	if (iTableWidth % 2 == 0)
		document.write('<table bgcolor="#ffffff" border="0" cellpadding="3" cellspacing="1" width="' + iTableWidth + '">');
	else
	{
		var iWidth1 = Math.floor(iTableWidth/10);
		document.write('<table bgcolor="#ffffff" border="0" cellpadding="3" cellspacing="1" width="' + iWidth1 + '%">');
	}
	document.write('<tr>');
	document.write('<td align="center" bgcolor="#000000" height="18" valign="middle">');
	document.write('<a class="whitetext" href="' + linkBase + 'blocks/hsefunction/default.htm">HSE Function</a></td>');
	document.write('<td align="center" bgcolor="#000000" height="18" valign="middle">');
	document.write('<a class="whitetext" href="' + linkBase + 'blocks/audits/audit.html">Audits</a></td>');
	document.write('<td align="center" bgcolor="#000000" height="18" valign="middle">');
	document.write('<a class="whitetext" href="' + linkBase + 'blocks/statistics/hsestatistics.html">Statistics</a></td>');
	document.write('<td align="center" bgcolor="#000000" height="18" valign="middle">');
	document.write('<a class="whitetext" href="' + linkBase + 'blocks/training/train.html">');
	document.write('HSE Training</a></td>');
	document.write('<td align="center" bgcolor="#000000" height="18" valign="middle">');
	document.write('<a class="whitetext" href="' + linkBase + 'blocks/hseplan/hseplan.html">HSE Plan</a></td>');
	document.write('<td align="center" bgcolor="#000000" height="18" valign="middle">');
	document.write('<a class="whitetext" href="' + linkBase + 'blocks/documentation/document.html">Documentation</a></td>');
	document.write('<td align="center" bgcolor="#000000" height="18" valign="middle">');
	document.write('<a class="whitetext" href="' + linkBase + 'blocks/links/links.html">Links</a></td>');
	document.write('</tr>');
	document.write('</table>');
}

function WriteFooterFull(iWidth)
{
	iTableWidth = screen.width-24;

	if (iTableWidth % 2 == 0)
		document.write('<table bgcolor="#ffffff" border="0" cellpadding="3" cellspacing="1" width="' + iTableWidth + '">');
	else
	{
		var iWidth1 = Math.floor(iTableWidth/10);
		document.write('<table bgcolor="#ffffff" border="0" cellpadding="3" cellspacing="1" width="' + iWidth1 + '%">');
	}
	document.write('<tr>');
	document.write('<td align="center" bgcolor="#000000" height="18" valign="middle">');
	document.write('<a class="whitetext" href="' + linkBase + 'blocks/hsefunction/default.htm">HSE Function</a></td>');
	document.write('<td align="center" bgcolor="#000000" height="18" valign="middle">');
	document.write('<a class="whitetext" href="' + linkBase + 'blocks/audits/audit.html">Audits</a></td>');
	document.write('<td align="center" bgcolor="#000000" height="18" valign="middle">');
	document.write('<a class="whitetext" href="' + linkBase + 'blocks/statistics/hsestatistics.html">Statistics</a></td>');
	document.write('<td align="center" bgcolor="#000000" height="18" valign="middle">');
	document.write('<a class="whitetext" href="' + linkBase + 'blocks/training/train.html">');
	document.write('HSE Training</a></td>');
	document.write('<td align="center" bgcolor="#000000" height="18" valign="middle">');
	document.write('<a class="whitetext" href="' + linkBase + 'blocks/hseplan/hseplan.html">HSE Plan</a></td>');
	document.write('<td align="center" bgcolor="#000000" height="18" valign="middle">');
	document.write('<a class="whitetext" href="' + linkBase + 'blocks/documentation/document.html">Documentation</a></td>');
	document.write('<td align="center" bgcolor="#000000" height="18" valign="middle">');
	document.write('<a class="whitetext" href="' + linkBase + 'blocks/links/links.html">Links</a></td>');
	document.write('</tr>');
	document.write('</table>');
}


function WriteContact(sPg)
{
	if (iTableWidth % 2 == 0)
		document.write('<table border="0" cellpadding="0" cellspacing="0" width="' + iTableWidth + '">');
	else
	{
		var iWidth1 = Math.floor(iTableWidth/10);
		document.write('<table border="0" cellpadding="0" cellspacing="0" width="' + iWidth1 + '%">');
	}
	document.write('<tr>');
	document.write('<td width="14" height="14" align="left">');
	document.write('<img src="'+linkBase + 'images/bl-inside.gif" width="14" height="14">');
	document.write('</td>');
	document.write('<td valign="middle" align="center" class="official" bgcolor="#ffffff">');
	document.write('Page Contact: ');
	switch(sPg)
	{
		case "hse":
			document.write('<b><a href="mailto:Nasra.NAA.Maamery@pdo.co.om">Nasra Al Maamery</a></b> (MSE/51 | +968 246 78494)');
			break;
		case "h":
			document.write('<b><a href="mailto:Brett.Young@pdo.co.om">Brett Young</a></b> (MSE/32 | +968 24677684)');
			break;
		case "s":
			document.write('<b><a href="mailto:Hamad.SM.Khalfeen@pdo.co.om">Hamed Al-Khalfeen</a></b> (MSE/1 | +968 24673718)');
			break;
		case "sa":
			document.write('<b><a href="mailto:Ian.Jewitt@pdo.co.om">Ian Jewitt</a></b> (MSE/4 | +968 24673261)');
			break;
		case "e":
			document.write('<b><a href="mailto:Mohammed.Shuayli@pdo.co.om">Mohammed Al Shuayli</a></b> (MSE/2 | +968 24675167)');
			break;
		case "ep":
			document.write('<b><a href="mailto:Nabil.Allawati@pdo.co.om">Nabil Al Lawati</a></b> (MSE/24 | +968 24675167)');
			break;
		case "dm":
			document.write('<b><a href="mailto:Abla.AHM.Naamani@pdo.co.om">Abla Naamani</a></b> (MSE/521 | +968 24675608)');
			break;
		case "ib":
			document.write('<b><a href="mailto:Jokha.J.Riyami@pdo.co.om">Jokha Riyami</a></b> (MSE/5211 | +968 24673230)');
			break;
		case "hm":
			document.write('<b><a href="mailto:Hamad.SM.Khalfeen@pdo.co.om">Hamed Al-Khalfeen</a></b> (MSE/1 | +968 24673718)');
			break;
		case "tr":
			document.write('<b><a href="mailto:Ian.Bowen@pdo.co.om">Ian Bowen</a></b> (HLD/8 | +968 24677312)');
			break;
		case "ctr":
			document.write('<b><a href="mailto:Hamed.AS.Esry@pdo.co.om">Hamed Esry</a></b> (MSE/131 | +968 24676446)');
			break;
		case "stop":
			document.write('<b><a href="mailto:huwaida.harthy@pdo.co.om">Huwaida Harthy</a></b> (MSE/111 | +968 24670404)&nbsp; <b><a href="mailto:Ram.K.Nivedita@pdo.co.om">Nivedita Ram</a></b> (MSE/11 | +968 24673616)');
			break;
		case "bbs":
			document.write('<b><a href="mailto:Ram.K.Nivedita@pdo.co.om">Nivedita Ram</a></b> (MSE/11 | +968 24673616)');
			break;
		case "au":
			document.write('<b><a href="mailto:Younis.YHM.Hinai@pdo.co.om">Younis Hinai</a></b> (MSE/53 | +968 24674087)');
			break;
		case "com":
			document.write('<b><a href="mailto:Soud.S.Meskiry@pdo.co.om">Soud Al-Meskiry</a></b> (MSE/6 | +968 24675452)');
			break;
		case "jp":
			document.write('<b><a href="mailto:Ian.Jewitt@pdo.co.om">Ian Jewitt</a></b> (MSE/4 | +968 24673261)');
			break;
		case "iso":
			document.write('<b><a href="mailto:Mohammed.Shuayli@pdo.co.om">Mohammed Al Shuayli</a></b> (MSE/2 | +968 24675167)');
			break;
		case "hsecases":
			document.write('<b><a href="mailto:Chris.JC.Gundersen@pdo.co.om">Chris Gundersun</a></b> (MSE/43 | +968 24671465)');
			break;
		case "hsecont":
			document.write('<b><a href="mailto:Kevin.KF.Doyle@pdo.co.om">Kevin Doyle</a></b> (MSE/12 | +968 24671072)<bR> ');
			break;

		default:
			document.write('<b><a href="mailto:Nasra.NAA.Maamery@pdo.co.om">Nasra Al Maamery</a></b> (MSE/51 | +968 246 78494)');
			break;
	}
	document.write('</td>');
	document.write('<td width="14" height="14" align="right">');
	document.write('<img src="'+linkBase + 'images/br-inside.gif" width="14" height="14">');
	document.write('</td>');
	document.write('</tr>');
	document.write('</table>');
}

function whereaminow()
{
 var url = document.URL;
 var s1 = url.replace(linkBase,"")
 var menunav = s1.split("/")

	if (iTableWidth % 2 == 0)
		
		document.write('<table background="'+linkBase+'images/bg_bluegradient.jpg" border="0" cellpadding="2" cellspacing="0" width="' + iTableWidth + '" cols="2">');
	else
	{
		var iWidth1 = Math.floor(iTableWidth/10);
		document.write('<table background="'+linkBase+'images/bg_bluegradient.jpg" border="0" cellpadding="2" cellspacing="0" width="' + iWidth1 + '%" cols="2">');
	}

 document.write('<form name="frmHSESearch" method="POST" action="'+linkBase +'searchresults.asp">');
 document.write('<tr>');
 document.write('<td height="22"><p class="text"><b>Current Location</b>: ');
 document.write('<a href="/">PDO</a>');
 document.write(' » <a href="'+linkBase+'">HSE</a>');
 for (i=0;i<menunav.length;i++)
 {
  if(menunav[i].indexOf('.')<0)
  {
   switch (menunav[i])
   {
    case "competence":
     document.write(' » <a href="'+linkBase+'competence/competence.asp">HSE Competence</a>');
     break;
    case "environment":
     document.write(' » <a href="'+linkBase+'environment/">Environment</a>');
     break;
    case "fountain":
     document.write(' » <a href="'+linkBase+'fountain/default.asp">Fountain</a>');
     break;
    case "gallery":
     document.write(' » <a href="'+linkBase+'gallery/default.htm">Gallery</a>');
     break;
    case "health":
     document.write(' » <a href="'+linkBase+'health/">Health</a>');
     break;
    case "hearts_minds":
     document.write(' » <a href="'+linkBase+'hearts_minds/">Hearts & Minds</a>');
     break;
    case "helpdesk":
     document.write(' » <a href="'+linkBase+'helpdesk/">Helpdesk</a>');
     break;
    case "impactsafety":
     document.write(' » <a href="'+linkBase+'impactsafety/">Impact Safety</a>');
     break;
    case "online_library":
     document.write(' » <a href="'+linkBase+'online_library/default.asp">Online Library</a>');
     break;
    case "safety":
     document.write(' » <a href="'+linkBase+'safety/">Safety</a>');
     break;
    case "audits":
     document.write(' » <a href="'+linkBase+'blocks/audits/audit.html">Audits</a>');
     break;
    case "hsefunction":
     document.write(' » <a href="'+linkBase+'blocks/hsefunction/default.htm">HSE Function</a>');
     break;
    case "documentation":
     document.write(' » <a href="'+linkBase+'blocks/documentation/document.html">HSE Documentation</a>');
     break;
    case "hseplan":
     document.write(' » <a href="'+linkBase+'blocks/hseplan/hseplan.html">HSE Plan</a>');
     break;
    case "links":
     document.write(' » <a href="'+linkBase+'blocks/links/links.html">Links</a>');
     break;
    case "statistics":
     document.write(' » <a href="'+linkBase+'blocks/statistics/hsestatistics.html">HSE Statistics</a>');
     break;
    case "training":
     document.write(' » <a href="'+linkBase+'blocks/training/train.html">HSE Training</a>');
     break;
    case "conferences":
     document.write(' » <a href="'+linkBase+'blocks/hsefunction/conferences/hseconferences.htm">HSE Conferences</a>');
     break;
    case "iso14001":
     document.write(' » <a href="'+linkBase+'environment/iso14001/">ISO14001</a>');
     break;
   }
  }
 }
 document.write(' » '+document.title);
 document.write('</td>');
 document.write('<td height="22" align="right" valign="middle" class="text">');
 document.write('<input type="text" name="txtSearch" value="">&nbsp;');
 document.write('<input type="submit" value="Search" name="cmdSearch" onClick="return ValidateSearchForm(this.form)">');
// document.write('<input type="image" src="'+linkBase+'images/search.jpg" name="cmdSearch">');
 document.write('</td>');
 document.write('</tr>');
 document.write('</form>');
 document.write('</table>');
}

function ValidateSearchForm(form)
{
  if (form.txtSearch.value=="" || form.txtSearch.value=="Text required!!")
  {
    form.txtSearch.value = "Text required!!"
    form.txtSearch.focus();
    return(false);
  }
  else
    return(true);
}

function formatdate(dt)
{
  var MA = new String('JANFEBMARAPRMAYJUNJULAUGSEPOCTNOVDEC');
  var m = 3 * dt.getMonth();
  return padzero(dt.getDate()) + '-' + MA.substring(m, m+3) + '-' + dt.getFullYear();
}

function padzero(x)
{ 
	return (x>=10||x<0?"":"0") + x
}

function toggleLayer(LayerToDisplay,LinkLayer,Text1,Text2)
{
	if (document.getElementById)
	{
		var style2=document.getElementById(LayerToDisplay).style;
		style2.display=style2.display? "":"block";
		var linkElement=document.getElementById(LinkLayer);
		if (linkElement.innerHTML==Text1)
			document.getElementById(LinkLayer).innerHTML=Text2;
		else
			document.getElementById(LinkLayer).innerHTML=Text1;
	}
	else if (document.all)
	{
		var style2=document.all[LayerToDisplay].style;
		style2.display=style2.display? "":"block";
		var linkElement=document.all[LinkLayer];
		if (linkElement.innerHTML==Text1)
			linkElement.innerHTML=Text2;
		else
			linkElement.innerHTML=Text1;
	}
	else if (document.layers)
	{
		var style2=document.layers[LayerToDisplay].style;
		style2.display=style2.display? "":"block";
		var linkElement=document.layers[LinkLayer];
		if (linkElement.innerHTML==Text1)
			linkElement.innerHTML=Text2;
		else
			linkElement.innerHTML=Text2;

	}
}

function getStyleObject(objectId) {
    // cross-browser function to get an object's style object given its id
    if(document.getElementById && document.getElementById(objectId)) {
	// W3C DOM
	return document.getElementById(objectId).style;
    } else if (document.all && document.all(objectId)) {
	// MSIE 4 DOM
	return document.all(objectId).style;
    } else if (document.layers && document.layers[objectId]) {
	// NN 4 DOM.. note: this won't find nested layers
	return document.layers[objectId];
    } else {
	return false;
    }
} // getStyleObject

function changeObjectVisibility(objectId, newVisibility) {
    // get a reference to the cross-browser style object and make sure the object exists
    var styleObject = getStyleObject(objectId);
    if(styleObject) {
	styleObject.visibility = newVisibility;
	return true;
    } else {
	// we couldn't find the object, so we can't change its visibility
	return false;
    }
} // changeObjectVisibility

function moveObject(objectId, newXCoordinate, newYCoordinate) {
    // get a reference to the cross-browser style object and make sure the object exists
    var styleObject = getStyleObject(objectId);
    if(newXCoordinate>480)
      newXCoordinate = 480;
    if(newYCoordinate>221)
      newYCoordinate = 221;
    if(styleObject) {
	styleObject.left = newXCoordinate;
	styleObject.top = newYCoordinate;
	return true;
    } else {
	// we couldn't find the object, so we can't very well move it
	return false;
    }
} // moveObject

// store variables to control where the popup will appear relative to the cursor position
// positive numbers are below and to the right of the cursor, negative numbers are above and to the left
var xOffset = 30;
var yOffset = -5;

function showPopup (targetObjectId, eventObj) {
    if(eventObj) {
	// hide any currently-visible popups
	hideCurrentPopup();
	// stop event from bubbling up any farther
	eventObj.cancelBubble = true;
	// move popup div to current cursor position 
	// (add scrollTop to account for scrolling for IE)
	var newXCoordinate = (eventObj.pageX)?eventObj.pageX + xOffset:eventObj.x + xOffset + ((document.body.scrollLeft)?document.body.scrollLeft:0);
	var newYCoordinate = (eventObj.pageY)?eventObj.pageY + yOffset:eventObj.y + yOffset + ((document.body.scrollTop)?document.body.scrollTop:0);
	moveObject(targetObjectId, newXCoordinate, newYCoordinate);
	// and make it visible
	if( changeObjectVisibility(targetObjectId, 'visible') ) {
	    // if we successfully showed the popup
	    // store its Id on a globally-accessible object
	    window.currentlyVisiblePopup = targetObjectId;
	    return true;
	} else {
	    // we couldn't show the popup, boo hoo!
	    return false;
	}
    } else {
	// there was no event object, so we won't be able to position anything, so give up
	return false;
    }
} // showPopup

function hideCurrentPopup() {
    // note: we've stored the currently-visible popup on the global object window.currentlyVisiblePopup
    if(window.currentlyVisiblePopup) {
	changeObjectVisibility(window.currentlyVisiblePopup, 'hidden');
	window.currentlyVisiblePopup = false;
    }
} // hideCurrentPopup


// ***********************
// hacks and workarounds *
// ***********************

// initialize hacks whenever the page loads
window.onload = initializeHacks;

// setup an event handler to hide popups for generic clicks on the document
document.onclick = hideCurrentPopup;

function initializeHacks() {
    // this ugly little hack resizes a blank div to make sure you can click
    // anywhere in the window for Mac MSIE 5
    if ((navigator.appVersion.indexOf('MSIE 5') != -1) 
	&& (navigator.platform.indexOf('Mac') != -1)
	&& getStyleObject('blankDiv')) {
	window.onresize = explorerMacResizeFix;
    }
    resizeBlankDiv();
    // this next function creates a placeholder object for older browsers
    createFakeEventObj();
}

function createFakeEventObj() {
    // create a fake event object for older browsers to avoid errors in function call
    // when we need to pass the event object to functions
    if (!window.event) {
	window.event = false;
    }
} // createFakeEventObj

function resizeBlankDiv() {
    // resize blank placeholder div so IE 5 on mac will get all clicks in window
    if ((navigator.appVersion.indexOf('MSIE 5') != -1) 
	&& (navigator.platform.indexOf('Mac') != -1)
	&& getStyleObject('blankDiv')) {
	getStyleObject('blankDiv').width = document.body.clientWidth - 20;
	getStyleObject('blankDiv').height = document.body.clientHeight - 20;
    }
}

function explorerMacResizeFix () {
    location.reload(false);
}

function fullScreen(theURL) 
{
	window.open(theURL,"","channelmode,scrollbars");
}

function commonutilities()
{
	document.write('<a class="whitetext" href="javascript:history.go(-1)">');
	document.write('<img src="'+linkBase+'images/backbutton.gif" border="0"></a>   ');
	document.write('<a class="whitetext" href="javascript:void(window.print())">');
	document.write('<img src="'+linkBase+'images/printbutton.gif" border="0"></a>   ');
	document.write('<a class="whitetext" href="javascript:void(window.close())">');
	document.write('<img src="'+linkBase+'images/closebutton.gif" border="0"></a> ');
}
