﻿// JScript File
function getElementsByClassName(strClass, strTag, objContElm) {
  strTag = strTag || "*";
  objContElm = objContElm || document;    
  var objColl = objContElm.getElementsByTagName(strTag);
  if (!objColl.length &&  strTag == "*" &&  objContElm.all) objColl = objContElm.all;
  var arr = new Array();                              
  var delim = strClass.indexOf('|') != -1  ? '|' : ' ';   
  var arrClass = strClass.split(delim);    
  for (var i = 0, j = objColl.length; i < j; i++) {                         
    var arrObjClass = objColl[i].className.split(' ');   
    if (delim == ' ' && arrClass.length > arrObjClass.length) continue;
    var c = 0;
    comparisonLoop:
    for (var k = 0, l = arrObjClass.length; k < l; k++) {
      for (var m = 0, n = arrClass.length; m < n; m++) {
        if (arrClass[m] == arrObjClass[k]) c++;
        if ((delim == '|' && c == 1) || (delim == ' ' && c == arrClass.length)) {
          arr.push(objColl[i]); 
          break comparisonLoop;
        }
      }
    }
  }
  return arr; 
}

// To cover IE 5 Mac lack of the push method
Array.prototype.push = function(value) {this[this.length] = value; };

function AddFavourite() {
    
}

function GoToUrl(url) {
    window.location = url;
}

function AddToFavourites(url,title) {
    if (window.sidebar) { // Mozilla Firefox Bookmark
        window.sidebar.addPanel(title, url,"");
	} else if( window.external ) { // IE Favorite
        window.external.AddFavorite( url, title); 
    } else if(window.opera && window.print) { // Opera Hotlist
        return true; 
    }
}
function LoadPageUrl(url) {
    var newHTML = "<iframe id='propertyFrame' src='" + url + "' width='100%' scrolling='no' frameborder='0' height='850'></iframe>";
    document.getElementById("detailPane1").innerHTML = newHTML;
    document.getElementById("detailPane2").style.display = 'none';
}

function LoadVTourUrl(){
    return true;
}
function LoadVTour(url) {
    var newHTML = "<iframe id='propertyFrame' src='" + url + "' width='100%' scrolling='no' frameborder='0' height='390'></iframe>";
    obj = document.getElementById("detailPane1").innerHTML = newHTML;
    
    //obj = document.getElementById("detailAddress");
    void('0');
    //if (obj != null) obj.style.display = "none";
}

function LoadFloorplan(propid) {
    var newHTML = "<iframe id='propertyFrame' onload='levelCols();' src='/images/properties/floorplans/" + propid + ".gif' width='100%' scrolling='no' frameborder='0' height='633'></iframe>";
    var obj = document.getElementById("detailPane1").innerHTML = newHTML;
    
    //obj = document.getElementById("detailAddress");
    void('0');
    //if (obj != null) obj.style.display = "none";
}

function LoadSlideshow(url) {
    var newWin = window.open(url,"slideshow","width=830,height=430");
}

function OpenWindow(url) {
    var newWin = window.open(url,"window","width=800,height=600,resizable=yes,scrollbars=yes");
}

function LoadSmsAgentForm(url) {
    var newWin = window.open(url,"smsform","width=600,height=560");
}

function LoadSmsAgentForm(url) {
    var newWin = window.open(url,"smsform","width=600,height=560");
}

function LoadEmailAgentForm(url) {
    var newWin = window.open(url,"emailform","width=600,height=560");
}
function LoadSubscribeForm(url) {
    var newWin = window.open(url,"subscribeform","width=600,height=480");
}

function LoadSendToFriendForm(url) {
    var newWin = window.open(url,"sendtofriendform","width=600,height=570");
}

/* This set is used for listings and detail pages */
	function levelHeights (objidContent,objidRightCol) {
		if (document.layers) {
			
		} else if (document.getElementById) {
			ContentCol = document.getElementById(objidContent);	
			RightCol = document.getElementById(objidRightCol)
			
			//alert("ContentCol: " + ContentCol.offsetHeight);
			//alert("RightCol: " + RightCol.offsetHeight);
			
			if (ContentCol == null) return;

			if (ContentCol.offsetHeight < RightCol.offsetHeight) {
				ContentCol.style.height = RightCol.offsetHeight + "px";	
			}
			if (RightCol.offsetHeight < ContentCol.offsetHeight) {
				RightCol.style.height = ContentCol.offsetHeight + "px";
			} 
		}
	}

	function levelCols() {
		levelHeights('leftcolwrapper','rightcolwrapper');
	}

    function levelPropertyCols() {
		if (document.layers) {
			
		} else if (document.getElementById) {
			ContentCol = document.getElementById('leftcolwrapper');	
			RightCol = document.getElementById('rightcolwrapper')
			
			DetailPane1 = document.getElementById("detailPane1");
			//alert(DetailPane1.offsetHeight);
			if (DetailPane1 == null) return;
			
		    ContentCol.style.height = DetailPane1.offsetHeight + "px";
			//alert(ContentCol.offsetHeight);
			RightCol.style.height = DetailPane1.offsetHeight + 8 + "px";
			//alert(RightCol.offsetHeight);
		}
    }
	
	function levelHeightsContent (objidContent,objidRightCol) {
		if (document.layers) {
			
		} else if (document.getElementById) {
			ContentCol = document.getElementById(objidContent);	
			RightCol = document.getElementById(objidRightCol)
			//alert(ContentCol.offsetHeight);
//			alert(RightCol.offsetHeight);
			if (ContentCol == null) return;

			if (ContentCol.offsetHeight < RightCol.offsetHeight) {
				//ContentCol.style.height = RightCol.offsetHeight-157 + "px";	
				ContentCol.style.height = RightCol.offsetHeight-8 + "px";	
			}
			if (RightCol.offsetHeight < ContentCol.offsetHeight) {
				RightCol.style.height = ContentCol.offsetHeight + "px";	
			} 
	//		alert(ContentCol.offsetHeight);
		//	alert(RightCol.offsetHeight);
		}
	}

	function levelColsContent() {
        obj = document.getElementById('rightcolwrapper');
		levelHeightsContent('leftcolwrapper','rightcolwrapper');
		arr = getElementsByClassName('content','div',obj);
		arr[0].style.height = obj.offsetHeight  + "px";
		obj1 = document.getElementById('rightbody');
		obj1.style.height= obj.offsetHeight-56 + "px";
	}
	var iframeids=["propertyFrame"];

	function resizeCaller() {
		for (i=0; i<iframeids.length; i++){
			resizeIframe(iframeids[i]);
		}
	}

	function resizeIframe(frameId) {
		var f = document.getElementById(frameId);
		var h = "";
		if (f== null) return false;
		
		if ( f.contentDocument ) {
			h = f.contentDocument.documentElement.offsetHeight + 20 + "px";
			f.setAttribute( "height", h );
			f.parentNode.setAttribute( "height", h );
		} else if ( f.contentWindow ) {
			h = f.contentWindow.document.body.scrollHeight + 5 + "px";
			f.setAttribute( "height", h );
			f.parentNode.setAttribute( "height", h );
		} 
	}
	
	
	function limitReached(txtObj,charLimit) {
		return (txtObj.value.length > charLimit);
	}
	function updateCharsLeft(txtObj,statusObjId,charLimit) {
		if (limitReached(txtObj,charLimit)) {
			alert("Character limit reached");
			txtObj.value = txtObj.value.substring(0,charLimit);
			return;
		}
		var obj = document.getElementById(statusObjId);
		var txt = document.createTextNode(charLimit - txtObj.value.length + "");
		obj.replaceChild(txt,obj.childNodes[0]);
	}
