var elementToCenter = 'page';

window.onload = setUp;
window.onresize = setUp;

function setUp(){
    setContent();    
    externalLinks();
}

function setContent(){
//	if (document.getElementById) {
//		var windowHeight = getWindowHeight();
//		if (windowHeight > 0) {
//			var contentElement = document.getElementById(elementToCenter);
//			var contentHeight = contentElement.offsetHeight;
//			if (windowHeight - contentHeight > 0) {
//				contentElement.style.position = 'relative';
//				contentElement.style.top = ((windowHeight / 2) - (contentHeight / 2)) + 'px';
//			}
//			else {
//				contentElement.style.position = 'static';
//			}
//		}
//	}
}

function externalLinks() { 
 if (!document.getElementsByTagName) return; 
 var anchors = document.getElementsByTagName("a"); 
 for (var i=0; i<anchors.length; i++) { 
   var anchor = anchors[i]; 
   if (anchor.getAttribute("href") && 
       anchor.getAttribute("rel") == "external") 
     anchor.target = "_blank"; 
 } 
}

function getWindowHeight(){
	var windowHeight = 0;
	if (typeof(window.innerHeight) == 'number') {
		windowHeight = window.innerHeight;
	}
	else {
		if (document.documentElement && document.documentElement.clientHeight) {
			windowHeight = document.documentElement.clientHeight;
		}
		else {
			if (document.body && document.body.clientHeight) {
				windowHeight = document.body.clientHeight;
			}
		}
	}
	return windowHeight;
}

function ajaxReadString(string){
  //alert(string);
  //alert('XML as string');
  var xmlObj = null;
  if(window.XMLHttpRequest){
	  xmlObj = new XMLHttpRequest();
  } 
  else if(window.ActiveXObject){
	  xmlObj = new ActiveXObject("Microsoft.XMLHTTP");
  } 
  else{
	  return;
  }
  
  xmlObj.onreadystatechange = function(){
	if(xmlObj.readyState == 4)
	{		
	  processResponse(xmlObj.responseText);	  
	}	
  }  
  xmlObj.open ('GET', string, true);
  xmlObj.send ('');
  //document.body.style.cursor = 'wait';
}

function strtrim(string){
   //Remove leading spaces
   while(string.charAt(0) == " ")
      string = string.substring(1, string.length);

   //Remove trailing spaces
   while(string.charAt(string.length-1) == " ")
      string = string.substring(string, string.length-1);

   return string;
}

function processResponse(obj){
	//alert(obj);
	var strcontenthtml = null;
	strcontenthtml = obj;
	document.getElementById('content').innerHTML = "";
	document.getElementById('content').innerHTML = strtrim(strcontenthtml);
	externalLinks();
	//alert(document.getElementById('footer').innerHTML);
	//document.body.style.cursor = 'default';
}

function create_window(url){

	//alert('create window');
	//add some pixels to the width and height
	var width = 0;
	var height = 0;

	//if the window is already open resize it to the new dimensions
	if (window.popup_window && !window.popup.closed){
		window.popup_window.resizeTo(width, height);
	} 

	width = width + 60;
	height = height + 100;
	//default window specs
	var window_specs = "location=no, scrollbars=no, menubars=no, toolbars=no, resizeable=yes, left=110px, top=90px, width=" + width + ", height=" + height;
	
	width = 60;
	height = 60;
	window_specs = "location=no, scrollbars=no, menubars=no, toolbars=no, resizeable=yes, left=110px, top=90px, width=340px, height=120px";
	
	//alert(window_specs);
	//popup_window = window.open(url, window_specs);
	//popup_window.focus();
	//'window.open(welcome.html','welcome','width=300,height=200')
	window.open(url,'welcome',window_specs);
	return false;
}