
// isEmpty
	function isEmpty (strValue) {
		return (! strValue.replace (/^(\s*)/, "", strValue));
	}

// isValidEmail
	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 isValidCurrency(strValue)  {
		var objRegExp = /(^\${0,1}\d{1,3}(,{0,1}\d{3})*(\.\d{2})*$)|(^\(\${0,1}\d{1,3}(,{0,1}\d{3})*(\.\d{2}\))*$)/;
		return objRegExp.test( strValue );
	}

// clearInput
	function clearInput(inputObj) {
    	if (inputObj.value == inputObj.defaultValue) {
        	inputObj.value = ""
		}
	}

// isValidDate
	function isValidDate (strValue) {
		var datePat = /^(\d{2})(\/|-)(\d{2})\2(\d{4})$/;
		var matchArray = strValue.match(datePat); 
		if (matchArray == null) { return false;	}
		day = matchArray[1]; month = matchArray[3]; year = matchArray[4];
		if (month < 1 || month > 12) { return false; }
		if (day < 1 || day > 31) { return false; }
		if ((month==4 || month==6 || month==9 || month==11) && day==31) { return false; }
		if (month==2) {
			var isleap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));
			if (day>29 || (day==29 && !isleap)) { return false; }
		}
		return true;
	}

// reduceToDigits
	function reduceToDigits (strValue) {
		return (strValue.replace (/([^0-9])/g, "", strValue));
	}
	 
// checkUserAdd

	function checkUserAdd(formObj) {  

		var alert_message = ""; 

		if (isEmpty(formObj.usrFirstName.value)) {
			alert_message = alert_message + "   First Name\n";
		}

		if (isEmpty(formObj.usrLastName.value)) {
			alert_message = alert_message + "   Last Name\n";
		}

		if (!isValidEmail(formObj.usrEmail.value)) {
			alert_message = alert_message + "   Email\n";
		}

		if (isEmpty(formObj.usrIdentifierTwo.value)) {
			alert_message = alert_message + "   Password\n";
		}

		if (isEmpty(formObj.usoOrganisation.value)) {
			alert_message = alert_message + "   Organisation\n";
		}

		if (alert_message) { 
			alert ("Your form is incomplete.\n" +
				   "You must supply the following information:\n" +
					alert_message);
			return false;
		} else { 
			return true;
		}
	}

// checkUserAddMultiple

	function checkUserAddMultiple(formObj) {  

		var alert_message = ""; 

		if (isEmpty(formObj.fileOfRespondents.value)) {
			alert_message = alert_message + "   File Of Respondents\n";
		}

		if (alert_message) { 
			alert ("Your form is incomplete.\n" +
				   "You must supply the following information:\n" +
					alert_message);
			return false;
		} else { 
			return true;
		}
	}
	
// checkSurveySkinAdd

	function checkSurveySkinAdd(formObj) {

		var alert_message = ""; 

		if (isEmpty(formObj.sknName.value)) {
			alert_message = alert_message + "   Skin Name\n";
		}

		if (isEmpty(formObj.sknIdentifier.value)) {
			alert_message = alert_message + "   Skin Identifier\n";
		}

		if (alert_message) { 
			alert ("Your form is incomplete.\n" +
				   "You must supply the following information:\n" +
					alert_message);
			return false;
		} else { 
			return true;
		}

	}

// checkQuestionBankCategoryAdd

	function checkQuestionBankCategoryAdd(formObj) {

		var alert_message = ""; 

		if (isEmpty(formObj.sbcName.value)) {
			alert_message = alert_message + "   Category Name\n";
		}

		if (alert_message) { 
			alert ("Your form is incomplete.\n" +
				   "You must supply the following information:\n" +
					alert_message);
			return false;
		} else { 
			return true;
		}

	}

// checkQuestionBankQuestionAdd

	function checkQuestionBankQuestionAdd(formObj) {

		var alert_message = ""; 

		if (isEmpty(formObj.sqbQuestion.value)) {
			alert_message = alert_message + "   Question\n";
		}

		if (alert_message) { 
			alert ("Your form is incomplete.\n" +
				   "You must supply the following information:\n" +
					alert_message);
			return false;
		} else { 
			return true;
		}

	}

// checkSurveyAdviceAdd

	function checkSurveyAdviceAdd(formObj) {

		var alert_message = ""; 

		if (isEmpty(formObj.savAction.value)) {
			alert_message = alert_message + "   Action\n";
		}

		if (isEmpty(formObj.savAdvice.value)) {
			alert_message = alert_message + "   Advice\n";
		}

		if (alert_message) { 
			alert ("Your form is incomplete.\n" +
				   "You must supply the following information:\n" +
					alert_message);
			return false;
		} else { 
			return true;
		}

	}

// checkLikertScaleAdd

	function checkLikertScaleAdd(formObj) {

		var alert_message = ""; 

		if (isEmpty(formObj.sagName.value)) {
			alert_message = alert_message + "   Name\n";
		}

		if (alert_message) { 
			alert ("Your form is incomplete.\n" +
				   "You must supply the following information:\n" +
					alert_message);
			return false;
		} else { 
			return true;
		}

	}

// checkLikertScaleAddTwo

	function checkLikertScaleAddTwo(formObj) {

		var alert_message = ""; 

		if (isEmpty(formObj.sagName.value)) {
			alert_message = alert_message + "   Name\n";
		}

		for (i = 1; i <= formObj.noOfLabels.value; i++) {
			if (isEmpty(eval('formObj.salAbbreviation_' + i + '.value'))) {
				alert_message = alert_message + "   Label " + i + " Abbreviation\n";
			}
			if (isEmpty(eval('formObj.salLabel_' + i + '.value'))) {
				alert_message = alert_message + "   Label " + i + " Text\n";
			}

			if (isEmpty(eval('formObj.salValue_' + i + '.value'))) {
				alert_message = alert_message + "   Label " + i + " Value\n";
			}
		}

		if (alert_message) { 
			alert ("Your form is incomplete.\n" +
				   "You must supply the following information:\n" +
					alert_message);
			return false;
		} else { 
			return true;
		}

	}

// checkPriceGroupAdd

	function checkPriceGroupAdd(formObj) {  

		var alert_message = ""; 

		if (isEmpty(formObj.prgName.value)) {
			alert_message = alert_message + "   Description\n";
		}

		if (isEmpty(formObj.prmPrice1.value) &&
			isEmpty(formObj.prmPrice2.value) &&
			isEmpty(formObj.prmPrice3.value) &&
			isEmpty(formObj.prmPrice4.value) &&
			isEmpty(formObj.prmPrice5.value)) {
			alert_message = alert_message + "   At Least One Price Break\n";
		}

		if (!isEmpty(formObj.prmPrice1.value) && !isValidCurrency(formObj.prmPrice1.value)) {
			alert_message = alert_message + "   First: Valid Price\n";
		}

		if (!isEmpty(formObj.prmPrice2.value) && !isValidCurrency(formObj.prmPrice2.value)) {
			alert_message = alert_message + "   Second: Valid Price\n";
		}

		if (!isEmpty(formObj.prmPrice3.value) && !isValidCurrency(formObj.prmPrice3.value)) {
			alert_message = alert_message + "   Third: Valid Price\n";
		}

		if (!isEmpty(formObj.prmPrice4.value) && !isValidCurrency(formObj.prmPrice4.value)) {
			alert_message = alert_message + "   Fourth: Valid Price\n";
		}

		if (!isEmpty(formObj.prmPrice5.value) && !isValidCurrency(formObj.prmPrice5.value)) {
			alert_message = alert_message + "   Fifth: Valid Price\n";
		}


		if (alert_message) { 
			alert ("Your form is incomplete.\n" +
				   "You must supply the following information:\n" +
					alert_message);
			return false;
		} else { 
			return true;
		}
	}


	
// checkCreateSurveyOne

	function checkCreateSurveyOne(formObj) {

		var alert_message = ""; 

		if (isEmpty(formObj.svyName.value)) {
			alert_message = alert_message + "   Survey Name\n";
		}

		if (!isValidDate(formObj.svyStartDate.value)) {
			alert_message = alert_message + "   Start Date\n";
		}

		if (!isValidDate(formObj.svyExpiryDate.value)) {
			alert_message = alert_message + "   Expiry Date\n";
		}

		if (isEmpty(formObj.svyTimeToComplete.value)) {
			alert_message = alert_message + "   Time to complete\n";
		}

		if (formObj.svyRedirectTo[2].checked) {
			checkURL = formObj.svyCompletedURL.value;
			checkURL = checkURL.substring(7,checkURL.length);
			if (isEmpty(checkURL)) {
				alert_message = alert_message + "   Alternative URL\n";
			}
		}

		if (alert_message) { 
			alert ("Your form is incomplete.\n" +
				   "You must supply the following information:\n" +
					alert_message);
			return false;
		} else { 
			return true;
		}

	}
	
// checkSurveyDuplicate

	function checkSurveyDuplicate(formObj) {

		var alert_message = ""; 

		if (	formObj.currentSvyID.selectedIndex == formObj.titlePositionOne.value || 
				formObj.currentSvyID.selectedIndex == formObj.titlePositionTwo.value || 
				formObj.currentSvyID.selectedIndex == formObj.titlePositionThree.value ) {
			alert_message = alert_message + "   Survey to duplicate\n";
		}

		if (isEmpty(formObj.svyName.value)) {
			alert_message = alert_message + "   Survey Name\n";
		}

		if (alert_message) { 
			alert ("Your form is incomplete.\n" +
				   "You must supply the following information:\n" +
					alert_message);
			return false;
		} else { 
			return true;
		}

	}
	
// checkFollowUpEmailAdd

	function checkFollowUpEmailAdd(formObj) {

		var alert_message = ""; 

		var dateString = formObj.sfeSendDay[formObj.sfeSendDay.selectedIndex].value + "/" + formObj.sfeSendMonth[formObj.sfeSendMonth.selectedIndex].value + "/" + formObj.sfeSendYear[formObj.sfeSendYear.selectedIndex].value;

		if (!isValidDate(dateString)) {
			alert_message = alert_message + "   Valid send date\n";
		}

		if (formObj.fk_sfe_sfrID.selectedIndex == 0) {
			alert_message = alert_message + "   Send to\n";
		}


		if (isEmpty(formObj.sfeSubject.value)) {
			alert_message = alert_message + "   Subject\n";
		}

		if (isEmpty(formObj.sfeContent.value)) {
			alert_message = alert_message + "   Content\n";
		}

		if (alert_message) { 
			alert ("Your form is incomplete.\n" +
				   "You must supply the following information:\n" +
					alert_message);
			return false;
		} else { 
			return true;
		}

	}

// checkQBankCategories

	function checkQBankCategories(formObj) {

		var alert_message = ""; 

		var categoriesChecked = 0;
		for (i = 0; i < formObj.sbcList.length; i++) {
			if (formObj.sbcList[i].checked == true) {
				categoriesChecked = categoriesChecked + 1;
			}
		}
		if (categoriesChecked == 0) {
			alert_message = alert_message + "   At least one category\n";
		}

		if (alert_message) { 
			alert ("Your form is incomplete.\n" +
				   "You must supply the following information:\n" +
					alert_message);
			return false;
		} else { 
			return true;
		}

	}

// checkQBankLikertQuestions

	function checkQBankLikertQuestions(formObj) {

		var alert_message = ""; 

		if (formObj.sagID.selectedIndex == 0) {
			alert_message = alert_message + "   Label options\n";
		}
		
		if (formObj.squFormat.selectedIndex == 0) {
			alert_message = alert_message + "   Question format\n";
		}

		if (isEmpty(formObj.sqyName.value)) {
			alert_message = alert_message + "   Short title\n";
		}

		if (isEmpty(formObj.sqyContent.value)) {
			alert_message = alert_message + "   Header statement\n";
		}

		var questionsChecked = 0;
		for (i = 0; i < formObj.sqbList.length; i++) {
			if (formObj.sqbList[i].checked == true) {
				questionsChecked = questionsChecked + 1;
			}
		}
		if (questionsChecked == 0) {
			alert_message = alert_message + "   At least one question\n";
		}

		if (alert_message) { 
			alert ("Your form is incomplete.\n" +
				   "You must supply the following information:\n" +
					alert_message);
			return false;
		} else { 
			return true;
		}

	}

// checkQBankTextQuestions

	function checkQBankTextQuestions(formObj) {

		var alert_message = ""; 

		var questionsChecked = 0;
		for (i = 0; i < formObj.sqbList.length; i++) {
			if (formObj.sqbList[i].checked == true) {
				questionsChecked = questionsChecked + 1;
			}
		}
		if (questionsChecked == 0) {
			alert_message = alert_message + "   At least one question\n";
		}

		if (alert_message) { 
			alert ("Your form is incomplete.\n" +
				   "You must supply the following information:\n" +
					alert_message);
			return false;
		} else { 
			return true;
		}

	}

// checkQB1Likert

	function checkQB1Likert(formObj) {

		var alert_message = ""; 

		formObj.noOfQuestions.value = reduceToDigits(formObj.noOfQuestions.value);

		if (isEmpty(formObj.noOfQuestions.value)) {
			alert_message = alert_message + "   No of Questions\n";
		}

		if (formObj.sagID.selectedIndex == 0) {
			alert_message = alert_message + "   Label Options\n";
		}

		if (formObj.squFormat.selectedIndex == 0) {
			alert_message = alert_message + "   Question Format\n";
		}


		if (alert_message) { 
			alert ("Your form is incomplete.\n" +
				   "You must supply the following information:\n" +
					alert_message);
			return false;
		} else { 
			return true;
		}

	}	
	
// checkQB2Likert

	function checkQB2Likert(formObj) {

		var alert_message = ""; 

		if (isEmpty(formObj.sqyName.value)) {
			alert_message = alert_message + "   Short Title\n";
		}

		if (isEmpty(formObj.sqyContent.value)) {
			alert_message = alert_message + "   Battery Header Statment\n";
		}

		for (i = 1; i <= formObj.noOfQuestions.value; i++) {
			if (isEmpty(eval('formObj.squQuestion_' + i + '.value'))) {
				alert_message = alert_message + "   Question " + i + " Text\n";
			}
		}

		if (alert_message) { 
			alert ("Your form is incomplete.\n" +
				   "You must supply the following information:\n" +
					alert_message);
			return false;
		} else { 
			return true;
		}

	}	

// updateLikertSequence
	function updateLikertSequence(formObj, startPos) {

		// work out where we are moving the question
		var endPos = eval('formObj.squBatterySequence_' + startPos + '[formObj.squBatterySequence_' + startPos + '.selectedIndex].value;');

		// work out if we are moving up the list or down the list
		var moveAmount = endPos - startPos;

		// set up arrays to store current values of each form fields
		var squArray = new Array();
		var sssArray = new Array();
		var manArray = new Array();
		var revArray = new Array();

		// loop over all of the current form fields and put them in their arrays
		for (i = 1; i <= formObj.noOfQuestions.value; i++) {
			// question text box
			squArray[i] = eval('formObj.squQuestion_' + i + '.value');
			// mandatory check box
			manArray[i] = eval('formObj.squMandatory_' + i + '.checked');
			// reverse reporting checkbox
			revArray[i] = eval('formObj.squReverseReport_' + i + '.checked');
			// sub scale may be a hidden or a select list
		    switch(eval('formObj.sssID_' + i + '.type')) {
			     case "select-one":
					sssArray[i] = eval('formObj.sssID_' + i + '.selectedIndex');
			     break;
			     default:
					sssArray[i] = eval('formObj.sssID_' + i + '.value');
			     break;
			}
			// set the sequence drop downs back to the correct order	
			var newSelectedIndex = i - 1; 
			eval('formObj.squBatterySequence_' + i + '.selectedIndex = ' + newSelectedIndex + ';');
		}
		
		// first up set the values in the new postion to those of the one we are moving
		eval('formObj.squQuestion_' + endPos + '.value = squArray[' + startPos + '];' );
		eval('formObj.squMandatory_' + endPos + '.checked = manArray[' + startPos + '];' );
		eval('formObj.squReverseReport_' + endPos + '.checked = revArray[' + startPos + '];' );
	    switch(eval('formObj.sssID_' + endPos + '.type')) {
		     case "select-one":
				eval('formObj.sssID_' + endPos + '.selectedIndex = sssArray[' + startPos + '];' );
		     break;
		     default:
				eval('formObj.sssID_' + endPos + '.value = sssArray[' + startPos + '];' );
		     break;
		}

		// if we are moving it up the list
		if (moveAmount > 0) {
			// loop over all questions in the list
			for (i = 1; i <= formObj.noOfQuestions.value; i++) {
				if (i <= endPos && i > startPos) {
					var newValue = i - 1;
					// shuffle all the values around as required
					eval('formObj.squQuestion_' + newValue + '.value = squArray[' + i + '];' );
					eval('formObj.squMandatory_' + newValue + '.checked = manArray[' + i + '];' );
					eval('formObj.squReverseReport_' + newValue + '.checked = revArray[' + i + '];' );
				    switch(eval('formObj.sssID_' + i + '.type')) {
		    			case "select-one":
							eval('formObj.sssID_' + newValue + '.selectedIndex = sssArray[' + i + '];' );
						break;
						default:
							eval('formObj.sssID_' + newValue + '.value = sssArray[' + i + '];' );
						break;
					}
				} 
			}
		// ...or if we are moving down the list
		} else {
			// loop over all questions in the list
			for (i = 1; i <= formObj.noOfQuestions.value; i++) {
				if (i >= endPos && i < startPos) {
					var newValue = i + 1;
					// shuffle all the values around as required
					eval('formObj.squQuestion_' + newValue + '.value = squArray[' + i + '];' );
					eval('formObj.squMandatory_' + newValue + '.checked = manArray[' + i + '];' );
					eval('formObj.squReverseReport_' + newValue + '.checked = revArray[' + i + '];' );
					switch(eval('formObj.sssID_' + i + '.type')) {
						case "select-one":
							eval('formObj.sssID_' + newValue + '.selectedIndex = sssArray[' + i + '];' );
						break;
						default:
							eval('formObj.sssID_' + newValue + '.value = sssArray[' + i + '];' );
						break;
					}
				} 
			}
		}
	}


	
// checkQB1Open

	function checkQB1Open(formObj) {

		var alert_message = ""; 

		if (isEmpty(formObj.squName_1.value)) {
			alert_message = alert_message + "   Short Title\n";
		}

		if (isEmpty(formObj.squQuestion_1.value)) {
			alert_message = alert_message + "   Question\n";
		}

		if (alert_message) { 
			alert ("Your form is incomplete.\n" +
				   "You must supply the following information:\n" +
					alert_message);
			return false;
		} else { 
			return true;
		}

	}	
	
// checkQB1Boolean

	function checkQB1Boolean(formObj) {

		var alert_message = ""; 

		if (isEmpty(formObj.squName_1.value)) {
			alert_message = alert_message + "   Short Title\n";
		}

		if (isEmpty(formObj.squQuestion_1.value)) {
			alert_message = alert_message + "   Question\n";
		}

		if (isEmpty(formObj.salLabel_1.value)) {
			alert_message = alert_message + "   Label One\n";
		}

		if (isEmpty(formObj.salLabel_2.value)) {
			alert_message = alert_message + "   Label Two\n";
		}

		if (alert_message) { 
			alert ("Your form is incomplete.\n" +
				   "You must supply the following information:\n" +
					alert_message);
			return false;
		} else { 
			return true;
		}

	}	
	
// checkQB1Multi

	function checkQB1Multi(formObj) {

		var alert_message = ""; 

		if (isEmpty(formObj.squName_1.value)) {
			alert_message = alert_message + "   Short Title\n";
		}

		if (isEmpty(formObj.squQuestion_1.value)) {
			alert_message = alert_message + "   Question\n";
		}

		if (alert_message) { 
			alert ("Your form is incomplete.\n" +
				   "You must supply the following information:\n" +
					alert_message);
			return false;
		} else { 
			return true;
		}

	}	

	// checkQB2Multi

	function checkQB2Multi(formObj) {

		var alert_message = ""; 

		for (i = 1; i <= formObj.noOfLabels.value; i++) {
			if (isEmpty(eval('formObj.salLabel_' + i + '.value'))) {
				alert_message = alert_message + "   Response " + i + " Text\n";
			}
		}

		if (alert_message) { 
			alert ("Your form is incomplete.\n" +
				   "You must supply the following information:\n" +
					alert_message);
			return false;
		} else { 
			return true;
		}

	}	

	
// checkQB1Sum

	function checkQB1Sum(formObj) {

		var alert_message = ""; 

		if (isEmpty(formObj.squName_1.value)) {
			alert_message = alert_message + "   Short Title\n";
		}

		if (isEmpty(formObj.squQuestion_1.value)) {
			alert_message = alert_message + "   Question\n";
		}

		formObj.sagResponsesRequired.value = reduceToDigits(formObj.sagResponsesRequired.value);
		
		if (isEmpty(formObj.sagResponsesRequired.value)) {
			alert_message = alert_message + "   Sum Total\n";
		}

		
		if (alert_message) { 
			alert ("Your form is incomplete.\n" +
				   "You must supply the following information:\n" +
					alert_message);
			return false;
		} else { 
			return true;
		}

	}	


// checkQB1Matrix

	function checkQB1Matrix(formObj) {

		var alert_message = ""; 

		formObj.noOfQuestions.value = reduceToDigits(formObj.noOfQuestions.value);

		if (isEmpty(formObj.noOfQuestions.value)) {
			alert_message = alert_message + "   No of Questions\n";
		}

		if (formObj.squFormat.selectedIndex == 0) {
			alert_message = alert_message + "   Question Format\n";
		}

		if (alert_message) { 
			alert ("Your form is incomplete.\n" +
				   "You must supply the following information:\n" +
					alert_message);
			return false;
		} else { 
			return true;
		}

	}	

// checkQB2Matrix

	function checkQB2Matrix(formObj) {

		var alert_message = ""; 

		if (isEmpty(formObj.sqyName.value)) {
			alert_message = alert_message + "   Short Title\n";
		}

		if (isEmpty(formObj.sqyContent.value)) {
			alert_message = alert_message + "   Battery Header Statment\n";
		}

		for (i = 1; i <= formObj.noOfQuestions.value; i++) {
			if (isEmpty(eval('formObj.squQuestion_' + i + '.value'))) {
				alert_message = alert_message + "   Question " + i + " Text\n";
			}
		}

		if (alert_message) { 
			alert ("Your form is incomplete.\n" +
				   "You must supply the following information:\n" +
					alert_message);
			return false;
		} else { 
			return true;
		}

	}	

// checkQB3Matrix

	function checkQB3Matrix(formObj) {

		var alert_message = ""; 

		for (i = 1; i <= formObj.noOfLabels.value; i++) {

			if (isEmpty(eval('formObj.salAbbreviation_' + i + '.value'))) {
				alert_message = alert_message + "   Response " + i + " Abbreviation\n";
			}

			if (isEmpty(eval('formObj.salLabel_' + i + '.value'))) {
				alert_message = alert_message + "   Response " + i + " Text\n";
			}

			eval('formObj.salValue_' + i + '.value = reduceToDigits(formObj.salValue_' + i + '.value);');
			
			if (isEmpty(eval('formObj.salValue_' + i + '.value'))) {
				alert_message = alert_message + "   Response " + i + " Value\n";
			}

		}

		if (alert_message) { 
			alert ("Your form is incomplete.\n" +
				   "You must supply the following information:\n" +
					alert_message);
			return false;
		} else { 
			return true;
		}

	}	

// checkQB1Open

	function checkQB1Text(formObj) {

		var alert_message = ""; 

		if (isEmpty(formObj.squName_1.value)) {
			alert_message = alert_message + "   Short Title\n";
		}

		if (isEmpty(formObj.squQuestion_1.value)) {
			alert_message = alert_message + "   Question\n";
		}

		if (alert_message) { 
			alert ("Your form is incomplete.\n" +
				   "You must supply the following information:\n" +
					alert_message);
			return false;
		} else { 
			return true;
		}

	}	
	
// checkSubScaleAdd

	function checkSubScaleAdd(formObj) {

		var alert_message = ""; 

		if (isEmpty(formObj.sssAbbreviation.value)) {
			alert_message = alert_message + "   Abbreviation\n";
		}

		if (isEmpty(formObj.sssName.value)) {
			alert_message = alert_message + "   Name\n";
		}

		if (alert_message) { 
			alert ("Your form is incomplete.\n" +
				   "You must supply the following information:\n" +
					alert_message);
			return false;
		} else { 
			return true;
		}

	}	
	
	
// checkFormalReportIntroAdd

	function checkFormalReportIntroAdd(formObj) {

		var alert_message = ""; 

		if (isEmpty(formObj.sfrIntroductionTitle.value)) {
			alert_message = alert_message + "   Title\n";
		}

		if (isEmpty(formObj.sfrIntroduction.value)) {
			alert_message = alert_message + "   Introduction\n";
		}

		if (alert_message) { 
			alert ("Your form is incomplete.\n" +
				   "You must supply the following information:\n" +
					alert_message);
			return false;
		} else { 
			return true;
		}

	}
	
// checkFormalReportDiscAdd

	function checkFormalReportDiscAdd(formObj) {

		var alert_message = ""; 

		if (isEmpty(formObj.sfrDiscussionTitle.value)) {
			alert_message = alert_message + "   Title\n";
		}

		if (isEmpty(formObj.sfrDiscussion.value)) {
			alert_message = alert_message + "   Discussion\n";
		}

		if (alert_message) { 
			alert ("Your form is incomplete.\n" +
				   "You must supply the following information:\n" +
					alert_message);
			return false;
		} else { 
			return true;
		}

	}

// checkSurveyDuplicate

	function checkSurveyDuplicate(formObj) {

		var alert_message = ""; 

		if (formObj.surveyBankSvyID.selectedIndex == 0) {
			alert_message = alert_message + "   Survey To Duplicate\n";
		}

		if (isEmpty(formObj.svyName.value)) {
			alert_message = alert_message + "   Name of New Survey\n";
		}

		if (alert_message) { 
			alert ("Your form is incomplete.\n" +
				   "You must supply the following information:\n" +
					alert_message);
			return false;
		} else { 
			return true;
		}

	}
	

// checkQB1Combo

	function checkQB1Combo(formObj) {

		var alert_message = ""; 

		formObj.squCount.value = reduceToDigits(formObj.squCount.value);

		if (isEmpty(formObj.squCount.value)) {
			alert_message = alert_message + "   Number of questions\n";
		}

		if (formObj.sqcCount.selectedIndex == 0) {
			alert_message = alert_message + "   Number of Columns\n";
		}

		if (alert_message) { 
			alert ("Your form is incomplete.\n" +
				   "You must supply the following information:\n" +
					alert_message);
			return false;
		} else { 
			return true;
		}

	}	


// checkQB2Combo

	function checkQB2Combo(formObj) {

		var alert_message = ""; 

		if (isEmpty(formObj.sqcName.value)) {
			alert_message = alert_message + "   Short Title\n";
		}

		if (isEmpty(formObj.sqcContent.value)) {
			alert_message = alert_message + "   Header Statement\n";
		}


		for (i = 1; i <= formObj.squCount.value; i++) {
			if (isEmpty(eval('formObj.squQuestion_' + i + '.value'))) {
				alert_message = alert_message + "   Question " + i + " Text\n";
			}
		}
		
		if (alert_message) { 
			alert ("Your form is incomplete.\n" +
				   "You must supply the following information:\n" +
					alert_message);
			return false;
		} else { 
			return true;
		}

	}	

// checkQB3Combo

	function checkQB3Combo(formObj) {

		var alert_message = ""; 

		for (i = 1; i <= formObj.sqcCount.value; i++) {
			if (isEmpty(eval('formObj.sqyName_' + i + '.value'))) {
				alert_message = alert_message + "   Column " + i + " Heading\n";
			}

			if (eval('formObj.sqtID_' + i + '.selectedIndex') == 0) {
				alert_message = alert_message + "   Column " + i + " Question Type\n";
			}

		}
		
		if (alert_message) { 
			alert ("Your form is incomplete.\n" +
				   "You must supply the following information:\n" +
					alert_message);
			return false;
		} else { 
			return true;
		}

	}	

// checkQB4Combo

	function checkQB4Combo(formObj) {

	var alert_message = ""; 

	currentCol = formObj.currentColumn.value;
	
	switch(eval('formObj.sqtID_' + currentCol + '.value')) {

		// likert
		case "1":
			if (eval('formObj.sagID_' + currentCol + '.selectedIndex') == 0) {
				alert_message = alert_message + "   Likert Scale\n";
			}

		break;

		// text
		case "2":
			// set of radio buttons so no need to check anything
		break;

		// boolean
		case "3":
			for (i = 1; i <= formObj.salLabelCount.value; i++) {
				if (isEmpty(eval('formObj.salAbbreviation_' + currentCol + '_' + i + '.value'))) {
					alert_message = alert_message + "   Option " + i + " Abbreviation\n";
				}
				if (isEmpty(eval('formObj.salLabel_' + currentCol + '_' + i + '.value'))) {
					alert_message = alert_message + "   Option " + i + "\n";
				}
			}
		break;

		// multi response
		case "4":
			for (i = 1; i <= formObj.salLabelCount.value; i++) {
				if (isEmpty(eval('formObj.salAbbreviation_' + currentCol + '_' + i + '.value'))) {
					alert_message = alert_message + "   Response " + i + " Abbreviation\n";
				}
				if (isEmpty(eval('formObj.salLabel_' + currentCol + '_' + i + '.value'))) {
					alert_message = alert_message + "   Response " + i + "\n";
				}
			}
		break;

		// multi choice
		case "5":
			for (i = 1; i <= formObj.salLabelCount.value; i++) {
				if (isEmpty(eval('formObj.salAbbreviation_' + currentCol + '_' + i + '.value'))) {
					alert_message = alert_message + "   Response " + i + " Abbreviation\n";
				}
				if (isEmpty(eval('formObj.salLabel_' + currentCol + '_' + i + '.value'))) {
					alert_message = alert_message + "   Response " + i + "\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;
		}

	}	

	
	
// y2k	
	function y2k(number) {
		return (number < 1000) ? number + 1900 : number;
	}
	
	var today		= new Date();
	var thisYear	= y2k(today.getYear());
	var thisMonth	= today.getMonth() + 1;
	var thisDay		= today.getDate();
	
// makeItToday
	function makeItToday(formObj) {
		formObj.sfeSendDay.selectedIndex = thisDay;
		formObj.sfeSendMonth.selectedIndex = thisMonth;
		currentYearSelectedIndex = 0;
		for (i=0; i < formObj.sfeSendYear.length; i++) {
			if (formObj.sfeSendYear[i].value == thisYear) {
				currentYearSelectedIndex = i;
			}
		}
		formObj.sfeSendYear.selectedIndex = currentYearSelectedIndex

		makeItADayMore(formObj);

	}
	
//makeItNoTime
	function makeItNoTime(formObj) {
		formObj.sfeSendDay.selectedIndex = 0;
		formObj.sfeSendMonth.selectedIndex = 0;
		formObj.sfeSendYear.selectedIndex = 0;
	}

	
//makeItADayMore
	function makeItADayMore(formObj) {
	
		var daySelected = formObj.sfeSendDay.selectedIndex;
		var monthSelected = formObj.sfeSendMonth.selectedIndex;
		var yearSelected =  formObj.sfeSendYear.selectedIndex;
		
		if (monthSelected == 0) {
			for (i=0; i < formObj.sfeSendMonth.length; i++) {
				if (formObj.sfeSendMonth[i].value == thisMonth) {
					monthSelected = i;
				}
			}
		}
		if (yearSelected == 0) {
			for (i=0; i < formObj.sfeSendYear.length; i++) {
				if (formObj.sfeSendYear[i].value == thisYear) {
					yearSelected = i;
				}
			}
		}
	
		var	year = formObj.sfeSendYear[yearSelected].value;
	
		var isleap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));
		
		var dayInAWeek = daySelected + 1;
		var monthInAWeek = monthSelected;
		var yearInAWeek = yearSelected;
	
		if (monthSelected == 2) {
	
			if (dayInAWeek > 29 || (dayInAWeek == 29 && !isleap)) {
				if (isleap) {
					dayInAWeek = 1 - (29 - daySelected); 
				} else {
					dayInAWeek = 1 - (28 - daySelected); 
				}
				monthInAWeek = monthInAWeek + 1;
			}
	
		} else if (monthSelected == 4 || monthSelected == 6|| monthSelected ==  9|| monthSelected ==  11) {
			if (dayInAWeek > 30) {
				dayInAWeek = 1 - (30 - daySelected); 
				monthInAWeek = monthInAWeek + 1;
			}
		} else if (monthSelected == 12) {
			if (dayInAWeek > 31) {
				dayInAWeek = 1 - (31 - daySelected); 
				monthInAWeek = 1;
				yearInAWeek = yearInAWeek + 1;
			}
	
		} else {
			if (dayInAWeek > 31) {
				dayInAWeek = 1 - (31 - daySelected); 
				monthInAWeek = monthInAWeek + 1;
			}
		}
	
		formObj.sfeSendDay.selectedIndex = dayInAWeek;
		formObj.sfeSendMonth.selectedIndex = monthInAWeek;
		formObj.sfeSendYear.selectedIndex = yearInAWeek;
	}
	
//makeItAWeekMore
	function makeItAWeekMore(formObj) {
	
		var daySelected = formObj.sfeSendDay.selectedIndex;
		var monthSelected = formObj.sfeSendMonth.selectedIndex;
		var yearSelected =  formObj.sfeSendYear.selectedIndex;
		
		if (monthSelected == 0) {
			for (i=0; i < formObj.sfeSendMonth.length; i++) {
				if (formObj.sfeSendMonth[i].value == thisMonth) {
					monthSelected = i;
				}
			}
		}
		if (yearSelected == 0) {
			for (i=0; i < formObj.sfeSendYear.length; i++) {
				if (formObj.sfeSendYear[i].value == thisYear) {
					yearSelected = i;
				}
			}
		}
	
		var	year = formObj.sfeSendYear[yearSelected].value;
	
		var isleap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));
		
		var dayInAWeek = daySelected + 7;
		var monthInAWeek = monthSelected;
		var yearInAWeek = yearSelected;
	
		if (monthSelected == 2) {
	
			if (dayInAWeek > 29 || (dayInAWeek == 29 && !isleap)) {
				if (isleap) {
					dayInAWeek = 7 - (29 - daySelected); 
				} else {
					dayInAWeek = 7 - (28 - daySelected); 
				}
				monthInAWeek = monthInAWeek + 1;
			}
	
		} else if (monthSelected == 4 || monthSelected == 6|| monthSelected ==  9|| monthSelected ==  11) {
			if (dayInAWeek > 30) {
				dayInAWeek = 7 - (30 - daySelected); 
				monthInAWeek = monthInAWeek + 1;
			}
		} else if (monthSelected == 12) {
			if (dayInAWeek > 31) {
				dayInAWeek = 7 - (31 - daySelected); 
				monthInAWeek = 1;
				yearInAWeek = yearInAWeek + 1;
			}
	
		} else {
			if (dayInAWeek > 31) {
				dayInAWeek = 7 - (31 - daySelected); 
				monthInAWeek = monthInAWeek + 1;
			}
		}
	
		formObj.sfeSendDay.selectedIndex = dayInAWeek;
		formObj.sfeSendMonth.selectedIndex = monthInAWeek;
		formObj.sfeSendYear.selectedIndex = yearInAWeek;
	}

// isSelected
	function isSelected (strValue) {
		if (strValue == "0" || strValue == "")
			return false;
		else
			return true;
	}
	

//checkSurveyCrossTab
	function checkSurveyCrossTab(formObj) {

		var alert_message = ""; 
	
		if (isEmpty(formObj.sctTitle.value)) {
			alert_message = alert_message + "   Title\n";
		}
		
		if (isEmpty(formObj.sctXLabel.value)) {
			alert_message = alert_message + "   X-axis Label\n";
		}
		
		if (isEmpty(formObj.sctYLabel.value)) {
			alert_message = alert_message + "   Y-axis Label\n";
		}

		
		// Radio Buttons - must select one - X_squID
		xEventOption = -1;
	
		if (formObj.X_squID[0]) {			
			for ( i=0; i <formObj.X_squID.length; i++) {
				if (formObj.X_squID[i].checked) {
					xEventOption = i;
				}
			}
		} 
		else {
			if (formObj.X_squID.checked) { xEventOption = 1; }
		}
			
		if(xEventOption == -1) {
			alert_message = alert_message + "   Question for Row\n";
		}
		
		
		// Radio Buttons - must select one - Y_squID
		yEventOption = -1;
	
		if (formObj.Y_squID[0]) {			
			for ( i=0; i <formObj.Y_squID.length; i++) {
				if (formObj.Y_squID[i].checked) {
					yEventOption = i;
				}
			}
		} 
		else {
			if (formObj.Y_squID.checked) { yEventOption = 1; }
		}
			
		if(yEventOption == -1) {
			alert_message = alert_message + "   Question for Column\n";
		}
		
		
		if (xEventOption == yEventOption) {
			alert_message = alert_message + "   Questions for row and column must be different\n";
		}
	
		
		if (alert_message) { 
			alert ("Your form is incomplete.\n" +
				   "You must supply the following information:\n" +
				   alert_message);
			return false;
		} else { 
			return true;
		}

	}

	
//checkQuestionExtraction_One
	function checkQuestionExtraction_One(formObj) {

		var alert_message = ""; 
	
		if (!isSelected(formObj.end_squID.value)) {
			alert_message = alert_message + "   End question\n";
		}
		
		if (alert_message) { 
			alert ("Your form is incomplete.\n" +
				   "You must supply the following information:\n" +
				   alert_message);
			return false;
		} else { 
			return true;
		}

	}

	
//checkQuestionExtraction_Two
	function checkQuestionExtraction_Two(formObj) {

		var alert_message = ""; 
		
		for (i = 1; i <= formObj.squSequenceNums.value; i++) {

			if (isEmpty(eval('formObj.squQuestion_' + i + '.value'))) {
				alert_message = alert_message + "   Question " + eval('formObj.squSequence_' + i + '.value') + " Text\n";
			}
			else if (eval('formObj.squQuestion_' + i + '.value.indexOf("[VARIABLE]")') == -1 ) {
				alert_message = alert_message + "   Question " + eval('formObj.squSequence_' + i + '.value') + " must contain the text '[VARIABLE]'\n";
			}
		}
		
		if (alert_message) { 
			alert ("Your form is incomplete.\n" +
				   "You must supply the following information:\n" +
				   alert_message);
			return false;
		} else { 
			return true;
		}

	}
