
function xmlAjaxRequest(urlAjax, get, post, retFunct, retType) {

if(window.XMLHttpRequest) {
	var http_request = new XMLHttpRequest();
} else if(window.ActiveXObject) {
	var http_request = new ActiveXObject("Microsoft.XMLHTTP");
}

http_request.onreadystatechange = function() {
	if(http_request.readyState == 4) {
		if(http_request.status == 200) {
			// alert(http_request.responseText);
			if(retType == "text") {
				retFunct(http_request.responseText);
							
			} else if(retType == "xml") {
				retFunct(http_request.responseXML);
			}
		
		} else {
			var errorStatus = http_request.status + '';
			// alert("HTTP Error: " + errorStatus);
		}
	}
}

if(post == null) {
	http_request.open("GET", urlAjax + "?" + get, true);
	http_request.send(null);

} else {
	var pieces = post.split("&");
	var parNum = pieces.length;
	http_request.open("POST", urlAjax + "?" + get, true);
	http_request.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	http_request.setRequestHeader('Content-length',parNum);
	http_request.send(post);
} 

}


function checkData(data) {

var splitted = data.split("/");
if(splitted.length != 3)
	return false;

var giorno = parseInt(parseVal(splitted[0]));
var mese = parseInt(parseVal(splitted[1]));
var anno = parseInt(parseVal(splitted[2]));

if(isNaN(giorno) || isNaN(mese) || isNaN(anno))
	return false;

if(anno < 1900)
	return false;

if((mese < 1) || (mese > 12)) 
	return false;

if((giorno < 1) || (giorno > 31))
	return false;

if((giorno > 29) && (mese == 2))
	return false;

if(giorno > 30 && ((mese == 4) || (mese == 6) || (mese == 9) || (mese == 11)))
	return false;

return true;

}


function checkAmericanData(data) {

var splitted = data.split("/");
if(splitted.length != 3)
	return false;

var giorno = parseInt(parseVal(splitted[2]));
var mese = parseInt(parseVal(splitted[1]));
var anno = parseInt(parseVal(splitted[0]));

if(isNaN(giorno) || isNaN(mese) || isNaN(anno))
	return false;

if(anno < 1900)
	return false;

if((mese < 1) || (mese > 12)) 
	return false;

if((giorno < 1) || (giorno > 31))
	return false;

if((giorno > 29) && (mese == 2))
	return false;

if(giorno > 30 && ((mese == 4) || (mese == 6) || (mese == 9) || (mese == 11)))
	return false;

return true;

}


function parseVal(val) {

var len = val.length;

while((len > 0) && (val.charAt(0) == '0')) {
	val = val.substring(1, val.length);
	len = len - 1;
}

if(len == 0)
	return '0';

return val;

}


function checkInteger(val) {

if(parseInt(parseVal(val)) != (val - 0))
	return false;

return true;

}


function checkPrezzo(val) {

var point = 0;

if(val.length == 0)
	return false;

while((point < val.length) && (val.charAt(point) != '.') && (val.charAt(point) != ','))
	point++;

if(point == val.length)
	return checkInteger(val);

var intero = val.substr(0,point);
if(checkInteger(intero) == false)
	return false;

cent = val.substr(point + 1);
if((checkInteger(cent) == false) || (cent.length > 2))
	return false;

return true;

}


function findBrowser() {

var useragent = navigator.userAgent;

if(useragent.indexOf("Konqueror") != -1)
	return "Konqueror";

else if(useragent.indexOf("Safari") != -1)
	return "Safari";

else if(useragent.indexOf("Opera") != -1)
	return "Opera";

else if(useragent.indexOf("Firefox") != -1)
	return "Firefox";

else if(useragent.indexOf("MSIE") != -1)
	return "IE";

return "";

}


function pluginClosePopup(request,win) {

win.close();
self.focus();

if(request != null)
        setTimeout(100,request);

}


function resizeArea(id,width,startWidth,timeout,endAction) {

if(width == startWidth) {

	if(endAction.length > 0) {
		setTimeout(endAction, timeout);
	}

	return;
}

if(startWidth < width)
	var newWidth = width - 2;
else
	var newWidth = width + 2;

var div = document.getElementById(id);
div.style.left = newWidth+ 'px';

setTimeout("resizeArea('" + id + "'," + newWidth + "," + startWidth + "," + timeout + ",'" + endAction + "')", timeout);

}


function getOffset(id,type) {

var div = document.getElementById(id);
var offset = 0;

switch(type) {
	case "width":
		offset = div.offsetWidth;
		return offset;

	case "height":
		offset = div.offsetHeight;
		return offset;
}

do {
	var value = 0;

	switch(type) {
		case "top":
			value = div.offsetTop;
			break;

		case "left":
			value = div.offsetLeft;
			break;
	}

	offset = offset + value;
	div = div.offsetParent;
} while(div);

return offset;

}


function lista_select(id,offset) {

try {
	var div = document.getElementById(id);
	var tbody = div.getElementsByTagName('tbody');
	tbody = tbody[tbody.length - 1];
	var tr = tbody.getElementsByTagName('tr');

	for(var i = 0; i < tr.length; i++) {
		if(i == offset)
			var color = '#A0CFEC';
		else if((i % 2) == 0)
			var color = 'white';
		else
			var color = 'white';
		
		tr[i].style.backgroundColor = color;
	}

} catch(error) {
	alert("Error in lista_select");
	return;
}

}


function setLinkExternal() {

try {
	var anchors = document.getElementsByTagName("a");
	
	for(var i = 0; i < anchors.length; i++) {
		var a = anchors[i];
		if(a.rel == "external") {
			a.target = "_blank";
		}
	}

} catch(error) {
	;
}

}


function setLinkPopup() {

try {
	var hWind = Math.floor(screen.height / 2);
	var wWind = Math.floor(screen.width / 2);
	var hPos = Math.floor(screen.height / 4);
	var wPos = Math.floor(screen.width / 4);

	var anchors = document.getElementsByTagName("a");
	
	for(var i = 0; i < anchors.length; i++) {
		var a = anchors[i];

		if(a.rel == "popup") {
			newHref = "javascript: var win = window.open('" + a.href + "','popup','width=" + wWind + ",height=" + hWind + ",left=" + wPos + ",top=" + hPos + ",directories=no,location=no,menubar=no,status=no,resizable=yes,toolbar=no,scrollbars=yes'); win.focus();";
			a.href = newHref;
		}
	}

} catch(error) {
	;
}

}


function invertContentPosition(id1,id2) {

try {
	var el1 = document.getElementById(id1);
	var el2 = document.getElementById(id2);

	tempHtml = el1.innerHTML;
	el1.innerHTML = el2.innerHTML;
	el2.innerHTML = tempHtml;

} catch(error) {
	;
}

}


function showBody(action) {

var body = document.getElementsByTagName('body')[0];
if(action == false)
	body.style.visibility = 'hidden';
else
        body.style.visibility = 'visible';

}

