﻿function FilterChars(e)
{
	var keyVal = e.keyCode ? e.keyCode : e.charCode;

	if ( (keyVal > 64 && keyVal < 91) || (keyVal > 96 && keyVal < 123) || keyVal == 32 || keyVal == 8)
	{
		return true;
	}
	else
	{
		return false;
	}	
}

function HideTable(tableName)
{
    var tabella = document.getElementById(tableName);

    if (tabella.style.display == 'block' || tabella.style.display == '')
    {
        tabella.style.display = 'none';
    }
    else
    {
	    tabella.style.display = 'block';
    }
}

function ShowProgress()
{
    var progress = document.getElementById("progress");
    progress.style.display = "";

	setTimeout('document.images["imgwait"].src = "img/attesa.gif"', 200);

    return true;
}
        
function openPopUp(url,w,h)
{
    var lt = (screen.width - w) / 2;
	var tp = (screen.height - h) / 2;
	window.open(url,'','width='+w+',height='+h+',left='+lt+',top='+tp+',scrollbars=yes,resize=no');
}

function sommaData(start_day, number_nights, the_div)
{	  
    var days = start_day;

    var exp = days.split("-");
    var giorno = exp[0];
    var mese = exp[1];
    var anno = exp[2];

    var diff = parseInt(number_nights, 10);
    var part = new Date(anno, parseInt(mese,10)-1, giorno);  

    var currentDate = new Date();
    var currYear = currentDate.getFullYear() + 1;
    var currMonth = currentDate.getMonth();

    var sumDayToCheck = parseInt(giorno,10) + diff;
    
    if(mese == 12 && sumDayToCheck > 31) anno = currYear;

    var fine = part;
    fine.setDate(fine.getDate() + diff);   

    var meseToDisplay = part.getMonth() + 1;
    
    if((meseToDisplay/10) < 1) meseToDisplay = '0' + meseToDisplay;

	var giornoToDisplay = fine.getDate();

	if((giornoToDisplay/10) < 1) giornoToDisplay = '0' + giornoToDisplay;
    
	var str = giornoToDisplay + '-' + meseToDisplay + '-' + anno;

    var objDiv = document.getElementById(the_div);

    if (objDiv.type == "text")
        objDiv.value = str;
    else
        objDiv.innerHTML = str;
}

function fillcombo(thecombo, value)
{
	var dest = document.getElementById(thecombo);

	for (var i=dest.options.length-1; i>=1; i--)
	{
		dest.options[i] = null;
	}

	dest.selectedIndex = 0;

	if (eval("typeof("+value+")!='undefined'"))
	{
		var arrDest = eval(value);

		for (var i = 0; i < arrDest.length; i++)
		{
			dest.options[dest.options.length] = new Option(arrDest[i].value, arrDest[i].text);
		}
	}
	//else
	//{
	//    dest.options[0] = new Option("", "");
	//}	
}

function fillcomboPoi(poiRow, thecombo, value)
{
    fillcombo(thecombo, value);
    
    var poi_row = document.getElementById(poiRow);
    var dest = document.getElementById(thecombo);
    
    if (dest.options.length == 0 || (dest.options.length == 1 && dest.options[0].text == "Seleziona...")) 
        poi_row.style.display = "none";
    else
        poi_row.style.display = "";
}
