// Script for Ajax stuff function createRequestObject(){ var request_o; var browser = navigator.appName; if(browser == "Microsoft Internet Explorer"){ request_o = new ActiveXObject("Microsoft.XMLHTTP"); } else { request_o = new XMLHttpRequest(); } return request_o; } var http = createRequestObject(); function ajaxIt(){ http.onreadystatechange = handleProducts; http.send(null); } function getSelect(){ http.open('get', 'http://www.chrisstylianou.co.uk/clichycars/query_cars.php?type=select'); ajaxIt(); } function getSearch(){ js_make = document.showroom.make.options[document.showroom.make.selectedIndex].value; document.getElementById('results').innerHTML = '

Loading...

'; http.open('get', 'http://www.chrisstylianou.co.uk/clichycars/query_cars.php?type=search&search=' + js_make + '&rand=' + Math.random()); ajaxIt(); } function getList(){ document.getElementById('results').innerHTML = '

Loading...

'; http.open('get', 'http://www.chrisstylianou.co.uk/clichycars/query_cars.php?type=list&rand=' + Math.random()); ajaxIt(); } function getCar(){ document.getElementById('car').innerHTML = '

Loading...

'; http.open('get', 'http://www.chrisstylianou.co.uk/clichycars/query_cars.php?type=car&car=' + js_car + '&rand=' + Math.random()); ajaxIt(); } function getPhotos(){ document.getElementById('photos').innerHTML = '

Updating...

'; http.open('get', 'http://www.chrisstylianou.co.uk/clichycars/query_cars.php?type=photos&car=' + js_car + '&rand=' + Math.random()); ajaxIt(); } function deletePhoto(name){ document.getElementById('photos').innerHTML = '

Processing...

'; http.open('get', 'http://www.chrisstylianou.co.uk/clichycars/query_cars.php?type=deletePhoto&car=' + js_car + '&name=' + name + '.jpg&rand=' + Math.random()); ajaxIt(); return false; } function mainPhoto(name){ document.getElementById('photos').innerHTML = '

Processing...

'; http.open('get', 'http://www.chrisstylianou.co.uk/clichycars/query_cars.php?type=mainPhoto&car=' + js_car + '&name=' + name + '.jpg&rand=' + Math.random()); ajaxIt(); return false; } function handleProducts(){ if(http.readyState == 4){ //Finished loading the response response = http.responseText; if(response.indexOf("select=>") == 0){ document.showroom.make.options.length = 0; document.showroom.make.options[document.showroom.make.options.length] = new Option('All Makes (0)', '-1'); var form_options = response.split("select=>"); var options = form_options[1].split("~#~"); for(i = 0; i < options.length - 1; i++){ values = options[i].split("~/~"); document.showroom.make.options[document.showroom.make.options.length] = new Option(values[1], values[0]); if(js_make == values[0]){ document.showroom.make.options[document.showroom.make.options.length - 1].selected = true; } } getSearch(); } else if(response.indexOf("search=>") == 0){ var form_options = response.split("search=>"); document.getElementById('results').innerHTML = form_options[1]; } else if(response.indexOf("car=>") == 0){ var form_options = response.split("car=>"); document.getElementById('car').innerHTML = form_options[1]; } else if(response.indexOf("photos=>") == 0){ var form_options = response.split("photos=>"); document.getElementById('photos').innerHTML = form_options[1]; setTimeout("getPhotos()", 5000); } else if(response.indexOf("deletePhoto=>") == 0){ var form_options = response.split("deletePhoto=>"); //document.getElementById('photos').innerHTML = form_options[1]; } else if(response.indexOf("mainPhoto=>") == 0){ var form_options = response.split("mainPhoto=>"); //document.getElementById('photos').innerHTML = form_options[1]; } else { //alert('Error! Cannot understand response: ' + response); } } } // Script for autosuggestion for features function autoComplete(ev, field) { var txtAuto = document.getElementById(field); initialCap(txtAuto); if(txtAuto.createTextRange || txtAuto.setSelectionRange){ if((ev.keyCode >= 48 && ev.keyCode <= 57) || (ev.keyCode >= 65 && ev.keyCode <= 90)){ var text = txtAuto.value; var initial_len = txtAuto.value.length; var suggestion = findMatch(text, field); //Firefox and Opera if(txtAuto.setSelectionRange){ if((suggestion) && (txtAuto.value == text)){ txtAuto.value = suggestion; txtAuto.setSelectionRange(initial_len, txtAuto.value.length); } //Internet Explorer } else if(txtAuto.createTextRange){ if((suggestion) && (txtAuto.value == text)){ txtAuto.value = suggestion; var oRange = txtAuto.createTextRange(); oRange.moveStart("character", initial_len); oRange.moveEnd("character", suggestion.length - txtAuto.value.length); oRange.select(); } } txtAuto.focus(); } } } var words_model = new Array("Fiesta", "Cayenne", "M-Class", "Mini", "V8", "Corolla", "CL", "Carrera", "C180SE", "911 997", "E220CDI Avanotgarde", "X3 Sport", ""); var words_fuel = new Array("Petrol", "Diesel", "Gas", "Electric", ""); var words_equipment = new Array("ABS", "Air Conditioning", "Climate Control", "Alarm / Immobiliser", "Alloy Wheels", "Central Locking", "Driver, Passenger and Side Airbags", "Power Assisted Steering", "Cruise Control", "Traction Control", "Electric Windows and Mirrors", "Electric Memory Seats", "In Car Navigation", "Full Service History", "Sunroof", "Heated Seats", "Leather Upholstery", "Convertible", "Bi Xenons", "CD Player", "CD Stacker", ""); function findMatch(text, field){ var words = new Array(""); if(field == 'make'){ words = words_make; } else if(field == 'model'){ words = words_model; } else if(field == 'body'){ words = words_body; } else if(field == 'doors'){ words = words_doors; } else if(field == 'fuel'){ words = words_fuel; } else if(field.indexOf('equip') == 0){ words = words_equipment; } var suggestion = false; for(var i = 0; i < words.length; i++){ var item = words[i]; if(!suggestion){ item_check = item.substring(0, text.length); if(item_check.toLowerCase() == text.toLowerCase()){ suggestion = item; } } } return suggestion; } function initialCap(field){ field.value = field.value.substr(0, 1).toUpperCase() + field.value.substr(1); field.value = field.value.replace(/^\s*/, ""); field.value = field.value.replace(/\s{2,}/, " "); } function checkAddCar(){ var str = document.getElementById('price').value; str += ''; var rgx = /^\d$/; var out = ''; for(var i = 0; i < str.length; i++) { if(rgx.test(str.charAt(i))){ // if(!((str.charAt(i) == '.' && out.indexOf( '.' ) != -1 ) || ( str.charAt(i) == '-' && out.length != 0 ))){ out += str.charAt(i); // } } } document.getElementById('price').value = out; if(document.getElementById('description').value == ""){ alert('You must enter a description to be displayed to clients'); return false; } else if(document.getElementById('make').value == -1){ alert('You must select the make of the car'); return false; } else if(document.getElementById('model').value == ""){ alert('You must enter the model of the car'); return false; } else if(document.getElementById('price').value == ""){ alert('You must enter a price to be displayed to clients'); return false; } else if(document.getElementById('body').value == -1){ alert('You must select the body style of the car'); return false; } else if(document.getElementById('doors').value == -1){ alert('You must select the number of doors of the car'); return false; } else if(document.getElementById('fuel').value == -1){ alert('You must select the fuel type of the car'); return false; } return true; }