var dom = {
	document	: document,
	functions	: new Array(),
	loaded 		: false,
	loadTimer	: '',
	interval	: 0,
	slider 		: {
		init : function(id,par,direction){
			if(typeof direction =='undefined' || direction==''){ direction = 'down'; }
			this.timeout = setTimeout('dom.slider.slide("'+id+'","'+par+'","'+direction+'")',5);
		},
		slide : function(id,par,direction){
			this.finished = false;
			factor = 5;
			if(direction!=this.direction){
				clearInterval(this.interval);
				this.interval = 0;
			}
			this.direction = direction;
			o = parent.getElement(id);
			h = parseFloat(parent.getStyle(o,'height'));
			t = parseFloat(parent.getStyle(o,'top'));
			if(direction=='down' && t == 0){ if(p = getElement(par)){ parent.setStyle(p,'display','block'); } }
			t = (direction=='down')?t+factor:t-factor;
			if((direction =='down' && t<=h) || (direction!='down' && t>=0)){
				parent.setStyle(o,'top',t+"px");
				if(this.interval==0){
					this.interval = setInterval('dom.slider.slide("'+id+'","'+par+'","'+direction+'")',25);
				}
			} else {
				this.finished = true;
				if(t<=0){ if(p = getElement(par)){ parent.setStyle(p,'display','none'); } }
				clearInterval(this.interval);
				this.interval = 0;
			}
		},
		stop : function (){
			if(this.direction!='down' || this.finished){
				clearInterval(this.interval);
				this.interval = 0;
			}
			clearTimeout(this.timeout);
			this.timeout = 0;
		}		
	}
	/*queuer		: function(f){
		this._queueTimerId = '';
		if(this.queue.length>0){
			if(this.call==false){
				call = this.queue.shift();
				call = call.replace(/ajax./,'this.');
				eval(call);
				if(this.queue.length>0){
					this._queueTimerId = setTimeout('ajax.checkQueue()',this.timer);
				}
			} else {
				this._queueTimerId = setTimeout('ajax.checkQueue()',this.timer);
			}
		} else {
			if(this.postQueue!=''){
				r = (this.postQueue.split(';'));
				for(i=0;i<r.length;i++){
					eval(r[i]);
				}
				this.postQueue = '';
			}
		}
	}*/
}

dom.onload = function(){
	this.loadTimer = '';
	if(dom.document.body!=null){
		this.loaded = true;
		for(i in this.functions){
			eval(this.functions[i]);
		}
	} else { if(this.loadTimer==''){ this.loadTimer = setTimeout("dom.onload()",300); } }
}

dom.getElement = function (elm){
	try {
		return document.getElementById(elm);
	} catch(e){
		try {
			return document.all(elm);
		} catch(e){ return false; }
	}
}

dom.setStyle = function(obj,property,value){
	if(obj!=null){
		try{
			eval('obj.style.'+property+' = "'+value+'"');
		} catch (e){
			eval('obj.'+property+' = "'+value+'"');
		}
	}
}

dom.getStyle = function(obj,property){
	if(obj!=null){
		try{ eval('ret = obj.style.'+property+';'); }
		catch (e){ eval('ret = obj.'+property+';'); }
		return ret;
	}
	return null;
}

dom.onload();

function createElement(elmName){
	if(arguments.length==1){
		return document.createElement(elmName);
	} else {
		if(document.all==undefined){
			ret = document.createElement(elmName);
			for(i=1;i<arguments.length;i++){
				eval("ret.setAttribute('"+arguments[i]+"','"+arguments[++i]+"')");
			}
		} else {
			props = "";
			for(i=1;i<arguments.length;i++){
				props += ' '+arguments[i]+'="'+arguments[++i]+'"';
			}
			eval("ret = document.createElement('<'+elmName+props+'>')");
		}
		return ret;
	}
}

function destroyElement(elmName){
	if(getElement(elmName)){
		document.body.removeChild(getElement(elmName));
	}
}

function getElement(elm){
	try {
		return document.getElementById(elm);
	} catch(e){
		try {
			return document.all(elm);
		} catch(e){ return false; }
	}
}

function setStyle(obj,property,value){
	if(obj!=null){
		try{
			eval('obj.style.'+property+' = "'+value+'"');
		} catch (e){
			eval('obj.'+property+' = "'+value+'"');
		}
	}
}

function getStyle(obj,property){
	if(obj!=null){
		try{ eval('ret = obj.style.'+property+';'); }
		catch (e){ eval('ret = obj.'+property+';'); }
		return ret;
	}
	return null;
}

function scrollTop(){
	if (document.documentElement && document.documentElement.scrollTop)
		theTop = document.documentElement.scrollTop;
	else if (document.body)
		theTop = document.body.scrollTop;
	return theTop;
}

function scrollLeft(){
	if (document.documentElement && document.documentElement.scrollLeft)
		theTop = document.documentElement.scrollLeft;
	else if (document.body)
		theTop = document.body.scrollLeft;
	return theTop;
}

function setAttribute(obj,attr,value){
	if(typeof eval("obj."+attr)!="undefined") {
		eval("obj."+attr+" = function(){ "+value+" }");
	} else if(obj.setAttribute){
		obj.setAttribute(attr,value);
	}
}

function checkFCK(item){
	if(typeof(FCKeditorAPI)!="undefined"){
		return ((FCKeditorAPI.GetInstance(item).GetXHTML() != '' && FCKeditorAPI.GetInstance(item).GetXHTML() != '<br>'))?1:0;
	} else {
		return ((document.forms['main'].elements[item].value != '' && document.forms['main'].elements[item].value != '<br>'))?1:0;
	}
}

function fetchFCK(item){
	return escape(((typeof(FCKeditorAPI)!="undefined")?FCKeditorAPI.GetInstance(item).GetXHTML():document.forms['main'].elements[item].value));
}

var Table = {
};

Table.create = function(){
	table = createElement("table");
}
Table.addThead = function(){
	thead = createElement("thead");
	table.appendChild(thead);
}
Table.addTbody = function(){
	tbody = createElement("tbody");
	table.appendChild(tbody);
}
Table.addTfoot = function(){
	tfoot = createElement("tfoot");
	table.appendChild(tfoot);
}
Table.addTr = function(dest){
	tr = createElement("tr");
	eval("dest.appendChild(tr)");
	return tr;
}
Table.addTd = function(dest){
	td = createElement("td");
	eval("dest.appendChild(td)");
	return td;
}
Table.display = function(dest){
	eval("dest.appendChild(table)");
}
Table.object = function(){
	return table;
}

function offsetX(event){
	if(event.offsetX){
		return event.offsetX;
	} else if(event.layerX){
		return event.layerX;
	} else {
		return false;
	}
}

function offsetY(event){
	if(event.offsetY){
		return event.offsetY;
	} else if(event.layerY){
		return event.layerY;
	} else {
		return false;
	}
}

var tinyId;
tinyId = new Array();
function initEditor(id) {
	tinyId[tinyId.length] = id;
	tinyMCE.execCommand('mceAddControl', false, id);
}

function doLogout(){
	ajax.load('utenti.php','doLogout&sezione=utenti');
}

Array.in_array = function(arr,key){
	for(i in arr){
		if(arr[i]==key){ return i; }
	}
	return -1;
}

function in_array(arr,key){
	for(i in arr){
		if(arr[i]==key){ return i; }
	}
	return -1;
}
