<!--
// Trim leading and trailing spaces from a string
trim = function(str) { 
	str = str.replace(/(^\s+)|(\s+$)/g,'');
	return str;
} 

// Encode string for URL
urlEncode = function(sStr) {
    return escape(sStr).
             replace(/\+/g, '%2B').
              replace(/\"/g,'%22').
               replace(/\'/g, '%27').
                replace(/\//g,'%2F');
}

// Form validation script v2.13
// Validate function scans for input fields with matching [id].validate hidden fields
// Value argument of the hidden field is used for the error feedback message
// Alt argument is used for [text/numeric/email/password]; [focus/select/none];
//                          [predecessor]; [predecessor type (display,compare,=)]
// Size argument used to set the minimum characters required
//      *Set as 1 for default any size

validate = function(form) {
	for(var i=0;i<form.length;i++) {
		var obj = form.elements[i];
		// Test all visible form objects
		if (obj.type != 'hidden') {
			var objID = obj.id;
			var vObj = form[objID+'.validate']
			// Does validation data exist
			if (vObj) {
				var isError = false;
				var message = vObj.value.replace(/\\n/g,'\n');
				var minSize = vObj.size;
				if (minSize < 2) {
					minSize = 0;
				}
				var alt = vObj.alt;
				var actions = new Array();
				var count = 0;
				var index1 = 0;
				var index2 = alt.indexOf('\;');
				while (index2 >= 0) {
					actions[count] = alt.substring(index1,index2);
					index1 = index2+1;
					index2 = alt.indexOf('\;',index1);
					count++;
				}
				actions[count] = alt.substring(index1,alt.length);
				vType	= (actions[0]) ? actions[0] : 'text';
				sType	= (actions[1]) ? actions[1] : 'focus';
				pred	= (actions[2]) ? actions[2] : '';
				pType	= (actions[3]) ? actions[3] : '';
				var doCheck = true;
				if (pred != '') {
					if (pType == 'display') { // Check object have display set to visible
						var styleProperty
						if (document.getElementById) {
							styleProperty = document.getElementById(pred).style;
						} else if (document.all) {
							styleProperty = document.all[pred].style;
						} else if (document.layers) {
							styleProperty = document.layers[pred];
						}
						if (styleProperty.display == 'none') {
							doCheck = false;
						}
					}
					if (pType == 'compare') { // Compare fields
						if (obj.value != form[pred].value) {
							isError = true;
							if (vType == 'password') {
								obj.value = '';
								form[pred].value = '';
								obj = form[pred];
							}
						}
					}
					if (pType.substr(0,1) == '=') { // Check variable equal to value
						var testValue = pType.substr(1);
						if (this[pred] != testValue) {
							doCheck = false;
						}
					}
				}
				if (doCheck) {
					// Trim leading/trailing spaces
					var value = obj.value.replace(/(^\s+)|(\s+$)/g,'');
					// Check if any value has been entered
					if (value == '') {
						isError = true;
					}
					// Check if value is numeric only > 0
					if (vType == 'numeric' && isNaN(value)) {
						isError = true;
						message += '\nThis is a numeric field.';
					} else if (vType == 'numeric' && value < 1) {
						isError = true;
						message += '\nYou must supply a value greater than zero.';
					}
					if (value.length < minSize && minSize > 0) {
						isError = true;
						message += '\nYou must enter a minimum of '+minSize+' characters.';
					}
					// Check if value is a valid email address
					var pattern  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
					if (vType == 'email' && !pattern.test(value)) {
						isError = true;
					}
					// Check if checkbox is checked
					if (vType == 'checkbox' && !obj.checked) {
						isError = true;
					}
					// Check if is valid radio selection
					if (obj.type == 'radio') {
						sType = 'none';
						obj = form[obj.name];
						isError = true;
						for (var j=0;j<obj.length;j++) {
							if (obj[j].checked) {
								isError = false;
							}
						}
					}
					// Process errors
					if (isError) {
						alert(message);
						if (sType == 'select') {
							obj.select();
						} else if (sType != 'none') {
							obj.focus();
						}
						return false;
					}
				}
			}
		}
	}
	return true;
}
//-->
