/* Author: Paolo Rau

*/
var Contact = {
    
    get_data: function(div){
	Contact.hide = true;
	Contact.div = '#'+div;
	$.get('http://gotobtl.com/wp-content/uploads/contacto-ajax.html', function(r){
	    $(Contact.div).html(r)
	    Contact.map = initialize();
	    
	    });
    },
    
    toggle: function(){
	
	if (Contact.hide){
	    Contact.hide = false;
	    $(Contact.div).slideDown('easein');
	    google.maps.event.trigger(Contact.map, 'resize');
	    Contact.map.setZoom( Contact.map.getZoom() );
	    
	}else{
	    Contact.hide = true;
	    $(Contact.div).slideUp('fast');    
	}  
	  
    },
    linkForm: function(){
	$('#contact').submit(function() {
	    return false;
	});
	
	$('#contact-msj').hide();  
	$("#enviar").click(function() {  
         // validate and process form here  
	    $('#contact-error').hide();  
	    var name = $("input#name").val();
	    var email = $("input#email").val();
	    var phone = $("input#phone").val();
	    var msj = $("textarea#message").val();
	       
	    if (name == "") {
	     //$("#contact-error").html('Debe introducir un nombre');
	     //$("#contact-error").show();
	     alert("Debe introducir un nombre.");
	     $("input#name").focus();  
	     return false;  
	     }
	     
	     if (email == "") {  
	     //$("#contact-error").html('Debe introducir un email');
	     //$("#contact-error").show();
	     alert("Debe introducir un email.");
	     $("input#email").focus();  
	     return false;  
	     }  
	    
	    var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;
	    
	    if (!filter.test(email)) {
	     //$("#contact-error").html('Debe introducir un email valido');
	     //$("#contact-error").show();  
	     alert('Debe introducir un email valido.')
	     $("input#email").focus();  
	     return false;  
	     }
	     
	     if (msj == "" || msj ==" ") {  
	     //$("#contact-error").html('Debe introducir un mensaje');
	     //$("#contact-error").show();
	     alert('Debe introducir un mensaje.');
	     $("input#message").focus();  
	     return false;  
	     }  
	    
	    var dataString = 'name='+ name + '&email=' + email + '&phone=' + phone + '&msj=' + msj
	    $.ajax({  
		type: "POST",  
		url: "/wp-content/themes/gotobtl/email.php",  
		data: dataString,  
		success: function(r) {  
		    if(r == "1"){
		    $('#contact-fieldset').remove();
		    $("#contact-msj").html('Muchas gracias, te contactaremos a la brevedad.');
		    $("#contact-msj").show();
		    }else{alert('Error, intente de nuevo mas tarde')}
		}
	    })
	    
	    return false
	})  
    }
}
























