﻿function changeTab(tab) {
    if (tab == 'technical') {
        $('technicalTab').src = '/Content/images/technicaltabon.gif';
        $('equipmentTab').src = '/Content/images/equipmenttaboff1.gif';
        $('optionsTab').src = '/Content/images/optionstaboff1.gif';
        $('reviewsTab').src = '/Content/images/reviewstaboff1.gif';
        $('technicalContainer').show();
        $('equipmentContainer').hide();
        $('optionsContainer').hide();
        $('reviewsContainer').hide();
    } else if (tab == 'equipment') {
        $('technicalTab').src = '/Content/images/technicaltaboff2.gif';
        $('equipmentTab').src = '/Content/images/equipmenttabon.gif';
        $('optionsTab').src = '/Content/images/optionstaboff2.gif';
        $('reviewsTab').src = '/Content/images/reviewstaboff2.gif';
        $('technicalContainer').hide();
        $('equipmentContainer').show();
        $('optionsContainer').hide();
        $('reviewsContainer').hide();
    } else if (tab == 'options') {
        $('technicalTab').src = '/Content/images/technicaltaboff3.gif';
        $('equipmentTab').src = '/Content/images/equipmenttaboff3.gif';
        $('optionsTab').src = '/Content/images/optionstabon.gif';
        $('reviewsTab').src = '/Content/images/reviewstaboff3.gif';
        $('technicalContainer').hide();
        $('equipmentContainer').hide();
        $('optionsContainer').show();
        $('reviewsContainer').hide();
    } else if (tab == 'reviews') {
        $('technicalTab').src = '/Content/images/technicaltaboff4.gif';
        $('equipmentTab').src = '/Content/images/equipmenttaboff4.gif';
        $('optionsTab').src = '/Content/images/optionstaboff1.gif';
        $('reviewsTab').src = '/Content/images/reviewstabon.gif';
        $('technicalContainer').hide();
        $('equipmentContainer').hide();
        $('optionsContainer').hide();
        $('reviewsContainer').show();
    }
}

function hideTechnicalContainer(id) {
    $(id).toggle();
}
function hideContainer(id) {
    $(id).toggle();
}

function getModels(id) {
    var url = "/AjaxCalls.aspx";

    new Ajax.Request(url, {
        method: 'get',
        parameters: 'Action=Models&Var1=' + id,
        onSuccess: function(transport) {
            $('modelDropContainer').innerHTML = transport.responseText;
        }

    });
}
function getEnquiryModels(id) {
    var url = "/AjaxCalls.aspx";

    new Ajax.Request(url, {
        method: 'get',
        parameters: 'Action=EnquiryModels&Var1=' + id,
        onSuccess: function(transport) {
            $('ModelDropEnquireContainer').innerHTML = transport.responseText;
        }

    });
}
function getVanModels(id) {
    var url = "/AjaxCalls.aspx";

    new Ajax.Request(url, {
        method: 'get',
        parameters: 'Action=VanModels&Var1=' + id,
        onSuccess: function(transport) {
            $('modelDropContainer').innerHTML = transport.responseText;
        }

    });
}
function getAdminModels(id) {
    var url = "/AjaxCalls.aspx";
    var model = 0;

    new Ajax.Request(url, {
        method: 'get',
        parameters: 'Action=AdminModels&Var1=' + id,
        onSuccess: function(transport) {
            $('modelDropContainer').innerHTML = transport.responseText;
            model = $('modelDrop').options[0].value;
            getAdminDervs(model);
        }

    });

}
function getAdminVanModels(id) {
    var url = "/AjaxCalls.aspx";
    var model = 0;

    new Ajax.Request(url, {
        method: 'get',
        parameters: 'Action=AdminVanModels&Var1=' + id,
        onSuccess: function(transport) {
            $('modelDropContainer').innerHTML = transport.responseText;
            model = $('modelDrop').options[0].value;
            getAdminVanDervs(model);
        }

    });

}
function getAdminDervs(id) {
    var url = "/AjaxCalls.aspx";

    new Ajax.Request(url, {
        method: 'get',
        parameters: 'Action=AdminDerv&Var1=' + id,
        onSuccess: function(transport) {
            $('dervDropContainer').innerHTML = transport.responseText;
        }
    });
}
function getAdminVanDervs(id) {
    var url = "/AjaxCalls.aspx";

    new Ajax.Request(url, {
        method: 'get',
        parameters: 'Action=AdminVanDerv&Var1=' + id,
        onSuccess: function(transport) {
            $('dervDropContainer').innerHTML = transport.responseText;
        }
    });
}
function getProfiles(id) {
    var url = "/AjaxCalls.aspx";

    new Ajax.Request(url, {
        method: 'get',
        parameters: 'Action=AdminProfiles&Var1=' + id,
        onSuccess: function(transport) {
            $('profileDropContainer').innerHTML = transport.responseText;
        }
    });
}
function getVanProfiles(id) {
    var url = "/AjaxCalls.aspx";

    new Ajax.Request(url, {
        method: 'get',
        parameters: 'Action=AdminVanProfiles&Var1=' + id,
        onSuccess: function(transport) {
            $('profileDropContainer').innerHTML = transport.responseText;
        }
    });
}
function saveContractPeriod() {
    if ($('newContractText').value != '') {

        var url = "/AjaxCalls.aspx";
        text = $('newContractText').value;
        new Ajax.Request(url, {
            method: 'post',
            parameters: 'Action=saveContractPeriod&Var1=' + text,
            onSuccess: function(transport) {
                $('contractDropContainer').innerHTML = transport.responseText;
                hideContainer('newContractPeriod');
            }

        });
    } else {
        alert("Please fill all fields to add a contract period");
    }
}
function saveVanContractPeriod() {
    if ($('newContractText').value != '') {

        var url = "/AjaxCalls.aspx";
        text = $('newContractText').value;
        new Ajax.Request(url, {
            method: 'post',
            parameters: 'Action=saveVanContractPeriod&Var1=' + text,
            onSuccess: function(transport) {
                $('contractDropContainer').innerHTML = transport.responseText;
                hideContainer('newContractPeriod');
            }

        });
    } else {
        alert("Please fill all fields to add a contract period");
    }
}

function saveProfile() {
    if ($('newProfileDeposit').value != '' && $('newProfileOngoing').value != '') {

        var url = "/AjaxCalls.aspx";
        CP = $('CarLease.ContractPeriodID').value;
        PD = $('newProfileDeposit').value;
        PO = $('newProfileOngoing').value;
        new Ajax.Request(url, {
            method: 'post',
            parameters: 'Action=saveProfile&contractPeriod=' + CP + '&profileDeposit=' + PD + '&profileOngoing=' + PO,
            onSuccess: function(transport) {
                hideContainer('addProfileContainer');
                $('profileDropContainer').innerHTML = transport.responseText;

            }

        });
    } else {
        alert("Please fill all fields to add a profile");
    }
}
function saveVanProfile() {
    if ($('newProfileDeposit').value != '' && $('newProfileOngoing').value != '') {

        var url = "/AjaxCalls.aspx";
        CP = $('CarLease.ContractPeriodID').value;
        PD = $('newProfileDeposit').value;
        PO = $('newProfileOngoing').value;
        new Ajax.Request(url, {
            method: 'post',
            parameters: 'Action=saveVanProfile&contractPeriod=' + CP + '&profileDeposit=' + PD + '&profileOngoing=' + PO,
            onSuccess: function(transport) {
                hideContainer('addProfileContainer');
                $('profileDropContainer').innerHTML = transport.responseText;

            }

        });
    } else {
        alert("Please fill all fields to add a profile");
    }
}

function checkCarForm() {

    if ( $('CarLease.CapID').value == '' )  {
        alert("Please fill the make, model and derivative");
        return false;
    }
    if ($('CarLease.MonthlyPayment').value == '') {
        alert("Please enter a monthly payment");
        return false;
    }
    if ($('ctl00_ContentHolder_DealExpires').value == '') {
        alert("Please enter when the deal will expire");
        return false;
    }
    if ($('CarLease.FinanceLease').checked == true && $('CarLease.FinalPayment').value == '') {
        alert("Please enter a final payment if the car is on finance lease");
        return false;
    }
    return true;
}
function removeItem(msgText) {
    var msg = confirm(msgText);
    
    if ( msg ){
        return true;
    } else {
        return false;
    }
}
function checkSearchForm() {
    if ($('makeDrop').value == "any" && $('bodyDrop').value == 'any') {
        alert("Please select either a make or body style to perform a search");
        return false;
    } else {
        return true;
    }
}
function checkVanSearchForm() {
    if ($('makeDrop').value == "0") {
        alert("Please select a make to perform a search");
        return false;
    }

    return true;
}
function checkGallery() {
    if ( $('CarGallery.Title').value =='' || $('CarGallery.Comments').value =='' ) {
        alert("Please complete the title and comments fields");
        return false;
    }
    
    return true;
}
valid = true;
function highlightReqField(Field, type) {
    if ($(Field).value == '') {
        if (type == 'req') {
            $(Field).className = "textBoxError";
        } else {
            $(Field).className = "textBoxOptional";
        }
        return (valid == false ? valid : false);
    }
}
function checkNews() {
    if ( $('CarNew.Title').value =='' || $('CarNew.newssummary').value =='' || $('CarGallery.newsContent').value =='') {
        alert("Please complete the title, news summary and content fields");
        return false;
    }
    
    return true;
}

function checkEnquiryForm() {
    valid = highlightReqField('CarEnquire.FirstName', 'req');
    valid = highlightReqField('CarEnquire.LastName', 'req');
    valid = highlightReqField('CarEnquire.Telephone', 'opt');
    valid = highlightReqField('CarEnquire.Email', 'opt');
    if (valid == false) {
        alert("Please complete all fields marked with red, at least one field has to be completed marked with blue");
    }
    return valid;
}
