// is this JavaScript 1.1 or higher?
var isJavaScript11 = false;
if (document.images) isJavaScript11 = true;

// What is the PATH to this HTML document?
var thisDocPath = location.pathname;
thisDocPath = thisDocPath.substring(0, thisDocPath.lastIndexOf("/")+1);

var noerror = true;

//#####################################################################################
// If a mandatory question is NOT answered, then the text of that question is returned.
// Otherwise a blank string is returned ("").
function checkMandatory(myForm)
{
  return ""
}

//#####################################################################################
function safeSubmit(thisField)
{
  if (noerror == true) {
//    alert("thisField.name = " + thisField.name + "thisField.value = " + thisField.value);
    thisField.form.VarX.value = thisField.name;       // ""
    return thisField.form.submit();
  }
}

//#####################################################################################
//  reload current page
function updatePage(thisField)
{
	// set VarX to "update"
	thisField.form.VarX.value = "update";
	return thisField.form.submit();
}

//#####################################################################################
function submitForm(myForm)
{
  if (isJavaScript11)
  {
    // we are running JavaScript 1.1 or higher -- okay to do extra processing
    var mand = checkMandatory(myForm);	// make sure all of the mandatory questions are answered
    if (mand != "") {			// at least one mandatory question was not answered
      alert("Please complete question " + mand);
      return false;
    }
  }
  return true;
}

//#####################################################################################
function myOnSubmit(myForm)
{
  if (isJavaScript11)	// the form is not okay to submit
    return false;
  return true;
}
//#####################################################################################
function listNotEqual(obj0, obj1, obj2)
{
	var arrObj = new Array(3);
	var msg = 'Please do not select 2 identical values from the drop list.';
		
	arrObj[0] = obj0;
	arrObj[1] = obj1;
	arrObj[2] = obj2;
	
	for(var i=0; i < (arrObj.length - 1); i++)
	{
		if(arrObj[i])
		{
			if(arrObj[i].selectedIndex > 0)
			{
				for(var j=i+1; j < arrObj.length; j++)
				{
					if(arrObj[j])
					{
						if(arrObj[j].selectedIndex > 0)
						{
							if(arrObj[i].options[arrObj[i].selectedIndex].value == arrObj[j].options[arrObj[j].selectedIndex].value)
							{
								alert(msg);
								arrObj[j].selectedIndex = 0;
								arrObj[j].select();
								arrObj[j].focus();

								return false;
							}
						}
					}
				}
			}
		}
	}
	return true;
}

//#####################################################################################
function myClear()
{
  if (isJavaScript11)
    return (confirm("Are you sure you want to clear this screen? (the data will be lost)"));
  else		// It is okay to clear the data
    return true;
}

//#####################################################################################
//Used in SPAN or DIV tags to select radio button and set focus to text box if corresponding display text is clicked.
function selectRadio(Item, oth)
{
	Item.click();
}
//#####################################################################################
//Used in SPAN or DIV tags to toggle check box button and set focus to text box if corresponding display text is clicked.
function selectCheck(Item, oth)
{
	Item.click();
}
//#####################################################################################
//Used in SPAN or DIV tags to set focus to text box if corresponding display text is clicked.
function selectBox(Item)
{
	Item.focus();
}

//#####################################################################################
//Used in SPAN or DIV tags to highlight onMouseOver display text.
function changeText(Item)
{
	Item.style.backgroundColor = "#F0F92E"
	Item.style.backgroundColor = "#F0F92E"
	//Item.style.fontWeight = "bold";

}
//#####################################################################################
//Used in SPAN or DIV tags to unhighlight onMouseOut display text.
function changeTextBack(Item)
{
	Item.style.backgroundColor = ""
}
//#####################################################################################
function trimString (str)   
//This function deletes white spaces from the beginning and ending of text.
{
  str = this != window? this : str;
  return str.replace(/^\s+/g, '').replace(/\s+$/g, '');
}
//#####################################################################################
//# Validates a string of integers.
function isInteger(objText)
{
   var ValidChars = "0123456789";
   var IsInt=true;
   var Char;
   var msg = "Value is not an integer. Please to not enter decimal or other non-numeric values.";
   var sText = new String (objText.value);
   
   for (i = 0; i < sText.length && IsInt == true; i++) 
   { 
      Char = sText.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) 
      {
         IsInt = false;
      }
   }
   if (!IsInt)
   {
  	alert(msg);
	objText.focus();
	objText.select();
   }
   return IsInt;
}

//#####################################################################################
//# Allows a drop list item to be selected only if the associated radio button is selected.
function checkRadioIfList(objList, objRadio)
{
	if (objRadio[1].checked)
	{
		// Allow a change
	}
	else
	{
		objList.selectedIndex = 0;
	}
}
//#####################################################################################
function checkBoxText(objCheck, objText, msg)
{
	var isCheck = false;
	var isText = false;
	
	if (objCheck && objText)
	{

		if (objCheck.checked) 
		{ 
			isCheck = true; 
		}

		if(isCheck)
		{
			if (!objText.value) 
			{ 
				alert(msg);
				objText.select();
				objText.focus();
				return false;			
			}
		}		
	}
	return true;
}
//#####################################################################################
//# This function sets focus to the first question when the web page is loaded.
function firstItemFocus(frm)
{
	var userControls = new Array(8);
	var x = 0;
	var y = 0;
	var str1 = new String();
	
	userControls[0] = "radio";
	userControls[1] = "checkbox";
	userControls[2] = "text";
	userControls[3] = "textarea";
	userControls[4] = "password";
	userControls[5] = "button";
	userControls[6] = "reset";
	userControls[7] = "submit";
	
	for(x=0; x < frm.elements.length; x++)
	{
		str1 = frm.elements[x].type;
		str1 = str1.toLowerCase();
		
		for(y=0; y < frm.elements.length; y++)
		{
			if (str1 == userControls[y])
			{
				if(frm.elements[x].disabled == true)
				{
					break;
				}
				frm.elements[x].focus();
				return;
			}
		}
	}
	return;
}
//#####################################################################################
//# Handles survey Radio type questions that are mandatory for page submission.
function radioMandatory(obj, msg)
{
	var isAnswered = false;
	var x;
	if (obj)
	{
		for (x=0; x < obj.length; x++) 
		{
			if (obj[x].checked) 
			{ 
				isAnswered = true; 
			}
		}
	
		if (isAnswered)
		{
			return true;
		}
		else
		{
			alert(msg);
			obj[0].focus();
			return false;
		}
	}
	return true;
}
//#####################################################################################
//# This functions handles radio control survey questions with and "Other" textbox associated with one of the items. 
//# If that "Other" item radio is checked, that textbox is mandatory.
function otherMandatory(objRadio, idx, objText, msg)
{
	var isRadio = false;
	var isText = false;
	
	if (objRadio && objText)
	{

		if (objRadio[idx].checked) 
		{ 
			isRadio = true; 
		}


		if(isRadio)
		{
			if (!objText.value) 
			{ 
				alert(msg);
				objText.select();
				objText.focus();
				return false;			
			}
		}		
	}
	return true;
}
//#####################################################################################
//# This functions handles radio control survey questions with and "Other" textbox associated with one of the items. 
//# If that "Other" item radio is checked, that textbox is mandatory.
function radioOtherMandatory(objRadio, objText, msgRadio, msgText, idx)
{
	var isRadio = false;
	var isText = false;
	var x;
	
	if (objRadio && objText)
	{
		for (x=0; x < objRadio.length; x++) 
		{
			if (objRadio[x].checked) 
			{ 
				isRadio = true; 
			}
		}
	
		if (isRadio)
		{
			if (objRadio[idx].checked) 
			{
				if (!objText.value) 
				{ 
					alert(msgText);
					objText.select();
					objText.focus();
					return false;			
				}
			}
			return true;
		}
		else
		{
			alert(msgRadio);
			objRadio[0].focus();
			return false;
		}
	}
	return true;
}
//#####################################################################################
//# This functions handles radio control survey questions with Drop List box associated with one of the items. 
//# If that drop list associated radio button is checked, selected an item from the drop list is mandatory.
function radioListMandatory(objRadio, objList, msgRadio, msgList)
{
	var isChecked = false;
	var x;
	var msg = "";

	for (x=0; x < objRadio.length; x++) 
	{
		if (objRadio[x].checked) 
		{ 
			isChecked = true; 
		}
	}

	if (isChecked)
	{
		if (objRadio[objRadio.length - 1].checked)
		{
			if (!objList.options[objList.selectedIndex].value)
			{
				alert(msgList);
				objList.focus();
				return false;
			}
		}
		return true;
	}
	else
	{
		alert(msgRadio);
		objRadio[0].focus();
		return false;
	}
}
//#####################################################################################
function dblListOtherMandatory(objList, objText, msgList, msgText)
{
	var isAnswered = false;
	var msg = "";

	if (objList)
	{
		if (objList.options[objList.selectedIndex].value) 
		{ 
			isAnswered = true; 
		}		
	}
	
	if (isAnswered)
	{
		if(objList.options[objList.selectedIndex].value == "ZZZ")
		{
			if(!objText.value)
			{
				alert(msgText);
				objText.focus();
				return false;	
			}
		}
		
		return true;
	}
	else
	{
		alert(msgList);
		objList.focus();
		return false;
	}
}
//#####################################################################################
function listMandatory(obj, msg)
{
	var isAnswered = false;
	
	if (obj)
	{
		if (obj.options[obj.selectedIndex].value) 
		{ 
			isAnswered = true; 
		}		
	}
		
	if (isAnswered)
	{
		return true;
	}
	else
	{
		alert(msg);
		obj.focus();
		return false;
	}
}
//#####################################################################################
function NumericRange(target, min, max)
{
	var v = target.value; 
	if (target.value == '') 
	{ 
		return true; 
	} 
	
	if (v >= min && v <=max) 
	{ 
		return true; 
	} 
	else 
	{ 	alert('Response is not within valid range of ' + min + '-' + max + '.\nPlease re-enter.'); 
		target.value = ''; 
		target.focus(); 
		target.select();
		return false; 
	}
}

//#####################################################################################
//# This functions either set focus to a text box or clears text box when a radio or checkbox is clicked
function TextBoxFocus(objButton, objText)
{
	if(objButton.checked) 
	{ 
		objText.focus(); 
	} 
	else 
	{ 
		objText.value = ""; 
	}
}
//#####################################################################################
//# This functions either set focus to a drop list or clears drop list when a radio or checkbox is clicked
function DropListFocus(objButton, objList)
{
	if(objButton.checked) 
	{ 
		objList.focus(); 
	} 
	else 
	{ 
		objList.selectedIndex = 0;
	}
}
//#####################################################################################
function TextAreaMax(target, max)
{
	var tmp = new String(target.value);
	if (tmp.length > max)
	{
		alert("Maximum of " + max + " characters only");
		target.value = tmp.substr(0,max);
	}
}

// *** AIRPORT SURVEY SPECIFIC SUPPORT ROUTINES ***

// dp--fix JAPANESE numerics
function fixJPN(target)
{
	var str = new String(target.value);
	str = trimString(str);

	if (document.forms[0].HDN_FORMPREFIX.value == "Japanese")
	{
		target.value = str.replace(/O/g, '0').replace(/P/g, '1').replace(/Q/g, '2').replace(/R/g, '3').replace(/S/g, '4').replace(/T/g, '5').replace(/U/g, '6').replace(/V/g, '7').replace(/W/g, '8').replace(/X/g, '9');
	}
	
	return true;
}

// dp--fix JAPANESE alphanumerics
function fixJPNA(target)
{
	var str = new String(target.value);
	str = trimString(str);

	if (document.forms[0].HDN_FORMPREFIX.value == "Japanese")
	{
		str = str.replace(/`/g, 'A').replace(/a/g, 'B').replace(/b/g, 'C').replace(/c/g, 'D').replace(/d/g, 'E').replace(/e/g, 'F').replace(/f/g, 'G').replace(/g/g, 'H').replace(/h/g, 'I').replace(/i/g, 'J').replace(/j/g, 'K').replace(/k/g, 'L').replace(/l/g, 'M').replace(/m/g, 'N').replace(/n/g, 'O').replace(/o/g, 'P').replace(/p/g, 'Q').replace(/q/g, 'R').replace(/r/g, 'S').replace(/s/g, 'T').replace(/t/g, 'U').replace(/u/g, 'V').replace(/v/g, 'W').replace(/w/g, 'X').replace(/x/g, 'Y').replace(/y/g, 'Z').replace(/|/g, '-').replace(/Q/g, '_').replace(/@/g, ' ').replace(//g, '@').replace(/D/g, '.');
		target.value = str.replace(/O/g, '0').replace(/P/g, '1').replace(/Q/g, '2').replace(/R/g, '3').replace(/S/g, '4').replace(/T/g, '5').replace(/U/g, '6').replace(/V/g, '7').replace(/W/g, '8').replace(/X/g, '9');
	}
	
	return true;
}

// dp--for page 0 of airport survey
//   remove dashes from serial number
function clearSerial(target)
{
	var str = new String(target.value);
	str = trimString(str);

	if (document.forms[0].HDN_FORMPREFIX.value == "Japanese")
	{
		//alert(str);
		
		// numerics...
		str = str.replace(/O/g, '0').replace(/P/g, '1').replace(/Q/g, '2').replace(/R/g, '3').replace(/S/g, '4').replace(/T/g, '5').replace(/U/g, '6').replace(/V/g, '7').replace(/W/g, '8').replace(/X/g, '9');
		
		// alpha...
		str = str.replace(/`/g, 'A').replace(/a/g, 'B').replace(/b/g, 'C').replace(/c/g, 'D').replace(/d/g, 'E').replace(/e/g, 'F').replace(/f/g, 'G').replace(/g/g, 'H').replace(/h/g, 'I').replace(/i/g, 'J').replace(/j/g, 'K').replace(/k/g, 'L').replace(/l/g, 'M').replace(/m/g, 'N').replace(/n/g, 'O').replace(/o/g, 'P').replace(/p/g, 'Q').replace(/q/g, 'R').replace(/r/g, 'S').replace(/s/g, 'T').replace(/t/g, 'U').replace(/u/g, 'V').replace(/v/g, 'W').replace(/w/g, 'X').replace(/x/g, 'Y').replace(/y/g, 'Z').replace(/|/g, '-').replace(/Q/g, '_').replace(/@/g, ' ').replace(//g, '@').replace(/D/g, '.');
		
		//alert(str);
	}
	str = str.toUpperCase(); 
	str = str.replace(/[ \-]/g, ''); //Take out dashes and spaces (but not underscores... let the Perl script do this)

	if (str == "")
	{
		return true;
	}

	target.value = str;
	
	//target.value = str.substr(0,3) + "-" + str.substr(3,3) + "-" + str.substr(6,2);
	
	return true;
}

// dp--for check_date function
//   fixed lazy-style date-entry
function padDate(str)
{
	arrDates = str.split(/\W/);
	for (var i=0; i < arrDates.length; i++)
	{
	    arrDates[i] = trimString(arrDates[i]);
	    var s = new String(arrDates[i]);
	    if (s.length < 2)
	    {
			arrDates[i] = "0" + arrDates[i];
	    }
	}
	var strNewDate = "";

	if(arrDates[0])
	{
		if (str.length == 8)
		{
			str = str.substr(0,4) + str.substr(6,2);
		}

		strNewDate = str;
	}
	if(arrDates[1])
	{
		strNewDate  = arrDates[0] + "/" + arrDates[1];
	}
	if(arrDates[2])
	{
		var rick = new String(arrDates[2]);
		if(rick.length == 4)
		{
			arrDates[2] = rick.substr(2,2);
		}
		strNewDate  = strNewDate + "/" + arrDates[2]
	}
	return strNewDate;
}

// dp--new concept
//   for validation, etc.
var fcPreambleRetval;

// dp--for airport survey page 0
//   modified slightly from original...
//   see below...
function check_date(field){
	var checkstr = "0123456789";
	var DateField = field;
	var Datevalue = "";
	var DateTemp = "";
	var seperator = ".";
	var day;
	var month;
	var year;
	var leap = 0;
	var err = 0;
	var i;

	fcPreambleRetval = 0;
	
	var str = new String(DateField.value);
	str = trimString(str);

	if (str == "") //Ok if user entered nothing
	{
		return true;
	}

	str = padDate(str);
	//Add year if user didn't add year. '
	str = str.replace(/\W/g, ''); //Take out dashes
	if (str.length == 4)
	{
		var today = new Date();
		var fullYear = new Number(today.getFullYear());

		var curMonth = today.getMonth() + 1;
		if(str.substr(0,2) == 12 && curMonth == 1)
		{
			fullYear = fullYear - 1;
		}
		
		var sFullYear = new String (fullYear);
		var endShortStr = sFullYear.substr(2,2);
		str = str + endShortStr;
	}
	err = 0;
	DateValue = str;
	/* Delete all chars except 0..9 */
	for (i = 0; i < DateValue.length; i++) {
		if (checkstr.indexOf(DateValue.substr(i,1)) >= 0) {
			DateTemp = DateTemp + DateValue.substr(i,1);
		}
	}
	DateValue = DateTemp;
	/* Always change date to 8 digits - string*/
	/* if year is entered as 2-digit / always assume 20xx */
	if (DateValue.length == 6) {
		DateValue = DateValue.substr(0,4) + '20' + DateValue.substr(4,2);
	}
	if (DateValue.length != 8) {
		err = 19;
	}
	/* year is wrong if year = 0000 */
	year = DateValue.substr(4,4);
	if (year == 0) {
		err = 20;
	}
	/* Validation of month*/
	//   month = DateValue.substr(2,2);
	month = DateValue.substr(0,2);
	if ((month < 1) || (month > 12)) {
		err = 21;
	}
	/* Validation of day*/
	//   day = DateValue.substr(0,2);
	day = DateValue.substr(2,2);
	if (day < 1) {
		err = 22;
	}

	/* Validation leap-year / february / day */
	if ((year % 4 == 0) || (year % 100 == 0) || (year % 400 == 0)) {
		leap = 1;
	}
	if ((month == 2) && (leap == 1) && (day > 29)) {
		err = 23;
	}
	if ((month == 2) && (leap != 1) && (day > 28)) {
		err = 24;
	}
	/* Validation of other months */
	if ((day > 31) && ((month == "01") || (month == "03") || (month == "05") || (month == "07") || (month == "08") || (month == "10") || (month == "12"))) {
		err = 25;
	}
	if ((day > 30) && ((month == "04") || (month == "06") || (month == "09") || (month == "11"))) {
		err = 26;
	}
	/* if 00 ist entered, no error, deleting the entry */
	//if ((day == 0) && (month == 0) && (year == 00)) {
	//   err = 0; day = ""; month = ""; year = ""; seperator = "";
	//}
	/* if no error, write the completed date to Input-Field (e.g. 13.12.2001) */
	if (err == 0) {

		//Format text field by MM/DD/YY
		DateField.value = str.substr(0,2) + "/" + str.substr(2,2) + "/" + str.substr(4,2);

		var today = new Date()

		var startDate = new Date(Date.parse(today)); //Get todays date
		var endDate = new Date(Date.parse(DateField.value));  //Get User entered Date

		var inconsist = startDate.getFullYear() - endDate.getFullYear(); // Difference Between 1900 & current Year
		var mod = inconsist % 100;
		if (!mod)
		{
			inconsist = inconsist + 0;
		}
		else // Not dividable by 100
		{
			var startYearStr = new String(startDate.getFullYear());
			var endYearStr = new String(endDate.getFullYear());

			var startShortStr = startYearStr.substr(2,2);
			var endShortStr = endYearStr.substr(2,2);

			var startShortNum = new Number(startShortStr)
			var endShortNum = new Number(endShortStr)

			inconsist = inconsist - (startShortNum - endShortNum);
		}

		var ShortYear = new Number(str.substr(4,2)) // 19##;
		var FullYear = 1900 + inconsist + ShortYear; // convert to 20##
		var tmp = str.substr(0,2) + "/" + str.substr(2,2) + "/" + FullYear.toString()

		//var jun1_04 = new Date(Date.parse("06/01/2004"));
		//var diff = DateDiff(jun1_04, tmp, "d", true);
		//diffNum = new Number(diff);
		//if (diffNum < 0)
		//{
		//	alert("Only flights after June 1, 2004 can be evaluated on this website. If you received a paper survey prior to that date, please mail it back in the envelope provided.");
		//	DateField.select();
		//	DateField.focus();
		//	return false;
		//}

		var diff = DateDiff(startDate, tmp, "d", true);
		diffNum = new Number(diff);
		diffNum++;
		if (diffNum > 1)
		{
			//alert("Future flights cannot be evaluated before they occur.");
			fcPreambleRetval = 1;
			DateField.select();
			DateField.focus();
			return false;
		}
		//else if (diffNum < -14)
		//{
			// Move this validation to the server side
			//alert("Flight must be within the last 14 days.");
			//DateField.select();
			//DateField.focus();
			//return false;
			//return true;
		//}
		else
		{
			return true;
		}
	}
	/* Error-message if err != 0 */
	else
	{
		//alert("The date you enter is not valid\nPlease enter a valid date...");
		fcPreambleRetval = 2;
		DateField.select();
		DateField.focus();
		return false;
	}
}

// dp--for check_date function
function DateDiff( start, end, interval, rounding )
{
    var iOut = 0;
    var bufferA = Date.parse( start ) ;
    var bufferB = Date.parse( end ) ;
    var number = bufferB-bufferA ;

    iOut = parseInt(number / 86400000) ;
    if(rounding) iOut += parseInt((number % 86400000)/43200001) ;

    return iOut ;
}

// dp--for many airport survey pages!!!
function searchForCity(objList, searchStr)
{
	for (var i = 0; i < objList.options.length; i++) 
	{          
		if (searchStr == objList.options[i].value)   
		{
			objList.options[i].selected = true;
			break;
		}
	}		
}

// dp--for airport survey page 1 (still)
function ClearPrefix(target, numLen)
{
	//var msg = "";
	var str = new String(target.value);
	str = trimString(str);

	fcPreambleRetval = 0;
	
	if (str.length > numLen)
	{
		//msg = "Flight number should not be more than " + numLen + "digits long.";
		//alert(msg);
		fcPreambleRetval = 1;
		target.value = '';
		target.focus();
		return false;
	}

	var val = str.match(/\D/i); // Match any non-digit character
	if (val)
	{
		//msg = "Flight number should be numeric only.";
		//alert(msg);
		fcPreambleRetval = 2;
		target.value = '';
		target.focus();
		return false;
	}

	// Clean out starting zeros
	str = str.replace(/^0+/, '');
	target.value = str;
	
	if(str)
	{
		document.forms[0].BLNKFLT.checked = false;
	}
	return true;
}

// dp--for airport survey page 1 (still)
function ClearPrefix2(target, numLen)
{
	//var msg = "";
	var str = new String(target.value);
	str = trimString(str);

	fcPreambleRetval = 0;
	
	if (str.length > numLen)
	{
		//msg = "Flight number should not be more than " + numLen + "digits long.";
		//alert(msg);
		fcPreambleRetval = 1;
		target.value = '';
		target.focus();
		return false;
	}

	var val = str.match(/\D/i); // Match any non-digit character
	if (val)
	{
		//msg = "Flight number should be numeric only.";
		//alert(msg);
		fcPreambleRetval = 2;
		target.value = '';
		target.focus();
		return false;
	}

	// Clean out starting zeros
	str = str.replace(/^0+/, '');
	target.value = str;
	
	if(str)
	{
		document.forms[0].NCBLNKFL.checked = false;
	}
	return true;
}

// dp--global version of TextAreaMax (kinda handy!!!)
//   for non-English version
//   simply returns true or false
function globTextAreaMax(target, max)
{
	var tmp = new String(target.value);
	if (tmp.length > max)
	{
		// dp--cut off!!!
		//   (this will happen at roughly the same time as the alert, so it's OK)
		target.value = tmp.substr(0,max);
		return true;
	}
	return false;
}

// for divideN function...
//   number validation function
function valNum(target, min, max, msg)
{	
	if (target.value == '') { return true; } 
	
	var str = new String(target.value);
	
	// dp--fix number for JAPANESE
	// dp--this had better be on a word boundary!!!
	
	if (document.forms[0].HDN_FORMPREFIX.value == "Japanese")
	{
		//alert(str);
		str = str.replace(/O/g, '0').replace(/P/g, '1').replace(/Q/g, '2').replace(/R/g, '3').replace(/S/g, '4').replace(/T/g, '5').replace(/U/g, '6').replace(/V/g, '7').replace(/W/g, '8').replace(/X/g, '9');
		//alert(str);
	}
	
	target.value = str;	
	var v = target.value; 

	if (v >= min && v <=max) 
	{ 
		return true; 
	} 
	else 
	{ 
		alert(msg); 
		target.value = '';
		target.focus();
		return false;
	}
}

// for divideN function...
//   updates total, etc...
function UPDATETOTAL(target, targettotal, szeval, msg)
{
	var msg = "";
	var total = 0;
	
	// dp--allow for a little dynamicism
	eval(szeval);
	
	//total = total +	cNum(document.forms[0].IMPCNSCH);
	//total = total +	cNum(document.forms[0].IMPRNDS);
	//total = total +	cNum(document.forms[0].IMPTKTPR);
	//total = total +	cNum(document.forms[0].IMPFFP);
	//total = total +	cNum(document.forms[0].IMPCSSRV);
	//total = total +	cNum(document.forms[0].IMPPRDFT);
	//total = total +	cNum(document.forms[0].IMPTRVPL);	

	if (total != targettotal)
	{	
		alert(msg);
		return false;
	}
	return true;
}

// for divideN function...
//   for now always updates "autosum" and "remainder"
function updateAutoSum(targettotal, szeval)
{	
	var total = 0;

	// dp--allow for a little dynamicism
	eval(szeval);

	//total = total +	cNum(document.forms[0].IMPCNSCH);
	//total = total +	cNum(document.forms[0].IMPRNDS);
	//total = total +	cNum(document.forms[0].IMPTKTPR);
	//total = total +	cNum(document.forms[0].IMPFFP);
	//total = total +	cNum(document.forms[0].IMPCSSRV);
	//total = total +	cNum(document.forms[0].IMPPRDFT);
	//total = total +	cNum(document.forms[0].IMPTRVPL);	


	document.getElementById('autosum').innerHTML = total;
	document.getElementById('remainder').innerHTML = targettotal - total;
}

// for divideN function...
function cNum(obj, msg)
{
	var ret = parseInt(obj.value, 10);
	var num = 0; 
	if (isNaN(ret)) 
	{
		num = 0;
		if(obj.value)
		{
			alert(msg);
			obj.value = "";
			obj.focus();
		}
	}
	else
	{
		num = ret;
		obj.value = num;
	}
	return num;
}