// Set Netscape up to run the "captureMousePosition" function whenever
// the mouse is moved. For Internet Explorer and Netscape 6, you can capture
// the movement a little easier.
if (document.layers) { // Netscape
    document.captureEvents(Event.MOUSEMOVE);
    document.onmousemove = captureMousePosition;
} else if (document.all) { // Internet Explorer
    document.onmousemove = captureMousePosition;
} else if (document.getElementById) { // Netscape 6
    document.onmousemove = captureMousePosition;
}


// Global variables
xMousePos = 0; // Horizontal position of the mouse on the screen
yMousePos = 0; // Vertical position of the mouse on the screen
xMousePosMax = 0; // Width of the page
yMousePosMax = 0; // Height of the page

function captureMousePosition(e) {
	try{
    if (document.layers) {
        // When the page scrolls in Netscape, the event's mouse position
        // reflects the absolute position on the screen. innerHight/Width
        // is the position from the top/left of the screen that the user is
        // looking at. pageX/YOffset is the amount that the user has
        // scrolled into the page. So the values will be in relation to
        // each other as the total offsets into the page, no matter if
        // the user has scrolled or not.
        xMousePos = e.pageX;
        yMousePos = e.pageY;
        xMousePosMax = window.innerWidth+window.pageXOffset;
        yMousePosMax = window.innerHeight+window.pageYOffset;
    } else if (document.all) {
        // When the page scrolls in IE, the event's mouse position
        // reflects the position from the top/left of the screen the
        // user is looking at. scrollLeft/Top is the amount the user
        // has scrolled into the page. clientWidth/Height is the height/
        // width of the current page the user is looking at. So, to be
        // consistent with Netscape (above), add the scroll offsets to
        // both so we end up with an absolute value on the page, no
        // matter if the user has scrolled or not.
        xMousePos = window.event.x+document.body.scrollLeft;
        yMousePos = window.event.y+document.body.scrollTop;
        xMousePosMax = document.body.clientWidth+document.body.scrollLeft;
        yMousePosMax = document.body.clientHeight+document.body.scrollTop;
    } else if (document.getElementById) {
        // Netscape 6 behaves the same as Netscape 4 in this regard
        xMousePos = e.pageX;
        yMousePos = e.pageY;
        xMousePosMax = window.innerWidth+window.pageXOffset;
        yMousePosMax = window.innerHeight+window.pageYOffset;
    }
	}catch(err){
		//do nothing
		//alert(err);
	}
}

/**
* show the floater with idValue
*/
function showFloater(idValue, followMouse){
	if (!document.getElementById(idValue)) 
		return;
	var obj = document.getElementById(idValue);
	// in IE absolute positioning doesn't work in case of scrollable divs,
	// but it works correcly skipping this scope
	if(followMouse && !document.all){
		obj.style.left = xMousePos + 'px';
		obj.style.top = yMousePos + 'px';
	}
	
	obj.style.visibility = 'visible';
	return;
}

function hideFloater(idValue){
	hide(idValue);
}

function hide(idValue){
	if (!document.getElementById(idValue))
		return;
	document.getElementById(idValue).style.visibility = "hidden";
	return;
}

function hideDelay(divId, delay){
	setTimeout('$(\''+divId+'\').hide()', delay);
}

function getClock(){
	return("<div class='loading'><br/><br/><b>loading...</b><br/><br/><br/><br/></div>");
}

function showClock(divId){
	$(divId).update(getClock());
}

function setBlankDate(element_id){
	$(element_id).value = '';
}

function switch_form_action(form_id, action){
	$(form_id).action = action;
	//alert($(form_id).action);
}

function toggleDisplay(id){
	if (document.layers)
	{
		if(document.layers[id]==null) return;
		current = (document.layers[id].display == 'none') ? 'block' : 'none';
		document.layers[id].display = current;
	}
	else if (document.all)
	{
		if(document.all[id]==null) return;
		current = (document.all[id].style.display == 'none') ? 'block' : 'none';
		document.all[id].style.display = current;
	}
	else if (document.getElementById)
	{
		if(document.getElementById(id)==null) return;
		vista = (document.getElementById(id).style.display == 'none') ? 'block' : 'none';
		document.getElementById(id).style.display = vista;
	}
}



function Trim(STRING){
	STRING = LTrim(STRING);
	return RTrim(STRING);
}

function RTrim(STRING){
	while(STRING.charAt((STRING.length -1))==" "){
	STRING = STRING.substring(0,STRING.length-1);
	}
	return STRING;
}


function LTrim(STRING){
	while(STRING.charAt(0)==" "){
	STRING = STRING.replace(STRING.charAt(0),"");
	}
	return STRING;
}

function open_multipitch_tables(anchor){
	window.open(
		'valutazione_mp.php#'+anchor,
		'Multipitch', 'width=600,height=400,status=no,resizable=yes,scrollbars=yes,top=200,left=200'
	);
	return;
}

function preview(text){
	window.open(
		'message_preview.php?testo='+text,
		'Preview', 'width=400,height=200,status=no,resizable=yes,scrollbars=yes,top=200,left=200'
	);
       return;	
}

function open_lista_rp(grado){
    win_ref = window.open(
        '_blank',
        'lista_rp', 'width=600,height=400,status=no,resizable=yes,scrollbars=yes,top=200,left=200'
    );
    document.getElementById(grado).submit();
    win_ref.focus();
}

function show_rp_list(url){
	$('grid_list_div').show();
	$('overlay').show();	
	$('grid_list_div').update(getClock());
	new Ajax.Updater("grid_list_div", url);
}

function show_bloc_list(url){
	$('grid_list_div').show();
	$('overlay').show();	
	$('grid_list_div').update(getClock());
	new Ajax.Updater("grid_list_div", url);
}

function update_rp_hard_soft(id, hard_soft, url){
	var element_id = 'rp_row_' + id;
	$("hard_soft_span_" + id).update("<p id='loading'>updating...</p>");
	new Ajax.Updater(element_id, url);
}

function show_comment_editor(url, id){
	$(id).show();
	$(id).update(getClock());
	//$$('div.comment_editor').each(hide);
	$(id).scrollTo();
	new Ajax.Updater(id, url, {evalScripts:true});
}

function hide_grid_list_div(){
	$('overlay').hide();
	$('grid_list_div').hide();
}





