
function goToMainPage( appl, form, page, params ) 
{		
	//alert('GoToMainPage - START');
			
	var url;
	//url = '/' + page;
	url = page;
	if ( appl != '' ) { url += '?IDAppl=' + appl; }
	if ( form != '' ) { url += '&IDForm=' + form; }
	if ( typeof(params) != 'undefined' ) { 
	  if ( params != '' ) { 
	    url += '&Params=' + params; 
	  }
	}

	var win;
	
	//alert(window.name);
	
  if(( window.name.search('SIPALWEB') >= 0 && window.name.length == 8 ) || ( window.name.search('SIPALWEB') < 0 ))
	{
		if ( window.name.search('SIPALWEB') < 0 )
		{
			window.name = 'SIPALWEB';												
		}
		window.location.href = url;
		//alert(window.name);
	}
	else
	{
		win = window.open( '', 'SIPALWEB' ); 
		win.location.href = url;
		closeWin(window); 
		win.focus();
	}				    
}	


function goToSubPage( appl, form, user, session, params ) 
{	
	if ( appl == '' ) { return false; }
	
	var url;			
	url = appl + '/Index.aspx?SessionID=' + session;
	if ( form != '' ) { url += '&IDForm=' + form; }
	if ( typeof(params) != 'undefined' ) { 
		if ( params != '' ) { 
			url += '&Params=' + params; 
		}
	}
	
	var win;
	
  if( window.name.search('SIPALWEB_') >= 0 )
	{
		window.location.href = url;
	}
	else
	{
		openApplWin(url, 'SIPALWEB_' + user + '_' + appl); 
		closeWin(window); 
		//win.focus();
	}				    
}	

function closeWin( win ) {
		
	//alert('closewin');
	//alert(win.opener);							
	
  if( win.opener )		// if( win.opener && !win.opener.closed )
	{ 
		win.close(); 
	}
	else				
	{
		if( win.history.length > 0) win.history.back();
		else win.location.href = 'about:blank';
	}			
}	

function openApplWin(url, target)
{
	var wide = window.screen.availWidth;
	var high = window.screen.availHeight;
	//var prop = "toolbar=no,location=no,menubar=no,status=no,resizable=yes,scrollbars=yes";		
	var prop = "toolbar=no,location=no,menubar=no,status=yes,resizable=yes,scrollbars=yes";		
	
	//Apro una nuova window, la massimizzo e imposto l'url
	var win = window.open( "", target, prop );
	win.moveTo( 0, 0 );
	win.resizeTo( wide, high );
	win.location = url;
	
	//return win;
}

function menuGotoAppl( appl, form, params )
{
	var id = document.all['__SessionID'];

	var sep = '?';
	var url = 'Index.aspx';
	if( appl != '' ) url = '../' + appl + '/' + url;
	if( id ) { url += sep + 'SessionID=' + id.value; sep = '&'; }
	if( form != '' ) url += sep + 'IDForm=' + form; 
	if( typeof(params) != 'undefined' ) {
		if ( params != '' ) { 
			url += sep + 'Params=' + params; 
		}
	}
	
	window.location.href = url;
}

function checkLoginEnter( event )
{ 	
	var NS4 = (document.layers) ? true : false;
	
	var ok = true; 
	var code = 0;
	var usr = document.all('dfUsr');
	var pwd = document.all('dfPwd');

	if( !usr || !pwd ) 
	{
		event.returnValue = false;
		return;
	}
	
	if( !event ) { code = 13;	}
	else {
		if( NS4 ) code = event.which;
		else code = event.keyCode;
	}
	//alert( code );
	
//	if( code == 27 ) 
//	{ 
//		//window.close();
//		usr.value = 'pollo'; 
//		pwd.value = 'pollo';
//		code = 13; 
//	}
	
	if( code == 13 ) 
	{	
		if( event ) event.returnValue = false;
	
		if( typeof(Page_ClientValidate) == 'function' ) ok = Page_ClientValidate(); 
		if( ok ) 
		{ 
    	document.body.style.cursor = 'wait';		
			__doPostBack('ulLogon',''); 
		}
		else 
		{
			if( !pwd.value ) pwd.focus();
			if( !usr.value ) usr.focus();
		}
	}
}

//
