// JavaScript Document

/***************************************************************************************************
* Author: Sang Huynh                                                                               *
* These programs belong to First Digital Pages                                                     *
***************************************************************************************************/
if(navigator.appName == "Microsoft Internet Explorer")
{   
	document.write('<link rel="stylesheet" type="text/css" href="css/winhlicorp_text.css" media="all" >')
	document.write('<link rel="stylesheet" type="text/css" href="css/winhlicorp_design.css" media="all" >')
	m=90
	
	
}
else
{
	document.write('<link rel="stylesheet" type="text/css" href="css/winhlicorp_text.css" media="all" >')
	document.write('<link rel="stylesheet" type="text/css" href="css/notwinhlicorp_design.css" media="all" >')
	m=1200
}
escrowFlag = false;
function LoadEvents(fn)
{
	if(typeof window.addEventListener != 'undefined')
		window.addEventListener('load',fn,false)
		else if(typeof document.addEventListener != 'undefined')
		document.addEventListener('load',fn,false);
		else if(typeof window.attachEvent != 'undefined')
		window.attachEvent('onload',fn)
	else
	 {
	 var oldfn = window.onload
	 if(typeof window.onload != 'function')
	 	window.onload=fn
	 else
	   window.onload = function()
	   {
	    oldfn()
		fn()
	   } // end anonymouse function 
	 } // end else
}

/*****************************************Check Box*************************************************/

function CheckYesCoBorrower()
{
   document.PurchaseForm.nocoborrower.checked=false;
}

function CheckNoCoBorrower()
{
	document.PurchaseForm.yescoborrower.checked=false;
}

function CheckYesOwner()
{
   document.PurchaseForm.noowner.checked=false;
}

function CheckNoOwner()
{
   document.PurchaseForm.yesowner.checked=false;
}

function CheckBoxSwitch(boxClicked,uncheckedBox)
{
   uncheckedBox = document.getElementById(uncheckedBox);
   uncheckedBox.checked = false;
}


function PopUpAppears(e,objectID, row,column)
{

var evt = (evt) ? evt : ((window.event) ? event : null)
objDate = document.getElementById(e)
objPopUp = document.getElementById(objectID)
objPopUpHeight = objPopUp.offsetHeight

y=objDate.offsetTop + m;
if(objPopUp && column < 4)
{
xPopUp = 245
x = objDate.offsetLeft + xPopUp-(objPopUp.offsetWidth)
objPopUp.style.left = x + 'px'
objPopUp.style.top = y + 'px'
objPopUp.style.visibility = 'visible'
}  // end if

else
{
xPopUp=265
x = objDate.offsetLeft - 86
objPopUp.style.left = x + 'px'
objPopUp.style.top = y + 'px'
objPopUp.style.visibility = 'visible'
 
}// end else
}  // end function

function CalendarPopUpActive(evt)
{
myObj = document.getElementById(evt)
myObj.style.visibility = 'visible'
}  // end function

function HideCalendarPopUp()
{
objPopUp.style.visibility = 'hidden'
}  // end function

/******************Calculator*******************************************/
function getLoanAmount(num)
{
 var housePrice = Number(document.calForm.housePrice.value)
 var downPayment = Number(num)
 var loanAmount = housePrice - downPayment
 document.calForm.loanAmount.value = loanAmount
 return loanAmount
 
}  // end getLoanAmount

function getMonthlyPayment(id)
{
 N = Number(document.calForm.lengthLoan.value) * 12
 P = getLoanAmount(Number(document.calForm.downPayment.value))
 I = Number(document.calForm.interestRate.value)
 J = I/(12 * 100)
 M = (P * J/(1-(Math.pow((1+J), -N)))).toFixed(2)
 Y = (M * 12).toFixed(2)
 C= (N * M).toFixed(2)   // cost of the loan
 
 HousePrice = document.getElementById('housePrice').value;
 DownPayment = document.getElementById('downPayment').value;
 LoanAmount = document.getElementById('loanAmount').value;
 InterestRate =  document.getElementById('interestRate').value
 LengthLoan = document.getElementById('lengthLoan').value
 
 if(HousePrice != '' && DownPayment != '' && LoanAmount !='' && InterestRate !='' && LengthLoan != '')
 {
 document.calForm.monthlyPayment.value = M
 document.calForm.yearlyPayment.value = Y
 document.calForm.numberPayments.value = N
 document.calForm.costLoan.value = C 
 }
 }  // end getMonthlyPayment
 
 function getRemaining(num)
 {
  L = Number(document.calForm.lLoan.value)
  N = L * 12
  P = Number(document.calForm.principal.value)
  I = Number(document.calForm.annualRate.value)
  J = I/(12 * 100)
  M = (P * J/(1-(Math.pow((1+J), -N)))).toFixed(2)
  
  paidNum = Number(document.calForm.paidMonthly.value)   // number of paid monthly payments
  C = (N * M)   // cost of the loann
  Remain = (C - (M * paidNum)).toFixed(2)
  document.calForm.remainBalance.value = Remain  
 }   // end getRemaining
 
 function ClearCalculator(num1,num2,formName)
 {
	 for(i=num1;i<num2;i++)
	 {
		 document.forms[formName].elements[i].value="";
	 }  // end for
 }
/********************************End Calculator***********************************/

/****************************Create Account****************************************/

function CheckEmail()
{
 var emailPattern = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/
  myId = document.getElementById("EmailRow")
  if(!emailPattern.test(CreateAccountForm.email.value))
  {
  
   if(myId.lastChild.id == "EmailError")
        myId.removeChild(myId.lastChild) 
   div = document.createElement("div")
   div.id = "EmailError"
   div.float = "left"
   div.className = "ErrorClass"
   txt = document.createTextNode("Incorrect Email Format.")
   div.appendChild(txt)
   myId.appendChild(div)
   return false;
  }
  else
  {
	  if(CreateAccountForm.email2.value!="")
	  {
		  myId2= document.getElementById("EmailRow2");
		  if(CreateAccountForm.email.value != CreateAccountForm.email2.value)
		  {
			if(myId2.lastChild.id == "EmailError")
        		myId2.removeChild(myId2.lastChild) 
   			
			div = document.createElement("div")
   			div.id = "EmailError"
   			div.float = "left"
   			div.className = "ErrorClass"
   			txt = document.createTextNode("Must Be The Same As The First.")
   			div.appendChild(txt)
   			myId2.appendChild(div)
   			return false;
		  }  // end if
		  
		  else
		  {
	      	if(myId2.lastChild.id == "EmailError")
             myId2.removeChild(myId2.lastChild) 
			 
			pic = document.createElement("img")
    		pic.id = "EmailError"
    		pic.float = "left"
    		pic.align="left"
    		pic.src = "images/checkmark.jpg"
    		myId2.appendChild(pic)	
    		return true	
		 }  // end else
	  }
	  else
	  {
   if(myId.lastChild.id == "EmailError")
        myId.removeChild(myId.lastChild) 
		
  pic = document.createElement("img")
  pic.id = "EmailError"
  pic.float = "left"
  pic.align="left"
  pic.src = "images/checkmark.jpg"
  myId.appendChild(pic)	
  return true
	  }  // end else
   }
}

function CheckSecondEmail()
{
	myId = document.getElementById("EmailRow2");
	if(CreateAccountForm.email.value != CreateAccountForm.email2.value)
	{
	if(myId.lastChild.id == "EmailError")
    	myId.removeChild(myId.lastChild) 
   
   div = document.createElement("div")
   div.id = "EmailError"
   div.float = "left"
   div.className = "ErrorClass"
   txt = document.createTextNode("Must Be The Same As The First.")
   div.appendChild(txt)
   myId.appendChild(div)
   return false;
	}
	
	else
	{
		if(CreateAccountForm.email2.value == "")
			return false
		else
		{
	if(myId.lastChild.id == "EmailError")
    myId.removeChild(myId.lastChild) 
	pic = document.createElement("img")
    pic.id = "EmailError"
    pic.float = "left"
    pic.align="left"
    pic.src = "images/checkmark.jpg"
    myId.appendChild(pic)	
    return true
		}
	}
}

function CheckContactEmail(emailRow, emailId)
{
 var emailPattern = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/
  myId = document.getElementById(emailRow)
  email = document.getElementById(emailId)
  if(!emailPattern.test(email.value))
  {
  myId.style.color = 'red' 
  return false;
   
  }
 else
  {
	  myId.style.color='#006600'
	  return true
  }  // end else
}

function CheckAllContactEmailForms(ErrorSubmitRow)
{ 
   f1=CheckContactEmail('EmailRow','client_email')
   f2=CheckBlank('SubjectRow','email_subject');
   f3=CheckBlank('MessageRow','client_message');
   flag = false
 
 if(f1 && f2 && f3 )
 {
	 flag=true
 
 }
 
 else
  {
        ErrorR = document.getElementById(ErrorSubmitRow)
        if(ErrorR.firstChild)
           ErrorR.removeChild(ErrorR.firstChild)
        txt = document.createTextNode("Please fix the follwing error(s)");
        ErrorR.appendChild(txt) 
		flag=false
   }
 
  return flag
}



function CheckPassword()
{
 myId = document.getElementById("PassWordRow");
 pwd = CreateAccountForm.password.value
 if(pwd.length < 6)
 {
	if(myId.lastChild.id == "NotePassword")
		myId.removeChild(myId.lastChild)
	
	div = document.createElement("div")
	div.id = "NotePassword"
	div.float="left"
	div.className = "ErrorClass"
    txt = document.createTextNode("Must Be At Least 6 Characters.")
    div.appendChild(txt)
    myId.appendChild(div)
    return false;
 }
else
	{
	if(myId.lastChild.id == "NotePassword")
    myId.removeChild(myId.lastChild) 
	pic = document.createElement("img")
    pic.id = "NotePassword"
    pic.float = "left"
    pic.align="left"
    pic.src = "images/checkmark.jpg"
    myId.appendChild(pic)	
    return true	
	}
	
}

function CheckSecondPassword()
{
	myId = document.getElementById("PassWordRow2");
	pwd1 = CreateAccountForm.password.value
	pwd2 = CreateAccountForm.password2.value
	if(pwd1 != pwd2)
	{
	if(myId.lastChild.id == "NotePassword")
		myId.removeChild(myId.lastChild)
	
	div = document.createElement("div")
	div.id = "NotePassword"
	div.float="left"
	div.className = "ErrorClass"
    txt = document.createTextNode("Must Be The Same As The First.")
    div.appendChild(txt)
    myId.appendChild(div)
    return false;			
	}
	else
	{
		if(pwd2 == "")
		{
			return false
		}
		else
		{
	if(myId.lastChild.id == "NotePassword")
    myId.removeChild(myId.lastChild) 
	pic = document.createElement("img")
    pic.id = "NotePassword"
    pic.float = "left"
    pic.align="left"
    pic.src = "images/checkmark.jpg"
    myId.appendChild(pic)	
    return true
		}
	}
}

function CheckQuestion1()
{
 myId = document.getElementById("QuestionRow");
 if(CreateAccountForm.question1.value == "")
 {
	if(myId.lastChild.id == "QuestionDiv")
		myId.removeChild(myId.lastChild)
		
	div = document.createElement("div")
	div.id = "QuestionDiv"
	div.float="left"
	div.className = "ErrorClass"
    txt = document.createTextNode("Question Cannot Be Blank.")
    div.appendChild(txt)
    myId.appendChild(div)
    return false;
 }
else
	{
	if(myId.lastChild.id == "QuestionDiv")
    myId.removeChild(myId.lastChild) 
	pic = document.createElement("img")
    pic.id = "QuestionDiv"
    pic.float = "left"
    pic.align="left"
    pic.src = "images/checkmark.jpg"
    myId.appendChild(pic)	
    return true	
	}
}

function CheckQuestion2()
{
 myId = document.getElementById("QuestionRow2");
 if(CreateAccountForm.question2.value == "")
 {
	if(myId.lastChild.id == "QuestionDiv")
		myId.removeChild(myId.lastChild)
	
	div = document.createElement("div")
	div.id = "QuestionDiv"
	div.float="left"
	div.className = "ErrorClass"
    txt = document.createTextNode("Question Cannot Be Blank.")
    div.appendChild(txt)
    myId.appendChild(div)
    return false;
 }
else
	{
	if(myId.lastChild.id == "QuestionDiv")
    	myId.removeChild(myId.lastChild) 
		
	pic = document.createElement("img")
    pic.id = "QuestionDiv"
    pic.float = "left"
    pic.align="left"
    pic.src = "images/checkmark.jpg"
    myId.appendChild(pic)	
    return true	
	}
}

function CheckAnswer1()
{
 myId = document.getElementById("AnswerRow");
 if(CreateAccountForm.answer1.value == "")
 {
	if(myId.lastChild.id == "QuestionDiv")
		myId.removeChild(myId.lastChild)
	
	div = document.createElement("div")
	div.id = "QuestionDiv"
	div.float="left"
	div.className = "ErrorClass"
    txt = document.createTextNode("Answer Cannot Be Blank.")
    div.appendChild(txt)
    myId.appendChild(div)
    return false;
 }
else
	{
	if(myId.lastChild.id == "QuestionDiv")
    	myId.removeChild(myId.lastChild) 
		
	pic = document.createElement("img")
    pic.id = "QuestionDiv"
    pic.float = "left"
    pic.align="left"
    pic.src = "images/checkmark.jpg"
    myId.appendChild(pic)	
    return true	
	}
}

function CheckAnswer2()
{
 myId = document.getElementById("AnswerRow2");
 if(CreateAccountForm.answer2.value == "")
 {
	if(myId.lastChild.id == "QuestionDiv")
		myId.removeChild(myId.lastChild)
	
	div = document.createElement("div")
	div.id = "QuestionDiv"
	div.float="left"
	div.className = "ErrorClass"
    txt = document.createTextNode("Answer Cannot Be Blank.")
    div.appendChild(txt)
    myId.appendChild(div)
    return false;
 }
else
	{
	if(myId.lastChild.id == "QuestionDiv")
    	myId.removeChild(myId.lastChild) 
		
	pic = document.createElement("img")
    pic.id = "QuestionDiv"
    pic.float = "left"
    pic.align="left"
    pic.src = "images/checkmark.jpg"
    myId.appendChild(pic)	
    return true	
	}
}

function CheckFirstName()
{
	myId = document.getElementById("FirstNameRow");
 if(CreateAccountForm.fname.value == "")
 {
	if(myId.lastChild.id == "QuestionDiv")
		myId.removeChild(myId.lastChild)
	
	div = document.createElement("div")
	div.id = "QuestionDiv"
	div.float="left"
	div.className = "ErrorClass"
    txt = document.createTextNode("First Name Cannot Be Blank.")
    div.appendChild(txt)
    myId.appendChild(div)
    return false;
 }
else
	{
	if(myId.lastChild.id == "QuestionDiv")
    	myId.removeChild(myId.lastChild) 
		
	pic = document.createElement("img")
    pic.id = "QuestionDiv"
    pic.float = "left"
    pic.align="left"
    pic.src = "images/checkmark.jpg"
    myId.appendChild(pic)	
    return true	
	}
}


function CheckLastName()
{
	myId = document.getElementById("LastNameRow");
 if(CreateAccountForm.lname.value == "")
 {
	if(myId.lastChild.id == "QuestionDiv")
		myId.removeChild(myId.lastChild)
	
	div = document.createElement("div")
	div.id = "QuestionDiv"
	div.float="left"
	div.className = "ErrorClass"
    txt = document.createTextNode("Last Name Cannot Be Blank.")
    div.appendChild(txt)
    myId.appendChild(div)
    return false;
 }
else
	{
	if(myId.lastChild.id == "QuestionDiv")
    	myId.removeChild(myId.lastChild) 
		
	pic = document.createElement("img")
    pic.id = "QuestionDiv"
    pic.float = "left"
    pic.align="left"
    pic.src = "images/checkmark.jpg"
    myId.appendChild(pic)	
    return true	
	}
}

function CheckDOB()
{
 year = CreateAccountForm.yeardob.options[CreateAccountForm.yeardob.selectedIndex].value;
 month = CreateAccountForm.monthdob.options[CreateAccountForm.monthdob.selectedIndex].value;
 date = CreateAccountForm.datedob.options[CreateAccountForm.datedob.selectedIndex].value;
 myId = document.getElementById("DOBRow");
 if(year == 'Year' || month==0 || date==0)
 {
  if(myId.lastChild.id == "QuestionDiv")
		myId.removeChild(myId.lastChild)
	
	div = document.createElement("div")
	div.id = "QuestionDiv"
	div.float="left"
	div.className = "ErrorClass"
    txt = document.createTextNode("Wrong Date of Birth Format.")
    div.appendChild(txt)
    myId.appendChild(div)  	 
  return false;
  }
 else 
 {
   if(myId.lastChild.id == "QuestionDiv")
    	myId.removeChild(myId.lastChild) 
		
	pic = document.createElement("img")
    pic.id = "QuestionDiv"
    pic.float = "left"
    pic.align="left"
    pic.src = "images/checkmark.jpg"
    myId.appendChild(pic)	
    return true;   
 }
}  // end CheckDOB

function CheckAllField()
{ 
   f1=CheckEmail();
   f2=CheckSecondEmail();
   f3=CheckPassword();
   f4=CheckSecondPassword();
   f5=CheckQuestion1();
   f6=CheckAnswer1();
   f7=CheckQuestion2();
   f8=CheckAnswer2();
   f9=CheckFirstName();
   f10=CheckLastName();
   f11=CheckDOB();
   flag = false
  if(!f1 || !f2 || !f3 || !f4 || !f5 || !f6 || !f7 || !f8 || !f9 || !f10 || !f11)
   {
	
   myId = document.getElementById("ErrorSubmitRow")
   if(myId.lastChild.id == "ErrorField")
	   myId.removeChild(myId.lastChild)
	
	div = document.createElement("div")
	div.id = "ErrorField"
	div.float="left"
	div.className = "ErrorClass"
    txt = document.createTextNode("Please Correct The Following Error(s).")
    div.appendChild(txt)
    myId.appendChild(div)
  flag = false
   }
  if(f1 && f2 && f3 && f4 && f5 && f6 && f7 && f8 && f9 && f10 && f11)
    flag = true
  return flag
}

function CopyAddress(copiedaddress,copyaddress,copiedCity,copyCity,copiedList,copyList,copiedZip,copyZip)
{
	copiedaddress = document.getElementById(copiedaddress);
	copyaddress = document.getElementById(copyaddress);
	copyaddress.value = copiedaddress.value;
	
	copiedcity = document.getElementById(copiedCity);
	copycity = document.getElementById(copyCity);
	copycity.value = copiedcity.value;
	
	copiedzip = document.getElementById(copiedZip);
	copyzip = document.getElementById(copyZip)
	copyzip.value = copiedzip.value;
	
	copiedList = document.getElementById(copiedList)
	copyList = document.getElementById(copyList)
	for(i=0;i<51;i++)
	 {
		if(copiedList.options[i].selected)
		   copyList.options[i].selected=true;
	 }
}

function CalculateLoanFromDown()
{
 salesPrice = document.getElementById('sales_price');
 downPercent = document.getElementById('down_percent');
 downPayment = document.getElementById('down_payment');
 loanAmount = document.getElementById('loan_amount');
 
 downPercent.value = ((downPayment.value / salesPrice.value) * 100).toFixed(2);
 loanAmount.value = ((salesPrice.value) - (downPayment.value)).toFixed(2);
 
}

function CalculateLoanFromPercent()
{
 salesPrice = document.getElementById('sales_price');
 downPercent = document.getElementById('down_percent');
 downPayment = document.getElementById('down_payment');
 loanAmount = document.getElementById('loan_amount');
 
 downPayment.value = ((downPercent.value/100)*(salesPrice.value)).toFixed(2)
 loanAmount.value = ((salesPrice.value) - (downPayment.value)).toFixed(2);
}

function CalculateLoanAmountFromSalesPrice()
{

 salesPrice = document.getElementById('sales_price')
 downPercent = document.getElementById('down_percent')
 downPayment = document.getElementById('down_payment')
 loanAmount = document.getElementById('loan_amount')
 
 downPercent.value = ((downPayment.value/salesPrice.value)*100).toFixed(2)
 loanAmount = (salesPrice.value - downPayment.value).toFixed(2) 
}


function Explanation(exBox)
{
 box = document.getElementById(exBox)
 heightOfBox = box.offsetHeight
 x = window.event.x;
 y = window.event.y;
 
 scrollDown = document.body.scrollTop
 box.style.left = x + 'px';
 box.style.top = (y-heightOfBox + scrollDown) + 'px';
 //box.style.top = y + 'px';
 box.style.visibility = "visible";
 
}

function HideExplanation(exBox)
{
	box = document.getElementById(exBox)
	box.style.visibility = 'hidden';
}

function IncomeOptions(menuOption)
{   
    incomeOpId = document.getElementById(menuOption.id)
	//document.getElementById('incomechosen').value = '';
    //document.getElementById('mincomeresult').value = '';
	//alert('sfs')
	if(incomeOpId.options[incomeOpId.selectedIndex].value == "hourly")
	{
	 myId = document.getElementById("IncomeRow")
	 if(myId.lastChild.id == "Hrly")
	   myId.removeChild(myId.lastChild)
	 div = document.createElement("div")
	 div.id = "Hrly"
	 div.className = "FormFieldFloat"
	 
	 txtField = document.createElement("input")
	 txtField.id = 'hrlyincome'
	 txtField.type = "text"
	 txtField.className = "FormFieldFloat"
	 txtField.size = "2"
	 txtField.value = "40"
	 
	 subdiv = document.createElement('div')
	 subdiv.className = "FormFieldFloat"
	 txt= document.createTextNode("hrs/week")
	 subdiv.appendChild(txt)
	 
	 div.appendChild(txtField)
	 div.appendChild(subdiv)
	 myId.appendChild(div)	
	}
	else
	{
	 myId = document.getElementById("IncomeRow")
	 if(myId.lastChild.id == "Hrly")
	   myId.removeChild(myId.lastChild)	
		
	}
	
}  // end function
function GetMonthlyIncome()
{
  myId = document.getElementById('incomeoption')
  result = document.getElementById('mincomeresult')
  incomeType = document.getElementById('incomechosen')
  baseMIncome = document.getElementById('mbaseincome')
  overtime = document.getElementById('overtime')
  bonus = document.getElementById('bonuses');
  commision = document.getElementById('commision');
  netrent = document.getElementById('netrent')
  otherincome = document.getElementById('otherincome')
  divInt = document.getElementById('divint')
  grossMIncome = document.getElementById('gincometotal')
  
  m=myId.selectedIndex
 month_income = 0
  
  
 if(myId.options[m].value == 'year')
  {
	 month_income = (incomeType.value/12)
  }
 else if(myId.options[m].value == 'biweekly')
 {
	month_income = (Number(incomeType.value * 2) + (Number(2 * incomeType.value)/10))  
 }
 else if(myId.options[m].value == 'weekly')
 {
	month_income = (Number(incomeType.value * 4) +  (Number(2 * incomeType.value)/5)) 
	
 }
 else if(myId.options[m].value == 'hourly')
 {
	incomeId = document.getElementById('hrlyincome') 
	//month_income = (Number(incomeType.value * incomeId.value * 4) + (Number(incomeId.value/5)*2)*incomeType.value)
	month_income = (Number(incomeType.value * incomeId.value * 52/12))  // This calculating formular is got from the Point software
 }

 result.value= month_income.toFixed(2)
 baseMIncome.value = (month_income).toFixed(2)
 
 total = ((month_income) + Number(overtime.value) + Number(bonus.value) + Number(commision.value) + Number(netrent.value)+Number(otherincome.value) + Number(divInt.value)).toFixed(2)
   
 grossMIncome.value = total
   
}

function calGrossIncome()
{
baseMIncome = document.getElementById('mbaseincome')
overtime = document.getElementById('overtime')
bonus = document.getElementById('bonuses');
commision = document.getElementById('commision');
netrent = document.getElementById('netrent')
otherincome = document.getElementById('otherincome')	
divInt = document.getElementById('divint')

grossMIncome = document.getElementById('gincometotal')
	
total = (Number(baseMIncome.value) + Number(overtime.value) + Number(bonus.value) + Number(commision.value) + Number(netrent.value)+Number(otherincome.value)+ Number(divInt.value)).toFixed(2)
grossMIncome.value = total	
}


function GetIncomeCalculator(e)
{
calculator = document.getElementById('IncomeCal')	
x = (e.offsetWidth + 620) + 'px'
y = (e.offsetHeight + 710) + 'px'
calculator.style.top = y
calculator.style.left = x
calculator.style.visibility="visible"
}


function GetCoIncomeCalculator(e)
{
calculator = document.getElementById('IncomeCal')	
x = (e.offsetWidth + 590) + 'px'
y = (e.offsetHeight + 370) + 'px'
calculator.style.top = y
calculator.style.left = x
calculator.style.visibility="visible"
}

function CloseCalculator()
{
calculator = document.getElementById('IncomeCal')
calculator.style.visibility="hidden"
}

function OwnRentChange()
{
parentRow1 = document.getElementById('MonthlyIncomeRow');
parentRow2 = document.getElementById('MonthlyIncomeNextRow');
									
if(document.PurchaseForm.ownorrent.selectedIndex == 2)
{
while(parentRow1.firstChild)
	  parentRow1.removeChild(parentRow1.firstChild)
while(parentRow2.firstChild)
	  parentRow2.removeChild(parentRow2.firstChild)	
	
row = document.getElementById('MonthlyIncomeRow');
txt = document.createTextNode('Monthly Rent Payment: ');
row.appendChild(txt);

divMark = document.createElement('div')
divMark.className = 'RequiredMark';
divMark.id = 'RequireMarkIncome'


mark = document.createTextNode('* $');
divMark.appendChild(mark)

txtField = document.createElement('input');
txtField.className = 'FormField'
txtField.name = 'rent_payment';
txtField.id = 'rent_payment';
txtField.size = '7'

parentRow2.appendChild(divMark);
parentRow2.appendChild(txtField);
}

else
{
	while(parentRow1.firstChild)
	  parentRow1.removeChild(parentRow1.firstChild)
	while(parentRow2.firstChild)
	  parentRow2.removeChild(parentRow2.firstChild)
}  // end else
}

function CalculateNetRent()
{
gross_rent = Number(document.getElementById('pro_gross_rent').value);
m_payment = Number(document.getElementById('pro_mtg_payment').value);
ins_mt_tx_mis = Number(document.getElementById('pro_ins').value);

net_rent = document.getElementById('pro_net_rent');
net_rent.value = ((gross_rent * .75)-m_payment-ins_mt_tx_mis).toFixed(2);
}

function EscrowAppear()
{
sale_price = Number(document.getElementById('sales_price').value);
escrowRow = document.getElementById('EscrowRow');
parentRow1 = document.getElementById('EscrowRowNextRow');
down_payment = Number(document.getElementById('down_payment').value);
down_percent = Number(document.getElementById('down_percent').vallue);
escrowTitle	= document.createTextNode('Wave Tax Escrow');
percentDown = (down_payment/sale_price) * 100

if(percentDown >=20 || down_percent >= 20)
{

myInput = document.createElement('select')
myInput.name = 'escrow_tx';
myInput.className = 'CalendarTxt'
//append escrow title
if(escrowRow.firstChild)
  {
   escrowRow.removeChild(escrowRow.firstChild)
  }
while(parentRow1.firstChild)
  parentRow1.removeChild(parentRow1.firstChild)

escrowRow.appendChild(escrowTitle)

//append requirement mark
divMark = document.createElement('div')
divMark.className = 'RequiredMark';
divMark.id = 'RequireMarkEscrow'

mark = document.createTextNode('* ');
divMark.appendChild(mark)

//create select list
escrowSelect = document.createElement('select');
escrowSelect.id ='escrow_tx'
escrowSelect.name = 'escrow_tx'
escrowSelect.className = 'CalendarTopTxt'

myOption1 = document.createElement('option')
myOption1.value = 'Please Choose'
optionName1 = document.createTextNode('Please Choose')
myOption1.appendChild(optionName1)

myOption2 = document.createElement('option')
myOption2.value = 'Yes'
optionName2 = document.createTextNode('Yes')
myOption2.appendChild(optionName2)

myOption3 = document.createElement('option')
myOption3.value = 'No'
optionName3 = document.createTextNode('No')
myOption3.appendChild(optionName3)

//attached option to select
escrowSelect.appendChild(myOption1)
escrowSelect.appendChild(myOption2)
escrowSelect.appendChild(myOption3)

parentRow1.appendChild(divMark)
parentRow1.appendChild(escrowSelect)
escrowFlag = true;
}

else
{
if(escrowRow.firstChild)
   escrowRow.removeChild(escrowRow.firstChild)
while(parentRow1.firstChild)
  parentRow1.removeChild(parentRow1.firstChild)   
   escrowFlag = false;
}

}

function Qk1Appear()
{
q_k1Title = document.createTextNode('What type of property did you own?')
q_k1 = document.getElementById('q_k1Row')

qk1NextRow = document.getElementById('q_k1NextRow')

divMark = document.createElement('div')
divMark.className = 'RequiredMark';
divMark.id = 'RequireMarkq_k1'
mark = document.createTextNode('* ');
divMark.appendChild(mark)


divMark2 = document.createElement('div')
divMark2.className = 'RequiredMark';
divMark2.id = 'RequireMarkq_k2'
mark2 = document.createTextNode('* ');
divMark2.appendChild(mark2)

q_k2Title = document.createTextNode('How did you hold title to the home?')
q_k2 = document.getElementById('q_k2Row')

qk2NextRow = document.getElementById('q_k2NextRow')

yesBox = document.getElementById('q_ky')
noBox = document.getElementById('q_kn')

if(yesBox.checked)
{
if(q_k1.firstChild)
   q_k1.removeChild(q_k1.firstChild)
while(qk1NextRow.firstChild)
     qk1NextRow.removeChild(qk1NextRow.firstChild)
	 
q_k1Row.appendChild(q_k1Title);
qk1NextRow.appendChild(divMark);

qk1Select = document.createElement('select');

qk1Select.id ='q_k1'
qk1Select.name = 'q_k1'
qk1Select.className = 'CalendarTopTxt'

myOption1 = document.createElement('option')
myOption1.value = 'Please Choose'
optionName1 = document.createTextNode('Please Choose')
myOption1.appendChild(optionName1)

myOption2 = document.createElement('option')
myOption2.value = 'Principal Residence'
optionName2 = document.createTextNode('Principal Residence')
myOption2.appendChild(optionName2)

myOption3 = document.createElement('option')
myOption3.value = 'Second Home'
optionName3 = document.createTextNode('Second Home')
myOption3.appendChild(optionName3)

myOption4 = document.createElement('option')
myOption4.value = 'Investment Property'
optionName4 = document.createTextNode('Investment Property')
myOption4.appendChild(optionName4)

qk1Select.appendChild(myOption1);
qk1Select.appendChild(myOption2)
qk1Select.appendChild(myOption3)
qk1Select.appendChild(myOption4)
qk1NextRow.appendChild(qk1Select)

/******************************************************************************/
if(q_k2.firstChild)
   q_k2.removeChild(q_k2.firstChild)
while(qk2NextRow.firstChild)
     qk2NextRow.removeChild(qk2NextRow.firstChild)
	 
q_k2Row.appendChild(q_k2Title);
qk2NextRow.appendChild(divMark2);	 

qk2Select = document.createElement('select');

qk2Select.id ='q_k2'
qk2Select.name = 'q_k2'
qk2Select.className = 'CalendarTopTxt'

myOption_a = document.createElement('option')
myOption_a.value = 'Please Choose'
optionName_a = document.createTextNode('Please Choose')
myOption_a.appendChild(optionName_a)

myOption_b = document.createElement('option')
myOption_b.value = 'Solely by Yourself'
optionName_b = document.createTextNode('Solely by Yourself')
myOption_b.appendChild(optionName_b)

myOption_c = document.createElement('option')
myOption_c.value = 'Jointly with Your Spouse'
optionName_c = document.createTextNode('Jointly with Your Spouse')
myOption_c.appendChild(optionName_c)

myOption_d = document.createElement('option')
myOption_d.value = 'Investment Property'
optionName_d = document.createTextNode('Investment Property')
myOption_d.appendChild(optionName_d)

qk2Select.appendChild(myOption_a);
qk2Select.appendChild(myOption_b)
qk2Select.appendChild(myOption_c)
qk2Select.appendChild(myOption_d)
qk2NextRow.appendChild(qk2Select)
}
//when yes box is not checked
else if(!yesBox.checked)
{
if(q_k1.firstChild)
   q_k1.removeChild(q_k1.firstChild)
while(qk1NextRow.firstChild)
     qk1NextRow.removeChild(qk1NextRow.firstChild)   
	 
if(q_k2.firstChild)
   q_k2.removeChild(q_k2.firstChild)
while(qk2NextRow.firstChild)
     qk2NextRow.removeChild(qk2NextRow.firstChild)	 
}

}

function LoanOptionChange()
{
	option = document.getElementById('loan_option');
	salesPriceTxt = document.createTextNode('Sales Price:')
	salesRow = document.getElementById('SalesPriceRow');
	salesNextRow = document.getElementById('SalePriceNextRow');
	
	if(option.options[option.selectedIndex].value=='Purchase')
	{
		loanAmountRow = document.getElementById('LoanAmountRow')
		loanAmountRow.style.color = '#006600'
		
		if(salesRow.firstChild)
		    salesRow.removeChild(salesRow.firstChild)
		salesRow.appendChild(salesPriceTxt)
		
		while(salesNextRow.firstChild)
			salesNextRow.removeChild(salesNextRow.firstChild)
		
		if(document.getElementById('ApprRow'))
	    {
		  ApproximateRow  = document.getElementById('ApprRow')
		   if(ApproximateRow.firstChild)
	       ApproximateRow.removeChild(ApproximateRow.firstChild)
	    }
        if(document.getElementById('ApprNextRow'))
        {     
	    ApproximateNextRow = document.getElementById('ApprNextRow')
		while(ApproximateNextRow.firstChild)
	         ApproximateNextRow.removeChild(ApproximateNextRow.firstChild)
         }
		
		requiredDiv = document.createElement('div');
		star = document.createTextNode('*$');
		requiredDiv.className = 'RequiredMark'
		requiredDiv.appendChild(star);
		salesNextRow.appendChild(requiredDiv);
	
	    txtBox = document.createElement('input')
		txtBox.type = 'text'
		txtBox.id = 'sales_price'
		txtBox.onblur = function()
         {
 			sPrice = document.getElementById('sales_price')
 			downPt = document.getElementById('down_percent')
 			downPay = document.getElementById('down_payment')
 			loanAnt = document.getElementById('loan_amount')
 
            downPt.value = ((downPay.value/sPrice.value)*100).toFixed(2)
 		    loanAnt = (sPrice.value - downPay.value).toFixed(2) 
		}
        txtBox.className = 'FormFieldFloat'
        txtBox.name = 'sales_price';
        txtBox.size = '30'
		salesNextRow.appendChild(txtBox)
		
	/*****Down Payment Row***************************************/
    DownPaymentTxt = document.createTextNode('Down Payment:')
	DownPayRow = document.getElementById('DownPaymentRow')
	DownNextRow = document.getElementById('DownPaymentNextRow')
	if(DownPayRow.firstChild)
		DownPayRow.removeChild(DownPayRow.firstChild)
	DownPayRow.appendChild(DownPaymentTxt)	
	
	while(DownNextRow.firstChild)
			DownNextRow.removeChild(DownNextRow.firstChild)
	
	    requiredDiv = document.createElement('div');
		star = document.createTextNode('*$');
		requiredDiv.className = 'RequiredMark'
		requiredDiv.appendChild(star);
		DownNextRow.appendChild(requiredDiv);
		
	    txtBox = document.createElement('input')
		txtBox.type = 'text'	
		txtBox.id = 'down_payment';
		txtBox.onblur = function()
		{			
		salesPrice = document.getElementById('sales_price')
        downPercent = document.getElementById('down_percent')
        downPayment = document.getElementById('down_payment')
        loanAmount = document.getElementById('loan_amount')
        downPercent.value = ((downPayment.value/salesPrice.value)*100).toFixed(2)
        loanAmount = (salesPrice.value - downPayment.value).toFixed(2) 	
		
		/* Escrow */
		
		sale_price = Number(document.getElementById('sales_price').value);
		escrowRow = document.getElementById('EscrowRow');
		parentRow1 = document.getElementById('EscrowRowNextRow');
		down_payment = Number(document.getElementById('down_payment').value);
		down_percent = Number(document.getElementById('down_percent').vallue);
		escrowTitle	= document.createTextNode('Wave Tax Escrow');
		percentDown = (down_payment/sale_price) * 100

if(percentDown >=20 || down_percent >= 20)
{

myInput = document.createElement('select')
myInput.name = 'escrow_tx';
myInput.className = 'CalendarTxt'
//append escrow title
if(escrowRow.firstChild)
  {
   escrowRow.removeChild(escrowRow.firstChild)
  }
while(parentRow1.firstChild)
  parentRow1.removeChild(parentRow1.firstChild)

escrowRow.appendChild(escrowTitle)

//append requirement mark
divMark = document.createElement('div')
divMark.className = 'RequiredMark';
divMark.id = 'RequireMarkEscrow'

mark = document.createTextNode('* ');
divMark.appendChild(mark)

//create select list
escrowSelect = document.createElement('select');
escrowSelect.id ='escrow_tx'
escrowSelect.name = 'escrow_tx'
escrowSelect.className = 'CalendarTopTxt'

myOption1 = document.createElement('option')
myOption1.value = 'Please Choose'
optionName1 = document.createTextNode('Please Choose')
myOption1.appendChild(optionName1)

myOption2 = document.createElement('option')
myOption2.value = 'Yes'
optionName2 = document.createTextNode('Yes')
myOption2.appendChild(optionName2)

myOption3 = document.createElement('option')
myOption3.value = 'No'
optionName3 = document.createTextNode('No')
myOption3.appendChild(optionName3)

//attached option to select
escrowSelect.appendChild(myOption1)
escrowSelect.appendChild(myOption2)
escrowSelect.appendChild(myOption3)

parentRow1.appendChild(divMark)
parentRow1.appendChild(escrowSelect)
}

else
{
if(escrowRow.firstChild)
   escrowRow.removeChild(escrowRow.firstChild)
while(parentRow1.firstChild)
  parentRow1.removeChild(parentRow1.firstChild)   
   
}

		/* Escrow */
		}
		
		txtBox.className = 'FormFieldFloat'
        txtBox.name = 'down_payment';
		txtBox.id = 'down_payment'
        txtBox.size = '7'
		DownNextRow.appendChild(txtBox)
		
		//Down Percent
	  DownPercentTxt = document.createTextNode('Down Percent ');
	  DownPercentDiv = document.createElement('div')
	  DownPercentDiv.className = 'FormFieldFloat'
	  DownPercentDiv.appendChild(DownPercentTxt);
	  DownNextRow.appendChild(DownPercentDiv)
	  
	  DownPercentTxtBox = document.createElement('input')
	  DownPercentTxtBox.type = 'text'
	  DownPercentTxtBox.id = 'down_percent'
	  DownPercentTxtBox.name = 'down_percent'
	  DownPercentTxtBox.className = 'FormFieldFloat'
	  DownPercentTxtBox.size = '3'
	  DownPercentTxtBox.onblur = function ()
	  {
		salesPrice = document.getElementById('sales_price');
 		downPercent = document.getElementById('down_percent');
        downPayment = document.getElementById('down_payment');
        loanAmount = document.getElementById('loan_amount');
        downPayment.value = ((downPercent.value/100)*(salesPrice.value)).toFixed(2)
        loanAmount.value = ((salesPrice.value) - (downPayment.value)).toFixed(2);
		
		/* Escrow */
		
		sale_price = Number(document.getElementById('sales_price').value);
escrowRow = document.getElementById('EscrowRow');
parentRow1 = document.getElementById('EscrowRowNextRow');
down_payment = Number(document.getElementById('down_payment').value);
down_percent = Number(document.getElementById('down_percent').vallue);
escrowTitle	= document.createTextNode('Wave Tax Escrow');
percentDown = (down_payment/sale_price) * 100

if(percentDown >=20 || down_percent >= 20)
{

myInput = document.createElement('select')
myInput.name = 'escrow_tx';
myInput.className = 'CalendarTxt'
//append escrow title
if(escrowRow.firstChild)
  {
   escrowRow.removeChild(escrowRow.firstChild)
  }
while(parentRow1.firstChild)
  parentRow1.removeChild(parentRow1.firstChild)

escrowRow.appendChild(escrowTitle)

//append requirement mark
divMark = document.createElement('div')
divMark.className = 'RequiredMark';
divMark.id = 'RequireMarkEscrow'

mark = document.createTextNode('* ');
divMark.appendChild(mark)

//create select list
escrowSelect = document.createElement('select');
escrowSelect.id ='escrow_tx'
escrowSelect.name = 'escrow_tx'
escrowSelect.className = 'CalendarTopTxt'

myOption1 = document.createElement('option')
myOption1.value = 'Please Choose'
optionName1 = document.createTextNode('Please Choose')
myOption1.appendChild(optionName1)

myOption2 = document.createElement('option')
myOption2.value = 'Yes'
optionName2 = document.createTextNode('Yes')
myOption2.appendChild(optionName2)

myOption3 = document.createElement('option')
myOption3.value = 'No'
optionName3 = document.createTextNode('No')
myOption3.appendChild(optionName3)

//attached option to select
escrowSelect.appendChild(myOption1)
escrowSelect.appendChild(myOption2)
escrowSelect.appendChild(myOption3)

parentRow1.appendChild(divMark)
parentRow1.appendChild(escrowSelect)
}

else
{
if(escrowRow.firstChild)
   escrowRow.removeChild(escrowRow.firstChild)
while(parentRow1.firstChild)
  parentRow1.removeChild(parentRow1.firstChild)   
   
}

		/* Escrow */
	   }
	   DownNextRow.appendChild(DownPercentTxtBox)
	   
	   
	  PercentSign = document.createTextNode('%');
	  PercentSignDiv = document.createElement('div')
	  PercentSignDiv.className = 'FormFieldFloat'
	  PercentSignDiv.appendChild(PercentSign);
	  DownNextRow.appendChild(PercentSignDiv)
	  
    loanAmountRequire = document.getElementById('LoanAmountRequire')
	
	if(loanAmountRequire.firstChild)
	     loanAmountRequire.removeChild(loanAmountRequire.firstChild)
	requiredTxt = document.createTextNode('$ ')
	loanAmountRequire.appendChild(requiredTxt)
      
	loanA = document.getElementById('loan_amount')
    loanA.value = ''  

}  // end if(option.options[option.selectedIndex].value=='Purchase')
	
else if(option.options[option.selectedIndex].value == 'Please Choose')
{
if(salesRow.firstChild)
		    salesRow.removeChild(salesRow.firstChild)	
while(salesNextRow.firstChild)
			salesNextRow.removeChild(salesNextRow.firstChild)	
if(document.getElementById('DownPaymentRow'))
   {
	   DownPayRow = document.getElementById('DownPaymentRow')
	   if(DownPayRow.firstChild)
		DownPayRow.removeChild(DownPayRow.firstChild)	   
   }
if(document.getElementById('DownPaymentNextRow'))
    {
		DownNextRow = document.getElementById('DownPaymentNextRow')
	    while(DownNextRow.firstChild)	
		     DownNextRow.removeChild(DownNextRow.firstChild)
	}
if(document.getElementById('ApprRow'))
	{
		ApproximateRow  = document.getElementById('ApprRow')
		if(ApproximateRow.firstChild)
	       ApproximateRow.removeChild(ApproximateRow.firstChild)
	}
if(document.getElementById('ApprNextRow'))
  {     
	    ApproximateNextRow = document.getElementById('ApprNextRow')
		while(ApproximateNextRow.firstChild)
	         ApproximateNextRow.removeChild(ApproximateNextRow.firstChild)
  }
			


loanAmountRequire = document.getElementById('LoanAmountRequire')
	
	if(loanAmountRequire.firstChild)
	     loanAmountRequire.removeChild(loanAmountRequire.firstChild)
	requiredTxt = document.createTextNode('$ ')
	loanAmountRequire.appendChild(requiredTxt)

loanA = document.getElementById('loan_amount')

loanA.value = ''
}  // end else if

else
{
	if(document.getElementById('DownPaymentRow'))
        DownPayRow = document.getElementById('DownPaymentRow')
	if(document.getElementById('DownPaymentNextRow'))
        DownNextRow = document.getElementById('DownPaymentNextRow')	
		
	aRow = document.getElementById('ApprRow');
	while(aRow.firstChild)
	   aRow.removeChild(aRow.firstChild)
	
	aNextRow = document.getElementById('ApprNextRow')
	while(aNextRow.firstChild)
	   aNextRow.removeChild(aNextRow.firstChild)
	
	if(salesRow.firstChild)
		    salesRow.removeChild(salesRow.firstChild)	
	
	while(salesNextRow.firstChild)
			salesNextRow.removeChild(salesNextRow.firstChild)
			
	if(DownPayRow.firstChild)
		DownPayRow.removeChild(DownPayRow.firstChild)
		
	while(DownNextRow.firstChild)
			DownNextRow.removeChild(DownNextRow.firstChild)	
	
	loanAmountRequire = document.getElementById('LoanAmountRequire')
	
	if(loanAmountRequire.firstChild)
	     loanAmountRequire.removeChild(loanAmountRequire.firstChild)
	requiredTxt = document.createTextNode('*$ ')
	loanAmountRequire.appendChild(requiredTxt)
	
	loanAmount = document.getElementById('loan_amount')
    loanAmount.value = ''		
	loanAmount.readOnly = false		
	
	    apprRow = document.getElementById('ApprRow')
		apprTxt = document.createTextNode('Approximate:')	
	    apprRow.appendChild(apprTxt)
		
		requiredDiv = document.createElement('div');
		star = document.createTextNode('*');
		requiredDiv.className = 'RequiredMark'
		requiredDiv.appendChild(star);
		
		apprNextRow = document.getElementById('ApprNextRow')
		apprNextRow.appendChild(requiredDiv);	
		
		txtBox = document.createElement('input')
		txtBox.type = 'text'
		txtBox.id = 'appr_value'
		txtBox.name = 'appr_value'
		txtBox.className = 'FormFieldFloat'
        txtBox.size = '30'
		apprNextRow.appendChild(txtBox)
}
	
}