//
// ------------   Modifica  01/01/2010 S-G  -   Inizio
//
var myAbsolutePath = "/PommierFurgocar/"
var myAbsolutePath_SkinFile = myAbsolutePath + "App_Themes/SkinFile/"


//
// Sostituisce un' immagine quando ci si passa sopra ...
//
function SwapMenu(myObyect) {
    var myId = myObyect.id
    var myClassName = document.getElementById(myId).className

    if (myClassName.search("_Out") > 0) {
        ResetMenu()
        ResetSubMenu()

        document.getElementById(myId).className = myClassName.replace("_Out", "_In")
    }
    else if (myClassName.search("_Selected") > 0) {
        ResetMenu()
        ResetSubMenu()
    }
    var asse_x = (document.body.clientWidth - 960) / 2

    document.getElementById("Sub" + myId).style.visibility = "visible"
    //document.getElementById("Sub" + myId).style.top = document.getElementById(myId).offsetHeight + 200
    //document.getElementById("Sub" + myId).style.left = asse_x + document.getElementById(myId).offsetLeft
}

//
// Sostituisce una riga quando ci si passa sopra ...
//
function SwapSubMenu(myObyect) {
    var myId = myObyect.id
    var myClassName = document.getElementById(myId).className

    if (myClassName.search("_In") > 0) {
        document.getElementById(myId).className = myClassName.replace("_In", "_Out")
    }
    else if (myClassName.search("_Out") > 0) {
        document.getElementById(myId).className = myClassName.replace("_Out", "_In")
    }

    //var myId = myObyect.id + "_Image"
    //var mySrc = document.getElementById(myId).src

    //if (mySrc.search("_In") > 0) {
        //document.getElementById(myId).src = mySrc.replace("_In", "_Out")
    //}
    //else if (mySrc.search("_Out") > 0) {
        //document.getElementById(myId).src = mySrc.replace("_Out", "_In")
    //}
}

function ResetMenu() {
    var myElement = document.getElementsByTagName("td")

    for (var i = 0; i < myElement.length; i++) {
        var myId = myElement[i].id

        if (myId.search("Menu_") == 0) {
            var myClassName = document.getElementById(myId).className

            if (myClassName.search("_In") > 0) {
                document.getElementById(myId).className = myClassName.replace("_In", "_Out")
            }
        }
    }
}

function ResetSubMenu() {
    var myElement = document.getElementsByTagName("div")

    for (var i = 0; i < myElement.length; i++) {
        var myId = myElement[i].id

        if (myId.search("SubMenu_") == 0) {
            document.getElementById(myId).style.visibility = "hidden"
        }
    }
    ResetMenu()
}


//
// Seleziona una riga ...
//
function SelectedItemStyle( myObyect )
	{
    if ( myObyect.className.search( "_Selected" ) < 0 )
        {
        var myElement = document.getElementsByTagName( "tr" )

        for ( var i = 0; i < myElement.length; i ++ )
            {
            var myClassName = myElement[i].className

            if ( myClassName.search( "_Selected" ) > 0 )
                {
                myElement[i].className = myClassName.replace( "_Selected", "" )
                }
            }

        myObyect.className = myObyect.className.replace( "_Evidenced", "_Selected" )
        }
    }


//
// Evidenzia una riga quando ci si passa sopra ...
//
function EvidencedItemStyle( myObyect )
	{
    var myClassName = myObyect.className

    if ( myClassName.search( "_Selected" ) > 0 )
        {
        myClassName = myClassName
        }
    else if ( myClassName.search( "_Evidenced" ) > 0 )
        {
        myClassName = myClassName.replace( "_Evidenced", "" )
        }
    else
        {
        myClassName = myClassName + "_Evidenced"
        }
    myObyect.className = myClassName
    }


//
// Aggiorna le dimensioni della maschera UpdatePanel ...
//
function UpdatePanel()
    {
    if (parseInt(navigator.appVersion) > 3)
        {
        if (navigator.appName == "Netscape")
            {
            myTop = window.pageYOffset
            myWidth = window.innerWidth
            myHeight = window.innerHeight
            }
        if (navigator.appName.indexOf("Microsoft") != -1)
            {
            myTop = document.body.scrollTop
            myWidth = document.body.offsetWidth
            myHeight = document.body.offsetHeight
            }
        }

    var myElement = document.getElementsByTagName("Div")

    for (var i = 0; i < myElement.length; i++)
        {
        if (myElement[i].id == "UpdatePanel_1")
            {
            myElement[i].style.top = myTop
            myElement[i].style.width = myWidth
            myElement[i].style.height = myHeight
            }
        if (myElement[i].id == "UpdatePanel_2")
            {
            myElement[i].style.top = myTop
            myElement[i].style.width = myWidth
            myElement[i].style.height = myHeight
            }
        }
    }


//
// Apre un PopUp ...
//
function OpenPopUp( myUrl )
	{
	myWindowWidth = screen.availWidth / 2
	myWindowHeight = screen.availHeight / 2

	window.open( myUrl, "", "toolbar=no, menubar=no, scrollbars=yes, status=yes, resizable=yes, width=" + myWindowWidth + ", height=" + myWindowHeight + ", left=0, top=0" )
    }


//
// Stampa ...
//
function PrintPopUp( myTxtInput, myElementId )
	{
	myWindowWidth = screen.availWidth / 2
	myWindowHeight = screen.availHeight / 2

    var myTxtOutput = "<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Transitional//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'>"
    myTxtOutput += "<html xmlns='http://www.w3.org/1999/xhtml' >"
    myTxtOutput += "<head>"
    myTxtOutput += "<title>" + document.title + "</title>"
    myTxtOutput += "<link rel='Shortcut Icon' href='" + myAbsolutePath + "/PommierFurgocar.ico'>"
    myTxtOutput += "<link href='" + myAbsolutePath + "App_Themes/SkinFile/CssFile_Web.css' rel='stylesheet' type='text/css'>"
    myTxtOutput += "<link href='" + myAbsolutePath + "CssFile_Print.css' rel='stylesheet' type='text/css'>"
    myTxtOutput += "<script language='javascript' src='" + myAbsolutePath + "Script/Script.js' type='text/javascript'></script>"
    myTxtOutput += "<script language='vbscript' src='" + myAbsolutePath + "Script/Script.vbs' type='text/vbscript'></script>"
    myTxtOutput += "<style>body { background: #FFFFFF none; }</style>"
    myTxtOutput += "<style>.NoPrint { display: none; }</style>"
    //myTxtOutput += "<style>INPUT { display: none; }</style>"
    myTxtOutput += "</head>"
    myTxtOutput += "<body style='background-color:White'>"

	if ( myElementId == "" )
		{
		myTxtOutput += myTxtInput
		}
	else
		{
		myTxtOutput += document.getElementById( myElementId ).innerHTML
		}

	myTxtOutput += "</body></html>"

	var myNewWindow = window.open( "", "", "toolbar=yes, menubar=yes, scrollbars=yes, status=yes, resizable=yes, width=" + myWindowWidth + ", height=" + myWindowHeight + ", left=0, top=0" )

	myNewWindow.document.open()
	myNewWindow.document.write( myTxtOutput )
	myNewWindow.document.close()

    //myNewWindow.print()
    //myNewWindow.close()
    }


//
// Esportare del testo in formato HTML ...
//
myExportHTML = setInterval( 'ExportHTML();', 2000 )

function ExportHTML()
	{
    if( document.getElementById("Stampa") )
        {
	    var myTxtOutput = document.getElementById("Stampa").innerHTML

        myTxtOutput = myTxtOutput.replace( /</g, "_Minore_" )
        myTxtOutput = myTxtOutput.replace( />/g, "_Maggiore_" )
        myTxtOutput = myTxtOutput.replace( / /g, "_Spazio_" )

        document.getElementById( "ctl00$TextBox_Fantasma" ).innerText = myTxtOutput
        }
    }


//
// Finestra che si muove con il mouse.
//
var myOffsetFromCursorX = 12 // Customize x offset of tooltip
var myOffsetFromCursorY = 10 // Customize y offset of tooltip

var myOffsetFromTollTipX = 0 // Customize x offset of tooltip DIV relative to pointer image
var myOffsetFromTollTipY = 20 // Customize y offset of tooltip DIV relative to pointer image. Tip: Set it to (height_of_pointer_image-1).

document.write( "<div id='myHtmlToolTip' align='center'></div>" )
document.write( "<img id='myHtmlPointer' />" )

var ie = document.all
var ns6 = document.getElementById && !document.all

var myEnableToolTip = false

if (ie || ns6)

var myObjectToolTip = document.all? document.all["myHtmlToolTip"] : document.getElementById? document.getElementById("myHtmlToolTip") : ""
var myObjectPointer = document.all? document.all["myHtmlPointer"] : document.getElementById? document.getElementById("myHtmlPointer") : ""

function ieTrueBody()
	{
	return ( document.compatMode && document.compatMode != "BackCompat" )? document.documentElement : document.body
	}

function VisibleToolTip( My_FullFileName, My_String )
    {
    var myWidthToolTip = 200
    var myWidthImg = myWidthToolTip - 10

    myTableTop = "<table border='0' cellspacing='0' cellpadding='0' style='width: auto;'>"
    myTableTop = myTableTop + "<tr><td class='ToolTip_Top_Sx'></td><td class='ToolTip_Top' style='width: " + myWidthToolTip + "px'>" + My_String + "</td><td class='ToolTip_Top_Dx'></td></tr>"
    myTableTop = myTableTop + "<tr><td class='ToolTip_Mibble_Sx' height='" + myWidthToolTip + "px' /></td>"
    myTableTop = myTableTop + "<td class='ToolTip_Mibble' align='center'><img src='" + My_FullFileName + "' border='1' width='" + myWidthImg + "px' align='absmiddle' /></td>"
    myTableTop = myTableTop + "<td class='ToolTip_Mibble_Dx'></td></tr>"
    myTableTop = myTableTop + "<tr><td class='ToolTip_Bottom_Sx'></td><td class='ToolTip_Bottom'></td><td class='ToolTip_Bottom_Dx'></td></tr>"
    myTableTop = myTableTop + "</table>"

    myObjectToolTip.innerHTML = myTableTop

    myEnableToolTip = true
    }

function HiddenToolTip()
    {
    myEnableToolTip = false

    myObjectToolTip.style.visibility = "hidden"
    myObjectPointer.style.visibility = "hidden"
    }

function PositionToolTip( e )
	{
	if ( myEnableToolTip )
		{
		var myPositionCursorX = ( ns6 )? e.pageX : event.clientX + ieTrueBody().scrollLeft;
		var myPositionCursorY = ( ns6 )? e.pageY : event.clientY + ieTrueBody().scrollTop;

		// Find out how close the mouse is to the corner of the window
		var myWindowWidth = ie && !window.opera? ieTrueBody().clientWidth : window.innerWidth - 20
		var myWindowHeight = ie && !window.opera? ieTrueBody().clientHeight : window.innerHeight - 20

		var myEdgeLeft = ( myOffsetFromCursorX < 0 )? myOffsetFromCursorX * ( -1 ) : -1000
		var myEdgeRight = ie && !window.opera? myWindowWidth - event.clientX - myOffsetFromCursorX : myWindowWidth - e.clientX - myOffsetFromCursorX
		var myEdgeBottom = ie && !window.opera? myWindowHeight - event.clientY - myOffsetFromCursorY : myWindowHeight - e.clientY - myOffsetFromCursorY

		// If the horizontal distance isn't enough to accomodate the width of the context menu
		if ( myEdgeRight < myObjectToolTip.offsetWidth )
			{
            myObjectToolTip.style.left = myPositionCursorX - myObjectToolTip.offsetWidth + myOffsetFromCursorX + "px"
			myObjectPointer.style.left = myPositionCursorX - myObjectPointer.offsetWidth - myOffsetFromCursorX + "px"
			myObjectPointer.src = myAbsolutePath_SkinFile + "ToolTip_Arrow_Right.gif"
			myObjectPointer.style.visibility = "hidden"
			}
		else if ( myPositionCursorX < myEdgeLeft )
			{
			myObjectToolTip.style.left = "5px"
			myObjectPointer.src = myAbsolutePath_SkinFile + "ToolTip_Arrow_Left.gif"
			myObjectPointer.style.visibility = "hidden"
			}
		else
			{
			// Move the horizontal position of the menu to the right by it's width
			myObjectToolTip.style.left = myPositionCursorX + myOffsetFromTollTipX + "px"
			myObjectPointer.style.left = myPositionCursorX + myOffsetFromCursorX + "px"
			myObjectPointer.src = myAbsolutePath_SkinFile + "ToolTip_Arrow_Left.gif"
			myObjectPointer.style.visibility = "hidden"
			}

		// Same concept with the vertical position
		if ( myEdgeBottom < myObjectToolTip.offsetHeight )
			{
			myObjectToolTip.style.top = myPositionCursorY - myObjectToolTip.offsetHeight - myOffsetFromCursorY + "px"
			myObjectPointer.style.visibility = "hidden"
			}
		else
			{
			myObjectToolTip.style.top = myPositionCursorY + myOffsetFromCursorY + myOffsetFromTollTipY + "px"
			myObjectPointer.style.top = myPositionCursorY + myOffsetFromCursorY + "px"
			}

		myObjectToolTip.style.visibility = "visible"
		}
    }

    document.onmousemove = PositionToolTip
