
/* findPos from http://www.quirksmode.org/js/findpos.html - could potentially go in separate file as it may be useful elsewhere other than forms */
function findPos(obj) {
	var curleft = curtop = 0;
	if (obj.offsetParent) {
			curleft = obj.offsetLeft
			curtop = obj.offsetTop
			while (obj = obj.offsetParent) {
					curleft += obj.offsetLeft
					curtop += obj.offsetTop
			}
	}
	return [curleft,curtop];
}

function formInitialise() {
		
	totalforms = document.forms.length;
	
	for(f=0;f<totalforms;f++) {
		
		document.forms[f].onsubmit = function() {
			return checkForm(this);
		}
		
		document.forms[f].onreset = resetConfirmation;
		
		inputs = document.forms[f].elements;
		totalinputs = inputs.length;
		
		for(e=0;e<totalinputs;e++) {
			
			input = inputs[e];
			
			if(input.type.toLowerCase() == 'text' || input.type.toLowerCase() == 'password' || input.nodeName.toLowerCase() == 'textarea') {
				// if a focus event already exists
				if(input.onfocus) {
					focusEvent = input.onfocus;
					// append the clearText function to that
					input.onfocus = function() {
						clearText(this);
						focusEvent();
					}
				} else {
					// otherwise, just made the onfocus event clearText
					input.onfocus = function() {
						clearText(this);
					}
				}
				// if a blur event already exists
				if(input.onblur) {
					blurEvent = input.onblur;
					// append the clearText function to that
					input.onblur = function() {
						addText(this);
						blurEvent();
					}
				} else {
					// otherwise, just made the onblur event clearText
					input.onblur = function() {
						addText(this);
					}
				}
				// if password field - check if capslock is on and warn user on keypress
				if (input.type.toLowerCase() == 'password') {
					// added via DOM for simplicity sake. Not a concern as the correction needs to be written in using DOM anyway and this is not an essential feature
					input.setAttribute('onkeypress','capsDetect(event,this)');
					// for IE7-
					if (typeof(lteie7) !== 'undefined') {
						input.onkeypress = function() {capsDetect(event,this)};
					}
				}
			}
			
			// if no auto complete specified
			if (input.className.classExists('noautocom')) {
				// add autocomplete="off" to the form - a proprietary attribute
				input.setAttribute('autocomplete', 'off');
				// for IE6-
				input.autocomplete = 'off';
			}
		}
	}
}

// set emptyString - either left blank, or just spaces entered
var emptyString = /^\s*$/ ;

form_multi_selects = new Object();

function checkForm(current_form) {
	
	//var current_form = this;
	var inputs = current_form.elements;
	var error = false;
	var first = null;
	
	found_form_errors = new Array();
	
	// set the total number of checked radio buttons to 0 by default;
	radio_checked = 0;
	radio_array = '';
	total_group_inputs = 0;
	
	for (var i = 0; i < inputs.length; i++) {
		var input = inputs[i];

		var errorText = null;
		var labelText = null;
		
		switch (input.nodeName.toLowerCase()) {
			case 'select':
				
				input_class = input.className;
				
				// if minimum and maximum values are set (both will be set by default)
				if(input_class.classExists('mins') && input_class.classExists('maxs')) {
					min_value = findEmbeddedValue('mins', 'mine', input_class);
					max_value = findEmbeddedValue('maxs', 'maxe', input_class);
					
					// total_options is the array of <options> in this <select>
					total_options = input.length;
					total_selected = 0;
					
					// total up the number of selected options
					for(y=0;y<total_options;y++) {
						// only add to the total_selected if the value of the selected item is not empty (i.e. the default valueless option in the list)
						if(input[y].selected && input[y].value != '') {
							total_selected++;
						}
					}
					
					if(total_selected < min_value) {
						// if absolutely none have been selected
						if(total_selected == 0) {
							// get appropriate error message from array
							errorText = form_errors['incomplete'];
						// otherwise, some items must have been selected, but just not enough
						} else {
							// get appropriate error message from array
							errorText = form_errors['notenough'];
						}
					// if more than the allowed number of items have been selected
					} else if (total_selected > max_value) {
						// get appropriate error message from array
						errorText = form_errors['toomany'];
					}					
					
				}				
				
				if(errorText) {
					input.onchange = checkValiditySelect;
					found_form_errors.push(findLabel(input.id))
				}
					
				break;
			
			// default for all 'input' and 'textarea' nodes
			default:
				input_type = input.getAttribute('type');
				switch (input_type) {
					
					case 'radio':
						if(input.className.classExists('required')) {
							input_name = input.getAttribute('name');
							// add the current radio name to the form_multi_selects object if it isn't there already and set it to 0
							if(!form_multi_selects[input_name]) {
								form_multi_selects[input_name] = 0;
							}
														
							current_group_array = current_form[""+input_name+""];//current_form.eval(input_name);
							total_group_inputs = current_group_array.length;
							
							// loop through array of radio buttons in this group
							for(r=0;r<total_group_inputs;r++) {
								
								// if the radio button being focussed on in the loop is the same as the current input
								if(current_group_array[r] == input) {
									// if the radio button is checked
									if(current_group_array[r].checked) {
										// increment total of checked items in this group
										form_multi_selects[input_name]++
									}
									// if this is the last loop and no radio buttons were found to have been checked
									if(r==(total_group_inputs-1) && form_multi_selects[input_name] == 0) { // was radio_checked
										// set the error text
										errorText = form_errors['incomplete'];
									}
								}
							}
							// if an error has been detected after looping through all radio buttons in this group
							if(errorText) {
						
								// find the main label for this radio group - search from 3 parent nodes up and return the 1st occurrence of a div with class formlabel
								input_label = getElementsByClassName(input.parentNode.parentNode.parentNode, 'span', 'label')[0].innerHTML;
								
								// add the radio label to the form errors
								found_form_errors.push(input_label);
								
								// re-loop through and add onchange event to all radio buttons in the group
								for(q=0;q<total_group_inputs;q++) {
									// find the last input in this group so it can be passed to onchange to write the error there
									current_group_array[q].last_group_input = current_group_array[total_group_inputs-1];
									
									// check if an onchange event already exists (e.g. submit form onchange)
									if(current_group_array[q].onchange) {
										// save the onchange event
										changeEvent = current_group_array[q].onchange;
										current_group_array[q].onchange = function() {
											// check validity
											checkValidityRadio(this,this.last_group_input,current_form);
											// append old onchange event
											changeEvent();
										}
									} else {
										current_group_array[q].onchange = function() {
											// check validity
											checkValidityRadio(this,this.last_group_input,current_form);
										}
									}
								}
								// reset variables associated with this radio button group
								current_group_array = '';
								total_group_inputs = 0;
								// reset total of checked items in this group
								form_multi_selects[input_name] = 0;
							}
						}
						break;
					case 'checkbox':
						
						input_class = input.className;
						// if minimum and maximum values are set (both will be set by default)
						if(input_class.classExists('mins') && input_class.classExists('maxs')) {
							min_value = findEmbeddedValue('mins', 'mine', input_class);
							max_value = findEmbeddedValue('maxs', 'maxe', input_class);
							
							input_name = input.getAttribute('name');
							// add the current radio name to the form_multi_selects object if it isn't there already and set it to 0
							if(!form_multi_selects[input_name]) {
								form_multi_selects[input_name] = 0;
							}
							
							current_group_array = current_form[""+input_name+""];//current_form.eval(input_name);
							total_group_inputs = current_group_array.length;
							
							// loop through array of radio buttons in this group
							for(r=0;r<total_group_inputs;r++) {
								// if the radio button being focussed on in the loop is the same as the current input
								if(current_group_array[r] == input) {
									// if the radio button is checked
									if(current_group_array[r].checked) {
										// increment total of checked items in this group
										form_multi_selects[input_name]++
									}
									
									// if this is the last loop
									if(r==(total_group_inputs-1)) {
										// if the total selected is less than the minimum required
										if(form_multi_selects[input_name] < min_value) {
											// if absolutely none have been selected
											if(form_multi_selects[input_name] == 0) {
												// get appropriate error message from array
												errorText = form_errors['incomplete'];
											// otherwise, some items must have been selected, but just not enough
											} else {
												// get appropriate error message from array
												errorText = form_errors['notenough'];
											}
										// if more than the allowed number of items have been selected
										} else if (form_multi_selects[input_name] > max_value) {
											// get appropriate error message from array
											errorText = form_errors['toomany'];
										}	
									}	
								}
							}
							// if an error has been detected after looping through all checkboxes in this group
							if(errorText) {
								// find the main label for this radio group - search from 3 parent nodes up and return the 1st occurrence of a div with class formlabel
								input_label = getElementsByClassName(input.parentNode.parentNode.parentNode, 'span', 'label')[0].innerHTML;
								
								// add the radio label to the form errors
								found_form_errors.push(input_label);
								
								// re-loop through and add onchange event to all radio buttons in the group
								for(q=0;q<total_group_inputs;q++) {
									// find the last input in this group so it can be passed to onselect to write the error there
									current_group_array[q].last_group_input = current_group_array[total_group_inputs-1];
									current_group_array[q].min_value = min_value;
									current_group_array[q].max_value = max_value;
									current_group_array[q].onclick = function() {
										checkValidityCheckbox(this,this.last_group_input,this.min_value,this.max_value,current_form);
									}
								}
								// reset variables associated with this radio button group
								current_group_array = '';
								total_group_inputs = 0;
								// reset total of checked items in this group
								form_multi_selects[input_name] = 0;
							}
						}
						break;	
						
					case 'file':
						// check for incomplete field
						if (input.className.classExists('required') && input != null && (input.value.match(emptyString) || input.value==form_fields[input.name])) {
							errorText = form_errors['incomplete'];
							found_form_errors.push(findLabel(input.id));
						}
						
						if(errorText) {
							if(input.onchange) {
								changeEvent = input.onchange;
								// append the function to the existing onchange event
								input.onchange = function() {
									checkValidity(this);
									changeEvent();
								}
								// FOR IE 4 and 5 - uncomment it later when you've detected the browser
								// input.onpropertychange = function() {...
							} else {
								// otherwise, just make the onchange event checkValidity
								input.onchange = function() {
									checkValidity(this);
								}
							}
						}
						break;
					
					case 'hidden':
					case 'image':
					case 'reset':
					case 'submit':
					case 'button':
						// do nothing
						break;
						// password, text, textarea (has no 'type' attribute so it must be included in the default)
					default:
						if (input.className.classExists('validEmail') && input.value != null && input.value != '' && !input.value.validEmail()) {
							errorText = form_errors['email'];
							found_form_errors.push(findLabel(input.id));
						} else if (input.className.classExists('validPostcode') && input.value != null && input.value != '' && !input.value.validPostcode()) {
							errorText = 'Please supply a valid post code';
							found_form_errors.push(findLabel(input.id));
						} else if (input.className.classExists('validDecimal') && input.value != null && input.value != '' && !input.value.validDecimal()) {
							errorText = 'Please supply a valid number';
							found_form_errors.push(findLabel(input.id));
						} else if (input.className.classExists('required') && input != null && (input.value.match(emptyString) || input.value == form_fields[input.name])) {
							errorText = form_errors['incomplete'];
							found_form_errors.push(findLabel(input.id));
						}
						
						if(errorText) {
							if(input.onkeyup) {
								keyupEvent = input.onkeyup;
								// append the function to the existing onfocus event
								input.onkeyup = function() {
									checkValidity(this);
									keyupEvent();
								}
							} else {
								// otherwise, just make the onfocus event checkValidity
								input.onkeyup = function() {
									checkValidity(this);
								}
							}
						}
						break;
					}
				break;
			}
		
		if (errorText) {
			if (first == null) {
				first = input;
			}

			error = true;
			writeCorrection(input, errorText);
			
		}
	}
	if (error) {
		error_message = form_error_message_start + '\n\n';
		for(e=0;e<found_form_errors.length;e++) {
			error_message += '* ' + found_form_errors[e] + '\n';
		}
		error_message += '\n' + form_error_message_end;
		alert(error_message);
		first.focus();
		return false;
	}

	return true;
}


function findLabel(input_id) {
	labels = document.getElementsByTagName('label');
	for(b=0;b<labels.length;b++) {
		label = (labels[b].getAttribute('for')) ? labels[b].getAttribute('for') : labels[b].getAttribute('htmlFor');
		if(label == input_id) {
			return labels[b].innerHTML;
		}
	}
}


function writeCorrection(input, text, correct) {
	var spans = input.parentNode.getElementsByTagName('span');
	var span = spans[0];

	if (typeof text == 'undefined') {
		if (span != null) {
			input.parentNode.removeChild(span);
		}

		for (var j = 0; j < spans.length; j++) {
			if (spans[j].className.classExists('correctiontext')) {
				input.parentNode.removeChild(spans[j]);

				break;
			}
		}
	} else {
		if (span == null) {
			input.parentNode.appendChild(document.createElement('br'));
			var newText = document.createElement('span');
			newText.className = 'correctiontext';
			input.parentNode.appendChild(newText);
		}

		var spans = input.parentNode.getElementsByTagName('span');

		for (var j = 0; j < spans.length; j++) {
			if (spans[j].className.classExists('correctiontext')) {
				var correctionText = spans[j];
				break;
			}
		}
		
		if(correct == true) {
			correctionText.className = correctionText.className.removeClass("warning");
		} else {
			correctionText.className = correctionText.className.addClass("warning");
		}

		writeSpan(correctionText, text);
	}

	return true;
}




function writeSpan(span, text) {
	var children = span.childNodes;

	for (var i = 0; children.length > 0;) {
		span.removeChild(children[i]);
	}

	var textNode = document.createTextNode(text);
	span.appendChild(textNode);

	return true;
}
			

function checkValidityCheckbox(input,last_group_input,min_value,max_value,current_form) {
	
	input_name = input.getAttribute('name');
	// add the current radio name to the form_multi_selects object if it isn't there already and set it to 0
	if(!form_multi_selects[input_name]) {
		form_multi_selects[input_name] = 0;
	}
	
	current_group_array = current_form[""+input_name+""];//current_form.eval(input_name);
	total_group_inputs = current_group_array.length;
	
	// loop through array of radio buttons in this group
	for(r=0;r<total_group_inputs;r++) {
		// if the checkbox being focussed on in the loop is the same as the current input
		
		// if the checkbox is checked
		if(current_group_array[r].checked) {
			// increment total of checked items in this group
			form_multi_selects[input_name]++
		}
		
		// if this is the last loop
		if(r==(total_group_inputs-1)) {
			// if the total selected is less than the minimum required
			if(form_multi_selects[input_name] < min_value) {
				// if absolutely none have been selected
				if(form_multi_selects[input_name] == 0) {
					// write the error
					writeCorrection(last_group_input, form_errors['incomplete']);
				// otherwise, some items must have been selected, but just not enough
				} else {
					// write the error
					writeCorrection(last_group_input, form_errors['notenough']);
				}
			// if more than the allowed number of items have been selected
			} else if (form_multi_selects[input_name] > max_value) {
				// write the error
				writeCorrection(last_group_input, form_errors['toomany']);
			} else {
				// write the okay to submit message
				writeCorrection(last_group_input, form_errors['okay'], true);
			}
			form_multi_selects[input_name] = 0;
		}	
	}
}


function checkValidityRadio(input,last_group_input,current_form) {	
	
	input_name = input.getAttribute("name");
	// add the current radio name to the form_multi_selects object if it isn't there already and set it to 0
	if(!form_multi_selects[input_name]) {
		form_multi_selects[input_name] = 0;
	}
	
	current_group_array = current_form[""+input_name+""];//current_form.eval(input_name);
	total_group_inputs = current_group_array.length;
	
	// loop through array of radio buttons in this group
	for(r=0;r<total_group_inputs;r++) {
			
		// if the radio button is checked
		if(current_group_array[r].checked) {
			// increment total of checked items in this group
			form_multi_selects[input_name]++;
		}
		
		// if this is the last loop
		if(r==(total_group_inputs-1)) {
			// if no radio buttons were found to have been checked
			if(form_multi_selects[input_name] == 0) {
				
				// write the error
				writeCorrection(last_group_input, form_errors['incomplete']);
			
			// else, a radio button has been checked
			} else {
				// write the okay to submit message
				writeCorrection(last_group_input, form_errors['okay'], true);
			}
			// reset total of checked items in this group
			form_multi_selects[input_name] = 0;
		}
	}
}

function checkValiditySelect() {
	var input = this;
	var spans = input.parentNode.getElementsByTagName("span");
	var labelText = null;
	
	input_class = input.className;
				
	// if minimum and maximum values are set (both will be set by default)
	if(input_class.classExists('mins') && input_class.classExists('maxs')) {
		min_value = findEmbeddedValue('mins', 'mine', input_class);
		max_value = findEmbeddedValue('maxs', 'maxe', input_class);
		
		// total_options is the array of <options> in this <select>
		total_options = input.length;
		total_selected = 0;
		
		// total up the number of selected options
		for(y=0;y<total_options;y++) {
			if(input[y].selected) {
				total_selected++;
			}
		}
		
		if(total_selected < min_value) {
			// if absolutely none have been selected
			if(total_selected == 0) {
				// get appropriate error message from array
				writeCorrection(input, form_errors['incomplete']);
			// otherwise, some items must have been selected, but just not enough
			} else {
				// get appropriate error message from array
				writeCorrection(input, form_errors['notenough']);
			}
		// if more than the allowed number of items have been selected
		} else if (total_selected > max_value) {
			// get appropriate error message from array
			writeCorrection(input, form_errors['toomany']);
		} else {
			writeCorrection(input, form_errors['okay'], true);
		}
		
	}
}

// checks on keystroke, etc
function checkValidity(input) {
	var spans = input.parentNode.getElementsByTagName('span');
	var labelText = null;

	for (var j = 0; j < spans.length; j++) {
		if (spans[j].className.classExists('labelText')) {
			var labelText = spans[j];
		}
	}
	
	posted_value = input.value;
	// if the posted value is the same as the default value for this field (i.e. the field has been submitted without completion)
	// value is checked against the default value for this field in the form_fields array. JavaScript's input.defaultValue is not used as it would error even if the field had been correctly submitted but a separate field returned an error with PHP. The defaultValue would have then become the user-entered data which IS correct.
	if(input.value == form_fields[input.name]) {
		// clear the posted value
		posted_value = "";
	}
	
	
	if (posted_value.match(emptyString)) {
		if (!input.className.classExists('required')) {
			writeCorrection(input, "");
			//since this field is not required, don't put the "please complete this field" message in if all data is removed
		} else {
			writeCorrection(input, form_errors['incomplete']);
		}
	} else if (input.className.classExists('validEmail') && !posted_value.validEmail()) {
		writeCorrection(input, form_errors['email']);
	} else if (input.className.classExists('validPostcode') && !posted_value.validPostcode()) {
		writeCorrection(input, 'Please supply a valid post code');
	} else if (input.className.classExists('validDecimal') && !posted_value.validDecimal()) {
		writeCorrection(input, 'Please supply a valid number');
	} else {
		writeCorrection(input, form_errors['okay'], true);
	}

	return true;
}

var browserVersion = navigator.appVersion;
var konquerorVersion = null;

// Check for Konqueror
if(navigator.vendor == 'KDE') {
	var versionPosition = browserVersion.indexOf('Konqueror/')+10;
	var konquerorVersion = browserVersion.substring(versionPosition,versionPosition+2);
}

// caps lock detect from http://www.howtocreate.co.uk/jslibs/script-capsDetect
// modified to enter warning message using DOM rather than alert and to filter out browsers that don't support it
function capsDetect(e,input) {
	// loose browser detection - filter out known browsers that can't tell the difference between lowercase and uppercase letters
	// Konqueror 3.1-, IE4 Windows, OmniWeb 4.2-, Rhino + pDOM (Clue browser), WebTV
	if((konquerorVersion && parseFloat(konquerorVersion)<=3.1) || (document.all && !document.getElementById) || (typeof(HotJava) !== 'undefined' && document.layers && !document.classes) || (document.getElementById && !document.childNodes) || (navigator.appName.indexOf('WebTV') != -1)) {
		// unsupported browser
	} else {
		// okay to run	
		// if the browser did not pass event information to the handler, check in window.event
		if (!e) {
			e = window.event;
		}
		if (!e) {
			return;
		}
		// what (case sensitive in good browsers) key was pressed
		// this uses all three techniques for checking, just in case
		var theKey = 0;
		// Netscape 4+, etc.
		if(e.which) {
			theKey = e.which;
		// Internet Explorer, etc.
		} else if (e.keyCode) {
			theKey = e.keyCode;
		// Gecko - probably not needed
		} else if (e.charCode) {
			theKey = e.charCode
		}
		// was the shift key was pressed
		var theShift = false;
		// Internet Explorer, etc.
		if (e.shiftKey) {
			theShift = e.shiftKey;
		// Netscape 4
		} else if (e.modifiers) {
			// check the third bit of the modifiers value (says if SHIFT is pressed)
			if (e.modifiers & 4) { // bitwise AND
				theShift = true;
			}
		}
		
		input_error_span = input.parentNode.getElementsByTagName('span')[0];
		// if there are no spans beneath this input's parent node OR there no span with 'warning' on it OR the span has no className
		if(!input_error_span || !input_error_span.className.classExists('warning') || !input_error_span.className.classExists('okay')) {
			// if upper case, check if shift is not pressed OR if lower case, check if shift is pressed
			if((theKey > 64 && theKey < 91 && !theShift) || (theKey > 96 && theKey < 123 && theShift)) {
				//writeCorrection(input, caps_lock_on, 'alert');
				showCallout(input, caps_lock_on);
			} else {
				if(document.getElementById) {
					callout = document.getElementById('callout');
					if(callout) {
						fade('callout',getOpacity(callout),'out');
					}
				}
			}
		}
	}
}

// Safari label click support - from: http://www.freshlabs.de/journal/archives/2006/10/clickable-form-labels-for-safari-and-ie/
// modified for versions prior to 3, also removed IE inclusion as IE already supports label click (even in IE5 Mac)
function fixFormLabels() {
	var labels;
	// Safari...
	if(navigator.userAgent.indexOf('Safari')> 0) {
		var versionPosition = browserVersion.indexOf('Version/')+8;
		// Versions less than 3
		if(parseInt(browserVersion.charAt(versionPosition))<3) {
			labels = document.getElementsByTagName('label');
			for(i=0; i<labels.length; i++) {
				labels[i].onclick = function() {
					var target = document.getElementById(this.getAttribute('for'));
					// Checkboxes or radio button labels
					if(target.type == 'checkbox' || target.type == 'radio') {
						target.checked = target.checked == false ? true : false;
					} else {
						// Textareas and input fields, Select elements
						target.focus();
					}
				}
			}
		}
	}
}

function showCallout(input, text) {
	
	var inputPosition = findPos(input);
	
	if(inputPosition) {
			
		// if the callout doesn't already exist, create it
		if (!document.getElementById('callout')) {
			
			callout = document.createElement('div');
			callout.id = 'callout';
			
			input.parentNode.appendChild(callout);
							
			// add text
			var textNode = document.createTextNode(text);
			callout.appendChild(textNode);
			
			var arrow = document.createElement('span');
			arrow.id = 'calloutarrow';
			
			callout.appendChild(arrow);
			setOpacity(callout, 0);
		}
			
		// default width is 15em, but make it smaller if there is less text
		if(text.length<30) {
			callout.style.width = text.length/2 + 'em';
		}
		
		// position it at the base of the input
		callout.style.top = (inputPosition[1] + input.offsetHeight + 2) + 'px';
		callout.style.left = inputPosition[0] + 'px';
		
		callout.style.visibility = 'visible';
		
		fade('callout',getOpacity(callout),'in');
			
		clearTimeout(window.hider);
		window.hider = setTimeout('fade(\'callout\',100,\'out\')', 3000);
	}
}

function removeElement(objId) {
	obj = document.getElementById(objId);
	if(obj) {
		parentElem = obj.parentNode;
		parentElem.removeChild(obj);
	}
}


function getOpacity(obj) {
	// even if not supported by the user's browser, obj.style.opacity should still have a value set as set by setOpacity
	if(obj.style.opacity) {
		opacity = obj.style.opacity*100;
		return (opacity>=99)?100:opacity;
	} else {
		return 0;
	}
}

function setOpacity(obj, opacity) {
  opacity = (opacity == 100)?99.999:opacity;
  
  // IE/Win
  obj.style.filter = 'alpha(opacity:'+opacity+')';
  
  // Safari<1.2, Konqueror
  obj.style.KHTMLOpacity = opacity/100;
  
  // Older Mozilla and Firefox
  obj.style.MozOpacity = opacity/100;
  
  // Safari 1.2, newer Firefox and Mozilla, CSS3
  obj.style.opacity = opacity/100;
  
}

function fade(objId,opacity,fadeDir) {
	if (document.getElementById) {
		obj = document.getElementById(objId);
		if(fadeDir=='in') {
			if (opacity <= 100) {
				setOpacity(obj, opacity);
				if(opacity<100) {
					opacity += 10;
					window.setTimeout('fade(\''+objId+'\','+opacity+',\'in\')', 25);
				}
			}
		} else if (fadeDir=='out') {
			if (opacity >= 0) {
				setOpacity(obj, opacity);
				if(opacity>0) {
					opacity -= 10;
					window.setTimeout('fade(\''+objId+'\','+opacity+',\'out\')', 25);
				} else {
					clearTimeout(window.hider);
					removeElement(objId);
				}
			}
		}
	}
}

// to be put on reset buttons
function resetConfirmation() {
	return confirm(form_reset_message);
}

// to be put on cancel buttons
function cancelConfirmation() {
	return confirm(cancel_confirm_message);
}

//------------------------- functions for clearing default text out

function clearText(input) {
	// compare the value of the form field to the corresponding value for this field in the array
	if (input.value==form_fields[input.name]) { // used to be if(textfield.defaultValue==textfield.value)
		// if it's the same, clear out the text
		input.value = '';
	}
}

function addText(input) {
	// if the textfield is blank onblur and the field is required, the defaultValue should be added back in
	if (input.value == '' && input.className.classExists('required')) {
		input.value = input.defaultValue;
	}
}
