// JavaScript Document 

var flag=1;


function setHdn()
{
	document.getElementById('hdnFinanceType').value='2';
	//document.getElementById('type1').className = "bkggradienthighlight"
	//document.getElementById("comments").style.top="830px";	
	///document.getElementById("layContinue").style.top="960px";		
}



 var val1;
function MM_showHideLayers() { //v6.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  val1=args[0];

 //op41=document.getElementById("op4").style.top
  if(val1==1)
  {	
	document.getElementById("op4").style.display = ''
	//document.getElementById("op4").style.top="799px";
	document.getElementById("txtLoanAmount2").style.backgroundColor = "#F6F6F6" ;
	document.getElementById('hdnFinanceType').value="1";
	document.getElementById('txtLoanAmount2').disabled = false
	//document.getElementById('type1').className = "bkggradienthighlight"
	//document.getElementById('type2').className = "bkggradientstrip"	
	//document.getElementById('type3').className = "bkggradientstrip"	
	//document.getElementById("comments").style.top="830px";	
	//document.getElementById("layContinue").style.top="960px";		
	if(document.getElementById('txtPurchasePrice2').value != "" || document.getElementById('txtDownPayment2').value != "" )
		document.getElementById('txtLoanAmount2').value = store;
	flag=1;
  }
  if(val1==2)
  {
	activelayer = 2;
	flag=2;	
	document.getElementById("op4").style.display = ''
	//document.getElementById("op4").style.top="753px";
	document.getElementById("txtLoanAmount2").style.backgroundColor = "#F6F6F6" ;
	document.getElementById('hdnFinanceType').value="2";
	document.getElementById('txtLoanAmount2').disabled = false	
//	storerefinance = document.getElementById('txtLoanAmount2').value; 
	document.getElementById('txtLoanAmount2').value = ""	
	//document.getElementById('type3').className = "bkggradientstrip"	
	//document.getElementById('type1').className = "bkggradientstrip"	
	//document.getElementById('type2').className = "bkggradienthighlight"	
	//document.getElementById("comments").style.top="830px";	
	//document.getElementById("layContinue").style.top="960px";		
  }
  if(val1==3)
  {		
	flag=3;
	document.getElementById("op4").style.display = 'none'
	document.getElementById("txtLoanAmount2").style.backgroundColor = "#F6F6F6" ;
	document.getElementById('hdnFinanceType').value="3";
	document.getElementById('txtLoanAmount2').disabled = false	
	document.getElementById('txtLoanAmount2').value = ""	
	//document.getElementById('type3').className = "bkggradienthighlight"	
	//document.getElementById('type2').className = "bkggradientstrip"	
	//document.getElementById('type1').className = "bkggradientstrip"	
	//document.getElementById("comments").style.top="919px";	
	//document.getElementById("layContinue").style.top="1040px";	
  }
  for (i=1; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'':(v=='hide')?'none':v; }
    obj.display=v; }
}

function anyExistingMort()
{
 
	cmbEM=document.getElementById('cmbAnyExistingMort2').value	
	 if(cmbEM=='[Select One]') //no mort existing
	{
		document.getElementById("op2first").style.display='none'
		document.getElementById("op2second").style.display='none'		
		//document.getElementById("op4").style.top="753px";
	}
	if(cmbEM==1) //no mort existing
	{
		document.getElementById("op2first").style.display='none'
		document.getElementById("op2second").style.display='none'		
		//document.getElementById("op4").style.top="753px";
	}
	if(cmbEM==2)
	{
		document.getElementById("op2first").style.display=''
		document.getElementById("op2second").style.display='none'
		//document.getElementById("op2first").style.top="752px";
		//document.getElementById("op2second").style.display=''			
		//document.getElementById("op2second").style.top="782px";
		//document.getElementById("op4").style.top="811px";
	}
		if(cmbEM==3)
	{
		document.getElementById("op2first").style.display='none'
		document.getElementById("op2second").style.display=''
		//document.getElementById("op2second").style.top="755px";
		//document.getElementById("op4").style.top="782px";
	}
	if(cmbEM==4)
	{
		document.getElementById("op2first").style.display=''
		document.getElementById("op2second").style.display=''		
		//document.getElementById("op4").style.top="782px";
	}


	
}
function checkempty(strvalue)
{
	var objControl ;
	
	objControl=document.getElementById(strvalue).id
	//alert("I Am ahere" + objControl)
	 
		if(document.getElementById(objControl).value=="" || document.getElementById(objControl).value=='[Select One]')
		{
			return true;
		}
	 
	
	
}
var strEmptyValues = new Array();
var strEmptytext = new Array();
function MM_validateLayers_quickApp2() 
{ 

	var validationsArray = new Array();
	//alert("valid")
	arrayindex=0;
	index=0
	textindex=0

	//
		validationsArray[arrayindex++] = new validation("txtEmailaddrss2" ,"validateEmail","","Loan Amount field is empty");

	validationsArray[arrayindex++] = new validation("txtFirstName2" ,"validateNotEmpty","txtAAF","Association Fees is required");
	if(checkempty('txtFirstName2') == true ){
		strEmptyValues[index++]='txtFirstName2';
		strEmptytext[textindex++]='FirstName';}
	validationsArray[arrayindex++] = new validation("txtLastName2","validateNotEmpty","txtAAF","Association Fees is required");
	if(checkempty('txtLastName2') == true ){
		strEmptyValues[index++]='txtLastName2';
		strEmptytext[textindex++]='LastName';
		}
		
	//validationsArray[arrayindex++] = new validation("txtEmailAdd" ,"validateEmail","","Valid Email Address is required");
	validationsArray[arrayindex++] = new validation("cmbSelfRated2" ,"validateCombo","","Loan Amount field is empty");
	if(checkempty('cmbSelfRated2') == true ){
		strEmptyValues[index++]='cmbSelfRated2';
		strEmptytext[textindex++]='Self-Rated Credit';}
	validationsArray[arrayindex++] = new validation("txtHomePhone2","validateUSPhone","txtLN","Last Name is required");	
	if(checkempty('txtHomePhone2') == true ){
		strEmptyValues[index++]='txtHomePhone2';
		strEmptytext[textindex++]='Home Phone';}
	validationsArray[arrayindex++] = new validation("cmbPrefLoanIntrest2" ,"validateCombo","","Loan Amount field is empty");
	if(checkempty('cmbPrefLoanIntrest2') == true ){
		strEmptyValues[index++]='cmbPrefLoanIntrest2';
		strEmptytext[textindex++]='Preferred Loan Type ';}
	validationsArray[arrayindex++] = new validation("cmbPrefLoanTerm2" ,"validateCombo","","Please select a Loan Type");
	if(checkempty('cmbPrefLoanTerm2') == true ){
		strEmptyValues[index++]='cmbPrefLoanTerm2';
		strEmptytext[textindex++]='Preferred Loan Term';}
	validationsArray[arrayindex++] = new validation("cmbState2" ,"validateCombo","","Loan Amount field is empty");
	if(checkempty('cmbState2') == true ){
		strEmptyValues[index++]='cmbState2';
		strEmptytext[textindex++]='State'; }
/*	validationsArray[arrayindex++] = new validation("txtStreet","validateNotEmpty","txtLN","Last Name is required");	
	if(checkempty('txtStreet') == true ){
		strEmptyValues[index++]='txtStreet';
		strEmptytext[textindex++]='Street';}*/
	validationsArray[arrayindex++] = new validation("txtCity2" ,"validateNotEmpty","","Loan Amount field is empty");
	if(checkempty('txtCity2') == true ){
		strEmptyValues[index++]='txtCity2';
		strEmptytext[textindex++]='City'; }
	validationsArray[arrayindex++] = new validation("txtZip2" ,"validateNotEmpty","","Please select a Loan Type");
	if(checkempty('txtZip2') == true ){
		strEmptyValues[index++]='txtZip2';
		strEmptytext[textindex++]='Zip';}
		flag=2;
			
	if(flag==1)
	{
		
		validationsArray[arrayindex++] = new validation("cmbPropertyFound2" ,"validateCombo","cmbPrT","Property type is required");
		if(checkempty('cmbPropertyFound2') == true ){
		strEmptyValues[index++]='cmbPropertyFound2';
		strEmptytext[textindex++]='Have You Found a Home?';}
		validationsArray[arrayindex++] = new validation("txtPurchasePrice2" ,"validateNotEmpty","txtPP1","Purchase Price is required");
		if(checkempty('txtPurchasePrice2') == true ){
		strEmptyValues[index++]='txtPurchasePrice2';
		strEmptytext[textindex++]='Purchase Price (Est.) ';
		}		
		validationsArray[arrayindex++] = new validation("txtDownPayment2" ,"validateNotEmpty","txtDP1","Down payment is required");
		if(checkempty('txtDownPayment2') == true ){
		strEmptyValues[index++]='txtDownPayment2';
		strEmptytext[textindex++]='Down Payment';
		}				
	}
	//alert(flag+cmbEM1);
	if(flag==2)
	{
		//alert(flag)txtLoanAmount2
		cmbEM1=document.getElementById('cmbAnyExistingMort2').value
		validationsArray[arrayindex++] = new validation("txtLoanAmount2" ,"validateNotEmpty","txtDPu","");		
		if(checkempty('txtLoanAmount2') == true ){
		strEmptyValues[index++]='txtLoanAmount2';
		strEmptytext[textindex++]='Requested Loan Amount';}						
		validationsArray[arrayindex++] = new validation("txtCurrentValue2" ,"validateNotEmpty","txtDPu","Please select Purchase date");
		if(checkempty('txtCurrentValue2') == true ){
		strEmptyValues[index++]='txtCurrentValue2';
		strEmptytext[textindex++]='Estimated Property ';}								
		validationsArray[arrayindex++] = new validation("cmbAnyExistingMort2" ,"validateCombo","txtPP1","Purchase Price is required");
		if(checkempty('cmbAnyExistingMort2') == true ){
		strEmptyValues[index++]='cmbAnyExistingMort2';
		strEmptytext[textindex++]='Any Existing Mortgages?';
		}										
		
		if(parseInt(cmbEM1)==2)
		{
			validationsArray[arrayindex++] = new validation("txtFirstMortgageBal2" ,"validateNotEmpty","txtDPu","Please select Purchase date");
		    if(checkempty('txtFirstMortgageBal2') == true ){
			strEmptyValues[index++]='txtFirstMortgageBal2';
			strEmptytext[textindex++]='1st Mortgage Balance';
			}										
		}
		if(parseInt(cmbEM1)==3)
		{
			validationsArray[arrayindex++] = new validation("txtSecondMortgageBal2" ,"validateNotEmpty","txtDPu","Please select Purchase date");
			if(checkempty('txtSecondMortgageBal2') == true ){
				strEmptyValues[index++]='txtSecondMortgageBal2';
				strEmptytext[textindex++]='2nd (HELOC) Balance';
			}										
		}
		if(parseInt(cmbEM1)==4)
		{
			validationsArray[arrayindex++] = new validation("txtFirstMortgageBal2" ,"validateNotEmpty","txtDPu","Please select Purchase date");
			if(checkempty('txtFirstMortgageBal2') == true ){
				strEmptyValues[index++]='txtFirstMortgageBal2';
			    strEmptytext[textindex++]='1st Mortgage Balance';
			}				
			if(checkempty('txtSecondMortgageBal2') == true ){
				strEmptyValues[index++]='txtSecondMortgageBal2';
				strEmptytext[textindex++]='2nd (HELOC) Balance';
			}							
			validationsArray[arrayindex++] = new validation("txtSecondMortgageBal2" ,"validateNotEmpty","txtDPu","Please select Purchase date");
			
		}
		validationsArray[arrayindex++] = new validation("txtLoanAmount2" ,"validateNotEmpty","cmbPrT","Property type is required");
		if(checkempty('txtLoanAmount2') == true ){
			strEmptyValues[index++]='txtLoanAmount2';
			strEmptytext[textindex++]='Requested Loan Amount';
		}		
		
	}
	if(flag==3)
	{
		//validationsArray[arrayindex++] = new validation("txtLoanAmount2" ,"validateNotEmpty","txtDPu","");				
		validationsArray[arrayindex++] = new validation("cmbConstLoanRequest2" ,"validateCombo","cmbPrU","Property Use   is required");		
		if(checkempty('cmbConstLoanRequest2') == true ){
			strEmptyValues[index++]='cmbConstLoanRequest2';
			strEmptytext[textindex++]='Construction Loan Request';}		
//		validationsArray[arrayindex++] = new validation("txtConstPeriodBegins" ,"validateUSDate","txtDPu","Please select Purchase date");
//		validationsArray[arrayindex++] = new validation("txtConstPeriodEnds" ,"validateUSDate","txtDPu","Please select Purchase date");
		
		validationsArray[arrayindex++] = new validation("txtConstructionDownPayment2" ,"validateNotEmpty","","Down Payment is required");		
		if(checkempty('txtConstructionDownPayment2') == true ){
			strEmptyValues[index++]='txtConstructionDownPayment2';
			strEmptytext[textindex++]='Down Payment';
		}		
		validationsArray[arrayindex++] = new validation("txtConstructionFutureValue2" ,"validateNotEmpty","","Future Value is required");		
		if(checkempty('txtConstructionFutureValue2') == true ){
			strEmptyValues[index++]='txtConstructionFutureValue2';
			strEmptytext[textindex++]='Future Value of Home';
		}				
		
		validationsArray[arrayindex++] = new validation("txtTotalConstructionCost2" ,"validateNotEmpty","","Construction Cost is required");	
		if(checkempty('txtTotalConstructionCost2') == true ){
			strEmptyValues[index++]='txtTotalConstructionCost2';
			strEmptytext[textindex++]='Total Construction Cost';
			}						
		validationsArray[arrayindex++] = new validation("txtConstructionLoanAmount2" ,"validateNotEmpty","","Loan Amount is required");
		if(checkempty('txtConstructionLoanAmount2') == true ){
			strEmptyValues[index++]='txtConstructionLoanAmount2';
			strEmptytext[textindex++]='Requested Loan Amount';
		}								
	}

//	validationsArray[arrayindex++] = new validation("txtLoanAmount2" ,"validateCombo","cmbPrT","Property type is required");

	if (validateControls (validationsArray) == true )
	
	return  false ;
	else
	return true ;
}

function postdatatoserver_Quickapp() 
{
	var theform;
	if (window.navigator.appName.toLowerCase().indexOf("netscape") > -1) 
	{
		theform = document.forms["form1"];
	}
	else {
		theform = document.forms[0]
	}
	theform.__EVENTTARGET.value = 'btnNextQuick'.split("$").join(":");
	theform.__EVENTARGUMENT.value = "";
	theform.submit();
}
ret=false;
function close()
{
	for(i=0;i<=strEmptyValues.length-1;i++)
		{ 
		if(i==0) document.getElementById(strEmptyValues[i]).focus();
		}
	document.getElementById('confirm').style.visibility='hidden'
}
function submitData_quickApp2()
{
		
	ret=MM_validateLayers_quickApp2();
	
/*	if(ret == false)
	{   var opt = new Option("","");
		//document.getElementById('confirm').style.visibility='visible'
		for(i=0;i<=strEmptyValues.length-1;i++)
		{ if(i==0) document.getElementById(strEmptyValues[i]).focus();
		   opt = new Option(strEmptytext[i],strEmptytext[i]);
		   document.getElementById('lstMultipleSites').options[i] = opt;
		 // document.getElementById(lstMultipleSites).options[i].text=strEmptyValues[i]
		 // alert(strEmptyValues[i])
		}
		window.location.href="#top"
	}*/
	if(ret == true)
	{	
		document.frmQyickAppConsolidate.action="QuickAppConsolidatesubmit.php";
		document.frmQyickAppConsolidate.submit();
	}
}

/*function myformatCurrency1(num)
{

	var buttonselect = document.forms[0]
	obj1=document.getElementById('txtPurchasePrice2');
	obj2=document.getElementById('txtDownPayment2');
	obj3=document.getElementById('txtLoanAmount2');
	obj4=document.getElementById('cmbPrefLoanTerm2');
	
	if (buttonselect.rbtPaymentAs[0].checked )
	{
		//alert("1 radio checked")
		return formatCurrency(num);
	}
	if (document.forms[0].rbtPaymentAs[1].checked )
	{
		if(obj1.value == '' )
		{
			
			return("Purchase Price Unspecified");
		}		
		else if(obj4.options.selectedIndex == 0 )
		{
			 
			return("Select a Loan Term")

		}		
		else
		{
			return(obj4.value + "%" )
		}
	}
	
	
}*/

function PercentChange()
{

	obj1=document.getElementById('txtPurchasePrice2');
	obj2=document.getElementById('txtDownPayment2');
	obj3=document.getElementById('txtLoanAmount2');
	obj4=document.getElementById('cmbPrefLoanTerm2');
	if(obj1.value == '' )
	{		
//		obj2.value = "Enter Purchase Price";
		obj2.value  = ""
	}		
	/*else if(obj4.options.selectedIndex == 0 )
	{		 
//		obj2.value = "Select a Loan Term" ;
		obj2.value  = ""		
	}		*/
	else
	{				
	
		var intValue = document.getElementById('txtDownPayment2').value
		var temp = intValue.substring(intValue.length - 1,intValue.length)
		var temp2 = intValue.substring(0,1)
		if(temp == "")
		{
				obj2.value = 0 + "%"
				obj3.value  =  obj1.value.substring(1,(obj1.value).length)	
				obj3.value  = formatCurrency(obj3.value)
		}
		else
		{
			if(temp != "%") 
			{
				t1 = obj1.value.substring(1,(obj1.value).length)	
		
				t2 = obj2.value.substring(1,(obj2.value).length)	
				str1 = removeCommas(t1)
				str2 = removeCommas(t2)	
		
				if(t1 == "0.00" )
				{
					obj2.value = 0 + "%"		
				}
				else
				{
					obj2.value = 100 *  parseFloat(str2) 
					obj2.value = parseFloat(obj2.value) / parseFloat(str1)	
					obj2.value = obj2.value  + "%"		
					store = obj3.value		
				}
		
				}		
			}	
			
				
			
	}
	Dissolver();
}

function PercentChangeOld()
{
	obj1=document.getElementById('txtPurchasePrice2');
	obj2=document.getElementById('txtDownPayment2');
	obj3=document.getElementById('txtLoanAmount2');
	//obj4=document.getElementById('cmbPrefLoanTerm2');
	
	
	
	if(obj1.value == '' )
	{		
//		obj2.value = "Enter Purchase Price";
		obj2.value  = ""
	}		
	/*else if(obj4.options.selectedIndex == 0 )
	{		 
//		obj2.value = "Select a Loan Term" ;
		obj2.value  = ""		
	}		*/
	else
	{				
	
		var intValue = document.getElementById('txtDownPayment2').value
		var temp = intValue.substring(intValue.length - 1,intValue.length)
		var temp2 = intValue.substring(0,1)
		if(temp == "")
		{
				obj2.value = 0 + "%"
				obj3.value  =  obj1.value.substring(1,(obj1.value).length)	
				obj3.value  = formatCurrency(obj3.value)
		}
		else
		{
			if(temp != "%") 
			{
				t1 = obj1.value.substring(1,(obj1.value).length)	
		
				t2 = obj2.value.substring(1,(obj2.value).length)	
				str1 = removeCommas(t1)
				str2 = removeCommas(t2)	
		
				if(t1 == "0.00" )
				{
					obj2.value = 0 + "%"		
				}
				else
				{
					obj2.value = 100 *  parseFloat(str2) 
					obj2.value = parseFloat(obj2.value) / parseFloat(str1)	
					obj2.value = obj2.value  + "%"		
					store = obj3.value		
				}
		
				}		
			}	
			
				
			
	}
	Dissolver();
}

function DollarChange()
{
	


	obj1=document.getElementById('txtPurchasePrice2');
	obj2=document.getElementById('txtDownPayment2');
	obj3=document.getElementById('txtLoanAmount2');
	obj4=document.getElementById('cmbPrefLoanTerm2');
	if(obj1.value == '' )
	{		
//		obj2.value = "Enter Purchase Price";
		obj2.value  = ""
	}		
	/*else if(obj4.options.selectedIndex == 0 )
	{		 
//		obj2.value = "Select a Loan Term" ;
		obj2.value  = ""		
	}		*/
	else
	{				
	
 	var intValue = document.getElementById('txtDownPayment2').value
	var temp = intValue.substring(intValue.length - 1,intValue.length)
	var temp2 = intValue.substring(0,1)
	

		if(temp2 !="$" )
 		{
 //-------------------
 
		t1 = obj1.value.substring(1,(obj1.value).length)	
		str1 = removeCommas(t1)
		str2 = obj2.value
		var x = parseFloat(str1) * parseFloat(str2)  * 0.01

		//called when dollar radio is clicked
		//obj2.value = obj4.value + "%" 		***MAYUR COMMENTS	
		obj2.value =  formatCurrency(x)	
		
		t1 = obj1.value.substring(1,(obj1.value).length)	
		str1 = removeCommas(t1)
		t2 = obj2.value.substring(1,(obj2.value).length)	
		str2 =removeCommas(t2)
		//var y = parseFloat(str1) - parseFloat(str2)
		
		
		//obj3.value=  formatCurrency(y)	
		
		//store = obj3.value		
		}



	}	
	Dissolver();
	
}

function DollarChangeOld()
{
	


	obj1=document.getElementById('txtPurchasePrice2');
	obj2=document.getElementById('txtDownPayment2');
	obj3=document.getElementById('txtLoanAmount2');
	obj4=document.getElementById('cmbPrefLoanTerm2');
	if(obj1.value == '' )
	{		
//		obj2.value = "Enter Purchase Price";
		obj2.value  = ""
	}		
	/*else if(obj4.options.selectedIndex == 0 )
	{		 
//		obj2.value = "Select a Loan Term" ;
		obj2.value  = ""		
	}		*/
	else
	{				
	
 	var intValue = document.getElementById('txtDownPayment2').value
	var temp = intValue.substring(intValue.length - 1,intValue.length)
	var temp2 = intValue.substring(0,1)
	

		if(temp2 !="$" )
 		{
 //-------------------
 
		t1 = obj1.value.substring(1,(obj1.value).length)	
		str1 = removeCommas(t1)
		str2 = obj2.value
		var x = parseFloat(str1) * parseFloat(str2)  * 0.01

		//called when dollar radio is clicked
		//obj2.value = obj4.value + "%" 		***MAYUR COMMENTS	
		obj2.value =  formatCurrency(x)	
		
		t1 = obj1.value.substring(1,(obj1.value).length)	
		str1 = removeCommas(t1)
		t2 = obj2.value.substring(1,(obj2.value).length)	
		str2 =removeCommas(t2)
		var y = parseFloat(str1) - parseFloat(str2)
		
		
		obj3.value=  formatCurrency(y)	
		
		store = obj3.value		
		}


	}	
	Dissolver();
	
}




function LoanTermChange()
{
/*	if (document.forms[0].rbtPaymentAs[1].checked )
	{
		PercentChange()
		calculateAmt();
	}
	if (document.forms[0].rbtPaymentAs[0].checked && document.getElementById('txtDownPayment2').value != '')
	{
	 	document.getElementById('txtDownPayment2').value = '' ;
	}
*/	
}


var store 
//var obj1 = 0, obj2 = 0

 
function setText(val)
{
	switch (parseInt(val)){
		case 1:
			document.getElementById('tdFinanceType').innerText="Purchase a New Home";			 
		break;
		case 2:
			document.getElementById('tdFinanceType').innerText="Refinance Your Home";
		break;
		case 3:
			document.getElementById('tdFinanceType').innerText="New Home Construction";			 
		break;
	}
	
}


function ChangeToDollar(num)
{
	 // alert("lost focus change to dollar")
	if (document.getElementById('rbtDollars').checked == true)
	{		
		return myformatCurrency(num)
	}
	else
	{		

		return (num) ;
	}
}
function ChangeToDollar1()
{
	document.getElementById('txtDownPayment2').value =   "$0.00"
	calculateAmt()
}


var store 
//var obj1 = 0, obj2 = 0
function calculateAmt()
  {	

  	CheckForPercentage()
  	var buttonselect = document.forms[0]
  	obj1=document.getElementById('txtPurchasePrice2');
	obj2=document.getElementById('txtDownPayment2');
	obj3=document.getElementById('txtLoanAmount2');
	obj4=document.getElementById('cmbPrefLoanTerm2');
	
	t1 = obj1.value.substring(1,(obj1.value).length)	
	str1 = removeCommas(t1) 	
	if (buttonselect.rbtPaymentAs[0].checked )
	{					
		t2 = obj2.value.substring(1,(obj2.value).length)		
		str2 = removeCommas(t2) 
		if( parseInt(str1) < parseInt(str2) ) 
		{
			
			// "Error: Down Payment > Purchase Price"
			obj3.value = "$0.00"
			obj2.value = formatCurrency(parseInt(str1))			
		}
		else
		{	
			if(obj1 != '' && obj2 != '')
			{
			  var x = parseInt(str1) - parseInt(str2)
			  //alert("difference is" + obj3.value )
			  obj3.value =  formatCurrency(x)
			  store = obj3.value
			}
		}
	}
	//if ((buttonselect.rbtPaymentAs[1].checked) && (obj4.options.selectedIndex != 0) && (obj1.value != ''))
	if ((buttonselect.rbtPaymentAs[1].checked) && (obj1.value != ''))
	{		
		 var x = parseInt(str1) - (parseInt(str1) * parseInt(obj2.value) * 0.01)
		 obj3.value =  formatCurrency(x)
		 store = obj3.value			
	}
	Dissolver();		
 }
 
 
 function CheckForPercentage()
{
	
	var intValue = document.getElementById('txtDownPayment2').value
	var temp = intValue.substring(intValue.length - 1,intValue.length)
	var temp2 = intValue.substring(0,1)
	
	if(temp != "")
	{
		if((temp != "%") && (temp2 !="$" ))
		{
			document.getElementById('txtDownPayment2').value = document.getElementById('txtDownPayment2').value + "%"
		}
	}
}



function myformatCurrency(num)
{

	var buttonselect = document.forms[0]
	obj1=document.getElementById('txtPurchasePrice2');
	obj2=document.getElementById('txtDownPayment2');
	obj3=document.getElementById('txtLoanAmount2');
	obj4=document.getElementById('cmbPrefLoanTerm2');
	
	if (buttonselect.rbtPaymentAs[0].checked )
	{
		//alert("1 radio checked")
		return formatCurrency(num);
	}
	if (document.forms[0].rbtPaymentAs[1].checked )
	{
		if(obj1.value == '' )
		{
			
//			return("Purchase Price Unspecified");
			return("");
		}		
/*		else if(obj4.options.selectedIndex == 0 )
		{
			 
//			return("Select a Loan Term")
			return("");			
		}
		else
		{
			return(obj4.value + "%" )
		}*/
	}	
}

function LoanAmt()
{
	
	obj1=document.getElementById('txtPurchasePrice2');
	obj2=document.getElementById('txtDownPayment2');
	obj3=document.getElementById('txtLoanAmount2');
	obj4=document.getElementById('cmbPrefLoanTerm2');
	cmbEM=document.getElementById('cmbAnyExistingMort2').value;	
	objmort1=document.getElementById("txtFirstMortgageBal2");
	objmort2=document.getElementById("txtSecondMortgageBal2");
	///////////////////////////
	var mort1=0;
	var mort2=0;
	if(cmbEM==1)
	{
		 
		mort1=0;
		mort2=0;
	}
	if(cmbEM==2)
	{
			 var motr111=objmort1.value.substring(1,(objmort1.value).length)	
			  var mort11 = removeCommas(motr111)		 		
		mort1=mort11;
		mort2=0;
	}
	if(cmbEM==3)
	{
 
		mort1=0;
		var motr111=objmort2.value.substring(1,(objmort2.value).length)	
		var mort11 = removeCommas(motr111)		
		mort2=mort11;
	}
	if(cmbEM==4)
	{
		var motr111=objmort1.value.substring(1,(objmort1.value).length)	
		var mort11 = removeCommas(motr111)		
		mort1=mort11;
		motr111=objmort2.value.substring(1,(objmort2.value).length)	
		mort11 = removeCommas(motr111)	
		mort2=mort11
	}
	
	var tempObj3=obj3.value;
	var motr111=obj3.value.substring(1,(obj3.value).length)	
	var mort11 = removeCommas(motr111)	
	var totalMort=parseFloat(mort1) + parseFloat(mort2) +parseFloat(mort11);

	document.getElementById('txtTotalConsolidate2').value= formatCurrency(totalMort)
//////////////////////////////
		/*var intValue = document.getElementById('txtDownPayment2').value
		var temp = intValue.substring(intValue.length - 1,intValue.length)
		var temp2 = intValue.substring(0,1)

		m1 = obj1.value.substring(1,(obj1.value).length)	
		mystr = removeCommas(m1) //purchase price

		/*if(parseInt(mystr) < parseInt(t3))
		{
			t3 = parseInt(mystr)
		}

		if(temp == "%") 
		{
					
		t1 = obj1.value.substring(1,(obj1.value).length)	
		
		var intValue = document.getElementById('txtLoanAmount2').value
		var mytemp = intValue.substring(0,1)
		if (mytemp == "$")
		{
		t3 = obj3.value.substring(1,(obj3.value).length)	
		}
		else
		{
		t3 = obj3.value
		}
		
		//write here
		
		

		if(parseInt(mystr) < t3)
		{
			t3 = mystr
			obj3.value = formatCurrency(t3)
		}

		//----------
		
		str1 = removeCommas(t1)
		str3 = removeCommas(t3)	

		obj2.value =  parseFloat(str1) - parseFloat(str3) 
		obj2.value = obj2.value * 100

		obj2.value = parseFloat(obj2.value) / parseFloat(str1)	
		
		obj2.value = obj2.value  + "%"
		obj3.value = formatCurrency(obj3.value)

		}
		
		if(temp2 == "$") 
		{
			
		t1 = obj1.value.substring(1,(obj1.value).length)	
		
		var intValue = document.getElementById('txtLoanAmount2').value
		var mytemp = intValue.substring(0,1)
		
		if (mytemp == "$")
		{
		t3 = obj3.value.substring(1,(obj3.value).length)	
		}
		else
		{
		t3 = obj3.value
		}
		 //write here
		//----------
		
		if(parseInt(mystr) < t3)
		{
			t3 = mystr
			obj3.value = formatCurrency(t3)
		}
		
		str1 = removeCommas(t1)
		str3 = removeCommas(t3)				
		obj2.value = parseFloat(str1)  -  parseFloat(str3)
		obj2.value = formatCurrency(obj2.value)
		
		
		}	
		
		obj3.value = formatCurrency(obj3.value)	
		Dissolver();*/
		
}


function Dissolver() 
{
	var buttonselect = document.forms[0]
  	obj1=document.getElementById('txtPurchasePrice2');
	obj2=document.getElementById('txtDownPayment2');
	obj3=document.getElementById('txtLoanAmount2');

	
if (obj1.value.indexOf("NaN") != -1  || obj1.value.indexOf("Infinity") != -1  ||  obj1.value.indexOf("-") != -1  )
	{
		obj1.value = "$0.00"
	}
	
if (obj2.value.indexOf("NaN") != -1  || obj2.value.indexOf("Infinity") != -1  ||  obj2.value.indexOf("-") != -1  )
	{
	if(buttonselect.rbtPaymentAs[0].checked) //$$$
		obj2.value = "$0.00"
	else
		obj2.value = "0%"			
	}
	
if (obj3.value.indexOf("NaN") != -1  || obj3.value.indexOf("Infinity") != -1  ||  obj3.value.indexOf("-") != -1  )
	{
		obj3.value = "$0.00"
	}	
	

	
}



