
var OverLayer;
//OverLayer = new SMOverLayer();

function hideObj( idObj )
{
	obj = $(idObj);
	if (obj)
	{
		obj.style.display = 'none';
	}
}

function showObj(idObj, use_inline )
{
	obj = $(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()
{
	OverLayer = new SMOverLayer();
	//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 selectAllOptions( objList )
{
	for (var i=0; i < objList.length; i++)
	{
		objList[i].selected = true;
	}
}
function unselectAllOptions( objList )
{
	for (var i=0; i < objList.length; i++)
	{
		objList[i].selected = false;
	}
}
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;
			}*/
		}
	}  
}
/* Funzioni per la scelta utenti e gruppi */
function copyListToList( id_from, id_to )
{
	var fromList = $(id_from);
	var toList   = $(id_to);

	var sel = false;
	for (i=0; i<fromList.options.length; i++)
	{
		var current = fromList.options[i];
		if (current.selected)
		{
			sel = true;
			txt = current.text;
			val = current.value;
			toList.options[toList.length] = new Option(txt,val);
			fromList.options[i] = null;
			i--;
		}
	}
	//if (!sel) alert ('Nessuna voce selezionata');
}
/*****************************************************************************************/
function print_r( arr )
{
    out = dump_arr( arr );
    if ( out )
    {
        alert ( out );
    }
}
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";
        }
    }
    return out;			
}
/* Funzioni per la gestione di file e cartelle */
function stopEventPropagation( evt ) 
{
   if(Prototype.Browser.Gecko) {  
        evt.stopPropagation();
   }    
   else if(Prototype.Browser.IE) {  
        evt.cancelBubble = true;
   }
}
/**
 * DHTML date validation script for dd/mm/yyyy. Courtesy of SmartWebby.com (http://www.smartwebby.com/dhtml/)
 */
// Declaring valid date character, minimum year and maximum year
var dtCh= "/";
var minYear=1990;
var maxYear=2100;
function isInteger(s){
	var i;
    for (i = 0; i < s.length; i++){   
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}
function stripCharsInBag(s, bag){
	var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++){   
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}
function daysInFebruary (year){
	// February has 29 days in any year evenly divisible by four,
    // EXCEPT for centurial years which are not also divisible by 400.
    return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
}
function DaysArray(n) {
	for (var i = 1; i <= n; i++) {
		this[i] = 31
		if (i==4 || i==6 || i==9 || i==11) {this[i] = 30}
		if (i==2) {this[i] = 29}
   } 
   return this
}
function isDate(dtStr)
{
	var daysInMonth = DaysArray(12)
	var pos1=dtStr.indexOf(dtCh)
	var pos2=dtStr.indexOf(dtCh,pos1+1)
	var strDay=dtStr.substring(0,pos1)
	var strDayTxt=strDay
	var strMonth=dtStr.substring(pos1+1,pos2)
	var strMonthTxt=strMonth
	var strYear=dtStr.substring(pos2+1)
	strYr=strYear
	if (strDay.charAt(0)=="0" && strDay.length>1) strDay=strDay.substring(1)
	if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1)
	for (var i = 1; i <= 3; i++) {
		if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1)
	}
	month=parseInt(strMonth)
	day=parseInt(strDay)
	year=parseInt(strYr)
	if (pos1==-1 || pos2==-1){
		//alert("The date format should be : dd/mm/yyyy")
		return false
	}
	if (strMonthTxt.length != 2 || month<1 || month>12){
		//alert("Please enter a valid month")
		return false//
	}
	if (strDayTxt.length != 2 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){
		//alert("Please enter a valid day")
		return false
	}
	if (strYear.length != 4 || year==0 || year<minYear || year>maxYear){
		//alert("Please enter a valid 4 digit year between "+minYear+" and "+maxYear)
		return false
	}
	if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false){
		//alert("Please enter a valid date")
		return false
	}
return true
}
/*************************************************** EN STANDARD JS FUNCTION ****************************************************************/