//Window handling, form handling, printable version handling

//WINDOW HANDLING

function explainwin(explainname)  {
	var explainwin = window.open("/explain.cfm?explainname=" + explainname, "explainWindow", "status=no,height=400,width=350,left=150,top=200,scrollbars=yes");
	return;
}

function alertwin()  {
	var explainwin = window.open("/alert.cfm", "alertWindow", "status=no,height=200,width=350,left=150,top=200,scrollbars=yes");
	return;
}

//FORM HANDLING
//Start with the focus in the first form element
function start(formName) {
	document[formName].elements[0].focus();
}

//Open the url selected in the current window. Used in the Popular Links in the topnav.
function formHandler(formName, selectName){
    var FUN = document[formName].elements[selectName];
    var URL = FUN.options[FUN.selectedIndex].value;
    if (URL != "") {
			if (URL.substring(0,4)=="http") { window.open(URL); }
			else { window.location.href = URL; }
		}
}

//Check all the checkboxes in the form. Used in the Renew All button for myloans.
function checkall(form) {
	form.renew_all.value = 1;	
	for (i = 0; i < form.elements.length; i++) {
		if ( form.elements[i].type == "checkbox" ) { form.elements[i].checked = true; }
	}
}

//Checks all the checkboxes in a group. checkname = the name of the checkboxes, and exby is this form.
function checkAll(checkname, exby) {
	for (i = 0; i < checkname.length; i++)
	checkname[i].checked = exby.checked? true:false
}

//Check if form element is empty
function emptyAlert(formName, selectName, fieldName){
	var fieldName = (fieldName == null) ? selectName : fieldName;
	if (document[formName].elements[selectName].value == ""){
		alert("You forgot to include your " + fieldName + "."); 
		document[formName].elements[selectName].focus();
		return true;
	}
	return false;
}

//Disable the form, used in a validation if form elements are not valid
function disableForm(formName) {
	if (document.all || document.getElementById) {
		//for (i = 0; i < document[formName].elements.length; i++) {
			//var tempobj = document[formName].elements[i];
		var frm = document.forms[formName];
		for (i = 0; i < frm.elements.length; i++) {
			var tempobj = frm.elements[i];
			if (tempobj.type.toLowerCase() == "submit"){ tempobj.disabled = true; }
		}
	}
}
// validate that the user has checked one of the radio buttons
function isValidRadio(radio) {
    var valid = false;
    for (var i = 0; i < radio.length; i++) {
        if (radio[i].checked) {
            return true;
        }
    }
    alert("Make a choice from the radio buttons.");
    return false;
}

// validates that the field value string has one or more characters in it
function isNotEmpty(elem) {
  var str = elem.value;
    var re = /.+/;
    if(!str.match(re)) {
        setTimeout("focusElement('" + elem.form.name + "', '" + elem.name + "')", 0);
        return false;
    } else {
        return true;
    }
}

//document.forms[].elements[],
//PRINTABLE VERSION HANDLING
//Auto print the screen and then close the printable version on time out
function Print_Close(){
	ID = window.setTimeout("window.close();", 240000);
	window.print();
} 
	
//Set the printer icon
printOn = new Image();
printOn.src = "/images/print/printiconroll.jpg"
printOff = new Image();
printOff.src = "/images/print/printicon.jpg"

//Switch images. Used by print fuction.
function changeImages() {
	if (changeImages.arguments[0] != ""){
		if (document.images) {
			for (var i=0; i<changeImages.arguments.length; i+=2) {
				document[changeImages.arguments[i]].src = eval(changeImages.arguments[i+1] + ".src");
			}
		} 
	}
}





