jQuery(document).ready(function() {
		jQuery('.lightbox').lightBox();
		
		jQuery('#prop_foto').click(function(){
			jQuery('#div_video').hide();
			jQuery('#div_mapa').hide();
			jQuery('.links_prop > div > span > a').removeClass('sel');
			jQuery('#prop_foto').addClass('sel');
			jQuery('#div_foto').show();
			return false;
		});
		
		jQuery('#prop_video').click(function(){
			jQuery('#div_foto').hide();
			jQuery('#div_mapa').hide();
			jQuery('.links_prop > div > span > a').removeClass('sel');
			jQuery('#prop_video').addClass('sel');
			jQuery('#div_video').show();
			return false;
		});
		
		jQuery('#prop_mapa').click(function(){
			jQuery('#div_video').hide();
			jQuery('#div_foto').hide();
			jQuery('.links_prop > div > span > a').removeClass('sel');
			jQuery('#prop_mapa').addClass('sel');
			jQuery('#div_mapa').show();
			var center = map.getCenter(); 
			map.checkResize(); 
			map.setCenter(center); 
			return false;
		});
		
		var options = { 
		        target:        '#enc_gracias',   // target element(s) to be updated with server response 
		        //beforeSubmit:  showRequest,  // pre-submit callback 
		        success:       showResponse  // post-submit callback 
		 
		        // other available options: 
		        //url:       url         // override for form's 'action' attribute 
		        //type:      type        // 'get' or 'post', override for form's 'method' attribute 
		        //dataType:  null        // 'xml', 'script', or 'json' (expected server response type) 
		        //clearForm: true        // clear all form fields after successful submit 
		        //resetForm: true        // reset the form after successful submit 
		 
		        // $.ajax options can be used here too, for example: 
		        //timeout:   3000 
		    }
		
		
		jQuery('#votar').click(function(){
			$('#encuesta').ajaxSubmit(options);
			return false;
		});
		
		function showResponse(responseText, statusText)  {
			$('#enc_gracias').dialog('open'); 
		};
		
		$("#enc_resultados").dialog({
            bgiframe: true,
            modal: true,
            autoOpen: false,
            resizable: false,
            buttons: {
                Ok: function() {
                    $(this).dialog('close');
                }
            }
        });
		
		$("#enc_gracias").dialog({
            bgiframe: true,
            modal: true,
            autoOpen: false,
            resizable: false,
            buttons: {
                Ok: function() {
                    $(this).dialog('close');
                }
            }
        });
		
		$('#ver_resultados').click(function() {
            $('#enc_resultados').dialog('open');
        })
		
		
		
		
$(function() {
    
    var nombres1 = $("#contacto_nombre");
    var email1= $("#contacto_email");
    var mensaje1 = $("#contacto_Mensaje");
    var allFields = $([]).add(nombres1).add(email1).add(mensaje1);
    var tips = $("#validateTips");

    function updateTips(t) {
        tips.text(t).effect("highlight",{},1500);
    }

    function checkLength(o,n,min,max) {

        if ( o.val().length > max || o.val().length < min ) {
            o.addClass('ui-state-error');
            updateTips("Length of " + n + " must be between "+min+" and "+max+".");
            return false;
        } else {
            return true;
        }

    }

    function checkRegexp(o,regexp,n) {

        if ( !( regexp.test( o.val() ) ) ) {
            o.addClass('ui-state-error');
            updateTips(n);
            return false;
        } else {
            return true;
        }

    }
    
    $("#gracias").dialog({
        bgiframe: true,
        modal: true,
        autoOpen: false,
        resizable: false,
        buttons: {
            Ok: function() {
                $(this).dialog('close');
            }
        }
    });

    $("#dialog").dialog({
        bgiframe: true,
        autoOpen: false,
        resizable: false,
        height: 350,
        width: 537,
        modal: true,
        buttons: {
            'Enviar': function() {
                allFields.removeClass('ui-state-error');

                var _bValid1 = checkLength(nombres1,"conacto_nombre",3,100) && checkLength(email1,"conacto_email",6,255) && checkLength(mensaje1,"conacto_Mensaje",1,999) && checkRegexp(email1,/^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?$/i,"eg. ui@jquery.com");
                if (_bValid1) {
                    $('#form_enviar_amigo').ajaxSubmit(); 
                    $(this).dialog('close');
        $("#gracias").dialog('open');

                }
            },
            Cancelar: function() {
                $(this).dialog('close');
            }
        },
        close: function() {
            allFields.val('').removeClass('ui-state-error');
        }
    });
    
    
    
    $('.EnviarLink').click(function() {
        __codigo__ = $(this).attr('id');
        $('#contacto_codigo').val(__codigo__);
        $('#dialog').dialog('open');
    })
    .hover(
        function(){ 
            $(this).addClass("ui-state-hover"); 
        },
        function(){ 
            $(this).removeClass("ui-state-hover"); 
        }
    ).mousedown(function(){
        $(this).addClass("ui-state-active"); 
    })
    .mouseup(function(){
            $(this).removeClass("ui-state-active");
    });

});

//++++++++++++++++++++++++++++++++++++++++

$(function() {
    
    var nombres = $("#consulta_nombre");
        email= $("#consulta_email");
        mensaje = $("#consulta_Mensaje");
        telefono = $("#consulta_telefono");
        allFields = $([]).add(nombres).add(email).add(mensaje).add(telefono);
        tips = $("#validateTips");

    function updateTips(t) {
        tips.text(t).effect("highlight",{},1500);
    }

    function checkLength(o,n,min,max) {

        if ( o.val().length > max || o.val().length < min ) {
            o.addClass('ui-state-error');
            updateTips("Length of " + n + " must be between "+min+" and "+max+".");
            return false;
        } else {
            return true;
        }

    }

    function checkRegexp(o,regexp,n) {

        if ( !( regexp.test( o.val() ) ) ) {
            o.addClass('ui-state-error');
            updateTips(n);
            return false;
        } else {
            return true;
        }

    }
    
    $("#gracias_consulta").dialog({
        bgiframe: true,
        modal: true,
        autoOpen: false,
        resizable: false,
        buttons: {
            Ok: function() {
                $(this).dialog('close');
            }
        }
    });

    $("#dialog_consulta").dialog({
        bgiframe: true,
        autoOpen: false,
        resizable: false,
        height: 350,
        width: 537,
        modal: true,
        buttons: {
            'Enviar_Consulta': function() {
                var bValid = true;
                allFields.removeClass('ui-state-error');

                bValid = bValid && checkLength(nombres,"consulta_nombre",3,100);
                bValid = bValid && checkLength(email,"consulta_email",6,255);
                bValid = bValid && checkLength(mensaje,"consulta_Mensaje",6,999);
                bValid = bValid && checkLength(telefono,"consulta_telefono",6,255);
                

                bValid = bValid && checkRegexp(email,/^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?$/i,"eg. ui@jquery.com");
                
                if (bValid) {
                    $('#form_enviar_consulta').ajaxSubmit(); 
                    $(this).dialog('close');
        $("#gracias_consulta").dialog('open');

                }
            },
            Cancelar: function() {
                $(this).dialog('close');
            }
        },
        close: function() {
            allFields.val('').removeClass('ui-state-error');
        }
    });
    
    
    
    $('.EnviarConsulta').click(function() {
        __codigo__ = $(this).attr('id');
        $('#contacto_codigo').val(__codigo__);
        $('#dialog_consulta').dialog('open');
    })
    .hover(
        function(){ 
            $(this).addClass("ui-state-hover"); 
        },
        function(){ 
            $(this).removeClass("ui-state-hover"); 
        }
    ).mousedown(function(){
        $(this).addClass("ui-state-active"); 
    })
    .mouseup(function(){
            $(this).removeClass("ui-state-active");
    });

});
		
		
		
});


