<!--
function findObj(n, d) {
	var p,i,x;

	if(!d) d=document;
	
	if((p=n.indexOf("?"))>0&&parent.frames.length) {
		d=parent.frames[n.substring(p+1)].document;
		n=n.substring(0,p);
	}

	if(!(x=d[n])&&d.all) x=d.all[n];

	for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];

	for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=findObj(n,d.layers[i].document);

	if(!x && document.getElementById) x=document.getElementById(n);

	return x;
}

function validate() {
	var i,p,q,nm,test,num,min,max,errors='',args=validate.arguments;
	
	for (i=0; i<(args.length-2); i+=3) {
		test=args[i+2];
		val=findObj(args[i]);

		if (val) {
			nm=val.title;
			if ((val=val.value)!="") {
				if (test.indexOf('isPass')!=-1)	{
					if (val != document.forms[0].confirm.value)	errors+='- Password and Confirm Password must be the same.\n';
				} else if (test.indexOf('isLen')!=-1) {
					if (p=test.indexOf(':')) min=test.substring(p+1);

					if (min>val.length)	errors+='- '+nm+': Must be at least ' +min+ ' characters in length.\n';
				} else if (test.indexOf('isEmail')!=-1)	{
					p=val.indexOf('@');

					if (p<1 || p==(val.length-1)) errors+='- '+nm+': Must contain an e-mail address (@).\n';
				} else if (test.indexOf('isTel')!=-1) { //tel numbers
					if(checkPhoneNumber(val) == false) {
						errors+='- '+nm+': Can only contain numbers, spaces, <(>, <)>, <+> or <->.\n';
					}
				} else if (test!='R') { //numbers only
					if (isNaN(val))	errors+='- '+nm+': Must contain a number.\n';
					
					if (test.indexOf('inRange') != -1) {
						p=test.indexOf(':');
						min=test.substring(8,p);
						max=test.substring(p+1);
						
						if (val<min || max<val)	errors+='- '+nm+': Must contain a number between '+min+' and '+max+'.\n';
					}
				}
			} else if (test.charAt(0) == 'R') errors += '- '+nm+': Is a required field.\n';
		}
	}
		
	return errors;
//	if (errors) alert('The following error(s) occurred:\n\n'+errors);
/*
	if (errors) { 
		return false; 
	} else {
		return true;
	}
*/
}

function checkPhoneNumber(number) {
	for (var i = 0; i <= number.length - 1; i++) {
		if (!parseInt(number.charAt(i)) && number.charAt(i) != ' ' && number.charAt(i) != '0' && number.charAt(i) != ')' && number.charAt(i) != '(' && number.charAt(i) != '-' && number.charAt(i) != '+') {
			return false;
		}
	}
}

			function validateContactNumber(value, what, required) {
				var errors = '';
				//if telephone entered 
				if (value.length != 0) {
					//if tel does not contain only numbers
					if(isNaN(value)) {
						errors += '- ' + what + ' number: Can only contain numbers (0 -9)\n';
					//else if length not 10 digits
					} else if (value.length != 10) {
						errors += '- ' + what + ' number: Must be 10 digits\n';
					}
				} else if (required == true) {
					errors += '- ' + what + ' number: is a required field.\n';
				}
				return errors;
			}
			
	function validateEmailAddress(value, required) {
		var errors = '';
		if (value.length != 0) {
			p = value.indexOf('@');
			if (p < 1) {
				errors += '- Email Address: Must contain an at ( @ ) character\n';
			} else if (p == (value.length-1)) {
				errors += '- Email Address: Must contain a domain name after the ( @ ) character\n';
			}
		} else if (required == true) {
			errors += '- Email Address: is a required field.\n';
		}
		return errors;
	}
			
			//-->
	function checkSearchForm() {
				var errors='';
		

				if (document.frmSearch.frmTitleSearch.checked == false && document.frmSearch.frmKeywordSearch.checked == false && document.frmSearch.frmFilenameSearch.checked == false) {
							errors += "- Please specify at least one method to search by.\n";
				}

				errors += validate('frmSearchText', '', 'R');

		
				if (errors) alert('The following error(s) occurred:\n\n'+errors);
						
				if (errors) { 
					return false; 
				} else {
					return true;
				}
			
		
	}
	
	function checkLoginForm() {
//		alert(frames['sampleframe'].location.href);
//		return false;
		var errors='';

		errors += validate('frmLogin','','R');
		errors += validate('frmPassword','','R');

		if (errors) alert('The following error(s) occurred:\n\n'+errors);
						
		if (errors) { 
			return false; 
		} else {
			return true;
		}
		
	}
