	var editor;

	function createEditor( field ) {
		if ( editor )
			return;
		editor = CKEDITOR.replace( field );
	}

	function removeEditor() {
		if ( !editor )
			return;

		editor.destroy();
		editor = null;
	}

/*
 * The Prototype Dollar function - returns the HTML element of the given ID.
 * Normally it takes an ID as an element eventhough it does not appear here!
 * Here the arguments are accessed via the 'arguments' variable.
 */
function $() {
    var elements = new Array();
    for (var i = 0; i < arguments.length; i++) {
        var element = arguments[i]; 
        if (typeof element == 'string') {
            element = document.getElementById(element);
        }
        if (arguments.length == 1) {
            return element;
        }
        elements.push(element);
    }
    return elements;
}


/*
 * Computes the document's viewport width.
 */
function getDocumentWidth () {
    var width;
    
    if ( window.innerWidth ) {
        // Normal behaviour, except IEs
        width  = window.innerWidth;
    } else if ( document.documentElement ) {
        // IE 6 strict mode
        width = document.documentElement.clientWidth;
    } else {
        // Desperate solution, other IEs
        width = document.body.clientWidth;
    }
    
    return width;
}

/*
 * Computes the document's viewport height.
 */
function getDocumentHeight () {
    var height;
    
    if ( window.innerWidth ) {
        // Normal behaviour, except IEs
        height = window.innerHeight;
    } else if ( document.documentElement ) {
        // IE 6 strict mode
        height = document.documentElement.clientHeight;
    } else {
        // Desperate solution, other IEs
        height = document.body.clientHeight;
    }
    
    return height;
}

function setIntoIFrame(act, page, menuitemid, langid) {
	if (act) {
		document.getElementById("targetcontent").src = page + "?menuitemid=" + menuitemid;
		document.getElementById("targetmenu").src = "adminsubmenu.jsp?menuitemid=" + menuitemid + "&langID=" + langid;
	}
}

function setTitle(title) {
	if (title) {
		this.title = title;
	}
}

function trMouseOver ( tr ) {
    if ( tr.className == "selected" ) {
    	tr.className = "hover_selected";
    } else {
	    tr.className = "hover";
    }
}

function trMouseOut ( tr ) {
    if ( tr.className == "selected" ) {
        tr.className = "selected";
    } else if ( tr.className == "hover_selected" ) {
    	tr.className = "selected";
    } else {
        tr.className = "";
    }
}

function popupWindow (saved, page, w, h) {
	if (saved == true) {
		var obj_calwindow = window.open(
			page,
			'popup_window', 
			'"location=1,' +
			'width=' + w + ',' +
			'height='+ h + ',' +
			'status=0,resizable=1,scrollbars=1,dependent=1,alwaysRaised=1"'
		);
		obj_calwindow.moveTo(w, h);
		obj_calwindow.opener = window;
		obj_calwindow.focus();
	} else {
		alert("Please save the entity record before you try to enter detailed field data");
	}
}

/* Toggles a component's visibility */
function toggleVisibility ( component_id ) {
	var obj = document.getElementById( component_id );
	if ( obj ) {
		if ( obj.style.display == "none" ) {
			obj.style.visibility = "visible";
			obj.style.display    = "block";
		} else if ( obj.style.display == "block" ) {
			obj.style.visibility = "hidden";
			obj.style.display    = "none";
		}
	}
	return;
}
