if (top.location.href!=self.location.href)
  top.location.href=self.location.href;

function fnCheckForm()
{
  if (document.frmManage.txtFirstname.value=="")
  {
    alert("Please enter your name.");
    document.frmManage.txtFirstname.focus();
    return false;
  }
  else if (document.frmManage.txtEmail.value=="")
  {
    alert("Please enter your email address.");
    document.frmManage.txtEmail.focus();
    return false;
  }
  else if (document.frmManage.txtCompany.value=="")
  {
    alert("Please enter your company name.");
    document.frmManage.txtCompany.focus();
    return false;
  }
  else if (document.frmManage.txtTelephone.value=="")
  {
    alert("Please enter your telephone number.");
    document.frmManage.txtTelephone.focus();
    return false;
  }
  else if (!(document.frmManage.txtEmail.value.match(/\b(^(\S+@).+((\.com)|(\.net)|(\.edu)|(\.mil)|(\.gov)|(\.org)|(\..{2,2}))$)\b/gi)))
  {
    alert("Please enter a valid email address.");
    document.frmManage.txtEmail.focus();
    return false;
  }
  else
    return true;
}


function fnCheckContact()
{
  if (document.frmManage.txtFirstname.value=="")
  {
    alert("Please enter your name.");
    document.frmManage.txtFirstname.focus();
    return false;
  }
  else if (document.frmManage.txtEmail.value=="")
  {
    alert("Please enter your email address.");
    document.frmManage.txtEmail.focus();
    return false;
  }
  //else if (document.frmManage.txtTel.value=="")
  //{
  //  alert("Please enter your telephone number.");
  //  document.frmManage.txtTel.focus();
  //  return false;
  //}
  else if (!(document.frmManage.txtEmail.value.match(/\b(^(\S+@).+((\.com)|(\.net)|(\.edu)|(\.mil)|(\.gov)|(\.org)|(\..{2,2}))$)\b/gi)))
  {
    alert("Please enter a valid email address.");
    document.frmManage.txtEmail.focus();
    return false;
  }
  else
    return true;
}


function fnCheckAppForm()
{
  if (document.frmApplication.txtFullName.value=="")
  {
    alert("Please enter your name.");
    document.frmApplication.txtFullName.focus();
    return false;
  }
  else if (document.frmApplication.txtCompanyName.value=="")
  {
    alert("Please enter your company name.");
    document.frmApplication.txtCompanyName.focus();
    return false;
  }
  else if (document.frmApplication.txtCompanyAddress.value=="")
  {
    alert("Please enter your company address.");
    document.frmApplication.txtCompanyAddress.focus();
    return false;
  }
  else if (document.frmApplication.txtPostcode.value=="")
  {
    alert("Please enter your company postcode.");
    document.frmApplication.txtPostcode.focus();
    return false;
  }
  else if (document.frmApplication.txtTelephoneNumber.value=="")
  {
    alert("Please enter your telephone number.");
    document.frmApplication.txtTelephoneNumber.focus();
    return false;
  }
  else if (document.frmApplication.txtEmailAddress.value=="")
  {
    alert("Please enter your email address.");
    document.frmApplication.txtEmailAddress.focus();
    return false;
  }
  else if (document.frmApplication.txtFinanceRequested.value=="")
  {
    alert("Please enter the amount of finance you require.");
    document.frmApplication.txtFinanceRequested.focus();
    return false;
  }
  else if (!(document.frmApplication.txtEmailAddress.value.match(/\b(^(\S+@).+((\.com)|(\.net)|(\.edu)|(\.mil)|(\.gov)|(\.org)|(\..{2,2}))$)\b/gi)))
  {
    alert("Please enter a valid email address.");
    document.frmApplication.txtEmailAddress.focus();
    return false;
  }
  else
    return true;
}


function fnCheckFurtherForm()
{
  if (document.frmManage.txtFirstname.value=="")
  {
    alert("Please enter your name.");
    document.frmManage.txtFirstname.focus();
    return false;
  }
  else if (document.frmManage.txtEmail.value=="")
  {
    alert("Please enter your email address.");
    document.frmManage.txtEmail.focus();
    return false;
  }
  else if (document.frmManage.txtJobTitle.value=="")
  {
    alert("Please enter your job title.");
    document.frmManage.txtJobTitle.focus();
    return false;
  }
  else if (document.frmManage.txtTelephone.value=="")
  {
    alert("Please enter your telephone number.");
    document.frmManage.txtTelephone.focus();
    return false;
  }
  else if (document.frmManage.txtPostcode.value=="")
  {
    alert("Please enter your postcode.");
    document.frmManage.txtPostcode.focus();
    return false;
  }       
  else if (document.frmManage.txtCompany.value=="")
  {
    alert("Please enter your company name.");
    document.frmManage.txtCompany.focus();
    return false;
  }  
  else if (!(document.frmManage.txtEmail.value.match(/\b(^(\S+@).+((\.com)|(\.net)|(\.edu)|(\.mil)|(\.gov)|(\.org)|(\..{2,2}))$)\b/gi)))
  {
    alert("Please enter a valid email address.");
    document.frmManage.txtEmail.focus();
    return false;
  }  
  else if (document.frmManage.dropSector.selectedIndex==0)
  {
    alert("Please select the business sector your company is in.");
    document.frmManage.dropSector.focus();
    return false;
  }
  else if (document.frmManage.txtEmployees.value=="")
  {
    alert("Please enter the number of employees at your company.");
    document.frmManage.txtEmployees.focus();
    return false;
  }
  else
    return true;
}


function makehomepage(objPage)
{
  if(navigator.appVersion.charAt(navigator.appVersion.indexOf("MSIE") + 5) >= 5 && navigator.platform.indexOf("Win16") == -1 && navigator.platform.indexOf("Mac") == -1)
  {
    objPage.style.behavior='url(#default#homepage)';
    objPage.setHomePage(document.location);
    objPage.href="#";
    return true;
  }
  else {return false};
}


function calculateprice(strLink)
{        
  total = 0.00;
  TotalWe = 0.00;
  TotalExist = 0.00;
  totalPercent = 0;
  
  intCount = 0;
  
  for (index = 1 ; index<document.frmCalc.txtPrice.length ; index++)
  {
    if (document.frmCalc.txtPrice[index].value!="")
    {      
      TotalWe += (document.frmCalc.qprice[index].value*document.frmCalc.usage[index].value);
      TotalExist += (document.frmCalc.txtPrice[index].value*document.frmCalc.usage[index].value);
      intCount++;
    }      
  }
  
  if (intCount<1)
  {
    fnFindBrowserObject('savingDisplay').innerHTML = "<h4 style='color: red;'>Calculation error</h4>You have not entered enough products. You have entered "+intCount+" ";
    fnFindBrowserObject('savingDisplay').innerHTML += (intCount==1) ? " product." : " products.";
  }
  else
  {
    total = TotalExist - TotalWe;
  
    //alert("Total: "+total+"\nTotal We:"+TotalWe+"\nPlus: "+document.frmCalc.qprice[index].value*document.frmCalc.usage[index].value+"\nTotal Entered"+TotalExist+"\nPlus entered: "+document.frmCalc.txtPrice[index].value*document.frmCalc.usage[index].value)
  
    totalPercent = parseInt(100 - ((100/TotalExist)*TotalWe));
    
    //document.frmCalc.savedtotal.value = "Â£" + total.toFixed(2);
    if (total < 0)
      fnFindBrowserObject('savingDisplay').innerHTML = "<h2>Congratulations</h2>We are unable to save you any money on the group of items that you selected at this time. Perhaps you would like to try a different combination of products or return at a later date to check out our pricing again. In the meantime thank you for your interest in Spiral Group.<br/><br/>";
    else
      fnFindBrowserObject('savingDisplay').innerHTML = "<h2>We will save you &pound;"+total.toFixed(2)+" which is an overall saving of "+totalPercent+"%</h2><strong>To see how much more we could be saving you <a href='"+strLink+"'>contact us</a>.</strong><br/><br/>";
  }
}


function fnSavingCheckQuantity(intValue)
{
  intValue=parseInt(intValue)
  
  if (isNaN(intValue)) 
    intValue = 1;
  
  return(intValue);
}

function fnCalcReady()
{
  if (document.frmManage.selMargin.selectedIndex > 0)
  {
    strValue = ((parseFloat(document.frmManage.txtProfit.value)/parseInt(document.frmManage.selMargin.options[document.frmManage.selMargin.selectedIndex].value))*100.00);
    document.frmManage.txtNetWorth.value = "£"+Math.round(strValue);
  }
}

function fnCalcLoan()
{
  fltAssets = parseFloat(document.frmApplication.txtHome.value);
  fltAssets += parseFloat(document.frmApplication.txtValuables.value);
  fltAssets += parseFloat(document.frmApplication.txtVehicles.value);
  fltAssets += parseFloat(document.frmApplication.txtElectronics.value);
  fltAssets += parseFloat(document.frmApplication.txtOther.value);
  fltAssets += parseFloat(document.frmApplication.txtCurrent.value);
  fltAssets += parseFloat(document.frmApplication.txtSavings.value);
  fltAssets += parseFloat(document.frmApplication.txtOther2.value);
  fltAssets += parseFloat(document.frmApplication.txtRetirement.value);
  fltAssets += parseFloat(document.frmApplication.txtISAs.value);
  fltAssets += parseFloat(document.frmApplication.txtStocks.value);
  fltAssets += parseFloat(document.frmApplication.txtProperty.value);
  
  fltLiabilities = parseFloat(document.frmApplication.txtMortgage.value);
  fltLiabilities += parseFloat(document.frmApplication.txtSecured.value);
  fltLiabilities += parseFloat(document.frmApplication.txtCar.value);
  fltLiabilities += parseFloat(document.frmApplication.txtOtherLoans.value);
  fltLiabilities += parseFloat(document.frmApplication.txtCredit.value);
  fltLiabilities += parseFloat(document.frmApplication.txtBank.value);
  fltLiabilities += parseFloat(document.frmApplication.txtOtherDebt.value);
  
  strTotal = (fltAssets - fltLiabilities);
  
  document.frmApplication.txtNetWorth.value = strTotal.toFixed(2);
  document.frmApplication.hidRealWorth.value = strTotal.toFixed(2);
}

function fnLoanRepay()
{
  if ((document.frmLoanApp.txtInterestRate.value!="")&&(document.frmLoanApp.txtPeriod.value!="")&&(document.frmLoanApp.txtAmount.value!=""))
  {    
    //fltMonthlyInterest1 = Math.pow((1+(document.frmLoanApp.txtInterestRate.value / 100)),(1/12))-1;
    fltMonthlyInterest1 = ((document.frmLoanApp.txtInterestRate.value / 100)/12);
    //fltMonthlyInterest2 = Math.pow((1+(document.frmLoanApp.txtInterestRate2.value / 100)),(1/12))-1;
    fltMonthlyInterest2 = ((document.frmLoanApp.txtInterestRate2.value / 100)/12);
    //fltMonthlyInterest3 = Math.pow((1+(document.frmLoanApp.txtInterestRate3.value / 100)),(1/12))-1;
    fltMonthlyInterest3 = ((document.frmLoanApp.txtInterestRate3.value / 100)/12);
    fltTerm = document.frmLoanApp.txtPeriod.value * 12;
    fltMultiplier1 = (fltMonthlyInterest1*Math.pow((1+fltMonthlyInterest1),fltTerm))/((Math.pow((1+fltMonthlyInterest1),fltTerm))-1);
    fltMultiplier2 = (fltMonthlyInterest2*Math.pow((1+fltMonthlyInterest2),fltTerm))/((Math.pow((1+fltMonthlyInterest2),fltTerm))-1);
    fltMultiplier3 = (fltMonthlyInterest3*Math.pow((1+fltMonthlyInterest3),fltTerm))/((Math.pow((1+fltMonthlyInterest3),fltTerm))-1);
    fltResult1 = fltMultiplier1 * document.frmLoanApp.txtAmount.value;
    fltResult2 = fltMultiplier2 * document.frmLoanApp.txtAmount.value;
    fltResult3 = fltMultiplier3 * document.frmLoanApp.txtAmount.value;
    document.frmLoanApp.txtNetWorth.value = "£" + fltResult1.toFixed(2);
    document.frmLoanApp.txtNetWorth2.value = "£" + fltResult2.toFixed(2);
    document.frmLoanApp.txtNetWorth3.value = "£" + fltResult3.toFixed(2);
    fltInterestOnly1 = ((document.frmLoanApp.txtInterestRate.value / 100) * document.frmLoanApp.txtAmount.value) / 12;
    fltInterestOnly2 = ((document.frmLoanApp.txtInterestRate2.value / 100) * document.frmLoanApp.txtAmount.value) / 12;
    fltInterestOnly3 = ((document.frmLoanApp.txtInterestRate3.value / 100) * document.frmLoanApp.txtAmount.value) / 12;
    document.frmLoanApp.txtInterestOnly.value = "£" + fltInterestOnly1.toFixed(2);
    document.frmLoanApp.txtInterestOnly2.value = "£" + fltInterestOnly2.toFixed(2);
    document.frmLoanApp.txtInterestOnly3.value = "£" + fltInterestOnly3.toFixed(2);
  }
}