
function xmlAjaxRequest(get,post,retFunct, type) {

var urlAjax = './ajax.php';

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(retFunct == null) {
				if(http_request.responseText != "1") {
					alert("Errore server: riprova più tardi");
				}
			
			} else {
				if(type == 'text')
					retFunct(http_request.responseText);
				else if(type == '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 '';

return val;

}




