/*
CREATED BY ITIGIA
*/

/*The following three declaration is GLOBALLY needed by contextHandler and imageOptions
Further implementations can be found in HTML

Goddamn I'm so tired...

<body onControlSelect="activeImg = event.srcElement" oncontextmenu="ctx = contextHandler(event.srcElement); if (ctx == 1) {return false;}">

*/

function del_ok(rut) {
	rut.style.visibility = 'visible';
}


var oImagePopup = window.createPopup();
var ctx = null;
var activeImg = null;

function contextHandler(obj) {
	switch(obj.tagName) {
		case 'IMG' :
			imageOptions(obj);
			return 1;
		break;

		default:
			return 0;
		break;
	} //switch
} //function


//-*-*-*	Allapot mentese/visszaallitasa
function DoSave(objname)
{
	obj = document.getElementById(objname);
	obj.setAttribute("content", obj.innerHTML);
	obj.save(objname+"EditContent");
}

function DoLoad(objname)
{
	obj = document.getElementById(objname);
	obj.load(objname+"EditContent");
	content = obj.getAttribute("content");
	if (content != null) obj.innerHTML=content;
}

function setobjFocus(objid) {
	$obj = document.getElementById(objid);
	$obj.focus();
} //function


var cursorPos;
function saveCursorPos()
{
	cursorPos=document.selection.createRange();
	//.duplicate()
}

function paste2cpos(str)
{
	if (str && cursorPos) 
	{
		//cursorPos.pasteHTML(str);
		cursorPos.text = str;
		//Paste utan visszaallitja a kurzor eredeti poziciojat
		cursorPos.select();
	}
}

function htmlMosoda(onEdit, onWash)
{
	objEdit	= document.getElementById(onEdit);
	objWash	= document.getElementById(onWash);

//alert(objWash.all.length);
//objEdit.innerHTML = objWash.outerText;
	tmp = objWash.outerText;
/*
//todo: arraybe szedni
	var rx_br = new RegExp("\n",'gi');
	var rx_html = new RegExp("<",'gi');
	var rx_html_ = new RegExp(">",'gi');
	//var rx_html = new RegExp("<.*?>",'gi');

	tmp = tmp.replace(rx_html,'&lt;');
	tmp = tmp.replace(rx_html_,'&gt;');
	tmp = tmp.replace(rx_br,"<BR>\n");
	//tmp = tmp.replace(rx_html,'');
*/
//paste2cpos(objWash.outerText);
paste2cpos(tmp);
objWash.innerHTML = '';
//setobjFocus(onEdit);
//objEdit.setActive();
/*
		for (var intLoop = 0; intLoop < objEdit.all.length; intLoop++) 
		{
		        el = objEdit.all[intLoop];
		        el.removeAttribute("className","",0);
		        el.removeAttribute("style","",0);
		}

	    objWash.innerHTML = objEdit.innerHTML; 
*/
}


//Docks the given "traveler" object before "receiver"
/*
area can be:

beforeBegin		Inserts oElement immediately before the object. 
afterBegin		Inserts oElement after the start of the object but before all other content in the object. 
beforeEnd		Inserts oElement immediately before the end of the object but after all other content in the object. 
afterEnd		Inserts oElement immediately after the end of the object. 
*/

function dockObject(objnameTraveler, objnameReceiver, area) 
{
	obj = document.getElementById(objnameTraveler);
	obj.style.position = 'relative';
	obj.style.visibility = 'visible';
	obj_src = document.getElementById(objnameReceiver);

	obj_src.insertAdjacentElement(area,obj);
} //function

//Objektum szelesseget es magassagat tarolja (objprops['div_maci'] = 'height,width';)
var objprops = new Array();

//Dimenziok tarolasa objprops-ba
function setDim(objname)
{
	obj = document.getElementById(objname);
	
	w = (obj.style.width ? obj.style.width : '100%');
	h = obj.style.height;
	
	objprops[objname] = w+','+h;
} //function

//Dimek lekerese
//Ha nincs a listaban, akkor gyorsan betesszuk, igy a korabban meg nem kezelt objok is elerhetoek lesznek
function getDim(objname)
{
	if (! objprops[objname])
		setDim(objname);

	dim = objprops[objname].split(',');

	return dim;
} //function

function sArea(objname,relpos)
{
	objlist = objname.split(',');
	for($i=0; $i < objlist.length; $i++)
	{
		obj = document.getElementById(objlist[$i]);
		obj.style.visibility = 'visible';
		
		dim = getDim(objlist[$i]);
		obj.style.width = dim[0];
		obj.style.height = dim[1];
			
		if (relpos == 1)
			obj.style.position = 'relative';
	}
}

function hArea(objname, abspos)
{
	objlist = objname.split(',');

	for($i=0; $i < objlist.length; $i++)
	{
		obj = document.getElementById(objlist[$i]);
		obj.style.visibility = 'hidden';
		
		dim = getDim(objlist[$i]);
		obj.style.width = 1;
		obj.style.height = 1;

		if (abspos == 1)
			obj.style.position = 'absolute';
	}
}

function inslink(content,pre,app) 
{
	var sel = document.selection;
	if (sel!=null) 
	{
		var rng = sel.createRange();
		if (rng!=null)
		{
			src = "<a href='"+pre+content+app+"'>"
			rng.pasteHTML(src+rng.text+'</A>');
		} //if
	} //if
} //function
