// -----------------
// SearchEngineFormWidget script
// -----------------

var FRANCE = "france";
var FOREIGN = "foreign";
var ALL = "all";



/**
 * Add a discount widget component into a given element
 */

function addSearchEngineFormWidgetToElement(elementIdToIncludeIn, type, dns, filterList, withLabel, json, idPartner, idPrivateWhiteLabel, suffixe) {
	
	// Initialize variables
	var element = document.getElementById(elementIdToIncludeIn);
	
	if(type == FOREIGN || json.selectableFrenchDestinations == null || json.selectableFrenchDestinations.length == 0)
		element.innerHTML = getSearchEngineForeignForm(filterList, withLabel, json, dns, idPartner, idPrivateWhiteLabel, suffixe);
	else if(type == FRANCE)
		element.innerHTML = getSearchEngineFrenchForm(filterList, withLabel, json, dns, idPartner, idPrivateWhiteLabel, suffixe);
	else if(type == ALL) {
		var html = [];
		html.push('<div id="'+suffixe+'Header">');
		html.push('  <div id="'+suffixe+'ForeignHeader" class="selected" onClick="document.getElementById(\''+suffixe+'ForeignForm\').style.display=\'block\';document.getElementById(\''+suffixe+'FrenchForm\').style.display=\'none\';document.getElementById(\''+suffixe+'ForeignHeader\').className=\'selected\';document.getElementById(\''+suffixe+'FrenchHeader\').className=\'\';">A l\'&eacute;tranger</div>');
		html.push('  <div id="'+suffixe+'FrenchHeader" class="" onClick="document.getElementById(\''+suffixe+'ForeignForm\').style.display=\'none\';document.getElementById(\''+suffixe+'FrenchForm\').style.display=\'block\';document.getElementById(\''+suffixe+'FrenchHeader\').className=\'selected\';document.getElementById(\''+suffixe+'ForeignHeader\').className=\'\';">En France</div>');
		html.push('</div>');
		html.push('<div id="'+suffixe+'Content">');
		html.push('  <div id="'+suffixe+'ForeignForm">');
		html.push(    getSearchEngineForeignForm(filterList, withLabel, json, dns, idPartner, idPrivateWhiteLabel, suffixe));
		html.push('  </div>');
		html.push('  <div id="'+suffixe+'FrenchForm" style="display:none">');
		html.push(    getSearchEngineFrenchForm(filterList, withLabel, json, dns, idPartner, idPrivateWhiteLabel, suffixe));
		html.push('  </div>');
		html.push('</div>');
		element.innerHTML = html.join('');
	}
	
}

function getSearchEngineForeignForm(filterList, withLabel, json, dns, idPartner, idPrivateWhiteLabel, suffixe) {

	var selectableCountries = json.selectableCountries;
	var selectableDepartureCities = json.selectableDepartureCities;
	var selectableStars = json.selectableStars;
	var selectableMealPlans = json.selectableForeignMealPlans;
	var selectableDurations = json.selectableForeignDurations;
	var selectableTypeProducts = json.selectableForeignTypeProducts;
	var selectableTopics = json.selectableForeignTopics;
	var selectableSuppliers = json.selectableForeignSuppliers;
	var selectableDiscountPercentages = json.selectableForeignDiscountPercentages;
	var selectableDepartureMonths = json.selectableForeignDepartureMonths;
	var selectableSchoolHolidays = json.selectableForeignSchoolHolidays;


	// Set the page content
	var html = [];
	var url = dns+'SearchEngineController';


	if(idPartner != null && idPartner != '' && idPartner != "undefined")
		url = url+'?idPartner='+idPartner;
	if(idPrivateWhiteLabel != null && idPrivateWhiteLabel != '' && idPrivateWhiteLabel != "undefined")
		url = url+'?idPrivateWhiteLabel='+idPrivateWhiteLabel;

	html.push('<form action="'+url+'" methode="post" id="'+suffixe+'fillTextForm">');

	for (var j = 0, len = filterList.length; j < len; ++j) {
		var filter = filterList[j];

		if(filter == 'country') {
			html.push('<div id="'+suffixe+'divcountry">');
			if(withLabel == 'true') {
				html.push('<label id="'+suffixe+'labelcountry">Destination</label>');
				html.push('<select id="'+suffixe+'selectcountry" name="country">');
				html.push('<option class="defaultOption" value="Indifferent">Indiff&eacute;rent</option>');
			}
			else {
				html.push('<select id="'+suffixe+'selectcountry" name="country">');
				html.push('<option class="defaultOption" value="Indifferent">Destination</option>');
			}
			if(selectableCountries != null) {
				for (var i = 0, len1 = selectableCountries.length; i < len1; ++i) { 
					var country = selectableCountries[i];
					if(country.name.charCodeAt(0) != 32 && country.name.charCodeAt(0) != 45 && country.name != "Indifférent")
						html.push('<option class="upperCase" value="'+country.code+'">'+country.name+'</option>');
					else
						html.push('<option value="'+country.code+'">'+country.name+'</option>');
				}
			}
			html.push('</select>');
			html.push('</div>');
		}

		else if(filter == 'mealPlan') {
			html.push('<div id="'+suffixe+'divmealPlan">');
			if(withLabel == 'true') {
				html.push('<label id="'+suffixe+'labelmealPlan">Prestation</label>');
				html.push('<select id="'+suffixe+'selectmealPlan" name="mealPlan">');
				html.push('<option class="defaultOption" value="Indifferent">Indiff&eacute;rent</option>');
			}
			else {
				html.push('<select id="'+suffixe+'selectmealPlan" name="mealPlan">');
				html.push('<option class="defaultOption" value="Indifferent">Prestation</option>');
			}
			if(selectableMealPlans != null) {
				for (var i = 0, len1 = selectableMealPlans.length; i < len1; ++i) { 
					var mealPlan = selectableMealPlans[i];
					html.push('<option value="'+mealPlan.code+'">'+mealPlan.name+'</option>');
				}
			}
			html.push('</select>');
			html.push('</div>');
		}

		else if(filter == 'departureCity') {
			html.push('<div id="'+suffixe+'divdepartureCity">');
			if(withLabel == 'true') {
				html.push('<label id="'+suffixe+'labeldepartureCity">Ville de d&eacute;part</label>');
				html.push('<select id="'+suffixe+'selectdepartureCity" name="departureCity">');
				html.push('<option class="defaultOption" value="Indifferent">Indiff&eacute;rent</option>');
			}
			else {
				html.push('<select id="'+suffixe+'selectpartureCity" name="departureCity">');
				html.push('<option class="defaultOption" value="Indifferent">Ville de d&eacute;part</option>');
			}
			if(selectableDepartureCities != null && selectableDepartureCities.length != 0) {
				html.push('<optgroup label="Top villes de d&eacute;part">');
				for (var i = 0, len1 = selectableDepartureCities.top.length; i < len1; ++i) { 
					var departureCity = selectableDepartureCities.top[i];
					html.push('<option value="'+departureCity.code+'">'+departureCity.name+'</option>');
				}
				html.push('</optgroup>');
			}
			if(selectableDepartureCities != null) {
				html.push('<optgroup label="Toutes les villes">');
				for (var i = 0, len1 = selectableDepartureCities.all.length; i < len1; ++i) { 
					var departureCity = selectableDepartureCities.all[i];
					html.push('<option value="'+departureCity.code+'">'+departureCity.name+'</option>');
				}
				html.push('</optgroup>');
			}
			html.push('</select>');
			html.push('</div>');
		}

		else if(filter == 'duration') {
			html.push('<div id="'+suffixe+'divduration">');
			if(withLabel == 'true') {
				html.push('<label id="'+suffixe+'labelduration">Dur&eacute;e</label>');
				html.push('<select id="'+suffixe+'selectduration" name="duration">');
				html.push('<option class="defaultOption" value="Indifferent">Indiff&eacute;rent</option>');
			}
			else {
				html.push('<select id="'+suffixe+'selectduration" name="duration">');
				html.push('<option class="defaultOption" value="Indifferent">Dur&eacute;e</option>');
			}
			if(selectableDurations != null) {
				for (var i = 0, len1 = selectableDurations.length; i < len1; ++i) {
					var duration = selectableDurations[i];
					html.push('<option value="'+duration.code+'">'+duration.name+'</option>');
				}
			}
			html.push('</select>');
			html.push('</div>');
		}

		else if(filter == 'typeProduct') {
			html.push('<div id="'+suffixe+'divtypeProduct">');
			if(withLabel == 'true') {
				html.push('<label id="'+suffixe+'labeltypeProduct">Type de produit</label>');
				html.push('<select id="'+suffixe+'selecttypeProduct" name="typeProduct">');
				html.push('<option class="defaultOption" value="Indifferent">Indiff&eacute;rent</option>');
			}
			else {
				html.push('<select id="'+suffixe+'selecttypeProduct" name="typeProduct">');
				html.push('<option class="defaultOption" value="Indifferent">Type de produit</option>');
			}
			if(selectableTypeProducts != null) {
				for (var i = 0, len1 = selectableTypeProducts.length; i < len1; ++i) { 
					var typeProduct = selectableTypeProducts[i];
					html.push('<option value="'+typeProduct.code+'">'+typeProduct.name+'</option>');
				}
			}
			html.push('</select>');
			html.push('</div>');
		}

		else if(filter == 'topic') {
			html.push('<div id="'+suffixe+'divtopic">');
			if(withLabel == 'true') {
				html.push('<label id="'+suffixe+'labeltopic">Th&eacute;matique</label>');
				html.push('<select id="'+suffixe+'selecttopic" name="topic">');
				html.push('<option class="defaultOption" value="Indifferent">Indiff&eacute;rent</option>');
			}
			else {
				html.push('<select id="'+suffixe+'selecttopic" name="topic">');
				html.push('<option class="defaultOption" value="Indifferent">Th&eacute;matique</option>');
			}
			if(selectableTopics != null) {
				for (var i = 0, len1 = selectableTopics.length; i < len1; ++i) {
					var topic = selectableTopics[i];
					html.push('<option value="'+topic.code+'">'+topic.name+'</option>');
				}
			}
			html.push('</select>');
			html.push('</div>');
		}

		else if(filter == 'star') {
			html.push('<div id="'+suffixe+'divstar">');
			if(withLabel == 'true') {
				html.push('<label id="'+suffixe+'labelstar">Cat&eacute;gorie</label>');
				html.push('<select id="'+suffixe+'selectstar" name="star">');
				html.push('<option class="defaultOption" value="Indifferent">Indiff&eacute;rent</option>');
			}
			else {
				html.push('<select id="'+suffixe+'selectstar" name="star">');
				html.push('<option class="defaultOption" value="Indifferent">Cat&eacute;gorie</option>');
			}
			if(selectableStars != null) {
				for (var i = 0, len1 = selectableStars.length; i < len1; ++i) { 
					var star = selectableStars[i];
					html.push('<option value="'+star.code+'">'+star.name+'</option>');
				}
			}
			html.push('</select>');
			html.push('</div>');
		}

		else if(filter == 'supplier') {
			html.push('<div id="'+suffixe+'divsupplier">');
			if(withLabel == 'true') {
				html.push('<label id="'+suffixe+'labelsupplier">Tour op&eacute;rateur</label>');
				html.push('<select id="'+suffixe+'selectsupplier" name="supplier">');
				html.push('<option class="defaultOption" value="Indifferent">Indiff&eacute;rent</option>');
			}
			else {
				html.push('<select id="'+suffixe+'selectsupplier" name="supplier">');
				html.push('<option class="defaultOption" value="Indifferent">Tour op&eacute;rateur</option>');
			}
			if(selectableSuppliers != null) {
				for (var i = 0, len1 = selectableSuppliers.length; i < len1; ++i) {
					var supplier = selectableSuppliers[i];
					html.push('<option value="'+supplier.code+'">'+supplier.name+'</option>');
				}
			}
			html.push('</select>');
			html.push('</div>');
		}

		else if(filter == 'discountPercentage') {
			html.push('<div id="'+suffixe+'divdiscountPercentage">');
			if(withLabel == 'true') {
				html.push('<label id="'+suffixe+'labeldiscountPercentage">Promotion</label>');
				html.push('<select id="'+suffixe+'selectdiscountPercentage" name="discountPercentage">');
				html.push('<option class="defaultOption" value="Indifferent">Indiff&eacute;rent</option>');
			}
			else {
				html.push('<select id="'+suffixe+'selectdiscountPercentage" name="discountPercentage">');
				html.push('<option class="defaultOption" value="Indifferent">Promotion</option>');
			}
			if(selectableDiscountPercentages != null) {
				for (var i = 0, len1 = selectableDiscountPercentages.length; i < len1; ++i) {
					var discountPercentage = selectableDiscountPercentages[i];
					html.push('<option value="'+discountPercentage.code+'">'+discountPercentage.name+'</option>');
				}
			}
			html.push('</select>');
			html.push('</div>');
		}

		else if(filter == 'departureMonth') {
			html.push('<div id="'+suffixe+'divdepartureMonth">');
			if(withLabel == 'true') {
				html.push('<label id="'+suffixe+'labeldepartureMonth">Mois de d&eacute;part</label>');
				html.push('<select id="'+suffixe+'selectdepartureMonth" name="departureMonth">');
				html.push('<option class="defaultOption" value="Indifferent">Indiff&eacute;rent</option>');
			}
			else {
				html.push('<select id="'+suffixe+'selectdepartureMonth" name="departureMonth">');
				html.push('<option class="defaultOption" value="Indifferent">Mois de d&eacute;part</option>');
			}
			if(selectableDepartureMonths != null) {
				for (var i = 0, len1 = selectableDepartureMonths.length; i < len1; ++i) {
					var departureMonth = selectableDepartureMonths[i];
					html.push('<option value="'+departureMonth.code+'">'+departureMonth.name+'</option>');
				}
			}
			html.push('</select>');
			html.push('</div>');
		}

		else if(filter == 'schoolHoliday') {
			html.push('<div id="'+suffixe+'divschoolHoliday">');
			if(withLabel == 'true') {
				html.push('<label id="'+suffixe+'labelschoolHoliday">P&eacute;riode scolaire</label>');
				html.push('<select id="'+suffixe+'selectschoolHoliday" name="schoolHolidays">');
				html.push('<option class="defaultOption" value="Indifferent">Indiff&eacute;rent</option>');
			}
			else {
				html.push('<select id="'+suffixe+'selectschoolHoliday" name="schoolHolidays">');
				html.push('<option class="defaultOption" value="Indifferent">P&eacute;riode scolaire</option>');
			}
			if(selectableSchoolHolidays != null) {
				for (var i = 0, len1 = selectableSchoolHolidays.length; i < len1; ++i) {
					var schoolHoliday = selectableSchoolHolidays[i];
					html.push('<option value="'+schoolHoliday.code+'">'+schoolHoliday.name+'</option>');
				}
			}
			html.push('</select>');
			html.push('</div>');
		}
	}

	html.push('<input type="hidden" name="actionType" value="generalWithRedirect" />');
	html.push('<input type="hidden" name="searchEngineType" value="foreign" />');
	html.push('<input id="'+suffixe+'fullTextSubmit" class="button" type="submit" name="Chercher" value="Chercher" />');
	html.push('</form>');

	return html.join('');
}

function getSearchEngineFrenchForm(filterList, withLabel, json, dns, idPartner, idPrivateWhiteLabel, suffixe) {

	var selectableFrenchDestinations = json.selectableFrenchDestinations;
	var selectableTypeHomeRentals = json.selectableTypeHomeRentals;
	var selectableAccommodationCapacities = json.selectableAccommodationCapacities;
	var selectableMealPlans = json.selectableFrenchMealPlans;
	var selectableDurations = json.selectableFrenchDurations;
	var selectableTypeProducts = json.selectableFrenchTypeProducts;
	var selectableTopics = json.selectableFrenchTopics;
	var selectableSuppliers = json.selectableFrenchSuppliers;
	var selectableDiscountPercentages = json.selectableFrenchDiscountPercentages;
	var selectableDepartureMonths = json.selectableFrenchDepartureMonths;
	var selectableSchoolHolidays = json.selectableFrenchSchoolHolidays;


	// Set the page content
	var html = [];
	var url = dns+'SearchEngineController';


	if(idPartner != null && idPartner != '' && idPartner != "undefined")
		url = url+'?idPartner='+idPartner;
	if(idPrivateWhiteLabel != null && idPrivateWhiteLabel != '' && idPrivateWhiteLabel != "undefined")
		url = url+'?idPrivateWhiteLabel='+idPrivateWhiteLabel;

	html.push('<form action="'+url+'" methode="post" id="'+suffixe+'fillTextForm">');

	for (var j = 0, len = filterList.length; j < len; ++j) {
		var filter = filterList[j];

		if(filter == 'frenchDestination') {
			html.push('<div id="'+suffixe+'divfrenchDestination">');
			if(withLabel == 'true') {
				html.push('<label id="'+suffixe+'labelfrenchDestination">Destination</label>');
				html.push('<select id="'+suffixe+'selectfrenchDestination" name="france">');
				html.push('<option class="defaultOption" value="Indifferent">Indiff&eacute;rent</option>');
			}
			else {
				html.push('<select id="'+suffixe+'selectfrenchDestination" name="france">');
				html.push('<option class="defaultOption" value="Indifferent">Destination</option>');
			}
			if(selectableFrenchDestinations != null) {
				for (var i = 0, len1 = selectableFrenchDestinations.length; i < len1; ++i) { 
					var frenchDestination = selectableFrenchDestinations[i];
					html.push('<option value="'+frenchDestination.code+'">'+frenchDestination.name+'</option>');
				}
			}
			html.push('</select>');
			html.push('</div>');
		}
		
		if(filter == 'typeHomeRental') {
			html.push('<div id="'+suffixe+'divtypeHomeRental">');
			if(withLabel == 'true') {
				html.push('<label id="'+suffixe+'labeltypeHomeRental">Destination</label>');
				html.push('<select id="'+suffixe+'selecttypeHomeRental" name="typeHomeRental">');
				html.push('<option class="defaultOption" value="Indifferent">Indiff&eacute;rent</option>');
			}
			else {
				html.push('<select id="'+suffixe+'selecttypeHomeRental" name="typeHomeRental">');
				html.push('<option class="defaultOption" value="Indifferent">Choix de l\'h&eacute;bergement</option>');
			}
			if(selectableTypeHomeRentals != null) {
				for (var i = 0, len1 = selectableTypeHomeRentals.length; i < len1; ++i) { 
					var typeHomeRental = selectableTypeHomeRentals[i];
					html.push('<option value="'+typeHomeRental.code+'">'+typeHomeRental.name+'</option>');
				}
			}
			html.push('</select>');
			html.push('</div>');
		}
		
		if(filter == 'accommodationCapacity') {
			html.push('<div id="'+suffixe+'divaccommodationCapacity">');
			if(withLabel == 'true') {
				html.push('<label id="'+suffixe+'labelaccommodationCapacity">Destination</label>');
				html.push('<select id="'+suffixe+'selectaccommodationCapacity" name="accommodationCapacity">');
				html.push('<option class="defaultOption" value="Indifferent">Indiff&eacute;rent</option>');
			}
			else {
				html.push('<select id="'+suffixe+'selectaccommodationCapacity" name="accommodationCapacity">');
				html.push('<option class="defaultOption" value="Indifferent">Nombre de personnes</option>');
			}
			if(selectableAccommodationCapacities != null) {
				for (var i = 0, len1 = selectableAccommodationCapacities.length; i < len1; ++i) { 
					var accommodationCapacity = selectableAccommodationCapacities[i];
					html.push('<option value="'+accommodationCapacity.code+'">'+accommodationCapacity.name+'</option>');
				}
			}
			html.push('</select>');
			html.push('</div>');
		}

		else if(filter == 'mealPlan') {
			html.push('<div id="'+suffixe+'divmealPlan">');
			if(withLabel == 'true') {
				html.push('<label id="'+suffixe+'labelmealPlan">Prestation</label>');
				html.push('<select id="'+suffixe+'selectmealPlan" name="mealPlan">');
				html.push('<option class="defaultOption" value="Indifferent">Indiff&eacute;rent</option>');
			}
			else {
				html.push('<select id="'+suffixe+'selectmealPlan" name="mealPlan">');
				html.push('<option class="defaultOption" value="Indifferent">Prestation</option>');
			}
			if(selectableMealPlans != null) {
				for (var i = 0, len1 = selectableMealPlans.length; i < len1; ++i) { 
					var mealPlan = selectableMealPlans[i];
					html.push('<option value="'+mealPlan.code+'">'+mealPlan.name+'</option>');
				}
			}
			html.push('</select>');
			html.push('</div>');
		}

		else if(filter == 'duration') {
			html.push('<div id="'+suffixe+'divduration">');
			if(withLabel == 'true') {
				html.push('<label id="'+suffixe+'labelduration">Dur&eacute;e</label>');
				html.push('<select id="'+suffixe+'selectduration" name="duration">');
				html.push('<option class="defaultOption" value="Indifferent">Indiff&eacute;rent</option>');
			}
			else {
				html.push('<select id="'+suffixe+'selectduration" name="duration">');
				html.push('<option class="defaultOption" value="Indifferent">Dur&eacute;e</option>');
			}
			if(selectableDurations != null) {
				for (var i = 0, len1 = selectableDurations.length; i < len1; ++i) {
					var duration = selectableDurations[i];
					html.push('<option value="'+duration.code+'">'+duration.name+'</option>');
				}
			}
			html.push('</select>');
			html.push('</div>');
		}

		else if(filter == 'typeProduct') {
			html.push('<div id="'+suffixe+'divtypeProduct">');
			if(withLabel == 'true') {
				html.push('<label id="'+suffixe+'labeltypeProduct">Type de produit</label>');
				html.push('<select id="'+suffixe+'selecttypeProduct" name="typeProduct">');
				html.push('<option class="defaultOption" value="Indifferent">Indiff&eacute;rent</option>');
			}
			else {
				html.push('<select id="'+suffixe+'selecttypeProduct" name="typeProduct">');
				html.push('<option class="defaultOption" value="Indifferent">Type de produit</option>');
			}
			if(selectableTypeProducts != null) {
				for (var i = 0, len1 = selectableTypeProducts.length; i < len1; ++i) { 
					var typeProduct = selectableTypeProducts[i];
					html.push('<option value="'+typeProduct.code+'">'+typeProduct.name+'</option>');
				}
			}
			html.push('</select>');
			html.push('</div>');
		}

		else if(filter == 'topic') {
			html.push('<div id="'+suffixe+'divtopic">');
			if(withLabel == 'true') {
				html.push('<label id="'+suffixe+'labeltopic">Th&eacute;matique</label>');
				html.push('<select id="'+suffixe+'selecttopic" name="topic">');
				html.push('<option class="defaultOption" value="Indifferent">Indiff&eacute;rent</option>');
			}
			else {
				html.push('<select id="'+suffixe+'selecttopic" name="topic">');
				html.push('<option class="defaultOption" value="Indifferent">Th&eacute;matique</option>');
			}
			if(selectableTopics != null) {
				for (var i = 0, len1 = selectableTopics.length; i < len1; ++i) {
					var topic = selectableTopics[i];
					html.push('<option value="'+topic.code+'">'+topic.name+'</option>');
				}
			}
			html.push('</select>');
			html.push('</div>');
		}

		else if(filter == 'supplier') {
			html.push('<div id="'+suffixe+'divsupplier">');
			if(withLabel == 'true') {
				html.push('<label id="'+suffixe+'labelsupplier">Tour op&eacute;rateur</label>');
				html.push('<select id="'+suffixe+'selectsupplier" name="supplier">');
				html.push('<option class="defaultOption" value="Indifferent">Indiff&eacute;rent</option>');
			}
			else {
				html.push('<select id="'+suffixe+'selectsupplier" name="supplier">');
				html.push('<option class="defaultOption" value="Indifferent">Tour op&eacute;rateur</option>');
			}
			if(selectableSuppliers != null) {
				for (var i = 0, len1 = selectableSuppliers.length; i < len1; ++i) {
					var supplier = selectableSuppliers[i];
					html.push('<option value="'+supplier.code+'">'+supplier.name+'</option>');
				}
			}
			html.push('</select>');
			html.push('</div>');
		}

		else if(filter == 'discountPercentage') {
			html.push('<div id="'+suffixe+'divdiscountPercentage">');
			if(withLabel == 'true') {
				html.push('<label id="'+suffixe+'labeldiscountPercentage">Promotion</label>');
				html.push('<select id="'+suffixe+'selectdiscountPercentage" name="discountPercentage">');
				html.push('<option class="defaultOption" value="Indifferent">Indiff&eacute;rent</option>');
			}
			else {
				html.push('<select id="'+suffixe+'selectdiscountPercentage" name="discountPercentage">');
				html.push('<option class="defaultOption" value="Indifferent">Promotion</option>');
			}
			if(selectableDiscountPercentages != null) {
				for (var i = 0, len1 = selectableDiscountPercentages.length; i < len1; ++i) {
					var discountPercentage = selectableDiscountPercentages[i];
					html.push('<option value="'+discountPercentage.code+'">'+discountPercentage.name+'</option>');
				}
			}
			html.push('</select>');
			html.push('</div>');
		}

		else if(filter == 'departureMonth') {
			html.push('<div id="'+suffixe+'divdepartureMonth">');
			if(withLabel == 'true') {
				html.push('<label id="'+suffixe+'labeldepartureMonth">Mois de d&eacute;part</label>');
				html.push('<select id="'+suffixe+'selectdepartureMonth" name="departureMonth">');
				html.push('<option class="defaultOption" value="Indifferent">Indiff&eacute;rent</option>');
			}
			else {
				html.push('<select id="'+suffixe+'selectdepartureMonth" name="departureMonth">');
				html.push('<option class="defaultOption" value="Indifferent">Mois de d&eacute;part</option>');
			}
			if(selectableDepartureMonths != null) {
				for (var i = 0, len1 = selectableDepartureMonths.length; i < len1; ++i) {
					var departureMonth = selectableDepartureMonths[i];
					html.push('<option value="'+departureMonth.code+'">'+departureMonth.name+'</option>');
				}
			}
			html.push('</select>');
			html.push('</div>');
		}

		else if(filter == 'schoolHoliday') {
			html.push('<div id="'+suffixe+'divschoolHoliday">');
			if(withLabel == 'true') {
				html.push('<label id="'+suffixe+'labelschoolHoliday">P&eacute;riode scolaire</label>');
				html.push('<select id="'+suffixe+'selectschoolHoliday" name="schoolHolidays">');
				html.push('<option class="defaultOption" value="Indifferent">Indiff&eacute;rent</option>');
			}
			else {
				html.push('<select id="'+suffixe+'selectschoolHoliday" name="schoolHolidays">');
				html.push('<option class="defaultOption" value="Indifferent">P&eacute;riode scolaire</option>');
			}
			if(selectableSchoolHolidays != null) {
				for (var i = 0, len1 = selectableSchoolHolidays.length; i < len1; ++i) {
					var schoolHoliday = selectableSchoolHolidays[i];
					html.push('<option value="'+schoolHoliday.code+'">'+schoolHoliday.name+'</option>');
				}
			}
			html.push('</select>');
			html.push('</div>');
		}
	}

	html.push('<input type="hidden" name="actionType" value="generalWithRedirect" />');
	html.push('<input type="hidden" name="searchEngineType" value="france" />');
	html.push('<input id="'+suffixe+'fullTextSubmit" class="button" type="submit" name="Chercher" value="Chercher" />');
	html.push('</form>');

	return html.join('');
}


//create a namespace for this example:
YAHOO.namespace("rpc.SearchEngineFormWidget");

YAHOO.rpc.SearchEngineFormWidget = function(dns, filterList) {

	//set up some shortcuts in case our typing fingers
	//get lazy:
	var Get = YAHOO.util.Get,
		tIds = {},
		current = null,
		elementIdToIncludeIn = null,
		dns = null,
		withLabel = null,
		filterList = null,
		type = null,
		idPartner = null, 
		idPrivateWhiteLabel = null, 
		suffixe = null;
		

	// We use the Get Utility's success handler in conjunction with
	// the web service callback in order to detect bad responses
	// from the web service.
	var onSiteExplorerSuccess = function(o) {
		// stop blocking requests
		loading = false;

		// A success response means the script node is inserted.  However, the
		// utility is unable to detect whether or not the content of the script
		// node is correct, or even if there was a bad response (like a 404
		// error).  To get around this, we use the web service callback to
		// verify that the script contents was correct.
		if (o.tId in tIds) {
			YAHOO.log("The Get Utility has fired the success handler indicating that the " +
			"requested script has loaded and is ready for use.", "info", "example");
		}
		else {
			YAHOO.log("The Get utility has fired onSuccess but the webservice callback did not " +
			"fire.  We could retry the transaction here, or notify the user of the " +
			"failure.", "info", "example");
		}
	}

	var onSiteExplorerFailure = function(o) {
		alert("An error occured while getting datas");
	}

	// Function to retrieve data from RPC web service 
	var getSiteExplorerData = function(type, filterList, dns) {
		//prepare the URL for the Yahoo Site Explorer API:
		var sURL = dns+"SearchEngineFormController?type="+type+"&filterList="+filterList+"&callback=YAHOO.rpc.SearchEngineFormWidget.callback";

		if(idPartner != null && idPartner != '' && idPartner != "undefined")
			sURL = sURL+'&idPartner='+idPartner;
		if(idPrivateWhiteLabel != null && idPrivateWhiteLabel != '' && idPrivateWhiteLabel != "undefined")
			sURL = sURL+'&idPrivateWhiteLabel='+idPrivateWhiteLabel;

		sURL = sURL+"&ramdom="+Math.random() ;
		
		//This simple line is the call to the Get Utility; we pass
		//in the URL and the configuration object, which in this case
		//consists merely of our success and failure callbacks:
		var transactionObj = Get.script(sURL, {
			onSuccess: onSiteExplorerSuccess,
			onFailure: onSiteExplorerFailure,
			scope	: this
		});

		// keep track of the current transaction id.  The transaction will be
		// considered complete only if the web service callback is executed.
		current = transactionObj.tId;
	}
	return {
		init: function(elementIdToIncludeInP, typeP, filterListP, withLabelP, dnsP, idPartnerP, idPrivateWhiteLabelP, suffixeP) {
			elementIdToIncludeIn = elementIdToIncludeInP;
			dns = dnsP;
			filterList = filterListP;
			withLabel = withLabelP;
			type = typeP;
			idPartner = idPartnerP;
			idPrivateWhiteLabel = idPrivateWhiteLabelP;
			suffixe = suffixeP;
			getSiteExplorerData(type, filterList, dns);
		},

		callback: function(results) {
			// Mark the transaction as complete.  This will be checked by the onSuccess
			// handler to determine if the transaction really succeeded.
			tIds[current] = true;

			// Add the widget into the element
			addSearchEngineFormWidgetToElement(elementIdToIncludeIn, type, dns, filterList, withLabel, results, idPartner, idPrivateWhiteLabel, suffixe);
		}
	}
}();



/**
 * Constructor for DiscountWidget
 */
SearchEngineFormWidget = function(elementIdToIncludeIn, type, filterList, withLabel, option) {
	if(option == null) {
		option = withLabel;
		withLabel = filterList;
		filterList = type;
		type = FOREIGN;
	}
	
	var idPartner;
	var idPrivateWhiteLabel;
	var dns;
	var suffixe = "";
	
	// Initailize variables
	if(typeof option == 'string') {
		 dns = option;
	}
	else {
		if(option.dns != null)
			dns = option.dns;
		if(option.idPartner != null)
			idPartner = option.idPartner;
		if(option.idPrivateWhiteLabel != null)
			idPrivateWhiteLabel = option.idPrivateWhiteLabel;
		if(option.suffix != null)
			suffixe = option.suffix;
	}

	// Add '/' at the end of the dns
	if(dns != null && dns.charAt(dns.length-1) != '/') dns = dns+'/';

	// Init widget
	YAHOO.rpc.SearchEngineFormWidget.init(elementIdToIncludeIn, type, filterList, withLabel, dns, idPartner, idPrivateWhiteLabel, suffixe);
}