function inlineMsg(target,string,autohide) {
  var MSGOFFSET = 3;
  var MSGHIDE = 3;
  var msg;
  var msgcontent;
  if($('#inlinemsg').length) { 
    msg = $('#inlinemsg');
    msgcontent = $('#msgcontent');   
  }else{      
    var msg = $('<div id="inlinemsg"/>');
    var msgcontent = $('<div id="msgcontent"/>');
    $('body').append(msg); 
    msg.append(msgcontent);      
  }                
  msgcontent.html(string);
  if(!autohide) {autohide = MSGHIDE;}   
  //autohide = '30000000';
  msg.fadeIn('fast').delay(autohide).fadeOut('fast');    
  var msgheight = msg.height();  
  var targetheight = $(target).height();
  var targetwidth = $(target).width(); 
  var position = $(target).offset();
  var topposition = position.top - ((msgheight - targetheight) / 2); 
  var leftposition = position.left + targetwidth + MSGOFFSET;  
  //alert(position.top);
  //alert(topposition);
  //alert(position.left);
  //alert(leftposition);                              
  msg.css( { "left": leftposition + "px", "top":topposition + "px" } );  
}
// preload the arrow //
if(document.images) {      
  arrow = new Image(7,80);
  arrow.src = "/_ezfiles/img/msg_arrow.gif";
}
function valida(){
  var fadetime='3000';       
  var emailRegex = /^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$/;
  
  var cnomereq=$('#cnomereq').val();
  var ccognomereq=$('#ccognomereq').val();
  var cemailreq=$('#cemailreq').val();
  var crichiestareq=$('#crichiestareq').val(); 
  if (typeof($('#ccaptchareq').val()) != 'undefined'){var ccaptchareq=$('#ccaptchareq').val();}else{var ccaptchareq='no';}
  if ($('#cnome').val() == "") {
    $('#cnome').focus();
    inlineMsg('#cnome',cnomereq,fadetime);
    return false ;
  }
  if ($('#ccognome').val() == "") {
    $('#ccognome').focus();
    inlineMsg('#ccognome',ccognomereq,fadetime);
    return false ;
  }
  if($('#cemail').val() == ""){
    $('#cemail').focus();
    inlineMsg('#cemail',cemailreq,fadetime);
    return false ;
  } 
    if(!$('#cemail').val().match(emailRegex)) {
      $('#cemail').focus();
      inlineMsg('#cemail',cemailreq,fadetime);
      return false ;
    }  
  if ($('#crichiesta').val() == "") {
    $('#crichiesta').focus();
    inlineMsg('#crichiesta',crichiestareq,fadetime);
    return false ;
  }
  if ($('#captcha').val() == "" && ccaptchareq !='no') {
    $('#captcha').focus();
    inlineMsg('#captcha',ccaptchareq,fadetime);
    return false ;
  }
  return true;
}
function valida_recuperopwd(){
  var fadetime='3000';       
  var emailRegex = /^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$/;
  var cemailreq=$('#cemailreq').val();

  if($('#cemail').val() == ""){
    $('#cemail').focus();
    inlineMsg('#cemail',cemailreq,fadetime);
    return false ;
  } 
    if(!$('#cemail').val().match(emailRegex)) {
      $('#cemail').focus();
      inlineMsg('#cemail',cemailreq,fadetime);
      return false ;
    } 
  return true;
}

function validareg(){
  var fadetime='3000';       
  var emailRegex = /^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$/;
  var passReg = /^([a-zA-Z0-9]+)$/; //only letters and numbers
  
jQuery.fn.exists = function(){return jQuery(this).length>0;}

if ($('#rnome').exists()) {
  var rnomereq=$('#rnomereq').val();
  var rcognomereq=$('#rcognomereq').val();
  var remailreq=$('#remailreq').val();
  var remail2req=$('#remail2req').val();
  var remail_unav_req=$('#remail_unav_req').val();
  var rusernamereq=$('#rusernamereq').val();
  var rusername_unav_req=$('#rusername_unav_req').val();
  var rvalidusernamereq=$('#rvalidusernamereq').val();
  var rcaptchareq=$('#rcaptchareq').val();
}  
if ($('#rpasswd').exists()) {
  var rpasswdreq=$('#rpasswdreq').val();
  var rpasswd2req=$('#rpasswd2req').val();
  var rvalidpasswdreq=$('#rvalidpasswdreq').val();
}  
  
if ($('#rnome').exists()) {
  if($('#rnome').val() == ""){
    $('#rnome').focus();
    inlineMsg('#rnome',rnomereq,fadetime);
    return false ;
  } 
  if($('#rcognome').val() == ""){
    $('#rcognome').focus();
    inlineMsg('#rcognome',rcognomereq,fadetime);
    return false ;
  }   
  if($('#remail').val() == "" || !$('#remail').val().match(emailRegex)) {
    $('#remail').focus();
    inlineMsg('#remail',remailreq,fadetime);
    return false ;
  }    
    if($('#remail').val() != $('#remail2').val()) {
      $('#remail2').focus();
      inlineMsg('#remail2',remail2req,fadetime);
      return false ;
    }
  if($('#ruser').val() == ""){
    $('#ruser').focus();
    inlineMsg('#ruser',rusernamereq,fadetime);
    return false ;
  } 
  if ($("#ruser").val().length > 0) { 
    if ($("#ruser").val().length < 5 || !passReg.test($("#ruser").val())) { 
      $('#ruser').focus();
      inlineMsg('#ruser',rvalidusernamereq,fadetime);
    	return false;
    }
  }

      $.ajax({
        url: "/include.php",
        type: 'POST',
        async: false,
        data: {f:'validareg', user:$('#ruser').val(), email:$('#remail').val()},
        success: function(data){
        if(data=='user_unavailable'){ 
          $('#ruser').focus();
          inlineMsg('#ruser',rusername_unav_req,fadetime); 
          registration_ok = false;
        }else if(data=='email_unavailable'){
          $('#remail').focus();
          inlineMsg('#remail',remail_unav_req,fadetime); 
          registration_ok = false;
        }else{
          registration_ok = true;
        }
      }
    });
                             
    if(registration_ok==false){return false;}  
}    
if ($('#rpasswd').exists()) {
  
  if($('#rpasswd').val() == ""){
    $('#rpasswd').focus();
    inlineMsg('#rpasswd',rpasswdreq,fadetime);
    return false ;
  } 
  if ($("#rpasswd").val().length > 0) { 
    if ($("#rpasswd").val().length < 5 || !passReg.test($("#rpasswd").val())) {   
      $('#rpasswd').focus();
      inlineMsg('#rpasswd',rvalidpasswdreq,fadetime);
    	return false;
    } 
    if ($("#rpasswd").val() != $("#rpasswd2").val()) {  
      $('#rpasswd2').focus();
      inlineMsg('#rpasswd2',rpasswd2req,fadetime);    
    	return false;
    }
  }
}
if ($('#rnome').exists()) {
  if ($('#captcha').val() == "" ) {
    $('#captcha').focus();
    inlineMsg('#captcha',rcaptchareq,fadetime);
    return false ;
  }
}  
                                
    
  return true;
}

function auth(){
  var fadetime='3000'; 
  var userreq=$('#userreq').val();
  var pwdreq=$('#pwdreq').val();
  if ($('#username').val().length < 1) {
    $('#username').focus(); 
    inlineMsg('#username',userreq,fadetime); 
    return false;
  }
  if ($('#passwd').val().length < 1) {
    $('#passwd').focus(); 
    inlineMsg('#passwd',pwdreq,fadetime);   
    return false;
  }
  return true;
}

/* newsletter */
function validanl(){
  var fadetime='3000';
  var emailRegex = /^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$/;
  
  var nomereq=$('#nomereq').val();
  var cognomereq=$('#cognomereq').val();
  var emailreq=$('#emailreq').val();
  var emailreq2=$('#emailreq2').val();   
  var privacyreq=$('#privacyreq').val();
  var listereq=$('#listereq').val(); 

   
  if ($('#nome').val() == '') {
    $('#nome').focus();
    inlineMsg('#nome',nomereq,fadetime);
    return false ;
  }   
  if ($('#cognome').val() == '') { 
    $('#cognome').focus();
    inlineMsg('#cognome',cognomereq,fadetime);
    return false ;
  }                     
  if ($('#email').val() == '') { 
    $('#email').focus();
    inlineMsg('#email',emailreq,fadetime);
    return false ;
  }             
    if(!$('#email').val().match(emailRegex)) {
      $('#email').focus();
      inlineMsg('#email',emailreq,fadetime);
      return false ;
    }                   
  if ($('#email').val() != $('#email2').val()) { 
    $('#email2').focus();
    inlineMsg('#email2',emailreq2,fadetime);
    return false ;
  } 
  /* selezione lista/e in caso di + scelte  */                 
  if($(".nlcheck").length > 0 && $(".nlcheck:checked").length < 1) { 
	    inlineMsg('#listecheck',listereq,fadetime);
	    return false;
	} 
                      
  if ($('#privacy:checked').length < 1) { 
    $('#privacy').focus();
    inlineMsg('#privacy',privacyreq,fadetime);
    return false ;
  }      
               
  return true;
}

function isNumeric(strString){
   var strValidChars = "0123456789.-";
   var strChar;
   var blnResult = true;
   if (strString.length == 0) return false;
   //  test strString consists of valid characters listed above
   for (i = 0; i < strString.length && blnResult == true; i++){
      strChar = strString.charAt(i);
      if (strValidChars.indexOf(strChar) == -1)
         {
         blnResult = false;
         }
      }
   return blnResult;
   }
/*
function alphanumeric(alphane){
	var numaric = alphane;
	for(var j=0; j<numaric.length; j++)		{
		  var alphaa = numaric.charAt(j);
		  var hh = alphaa.charCodeAt(0);
		  if((hh > 47 && hh<58) || (hh > 64 && hh<91) || (hh > 96 && hh<123)){
		  }else{
			 return false;
		  }
 		}
 return true;
}

*/
function calbox(month,year){
  var pars = 'month='+month+'&year='+year;
  //$('#calbox').html("attendere...");
  $.ajax({
     type: "GET",
     url: '/_ezfiles/calbox.php',
     data: pars,
     dataType: "html",
     success: function(msg){
      $('#calbox').html(msg);
     }
  });
}



function validaBlog(){
  var fadetime='3000';
  var emailRegex = /^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$/;

  var cnomereq=$('#cnomereq').val();
  var cemailreq=$('#cemailreq').val();
  var ccommentoreq=$('#ccommentoreq').val();

  if ($('#cnome').val() == "") {
    $('#cnome').focus();
    inlineMsg('#cnome',cnomereq,fadetime);
    return false ;
  }
  if($('#cemail').val() == ""){
    $('#cemail').focus();
    inlineMsg('#cemail',cemailreq,fadetime);
    return false ;
  }
    if(!$('#cemail').val().match(emailRegex)) {
      $('#cemail').focus();
    inlineMsg('#cemail',cemailreq,fadetime);
      return false ;
    }
  if ($('#ccommento').val() == "") {
    $('#ccommento').focus();
    inlineMsg('#ccommento',ccommentoreq,fadetime);
    return false ;
  }
  if (typeof($('#ccaptchareq').val()) != 'undefined'){var ccaptchareq=$('#ccaptchareq').val();}else{var ccaptchareq='no';}
  if ($('#captcha').val() == "" && ccaptchareq !='no') {
    $('#captcha').focus();
    inlineMsg('#captcha',ccaptchareq,fadetime);
    return false ;
  }
  return true;
}
/* autoregolazione dell'altezza di un gruppo di div in base al div pił alto (vedi galleria: albums)*/
function equalHeight(group) {
   tallest = 0;
   group.each(function() {
      thisHeight = $(this).height();
      if(thisHeight > tallest) {
         tallest = thisHeight;
      }
   });
   group.height(tallest);
}

document.write('<script type="text/javascript" src="/jscripts/f2.js"></script>');
