// // Copyright 2012, PolyTuff Pty. Ltd. // var AjaxObject = function() { this.xmlHttp = null this.transport = null this.method = "post" this.url = "" this.div = "" this.create = function(url, transport, method) { this.xmlHttp = initialize() this.transport = transport this.url = url this.method = method } this.request = function(action, params,div) { this.div = div var string = this.url + '?action='+action+'¶ms='+params this.xmlHttp.open(this.method,string,true) this.xmlHttp.onreadystatechange = this.transport this.xmlHttp.send(null) } this.getData = function() { if (this.xmlHttp.readyState == 4) { return this.xmlHttp.responseText } return null } this.getDiv = function() { return this.div } function initialize() { var xmlHttp=null try { xmlHttp=new XMLHttpRequest() } catch (e) { try { xmlHttp=new ActiveXObject("Msxml2.XMLHTTP") } catch (e) { try { xmlHttp=new ActiveXObject("Microsoft.XMLHTTP") } catch (e) { alert("Your browser does not support AJAX, please upgrade!") return false } } } return xmlHttp } } var SELECTED_NEEDED_MSG = "Please select a Vehicle Type and Make and Model"; var ajaxDrive = new AjaxObject(); var ajaxMake = new AjaxObject(); var ajaxModel = new AjaxObject(); var ajaxDataTable = new AjaxObject(); ajaxDrive.create("catalogue.php", updateDriveCombo, "get"); ajaxMake.create("catalogue.php", updateMakeCombo, "get"); ajaxModel.create("catalogue.php", updateModelCombo, "get"); ajaxDataTable.create("catalogue.php", updateTableBox, "get"); function updateDriveCombo() { var response = ajaxDrive.getData(); if (response != null) { debug(response); document.getElementById("driveBox").innerHTML=response; document.getElementById("driveList").value = selDrive; } } function updateMakeCombo() { var response = ajaxMake.getData(); if (response != null) { debug(response); document.getElementById("makeBox").innerHTML=response; document.getElementById("driveList").value = selDrive; document.getElementById("makeList").value = selMake; } } function updateModelCombo() { var response = ajaxModel.getData(); if (response != null) { debug(response); document.getElementById("modelBox").innerHTML=response; document.getElementById("driveList").value = selDrive; document.getElementById("makeList").value = selMake; document.getElementById("modelList").value = selModel; } } function updateTableBox() { var response = ajaxDataTable.getData(); if (response != null) { debug(response); document.getElementById("tableBox").innerHTML=response; document.getElementById("driveList").value = selDrive; document.getElementById("makeList").value = selMake; document.getElementById("modelList").value = selModel; } } function GetDrives() { ajaxDrive.request("getdrives", ""); } function SelectDrive(driveVal) { if (driveVal == "") { //GetMakes(driveVal); CheckRedirect(driveVal, "", ""); document.getElementById("tableBox").innerHTML=SELECTED_NEEDED_MSG; return; } al_RedirectLocation("LocationAnchor", "ancCatalogue", "#" + encodeURIComponent(driveVal)); } function GetMakes(driveVal) { ajaxMake.request("getmakes", "&drive="+encodeURIComponent(driveVal)); } function SelectMake(makeVal) { driveVal = document.getElementById("driveList").value; if (driveVal == "" || makeVal == "") { //GetMakes(driveVal); //GetModels(driveVal, makeVal); CheckRedirect(driveVal, makeVal, ""); document.getElementById("tableBox").innerHTML=SELECTED_NEEDED_MSG; return; } al_RedirectLocation("LocationAnchor", "ancCatalogue", "#" + encodeURIComponent(driveVal) + "/" + encodeURIComponent(makeVal)); } function GetModels(driveVal, makeVal) { ajaxModel.request("getmodels", "&drive="+encodeURIComponent(driveVal)+"&makeId="+encodeURIComponent(makeVal)); } function SelectModel(modelVal) { // Get both the Make and Model selection box values and submit it to our function driveVal = document.getElementById("driveList").value; makeVal = document.getElementById("makeList").value; if (driveVal == "" || makeVal == "" || modelVal == "") { //GetMakes(driveVal); //GetModels(driveVal, makeVal); //GetSeries(driveVal, makeVal, modelVal); CheckRedirect(driveVal, makeVal, modelVal); document.getElementById("tableBox").innerHTML=SELECTED_NEEDED_MSG; return; } al_RedirectLocation("LocationAnchor", "ancCatalogue", "#" + encodeURIComponent(driveVal) + "/" + encodeURIComponent(makeVal) + "/" + encodeURIComponent(modelVal)); } function CheckRedirect(driveVal, makeVal, modelVal) { if (modelVal != "" && makeVal != "" && driveVal != "") { al_RedirectLocation("LocationAnchor", "ancCatalogue", "#" + encodeURIComponent(driveVal) + "/" + encodeURIComponent(makeVal) + "/" + encodeURIComponent(modelVal)); } else if (makeVal != "" && driveVal != "") { al_RedirectLocation("LocationAnchor", "ancCatalogue", "#" + encodeURIComponent(driveVal) + "/" + encodeURIComponent(makeVal)); } else if (driveVal != "") { al_RedirectLocation("LocationAnchor", "ancCatalogue", "#" + encodeURIComponent(driveVal)); } else { al_RedirectLocation("LocationAnchor", "ancCatalogue", "#"); } } function GetSeries(driveVal, makeVal, modelVal) { // Get both the Make and Model selection box values and submit it to our function ajaxDataTable.request("getlinktable", "&drive="+encodeURIComponent(driveVal)+"&makeId="+encodeURIComponent(makeVal)+"&modelId="+encodeURIComponent(modelVal)); } function SelectSeries(seriesVal) { // Get both the Make and Model selection box values and submit it to our function driveVal = document.getElementById("driveList").value; makeVal = document.getElementById("makeList").value; modelVal = document.getElementById("modelList").value; al_RedirectLocation("LocationAnchor", "ancCatalogue", "#" + encodeURIComponent(driveVal) + "/" + encodeURIComponent(makeVal) + "/" + encodeURIComponent(modelVal) + "/" + encodeURIComponent(seriesVal)); } function GetProductInfo(driveVal, makeVal, modelVal, seriesVal) { // Get both the Make and Model selection box values and submit it to our function if (seriesVal == "" || driveVal == "" || makeVal == "" || modelVal == "") { //alert("empty values"); return; } debug("Drive: " + driveVal + " Make: " + makeVal + " Model: " + modelVal + " Series: " + seriesVal); //sendReq("catalogue.php", "getproductinfotable", "&makeId="+encodeURIComponent(makeVal)+"&modelId="+encodeURIComponent(modelVal)+"&seriesId="+encodeURIComponent(seriesVal), updateTableBox); //ajaxDataTable.get("catalogue.php", "getproductinfotable", "&makeId="+encodeURIComponent(makeVal)+"&modelId="+encodeURIComponent(modelVal)+"&seriesId="+encodeURIComponent(seriesVal)); ajaxDataTable.request("getproductinfotable", "&makeId="+encodeURIComponent(makeVal)+"&modelId="+encodeURIComponent(modelVal)+"&seriesId="+encodeURIComponent(seriesVal)); } function OnPageLoad() { al_Init(); GetDrives(); ProcessOnHashChange(); } // The currently selected items. var selDrive = ""; var selMake = ""; var selModel = ""; var selSeries = ""; function ProcessOnHashChange() { var hashTag = al_GetHashTag(); if (hashTag != "") { // Parse the hashtag in the format !/drive/make/model/seriesId var urlparts = hashTag.split('/'); var partCount = urlparts.length; //alert(hashTag); selDrive = ""; selMake = ""; selModel = ""; selSeries = ""; if (partCount >= 1) { selDrive = decodeURIComponent(urlparts[0]); } if (partCount >= 2) { selMake = decodeURIComponent(urlparts[1]); } if (partCount >= 3) { selModel = decodeURIComponent(urlparts[2]); } if (partCount >= 4) { selSeries = decodeURIComponent(urlparts[3]); } // Retrieve the necessary lists // Note: We need to determine if a series has been selected or not // as both the series and product info tables update the same id and can cause conflicts. if (partCount >= 1) { //alert("make: " + selMake); GetDrives(); GetMakes(selDrive); GetModels(selDrive, selMake); } if (partCount == 3) { //alert("model1: " + selModel); GetSeries(selDrive, selMake, selModel); } if (partCount >= 4) { GetProductInfo(selDrive, selMake, selModel, selSeries); } // Keep the other elements tidy // if (partCount < 1) // { // document.getElementById("driveList").value = ""; // } if (partCount < 2) { document.getElementById("makeList").value = ""; } if (partCount < 3) { document.getElementById("modelList").value = ""; document.getElementById("tableBox").innerHTML=SELECTED_NEEDED_MSG; } } else { // Nothing selected so clear everything and reload selDrive = ""; selMake = ""; selModel = ""; selSeries = ""; document.getElementById("driveList").value = ""; document.getElementById("makeList").value = ""; document.getElementById("modelList").value = ""; document.getElementById("tableBox").innerHTML=SELECTED_NEEDED_MSG; GetDrives(); GetMakes(selDrive); GetModels(selDrive, selMake); } }