
	function validInteger(objQuest,mindigits,maxdigits,strText){
		var myRE = new RegExp("[0-9]*$");
		var myStr = new String(objQuest.value);
		if (myStr.search(myRE) == -1 || myStr.length > maxdigits || myStr.length < mindigits) {
			strAlert += '\n - ' + strText;
			if (blValid) objFocus = objQuest;
			blValid=false;
		}
	}

	function validRadio(objQuest,strText){
		var blChecked = false;
		if (objQuest.length) {
			for (i = 0;  i < objQuest.length;  i++){
				if (objQuest[i].checked)
					blChecked = true;
			}
		} else {
			// if only one option:
			blChecked = true;
			objQuest.checked = true;
		}
		if (!blChecked){
			strAlert += '\n - ' + strText;
			if (blValid) objFocus = objQuest[0];
			blValid=false;
		}
	}

	function validCheck(arrQuest,strText){
		var blChecked = false;
		for (i = 0; i < (arrQuest.length); i++){
			if (arrQuest[i] && arrQuest[i].checked && !blChecked){
				blChecked=true;
			}
		}
		if (!blChecked){
			strAlert += '\n - ' + strText;
			if (blValid) objFocus = arrQuest[0];
			blValid=false;
		}
	}

	function validCheckN(arrQuest,strText,N){
		var numChecked = 0;
		for (i = 0; i < (arrQuest.length); i++){
		  if (arrQuest[i] && arrQuest[i].checked) numChecked++;
		}
		if (numChecked < N){
			strAlert += '\n - ' + strText;
			if (blValid) objFocus = arrQuest[0];
			blValid=false;
		}
	}

	function validRanking(arrQuest,strText,N){
		var numRanked = 0;
		for (i = 0; i < (arrQuest.length); i++){
		  if (arrQuest[i] && Number(arrQuest[i].value)!=NaN && Number(arrQuest[i].value)>0 && Number(arrQuest[i].value)<=N) numRanked++;
		}
		if (numRanked != N){
			strAlert += '\n - ' + strText;
			if (blValid) objFocus = arrQuest[0];
			blValid=false;
		}
	}

	 function validCBset(theForm,quest,iMax,strText) {
		var i;
		var newObj;
		var blChecked = false;

		for(i=1; i<=iMax; i++) {
			newObj = eval("theForm." + quest + "_" + i);
			if ((newObj) && (newObj.checked)) {
				blChecked = true;
			}
		}
		if (!blChecked){
			strAlert += '\n - ' + strText;
			if (blValid) objFocus = eval("theForm." + quest + "_1");
			blValid=false;
		}
	 }

	function validText(objQuest,strText){
		if (objQuest.value==""){
			strAlert += '\n - ' + strText;
			if (blValid) objFocus = objQuest;
			blValid=false;
		}
	}
	
	function validPostcode(objQuest,strText){
		var myRE = /[1-9][0-9][0-9][0-9]$/;
		var myStr = new String(objQuest.value);
		if (myStr.search(myRE) == -1){
			strAlert += '\n - ' + strText;
			if (blValid) objFocus = objQuest;
			blValid=false;
		}
	}

	function validZeroOrMore(objQuest,strText){
		if (!validNumber(10,objQuest) || objQuest.value==""){
			strAlert += '\n - ' + strText;
			if (blValid) objFocus = objQuest;
			blValid=false;
		}
	}

	function validLessThanOther(objQuest,qOther,strText){
		if (objQuest.value=="" || Number(objQuest.value)>Number(qOther.value)){
			strAlert += '\n - ' + strText;
			if (blValid) objFocus = objQuest;
			blValid=false;
		}
	}

function chkDateField(objQuest,pMin,pMax,strText) {
	if ((parseInt(objQuest.value)!=objQuest.value-0) || (objQuest.value < pMin || objQuest.value > pMax))
	{
		strAlert += '\n - ' + strText;
		if (blValid) objFocus = objQuest;
		blValid=false;
		return false;
	}
	else
		return true;
}

function validMonth(objQuest,strText) {
	chkDateField(objQuest, 1, 12, strText);
}

function validDay(objQuest,strText) {
	chkDateField(objQuest, 1, 31, strText);
}

function validYear(objQuest,strText) {
	chkDateField(objQuest, 2004, 2005, strText);
}

function setOther(obj,qOther){
	if (obj.value!=""){
		eval("obj.form."+qOther+".checked=true;");
	}
	else{
		eval("obj.form."+qOther+".checked=false;");
	}
}

	function validLen(objQuest,iLen,strText){
		if (objQuest.value.length<iLen){
			strAlert += '\n - ' + strText;
			if (blValid) objFocus = objQuest;
			blValid=false;
		}
	}

	function validPrompt(objQuest,iLen,strText){
		if (iPrompts==0){
			if (objQuest.value.length<iLen){
				strAlert = strText;
				if (blValid) objFocus = objQuest;
				blValid=false;
				iPrompts=1;
			}
		}
	}

	function checkSameID(target1,target2,iMax,strText){
		var blSame = false;
		var iChecked = 0;
		var obj1;
		var obj2;
		
		for (i = 1;  i <= iMax;  i++){
			obj1=(document.all) ? document.all[target1+i] : document.getElementById(target1+i);
			obj2=(document.all) ? document.all[target2+i] : document.getElementById(target2+i);

			if (obj1 && obj2 && obj1.checked && obj2.checked){
			        blSame = true;
			        break;
				iChecked = i;
			}
		}
		if (blSame){
			strAlert += '\n - ' + strText;
			if (blValid) objFocus = obj2;
			obj2.checked=false;
			blValid=false;
		}
	}

	function checkSame(obj1,obj2,iMax,strText){
		var blSame = false;
		var iChecked = 0;
		for (i = 0;  i <= iMax;  i++){
			if (obj1[i].checked && obj2[i].checked){
			        blSame = true;
				iChecked = i;
			}
		}
		if (blSame){
			strAlert += '\n - ' + strText;
			if (blValid) objFocus = obj2[iChecked];
			blValid=false;
		}
	}

	function clearBoxes(obj,quest, iMin, iMax){
		for (i = iMin;  i <= iMax;  i++){
			newObj = eval("obj.form." + quest + "_" + i);
			if (newObj) newObj.checked = false;
		}
	}

	function chkNotSame(me,other,imax) {
		var i;
		for (i=0;i<imax;i++)
		  if (me[i].checked && other[i].checked) {
			alert('Please choose 2 different items.');
			me[i].checked=false;
			return;
			}
	}


	function validNumber(maxdigits,objQuest){
	// ensure a number NOT zero
		if (objQuest.value=="0") return false;
		var myRE = /[0-9]([0-9]|\s)*$/;
		var myStr = new String(objQuest.value);
		return (myStr.search(myRE) != -1 && myStr.length <= maxdigits);
	}

	function chkOrdering(obj,aQuestions,iMax) {
		var i;
		var newObj;
		if (obj.value!='')		// if clearing, then do nothing
			if (obj.value!=NaN && obj.value<=iMax)
				for(i=1; i<=aQuestions.length; i++) {
					if (obj.name != aQuestions[i] ) {
						newObj = eval("obj.form." + aQuestions[i]);
						if (newObj && (newObj.value == obj.value)) {
							alert('Please enter a ranking that has not already been used.');
							obj.value='';
							obj.focus();
							return;
						}
					}
				}
			else {
				alert('Please enter only numbers between 1 and ' + iMax);
				obj.value='';
			}
	 }
	
	function chkDigit(obj,lo,hi,numdigits) {
	// ensure a number between the low and high values and no longer than numdigits
		if (!obj) return true;
		
		if (isNaN(obj.value) || obj.value.length>numdigits || obj.value>hi || obj.value<lo) { 
			alert("Please enter a " + numdigits + " digit number between " + lo + " and " + hi);
			obj.value = "";
			obj.focus();
			return false;
		}
		
	}
	

	function   validHTMLeq(target,eqValue,strText) {
	  var oTot = (document.all) ? document.all[target] : document.getElementById(target);
	  if (oTot && oTot.innerHTML!=eqValue) {
		strAlert += '\n' + strText;
		blValid=false;
	  }
	}

//---------------------

function GetRadioValue() {
	for (var i=0; i<this.length; i++) 
		if (this[i].checked) return this[i].value;
	return null;
};

function validRegExp(objQuest,strRE,strText){
	// validate using a specified regular expression.
	//
	// note must escape backslashes in the text:
	// eg. strRE  = "^[0-9]+\\tOK\\.$"

	var myRE = new RegExp(strRE);
	var myStr = new String(objQuest.value);

	if (myStr.search(myRE) == -1){
		strAlert += '\n - ' + strText;
		if (blValid) objFocus = objQuest;
		blValid=false;
	}
}
