//created by ars 2002 (mpo corrections)
function Popup(name,x,y)
{
	if (typeof window.popupDefs == "undefined")
		window.popupDefs = new Array();
	
	this.idx = window.popupDefs.length;
	window.popupDefs[window.popupDefs.length]=this;
	
	if (typeof name == "string")
	{
		
      	if((x == null || typeof(x)!="number") && (y == null))
		{
			
        	this.positioning = 1;
			popName = "pop"+this.idx;
			insertLink(popName,x);
			x=0;
			y=0;
		}
		else
			this.positioning = 0;

		this.name = name;
		this.caption = name;
		this.mainX=x;
		this.mainY=y;
		this.mainWidth = 150;
		this.mainHeight = 16;
		this.mainBgColor = "#FFFFFF";
		this.mainHlBgColor = "#A0A0A0";
		this.mainBorderColor = "#290000";
		this.mainBorderWidth = 2;
		this.mainPadding = 0;
		this.prepMainFun=null;
		this.mainTextAlign = "left";
		this.popupTextAlign = "left";
	
		this.popupRowHeight = 18;
		this.popupWidth = 170;
		this.popupBgColor = "#FFFF00";
		this.popupHlBgColor = "#A0A0A0";
		this.popupBorderColor = "#666666";
		this.popupBorderWidth = 2;
		this.popupPadding = 0;
		this.popupXOffset = 0;
		this.popupYOffset = 0;
	
		this.subelems = new Array();
		this.prepRowFun=null;
		this.onChange=null;
		
		this.mainIcon= "";
		this.mainHiIcon= "";
		this.mainIconAlign= "left";


		this.autoSort = 0;
		this.autoClose = 1;
		this.autoOpen = 0;
		this.comboMode = 0;
		this.current = -1;
		this.closed = true;
		this.autoCloseTimeout = 300;//ms
		this.anchored=false;
	}
	else
	{
		//alert(typeof name);
		this.positioning = name.positioning;
		this.name = name.name;
		this.caption = name.caption;
		this.mainX = name.mainX;
		this.mainY = name.mainY;
		this.mainWidth = name.mainWidth;
		this.mainHeight = name.mainHeight;
		this.mainBgColor = name.mainBgColor;
		this.mainHlBgColor = name.mainHlBgColor;
		this.mainBorderColor = name.mainBorderColor;
		this.mainBorderWidth = name.mainBorderWidth;
		this.mainPadding = name.mainPadding;
		this.mainTextAlign = name.mainTextAlign;
        this.prepMainFun = name.prepMainFun;

		this.popupRowHeight = name.popupRowHeight;
		this.popupWidth = name.popupWidth;
		this.popupBgColor = name.popupBgColor;
		this.popupHlBgColor = name.popupHlBgColor;
		this.popupBorderColor = name.popupBorderColor;
		this.popupBorderWidth = name.popupBorderWidth;
		this.popupPadding = name.popupPadding;
		this.popupXOffset = name.popupXOffset;
		this.popupYOffset = name.popupYOffset;
		this.popupTextAlign = name.popupTextAlign;

		this.subelems = new Array();
		this.prepRowFun = name.prepRowFun;
		this.onChange=name.onChange;
		
		this.mainHiIcon = name.mainHiIcon;
		this.mainIcon = name.mainIcon;
		this.mainIconAlign = name.mainIconAlign;

		this.autoSort = name.autoSort;
		this.autoClose = name.autoClose;
		this.autoOpen = name.autoOpen;
		this.comboMode = name.comboMode;
		this.current = name.current;
		this.closed = name.closed;
		this.autoCloseTimeout = name.autoCloseTimeout;
		this.anchored=name.anchored;
		for (var i=0;i<name.subelems.length;i++)
			this.Add(name.subelems[i].caption,name.subelems[i].action,name.subelems[i].param);
	}


	//do not set following variables outside
	this.unsorted = 1;
	this.mouseOverMain = 0; 

}



function findAnchorPos(obj,odl,type)
{

 if(type == "x")
		 odl = odl + obj.offsetLeft;
	 else if(type == "y")
			 odl = odl + obj.offsetTop;
  else
      return odl;

if(obj.offsetParent)
odl = findAnchorPos(obj.offsetParent,odl,type);
return odl;
}

function ScrollToAnchor(name)
{

if (document.layers) //NS4
{
if (name=="TOP")
{ 
window.scrollTo(window.pageXOffset, 0 );
return;
}

var anch = window.document.anchors;
for (var i = 0 ;i<anch.length;i++)
if ( name == anch[i].name )
{
		 window.scrollTo(window.pageXOffset, anch[i].y - 8 )
return;
}
window.top.status= "Anchor not found.";
}
else //IE ,MOZILLA 5
{
        if (name=="TOP")
{
window.scrollTo(window.document.body.scrollLeft,0);
return;
}
if (document.all) //ie;
{
var anch = window.document.anchors;
//alert(anch);
for (var i = 0 ; i< anch.length;i++)
{
if (anch[i].name == name)
{
window.location.hash = name;
return;
}
}

}
else
{ 
var anch = window.document.anchors; 
for (var i = 0 ; i< anch.length;i++)
{
if (anch[i].name == name)
{
anch_pos = findAnchorPos(anch[i],0,"y");
var pos = anch_pos-10; //findAnchorPos(document.anchors[i],0,"y");
window.scrollTo(window.document.body.scrollLeft,pos);
return;
}
}

}
}
window.top.status= "Anchor not found.";
return;
}






function setRow(id)
{
	if(id<20)
	{
	for(i=1;i<=18;i++)
	{
	if(i==id){
		continue;
	}
	else
	{
	document.getElementById(i).style.backgroundColor='';
	document.getElementById(i).style.color='#000000';
	}
	}

	document.getElementById(id).style.backgroundColor='#30B0E8';
	document.getElementById(id).style.color='#FFFFFF';
	}
	if(id>20&&id<30)
	{
	for(i=21;i<=24;i++)
	{
	if(i==id){		continue;	}
	else
	{
		document.getElementById(i).style.backgroundColor='';
		document.getElementById(i).style.color='#000000';
		}
	}
	document.getElementById(id).style.backgroundColor='#ff9600';
	document.getElementById(id).style.color='#FFFFFF';
	}

	if(id>30)
	{
	for(i=31;i<=33;i++)
	{
	if(i==id){
		continue;
	}
	else
	{
		document.getElementById(i).style.backgroundColor='';
		document.getElementById(i).style.color='#000000';
		}
	}
	document.getElementById(id).style.backgroundColor='red';
	document.getElementById(id).style.color='#FFFFFF';

	}
	
}

function setRow2(id)
{
	if(id<20)
	{
	for(i=1;i<=19;i++)
	{
	if(i==id){
		continue;
	}
	else
	{
	parent.document.getElementById(i).style.backgroundColor='';
	parent.document.getElementById(i).style.color='#000000';
	}
	}

	parent.document.getElementById(id).style.backgroundColor='#30B0E8';
	parent.document.getElementById(id).style.color='#FFFFFF';
	}
	if(id>20&&id<30)
	{
	for(i=21;i<=24;i++)
	{
	if(i==id){		continue;	}
	else
	{
		parent.document.getElementById(i).style.backgroundColor='';
		parent.document.getElementById(i).style.color='#000000';
		}
	}
	parent.document.getElementById(id).style.backgroundColor='#ff9600';
	parent.document.getElementById(id).style.color='#FFFFFF';
	}

	if(id>30)
	{
	for(i=31;i<=33;i++)
	{
	if(i==id){
		continue;
	}
	else
	{
		parent.document.getElementById(i).style.backgroundColor='';
		parent.document.getElementById(i).style.color='#000000';
		}
	}
	parent.document.getElementById(id).style.backgroundColor='#ec4404';
	parent.document.getElementById(id).style.color='#FFFFFF';

	}
	
}




function PopupOnClick(elem)
{
	if (this.subelems[elem].inactive)
		return;
	this.Close();
    	if (this.comboMode)
    	{
		this.caption = this.subelems[elem].caption;
		this.current = elem;
		this.FillMainLayer(0);
		this.FillMainLayer(1);
	}
	if (this.onChange)
		this.onChange(this,elem);
	var subelem =  this.subelems[elem];
	if (this.subelems[elem].action) 
		subelem.action(elem,subelem.param);
/*
	else
		alert("Popup "+window.popupDefs[id].name+ "\nSublelement: "+window.popupDefs[id].subelems[elem].caption+
			  "\n Error! There is no action "); 
*/
}

function PopupSortSubelems()
{
	var i,j;
	for (i=0;i<this.subelems.length-1;i++)
	{
        var min_idx=i;
		for (j=i+1;j<this.subelems.length;j++)
			if (this.subelems[min_idx].caption > this.subelems[j].caption)
				min_idx = j;
		var tmp = this.subelems[i];
		this.subelems[i] = this.subelems[min_idx];
		this.subelems[min_idx]=tmp;
	}
	this.unsorted=0;
}

function PopupAddSubelem(caption,action,param,refresh_layers,inactive)
{
	var elem = new Object();
    elem.caption = caption;
	elem.action = action;
	elem.param = param;
	elem.inactive = inactive;
	elem.type = 'elem';
	elem.height= this.popupRowHeight;

	this.subelems[this.subelems.length] = elem;
	this.unsorted=1;
	if (this.autoSort)
	   this.Sort();
	if (typeof this.popupLayer !="undefined" && refresh_layers)
	{
		this.RefillLayers();
	}
}
function PopupAddSeparator(type,height,refresh_layers)
{
	var elem = new Object();
    elem.inactive = 1;
    elem.caption = "";
	elem.action = null;
	elem.param = null;
	elem.type = type;
	elem.height = height?height:this.popupRowHeight;
	this.subelems[this.subelems.length] = elem;
	this.unsorted=1;
	if (this.autoSort)
	   this.Sort();
	if (this.popupLayer && refresh_layers)
	{
		this.RefillLayers();
	}
}

function PopupRemoveSubelem(num,refresh_layers)
{
	if (num < 0 || num >=this.subelems.length) return;
    for (var i = 0; i<  this.subelems.length-1;i++)
		 this.subelems[i]=this.subelems[i+1];
	this.subelems.length--;
	
    if (this.popupLayer && refresh_layers)
		this.RefillLayers();
}

function PopupRemoveAllSubelems(refresh_layers)
{
    this.subelems=new Array();
	if (this.popupLayer && refresh_layers)
		this.RefillLayers();
}

function PreprocessNS4Content(content,width,height,borderWidth,borderColor,padding,bgcolor)
{
  var out;
  //alert('PreprocessNS4Content(content='+content+',width='+ width+',height='+height+',borderWidth'+borderWidth+',borderColor='+borderColor+',padding='+padding+',bgcolor='+bgcolor+')');
  if ((typeof document.layers != "undefined"))
  {
		if (borderWidth>0 && padding>0)	   //width='"+(width-2*borderWidth)+"' height='"+(height-2*borderWidth)+"'
        {
			out = "<table bgcolor='"+  bgcolor+"' border=0 cellspacing=0 cellpadding=0>"
				    +"<tr><td bgcolor='" + borderColor +"' colspan=5 height='" + borderWidth + "' ><img border=0 src='"+this.transparency+"'></td></tr>" 
				     
					+"<tr><td width='" + borderWidth + "' bgcolor='" + borderColor +"' height='" + padding + "' ><img border=0 src='"+this.transparency+"'></td>" 
						+"<td colspan=3 ><img border=0 src='"+this.transparency+"'></td>"
					    +"<td width='" + borderWidth + "' bgcolor='" + borderColor +"' ><img border=0 src='"+this.transparency+"'></td></tr>"

					+"<tr><td bgcolor='" + borderColor +"' height='" + height + "' width='" + borderWidth + "'><img border=0 src='"+this.transparency+"'></td>" 
						+"<td width='" + padding + "'><img border=0 src='"+this.transparency+"'></td>"
						+"<td width='" + width + "'>" + content + "</td>"
						+"<td width='" + padding + "'><img border=0 src='"+this.transparency+"'></td>"
						+"<td bgcolor='" + borderColor +"' width='" + borderWidth + "'><img border=0 src='"+this.transparency+"'></td></tr>"
					
					+"<tr><td bgcolor='" + borderColor +"' height='" + padding + "' ><img border=0 src='"+this.transparency+"'></td>" 
						+"<td colspan=3 ><img border=0 src='"+this.transparency+"'></td>"
					    +"<td bgcolor='" + borderColor +"' ><img border=0 src='"+this.transparency+"'></td></tr>"
					+"<tr><td bgcolor='" + borderColor +"' colspan=5 height='" + borderWidth + "'><img border=0 src='"+this.transparency+"'></td></tr>" 
					+"</table>"	
		}
        else if (borderWidth>0 || padding>0)
		{
			var c1=borderWidth>0?borderColor:bgcolor; 
			var s1=borderWidth>0?borderWidth:padding; 
			//c1="#0000FF";
			out = "<table bgcolor='"+  bgcolor+"' border=0 cellspacing=0 cellpadding=0>"
						+"<tr><td colspan=3 bgcolor='" + c1 +"' height='" + s1 + "'><img border=0 src='"+this.transparency+"'></td></tr>"
					+"<tr><td bgcolor='"+c1+"' height='" + height + "' width='" + s1 + "'><img border=0 src='"+this.transparency+"'></td>"
						+"<td width='" + width + "'>" + content + "</td>"
						+"<td bgcolor='"+c1+"' width='" + s1 + "'><img border=0 src='"+this.transparency+"'></td></tr>"
						+"<tr><td colspan=3 bgcolor='" + c1 +"' height='" + s1 + "'><img border=0 src='"+this.transparency+"'></td>"
					    +"</tr></table>"
		}
		else
		{
			 out = "<table bgcolor='"+  bgcolor+"' border=0 cellspacing=0 cellpadding=0>"
						+"<tr>" 
						+"<td height='"+height+"'  width='" + width + "'>" + content + "</td>"
						    +"</tr></table>"
		}
	}
	else
		out=content;
	
  return out;
}

function PopupMakeLayer(posx,posy,width,height,visible,content,zIndex,borderWidth,borderColor,padding,bgcolor)
{
	
	if (typeof document.all != "undefined")
	{
		width += 2*padding + 2*borderWidth;
		height += 2*padding + 2*borderWidth;
	}

	if (window.tmpPopupLayersCnt)
		window.tmpPopupLayersCnt++;
	else
		window.tmpPopupLayersCnt=1;
	var lay_name = "PopupLayer_" + window.tmpPopupLayersCnt;
	if (typeof document.layers != "undefined")
	{
		lay = new Layer(width+2*padding+2*borderWidth);
		lay.left=posx;
		lay.top=posy;
		lay.zIndex=zIndex;
        lay.visibility  = visible?"show":"hide";
		content = this.PreprocessNS4Content(content,width,height,borderWidth,borderColor,padding,bgcolor);
		
		if (bgcolor!="") lay.bgColor=bgcolor;
		lay.document.open();
		lay.document.write(content);
		lay.document.close();
	}
	else
	{            
		if (document.getElementById)
		{
			lay = document.createElement("DIV");
			document.body.appendChild(lay); 
			lay.style.position ="absolute";
		}
		else if (typeof document.all != "undefined")
		{
			document.body.insertAdjacentHTML("beforeEnd","<DIV style='position:absolute' id='" + lay_name+"'>&nbsp;</div>");
			lay = document.all[lay_name];
		}
		else return null;
        
		lay.style.visibility = visible?"visible":"hidden";
		lay.style.display="block";
		lay.style.padding = ""+ padding + "px";
		if (bgcolor!="") lay.style.backgroundColor = bgcolor ;
        if (borderWidth>0)
		{
			lay.style.borderWidth = ""+borderWidth +"px";
			lay.style.borderColor = ""+borderColor ;
			lay.style.borderStyle = "solid";
		}
		lay.style.zIndex=zIndex;
		lay.style.left=""+posx+"px";
		lay.style.top=""+posy+"px";
		lay.style.height=""+height+"px";
		lay.style.width=""+width+"px";
		lay.innerHTML=content;
	}
    return lay;
}

function FillMainLayer(state)
{
//	this.mainWidth = 150;
//	this.mainHeight = 16;
	var content = this.caption;
	var lay = state?this.mainHoverLayer:this.mainLayer;
	if (this.prepMainFun)
		content = this.prepMainFun(state,content);
	var ico = this.mainIcon;
	if (state && this.mainHiIcon!="") 
		this.mainHiIcon;
	if (ico!="")
	{
		if (this.mainIconAlign=="right")
		{
			content = "<table border=0 cellspacing=0 cellpadding =0 width="+this.mainWidth+" height="+this.mainHeight+"><tr>"
				+"<td align='"+this.mainTextAlign+"' valign='middle'>"+content+"</td>"
				+"<td align='right' valign='middle' width='1%'><IMG src='"+ico+"' border='0'></td>"
				+"</tr></table>";
		}
		else
		{
			content = "<table border=0 cellspacing=0 cellpadding =0 width="+this.mainWidth+" height="+this.mainHeight+"><tr>"
				+"<td align='left' valign='middle' width='1%'><IMG src='"+ico+"' border='0'></td>"
				+"<td align='"+this.mainTextAlign+"' valign='middle'>"+content+"</td>"
				+"</tr></table>";			
		}
	}
//	alert(content);
	/*
	if ((!state|| this.mainHiIcon=="" ) && this.mainIcon!="")
		content = "<IMG src='"+this.mainIcon+"' border='0' align='absmiddle' align='"+this.mainIconAlign+"'>" + content;
	
	else if (state  && this.mainHiIcon!="" )
		content = "<IMG src='"+this.mainHiIcon+"' border='0' align='absmiddle'  align='"+this.mainIconAlign+"'>" + content;
 */
	var color = state?this.mainHlBgColor:this.mainBgColor;
    if ((typeof document.layers != "undefined"))
	{
		//alert(content);
		lay.document.open();
        lay.document.write(
			this.PreprocessNS4Content(content,this.mainWidth,this.mainHeight,this.mainBorderWidth,this.mainBorderColor,this.mainPadding,color));
		lay.document.close();
	}
	else
	{
		lay.style.backgroundColor = color;
		var str= content; 
		lay.innerHTML = str ; 
	}
}


function PopupMainMouseOver()
{
	
	if (this.closeTimer)
		clearTimeout(this.closeTimer);
	if (this.autoOpen)
		this.Open();
	this.mouseOverMain=true;
	
	this.FillMainLayer(1);

	if ((typeof document.layers != "undefined"))
		this.mainHoverLayer.visibility = "show";
	else 
		this.mainHoverLayer.style.visibility = "visible";
}

function PopupMainMouseOut()
{
	if ((typeof document.layers != "undefined"))
		this.mainHoverLayer.visibility = this.closed?"hide":"show";
	else 
		this.mainHoverLayer.style.visibility = this.closed?"hidden":"visible";

	this.mouseOverMain=false;
	if (this.autoClose)  
		this.closeTimer = window.setTimeout("window.popupDefs["+this.idx+"].Close()",this.autoCloseTimeout);
}

function PopupMouseOver(sub)
{
	if (this.closeTimer)
		clearTimeout(this.closeTimer);
    if (this.subelems[sub].inactive)
		return;
	var content = "<table border=0 cellspacing=0 cellpadding='0'>"+ this.PrepTextLine(sub,1)+"</table>"
	var offset = +2*this.mainBorderWidth+2*this.mainPadding + this.mainHeight;
	var xtop = this.mainY+this.popupBorderWidth+this.popupPadding + this.popupYOffset;
	var i;
	for (i=0;i<sub;i++)
		xtop +=this.subelems[i].height;

	if ((typeof document.layers != "undefined"))
	{
		this.popupHoverLayer.document.open();
        this.popupHoverLayer.document.write(
			this.PreprocessNS4Content(content,this.popupWidth,this.popupRowHeight,0,"",0,this.popupBgColor));
		this.popupHoverLayer.document.close();
		this.popupHoverLayer.top = xtop; 
		this.popupHoverLayer.visibility="show";
	}
	else
	{
		this.popupHoverLayer.style.top = xtop; 
		this.popupHoverLayer.innerHTML = content; 
		this.popupHoverLayer.style.visibility="visible";
	}


}
///------------------------

function PopupMouseOut()
{
	if (this.autoClose)
		this.closeTimer = window.setTimeout("window.popupDefs["+this.idx+"].Close()",this.autoCloseTimeout);
	if ((typeof document.layers != "undefined"))
		this.popupHoverLayer.visibility="hide";
	else
        this.popupHoverLayer.style.visibility="hidden";
	
}


function PopupTurnOnOff()
{
	if (this.closed)
		this.Open();
	else
		this.Close();
}

function PopupOpen()
{

	this.closed=false;

	if ((typeof document.layers != "undefined"))
	{
		/*if (this.anchored)
		{
			this.popupMapLayer.left = this.popupLayer.left = this.mainX+window.pageXOffset;
			this.popupMapLayer.top = this.popupLayer.top =  this.mainY+this.popupYOffset++window.pageYOffset;
		}*/
		this.mainHoverLayer.visibility = "show";
		this.popupLayer.visibility="show";
		this.popupMapLayer.visibility="show";
	}
	else 
	{
		/*if (this.anchored)
		{
			this.popupMapLayer.style.left = this.popupLayer.style.left = this.mainX+window.document.scrollLeft;
			this.popupMapLayer.style.top = this.popupLayer.style.top =  this.mainY+this.popupYOffset+window.document.scrollTop;
		} */
		this.mainHoverLayer.style.visibility = "visible";
		this.popupLayer.style.visibility = "visible";
		this.popupMapLayer.style.visibility = "visible";
	}
}

function PopupClose()
{
	this.closed=true;
	if ((typeof document.layers != "undefined"))
		this.mainHoverLayer.visibility = this.mouseOverMain?"show":"hide";
	else 
		this.mainHoverLayer.style.visibility = this.mouseOverMain?"visible":"hidden";
	
    if ((typeof document.layers != "undefined"))
	{
		this.popupLayer.visibility="hide";
		this.popupMapLayer.visibility="hide";
		this.popupHoverLayer.visibility="hide";
	}
	else 
	{
		this.popupLayer.style.visibility = "hidden";
		this.popupMapLayer.style.visibility = "hidden";
		this.popupHoverLayer.style.visibility="hidden";
	}
}

function PopupPrepTextLine(n,state)
{
	if (this.subelems[n].type=='elem')
	{
		var cap = this.subelems[n].caption;
		if ( this.prepRowFun )
			cap = this.prepRowFun(state,cap,n)
		return "<tr><td bgcolor='"+(state?this.popupHlBgColor:this.popupBgColor) +"' align="+this.popupTextAlign +" width='"+this.popupWidth+"' height='"+this.subelems[n].height+"'>"+cap+"</td></tr>";
	}
	else if (this.subelems[n].type=='sep_empty' )
	{
		return "<tr><td bgcolor='"+this.popupBgColor+"' width='"+this.popupWidth+"' height='"+this.subelems[n].height+"'><img src='"+this.transparency+"' border=0></td></tr>";
	}
	else if (this.subelems[n].type=='sep_line')
	{
		
		var h = Math.floor((this.subelems[n].height -this.popupBorderWidth)/2);
		var h1= this.subelems[n].height - this.popupBorderWidth - h;

		var w = this.popupWidth;
		var ret = 
			"<tr><td bgcolor='"+this.popupBgColor+"' width='"+w+"' height='"+h+"'><img src='"+this.transparency+"' border=0></td></tr>"
			+"<tr><td bgcolor='"+this.popupBorderColor+"' width='"+w+"' height='"+this.popupBorderWidth+"'><img src='"+this.transparency+"' border=0></td></tr>"
			+"<tr><td bgcolor='"+this.popupBgColor+"' width='"+w+"' height='"+h1+"'><img src='"+this.transparency+"' border=0></td></tr>"
			;
		//alert(ret);	

		return ret;
/*
																																 
		alert("<tr><td bgcolor='" +this.popupBgColor    +"' width='"+this.popupWidth+"' height='"+h+"'><img src='"+this.transparency+"' border=0></td></tr>"
			+"\n<tr><td bgcolor='"+this.popupBorderColor +"' width='"+this.popupWidth+"' height='"+this.popupBorderWidth+"'><img src='"+this.transparency+"' border=0></td></tr>"
			+"\n<tr><td bgcolor='"+this.popupBgColor     +"' width='"+this.popupWidth+"' height='"+h+"'><img src='"+this.transparency+"' border=0></td></tr>");
	   return 
			//"<tr><td bgcolor='" +this.popupBgColor    +"' width='"+this.popupWidth+"' height='"+h+"'><img src='"+this.transparency+"' border=0></td></tr>"
			"\n<tr><td bgcolor='"+this.popupBorderColor +"' width='"+this.popupWidth+"' height='"+this.subelems[n].height+"'><img src='"+this.transparency+"' border=0></td></tr>"
			//+"\n<tr><td bgcolor='"+this.popupBgColor     +"' width='"+this.popupWidth+"' height='"+h1+"'><img src='"+this.transparency+"' border=0></td></tr>";
*/			
	}
	return "";
}


function PopupPrepText(n)
{
	
	var i;
	var inWidth = this.popupWidth;
	var se = this.subelems;
	var popup_text=	"<table border=0 cellspacing=0 cellpadding='0'>";
	for (i=0;i<se.length;i++)
		popup_text+= this.PrepTextLine(i,i==n);
	popup_text +="</table>";		    
	return    popup_text;
}

function PopupGetMapText()
{   
	var se=this.subelems;
	var maptext= "<img src=\""+this.transparency+"\" border=0 USEMAP=\"#popup_hover_mapp"+this.idx+"\" WIDTH=\"" + this.popupWidth + "\" "
				+"HEIGHT=\"" + (this.popupRowHeight * se.length) + "\" border=\"0\">";
	maptext+= "<map name=\"popup_hover_mapp"+this.idx+"\">";
	var mY = 0;
	for (i=0;i<se.length;i++)
    {
		var ob=se[i];
    	maptext +=  "<area SHAPE=\"RECT\" COORDS=\"0," + mY + "," + this.popupWidth + "," + (mY + ob.height-1) + "\"";
 	maptext +=" HREF='javascript:window.popupDefs["+this.idx+"].OnClick("+i+")'";
	maptext +=	
		" onmouseover=\"window.popupDefs["+this.idx+"].MouseOver("+i+");\""+" onmouseout=\"window.popupDefs["+this.idx+"].MouseOut();\""
		+">";
		mY += ob.height;
	}
    maptext+= "</map>";
	return maptext;

}

function PopupGetHeight()
{
	var se=this.subelems;
	var mY = 0;
	for (i=0;i<se.length;i++)
        mY += se[i].height;
    return mY;
}
function PopupCreateLayers()
{
	if (this.popupYOffset == null) 
		this.popupYOffset =  this.mainHeight + 2*this.mainBorderWidth + 2*this.mainPadding;
	
	if (this.autoOpen && (this.popupYOffset < (this.mainHeight + 2*this.mainBorderWidth + 2*this.mainPadding))) 
		this.autoOpen = false;

	if (this.autoSort && this.unsorted)
		this.Sort();
	
	if (this.comboMode)
	{ 
		if (this.current>=0 &&  this.current<this.subelems.length)
			this.caption = this.subelems[this.current].caption;
		else
			this.caption = this.name;
	}
	this.mainLayer = this.MakeLayer(this.mainX,this.mainY,this.mainWidth,this.mainHeight,true,"&nbsp;",7,this.mainBorderWidth,this.mainBorderColor,this.mainPadding,this.mainBgColor);
	this.mainHoverLayer = this.MakeLayer(this.mainX,this.mainY,this.mainWidth,this.mainHeight,!this.closed,"&nbsp;",7,this.mainBorderWidth,this.mainBorderColor,this.mainPadding,this.mainHlBgColor);
	this.FillMainLayer(1);
	this.FillMainLayer(0);

	var se=this.subelems;
    var maptext= "<a href=\"javascript:window.popupDefs["+this.idx+"].TurnOnOff()\""
		+" onmouseover=\"window.popupDefs["+this.idx+"].MainMouseOver();\""+" onmouseout=\"window.popupDefs["+this.idx+"].MainMouseOut();\""
		+"><img src=\""+this.transparency+"\" border='0' WIDTH=\"" + this.mainWidth + "\" " + "HEIGHT=\"" + this.mainHeight+ "\" ></a>";
    
	this.mainMapLayer = this.MakeLayer(this.mainX+this.mainBorderWidth+this.mainPadding,
									this.mainY+this.mainBorderWidth+this.mainPadding,
									this.mainWidth,
									this.mainHeight,
									true,maptext,9,0,"",0,"");
	//var se=this.subelems;	
	var popup_text=	this.PrepText(-1);
	this.popupLayer = this.MakeLayer(this.mainX+this.popupXOffset, 
								 this.mainY+this.popupYOffset,
								 this.popupWidth,
								 this.GetHeight(),
								 !this.closed,popup_text,10,this.popupBorderWidth,this.popupBorderColor,this.popupPadding,this.popupBgColor);
	
	maptext= this.GetMapText();
	
	this.popupMapLayer = this.MakeLayer(this.mainX+this.popupBorderWidth+this.popupPadding+this.popupXOffset, 
									 this.mainY+this.popupBorderWidth+this.popupPadding+this.popupYOffset,
									 this.popupWidth,
									 this.GetHeight(),
									 !this.closed,maptext,16,0,"",0,"");
	
	this.popupHoverLayer = this.MakeLayer(this.mainX+this.popupBorderWidth+this.popupPadding+this.popupXOffset, 
									 this.mainY+this.popupBorderWidth+this.popupPadding+this.popupYOffset,
									 this.popupWidth,
									 this.popupRowHeight,
									 false,"&nbsp;",11,0,"",0,"");

	if (!this.closed && this.autoClose)
		this.closeTimer = setTimeout("window.popupDefs["+this.idx+"].Close()",this.autoCloseTimeout);
}

function PopupRefillLayers()
{
	if (this.autoSort && this.unsorted)
		this.Sort();
	if (this.comboMode)
	{
		if (this.current>=0 &&  this.current<this.subelems.length)
			this.caption = this.subelems[this.current].caption;
		else
			this.caption = this.name;
	}
	   
        this.FillMainLayer(1);
	this.FillMainLayer(0);
	
	var maptext= this.GetMapText();
	var se=this.subelems;
	//alert (se.length)
    if((typeof document.layers != "undefined"))
	{
		this.popupMapLayer.document.open();
        this.popupMapLayer.document.write(maptext);
		this.popupMapLayer.document.close();
	}
	else
	{
		this.popupMapLayer.style.height= this.GetHeight();
		this.popupMapLayer.innerHTML = maptext;
	}
	
	var content=this.PrepText(-1);
    if((typeof document.layers != "undefined"))
	{
		this.popupLayer.document.open();
        	this.popupLayer.document.write(
			this.PreprocessNS4Content(content,this.popupWidth,this.GetHeight(),this.popupBorderWidth,this.popupBorderColor,this.popupPadding,this.popupBgColor));
		this.popupLayer.document.close();
	}
	else
	{
		this.popupLayer.style.height= this.GetHeight()+2*this.popupPadding+ 2*this.popupBorderWidth;
		this.popupLayer.innerHTML = content;
	}
}




function InitPopups(transparency)
{

	if (!transparency)
		transparency = "site_icons/tr.gif";
	var i;
	if (!window.popupDefs || window.popupDefs.length==0) return;

	//setting possitions and transparency link  
	for (i=0; i< window.popupDefs.length; i++)
	{
		if(window.popupDefs[i].positioning == 1)
      	{
			
			var popNameX = "pop"+window.popupDefs[i].idx;
			var pos = anchorPositionX(popNameX);
			window.popupDefs[i].mainX = pos.X;
			window.popupDefs[i].mainY = pos.Y;
		}
		window.popupDefs[i].transparency= transparency;
	}
	
	//creating layers for objects
	for (i=0; i< window.popupDefs.length; i++)
		window.popupDefs[i].CreateLayers();
	
}

function PopupChangeCaption(pos,text)
{
	if (pos<0 || pos >=this.subelems.length) return;
	this.subelems[pos].caption = text;
	if (this.comboMode && this.current == pos)
	{
		this.caption = text;
		this.FillMainLayer(0);
		this.FillMainLayer(1);
	}
	var popup_text=	this.PrepText(-1);
	if ((typeof document.layers != "undefined"))
	{
		popup_text = this.PreprocessNS4Content(popup_text,this.popupWidth,this.popupRowHeight*this.subelems.length,this.popupBorderWidth,this.popupBorderColor,this.popupPadding,this.popupBgColor);
		this.popupLayer.document.open();
		this.popupLayer.document.write(popup_text);
		this.popupLayer.document.close();
	}
	else
		this.popupLayer.innerHTML = popup_text;


	
}
function PopupFindSubelemByParam(id)
{
	for (var i=0;i<this.subelems.length;i++)
		if (this.subelems[i].param == id)
			return i;
	return -1;
}
function PopupSetCurrent(c)
{
	this.current=c;
	if (this.comboMode)
	{
		if (this.current >= 0 &&  this.current < this.subelems.length)
			this.caption = this.subelems[this.current].caption;
		else
			this.caption = this.name;
	}
   	if (this.mainLayer)
	{	
		this.FillMainLayer(0);
		this.FillMainLayer(1);
	}
}

///////////////////////////////////////////////
function insertLink(name,d)
{
	if ((typeof document.layers != "undefined"))
		d.write("<A name=\""+name+"\">&nbsp;</A>");
	else
		document.write("<A name=\""+name+"\">&nbsp;</A>");

}

function findNSAnchorPos(name,d)
{
	var i;  
  	if(!d) d=window.document; 
	var anchPos = 0;
	for(i=0;i<d.anchors.length;i++)
	{
		//alert(d.anchors[i].name);
		if(d.anchors[i].name == name)
		{
			var anch = d.anchors[i];
			anchPos = new Object();
			anchPos.X = anch.x;
			anchPos.Y = anch.y;
		}
		
	}
	if (!anchPos && d.layers)
		for (i=0 ; !anchPos && i<d.layers.length ; i++) 
		{
			anchPos=findNSAnchorPos(name,d.layers[i].document); 
			if (anchPos)
			{
				anchPos.X += d.layers[i].x;
				anchPos.Y += d.layers[i].y;
			}
		}
	return anchPos;
}

function anchorPositionX(name)
{

	if ((typeof document.layers != "undefined"))
		return findNSAnchorPos(name);
	var i;
	for(i=0;i<document.anchors.length;i++)
	{
		if(document.anchors[i].name == name)
		{
			//anch = document.anchors[i];		
	    	var pos = new Object();
			pos.X = findAnchorPos(document.anchors[i],0,"x");
			pos.Y = findAnchorPos(document.anchors[i],0,"y");
			return pos;
		}
	}
	alert("anchor_not_found");
	return null;
}


function findAnchorPos(obj,odl,type)
{
	
   if(type == "x")
      odl = odl + obj.offsetLeft;
   else if(type == "y")
      odl = odl + obj.offsetTop;
   else
      return odl;

	if(obj.offsetParent)
		odl = findAnchorPos(obj.offsetParent,odl,type);
	return odl;
}
///////////////////////////////////////////////
function PopupReposition()
{

	if(this.positioning == 1)
    {
		var popNameX = "pop"+this.idx;
		var pos = anchorPositionX(popNameX);
		this.mainX = pos.X;
		this.mainY = pos.Y;
	}

	var dX = this.mainX - parseInt(this.mainLayer.style.left);
	var dY = this.mainY - parseInt(this.mainLayer.style.top);
		
	this.mainLayer.style.left = (parseInt(this.mainLayer.style.left)+dX )+"px";
	this.mainLayer.style.top = (parseInt(this.mainLayer.style.top)+dY )+"px";
	this.mainHoverLayer.style.left = (parseInt(this.mainHoverLayer.style.left) +dX )+"px";
	this.mainHoverLayer.style.top = (parseInt(this.mainHoverLayer.style.top) +dY )+"px";
	this.mainMapLayer.style.left = (parseInt(this.mainMapLayer.style.left) +dX )+"px";
	this.mainMapLayer.style.top = (parseInt(this.mainMapLayer.style.top) +dY )+"px";
	
	this.popupLayer.style.left = (parseInt(this.popupLayer.style.left) +dX )+"px";
	this.popupLayer.style.top = (parseInt(this.popupLayer.style.top) +dY )+"px";
	this.popupHoverLayer.style.left = (parseInt(this.popupHoverLayer.style.left) +dX )+"px";
	this.popupHoverLayer.style.top = (parseInt(this.popupHoverLayer.style.top) +dY )+"px";
	this.popupMapLayer.style.left = (parseInt(this.popupMapLayer.style.left) +dX )+"px";
	this.popupMapLayer.style.top = (parseInt(this.popupMapLayer.style.top) +dY )+"px";
}

Popup.prototype.Add = PopupAddSubelem;
Popup.prototype.AddSeparator = PopupAddSeparator;
Popup.prototype.Remove = PopupRemoveSubelem;
Popup.prototype.RemoveAll = PopupRemoveAllSubelems;
Popup.prototype.Sort = PopupSortSubelems;
Popup.prototype.CreateLayers = PopupCreateLayers;
Popup.prototype.PrepText=PopupPrepText;
Popup.prototype.PrepTextLine=PopupPrepTextLine;
Popup.prototype.Open = PopupOpen;
Popup.prototype.Close = PopupClose;
Popup.prototype.MouseOut=PopupMouseOut;
Popup.prototype.MouseOver=PopupMouseOver;
Popup.prototype.OnClick=PopupOnClick;
Popup.prototype.MakeLayer = PopupMakeLayer;
Popup.prototype.RefillLayers = PopupRefillLayers;
Popup.prototype.MainMouseOut = PopupMainMouseOut;
Popup.prototype.MainMouseOver = PopupMainMouseOver;
Popup.prototype.FillMainLayer=FillMainLayer;
Popup.prototype.TurnOnOff=PopupTurnOnOff;
Popup.prototype.ChangeCaption=PopupChangeCaption;
Popup.prototype.SetCurrent=PopupSetCurrent;
Popup.prototype.GetMapText=PopupGetMapText;
Popup.prototype.FindSubelemByParam=PopupFindSubelemByParam;
Popup.prototype.GetHeight= PopupGetHeight;
Popup.prototype.Reposition = PopupReposition;
Popup.prototype.PreprocessNS4Content = PreprocessNS4Content;

