﻿// * * * photoShow * * *
function photoShow(a) {
	//hideSelects(0);
	
	wTop=document.all? (document.documentElement.scrollTop?document.documentElement.scrollTop:document.body.scrollTop) : pageYOffset;	

	document.getElementById('photoShowImg').style.display='none'
	document.getElementById('photoShowLoading').style.display='block'
	document.getElementById('photoShowImg').src=a
	document.getElementById('photoShow').style.top=(wTop+100)+"px"
	document.getElementById('photoShow').style.display='block'
}

function photoHide() {
	document.getElementById('photoShow').style.display='none'
	//hideSelects(1);
}

function searchPanelSwitch() {
	if (document.getElementById('searchPanelBuy').checked) {
		
		// Price Min
		document.getElementById('lfPriceMinRent').style.display='none';
		document.getElementById('lfPriceMinRent').name='temp1';

		document.getElementById('lfPriceMinBuy').style.display='';
		document.getElementById('lfPriceMinBuy').name='lfPriceMin';

		// Price Max
		document.getElementById('lfPriceMaxRent').style.display='none';
		document.getElementById('lfPriceMaxRent').name='temp2';

		document.getElementById('lfPriceMaxBuy').style.display=''
		document.getElementById('lfPriceMaxBuy').name='lfPriceMax';

		// Area
		document.getElementById('lfAreaRent').style.display='none';
		document.getElementById('lfAreaRent').name='temp3';

		document.getElementById('lfAreaBuy').style.display='';
		document.getElementById('lfAreaBuy').name='lfArea';

		// Tube
		document.getElementById('lfTubeRent').style.display='none';
		document.getElementById('lfTubeRent').name='temp4';

		document.getElementById('lfTubeBuy').style.display=''
		document.getElementById('lfTubeBuy').name='lfTube';

		document.getElementById('seachPanelForm').setAttribute("action", searchPanelActionBuy);
	} else {
		// Price Min
		document.getElementById('lfPriceMinRent').style.display='';
		document.getElementById('lfPriceMinRent').name='lfPriceMin';

		document.getElementById('lfPriceMinBuy').style.display='none';
		document.getElementById('lfPriceMinBuy').name='temp1';

		// Price Max
		document.getElementById('lfPriceMaxRent').style.display='';
		document.getElementById('lfPriceMaxRent').name='lfPriceMax';

		document.getElementById('lfPriceMaxBuy').style.display='none'
		document.getElementById('lfPriceMaxBuy').name='temp2';
	
		// Area
		document.getElementById('lfAreaRent').style.display='';
		document.getElementById('lfAreaRent').name='lfArea';

		document.getElementById('lfAreaBuy').style.display='none';
		document.getElementById('lfAreaBuy').name='temp3';

		// Tube
		document.getElementById('lfTubeRent').style.display='';
		document.getElementById('lfTubeRent').name='lfTube';

		document.getElementById('lfTubeBuy').style.display='none'
		document.getElementById('lfTubeBuy').name='temp4';

		document.getElementById('seachPanelForm').setAttribute("action", searchPanelActionRent);
	}
}

function calculatorCalculate() {
	var a=document.getElementById("calculatorAmount").value;
	var d=document.getElementById("calculatorDeposit").value;
	var p=document.getElementById("calculatorTerm").value;
	var r=document.getElementById("calculatorRate").value;
		
	if (a.indexOf('£') >= 0) a = a.replace('£','');
	if (a.indexOf(',') >= 0) a = a.replace(',','');
	if (d.indexOf('£') >= 0) d = d.replace('£','');
	if (d.indexOf(',') >= 0) d = d.replace(',','');
	a=a-d;
	
	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("calculatorMonthly").value = "£" + roundit(v,0);
		v = (a*r)/12;
		document.getElementById("calculatorInterest").value = "£" + roundit(v,0);
	} else {
		alert('We are sorry but you seem to have entered some invalid data.  Please try again. \n');
	}
}

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 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 calculatorShow() {
	document.getElementById('calculatorShow').style.display="block";
}
function calculatorHide() {
	document.getElementById('calculatorShow').style.display="none";
}

function journeyShow() {
	document.getElementById('journeyShow').style.display="block";
}
function journeyHide() {
	document.getElementById('journeyShow').style.display="none";
}


