 $(document).ready(function() {
 	setCurrentDate();
	fillLocations(locations);
	/*$('#selArea').addClass('lightgrey');
	$("#selArea").searchA();
	$("#selArea").autocomplete(locations, {
		minChars: 0,
		width: 180,
		max: 500,
		mustMatch:0,
		formatItem: function(row, i, max) {
			//return i + "/" + max + ": \"" + row.name + "\" [" + row.to + "]";
			return row.ort + " " + row.partner;
		},
		formatMatch: function(row, i, max) {
			return row.ort ;
			$("#selArea").removeClass("errorinput");
			$("#errordialog").hide();
		},
		formatResult: function(row) {	
			return row.ort;
		}
	});
	*/
	
});

function fillLocations() {
   var newLocItem = '';
   for (var i = 0; i < locations.length; i++){ 
      newLocItem ='<option value="'+locations[i].tomasid+'">'+locations[i].ort+' '+locations[i].partner+'</option>';
	  $('#selArea').append(newLocItem);
  }
}

function setCurrentDate(){
	var today = new Date();
	document.form.selDay.selectedIndex = today.getDate() - 1;
	document.form.selMonth.selectedIndex = today.getMonth();
	document.form.selYear.selectedIndex = today.getFullYear() - 2009;		
}

function getValue(id, key){
	/*
	
	for (var i = 0; i < Area.length; i++) {
  		if (Area[i]['TomasID'] == id){
			return Area[i][key];
			}
	}
	 */
}

function getTotValue(id, keyId){
	switch(keyId){
		case "WBX00020010000101350":
			key = "ezHotel";
			break;
		case "DEU00000100000218218":
			key = "ezFewo";
			break;
		case "WBX00020010000101352":
			key = "ezPension";
			break;
		case "GER00020060003360028":
			key = "ezPension";
			break;
		case "DEU00000100000218216":
			key = "ezPension";
			break;
		case "WBX00020010000101356":
			key = "ezFeha";
			break;
		case "FIT00020070000446663":
			key = "ezCamp";
			break;
		case "GER00020060003457474":
			key = "ezPension";
			break;
		case "GER00020060003360034":
			key = "ezBauer";
			break;
		case "FIT00020070000000230":
			key = "ezBauer";
			break;
		default:
			key = "ezAll";
			break;
	}
	for (var i = 0; i < Area.length; i++) {
  		if (Area[i]['TomasID'] == id){
			return Area[i][key];
			}
	}
}

function getVacancyLink(){
	var form = document.forms[0];
	var link = "";
	var type = form.bookable.checked;
	var areaID = form.selArea.value;

	// switches between tomas and ez search
	switch (type){
		// if search is set to bookable only
		case true:
	    	link += "TOID=" + strTOID;
	    	link += "&MODULE=MOD_EXEC_VAC"; //suchergebnisse anzeigen
	    	link += "&VAC_PROFILE=" + strVAC_PROFILE; //Vakanzprofil
	    	link += "&LID="+ strLID; // Tracking Benutzer
	    	link += "&NAV=" + strNAV;
	    	link += "&LANG=" + strLang;
	    	link += "&ARR_DAY=" + form.selDay.value;
	    	link += "&ARR_MONTH=" + form.selMonth.value;
	    	link += "&ARR_YEAR=" + form.selYear.value;
	    	link += "&NIGHTS=" + form.selNights.value;
	    	link += "&ADULTS=" + form.selPax.value;
	    	link += "&SP_LOCATION=" + areaID; // Parameter für Gebietssuche
			link += "&SEARCH_FIELD_2=" + form.selTot.value; // Parameter für Touristischer Objekttyp

			// language specific webpage
			switch(strLang){
				case "fr":
					link = getValue(areaID, 'ezDomain') + strIframe + escape(link);
					 break;
				case "en":
					link = getValue(areaID, 'ezDomain') + strIframe + escape(link);
					break;
				default:
					link = strIframe + escape(link);
					break;
			}

			parent.location.href=link;
			return link;
			break;

		// if search is set to non bookable
	  	case false:
			link = getValue(areaID, 'ezDomain');
			link += "/content/view/full/";
			//ezID der Unterkunftsart
			link += getTotValue(areaID, form.selTot.value);
			// ezID der Region
			link += "/(region)/";
			link +=  getValue(areaID, 'ezID');
			// andere Suchparameter
			link += "/(kategorie)/undefined/(ort)/0/(sterne)/-/(list)/1";

			parent.location.href = link;
			break;
	  	}
}

/* Detailsuche im Iframe */
function getDetailVacancyLink(){
	var link = "";
	var form = document.forms[0];
	var areaID = form.selArea.value;

	link += "TOID=" + strTOID;
	link += "&MODULE=MOD_VAC"; //suchmaske anzeigen
	link += "&VAC_PROFILE=" + strVAC_PROFILE; //Vakanzprofil
	link += "&LID="+ strLID; // Tracking Benutzer
	link += "&NAV=" + strNAV;
	link += "&LANG=" + strLang;
	link += "&ARR_DAY=" + form.selDay.value;
	link += "&ARR_MONTH=" + form.selMonth.value;
	link += "&ARR_YEAR=" + form.selYear.value;
	link += "&NIGHTS=" + form.selNights.value;
	link += "&ADULTS=" + form.selPax.value;
	link += "&SP_LOCATION=" + areaID; // Parameter für Gebietssuche
	link += "&SEARCH_FIELD_2=" + form.selTot.value; // Parameter für Touristischer Objekttyp
/*
	switch(strLang){
		case "fr":
				 link = getValue(areaID, 'ezDomain') + strIframe + escape(link);
 				 break;
		case "en":
 				 link = getValue(areaID, 'ezDomain') + strIframe + escape(link);
 				 break;
		default:
 				 link = getValue(areaID, 'ezDomain') + strIframe + escape(link);
				 break;
	}
*/
	//link = getValue(areaID, 'ezDomain') + strIframe + escape(link);
	link = strIframe + escape(link);
	//alert(link);
	parent.location.href=link;
	return link;
}


/** Textanpassung Sprache**/
function changeText(Sprache) {
	switch(Sprache){
		case "de":
		 strLang = "de";
		/* document.getElementById("SuchButton").firstChild.nodeValue = "suchen";
		 document.getElementById("DetailButton").firstChild.nodeValue = "Detailsuche";
		 document.getElementById("OnlineButton").firstChild.nodeValue = "verfügbare Anzeigen";
		 */
		 document.getElementById("Titel").firstChild.nodeValue = "suchen und buchen";
		 /* Oberster Regionen Wert */
		 document.getElementById("selArea").options[0].text = "alle Regionen...";
		 /* Personenanzahl */
		 document.getElementById("selPax").options[0].text = "Personen";
		 document.getElementById("selPax").options[1].text = "1 Person";
		 document.getElementById("selPax").options[2].text = "2 Personen";
		 document.getElementById("selPax").options[3].text = "3 Personen";
		 document.getElementById("selPax").options[4].text = "4 Personen";
		 document.getElementById("selPax").options[5].text = "5 Personen";
		 document.getElementById("selPax").options[6].text = "6 Personen";
		 document.getElementById("selPax").options[7].text = "7 Personen";
		 document.getElementById("selPax").options[8].text = "8 Personen";
		 document.getElementById("selPax").options[9].text = "9 Personen";
		 document.getElementById("selPax").options[10].text = "10 Personen";
		 /* Monate */
		 document.getElementById("selMonth").options[0].text = "Jan";
		 document.getElementById("selMonth").options[1].text = "Feb";
		 document.getElementById("selMonth").options[2].text = "März";
		 document.getElementById("selMonth").options[3].text = "April";
		 document.getElementById("selMonth").options[4].text = "Mai";
		 document.getElementById("selMonth").options[5].text = "Juni";
		 document.getElementById("selMonth").options[6].text = "Juli";
		 document.getElementById("selMonth").options[7].text = "Aug";
		 document.getElementById("selMonth").options[8].text = "Sep";
		 document.getElementById("selMonth").options[9].text = "Okt";
		 document.getElementById("selMonth").options[10].text = "Nov";
		 document.getElementById("selMonth").options[11].text = "Dez";
		 /* Nächte */
		 document.getElementById("selNights").options[0].text = "1 Nacht";
		 document.getElementById("selNights").options[1].text = "2 Nächte";
		 document.getElementById("selNights").options[2].text = "3 Nächte";
		 document.getElementById("selNights").options[3].text = "4 Nächte";
		 document.getElementById("selNights").options[4].text = "5 Nächte";
		 document.getElementById("selNights").options[5].text = "6 Nächte";
		 document.getElementById("selNights").options[6].text = "7 Nächte";
		 document.getElementById("selNights").options[7].text = "8 Nächte";
		 document.getElementById("selNights").options[8].text = "9 Nächte";
		 document.getElementById("selNights").options[9].text = "10 Nächte";
		 document.getElementById("selNights").options[10].text = "11 Nächte";
		 document.getElementById("selNights").options[11].text = "12 Nächte";
		 document.getElementById("selNights").options[12].text = "13 Nächte";
		 document.getElementById("selNights").options[13].text = "14 Nächte";
		 document.getElementById("selNights").options[14].text = "15 Nächte";
		 document.getElementById("selNights").options[15].text = "16 Nächte";
		 document.getElementById("selNights").options[16].text = "17 Nächte";
		 document.getElementById("selNights").options[17].text = "18 Nächte";
		 document.getElementById("selNights").options[18].text = "19 Nächte";
		 document.getElementById("selNights").options[19].text = "20 Nächte";
		 /* Betriebsart */
		 document.getElementById("selTot").options[0].text = "alle Unterkunftsarten";
		 document.getElementById("selTot").options[1].text = "Hotel";
		 document.getElementById("selTot").options[2].text = "Ferienwohnung";
		 document.getElementById("selTot").options[3].text = "Pension/Gästehaus";
		 document.getElementById("selTot").options[4].text = "Gasthof";
		 document.getElementById("selTot").options[5].text = "Ferienhaus";
	 	 document.getElementById("selTot").options[6].text = "Campingplatz";
		 document.getElementById("selTot").options[7].text = "Privatvermieter";
	 	 document.getElementById("selTot").options[8].text = "Bauernhof";
		 document.getElementById("selTot").options[9].text = "Winzerhof";

		 break;

		case "en":
		 strLang = "en";
		 /*document.getElementById("SuchButton").firstChild.nodeValue = "search";
		 document.getElementById("DetailButton").firstChild.nodeValue = "more options";
		 document.getElementById("OnlineButton").firstChild.nodeValue = "show available";
		 */
		 document.getElementById("Titel").firstChild.nodeValue = "search & book";
		 /* Oberster Regionen Wert */
		 document.getElementById("selArea").options[0].text = "all regions";

		 document.getElementById("selPax").options[0].text = "persons";
		 document.getElementById("selPax").options[1].text = "1 person";
		 document.getElementById("selPax").options[2].text = "2 persons";
		 document.getElementById("selPax").options[3].text = "3 persons";
		 document.getElementById("selPax").options[4].text = "4 persons";
		 document.getElementById("selPax").options[5].text = "5 persons";
		 document.getElementById("selPax").options[6].text = "6 persons";
		 document.getElementById("selPax").options[7].text = "7 persons";
		 document.getElementById("selPax").options[8].text = "8 persons";
		 document.getElementById("selPax").options[9].text = "9 persons";
		 document.getElementById("selPax").options[10].text = "10 persons";
		 /* Monate */

		 document.getElementById("selMonth").options[0].text = "jan";
		 document.getElementById("selMonth").options[1].text = "feb";
		 document.getElementById("selMonth").options[2].text = "mar";
		 document.getElementById("selMonth").options[3].text = "apr";
		 document.getElementById("selMonth").options[4].text = "may";
		 document.getElementById("selMonth").options[5].text = "jun";
		 document.getElementById("selMonth").options[6].text = "jul";
		 document.getElementById("selMonth").options[7].text = "aug";
		 document.getElementById("selMonth").options[8].text = "sep";
		 document.getElementById("selMonth").options[9].text = "oct";
		 document.getElementById("selMonth").options[10].text = "nov";
		 document.getElementById("selMonth").options[11].text = "dec";
		 /* Nächte */
		 document.getElementById("selNights").options[0].text = "1 night";
		 document.getElementById("selNights").options[1].text = "2 nights";
		 document.getElementById("selNights").options[2].text = "3 nights";
		 document.getElementById("selNights").options[3].text = "4 nights";
		 document.getElementById("selNights").options[4].text = "5 nights";
		 document.getElementById("selNights").options[5].text = "6 nights";
		 document.getElementById("selNights").options[6].text = "7 nights";
		 document.getElementById("selNights").options[7].text = "8 nights";
		 document.getElementById("selNights").options[8].text = "9 nights";
		 document.getElementById("selNights").options[9].text = "10 nights";
		 document.getElementById("selNights").options[10].text = "11 nights";
		 document.getElementById("selNights").options[11].text = "12 nights";
		 document.getElementById("selNights").options[12].text = "13 nights";
		 document.getElementById("selNights").options[13].text = "14 nights";
		 document.getElementById("selNights").options[14].text = "15 nights";
		 document.getElementById("selNights").options[15].text = "16 nights";
		 document.getElementById("selNights").options[16].text = "17 nights";
		 document.getElementById("selNights").options[17].text = "18 nights";
		 document.getElementById("selNights").options[18].text = "19 nights";
		 document.getElementById("selNights").options[19].text = "20 nights";
		 /* Betriebsart */

		 document.getElementById("selTot").options[0].text = "all accomodation types";
		 document.getElementById("selTot").options[1].text = "Hotel";
		 document.getElementById("selTot").options[2].text = "Holiday apartment";
		 document.getElementById("selTot").options[3].text = "Pension/Guest house";
		 document.getElementById("selTot").options[4].text = "Inn";
		 document.getElementById("selTot").options[5].text = "Holiday house";
	 	 document.getElementById("selTot").options[6].text = "Campground";
		 document.getElementById("selTot").options[7].text = "Private landlords";
	 	 document.getElementById("selTot").options[8].text = "Farm";
		 document.getElementById("selTot").options[9].text = "Winegrower yard";
		 break;
		case "fr":
		 strLang = "fr";
		/* document.getElementById("SuchButton").firstChild.nodeValue = "rechercher";
		 document.getElementById("DetailButton").firstChild.nodeValue = "autres critères";
		 document.getElementById("OnlineButton").firstChild.nodeValue = "voir disponible";
		*/
		 document.getElementById("Titel").firstChild.nodeValue = "réserver";
		 /* Oberster Regionen Wert */
		 document.getElementById("selArea").options[0].text = "tous les Régions";

		 document.getElementById("selPax").options[0].text = "Personnes";
		 document.getElementById("selPax").options[1].text = "1 Personne";
		 document.getElementById("selPax").options[2].text = "2 Personnes";
		 document.getElementById("selPax").options[3].text = "3 Personnes";
		 document.getElementById("selPax").options[4].text = "4 Personnes";
		 document.getElementById("selPax").options[5].text = "5 Personnes";
		 document.getElementById("selPax").options[6].text = "6 Personnes";
		 document.getElementById("selPax").options[7].text = "7 Personnes";
		 document.getElementById("selPax").options[8].text = "8 Personnes";
		 document.getElementById("selPax").options[9].text = "9 Personnes";
		 document.getElementById("selPax").options[10].text = "10 Personnes";
		 /* Monate */
		 document.getElementById("selMonth").options[0].text = "Janv";
		 document.getElementById("selMonth").options[1].text = "Févr";
		 document.getElementById("selMonth").options[2].text = "Mars";
		 document.getElementById("selMonth").options[3].text = "Avr";
		 document.getElementById("selMonth").options[4].text = "Mai";
		 document.getElementById("selMonth").options[5].text = "Juin";
		 document.getElementById("selMonth").options[6].text = "Juill";
		 document.getElementById("selMonth").options[7].text = "Août";
		 document.getElementById("selMonth").options[8].text = "Sept";
		 document.getElementById("selMonth").options[9].text = "Oct";
		 document.getElementById("selMonth").options[10].text = "Nov";
		 document.getElementById("selMonth").options[11].text = "Déc";
		 /* Nächte */
		 document.getElementById("selNights").options[0].text = "Une Nuit";
		 document.getElementById("selNights").options[1].text = "2 Nuits";
		 document.getElementById("selNights").options[2].text = "3 Nuits";
		 document.getElementById("selNights").options[3].text = "4 Nuits";
		 document.getElementById("selNights").options[4].text = "5 Nuits";
		 document.getElementById("selNights").options[5].text = "6 Nuits";
		 document.getElementById("selNights").options[6].text = "7 Nuits";
		 document.getElementById("selNights").options[7].text = "8 Nuits";
		 document.getElementById("selNights").options[8].text = "9 Nuits";
		 document.getElementById("selNights").options[9].text = "10 Nuits";
		 document.getElementById("selNights").options[10].text = "11 Nuits";
		 document.getElementById("selNights").options[11].text = "12 Nuits";
		 document.getElementById("selNights").options[12].text = "13 Nuits";
		 document.getElementById("selNights").options[13].text = "14 Nuits";
		 document.getElementById("selNights").options[14].text = "15 Nuits";
		 document.getElementById("selNights").options[15].text = "16 Nuits";
		 document.getElementById("selNights").options[16].text = "17 Nuits";
		 document.getElementById("selNights").options[17].text = "18 Nuits";
		 document.getElementById("selNights").options[18].text = "19 Nuits";
		 document.getElementById("selNights").options[19].text = "20 Nuits";
		 /* Betriebsart */
		 document.getElementById("selTot").options[0].text = "tous types d'hébergement";
		 document.getElementById("selTot").options[1].text = "Hôtel";
		 document.getElementById("selTot").options[2].text = "Appartement";
		 document.getElementById("selTot").options[3].text = "Pension/Maison d'hôte";
		 document.getElementById("selTot").options[4].text = "Auberge";
		 document.getElementById("selTot").options[5].text = "Maison de vacances";
	 	 document.getElementById("selTot").options[6].text = "Camping";
		 document.getElementById("selTot").options[7].text = "Propriétaires privés";
	 	 document.getElementById("selTot").options[8].text = "Ferme";
		 document.getElementById("selTot").options[9].text = "Ferme viticole";

		break;
		default:
 		strLang = "de";
		break;
	}

}

