/* Javascript March 1, 2010*/
///////////////////////////////////////////////////////
//BHDialog v1.0 (c) 2006 suvadia.com
///////////////////////////////////////////////////////
function BHDialog(ocf)
{
	var div,tb,tr,td,img,s,a,e;
	bhUI.createObject('Dialog',this);
	this.div=div=bhUI.createElement();
	div.style.visibility='hidden';
	div.style.top='0px';div.style.left='-10000px';
	div.style.position='absolute';
	div.className='dialog ';
	document.body.appendChild(div);
	div.bhondragstart=function(evt){evt.bhdataTransfer.dragMode=1;}
	tb=div.addElement({name:'TABLE',cellPadding:'0',cellSpacing:'0'},
					  {name:'TBODY'})[1];
	var i,n=["top-left","middle-top","top-right",
			 "middle-left","middle","middle-right",
			 "bottom-left","middle-bottom"," bottom-right"];
	for(i=0;i<n.length;i++){
		  if(i%3 == 0)tr=tb.addElement('TR');
	  	   n[i]=tr.addElement({name:'TD','class':n[i]});
	 }
	 div=n[0].addElement();
	 div.className='title-bar';
     div=div.addElement('SPAN');
	 div.className='button';
     var a=div.addElement('A');a.href="#";
     a.onclick=new Function(this.Tx+".close();return false;");
	 this.content=n[4];
	 this.close=new Function("this.show(false);return false;");
}


BHDialog.prototype.open=function(content)
{	
	if(typeof(content)=='string')this.content.innerHTML=content;
	else{ 
		this.content.innerHTML='';
		this.content.appendChild(content);
	}
	if(arguments[1]){
		this.show();
		this.moveTo();	
	}
}

BHDialog.prototype.show=function()
{
	var v;
	if(arguments[0]===false)
	{
		v='hidden';
		if(this.div.style.visibility==v)return;
		this.div.style.visibility=v;
		setTimeout('bhUI.contentLock(false);',400);
	}
	else
	{
		v='visible';
     	if(this.div.style.visibility==v)return;
		this.div.style.visibility=v;
		bhUI.contentLock(true);
	}
}

BHDialog.prototype.hide=function()
{
	var s='hidden';
	if(this.div.style.visibility!=s){
		this.div.style.visibility=s;
		setTimeout('bhUI.contentLock(false);',400);
	}
}

BHDialog.prototype.moveTo=function(x,y,node)
{
	var e,b=bhUI.getScroll();
	if(typeof(node)==__UF){
		b.left+=((document.body.offsetWidth-this.div.offsetWidth)/2);
		b.top+=((document.body.offsetHeight-this.div.offsetHeight)/3);
    }else{
		e=node;
		while(e.offsetParent){b.top+=e.offsetTop;
		b.left+=e.offsetLeft;e=e.offsetParent;}
		b.left+=((e.offsetWidth-this.div.offsetWidth)/2)
		b.top+=((e.offsetHeight-this.div.offsetHeight)/2)
		if((b.top+this.div.offsetHeight)>=screen.availHeight){
			b.top=((screen.availHeight-this.div.offsetHeight)/2);
		}
	}
	if(b.top < 0)b.top=0;
	if(b.left < 0)b.left=0;
	
	this.div.style.top=b.top+'px';
	this.div.style.left=b.left+'px';
}


BHDialog.prototype.MessageBox=function(icon,title,message,buttons)
{
	var f,tb,tr,td,node=this.content;
	node.innerHTML='';
	tb=node.addElement('TABLE');
	tb.border="0";tb.cellspacing="0";tb.cellpadding="0";tb.width='100%';
	tb=tb.addElement('TBODY');tr=tb.addElement('TR');td=tr.addElement('TD');
	td.style.padding="16px";td.style.paddingRight="8px";
	td.style.paddingTop="2px";td.style.verticalAlign='top';
	img=td.addElement('IMG');
	switch(icon){
	case "?": f ="ask.gif"; break;
	case "!": f ="warning.gif"; break;
	case "i": f ="inform.gif"; break;
	case "-": f ="error.gif";break;}
	img.src="/newlook/dialog/skins/default/img/"+f;
	td=tr.addElement('TD');td.style.paddingRight="16px";
	td.style.verticalAlign='top';
	td.innerHTML='<div style=" font-size:14px; margin-top:0px; font-weight:bold;">'+title+'&nbsp;</div>'+message;
	
	td=tb.addElement({name:'TR'},{name:'TD',colSpan:2,align:'center'},
	{name:'A',style:'Button',href:'',text:'Close',
	onclick:new Function(this.Tx+".close();return false;")})[1];
	td.style.paddingTop="8px";td.style.paddingLeft="18px";
    
	if(this.div.offsetWidth>screen.availWidth)
 		this.div.width=screen.availWidth+'px';
	if(this.div.offsetHeight>screen.availHeight)
	   this.div.height=screen.availHeight+'px';
	   
	this.moveTo();this.show();
}

