var LF = String.fromCharCode(10),
	QT = String.fromCharCode(34);

function setDisplayById (id, v)
{
	return setDisplay(dgeid(id),v);
}
function setDisplay (obj, v)
{
	if (obj.style==undefined)	return false;
	if (v==1)		obj.style.display = '';
	else 			obj.style.display = 'none';
	return true;
}
function toggleDisplay (obj)
{
	if (obj.style==undefined)	return false;
	return setDisplay(obj, obj.style.display=='none');
}
function setVisibility (obj, v)
{
	if (obj.style==undefined)	return false
	if (v==1)	{	obj.style.visibility = 'visible';	}
	else 		{	obj.style.visibility = 'hidden';	}
	return true
}
function setVisibilityById (id, v)
{
	var obj=dgeid(id);
	return setVisibility(obj,v);
}

function dgeid (id)
{	return document.getElementById(id);
}

function alert_obj(o,ret)
{
	var s = '', i;
	for (i in o)	s += i+': '+o[i]+LF;	//';  ';
	if (ret)	return s;
	else		alert(s);
}
function trim(s)
{
	var trim_left=arguments[1], trim_right=arguments[2], r=s;
	if (!trim_left && !trim_right)	trim_left=trim_right=1;
	if (trim_left)		while (r.indexOf(' ')==0)			r = r.substr(1);
	if (trim_right)		while (r.substr(r.length-1)==' ')	r = r.substr(0,r.length-1);
	return r;
}

function frame_deasupra ()
{
	this.width	= 500;
	this.height	= 420;
	this.top	= (document.body.clientHeight - this.height) / 2;
	this.left	= (document.body.clientWidth - this.width) / 2;
	this.title	= '';
	this.src	= '';
	
	this.d = dgeid('d_frame_deasupra');
	if (!this.d)
	{	var d = document.createElement('DIV');
		d.id = 'd_frame_deasupra';
		d.className = 'frame_deasupra';
		document.body.appendChild(d);
		this.d = dgeid('d_frame_deasupra');
	}
	
	this.show = function()
	{	setDisplay(this.d,1);
		var fr=dgeid('fr_deasupra');
		fr.focus();
		fr.src = this.src;
	}
	this.hide = function()
	{	setDisplay(this.d,0);
	}
	this.display = function(src)
	{
		if (!this.d)	{ alert('Browser problem :('); return false; }
		if (arguments[1])	this.d.style.top = parseInt(dgeid('body').scrollTop)+100;		//tin cont de scroll
		else				this.d.style.top = this.top;
		this.d.style.left	= this.left;
		this.d.style.width	= this.width;
		this.d.style.height	= this.height;
		if (src)	this.src = src;
		var				h = '<div class="click" title="Inchide" style="position:absolute; top:2; right:20; border:1px solid #777777; background:#cfcfcf; padding:3;" onClick="setDisplay(this.parentNode,0)">x</div>';
		if (this.title)	h+= '<div style="position:absolute; top:0; left:0; width:300; border:1px solid #777777; background:#cfcfcf; padding:3;"> &nbsp; <b>'+this.title+'</b></div>';
		if (this.src)	h+= '<iframe id="fr_deasupra" src="'+this.src+'" width="100%" height="100%" scrolling="" border="0" style="border:none;"></iframe>';
		this.d.innerHTML = h;
		if (this.src)	this.show();
	}
}

function layer_deasupra ()
{
	this.width	= 500;
	this.height	= 420;
	this.top	= 120;
	this.left	= (document.body.clientWidth - this.width) / 2;
	this.title	= '';
	this.src	= '';
	
	this.d = dgeid('d_layer_deasupra');
	if (!this.d)	return false;
	
	this.show = function()
	{	setDisplay(this.d,1);
		dgeid('layer_deasupra').focus();
	}
	this.hide = function()
	{	setDisplay(this.d,0);
	}
	this.display = function(src)
	{
		if (!this.d)	{ alert('Browser problem :('); return false; }
		this.d.style.width	= this.width;
		this.d.style.height	= this.height;
		this.d.style.top	= this.top;
		this.d.style.left	= this.left;
		if (src)	this.src = src;
		var				h = '<div class="click" title="Inchide" style="position:absolute; top:2; right:20; border:1px solid #777777; background:#cfcfcf; padding:3;" onClick="setDisplay(this.parentNode,0)">x</div>';
		if (this.title)	h+= '<div style="position:absolute; top:0; left:0; width:300; border:1px solid #777777; background:#cfcfcf; padding:3;"> &nbsp; <b>'+this.title+'</b></div>';
		if (this.src)	h+= '<iframe id="fr_deasupra" src="'+this.src+'" width="100%" height="100%" scrolling="" border="0" style="border:none;"></iframe>';
		this.d.innerHTML = h;
		if (this.src)	this.show();
		return false;
	}
}

var modal=null;
//var modal=new Window(null);
function openModal(objWindowParams)
{
	modal = new Window(objWindowParams);
	if (arguments[1]==false);	else	modal.showCenter(true);
	modal.refresh();
}

function activeLoading(value)
{
	if (value)	Dialog.info("<b>Se încarcă...</b>", {className:'alphacube', width:250, height:100, showProgress: true});
	else		Dialog.closeInfo();
}


var isIE, isFF, isOpera, isGecko, isSafari, isKonqueror;
function get_ua()
{
	var ua = navigator.userAgent.toLowerCase();
	//alert(ua);
	isIE		= ((ua.indexOf("msie") != -1) && (ua.indexOf("opera") == -1) && (ua.indexOf("webtv") == -1)); 
	isFF		= (ua.indexOf("firefox") != -1); 
	isOpera		= (ua.indexOf("opera") != -1); 
	isGecko		= (ua.indexOf("gecko") != -1);
	isSafari	= (ua.indexOf("safari") != -1);
	isKonqueror = (ua.indexOf("konqueror") != -1);
}
get_ua();

if (!isIE){
HTMLElement.prototype.insertAdjacentElement = function(where, element) {
	switch (where.toLowerCase()) {
		case "beforebegin":
			this.parentNode.insertBefore(element, this);
			break;
		case "afterbegin":
			this.insertBefore(element, this.firstChild);
			break;
		case "beforeend":
			this.appendChild(element);
			break;
		case "afterend":
			this.parentNode.insertBefore(element, this.nextSibling);
			break;
	}
};
}
