//---| GLOBAL JAVASCRIPT FUNCTIONS |---


//---| IMAGE RESIZING |--------------------------------------------------------------
function ImageResize(imgname,imgwidth,imgheight){
	if(imgname.width>imgwidth){
		imgname.height = imgname.height*(imgwidth/imgname.width);
		imgname.width = imgwidth;
	}
	if(imgname.height>imgheight){
		imgname.width = imgname.width*(imgheight/imgname.height);
		imgname.height = imgheight;
	}
}


//---| POPUPS |----------------------------------------------------------------------
function openPhoto(baseURL){
	window.open(baseURL,"","top=20,left=20,width=720,height=580,toolbar=no,status=no,directories=no,menubar=no,resizable=yes,scrollbars=yes");
}
function openFloorPlan(baseURL){
	window.open(baseURL,"","top=20,left=20,width=720,height=580,toolbar=no,status=no,directories=no,menubar=no,resizable=yes,scrollbars=yes");
}
function openVirtualTour(baseURL){
	window.open(baseURL,"","top=20,left=20,width=550,height=450,toolbar=no,status=no,directories=no,menubar=no,resizable=yes,scrollbars=yes");
}
function openMail(baseURL) {
	window.open(baseURL,"","top=20,left=20,width=400,height=480,toolbar=no,status=no,directories=no,menubar=no,resizable=no,scrollbars=no");
}
function openPrint(baseURL) {
	window.open(baseURL,"","top=20,left=20,width=720,height=640,toolbar=no,status=no,directories=no,menubar=no,resizable=yes,scrollbars=yes");
}
function openCell(baseURL) {
	window.open(baseURL,"","top=20,left=20,width=400,height=420,toolbar=no,status=no,directories=no,menubar=no,resizable=no,scrollbars=no");
}
function openMap(baseURL) {
	window.open(baseURL,"","top=20,left=20,width=640,height=570,toolbar=no,status=no,directories=no,menubar=no,resizable=no,scrollbars=no");
}

//---| Window Scroll |---------------------------------------------------------------

		function scroll()
        {

            var MapTop = RecurseOffset(document.getElementById("mapBorder")).offsetTop;
            if (document.documentElement)
            {
                var scrollTop = document.documentElement.scrollTop;
            }
            else
            {
                var scrollTop = document.body.scrollTop;
            }
            if (MapTop != null)
            {
                window.scrollTo(0,MapTop);
            }

        }


        function RecurseOffset(obj)
        {
            if (GetType(obj)=="string")
            {
                if (document.getElementById(obj)==null)
                {
                    alert("RecurseOffset requires a valid DOM object");
                }
                else
                {
                    obj = document.getElementById(obj);
                }
            }
           var ROO = new RecurseOffsetObject(obj);
           var Offsets = new Object();
               Offsets.offsetLeft   = ROO.GetOffsetLeft();
               Offsets.offsetTop    = ROO.GetOffsetTop();
               Offsets.offsetWidth  = ROO.GetOffsetWidth();
               Offsets.offsetHeight = ROO.GetOffsetHeight();
           
           return Offsets;
        }


        function GetType(Element)
        {
	        if (Element==null)
	        {
		        return "null";
	        }
	        if (Element.constructor == null)
	        {
		        return "object";
	        }
	        else
	        {
		        var Catches = Element.constructor.toString().toLowerCase().match(/([a-z0-9]+)(\(\))/i);
		        if (Catches != null)
		        {
			        return Catches[1];
		        }
		        else
		        {
			        return "unknown";
		        }
	        }
        }

        function RecurseOffsetObject(obj)
        {
	        this.ParentObj = null;
	        this.CurrentObj = obj;
            this.offsetLeft = obj.offsetLeft;
            this.offsetTop = obj.offsetTop;
            this.offsetWidth = obj.offsetWidth;
            this.offsetHeight = obj.offsetHeight;
            
	        RecurseOffsetObject.prototype.Init = function()
	        {
	            if (this.CurrentObj.offsetParent != null)
	            {
	                do
		            {
                        this.ParentObj = this.CurrentObj.offsetParent;
                        this.offsetLeft += this.ParentObj.offsetLeft;
                        this.offsetTop += this.ParentObj.offsetTop;
                        this.CurrentObj = this.ParentObj;
		            }
		            while (this.CurrentObj.offsetParent != null);
	            }
	        };
	        RecurseOffsetObject.prototype.GetOffsetLeft = function(){ return this.offsetLeft; };
	        RecurseOffsetObject.prototype.GetOffsetTop = function(){ return this.offsetTop; };
	        RecurseOffsetObject.prototype.GetOffsetWidth = function(){ return this.offsetWidth; };
	        RecurseOffsetObject.prototype.GetOffsetHeight = function(){ return this.offsetHeight; };
	        this.Init();
        }