<!--

function continueForm(formname)
{
	if (Validator(formname))
	{
		formname.submit();
	}
}

function Validator(theForm)
{
	var missing_fields = new Array();
	var i    = 0;
	var x    = "";
	var y    = "";
	var Fr = 0;
	var Pr = 0;
		
	/* check for missing fields */

	if (Trim(theForm.first_name.value) == "")
	{
		missing_fields[i] = "Please enter your contact first name.";
		theForm.first_name.focus();
		i = i + 1;
	}

	if (Trim(theForm.last_name.value) == "")
	{
		missing_fields[i] = "Please enter your contact last name.";
		theForm.last_name.focus();
		i = i + 1;
	}

	if (Trim(theForm.company.value) == "")
	{
	  missing_fields[i] = "Please enter your company name.";
	  theForm.company.focus();
	  i = i + 1;
	}

	if (Trim(theForm.phone.value) == "")
	{
	  missing_fields[i] = "Please enter your main phone number.";
	  theForm.phone.focus();
	  i = i + 1;
	}

	if (Trim(theForm.address.value) == "")
	{
		missing_fields[i] = "Please enter your street address.";
		theForm.address.focus();
		i = i + 1;
	}
	
	if (Trim(theForm.zip.value) == "")
	{
		missing_fields[i] = "Please enter your zip code.";
		i = i + 1;
	}

	if (!isEmailAddr(Trim(theForm.email.value)))
	{
	  missing_fields[i] = "Please enter a valid email address.";
	  theForm.email.focus();
      i = i + 1;
	}
    
	if (theForm.business.selectedIndex == 0)
	{
		missing_fields[i] = "Please choose your business type.";
		i = i + 1;
	}

	if (theForm.los.selectedIndex == 0)
	{
	  missing_fields[i] = "Please tell us how many loan officers are in your office.";
	  theForm.los.focus();
	  i = i + 1;
	}

	if (theForm.states.selectedIndex == 0)
	{
	  missing_fields[i] = "Please tell us how many states you have a lending license in.";
	  theForm.states.focus();
	  i = i + 1;
	}

	if (theForm.leadmgmt.value == 'undefined')
	{
	  missing_fields[i] = "Please tell us if you work with any lead management systems.";
	  theForm.leadmgmt.focus();
	  i = i + 1;
	}
	
 	if (theForm.leadmgmt[0].checked == true){
        for(y=0;y<theForm.leadmgmtcompany.length;y++){
        if(theForm.leadmgmtcompany[y].checked==true)Pr=1
        }
        if(Pr=="0")
        {
          missing_fields[i] = "Please tell us what lead management systems you work with.";
          i = i + 1;
        } 
    }	 

    for(y=0;y<theForm.leadtype.length;y++){
    if(theForm.leadtype[y].checked==true)Fr=1
    }
    if(Fr=="0")
    {
      missing_fields[i] = "Please tell us what type of Internet mortgage leads you are interested in.";
      i = i + 1;
    } 

    for(y=0;y<theForm.credit.length;y++){
    if(theForm.credit[y].checked==true)Fr=1
    }
    if(Fr=="0")
    {
      missing_fields[i] = "Please tell us what credit profiles you are interested in.";
      i = i + 1;
    } 
    
	if (i > 0)
	{
	  for (var i=0; i<missing_fields.length; i++)
		{
	  	var x = x + "\n" + missing_fields[i];
		}
	  alert("The following information is missing:\n" + x );
	  return(false);
	}
	return(true); /* for fast_app_accept */
}

function Trim(TRIM_VALUE){
	if(TRIM_VALUE.length < 1){
		return"";
	}
	
	TRIM_VALUE = RTrim(TRIM_VALUE);
	TRIM_VALUE = LTrim(TRIM_VALUE);
	
	if(TRIM_VALUE==""){
		return "";
	}
	else{
		return TRIM_VALUE;
	}
} //End Function

function RTrim(VALUE){
	var w_space = String.fromCharCode(32);
	var v_length = VALUE.length;
	var strTemp = "";	
	
	if(v_length < 0){
		return"";
	}
	
	var iTemp = v_length -1;

	while(iTemp > -1){
		if(VALUE.charAt(iTemp) == w_space){
		}
		else{
			strTemp = VALUE.substring(0,iTemp +1);
			break;
		}
	
		iTemp = iTemp-1;
	} //End While
	
	return strTemp;
} //End Function

function LTrim(VALUE){
	var w_space = String.fromCharCode(32);
	var v_length = VALUE.length;
	var strTemp = "";
	
	if(v_length < 1){
		return "";
	}	
	
	var iTemp = 0;

	while(iTemp < v_length){
		if(VALUE.charAt(iTemp) == w_space){
		}
		else{
			strTemp = VALUE.substring(iTemp,v_length);
			break;
		}
		
		iTemp = iTemp + 1;
	} //End While
	
	return strTemp;
} //End Function

function isEmailAddr(s) 
{
	var charBogus = "`~!#$%^&*()+={}[]\\|:;\"'<>,?/ ";
	var allValid = true;
	var atCount = 0;
	var i, j;
	for(i = 0; i < s.length; i++) 
	{
		var c = s.charAt(i);
		for(j = 0; j < charBogus.length; j++)
		{
			if(c == charBogus.charAt(j)) 
			{
				allValid = false;
				break;
			}
		}
		if(allValid == false)
			return false;
		if(c == '@')
		{
			atCount += 1;
			for(k=i; k < charBogus.length; k++)
			{
				var nextC = s.charAt(k+1);
				if (nextC == '.')
				{
					atCount += 1;
					break;
				}
			}
		}
	}
	return((atCount != 2) ? false : true);
}
//-->