function img_rid(id, largh, alt) {

	//ricavo la larghezza e altezza originali
        var largh_or = document.getElementById(id).width;
	var alt_or = document.getElementById(id).height;
        
	// se è orrizontale o quadrata
	if(largh_or >= alt_or) {
	     if (largh < largh_or){
	    
		var alt_new = largh * alt_or / largh_or;
		document.getElementById(id).width = largh;
		document.getElementById(id).height = alt_new;
	     }else{
	    
		document.getElementById(id).width = largh_or;
		document.getElementById(id).height = alt_or;
	     }
	}

	// se è verticale
	else if(alt_or > largh_or) {
	    if (alt < alt_or){
	    
		var largh_new = largh_or * alt / alt_or;
		document.getElementById(id).width = largh_new;
		document.getElementById(id).height = alt;
		}else{
			document.getElementById(id).width = largh_or;
			document.getElementById(id).height = alt_or;	
		}
	}
	
	
}


function toggleMenu(objID) {
if (!document.getElementById) return;
var ob = document.getElementById(objID).style;

ob.display = (ob.display == 'block')?'none': 'block';

}

function toggleMenu1(objID) {
if (!document.getElementById) return;
var ob = document.getElementById(objID).style;
ob.display = (ob.display == 'block')?'none': 'block';

}

function nascondi(objID) {
if (!document.getElementById) return;
var ob = document.getElementById(objID).style;

ob.display = 'none';

}

function check(objID) {

if (document.Strutt.tipoStruttura.value == -1){
   alert ('Seleziona il tipo di struttura che desideri ricercare');
   return false;}

   return true;
  
   }

function checkScheda(objID) {

if (document.StruttScheda.tipoStruttura.value == -1){
   alert ('Seleziona il tipo di struttura che desideri ricercare');
   return false;}

   return true;
  
   }
   
function next_mese(tipo, mese, giorno, meseNumero) {


	if (tipo == "mese"){
		if (mese == 11){
			document.getElementById("mese").value = 0;
			}
		else{
			document.getElementById("mese").value = mese + 1;
			
			}
			document.getElementById("richiesta").value = "mese";
			
		}
	else if (tipo = "giorno"){
	        document.getElementById("richiesta").value = "eventi_giorno";
	        document.getElementById("data").value = giorno;
			document.getElementById("mese").value = meseNumero;
	        }
	document.forms["calendar_form"].submit();
	
}

function prev_mese(mese) {


	if (mese == 0)
		document.getElementById("mese").value = 11;
	else if (mese == 11)
		document.getElementById("mese").value = 0;
	else
		document.getElementById("mese").value = mese - 1;
		
	document.getElementById("richiesta").value = "mese";
	document.forms["calendar_form"].submit();
	
}	



/* Funzioni della scheda appuntamento */
function getImageWidth(myImage){
	 img = new Image();
	 img.src = myImage;
	 return img.width
}
function getImageHeight(myImage){
	 img = new Image();
	 img.src = myImage;
	 return img.height;
}

function showImage(title, image, bgcolor, linkstyle, imagetext){
a =  getImageWidth(image);
b = getImageHeight(image);
	var window = open('', "", "width="+a+",height="+(b+40)+" ,left=" +((screen.width - 100) / 2) + ",top=" + ((screen.height - 100) / 2)  +",resizable = yes , scrollbars=1");
	
	window.document.write('<html><head><title>');
	window.document.write(title);
	window.document.write('</title><style type="text/css">');
	window.document.write('a{ ' + linkstyle + ' }');
	
	window.document.write('</style></head><body onblur="close();"  bgcolor="' + bgcolor + '" topmargin="0" bottommargin="0" leftmargin="0" rightmargin="0"><center><img alt="' + imagetext + '" src= "');
	window.document.write(image);
	window.document.write('"><br>');
	window.document.write('<p class="pagine" align="center" ><a style="FONT-SIZE: 80%;color: #A8B149;"  href="#"onClick=" window.close()">Chiudi finestra</a></p>')
	window.document.write('</center></body></html>');
	window.document.close();

}
/* Fine Funzioni della scheda appuntamento */

/*Funzioni inserimento evento */

function controllaData()
{
	var data = document.getElementById('dataI').value;
	
	var espressione = /^[0-9]{2}\-[0-9]{2}\-[0-9]{4}$/;
if (!espressione.test(data))
{
	alert("Formato Data Inizio Sbagliato, ti ricordiamo di inserire la data nel formato gg-mm-aaaa. Sei pregato di utilizzare il trattino - come separatore. Grazie");
	return false;
}

var dataF = document.getElementById('dataF').value;
	
	
if (!espressione.test(dataF))
{
	alert("Formato Data Fine Sbagliato, ti ricordiamo di inserire la data nel formato gg-mm-aaaa. Sei pregato di utilizzare il trattino - come separatore. Grazie");
	return false;
}else{
	
	return true;
}
	
}

/* Funzioni registrazione utente */

			
		function checkReg ( ){
	
					if (!hasData(document.regform.nome.value)){
		
						alert("Prego inserire il corretto valore nel campo 'Nome'!");
						 return false;
}

					
									if (!checkMail(document.regform.email.value)){
		
						alert("Prego inserire il corretto valore nel campo 'Mail'!");
						 return false;
}
					
				

					

					if (!checkPwd( document.regform.pwd.value , document.regform.pwd1.value)){
								alert("Prego inserire un valore per i campi 'Password' e assicurarsi che siano uguali!");
								return false;
								}
					else return  true;
    
  
}

function hasData (s ){
	
					if (s.length == 0){
						 return false;
}
			else return true;
	}
	
function checkMail (s ){
	
					if (!hasData(s)){
						 return false;
}
		if ((s.indexOf("@")) == -1)
			return false;
			return true;
	}

function checkPwd (s  , t){
	
					if (!hasData(s)){
						 return false;
}
		if(!(s == t))
			return false;
		 return true;
	}


/* Fine funzioni registrazione utente */

/* Funzioni proposta gruppo */

	function checkG ( ){
	
					if (!hasDataG(document.propostaG.denominazione.value)){
		
						alert("Prego inserire un valore nel campo 'Gruppo'!");
						 return false;
					}

					
					if (!hasDataG(document.propostaG.contatto.value)){
		
						alert("Prego inserire un valore nel campo 'Contatto'!");
						 return false;
					}
				

					if (!checkPwdG( document.propostaG.pwd.value , document.propostaG.pwd1.value)){
								alert("Prego inserire un valore per i campi 'Password'!");
								return false;
								}
					else return  true;
    
  
}

function hasDataG (s ){
	
			if (s.length == 0){
				return false;
			}
			else return true;
	}
	


function checkPwdG (s  , t){
	
		if (!hasDataG(s)){
			return false;
		}
		if(!(s== t))
			return false;
		 return true;
	}
/*fine funzioni proposta gruppo */
