function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function doSum(form)
{
    var weeks;             // holds number of weeks
    var counties;          // holds number of counties

    var basecost; // dependent on number of counties
    var discount;  // relitive discount
    var total;       // total estimate
    var totDis;      // to work out the saving

    var resultString; //holds the final string of text


    /*get week and county value*/

    weeks = form.weeks.options[form.weeks.selectedIndex].text;

    /*get the second character of the number if required*/
    if(weeks.charAt(1) == " "){
        weeks = weeks.charAt(0);
    } else {
        weeks = weeks.charAt(0) + weeks.charAt(1);
    }

    counties = form.counties.options[form.counties.selectedIndex].text;

    /*get the second character of the number if required*/
    if(counties.charAt(1) == " "){
        counties = counties.charAt(0);
    } else {
        counties = counties.charAt(0) + counties.charAt(1);
    }


    /**do the formula**/
    basecost  = 15 + (counties*5);

    //first run
    //initial discount
    //initial total
    discount = getDiscount(1);
    total = basecost;


    for(var i=4; i < weeks; i++) {
        discount = getDiscount(i+1);
        total = getQuote(total, basecost, discount);

    }

    total = Math.round(total);

    //work out the amount saved using the same formula but not using the discount
    totDis = basecost;

    for(var i=4; i < weeks; i++) {
        totDis = getQuote(totDis, basecost, 1);
   }
   //get the amount saved
   totDis = (total/totDis)*100;
   totDis = Math.round(totDis);
   totDis = 100 - totDis;

   resultString = "Your quote is: &pound;" + total;

   // if the discount is worth shouting about
   if(totDis > 10) {
       resultString = "Your quote is £" + total +"," + "<br />Saving " + totDis + "% with discounts";
   }




    /*put the total into the results box*/
    input = document.getElementById("result");
    input.innerHTML = resultString;

    input = document.getElementById("calcBox");
    input.style.display ='none';


    input = document.getElementById("calcResultBox");
    input.style.display ='block';




}

function getDiscount(weeks) {
        var dis; //holds the discount value

        if(weeks <= 4){
            return 1;
        } else {
            dis = 0.95-(0.05*(weeks/4));
            return dis;
        }
}

function getQuote(current, basecost, discount){
    var total;
    total = (basecost/4);
    total = total * discount;
    total = total + current;
    return total;
}

function submitForm(form)
{
        form.submit();
}

function contact() {

open('ForgotPassword.html','Contact','width=800,height=750,left=50,screenX=196,top=100,screenY=100,scrollbars=yes');

}
