function CaricaPagina(NomePagina, NomeDiv){
  $('#'+NomeDiv).load(
    NomePagina, //pagina da caricare
	    {}, //un oggetto JavaScript vuoto = nessun dato da inviare
	    function () { //funzione di callback
	    //    alert("dati caricati!"); 
	    }
	);
}

function mostra_box (NomeDiv) {
  var box = $('#'+NomeDiv);
  //box.slideToggle("fast");
  box.toggle();
}

function CaricaEditor (NomePagina, NomeDiv) {
  //var box = $('#'+NomeDiv);
  //CaricaPagina(NomePagina, NomeDivCar);
  //box.slideToggle("fast");
  CKEDITOR.replace(NomeDiv);
}

function ControllaLogin ()
{
  //remove all the class add the messagebox classes and start fading
  $("#msgbox").removeClass().addClass('messagebox').text('Validating....').fadeIn(1000);
  //check the username exists or not from ajax
  $.post("lib_php/lib_login.php",{ username:$('#username').val(),
                                   password:$('#password').val(),
                                   rand:Math.random() } ,function(data)
      {
        if(data=='yes') //if correct login detail
        {
          $("#msgbox").fadeTo(200,0.1,function()  //start fading the messagebox
          { 
            //add message and change the class of the box and start fading
            $(this).html('Logging in.....').addClass('messageboxok').fadeTo(900,1,
                  function()
            {
             mostra_box ('Login');
             //redirect to secure page
             document.location='index.php';
            });
            
          });
        }
        else 
        {
          $("#msgbox").fadeTo(200,0.1,function() //start fading the messagebox
          { 
            //add message and change the class of the box and start fading
            $(this).html('Login errata ...').addClass('messageboxerror').fadeTo(900,1);
          });		
        }
      });
  return document.location='index.php'; //not to post the  form physically
}

