function hideObj( idObj )
{
	obj = document.getElementById(idObj);
	if (obj)
	{
		obj.style.display = 'none';
	}
}
  
function showObj(idObj, use_inline )
{
	obj = document.getElementById(idObj);
	if (obj)
	{
		if ( use_inline )
		{
			obj.style.display = 'inline';
		}
		else
		{
			obj.style.display = 'block';
		}
	}
}

/***** START: Functions for realClock ******/
var objClock;
function startClock( idObjHour, idObjMin, idObjSec )
{
	objClock = new realClock;
	objClock.start( idObjHour, idObjMin, idObjSec );
}
function stopClock()
{
	if (objClock)
	{
		objClock.stop();
	}
}
/***** END: Functions for realClock ******/


/***** START: Functions for close errors and msg popup ******/
function timeoutError()
{
	idTimeout1 = setTimeout("hideObj('ErrorMsg')",10000);
	idTimeout2 = setTimeout("hideObj('StandardMsg')",10000);
}
/***** END: Functions for close errors and msg popup ******/


/***** START: functions to start on load ******/
function bodyOnLoad()
{
	timeoutError();
	startClock('clockHour','clockMin','clockSec');
}
/***** ENDART: functions to start on load ******/


/* IMPORTANTE per la LOGIN 
*  Converte in MD5 la password lato client per inviarla già criptata	
*/
function doLogin(theForm)
{

	if (theForm.username.value == '' || theForm.cpwd.value == '')
	{
		alert('Inserire user e password.');
		return false;
	}
	pwdhash = hex_md5(theForm.cpwd.value);
	theForm.cpwd.value = '';
	theForm.hpwd.value = pwdhash;
	return true;
}

/* Gestione elementi & AJAX */
function clearSelect( oSelect, disable ) {
	if ( oSelect ) {
		n_options = oSelect.options.length;
		for(var i=n_options-1; i>=0; i--) {
			oSelect.options[i] = null;
		}
	    // oSelect.disabled = true;
		oSelect.disabled = disable;
	}
}

function fillSelect( oSelect, oList, insert_default_option, first_option_label, first_option_value ) {
	
	if ( oSelect && oList ) {
		
		if ( insert_default_option ) {
			oSelect.options[0] = new Option(first_option_label, first_option_value);
		}
		
		for(var i=0; i<oList.length; i++) {
			var value = oList[i].id;
			var label = oList[i].name;			
			//alert('value = ' + value + ' - label = ' + label);
			oSelect.options[oSelect.options.length] = new Option(label, value);
			/*if(selected == true || selected == 'true')
			{
				oSelect[oSelect.options.length-1].selected = true;
			}*/
		}
	}
	
}


function dump_arr( arr )
{
	out = "Object Dump:\n";
	for ( var item in arr )
	{
		var type = typeof arr[item];
		switch(type) {
			case 'undefined':
			case 'function':
			case 'unknown': continue;
			case 'boolean': continue;
		}

		if ( type == 'object' )
		{
			out = out + "[" + item + "] = ...\n\t" + dump_arr( arr[item] );
		}
		else
		{
			out = out + "[" + item + "] = " + arr[item] + "\n";
		}
	}
	//alert ( out );
	return out;
}

function print_r( arr )
{
	out = dump_arr( arr );
	if ( out )
	{
		alert ( out );
	}
}

function getNewId()
{
	myDate = new Date();
	uniqueId = myDate.getTime();
	return uniqueId;
}
	  
function openPopUp( url,w,h )
{    
   var l = Math.floor((screen.width-w)/2);
   var t = Math.floor((screen.height-h)/2);
   
   var popup = window.open(url,"NewPopUp","width=" + w + ",height=" + h + ",top=" + t + ",left=" + l + ", status=no, menubar=no, toolbar=no, scrollbars=yes"); 
   popup.focus();
   
}

function checkData(id_field , allow_chars )
{
	var checkOK  = allow_chars; //"0123456789-,";
	var checkStr = id_field.value;

	for (i = 0;  i < checkStr.length;  i++)
	{
		ch = checkStr.charAt(i);
		for (j = 0;  j < checkOK.length;  j++)
		{
			if (ch == checkOK.charAt(j))
			{
				break;
			}
			if (j == checkOK.length-1)
			{
				return false;
				break;
			}
		}
	}
	
	return true;   
}