function ajaxRequest()
{
	var xmlHttp = false;
	try
	{	xmlHttp=new XMLHttpRequest();
	}
	catch (e)
	{
		try
		{	xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e)
		{
			try
			{	xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch (e)
			{	return false;
			}
		}
	}
	return(xmlHttp);	
}


function showSelect(aParametri,nameDiv){

	if (document.getElementById('button'+nameDiv))
		document.getElementById('button'+nameDiv).style.display='none';	

	if (document.getElementById(nameDiv))
		document.getElementById(nameDiv).disabled = true;

	if (document.getElementById('loader'+nameDiv))
		document.getElementById('loader'+nameDiv).style.display='block';	
	
	for (var nI=0;nI<aParametri.length;nI++){
		document.getElementById(nameDiv).options[nI+1]=new Option(aParametri[nI]['location'],escape(aParametri[nI]['location_keyurl']),false,false);
	}
	if (document.getElementById('loader'+nameDiv))
		document.getElementById('loader'+nameDiv).style.display='none';

	if (document.getElementById('button'+nameDiv))
		document.getElementById('button'+nameDiv).style.display='block';	

	if (document.getElementById(nameDiv))		
		document.getElementById(nameDiv).disabled = false;
}


function createSelect(sTipo,nameDiv){

	var sPath = "/loadSelect.php?s="+ sTipo;

	var XMLReq = ajaxRequest();
	
	if (!XMLReq) 
		return(false);

	XMLReq.open("GET",sPath, true);
	XMLReq.send(null);

	XMLReq.onreadystatechange=function(){
	
	// stato della richiesta (Load completato)
    	if(XMLReq.readyState==4 ){
		// restituzione senza errori
		if(XMLReq.status == 200){
			
			try {
				var XMLResponse = XMLReq.responseXML;

				var oXmlAdvert =  XMLResponse.getElementsByTagName('loc');
				
				var countElement = oXmlAdvert.length;
				
				var aParametri = new Array();
				
				for (var i=0;i<countElement;i++){
					aParametri[i] = new Array();
					aParametri[i]['location']=oXmlAdvert.item(i).getElementsByTagName('location').item(0).firstChild.nodeValue
					aParametri[i]['location_keyurl'] = oXmlAdvert.item(i).getElementsByTagName('location_keyurl').item(0).firstChild.nodeValue
				}
				showSelect(aParametri,nameDiv);

			}catch(e){
				//alert(e.description);
				return false;
			}
		}
	}
}

}




function destroy(divDestroy){

	_div = document.getElementById(divDestroy);

	_div.parentNode.removeChild(_div);

	return false;

}





function createAlert(msgError,title){

	

	_body = document.getElementsByTagName('body') [0];

	_divCont = document.createElement('div');

	_divCont.setAttribute("id", "popup_container");

	_divCont.setAttribute("style", "position: absolute; z-index: 99999; min-width: 363px; max-width: 363px;top: 250px; left: 527px;");





	_title = document.createTextNode(title)

	_h1 = document.createElement('h1');		

	_h1.setAttribute("id", "popup_title");

	_h1.appendChild(_title);





	_divC = document.createElement('div');

	_divC.setAttribute("id", "popup_content");





	_error = document.createTextNode(msgError)

	_divMes = document.createElement('div');

	_divMes.setAttribute("id", "popup_message");	

	_divMes.appendChild(_error);





	_divPan = document.createElement('div');

	_divPan.setAttribute("id", "popup_panel");	



	_input = document.createElement('input');

	_input.setAttribute("id", "popup_ok");

	_input.setAttribute("type", "button");

	_input.setAttribute("value", " OK ");

	_input.setAttribute("onClick", "destroy('popup_container');return false;");



	_divPan.appendChild(_input);

	_divC.appendChild(_divMes);

	_divC.appendChild(_divPan);





	_divCont.appendChild(_h1);



	_divCont.appendChild(_divC);



	_body.appendChild(_divCont);

}





function jAlert(msgErr,title){

	createAlert(msgErr,title);

	return false;

}





function setCalendar(tab){

	

	if (tab == 'voli'){

		dp_cal1  = new Epoch('cal1','popup',document.getElementById("dataAndata"),false);
		dp_cal2  = new Epoch('cal2','popup',document.getElementById("dataRitorno"),false);	

	}



	if (tab == 'viaggi'){

		dp_cal3  = new Epoch('cal3','popup',document.getElementById("VdataAndata"),false);
		dp_cal4  = new Epoch('cal4','popup',document.getElementById("VdataRitorno"),false);		

	}



	if (tab == 'hotel'){

		dp_cal5  = new Epoch('cal5','popup',document.getElementById("HdataAndata"),false);
		dp_cal6  = new Epoch('cal6','popup',document.getElementById("HdataRitorno"),false);		

	}



}





function setTab(tabView,tabNoview_1,tabNoview_2,createSel){



	document.getElementById(tabView).style.display="block";

	document.getElementById('selectMotore').value = tabView;

	document.getElementById("tab"+tabView).className="motoreTabAttivo";

	document.getElementById(tabNoview_1).style.display="none";

	document.getElementById("tab"+tabNoview_1).className="motoreTabInattivo";

	document.getElementById(tabNoview_2).style.display="none";

	document.getElementById("tab"+tabNoview_2).className="motoreTabInattivo";

	setCalendar(tabView);

	if (createSel=='mv'){
		createSelect("mvd","Vdestinazione");
		createSelect("mvl","Vlocation");
	}


}

function setTabItinerari(tabView,cont){
	
	for(i=0;i<=cont-1;i++){
		document.getElementById("itinerari_text_"+i).style.display="none";
		document.getElementById("tabItinerari"+i).className="tabItinerariInattivo";
	}
	document.getElementById("itinerari_text_"+tabView).style.display="block";
	document.getElementById("tabItinerari"+tabView).className="tabItinerariAttivo";
}
//TABS PER AREA AMMINISTRAZIONE
function setTabAdmin(tabView,cont){
	
	for(i=0;i<=cont-1;i++){
		document.getElementById("menu_text_"+i).style.display="none";
		document.getElementById("tabMenu"+i).className="tabInattivo";
	}
	document.getElementById("menu_text_"+tabView).style.display="block";
	document.getElementById("tabMenu"+tabView).className="tabAttivo";
}



var aErrMsgVoli = new Array (

	/* 0  msg citta partenza */ "Inserisci una citta' di partenza",

	/* 1  msg giorno */ "Seleziona la data di partenza",

	/* 4  msg citta partenza */ "Seleziona la data di ritorno",

	/* 5  msg giorno */ "Inserisci una citta' di arrivo"

	);



var aTagIdVoli = new Array (

	/* 0  tag citta partenza */ 	"Da",

	/* 1  tag mese partenza */ 	"dataAndata",

	/* 2  tag giorno partenza */ 	"dataRitorno",

	/* 3  tag citta Arrivo */ 	"A"

	);



var aErrMsgVoliAndataRitorno = new Array (

	/* 0  msg citta partenza */ "Inserisci una citta' di partenza",

	/* 1  msg giorno */ "Seleziona la data di partenza",

	/* 3  msg giorno */ "Inserisci una citta' di arrivo"

	);

var aTagIdVoliAndataRitorno = new Array (

	/* 0  tag citta partenza */ 	"Da",

	/* 1  tag mese partenza */ 	"dataAndata",

	/* 2  tag citta Arrivo */ 	"A"

	);









var aErrMsgHotel = new Array (

	/* 0  msg giorno */ "E' obbligatorio selezionare la destinazione",

	/* 1  msg giorno */ "Seleziona la data di partenza",

	/* 2  msg mese */ "Seleziona la data di ritorno"

	);



var aTagIdHotel = new Array (

	/* 0  tag destinazione */ 	"Hdestinazione",

	/* 1  tag mese partenza */ 	"HdataAndata",

	/* 2  tag giorno partenza */ "HdataRitorno"

	);









var aErrMsgViaggi = new Array (

	/* 0  msg citta partenza */ "Inserisci la destinazione",

	/* 1  msg giorno */ "Seleziona la data della partenza",

	/* 2  msg mese */ "Seleziona la data del ritorno",

	/* 4  msg citta partenza */ "Inserisci la localit&agrave;",

	/* 4  msg citta partenza */ "Inserisci il numero di notti"

	);



var aTagIdViaggi = new Array (

	/* 0  tag citta partenza */ "Vdestinazione",

	/* 1  tag mese partenza */ 	"VdataAndata",

	/* 2  tag giorno partenza */ "VdataRitorno",

	/* 4  tag citta Arrivo */ 	"Vlocation",

	/* 8  tag notti */ 		"notti"

	);





function chkDaA(tagId, n) {

	

	select = document.getElementById('selectMotore').value;



	if (select=='voli'){
		if (document.getElementById('sa').value=='on')
			aErrMsg = aErrMsgVoliAndataRitorno
		else
			aErrMsg = aErrMsgVoli;

		forms = document.getElementById(tagId);

	}



	if (select=='viaggi'){

		aErrMsg = aErrMsgViaggi;

		forms = document.getElementById(tagId)



	}



	if (select=='hotel'){

		aErrMsg = aErrMsgHotel;

		forms = document.getElementById(tagId)

	}





	eName   =  forms

	if (eName!= null){

		sValue  = eName.value; 

		nLength = eName.value.length;

	}



	if(sValue == "00" ||  sValue == "0000" || nLength < 1)

	{

		//jAlert(aErrMsg[n], 'Attenzione');

		alert(aErrMsg[n]);

		

		eName.focus();

		return false;

	}

	return true;



}



function controllaForm(nameForm) {



	if (!document.getElementById('selectMotore')){

		return false

	}



	select = document.getElementById('selectMotore').value;

	

	if (select=='voli'){
		if (document.getElementById('sa').value=='on')
			aTagId = aTagIdVoliAndataRitorno;
		else
			aTagId = aTagIdVoli;
	}


	if (select=='viaggi')

		aTagId = aTagIdViaggi;



	if (select=='hotel')

		aTagId = aTagIdHotel;



	for (var i=0; i<=aTagId.length;i++){

		var bResult = chkDaA(aTagId[i], i);

		if (!bResult)

		{

			return bResult;

			break;

		}

	}

	document.getElementById(nameForm).submit();

}





function viewBox(div){

	

	if (document.getElementById(div)){

		

		status = document.getElementById(div).style.display;

		if (status=='none' || status=='')

			document.getElementById(div).style.display='block';

		else

		document.getElementById(div).style.display='none';

	}

}



function viewHideBox(showDiv,hideDiv){

	document.getElementById(showDiv).style.display="block"

	document.getElementById(hideDiv).style.display="none"

}



function hide(div){

	if (document.getElementById(div)){

		document.getElementById(div).style.display='none';

	}

}







function clearInputMotore(){

	

	aUnione = aTagIdVoli.concat(aTagIdHotel);

	aConcat = aUnione.concat(aTagIdViaggi);

	count = (aConcat.length)-1;





	for(var i=0 ; i < count;i++){

		if (document.getElementById(aConcat[i]).tagName == "SELECT"){

			document.getElementById(aConcat[i]).options[0].value='' ;

		}else if (document.getElementById(aConcat[i]))

				document.getElementById(aConcat[i]).value='';



	} 

}







function clearInputMotore(){

	

	aUnione = aTagIdVoli.concat(aTagIdHotel);

	aConcat = aUnione.concat(aTagIdViaggi);

	count = (aConcat.length);





	for(var i=0 ; i < count;i++){

		if(document.getElementById(aConcat[i])){

			if (document.getElementById(aConcat[i]).selectedIndex){

				document.getElementById(aConcat[i]).selectedIndex=0 ;

			}else if (document.getElementById(aConcat[i]))

					document.getElementById(aConcat[i]).value='';

		}



	} 

}

function cancellaTag(idTag){
//document.getElementById('idFrame').innerHTML='';			
	alert(111);
}

