	function matrixClick(input) {
	var inputName= input.name;
	var counter = input.form["mandatoryResponsesRequired_"+inputName+"_counter"];

	var actualNum = $F(input.form['mandatoryResponsesRequired'+inputName.substring(inputName.indexOf('_'))]);
	if(input.checked) {
		if($F(counter) > 0) {
			counter.value = Number(counter.value) - 1;
			return true;
		} else {
			alert("You can not select more than "+actualNum+" responses.");
			return false;
		}
	} else {
		counter.value =  Number(counter.value) + 1;
		return true;
	}
}
	
	function focusOnIt() {
		if (!((navigator.appName == "Microsoft Internet Explorer") && ((parseInt(navigator.appVersion) <= 3)) )) {
			window.focus();
		} 
	}


	function populateNext(formObj, currentListNumber, currentSquID) {

		currentListObj = eval('formObj.input_' + currentListNumber + '_' + currentSquID);

		nextListNumber = currentListNumber + 1;
		subsequentListNumber = currentListNumber + 2;

		updateListObj = eval('formObj.input_' + nextListNumber + '_' + currentSquID);

		newOptionPos = 1;

		for (i = 1; i < currentListObj.options.length; i++) {
			if (currentListObj.selectedIndex != i) {
				updateListObj.options[newOptionPos] = new Option(currentListObj.options[i].text);
				updateListObj.options[newOptionPos].value = currentListObj.options[i].value;
				newOptionPos = newOptionPos + 1;
			}
		}


		for (j = subsequentListNumber; j <= eval('formObj.mandatoryNoOfPriorities_' + currentSquID + '.value'); j++) {		
			secondaryUpdateListObj = eval('formObj.input_' + j + '_' + currentSquID);
			countTo = secondaryUpdateListObj.options.length;
			for (k = countTo; k >= 0; k--) {
				secondaryUpdateListObj.options.remove(k);
			}
			secondaryUpdateListObj.options[0] = new Option('-');
			secondaryUpdateListObj.options[0].value = '';
		}	
	}
	
	function isValidEmail (emailStr) {

		var emailPat=/^(.+)@(.+)$/; 
		var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]";
		var validChars="\[^\\s" + specialChars + "\]"; 
		var quotedUser="(\"[^\"]*\")";
		var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;
		var atom=validChars + '+'; 
		var word="(" + atom + "|" + quotedUser + ")";
		var userPat=new RegExp("^" + word + "(\\." + word + ")*$");
		var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$");

		var matchArray=emailStr.match(emailPat)
		if (matchArray==null) {
			return false;
		}
		
		var user=matchArray[1];
		var domain=matchArray[2];
		
		if (user.match(userPat)==null) {
			return false;
		}
		
		var IPArray=domain.match(ipDomainPat)
		if (IPArray!=null) {
			for (var i=1;i<=4;i++) {
				if (IPArray[i]>255) {
					return false;
				}
			}
			return true;
		}
		
		var domainArray=domain.match(domainPat)
		if (domainArray==null) {
		    return false;
		}

		var atomPat=new RegExp(atom,"g")
		var domArr=domain.match(atomPat)
		var len=domArr.length
		if (domArr[domArr.length-1].length<2 || 
			domArr[domArr.length-1].length>3) {
			return false;
		}
	
		if (len<2) {
			return false;
		}

		return true;
	}

	function checkOpenLogon(formObj) {

		var alert_message = ""; 

		for (i = 0; i < formObj.mandatoryFields.length; i++) {

			inputType = '';
			if (eval('formObj.' + formObj.mandatoryFields[i].value + '.type')) {
				inputType = eval('formObj.' + formObj.mandatoryFields[i].value + '.type');
			}
			else {
				inputType = eval('formObj.' + formObj.mandatoryFields[i].value + '[0].type');
			}
			
			switch(inputType)
				{
					case "hidden":
						temp = 'nothing';
					break;
					default:
						if (isEmpty(eval('formObj.' + formObj.mandatoryFields[i].value + '.value'))) {
							alert_message = alert_message + '   ' + formObj.mandatoryCaption[i].value + '\n';
						}
					break;
			}

		}

		if (alert_message) { 
			alert ("Your form is incomplete.\n" +
				   "You must supply the following information:\n" +
					alert_message);
			return false;
		} else { 
			return true;
		}

	}
	

	function isEmpty (strValue) {
		return (! strValue.replace (/^(\s*)/, "", strValue));
	}

	function checkSurveyAnswers(formObj) {  
		
		var alert_message = ""; 

		
		for (i = 0; i < formObj.mandatoryFields.length; i++) {

			inputType = '';
			if (eval('formObj.input_' + formObj.mandatoryFields[i].value + '.type')) {
				inputType = eval('formObj.input_' + formObj.mandatoryFields[i].value + '.type');
			}
			else {
				inputType = eval('formObj.input_' + formObj.mandatoryFields[i].value + '[0].type');
			}
			
			switch(inputType)
				{
					case "hidden":
						temp = 'nothing';
					break;
					case "text":
						
						if (eval('formObj.maxValue_' + formObj.mandatoryFields[i].value)) {
							var inputValue = eval('formObj.input_' + formObj.mandatoryFields[i].value + '.value');
							var maxValue = eval('formObj.maxValue_' + formObj.mandatoryFields[i].value + '.value');

							if ( inputValue != maxValue ) {
								alert_message = alert_message + '   Question ' + formObj.mandatorySequence[i].value + ' must total ' + maxValue + '.\n';
							}
						} else {
							if (isEmpty(eval('formObj.input_' + formObj.mandatoryFields[i].value + '.value'))) {
								alert_message = alert_message + '   Question ' + formObj.mandatorySequence[i].value + '\n';
							}
						}
						

					break;
					case "textarea":
						if (isEmpty(eval('formObj.input_' + formObj.mandatoryFields[i].value + '.value'))) {
							alert_message = alert_message + '   Question ' + formObj.mandatorySequence[i].value + '\n';
						}
					break;
					case "checkbox":
						var optionsChecked = 0;
						for (j = 0; j < eval('formObj.input_' + formObj.mandatoryFields[i].value + '.length'); j++) {
							if (eval('formObj.input_' + formObj.mandatoryFields[i].value + '[' + j + '].checked') == true) {
								optionsChecked = optionsChecked + 1;
							}
						}
						if (eval('formObj.mandatoryResponsesRequired_' + formObj.mandatoryFields[i].value)) {
							responsesRequired = eval('formObj.mandatoryResponsesRequired_' + formObj.mandatoryFields[i].value + '.value');
							if (responsesRequired > 0 ) {
								if (optionsChecked != responsesRequired) {
									alert_message = alert_message + '   Question ' + formObj.mandatorySequence[i].value + ' MUST have ' + responsesRequired + ' options checked.\n';
								}
							}
							else if (responsesRequired < 0 ) {
								responsesRequired = 0 - responsesRequired;
								if (optionsChecked == 0) {
									alert_message = alert_message + '   Question ' + formObj.mandatorySequence[i].value + ' must have at least 1 and up to a maximum of ' + responsesRequired + ' options checked.\n';
								}
								else if (optionsChecked > responsesRequired) {
									alert_message = alert_message + '   Question ' + formObj.mandatorySequence[i].value + ' can only have a maximum of ' + responsesRequired + ' options checked.\n';
								}
							}
						}
						else {
							if (optionsChecked == 0) {
								alert_message = alert_message + '   Question ' + formObj.mandatorySequence[i].value + '\n';
							}
						}
					break;
					case "radio":
						var optionsChecked = 0;
						for (j = 0; j < eval('formObj.input_' + formObj.mandatoryFields[i].value + '.length'); j++) {
							if (eval('formObj.input_' + formObj.mandatoryFields[i].value + '[' + j + '].checked') == true) {
								optionsChecked = optionsChecked + 1;
							}
						}
						if (optionsChecked == 0) {
							alert_message = alert_message + '   Question ' + formObj.mandatorySequence[i].value + '\n';
						}
						else {
							var optionSelected = '';
							for (k = 0; k < eval('formObj.input_' + formObj.mandatoryFields[i].value + '.length'); k++) {
								if (eval('formObj.input_' + formObj.mandatoryFields[i].value + '[' + k + '].checked') == true) {
									optionSelected = k;
								}
							}
							if (eval('formObj.input_' + formObj.mandatoryFields[i].value + '[optionSelected].value') == -1) {
								if (isEmpty(eval('formObj.input_other_' + formObj.mandatoryFields[i].value + '.value'))) {
									alert_message = alert_message + '   Question ' + formObj.mandatorySequence[i].value + ' you must specify an other.\n';
								}
							}
						}
					break;
					case "select-one":
						if (eval('formObj.input_' + formObj.mandatoryFields[i].value + '.selectedIndex') == 0) {
							alert_message = alert_message + '   Question ' + formObj.mandatorySequence[i].value + '\n';
						}
						else {
							if (eval('formObj.input_' + formObj.mandatoryFields[i].value + '[formObj.input_' + formObj.mandatoryFields[i].value + '.selectedIndex].value') == -1) {
								if (isEmpty(eval('formObj.input_other_' + formObj.mandatoryFields[i].value + '.value'))) {
									alert_message = alert_message + '   Question ' + formObj.mandatorySequence[i].value + '  you must specify an other.\n';
								}
							}
						}
					break;
					case "select-multiple":
						var optionsChecked = 0;
						for (j = 0; j < eval('formObj.input_' + formObj.mandatoryFields[i].value + '.options.length'); j++) {
							if (eval('formObj.input_' + formObj.mandatoryFields[i].value + '.options[' + j + '].selected') == true) {
								optionsChecked = optionsChecked + 1;
							}
						}
						if (eval('formObj.mandatoryResponsesRequired_' + formObj.mandatoryFields[i].value)) {
							responsesRequired = eval('formObj.mandatoryResponsesRequired_' + formObj.mandatoryFields[i].value + '.value');
							if (responsesRequired > 0 ) {
								if (optionsChecked != responsesRequired) {
									alert_message = alert_message + '   Question ' + formObj.mandatorySequence[i].value + ' MUST have ' + responsesRequired + ' options checked.\n';
								}
							}
							else if (responsesRequired < 0 ) {
								responsesRequired = 0 - responsesRequired;
								if (optionsChecked > responsesRequired) {
									alert_message = alert_message + '   Question ' + formObj.mandatorySequence[i].value + ' can only have a maximum of ' + responsesRequired + ' options checked.\n';
								}
							}
						}
						else {
							if (optionsChecked == 0) {
								alert_message = alert_message + '   Question ' + formObj.mandatorySequence[i].value + '\n';
							}
						}
					break;
					default:
						alert('Checkin the default!');
						if (isEmpty(eval('formObj.input_' + formObj.mandatoryFields[i].value + '.value'))) {
							alert_message = alert_message + '   Question ' + formObj.mandatorySequence[i].value + '\n';
						}
					break;
			}

		}

		if (alert_message) { 
			alert ("Your form is incomplete.\n" +
				   "You must supply the following information:\n" +
					alert_message);
			return false;
		} else { 
			return true;
		}
	}
	
	function numericOnly(fieldID) {
		var currentVal = document.getElementById(fieldID).value;	
		document.getElementById(fieldID).value = currentVal.replace(/[^0-9. ]/g, ''); 
	}
	
