﻿// JScript File

var LastCallingControl = null;

function VehicleDBAjaxURLAppend(ID, Name)
{
   var x = document.getElementById(ID);
   if (x == null) return "";
   
   return "&" + Name + "=" + x.value;
}

function VehicleDBAjaxURLAppendText(ID, Name)
{
   var x = document.getElementById(ID);
   if (x == null) return "";
   
   var selIndex = x.selectedIndex;
   if (selIndex == null) return "";
   if (selIndex == -1) return "";
   
   return "&" + Name + "=" + x.options[selIndex].text;
}

function VehicleDBAjaxUpdate(control)
{
    if (control == null) return;
    
    LastCallingControl = control;
    var ControlName = control.name;
    
    var url = "/PageCode/VehicleDB.aspx?CallingControlName=" + ControlName;
    
    if (ControlName == "ctgInsuranceQuestion_ModelYear" || ControlName == "ctgInsuranceQuestion_ModelMake" || ControlName == "ctgInsuranceQuestion_ModelName" || ControlName == "ctgInsuranceQuestion_ModelNameText" || ControlName == "ctgInsuranceQuestion_ModelDescription")
    {
        url += VehicleDBAjaxURLAppend("ctgInsuranceQuestion_ModelYear", "ModelYear");
        url += VehicleDBAjaxURLAppend("ctgInsuranceQuestion_ModelMake", "ModelMake");
        url += VehicleDBAjaxURLAppend("ctgInsuranceQuestion_ModelName", "ModelName");
        url += VehicleDBAjaxURLAppendText("ctgInsuranceQuestion_ModelName", "ModelNameText");
        url += VehicleDBAjaxURLAppend("ctgInsuranceQuestion_ModelDescription", "ModelDescription");
    }
    
    url += VehicleDBAjaxURLAppend("ctgInsuranceQuestion_TrailerYear", "TrailerYear");
    url += VehicleDBAjaxURLAppend("ctgInsuranceQuestion_TrailerMake", "TrailerMake");    
   
    if (ControlName == "ctgInsuranceQuestion_ModelYear2" || ControlName == "ctgInsuranceQuestion_ModelMake2" || ControlName == "ctgInsuranceQuestion_ModelName2")
    {
       // Get value from numbered field, but send without number
        url += VehicleDBAjaxURLAppend("ctgInsuranceQuestion_ModelYear2", "ModelYear");
        url += VehicleDBAjaxURLAppend("ctgInsuranceQuestion_ModelMake2", "ModelMake");
        url += VehicleDBAjaxURLAppend("ctgInsuranceQuestion_ModelName2", "ModelName");
    }
    
    if (ControlName == "ctgInsuranceQuestion_ModelYear3" || ControlName == "ctgInsuranceQuestion_ModelMake3" || ControlName == "ctgInsuranceQuestion_ModelName3")
    {
       // Get value from numbered field, but send without number
        url += VehicleDBAjaxURLAppend("ctgInsuranceQuestion_ModelYear3", "ModelYear");
        url += VehicleDBAjaxURLAppend("ctgInsuranceQuestion_ModelMake3", "ModelMake");
        url += VehicleDBAjaxURLAppend("ctgInsuranceQuestion_ModelName3", "ModelName");
    }
    
    if (ControlName == "ctgInsuranceQuestion_ModelYear4" || ControlName == "ctgInsuranceQuestion_ModelMake4" || ControlName == "ctgInsuranceQuestion_ModelName4")
    {
       // Get value from numbered field, but send without number
        url += VehicleDBAjaxURLAppend("ctgInsuranceQuestion_ModelYear4", "ModelYear");
        url += VehicleDBAjaxURLAppend("ctgInsuranceQuestion_ModelMake4", "ModelMake");
        url += VehicleDBAjaxURLAppend("ctgInsuranceQuestion_ModelName4", "ModelName");
    }
    
    if (ControlName == "ctgInsuranceQuestion_EngineYear1" || ControlName == "ctgInsuranceQuestion_EngineMake1")
    {
        // Get value from numbered field, but send without number
        url += VehicleDBAjaxURLAppend("ctgInsuranceQuestion_EngineYear1", "EngineYear");        
        url += VehicleDBAjaxURLAppend("ctgInsuranceQuestion_EngineMake1", "EngineMake");        
    }

    if (ControlName == "ctgInsuranceQuestion_EngineYear2" || ControlName == "ctgInsuranceQuestion_EngineMake2")
    {
        // Get value from numbered field, but send without number
        url += VehicleDBAjaxURLAppend("ctgInsuranceQuestion_EngineYear2", "EngineYear");        
        url += VehicleDBAjaxURLAppend("ctgInsuranceQuestion_EngineMake2", "EngineMake");        
    }

    if (ControlName == "ctgInsuranceQuestion_EngineYear3" || ControlName == "ctgInsuranceQuestion_EngineMake3")
    {
        // Get value from numbered field, but send without number
        url += VehicleDBAjaxURLAppend("ctgInsuranceQuestion_EngineYear3", "EngineYear");        
        url += VehicleDBAjaxURLAppend("ctgInsuranceQuestion_EngineMake3", "EngineMake");        
    }

    if (ControlName == "ctgInsuranceQuestion_EngineYear4" || ControlName == "ctgInsuranceQuestion_EngineMake4")
    {
        // Get value from numbered field, but send without number
        url += VehicleDBAjaxURLAppend("ctgInsuranceQuestion_EngineYear4", "EngineYear");        
        url += VehicleDBAjaxURLAppend("ctgInsuranceQuestion_EngineMake4", "EngineMake");        
    }
    
    
    if (ControlName == "ctgInsuranceQuestion_Species1")
    {
        // Get value from numbered field, but send without number
        url += VehicleDBAjaxURLAppend("ctgInsuranceQuestion_Species1", "Species");        
    }
    
    if (ControlName == "ctgInsuranceQuestion_Species2")
    {
        // Get value from numbered field, but send without number
        url += VehicleDBAjaxURLAppend("ctgInsuranceQuestion_Species2", "Species");        
    }
    
    if (ControlName == "ctgInsuranceQuestion_Species3")
    {
        // Get value from numbered field, but send without number
        url += VehicleDBAjaxURLAppend("ctgInsuranceQuestion_Species3", "Species");        
    }
    
    loadXMLDoc(url, VehicleDBAjaxCallBack);
}

function VehicleDBAjaxCallBack()
{
    if (req.readyState == 4) {
        // only if "OK"
        if (req.status == 200) {
            VehicleDBAjaxApply();
         } else {
            //alert("There was a problem retrieving the XML data:\n" + req.statusText);
         }
    }
}



function VehicleDBAjaxApply()
{
    AjaxProcessResponse();
}

