﻿// --------------------- Funzioni Generiche ---------------------------
function IsValidRegex(name, regex)
{

	var txt = document.getElementById(name);
	if (txt.value == '')
		return true;
	else
	{
		var i = new RegExp(regex);
		var r = i.test(txt.value);
		return r;
	}
}

function IsValidRegexValue(szValueToTest, regex)
{
	if (szValueToTest == '')
		return true;
	else
	{
		var i = new RegExp(regex);
		return i.test(szValueToTest);
	}
}

function IsNumeric(name)
//  check for valid numeric strings	
{
	var txt = document.getElementById(name);
	var strString = txt.value;
	var strValidChars = "0123456789";
	var strChar;
	var blnResult = true;
	
	if (strString.length == 0) return false;
	
	//  test strString consists of valid characters listed above
	for (i = 0; i < strString.length && blnResult == true; i++)
	{
		strChar = strString.charAt(i);
		if (strValidChars.indexOf(strChar) == -1)
	 	{
	 		blnResult = false;
	 	}
	}
	return blnResult;
}

// Regex per la validazione delle date
function ValidateDate(dateToValidate)
{
    var regularExpression = /(0[1-9]|[12][0-9]|3[01])[/](0[1-9]|1[012])[/](19|20)\d\d/;
    return regularExpression.test(dateToValidate);
}

function AddDays(inDate, days)
{
	return new Date(inDate.getTime() + days*24*60*60*1000);
}


function IsValidEmail(name)
{
	return IsValidRegex(name, "^([\\w-\\.\\&\\#\\!\\$\\%\\'\\*\\+\\-\\/\\=\\?\\^\\_\\`\\{\\|\\}\\~]+)@((\\[[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.)|(([\\w-]+\\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\\]?)$");
}

function IsValidFax(name)
{
	return IsValidRegex(name, "^[0-9]{0,}$");
}

function IsValidZip(name)
{
	return IsValidRegex(name, "^[0-9]{5}$");
}

function IsValidHomeNumber(name)
{
	return IsNumeric(name);
}

function IsChecked(name)
{
	var txt = document.getElementById(name);
	return txt.checked;
}

function GetRadioButtonSelectedValue(name)
{
	var obj = document.getElementsByName(name);
	
	//var obj = document.getElementById(name);
	
	for (var i = 0; i < obj.length; i++)
	{
		if (obj[i].checked)
			return obj[i].value;
	}
	
	return "";
}

function ValidateCF(cf)
{
	var validi, i, s, set1, set2, setpari, setdisp;
	if( cf == '' )  return '';
	cf = cf.toUpperCase();
	if( cf.length != 16 )
//		return "La lunghezza del codice fiscale non è\n"
//		+"corretta: il codice fiscale dovrebbe essere lungo\n"
//		+"esattamente 16 caratteri.\n";
		return false;
	validi = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
	for( i = 0; i < 16; i++ ){
		if( validi.indexOf( cf.charAt(i) ) == -1 )
//			return "Il codice fiscale contiene un carattere non valido `" +
//				cf.charAt(i) +
//				"'.\nI caratteri validi sono le lettere e le cifre.\n";
			return false
	}
	set1 = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
	set2 = "ABCDEFGHIJABCDEFGHIJKLMNOPQRSTUVWXYZ";
	setpari = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
	setdisp = "BAKPLCQDREVOSFTGUHMINJWZYX";
	s = 0;
	for( i = 1; i <= 13; i += 2 )
		s += setpari.indexOf( set2.charAt( set1.indexOf( cf.charAt(i) )));
	for( i = 0; i <= 14; i += 2 )
		s += setdisp.indexOf( set2.charAt( set1.indexOf( cf.charAt(i) )));
	if( s%26 != cf.charCodeAt(15)-'A'.charCodeAt(0) )
//		return "Il codice fiscale non è corretto:\n"+
//			"il codice di controllo non corrisponde.\n";
		return false;
//	return "";
	return true;
}

function ValidatePIVA(pi)
{
	if( pi == '' )  return false;
	if( pi.length != 11 )
//		return "La lunghezza della partita IVA non è\n" +
//			"corretta: la partita IVA dovrebbe essere lunga\n" +
//			"esattamente 11 caratteri.\n";
		return false;
	validi = "0123456789";
	for( i = 0; i < 11; i++ ){
		if( validi.indexOf( pi.charAt(i) ) == -1 )
//			return "La partita IVA contiene un carattere non valido `" +
//				pi.charAt(i) + "'.\nI caratteri validi sono le cifre.\n";
			return false;
	}
	s = 0;
	for( i = 0; i <= 9; i += 2 )
		s += pi.charCodeAt(i) - '0'.charCodeAt(0);
	for( i = 1; i <= 9; i += 2 ){
		c = 2*( pi.charCodeAt(i) - '0'.charCodeAt(0) );
		if( c > 9 )  c = c - 9;
		s += c;
	}
	if( ( 10 - s%10 )%10 != pi.charCodeAt(10) - '0'.charCodeAt(0) )
//		return "La partita IVA non è valida:\n" +
//			"il codice di controllo non corrisponde.\n";
		return false;
//	return '';
	return false;
}

function ValidateRadioButton(objRadio)
{
	var radioChecked = false;
	
	for (var i=0; i < objRadio.length; i++)
	{
		if (objRadio[i].checked)
		{
			radioChecked = true;
		}
	}
	return radioChecked;
}


function Mid(str, start, len)
{
    if (start < 0 || len < 0) return "";

    var iEnd, iLen = String(str).length;
    if (start + len > iLen)
            iEnd = iLen;
    else
            iEnd = start + len;

    return String(str).substring(start,iEnd);
}


// Funzione per la concatenazione delle stringhe
function StringBuilder()
{
	this._strings = [];
	this.append = function(s) { this._strings.push(s); };
	this.toString = function() { return this._strings.join(''); };
}

function GetBrowserInnerDim()
{
	var retW = 0;
	var retH = 0;
	
	if(typeof(window.innerWidth) == "number")
	{
		//Non-IE
		retW = window.innerWidth;
		retH = window.innerHeight;
	} else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
		//IE 6+ in 'standards compliant mode'
		retW = document.documentElement.clientWidth;
		retH = document.documentElement.clientHeight;
	} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
		//IE 4 compatible
		retW = document.body.clientWidth;
		retH = document.body.clientHeight;
	}
	
	return [retW,retH];
}

function GoToAnchor(anchorName)
{
	location.href = "#" + anchorName
}

function Point(x, y) {
    this.x = x;
    this.y = y;
}

function FindElementPos(o) {
    var oX = 0;
    var oY = 0;
    if (o.offsetParent) {
        while (1) {
            oX+=o.offsetLeft;
            oY+=o.offsetTop;
                if (!o.offsetParent) {
                    break;
                }
            o=o.offsetParent;
        }
    } else if (o.x) {
        oX+=o.x;
        oY+=o.y;
    }
    return new Point(oX, oY);
}

function PageScrollTopPosition()
{
	var ScrollTop = document.body.scrollTop;
	if (ScrollTop == 0)
	{
		if (window.pageYOffset)
			ScrollTop = window.pageYOffset;
		else
			ScrollTop = (document.body.parentElement) ? document.body.parentElement.scrollTop : 0;
	}
	return ScrollTop;
}

function ShowElement(elementId, showChild, scrollWindow, toElementTop)
{
	if(showChild)
	{
		if(document.getElementById(elementId).childNodes.length > 0)
		{
		    if (document.getElementById(elementId).childNodes[0].style)
		        document.getElementById(elementId).childNodes[0].style.display = "block";
		}
	}
	else
		document.getElementById(elementId).style.display = "block";
		
	if(scrollWindow)
	{
		var innerBrowserDim = GetBrowserInnerDim();
		var elemHeight = document.getElementById(elementId).offsetHeight;
		var elemTop = FindElementPos(document.getElementById(elementId)).y;
		
		var scrollDwn = 0;
		if(toElementTop)
			scrollDwn = elemTop - PageScrollTopPosition();
		else
			scrollDwn = ((elemTop + elemHeight) - (innerBrowserDim[1] + PageScrollTopPosition()));
		
		if(scrollDwn > 0)
			window.scrollBy(0, scrollDwn);
	}
}

function HideElement(elementId, hideChild)
{
	if(hideChild)
	{
		if(document.getElementById(elementId).childNodes.length > 0)
			document.getElementById(elementId).childNodes[0].style.display = "none";
	}
	else
		document.getElementById(elementId).style.display = "none";
}

function ShowHideElement(elementId)
{
	if(document.getElementById(elementId).style.display)
	{
		if(document.getElementById(elementId).style.display == "block")
			document.getElementById(elementId).style.display = "none";
		else
			document.getElementById(elementId).style.display = "block";
	}
	else
		document.getElementById(elementId).style.display = "block";
}

// Popola una dropdown correlata in base ad un array di valori memorizzati in un hidden
function PopRelatedDdl(objDdlFrom, objDdlTo, objHiddenValues, optionValueSelected, hasEmptyElement)
{
	var index = objDdlFrom.selectedIndex - 1;
	
	if (hasEmptyElement)
		for (var i = objDdlTo.options.length - 1; i > 0; i--)
			objDdlTo.options[i] = null;
	else
		for (var i = objDdlTo.options.length - 1; i >= 0; i--)
			objDdlTo.options[i] = null;

	if (index != -1)
	{
		var dests = new Array();
		dests = objHiddenValues.value.split('|');
		
		var locs = new Array();
		locs = dests[index].split('#');
		
		for (var i = 0; i < locs.length; i++)
		{
			var loc = locs[i].split('@');
			
			if(loc[1] == optionValueSelected)
			{
				objDdlTo.options[objDdlTo.length] = new Option(loc[0], loc[1], false, true);
			}
			else
			{
				objDdlTo.options[objDdlTo.length] = new Option(loc[0], loc[1]);
			}
		}
	}
}

function DeleteChildNodes(objToEmpty)
{
	if (objToEmpty.hasChildNodes() )
	{
		while (objToEmpty.childNodes.length >= 1 )
		{
			objToEmpty.removeChild(objToEmpty.firstChild);       
		} 
	}
}

function CreateDdl(appendToObj, ddlId, ddlClass, optionsArray, optionValueSelected, createEmptyOption, emptyOptionValue, emptyOptionText, onChangeFunction)
{
	// Creo la Select 
	newSelect = document.createElement("select");
	
	// Imposto il suo Id
	newSelect.setAttribute("id",ddlId);
	newSelect.setAttribute("name",ddlId);
	
	// Se ha una classe la assegno
	if(ddlClass != "")
		newSelect.className = ddlClass;
		
	// Se ha un "onchange" lo assegno
	if(onChangeFunction != "")
		newSelect.onchange = new Function(onChangeFunction);
	
	if(createEmptyOption)
	{
		newOption = document.createElement("option");
		newOptionText = document.createTextNode(emptyOptionText);
		newOption.appendChild(newOptionText);
		newOption.setAttribute("value", emptyOptionValue);
		newSelect.appendChild(newOption);
	}
	
	if(optionsArray.length > 0)
	{
		// Creo le Option
		var ddlOptions = new Array();
		ddlOptions = optionsArray.split("#");
			
		for (var i = 0; i < ddlOptions.length; i++)
		{
			var optionValue = ddlOptions[i].split("@");
			
			newOption = document.createElement("option");
			newOptionText = document.createTextNode(optionValue[0]);
			newOption.appendChild(newOptionText);
			newOption.setAttribute("value", optionValue[1]);
			if(optionValue[1] == optionValueSelected)
				newOption.setAttribute("selected", "true");
			
			newSelect.appendChild(newOption);
		}
	}
	
	appendToObj.appendChild(newSelect);
}

// --------------------------- Funzioni Custom --------------------------------

// Funzione per invio ricerca da HP
function searchDestination(ref)
{
    if((document.forms["searchForm"].srcDestinationId.value != "") > 0 && (ValidateDate(document.forms["mainForm"].srcDestDate.value)))
    {
		var departureDateString = document.forms["mainForm"].srcDestDate.value;
		var departureDateDay = Mid(departureDateString,0,2);
		if(departureDateDay.indexOf("0") == 0)
			departureDateDay = Mid(departureDateDay,1,1);
		var departureDateMonth = Mid(departureDateString,3,2);
		if(departureDateMonth.indexOf("0") == 0)
			departureDateMonth = Mid(departureDateMonth,1,1);
		var departureDateYear = Mid(departureDateString,6,4);
		
		var departureDate = new Date(parseInt(departureDateYear), (parseInt(departureDateMonth) - 1), parseInt(departureDateDay));
		var todayDate = new Date();
		var one_day = 1000*60*60*24;
		
		if(parseInt(Math.floor((departureDate.getTime() - todayDate.getTime()) / one_day)) < 0)
		{
			alert("Selezionare una data di partenza successiva alla data odierna");
		}
		else
		{
			document.forms["searchForm"].srcDepartureDate.value = departureDateString;
			document.forms["searchForm"].action += '?ref=' + ref;
			document.forms["searchForm"].submit();
		}
    }
    else
    {
        alert("Selezionare una destinazione e una data di partenza");
    }
}

function PopRelatedDestination(selectedValue)
{
	PopRelatedDdl(document.getElementById("Page_Menu_Destination_Change_ddlDestinations"), document.getElementById("ddlSubDestinations"), document.getElementById("Page_Menu_Destination_Change_hdnLocality"), selectedValue, false);
	if(document.getElementById("ddlSubDestinations").options.length > 1)
		ShowElement("ddlSubDestinations", false, false, false);
	else
		HideElement("ddlSubDestinations");
}

// Funzione per invio ricerca da Elenco destinazioni
function searchDestinationFromList(destinationId, parentDestinationId)
{
	if(destinationId > 0 && parentDestinationId > 0)
	{
		var leaveDate = AddDays(new Date(), 1);
		
		document.forms["searchForm"].srcDestinationId.value = destinationId;
		document.forms["searchForm"].srcParentDestinationId.value = parentDestinationId;
		document.forms["searchForm"].srcDepartureDate.value = leaveDate.getDate() + "/" + (leaveDate.getMonth() + 1) + "/" + leaveDate.getFullYear();
		document.forms["searchForm"].submit();
	}
}

// Funzione per invio ricerca da Destination
function searchDestinationChange(ref)
{
    var ddlSelectedIndex = document.forms["mainForm"].Page_Menu_Destination_Change$ddlDestinations.selectedIndex;
    
    if((ddlSelectedIndex > 0) && (ValidateDate(document.forms["mainForm"].Page_Menu_Destination_Change$srcDestDate.value)))
    {
		var departureDateString = document.forms["mainForm"].Page_Menu_Destination_Change$srcDestDate.value;
		var departureDateDay = Mid(departureDateString,0,2);
		if(departureDateDay.indexOf("0") == 0)
			departureDateDay = Mid(departureDateDay,1,1);
		var departureDateMonth = Mid(departureDateString,3,2);
		if(departureDateMonth.indexOf("0") == 0)
			departureDateMonth = Mid(departureDateMonth,1,1);
		var departureDateYear = Mid(departureDateString,6,4);
		
		var departureDate = new Date(parseInt(departureDateYear), (parseInt(departureDateMonth) - 1), parseInt(departureDateDay));
		var todayDate = new Date();
		var one_day = 1000*60*60*24;
		
		if(parseInt(Math.floor((departureDate.getTime() - todayDate.getTime()) / one_day)) < 0)
		{
			alert("Selezionare una data di partenza successiva alla data odierna");
		}
		else
		{
			if(document.forms["mainForm"].ddlSubDestinations)
			{
				document.forms["searchForm"].srcDestinationId.value = document.forms["mainForm"].ddlSubDestinations.options[document.forms["mainForm"].ddlSubDestinations.selectedIndex].value;
				document.forms["searchForm"].srcParentDestinationId.value = document.forms["mainForm"].Page_Menu_Destination_Change$ddlDestinations.options[ddlSelectedIndex].value;
			}
			else
			{
				document.forms["searchForm"].srcDestinationId.value = document.forms["mainForm"].Page_Menu_Destination_Change$ddlDestinations.options[ddlSelectedIndex].value;
				document.forms["searchForm"].srcParentDestinationId.value = "-1";
			}
			document.forms["searchForm"].srcDepartureDate.value = departureDateString;
			document.forms["searchForm"].action += '?ref=' + ref;
			document.forms["searchForm"].submit();
        }
    }
    else
    {
        alert("Selezionare una destinazione e una data di partenza");
    }
}

// Funzione per invio ricerca da Package
function searchDestinationPackage(srcDestinationId, srcParentDestinationId, srcPackageCode)
{
	if((srcDestinationId != "") && (srcPackageCode != "") && (ValidateDate(document.forms["mainForm"].srcDestDatePackage.value)))
	{
		var departureDateString = document.forms["mainForm"].srcDestDatePackage.value;
		var departureDateDay = Mid(departureDateString,0,2);
		if(departureDateDay.indexOf("0") == 0)
			departureDateDay = Mid(departureDateDay,1,1);
		var departureDateMonth = Mid(departureDateString,3,2);
		if(departureDateMonth.indexOf("0") == 0)
			departureDateMonth = Mid(departureDateMonth,1,1);
		var departureDateYear = Mid(departureDateString,6,4);
		
		var departureDate = new Date(parseInt(departureDateYear), (parseInt(departureDateMonth) - 1), parseInt(departureDateDay));
		var todayDate = new Date();
		var one_day = 1000*60*60*24;
		
		if(parseInt(Math.floor((departureDate.getTime() - todayDate.getTime()) / one_day)) < 0)
		{
			alert("Selezionare una data di partenza successiva alla data odierna");
		}
		else
		{
			document.forms["searchForm"].srcDestinationId.value = srcDestinationId;
			document.forms["searchForm"].srcParentDestinationId.value = srcParentDestinationId;
			document.forms["searchForm"].srcPackageCode.value = srcPackageCode;
			document.forms["searchForm"].srcDepartureDate.value = departureDateString;
			document.forms["searchForm"].submit();
		}
    }
    else
    {
        alert("Selezionare una data di partenza");
    }
}

function searchWarDestinationPackage(srcDestinationId, srcParentDestinationId, srcPackageCode, departureDate)
{
	if((srcDestinationId != "") && (ValidateDate(departureDate)))
	{
		//debugger;
		
		var departureDateString = departureDate + "";
		var departureDateDay = Mid(departureDateString,0,2);
		if(departureDateDay.indexOf("0") == 0)
			departureDateDay = Mid(departureDateDay,1,1);
		var departureDateMonth = Mid(departureDateString,3,2);
		if(departureDateMonth.indexOf("0") == 0)
			departureDateMonth = Mid(departureDateMonth,1,1);
		var departureDateYear = Mid(departureDateString,6,4);
		
		var departureDate = new Date(parseInt(departureDateYear), (parseInt(departureDateMonth) - 1), parseInt(departureDateDay));
		var todayDate = new Date();
		var one_day = 1000*60*60*24;
		
		if(parseInt(Math.floor((departureDate.getTime() - todayDate.getTime()) / one_day)) < 0)
		{
			alert("Selezionare una data di partenza successiva alla data odierna");
		}
		else
		{
			document.forms["searchForm"].srcDestinationId.value = srcDestinationId;
			document.forms["searchForm"].srcParentDestinationId.value = srcParentDestinationId;
			document.forms["searchForm"].srcPackageCode.value = srcPackageCode;
			document.forms["searchForm"].srcDepartureDate.value = departureDateString;
			document.forms["searchForm"].submit();
		}
    }
    else
    {
        alert("Selezionare una data di partenza");
    }
}

var menuActiveInnerHTML = "";
var menuActiveId = "";

function showDestinationCal(menuId)
{
    if (menuActiveInnerHTML != "")
        document.getElementById("menu-" + menuActiveId).innerHTML = menuActiveInnerHTML;
        
    menuActiveInnerHTML = document.getElementById("menu-" + menuId).innerHTML;
    menuActiveId = menuId;
    
    document.getElementById("menu-" + menuId).innerHTML = "<td id=\"box-departure\"><div class=\"box-departure-title\"><a href='javascript:void;' onclick=\"hideDestinationCal('" + menuId + "'); return false;\">" + document.getElementById("menu-" + menuId).getElementsByTagName("a")[0].innerHTML + "</a></div><div class=\"box-departure\"><table cellpadding=\"0\" cellspacing=\"0\"><tr><td>Data Partenza</td><td class=\"delta\">+/- 7gg</td></tr><tr><td><input type=\"text\" class=\"input-txt\" id=\"\" name=\"srcDestDate\" onfocus=\"displayCalendar(document.forms['mainForm'].srcDestDate,'dd/mm/yyyy',this,0,0,true);return false;\" /></td><td align=\"center\"><input type=\"image\" src=\"/img/calendar.gif\" alt=\"\" onclick=\"displayCalendar(document.forms['mainForm'].srcDestDate,'dd/mm/yyyy',this,0,0,true);return false;\" /></td></tr><tr><td></td><td><a href=\"javascript:searchDestination('search_engine_sx');\"><img src=\"/img/it/arrow-dx-go-orange.gif\" alt=\"\" /></a></td></tr></table></div></td>";
    
    document.forms["searchForm"].srcDestinationId.value = menuId;
    
    var innerBrowserDim = GetBrowserInnerDim();
    var elemHeight = document.getElementById("menu-" + menuId).offsetHeight;
    var elemTop = FindElementPos(document.getElementById("menu-" + menuId)).y;
    
    var scrollDwn = ((elemTop + elemHeight) - (innerBrowserDim[1] + PageScrollTopPosition()));
	
	if(scrollDwn > 0)
		window.scrollBy(0, scrollDwn);
}

function hideDestinationCal(menuId)
{
	document.getElementById("menu-" + menuId).innerHTML = menuActiveInnerHTML;
   
    document.forms["searchForm"].srcDestinationId.value = "";
}

function showDestinationInfo(divToShow)
{
    document.getElementById("dest-mappa").className = "content-div-off";
    document.getElementById("dest-meteo").className = "content-div-off";
    document.getElementById("dest-info").className = "content-div-off";
    document.getElementById("dest-appunti").className = "content-div-off";
    document.getElementById("dest-mappa-label").className = "label-off";
    document.getElementById("dest-meteo-label").className = "label-off";
    document.getElementById("dest-info-label").className = "label-off";
    document.getElementById("dest-appunti-label").className = "label-off";
    
    document.getElementById(divToShow).className = "content-div-on";
    document.getElementById(divToShow + "-label").className = "label-on";
}

function showStructureBigImage(smlImage)
{
	document.getElementById("imgPackageBig").src = document.getElementById(smlImage).src
}

function goToPage(i)
{
	document.getElementById('hdnPage').value = i;
	__doPostBack('lnkPagination','');
}

// Funzione per la visualizzazione di una Foto Gallery
function popUpGallery(theURL) 
{
  var winWidth = 1000;
  var winHeight = 550;
  var screenWidth = ( screen.width - winWidth ) / 2;
  var screenHeight = ( screen.height - winHeight ) / 2;
  
  window.open(theURL,"popupGalleryWindow","screenX=" + screenWidth + ",screenY=" + screenHeight + ",left=" + screenWidth + ",top=" + screenHeight + ",width=" + winWidth + ",height=" + winHeight + ",toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,copyhistory=no");
}

function showPackageDetailInfo(divToShow)
{
	if(document.getElementById("package-detail-info-detail"))
		HideElement("package-detail-info-detail");
	if(document.getElementById("package-detail-info-itinerary"))
		HideElement("package-detail-info-itinerary");
	if(document.getElementById("package-detail-info-excursions"))
		HideElement("package-detail-info-excursions");
	if(document.getElementById("package-detail-info-diving"))
		HideElement("package-detail-info-diving");
	if(document.getElementById("package-detail-info-safari"))
		HideElement("package-detail-info-safari");
	if(document.getElementById("package-detail-info-flights"))
		HideElement("package-detail-info-flights");
	ShowElement(divToShow, false, true, true);
}

function ChangeTab(tabid)
{
   document.getElementById('hdnSelectedTab').value = tabid;
   __doPostBack('lnkChangeTab','');
}
        
function GoToPackage(url, duration, date, destinationid, parentDestinationID)
{
	document.forms['searchForm'].srcDepartureDate.value = date;
	document.forms['searchForm'].srcDestinationId.value = destinationid;
	document.forms['searchForm'].srcParentDestinationId.value = parentDestinationID;
	document.forms['searchForm'].srcPackageDuration.value = duration;
    document.forms['searchForm'].action = url;
    document.forms['searchForm'].submit();
}

// Funzione che dalla pagina di ricerca porta alla pagina pacchetto per una specifica data e durata
function GoToPackageFromSearch(frmAction, duration, departureDateFixed, airportCode)
{
	if(ValidateDate(document.forms["mainForm"].Page_Menu_Destination_Change$srcDestDate.value))
    {
		document.forms["searchForm"].srcDepartureDate.value = document.forms["mainForm"].Page_Menu_Destination_Change$srcDestDate.value;
        document.forms["searchForm"].srcPackageDuration.value = duration;
        document.forms["searchForm"].srcDepartureDateFixed.value = departureDateFixed;
        document.forms["searchForm"].srcAirportCode.value = airportCode;
        document.forms["searchForm"].action = frmAction;
        document.forms["searchForm"].submit();
    }
    else
    {
        alert("Selezionare una data di partenza");
    }
}

function checkNewsletter(control)
{
    if (document.getElementById(control + '_txtNewsletter').value == '')
        alert('Specificare un indirizzo e-mail');
    else
    {
        if (! IsValidEmail(control + '_txtNewsletter'))
            alert('Indirizzo e-mail specificato non valido');
        else
            __doPostBack(control + '$lnkSubscribe');                    
    }
}

function checkTellAFriend()
{
	if(document.getElementById("txtSenderFirstName").value == "")
	{
		alert("Inserire il Nome del Mittente");
		return false;
	}
	
	if(document.getElementById("txtSenderLastName").value == "")
	{
		alert("Inserire il Cognome del Mittente");
		return false;
	}
	
	if(document.getElementById("txtSenderEmail").value == "")
	{
		alert("Inserire l'E-mail del Mittente");
		return false;
	}
	
	if(!IsValidEmail("txtSenderEmail"))
	{
		alert("Inserire una E-mail valida del Mittente");
		return false;
	}
	
	if(document.getElementById("txtReceiverFirstName").value == "")
	{
		alert("Inserire il Nome del Destinatario");
		return false;
	}
	
	if(document.getElementById("txtReceiverLastName").value == "")
	{
		alert("Inserire il Cognome del Destinatario");
		return false;
	}
	
	if(document.getElementById("txtReceiverEmail").value == "")
	{
		alert("Inserire l'E-mail del Destinatario");
		return false;
	}
	
	if(!IsValidEmail("txtReceiverEmail"))
	{
		alert("Inserire una E-mail valida del Destinatario");
		return false;
	}
	
	if(document.getElementById("txtTellMessage").value == "")
	{
		alert("Inserire il Testo del Messaggio");
		return false;
	}
	
	if(document.getElementById("txtCaptcha").value == "")
	{
		alert("Inserire i caratteri visualizzati nell'immagine");
		return false;
	}
	
	return true;
}

function tellAFriend()
{
	if(checkTellAFriend())
		__doPostBack('lnkTellAFriend','');
}

function checkCallMeBack()
{
	
	if(document.getElementById("txtCMBFirstName").value == "")
	{
		alert("Inserire il Nome");
		return false;
	}
	
	if(document.getElementById("txtCMBLastName").value == "")
	{
		alert("Inserire il Cognome");
		return false;
	}
	
	if(document.getElementById("txtCMBMobile").value == "" && document.getElementById("txtCMBPhone").value == "")
	{
		alert("Inserire un numero di telefono Cellulare o Fisso");
		return false;
	}
			
	if(!IsValidHomeNumber("txtCMBMobile") && document.getElementById("txtCMBMobile").value != "")
	{
		alert("Inserire solo cifre nel campo Cellulare");
		return false;
	}
	
	if(!IsValidHomeNumber("txtCMBPhone") && document.getElementById("txtCMBPhone").value != "")
	{
		alert("Inserire solo cifre nel campo Telefono");
		return false;
	}
	
	if(document.getElementById("txtCMBEmail").value == "")
	{
		alert("Inserire un indirizzo E-mail");
		return false;
	}
	
	if(!IsValidEmail("txtCMBEmail"))
	{
		alert("Inserire una E-mail valida");
		return false;
	}
	
	if(!document.getElementById("cbxCMBPrivacy").checked)
	{
		alert("Per procedere è necessario acconsentire al trattamento dei dati personali.");
		return false;
	}
	
	return true;
}

function sendCallMeBack()
{
	if(checkCallMeBack())
		__doPostBack('lnkCallMeBack','');
}

function trackTrans(pnr, city, prov, country, destinationName, packageName, hotelName, price, quantity)
{
     pageTracker._addTrans(pnr, '', price, '0.00','0.00', city, prov, country);
     pageTracker._addItem(pnr, destinationName, packageName, hotelName, price, quantity);
     pageTracker._trackTrans();
} 

function getSelectedValue(szDDLName)
{
	var ddl = document.getElementById(szDDLName);
	return ddl.options[ddl.selectedIndex].value;
}

function createGMap(destinationID, lat, lng, zoom, language)
{
    initMap('divGMap', lat, lng, zoom);
    var pl = new SOAPClientParameters();
    pl.add("destinationID", destinationID);
    pl.add("language", language);
    SOAPClient.invoke('/WebService/GMaps.asmx', 'GetHotelsMarkerScript', pl, true, createGMap_CallBack);
}

function createGMap_CallBack(r, soapResponse)
{
    eval(r);
}

function backDestroyer()
{
    window.location = '/it/index.htm';
}

function addThis()
{   
    var url = 'http://www.addthis.com/bookmark.php?v=10&pub=alex79&url=' + escape(document.location.href) + '&title=' + escape(document.title);
    window.open(url,"addthis","scrollbars=yes,menubar=no,width=620,height=520,resizable=yes,toolbar=no,location=no,status=no,screenX=200,screenY=100,left=200,top=100");
}

function popupGenerico(url) 
{
    window.open(url,'popupWindow','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=no,width=640,height=400,screenX=250,screenY=250,top=400,left=420')
}

// Load Google Map
function loadMap(lMapLat, lMapLng, iMapZoom)
{
	if (GBrowserIsCompatible())
	{ 
		var map = new GMap2(document.getElementById("map"));
		map.setCenter(new GLatLng(lMapLat, lMapLng), iMapZoom);
		map.addControl(new GOverviewMapControl());
		map.addControl(new GSmallZoomControl());
	} 
	
	return(map);
}

function loadMapDestinazione(lMapLat, lMapLng, iMapZoom)
{
	if (GBrowserIsCompatible())
	{ 
		var map = new GMap2(document.getElementById("map"));
		map.setCenter(new GLatLng(lMapLat, lMapLng), iMapZoom);
	} 
	
	return(map);
}

// Set a point on the Map
function setMapPoint(map, lPointLat, lPointLng, sText, sImgPath)
{
	var icona1 = new GIcon(G_DEFAULT_ICON);
	icona1.image = sImgPath;
	icona1.shadow = "";
	icona1.iconSize = new GSize(20, 35);
	
	marker = new GMarker(new GLatLng(lPointLat, lPointLng), {icon: icona1});
	map.addOverlay(marker);
	
	GEvent.addListener(marker, "mouseover", 
		function()
		{
			map.openInfoWindowHtml(new GLatLng(lPointLat, lPointLng), sText); 
		}
	);
}