$(document).ready(function(){
	$("#help_popup, #help_link").bind("mouseenter", function(){
		$("#help_popup").css({visibility:"visible"});
	}).bind("mouseleave", function(){
		$("#help_popup").css({visibility:"hidden"});
	});	
	
	$("a").each(function(){
		if($(this).attr("rel")=="external")	$(this).attr("target", "_blank"); 
	});
  
  
  $('.btnop').click(function() {
    /*var pre = $('#prefisso');
    
    if(!pre.val() || pre.val() == '0'){
      alert('Attenzione! Devi indicare il prefisso del tuo numero di cellulare.');
      pre.focus();
      err = 1;
      return false;
    }*/
        
    var cell = $('#cellulare');
    if(!cell.val()){
      alert('Attenzione! Devi indicare il numero del tuo cellulare.');
      cell.focus();
      return false;
    }
    else{
      pt = /^\d+$/;
      if(!pt.test(cell.val())){
        alert('Attenzione! Il numero di cellulare può contenere solo caratteri numerici.')
        cell.focus();
        return false;
      }
      else if(cell.val().length < 9 || cell.val().length > 11){
        alert('Attenzione! Il numero di cellulare non è valido.')
        cell.focus();
        return false;
      }
    }
    
    var captcha = $('#frmcaptcha');
    if(!captcha.val()){
      alert("Attenzione! Devi indicare il codice di sicurezza presente nell'immagine.");
      captcha.focus();
      return false;
    }  
        

    var dest = $(this).attr('id');
    var page = '';
    switch(dest){
      case 'play_game': page = 'play'; break;
      case 'bottom_left_button': page = 'storico'; break;
      case 'bottom_right_button': page = 'premio'; break;
    }
        
    $('#frmpage').val(page);
    $('#frmauth').submit();
  });
  
  $('.conferma_a').click(function() {
      var id = $(this).attr('id');
      var c = id.split("_");
      $('#frmcaptcha').val(c[1]);
      $("#user_captcha").attr("src", "images/"+id+".jpg");
  });
  
});

function PopupCentrata(url_link, w, h) {
	var l = Math.floor((screen.width-w)/2);
	var t = Math.floor((screen.height-h)/2);
	window.open( url_link ,"","width=" + w + ",height=" + h + ",top=" + t + ",left=" + l +" status=no, menubar=no, toolbar=no, scrollbars=yes");
}

