function openwindow(url, width, height) {
	// hack for IE 7
	if(navigator.appVersion.indexOf('MSIE 7') != -1) {
		height += 20;
	}

	xposition = 20; yposition = 20;
	if ((parseInt(navigator.appVersion) >= 4 )){
		xposition = (screen.width - width) / 2;
		yposition = (screen.height - height) / 2;
	}

	args = "width=" + width + ","
		    + "height=" + height + ","
			+ "location=0,"
			+ "menubar=0,"
			+ "resizable=0,"
			+ "scrollbars=no,"
			+ "status=0,"
			+ "titlebar=0,"
			+ "toolbar=0,"
			+ "hotkeys=0,"
			+ "screenx=" + xposition + ","  //NN Only
			+ "screeny=" + yposition + ","  //NN Only
			+ "left=" + xposition + ","     //IE Only
			+ "top=" + yposition;           //IE Only
	ww = window.open(url, '', args);
}



function addEvent(obj, sType, fn, rmFn)
{
	if(obj.addEventListener) {
		try
		{
			obj.removeEventListener(sType, rmFn, false);
		}
		catch(e)
		{
		}
		obj.addEventListener(sType, fn, false);
	}
	else if (obj.attachEvent)
	{
		try
		{
			var r = obj.detachEvent('on'+sType, rmFn);
		}
		catch(e)
		{
		}
		var r = obj.attachEvent('on'+sType, fn);
	}
	else
	{
		alert("Neimanoma prisieti veiksmo!");
	}
}

function removeEvent(obj, sType, fn) {
	if (obj.removeEventListener) {
		obj.removeEventListener(sType, fn, false);
	}
	else {
		obj.detachEvent('on' + sType, fn);
	}
}

function removeAllEditors() {
	for(i = 0; i < document.forms.length; i++) {
		if(document.forms[i] != null)
			for(j = 0; j < document.forms[i].elements.length; j++) {
				element = document.forms[i].elements[j];
				if (tinyMCE.get(element.id) != null) {
					element.value = tinyMCE.get(element.id).getContent();
					tinyMCE.execCommand('mceRemoveControl', false, element.id);
				}
			}
	}
}

function toggleEditor(id) {
	var elm = document.getElementById(id);
	// submitinant tevine forma reikia nuimti redaktoriu
	if (tinyMCE.getInstanceById(id) == null) {
		$('.toggle-editor-on').hide();
		$('.toggle-editor-off').show();
		tinyMCE.execCommand('mceAddControl', false, id);
	}
	else {
		$('.toggle-editor-off').hide();
		$('.toggle-editor-on').show();
		tinyMCE.execCommand('mceRemoveControl', false, id);
	}
}
