$(document).ready(function() {
	$("input:text:visible:first").focus();
});

function contactSend(){
	
	if($.trim($("#contactEmail").val())==""){
		showContactError("El nombre o e-mail no puede ser vacío");
		return;
	}

	if($.trim($("#contactComments").val())==""){
		showContactError("El comentario no puede ser vacío");
		return;
	}	
	
	blockUI('<p style="margin:40px;"><img src="/img/blueAjaxLoader.gif">&nbsp;&nbsp;Enviando mensaje...</p>');
	$.ajax({
		type: "POST",
		dataType: "json",
		url: "/ajax/contactUs.do",
		contentType: "application/x-www-form-urlencoded; charset=UTF-8",
		data: 'contactEmail='+$("#contactEmail").val()+'&contactComments='+$("#contactComments").val()+'&captcha='+$("#captcha").val(),
        success: function(data){
        	if(data["success"]){
        		showMessageSend();
        	}else{
        		showContactError(data["response"]["error"]);        		
        	}
        }		        
});
}

function blockUI(msg){
	  $.blockUI({
	  	message: msg,
	  	bindEvents:false,
	  	fadeIn:100,
	  	fadeOut:0
	  	});
	}

function unblockUI(){
	$.unblockUI();
}

function showContactError(errorMsg){
	blockUI('<p style="margin:40px;" class="errorDiv"><span style="float: left;" class="errorDivIcon"></span><strong>'+errorMsg+'</strong></p><p><h3 class="bluebutton" style="margin:20px auto;width:200px;" onclick="javascript:unblockUI();" >Aceptar</h3></p>');	
}

function showMessageSend(){
	blockUI('<p style="margin:40px;">El mensaje ha sido enviado al equipo de spacedelta.com correctamente :)</p><p><h3 class="bluebutton" style="margin:20px auto;width:200px;" onclick="location.href=\'/contactUs.do\'" >Aceptar</h3></p>');
}
