/**********************************************************************
 chkMandatory: check mandatory fields on the form objForm
 parameters: objForm - form reference

 pre-requisites: aMandatory - array of fields for which mandatory evaluation
				should be done
		aMandatory should be defined on each HTML page
 format of aMandatory:
    aMandatory[<field-name-string>] = new Array(<message-string>, <input-type-string>, <focus-on-string>);

 <message-string>: message to be displayed on mandatory check failure
		(NOTE: system dispalyes "<message-string> is mandatory")
 <input-type-string>: "TEXT", "RADIO"
 <focus-on-string>: name of the field where focus should be placed on mandatory check failure.
		    if this is "" then focus is place on <field-name-string>
**********************************************************************/
var aMandatory = new Array();
function chkMandatory(objForm)
{
	for (var iLoop in aMandatory)
	{
		var strVal;
		strVal = "";
		if (aMandatory[iLoop][1] == "Text")
			strVal = eval("objForm." + iLoop + ".value");
		else if (aMandatory[iLoop][1] == "Radio")
		{
			var oEle = eval("objForm." + iLoop);
			var iLen = oEle.length;
			for (var iEle = 0; iEle < iLen; iEle++)
				if (oEle[iEle].checked)
				{
					strVal = oEle[iEle].value;
					break;
				}
		}
		else if (aMandatory[iLoop][1] == "Select")
		{
			var iIdx = eval("objForm." + iLoop + ".selectedIndex");
			if (iIdx > -1)
				strVal = eval("objForm." + iLoop + "[" + iIdx + "].value");
			else
				strVal = "";
		}
		if (strVal == "")
		{
			alert("Please enter a value for " + aMandatory[iLoop][0] + ".");
			if (aMandatory[iLoop][2] != "")
				eval("objForm." + aMandatory[iLoop][2] + ".focus()");
			else
			{
				if (aMandatory[iLoop][1] == "Radio")
					eval("objForm." + iLoop + "[0].focus()");
				else
					eval("objForm." + iLoop + ".focus()");
			}
			return false;
		}
	}
	return true;
}

aMandatory["USER_STATE"] = new Array("State", "Select", "");
aMandatory["USER_LOAN_PROGRAM"] = new Array("Loan Program", "Select", ""); 
aMandatory["USER_LOAN_AMOUNT"] = new Array("Amount", "Text", "");

function chkForm(objForm)
	{
		var bRetVal = true;

		bRetVal = chkMandatory(objForm);
		if (!bRetVal)
			return bRetVal;

		return true;
	}

function doSubmit(Fm){
	result = chkForm(Fm);
	if(result){
		url = Fm.action;
		url = url + "/"+Fm.USER_STATE[Fm.USER_STATE.selectedIndex].value;
		url = url + "/"+ Fm.USER_LOAN_PROGRAM[Fm.USER_LOAN_PROGRAM.selectedIndex].value
		url = url + "/"+ Fm.USER_POINTS.value
		url = url + "/"+ Fm.USER_LOAN_AMOUNT.value
		window.location.href = url + '?src=13';
	}	
}

 function change_amount(lpval)
 {
  var lpval = document.Search.USER_LOAN_PROGRAM[document.Search.USER_LOAN_PROGRAM.selectedIndex].value
  if( lpval.charAt(0) == "J" )
  	{
	var amount = 300000;
	}
  else amount = 150000;
	document.Search.USER_LOAN_AMOUNT.value = amount
  }


function number_validation(val, pos)
 {
   edited_value = "";
   var len=val.length;
   var dot_cntr = 0;
   var field = pos;
   var temp;

 for(i=0;i<len;++i)
 {

  temp=val.substring(i,i+1);

   if( (temp >= "0" && temp <= "9") || val.charAt(i) == ".")
    {
	 if(val.charAt(i) == "." )
	   {
	    ++dot_cntr;
	    if(dot_cntr >= 2)
	       {
		 alert("There are two or more decimals in the amount field. The amount field will be changed to default values.");
         	     var lpval = document.Search.USER_LOAN_PROGRAM[document.Search.USER_LOAN_PROGRAM.selectedIndex].value
  				 if( lpval.charAt(0) == "J" )
  						{
						amount = 300000;
						}
  						else
						{
						amount = 150000;
						}
						edited_value = amount;
		 break ;
	       }
        }
	  edited_value = edited_value + val.substring(i,i+1);
    }

  }
 return edited_value;
 }