	function focusControl( ctrl ) {
		cmdFocus = "getMainForm().elements['"+ ctrl +"'].focus();";
		setTimeout( cmdFocus, 100 );
		return true;
	}
	/* Vecchi nomi, da eliminare */
	function validateMethod( obj ) {
		return validateForm( obj );
	}	
	
	function openMethod( obj, method ) { openerMethod( obj, method ); }

	function getForm( obj ) {
		if( obj.elements != undefined ) {
			form = obj;
		} else if( obj.form != undefined ) {
			form = obj.form;
		} else if( document.forms[ obj ] != undefined ) {
			form = document.forms[ obj ];
		} else {
			form = document.getElementById( obj );
			if (form == undefined || form.elements == undefined){
				alert( 'L\'oggetto e\' nullo o non e\' un form: '+obj );
			}
		}
		return form;
	}

    function callMethod( obj, method ) {
		if ( popupWindow != null && !popupWindow.closed ){
			popupWindow.close();
		}
		showHourGlass();
		executeMethodCall( obj, method );
    }

	function callMethodNoRefresh( obj, method ) {
		if ( popupWindow != null && !popupWindow.closed ){
			popupWindow.close();
	}
		executePopUpMethodCall( obj, method );
		form.reset();
	}

	function callOpenerMethod( obj, method ) {
		if ( popupWindow != null && !popupWindow.closed ){
			popupWindow.close();
		}
		showHourGlass();
		executeOpenerMethodCall( obj, method );
	}

	function beforeMethodCall( obj, method ) {
		if( method == undefined ) {
			form = getMainForm();
			method = obj;
		} else {
			form = getForm( obj );
		}

		if ( !form.isCalled() ) {
			return false;
		}
		result = true;
		if ( form.metodo==undefined ){
			createFormProperty( form, 'hidden', 'metodo', method );
		}else{
			form.metodo.value = method;
		}
		return result;
	}
	
	function executeMethodCall( obj, method ) {
		var result = beforeMethodCall( obj, method );
		if( result == true) {
			form.call();
		}
		return result;
	}

	function executePopUpMethodCall( obj, method ) {
		var result = beforeMethodCall( obj, method );
		if( result == true) {
			form.popUpCall();
		}
		return result;
	}

	function executeOpenerMethodCall( obj, method ) {
		var result = beforeMethodCall( obj, method );
		if( result == true) {
			form.openerCall();
		}
		return result;
	}

	function showHourGlass(){
		if ( _isIE() ){
			document.body.style.cursor="url('images/hourglas.ani')";
		}else{
			document.body.style.cursor='wait';
		}
	}

	function hideHourGlass(){
		document.body.style.cursor='default';
	}
	

	function validateForm( obj, nameFunction ) {
		if(obj == undefined){
			obj = getMainForm();
		}
		form = getForm( obj );
		
		if ( !form.isCalled() ) {
			return false;
		}
		
		if ( nameFunction != undefined ) {
			functionObj = eval( nameFunction );
			return functionObj( form );
		}

		if ( Validation != undefined ) {
			return Validation.validateForm( obj );
		}	
	}

	function confirmMethod( obj, method, operation, validate ) {
		form = getForm( obj );
		if ( !form.isCalled() ) {
			return false;
		}
		
		if( obj == undefined ) {
			obj = null;
		}
		
		if( operation == undefined ) {
			operation = "";
		}
		
		if( validate == undefined ) {
		  	validate = 'false';
		}
		
		result = true;
		
		if( validate == 'true' ) {
			result = validateMethod ( obj );
        }
		
		if( result == true && confirm( "Confermi l'operazione di " + operation + " ?" ) ) {
			result = callMethod( obj, method );
		}
		
		return result;
	}

	function confirmOperation( operation ) {
		 return confirm( "Confermi l'operazione di " + operation + " ?" );
	}

	function openerMethod( obj, method ) {				
		form = getForm( obj );
		
		if ( form.isCalled() ) {
			form.target = opener.name; 
			callOpenerMethod( obj, method );
			self.close();
		}
	}

    function openHelpPopup( helpTopic ) {
		//var helpUrl = '/sun/help/helpHome.html';
		var helpUrl = './helpViewlet/helpHome.html';
		if ( helpTopic != '' ) {
			helpTopic = helpTopic.replace(/[\.]/g,"/");
			//helpUrl = '/sun/help/' + helpTopic + '.html';
			helpUrl = './helpViewlet/' + helpTopic + '.html';
		}
		var windowLeft = ( screen.width - 750 ) / 2;
	    var windowTop = ( screen.height - 545 ) / 2;
		var attributes = 'resizable=no,status=no,toolbar=no,menubar=no,location=no,dependent=yes,top=' + windowTop + ',left=' + windowLeft + ',height=545,width=750';
		popupHelpWindow = window.open( helpUrl, 'help', attributes );
		if ( window.focus ) {
			popupHelpWindow.focus();
		}

		return popupHelpWindow;
	}

	function openPopup( url, name, height, width ) {
		if( height == undefined ) {
			height = 600;
		}
		
		if( width == undefined ) {
			width = 800;
		}
		
		var windowLeft = ( screen.width - width ) / 2;
	    var windowTop = ( screen.height - height ) / 2;
		var attributes = 'resizable=yes,status=no,toolbar=no,menubar=no,location=no,dependent=yes,top=' + windowTop + ',left=' + windowLeft + ',height=' + height + ',width=' + width;
		popupWindow = window.open( url, name, attributes );
		
		if ( window.focus ) {
			popupWindow.focus();
		}
		return popupWindow;	
	}

	var popupWindow = null;
	function popupMethod( obj, method, height, width ) {
		form = getForm( obj );
		if ( popupWindow != null && !popupWindow.closed ){
			popupWindow.close();
		}
		popupWindow = openPopup( 'about:blank', 'popupWindow', height, width );
		
		oldTarget = form.target;
		form.target = popupWindow.name;
		
		executePopUpMethodCall( obj, method );
		form.reset();
		
		form.target = oldTarget;
		return popupWindow;
	}

// Trim whitespace from left and right sides of s.
    function trim( s ) {
        return s.replace( /^\s*/, "" ).replace( /\s*$/, "" );
    }   
    
    function parseBool( val ) {
    	return ( val != null && ( val == '1' || val == 'true' || val == 'yes' || val == 'on' ) ) ? true : false;
    }
    
     function getBaseName( name ) {
    	    	
    	if( name != '' ) {
    		var index = name.indexOf('__');
    		if( index >= 0 ) {    		
    			return name.substring(0, index);
    		}
    	}
    	
    	return name;
    }    
    
	function getPageCoords ( obj ) {
		var coords = {x: 0, y: 0};
		while ( obj ) {
			coords.x += obj.offsetLeft;
			coords.y += obj.offsetTop;
			obj = obj.offsetParent;
			}
		return coords;
	}

	// Verifica se si sta utilizzando Netscape
	function _isNetscape() {
		if(navigator.appName.indexOf("Netscape") != -1)
			return true;
		else
			return false;
	}
	// Verifica se si sta utilizzando internet explorer
	function _isIE() {
		if( navigator.appName.indexOf( "Microsoft" ) != -1 )
			return true;
		else
			return false;
	}
	// Funzione che crea un campo HTML dinamicamente
	function createFormProperty(formName,_type,_name,_value){
		_form = getForm( formName );
		if (_form!=undefined){
			if (!_isNetscape()) {
				// Funziona per Explorer
				var newInput = document.createElement("<INPUT TYPE='"+_type+"' NAME='"+_name+"' PROPERTY='"+_form.name+"' VALUE=''>")
				_form.insertBefore(newInput);
			}
			else {
				// Funziona su Firefox
				var input = document.createElement('input');
				input.setAttribute('type',_type);
				input.setAttribute('name', _name);
				input.setAttribute('property', _form.name);
				_form.appendChild(input);
			}
			var _formField=eval(_form[_name]);
			_formField.value=_value;
		}
		return true;	
	}
	
	// Funzione che imposta il valore ad un campo HTML
	// Se il campo non esiste viene creato dinamicamente
	function setFormProperty( form,_type,_name,_value ){
		var formField=eval( form[_name] );
		if ( formField==undefined ){
			createFormProperty( form, _type, _name, _value );
		}else{
			formField.value = _value;
		}

	}

	function checkDirty( form ){
		if ( form == undefined ) {
			form = getMainForm();
		}
		dirty = getForm( form ).isDirty();
		if( dirty ) {
			ok = confirm( "Abbandonare le modifiche effettuate?" );
			return ok;
		}
		return true;
	}
	function checkNavigation( url ) {
		ok = true;
		if( context.hasBack() ) {
			ok = confirm( "Interrompere l'operazione corrente?" );
		}
		if( ok ) {
			document.location.href = url;
		}
	}
//ie = (document.all)?true:false ;
//nn = (document.layers)?true:false ;
	
   function panelPatch(tabName){
	if(tabName==null)
	   tabName = 'TabGenerale';
    var test = document.getElementById(tabName);
	if(navigator.appName=="Netscape" && test!=null)
	   focusSimulate(test);
	}   
	
	
   function focusSimulate(test){
     test.focus();
     test.blur();
    }


function showKey( e ) {
	// Disabilitazione tasti Canc - F5 - F11
	if (_isIE() ){ // Explorer
		var code = event.keyCode;
		var elType = event.srcElement.type;
		if (	( code == 8 && ( elType == undefined || elType == 'image' || event.srcElement.readOnly == true ) ) ||
				( code == 116 || code == 122 )
		    ){
	        event.keyCode = 0;
	        event.cancelBubble = true;
	        event.returnValue = false;
	    }
	}else{ // Mozilla
		var code = e.which;
		var elType = e.target.type;
	  	if (
	  		( code == 8 && ( elType == undefined || elType == 'image' || e.target.readOnly == true ) ) ||
	  		( code == 116 || code == 122 )
	  	   )
	  	{
          return false;
	  	}
	}
}

// Disabilitazione Tasto Destro del Mouse
var _keymessage="";

function clickIE() {
	if (document.all) {
		(_keymessage);
		return false;
	}
}

function clickNS(e) {
	if ( document.layers || ( document.getElementById && !document.all ) ) {
		if (e.which==2||e.which==3) {
			(_keymessage);
			return false;
		}
	 }
}

 
 function checkSave(msg){
 var check = confirm(msg);
 if(!check){
     return false;
  } 
 }
 
 function checkSelection(msg){
  var elementi = document.forms[0].elements;
  var continua = true;
  for (var index = 0; (index < elementi.length && continua); index++) {
		var obj = elementi[ index ];
		if(obj.type == 'checkbox' && obj.checked){
			var check = confirm(msg);
			continua = false;
				if(!check){
				    return false;
				} 
		}
  }
  
  
 }
	 
 
 
 function callAction(actionName, targetName) {
	var f = document.createElement("form");
	
	document.body.appendChild(f);
	if (targetName) { 
		f.target=targetName; 
	}	
	f.action = actionName;
	f.method = "POST"
	
	f.submit();
} 

