/*******************************************************************************/ /* */ /* Functions For the Ajax Form */ /* Jaime. 01/02/2007 */ /* */ /*******************************************************************************/ var language = ''; var xmlHttp = new Array(15); var timing = new Array(15); var processLoad = "Please wait"; var dot = "."; var processWait = ""; var any = "Any"; function initMenu(nation){ var nations = document.getElementById('ajx_nation'); var regions = document.getElementById('ajx_region'); retrieveData(1, 0, 'ajx_nation', '', 0, nation); nations.onchange=function(){retrieveData(2, 0, 'ajx_region', '', nations.options[nations.selectedIndex].value)}; retrieveData(2, 0, 'ajx_region', '', nation); } function initMenuMallorca(nation){ var nations = document.getElementById('ajx_nation'); var regions = document.getElementById('ajx_region'); retrieveData(1, 0, 'ajx_nation', '', 'mallorca', nation); nations.onchange=function(){retrieveData(2, 0, 'ajx_region', '', nations.options[nations.selectedIndex].value)}; retrieveData(2, 0, 'ajx_region', '', nation); } function initForm(nation, region, town){ var nations = document.getElementById('ajx_nation_form'); var regions = document.getElementById('ajx_region_form'); var towns = document.getElementById('ajx_town_form'); if (typeof nation != "undefined") { retrieveData(1, 0, 'ajx_nation_form', '', 0, nation); if (typeof region != "undefined") { retrieveData(2, 0, 'ajx_region_form', '', nation, region); if (typeof town != "undefined") retrieveData(3, 0, 'ajx_town_form', '', region, town); }else{ retrieveData(2, 0, 'ajx_region_form', '', nation); } }else{ retrieveData(1, 0, 'ajx_nation_form', '', 0); regions.options[0] = new Option(any, any); } if (towns != null) { nations.onchange = function(){retrieveData(2, 0, 'ajx_region_form', '', nations.options[nations.selectedIndex].value); retrieveData(3, 0, 'ajx_town_form', '', '')}; regions.onchange = function(){retrieveData(3, 0, 'ajx_town_form', '', regions.options[regions.selectedIndex].value)}; towns.options[0] = new Option(any, any); }else{ nations.onchange = function(){retrieveData(2, 0, 'ajx_region_form', '', nations.options[nations.selectedIndex].value)}; } } function initFormReg(nation, region, town){ var nations = document.getElementById('ajx_nation_form'); var regions = document.getElementById('ajx_region_form'); var towns = document.getElementById('ajx_town_form'); if (typeof region == "undefined") region = ''; if (typeof town == "undefined") town = ''; retrieveData(4, 0, 'ajx_nation_form', '', 0, nation); if (towns != null) { if (town != '') { retrieveData(5, 0, 'ajx_region_form', '', nation, region); retrieveData(6, 0, 'ajx_town_form', '', region, town); }else retrieveData(5, 6, 'ajx_region_form', 'ajx_town_form', nation, region); nations.onchange = function(){retrieveData(5, 6, 'ajx_region_form', 'ajx_town_form', nations.options[nations.selectedIndex].value)}; regions.onchange = function(){retrieveData(6, 0, 'ajx_town_form', '', regions.options[regions.selectedIndex].value)}; }else{ retrieveData(5, 0, 'ajx_region_form', '', nation, region); nations.onchange = function(){retrieveData(5, 0, 'ajx_region_form', '', nations.options[nations.selectedIndex].value)}; } } /* Function that shows the message "Please Wait" with the dot animation */ function wait(id, i){ var dropdown = document.getElementById(id); dropdown.options.length = 0; dropdown.options[0] = new Option(processLoad + processWait, ''); processWait = (processWait.length == 3)?"":processWait + dot; timing[i] = setTimeout("wait('"+id+"', "+i+")", 500); } /* Function that stops the animation */ function stop(i){ clearTimeout(timing[i]); } /* Function that does the request to the asp page containing the queries */ /* op: number of the query inside the asp page */ /* op2: for the cases that the first query triggers a second one */ /* id: identifier of the dropdown to load with the data recovered with op */ /* id2: identifier of the dropdown to load with the data recovered with op2 */ /* param1: optional parameter for the query in op */ /* param2: optional parameter for selecting a default value in the dropdown id */ function retrieveData(op, op2, id, id2, param1, param2){ var i=0; var dropdown = document.getElementById(id); while (xmlHttp[i]!=null && i<15) i++; dropdown.disabled = true; if (param1 != "mallorca"){ timing[i] = setTimeout("wait('"+id+"', "+i+")", 500); } xmlHttp[i] = GetXmlHttpObject(); if (xmlHttp[i]==null){ alert ("Your browser does not support AJAX!"); return; } if (param1 != "mallorca"){ xmlHttp[i].onreadystatechange = function(){fillDropDown(op2, id, id2, i, param2)}; } xmlHttp[i].open("GET","http://www.abc-mallorca.com/ajaxqueries.asp?lng=2&op="+op+"¶m="+param1,true); xmlHttp[i].send(null); } /* Function that loads a dropdown with the data recovered by xmlHttpRequest */ /* op2: for the cases that the first query triggers a second one */ /* id: identifier of the dropdown to load with the data recovered with op */ /* id2: identifier of the dropdown to load with the data recovered with op2 */ /* i: the index of the xmlHttp array that contains the xmlHttpRequest object to use on this operation */ /* param2: optional parameter for selecting a default value in the dropdown id */ function fillDropDown(op2, id, id2, i, param){ if (xmlHttp[i].readyState==4){ stop(i); var dropdown = document.getElementById(id); var optionsArray = xmlHttp[i].responseText.split('|'); var textAndValue; xmlHttp[i] = null; dropdown.options.length = 0; for (var i=0; i