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;
}

//clearing input fields start

function isNotEmpty(field){
	return field != undefined && field.length > 0;
}
function loadSrc(img, field, fullFieldSrc){
    obj = MM_findObj(img);
    if(field != undefined && field.length > 0)
	    obj.src = fullFieldSrc;
}

function ClearInput(value, id){
    var input = document.getElementById(id);
	if(value == input.value){
		input.value = '';
	}else{
		input.value = input.value;
	}
}

//clearing input fields end

//popUp div start

var amID = "blank";

function switchDisplay(objId){
	obj = MM_findObj(objId);
	if (!obj) return;
	if(obj.style.display == 'none')
	    obj.style.display = 'block';
    else
	    obj.style.display = 'none';
}

function showMe(containerId){
	if(amID != "blank"){
		hideMe(amID);	
	}	
	
	amID = containerId;
	showContainer(containerId);
}

function showContainer(containerId){
	obj = MM_findObj(containerId);
	if (!obj)	 
	 return;
	 	 	 
	obj.style.display = 'block';
}

function hideMe(containerId){
	obj2 = MM_findObj(containerId)
	if (!obj2) return;
	obj2.style.display = 'none';
}

//popUp div end


function swapClass(obj, className){
	obj.className = className;
}






// serviced apartments functions

function clearItem(item, defaultText) {
	obj = MM_findObj(item);
	if (!obj) return;
	if (obj.value == defaultText)
		obj.value = "";
}
function restoreItem(item, defaultText) {
	obj = MM_findObj(item);
	if (!obj) return;
	if (obj.value == "")
		obj.value = defaultText;
}
function setStatus(text) {
	window.status = text;
}

function clearStatus() {
	window.status = '';
}

function dateOK(Y, M, D) {
    return D > 0 &&
        (D <= [, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31][M] ||
        D == 29 && M == 2 && Y % 4 == 0 && (Y % 100 > 0 || Y % 400 == 0));
}

function MM_validateForm() { //v4.0
  var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
  for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args[i]);
    if (val) { nm=val.name; if ((val=val.value)!="") {
      if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
        if (p<1 || p==(val.length-1)) errors+='- The Email field must contain an email address.\n';
     } else if (test!='R') { num = parseFloat(val);
        if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';
        if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
          min=test.substring(8,p); max=test.substring(p+1);
          if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
    } } } else if (test.charAt(0) == 'R') errors += '- '+nm+' is required.\n'; }
  } 
    inday = MM_findObj('_CheckInDay');
    inmonth = MM_findObj('_CheckInMonth');
    inyear = MM_findObj('_CheckInYear');
    var indateValid = false;
    if( inday != null || inmonth != null || inyear != null ){
        if( inday.selectedIndex == 0 || inmonth.selectedIndex == 0 || inyear.selectedIndex == 0 || 
        !dateOK(parseInt(inyear.value), parseInt(inmonth.value), parseInt(inday.value)) )
            errors += '- Invalid Check-in Date.\n';
        else {
            var yesterday = new Date();
            var dateIn = new Date();
            dateIn.setFullYear(parseInt(inyear.value), parseInt(inmonth.value)-1, parseInt(inday.value));
            yesterday.setDate(yesterday.getDate() - 1);
            
            if( dateIn < yesterday )
                errors += '- Check-in Date must be a current or future date.\n';
            else 
                indateValid = true;
        }
    }
    outday = MM_findObj('_CheckOutDay');
    outmonth = MM_findObj('_CheckOutMonth');
    outyear = MM_findObj('_CheckOutYear');
    if( outday != null || outmonth != null || outyear != null ) {
        if( outday.selectedIndex == 0 || outmonth.selectedIndex == 0 || outyear.selectedIndex == 0 || 
        !dateOK(parseInt(outyear.value), parseInt(outmonth.value), parseInt(outday.value)) )
            errors += '- Invalid Check-Out Date.\n';
        else if( indateValid ){
            var dateIn = new Date();
            var dateOut = new Date();
            dateIn.setFullYear(parseInt(inyear.value), parseInt(inmonth.value)-1, parseInt(inday.value));
            dateOut.setFullYear(parseInt(outyear.value), parseInt(outmonth.value)-1, parseInt(outday.value));
            
            if( dateOut < dateIn )
                errors += '- Check-out date must not be before the check-in date.\n';
        }
    }
    
  if (errors) alert('Sorry, your request has not been completed. The following error(s) occurred:\n\n'+errors);
  document.MM_returnValue = (errors == '');
}
function GetParam(name)
{
  var start=location.search.indexOf("?"+name+"=");
  if (start<0) start=location.search.indexOf("&"+name+"=");
  if (start<0) return '';
  start += name.length+2;
  var end=location.search.indexOf("&",start)-1;
  if (end<0) end=location.search.length;
  var result=location.search.substring(start,end);
  var result='';
  for(var i=start;i<=end;i++) {
    var c=location.search.charAt(i);
    result=result+(c=='+'?' ':c);
  }
  return unescape(result);
}

function validateForm(){
	eml = MM_findObj('_email');
	if (eml.value.indexOf('@')>0 && eml.value.indexOf('.')>0){
		return true;}
	else{
		alert("Please enter an email address so that we can contact you back");
		return false;
	}										
}

//start popup image
function init() {
	this.ns4 = (document.layers)? true:false;
	this.ns6 = (document.getElementById)? true:false;
	this.ie4 = (document.all)? true:false;
	this.ie5 = false;
	this.ie6 = false;
	this.mac = (navigator.userAgent.indexOf('Mac') > 0) ? true:false;

	if (ie4) {
		if (navigator.userAgent.indexOf('MSIE 5') > 0) {
			ie5 = true;
		} else if (navigator.userAgent.indexOf('MSIE 6') > 0) {
			ie6 = true;
			//ie4 = false;
		}
		if (ns6) {
			ns6 = false;
		}
	}
}

function getPos(obj) {
	var x = 0, y = 0;
	for (o = obj; o != null; o = o.offsetParent) {
		x += o.offsetLeft - o.scrollLeft;
		y += o.offsetTop - o.scrollTop;
	}
	if (ie5) {
		x -= document.documentElement.scrollLeft;
		y -= document.documentElement.scrollTop;
	}
	return {x:x, y:y};
}

function getHeight(obj) {
	height = 0;
	if (ie4)
		height = obj.offsetHeight;
	else if (ns4)
		height = obj.offsetHeight;
	else if (ns6)
		height = obj.offsetHeight;

	return height;
}

function getWidth(obj) {
	width = obj.offsetWidth;
	return width;
}

function hideImage(divName) {
	div = MM_findObj(divName);
	if (!div) return;
	div.style.display = "none";
}

var img, div;
var target;

function showImage(evt, url, divName, posType, posAlign, posTop, posLeft) {
	if (typeof(ie6) == 'undefined')
		init();
	
	div = MM_findObj(divName);
	if (!div) return;

	winoffset = (ie6) ? document.documentElement.scrollLeft : (ie4) ? document.body.scrollLeft : pageXOffset;
	if (ie4) iwidth = document.body.clientWidth;
	if (ns4) iwidth = innerWidth;
	if (ns6) iwidth = outerWidth;

	scrolloffset = (ie6) ? document.documentElement.scrollTop : (ie4) ? document.body.scrollTop : pageYOffset;
	if (ie4) iheight = document.body.clientHeight;
	if (ns4) iheight = innerHeight;
	if (ns6) iheight = outerHeight;

	img = new Image();
	img.src = url;
	
	target = (evt.target) ? evt.target : evt.srcElement;
	popupImage(posType, posAlign, posTop, posLeft);
}

function popupImage(posType, posAlign, posTop, posLeft) {
	if (img == null || target == null || div == null)
		return;
	
	if (!img.complete) {
		setTimeout("popupImage('" + posType + "','" + posAlign + "'," + posTop + "," + posLeft + ")", 10);
		return;
	}
	
	imgWidth = img.width;
	imgHeight = img.height;
	
	initialDivWidth = 39;
	initialDivHeight = getHeight(div);

	div.innerHTML = '<img src="' + img.src + '" />';
	
	div.style.display = "block";
	
	divWidth = getWidth(div);
	divHeight = getHeight(div);

	//alert('imgWidth: ' + imgWidth + '\r\ninitialDivWidth: ' + initialDivWidth + '\r\ndivWidth: ' + divWidth);
	//alert(target);

	if (posType == 0) {	//absolute to window
		yPos = (scrolloffset + posTop);
		xPos = (winoffset + posLeft);
	}
	else if (posType == 1) {	//above item
		//elem = (evt.target) ? evt.target : evt.srcElement;
		pos = getPos(target);

		xPos = pos.x + posLeft + winoffset;
		yPos = pos.y - divHeight + posTop + scrolloffset;
		if (yPos < 0)
			yPos = 0;
	}
	else if (posType == 2) {	//below item
		//elem = (evt.target) ? evt.target : evt.srcElement;
		pos = getPos(target);

		if (posAlign == 'left') {
			xPos = pos.x + posLeft + winoffset;
			yPos = pos.y + posTop + scrolloffset;
		} else {
			xPos = pos.x + getWidth(target) + posLeft + winoffset - imgWidth - initialDivWidth;
			yPos = pos.y + posTop;
		}
	}
	
	if (ns4) {
		div.top = yPos;
		div.left = xPos;
	} else if (ns6 || (mac && ie5)) {
		div.style.top = yPos + "px";
		div.style.left = xPos + "px";
	} else {
		div.style.top = yPos;
		div.style.left = xPos;
	}
	
	document.MM_returnValue = false; //block any page refresh
}
//end popup image

//homepage random complex start

var projects = new Array();
projects[0] = "theQuays.txt";
projects[1] = "questNewmarket.txt";
projects[2] = "ascent.txt";
projects[3] = "beaumontQuater.txt";
projects[4] = "hudsonBrown.txt";
projects[5] = "lighterQuay.txt";
projects[6] = "perspective.txt";
projects[7] = "qCentral.txt";
projects[8] = "qvbApartments.txt";
projects[9] = "theGuardian.txt";
projects[10] = "theKingsland.txt";
projects[11] = "theLandings.txt";

var numProjects = 12;

function getFeaturedProject() {
	obj = MM_findObj('featuredProjectDiv');	
	
	x = Math.floor(Math.random() * numProjects);

	content = LoadFile('/bribanc/Library/' + projects[x]);
	content = content.replace(/\.\.\//g, "");	
	obj.innerHTML = content;
}

function LoadFile(filename) {
	oxmlhttp = null;
	try {
		oxmlhttp = new XMLHttpRequest();
		oxmlhttp.overrideMimeType("text/xml");
	} catch(e) {
		try {
			oxmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
		} catch(e) {
			return null;
		}
	}
	if (!oxmlhttp)
		return null;
	try {
		oxmlhttp.open("GET",filename,false);
		oxmlhttp.send(null);
	} catch(e) {
		return null;
	}
	return oxmlhttp.responseText;
}

//homepage random complex end