function onDivClick( divName, checked ) {
  
  	if( checked == true ) {
		eval( getDocObj( divName ) ).style.display="block";
  	}
  	else {
     	eval( getDocObj( divName ) ).style.display="none";
  	}
}

function onChildrenSelect( num ) {
  
  	for ( i = 1; i <= 6; i++ ) {
	  	if ( i <= num ) {
	  	  	eval( getDocObj( "child" + i + "Info" ) ).style.display="block";
	  	}	  	  
	  	else {
	  	  	eval( getDocObj( "child" + i + "Info" ) ).style.display="none";
	  	}
	}
}


function checkAllZips(chk) {
  frm = document.forms[0];
  for (i = 0; i < frm.length; i++)   {
    if(frm[i].type == "checkbox")     {
      if(chk.checked == true && frm[i].value != 1) {
        frm[i].checked = true;
      }
      else if (chk.checked == false && frm[i].value != 1) {
        frm[i].checked = false;
      }
    }
  }
}

function selectAll(obj, selected) {
	for (i = 0; i < obj.length; i++) {
		obj.options[i].selected = selected;
	}
    document.TheForm.checkAll
}

function unCheck(obj) {
    if (obj) {
        obj.checked = false;
    }
}

function deleteSelected(obj) {
	for (i = 0; i < obj.length; i++) {
		if (obj.options[i].selected) {	
			obj.options[i] = null;
			i--;
		}
	}
}

function checkMoveCursor(source, target, maxLength) {
  var noSpace = source.value;
  source.value = noSpace.replace( /\s/g, '' );
  
  if (source.value.length == maxLength) {
    target.focus();
  }
}

function getDocObj(elem,parent) {
    if (document.layers) {
        if (parent) {
            return "document."+parent+".document."+elem;
        }
        else {
            return "document."+elem;
        }
    }
    else if (document.all){
        return "document.all."+ elem;
    }
    else if (document.getElementById) {
        return "document.getElementById('"+elem+"')";
    }
}

// Browser Display of Table Row
function bdtr() {
	var agt=navigator.userAgent.toLowerCase();
	if (agt.indexOf("msie") != -1) {
		return 'block';
	} else {
		return 'table-row';
	}
}


function switchView(obj, imageID) {

	if (obj.style.display == 'none') {
	 
        obj.style.visibility='visible';
        obj.style.display='';
        
        if (imageID) {
        
        	imageID.src = 'images/tree_open.gif';
        	
        }
        
    } else {
    
        obj.style.display = 'none';
        
        if (imageID) {
        
        	imageID.src = 'images/tree_closed.gif';
        	
        }
        
    }
}

function getRADValue(radioObj) {
	
		if (!radioObj)
			return "";
		
		var radioLength = radioObj.length;
	
		if (radioLength == undefined) {
		
			if (radioObj.checked) {
			
				return radioObj.value;
				
			}
			else {
			
				return "blank";
				
			}
				
		}
	
		for (var i = 0; i < radioLength; i++) {
		
			if(radioObj[i].checked) {
				return radioObj[i].value;
			}
			
		}
		
		return "";
	
	}
	
	
	function clearRADValue(radioObj) {
	
		if (radioObj) {
		
			var radioLength = radioObj.length;
	
			if (radioLength == undefined) {
		
				radioObj.checked = false;
				
			}
	
			for (var i = 0; i < radioLength; i++) {
		
				radioObj[i].checked = false;
				
			}
		
		}
	
	}
	
	
function SingleSelectRequired(Form, Field)
{
	var itemSelected = eval("document." + Form + "." + Field + ".selectedIndex");
	if (itemSelected == 0)
		{ return false; }
	else { return true; }
}

function TextAreaRequired(Form, Field)
{
	var length = eval("document." + Form + "." + Field + ".value.length");
	if (length == 0)
		{ return false; }
	else { return true; }
}

function ValidateForm( FormName )
{

	if (!SingleSelectRequired(FormName,'dob_month_pi'))
	{
	document.TheForm.complete.value=1;
	alert("Please enter your month of birth. The cursor will move to the proper place on the form to enter this when you click OK.");
	eval("document."+FormName+".dob_month_pi"+".focus();");
	return false;
	}
	
	if (!SingleSelectRequired(FormName,'dob_day_pi'))
	{
	document.TheForm.complete.value=1;
	alert("Please enter your day of birth. The cursor will move to the proper place on the form to enter this when you click OK.");
	eval("document."+FormName+".dob_day_pi"+".focus();");
	return false;
	}
	
	if (!SingleSelectRequired(FormName,'dob_year_pi'))
	{
	document.TheForm.complete.value=1;
	alert("Please enter your year of birth. The cursor will move to the proper place on the form to enter this when you click OK.");
	eval("document."+FormName+".dob_year_pi"+".focus();");
	return false;
	}
	
	if (!SingleSelectRequired(FormName,'hgt_ft_pi'))
	{
	document.TheForm.complete.value=1;
	alert("Please enter your height in feet. The cursor will move to the proper place on the form to enter this when you click OK.");
		eval("document."+FormName+".hgt_ft_pi"+".focus();");
		return false;
	}

	if (!SingleSelectRequired(FormName,'hgt_in_pi'))
	{
	document.TheForm.complete.value=1;
	alert("Please enter your height in inches. The cursor will move to the proper place on the form to enter this when you click OK.");
		eval("document."+FormName+".hgt_in_pi"+".focus();");
		return false;
	}

	if (!TextAreaRequired(FormName,'wgt_pi'))
	{
	document.TheForm.complete.value=1;
	alert("Please enter your weight. The cursor will move to the proper place on the form to enter this when you click OK.");
		eval("document."+FormName+".wgt_pi"+".focus();");
		return false;
	}
	
	if (!TextAreaRequired(FormName,'first_name'))
	{
		onDivClick('contact', true);
		alert("Please enter your first name.");
		eval("document."+FormName+".first_name"+".focus();");
		return false;
	}

 	if (!TextAreaRequired(FormName,'last_name'))
	{
		alert("Please enter your last name.");
		eval("document."+FormName+".last_name"+".focus();");
		return false;
	}
	
	if (!TextAreaRequired(FormName,'address'))
	{
		alert("Please enter your address.");
		eval("document."+FormName+".address"+".focus();");
		return false;
	}

	if (!TextAreaRequired(FormName,'city'))
	{
		alert("Please enter your city.");
		eval("document."+FormName+".city"+".focus();");
		return false;
	}

	if (!SingleSelectRequired(FormName,'state'))
	{
		alert("Please select your state.");
		eval("document."+FormName+".state"+".focus();");
		return false;
	}

	if (!TextAreaRequired(FormName,'zip_code'))
	{
		alert("Please enter your zip code.");
		eval("document."+FormName+".zip_code"+".focus();");
		return false;
	}

	if (!TextAreaRequired(FormName,'phone_1_area'))
	{
		alert("Please enter your daytime phone number area code.");
		eval("document."+FormName+".phone_1_area"+".focus();");
		return false;
	}
	
	if (!TextAreaRequired(FormName,'phone_1_prefix'))
	{
		alert("Please enter your daytime phone number prefix.");
		eval("document."+FormName+".phone_1_prefix"+".focus();");
		return false;
	}

	if (!TextAreaRequired(FormName,'phone_1_last4'))
	{
		alert("Please enter the last 4 digits of your daytime phone number.");
		eval("document."+FormName+".phone_1_last4"+".focus();");
		return false;
	}
}
