//Javascript to disable all buttons when a user presses one. 
//This file is included in error.asp

//Note: when a button is "disabled" its value is not sent with the form
//Some of CircleLending's form make decisions based on which form button 
//was pressed. to get around this problem a hidden input field labeled
//below is instered into each form. This hidden field is then altered
//to get the value of the button that was pressed.

var theHiddenField = "buttonDisableXYZ";
//add the event to the onload tag
var isNetscape;
if (navigator.appName == "Netscape" || navigator.appName == "netscape") {
	isNetscape = true;
} else {
	isNetscape = false; 
}

if (!isNetscape) {
	addLoadEvent(onLoadDisableButtons); 
}

function addLoadEvent(func) {
	var oldonload = window.onload;
	if (typeof window.onload != 'function') {
	window.onload = func;
  } else {
	window.onload = function() {
	oldonload();
	func();
    }
  }
}

function onLoadDisableButtons() {
	//for all forms add an onsubmit handler to disable buttons
	for (var i=0; i < document.forms.length; i++) {
		var tempForm = document.forms[i];
		if (tempForm.onsubmit == null) {
			tempForm.onsubmit = onExit; 	
		} else {
			var oldonsubmit = tempForm.onsubmit;
			tempForm.onsubmit = function () {
				var isValid = oldonsubmit();
				if (isValid == true || isValid == null) {
					onExit();
					return true;  				
				} else {
					return false; 
				}
			}
		}
		
		
		for (var j=0; j<document.forms[i].length; j++) {
			var tempInput = document.forms[i].elements[j];
			var tempAction = document.forms[i].action;
					
			if (tempInput.type == 'submit' || tempInput.type=='reset') {
				if (tempInput.onclick == null) {
					tempInput.onclick = assignHiddenField; 
				} else {
		
					var oldonclick = tempInput.onclick;
					tempInput.onclick = function () {
						var isValid = oldonclick();
						if (isValid == true || isValid == null) {
							assignHiddenField();
							return true; 
						} else {
							return false; 
						}
					}
				}
			} else if (tempInput.type == "button") {
				var myString = tempInput.onclick + " ";
				var myMatch = "document.location";
				var myRE = new RegExp(myMatch, "i", "g")
				if (myString.match(myRE)) {
					var oldonclick = tempInput.onclick;
					tempInput.onclick = function () {
						var isValid = oldonclick();
						if (isValid == true || isValid == null) {
							assignHiddenField();
							onExit();
						} else {
							return false; 
						}
					}					
				}
			}	
		}
	}
}


function assignHiddenField() {

	hiddenField = document.getElementById("buttonDisableXYZ");
	if (hiddenField) {
		hiddenField.value = window.event.srcElement.value;
		hiddenField.name = window.event.srcElement.name;
	} else {
	}
	return true; 
}


function onExit() {
	for (var i=0; i < document.forms.length; i++) {
		for (var j=0; j<document.forms[i].length; j++) {
			var tempInput = document.forms[i].elements[j];
	
			if (tempInput.type == "submit" || tempInput.type == "button" || tempInput.type == "reset") {
				tempInput.disabled = "true";
			}
		
		}
	}
	return true;
}