window.onload 	= initialize_page;

function popUp(URL)
{
	day = new Date();
	id = day.getTime();
	eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=640,height=380,left = 300,top = 200');");
}

function MM_jumpMenu(targ,selObj,restore)
{ //v3.0
  popUp(selObj.options[selObj.selectedIndex].value);
  //eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}



/**********************************************************************/
function initialize_page()
{
	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';
}



/**********************************************************************/
// usage <div onMouseOut="fixOnMouseOut(this, event, 'JavaScript Code');">So many childs</div>

function is_child_of(parent, child)
{
	if(child!=null)
	{
		while(child.parentNode)
		{
			if(child.parentNode==parent)
				return true;
			else
				child = child.parentNode;
		}
	}
	return false;
}

function fixOnMouseOut(element, event, JavaScript_code)
{
	var current_mouse_target = null;

	if(event.toElement)
		current_mouse_target = event.toElement;
	else if(event.relatedTarget)
		current_mouse_target = event.relatedTarget;

	if(!is_child_of(element, current_mouse_target) && element != current_mouse_target )
		eval(JavaScript_code);
}
/**********************************************************************/

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; }
