//shows and dom element and show another. both elements are optional

function showhide( idHide , idShow )
{
	if( idHide != null )
		dojo.html.hide( dojo.byId( idHide ) );
	if( idShow != null )
		dojo.html.show( dojo.byId( idShow ) );
}

function show_hide_region( id )
{
	if( id != null )
		if( dojo.html.isShowing( dojo.byId( id ) ) )
			dojo.html.hide( dojo.byId( id ) );
		else
			dojo.html.show( dojo.byId( id ) );
}


var activePopup = null;

function hide_active_popup()
{
	if(activePopup!=null)
	{
		var nodeActive = dojo.byId(activePopup);
		if(nodeActive != null)
			hide_popup( activePopup );
	}
}

function hide_popup( id )
{
	if( id == null )
		return;

	var htmlnode =  dojo.byId( id );
	if( !htmlnode )
		return;

	if( dojo.html.isShowing( htmlnode ) )
		{
		dojo.html.hide( htmlnode );
		activePopup=null;
		eval("clearTimeout(menu_timer_"+id+");");
		return;
		}
}

function show_as_popup( id )
{
	if( id == null )
		return;

	var htmlnode =  dojo.byId( id );
	if( !htmlnode )
		return;

	var poz = dojo.html.getAbsolutePosition( htmlnode.parentNode, true );

	htmlnode.style.top = (poz.y+15)+"px";
	htmlnode.style.left = poz.x+"px";

	if(activePopup!=null)
	{
		var nodeActive = dojo.byId(activePopup);
		if(nodeActive != null)
			hide_popup( activePopup );
	}
	activePopup = id;

	dojo.html.show( htmlnode );
	eval('clearTimeout(menu_timer_'+id+'=0);');
	eval("menu_timer_"+id+"=setTimeout('hide_popup(\""+id+"\")',2000);");
}

var main_menu_active_item = null;
function show_hide_menu_action( id )
{
	node = dojo.byId( id );
	if( node != null)
	{
		if( dojo.html.isShowing(node) )
		{
			dojo.html.hide( node );
		}
		else
		{
			if( main_menu_active_item != null )
				dojo.html.hide( dojo.byId( main_menu_active_item ) );
			dojo.html.show( node );
			main_menu_active_item = id;
		}
	}
}

function gotopage( url )
{
	page = url;
	if( dojo.string.startsWith( url, "page:", true) )
		page = page.substr(5);
	window.location = page;
}

function gotonewpage( url )
{
	page = url;
	if( dojo.string.startsWith( url, "newpage:", true) )
		page = page.substr(8);

	var newwin = window.open(url,'mywindow','width=1024,height=768,toolbar=yes,location=yes,directories=yes,status=yes,menubar=yes,scrollbars=yes,copyhistory=yes,resizable=yes');

	if(!newwin)
		window.location = url;
}

function goinpage( anchor )
{
	url = ''+window.location;
	pos = url.lastIndexOf('#');
	if(pos>-1)
		url = url.substring(0,pos)+"#"+anchor;
	else
		url = url+"#"+anchor;
	window.location = url;
}

function getRadioValue( parent )
{
	/*var user_input = null;
	for (i=0;i<radio.length;i++)
	{
		if (radio[i].checked)
		{
			user_input = radio[i].value;
			break;
		}
	}
	return user_input;*/
	var radios = dojo.html.getElementsByClass("formradiob",parent,"input");
	var i = 0;
	var retval = "";

	for( i = 0; i < radios.length; i++ )
	{
		if( radios[i].checked )
		{
			retval += dojo.html.getAttribute( radios[i], "value" );
			break;
		}
	}
	return retval;
}

function cloasetoast()
{
	//alert('aa'+et);
	et.hide();
}

function toast( text )
{
	var text = '<div class="toasterclosebut"><a id="toastcloseb" onclick="cloasetoast()">close</a></div>' + text;

	dojo.event.topic.publish('maintoaster', {message:text,type:'MESSAGE',delay:20000});

	//dojo.connect(dojo.byId('toastcloseb'),'onclick','cloasetoast()');
}

//PB// dom tree functions
function p_descendantTest(suspectedParent, suspectedChild) //function that tests if suspectedChild is a descendent of suspectedParent (not necesarily direct descendent)
	{
	if (!suspectedChild || suspectedChild==document.body || suspectedChild==document.documentElement) return false;
	else
	  {
	  if (suspectedParent==suspectedChild) return true;
	  else return p_descendantTest(suspectedParent, suspectedChild.parentNode);
	  }
	}

//PB// event canceling functions
function p_stopTriggerInside(element, handler, event)
	{
	if (element.addEventListener && !p_descendantTest(element, event.relatedTarget))
	  handler(event);
	else if (element.attachEvent && !p_descendantTest(element, ((window.event.type=="mouseover")?window.event.fromElement:window.event.toElement)))
	  handler(window.event);
	}