// 
// Copywrite Coldwell Banker Residential Brokerage 2004
//     Unauthorized use is strictly prohibited.
//

var navIds = new Array();
var navigation;
var hideTimeout;

function addNav(navId) {
    navIds[navIds.length] = navId;
}

function newPositionNav(navId, imageBase) {
    var baseImage = document.images[imageBase];

    x = findPosX(baseImage) + 3;
    y = findPosY(baseImage) + baseImage.height + 3;
    
    document.getElementById(navId).style.left = x;
    document.getElementById(navId).style.top  = y;
}
    
function getElementById(elementId) {
    if (document.getElementById) {
        return document.getElementById(elementId);
    } else if (document.all) {
        return document.all[elementId];
    } else if (document.layers) {
        return document.layers[elementId];
    }
}

function positionNavigation() {
    tableX = getElementById('menu-table').offsetLeft;
    tableY = getElementById('menu-table').offsetTop;
    menuX = getElementById('menu-cell').offsetLeft;
    menuY = getElementById('menu-cell').offsetTop;
    menuWidth = tableX + menuX + getElementById('menu-cell').offsetWidth;
    menuHeight = tableY + menuY + getElementById('menu-cell').offsetHeight;
	
    positionNav('townsMenu','townsButton');

    var width = document.getElementById('relocationNav').style.left;
    
    document.getElementById('relocationNav').style.left = width - relo_offset;
}

function positionNav(navId, imageBase) {
    document.getElementById(navId).style.left = 0;
    document.getElementById(navId).style.top  = 0;
}

function showMenu(navId,imageBase) {
    setTimeout("show('" + navId + "','" + imageBase + "')",300);
//    clearTimeout(hideTimeout);
//    hideTimeout = setTimeout("hide()", 5000);
}

function show(navId,imageBase) {
  navigation = document.getElementById(navId);
  navigation.style.visibility = 'visible';
  navigation.style.display = 'block';
}

function hide() {
  if (navigation) {
    navigation.style.visibility = 'hidden';
  }
}

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_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

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_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function findPosX(obj)
{
	var curleft = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curleft += obj.offsetLeft
			obj = obj.offsetParent;
		}
	}
	else if (obj.x)
		curleft += obj.x;
	return curleft;
}

function findPosY(obj)
{
	var curtop = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curtop += obj.offsetTop
			obj = obj.offsetParent;
		}
	}
	else if (obj.y)
		curtop += obj.y;
	return curtop;
}

  function pop(loc, name, w, h) {
      LeftPosition = (screen.width) ? (screen.width-w)/2 : 0;
      TopPosition = (screen.height) ? (screen.height-h)/400 : 0;
      setToolbar = 'yes';
      setLocation = 'yes';
      setDirectories = 'no';
      setStatus = 'yes';
      setMenubar = 'yes';
      setScrollbars = 'yes';
      setResizable = 'yes';
      setCopyhistory = 'no';
      settings = 'height='+h+',width='+w+',top='+TopPosition+',left='+LeftPosition+',toolbar='+setToolbar+',location='+setLocation+',directories='+setDirectories+',status='+setStatus+',menubar='+setMenubar+',scrollbars='+setScrollbars+',resizable='+setResizable+',copyhistory='+setCopyhistory+''
      var opp = window.open(loc, name, settings);
      opp.focus();
      return opp;
  }

  function popWin(windowName, loc, w, h, setToolbar, setLocation, setDirectories, setStatus, setMenubar, setScrollbars, setResizable, setCopyhistory) {
      LeftPosition = (screen.availWidth) ? (screen.availWidth-w)/2 : 0;
      TopPosition = (screen.availHeight) ? (screen.availHeight-h)/2 : 0;
      settings = 'height='+h+',width='+w+',top='+TopPosition+',left='+LeftPosition+',toolbar='+setToolbar+',location='+setLocation+',directories='+setDirectories+',status='+setStatus+',menubar='+setMenubar+',scrollbars='+setScrollbars+',resizable='+setResizable+',copyhistory='+setCopyhistory;
      var opp = window.open(loc, windowName, settings);
      opp.focus();
  }
  
  function popOrdinary(location, name) {
    pop(location, name, 820, 600);
  }
  
  function popSimple(width, height, location) {
    windowName = 'popup';
    pop(location, windowName, width, height);
  }
  
  function popNoDecorations(width, height, location) {
    popWin('popup', location, width, height, 'no', 'no', 'no', 'no', 'no', 'no', 'no', 'no');
  }
  
  /**
  * Opens the location in the window that opened this one.  If no
  * such window exists, a new window is opened.
  */
  function popInOpener(location) {
    if (window.opener && !window.opener.closed) {
      window.opener.location = location;
      window.opener.focus();
    } else {
      popOrdinary(location, 'nemoves');
    }
  }

  // TODO: is this still used?
  function openCalculatorWithPurchasePrice(price)
  {
    var agt=navigator.userAgent.toLowerCase();
    var is_aol = (agt.indexOf("aol") != -1);
	alert('Test Calc: '+price);
    if (is_aol) {
      var calculatorframe = document;
      var calculatorframe= window.open("http://newenglandmoves.com/MortgageCalculator/Calculator.htm?PurchasePrice=" + price,"newwin",'resizable=yes,scrollbars=yes,height=400,width=510');
      calculatorframe.focus();
    } else {
      var calculatorframe = document;
      var calculatorframe= window.open("http://newenglandmoves.com/MortgageCalculator/Calculator.htm?PurchasePrice=" + price,"newwin",'resizable=yes,scrollbars=yes,menubar=yes,height=452,width=510,top=30,left=140');
      calculatorframe.focus();
    }
  }

function popWin(windowName, loc, w, h, setToolbar, setLocation, setDirectories, setStatus, setMenubar, setScrollbars, setResizable, setCopyhistory)
{
  // Determine pop-up position to center on screen
  LeftPosition = (screen.availWidth) ? (screen.availWidth-w)/2 : 0;
  TopPosition = (screen.availHeight) ? (screen.availHeight-h)/2 : 0;

  settings = 'height='+h+',width='+w+',top='+TopPosition+',left='+LeftPosition+',toolbar='+setToolbar+',location='+setLocation+',directories='+setDirectories+',status='+setStatus+',menubar='+setMenubar+',scrollbars='+setScrollbars+',resizable='+setResizable+',copyhistory='+setCopyhistory;

  var opp = window.open(loc, windowName, settings);
  opp.focus();
}

function popUpHomeMovie(id) {
	alert('Home Movie ID: '+id);
  popWin("homeMovie", "../movies/HomeMovie.html?id=" + id, 510, 540, "no", "no", "no", "yes", "no", "no", "yes");
}

function popUpAgentMovie(id,agent) {
	alert('Agent Movie ID: '+id+' Agent: '+agent);
  popWin("AgentMovie", "../agentmovie/AgentMovie.html?id=" + id + "&agent=" + agent, 510, 530, "no", "no", "no", "yes", "no", "no", "yes");
}

function popUpPhotoGallery(id) {
alert('Photo Gallery ID: '+id);
  popWin("photoGallery", "../PhotoGallery/Index.htm?id=" + id, 740, 520, "no", "no", "no", "yes", "no", "no", "yes");
}

function popUpMLSPhotoGallery(id) {
	alert('Photo Gallery MLS ID: '+id);
  popWin("photoGallery", "../PhotoGallery/MLSPhoto.htm?id=" + id, 740, 470, "no", "no", "no", "yes", "no", "no", "yes");
}
