$(function(){
    $('span.error').hide();
    $('.text-input').css({
        backgroundColor: "#FFFFFF"
    });
    $('.text-input').focus(function(){
        $(this).css({
            backgroundColor: "#FFDDAA"
        });
    });
    $('.text-input').blur(function(){
        $(this).css({
            backgroundColor: "#FFFFFF"
        });
    });
    
    $("#enviar_correo_suscripcion").click(function(){
        var email = $("input#mail_suscripcion").val();
		var caja = $('#suscripcion_usuario');
        $.ajax({
			url: 'general.php',
            type: "GET",
            data: "registrar_suscriptor&email="+email,
           	success: function(datos){
				
            	if (datos == '1') {
					caja.html('<span style=\"margin:10px 0 0 10px; font-weight:bold; color:#fff; font-size:15px;\">Suscripción Exitósa.</span>');
				}
				else if (datos == '2') 
						alert('Email ya existe');
			}
        });
		
		/*$.ajax({
            url: 'evento.php',
            type: "GET",
            data: "eliminar_evento&even_id="+even_id,
            success: function(datos){
                $("#fila-" + even_id).fadeOut(1000);
            }
        });*/
        return false;
    });
    
    /* ENVIO DE COMENTARIO */
    $(".enviar_comentario").click(function(){
        $('.error').hide();
        
        var name = $("input#nombre").val();
        if (name == "") {
            $("span#name_error").fadeIn("slow");
            $("input#nombre").focus();
            return false;
        }
        var email = $("input#email").val();
        if (email == "") {
            $("span#email_error").fadeIn("slow");
            $("input#email").focus();
            return false;
        }
        var comment = $("textarea#comment").val();
        if (comment == "") {
            $("span#comment_error").fadeIn("slow");
            $("textarea#comment").focus();
            return false;
        }
        
        
        var accion = $("input#accion").val();
        
        var dataString = '';
        
        if (accion == 'noticia.php') {
            var not_id = $("input#not_id").val();
            dataString = 'not_id=' + not_id + '&nombre=' + name + '&email=' + email + '&comment=' + comment;
        }
        else 
            if (accion == 'evento.php') {
                var even_id = $("input#even_id").val();
                dataString = 'even_id=' + even_id + '&nombre=' + name + '&email=' + email + '&comment=' + comment;
            }
            else 
                if (accion == 'chica.php') {
                    var chica_id = $("input#chica_id").val();
                    dataString = 'chica_id=' + chica_id + '&nombre=' + name + '&email=' + email + '&comment=' + comment;
                }
        //alert (dataString); return false;
        $.ajax({
            type: "POST",
            url: accion + "?registrar_comentario",
            data: dataString,
            success: function(obj){
                var obj = eval("(" + obj + ")");
                for (i = 0; i < obj.length; i++) {
                    msg = obj[i].c_cnt % 2 == 0 ? "<div class=\"detalle_comentario_par\">\n" : "<div class=\"detalle_comentario_impar\">\n";
                    msg += "<p class=\"info_comentario\"><span>" + obj[i].c_autor + "</span> " + obj[i].c_date + "</p>\n";
                    msg += "<p class=\"desc_comentario\">" + obj[i].c_content + "</p>\n";
                    msg += "<h1 class=\"num_comentario\">" + obj[i].c_cnt + "</h1>\n";
                    msg += "</div>";
                }
                $('#content_form').html("<div id='message'></div>");
                $('#message').html("<h2>Mensaje enviado correctamente.</h2>").append("<p>Este mensaje sera sujeto a aprobación.</p>").hide().fadeIn('slow');
                $('#comentarios_detalle').append(msg).fadeIn('slow');
            }
        });
        return false;
    });
});

/* ------------------------------------ */
$(document).ready(function(){
    
	
	$("div.evento_mes").click(function(){
        window.location = $(this).find("a").attr("href");
        return false;
    });
			
    $("#galeria_chicapc").click(function(){
        window.location = $(this).find("a").attr("href");
        return false;
    });
	
	$(".chicapc_der").click(function(){
        window.location = $(this).find("a").attr("href");
        return false;
    });
	
	$("#escribenos").click(function(){
        $("#form_contacto_principal").slideToggle("slow");
        $(this).toggleClass("active");
        return false;
    });
		
	$(".cerrarVentana").click(function(){
        $("#form_enviar_correo").slideToggle("slow");
        $(this).toggleClass("active");
        return false;
    });
	
    $(".mostrarFormulario").click(function(){
        $("#form_contacto").slideToggle("slow");
        $(this).toggleClass("active");
        return false;
    });
	
	$(".mostrar_cerrar_historia").click(function(){
        $("#historia").slideToggle("slow");
        $(this).toggleClass("active");
        return false;
    });
    
    /* AUMENTAR FONT */
    $('#aumentar').fontSizer({
        action: "up",
        elements: "#not_desc p",
        max: 20
    });
    
    $('#disminuir').fontSizer({
        action: 'down',
        elements: "#not_desc p"
    });
    /* FORMULARIO CONTACTO CHICAS */
	var nombre_contacto = $("#nombre_contacto");
	if (nombre_contacto.val() == "") {
        nombre_contacto.attr("value", "Ingresa tu nombre");
    }
    nombre_contacto.focus(function(){
        if (nombre_contacto.val() == "" || nombre_contacto.val() == "Ingresa tu nombre") 
            nombre_contacto.attr("value", "");
    });
    nombre_contacto.blur(function(){
        if (nombre_contacto.val() == "" || nombre_contacto.val() == "Ingresa tu nombre") {
            nombre_contacto.attr("value", "Ingresa tu nombre");
        }
    });
	/* --------------------------------------------- */
	var email_contacto = $("#email_contacto");
    if (email_contacto.val() == "") {
        email_contacto.attr("value", "Ingresa un email");
    }
    email_contacto.focus(function(){
        if (email_contacto.val() == "" || email_contacto.val() == "Ingresa un email") 
            email_contacto.attr("value", "");
    });
    email_contacto.blur(function(){
        if (email_contacto.val() == "" || email_contacto.val() == "Ingresa un email") {
            email_contacto.attr("value", "Ingresa un email");
        }
    });
	/* --------------------------------------------- */
	var mensaje_contacto = $("#mensaje_contacto");
    if (mensaje_contacto.val() == "") {
        mensaje_contacto.attr("value", "Ingresa un mensaje");
    }
    mensaje_contacto.focus(function(){
        if (mensaje_contacto.val() == "" || mensaje_contacto.val() == "Ingresa un mensaje") 
            mensaje_contacto.attr("value", "");
    });
    mensaje_contacto.blur(function(){
        if (mensaje_contacto.val() == "" || mensaje_contacto.val() == "Ingresa un mensaje") {
            mensaje_contacto.attr("value", "Ingresa un mensaje");
        }
    });
	
	
    /* FORMULARIO ENVIAR CORREO */
    var nombre = $("#tu_nombre");
    if (nombre.val() == "") {
        nombre.attr("value", "Ingresa tu nombre");
    }
    nombre.focus(function(){
        if (nombre.val() == "" || nombre.val() == "Ingresa tu nombre") 
            nombre.attr("value", "");
    });
    nombre.blur(function(){
        if (nombre.val() == "" || nombre.val() == "Ingresa tu nombre") {
            nombre.attr("value", "Ingresa tu nombre");
        }
    });
    
    /* ----------------------------------- */
    
    var nombre_amigo = $("#nombre_amigo");
    if (nombre_amigo.val() == "") {
        nombre_amigo.attr("value", "Ingresa nombre amigo");
    }
    nombre_amigo.focus(function(){
        if (nombre_amigo.val() == "" || nombre_amigo.val() == "Ingresa nombre amigo") 
            nombre_amigo.attr("value", "");
    });
    nombre_amigo.blur(function(){
        if (nombre_amigo.val() == "" || nombre_amigo.val() == "Ingresa nombre amigo") {
            nombre_amigo.attr("value", "Ingresa nombre amigo");
        }
    });
    
    /* ----------------------------------- */
    
    var email_amigo = $("#email_amigo");
    if (email_amigo.val() == ""){
        email_amigo.attr("value", "Ingresa email amigo");
    }
    email_amigo.focus(function(){
        if (email_amigo.val() == "" || email_amigo.val() == "Ingresa email amigo") 
            email_amigo.attr("value", "");
    });
    email_amigo.blur(function(){
        if (email_amigo.val() == "" || email_amigo.val() == "Ingresa email amigo") {
            email_amigo.attr("value", "Ingresa email amigo");
        }
    });
	
	
	
});

