/**
 * @author Jonas Wilson Schnack
 */
function center_object_in_window(objectID)
{
	var object = document.getElementById(objectID);
	var leftValue = 0;
	var topValue = 0;
	
	if (object.offsetWidth < get_window_width())
		leftValue = (get_window_width() - object.offsetWidth)/2;
	
	if	(object.offsetHeight < get_window_height())
		topValue = (get_window_height() - object.offsetHeight)/2;
	
	object.style.left = leftValue + "px";
	object.style.top = topValue + "px";
}

function center_object_in_window_xyMod(objectID, x, y)
{
	var object = document.getElementById(objectID);
	var leftValue = 0;
	var topValue = 0;
	
	if (object.offsetWidth < get_window_width())
		leftValue = (get_window_width() - object.offsetWidth)/2;
	
	if	(object.offsetHeight < get_window_height())
		topValue = (get_window_height() - object.offsetHeight)/2;
	
	object.style.left = (leftValue + x) + "px";
	object.style.top = (topValue + y) + "px";
}

function horizontal_center_object_in_window(objectID)
{
	var object = document.getElementById(objectID);
	var leftValue = 0;
		
	if (object.offsetWidth < get_window_width())
		leftValue = (get_window_width() - object.offsetWidth)/2;
	
	object.style.left = leftValue + "px";
}

function center_object1_in_object2(object1ID, object2ID)
{
	var object1 = document.getElementById(object1ID);
	var leftValue = 0;
	var topValue = 0;
	
	var object2 = document.getElementById(object2ID);
		
	if (object1.offsetWidth < object2.offsetWidth)
		leftValue = (object2.offsetWidth - object1.offsetWidth)/2;
	
	if	(object1.offsetHeight < object2.offsetHeight)
		topValue = (object2.offsetHeight - object1.offsetHeight)/2;
	
	object1.style.left = leftValue + "px";
	object1.style.top = topValue + "px";
}

function unhide_canvas()
{
	document.getElementById("canvas").style.visibility = "visible";
}

function get_window_width() 
{
	var winW = 0;
	if( typeof( window.innerWidth ) == 'number' ) 
	{
		//Non-IE
		winW = window.innerWidth;
	} 
	else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) 
	{
		//IE 6+ in 'standards compliant mode'
		winW = document.documentElement.clientWidth;
	} 
	else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) 
	{
		//IE 4 compatible
		winW = document.body.clientWidth;
	}
	return winW;
}

function get_window_height() 
{
	var winH = 0;
	if( typeof( window.innerHeight ) == 'number' ) 
	{
		//Non-IE
		winH = window.innerHeight;
	} 
	else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) 
	{
		//IE 6+ in 'standards compliant mode'
		winH = document.documentElement.clientHeight;
	} 
	else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) 
	{
		//IE 4 compatible
		winH = document.body.clientHeight;
	}
	return winH;
}

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 set_cookie( name, value, expiredays )
{
	var expiredate = new Date();
	expiredate.setDate( expiredate.getDate() + expiredays );
	document.cookie = name + "=" + escape( value ) +
	( ( expiredays==null ) ? "" : ";expires=" + expiredate.toUTCString() );
}

function get_cookie( name )
{
	if ( document.cookie.length > 0)
	{
		var cookieStart = document.cookie.indexOf( name + "=" );
		if ( cookieStart != - 1 )
		{
			cookieStart = cookieStart + name.length + 1;
			cookieEnd = document.cookie.indexOf( ";", cookieStart );
		    
			if ( cookieEnd == -1 ) 
		    	cookieEnd = document.cookie.length;
		    
			return unescape( document.cookie.substring( cookieStart, cookieEnd ) );
		}
	}
	return "";
}

function delete_cookie ( cookie_name )
{
  var cookie_date = new Date ( );  // current date & time
  cookie_date.setTime ( cookie_date.getTime() - 1 );
  document.cookie = cookie_name += "=; expires=" + cookie_date.toGMTString();
}
