// JavaScript Document

function resizeRight(){
	//alert("contact");
	var offset = 0;
	var leftDiv = document.getElementById("leftDiv");
	var rightDiv = document.getElementById("rightDiv");
	//alert(rightDiv.offsetHeight);
	if(leftDiv.offsetHeight > 440){
		rightDiv.style.height = (leftDiv.offsetHeight+offset)+"px";
	} else {
		rightDiv.style.height = "500px";
		leftDiv.style.height = "500px";
		document.getElementById("contentDiv").style.height = "376px";
		document.getElementById("uiDiv").style.height = "386px";
	}
}

function resizeSideBar(){
	var offset = -2;
	var subNav = document.getElementById("uiDiv");
	var contentWrapper = document.getElementById("contentWrapper");
	//alert(subNav.offsetHeight+", "+contentWrapper.offsetHeight);
	if(subNav != null && contentWrapper != null){
		//alert(subNav.offsetHeight+", "+contentWrapper.offsetHeight);
		if(subNav.offsetHeight > contentWrapper.offsetHeight){
			contentWrapper.style.height = (subNav.offsetHeight-12)+"px";
			offset = 0;
		} else {
			subNav.style.height = (contentWrapper.offsetHeight+2)+"px";
		}
	}
	var leftDiv = document.getElementById("leftDiv");
	var rightDiv = document.getElementById("rightDiv");
	
	if (leftDiv.offsetHeight > 440){
		rightDiv.style.height = (leftDiv.offsetHeight+offset)+"px";
	} else {
		var contentDiv = document.getElementById("contentDiv");
		resizeRight();
		//rightDiv.style.height = "442px";
		//leftDiv.style.height = "440px";
		if(contentDiv != null){
			//contentDiv.style.height = "316px";
		}
		//setTimeout("resizeRight()",5);
		setTimeout("resizeRight()",500);
		setTimeout("resizeRight()",1000);
	}
}

function GetWidth() {

        var x = 0;
        if (self.innerHeight)
        {
                x = self.innerWidth;
        }
        else if (document.documentElement && document.documentElement.clientHeight)
        {
                x = document.documentElement.clientWidth;
        }
        else if (document.body)
        {
               x = document.body.clientWidth;
        }
        return x;
}

function central(){
	var w = GetWidth();
	if (w > 1000){
	var prim = document.getElementById("primaryDiv");
	var l = (w-1000)/2;
	prim.style.left = l+"px";
	}
}

function OpenLittleWindow(theurl){
	OpenWin = this.open(theurl, "info", "toolbar=no,menubar=no,location=no,scrollbars=yes,resizable=yes,width=475,height=400");
}

function emailFriend(){
	var ref = location.href;
	var email = "";
	var subject = "Wanted to tell you about Rehabcare";
	var title = document.title;
	var body_message = "I thought you'd like to read <a href='"+ref+"' target='_blank'>"+title+"</a> at "+ref;
	
	var mailto_link = 'mailto:'+email+'?subject='+subject+'&body='+body_message;
	
	win = window.open(mailto_link,'emailWindow');
	if (win && win.open &&!win.closed) win.close();
}


window.onresize = central;


