function handleError(msg, url, ln) {
   // Do you custom code here
   return true;
}

window.onerror = handleError;

function handleEnter (field, event) {
		var keyCode = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode;
		if (keyCode == 13) {
			var i;
			for (i = 0; i < field.form.elements.length; i++)
				if (field == field.form.elements[i])
					break;
			i = (i + 1) % field.form.elements.length;
			field.form.elements[i].focus();
			return false;
		} 
		else
		return true;
	}      



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 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+"')";
    }
}
	
	
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 ExtendJS( FormName )
{

	if (!SingleSelectRequired(FormName,'sex_pi'))
	{
	alert("Please enter your gender. The cursor will move to the proper place on the form to enter this when you click OK.");
	eval("document."+FormName+".sex_pi"+".focus();");
	return false;
	}

	if (!SingleSelectRequired(FormName,'dob_month_pi'))
	{
	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'))
	{
	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'))
	{
	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'))
	{
	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'))
	{
	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'))
	{
	    alert("Please enter your weight in pounds. 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. The cursor will move to the proper place on the form to enter this when you click OK");
		eval("document."+FormName+".first_name"+".focus();");
		return false;
	}

 	if (!TextAreaRequired(FormName,'last_name'))
	{
		alert("Please enter your last name. The cursor will move to the proper place on the form to enter this when you click OK");
		eval("document."+FormName+".last_name"+".focus();");
		return false;
	}
	
	if (!TextAreaRequired(FormName,'address'))
	{
		alert("Please enter your address. The cursor will move to the proper place on the form to enter this when you click OK");
		eval("document."+FormName+".address"+".focus();");
		return false;
	}

	if (!TextAreaRequired(FormName,'city'))
	{
		alert("Please enter your city. The cursor will move to the proper place on the form to enter this when you click OK");
		eval("document."+FormName+".city"+".focus();");
		return false;
	}

	if (!SingleSelectRequired(FormName,'state'))
	{
		alert("Please select your state. The cursor will move to the proper place on the form to enter this when you click OK");
		eval("document."+FormName+".state"+".focus();");
		return false;
	}

	if (!TextAreaRequired(FormName,'zip_code'))
	{
		alert("Please enter your zip code. The cursor will move to the proper place on the form to enter this when you click OK");
		eval("document."+FormName+".zip_code"+".focus();");
		return false;
	}

	if (!TextAreaRequired(FormName,'phone_1_area'))
	{
		alert("Please enter your daytime phone number area code. The cursor will move to the proper place on the form to enter this when you click OK");
		eval("document."+FormName+".phone_1_area"+".focus();");
		return false;
	}
	
	if (!TextAreaRequired(FormName,'phone_1_prefix'))
	{
		alert("Please enter the prefix of your daytime phone number. The cursor will move to the proper place on the form to enter this when you click OK");
		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. The cursor will move to the proper place on the form to enter this when you click OK");
		eval("document."+FormName+".phone_1_last4"+".focus();");
		return false;
	}
}
