/*****************/
/* Message popup */
/*               */
/* Base library  */
/*****************/

function getScrollTop(){
	var pos = 0;
	if (window.pageYOffset)	{	pos = window.pageYOffset;	}
	else if (document.documentElement && document.documentElement.scrollTop) { pos = document.documentElement.scrollTop; }
	else if (document.body) { pos = document.body.scrollTop; }
	return pos;
}

function getScrollLeft(){
	var pos = 0;
	if (window.pageXOffset)	{	pos = window.pageXOffset; }
	else if (document.documentElement && document.documentElement.scrollLeft)	{	pos += document.documentElement.scrollLeft; }
	else if (document.body)	{	pos += document.body.scrollLeft; }
	return pos;
}

function getWidth() {
	var width = 0;
	if (document.documentElement && document.documentElement.offsetWidth) { width = document.documentElement.offsetWidth; }
	else if (document.documentElement && document.documentElement.clientWidth) { width = document.documentElement.clientWidth; }
	else if (document.body && document.body.offsetWidth) { width = document.body.offsetWidth; }
	else if (document.body && document.body.clientWidth) { width = document.body.clientWidth; }
	else if (window.innerWidth) { width = window.innerWidth; }
	return width;
}

/* This function has the behaviour to return the correct main window's height. */
function getHeight() {
 var window_height = 0;
 if(typeof(window.innerWidth) == "number") {
   //Browser not IE
   window_height = window.innerHeight;
 } else if(document.documentElement && (document.documentElement.clientHeight || document.documentElement.clientWidth)){
   //Compatible with IE 6+
   window_height = document.documentElement.clientHeight;
 } else if(document.body && (document.body.clientHeight || document.body.clientWidth)){
   //Compatibler with IE 4
   window_height = document.body.clientHeight;
 }
 return window_height;
}

// Display a message on screen
function show(div,mess,event) {
	if(document.readyState=="complete" || !(/*@cc_on!@*/false)){
		/*alert(document.getElementById(div));*/
		if(!document.getElementById(div)){
			var elem = document.createElement('div');
			if(mess) elem.innerHTML = mess;
			ghrs_setAttributeMP(elem, 'id', div);
			document.getElementsByTagName("body")[0].appendChild(elem);
		}
		var op = document.getElementById(div);
		var Xoffset, Yoffset;
		
		var clientX = (arguments.length > 3) ? arguments[3] : event.clientX;
		var clientY = (arguments.length > 4) ? arguments[4] : event.clientY;
		op.innerHTML = mess;
		
		/* Unitravel 2008 bug solving */
		/*var wrp_left_mod = 0;
		var wrp_top_mod = 0;
		if(document.getElementById("gui_wrp")) wrp_left_mod = document.getElementById("gui_wrp").offsetLeft;
		if(document.getElementById("sk_htl_wrp")) wrp_left_mod += document.getElementById("sk_htl_wrp").offsetLeft; 
		if(document.getElementById("sk_htl_wrp")) wrp_top_mod = document.getElementById("sk_htl_wrp").offsetTop;*/
		
		if ((clientX + op.offsetWidth + 35) >= getWidth()) {
			if (clientX < (op.offsetWidth + 5)) Xoffset = (getWidth() / 2 - clientX) - (op.offsetWidth / 2);
			else Xoffset = -op.offsetWidth -15;
		} else Xoffset = 15;
		if (clientY - op.offsetHeight - 10 < 0) Yoffset = 10;
		else Yoffset = - op.offsetHeight - 10;
		
		op.style.left = clientX + Xoffset + getScrollLeft() /*- wrp_left_mod*/ + 'px';
		op.style.top = clientY + Yoffset + getScrollTop() /*- wrp_top_mod*/  + 'px';
		op.style.visibility = 'visible';
	}
}


// Hide a message
function hide(div) {
	if(document.readyState=="complete" || !(/*@cc_on!@*/false)){
		if(document.getElementById(div)){
			var op = document.getElementById(div);
			op.style.visibility = 'hidden';
			op.innerHTML = '';
		}
	}
}

// Hide float baloon 
function ph() {
	return hide('float_baloon');
}


/* Popup currency */
/* common_get variable must be defined */
/* 4th optional parameter refer to a specific base_href */ 
function convert(from,to,amount) {
	var link = ((arguments.length > 3) ? arguments[3] : '') + '?action=form_currency&funzione=124&bodyonly=1&param[from]=' + from + '&param[to]=' + to + '&param[amount]=' + amount + common_get;
	var a = window.open(link,'currency_converter','width=480,height=230,toolbar=no,scrollbars=no,resizable=no,menubar=no,location=no,status=no');
	return;
}

/* This function replace the normal setAttribute javascript function to allow us */
/* to set the attribute in all browsers without errors. */
function ghrs_setAttributeMP(node,name,value){
	var attr = '';
	if(node.getAttribute(name)) node.setAttribute(name, value);
	else{
		attr = document.createAttribute(name);
		attr.value = value;
		node.setAttributeNode(attr);
	}
}

