// JavaScript Document

	//var scelta="search.jsp";
        var scelta="http://epowerv4.amadeus.com.tr/salina/portals/salina/flightFareSearch.aspx?IsExternalAccess=true";
	



        
        var aeroporti=[];
        var paesi=[];
        function ripristina(lista){
		var x=document.getElementById(lista);
		for(i=0;i<aeroporti.length;i++){
                        if(aeroporti[i]!=null){
				var j=x.options.length;
                                x.options[j]=new Option('',aeroporti[i][0],false,false);
                                x.options[j].innerHTML = aeroporti[i][1];
			}
		}
	}

	function annulla(){
		document.forms[0].departure.value="";
		document.forms[0].arrivo1.value="";
		document.forms[0].arrivo.value="";
		document.forms[0].partenza1.value="";
		var x=document.getElementById("paeseA");
		if(x.selectedIndex==0){
			ripristina("arrivi");
		}else{
			filtraXtesto("arrivi",x.options[x.selectedIndex],true);

		}
		x=document.getElementById("paeseDa");
		filtraXtesto("partenze",x.options[x.selectedIndex],true);
		
	}
	

        function assegna(campo,da){
                campo.value=da.options[da.selectedIndex].text;
        }

        function filtra(paese,lista){
                var paeseScelto = paese.options[paese.selectedIndex].value;
                
        }
	
	function aggiornaCalendario(){
		document.forms[0].dd_R.disabled=false;
                document.forms[0].mm_R.disabled=false;
                document.forms[0].yy_R.disabled=false;
//		document.forms[0].dd_R.selectedIndex=document.forms[0].dd_A.selectedIndex;
//		document.forms[0].mm_R.selectedIndex=document.forms[0].mm_A.selectedIndex;
//		document.forms[0].yy_R.selectedIndex=document.forms[0].yy_A.selectedIndex;
		onchangeDataA();
	}

	function blocca(){
		document.forms[0].dd_R.disabled=true;
		document.forms[0].mm_R.disabled=true;
		document.forms[0].yy_R.disabled=true;
	}

	function checkDateAR(){
		if(document.f.yy_A.value < document.f.yy_R.value)
			return true;
		if(document.f.yy_A.value == document.f.yy_R.value){
			if(document.f.mm_A.value < document.f.mm_R.value)
				return true;
			if(document.f.mm_A.value == document.f.mm_R.value){
				if(document.f.dd_A.value <= document.f.dd_R.value)
					return true;
			}
		}

		return false;
	}

	function Convalidate () {	
		
                var ok;
		var err;
		var ar_checked;
		
		err = '';	
		ok = true;
		ar_checked = -1;
		ws_checked = "none";

		///////////////////////////////funxione controlllo
		var partenze = document.getElementById("partenze");
		//if(partenze.selectedIndex==-1 && partenze.options.length!=1){
                if(document.f.partenza1.value.length<3){
				err +=SELECT1;
				ok= false;
		}else{
				/*if(partenze.selectedIndex==-1){
						partenze.selectedIndex=0;
				} */
                                if(partenze.selectedIndex>-1){
                                    document.forms[0].da.value=partenze.options[partenze.selectedIndex].value;		
				} 
                                
		}

		var arrivi=document.getElementById("arrivi");
		//if(arrivi.selectedIndex==-1 && arrivi.options.length!=1){
                if(document.f.arrivo1.value.length<3){
				err+=SELECT2;
				ok= false;
		 }else{
				/*if(arrivi.selectedIndex==-1){
						arrivi.selectedIndex=0;
				} */
                                if(arrivi.selectedIndex>-1){
                                    document.forms[0].a.value=arrivi.options[arrivi.selectedIndex].value;		
				}
                                
		 }

		 if(document.f.INFANTSelect.value > document.f.ADULTSelect.value){
			err +=INFANTS_ERR;
			ok= false;
		 }

		 if(document.f.INFANTSelect.value > 2){
			err +=INFANTS2_ERR;
			ok= false;
		 }

		if (document.f.ar[0].checked) {	
			if (!checkDateAR()) {
					err += DATE_ERR;
					ok = false;
			}
		}
		
		/////////////////////////////fine controllo
	
		for (i=0; i<2; i++) {
			// alert("ar: " + i + " - " + document.f.ar[i].checked + " - " + document.f.ar[i].value);
			if (document.f.ar[i].checked) { ar_checked = i; }
		}
		
		if (ar_checked > 1) {
                        
			alert ("Selezionare \"Andata\" o \"Andata e Ritorno\" per il volo.");
		}

		
			
		if (ar_checked == 1) {
				
				//alert ("setting action=dosearchow.jsp");
		}
                
                
                


		if (ok == true) {
                    
            
                        submitRealForm(ar_checked);
                        
			//document.f.submit();		
		}		
		else {
			alert (err);
		}
	}
        
        function submitRealForm(ar_checked)
        {
            if (document.f2)
            {
                var f2=document.f2;
                f2.External_FlightFareSearch_DepartureDate.value=document.f.dd_A.value+"/"+document.f.mm_A.value+"/"+document.f.yy_A.value;
                f2.External_FlightFareSearch_ReturnDate.value=document.f.dd_R.value+"/"+document.f.mm_R.value+"/"+document.f.yy_R.value;
                f2.External_FlightFareSearch_NumberOfAdults.value=document.f.ADULTSelect.value;
                f2.External_FlightFareSearch_NumberOfChilds.value=document.f.CHILDSelect.value;
                f2.External_FlightFareSearch_NumberOfInfants.value=document.f.CHILDSelect.value;
                f2.External_FlightFareSearch_From.value=document.f.da.value;
                f2.External_FlightFareSearch_To.value=document.f.a.value;
                if (ar_checked==1)
                    f2.External_FlightFareSearch_SearchType.value='OneWay';
                else if (ar_checked==0)
                    f2.External_FlightFareSearch_SearchType.value='RoundTrip';
                if (document.f.plusminus3days.checked)
			f2.External_FlightFareSearch_Calendar.value='on';
		else
					f2.External_FlightFareSearch_Calendar.value='off';
                
            } else {
                var secondFormFragment = document.createDocumentFragment();
                var f2=document.createElement("form");
                f2.setAttribute("id","f2");
                f2.setAttribute("name","f2");
                f2.setAttribute("action","/"+LANGUAGE+"/flightresults.html");
                f2.setAttribute("method","post");
                f2.setAttribute("target","_self");
                
                var fromDate = document.createElement("input");
                fromDate.setAttribute("type","hidden");
                fromDate.setAttribute("name","External_FlightFareSearch_DepartureDate");
                fromDate.value=document.f.dd_A.value+"/"+document.f.mm_A.value+"/"+document.f.yy_A.value;
                f2.appendChild(fromDate);
                
                var toDate = document.createElement("input");
                toDate.setAttribute("type","hidden");
                toDate.setAttribute("name","External_FlightFareSearch_ReturnDate");
                toDate.value=document.f.dd_R.value+"/"+document.f.mm_R.value+"/"+document.f.yy_R.value;
                f2.appendChild(toDate);
                
                var adultsNum = document.createElement("input");
                adultsNum.setAttribute("type","hidden");
                adultsNum.setAttribute("name","External_FlightFareSearch_NumberOfAdults");
                adultsNum.value=document.f.ADULTSelect.value;
                f2.appendChild(adultsNum);
                
                var childrenNum = document.createElement("input");
                childrenNum.setAttribute("type","hidden");
                childrenNum.setAttribute("name","External_FlightFareSearch_NumberOfChilds");
                childrenNum.value=document.f.CHILDSelect.value;
                f2.appendChild(childrenNum);
                
                var infantsNum = document.createElement("input");
                infantsNum.setAttribute("type","hidden");
                infantsNum.setAttribute("name","External_FlightFareSearch_NumberOfInfants");
                infantsNum.value=document.f.INFANTSelect.value;
                f2.appendChild(infantsNum);
                
                var fromAirport = document.createElement("input");
                fromAirport.setAttribute("type","hidden");
                fromAirport.setAttribute("name","External_FlightFareSearch_From");
                fromAirport.value=document.f.da.value;
                f2.appendChild(fromAirport);
               
                var toAirport = document.createElement("input");
                toAirport.setAttribute("type","hidden");
                toAirport.setAttribute("name","External_FlightFareSearch_To");
                toAirport.value=document.f.a.value;
                f2.appendChild(toAirport);
                
                var tripType = document.createElement("input");
                tripType.setAttribute("type","hidden");
                tripType.setAttribute("name","External_FlightFareSearch_SearchType");
                if (ar_checked==1)
                    tripType.value='OneWay';
                else if (ar_checked==0)
                    tripType.value='RoundTrip';
                f2.appendChild(tripType);
                
                var searchTypeByProvider = document.createElement("input");
                searchTypeByProvider.setAttribute("type","hidden");
                searchTypeByProvider.setAttribute("name","External_FlightSearchTypeByProvider");
                searchTypeByProvider.value='AmadeusAndExtProviders';
                f2.appendChild(searchTypeByProvider);
                
                var customLang = document.createElement("input");
                customLang.setAttribute("type","hidden");
                customLang.setAttribute("name","Culture");
                customLang.value=document.f.Culture.value;
                f2.appendChild(customLang);
                
                var externalAccess = document.createElement("input");
                externalAccess.setAttribute("type","hidden");
                externalAccess.setAttribute("name","IsExternalAccess");
                externalAccess.value='true';
                f2.appendChild(externalAccess);
		
		var plusminus3days = document.createElement("input");
		plusminus3days.setAttribute("type","hidden");
                plusminus3days.setAttribute("name","External_FlightFareSearch_Calendar");
		if (document.f.plusminus3days.checked)
			plusminus3days.value='on';
		else
			plusminus3days.value='off';
                f2.appendChild(plusminus3days);
		
                secondFormFragment.appendChild(f2);
                
                document.body.appendChild(secondFormFragment);
            }
	    
	     document.f2.submit();
	   
	    (function($){
		
		
		
		//$('form#f').replaceWith(loader);
		
		
		
		//$("iframe#amresult").attr('src',amadeusUrl);
		/*var amadeusUrl='http://epowerv4.amadeus.com.tr/salina/portals/salina/flightFareSearch.aspx?';
		amadeusUrl+=$("#f2").serialize();
		*/
		
		
		
		
		})(jQuery);
            //document.f2.submit();
            
            
            
            
        }
	
		
	

	function DisabilitaRitorno () {
		document.f.mese_R.disabled = true;
		document.f.dd_R.disabled = true;
	}
	
	function AbilitaRitorno () {
		document.f.mese_R.disabled = false;
		document.f.dd_R.disabled = false;
	}
	
	function getCookie(c_name){
        if (document.cookie.length>0) {
        	c_start=document.cookie.indexOf(c_name + "=")
	        if (c_start!=-1) {
    	        c_start=c_start + c_name.length+1
        	    c_end=document.cookie.indexOf(";",c_start)
            	if (c_end==-1) {
			    	c_end=document.cookie.length
				}
    	        return unescape(document.cookie.substring(c_start,c_end))
        	}
        }
        return ""
    }

	function checkCookie(name) {
		biscotto=getCookie(name)
		if (biscotto!=null || biscotto!=""){
			numTimes=parseInt(biscotto)
			if(numTimes>=3){
				alert("e'almeno la terza volta che cerchi!");
				document.getElementById("divemail").style.visibility= "visible"; 
			}
		}
	}

	function setMeseEAnnoAndata() {
		document.f.mm_A.value = document.f.mese_A.value.substring(4,6);
		document.f.yy_A.value = document.f.mese_A.value.substring(0,4);
	}

	function setMeseEAnnoRitorno() {
		document.f.mm_R.value = document.f.mese_R.value.substring(4,6);
		document.f.yy_R.value = document.f.mese_R.value.substring(0,4);
	}

	function getLayerPositionLeft(livello){

		obj=document.getElementById(livello);
		var curleft = 0;

		if (obj.offsetParent){
			while (obj.offsetParent){
				curleft += obj.offsetLeft
				obj = obj.offsetParent;
			}
		}
		else if (obj.x)
			curleft += obj.x;
		return curleft;
	}
	
	function getLayerPositionTop(livello){

		obj=document.getElementById(livello);
		var curtop = 0;

		if (obj.offsetParent){
			while (obj.offsetParent){
				curtop += obj.offsetTop
				obj = obj.offsetParent;
			}
		}
		else if (obj.x)
			curtop += obj.x;
		return curtop;
	}
	
	
	function apriLayer(livello){
                //document.getElementById(livello).style.visibility= "visible";
		var layer = document.getElementById(livello);
		if(livello=="layer2"){
		//	alert("La posizione corretta: "+getLayerPositionTop("table3"));
			layer.style.top='-130pt'//0;//getLayerPositionTop("table3")-4;
			layer.style.left='0pt';//getLayerPositionLeft("table3")-10;
			jQuery('div.art-nav').css('z-index','-1');
/*
			document.f.dd_A.style.display="none";
			document.f.mm_A.style.display="none";
			document.f.yy_A.style.display="none";

			document.f.dd_R.style.display="none";
			document.f.mm_R.style.display="none";
			document.f.yy_R.style.display="none";

			document.f.ADULTSelect.style.display="none";
			document.f.CHILDSelect.style.display="none";
			document.f.INFANTSelect.style.display="none";
			document.f.CONTINUITYSelect.style.display="none";

*/
			document.f.dd_A.style.visibility="hidden";
			document.f.mm_A.style.visibility="hidden";
			document.f.yy_A.style.visibility="hidden";

			document.f.dd_R.style.visibility="hidden";
			document.f.mm_R.style.visibility="hidden";
			document.f.yy_R.style.visibility="hidden";

			document.f.ADULTSelect.style.visibility="hidden";
			document.f.CHILDSelect.style.visibility="hidden";
			document.f.INFANTSelect.style.visibility="hidden";
	
		}
		layer.style.display="block";
        }

        function conferma(livello){
		
		chiudiLayer(livello);
		aggiorna(document.forms[0].arrivo,document.forms[0].arrivo1);
		aggiorna(document.forms[0].departure,document.forms[0].partenza1);
        }

	function chiudiLayer(livello){
                //document.getElementById(livello).style.visibility= "hidden";

		if(livello=="layer2"){
/*
			document.f.dd_A.style.display="inline";
			document.f.mm_A.style.display="inline";
			document.f.yy_A.style.display="inline";

			document.f.dd_R.style.display="inline";
			document.f.mm_R.style.display="inline";
			document.f.yy_R.style.display="inline";

			document.f.ADULTSelect.style.display="inline";
			document.f.CHILDSelect.style.display="inline";
			document.f.INFANTSelect.style.display="inline";

*/
			document.f.dd_A.style.visibility="visible";
			document.f.mm_A.style.visibility="visible";
			document.f.yy_A.style.visibility="visible";

			document.f.dd_R.style.visibility="visible";
			document.f.mm_R.style.visibility="visible";
			document.f.yy_R.style.visibility="visible";

			document.f.ADULTSelect.style.visibility="visible";
			document.f.CHILDSelect.style.visibility="visible";
			document.f.INFANTSelect.style.visibility="visible";
			
			jQuery('div.art-nav').css('z-index','100');

		}

                document.getElementById(livello).style.display="none";
        }

        function aggiorna(campo,camponuovo){
                camponuovo.value=campo.value;
//                camponuovo.value=campo.value.substring(0,campo.value.indexOf('(')-1);
        }

	


