// Place your application-specific JavaScript functions and classes here
// This file is automatically included by javascript_include_tag :defaults
//document.getElementById
function editme() {
    hide(getid(this.id));
    var suffix=getid(this.id).replace("report_", "");
    block('prompt_'+suffix);
    block('action_prompt_'+suffix);
}

function remaineditme() {
    deactivateprompt(getid(this.id));
    block('cancel_action_'+ getid(this.id));
}

function releaseeditme() {
    hide(getid(this.id));
    var suffix=getid(this.id).replace("prompt_", "");
    block('report_'+suffix);
    hide('action_prompt_'+suffix);
}

function cancelremain(element) {
    hide('cancel_action_'+ element);
    hide(element);
    var suffix=element.replace("prompt_", "");
    block('report_'+suffix);
    activateprompt(element);
}


/*
 * Activate functions, handling compatibility
 */
function activateprompt(this_id) {
    if ($(this_id).addEventListener) {
	$(this_id).addEventListener('click',remaineditme,false);
	$(this_id).addEventListener('mouseout',releaseeditme,false);
    }
    else if ($(this_id).attachEvent) {
	$(this_id).attachEvent('onclick',remaineditme);
	$(this_id).attachEvent('onmouseout',releaseeditme);
    }
    else { /*TODO: Ouch*/ }
}

function activatereport(this_id) {
    if ($(this_id).addEventListener) {
	$(this_id).addEventListener('mouseover',editme,false)
	    }
    else if ($(this_id).attachEvent) {
	$(this_id).attachEvent('onmouseover',editme);
    }
    else { /*TODO: Ouch*/ }
}

/*
 * Deactivate functions, handling compatibility
 */
function deactivateprompt(this_id) {
    if ($(this_id).removeEventListener) {
	$(this_id).removeEventListener('mouseout',releaseeditme,false);
	$(this_id).removeEventListener('click',remaineditme,false);
    }
    else if ($(this_id).detachEvent) {
	$(this_id).detachEvent('onmouseout',releaseeditme);
	$(this_id).detachEvent('onclick',remaineditme);
    }
    else { /*TODO: Ouch*/ }
}

function deactivatereport(this_id) {
    if ($(this_id).removeEventListener) {
	$(this_id).removeEventListener('mouseover',editme,false);
    }
    else if ($(this_id).detachEvent) {
	$(this_id).detachEvent('onmouseover',editme);
    }
    else { /*TODO: Ouch*/ }
}


/*
 * styles management functions
 */

function hide(this_id) {
    $(this_id).style.display = 'none';
}

function block (this_id) {
    $(this_id).style.display = 'block';
}

function getid(id_candidate) {
    if (id_candidate == undefined)
	{
	    if (window.event)
		{
		    return window.event.srcElement.id;
		}
	}
    return id_candidate;
}

//not working yet, not used for anyone
function resize(e) {
    if (e.target)
{
targ = e.target;
}
else if (e.srcElement)
{
targ = e.srcElement;
}
$(targ).textContent=e.layerY;
}