// find click hoz coordinates
// usage: clickX(e)
function clickX(e) {
	var posX = 0;
	if (!e) var e = window.event;
	if (e.pageX) posX = e.pageX;
	else if (e.clientX) posX = e.clientX + document.body.scrollLeft + document.documentElement.scrollLeft;
return [posX];
}
// find click hoz coordinates
// usage: clickY(e)
function clickY(e) {
	var posY = 0;
	if (!e) var e = window.event;
	if (e.pageY) posY = e.pageY;
	else if (e.clientY) posY = e.clientY + document.body.scrollTop + document.documentElement.scrollTop;
return [posY];
}
function createXMLHttpRequest() {
  var xmlHttp;
  if (window.XMLHttpRequest) xmlHttp = new XMLHttpRequest();
  else if (window.ActiveXObject) xmlHttp = new ActiveXObject('Microsoft.XMLHTTP');
  return xmlHttp;
} // function createXMLHttpRequest
// find click coordinates
// usage: findClickCoords(e)
function findClickCoords(e) {
	var posX = clickX(e);
	var posY = clickY(e);
return [posX, posY];

}
// finds the position of any HTML element relatvie to the page
function findPos(obj) {
	var curLeft = posX(obj);
  var curTop = posY(obj);
	return [curLeft,curTop];
}
function getPageSizeWithScroll() {
	if (window.innerHeight && window.scrollMaxY) {// Firefox
		yWithScroll = window.innerHeight + window.scrollMaxY;
		xWithScroll = window.innerWidth + window.scrollMaxX;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		yWithScroll = document.body.scrollHeight;
		xWithScroll = document.body.scrollWidth;
	} else { // works in Explorer 6 Strict, Mozilla (not FF) and Safari
		yWithScroll = document.body.offsetHeight;
		xWithScroll = document.body.offsetWidth;
  	}
	arrayPageSizeWithScroll = new Array(xWithScroll,yWithScroll);
	return arrayPageSizeWithScroll;
}
function getScrollY() {
  var scrOfY = 0;
  if( typeof( window.pageYOffset ) == 'number' ) {
    //Netscape compliant
    scrOfY = window.pageYOffset;
  } else if(document.body && document.body.scrollTop) {
    //DOM compliant
    scrOfY = document.body.scrollTop;
  } else if (document.documentElement && document.documentElement.scrollTop) {
    //IE6 standards compliant mode
    scrOfY = document.documentElement.scrollTop;
  }
  return scrOfY;
}
// trova lo spazio del viewport visible
function getViewportSize()
{
 var size = [0, 0];
 if (typeof window.innerWidth != 'undefined')
 {
   size = [
       window.innerWidth,
       window.innerHeight
   ];
 }
 else if (typeof document.documentElement != 'undefined'
     && typeof document.documentElement.clientWidth !=
     'undefined' && document.documentElement.clientWidth != 0)
 {
   size = [
       document.documentElement.clientWidth,
       document.documentElement.clientHeight
   ];
 }
 else
 {
   size = [
       document.getElementsByTagName('body')[0].clientWidth,
       document.getElementsByTagName('body')[0].clientHeight
   ];
 }
 return size;
}
function isMouseLeaveOrEnter(e, handler) { 
  if (e.type != 'mouseout' && e.type != 'mouseover') return false; 
  var reltg = e.relatedTarget ? e.relatedTarget : e.type == 'mouseout' ? e.toElement : e.fromElement; 
  while (reltg && reltg != handler) reltg = reltg.parentNode; 
  return (reltg != handler); 
}
// MODIFIED FROM http://brainerror.net/scripts/javascript/blendtrans/

function opacityFX(objId, opacityStart, opacityEnd, millisec) {
    //speed for each frame
    var speed = Math.round(millisec / 100);
    var timer = 0;
    //determine the direction for the blending, if start and end are the same nothing happens
    if (opacityStart > opacityEnd) {
        for (i = opacityStart; i >= opacityEnd; i--) {
            setTimeout("setOpacity(" + i + ",'" + objId + "')",(timer * speed));
            timer++;
        }
    } else if (opacityStart < opacityEnd) {
        for(i = opacityStart; i <= opacityEnd; i++)
            {
            setTimeout("setOpacity(" + i + ",'" + objId + "');",(timer * speed));
            timer++;
        }
    }
}
// finds the X position of any HTML element
// usage: alert('distance from left: ' + posX(obj) + 'px');

function posX(obj) {
	var pos = 0;
	if (obj.offsetParent) {
		pos = obj.offsetLeft;
		while (obj = obj.offsetParent) {
			pos += obj.offsetLeft;
		} // while parent
	}  // if obj.offsetParent
	return pos;
} // function
// finds the Y position of any HTML element
// usage: alert('distance from top: ' + posY(obj) + 'px');

function posY(obj) {
	var pos = 0;
	if (obj.offsetParent) {
		pos = obj.offsetTop;
		while (obj = obj.offsetParent) {
			pos += obj.offsetTop;
		} // while parent
	}  // if obj.offsetParent
	return pos;
} // function
// change the opacity for different browsers
// MODIFIED FROM http://brainerror.net/scripts/javascript/blendtrans/

function setOpacity(myOpacity, objId) {
    var object = document.getElementById(objId);
    object.style.opacity = (myOpacity);
    object.style.MozOpacity = (myOpacity / 100);
    object.style.KhtmlOpacity = (myOpacity / 100);
    object.style.filter = "alpha(opacity=" + myOpacity + ")";
    
} 
// MODIFIED FROM http://brainerror.net/scripts/javascript/blendtrans/

function shiftOpacity(id, millisec) {
    //if an element is invisible, make it visible, else make it ivisible
    if(document.getElementById(id).style.opacity == 0) {
        opacityFX(id, 0, 100, millisec);
    } else {
        opacity(id, 100, 0, millisec);
    }
} 
/**
*
*  UTF-8 data encode / decode
*  http://www.webtoolkit.info/
*
**/

// method for url encoding
function utf8Encode (string) {
        string = string.replace(/\r\n/g,"\n");
        var utftext = "";

        for (var n = 0; n < string.length; n++) {

            var c = string.charCodeAt(n);

            if (c < 128) {
                utftext += String.fromCharCode(c);
            }
            else if((c > 127) && (c < 2048)) {
                utftext += String.fromCharCode((c >> 6) | 192);
                utftext += String.fromCharCode((c & 63) | 128);
            }
            else {
                utftext += String.fromCharCode((c >> 12) | 224);
                utftext += String.fromCharCode(((c >> 6) & 63) | 128);
                utftext += String.fromCharCode((c & 63) | 128);
            }

        }

        return utftext;
    }

// public method for url decoding
function utf8Decode(utftext) {
        var string = "";
        var i = 0;
        var i = 0;
        var c = 0;
        var c1 = 0;
        var c2 = 0;

        while ( i < utftext.length ) {

            c = utftext.charCodeAt(i);

            if (c < 128) {
                string += String.fromCharCode(c);
                i++;
            }
            else if((c > 191) && (c < 224)) {
                c2 = utftext.charCodeAt(i+1);
                string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
                i += 2;
            }
            else {
                c2 = utftext.charCodeAt(i+1);
                c3 = utftext.charCodeAt(i+2);
                string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
                i += 3;
            }

        }

        return string;
    }

// find click hoz coordinates
// usage: clickX(e)
function clickX(e) {
	var posX = 0;
	if (!e) var e = window.event;
	if (e.pageX) posX = e.pageX;
	else if (e.clientX) posX = e.clientX + document.body.scrollLeft + document.documentElement.scrollLeft;
return [posX];
}
// find click hoz coordinates
// usage: clickY(e)
function clickY(e) {
	var posY = 0;
	if (!e) var e = window.event;
	if (e.pageY) posY = e.pageY;
	else if (e.clientY) posY = e.clientY + document.body.scrollTop + document.documentElement.scrollTop;
return [posY];
}
function createXMLHttpRequest() {
  var xmlHttp;
  if (window.XMLHttpRequest) xmlHttp = new XMLHttpRequest();
  else if (window.ActiveXObject) xmlHttp = new ActiveXObject('Microsoft.XMLHTTP');
  return xmlHttp;
} // function createXMLHttpRequest
// find click coordinates
// usage: findClickCoords(e)
function findClickCoords(e) {
	var posX = clickX(e);
	var posY = clickY(e);
return [posX, posY];

}
// finds the position of any HTML element relatvie to the page
function findPos(obj) {
	var curLeft = posX(obj);
  var curTop = posY(obj);
	return [curLeft,curTop];
}
function getPageSizeWithScroll() {
	if (window.innerHeight && window.scrollMaxY) {// Firefox
		yWithScroll = window.innerHeight + window.scrollMaxY;
		xWithScroll = window.innerWidth + window.scrollMaxX;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		yWithScroll = document.body.scrollHeight;
		xWithScroll = document.body.scrollWidth;
	} else { // works in Explorer 6 Strict, Mozilla (not FF) and Safari
		yWithScroll = document.body.offsetHeight;
		xWithScroll = document.body.offsetWidth;
  	}
	arrayPageSizeWithScroll = new Array(xWithScroll,yWithScroll);
	return arrayPageSizeWithScroll;
}
function getScrollY() {
  var scrOfY = 0;
  if( typeof( window.pageYOffset ) == 'number' ) {
    //Netscape compliant
    scrOfY = window.pageYOffset;
  } else if(document.body && document.body.scrollTop) {
    //DOM compliant
    scrOfY = document.body.scrollTop;
  } else if (document.documentElement && document.documentElement.scrollTop) {
    //IE6 standards compliant mode
    scrOfY = document.documentElement.scrollTop;
  }
  return scrOfY;
}
// trova lo spazio del viewport visible
function getViewportSize()
{
 var size = [0, 0];
 if (typeof window.innerWidth != 'undefined')
 {
   size = [
       window.innerWidth,
       window.innerHeight
   ];
 }
 else if (typeof document.documentElement != 'undefined'
     && typeof document.documentElement.clientWidth !=
     'undefined' && document.documentElement.clientWidth != 0)
 {
   size = [
       document.documentElement.clientWidth,
       document.documentElement.clientHeight
   ];
 }
 else
 {
   size = [
       document.getElementsByTagName('body')[0].clientWidth,
       document.getElementsByTagName('body')[0].clientHeight
   ];
 }
 return size;
}
function isMouseLeaveOrEnter(e, handler) { 
  if (e.type != 'mouseout' && e.type != 'mouseover') return false; 
  var reltg = e.relatedTarget ? e.relatedTarget : e.type == 'mouseout' ? e.toElement : e.fromElement; 
  while (reltg && reltg != handler) reltg = reltg.parentNode; 
  return (reltg != handler); 
}
// MODIFIED FROM http://brainerror.net/scripts/javascript/blendtrans/

function opacityFX(objId, opacityStart, opacityEnd, millisec) {
    //speed for each frame
    var speed = Math.round(millisec / 100);
    var timer = 0;
    //determine the direction for the blending, if start and end are the same nothing happens
    if (opacityStart > opacityEnd) {
        for (i = opacityStart; i >= opacityEnd; i--) {
            setTimeout("setOpacity(" + i + ",'" + objId + "')",(timer * speed));
            timer++;
        }
    } else if (opacityStart < opacityEnd) {
        for(i = opacityStart; i <= opacityEnd; i++)
            {
            setTimeout("setOpacity(" + i + ",'" + objId + "');",(timer * speed));
            timer++;
        }
    }
}
// finds the X position of any HTML element
// usage: alert('distance from left: ' + posX(obj) + 'px');

function posX(obj) {
	var pos = 0;
	if (obj.offsetParent) {
		pos = obj.offsetLeft;
		while (obj = obj.offsetParent) {
			pos += obj.offsetLeft;
		} // while parent
	}  // if obj.offsetParent
	return pos;
} // function
// finds the Y position of any HTML element
// usage: alert('distance from top: ' + posY(obj) + 'px');

function posY(obj) {
	var pos = 0;
	if (obj.offsetParent) {
		pos = obj.offsetTop;
		while (obj = obj.offsetParent) {
			pos += obj.offsetTop;
		} // while parent
	}  // if obj.offsetParent
	return pos;
} // function
// change the opacity for different browsers
// MODIFIED FROM http://brainerror.net/scripts/javascript/blendtrans/

function setOpacity(myOpacity, objId) {
    var object = document.getElementById(objId);
    object.style.opacity = (myOpacity);
    object.style.MozOpacity = (myOpacity / 100);
    object.style.KhtmlOpacity = (myOpacity / 100);
    object.style.filter = "alpha(opacity=" + myOpacity + ")";
    
} 
// MODIFIED FROM http://brainerror.net/scripts/javascript/blendtrans/

function shiftOpacity(id, millisec) {
    //if an element is invisible, make it visible, else make it ivisible
    if(document.getElementById(id).style.opacity == 0) {
        opacityFX(id, 0, 100, millisec);
    } else {
        opacity(id, 100, 0, millisec);
    }
} 
/**
*
*  UTF-8 data encode / decode
*  http://www.webtoolkit.info/
*
**/

// method for url encoding
function utf8Encode (string) {
        string = string.replace(/\r\n/g,"\n");
        var utftext = "";

        for (var n = 0; n < string.length; n++) {

            var c = string.charCodeAt(n);

            if (c < 128) {
                utftext += String.fromCharCode(c);
            }
            else if((c > 127) && (c < 2048)) {
                utftext += String.fromCharCode((c >> 6) | 192);
                utftext += String.fromCharCode((c & 63) | 128);
            }
            else {
                utftext += String.fromCharCode((c >> 12) | 224);
                utftext += String.fromCharCode(((c >> 6) & 63) | 128);
                utftext += String.fromCharCode((c & 63) | 128);
            }

        }

        return utftext;
    }

// public method for url decoding
function utf8Decode(utftext) {
        var string = "";
        var i = 0;
        var i = 0;
        var c = 0;
        var c1 = 0;
        var c2 = 0;

        while ( i < utftext.length ) {

            c = utftext.charCodeAt(i);

            if (c < 128) {
                string += String.fromCharCode(c);
                i++;
            }
            else if((c > 191) && (c < 224)) {
                c2 = utftext.charCodeAt(i+1);
                string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
                i += 2;
            }
            else {
                c2 = utftext.charCodeAt(i+1);
                c3 = utftext.charCodeAt(i+2);
                string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
                i += 3;
            }

        }

        return string;
    }
