// JavaScript Document

//  Developed by Roshan Bhattarai 
//  Visit http://roshanbh.com.np for this script and more.
//  This notice MUST stay intact for legal use

$(document).ready(function()
{
	$("#commentForm").submit(function()
	{
		//remove all the class add the messagebox classes and start fading
		$("#msgbox").removeClass().addClass('messagebox').text('Validando....').fadeIn(1000);
		//check the username exists or not from ajax
		$.post("scripts/ajax-email.php",{ 
			   name:$('#name').val(),
			   lastname:$('#lastname').val(),
			   email:$('#email').val(),
			   phone:$('#phone').val(),
			   comments:$('#comments').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('Enviando.....').addClass('messageboxok').fadeTo(900,1,
              function()
			  { 
			  	 
				 $(this).fadeOut();
				 $('#display-form').fadeOut(function() {
					
					$('#send-box').fadeIn();
				 
				 });
				 
			  });
			  
			});
			
		  }
		  
		  if(data=='error1') //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('Debe completar los campos obligatorios').addClass('messageboxerror').fadeTo(900,1);
			});	
		  }
		  
		  if(data=='error2') //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('El formato del email es incorrecto').addClass('messageboxerror').fadeTo(900,1);
			});	
		  }
				
        });
 		return false; //not to post the  form physically
	});
	//now call the ajax also focus move from 
	$("#password").blur(function()
	{
		$("#login_form").trigger('submit');
	});
});
