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 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+"')";
    }
}

	
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; }
}

var complete = "0";
function ExtendJS( FormName )
{

	if (!SingleSelectRequired(FormName,'industry'))
	{
		alert("Please select what best describes the industry your business is in. The cursor will move to the field when you click ok.");
		eval("document."+FormName+".industry"+".focus();");
		return false;
	}

	if (!TextAreaRequired(FormName,'nature_of_business'))
	{		
		alert("Please enter the nature of the business.");
		eval("document."+FormName+".nature_of_business"+".focus();");
		return false;
	}	
	
	if (!SingleSelectRequired(FormName,'year_started'))
	{		
		alert("Please select the year your business started.");
		eval("document."+FormName+".year_started"+".focus();");
		return false;
	}
	
	if (!SingleSelectRequired(FormName,'legal_entity'))
	{
		alert("Please select the business legal entity.");
		eval("document."+FormName+".legal_entity"+".focus();");
		return false;
	}
	
	if (!SingleSelectRequired(FormName,'annual_revenue'))
	{
		alert("Please select the annual revenue range of the business. It is OK to estimate this amount.");
		eval("document."+FormName+".annual_revenue"+".focus();");
		return false;
	}
	
		if (!SingleSelectRequired(FormName,'gross_payroll'))
	{
		alert("Please select the gross payroll range. It is OK to estimate this amount.");
		eval("document."+FormName+".gross_payroll"+".focus();");
		return false;
	}

    if (!SingleSelectRequired(FormName,'owner_years_of_experience'))
	{		
		alert("Please select the number of years of experience the most experienced owner of your company has in your industry.");
		eval("document."+FormName+".owner_years_of_experience"+".focus();");
		return false;
	}	

	if (!SingleSelectRequired(FormName,'owners_number_of'))
	{		
		alert("Please select the total number of owners or partners in the business.");
		eval("document."+FormName+".owners_number_of"+".focus();");
		return false;
	}

	if (!SingleSelectRequired(FormName,'employees_full_time_number_of'))
	{		
		alert("Please select the total number of full-time employees in the business.");
		eval("document."+FormName+".employees_full_time_number_of"+".focus();");
		return false;
	}

	if (!SingleSelectRequired(FormName,'employees_part_time_number_of'))
	{		
		alert("Please select the total number of part-time employees in the business.");
		eval("document."+FormName+".employees_part_time_number_of"+".focus();");
		return false;
	}

	if (!SingleSelectRequired(FormName,'subcontractors_number_of'))
	{		
		alert("Please select the total number of subcontractors used by the business.");
		eval("document."+FormName+".subcontractors_number_of"+".focus();");
		return false;
	}

	if (!SingleSelectRequired(FormName,'timeframe'))
	{
		alert("Please select when you need coverage to start.");
		eval("document."+FormName+".timeframe"+".focus();");
		return false;
	}

 	if (!TextAreaRequired(FormName,'first_name'))
	{
		onDivClick('contact', true);
		alert("Please enter the first name of the contact person.");
		eval("document."+FormName+".first_name"+".focus();");
		return false;
	}

 	if (!TextAreaRequired(FormName,'last_name'))
	{
		alert("Please enter the last name of the contact person.");
		eval("document."+FormName+".last_name"+".focus();");
		return false;
	}
	
	if (!TextAreaRequired(FormName,'business_name'))
	{
		alert("Please enter the name of the business.");
		eval("document."+FormName+".business_name"+".focus();");
		return false;
	}
	
	if (!TextAreaRequired(FormName,'address'))
	{
		alert("Please enter the address of the business.");
		eval("document."+FormName+".address"+".focus();");
		return false;
	}

	if (!TextAreaRequired(FormName,'city'))
	{
		alert("Please enter the city of the business.");
		eval("document."+FormName+".city"+".focus();");
		return false;
	}

	if (!SingleSelectRequired(FormName,'state'))
	{
		alert("Please select the state your business is located.");
		eval("document."+FormName+".state"+".focus();");
		return false;
	}

	if (!TextAreaRequired(FormName,'zip_code'))
	{
		alert("Please enter the zip code of the business.");
		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;
	}

}

