
/* ******************************************************************************************************************************************
************************************************* ussas_mp *******************************************************************************
****************************************************************************************************************************************** */

function	ussas_mp()
{
   var __isFireFox = navigator.userAgent.match(/gecko/i);  
	//---------------------------------------------------------------
	function xGetElementById(e)
	{
	  if(typeof(e)=='string') {
		 if(document.getElementById) e=document.getElementById(e);
		 else if(document.all) e=document.all[e];
		 else e=null;
	  }
	  return e;
	}
	//---------------------------------------------------------------
	function xGetElementsByTagName(t,p)
	{	var list = null;
		t = t || '*';
		p = xGetElementById(p) || document;
		if (typeof p.getElementsByTagName != 'undefined') { // DOM1
			list = p.getElementsByTagName(t);
			if (t=='*' && (!list || !list.length)) list = p.all; // IE5 '*' bug
		}
		else { // IE4 object model
			if (t=='*') list = p.all;
			else if (p.all && p.all.tags) list = p.all.tags(t);
		}
		return list || [];
	}
	//---------------------------------------------------------------
	this.xGetElementsByClassName=function (c,p,t,f)
	{	
		return xGetElementsByClassName(c,p,t,f);
	}
	//---------------------------------------------------------------
	function xGetElementsByClassName(c,p,t,f)
	{	var r=new Array();
		var re=new RegExp("(^|\\s)"+c+"(\\s|$)");
		var e=xGetElementsByTagName(t,p);
		
		for(var i=0;i<e.length;++i)
		{	if(re.test(e[i].className))
			{	r[r.length]=e[i];
				if(f)
					f(e[i]);
			}
		}
		return r;
	}
	//---------------------------------------------------------------
	function xPageY(e)
	{	var y = 0;
		//e = xGetElementById(e);
		while (e) 
		{	y += e.offsetTop;
			e = e.offsetParent;
		}
		return y;
	}
	//---------------------------------------------------------------
	this.addLoadEvent = function(func) 
	{
		var oldonload = window.onload; 
		if (typeof window.onload != 'function') 
			window.onload = func; 
		else 
		{	window.onload = function() 
			{	if (oldonload) 
			  		oldonload(); 
				func(); 
			} 
		} 
	} 
	//---------------------------------------------------------------
	this.RemoveElement = function(id)
	{	var obj=xGetElementById(id);
		if (obj==null)
			return;
		var parent = obj.parentNode;	
		if (parent==null)
			return;
		parent.removeChild(obj);
	}
	//---------------------------------------------------------------
	this.AutoBorder = function(objid)
	{	
		var obj=xGetElementById(objid);
		if (obj==null)
			return;
			
		var template=xGetElementById("mp_border_1");
		if (template==null)
			return;

		var newborder=template.cloneNode(true);
		newborder.id='';
		newborder.style.display='';

		var div=xGetElementsByClassName("mp_border_body",newborder,"div")[0];
		var cloneobj=obj.cloneNode(true);
		var parent = div.parentNode;
		parent.replaceChild(cloneobj,div);
	
		parent = obj.parentNode;
		parent.replaceChild(newborder,obj);
	}
	//---------------------------------------------------------------
	this.AdjustBottom = function(slots)
	{	var bottom=0;
		var sl;
		var y;
		var i;
		
		if (typeof(slots)=='undefined')
			return;
		
		for (i=0;i<slots.length;i++)
		{	sl=slots[i]=xGetElementById(slots[i]);
			if (sl==null)
			{	alert("he he");
				return;
			}
			y=xPageY(sl);
			if (y+sl.offsetHeight > bottom)
				bottom=y+sl.offsetHeight;
		}
		//alert("bottom: "+bottom);
		for (i=0;i<slots.length;i++)
		{	sl=slots[i];
			y=xPageY(sl);
			if (y+sl.offsetHeight < bottom)
			{	var inc=bottom-y-sl.offsetHeight;
				/*
				var padding=parseInt(sl.style.paddingBottom.replace("px",""));
				//document.write(inc+", "+padding+"<br>");
				inc+=padding;
				sl.style.paddingBottom=inc+"px";
				//document.write("padding: "+sl.style.paddingBottom+"<br>");
				*/
				//sl.innerHTML=sl.innerHTML+'<div style="height:'+inc+'px;clear:both"></div>';
				pillow=document.createElement("div");
				pillow.style.height=inc+"px";
				pillow.style.clear="both";
				sl.appendChild(pillow);
			}
		}
	}
	//---------------------------------------------------------------
	this.FindActiveMenu = function(MenuName)
	{	var Lis=xGetElementsByTagName("li",MenuName); 

		for (var i=0;i<Lis.length;i++)
		{	if (Lis[i].className=="active")
				break;
		}
		if (i==Lis.length)
			return -1;
		return i;
	}
	//---------------------------------------------------------------
	this.ModifyDateLine = function(p)
	{	var objs=xGetElementsByTagName("label",p);
		if (objs==null || objs.length==0)
			return;
		for (var i=0;i<objs.length;i++)
		{	if (objs[i].className=="dateline")
				break;
		}
		if (i==objs.length)
			return;
		
		objs=xGetElementsByTagName("span",objs[i]);
		if (objs==null || objs.length!=2)
			return;
		objs[0].style.display="none";
		/*
		objs[2].style.display="none";
		objs[1].nextSibling.nodeValue="";
		objs[1].previousSibling.nodeValue="";
		*/
		objs[0].nextSibling.nodeValue="";
		
	}
	//---------------------------------------------------------------
	this.CorrectPageBottom= function()
	{	var fixed_slot;

		fixed_slot=xGetElementById("powered-bottom");
		var line1=xGetElementById("powered-bottom-line-1");
		var line2=xGetElementById("powered-bottom-line-2");
		bottom_slot=xGetElementById("bottom_line");
		if (fixed_slot==null || line1==null || line2==null || bottom_slot==null)
			return;

		var objs=xGetElementsByTagName("div",bottom_slot);
		if (objs==null || objs.length!=3)
			return;
		objs[0].style.float="right";
		objs[1].style.float="right";
		objs[1].style.clear="right";
		
		line1.innerHTML=objs[0].innerHTML;
		line2.innerHTML=objs[1].innerHTML;
		this.RemoveElement("bottom_line");
		fixed_slot.id="bottom_line";
	}
	//---------------------------------------------------------------
	this.MakeImageTile= function(slot)
	{	var imgs=xGetElementsByTagName("img",slot);
		var template;

		for (var i=0;i<imgs.length;i++)
		{	var align=imgs[i].getAttribute('align');
			var alt=imgs[i].getAttribute('alt');
			
			switch (align)
			{	
				case 'middle':
					template=xGetElementById("mp_img_center");
					break;
				case 'right':
					template=xGetElementById("mp_img_right");
					break;
				default:
					template=xGetElementById("mp_img_left");
					break;
				
			}
			if (template==null)
				return;

			var newborder=template.cloneNode(true);
			newborder.id='';
			newborder.style.display='';
			newborder.style.styleFloat=newborder.style.cssFloat=+imgs[i].getAttribute('align');
			newborder.style.width=imgs[i].getAttribute('width')+'px';
			//var div=xGetElementsByClassName("mp_img_body",newborder,"div")[0];
			var div=xGetElementsByTagName("div",newborder)[0];
			var p=xGetElementsByTagName("p",newborder)[0];
			if (alt!=null && alt!="")
				p.innerText=alt;
			else
				newborder.removeChild(p);
				
			var cloneobj=imgs[i].cloneNode(true);
			cloneobj.removeAttribute('align');
			
			var parent = div.parentNode;
			parent.replaceChild(cloneobj,div);
		
			parent = imgs[i].parentNode;
			parent.replaceChild(newborder,imgs[i]);
		}
	}
}
