// onload will process an array we can push any functions to that we want
var old = window.onload; // catch any existing onload calls 1st
window.onload = function (e) {
  if (old) { // execute existing onloads
    old(e);
  };
  for (var ii = 0; arguments.callee.actions.length > ii; ii++) {
    arguments.callee.actions[ii](e);
  };
};
window.onload.actions = [];

function fixLinks()
{
	if (!document.getElementsByTagName) return null;
	var server = document.location.hostname;
	var anchors = document.getElementsByTagName("a");
	var id, href, title;
	for(var i=0; i < anchors.length; i++){
	if(!anchors[i].href) continue;
		href = anchors[i].href;
		title = anchors[i].title;
		id = anchors[i].id;
		if(href.indexOf(server) == -1){ // Href is not a file on my server
			if(href.indexOf("javascript:") == -1){ // Href is not a javascript call
				if(!anchors[i].onclick){ // Href does not have an onclick event
					if(href.indexOf("mailto:") == -1){ // Href is not a mailto:
						if((href.indexOf("http://") != -1) || (href.indexOf("https://") != -1)){ // Href is not relative (for Safari)
							anchors[i].setAttribute("target","_blank");
							anchors[i].setAttribute("title",title + " [This Link Will Open in a New Window]");
						}
					}
				}
			}
		}
	}
	
	//DO THE SAME FOR FORMS

	var forms = document.getElementsByTagName("form");
	for(var i=0; i < forms.length; i++){
	if(!forms[i].action) continue;
		href = forms[i].action;
		title = forms[i].title;
		id = forms[i].id;
		if(href.indexOf(server) == -1){ // Href is not a file on my server
			if((href.indexOf("http://") != -1) || (href.indexOf("https://") != -1)){ // Href is not relative (for Safari)
				forms[i].setAttribute("target","_blank");
			}
		}
	}
	return null;
}
window.onload.actions.push(fixLinks);


window.onresize = resizeContent;

function resizeContent(){
	chromeWidth = 226;
	chromeHeight = 154;


	var x,y;
	if (self.innerHeight) // all except Explorer
	{
		x = self.innerWidth;
		y = self.innerHeight;
	}
	else if (document.documentElement && document.documentElement.clientHeight)
		// Explorer 6 Strict Mode
	{
		x = document.documentElement.clientWidth;
		y = document.documentElement.clientHeight;
	}
	else if (document.body) // other Explorers
	{
		x = document.body.clientWidth;
		y = document.body.clientHeight;
	}

	// FIND OUT IF THERE IS A TITLE FOR THIS PAGE
	
	if($("#t_content/h1").size()) chromeHeight+=76; // Add the title area in to the "chrome" if it's there.
	
	contentWidth = x - chromeWidth;
	contentHeight = y - chromeHeight;
	
	if (document.getElementById("t_scrollable_content")){
		document.getElementById("t_scrollable_content").style.overflow = "auto";
		document.getElementById("t_scrollable_content").style.height = contentHeight+"px";
		//document.getElementById("t_scrollable_content").style.width = contentWidth+"px";
		document.getElementById("t_scrollable_content").style.margin = "0";
		document.getElementById("t_scrollable_content").style.padding = "0";
	
		/*if(document.getElementById("t_content_sidebar")){
			$(document.getElementById("t_content_sidebar")).filter(".t_show_details").css({height:((document.getElementById("t_scrollable_content").clientHeight)+"px")});
		}*/
	}

}
window.onload.actions.push(resizeContent);
//window.onload.actions.push(resizeContent); // do it a second time to make sure it looks right (mostly for Safari)
