var http = createRequestObject();
var disableProv=false;
var disableCheck=false;

var disableNCitta=false;
var disableCitta=false;

function createRequestObject() {
	var ro;
	var browser = navigator.appName;
	if(browser == "Microsoft Internet Explorer"){
		ro = new ActiveXObject("Microsoft.XMLHTTP");
	}else{
		ro = new XMLHttpRequest();
	}
	return ro;
}

function loading1(id,item1){
	if(disableCheck) return;
	switch (item1){
		case 'id_provincia_n':
			disableCitta=true;
			http.open('GET','funzioni.php?azione=city&id_provincia='+id, true);
			http.onreadystatechange = getNCity;
			break;
	}
	http.send(null);
}

function loading(id,item1){
	if(disableCheck) return;
	switch (item1){
		case 'id_provincia':
			disableProv=true;
			disableNCitta=true;
			http.onreadystatechange = getCity;
			http.open('GET','funzioni.php?azione=city&id_provincia='+id, true);
			http.onreadystatechange = getCity;
			http.send(null);
			break;
		case 'id_regione':
			disableNCitta=true;
			http.onreadystatechange = getProv;
			http.open('GET','funzioni.php?azione=prov&id_regione='+id, true);
			http.onreadystatechange = getProv;
			http.send(null);
			break;
		case 'regione1_id':
			disableNCitta=true;
			http.onreadystatechange = getProv1;
			http.open('GET','funzioni.php?azione=prov&id_regione='+id, true);
			http.onreadystatechange = getProv1;
			http.send(null);
			break;
		case 'regione2_id':
			disableNCitta=true;
			http.onreadystatechange = getProv2;
			http.open('GET','funzioni.php?azione=prov&id_regione='+id, true);
			http.onreadystatechange = getProv2;
			http.send(null);
			break;
		case 'regione3_id':
			disableNCitta=true;
			http.onreadystatechange = getProv3;
			http.open('GET','funzioni.php?azione=prov&id_regione='+id, true);
			http.onreadystatechange = getProv3;
			http.send(null);
			break;
		case 'provincia1_id':
			disableProv=true;
			disableNCitta=true;
			http.onreadystatechange = getCity1;
			http.open('GET','funzioni.php?azione=city&id_provincia='+id, true);
			http.onreadystatechange = getCity1;
			http.send(null);
			break;
		case 'provincia2_id':
			disableProv=true;
			disableNCitta=true;
			http.onreadystatechange = getCity2;
			http.open('GET','funzioni.php?azione=city&id_provincia='+id, true);
			http.onreadystatechange = getCity2;
			http.send(null);
			break;
		case 'provincia3_id':
			disableProv=true;
			disableNCitta=true;
			http.onreadystatechange = getCity3;
			http.open('GET','funzioni.php?azione=city&id_provincia='+id, true);
			http.onreadystatechange = getCity3;
			http.send(null);
			break;
	}
}

function getNCity(){
	if(disableNCitta) return;
	var newOption;
	var where = (navigator.appName == "Microsoft Internet Explorer") ? -1 : null;
	var City = document.getElementById('id_citta_n');
	
	while (City.options.length) {
		City.remove(0);
	}
	id = document.getElementById('id_provincia_n').value;
	
	if(id == ''){
		document.getElementById('id_citta_n').disabled = true;
		newOption = document.createElement("option");
		newOption.value = '';
		newOption.text = 'Seleziona una Citta\'';
		City.add(newOption, where);
	} else {
		if(http.readyState == 4){
			if (http.status == 200) {
				var response = http.responseText;
				if(response == ''){
					document.getElementById('id_citta_n').disabled = true;
					newOption = document.createElement("option");
					newOption.value = '';
					newOption.text = 'Nessuna voce';
					City.add(newOption, where);
				}else{
					coppia = response.split(',');
					max = coppia.length;
					newOption = document.createElement("option");
					newOption.value = '';
					newOption.text = 'Seleziona una Citta\'';
					City.add(newOption, where);
					for(x=0;x<max;x++){
						val = coppia[x].split('-');
						newOption = document.createElement("option");
						newOption.value = val[0];
						newOption.text = val[1];
						City.add(newOption, where);
					}
					document.getElementById('id_citta_n').disabled = false;
				}
			}
		}
	}
	disableCitta=false;
	City=null;
	newOption=null;
}

function getCity(){
	if(disableCitta) return;
	var newOption;
	var where = (navigator.appName == "Microsoft Internet Explorer") ? -1 : null;
	var City = document.getElementById('id_citta');
	
	while (City.options.length) {
		City.remove(0);
	}
	id = document.getElementById('id_provincia').value;
	
	if(id == ''){
		document.getElementById('id_citta').disabled = true;
		newOption = document.createElement("option");
		newOption.value = '';
		newOption.text = 'Seleziona una Citta\'';
		City.add(newOption, where);
	}else{
		if(http.readyState == 4){
			if (http.status == 200) {
				var response = http.responseText;
				if(response == ''){
					document.getElementById('id_citta').disabled = true;
					newOption = document.createElement("option");
					newOption.value = '';
					newOption.text = 'Nessuna voce';
					City.add(newOption, where);
				}else{
					coppia = response.split(',');
					max = coppia.length;
					newOption = document.createElement("option");
					newOption.value = '';
					newOption.text = 'Seleziona una Citta\'';
					City.add(newOption, where);
					for(x=0;x<max;x++){
						val = coppia[x].split('-');
						newOption = document.createElement("option");
						newOption.value = val[0];
						newOption.text = val[1];
						City.add(newOption, where);
					}
					disableProv=false;
					document.getElementById('id_citta').disabled = false;
				}
			}
		}
	}
	City=null;
	newOption=null;
	disableNCitta=false;
}

function getProv(){
	if(disableProv) return;
	var newOption;
	var where = (navigator.appName == "Microsoft Internet Explorer") ? -1 : null;
	var Prov = document.getElementById('id_provincia');
	
	while (Prov.options.length) {
		Prov.remove(0);
	}
	var City = document.getElementById('id_citta');
	
	while (City.options.length) {
		City.remove(0);
	}
	
	id = document.getElementById('id_regione').value;
	
	if(id == ''){
		document.getElementById('id_provincia').disabled = true;
		newOption = document.createElement("option");
		newOption.value = '';
		newOption.text = 'Seleziona una provincia';
		Prov.add(newOption, where);
	}else{
		if(http.readyState == 4){
			if (http.status == 200) {
				var response = http.responseText;
				if(response == ''){
					document.getElementById('id_provincia').disabled = true;
					newOption = document.createElement("option");
					newOption.value = '';
					newOption.text = 'Nessuna voce';
					Prov.add(newOption, where);
				}else{
					coppia = response.split(',');
					max = coppia.length;
					newOption = document.createElement("option");
					newOption.value = '';
					newOption.text = 'Seleziona una provincia';
					Prov.add(newOption, where);
					for(x=0;x<max;x++){
						val = coppia[x].split('-');
						newOption = document.createElement("option");
						newOption.value = val[0];
						newOption.text = val[1];
						Prov.add(newOption, where);
					}
					document.getElementById('id_provincia').disabled = false;
				}
			}
		}
	}
	City=null;
	newOption=null;
	disableNCitta=false;
}

function getNick(){
	if(http.readyState == 4){
		if (http.status == 200) {
			var response = http.responseText;
			if(response != '0'){
				document.getElementById('errorsDiv_username').innerHTML= 'Username gi&agrave; utilizzato';
				document.getElementById('username').focus();
				document.getElementById('username').select();
			}else{
				if(document.getElementById('errorsDiv_username').innerHTML!="") {
					document.getElementById('errorsDiv_username').innerHTML= '';
					}
			}
		}
	}
}
	
function tiporeg(radio1,radio2,id1,val){
	var a=document.getElementById(radio1);
	var b=document.getElementById(radio2);
	var c=document.getElementById('usertype');
	var x=document.getElementById(id1);
	var IE=(window.navigator.userAgent.indexOf('MSIE')>-1)?1:0;
	c.value=val;
	
	if(a.checked){
		b.checked=false;
	}else{
		a.checked=false;
	}
	if(a.id=='usertype1'){
		x.style.display="none";
	}else{
		x.style.display = (IE)?'block':'table-row';
	}
	var user=document.getElementById('username');
	user.focus();
}

function cambiaTipo(radio1,radio2,id1,id2,val){
	var a=document.getElementById(radio1);
	var b=document.getElementById(radio2);
	var c=document.getElementById('tipoData');
	var x=document.getElementById(id1);
	var y=document.getElementById(id2);
	var IE=(window.navigator.userAgent.indexOf('MSIE')>-1)?1:0;
	c.value=val;
	if(a.checked){
		b.checked=false;
		y.style.display="none";
		x.style.display = (IE)?'block':'table-row';
		
	}else{
		a.checked=false;
		x.style.display="none";
		y.style.display = (IE)?'block':'table-row';
	}
	/*if(IE){
		var user=document.getElementById('username');
		x.blur();
	 	user.focus();
	}*/
}


function fNazione(){

	var x1=document.getElementById('nazione1');
	var x2=document.getElementById('nazione2');
	var y=document.getElementById('trnazione');
	var y1=document.getElementById('trprovincia');
	var y2=document.getElementById('trcitta');
	
	var IE=(window.navigator.userAgent.indexOf('MSIE')>-1)?1:0;
	
	if(x1.checked){
		y.style.display="none";
		y1.style.display = (IE)?'block':'table-row';
		y2.style.display = (IE)?'block':'table-row';
	}else{
		y.style.display = (IE)?'block':'table-row';
		y1.style.display="none";
		y2.style.display="none";
	}
}

function getProv1(){
	if(disableProv) return;
	var newOption;
	var where = (navigator.appName == "Microsoft Internet Explorer") ? -1 : null;
	var Prov = document.getElementById('provincia1_id');
	
	while (Prov.options.length) {
		Prov.remove(0);
	}
	var City = document.getElementById('citta1_id');
	
	while (City.options.length) {
		City.remove(0);
	}
	
	id = document.getElementById('regione1_id').value;
	
	if(id == ''){
		document.getElementById('provincia1_id').disabled = true;
		newOption = document.createElement("option");
		newOption.value = '';
		newOption.text = 'Seleziona una provincia';
		Prov.add(newOption, where);
	}else{
		if(http.readyState == 4){
			if (http.status == 200) {
				var response = http.responseText;
				if(response == ''){
					document.getElementById('provincia1_id').disabled = true;
					newOption = document.createElement("option");
					newOption.value = '';
					newOption.text = 'Nessuna voce';
					Prov.add(newOption, where);
				}else{
					coppia = response.split(',');
					max = coppia.length;
					newOption = document.createElement("option");
					newOption.value = '';
					newOption.text = 'Seleziona una provincia';
					Prov.add(newOption, where);
					for(x=0;x<max;x++){
						val = coppia[x].split('-');
						newOption = document.createElement("option");
						newOption.value = val[0];
						newOption.text = val[1];
						Prov.add(newOption, where);
					}
					document.getElementById('provincia1_id').disabled = false;
				}
			}
		}
	}
	City=null;
	newOption=null;
	disableNCitta=false;
}

function getProv2(){
	if(disableProv) return;
	var newOption;
	var where = (navigator.appName == "Microsoft Internet Explorer") ? -1 : null;
	var Prov = document.getElementById('provincia2_id');
	
	while (Prov.options.length) {
		Prov.remove(0);
	}
	var City = document.getElementById('citta2_id');
	
	while (City.options.length) {
		City.remove(0);
	}
	
	id = document.getElementById('regione2_id').value;
	
	if(id == ''){
		document.getElementById('provincia2_id').disabled = true;
		newOption = document.createElement("option");
		newOption.value = '';
		newOption.text = 'Seleziona una provincia';
		Prov.add(newOption, where);
	}else{
		if(http.readyState == 4){
			if (http.status == 200) {
				var response = http.responseText;
				if(response == ''){
					document.getElementById('provincia2_id').disabled = true;
					newOption = document.createElement("option");
					newOption.value = '';
					newOption.text = 'Nessuna voce';
					Prov.add(newOption, where);
				}else{
					coppia = response.split(',');
					max = coppia.length;
					newOption = document.createElement("option");
					newOption.value = '';
					newOption.text = 'Seleziona una provincia';
					Prov.add(newOption, where);
					for(x=0;x<max;x++){
						val = coppia[x].split('-');
						newOption = document.createElement("option");
						newOption.value = val[0];
						newOption.text = val[1];
						Prov.add(newOption, where);
					}
					document.getElementById('provincia2_id').disabled = false;
				}
			}
		}
	}
	City=null;
	newOption=null;
	disableNCitta=false;
}

function getProv3(){
	if(disableProv) return;
	var newOption;
	var where = (navigator.appName == "Microsoft Internet Explorer") ? -1 : null;
	var Prov = document.getElementById('provincia3_id');
	
	while (Prov.options.length) {
		Prov.remove(0);
	}
	var City = document.getElementById('citta3_id');
	
	while (City.options.length) {
		City.remove(0);
	}
	
	id = document.getElementById('regione3_id').value;
	
	if(id == ''){
		document.getElementById('provincia3_id').disabled = true;
		newOption = document.createElement("option");
		newOption.value = '';
		newOption.text = 'Seleziona una provincia';
		Prov.add(newOption, where);
	}else{
		if(http.readyState == 4){
			if (http.status == 200) {
				var response = http.responseText;
				if(response == ''){
					document.getElementById('provincia3_id').disabled = true;
					newOption = document.createElement("option");
					newOption.value = '';
					newOption.text = 'Nessuna voce';
					Prov.add(newOption, where);
				}else{
					coppia = response.split(',');
					max = coppia.length;
					newOption = document.createElement("option");
					newOption.value = '';
					newOption.text = 'Seleziona una provincia';
					Prov.add(newOption, where);
					for(x=0;x<max;x++){
						val = coppia[x].split('-');
						newOption = document.createElement("option");
						newOption.value = val[0];
						newOption.text = val[1];
						Prov.add(newOption, where);
					}
					document.getElementById('provincia3_id').disabled = false;
				}
			}
		}
	}
	City=null;
	newOption=null;
	disableNCitta=false;
}

function getCity1(){
	if(disableCitta) return;
	var newOption;
	var where = (navigator.appName == "Microsoft Internet Explorer") ? -1 : null;
	var City = document.getElementById('citta1_id');
	
	while (City.options.length) {
		City.remove(0);
	}
	id = document.getElementById('provincia1_id').value;
	
	if(id == ''){
		document.getElementById('citta1_id').disabled = true;
		newOption = document.createElement("option");
		newOption.value = '';
		newOption.text = 'Seleziona una Citta\'';
		City.add(newOption, where);
	}else{
		if(http.readyState == 4){
			if (http.status == 200) {
				var response = http.responseText;
				if(response == ''){
					document.getElementById('citta1_id').disabled = true;
					newOption = document.createElement("option");
					newOption.value = '';
					newOption.text = 'Nessuna voce';
					City.add(newOption, where);
				}else{
					coppia = response.split(',');
					max = coppia.length;
					newOption = document.createElement("option");
					newOption.value = '';
					newOption.text = 'Seleziona una Citta\'';
					City.add(newOption, where);
					for(x=0;x<max;x++){
						val = coppia[x].split('-');
						newOption = document.createElement("option");
						newOption.value = val[0];
						newOption.text = val[1];
						City.add(newOption, where);
					}
					disableProv=false;
					document.getElementById('citta1_id').disabled = false;
				}
			}
		}
	}
	City=null;
	newOption=null;
	disableNCitta=false;
}

function getCity2(){
	if(disableCitta) return;
	var newOption;
	var where = (navigator.appName == "Microsoft Internet Explorer") ? -1 : null;
	var City = document.getElementById('citta2_id');
	
	while (City.options.length) {
		City.remove(0);
	}
	id = document.getElementById('provincia2_id').value;
	
	if(id == ''){
		document.getElementById('citta2_id').disabled = true;
		newOption = document.createElement("option");
		newOption.value = '';
		newOption.text = 'Seleziona una Citta\'';
		City.add(newOption, where);
	}else{
		if(http.readyState == 4){
			if (http.status == 200) {
				var response = http.responseText;
				if(response == ''){
					document.getElementById('citta2_id').disabled = true;
					newOption = document.createElement("option");
					newOption.value = '';
					newOption.text = 'Nessuna voce';
					City.add(newOption, where);
				}else{
					coppia = response.split(',');
					max = coppia.length;
					newOption = document.createElement("option");
					newOption.value = '';
					newOption.text = 'Seleziona una Citta\'';
					City.add(newOption, where);
					for(x=0;x<max;x++){
						val = coppia[x].split('-');
						newOption = document.createElement("option");
						newOption.value = val[0];
						newOption.text = val[1];
						City.add(newOption, where);
					}
					disableProv=false;
					document.getElementById('citta2_id').disabled = false;
				}
			}
		}
	}
	City=null;
	newOption=null;
	disableNCitta=false;
}

function getCity3(){
	if(disableCitta) return;
	var newOption;
	var where = (navigator.appName == "Microsoft Internet Explorer") ? -1 : null;
	var City = document.getElementById('citta3_id');
	
	while (City.options.length) {
		City.remove(0);
	}
	id = document.getElementById('provincia3_id').value;
	
	if(id == ''){
		document.getElementById('citta3_id').disabled = true;
		newOption = document.createElement("option");
		newOption.value = '';
		newOption.text = 'Seleziona una Citta\'';
		City.add(newOption, where);
	}else{
		if(http.readyState == 4){
			if (http.status == 200) {
				var response = http.responseText;
				if(response == ''){
					document.getElementById('citta3_id').disabled = true;
					newOption = document.createElement("option");
					newOption.value = '';
					newOption.text = 'Nessuna voce';
					City.add(newOption, where);
				}else{
					coppia = response.split(',');
					max = coppia.length;
					newOption = document.createElement("option");
					newOption.value = '';
					newOption.text = 'Seleziona una Citta\'';
					City.add(newOption, where);
					for(x=0;x<max;x++){
						val = coppia[x].split('-');
						newOption = document.createElement("option");
						newOption.value = val[0];
						newOption.text = val[1];
						City.add(newOption, where);
					}
					disableProv=false;
					document.getElementById('citta3_id').disabled = false;
				}
			}
		}
	}
	City=null;
	newOption=null;
	disableNCitta=false;
}

function checknick(item1){
	if(disableCheck) return;
	if(item1==''){
			if(document.getElementById('errorsDiv_username').innerHTML!="") {
			document.getElementById('errorsDiv_username').innerHTML= ' ';
		}
		return;
	}
	http.onreadystatechange = getNick;
	http.open('GET','funzioni.php?azione=ck&nick='+item1, true);
	http.onreadystatechange = getNick;
	http.send(null);
}

function checkCell(item1){
	if(item1==''){
		document.getElementById('errorsDiv_cellulare').innerHTML= ' ';
		return;
	}
	if(document.getElementById('oldcell').value!='' && document.getElementById('oldcell').value==document.getElementById('cellulare').value){
		document.getElementById('errorsDiv_cellulare').innerHTML= ' ';
		return;
	}

	if(disableCheck) return;
	http.onreadystatechange = getCell;
	http.open('GET','funzioni.php?azione=cc&cell='+item1, true);
	http.onreadystatechange = getCell;
	http.send(null);
}

function getCell(){
	if(http.readyState == 4){
		if (http.status == 200) {
			var response = http.responseText;
			if(response.substr(-1) != 0){
				document.getElementById('errorsDiv_cellulare').innerHTML= 'Cellulare gi&agrave; utilizzato';
				document.getElementById('cellulare').focus();
				document.getElementById('cellulare').select();
			}else{
				if(document.getElementById('errorsDiv_cellulare').innerHTML!="") {
				document.getElementById('errorsDiv_cellulare').innerHTML= ' ';
				}
			}
		}
	}
}

function checkCf(item1){

	if(disableCheck) return;
	if(item1==''){
		if(document.getElementById('errorsDiv_codicefiscale').innerHTML!="") {
			document.getElementById('errorsDiv_codicefiscale').innerHTML= ' ';
		}
		return;
	}
	if(document.getElementById('oldcf').value!='' && document.getElementById('oldcf').value==document.getElementById('codicefiscale').value){
		if(document.getElementById('errorsDiv_codicefiscale').innerHTML!="") {
			document.getElementById('errorsDiv_codicefiscale').innerHTML= ' ';
		}
		return;
	}
	if(disableCheck) return;
	http.onreadystatechange = getCf;
	http.open('GET','funzioni.php?azione=cf&codfisc='+item1, true);
	http.onreadystatechange = getCf;
	http.send(null);
}

function getCf(){
	if(http.readyState == 4){
		if (http.status == 200) {
			var response = http.responseText; 
			if(response.substr(-1) != 0){
				document.getElementById('errorsDiv_codicefiscale').innerHTML= 'C.F./P.Iva gi&agrave; utilizzato';
				document.getElementById('codicefiscale').focus();
				document.getElementById('codicefiscale').select();
			}else{
				if(document.getElementById('errorsDiv_codicefiscale').innerHTML!="") {
					document.getElementById('errorsDiv_codicefiscale').innerHTML= ' ';
				}
			}
		}
	}
}

function checkEmail(item1){
	if(item1==''){
		if(document.getElementById('errorsDiv_email').innerHTML!="") {
			document.getElementById('errorsDiv_email').innerHTML= ' ';
		}
		return;
	}
	if(document.getElementById('oldemail').value!='' && document.getElementById('oldemail').value==document.getElementById('email').value){
		if(document.getElementById('errorsDiv_email').innerHTML!="") {
			document.getElementById('errorsDiv_email').innerHTML= ' ';
		}
		return;
	}
	if(disableCheck) return;
	http.onreadystatechange = getEmail;
	http.open('GET','funzioni.php?azione=ce&email='+item1, true);
	http.onreadystatechange = getEmail;
	http.send(null);
}

function getEmail(){
	if(http.readyState == 4){
		if (http.status == 200) {
			var response = http.responseText;
			if(response.substr(-1) != 0){
				document.getElementById('errorsDiv_email').innerHTML= 'Email gi&agrave; utilizzato';
				document.getElementById('email').focus();
				document.getElementById('email').select();
			}else{
				if(document.getElementById('errorsDiv_email').innerHTML!="") {
					document.getElementById('errorsDiv_email').innerHTML= ' ';
				}
			}
		}
	}
}

function winpopup(pagename){
	document.getElementById('column-1').style.display='';
	http.open('GET','funzioni.php?azione=winpopup&pageName='+pagename, true);
	http.onreadystatechange = getInfo;
	http.send(null);
	javascript:document.documentElement.style.overflow='hidden';
}

function getInfo(){
	if(http.readyState == 4){
		if (http.status == 200) {
			var response = http.responseText;
			if(response != ''){
				document.getElementById('info').innerHTML=response;
			}else{
				if(document.getElementById('errorsDiv_email').innerHTML!="") {
					document.getElementById('info').innerHTML= '';
				}
			}
		}
	}
}


function validaHM(lang,hh,mm,rh1,rm1,rh2,rm2){
	hh=hh*1;
	mm=mm*1;
	rh1=rh1*1;
	rh2=rh2*1;
	rm1=rm1*1;
	rm2=rm2*1;
	
	if(lang=='it'){
		msg= "Orario non compreso nel periodo!";
	}else{
		msg= "Orario non compreso nel periodo!";
	}

	if(hh<rh1 || hh>rh2 ){
		return msg;		
	}else if(hh==rh1){
		if(mm<rm1){
			return msg;
		}else{
			return null;
		}
	}else if(hh==rh2){
		if(mm>rm2){
			return msg;
		}else{
			return null;
		}
	}
}		


function validaHMPeriodo(lang,oggi,data,hh,mm,rh1,rm1,rh2,rm2,tipodata){
	
	if(lang=='it'){
		msg= "Orario periodo non valido!";
	}else{
		msg= "Orario periodo non valido!";
	}
	hh=hh*1;
	mm=mm*1;
	rh1=rh1*1;
	rh2=rh2*1;
	rm1=rm1*1;
	rm2=rm2*1;
	
	if(tipodata==1 || oggi<data){
	 	if(rh1>rh2 ){
			return msg;		
		}else if(rh1==rh2){
			if(rm1>=rm2){
				return msg;
			}else{
				return null;
			}
		}
	}else{
		if(hh>rh1 || rh1>rh2 ){
			return msg;		
		}else if(hh==rh1 && mm>rm1){
			return msg;
		}else if(rh1==rh2){
			if(rm1>=rm2){
				return msg;
			}else{
				return null;
			}
		}
	}
}		

		
function validaCell(){
	var num=document.getElementById('cellulare');
	var val=num.value;
	var rx= /^3[\d]{8,}$/g;
	var xx=val.match(rx);
	
	if(xx==null){
		if (val.length==0){
			return "Inserire il numero di cellulare";
		}else{
			return "Numero non corretto";
		}
	}else if(val.length==xx[0].length){
		return null;
	}
}		
		

function DataNascita(){
	var anno=document.getElementById('anno_n');
	var mese=document.getElementById('mese_n');
	var giorno=document.getElementById('giorno_n');
	var nato=document.getElementById('nato_il');
	
	if(anno.value=='' || mese.value=='' || giorno.value=='')
		nato.value='';
	else
		nato.value=giorno.value+'-'+mese.value+'-'+anno.value;
}

function textCounter(field,cntfield,maxlimit) {
	if (field.value.length > maxlimit) // if too long...trim it!
		field.value = field.value.substring(0, maxlimit);
	// otherwise, update 'characters left' counter
	else {
		cntfield.value = maxlimit - field.value.length;
	}
}

function isEmail(string) {
if (string.search(/^\w+((-\w+)|(\.\w+))*\@\w+((\.|-)\w+)*\.\w+$/) != -1)
return 1;
else
return 0;
}


function controllaMail(valore, oggetto){
var ogg=document.getElementById(oggetto);

if ( isEmail(valore) == 0 ) 
{ 
	ogg.innerHTML= 'Indirizzo mail non valido';
	ogg.focus();
	ogg.select();
	return false;
}
else
	{
	if(ogg.innerHTML!="") {
		ogg.innerHTML= ' ';
	}
	return true;
	}
return false;
}

function ValidazioneBannerUpdate(){
	var result=true;
	var x=document.getElementById('title');
	var y=document.getElementById('errorsDiv_title');
	
	if(x.value==''){
		y.innerHTML='Inserire il titolo del banner';
		result=( result && false );
	}else{
		y.innerHTML='';
		result=( result && true );
	}
	
	x=document.getElementById('orientamento');
	y=document.getElementById('errorsDiv_orientamento');
	if(x.value==0){
		y.innerHTML='Selezionare un orientamento';
		result=( result && false );
	}else{
		y.innerHTML='';
		result=( result && true );
	}
		
	return result;
}

function ValidazioneBanner(){
	var result=true;
	var x=document.getElementById('title');
	var y=document.getElementById('errorsDiv_title');
	
	if(x.value==''){	
		y.innerHTML='Inserire il titolo del banner';
		result=( result && false );
	}else{
		y.innerHTML='';
		result=( result && true );
	}
	
	x=document.getElementById('orientamento');
	y=document.getElementById('errorsDiv_orientamento');
	if(x.value==0){
		y.innerHTML='Selezionare un orientamento';
		result=( result && false );
	}else{
		y.innerHTML='';
		result=( result && true );
	}
	
	x=document.getElementById('immagine1');
	y=document.getElementById('errorsDiv_immagine1');
	if(x.value==''){
		y.innerHTML='Inserire un immagine';
		result=( result && false );
	}else{
		y.innerHTML='';
		result=( result && true );
	}
		
	return result;
}


function ValidazioneSMS(){
	var result=true;
	var x=document.getElementById('testo');
	var y=document.getElementById('errorsDiv_testo');
	
	if(x.value.length<30){
		y.innerHTML='Il testo deve essere lungo almeno 30 caratteri';
		result=( result && false );
	}else{
		y.innerHTML='';
		result=( result && true );
	}
		
	return result;
}

 
function servizio_add_check_date(){


	var res=true;
	var tipo=document.getElementById('tipoData');
	var oggi=document.getElementById('dataoggi');
	
	var app=document.getElementById('disponibile_data');

	var data_da=document.getElementById('disponibile_data_da');
	var data_a=document.getElementById('disponibile_data_a');


	if(tipo.value==0){
		//data 
		var div=document.getElementById('errorsDiv_dataoggi');
		if(oggi.value>app.value) {
			res=false;
			div.innerHTML=' ';
			div.innerHTML='Data disponibilit&agrave;� errata';
		}else{
				div.innerHTML='';
		}
	}else{
		//periodo
		var div=document.getElementById('errorsDiv_disponibile_data_da');
		if(oggi.value>data_da.value) {
			res=false;
			div.innerHTML='Data inizio disponibilit&agrave;� errata';
		}else{
			div.innerHTML='';
		}
		var div=document.getElementById('errorsDiv_disponibile_data_a');
		if(oggi.value>data_a.value) {
			res=false;
			div.innerHTML='Data fine disponibilit&agrave;� errata';
		}else{
			div.innerHTML='';
		}
		if(data_da.value>data_a.value) {
			res=false;
			var div=document.getElementById('errorsDiv_disponibile_data_da');
			div.innerHTML='Periodo disponibilit&agrave; errato';
			var div=document.getElementById('errorsDiv_disponibile_data_a');
			div.innerHTML='';
		}else{
			div.innerHTML='';
			var div=document.getElementById('errorsDiv_disponibile_data_a');
			div.innerHTML='';
		}
	}

	return res;		
}