
function CheckRadioButton(element, checked) {
    var elementList = element.getElementsByTagName("input");
    for (i = 0; i < elementList.length; i++) {
        if (elementList[i].type == "radio") {
            elementList[i].checked = checked;
        }
    }
}


function StopEventBubbling(e)
{
	var e = window.event;
	e.cancelBubble = true;
	if (e.stopPropagation)
		e.stopPropagation();
}


function ToggleAnnualCost(checkBox)
{
	var kmPerYear = document.getElementById("txtKmPerYear");
	var centsPerLitre = document.getElementById("txtFuelCentsPerLitre");
	if(kmPerYear != null && centsPerLitre != null)
	{
		if(checkBox.checked == true)
		{
			kmPerYear.disabled = false;
			centsPerLitre.disabled = false;
		}
		else
		{
			kmPerYear.disabled = true;
			centsPerLitre.disabled = true;
		}
	}
}


function ShowYearRatingAlert(year)
{
	alert("WARNING - Vehicles from this model year were rated under an earlier rating system that is not comparable with ratings for current models or model years from " + year);
}

function EnableGeneralClick(event) {

    if (event == null) {
        return;
    }
    
    //netscape
    if (event.target) {
        if ((event.target.localName != "input") || (event.target.localName == "input" && event.target.type == "radio")) {
            if (event.target.type == "radio" || !IsGeneralSelected()) {
                DisableGeneralCriteria(false);
                //cancel event if button is clicked
                if (event.target.type == "image") {
                    event.returnValue = false;
                }
                DisableDetailedCriteria(true);
            }
        }
    }

    //ie
    if (event.srcElement) {
        if ((event.srcElement.tagName != "input") || (event.srcElement.tagName == "input" && event.srcElement.type == "radio")) {

            if (event.srcElement.type == "radio" || !IsGeneralSelected()) {
                DisableGeneralCriteria(false);
                //cancel event if button is clicked
                if (event.srcElement.type == "image") {
                    event.returnValue = false;
                }
                DisableDetailedCriteria(true);
            }
        }
    }
}

function EnableDetailedClick(event) {

    if (event == null) {
        return;
    }

    //netscape
    if (event.target) {
        if ((event.target.localName != "input") || (event.target.localName == "input" && event.target.type == "radio")) {
            if (event.target.type == "radio" || !IsDetailedSelected()) {
                DisableDetailedCriteria(false);
                //cancel event if image button is clicked
                if (event.target.type == "image") {
                    event.returnValue = false;
                }
            }
            DisableGeneralCriteria(true);
        }      
    }
    
    //ie
    if (event.srcElement) {
        if ((event.srcElement.tagName != "input") || (event.srcElement.tagName == "input" && event.srcElement.type == "radio")) {

            if (event.srcElement.type == "radio" || !IsDetailedSelected()) {
                DisableDetailedCriteria(false);
                //cancel event if image button is clicked
                if (event.srcElement.type == "image") {
                    event.returnValue = false;
                }
            }
            DisableGeneralCriteria(true);
        }
    }
}

function DisableGeneralCriteria(isDisabled) {
    var detailed = document.getElementById("AdvSVehicle");
    if (detailed != null) {
        var inputList = detailed.getElementsByTagName("input");
        for (i = 0; i < inputList.length; i++) {
            if (inputList[i].type == "radio") {
                inputList[i].checked = !isDisabled;
            }
            else {

                if (isDisabled) {
                    inputList[i].disabled = isDisabled;
                }
                else {
                    try {
                        inputList[i].removeAttribute('disabled');
                        inputList[i].parentElement.removeAttribute('disabled');
                    } catch (e) { }
                }
            }
        }
    }
}

function IsGeneralSelected() {
    var detailed = document.getElementById("AdvSVehicle");
    if (detailed != null) {
        var inputList = detailed.getElementsByTagName("input");
        for (i = 0; i < inputList.length; i++) {
            if (inputList[i].type == "radio") {
                if (inputList[i].checked) {
                    return true;
                }
            }
        }
    }
    return false;
}

function IsDetailedSelected() {
    var detailed = document.getElementById("AdvSDetailedCriteria");
    if (detailed != null) {
        var inputList = detailed.getElementsByTagName("input");
        for (i = 0; i < inputList.length; i++) {
            if (inputList[i].type == "radio") {
                if (inputList[i].checked) {
                    return true;
                }
            }
        }
    }
    return false;
}

function DisableDetailedCriteria(isDisabled) {
    var detailed = document.getElementById("AdvSDetailedCriteria");
    if (detailed != null) {
        var inputList = detailed.getElementsByTagName("input");
        for (i = 0; i < inputList.length; i++) {
            if (inputList[i].type == "radio") {
                inputList[i].checked = !isDisabled;
            }
            else {
                inputList[i].disabled = isDisabled;
            }
        }

        var optionList = detailed.getElementsByTagName("select");
        for (i = 0; i < optionList.length; i++) {
            optionList[i].disabled = isDisabled;
        }

        var linkList = detailed.getElementsByTagName("a");
        for (i = 0; i < linkList.length; i++) {
            if (isDisabled) {
                linkList[i].style.display = 'none';
            }
            else {
                linkList[i].style.display = '';
            }
        }
    }
}


function SelectCheckBoxs(checkBoxTR) {
    var elementList = checkBoxTR.getElementsByTagName("input");
    for (i = 0; i < elementList.length; i++) {
        if (elementList[i].type == "checkbox") {
            if (i == (elementList.length - 2))
            {
                elementList[i].checked = true;
            }
            else{
                elementList[i].checked = false;
            }
        }
    }
}

function ClearAddVehicleClassSelections() {
    var vehicleClass = document.getElementById("AdvSVehicle");
    if (vehicleClass != null) {
        var checkboxList = vehicleClass.getElementsByTagName("input");
        for (i = 0; i < checkboxList.length; i++) {
            if (checkboxList[i].type == "checkbox") {
                if (checkboxList[i].name.indexOf("allVehiclesHtmlCheckBox") == -1 && checkboxList[i].name.indexOf("chkShowSafetyFeatures") == -1) {
                    checkboxList[i].checked = false;
                }
            }
            
            
        }
    }
}



