function CalculateRatio(form)
{
  if(isFloat(form.RequiredLoanAmount.value) && isFloat(form.EstimatedValuationofSecurityProperty.value))
  {
     amount = 100 * parseFloat(form.RequiredLoanAmount.value) / parseFloat(form.EstimatedValuationofSecurityProperty.value);
     amount = Math.round(amount*100)/100;
     form.EstimatedLoantoValuationRatio.value = amount.toString();
  }
}


function OnApply(form, url)
{
  form.action = url;
  form.submit();
}


function OnBankDetails(form, url)
{
  var width = 750;
  var height = 500;
  
  window.open(url, "ANZWIN3", "toolbar=0,status=1,location=no,menubar=no,directories=no,scrollbars=yes,resizable=yes,screenX=0,screenY=0,left=0,top=0,width=" + width + ",height=" + height);
}


function OnBrokerLogIn(form)
{
  var ok;
  
  ok = true;
  
  ok = OnTextBox(ok, form.login, "Login", 50)
  
  if(ok)
    form.submit();
}


function OnCalculator(form)
{
  var ok, val;
  
  ok = true;
  
  ok = OnTextFloat(ok, form.loan_amount, "Loan Amount");
  
  if(ok)
  {
    val = parseInt(form.loan_amount.value)
    
    if(val < 0)
    {
      ok = false;
      alert('You must a loan amount greater than 0!');
      form.loan_amount.focus();
    }
  }

  ok = OnTextFloat(ok, form.interest_rate, "Interest Rate");

  if(ok)
  {
    val = parseInt(form.interest_rate.value)
    
    if(!(1 <= val && val <= 100))
    {
      ok = false;
      alert('You must enter an interested rate between 1 and 100!');
      form.interest_rate.focus();
    }
  }

  ok = OnTextFloat(ok, form.loan_period, "Loan Period");
  
  if(ok)
  {
    val = parseInt(form.loan_period.value)
    
    if(val < 0)
    {
      ok = false;
      alert('You must a loan amount greater than 0!');
      form.loan_period.focus();
    }
  }
  
  if(ok)
    form.submit();
}


function OnCannex(select)
{
  if(select.selectedIndex != 0)
  {
    var left, top1;
    
    left = (screen.width - 0.85*screen.width)/2;    top1 = (screen.height - 0.85*screen.height)/4;        window.open('cannex.asp?filename=' + escape(select.options[select.selectedIndex].value), 'add_existing', 'width=700,height=500,alwaysLowered=1,alwaysRaised=0,channelmode=0,dependent=0,directories=0,fullscreen=0,hotkeys=1,location=0,menubar=0,resizable=1,scrollbars=1,status=0,titlebar=0,toolbar=0,left=' + left + ',top=' + top1 + ',z-lock=0');  }
  else
  {
    alert('You must select a product');
    select.focus();
  }
}


function OnChangeProduct(form, select, scenario_capture)
{
  if(select.selectedIndex != 0)
  {
    if(scenario_capture)
      form.action = 'scenario_capture.asp';
    else
      form.action = 'broker_app.asp';
    
    form.submit();
  }
}


function OnChangeProductHome(form, select, scenario_capture)
{
  if(select.selectedIndex != 0)
  {
    form.action = 'scenario_capture_home.asp';
    form.submit();
  }
}


function OnChangeTypeofHomeLoan(select, TypeofHomeLoanOther)
{
  if(select.selectedIndex == 4)
    TypeofHomeLoanOther.style.display = 'block';
  else
    TypeofHomeLoanOther.style.display = 'none';
}


function OnCustomerLogIn(form)
{
  var ok;
  
  ok = true;
  
  ok = OnTextBox(ok, form.login, "Login", 50)
  
  if(ok)
    form.submit();
}


function OnLenderRate(url)
{
  var width = 750;
  var height = 500;
  
  window.open(url, "LenderRate", "toolbar=0,status=1,location=no,menubar=no,directories=no,scrollbars=yes,resizable=yes,screenX=0,screenY=0,left=0,top=0,width=" + width + ",height=" + height);
}


function OnPollAnswer(form, answer)
{
  form.result.value = answer;
  form.submit();
}


function OnSendEnquiry(form)
{
  var ok;
  
  ok = true;
  
  ok = OnRadio(ok, form.title, "Title");
  ok = OnTextBox(ok, form.first, "First name", 50);
  ok = OnTextBox(ok, form.last, "Last name", 50);
  ok = OnTextBox(ok, form.street, "Street", 50);
  ok = OnTextBox(ok, form.suburb, "Suburb", 50);
  ok = OnTextBox(ok, form.pcode, "Postcode", 50);
  ok = OnSelect(ok, form.state, "State");
  ok = OnTextBox(ok, form.phone_std, "Phone prefix", 50);
  ok = OnTextBox(ok, form.phone, "Phone", 50);
  ok = OnEmail(ok, form.email);
  ok = OnSelect(ok, form.product_name, "Product");
  ok = OnTextBox(ok, form.LoanAmount, "Loan Amount", 50);
  
  if(ok)
    form.submit();
  
}


function OnSubscribe(form)
{
  var ok;
  
  ok = true;
  
  ok = OnTextBox(ok, form.first, "First name", 50);
  ok = OnTextBox(ok, form.last, "Last name", 50);
  ok = OnEmail(ok, form.email);
  ok = OnSelect(ok, form.state, "State");
  ok = OnRadio(ok, form.client_type, "Client type");
  
  if(ok)
    form.submit();
}


function OnSubmitBrokerApplication(form, office)
{
  var ok;
  
  ok = true;
  
  ok = OnTextBox(ok, form.name, "Individual Broker name", 50)
  ok = OnSelect(ok, form.IDDataContent_26, "Collins product");
  ok = OnTextBox(ok, form.name, "Individual Broker name", 50)
  ok = OnEmail(ok, form.individual);
  ok = OnTextBox(ok, form.client, "Client name", 50);

  ok = OnTextBox(ok, form.required, "Required Loan Amount", 50);
  
  
  ok = OnTextBox(ok, form.security, "Security Property Postcode", 50);
  ok = OnTextBox(ok, form.purpose, "Purpose", 50)
  
  if(ok)
  {
    form.action = 'broker_thankyou.asp?collins=' + office;
    form.submit();
  }

}


function OnSubmitBrokerApplicationHome(form)
{
  var ok;
  
  ok = true;
  
  ok = OnTextBox(ok, form.firstname, "Client First Name", 50)
  ok = OnTextBox(ok, form.surname, "Client Surname", 50)
  ok = OnTextBox(ok, form.MortgagorTitleHolder, "Mortgagor Title Holder", 50)
  ok = OnSelect(ok, form.IDDataContent_26_27, "Collins Product");

  ok = OnTextBox(ok, form.RequiredLoanAmount, "Required Loan Amount", 50)
  ok = OnTextBox(ok, form.EstimatedValuationofSecurityProperty, "Estimated Valuation of Security Property", 50)
  ok = OnTextBox(ok, form.IndicativeMonthlyRepayments, "Indicative Monthly Repayments", 50)
  
  ok = OnTextFloat(ok, form.MortgageInsurance, "Mortgage Insurance");
  ok = OnTextFloat(ok, form.TotalFees, "Total Fees");
  
  ok = OnEmail(ok, form.ClientEmail);
  ok = OnEmail(ok, form.your_email);
  
  if(ok)
  {
    form.action = 'broker_home_thankyou.asp';
    form.submit();
  }

}
