/*
	FILE : pulcra.js
	Author : Gael Pegliasco
	
	Description : 
	  Javascript functions used to allow or disallow web surf
	  and other WebCP functionnalities.
*/


var webCPPopupName         = 'WebCPCommandWindow';
var webCPWindowWebSurfName = 'WebCPWindowWebSurf';
//var timerWebCP     = '';
var doNotBlockWebSurf = false;


/*
  Function : disallowWebSurf
  
  Description :
    DIS-Allow the surf on unauthorized urls.
    
    Actually a new window is opened and it called the url http://bloquerinternet.ese
    Then call the 'about:blank' in order to hide the display of "bloquer internet"
    This only works with WebCP navigator.
    
    When calling this function, the only allowed urls are taken from the windows registry key 
    HKEY_LOCAL_MACHINE\SOFTWARE\Devaxe\WebCP\Intranets
    Do not forget to include the url of the webserver in this list...
      
  ATTENTION : webCPPopupName correspond au nom de l iframe
    
*/
function disallowWebSurf() {

	try {
		if( ! doNotBlockWebSurf ) {
		    //clearTimeout( timerWebCP );
			var new_window = window.open('http://bloquerinternet.ese', webCPPopupName, '' ); //, 'width=100,height=100,top=9999,left=9999,alwaysLowered=yes' );
			new_window     = window.open('about:blank', webCPPopupName, '' ); //, 'width=100,height=100,top=9999,left=9999,alwaysLowered=yes' );
			
			// Also close websurf window if we came from this window
			var referrer = document.referrer;
						
			if( referrer ) {
			
			    if( referrer.indexOf( "Global=4" ) != -1 || referrer.indexOf( "GlobalTreeNode=InternetLibre" ) != -1 ) {      
			
			       new_window = window.open( 'about:blank', webCPWindowWebSurfName, 'left=1600,top=0,width=1,height=1' );
			       if( new_window != null )
			           new_window.close();
			       
			       
			    }
			}
			
		}
	}
	catch( except ){
		alert( except.message );
	}
}
		
/*
  Function : allowWebSurf
  
  Description :
    Allow to surf on any web url.
    
    Actually a new window is opened and it called the url http://autoriserinternet.ese
    Then call the 'about:blank' in order to hide the display of "autoriser internet"
    This only works with WebCP navigator.
    
        
    ATTENTION : webCPPopupName correspond au nom de l iframe
    
*/
function allowWebSurf() {

		
	try {
     	 //clearTimeout( timerWebCP );
	     
	     //var new_window = window.open( 'http://autoriserinternet.ese', webCPPopupName, '' ); // 'width=100,height=100,top=9999,left=9999,alwaysLowered=yes'
	     //new_window = window.open( 'about:blank', webCPPopupName, 'width=100,height=100'   ); // 'width=100,height=100,top=9999,left=9999,alwaysLowered=yes'
	     if (window.WebCPCommandWindow!=null)
	     {
	     	window.WebCPCommandWindow.location.href='http://autoriserinternet.ese';
	     }
	}
	catch( except ){
		alert( except.message );
	}		
}

function closeIEWindows( windowName ) {

	try {
			var new_window = window.open( 'http://fermeturefenetre.ese', windowName, '' ); //, 'width=100,height=100,top=9999,left=9999,alwaysLowered=yes' );
			new_window     = window.open( 'about:blank', windowName, '' ); //, 'width=100,height=100,top=9999,left=9999,alwaysLowered=yes' );
		
	}
	catch( except ){
		alert( except.message );
	}
}

// 
// DISALLOW WEB SURF BY DEFAULT ON ALL PAGES
//
// This name must be the same as the one in style/portal-page.xsl
// disallowWebSurf( webCPPopupName );




