function submitMoreLink(strForm,intFGMID)
// submits the More Link
{
			window.document[strForm].B.value='y';
			window.document[strForm].FGMIDMore.value=intFGMID;
			window.document[strForm].submit();
}

function submitAddAnotherLink(strForm,intFGID)
// submits the Add Another Link
{
			window.document[strForm].mode.value=4;
			window.document[strForm].addAnother.value='y';
			window.document[strForm].FGIDAnother.value=intFGID;
			window.document[strForm].submit();
}

function doBrowse(strSearchString,intPageNum)
{
	window.document.searchForm.s.value=strSearchString;
	window.document.searchForm.PAGE.value=intPageNum;
	window.document.searchForm.submit();
	
}

function CheckNotSpecificEnough(inputbox,SValue)
{
	if (inputbox.value == SValue)
	{
		window.alert('The answer ' + SValue + ' is not specific enough.  Please enter a more specific answer.');
		inputbox.value='';
		inputbox.focus();
	}

}

function LeftTrim(String,TrimChar)
{
 // **********************************************************
 // Placed in the public domain by Affordable Production Tools
 // April 27, 1998
 // Web site: http://www.apt.simplenet.com
 //
 // December 2, 1998 -- Modified to allow specification of
 // character to be trimmed.
 //
 // This function trims spaces (default) or the specified
 // character from the left of a string or form field.
 // **********************************************************
 String += "";         // Force argument to string.
 TrimChar += "";       // Force argument to string.
 if((TrimChar == "") || (!(TrimChar.length == 1))) {
  TrimChar = " ";
 }
 if(String.length == 0)
  return(String);
 var Count = 0;
 for(Count = 0;Count < String.length;Count++)
 {
  if(!(String.charAt(Count) == TrimChar))
   return(String.substring(Count,String.length));
 }
 return("");
}

function RightTrim(String,TrimChar)
{
 // **********************************************************
 // Placed in the public domain by Affordable Production Tools
 // April 27, 1998
 // Web site: http://www.apt.simplenet.com
 //
 // December 2, 1998 -- Modified to allow specification of
 // character to be trimmed.
 //
 // This function trims spaces (default) or the specified
 // character from the right of a string or form field.
 // **********************************************************
 String += "";        // Force argument to string.
 TrimChar += "";      // Force argument to string.
 if((TrimChar == "") || (!(TrimChar.length == 1)))
  TrimChar = " ";
 if(String.length == 0)
  return(String);
 var Count = 0;
 for(Count = String.length -1;Count >= 0;Count--)
 {
  if(!(String.charAt(Count) == TrimChar))
   return(String.substring(0,Count + 1));
 }
 return("");
}

function AllTrim(String,TrimChar)
{
 // **********************************************************
 // Placed in the public domain by Affordable Production Tools
 // April 27, 1998
 // Web site: http://www.apt.simplenet.com
 //
 // December 2, 1998 -- Modified to allow specification of
 // character to be trimmed.
 //
 // This function trims spaces (default) or the specified
 // character from the left and the right of a string or form field.
 //
 // Note that this functions uses two other library functions,
 // TrimLeft() and TrimRight().
 // **********************************************************
 String += "";        // Force argument to string.
 TrimChar += "";      // Force argument to string.
 if((TrimChar == "") || (!(TrimChar.length == 1)))
  TrimChar = " ";
 return(RightTrim(LeftTrim(String,TrimChar),TrimChar));
}

function replaceSubstring(input, from, to) {
 // Goes through the input and replaces every occurrence of from with to
 var output='';
 while(input.length >= from.length && input.length > 0){
  if(input.substring(0,from.length) == from){
   output += to;
   input = input.substring(from.length);
  }else{
   output += input.substring(0,1); 
   input = input.substring(1);
  } 
 }
 return output + input;
}

function clearRadioButton(strRadioButtonName)
{
// clears radio buttons answers

	thecheckbox = eval("document.newQuestion." + strRadioButtonName); 
	
	if (thecheckbox)
	{
		if (thecheckbox.length >= 2)
		{
			for (i=0;i<thecheckbox.length;i++)
			{
				document.newQuestion[strRadioButtonName][i].checked=false;
			}
		}
		else 
		{
			thecheckbox.checked=false;						
		}
	}
}


function SaveAnswerAndSubmit(ControlName,AnswerId)
{
	// saves an answer & submits it

	brwseform[ControlName].value = AnswerId;
	brwseform.submit();

}
function clearButtonFlags(strForm)
{

	if (window.document[strForm])
	{

		window.document[strForm].B.value='';
		window.document[strForm].addAnother.value='';
		window.document[strForm].FGIDAnother.value='';
		window.document[strForm].FGMIDMore.value='';

	}

}

function SubmitQFormNext(strForm)
{
    window.document[strForm].FGMIDMore.value = '';

    ClearInvalidFields();
	
	var newtext;
	// check to see if the ordernow form exists on the page and the employmentstatus questions are there
	for (j=0;j<document.forms.length;j++)
	{
		if (document.forms[j].name == 'ordernowform')
		{
			for (i=0;i<document.ordernowform.elements.length;i++)
			{
				if (document.ordernowform.elements[i].name == 'employmentstatusid')
				{
					if (document.ordernowform.employmentstatusid.value != '')
					{
					// add employmentstatusID value from ordernow form to the question form so it will
					// get passed to the answerquestion page along with other question answers
					newtext = '<input type=hidden name=esID value=' + document.ordernowform.employmentstatusid.value + '>';
						window.document[strForm].insertAdjacentHTML('beforeEnd',newtext);
					}
				}
			}
		break;
		}
	}
}

// See renderqform.asp for details on this function
function AddMultiAnswerArea(fg)
{
	var tbl = document.getElementById('TBL_'+fg);

	var example = tbl.rows[0].cells[0].innerHTML;
	var tr = tbl.insertRow(tbl.rows.length - 1);
	var td = tr.insertCell(0);
	td.colSpan = 2;
	td.innerHTML = '<hr>';
	
	var tr = tbl.insertRow(tbl.rows.length - 1);
	var td = tr.insertCell(0);
	td.colSpan = 2;
	var next = document.getElementById('next_' + fg);
	var nextVal = parseInt(next.value);
	td.innerHTML = example.replace(/_EX/g, '_' + nextVal);
	next.value = nextVal + 1;

	var link = document.getElementById('dlink_'+fg);
	link.style.display="inline";

	if (tbl.rows.length >= 10)
	{
		var aalink = document.getElementById('aalink_'+fg);
		aalink.style.display="none";
	}

	var acfs = acf[fg];
	if (acfs != null)
	{
		for (var ifgm in acfs)
		{
			var fgm = acfs[ifgm];
			ActivateAutoComplete('FV' + fgm[0] + '_' + nextVal, fgm[0], fgm[1], fgm[2]);
		}
	}
}

// See renderqform.asp for details on this function
function RemoveMultiAnswerArea(fg)
{
	var tbl = document.getElementById('TBL_'+fg);
	var len = tbl.rows.length
	if (len > 2)
	{
		tbl.deleteRow(len - 3);
		tbl.deleteRow(len - 3);
	}
	if (tbl.rows.length <= 4)
	{
		var link = document.getElementById('dlink_'+fg);
		link.style.display="none";
	}
	var aalink = document.getElementById('aalink_'+fg);
	aalink.style.display="inline";
}

function addOnloadEvent(fnc){
  if ( typeof window.addEventListener != "undefined" )
    window.addEventListener( "load", fnc, false );
  else if ( typeof window.attachEvent != "undefined" ) {
    window.attachEvent( "onload", fnc );
  }
  else {
    if ( window.onload != null ) {
      var oldOnload = window.onload;
      window.onload = function ( e ) {
        oldOnload( e );
        window[fnc]();
      };
    }
    else
      window.onload = fnc;
  }
}