var XmlHttpObj; // declare a global XMLHTTP Request object var XmlHttpObj1; // declare a global XMLHTTP1 Request object // var domain_name = "http://www.rentalcargroup.co.uk/"; var domain_name = document.URL; var testdomain; if (domain_name.match("www")){ testdomain = domain_name.substring(11,domain_name.lastIndexOf('/')); var myUrl = "http://www."+testdomain; } else{ testdomain = domain_name.substring(7,domain_name.lastIndexOf('/')); var myUrl = "http://"+testdomain; } if (testdomain.match("/")) myUrl = myUrl.substring(0,myUrl.lastIndexOf('/')); function CreateXmlHttpObj(){ // create an instance of XMLHTTPRequest Object, varies with browser type, try for IE first then Mozilla try{ // try creating for IE (note: we don't know the user's browser type here, just attempting IE first.) XmlHttpObj = new ActiveXObject("Msxml2.XMLHTTP"); } catch(e){ try{ XmlHttpObj = new ActiveXObject("Microsoft.XMLHTTP"); } catch(oc){ XmlHttpObj = null; } } if(!XmlHttpObj && typeof XMLHttpRequest != "undefined"){ // if unable to create using IE specific code then try creating for Mozilla (FireFox) XmlHttpObj = new XMLHttpRequest(); } } function CreateXmlHttpObj1(){ // create an instance of XMLHTTPRequest Object, varies with browser type, try for IE first then Mozilla try{ // try creating for IE (note: we don't know the user's browser type here, just attempting IE first.) XmlHttpObj1 = new ActiveXObject("Msxml2.XMLHTTP"); } catch(e){ try{ XmlHttpObj1 = new ActiveXObject("Microsoft.XMLHTTP"); } catch(oc){ XmlHttpObj1 = null; } } if(!XmlHttpObj1 && typeof XMLHttpRequest != "undefined"){ // if unable to create using IE specific code then try creating for Mozilla (FireFox) XmlHttpObj1 = new XMLHttpRequest(); } } function GetInnerText (node){ // returns the node text value return (node.textContent || node.innerText || node.text) ; } // All function of "StateChangeHandler" called when state of XmlHttpObj changes // we're interested in the state that indicates data has been // received from the server function StateChangeHandler2(){ if(XmlHttpObj.readyState == 4){ // state ==4 indicates receiving response data from server is completed if(XmlHttpObj.status == 200){ // To make sure valid response is received from the server, 200 means response received is OK PopulateLocationList(XmlHttpObj.responseXML.documentElement); } else{ alert("problem retrieving data from the server, status code: " + XmlHttpObj.status); } } } function StateChangeHandler3(){ if(XmlHttpObj.readyState == 4){ // state ==4 indicates receiving response data from server is completed if(XmlHttpObj.status == 200){ // To make sure valid response is received from the server, 200 means response received is OK PopulateCityList(XmlHttpObj.responseXML.documentElement); } else{ alert("problem retrieving data from the server, status code: " + XmlHttpObj.status); } } } function PopulateCityList(cityNode){// populate the contents of the City dropdown list var cityList = document.getElementById("cityList"); var pick_up_loc = document.getElementById("pick_up_loc"); // clear the list if (pick_up_loc != null) { for (var count = pick_up_loc.options.length-1; count >-1; count--){ pick_up_loc.options[count] = null; } } for (var count = cityList.options.length-1; count >-1; count--){ cityList.options[count] = null; } var cityNodes = cityNode.getElementsByTagName('city'); var idValue ; var textValue; var optionItem; for (var count = 0; count < cityNodes.length; count++){ // populate the dropdown list with data from the xml doc textValue = GetInnerText(cityNodes[count]); idValue = cityNodes[count].getAttribute("id"); optionItem = new Option( textValue, idValue, false, false); cityList.options[cityList.length] = optionItem; } } function CityListOnChange(){ // called from onChange or onClick event of the country dropdown list var cityList = document.getElementById("cityList"); var country_selected = document.main.countryname.value; var selectedIndexValue = cityList.selectedIndex; if (selectedIndexValue == -1) selectedIndexValue = 0; var selectedCity = cityList.options[selectedIndexValue].value; // get selected country from dropdown list var requestUrl; // url of page that will send xml data back to client browser requestUrl = myUrl + "/xml_data_provider.php" + "?filter3=" + encodeURIComponent(selectedCity) + "&active_country=" + country_selected; CreateXmlHttpObj(); if(XmlHttpObj){ // verify XmlHttpObj variable was successfully initialized // assign the StateChangeHandler function ( defined below in this file) // to be called when the state of the XmlHttpObj changes // receiving data back from the server is one such change XmlHttpObj.onreadystatechange = StateChangeHandler2; XmlHttpObj.open("GET", requestUrl, true); // define the iteraction with the server -- true for as asynchronous. XmlHttpObj.send(null); // send request to server, null arg when using "GET" document.main.pick_up_loc.disabled=false; } } function PopulateLocationList(locationNode){ // populate the contents of the country dropdown list var pick_up_loc = document.getElementById("pick_up_loc"); for (var count = pick_up_loc.options.length-1; count >-1; count--){ // clear the country list pick_up_loc.options[count] = null; } var locationNodes = locationNode.getElementsByTagName('location'); var idValue; var textValue; var optionItem; for (var count = 0; count < locationNodes.length; count++){ // populate the dropdown list with data from the xml doc textValue = GetInnerText(locationNodes[count]); idValue = locationNodes[count].getAttribute("id"); optionItem = new Option( textValue, idValue, false, false); pick_up_loc.options[pick_up_loc.length] = optionItem; } } function OnCityLoad() { var countryList = document.getElementById("cityList"); var selectedCountry = document.main.countryname.value; var requestUrl; requestUrl = myUrl + "/xml_data_provider.php" + "?filter1=" + encodeURIComponent(selectedCountry); CreateXmlHttpObj(); if(XmlHttpObj) { // verify XmlHttpObj variable was successfully initialized // assign the StateChangeHandler function ( defined below in this file) // to be called when the state of the XmlHttpObj changes // receiving data back from the server is one such change XmlHttpObj.onreadystatechange = StateChangeHandler3; XmlHttpObj.open("GET", requestUrl, true); // define the iteraction with the server -- true for as asynchronous. XmlHttpObj.send(null); // send request to server, null arg when using "GET" } setTimeout('document.main.cityList.focus();', 2000); // document.main.city.focus(); } function StateChangeHandler5() { if(XmlHttpObj1.readyState == 4){ // state ==4 indicates receiving response data from server is completed if(XmlHttpObj1.status == 200){// To make sure valid response is received from the server, 200 means response received is OK PopulateCORList(XmlHttpObj1.responseXML.documentElement); } else{ alert("problem retrieving data from the server, status code: " + XmlHttpObj.status); } } } function OnCORLoad() { // On Page Load var countryList = document.main.cntry; var requestUrl; // url of page that will send xml data back to client browser requestUrl = myUrl+"/ip_country_xml.php"; CreateXmlHttpObj1(); if(XmlHttpObj1){ // verify XmlHttpObj variable was successfully initialized // assign the StateChangeHandler function ( defined below in this file) // to be called when the state of the XmlHttpObj changes XmlHttpObj1.onreadystatechange = StateChangeHandler5; // receiving data back from the server is one such change XmlHttpObj1.open("GET", requestUrl, true); // define the iteraction with the server -- true for as asynchronous. XmlHttpObj1.send(null); // send request to server, null arg when using "GET" } } function PopulateCORList(countryNode){ var countryList = document.main.cntry; for (var count = countryList.options.length-1; count >-1; count--){ // clear the country list countryList.options[count] = null; } var countryNodes = countryNode.getElementsByTagName('country'); var idValue; var textValue; var optionItem; var curr_selected; var sindex; for (var count = 0; count < countryNodes.length; count++){ // populate the dropdown list with data from the xml doc textValue = GetInnerText(countryNodes[count]); if (textValue.length < 2) continue; idValue = countryNodes[count].getAttribute("id"); curr_selected = countryNodes[count].getAttribute("default"); if (curr_selected == 1) sindex = count; optionItem = new Option( textValue, idValue, false, false); countryList.options[countryList.length] = optionItem; } countryList.selectedIndex = sindex; }