function openWindow (url,tit,widgets) {
	popupWin = window.open (url,tit,widgets);
	popupWin.focus();
}

function show_hide(id){
	if(document.getElementById(id).style.display == "block") {
		document.getElementById(id).style.display = "none";
	}
	else if(document.getElementById(id).style.display == "" || document.getElementById(id).style.display == "none") {
		document.getElementById(id).style.display = "block";
	}
	return;
}

function loadImg(divtoshow,srcimg,file){	
	show_hide(divtoshow);
	document.getElementById(srcimg).src = file;
}


//*******************************************************
//FUNZIONI DI VALIDAZIONE DEL FORM
//*******************************************************


// checkPatternChars : checks a specific pattern of typed chars
function checkPatternChars(nm,vlu,pattern,required){
  if ( required === undefined ) {
      required = false;
   } 
  if(!required && vlu==""){
    return true;
  }
  if (!pattern.test(vlu)){
	$("#msg").load("all_message.php",{msg:'o'+nm+'_chars'});	
    return false;
  }
  else { 
    return true; 
  }
}

function validateFileExtension(fld) {
	if(!/(\.gif|\.jpg|\.jpeg)$/i.test(fld)) return false;
	else return true;
}



function dosearch(dove){
	if(dove != "convenzioni.php" && dove != "cosa_abbiamo_fatto.php" && dove != "archivio.php" && dove != "news_com.php")dove = "news_com.php";
	window.location = dove+"?search="+$("#search").val();
}

//FUNZIONI PER LA PAGINA CONTATTI

function isEmailcontatti(what){
   var i=new RegExp("^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,3}|[0-9]{1,3})(\\]?)$");
   if(!i.test(what)){return true}   
   return false;
}

function isCAP(what){
   var i=new RegExp("^[0-9]{5}$");
   if(!i.test(what)) {return true }   
   return false;
}

function check_campi(modulo){
	if(document.getElementById("nome").value == ""){
		alert("Non hai inserito il tuo nome...");
		document.getElementById("nome").focus();
		return;	
	}  else if (document.getElementById("email").value == "" || isEmailcontatti(document.getElementById("email").value)){
		alert("La mail e' sbagliata oppure hai dimenticato di inserirla...");
		document.getElementById("email").focus();
		return;	
	}  else if (document.getElementById("spamcode").value == ""){
		alert("Non hai messo correttamente il codice AntiSpam!!!");
		document.getElementById("spamcode").focus();
		return;
	}
	modulo.submit();
}



function check_campi_iscr(modulo){

	var ord_sost;
	ord_sost = jQuery('#iscriviti_form input:radio:checked').val();  

	if(document.getElementById("nome").value == ""){
		alert("Il campo nome è obbligatorio...");
		document.getElementById("nome").focus();
		return;	
	} else if(document.getElementById("cognome").value == ""){
		alert("Il campo cognome è obbligatorio...");
		document.getElementById("cognome").focus();
		return;	
	} else if(document.getElementById("cf").value == ""){
		alert("Il campo codice fiscale è obbligatorio...");
		document.getElementById("cf").focus();
		return;	
	} else if(document.getElementById("docutipo").value == ""){
		alert("Il campo tipo documento è obbligatorio...");
		document.getElementById("docutipo").focus();
		return;	
	} else if(document.getElementById("docunumero").value == ""){
		alert("Il campo numero documento è obbligatorio...");
		document.getElementById("docunumero").focus();
		return;	
	} else if(document.getElementById("indirizzo").value == ""){
		alert("Il campo indirizzo è obbligatorio...");
		document.getElementById("indirizzo").focus();
		return;	
	} else if(document.getElementById("cap").value == "" || isCAP(document.getElementById("cap").value)){
		alert("Formato del CAP errato o non inserito...");
		document.getElementById("cap").focus();
		return;	
	} else if(document.getElementById("citta").value == ""){
		alert("Il campo citta è obbligatorio...");
		document.getElementById("citta").focus();
		return;	
	} else if(document.getElementById("email").value == "" && document.getElementById("telefono").value == "" && document.getElementById("cellulare").value == ""){
		alert("E' obbligatorio inserire almeno uno tra telefono, cellulare o email");
		document.getElementById("email").focus();
		return;	
	} else if(document.getElementById("giorno").value == "" || document.getElementById("mese").value == "" || document.getElementById("anno").value == ""){
		alert("La data di nascita e' obbligatoria...");
		document.getElementById("giorno").focus();
		return;	
	} else if (document.getElementById("spamcode").value == ""){
		alert("Non hai messo correttamente il codice AntiSpam!!!");
		document.getElementById("spamcode").focus();
		return;
	} else if(document.getElementById("statuto").value != "on"){
		alert("L'accettazione dello statuto dell'Associazione e' obbligatoria ai fini dell'iscrizione");
		document.getElementById("statuto").focus();
		return;	
	} else if(document.getElementById("datip").value != "on"){
		alert("Il consenso al trattamento dei dati personali e' obbligatoria ai fini dell'iscrizione");
		document.getElementById("datip").focus();
		return;	
	} else if(ord_sost == "sostenitore"){		
		var qt = eval(document.getElementById("quota").value);
		if(document.getElementById("quota").value == "" || qt < 50){
			alert("In caso di socio sostenitore è obbligatorio specificare la quota (minimo 50 euro)");
			document.getElementById("quota").focus();
			return;	
		} 		
	} 
	modulo.submit();
}



// make it a plugin!

(function($) {
 $.fn.vCenter = function(options) {
   var pos = {
     sTop : function() {
       return window.pageYOffset
       || document.documentElement && document.documentElement.scrollTop
       ||  document.body.scrollTop;
     },
     wHeight : function() {
       return window.innerHeight
       || document.documentElement && document.documentElement.clientHeight
       || document.body.clientHeight;
     }
   };
   return this.each(function(index) {
     if (index == 0) {
       var $this = $(this);
       var elHeight = $this.height();
       var elTop = pos.sTop() + (pos.wHeight() / 2) - (elHeight / 2);
       $this.css({
         position: 'absolute',
         marginTop: '0',
         top: elTop
       });
     }
   });
 };
})(jQuery); // end plugin


//funzione di salva e stampa
function vedi_stampa_esporta(azione,id,tab){
	openWindow("inc.stampavedi.php?azione="+azione+"&tab="+tab+"&id="+id,"","width=490, height=600, scrollbars=yes, toolbars=no, resizable=yes");
}

//gestione blocco note...
// le azioni sono: add, remove
function addRemoveNote(azione,id,tab){
	$("#notes").load("inc.notes.php",{azione:azione,id:id,tab:tab});
}


function addelements(action){
	if(action=="a"){
		$("#menuleft").append("<li><a href='javascript:vedi_stampa_esporta(\"stampalista\",0,\"\");'>Stampa blocco note</a></li>");
		$("#menuleft").append("<li><a href='javascript:vedi_stampa_esporta(\"view\",0,\"\");'>Visualizza blocco note</a></li>");
	} else {
		//opener.$("#liuno").empty();
		//opener.$("#lidue").empty();
	}
	
}


function show_det_v(id_det,cosa) {
	$('#bg').height($(document).height());
	$('#bg').fadeIn('fast');
	$('#det').vCenter();
	$('#det').fadeIn('fast');	
	$("#det").animate( {"left": "-=25%", width:"600px"}, 1000 );
	$("#det").animate( {"top": "-=190px",  height:"380px"}, 1000 );

	$("#det").load(cosa + "_det.php",{id:id_det,tab:cosa});
}

function show_det_d(id_det) {
	$('#bg').height($(document).height());
	$('#bg').fadeIn('fast');
	$('#det').vCenter();
	$('#det').fadeIn('fast');	
	$("#det").animate( {"left": "-=25%", width:"600px"}, 1000 );
	$("#det").animate( {"top": "-=190px",  height:"380px"}, 1000 );

	$("#det").load("allegati_dossier.php",{id:id_det});
}


function Close_Popup() {
	
	$("#det").animate( {"left": "+=25%", width:"0px"}, 1000 );
	$("#det").animate( {"top": "+=190px",  height:"0px"}, 1000 );
	$('#bg').fadeOut('fast');
	$('#det').fadeOut('fast');
}

