﻿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();

