var destinationMenuId  = 'destinationsMenu';
var destinationInputId = 'txtDestinationNameId';
var spanDestinationNameId = 'spanDestinationName';
var cityInputId = 'txtLocationNameId';
var labelDestinationNameId = 'labelDestinationName';
var txtDestinationName1Id = 'txtDestinationName1';

function showDestinationsMenu(element)
{
    var divObject = document.getElementById( destinationMenuId );
    divObject.style.display  = 'block';
    divObject.style.position = 'absolute';
    
  //  divObject.style.left     = (findPosX(element)+ 210) + 'px'; 
   // divObject.style.top      = (findPosY(element)- 200) + 'px';    
}

function hideDestinations() {
    if (document.getElementById("IMAGESLIDE") != null) { document.getElementById("IMAGESLIDE").style.visibility = 'visible';}
    if (document.getElementById("_ctl1_ddlDepartureAirport") != null) {document.getElementById("_ctl1_ddlDepartureAirport").style.visibility = 'visible';}
    document.getElementById( destinationMenuId ).style.display  = 'none';
    
    //
	//	Turn on all 'drop downs' if not visible
	//
	// works for IE ONLY
	//*********************************
	var objectid;
	var ix;
	if (document.all) {
		for(ix=0; ix <document.all.length; ix++) {
			objectid = document.all[ix].id;
			if (objectid.indexOf("cmb") > 0) {
				document.all[ix].style.visibility = 'visible';
	
			}
		}
	}
}

function setDestination( destVal ) {

   
    if (document.getElementById( txtDestinationNameId ) != null){
        document.getElementById( txtLocationNameId ).style.visibility='hidden';
        document.getElementById( txtLocationNameId ).value = '';
        document.getElementById( txtDestinationNameId ).value = destVal;
    }
    if (document.getElementById( "divDestinationName" ) != null){
        document.getElementById( "divDestinationName" ).innerHTML = destVal;
    }
    if (document.getElementById( "lbCity" ) != null) {
        document.getElementById( "lbCity" ).style.visibility = "hidden";  
    }
    
    hideDestinations();
}

function setDestination_lastminute( destVal ) {

   
    if (document.getElementById( txtDestinationNameId ) != null){
        document.getElementById( txtLocationNameId ).style.visibility='hidden';
        document.getElementById( txtLocationNameId ).value = '';
        document.getElementById( txtDestinationNameId ).value = destVal;
    }
    if (document.getElementById( "divDestinationName" ) != null){
        document.getElementById( "divDestinationName" ).innerHTML = destVal;
    }
    if (document.getElementById( "lbCity" ) != null) {
        document.getElementById( "lbCity" ).style.visibility = "hidden";  
    }
    
    hideDestinations();
}

function setDestinationMultiple(  ) {


    var destList = "";
    var destListName = "";
var cityList = "";
var cityListName = "";
  $("input:checkbox:checked").each(function (i) {
 
        if (this.value.split("_")[0].length >0){
        cityList+=this.value.split("_")[0] + "|"; 
        cityListName+=this.value.split("_")[0] + ","; 
        }
        else{
         destList += this.value.split("_")[1] + "|";       
        destListName += this.value.split("_")[1] + ","; 
        }
             
   
  });
document.getElementById( "divDestinationNameMultiple" ).innerHTML = '';
document.getElementById( txtDestinationNameId ).value = '';
document.getElementById( txtLocationNameId ).value = '';
    if (document.getElementById( "divDestinationName" ) != null){
        document.getElementById( "divDestinationName" ).innerHTML = "Selezione multipla";
        
    }
    if (document.getElementById( "divDestinationNameMultiple" ) != null){
        if (destList.length > 0)
            document.getElementById( "divDestinationNameMultiple" ).innerHTML = destList.substring(0,destList.length - 1);;
        if (destListName.length > 0)
            document.getElementById( txtDestinationNameId ).value = destListName.substring(0,destListName.length - 1);
        
          if (cityList.length > 0)
            document.getElementById( "divDestinationNameMultiple" ).innerHTML += "|"+cityList.substring(0,cityList.length - 1);;
        if (cityListName.length > 0)
            document.getElementById( txtLocationNameId ).value = cityListName.substring(0,cityListName.length - 1);
    }
    //alert(destListName)
    //alert(cityListName)
    hideDestinations();
    
}


function setGroupDestination( groupVal ) {
    location.href='http://lastminute.easymarketcrs.it/vacation/result.aspx?groupId='+groupVal;
}

function setDestinationCity( destVal, cityVal ) {
   

    if(document.getElementById( txtDestinationNameId ) != null){
	    document.getElementById( txtLocationNameId ).style.visibility='visible';
        document.getElementById( txtDestinationNameId ).value = destVal;
      
        document.getElementById( 'lbCity' ).style.display='block';
	    document.getElementById( txtLocationNameId ).value = cityVal;
      if (document.getElementById( "divDestinationName" ) != null){
        document.getElementById( "divDestinationName" ).innerHTML = destVal;
    }
    }
    hideDestinations();
}
