
/* Opens popup window  */
function opener(page)
{
  window.open(page, "popup", "location=no,menubar=no,resizable=no,width=550,height=580,scrollbars=yes");
}

/* Opens popup window */
function NewWindow(mypage, myname, w, h, scroll) 
{
  var winl = (screen.width - w) / 2;
  var wint = (screen.height - h) / 2;
  winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars='+scroll+',resizable'
  win = window.open(mypage, myname, winprops)
  if (parseInt(navigator.appVersion) >= 4) { win.window.focus(); }
}

/* Even 'column' script
Derived from a script by Alejandro Gervasio. 
Modified to work in FireFox by Stefan Mischook for Killersites.com
Modified by Erica Melton to work in WST
How it works: just apply the CSS class of 'column' to your pages' main columns.
Add "matchColumns();" to body onload.
*/
function matchColumns()
{ 
  var divs,contDivs,maxHeight,divHeight,d; 
	
  // get all <div> elements in the document 
  divs=document.getElementsByTagName('div'); 
  contDivs=[]; 

  // initialize maximum height value 
  maxHeight=0; 

  // iterate over all <div> elements in the document 
  for(var i=0;i<divs.length;i++){ 
    // make collection with <div> elements with class attribute 'container' 
    if(/\bcolumn\b/.test(divs[i].className))
	  { 
      d=divs[i]; 
      contDivs[contDivs.length]=d; 
		
      // determine height for <div> element 
      if(d.offsetHeight)
	    { divHeight=d.offsetHeight;}
      else if(d.style.pixelHeight)
	    { divHeight=d.style.pixelHeight;} 

      // calculate maximum height 
      maxHeight=Math.max(maxHeight,divHeight); 
      } 
    } 

    // assign maximum height value to all of container <div> elements 

    for(var i=0;i<contDivs.length;i++)
	{ contDivs[i].style.height=maxHeight + "px"; } 	
} 

/* AJAX FUNCTION */
function ajaxFunction(url,divid)
  {
  var xmlHttp;
  try
    {
    // Firefox, Opera 8.0+, Safari
    xmlHttp=new XMLHttpRequest();
    }
  catch (e)
    {
    // Internet Explorer
    try
      {
      xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
      }
    catch (e)
      {
      try
        {
        xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
        }
      catch (e)
        {
        alert("Your browser does not support AJAX!");
        return false;
        }
      }
    }
    xmlHttp.onreadystatechange=function()
      {
      if(xmlHttp.readyState==4)
        {
        document.getElementById(divid).innerHTML = xmlHttp.responseText;
        }
      }
    xmlHttp.open("GET",url,true);
    xmlHttp.send(null);
  }
  
  
  
  /* Client-side access to querystring name=value pairs
	Version 1.2.3
	22 Jun 2005
	Adam Vandenberg
*/
function Querystring(qs) { // optionally pass a querystring to parse
	this.params = new Object()
	this.get=Querystring_get
	
	if (qs == null)
		qs=location.search.substring(1,location.search.length)

	if (qs.length == 0) return

// Turn <plus> back to <space>
// See: http://www.w3.org/TR/REC-html40/interact/forms.html#h-17.13.4.1
	qs = qs.replace(/\+/g, ' ')
	var args = qs.split('&') // parse out name/value pairs separated via &
	
// split out each name=value pair
	for (var i=0;i<args.length;i++) {
		var value;
		var pair = args[i].split('=')
		var name = unescape(pair[0])

		if (pair.length == 2)
			value = unescape(pair[1])
		else
			value = name
		
		this.params[name] = value
	}
}

function Querystring_get(key, default_) {
	// This silly looking line changes UNDEFINED to NULL
	if (default_ == null) default_ = null;
	
	var value=this.params[key]
	if (value==null) value=default_;
	
	return value
}


// function to determine which flash nav to show
function determineNav(){
	 var qs = new Querystring();
	 var id = qs.get("n");
	 var parent = qs.get("p");
	 if(parent != 0){
		 id = parent;
	 }
	 if(parent == 7 || parent == 8){
	 	id = 2;
	 }
	 if(parent == 9 || parent == 10 || parent == 25){
	 	id = 3;
	 }
	 
	 
	
	 return id;
}

// function to determine which flash nav to show
function checkerror(){
	 var qs = new Querystring();
	 var error = qs.get("error");
	 return error;
}


// function to determine which flash nav to show
function getPicURL(){
	 var qs = new Querystring();
	 var id = qs.get("image");
	 return id;
}


//DetectImageSize function
   function DetectImageSize(picName,picTitle){
      picURL=picName;
	  alert(picURL);
	 
      newWindow=window.open(picURL,'newWin','toolbar=no, width='+picName.width+',height='+picName.height);
      newWindow.document.write('<html><head><title>'+picTitle+'<\/title><\/head><body background="'+picURL+'"><\/body><\/html>');
      newWindow.resizeBy(picName.width-newWindow.document.body.clientWidth,picName.height-newWindow.document.body.clientHeight);
      newWindow.focus();
   } 


/* 
PHOTO GALLERY SCRIPT 1.0 
Written by Erica Melton on 8.21.2007 
For this script to work, thumbnails must be saved [filename].jpg and large images must be saved [filename]lg.jpg 
in the /images/homelistings/ folder. File: HomeListing.xsl 
PHOTO GALLERY SCRIPT 1.1
Modification made on the 28 Aug 2007, for cases where there was less than 6 images

*/
function swapImage(imgid,image,caption) 
{
	
	//document.getElementById(photo)
	document.getElementById('caption').innerHTML = caption;
	//variable for tracking last images number
	var lastimage = 0;
    //change border for all photos to match background color simulating border is turned off
    //Loop through objects, fix for missing images  DEP 28 Aug
	for(i=0; i < 9; i++)
	{
		var photo
		photo = 'photo' + i;
		if(document.getElementById(photo) != null) //check for case of less than 6 images
		{
			document.getElementById(photo).style.border = '1px solid #d1cebc';
			lastimage = i;
		}
	}

    
	//set border to current selected photo 
     document.getElementById('photo'+imgid).style.border = '1px solid #386e55';
    
	//show large photo 
     document.getElementById('largeimage').src = 'images/homephotos/'+image;
    
	//change previous link 
    // if(imgid == 1) {previmgid = 6;} else { previmgid = imgid - 1; }
	// Change made for cases when there is less than 6 images display on page DEP 28 Aug
	// lastimage tracks number of images on page
	
	 //if(imgid == 1) {previmgid = lastimage;} else { previmgid = imgid - 1; }
	 //previmage = document.getElementById('photo'+previmgid).src;
     //previndex1 = previmage.indexOf('homelistings/');
	 //previndex2 = previmage.indexOf('.jpg');
	 //previmage = previmage.substring(previndex1+13,previndex2) + 'lg.jpg';
     //document.getElementById('prevlink').innerHTML = "<a style='color:#7d7f4b;' href='#' onclick='swapImage("+previmgid+",\""+previmage+"\");return false;'>&lt; previous</a>";
	//change next link 
	 
	 //change imgid == 6  Change made for cases when there is less than 6 images display on page DEP 28 Aug
	// if(imgid == lastimage) {nextimgid = 1;} else { nextimgid = imgid + 1; }
     //nextimage = document.getElementById('photo'+nextimgid).src;
     //nextindex1 = nextimage.indexOf('homelistings/');
	 //nextindex2 = nextimage.indexOf('.jpg');
     //nextimage = nextimage.substring(nextindex1+13,nextindex2) + 'lg.jpg';
     //document.getElementById('nextlink').innerHTML = "<a style='color:#7d7f4b;' href='#' onclick='swapImage("+nextimgid+",\""+nextimage+"\");return false;'>next &gt;</a>";
}