
/* Copyright © Mja Engineers Limited */

/* XML */
var objXMLHttpRequest;
function loadXMLDoc(strURL, 
                    strReadyStateChange) {
    if (window.XMLHttpRequest) {
        objXMLHttpRequest = new XMLHttpRequest();
        objXMLHttpRequest.onreadystatechange = eval(strReadyStateChange);
        objXMLHttpRequest.open("GET", strURL, true);
        objXMLHttpRequest.send(null)
    } 
    else if (window.ActiveXObject) {
        objXMLHttpRequest = new ActiveXObject("Microsoft.XMLHTTP");
        if (objXMLHttpRequest) {
            objXMLHttpRequest.onreadystatechange = eval(strReadyStateChange);
            objXMLHttpRequestopen("GET", strURL, true);
            objXMLHttpRequest.send()
        }
    }
}

/* Model List */
function ModelListUpdate() { 
    var objModels = document.getElementById(ModelList.Id);
    if (objXMLHttpRequest.readyState == 4) { 
        if (objXMLHttpRequest.status == 200) { 
            objXML = objXMLHttpRequest.responseXML;
            objModels.length   = 0;
            objModels[0]       = new Option(ModelList.SelectText);
            objModels[0].value = ModelList.SelectText;
            for (var intModel=0; intModel<(objXML.getElementsByTagName(ModelList.ModelTag).length); intModel++) {
                objModels[intModel+1] = new Option(objXML.getElementsByTagName(ModelList.ModelTag)[intModel].firstChild.data);
                objModels[intModel+1].value = objXML.getElementsByTagName(ModelList.ModelTag)[intModel].firstChild.data
            }
        }
    }
}

function ModelListSendXML() { 
    var objMake = document.getElementById(ModelList.MakeId);
    var strMake = objMake[objMake.selectedIndex].value;
    loadXMLDoc(ModelList.XmlURL+strMake,
               'ModelListUpdate')
}

function ModelListMenu() { 
    this.Id         = 'Model';
    this.MakeId     = 'Make';
    this.ModelId    = 'Model';
    this.ModelTag   = 'model';
    this.XmlURL     = '/xml-models.aspx?Make=';
    this.XmlNode    = '//model';
    this.Select     = 'Select';
    this.SelectText = 'Select a Model';
    this.FormName   = 'TopSearchForm';
    this.Update     = ModelListSendXML
}
var ModelList = new ModelListMenu;

/* Top Search */
function TopSearchSubmit() {
    var objMake  = document.getElementById(ModelList.MakeId);
    var objModel = document.getElementById(ModelList.ModelId);
    var strMake  = objMake[objMake.selectedIndex].value;
    var strModel = objModel[objModel.selectedIndex].value;
    if ((strMake.indexOf(ModelList.Select)==-1)&&
        (strModel.indexOf(ModelList.Select)==-1)) { 
        document.getElementById(ModelList.FormName).submit()
    }
}

function TopSearchForm() { 
    this.SubmitForm = TopSearchSubmit
}
var TopSearch = new TopSearchForm;

/* Data Tabs */
function ShowTab(intTabShow) {
    var objTab;
    var objTabData;
    for (intTab=0;intTab<DataTab.TabIds.length;intTab++) {
        objTab     = document.getElementById(DataTab.TabIds[intTab]);
        objTabData = document.getElementById(DataTab.TabDataIds[intTab]);
        objTab.style.backgroundImage=DataTab.TabBG;
        objTabData.style.display='none'
    }
    objTab     = document.getElementById(DataTab.TabIds[intTabShow]);
    objTabData = document.getElementById(DataTab.TabDataIds[intTabShow]);
    objTab.style.backgroundImage=DataTab.ActiveTabBG;
    objTabData.style.display='block'
}

function Tab() {
    this.TabBG         = 'url(/images/car_sales_details_data_tab.gif)';
    this.ActiveTabBG   = 'url(/images/car_sales_details_data_tab_active.gif)';
    this.TabIds        = ['TabGeneral',
                          'TabTechnical',
                          'TabFinance',
                          'TabContact'];
    this.TabDataIds    = ['DataGeneral',
                          'DataTechnical',
                          'DataFinance',
                          'DataContact'];
    this.ShowGeneral   = function ShowGeneral()   { ShowTab(0) };
    this.ShowTechnical = function ShowTechnical() { ShowTab(1) };
    this.ShowFinance   = function ShowFinance()   { ShowTab(2) };
    this.ShowContact   = function ShowContact()   { ShowTab(3) }
}
var DataTab = new Tab();

/* Photos */
function PhotoShow(intPhotoId) { 
    var objPhoto;
    for (intPhoto=0;intPhoto<Photo.PhotoIds.length;intPhoto++) {
        objPhoto = document.getElementById(Photo.PhotoIds[intPhoto]);
        objPhoto.style.visibility='hidden'
    }
    objPhoto = document.getElementById(Photo.PhotoIds[intPhotoId]);
    objPhoto.style.visibility='visible'
}

function PhotosHide() { 
    var objPhoto;
    for (intPhoto=0;intPhoto<Photo.PhotoIds.length;intPhoto++) {
        objPhoto = document.getElementById(Photo.PhotoIds[intPhoto]);
        objPhoto.style.visibility='hidden'
    }
}

function Photos() { 
    this.PhotoIds = ['Photo1',
                     'Photo2',
                     'Photo3',
                     'Photo4',
                     'Photo5',
                     'Photo6'];
    this.ShowPhoto1 = function ShowPhoto1() { PhotoShow(0) };
    this.ShowPhoto2 = function ShowPhoto2() { PhotoShow(1) };
    this.ShowPhoto3 = function ShowPhoto3() { PhotoShow(2) };
    this.ShowPhoto4 = function ShowPhoto4() { PhotoShow(3) };
    this.ShowPhoto5 = function ShowPhoto5() { PhotoShow(4) };
    this.ShowPhoto6 = function ShowPhoto6() { PhotoShow(5) };
    this.HidePhotos = PhotosHide
}
var Photo = new Photos();

/* Photo Popup */
function PhotoPopup(strURL) { 
    var Width  = 600;
    var Height = 450;
    var Top    = (screen.height/2)-(Height/2);
    var Left   = (screen.width/2)-(Width/2);
    window.open(strURL,
                'PhotoPopupWin',
                'scrollbars=no,width='+Width+',height='+Height+',top='+Top+',left='+Left)
}

/* End */