function replaceEditable(id, callback, annex, annex2)
{
	var textElement = $("editable_text_" + id);
	var editImgElement  = $('editable_img_' + id);
	
	var inputElement = new Element('input', { 'id': 'editable_input_' + id, 'type': 'text', 'value': $('editable_text_' + id).innerHTML, 'onkeydown': 'checkForEnterEditable(event, \'' + id + '\', \'' + callback + '\', \'' + annex + '\', \'' + annex2 + '\');'});
	var okImgElement = new Element('img', { 'id': 'editable_img_' + id, 'src': 'style/icons/dialog/dialog-ok.png', 'style': 'cursor:pointer; padding-left: 4px; vertical-align: top;', 'onclick': 'revertEditable(\'' + id + '\', \'' + callback + '\', \'' + annex + '\', \'' + annex2 + '\');'});	
	
	textElement.parentNode.replaceChild(inputElement, textElement);
	editImgElement.parentNode.replaceChild(okImgElement, editImgElement);
}

function checkForEnterEditable(e, id, callback, annex, annex2)
{
	var keynum = 0;
	if(window.event) // IE
	{
		keynum = e.keyCode;
	}
	else if(e.which) // Netscape/Firefox/Opera
	{
		keynum = e.which;
	}
	if(keynum == 13)
		revertEditable(id, callback, annex, annex2);
}

function revertEditable(id, callback, annex, annex2)
{
	eval(callback + "('" + $F('editable_input_' + id) + "', '" + annex + "', '" + annex2 + "')");
	
	var inputElement = $("editable_input_" + id);
	var okImgElement = $("editable_img_" + id);
	
	var textElement = new Element('span', { 'id': 'editable_text_' + id, 'style': 'cursor:pointer;', 'onclick': 'replaceEditable(\'' + id + '\', \'' + callback + '\', \'' + annex + '\', \'' + annex2 + '\');'}).update($F('editable_input_' + id));
	var editImgElement = new Element('img', { 'id': 'editable_img_' + id, 'src': 'style/icons/edit.png', 'style': 'cursor:pointer; padding-left: 4px; vertical-align: bottom;', 'onclick': 'replaceEditable(\'' + id + '\', \'' + callback + '\', \'' + annex + '\', \'' + annex2 + '\');'});	

	inputElement.parentNode.replaceChild(textElement, inputElement);
	okImgElement.parentNode.replaceChild(editImgElement, okImgElement);
}

function showSuggest(id, callback){
    var span = $('gui_suggest_' + id);
    span.appendChild(newChild);
    span.
    alert("gui_suggest_" + id);
}

var dialog = new Dialog();

function Dialog() {

    this.show = function(title, okActionString) {
        var lockDiv = $('lock');
        lockDiv.style.display = "block";
        lockDiv.setAttribute("onclick", "");

        var dialogDiv = document.createElement("div");
        //dialogDiv.setAttribute("style", "position: relative; width: 80%; height: 80%; top: 10%; left: 10%; border: 1px solid black; background-color: #fffebf; padding: 10px;");
        dialogDiv.setAttribute("id", "dialog_dev");
        dialogDiv.setAttribute("onclick", "");
        var dialogTitle = document.createElement("h1");
        dialogTitle.appendChild(document.createTextNode(title));
        dialogDiv.appendChild(dialogTitle);
        lockDiv.appendChild(dialogDiv);

        var contentDiv = document.createElement("div");
        height = dialogDiv.getHeight() - 110;
        contentDiv.setAttribute("id", "dialog_content");
        contentDiv.setAttribute("style", "height: " + height + "px; overflow: auto;");
        dialogDiv.appendChild(contentDiv);

        var OKButton = this.createButton(Lok, okActionString + "; d = new Dialog(); d.hide();", "dialog/dialog-ok");
        style = OKButton.getAttribute("style");
        OKButton.setAttribute("style", style + " position: absolute; bottom: 15px; right: 120px;");
        dialogDiv.appendChild(OKButton);

        var CancelButton = this.createButton(Lcancel, "d = new Dialog(); d.hide();", "dialog/dialog-cancel");
        style = CancelButton.getAttribute("style");
        CancelButton.setAttribute("style", style + " position: absolute; bottom: 15px; right: 15px;");
        dialogDiv.appendChild(CancelButton);
    }

    this.hide = function() {
        var lockDiv = $('lock');
        lockDiv.style.display = "none";
        lockDiv.removeChild($('dialog_dev'));
        lockDiv.setAttribute("onclick", "barList.Blink();");
    }

    this.createButton = function(text, action, icon) {
        var a = document.createElement("a");
        a.setAttribute("class", "actionlink");
        a.setAttribute("style", "background-image: url('style/icons/" + icon + ".png');");
        a.setAttribute("onclick", action);
        a.appendChild(document.createTextNode(text));
        return a;
    }

    this.blink = function()
    {
        element = $('dialog_dev');
        element.style.backgroundColor = "red";
        var counter = 0;
        blinkInterval = window.setInterval(function()
        {
            switch(counter)
            {
                case 0:
                    element.style.backgroundColor = "#fffebf";
                    break;
                case 1:
                    element.style.backgroundColor = "red";
                    break;
                case 2:
                    element.style.backgroundColor = "#fffebf";
                    window.clearInterval(blinkInterval);
            }
            counter++;
        }, 200);
    }
}



