var termsvar=0;
function popUpTerms(URLStr)
{
  if(termsvar)
  {
    if(!termsvar.closed) termsvar.close();
  }

  termsvar = open(URLStr, 'termsvar', '');
}


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_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+='- '+nm+' must contain an e-mail 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'; }
  } if (errors) alert('The following error(s) occurred:\n'+errors);
  document.MM_returnValue = (errors == '');
}

var resetRolls = new Object();

function resetimage(src)
{
this.src=src;
this.confirm=true;
this.alt="Reset";
this.write=resetimage_write;
}

function resetimage_write()
{
document.write('<A ');
if (this.rollover)
    {
    if (! this.name)
        {
        alert('to create a rollover you must give the image a name');
        return;
        }

    resetRolls[this.name] = new Object();
    resetRolls[this.name].over = new Image();
    resetRolls[this.name].over.src=this.rollover;
    resetRolls[this.name].out = new Image();
    resetRolls[this.name].out.src=this.src;
    document.write(
        ' onMouseOver="if (document.images)document.images[\'' + 
        this.name + '\'].src=resetRolls[\'' + this.name + '\'].over.src"' + 
        ' onMouseOut="if (document.images)document.images[\'' + 
        this.name + '\'].src=resetRolls[\'' + this.name + '\'].out.src"'
        );
    }
document.write(' HREF="javascript:');
if (this.confirm)
    document.write('if(confirm(\'Are you sure you want to reset?\'))');
document.write(
    'document.forms[' + 
    (document.forms.length - 1) + '].reset();void(0);">');
document.write('<IMG SRC="' + this.src + '" ALT="' + this.alt + '"');
document.write(' BORDER=0');
if (this.name)document.write(' NAME="' + this.name + '"');
if (this.height)document.write(' HEIGHT=' + this.height);
if (this.width)document.write(' WIDTH=' + this.width);
if (this.otheratts)document.write(' '+ this.otheratts);
document.write('></A>');
}

function switchImage(imgName, imgSrc) 
{
  if (document.images)
  {
    if (imgSrc != "none")
    {
      document.images[imgName].src = imgSrc;
    }
  }
}
if(document.getElementById) {
   var upLevel = true;
}
else if(document.layers) {
   var ns4 = true;
}
else if(document.all) {
   var ie4 = true;
}


var popUpC=0;
function popUpCalender(URLStr)
{
  if(popUpC)
  {
    if(!popUpC.closed) popUpC.close();
  }

  popUpC = open(URLStr, 'popUpC', 'scrollbars=yes,toolbar=no,location=no,directories=no,status=yes,menubar=no, resizable=yes,copyhistory=no,width=800,height=800,left=200,top=0');
}
var popUpI=0;
function popUpImage(URLImage)
{
  if(popUpI)
  {
    if(!popUpI.closed) popUpI.close();
  }

  popUpI = open(URLImage, 'popUpI', 'toolbar=no,location=no,directories=no,status=yes,menubar=no,resizable=np,copyhistory=no,width=800,height=800,left=200, top=0');
}
function MM_openBrWindow(theURL,winName,features) { 
  window.open(theURL,winName,features);
}

function makeLink(url, title){
if(document.all)
window.external.AddFavorite(url,title)
}

 var offsetfrommouse=[15,15];
var ua = navigator.userAgent.toLowerCase();
var divw=0;
var divh=0;

if (document.getElementById || document.all)
	document.write('<div id="imgtrailer" style="position:absolute;visibility:hidden;"></div>')
	
	function gettrailobject()
	{
	if (document.getElementById)
		return document.getElementById("imgtrailer")
	else if (document.all)
		return document.all.trailimagid
	}

function gettrailobj()
	{
	if (document.getElementById)
		return document.getElementById("imgtrailer").style
	else if (document.all)
		return document.all.trailimagid.style
	}

function truebody()
	{
	return (!window.opera && document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
	}

function trailOff()
	{
	document.onmousemove='';
	gettrailobj().visibility="hidden";
	}

function trailOn(thumbimg,roomimg,imgtitle,thw,thh)
	{
	if(ua.indexOf('opera') == -1 && ua.indexOf('safari') == -1)
		{
		gettrailobj().left="-1000px";
		divthw = parseInt(thw)+326; // 326 is the total width required
		gettrailobject().innerHTML = '<div style="background-color: #fffed8; layer-background-color: #fffed8; border: 1px none #808080; padding:10px; width:'+divthw+'px;"><img src="'+thumbimg+'" border="0" align="left" width="'+thw+'" height="'+thh+'"><img src="'+roomimg+'" border="0" width="'+thw+'" height="'+thh+'"><div style="padding:3px" class="txtgrey11">'+imgtitle+'</div></div></div>';
		gettrailobj().visibility="visible";
		divw = parseInt(thw)+250;
		divh = parseInt(thh)+13;
		document.onmousemove=followmouse;
		}
	}

function followmouse(e){

	var xcoord=offsetfrommouse[0]
	var ycoord=offsetfrommouse[1]

	var docwidth=document.all? truebody().scrollLeft+truebody().clientWidth : pageXOffset+window.innerWidth-15
	var docheight=document.all? Math.min(truebody().scrollHeight, truebody().clientHeight) : Math.min(window.innerHeight)

	//if (document.all){
	//	gettrailobjnostyle().innerHTML = 'A = ' + truebody().scrollHeight + '<br>B = ' + truebody().clientHeight;
	//} else {
	//	gettrailobjnostyle().innerHTML = 'C = ' + document.body.offsetHeight + '<br>D = ' + window.innerHeight;
	//}

	if (typeof e != "undefined")
		{
		if (docwidth - e.pageX < 730){
			xcoord = e.pageX - xcoord - 400; // Move to the left side of the cursor
		} else {
			xcoord += e.pageX;
		}
		if (docheight - e.pageY < (divh + 110)){
			ycoord += e.pageY - Math.max(0,(110 + divh + e.pageY - docheight - truebody().scrollTop));
		} else {
			ycoord += e.pageY;
		}

	} else if (typeof window.event != "undefined"){ // typically this deals with moving the image to the left
		if (docwidth - event.clientX < 730){
			xcoord = event.clientX + truebody().scrollLeft - xcoord - 620; // Move to the left side of the cursor
		} else {
			xcoord += truebody().scrollLeft+event.clientX
		}
		if (docheight - event.clientY < (divh + 110)){
			ycoord += event.clientY + truebody().scrollTop - Math.max(0,(110 + divh + event.clientY - docheight));
		} else {
			ycoord += truebody().scrollTop + event.clientY;
		}
	}

	var docwidth=document.all? truebody().scrollLeft+truebody().clientWidth : pageXOffset+window.innerWidth-15
	var docheight=document.all? Math.max(truebody().scrollHeight, truebody().clientHeight) : Math.max(document.body.offsetHeight, window.innerHeight)
		if(ycoord < 0) { ycoord = ycoord*-1; 
	}
	gettrailobj().left=xcoord+"px"
	gettrailobj().top=ycoord+"px"
	}  
	
	function setPointer() {
    if (document.all) {
       for (var i=0;i < document.all.length; i++)
	     document.all(i).style.cursor = 'wait'; 
    }
}

function changePage(url,pageNo) {
   var form = document.MainForm;
   form.ListingUnitSearchResultsGetPage.value = pageNo;
   form.action=url;
   setPointer();
   form.submit();
   return false;
}