/*
Created by ITIGIA @ Dixie Flatline
*/

function del_ok(objname) {
	obj = document.getElementById(objname);
	obj.style.visibility = 'visible';
}

//Show hide rows...
//id = '1' or '1,2,3', so a comma delimeted list is allowed
function shRow(objname, id)
{
	rows = id.split(',');

	for ($i=0; $i < rows.length; $i++)
	{
		x = document.getElementById(objname+rows[$i]);
		x.style.visibility = 'visible';
		x.style.position = 'relative';
	}
}



function setobjFocus(objid) {
	$obj = document.getElementById(objid);
	$obj.focus();
} //function

function email(email)
{
	var regexp = /#/gi;
	em = email.replace(regexp,'@');
	var regexp = /\*/gi;
	em = em.replace(regexp,'.');

	self.location = 'mailto:'+em;
	//top.location.href = 'mailto:'+em;
}

function winCenter(pageURL, pageName, popWidth, popHeight) 
{
	var posLeft	= (screen.width - popWidth) / 2;
	var posUp	= (screen.height - popHeight) / 2;

	//location,status,scrollbars,
	winProp	= 'width='+popWidth+',height='+popHeight+',left='+posLeft+',top='+posUp;

	Win = window.open(pageURL, pageName, winProp);
	if (parseInt(navigator.appVersion) >= 4) { Win.window.focus(); }
} 


function puttext(input, tipus) 
{
	objname = 'editor';
document.getElementById(objname).focus();
	switch(tipus) {
		//Bold
		case 'b' :
			settag(objname,'[B]','[/B]');
		break;

		case 'i' :
			settag(objname,'[I]','[/I]');
		break;

		case 'u' :
			settag(objname,'[U]','[/U]');
		break;

		case 'l' :
			settag(objname,'[URL]','[/URL]');
		break;

		case 'e' :
			settag(objname,'[EMAIL]','[/EMAIL]');
		break;

		case 'q' :
			settag(objname,'[QUOTE]','[/QUOTE]');
		break;

		case 'c' :
			settag(objname,'[CODE]','[/CODE]');
		break;

		case 'k' :
			settag(objname,'[IMG]','[/IMG]');
		break;

		case 'h' :
			settag(objname,'[SPOILER]','[/SPOILER]');
		break;
	} //switch
}


var cursorPos; 
function saveCursorPos()
{
		cursorPos=document.selection.createRange().duplicate();
        //.duplicate()
}

/*
NOTE:

PROBLEM: MSIE - If accesskeys are used, the createrange drops start and end positions, therefore it is useless.
SOLUTION: Set az onselect event on the receiving edit area and save the actual selection into a global variable and use it afterwards

*/
function settag(objname,strPrepend,strAppend)
{
	obj = document.getElementById(objname);
	//MSIE
	if (document.selection)
	{
		obj.focus();
		if (cursorPos.text)
		{
		//accesskeys won't work under MSIE, so this is needed
			cursorPos.text = strPrepend + cursorPos.text + strAppend;
			cursorPos.select();
		}
		else
		{
			sel = document.selection.createRange();
			sel.text = strPrepend + sel.text + strAppend;
			sel.select();
		}
	}
	//MOZILLA
	else if (obj.selectionStart || obj.selectionStart == '0')
	{
		var sPos  = obj.selectionStart;
		var ePos  = obj.selectionEnd;
		seltext = obj.value.substring(sPos,ePos);

		obj.value = obj.value.substring(0,sPos) + strPrepend + seltext + strAppend + obj.value.substring(ePos, obj.value.length);
	}
	else
	{
		obj.value += strPrepend + strAppend; 
	}
} //function


function paste2cpos(objname,str)
{
	obj = document.getElementById(objname);
	//MSIE
	if (document.selection)
	{
		obj.focus();

		if (str)
	    {
			sel = document.selection.createRange();
			sel.text = str;
	    } //if
	}
	//MOZILLA
	else if (obj.selectionStart || obj.selectionStart == '0')
	{
		var sPos  = obj.selectionStart;
		var ePos  = obj.selectionEnd;
		obj.value = obj.value.substring(0,sPos) + str + obj.value.substring(ePos, obj.value.length);
	}
	else
	{
		objname.value += str;
	}
	
}

