window.onload = initControls;
function initControls() {
document.getElementById("btn1").onclick = Btn1Click;
document.getElementById("btn2").onclick = Btn2Click;
document.forms[0].FirstName.onfocus = FocusColor;
document.forms[0].FirstName.onblur = BlurColor;
document.forms[0].LastName.onfocus = FocusColor;
document.forms[0].LastName.onblur = BlurColor;
document.getElementById("rb1").onclick = BkColor;
document.getElementById("rb2").onclick = BkColor;
document.getElementById("rb3").onclick = BkColor;
document.forms[0].NewColors.onchange = ResetColor;
document.forms[0].onsubmit = ValidateForm;
document.forms[0].onreset = DefaultColor;
document.getElementById("rb3").click();
}
function Btn1Click() {
document.forms[0].FirstName.focus();
document.forms[0].FirstName.select();
}
function Btn2Click() {
document.getElementById("cbAdult").checked =
document.getElementById("cbAdult").checked == true ? false : true;
}
function FocusColor() {
this.style.backgroundColor = "#ffffcc";
}
function BlurColor() {
this.style.backgroundColor = "";
}
function BkColor() {
document.forms[0].style.backgroundColor = this.value;
}
function ResetColor() {
document.getElementById("rb1Lbl").innerHTML = this.options[this.selectedIndex].text;
document.getElementById("rb1").value = this.options[this.selectedIndex].value;
document.getElementById("rb1").click();
}
function ValidateForm() {
var rtn = true;
if (document.forms[0].LastName.value == "") {
alert("Form is not valid!");
rtn = false;
}
return rtn;
}
function DefaultColor() {
document.getElementById("rb3").click();
}