/* index.js */

function include(filename) {
document.write("<script language='javascript' type='text/javascript' src='/venterre/javascript/")
document.write(filename)
document.write("'></script>")
}
function include_external(filename) {
document.write("<script language='javascript' type='text/javascript' src='http://www.venterre.com/javascript/")
document.write(filename)
document.write("'></script>")
}

/********************************************/

include("time.js");
include("settings.js");
include("script.js");

/********************************************/

// Javascript Libraries //
//include_external("prototype/prototype.js");
//include_external("prototype/scriptaculous.js?load=effects");
//include_external("mootools.js");


// Image Effects //
//include_external("lightbox.js");
//include_external("lytebox.js");



// Form Validation //
//include_external("formvalidation.js");

// Venterre File //
//include_external("venterre.js");

//mortage calculator functions
function IsNumeric(strString)
   //  check for valid numeric strings
   {
   var strValidChars = "0123456789.-";
   var strChar;
   var blnResult = true;

   if (strString.length == 0) return false;

   //  test strString consists of valid characters listed above
   for (i = 0; i < strString.length && blnResult == true; i++)
      {
      strChar = strString.charAt(i);
      if (strValidChars.indexOf(strChar) == -1)
         {
         blnResult = false;
         }
      }
   return blnResult;
   }

function roundit(Num, Places) {
   if (Places > 0) {
      if ((Num.toString().length - Num.toString().lastIndexOf('.')) > (Places + 1)) {
         var Rounder = Math.pow(10, Places);
         return Math.round(Num * Rounder) / Rounder;
      }
      else return Num;
   }
   else return Math.round(Num);
}

function trim(str) {
	 return str.replace(/^\s+/g, '').replace(/\s+$/g, '');
}
	function mortgage_calculator() {
		var a=document.getElementById("amount").value;
		var p=document.getElementById("period").value;
		var r=document.getElementById("rate").value;

		document.getElementById("calc0").style.display='block';
		document.getElementById("calc1").style.display='block';
		document.getElementById("calc2").style.display='block';
		document.getElementById("calc3").style.display='block';

		if (a.indexOf('£') >= 0) a = a.replace('£','');
		if (a.indexOf(',') >= 0) a = a.replace(',','');
		if (r.indexOf('%') > 0) r = r.replace('%','');
		if (p.indexOf('yrs') > 0) p = p.replace('yrs','');
		if (p.indexOf('ys') > 0) p = p.replace('ys','');
		if (p.indexOf('years') > 0) p = p.replace('years','');
		if (p.indexOf('year') > 0) p = p.replace('year','');
		if (p.indexOf('yers') > 0) p = p.replace('yers',''); //allow for a few spelling mistakes
		if (p.indexOf('yars') > 0) p = p.replace('yars','');
		p = trim(p);
		//allow for months
			var ismonth='';
			if (p.indexOf('months') > 0) {
				p = p.replace('months','');
				ismonth='1';
			}
			//allow for a few spelling mistakes
			if (p.indexOf('mnths') > 0) {
				p = p.replace('mnths','');
				ismonth='1';
			}
			if (p.indexOf('moths') > 0){
				p = p.replace('moths','');
				ismonth='1';
			}
			if (p.indexOf('mths') > 0) {
				p = p.replace('mths','');
				ismonth='1';
			}
			if (p.indexOf('mth') > 0){
				p = p.replace('mth','');
				ismonth='1';
			}
			if (p.indexOf('mnth') > 0) {
				p = p.replace('mnth','');
				ismonth='1';
			}
			if (ismonth =='1')  p = (p / 12);

		if ((IsNumeric(a)) && (IsNumeric(p)) && (IsNumeric(r))) {
		r = r / 100;
		var v = ((a*r)/12) * (1/(1-(Math.pow(1/(1+r),p))));
		document.getElementById("monthly").innerHTML = "£" + roundit(v,0);
		v = (a*r)/12;
		document.getElementById("interest").innerHTML = "£" + roundit(v,0);
		} else {
			alert('We are sorry but you seem to have entered some invalid data.  Please try again. \n');
		}
	}

	function resetcalc() {
		document.getElementById("amount").value='';
		document.getElementById("period").value='';
		document.getElementById("rate").value='';
		document.getElementById("monthly").innerHTML = '';
		document.getElementById("interest").innerHTML = '';
	}
//