// JavaScript Document

// Imposta il campo hidden per il post back (Aggiungere alla pagina il controllo hidden 'hidPOSTBACK')
function SetPostBack() {
	document.getElementById("hidPOSTBACK").value = 'true';
}

// Assegna la gestione della classe Hover a tutti i figli di objParent
function SetHoverStyle(objParent) {
	for (i = 0; i < objParent.childNodes.length; i++) {
		objParent.childNodes[i].className = 'btnOut';
		objParent.childNodes[i].onmouseover = function() { this.className = 'btnHover'; }
		objParent.childNodes[i].onmouseout	= function() { this.className = 'btnOut'; }
	}	
}


function controllaAnno(tipo) {
	var objDDLAnnoInizio	=	document.getElementById('annoInizio');
	var objDDLAnnoFine	=	document.getElementById('annoFine');
	
	// Questa parte va fatta solo se cambio la casella di inizio
	if (tipo == 'inizio') {
		if (objDDLAnnoInizio.value != '*') {
			if (objDDLAnnoFine.disabled == true) {
				objDDLAnnoFine.disabled 	= false;
				objDDLAnnoFine.value 		= objDDLAnnoInizio.value;
			}
			if (objDDLAnnoInizio.value > objDDLAnnoFine.value) {
				alert("L'anno iniziale non può essere successivo all'anno finale");
				objDDLAnnoInizio.value = objDDLAnnoFine.value;
			}
		}
		else {
			objDDLAnnoFine.disabled = true; 
		}
	}
	else if (tipo == 'fine') {
		// Questa parte invece va fatta se cambio la casella di fine
		if (objDDLAnnoInizio.value > objDDLAnnoFine.value) {
			alert("L'anno finale non può essere precedente all'anno di inizio");
			objDDLAnnoFine.value = objDDLAnnoInizio.value;
		}
	}
}


function controllaMese(tipo) {
	var objDDLMeseInizio	= document.getElementById("meseInizio");
	var objDDLMeseFine	= document.getElementById("meseFine");
	
	// Questa parte va fatta solo se cambio la casella di inizio
	if (tipo == 'inizio') {
		if (objDDLMeseInizio.value != '*') {
			if (objDDLMeseFine.disabled == true) {
				objDDLMeseFine.disabled = false;
				objDDLMeseFine.value = objDDLMeseInizio.value;
			}
			if ( parseInt(objDDLMeseInizio.value) > parseInt(objDDLMeseInizio.value) ) {
				alert("Il mese iniziale non può essere successivo al mese finale.");
				objDDLMeseInizio.value = objDDLMeseFine.value;
			}
		}
		else {
			objDDLMeseFine.disabled = true;
		}
	}
	else if (tipo == 'fine') {
		// Questa parte invece va fatta se cambio la casella di fine
		if ( parseInt(objDDLMeseInizio.value) > parseInt(objDDLMeseFine.value) ) {
			alert("Il mese finale non può essere precedente al mese di inizio.");
			objDDLMeseFine.value = objDDLMeseInizio.value;
		}
	}
}


function ChangeStars(id) {
	for (i = 0; i <= id; i++) {
		document.getElementById("Star" + i).src = "Immagini/Decorazioni/Stella_Gialla_small.gif";
	}
	if (id < 4) {
		for (i = id + 1; i <= 4; i++) {
			document.getElementById("Star" + i).src = "Immagini/Decorazioni/Stella_Blu_small.gif";
		}
	}
	
	document.getElementById("bellezza").value = id + 1;
}



// Data una DL con DT al cui interno ci sono tag A, colora di chiaro l'A su cui si è cliccato e scurisce gli altri
function SetButtonList(objClicked) {	
	var objList			= objClicked.parentNode.parentNode;
	var listElements	= objList.childNodes;
	
	for (i = 0; i < listElements.length; i++) {
		if (listElements[i].nodeName == "DT") {
			listElements[i].childNodes[0].style.color = "#000066";
		}
	}
	objClicked.style.color = "#C7D7F1";
}




//
// getPageScroll()
// Returns array with x,y page scroll values.
// Core code from - quirksmode.org
//
function getPageScroll(){

	var yScroll;

	if (self.pageYOffset) {
		yScroll = self.pageYOffset;
	} else if (document.documentElement && document.documentElement.scrollTop){	 // Explorer 6 Strict
		yScroll = document.documentElement.scrollTop;
	} else if (document.body) {// all other Explorers
		yScroll = document.body.scrollTop;
	}

	arrayPageScroll = new Array('',yScroll) 
	return arrayPageScroll;
}



//
// getPageSize()
// Returns array with page width, height and window width, height
// Core code from - quirksmode.org
// Edit for Firefox by pHaez
//
function getPageSize(){
	
	var xScroll, yScroll;
	
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	
	var windowWidth, windowHeight;
	if (self.innerHeight) {	// all except Explorer
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){	
		pageWidth = windowWidth;
	} else {
		pageWidth = xScroll;
	}


	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
	return arrayPageSize;
}


function ClearFindTextBox(objTextBox) {
	objTextBox.style.backgroundImage 	= "url(./Immagini/Decorazioni/casellaCercaBlank.gif)";
	objTextBox.style.backgroundPosition = "right top";		// Questa istruzione e la successiva sarebbero ridondanti ma servono ad Explorer
	objTextBox.style.backgroundRepeat 	= "repeat-x";
	objTextBox.style.backgroundColor		= "#FFF";
}

function ResetFindTextBox(objTextBox) {
	if (objTextBox.value == "") {
		objTextBox.style.backgroundImage = "url(./Immagini/Decorazioni/casellaCerca.gif)";
		objTextBox.style.backgroundColor	= "#FFF";
	}
}

function DoFindTextBox(IDTextBox) {
	var objTextBox = document.getElementById(IDTextBox);
	
	if (objTextBox.value == "") {
		alert("Devi indicare nella casella di testo una o più parole da cercare.");
	}
	else {
		objTextBox.parentNode.submit();
	}
}


function BloccoPropagazioneEventi(event) 
{
	if(window.event) { // (probably IE)  browser
		window.event.cancelBubble = true;
	}
	else {
		event.stopPropagation();
	}
}


// Gestione coordinate del mouse per elementi relativi
function getMouseCoordsWithinEventTarget(event)
{
        var coords = { x: 0, y: 0};

        if(!event) // then we have a non-DOM (probably IE)  browser
        {
                event = window.event;
                coords.x = event.offsetX;
                coords.y = event.offsetY;
        }
        else       // we assume DOM modeled  javascript
        {
                var Element = event.target ;
                var CalculatedTotalOffsetLeft = 0;
                var CalculatedTotalOffsetTop = 0 ;

                while (Element.offsetParent)
                {
                        //alert(Element.offsetLeft);
								CalculatedTotalOffsetLeft += Element.offsetLeft ;     
                        CalculatedTotalOffsetTop += Element.offsetTop ;
                        Element = Element.offsetParent ;
                }

                coords.x = event.pageX - CalculatedTotalOffsetLeft ;
                coords.y = event.pageY - CalculatedTotalOffsetTop ;
        }

        return coords;
}

function getPageCoords(emt)
{
    var coords = {x: 0, y: 0};
    while (emt)
    {
            coords.x += emt.offsetLeft;
            coords.y += emt.offsetTop;
            emt = emt.offsetParent;
        }
    return coords;
}

function isElement(node)
{ return (node.nodeType == 1); }




// Assegnamento di eventi generali comuni a tutte le pagine
var oldonload = window.onload;
if (typeof window.onload != 'function')	{
	window.onload = function() {	autoLoadImg('img', 1, ""); }
} 
else {
	window.onload = function()	{	oldonload();
											autoLoadImg('img', 1, "");
										}
}

/*

window.onload = function() { 	autoLoadImg('img', 1);
											//SetHoverStyle(document.getElementById("rightMenu"));
									 }*/