function RefreshDescription() {
	year = document.getElementById("yearSelect").value;
	make = document.getElementById("makeSelect").value;
	model = document.getElementById("Model").value;
	app = document.getElementById("applicationSelect").value;
	color = getRadioValue("color");
	bulb = document.getElementById("bulbSelect").value;

	if (bulb == 'NA') {
		document.getElementById("description").innerHTML = year + ' ' + make + ' ' + model + ' ' + app + '<br />' + color + ' bulb color';
		document.getElementById("os0").value = year + ' ' + make + ' ' + model + ' ' + app + ' with ' + color + ' bulb color';
	} else {
		document.getElementById("description").innerHTML = bulb + ' bulb size' + '<br />' + color + ' bulb color';
		document.getElementById("os0").value = bulb + ' bulb size with ' + color + ' bulb color';
	}

	if (model != 'Model') {
		document.getElementById("modelError").style.display = "none";
	}

	if (app == 'High Beams') {
		document.getElementById("warning").style.display = "inline";
	} else {
		document.getElementById("warning").style.display = "none";
	}
}

function RefreshBulb() {
	bulb = document.getElementById("bulbSelect").value;
	if (bulb == 'NA') {
		document.getElementById("vehicle").style.display = "inline";
		RefreshDescription();
	} else {
		document.getElementById("vehicle").style.display = "none";
		RefreshDescription();
	}
}

function PayNow() {
	ApplyCoupon();

	bulb = document.getElementById("bulbSelect").value;
	model = document.getElementById("Model").value;

	if (bulb == 'NA') {
		if (model == 'Model') {
			document.getElementById("modelError").style.display = "block";
			alert ("Please enter your car model.")
		} else {
			document.paypal.submit();
		}
	} else {
		document.paypal.submit();
	}
}


function ApplyCoupon() {
	coupon = document.getElementById("Coupon").value;

	if (coupon == '') {
		document.getElementById("totalPrice").innerHTML = '<b>$129.95</b>';
		document.getElementById("Discount").innerHTML = '- $0.00';
		document.getElementById("amount").value = '129.95';
	} else {
		document.getElementById("Discount").innerHTML = '<span style="font-size:12px; color:#f00;">Invalid Coupon</span>';
	}
}

function getRadioValue(idOrName) {
        var value = null;
        var element = document.getElementById(idOrName);
        var radioGroupName = null;  
        
        // if null, then the id must be the radio group name
        if (element == null) {
                radioGroupName = idOrName;
        } else {
                radioGroupName = element.name;     
        }
        if (radioGroupName == null) {
                return null;
        }
        var radios = document.getElementsByTagName('input');
        for (var i=0; i<radios.length; i++) {
                var input = radios[ i ];    
                if (input.type == 'radio' && input.name == radioGroupName && input.checked) {                          
                        value = input.value;
                        break;
                }
        }
        return value;
}
