﻿function VE_PanelCustom(id,x,y,width,height,color,zIndex,title,body,footer,mouseovertitle,bOpaque)
{
	this.index=0;
	this.x=x;
	this.y=y;
	this.width=width;
	this.height=height;
	this.dynamicHeightMax=225;
	this.color=color;
	this.toolbarHeight=20;
	this.footerHeight=20;
	this.min=false;
	this.visible=true;
	this.onTitleClick=null;
	this.onCloseClick=null;
	var el=VE_PanelCustom._CreateElement("div",id,"",zIndex);
	this.el=el;
	this.titleDisabled=false;
	this.title=VE_PanelCustom._CreateElement("a",id+"_title","VE_VE_Panel_title "+(mouseovertitle?" VE_Panel_title_mouseover":""),zIndex+1);
	this.title.innerHTML=IOSec.EncodeHtml(title);
	this.title.onclick=VE_PanelCustom._OnTitleClick;
	this.title.unselectable="on";
	el.appendChild(this.title); 
	this.closeboxDisabled=false;
	this.cb=VE_PanelCustom._CreateElement("a",id+"_cb","VE_VE_Panel_cb",zIndex+1);
	this.cb.innerHTML="X";
	this.cb.onclick=VE_PanelCustom._OnCloseClick;
	this.cb.unselectable="on";
	el.appendChild(this.cb);
	this.tb=VE_PanelCustom._CreateElement("div",id+"_tb","VE_VE_Panel_tb",zIndex+1);
	this.tb.unselectable="on";
	el.appendChild(this.tb);
	this.body=VE_PanelCustom._CreateElement("div",id+"_body","VE_Panel_body",zIndex+1);
	this.body.innerHTML=body;
	el.appendChild(this.body);
	this.foot=VE_PanelCustom._CreateElement("div",id+"_foot","VE_VE_Panel_foot",zIndex+1);
	this.foot.innerHTML=footer;
	this.foot.unselectable="on";
	el.appendChild(this.foot);
	this.Resize();
	if(!bOpaque)
	{
		this.SetOpacity(100);
	}
	VE_PanelCustom.panels.push(this);
	document.body.appendChild(el);
}

VE_PanelCustom.panels=new Array();

VE_PanelCustom.shadowThickness=3;

VE_PanelCustom._CreateElement=function(type,id,className,zIndex)
{
	var el=document.createElement(type);
	el.id=id;
	el.className=className;
	el.style.position="absolute";
	el.style.zIndex=zIndex;
	return el;
	
}

VE_PanelCustom._PositionElement=function(el,x,y,w,h)
{
	el.style.top=y+"px";
	el.style.left=x+"px";
	el.style.width=w+"px";
	el.style.height=h+"px";
	
}

VE_PanelCustom.prototype.SetPosition=function(x,y,w,h)
{
	this.x=x;
	this.y=y;
	this.w=w;
	this.h=h;
	
}

VE_PanelCustom.prototype.SetToolbarSize=function(toolbarHeight)
{
	this.toolbarHeight=toolbarHeight;
	var d=eval(toolbarHeight)>0?"block":"none";
	this.tb.style.display=d;
	this.Resize();
	
}

VE_PanelCustom.prototype.SetFooterSize=function(footerHeight)
{
	this.footerHeight=footerHeight;
	var d=eval(footerHeight)>0?"block":"none";
	this.foot.style.display=d;
	this.Resize();
	
}

VE_PanelCustom.prototype.Resize=
function()
{
	var x=eval(this.x);
	var y=eval(this.y);
	var w=Math.max(eval(this.width),100);
	var h=Math.max(eval(this.height),18);
	var th=eval(this.toolbarHeight);
	var fh=eval(this.footerHeight);
	var st=VE_PanelCustom.shadowThickness;
	var by=21+th;
	var bh=h-27-th-fh;
	if(this.min)
	{
		h=21;
	}
	else
	{
		if(th>0)
		{
			VE_PanelCustom._PositionElement(this.tb,1,19,w-4,th);
		}
		else
		{
			by-=2;bh+=2;
		}
		if(fh>0)
		{
			VE_PanelCustom._PositionElement(this.foot,1,h-fh-3,w-4,fh);
		}
		else
		{
			bh+=2;
		}
		if(bh>0)
		{
			VE_PanelCustom._PositionElement(this.body,1,by,w-11,bh-5);
		}
	}
	VE_PanelCustom._PositionElement(this.el,x,y,w,h);
	VE_PanelCustom._PositionElement(this.title,1,1,w-19,17);
	VE_PanelCustom._PositionElement(this.cb,w-19,1,16,17);
}

VE_PanelCustom.prototype.SetHeightToFit=function()
{
	var contentid=this.id+'_body_table';
	var content=document.getElementById(contentid);
	if(!content)
	{
		return false;
		
	}
	this.height=0;
	var width=Math.max(eval(this.width),100);
	if(content.offsetWidth>width-14)
	{
		this.height+=scrollbarWidth;
		
	}
	this.height+=(this.titleDisabled)?14:21+14;
	this.height+=this.toolbarHeight;
	this.height+=content.offsetHeight;
	this.height+=this.footerHeight;
	this.height=Math.min(this.dynamicHeightMax,this.height);
	
}

VE_PanelCustom.prototype.DisableClosebox=function()
{
	if(this.closeboxDisabled)
	{
		return;
		
	}
	this.closeboxDisabled=true;
	this.el.removeChild(this.cb);
	
}

VE_PanelCustom.prototype.EnableClosebox=function()
{
	if(!this.closeboxDisabled)
	{
		return;
		
	}
	this.closeboxDisabled=false;
	this.el.insertBefore(this.cb,this.tb);
}

VE_PanelCustom.prototype.DisableTitle=function()
{
	if(this.titleDisabled)
	{
		return;
	}
	this.titleDisabled=true;
	this.el.removeChild(this.cb);
	this.el.removeChild(this.title);
	
}

VE_PanelCustom.prototype.EnableTitle=function()
{
	if(!this.titleDisabled)
	{
		return;
		
	}
	this.titleDisabled=false;
	this.el.insertBefore(this.cb,this.tb);this.el.insertBefore(this.title,this.cb);
}

VE_PanelCustom.prototype.SetTitle=function(c)
{
	this.title.innerHTML=IOSec.EncodeHtml(c);
}

VE_PanelCustom.prototype.SetToolbar=function(c)
{
	this.tb.innerHTML=c;
	
}

VE_PanelCustom.prototype.SetBody=function(c)
{
	this.body.innerHTML=c;
	
}

VE_PanelCustom.prototype.SetDynamicBody=function(c)
{
	this.body.innerHTML='<table id="'+this.id+'_body_table"><tr><td>'+c+'</td></tr></table>';
	
}

VE_PanelCustom.prototype.SetFooter=function(c)
{
	this.foot.innerHTML=c;
	
}

VE_PanelCustom.prototype.SetOpacity=function(o)
{
	if(o>=100)o=99.99;
	with(this.el.style)
	{
		filter="alpha(opacity:"+o+")";
		o*=0.01;
		KHTMLOpacity=o;
		MozOpacity=o;
		opacity=o;
		
	}
	
}

VE_PanelCustom.prototype.SetColor=function(c)
{
	this.color=c;
	this.title.className="VE_VE_Panel_title" ;
	this.foot.className="VE_VE_Panel_foot";
	this.cb.className="VE_VE_Panel_cb";
	
}

VE_PanelCustom.prototype.Minimize=function()
{
	this.min=true;
	this.tb.style.display="none";
	this.body.style.display="none";
	this.foot.style.display="none";
	this.Resize();
	
}

VE_PanelCustom.prototype.Maximize=function()
{
	this.min=false;
	if(eval(this.toolbarHeight)>0)
	{
		this.tb.style.display="block";
		
	}
	if(eval(this.footerHeight)>0)
	{
		this.foot.style.display="block";
		
	}
	this.body.style.display="block";
	this.Resize();
	
}

VE_PanelCustom.prototype.Show=function()
{
	this.el.style.display="block";
	this.visible=true;
	
}

VE_PanelCustom.prototype.Hide=function()
{
	this.el.style.display="none";
	this.visible=false;
	
}

VE_PanelCustom.prototype.Toggle=function()
{
	if(this.min)
	{
		this.Maximize();
		
	}
	else
	{
		this.Minimize();
		
	}
	
}

VE_PanelCustom.prototype.Destroy=function()
{
	document.body.removeChild(this.el);
	var p=VE_PanelCustom.panels;
	for(var i=0;i<p.length;i++)
	{
		if(p[i]==this)
		{
			p.splice(i,1);
			return;
			
		}
		
	}
	
}

VE_PanelCustom.ResizeAllPanels=function()
{
	var p=VE_PanelCustom.panels;
	for(var i=0;i<p.length;i++)
	{
		p[i].Resize();
		
	}
	
}

function VE_PanelEvent(srcPanel)
{
	this.srcPanel=srcPanel;
	
}

VE_PanelCustom.prototype._CreateEvent=function()
{
	return new VE_PanelEvent(this);
	
}

VE_PanelCustom._OnTitleClick=function(e)
{
	if(!e)e=window.event;
	var t=GetTarget(e);
	var p=VE_PanelCustom.panels;
	for(var i=0;i<p.length;i++)
	{
		if(p[i].title==t)
		{
			if(p[i].onTitleClick)
			{
				p[i].onTitleClick(p[i]._CreateEvent());
				
			}
			return;
			
		}
		
	}
	
}

VE_PanelCustom._OnCloseClick=function(e)
{
	var p=VE_PanelCustom.panels;
	for(var i=0;i<p.length;i++)
	{
	    p[i].Hide();
	}
	// for removing iFrame from 3D Map 
	//RemoveMyPopupFrame3D();
}

function Destroy()
{
	RemoveSummary();
	RemoveRoutePins();
	RemoveRouteHighlight();
	summaryElement=route=instructionsWithPins=routeHighlight=null;
	
}

