// JavaScript Document

// toolbar
function areaToolbar(areaParent,title){
	this.iconsPath='ad/images/icons/';
	
	this.title=title;
	this.areaParent=areaParent;
	this.icons=new Object();
	this.icons['edit']='reply.gif';
	this.icons['save']='save.gif';
	this.buttons=new Object();
	
	var d1=document.createElement('div');
	var d2=document.createElement('div');
	var d3=document.createElement('div');
	var d4=document.createElement('div');
	var d5=document.createElement('div');
	d1.className='ei_container';
	d2.className='ei_panel_back1';
	d3.className='ei_panel_back2';
	d4.className='ei_panel_back3';
	d5.className='ei_panel';
	d3.appendChild(d4);
	d2.appendChild(d3);
	this.panel_back=d1.appendChild(d2);
	this.panel=d1.appendChild(d5);
	this.panel.toolbarParent=this;
	this.container=d1;
	setOpacity(this.panel_back,0.85);
	
	this.panel.onmouseover=function(){
		this.promptTitle=this.appendChild(document.createTextNode(this.toolbarParent.title+' '));
		this.onmouseout=function(){
			this.removeChild(this.promptTitle);
			this.onmouseout=null;
			this.toolbarParent.updateBackground();
		}
		this.toolbarParent.updateBackground();
	}
	
	/*****************/
	this.setButton=function(type,action){
		if(!this.icons[type]) return false;
		if(this.buttons[type]){
			this.buttons[type].onclick=action;
			return true;
		}
		this.buttons[type]=document.createElement('img');
		this.buttons[type].src=this.iconsPath+this.icons[type];
		this.buttons[type].width='16';
		this.buttons[type].height='16';
		this.buttons[type].align='top';
		this.buttons[type].className='ei_button';
		this.buttons[type].areaParent=this.areaParent;
		this.buttons[type].toolbarParent=this;
		this.buttons[type].toolbarType=type;
		this.buttons[type].onclick=action;
		this.buttons[type]=this.panel.appendChild(this.buttons[type]);
		this.updateBackground();
		return true;
	}
	this.updateBackground=function(){
		this.panel_back.style.width=this.panel.offsetWidth+'px';
		this.panel_back.style.height='20px';
	}
	this.removeButton=function(button){
		if(!this.buttons[button.toolbarType]) return;
		this.buttons[button.toolbarType]=null;
		button.parentNode.removeChild(button);
		this.updateBackground();
	}
	this.setWait=function(button){
		if(!this.buttons[button.toolbarType]) return;
		button.src=this.iconsPath+'ajax-loader.gif';
	}
	this.dropWait=function(button){
		if(!this.buttons[button.toolbarType]) return;
		button.src=this.iconsPath+this.icons[button.toolbarType];
	}
	this.append=function(){
		this.container=this.areaParent.parentNode.insertBefore(this.container,this.areaParent);
		this.updateBackground();
	}
}

// dialog
function areaDialog(){
	var setPos=function(e){
		if(BR_MSIE_6==checkBrowser()) e.style.position='absolute';
		else e.style.position='fixed';
		e.style.top='0px';
		e.style.left='0px';
	}
	this.background=document.createElement('div');
	this.background.id='fckeditor_dialog_background';
	setPos(this.background);
	this.container_table=document.createElement('table');
	this.container_table.id='fckeditor_dialog_container';
	setPos(this.container_table);
	var tbody=this.container_table.appendChild(document.createElement('tbody'));
	var tr=tbody.appendChild(document.createElement('tr'));
	this.container=tr.appendChild(document.createElement('td'));
	this.getContainer=function(){return this.container;}
	this.append=function(){
		var b=document.getElementsByTagName('body')[0];
		this.background=b.insertBefore(this.background,b.childNodes[0]);
		setOpacity(this.background,0.7);
		this.container_table=b.insertBefore(this.container_table,b.childNodes[0]);
	}
	this.remove=function(){
		this.background.parentNode.removeChild(this.background);
		this.container_table.parentNode.removeChild(this.container_table);
	}
	this.createServerSideForm=function(areaParent,action){
		globalAjaxObject=new Ajax();
		globalAjaxObject.POST['action']=action;
		for(var key in areaParent.sendParams){
			globalAjaxObject.POST[key]=areaParent.sendParams[key];
		}
		var cont=this.getContainer();
		cont.processResult=function(content){
			var h1=document.createElement('h1');
			h1.innerHTML=
			this.innerHTML=content;
		}
		globalAjaxObject.makeRequest(window.location,cont);
	}
}

// opacity
function getOpacityProperty(){
  if(typeof document.body.style.opacity=='string') return 'opacity';
  else if(typeof document.body.style.MozOpacity=='string') return 'MozOpacity';
  else if(typeof document.body.style.KhtmlOpacity=='string') return 'KhtmlOpacity';
  else if(document.body.filters && navigator.appVersion.match(/MSIE ([\d.]+);/)[1]>=5.5) return 'filter';
  return false;
}
function setOpacity(elem, nOpacity){
	var opacityProp = getOpacityProperty();
	if (!elem || !opacityProp) return;
	if(opacityProp=="filter"){ // Internet Exploder 5.5+
		nOpacity *= 100;
		var oAlpha = elem.filters['DXImageTransform.Microsoft.alpha'] || elem.filters.alpha;
		if(oAlpha) oAlpha.opacity = nOpacity;
		else elem.style.filter += "progid:DXImageTransform.Microsoft.Alpha(opacity="+nOpacity+")";
	}else elem.style[opacityProp] = nOpacity;
}
//Browser check
var BR_MSIE_6 = 10;
var BR_MSIE_7 = 11;
var BR_MSIE_OTHER = 12;
var BR_MOZILLA = 20;
var BR_OPERA = 30;
var BR_SAFARI = 40;
var BR_UNKNOWN = 90;
function checkBrowser(){
	if(navigator.appName=='Microsoft Internet Explorer'){
		var pos=navigator.userAgent.search(/MSIE ...;/);
		var ver=navigator.userAgent.substr(pos+5,1);
		switch(ver){
			case '6': return BR_MSIE_6;
			case '7': return BR_MSIE_7;
			default: return BR_MSIE_OTHER;
		}
	}else if(navigator.userAgent.search(/Safari/)>=0){
		return BR_SAFARI;
	}else if(navigator.userAgent.search(/Opera/)>=0){
		return BR_OPERA;
	}else return BR_MOZILLA;
	
}