var tmp_function_default = window.onload;

window.onload = function()
{
	if(tmp_function_default!=null)
		tmp_function_default(); // do not erase previous functions
	
	update_external_links();
}

function update_external_links()
{
	if(!document.getElementsByTagName) return;
	var anchors = document.getElementsByTagName("a");

	for(var i=0; i<anchors.length; i++)
	{	
		var link = anchors[i].getAttribute("href");
		var href = link.replace('http://'+location.hostname+'/', '/'); // IE
		
		if(href.substr(0, 7)=='http://')
			anchors[i].target = "_blank";
	}
}

function get_email(name, domain)
{
	var email=name+'@'+domain;
	return "<a href='mailto:"+email+"'>"+email+"</a>";
}


//<img style='visibility: hidden' width='WWW' height='HHH' alt='' onload='scale_image(this, WWW, HHH)' src='' />
function scale_image(obj, bound_width, bound_height, stretch)
{
	var x_ratio = 1;
	var y_ratio = 1;
	var stretch = (stretch==null)?false:true;
	
	// IE does not have naturalWidth and naturalHeight
	obj.removeAttribute('width');
	obj.removeAttribute('height');

	var width 	= obj.naturalWidth || obj.width;
	var height 	= obj.naturalHeight || obj.height;

	if(bound_width>0 && (width>bound_width || (stretch && width>=height)))
		x_ratio=bound_width/width;
	
	width  = Math.round(width*x_ratio*10)/10;
	height = Math.round(height*x_ratio*10)/10;

	if(bound_height>0 && (height>bound_height || (stretch && height>=width)))
		y_ratio=bound_height/height;
	
	width  = Math.round(width*y_ratio*10)/10;
	height = Math.round(height*y_ratio*10)/10;

	obj.style.width		 = Math.round(width)+'px';
	obj.style.height	 = Math.round(height)+'px';
	obj.style.visibility = 'visible';
}

function clearFileInputField(id) {
    var elem = document.getElementById( id );
    elem.parentNode.innerHTML = elem.parentNode.innerHTML;
}

/**********************************************************************/

function hide_me() { return hide_object(this); }
function hide_id(id) { return hide_object(document.getElementById(id)); }
function hide_object(obj) { obj.style.display='none'; return false; }

function show_me() { return show_object(this); }
function show_id(id) { return show_object(document.getElementById(id)); }
function show_object(obj) { obj.style.display='block'; return false; }