window.onload = initscript;

/*document.write('<script language="javascript" src="../incl/global.js"></script>');*/

function initscript(){
document.getElementById("helpbtncom").onclick=fieldComHelp;
document.getElementById("helpbtntrez").onclick=fieldTrezHelp;
document.getElementById("trezlname").onblur=textfix;
document.getElementById("at1fname").onblur=textfix;
document.getElementById("at1lname").onblur=textfix;
document.getElementById("at2fname").onblur=textfix;
document.getElementById("at2lname").onblur=textfix;
document.getElementById("validation").onclick=validation;
document.getElementById("clear").onclick=clear_form;
document.getElementById("com_id").onblur=submitCommiteeID;
document.getElementById("validation").onclick=validation;
document.getElementById("clear").onclick=clear_form;
redrawFormDiv();
}

/* Because IE is such a fickle pain... we needed to specify the height of the 
div containing the form. Well now when the form expands to contain the name
of the commitee it pushes the buttons out of the background.
This function resizes the background so the buttons stay on the bottom.
*/
function redrawFormDiv(){
	if(document.getElementById("com_para")){
		var formDiv = document.getElementById("classreg_webform");
		formDiv.style.height="610px";
		document.getElementById("trezlname").focus();
	}
}

/* Submits the comm_id so that the commitee name may be retrieved */
function submitCommiteeID(){
    document.forms[0].submit();
}


/* Help message for the com_id field */
function fieldComHelp() {
	document.train["com_id"].focus();
	alert("Begin by entering the six-digit Committee ID# (assigned to \
the committee by the Bureau of Elections) of the committee on \
whose behalf you are seeking training. \n\nAfter you TAB into the next \
field, the committee name will display, \
allowing you to verify that you have entered the correct Committee ID#. \
Once you have done this, the list of available training classes will display.\n\n\
If you are seeking training on the behalf of multiple committees of \
different types (i.e. Candidate and Political Party and PAC, \
etc.), you will have to register multiple times; once for each \
different committee type.");
}

/*Help message for the tresururer last name field */
function fieldTrezHelp(){
	document.train["trezlname"].focus();
	alert("For verification purposes, enter the last name of the CURRENT treasurer of the \
committee. This can ONLY be the most recent treasurer \
submitted on a Statement of Organization form to the \
Bureau of Elections, and MUST be spelled correctly including \
any and all punctuation, prefixes or suffixes (i.e. ST. JOSEPH JR).");
}



function errWindow(fName) {
	switch (fName) {
		case "com_id" :
			alert("A valid Committee ID# is required.");
			break;
		case "trezlname" :
			alert("A valid Treasurer Last Name is required.");
			break;
		case "at1fname" :
			alert("Attendee #1 First Name is required.");
			break;
		case "at1lname" :
			alert("Attendee #1 Last Name is required.");
			break;
		case "phone" :
			alert("A complete and valid Contact Phone # is required.");
			break;
		case "class" :
			alert("A selection of one class to register for is required.");
			break;
	}
}

function textfix() {

	this.value = this.value.toUpperCase();
	this.value = Trim(this.value);
//	textObj.value = htmlentities(textObj.value); //jjtest
}

function validation() {
	if (validate_form()) {

		document.train.action = "register.php";
		document.train.submit();
		return true;
	} 
	else {
		return false;
	}
}

function validate_form() {
	if ((isBlank(document.train["com_id"].value)) || !isNumeric(document.train["com_id"].value)) {
		document.train["com_id"].style.background = "ff0000";
		document.train["com_id"].select();
		errWindow("com_id");
		return false;
	}
	else {
		document.train["com_id"].style.background = "ffffff";
	}
	if (isBlank(document.train["com_name"].value)) {
		document.train["com_id"].style.background = "ff0000";
		document.train["com_id"].value = ""; //Clear out to force re-entry
		document.train["com_id"].select();
		errWindow("com_id");
		return false;
	}
	else {
		document.train["com_id"].style.background = "ffffff";
	}
	if (isBlank(document.train["trezlname"].value)) {
		document.train["trezlname"].style.background = "ff0000";
		document.train["trezlname"].select();
		errWindow("trezlname");
		return false;
	}
	else {
		document.train["trezlname"].style.background = "ffffff";
	}
	if (isBlank(document.train["at1fname"].value)) {
		document.train["at1fname"].style.background = "ff0000";
		document.train["at1fname"].select();
		errWindow("at1fname");
		return false;
	}
	else {
		document.train["at1fname"].style.background = "ffffff";
	}
	if (isBlank(document.train["at1lname"].value)) {
		document.train["at1lname"].style.background = "ff0000";
		document.train["at1lname"].select();
		errWindow("at1lname");
		return false;
	}
	else {
		document.train["at1lname"].style.background = "ffffff";
	}
	var str = document.train["phone1"].value;
	if ((isBlank(document.train["phone1"].value)) || !isNumeric(document.train["phone1"].value) || (str.length != 3)) {
		document.train["phone1"].style.background = "ff0000";
		document.train["phone1"].select();
		errWindow("phone");
		return false;
	}
	else {
		document.train["phone1"].style.background = "ffffff";
	}
	var str = document.train["phone2"].value;
	if ((isBlank(document.train["phone2"].value)) || !isNumeric(document.train["phone2"].value) || (str.length != 3)) {
		document.train["phone2"].style.background = "ff0000";
		document.train["phone2"].select();
		errWindow("phone");
		return false;
	}
	else {
		document.train["phone2"].style.background = "ffffff";
	}
	var str = document.train["phone3"].value;
	if ((isBlank(document.train["phone3"].value)) || !isNumeric(document.train["phone3"].value) || (str.length != 4)) {
		document.train["phone3"].style.background = "ff0000";
		document.train["phone3"].select();
		errWindow("phone");
		return false;
	}
	else {
		document.train["phone3"].style.background = "ffffff";
	}
	if (isBlank(document.train["class"].value)) {
		document.train["class"].style.background = "ff0000";
		document.train["class"].focus();
		errWindow("class");
		return false;
	}
	else {
		document.train["class"].style.background = "ffffff";
	}
	return true;
}

function clear_form() {
	document.train.action = "training.php";
	document.train["com_id"].value = "";
	document.train.submit();
	document.train.reset();
}

function load_form() {
	if (isBlank(document.train["com_id"].value)) {
		document.train.com_id.focus();
	} 
	else {
		document.train.trezlname.focus();
	}
}

