
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";

}


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;

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

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

		case "width":
			value = div.offsetWidth;
			break;

		case "height":
			value = div.offsetHeight;
			break;
	}

	offset = offset + value;

} while(div = div.offsetParent);

return offset;

}


function setTargetNew() {

var ancore = document.getElementsByTagName('a');

for(var i = 0; i < ancore.length; i++) {
        var ancora = ancore[i];

        if(ancora.rel == "external") {
	        ancora.target = "_new";
        }
}

}

function showBody(action) {

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

}

