// JavaScript Document
$(document).ready(function(){
						   

			$(".input").blur(function(){
				valor=this.value;
				campo=this.id;
				$("div#mensaje"+campo).html('<img src="../images/ajax-loader.gif" height="16" width="16" />');
     			 this.timer = setTimeout(function () {
                 $.ajax({
                        url:'phpScripts/checker.php',
                        data: 'campo='+campo+'&name='+ valor,
                        dataType: 'json',
                        type: 'post',
                        complete: function (j) {
                            // put the 'msg' field from the $resp array from check_username (php code) in to the validation message
							resultado = JSON.parse( j.responseText );
							
							if(resultado.ok==true){
								$("div#mensaje"+campo).html('');
								$("div#mensaje"+campo).html('<img src="../images/accept.png" height="16" width="16" /> ');
							}else{
								$("div#mensaje"+campo).html('<img src="../images/delete.png" height="16" width="16" /> '+resultado.mensaje);
							}
							
                        }
                    })
                }, 200);
	

			});
			
			
			//envio
			$('input#sendbutton').click(function(){
				var nombre=$("input#Name").val();
				var mail=$("input#Email").val();
				var webactual=$("input#Website").val();
				var mensaje=$("textarea#message").val();
				if(nombre!='' && mail!= '' && mensaje!=''){
				//$("div#mensaje"+campo).html('<img src="../images/ajax-loader.gif" height="16" width="16" />');
     			  $.ajax({
                        url:'phpScripts/enviar.php',
                        data: 'nombre='+nombre+'&mail='+ mail+'&webactual='+ webactual+'&mensaje='+ mensaje,
                        dataType: 'json',
                        type: 'post',
                        complete: function (j) {
							   // parseo la respuesta en un objeto json
							 //Esta funcion sale de jquery-impromptu.3.1 y su css esta en warning.css
							$.prompt('El mail se envio con exito',{ show:'slideDown' });
							//alert("el mail se envio con exito");
							//resultado = JSON.parse( j.responseText );
							
							/*if(resultado.ok==true){
								alert(resultado.mensaje);
							//$("div#mensaje"+campo).html('');
                            //$("div#mensaje"+campo).html('<img src="../images/accept.png" height="16" width="16" /> ');
							}else{
								alert(resultado.mensaje);
								//$("div#mensaje"+campo).html('<img src="../images/delete.png" height="16" width="16" /> '+resultado.mensaje);
							}*/
							 //recargo la página
							//window.location.replace("index.html");
							
							//Limpio los campos
							$("input#Name").attr("value","");
							$("input#Email").attr("value","");
							$("input#Website").attr("value","");
							$("textarea#message").attr("value","");
							$("div#mensajeName").html('');
							$("div#mensajeEmail").html('');
							$("div#mensajeWebsite").html('');
							$("div#mensajeMensaje").html('');
                        }
                    })
                
				}else{
					$.prompt('Alguno de los campos obligatorios estan vacios',{ show:'slideDown' });
					//alert("Alguno de los campos obligatorios estan vacios");
				}
	
		});
	
});


                
                // fire an ajax request in 1/5 of a second
          
