/*======================================= 
	SBM Offshore Website 
	JS Document 
	Creation date: 18-Sep-2007
	Last modified: 05-May-2008
=======================================*/

/* General Fns */
var mnTimer;
function showSubCat( id )
{
	var mn = document.getElementById( "L2_"+id );
	if( mn!=null )
	{
		if( slcCatId!=null && slcCatId!=id ) hideSubCat(slcCatId);
		else window.clearTimeout(mnTimer);
		mn.style.display = "block";
		mn.style.color = "#F9888D";
		slcCatId = id;
	} else {
		window.clearTimeout(mnTimer);
		mnTimer = window.setTimeout( 'hideSubCat( "'+slcCatId+'" )',1000 );
	}
}

function hideSubCat( id )
{
	var mn = document.getElementById( "L2_"+id );
	if( mn!=null )
	{
		mn.style.display = "none";
		mn.style.color = "";
	}
}

function initTree( id,n )
{	
	var itm = n>1 ? document.getElementById( 'Lev_'+id ) : document.getElementById( 'Lev1_'+id );
	if( itm!=null )
	{		
		if( n>2 )
		{
			itm.style.cssText = "border:1px solid #ccc; background:#f4f4f4;";
			var parentItm = itm.parentNode;			
			if( parentItm!=null )
			{ 
				//parentItm.style.display='block';				
				var parentItmId = parentItm.getAttribute('id').split('__')[1];
				expandGroup( parentItmId );
			}			
			if( parentItm.parentNode!=null && parentItm.parentNode.nodeName.toLowerCase()=="span" )
			{
				parentItm.parentNode.style.display='block';
				var rootItmId = 'L1_'+splitId( 'Lev1_',parentItm.parentNode.getAttribute('id') );
				highlightBannerItm( rootItmId );
			}
		} else if( n==2 ) {
			itm.style.cssText = "border:1px solid #ccc; background:#f4f4f4;";
			var parentItm = itm.parentNode;
			var rootItmId = 'L1_'+splitId( 'Lev1_',parentItm.getAttribute('id') );
			highlightBannerItm( rootItmId );
			if( parentItm!=null ) parentItm.style.display='block';
			expandGroup( id );
		} else {
			var rootItmId = 'L1_'+id;
			highlightBannerItm( rootItmId );
			itm.style.display = 'block';
		}
	}
}

function expandGroup( id )
{
	var itm = document.getElementById( 'Lev_'+id );
	if( itm!=null )
	{
		var blt = itm.getElementsByTagName("img")[0];
		var nextEl = itm.nextSibling;			
		if( nextEl!=null && nextEl.nodeName.toLowerCase()=="ul"  )
		{
			var regexp = new RegExp('expand','gi');
			if( !regexp.test( blt.src ) )
			{				
				//blt.src = path+"icn_expand.gif";		
				blt.src = blt.src.vbreplace('blt_lev2','expand');
				nextEl.style.display='block';
			} else {
				//blt.src = path+"icn_blt_lev2.gif";
				blt.src = blt.src.vbreplace('expand','blt_lev2');
				nextEl.style.display='none';
			} // else
		} // if
	}
}

function highlightBannerItm( id )
{
	if( id!=undefined )
	{
		var banMenuItm = document.getElementById( id );
		var liBanMenuItm = banMenuItm.parentNode;
		if( liBanMenuItm!=null && liBanMenuItm.nodeName.toLowerCase()=='li' )
		{
			banMenuItm.className = "mainMenuActive";
			//liBanMenuItm.style.border = "1px inset #C3232A";
			liBanMenuItm.style.border = "1px inset #f4f4f4";
			liBanMenuItm.style.background = "#fff";
		}
	}
}

function splitId( pref,id )
{
	if( pref!=undefined && id!=undefined )
		return (id).split(pref)[1];
}

function OpenWin(url,width,height) 
{
	if (screen.availHeight) {
		maxHeight = (((screen.availHeight)-(height))/2)-15;
		maxWidth = ((screen.availWidth)-(width))/2;		
		w = window.open (url,'designWin','height='+height+', left='+maxWidth+', location=0, menubar=0, resizable=1, scrollbars=1, status=0, titlebar=0, toolbar=0, top='+maxHeight+', width='+width);
		w.focus();
	}
	if (window.innerHeight) {
		maxHeight = ((window.innerHeight)-(height)/2)-15;
		maxWidth = ((window.innerWidth)-(width)/2);
		w = window.open (url,'designWin','height='+height+', left='+maxWidth+', location=0, menubar=0, resizable=1, scrollbars=1, status=0, titlebar=0, toolbar=0, top='+maxHeight+', width='+width);
		w.focus();
	}
	else if (document.layers) {
		window.open (url,'designWin','height=800, left=100, location=0, menubar=0, resizable=1, scrollbars=1, status=0, titlebar=0, toolbar=0, top=100, width=600');
	}
}

function OpenMatrix(url) 
{
	if (screen.availHeight) {
		height = screen.availHeight-25;
		width = screen.availWidth-10;		
		openMatrix = window.open (url,'PopWin','height='+height+', left=0, location=0, menubar=0, resizable=1, scrollbars=0, status=0, titlebar=0, toolbar=0, top=0, width='+width);
		openMatrix.focus();
	}
	if (window.innerHeight) {
		maxHeight = ((window.innerHeight)-(height)/2)-15;
		maxWidth = ((window.innerWidth)-(width)/2);
		openMatrix = window.open (url,'PopWin','height='+height+', left='+maxWidth+', location=0, menubar=0, resizable=1, scrollbars=1, status=0, titlebar=0, toolbar=0, top='+maxHeight+', width='+width);
		openMatrix.focus();
	}
	else if (document.layers) {
		window.open (url,'PopWin','height=800, left=100, location=0, menubar=0, resizable=1, scrollbars=1, status=0, titlebar=0, toolbar=0, top=100, width=600');
	}
}

function PrintPage(doc)
{
	if( doc.getElementById('divContent')!=null )
	{
		var Footer = doc.getElementById('footer')==null ? '' : doc.getElementById('footer').innerHTML; 
		var Content = doc.getElementById('divContent').innerHTML;
		var WinTitle = doc.title;
	
		OpenWin("",640,480);
				
		var head = 	'<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" '+
					'"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">' +
					'<html xmlns="http://www.w3.org/1999/xhtml">'+
					'<head><title>'+ WinTitle +'</title>' +
					'<link href="http://'+SrvDmn+'/Includes/style.common.css" rel="stylesheet" type="text/css" media="screen" />' +
					'<link href="http://'+SrvDmn+'/Includes/style.printer.css" rel="stylesheet" type="text/css" media="print" />' +
					'<style type="text/css">'+
					'html{ background:#fff; }'+
					'</style>'+
					'</head><body style="margin:5px;">';
		var closeHtml = '</body></html>';
		var Print = '<a href="javascript:;" onclick="self.print();" title="Print page">' +
					'<img src="http://'+SrvDmn+'/Images/Shared/Icon_Printer.jpg" alt="" width="20" height="16" border="0" align="top" />'+
					'Print Page</a>';
		var CloseWin = '<a href="javascript:;" onclick="self.close();" title="Close window">Close Window</a>';
		w.document.write(head);
		w.document.write(Logo);
		w.document.write('<div id="divHead">'+Print+' | '+CloseWin+'</div>');
		w.document.write('<div class="title">'+WinTitle+'</div>');
		w.document.write('<div id="divContent">'+Content+'</div>');
		w.document.write('<div id="footer" style="color:#333;width:auto;">'+Footer+'</div>');
		w.document.write('<div id="divFooter" style="font-size:10px;">'+Print+' | '+CloseWin+'</div>');
		w.document.write('<script language="javascript">self.print();</script>');
		w.document.write(closeHtml);
		w.document.close();
	}
}

function EmailPage(doc)
{
	/*"http://" + SrvDmn + */
	var url = "Send_Page.htm";
	OpenWin(url,640,480);
}

function setFont(size,div)
{
	if( document.getElementById(div)!=null )
	{
		var fsmin=10, fsmax=17; 
		var d = document.getElementById(div);
		var fs = d.style.fontSize;
		
		if( fs=="" && size=="14" ) fs = size+"px";

		if( fs=="" && size=="10" ) fs = size+"px";
		
		if( fs!="" && parseInt(fs)<=fsmax && parseInt(fs)>=fsmin )
		{
			if( size=="14" ) fs = parseInt(fs)<fsmax ?  parseInt(fs)+1 : parseInt(fs);
			if( size=="10" ) fs = parseInt(fs)>fsmin ? parseInt(fs)-1 : parseInt(fs);
			d.style.fontSize =  fs + "px";
		}
	}
}

function Search()
{
	var sFld = 'PAGES/';
	var regex = new RegExp(sFld,'gi');
	var cUrl = location.href;
	var searchPath = regex.test(cUrl) ? '' : sFld;
	document.form1.method = "get";
	//document.form1.action = "Search/SearchInHouse.asp";
	document.form1.action = searchPath+"search.asp";	
	document.form1.target = "_self";
	document.form1.submit();
}

var colInterval;
function collapseMenu()
{
	var menuCol = document.getElementById('menuCol');
	var contentCol = document.getElementById('contentCol');
	var wrapper = document.getElementById('wrapper');
	var expcol = document.getElementById('expcol');
	var expclpcol = document.getElementById('expclpcol');
	expclpcol.style.display = 'none';
	try{
		var d = 60, i = 15, bgX = 0;
		function collapseCol()
		{
			menuCol.style.overflow = 'hidden';
			var mColW = menuCol.clientWidth;
			var cColW = contentCol.clientWidth;
			var cMW = mColW-d, cCW = cColW+d, bgX = bgX-d;
			if( cMW<=d ){
				menuCol.style.display = 'none';
				expcol.style.display = 'block';
				bgX = -192, cMW = 0, cCW = 930;				
				clearInterval( colInterval );
			}
			menuCol.style.width = cMW+'px';
			contentCol.style.width = cCW+'px';
			wrapper.style.background = '#fff url(../Images/Shared/bg_submenuCol.jpg) ' +
										bgX + 'px 0 repeat-y'; 
		}
		colInterval = setInterval( collapseCol, i );
	} catch(e) {
		menuCol.style.display = 'none';
		contentCol.style.width = '930px';
		wrapper.style.background = wrapperBg;
		expcol.style.display = 'block';
	}
}

function expandMenu()
{
	var menuCol = document.getElementById('menuCol');
	var contentCol = document.getElementById('contentCol');
	var wrapper = document.getElementById('wrapper');
	var expcol = document.getElementById('expcol');
	var expclpcol = document.getElementById('expclpcol');
	menuCol.style.width = '0';
	expcol.style.display = 'none';
	menuCol.style.display = 'block';
	try{
		var d = 60, i = 15, bgX = -192;
		function expandCol()
		{
			menuCol.style.overflow = '';
			var mColW = parseInt(menuCol.style.width);
			var cColW = contentCol.clientWidth;
			var cMW = mColW+d, cCW = cColW-d, bgX = bgX+d;
			if( cMW>(190-d) ){
				menuCol.style.display = 'block';
				expclpcol.style.display = 'block';
				bgX = 0, cMW = 190, cCW = 760;
				clearInterval( colInterval );
			}			
			menuCol.style.width = cMW+'px';
			contentCol.style.width = cCW+'px';
			wrapper.style.background = '#fff url(../Images/Shared/bg_submenuCol.jpg) ' +
										bgX + 'px 0 repeat-y';			
		}
		colInterval = setInterval( expandCol, i );
	} catch(e) {
		menuCol.style.display = 'block';
		contentCol.style.width = '760px';
		wrapper.style.background = '#fff url(../Images/Shared/bg_submenuCol.jpg) 0 0 repeat-y';
		expcol.style.display = 'none';	
	}	
}

String.prototype.vbreplace = function (as_rex,as_out)
{
	var ls_rex, as;	
	ls_rex = new RegExp(as_rex,"g");
	as = this.replace(ls_rex, as_out);
	return as;
}


// Js general dream fns

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 MM_validateForm() { //v4.0
  var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
  for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args[i]);
    if (val) { nm=val.name; if ((val=val.value)!="") {
      if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
        if (p<1 || p==(val.length-1)) errors+='- '+nm+' must contain an e-mail address.\n';
      } else if (test!='R') { num = parseFloat(val);
        if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';
        if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
          min=test.substring(8,p); max=test.substring(p+1);
          if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
    } } } else if (test.charAt(0) == 'R') errors += '- '+nm+' is required.\n'; }
  } if (errors) alert('The following error(s) occurred:\n'+errors);
  document.MM_returnValue = (errors == '');
}



/* */
var rgx = new RegExp('cis','gi');
var SrvDmn = rgx.test(document.domain) ? document.domain + "/CIS_info/SBMOffshoreV2" : document.domain;
var Logo = 	'<a href="http://'+SrvDmn+'" target="_blank" alt="">'+
			'<img src="http://'+SrvDmn+
			'/Images/Shared/sbmo_logo.jpg" border="0" alt="SBM Offshore N.V." /></a>';
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
//v1.0
//Copyright 2006 Adobe Systems, Inc. All rights reserved.
function AC_AddExtension(src, ext)
{
  if (src.indexOf('?') != -1)
    return src.replace(/\?/, ext+'?'); 
  else
    return src + ext;
}

function AC_Generateobj(objAttrs, params, embedAttrs) 
{ 
  var str = '<object ';
  for (var i in objAttrs)
    str += i + '="' + objAttrs[i] + '" ';
  str += '>';
  for (var i in params)
    str += '<param name="' + i + '" value="' + params[i] + '" /> ';
  str += '<embed ';
  for (var i in embedAttrs)
    str += i + '="' + embedAttrs[i] + '" ';
  str += ' ></embed></object>';

  document.write(str);
}

function AC_FL_RunContent(){
  var ret = 
    AC_GetArgs
    (  arguments, ".swf", "movie", "clsid:d27cdb6e-ae6d-11cf-96b8-444553540000"
     , "application/x-shockwave-flash"
    );
  AC_Generateobj(ret.objAttrs, ret.params, ret.embedAttrs);
}

function AC_SW_RunContent(){
  var ret = 
    AC_GetArgs
    (  arguments, ".dcr", "src", "clsid:166B1BCA-3F9C-11CF-8075-444553540000"
     , null
    );
  AC_Generateobj(ret.objAttrs, ret.params, ret.embedAttrs);
}

function AC_GetArgs(args, ext, srcParamName, classid, mimeType){
  var ret = new Object();
  ret.embedAttrs = new Object();
  ret.params = new Object();
  ret.objAttrs = new Object();
  for (var i=0; i < args.length; i=i+2){
    var currArg = args[i].toLowerCase();    

    switch (currArg){	
      case "classid":
        break;
      case "pluginspage":
        ret.embedAttrs[args[i]] = args[i+1];
        break;
      case "src":
      case "movie":	
        args[i+1] = AC_AddExtension(args[i+1], ext);
        ret.embedAttrs["src"] = args[i+1];
        ret.params[srcParamName] = args[i+1];
        break;
      case "onafterupdate":
      case "onbeforeupdate":
      case "onblur":
      case "oncellchange":
      case "onclick":
      case "ondblClick":
      case "ondrag":
      case "ondragend":
      case "ondragenter":
      case "ondragleave":
      case "ondragover":
      case "ondrop":
      case "onfinish":
      case "onfocus":
      case "onhelp":
      case "onmousedown":
      case "onmouseup":
      case "onmouseover":
      case "onmousemove":
      case "onmouseout":
      case "onkeypress":
      case "onkeydown":
      case "onkeyup":
      case "onload":
      case "onlosecapture":
      case "onpropertychange":
      case "onreadystatechange":
      case "onrowsdelete":
      case "onrowenter":
      case "onrowexit":
      case "onrowsinserted":
      case "onstart":
      case "onscroll":
      case "onbeforeeditfocus":
      case "onactivate":
      case "onbeforedeactivate":
      case "ondeactivate":
      case "type":
      case "codebase":
        ret.objAttrs[args[i]] = args[i+1];
        break;
      case "width":
      case "height":
      case "align":
      case "vspace": 
      case "hspace":
      case "class":
      case "title":
      case "accesskey":
      case "name":
      case "id":
      case "tabindex":
        ret.embedAttrs[args[i]] = ret.objAttrs[args[i]] = args[i+1];
        break;
      default:
        ret.embedAttrs[args[i]] = ret.params[args[i]] = args[i+1];
    }
  }
  ret.objAttrs["classid"] = classid;
  if (mimeType) ret.embedAttrs["type"] = mimeType;
  return ret;
}

