//validFuncs
/*
CALL WITH 
function Form_Validator(theForm){
  if(!validMixText(theForm.fullapp_100_fName,"First Name")) return (false);
  if(!validNumLenEq(theForm.fullapp_108c_ssn,4,"Social Security Number")) return (false); 
  if(!validSelect(theForm.sel_married,"Marital Status")) return (false);
  ...
  ...
*/
//alert("FOUND SCRIPT");


function rtfValidate(theForm){
	if(theForm.rate_fName.value == "" )
	{
		alert( "Please enter a valid first name!" );
		theForm.rate_fName.focus();
		return false;
	}
	if(theForm.rate_lName.value == "" )
	{
		alert( "Please enter a valid last name!" );
		theForm.rate_fName.focus();
		return false;
	}
	if(! validEmail(theForm.rate_email,"email address") )
		return false;
	if(theForm.rate_phone1.value == "" ||
		theForm.rate_phone1.value.length < 10 )
	{
		alert( "Please enter a valid home phone number, including area code!" );
		theForm.rate_phone1.focus();
		return false;
	}
	return true;
}




function qkaValidate(theForm){
	if(theForm.qApp_fName.value == "" )
	{
		alert( "Please enter a valid first name!" );
		theForm.qApp_fName.focus();
		return false;
	}
	if(theForm.qApp_lName.value == "" )
	{
		alert( "Please enter a valid last name!" );
		theForm.qApp_lName.focus();
		return false;
	}
	if(! validEmail(theForm.qApp_email,"email address") )
		return false;
	if(theForm.qApp_phone.value == "" ||
		theForm.qApp_phone.value.length < 10 )
	{
		alert( "Please enter a valid phone number, including area code!" );
		theForm.qApp_phone.focus();
		return false;
	}
	if(theForm.qApp_lAmt.value == "" )
	{
		alert( "Please enter a valid loan amount!" );
		theForm.qApp_lAmt.focus();
		return false;
	}
	if(theForm.qApp_expense.value == "" )
	{
		alert( "Please enter monthly expenses!" );
		theForm.qApp_expense.focus();
		return false;
	}
	if(theForm.qApp_income.value == "" )
	{
		alert( "Please enter monthly income!" );
		theForm.qApp_income.focus();
		return false;
	}
	return true;
}

function qfmValidate(theForm)
{

  if (theForm.qform_name.value == "")
  {
    alert("Please enter a value for the \"name\" field.");
    theForm.qform_name.focus();
    return (false);
  }

  if (! validEmail(theForm.qform_email, "email address"))
    return (false);
/*
  	if(theForm.qform_phone1.value == "" ||
		theForm.qform_phone1.value.length < 10 )
	{
		alert( "Please enter a valid day phone number, including area code!" );
		theForm.qform_phone1.focus();
		return false;
	}
	if(theForm.qform_phone2.value == "" ||
		theForm.qform_phone2.value.length < 10 )
	{
		alert( "Please enter a valid evening phone number, including area code!" );
		theForm.qform_phone2.focus();
		return false;
	}*/
  return (true);
}

function validActNumLenGt(actNum,aNumLen,outStr){
  if ( (actNum.value == "") || (actNum.value.length < aNumLen) ){
    alert("Please enter a valid " + outStr + ".");
    actNum.focus();
    return (false);
  }	
  if (isNaN(actNum.value)){
  	var tStr = charStrip(actNum.value, ",");
	tStr = charStrip(tStr, ".");
	tStr = charStrip(tStr, "-");
	tStr = charStrip(tStr, " ");
  	if (isNaN(tStr)){
    	alert("Please enter a valid " + outStr + ".");
    	actNum.focus();
    	return (false);
		}
  }
return (true);
}

function checkFieldMaxLen(theField, maxLen){
	if(theField.value.length > maxLen){
    alert("Entry is greater than field's maximum length of " + maxLen + ".\nPlease remove " + (theField.value.length - maxLen) + " characters.");
    theField.focus();
    return (false);
	}
return (true);
}
function validMMDDYYYY(month,day,year,outStr){
  if ( (day.value == "") || (month.value == "") || (year.value == "") ){
    alert("Please enter a valid " + outStr + ". Format: MM/DD/YYYY");
    day.focus();
    return (false);
  }
  else if ( isNaN(day.value) || isNaN(month.value)  || isNaN(year.value)  ){
    alert("Please enter a valid " + outStr + ". Format: MM/DD/YYYY");
    day.focus();
    return (false);
  }
  else if ( day.value > 31 || month.value > 12 || year.value > 2010 ){
    alert("Please enter a valid " + outStr + ". Format: MM/DD/YYYY");
    day.focus();
    return (false);
  }
  else if ( day.value < 1 || month.value < 1 || year.value < 1900 ){
    alert("Please enter a valid " + outStr + ". Format: MM/DD/YYYY");
    day.focus();
    return (false);
  }
	  
return (true);
}


function charStrip(num,ripChar){
	var bStr = new String(num);
	var sStr, cLoc;
	cLoc=0;
	sStr = new String(bStr);

	//document.write("<br> cLoc:" + cLoc);
	while(cLoc > -1){
		cLoc = sStr.indexOf(ripChar , cLoc);
		sStr = (sStr.substring(0, cLoc)) + (sStr.substring((cLoc+1), sStr.length));
		//document.write("<br> LLsStr:" + sStr);
		//document.write("<br> LLcLoc:" + cLoc);
	}
return sStr;
}

function validRadio(theRadGrp,outStr){
	for (var i=0; theRadGrp[i]; i++) {
		if (theRadGrp[i].checked) {
			return (true); 
		}
	}
    	alert("Please select a value for the " +  outStr + " field.");
    	//theRadGrp.focus();
	return (false);
}

function validSelect2(nullChar,theSel,outStr){
	if (theSel.value == nullChar){
    	alert("Please select a value for the " +  outStr + " field.");
    	theSel.focus();
    return (false);
  	}
return (true);
}
function validSelect(theSel,outStr){
	if (theSel.value == "" || theSel.value =="Select"){
    	alert("Please select a value for the " +  outStr + " field.");
    	theSel.focus();
    return (false);
  	}
return (true);
}

function validMixText(theText,outStr){
  if (theText.value == "")
  {
    alert("Please enter a value for the " + outStr + " field.");
    theText.focus();
    return (false);
  }
return (true);
}

function validChkBox(chkBox,outStr){
  if (!chkBox.checked)
  {
    alert("You must check the " + outStr + " field to continue");
    chkBox.focus();
    return (false);
  }
return (true);
}



function validNumLenEq(theNum,numLen,outStr){
//alert("valid" + theNum.value);
  if ( (theNum.value == "") || (isNaN(theNum.value)) || (theNum.value.length != numLen) ){
    alert("Please enter a valid " + outStr + ".");
    theNum.focus();
    return (false);
  }	
return (true);
}

function validNumLenGt(theNum,numLen,outStr){
  if ( theNum.value == "" || isNaN(theNum.value) || theNum.value.length < numLen ){
    alert("Please enter a valid " + outStr + ".");
    theNum.focus();
    return (false);
  }	
return (true);
}

function validMonLenGt(theMon,monLen,outStr){
  if ( (theMon.value == "") || (theMon.value.length < monLen) ){
    alert("Please enter a valid " + outStr + ".");
    theMon.focus();
    return (false);
  }	
  if (isNaN(theMon.value)){
  	var tStr = charStrip(theMon.value, ",");
  	if (isNaN(tStr)){
    	alert("Please enter a valid " + outStr + ".");
    	theMon.focus();
    	return (false);
		}
  }
return (true);
}

function validMonOrNull(theMon,outStr){
  if ( (theMon.value != "") && isNaN(theMon.value)){
  	var tStr = charStrip(theMon.value, ",");
  	if (isNaN(tStr)){
    	alert("Please enter a valid " + outStr + ".");
    	theMon.focus();
    	return (false);
		}
  }
return (true);
}

function validEmail(theEmlAdr,outStr){
  if (theEmlAdr.value == "")
  {
    alert("Please enter a valid " + outStr + ".");
    theEmlAdr.focus();
    return (false);
  }
  else
  { //test for @ char...
  
  	var tStr = theEmlAdr.value;
  	var atChar = tStr.indexOf("@");
	var ptChar = -432;

	if(atChar <= 0){
    	alert("Please enter a valid " + outStr + ".");
   		theEmlAdr.focus();
    	return (false);
		}

	else{ //test for . char...
		tStr=tStr.substring(atChar,tStr.length);
		ptChar = tStr.indexOf(".");
		if(ptChar <= 1){
    	alert("Please enter a valid " + outStr + ".");
 			theEmlAdr.focus();
    		return (false);
			}
		}
  }
return (true);
}

