function saveInformation(surveyAbbr){
	var confirmClear = confirm("Are you sure you want to save the information and go to Table of Contents page?\nClick 'OK' to save the information.\nClick 'Cancel' to return to Status page without saving.");
	if (confirmClear){
		document.forms[0].action="index.cfm?fuseaction=survey"+surveyAbbr+".act_section&save_info=0";
		return true;
	}
	else { 
		window.location.href = "index.cfm?fuseaction=survey"+surveyAbbr+".dsp_sections";
		return false;
	}
}

function clearForm(theForm,confirmInd){
	if (confirmInd == 'Y'){
		var confirmClear = confirm('Are you sure you want to clear all questions of their current answers?\n\nClick OK to clear the form.\n\nClick Cancel to return to the form and retain current form values.');
		if(confirmClear){
			nullAllFormFields(theForm);
			return true;
		}
		else {
			return false;
		}
	}
	else {
		theForm.reset();
		return true;
	}
}

function nullAllFormFields(myForm)
	{
	for (i=0; i<myForm.elements.length; i++)
		{
		//loaded the
		var obj = myForm.elements[i];

		//check the form fields except for fileName and player caption
		if(obj.type == "text")
			{
			obj.value="";		
			}

		//textarea check
		if(obj.type == "textarea")
			{
			obj.value="";
			}

		if(obj.type == "checkbox")
			{
			obj.checked = false;			
			}

		//checking the drop downs
		//if(obj.type == "select-one" && obj.options[obj.selectedIndex].value == "99" || obj.options[obj.selectedIndex].value == null){
		if(obj.type == "select-one")
			{
			obj.options.selectedIndex = 0;			
			}

		//if(obj.type == "select-multiple" && obj.options[obj.selectedIndex].value == "" || obj.options[obj.selectedIndex].value == null){
		if(obj.type == "select-multiple")
			{
			obj.options.selectedIndex = 0;			
			}

		if(obj.type=="radio")
			{
			obj.checked = false;
			}
		}
	return true;
	}

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;
   	err = 0;
   DateValue = DateField.value;
   /* 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 8 digits - string*/
   
   if (DateValue.length == 0) {
      err = 1;}
//   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;
   }
   if (year.substr(0,1) == 0){
      err = 20;
   }
   /* Validation of month*/
   month = DateValue.substr(0,2);
   if ((month < 1) || (month > 12)) {
      err = 21;
   }
   /* Validation of day*/
   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 (err == 0) {
      DateField.value = month + seperator + day + seperator + year;
	 return true;
   }
   else {
	  return false;
   }
}

// Check Integer Numbers.  If field is not blank or doesn't contain "NI" or "NA", check to make sure the entry is a valid positive integer not exceeding the maximum value for integer fields.
function isValidBigInt(field)
{
	if (field.value != "")
	{
		value =  stripCommas(field.value);
		if (!isPosInteger(value))
		{
			alert("Number of minutes must be a positive whole number (no decimal point).");
			field.focus();
			field.select();
			return false;
		} else {
			if (exceedsBigIntMax(value))
			{
				alert("Value entered exceeds maximum allowed.");
				field.focus();
				field.select();
				return false;
			} else {
				field.value=value;
				return true;
			}
		}
	} else {
		return true;
	}
}

// Check for a positive integer value.
function isPosInteger(inputVal)
{
	inputStr = inputVal.toString();
	for (var i = 0; i < inputStr.length; i++)
	{
		var oneChar = inputStr.charAt(i);
		if (oneChar < "0" || oneChar > "9")
		{
			return false;
		}
	}
	return true;
}

function isNumber(inNum)
	{
	if(inNum == '')
		{
		return false;
		}
		
	var allowables = '0123456789';
	var numLen = inNum.length;
	
	for(z=0; z<numLen; z++)
		{
		if(allowables.indexOf(inNum.charAt(z)) < 0)
			{
			return false;
			}
		}
	return true;
}

// Check to see if integer value exceeds maximum for integer field.
function exceedsBigIntMax(inputStr)
{
	compareNum = 999;
	//Optional second parameter, pass in value for "maximum integer"
	if (typeof arguments[1] == 'number' ) {
		compareNum = arguments[1];
	}
	num = parseInt(inputStr);
	if (num > compareNum)
	{
		return true;
	}
	return false;
}

// Strips commas from numeric entries.  Used before checking for a valid integer or smallint entry.  Don't want to give the user an error message for putting commas in their numbers, but don't want them to cause an ODBC error either, so allow user to enter, but strip them out.
function stripCommas(inputStr)
{
	var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is a comma, remove it from input string.
    for (i = 0; i < inputStr.length; i++)
    {   
        var c = inputStr.charAt(i);
        if (c != ",") returnString += c;
    }
    return returnString;
}

// Validates textarea field on change.
function isValidTextArea(field){
	if(field.value.length > 4000){
		alert(field + ' exceeds the maximum of 4000 characters.  Please change your comments to fit within this limit and click the "Save & Continue" button again.  Further comments can be emailed to cgq@aamc.org. Thank you.');
		field.focus();
		field.select();
		return false;
	}
	
	return true;
}

// Validates email field on change (onChange in email input tag).
function emailcheck(field){
	if (field.value!=""){
		if (field.value.indexOf("@")==-1 ||      
			field.value.indexOf(".")==-1 ||
			field.value.indexOf(" ")!=-1 ||        
			field.value.length<6){
		
		alert("A valid email address must be at least 5 characters long, have an @ sign and follow the format:\n name@domain.suffix");
		field.focus();
		field.select();
		return false;
		} 
		else {
			return true;
		}
	} 
	else {
		return true;
	}
}

function centerPopUp( url, name, width, height, scrollbars ) { 
 
	if( scrollbars == null ) scrollbars = "0" 
 
	str  = ""; 
	str += "resizable=1,"; 
	str += "scrollbars=" + scrollbars + ","; 
	str += "width=" + width + ","; 
	str += "height=" + height + ","; 
 
	if ( window.screen ) { 
		var ah = screen.availHeight - 30; 
		var aw = screen.availWidth - 10; 
 
		var xc = ( aw - width ) / 2; 
		var yc = ( ah - height ) / 2; 
 
		str += ",left=" + xc + ",screenX=" + xc; 
		str += ",top=" + yc + ",screenY=" + yc; 
	} 
	window.open( url, name, str ); 
} 

function popWin(theUrl, theTitle, theFeatures)
	{
	window.open(theUrl, theTitle, theFeatures)
	}
	
function isFloat(inNum)
	{
	if(inNum.length < 1)
		{
		return false;
		}
		
	var allowables = '-0123456789.';
	var numLen = inNum.length;
	
	for(z=0; z<numLen; z++)
		{
		if(allowables.indexOf(inNum.charAt(z)) < 0)
			{
			return false;
			}
		}
	return true;
	}
	
function nullFormField(fieldList, formName)
	{
	var thisField;
	var fieldArray = fieldList.split('|');
	
	for(j=0; j<fieldArray.length; j++)
		{
		
		thisField = eval('document.'+ formName +'.'+ fieldArray[j]);
		
		// RADIO
		if(thisField[0] && thisField[0].type == 'radio')
			{
			for(k=0; k<thisField.length; k++)
				{
				thisField[k].checked = false;
				}
			}
			
		// MULTIPLE CHECKBOXES
		else if(thisField[0] && thisField[0].type == 'checkbox')
			{
			for(k=0; k<thisField.length; k++)
				{
				thisField[k].checked = false;
				}
			}
					
		// SINGLE CHECKBOX
		else if(thisField.type == 'checkbox')
			{
			thisField.checked = false;
			}
					
		// DROP-DOWN
		else if(thisField.type == 'select-one' || thisField.type == 'select-multiple')
			{
			for(k=0; k<thisField.length; k++)
				{
				if(thisField[k].value == '')
					{
					thisField[k].selected = true;
					}
				}
			}
					
							
		// REGULAR VALUE FIELD
		else
			{
			thisField.value = '';
			}	
		}	
	}
	
function checkElementDisplay(checkElement, showElement, nullFieldList, theForm)
	{
	var showArray = showElement.split('|');
			
	if(checkElement.checked)
		{
		for(i=0; i<showArray.length; i++)
			{
			document.getElementById(showArray[i]).className = 'available';
			}
		}
	else
		{
		nullFormField(nullFieldList, theForm);
		for(i=0; i<showArray.length; i++)
			{
			document.getElementById(showArray[i]).className = 'unavailable';
			}
		
		}
	
	}
	
function valueElementDisplay(elementValue, valueList, elementList, showStyle, hideStyle)
	{
	var valueArray = valueList.split('|');
	var elementArray = elementList.split('|');
	var whichStyle = hideStyle;
		
	for(i=0; i<valueArray.length; i++)
		{
		if(elementValue == valueArray[i])
			{
			whichStyle = showStyle;
			}
		}
	
	for(j=0; j<elementArray.length; j++)
		{
		document.getElementById(elementArray[j]).style.display = whichStyle;
		}	
	}
	
function calcTotal(formName, elementList, totalItem)
	{
	var elementArray = elementList.split('|');
	var totalAmount = 0;
	var thisAmount;
	var totalField = eval('document.' + formName + '.' + totalItem);
	var numCheck = true;
	
	for(i=0; i<elementArray.length; i++)
		{
		thisAmount = eval('document.' + formName + '.' + elementArray[i]);
		if(thisAmount.value != '')
			{
			if(isNaN(thisAmount.value))
				{
				numCheck = false;
				}
			else
				{
				totalAmount = totalAmount + parseFloat(thisAmount.value);
				}
			}
		}
	totalField.value = totalAmount;
	return numCheck;
	}
	
function checkElementDisable(checkElement, formName, fieldDisableList, idDisableList, disableClassName)
	{
	var fieldDisableArray = fieldDisableList.split('|');
	var thisField;
	var disableStatus;
	if(idDisableList)
		{
		var idDisableArray = idDisableList.split('|');
		}
	else
		{
		var idDisableArray = new Array();
		}
	
	if(checkElement.checked)
		{
		disableStatus = false;
		}
	else
		{
		disableStatus = true;
		for(m=0; m<idDisableArray.length; m++)
			{
			
			document.getElementById(idDisableArray[m]).className = disableClassName;
			}
		}
			
	for(j=0; j<fieldDisableArray.length; j++)
		{

		thisField = eval('document.'+formName+'.'+fieldDisableArray[j]);
		
		// RADIO
		if(thisField[0] && thisField[0].type == 'radio')
			{
			for(k=0; k<thisField.length; k++)
				{
				thisField[k].disabled = disableStatus;
				thisField[k].checked = false;
				}
			}

		// MULTIPLE CHECKBOXES
		else if(thisField[0] && thisField[0].type == 'checkbox')
			{
			for(k=0; k<thisField.length; k++)
				{
				thisField[k].disabled = disableStatus;
				thisField[k].checked = false;
				}
			}

		// SINGLE CHECKBOX
		else if(thisField.type == 'checkbox')
			{
			thisField.disabled = disableStatus;
			thisField.checked = false;
			}

		// DROP-DOWN
		else if(thisField.type == 'select-one' || thisField.type == 'select-multiple')
			{
			thisField.disabled = disableStatus;
			for(k=0; k<thisField.length; k++)
				{
				if(thisField[k].value == '')
					{
					thisField[k].selected = true;
					}
				}
			}

		// REGULAR VALUE FIELD
		else
			{
			thisField.disabled = disableStatus;
			//thisField.value = '';
			}	
		}	
	}
	
function checkElementFieldRequire(checkElement, formName, fieldRequireList, message)
	{
		//alert('here');
	var fieldRequireArray = fieldRequireList.split('|');
	
	if(checkElement.checked)
		{
		for(i=0; i<fieldRequireArray.length; i++)
			{
			if(getFieldVal(formName, fieldRequireArray[i]) == '')
				{
				alert(message);
				return false;
				}
			}
		}
	return true;
	}
	
function getFieldVal(theForm, theField)
	{
	var field = eval('document.'+ theForm+'.'+ theField);
	var fieldVal = '';
								
	// RADIO
	if(field[0] && field[0].type == 'radio')
		{
		fieldVal = '';
		for(j=0; j<field.length; j++)
			{
			if(field[j].checked == true)
				{
				fieldVal = field[j].value;
				}
			}
		}

	// MULTIPLE CHECKBOXES
	else if(field[0] && field[0].type == 'checkbox')
		{
		fieldVal = '';
		for(j=0; j<field.length; j++)
			{
			if(field[j].checked == true)
				{
				fieldVal = field[j].value;
				}
			}
		}

	// SINGLE CHECKBOX
	else if(field.type == 'checkbox')
		{
		fieldVal = '';
		if(field.checked == true)
			{
			fieldVal = field.value;
			}
		}

	// DROP-DOWN
	else if(field.type == 'select-one' || field.type == 'select-multiple')
		{
		fieldVal = '';
		for(j=0; j<field.length; j++)
			{
			if(field[j].selected == true)
				{
				fieldVal = field[j].value;
				}
			}
		}


	// REGULAR VALUE FIELD
	else
		{
		fieldVal = field.value;
		}
		
	return fieldVal;
	}
	
	
function checkElementAvailable(checkElement, formName, elementList, theClassName)
	{
	var elementArray = elementList.split('|');
	
	if(checkElement.checked)
		{
		for(i=0; i<elementArray.length; i++)
			{
			document.getElementById(elementArray[i]).className = theClassName;
			}
		}
	}

function confirmDecision(message)
	{
	var confirmed = confirm(message);
	if(!confirmed)
		{
		return false;
		}
	return true;
	}
	
	
function stripSmartQuotes(strippedString)
	{
	// define the bad characters
	var SMART_DOUBLE_QUOTES    = new RegExp( '[\\u201C\\u201D]', 'g' );
  	var SMART_SINGLE_QUOTES    = new RegExp( '[\\u2018\\u2019]', 'g' );
	var SMART_ELLIPSIS = new RegExp('\\u2026', 'g');
	var SMART_DASHES = new RegExp('[\\u2013\\u2014]', 'g');
	var BROKEN_BAR = new RegExp('\\u00A6', 'g');
	var TRADE_MARK_SIGN = new RegExp('\\u2122', 'g');
	var YEN_SIGN = new RegExp('\\u00A5', 'g');
	
	strippedString = strippedString.replace(SMART_DOUBLE_QUOTES, '\"');
	strippedString = strippedString.replace(SMART_SINGLE_QUOTES, '\'');
	strippedString = strippedString.replace(SMART_ELLIPSIS, '\.\.\.');
	strippedString = strippedString.replace(SMART_DASHES, '--');
	strippedString = strippedString.replace(BROKEN_BAR, '|');
	strippedString = strippedString.replace(TRADE_MARK_SIGN, 'tm');
	strippedString = strippedString.replace(TRADE_MARK_SIGN, 'Y');
			
	return strippedString;	
	}	 
	
function pageConfirmLogout(surveyAbbr) {
	var confirmLogout = confirm("Clicking \'OK\' will save your answers for this section and log you out.");
	if(confirmLogout){
		// If click OK to save, validate form fist
		var form_validated = validateform();
		if(form_validated ) {	
		document.forms[0].action="index.cfm?fuseaction=survey"+surveyAbbr+".act_section&save_info=2";
		document.forms[0].submit();
		return true;	
		}
		else
		return true;			
	} 
	else {		
		window.location.href="index.cfm?fuseaction=survey" + surveyAbbr + ".act_logout";
		return true;
	}
}	