function caa_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=caa_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function caa_changeProp(objName,x,theProp,theValue) { //v6.0
  var obj = caa_findObj(objName);
  if (obj && (theProp.indexOf("style.")==-1 || obj.style)){
    if (theValue == true || theValue == false)
      eval("obj."+theProp+"="+theValue);
    else eval("obj."+theProp+"='"+theValue+"'");
  }
}

function caa_changeProp2(objName,x,theProp,theValue) { //v6.0
  var obj = caa_findObj(objName);
  if (obj && (theProp.indexOf("style.")==-1 || obj.style)){
    if (theValue == true || theValue == false)
    eval("obj."+theProp+"="+theValue);
    else eval("obj."+theProp+"='"+theValue+"'");
  }
  document.form.OTHER_AMOUNT.value = ""
}

function confirmDelete()
{
var agree=confirm("Are you sure you wish to delete this record?");
if (agree)
        return true ;
else
        return false ;
}

function confirmFinish()
{
var agree=confirm("Are you sure you wish to finish your application? This step can not be undone.");
if (agree)
        return true ;
else
        return false ;
}

function SetAllCheckBoxes(FormName, FieldName, CheckValue)
{
	if(!document.forms[FormName])
		return;
	var objCheckBoxes = document.forms[FormName].elements['id[]'];
	if(!objCheckBoxes)
		return;
	var countCheckBoxes = objCheckBoxes.length;
	if(!countCheckBoxes)
		objCheckBoxes.checked = CheckValue;
	else
		// set the check value for all check boxes
		for(var i = 0; i < countCheckBoxes; i++)
			objCheckBoxes[i].checked = CheckValue;
}

function toggle_DisplaySelect()
{
	var selectBox = document.getElementById('country_select');
	var state2_div = document.getElementById('div_state2');
	var state1_div = document.getElementById('div_state1');	
	var state2_input = document.getElementById('state2');		
	if (selectBox.value!=410) 
	{
		state2_div.style.display = 'block';
		state1_div.style.display = 'none';
	}
	else
	{
		state2_input.value = "";
		state2_div.style.display= 'none';		
		state1_div.style.display = 'block';		
	}	
}


var submitcount=0;

function checkSubmit() 
{
	if (submitcount == 0)
	{
		submitcount++;
		document.Surv.submit();
	}
}


function wordCounter(field, countfield, maxlimit) 
{
	wordcounter=0;
	for (x=0;x<field.value.length;x++) 
	{
		if (field.value.charAt(x) == " " && field.value.charAt(x-1) != " ")  {wordcounter++}  // Counts the spaces while ignoring double spaces, usually one in between each word.
		if (wordcounter > 250) {field.value = field.value.substring(0, x);}
		else {countfield.value = maxlimit - wordcounter;}
	}
}

function textCounter(field, countfield, maxlimit) 
{
	if (field.value.length > maxlimit)
	{field.value = field.value.substring(0, maxlimit);}
	else
	{countfield.value = maxlimit - field.value.length;}
}

function CheckAll()
{
	count = document.frm.elements.length;
    for (i=0; i < count; i++) 
	{
    if(document.frm.elements[i].checked == 1)
    	{document.frm.elements[i].checked = 0; }
    else {document.frm.elements[i].checked = 1;}
	}
}

function doClear(theText) {
    if (theText.value == theText.defaultValue) {
        theText.value = ""
	}
}
function SetChecked(val,chkName, form) {
	dml=document.forms[form];
	len = dml.elements.length;
	var i=0;
	for( i=0 ; i<len ; i++) {
		if (dml.elements[i].name==chkName) {
			dml.elements[i].checked=val;
		}
	}
}

function ValidateForm(dml,chkName){
	len = dml.elements.length;
	var i=0;
	for( i=0 ; i<len ; i++) {
		if ((dml.elements[i].name==chkName) && (dml.elements[i].checked==1)) return true
	}
	alert("Please select at least one record")
	return false;
}

function changeRow(rowName, invisibleName, selectedStyle, unselectedStyle){
	var mycell = document.getElementById(rowName);
	var myinvisible = document.getElementById(invisibleName);	
	if(myinvisible.value == "selected")
	{
		myinvisible.value = "unselected";
		rowName.style = unselectedStyle;		
	}
	else
	{
		myinvisible.value = "selected";
		rowName.style = selectedStyle;		
	}
}

function changeInvisible(invisibleName){
	var myinvisible = document.getElementById(invisibleName);
	if(myinvisible.value == "selected")
	{
		myinvisible.value = "unselected";
	}
	else
	{
		myinvisible.value = "selected";
	}	
}

function navigate(choice) {
	var url = choice.options[choice.selectedIndex].value; 
	if (url) { 
		location.href = url; 
	} 
}