var Giu = true;
var L, T, X, Y;

if(window.Event && document.captureEvents)
document.captureEvents(Event.MOUSEMOVE || Event.MOUSEUP || Event.MOUSEDOWN);

function cambiascritta(tipo) {
if (tipo == 1) {
document.getElementById("boxseltra").firstChild.nodeValue = "Trascina per spostare";
}
else {
document.getElementById("boxseltra").firstChild.nodeValue = "Seleziona data";
}
}

function Coordinate(e) {
	if (document.getElementById("calendariettop").style.display == "block") {
		Giu = true;
		document.onmousemove = Muovi;
		document.onmousedown = Coordinate;

		if (window.event) {
			e = window.event;
			X = e.clientX;
			Y = e.clientY;
			L = document.getElementById("calendariettop").style.pixelLeft;
			T = document.getElementById("calendariettop").style.pixelTop;
		}
		else {
			X = e.pageX;
			Y = e.pageY;
			L = document.getElementById("calendariettop").style.left;
			T = document.getElementById("calendariettop").style.top;
		}
	}
}

function Muovi(e) {
	if (Giu == true) {
		var mouseX = 0;
		var mouseY = 0;
		if (window.event) {
			e = window.event;
			mouseX = e.clientX;
			mouseY = e.clientY;
			document.getElementById("calendariettop").style.pixelLeft = (L + mouseX - X);
			document.getElementById("calendariettop").style.pixelTop = (T + mouseY - Y);
		}
		else {
			mouseX = e.pageX;
			mouseY = e.pageY;
			if (L == '') {
			  document.getElementById("calendariettop").style.left = (L + mouseX - X) + "px";
			}
			else {
			  document.getElementById("calendariettop").style.left = (parseInt(L) + mouseX - X) + "px";
			}
			if (T == '') {
			  document.getElementById("calendariettop").style.top = (T + mouseY - Y) + "px";
			}
			else {
			  document.getElementById("calendariettop").style.top = (parseInt(T) + mouseY - Y) + "px";
			}
		}
	}
}

function Su() { 
	Giu = false;
}

document.onmouseup = Su;

function calendarietto(idgiorno,idmese,idanno) {
	liveReq3 = false;
	if (window.XMLHttpRequest) {
		liveReq3 = new XMLHttpRequest();
	}
	else if (window.ActiveXObject) {
		liveReq3 = new ActiveXObject("Microsoft.XMLHTTP");
	}
	if (liveReq3 && liveReq3.readyState < 4) {
		liveReq3.abort();
	}
	var giorno = document.getElementById(idgiorno);
	var mese = document.getElementById(idmese);
	var anno = document.getElementById(idanno);

	var url41 = "http://www.sardegnacultura.it/index.php?xsl=330&s=7&v=5&c=2507&g=" + giorno.options[giorno.options.selectedIndex].value + "&m=" + mese.options[mese.options.selectedIndex].value + "&y=" + anno.options[anno.options.selectedIndex].value + "&idgiorno=" + idgiorno + "&idmese=" + idmese + "&idanno=" + idanno;
	liveReq3.onreadystatechange = liveReq3Fun;
	liveReq3.open("GET",url41 );
	liveReq3.send(null);
}

function calendarietto2(idgiorno,idmese,idanno,giorno,mese,anno) {
	liveReq3 = false;
	if (window.XMLHttpRequest) {
		liveReq3 = new XMLHttpRequest();
	}
	else if (window.ActiveXObject) {
		liveReq3 = new ActiveXObject("Microsoft.XMLHTTP");
	}
	if (liveReq3 && liveReq3.readyState < 4) {
		liveReq3.abort();
	}
	var url41 = "http://www.sardegnacultura.it/index.php?xsl=330&s=7&v=5&c=2507&g=" + giorno + "&m=" + mese + "&y=" + anno + "&idgiorno=" + idgiorno + "&idmese=" + idmese + "&idanno=" + idanno;
	liveReq3.onreadystatechange = liveReq3Fun;
	liveReq3.open("GET",url41 );
	liveReq3.send(null);
	return false;
}

function liveReq3Fun() {
	if (liveReq3.readyState == 4) {
		var calendariettop = document.getElementById("calendariettop");
		calendariettop.innerHTML = liveReq3.responseText;
		document.getElementById("calendariettop").style.display = "block";
	}
}

function chiudical() {
	document.getElementById("calendariettop").style.display= "none";
	return false;
}
	    
function valorizza(idgiorno,idmese,idanno,giorno,mese,anno) {
	document.getElementById(idgiorno).value = giorno;
	document.getElementById(idmese).value = mese;
	document.getElementById(idanno).value = anno;
	document.getElementById("calendariettop").style.display= "none";
	return false;
}

function collocagifcal() {
	miolink=document.createElement("a");
	miolink.href = "javascript: calendarietto(\'dagg\',\'damm\',\'dayy\');";
	miolink.setAttribute("href","javascript: calendarietto(\'dagg\',\'damm\',\'dayy\');");
	miaimg=document.createElement("img");
	miaimg.setAttribute("src","/immagini/7_76_20071228113609.gif");
	miaimg.setAttribute("style","width:1.97em;float:left;border:0px;padding:0px;margin:0px;");
	miolink.appendChild(miaimg);
	document.getElementById("colonninada").appendChild(miolink);
	
	miolink2=document.createElement("a");
	miolink2.href = "javascript: calendarietto(\'agg\',\'amm\',\'ayy\');";
	miolink2.setAttribute("href","javascript: calendarietto(\'agg\',\'amm\',\'ayy\');");
	miaimg2=document.createElement("img");
	miaimg2.setAttribute("src","/immagini/7_76_20071228113609.gif");
	miaimg2.setAttribute("style","width:1.97em;float:left;border:0px;padding:0px;margin:0px;");
	miolink2.appendChild(miaimg2);
	document.getElementById("colonninaa").appendChild(miolink2);
}


