﻿function addOnLoadFunction( newOnLoadFunction, specificWindow ) 
{ 
    var win = ( specificWindow || window );
    var origOnLoadFunction = win.onload; 
    if( typeof win.onload != 'function' )
    { 
        win.onload = newOnLoadFunction; 
    }
    else
    { 
        win.onload = function() 
        { 
            if( origOnLoadFunction )
            { 
                origOnLoadFunction(); 
            } 
            newOnLoadFunction(); 
        } 
    } 
} 
function addOnUnloadFunction( newOnUnloadFunction, specificWindow ) 
{ 
    var win = ( specificWindow || window );
    var origOnUnloadFunction = win.onunload; 
    if( typeof win.onunload != 'function' )
    { 
        win.onunload = newOnUnloadFunction; 
    }
    else
    { 
        win.onunload = function() 
        { 
            if( origOnUnloadFunction )
            { 
                origOnUnloadFunction(); 
            } 
            newOnUnloadFunction(); 
        } 
    } 
} 
function LoadFunctions() 
{
}
addOnLoadFunction( LoadFunctions );
function checkEnterKey( e, cid )
{
    if( e.keyCode == 13 )
    {
        //__doPostBack( cid, '' );
        document.getElementById( cid ).click();
        return false;
    }
    else
    {
        return true;
    }
}
function MM_openBrWindow(theURL,winName,features) 
{
  if(typeof(_hbDownload)=='function')
  {
    _hbDownload(theURL);
  }
  window.open(theURL,winName,features); 
}
function toggleLanguage()
{
 var currentURL=document.URL;
 if (currentURL.indexOf('/eng')>=0)
 {
  document.location=currentURL.replace('/eng','/fr');
 } 
 else if (currentURL.indexOf('/fr')>=0)
 {
  document.location=currentURL.replace('/fr','/eng');
 }
 else if (currentURL.indexOf('lang=en')>=0)
 {
  document.location=currentURL.replace('lang=en','lang=fr');
 }
 else if (currentURL.indexOf('lang=fr')>=0)
 {
  document.location=currentURL.replace('lang=fr','lang=en');
 }
 else if (currentURL.indexOf('/petroen')>=0) 
 { 
  document.location=currentURL.replace('/petroen','/petrofr'); 
 } 
 else if (currentURL.indexOf('/petrofr')>=0) 
 { 
  document.location=currentURL.replace('/petrofr','/petroen'); 
 } 
 else if (typeof(opplanguage)=="function")
 {
  opplanguage();
 }
}
function forceDownload( p_url )
{
 __doPostBack( "FORCE_DOWNLOAD", p_url );
 return false;
}
var GLOBALJS_popUpWin=0;
function popUpWindow( URLStr, left, top, width, height, windowName )
{
    if( GLOBALJS_popUpWin )
    {
        if( !GLOBALJS_popUpWin.closed )
        {
            GLOBALJS_popUpWin.close();
        }
    }
    GLOBALJS_popUpWin = open(URLStr, ( windowName || "popUpWin" ), 'toolbar=no,location=no,directories=no,status=no,menubar=yes,scrollbars=yes,resizable=no,copyhistory=yes,width='+width+',height='+height+',left='+left+', top='+top+',screenX='+left+',screenY='+top+'');
    return GLOBALJS_popUpWin;
}
function appendStyleSheet( cssPath )
{
    var head = document.getElementsByTagName( "head" )[0];
    var element = document.createElement( "link" );
    element["rel"]  = "stylesheet";
    element["type"] = "text/css";
    element["href"] = cssPath;
    head.appendChild( element );
}
function readCookie( name ) {
    var start = document.cookie.indexOf( name + "=" );
    var len = start + name.length + 1;
    if ( ( !start ) && ( name != document.cookie.substring( 0, name.length ) ) ) {
        return null;
    }
    if ( start == -1 ) return null;
    var end = document.cookie.indexOf( ';', len );
    if ( end == -1 ) end = document.cookie.length;
    return unescape( document.cookie.substring( len, end ) );
}
function createCookie( name, value, expires, path, domain, secure ) {
    var today = new Date();
    today.setTime( today.getTime() );
    if ( expires ) {
        expires = expires * 1000 * 60 * 60 * 24;
    }
    var expires_date = new Date( today.getTime() + (expires) );
    document.cookie = name+'='+escape( value ) +
        ( ( expires ) ? ';expires='+expires_date.toGMTString() : '' ) + //expires.toGMTString()
        ( ( path ) ? ';path=' + path : '' ) +
        ( ( domain ) ? ';domain=' + domain : '' ) +
        ( ( secure ) ? ';secure' : '' );
}
function deleteCookie( name, path, domain ) {
    if ( getCookie( name ) ) document.cookie = name + '=' +
            ( ( path ) ? ';path=' + path : '') +
            ( ( domain ) ? ';domain=' + domain : '' ) +
            ';expires=Thu, 01-Jan-1970 00:00:01 GMT';
}
function GlobalEvent( preventDefaultBehaviour )
{
 GlobalEvent.c_event = null;
 GlobalEvent.eventHandler = function( objEvent ) 
 {
  GlobalEvent.c_event = ( objEvent ? objEvent : window.event );        
 };
 GlobalEvent.attachEvent = function( obj, eventType, callFunction )
 {
  var success = false;
  if( obj.addEventListener )
  {
   obj.addEventListener( eventType, callFunction, true );
   success = true;
  }
  else if( obj.attachEvent )
  {
   success = obj.attachEvent( "on" + eventType, callFunction );
  }
  return success;
 }
 GlobalEvent.event = function()
 {
  return( window.event ? window.event : GlobalEvent.c_event );
 }
 GlobalEvent.eventTarget = function()
 {
  var e = GlobalEvent.event();
  var target = null;  
  if( e.target )
  {
   target = e.target;
  }
  else if( e.srcElement )
  {
   target = e.srcElement;
  }
  if( target.nodeType == 3 ) // safari
  {
   target = target.parentNode;
  }
  return target;        
 }
 var tagPattern = /<\/?[^>]+>/gi;
 GlobalEvent.innerText = function( element )
 {
  return (
   element ?
   (
    element.innerText ?
    element.innerText :
    element.innerHTML.replace( tagPattern, "" )
   ) :
   ""
  );
 }
 GlobalEvent.parentWithAttribute = function( element, attribute )
 {
  var returnValue = element;
  while( !returnValue.getAttribute( attribute ) && returnValue.parentNode )
  {
   returnValue = returnValue.parentNode;
  }
  return returnValue;
 }
 GlobalEvent.parentWithOnclickAttribute = function( element )
 {
  return GlobalEvent.parentWithAttribute( element, "onclick" );
 }
 if( !preventDefaultBehaviour )
 {
  GlobalEvent.attachEvent( document, "click", GlobalEvent.eventHandler );
 }
}
GlobalEvent();
function openWindow(url){
 MM_openBrWindow(url,'externalLink','toolbar=yes,location=yes,menubar=yes,scrollbars=yes,resizable=yes,status=yes,width=650,height=450,top=10,left=10');
}

function P7_autoLayers() { //v1.4
 var g,b,k,f,args=P7_autoLayers.arguments;a=parseInt(args[0]);if(isNaN(a))a=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.visibility="hidden";}}for(k=1;k<args.length;k++){
 if((g=MM_findObj(args[k]))!=null){b=(document.layers)?g:g.style;b.visibility="visible";f=false;
 for(var j=0;j<p7c[a].length;j++){if(args[k]==p7c[a][j]) {f=true;}}
 if(!f){p7c[a][p7c[a].length++]=args[k];}}}
}
function ReDoIt() { //v1.2
 if(document.layers) {MM_reloadPage(false);}
}
function MM_showHideLayers() { //v3.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  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_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_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_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 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);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}
function MM_reloadPage(init) {  
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
function OpenNewWindow(pdfFile)
{
 MM_openBrWindow(pdfFile,'pdfwindow','scrollbars=yes,resizable=yes,width=650,height=450,top=0px,left=0px');
}
function TWnewWindow(imageName,imageWidth,imageHeight,alt) {
var posLeft=(screen.width)?(screen.width-imageWidth)/2:100;
var posTop=(screen.height)?(screen.height-imageHeight)/2:100;
newWindow = window.open("","newWindow","width="+imageWidth+",height="+imageHeight+",left="+posLeft+",top="+posTop);
newWindow.document.open();
newWindow.document.write('<ht'+'ml><tit'+'le>'+alt+'</tit'+'le><bo'+'dy bgcolor="#FFFFFF" leftmargin="0" topmargin="0" marginheight="0" marginwidth="0" onBlur="self.close()">'); 
newWindow.document.write('<a href=javascript:self.close()><img src='+imageName+' border=0 width='+imageWidth+' height='+imageHeight+' alt=\"'+alt+'\"></a>'); 
newWindow.document.write('</bo'+'dy></ht'+'ml>');
newWindow.document.close();
newWindow.focus();
}
