<!--

var is = { init:function() {
  this.ua = navigator.userAgent.toLowerCase();
  this.major = parseInt(navigator.appVersion);
  this.minor = parseFloat(navigator.appVersion);
  this.nav   = ( (this.ua.indexOf('mozilla')!=-1) && ((this.ua.indexOf('spoofer')==-1) && (this.ua.indexOf('compatible') == -1)));
  this.nav4  = (this.nav && (this.major == 4));
  this.nav4up= (this.nav && (this.major >= 4));
  this.nav5up= (this.nav && (this.major >= 5));
  this.gecko = (this.ua.indexOf('gecko') != -1);
  this.ie    = (this.ua.indexOf("msie") != -1);
  this.ie3   = (this.ie && (this.major == 2));
  this.ie4   = ( this.ie && (this.major == 4) && (this.ua.indexOf("msie 5.0")==-1));
  this.ie4up = (this.ie  && (this.major >= 4));
  this.ie5up = (this.ie && !this.ie3 && !this.ie4);
  this.opera = (this.ua.indexOf("opera") != -1);
  this.hotjava = (this.ua.indexOf("hotjava") != -1);
  this.webtv = (this.ua.indexOf("webtv") != -1);
  this.aol   = (this.ua.indexOf("aol") != -1);
  this.safari= (this.ua.indexOf("safari") != -1);
} }
is.init();

function openDir( form, locations ) { 
	
	// alert(locations);
	
	var newIndex = form.thebranch.selectedIndex;
		
	form.area.options[0].value = 'test';
	
	// cururl = form.thebranch.options[ newIndex ].value; 
		
	//window.location.assign( cururl ); 
	
}
	
function element(id){
    this.id = id;
    if ( document.getElementById(this.id) ) this.el = document.getElementById(this.id);
    if ( document.all ) this.el = document.all[this.id];
    if ( document.layers ) this.el = document.layers[this.id];
    this.setWidth = function(w){
        if (is.opera) this.el.style.pixelWidth = w;
        else this.el.style.width = w+'px';
        };
    this.setContent = function(d){
        if (document.all)
            {
            this.el.innerHTML = d;
            }
        else if (document.getElementById)
            {
            rng = document.createRange();
            rng.setStartBefore(this.el);
            htmlFrag = rng.createContextualFragment(d);
            while (this.el.hasChildNodes()) this.el.removeChild(this.el.lastChild);
            this.el.appendChild(htmlFrag);
            }
        else if (document.layers)
            {
            this.el.document.open();
            this.el.document.write(d);
            this.el.document.close();
            }
        };
    this.setOpacity = function(d){
        d = (d==100) ? 99.999 : d;
        this.el.style.opacity = (d/100);
        this.el.style.MozOpacity = (d/100);
        this.el.style.KhtmlOpacity = (d/100);
        this.el.style.filter = "alpha(opacity="+d+")";
        };
    this.setVisibility = function(d){
        this.el.style.visibility = d ? 'visible' : 'hidden';
        };
    this.setSrc = function(d){
        this.el.setAttribute('src',d);
        };
    this.setBgImage = function(d){
        this.el.style.backgroundImage = "url("+d+")";
        };
    }


function NtoA(a) { b = new Array(); b[0] = a; return b; }
function StoA(a) { b = a.split(','); c = new Array(); for(var d in b) c[c.length] = parseInt(b[d]); return c; }
function isFunction(a) { return typeof a == 'function'; }
function isNull(a) { return typeof a == 'object' && !a; }
function isNumber(a) { return typeof a == 'number' && isFinite(a); }
function isObject(a) { return (a && typeof a == 'object') || isFunction(a); }
function isString(a) { return typeof a == 'string'; }
function isUndefined(a) { return typeof a == 'undefined'; }
function isBoolean(a) { return typeof a == 'boolean'; }
function isArray(a) { return isObject(a) && a.constructor == Array; }

// viewport

var viewport = {
  getWinWidth: function () {
    this.width = 0;
    if (window.innerWidth) this.width = window.innerWidth - 18;
    else if (document.documentElement && document.documentElement.clientWidth)
        this.width = document.documentElement.clientWidth;
    else if (document.body && document.body.clientWidth)
        this.width = document.body.clientWidth;
    return this.width;
  },

  getWinHeight: function () {
    this.height = 0;
    if (window.innerHeight) this.height = window.innerHeight - 18;
    else if (document.documentElement && document.documentElement.clientHeight)
        this.height = document.documentElement.clientHeight;
    else if (document.body && document.body.clientHeight)
        this.height = document.body.clientHeight;
    return this.height;
  },

  getScrollX: function () {
    this.scrollX = 0;
    if (typeof window.pageXOffset == "number") this.scrollX = window.pageXOffset;
    else if (document.documentElement && document.documentElement.scrollLeft)
        this.scrollX = document.documentElement.scrollLeft;
    else if (document.body && document.body.scrollLeft)
        this.scrollX = document.body.scrollLeft;
    else if (window.scrollX) this.scrollX = window.scrollX;
    return this.scrollX;
  },

  getScrollY: function () {
    this.scrollY = 0;
    if (typeof window.pageYOffset == "number") this.scrollY = window.pageYOffset;
    else if (document.documentElement && document.documentElement.scrollTop)
        this.scrollY = document.documentElement.scrollTop;
    else if (document.body && document.body.scrollTop)
        this.scrollY = document.body.scrollTop;
    else if (window.scrollY) this.scrollY = window.scrollY;
    return this.scrollY;
  },

  getAll: function () {
    this.getWinWidth(); this.getWinHeight();
    this.getScrollX();  this.getScrollY();
  }

}


var map;
var icon = new Array();

function 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 init()
    {
    if (!GBrowserIsCompatible()) return false;
    var argv = init.arguments;
    var Full = argv[0] ? true : false;
    var Lon = argv[1] ? argv[1] : startLon;
    var Lat = argv[2] ? argv[2] : startLat;
    var Zoom = argv[3] ? argv[3] : startZoom;
    var Pin = argv[4] ? true : false;
    var m = document.getElementById('map');
    if (typeof(m) == 'undefined') return;
    map = new GMap2(m);

    if (Full)
        {
        map.addControl(new GLargeMapControl());
        map.addControl(new GMapTypeControl());
        map.addControl(new GScaleControl());
        map.setCenter(new GLatLng(Lat,Lon),Zoom);
        }
        else
        {
        //map.addControl(new GMapTypeControl());
        map.addControl(new GSmallZoomControl());
        map.setCenter(new GLatLng(Lat,Lon),Zoom);
        }

    var colour = new Array('blue','green','purple','red','white','yellow','black','cyan','orange');
    for (i=0; i<colour.length; i++)
        {
        tmp = new GIcon();
        tmp.image = '/img/google/mm_20_'+colour[i]+'.png';
        tmp.shadow = '/img/google/mm_20_shadow.png';
        tmp.iconSize = new GSize(12,20);
        tmp.shadowSize = new GSize(22,20);
        tmp.iconAnchor = new GPoint(6,20);
        tmp.infoWindowAnchor = new GPoint(5,1);
        icon[colour[i]] = tmp;
        }

    if (Pin) addIcon(Lat,Lon,argv[4],'');

    }

function addIcon(lat,lon,col,data)
    {
    var marker = new GMarker(new GLatLng(lat,lon),icon[col]);
    if (data)
        {
        if (isString(data))
            {
            GEvent.addListener(marker,'click',function() { marker.openInfoWindowHtml(data); });
            }
        else
            {
            var tabs = new Array();
            for (var i in data) tabs[tabs.length] = new GInfoWindowTab(i,data[i]);
            GEvent.addListener(marker,'click',function() { marker.openInfoWindowTabsHtml(tabs); });
            }
        }
    // GEvent.addListener(marker,'click',function() { marker.showMapBlowup(2); });
    map.addOverlay(marker);
    return marker;
    }

function changeImgSrc(id,v)     { var el = document.getElementById(id); if (el) el.setAttribute('src',v); }
function changeClass(id,v)      { var el = document.getElementById(id); if (el) el.className = v; }
function changeColor(id,v)      { var el = document.getElementById(id); if (el) el.style.color = v; }
function changeVisibility(id,v) { var el = document.getElementById(id); if (el) el.style.visibility = v ? 'visible' : 'hidden'; }
function changeHeight(id,v)     { var el = document.getElementById(id); if (el) el.style.height = v+'px'; }
function changeBgImage(id,v)    { var el = document.getElementById(id); if (el) el.style.backgroundImage = 'url('+v+')'; }
function changeOpacity(id,v)    { var el = document.getElementById(v); if (el) { el.style.opacity = (v/101); el.style.MozOpacity = (v/101); el.style.KhtmlOpacity = (v/101); el.style.filter = "alpha(opacity="+v+")"; } };

function calcRental() {
	with (document.rental) {
		if (checkNumber(rental.value) && rental.value>0  && checkNumber(deposit.value) && deposit.value>0) {
		  	
		  	var therentalcost = rental.value;
		  	var themoveincost = 0;
		  	var thedeposit = 0;
			var numtenants = parseInt(tenants.value);
			var tenantscost = 0;
			var vat = 1.175;
					  	
		  	thedeposit = parseInt(therentalcost) + parseInt(100);
		  	
		  	deposit.value = thedeposit;
		  	
		  	switch( numtenants ) {
		  		case 1:
		  			tenantscost = 150 * vat;
		  			break
		  		case 2:
		  			tenantscost = 200 * vat;
		  			break
		  		case 3:
		  			tenantscost = 225 * vat;
		  			break
		  		case 4:
		  			tenantscost = 250 * vat;
		  			break
		  		default:
		  			tenantscost = 250 * vat;
		  			break
		  	}
		  	
		  	themoveincost = parseInt(rental.value) + parseInt(thedeposit) + tenantscost;
		  	
		  	moveincost.value = formatNumber(themoveincost,2,1);
		}
	}
}

function calcMortgage()
    {
    with (document.mortgage) {
    
       if (checkNumber(principal.value) && principal.value>0 && checkNumber(years.value) && years.value>0 &&
          checkNumber(rate.value) && rate.value>0) {
    
          var lnAmt = Math.min(parseFloat(principal.value),10000000);
          principal.value = lnAmt;
          var lnRate = Math.min(parseFloat(rate.value),999.99);
          rate.value = lnRate;
          lnRate = lnRate/1200;
          var lnYears = Math.min(parseFloat(years.value),100);
          years.value = lnYears;
          if (interestonly.checked) {
             monthly.value = formatNumber(lnAmt*lnRate,2,1);
             // interest.value = formatNumber(lnAmt*lnRate*lnYears*12,2,1);
          } else {
             var lnMonthly = formatRound(calcPayment(lnAmt,lnRate,lnYears*12));
             monthly.value = formatNumber(lnMonthly,2,1);
             // interest.value = formatNumber((lnMonthly*lnYears*12)-principal.value,2,1);
           }
       } else {
             monthly.value = "";
             // interest.value = "";
       }
    
    }
}

function tpmCalcMortgage2() {
	alert('tpmCalcMortgage');
}

function raiseP(x,y)
{ total=1;
  for (j=0; j<y; j++)
   { total*=x; }
  return total; //result of x raised to y power
}

function tpmCalcMortgage()
    {
    
       var frequency = 12;
       var principal=document.getElementById("ctl00_MortgageCalculator2_txtPrice"); 
       
       var deposit=document.getElementById("ctl00_MortgageCalculator2_txtDeposit");       
      
       var years=document.getElementById("ctl00_MortgageCalculator2_txtTerm");
             
       var rate=document.getElementById("ctl00_MortgageCalculator2_drpInterest");
       
       var monthly=document.getElementById("ctl00_MortgageCalculator2_txtPayments");
       
       var mortgage=document.getElementById("ctl00_MortgageCalculator2_txtAmount");
            
      if (checkNumber(principal.value) && principal.value>0 && checkNumber(years.value) && years.value>0 &&
          checkNumber(rate.value) && rate.value>0) {
    
          var lnDep = Math.min(parseFloat(deposit.value),10000000);
          deposit.value = lnDep;
          var lnAmt = Math.min(parseFloat(principal.value),10000000);
          principal.value = lnAmt;
          var lnRate = Math.min(parseFloat(rate.value),999.99);
          rate.value = lnRate;
          lnRate = lnRate/1200;
          var lnYears = Math.min(parseFloat(years.value),100);
          years.value = lnYears;
          
		var borrowed = lnAmt - lnDep;
		mortgage.value = borrowed;

//         effectiveInterestRate = (1 + ((interestRate / 100) / frequency)) ^ (12 / frequency) - 1
//         period = frequency * term
//         a = 1 + effectiveInterestRate
//         b = 1 / a
//         c = b ^ 360
//         d = 1 - c
//         annuityFactor = d / effectiveInterestRate
//         payment = mortgageAmount / annuityFactor

         var firstrate = (1 + ((lnRate / 100) / frequency));
         
//           alert("firstrate: " + firstrate);
//           
//           var firstrate = lnRate / 100;
//          
//          var firstrate = firstrate / frequency;
//          
//          var firstrate = 1 + firstrate;
//           
//           alert("firstrate: " + firstrate);
         
         
         var secondrate = ( 12 / frequency) - 1;
         
         var thirdrate =  raiseP(firstrate,secondrate) ;
         
         var period = frequency * lnYears;
         
         var a = 1 + thirdrate;

         var b = 1 / a;
         
         var c = raiseP(b,360);
         
         var d =  c;
         
         var annuityFactor = d / thirdrate;
         
         var payment = borrowed / annuityFactor;
         
         // alert("firstrate: " + firstrate + "\n secondrate: " + secondrate + "\n thirdrate: " + thirdrate + "\n period: " + period + "\n a: " + a + "\n b: " + b + "\n c: " + c + "\n d: " + d  + "\n annuityFactor: " + annuityFactor);
         // alert("payment: " + payment);
         
         var lnMonthly = formatRound(calcPayment(lnAmt,lnRate,lnYears, 0));
             lnMonthly = lnMonthly / 12;
             
             monthly.value = formatNumber(lnMonthly,2,1);
       } else {
             monthly.value = "";
             // interest.value = "";
       }
}

function calcPayment (amount,rate,time,balloon) {
   if (rate<=0) {
      if (time<=0) {
        return amount;
      } else {
        return amount/time;
      }
   }
   if (balloon==null) balloon = 0;
   
   var ln = Math.pow(1+rate,time);
   // alert(ln);
   return (amount-balloon/ln)/((1-(1/ln))/rate);
}

function checkNumber(number, msg, min, max) {
   msg = msg+" field has invalid numeric data: "+number.value;
   var str = number.value;
   if (str==null || str=="" || !str) return true;
   if (str.substring(1,1)=="$") {
      str = str.substring(2);
   }
   if (!validNumber(str)) {
      alert(msg);
      return false;
   }
   var num = parseFloat(str);
   if (min!=null && max!=null) {
      if (num<min || num>max) {
         alert(msg+" not in range ["+min+".."+max+"]");
         return false;
      }
   }
   number.value = str;
   return true;
}

function validNumber(number) {
   var checknum = parseFloat(number);
   if (isNaN(checknum)) return false;
   return true;
}

function formatRound(number,precision) {
   if (precision==null) precision = 2;
   if (precision==0) {
      return Math.round(number);
   }
   lnFactor = Math.floor(Math.pow(10,precision));
   if (precision<0) {
      return  Math.round(number/lnFactor)*lnFactor;
   }
   
   return Math.round(number*lnFactor)/lnFactor;
}

function formatNumber(number,precision,commas) {
   if (precision==null) precision = 2;
   number = formatRound(number,precision);
   var llSign = number<0;
   number = Math.abs(number);
   var ln = precision+1;
   var lc = "";
   number = Math.floor(number*Math.pow(10,precision));
   while (((ln--)>0) || (number>0)) {
      lc = (number%10)+lc;
      number = Math.floor(number/10);
      if (ln==1) lc = "."+lc;
   }
   if (llSign) lc = "-"+lc;
   var lc2 = "";
   if (commas) {
      var lc3 = lc;
      ln = lc.length;
      if (lc.indexOf(".")!=-1) {
         lc2 = lc.substring(lc.indexOf("."),ln);
         lc3 = lc.substring(0,lc.indexOf("."));
      }
      ln = lc3.length;
      var lnCount = 0;
      while (ln>0) {
         lnCount++;
         if (lnCount==4) {
            lc2 = ","+lc2;
            lnCount = 1;
         } 
         lc2 = lc3.substring(ln-1,ln)+lc2;
         ln--;
      }
   } else {
      lc2 = lc;
   }
   return lc2;
}

function qsPopulate()
    {
    var min = findObj('min');
    var max = findObj('max');
    var type = findObj('type');
    var sss = type.value;
    var ss;
    var s = (sss == '2' ? ' pcm' : '');
   
   alert(sss);
   
   if (sss == '' || sss == 0) { min.disabled = true; max.disabled = true; return; }
    ss = qs[sss+'.min'].split(';');
    if (ss.length > 1)
        {
        min.disabled = false; min.options.length = 0; min.options[0] = new Option('Min Price','');
        for (i=1;i<ss.length;i++) { min.options[i] = new Option(''+formatNumber(ss[i],0,1)+s,ss[i]); }
        }
    ss = qs[sss+'.max'].split(';');
    if (ss.length > 1)
        {
        max.disabled = false; max.options.length = 0; max.options[0] = new Option('Max Price','');
        for (i=1;i<ss.length;i++) { max.options[i] = new Option(''+formatNumber(ss[i],0,1)+s,ss[i]); }
        }
    }

function virtual(branch,id)
    {
    var width=680;
    var height=542;
    var options,top=(screen.availHeight-height)/2,left=(screen.availWidth-width)/2;
    options = "top="+top+",left="+left+",location=0,status=0,toolbar=0,menubar=0,directories=0,width="+width+",height="+height+",scrollbars=1,resizable=0";
    window.open('/'+branch+'/virtual/'+id,'VirtualTour',options);
    }

function imgPopup(width,height,location,description) {
    height+=40; width+=60;
    var options,needscroll=false,top=(screen.availHeight-height)/2,left=(screen.availWidth-width)/2;
    options = "top="+top+",left="+left+",location=0,status=0,";
    options = options+"toolbar=0,menubar=0,directories=0,width="+width;
    options = options + ",height="+height;
    options = "scrollbars=1,resizable=0," + options;
    if (window.popup) popup.close();
    popup=window.open("",description,options);
    popup.document.open();
    popup.document.write("<html><head><title>"+description+"</title></head><body marginwidth=\"0\" marginheight=\"0\" leftmargin=\"0\" topmargin=\"0\" rightmargin=\"0\" bottommargin=\"0\" onload=\"window.focus();\"><div align=\"center\"><a href=\"javascript:window.close();\"><img src=\""+location+"\" border=\"0\" style=\"margin:20px;\" alt=\"Click image to close\" /></a></div></body></html>");
    popup.document.close();
    }

// virtual tour code

var stopvtScroll=false;
var vtImgWidth=0;

function resetvtScroll()
    {
    var el=document.getElementById("vtScroll");
    // alert('resetting vtScroll left position from '+el.style.left+' to 0px');
    el.style.left = String("1px");
    el.style.left = String("0px");
    // alert('vtScroll left position now at '+el.style.left);
    }

function startvtScroll(i)
    {
    stopvtScroll=false;
    dovtScroll(i);
    vtImgWidth = Number(document.getElementById("vtImg").width);
    }

function dovtScroll(i)
    {
    if (stopvtScroll) return;
    var el=document.getElementById("vtScroll");
    var intPos=Number(el.style.left.substring(0,el.style.left.length-2));
    intPos+=i*6;
    if (intPos > 0) intPos -= vtImgWidth;
    if (intPos < -vtImgWidth) intPos += vtImgWidth;
    el.style.left = String(intPos+"px");
    setTimeout("dovtScroll("+i+");",20);
    }

// Added by LWW 2007-09_-18


// Script to clear fileds in forms
 function doClear(theText) {
     if (theText.value == theText.defaultValue) {
         theText.value = ""
     }
 }


//-->
