﻿//Aram JS routine library
//v1.01- Author: Omboni Andrea (http://www.aramx.com)
//Last updated: May.03.010

var pnl1;
var pnlLeft;
var xmlHttp;
var sessionVar;
var pnlt;
function retrieveSession(nome) {
sessionVar="";
xmlHttp=GetXmlHttpObject()
	if (xmlHttp==null){
		alert ("Browser does not support HTTP Request")
		return
	} 
	
	//build the processing page and it's query string
	//invoke a request to the server using javascript async call
	var url="/pages/wfGetSession.aspx?v="+nome;
	url=url+"&sid="+Math.random();					
//	xmlHttp.onreadystatechange=stateRetrieve	
	
	xmlHttp.open("GET",url,false)
	xmlHttp.send(null)
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){ 
	    area = xmlHttp.responseText;
	    try {
		    sessionVar=area;
		}
		catch(Err)
		{
		}
		
	} 
    
}
function stateRetrieve() { 
var area;
    sessionVar="";
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){ 
	    area = xmlHttp.responseText;
	    try {
		    sessionVar=area;
		}
		catch(Err)
		{
		}
		
	} 
	//alert(sessionVar);
} 

function posizionaalbero(nuovapos) {
    showContentsEx('divTree'+nuovapos,nuovapos,'');
}
/***********************************************************
//Builds the query string and invoke a request to the server 
//using javascript async call
/***********************************************************/
function showContentsEx(div, str, lmsg){
	if (div == null) return;
	divObj = div;
		
		
	var objDivContainer = document.getElementById(eval("'"+div+"'"));
	 
	if (objDivContainer == null) return;
	
	if (str == "") {
		objDivContainer.innerHTML= "";		
		return;
	}
	//else
	//show the processing image to the user
	objDivContainer.innerHTML = "<img src='images/loading.gif' border='0'/>";
	
	//get the xml http object
	xmlHttp=GetXmlHttpObject()
	if (xmlHttp==null){
		alert ("Browser does not support HTTP Request")
		return
	} 
	
	//build the processing page and it's query string
	//invoke a request to the server using javascript async call
	var url="/pages/wfGetAlbero.aspx?q="+str+"&d="+lmsg;
	url=url+"&sid="+Math.random();					
	xmlHttp.onreadystatechange=stateChangedEx	
	xmlHttp.open("GET",url,true)
	xmlHttp.send(null)
	/**/
}

//The extented method to check the http request state has changed
//Then the dynamic div tag will be filled with the response text
function stateChangedEx() { 
var area;
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){ 
	    area = xmlHttp.responseText;
	    try {
		    document.getElementById(eval("'"+divObj+"'")).innerHTML=area;
		}
		catch(Err)
		{
		}
		
	} 
} 

//The core function to get the xml http request object
function GetXmlHttpObject(){ 
	var objXMLHttp=null
	if (window.XMLHttpRequest){
		objXMLHttp=new XMLHttpRequest()
	}
	else if (window.ActiveXObject) {
		objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP")
	}
	return objXMLHttp
}

//To toggle the node image and expand collapse
function Toggle(node){
 
	// Unfold the branch if it isn't visible
	if (node.nextSibling.style)	{		
		if (node.childNodes.length > 0)	{
			if ( node.childNodes.item(0).nodeName == "IMG"){
				if(node.childNodes.item(0).src.indexOf("plus.gif")> -1){
					
					node.nextSibling.style.display = 'block';
					node.childNodes.item(0).src = "images/minus.gif";
					return true;
				}
				else {
				
					node.nextSibling.style.display = 'none';
					node.childNodes.item(0).src = "images/plus.gif";
					return false;
				}				 
			}
		}		
	}
}

    function overtasto(obj, immagine) {
       // alert(immagine);
        obj.style.backgroundImage = "url('" + immagine + "')";
    }
    function overtastoimg(obj, immagine) {
        // alert(immagine);
        obj.src = immagine;
    }
    function test(immagine) {

    }
    // AREA PER WAIT

    function pageLoad(sender, args) {
        //alert('load');
        try {
            var sm = Sys.WebForms.PageRequestManager.getInstance();
//            alert('OK:' + sm.get_isInAsyncPostBack());
            if (!sm.get_isInAsyncPostBack()) {
                //alert('ADD events');
                sm.add_beginRequest(onBeginRequest);
                sm.add_endRequest(onRequestDone);
            }
            
        }
        catch (e) {
            //alert(e.message);
        }

    }


    function onBeginRequest(sender, args) {
        //alert('begin');
        var send = args.get_postBackElement().value;
        if (displayWait(send) == "yes") {
            if ($find('PleaseWaitPopup') != null) {
          //      alert('ok');
                $find('PleaseWaitPopup').show();
            }
        }
    }

    function onRequestDone() {
        //alert('Done:' + scrollTop);
        pnl1 = document.getElementById('ctl00_ContentPlaceHolder1_frame1');
        pnlLeft = document.getElementById('ctl00_ContentPlaceHolder1_pnlTree');

        if ($find('PleaseWaitPopup') != null)
            $find('PleaseWaitPopup').hide();
        if (pnl1 != null) {
        try {
            pnl1.scrollTop = scrollTop;
            }
            catch (e) {
                //alert(e.message);
            }
            
        }
        if (pnlLeft != null) {
            try {
                pnlLeft.scrollTop = scrollTopLeft;
            }
            catch (e) {
                //alert(e.message);
            }

        }
    }

    function displayWait(send) {
        switch (send) {
            case "Save":
                return ("yes");
                break;
            case "Save and Close":
                return ("yes");
                break;
            default:
                return ("yes");
                break;
        }
    }

    function ret(sender, e) {
        var str = "";
        var codice;

        str = sender.get_element().id;


        codice = str.substring(str.length - 2, str.length);


        var hdCustID = $get(hf[parseInt(codice)]);
        hdCustID.value = e.get_value();
        //ATC(e.get_value(), parseInt(codice));


    }

    function ATC(valore, chiave) {

        alert('ok:' + valore);
        var obj = $get(labelhf[chiave]);
        obj.value = valore;
        alert(obj.value);

    }

    function overtastoimgdiv(obj, immagine) {
        // alert(immagine);
        obj.style.backgroundImage = "url('" + immagine + "')";
    }
    function seleziona(Radiob, imgsel, tgname) {
        //alert(tgname);
        var Images = document.getElementsByTagName('span')
        for (i = 0; i < Images.length; i++) {
            if (Images[i].id.substr(0, tgname.length) == tgname)
                Images[i].style.backgroundImage = "url('/images/radio_off.png')";
        }
        document.getElementById(Radiob).checked = true;
        imgsel.style.backgroundImage = "url('/images/radio_on.png')";

    }
    function ridimensiona() {
        
        tabella.style.height = GetAltezza() - 32;
        areacentrale.style.height = GetAltezza() - 61 - 40 - 0;
        divcentrale.style.height = GetAltezza() - 61 - 40 - 0;
        divcentrale.style.width = GetLarghezza();
        corpo.style.height = GetAltezza() + 32;
        AltezzaTree();



//        window.onbeforeunload = onBack;
//        if (history.length > 0) history.go(+1);
        //window.history.forward(1); 
    }

    function onBack(evt) {
        
        
        if (evt == undefined)
            evt = window.event;
        if ((evt.clientX < 0) ||
		(evt.clientY < 0) ||
		(evt.clientX > document.body.clientWidth) ||
		(evt.clientY > document.body.clientHeight)
	    ) {
            //alert(window.event.returnValue);
            return "ATTENZIONE: NON E' CONSIGLIATO L'UTILIZZO DEL TASTO INDIETRO."
            //return "Non è consigliabile tornare indietro!";
        }
        else
            return undefined;

    }



    function AltezzaTree() {
        pnlt = "divTree";
        //alert(pnlt);
        if (document.getElementById(pnlt) != null) {
            document.getElementById(pnlt).style.height = GetAltezza() - 108;
            document.getElementById(pnlt).scrollTop = readCookie('scrollpos');
        }
    }
    
    function GetAltezza() {
        var x, y;
        if (self.innerHeight) // all except Explorer
        {
            x = self.innerWidth;
            y = self.innerHeight;
        }
        else if (document.documentElement && document.documentElement.clientHeight)
        // Explorer 6 Strict Mode
        {
            x = document.documentElement.clientWidth;
            y = document.documentElement.clientHeight;
        }
        else if (document.body) // other Explorers
        {
            x = document.body.clientWidth;
            y = document.body.clientHeight;
        }
        return y;
    }
    function GetLarghezza() {
        var x, y;
        if (self.innerHeight) // all except Explorer
        {
            x = self.innerWidth;
            y = self.innerHeight;
        }
        else if (document.documentElement && document.documentElement.clientHeight)
        // Explorer 6 Strict Mode
        {
            x = document.documentElement.clientWidth;
            y = document.documentElement.clientHeight;
        }
        else if (document.body) // other Explorers
        {
            x = document.body.clientWidth;
            y = document.body.clientHeight;
        }
        return x;
    }
    function confermastato() {
        if (confirm("Confermi il cambio stato della misurazione selezionata?") == true)
            return true;
        else
            return false;
    }


