﻿  function checkEmail(email) { 
    var pattern = /^([a-zA-Z0-9_\.\-\+])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
    var emailVal = $("#" + email).val();
    return pattern.test(emailVal);
  }
  function ajaxSubscribe() { 
      
	  $('#subscribeloading').fadeIn(500);
	  
      // First, disable the form from submitting
      $('form#subForm').submit(function() { return false; });
      
      // Grab form action
      var formAction = $("form#subForm").attr("action");
      
      // Hacking together id for email field
 
      var id = "kupz";
      var emailId = id + "-" + id;
      
      // Validate email address with regex
      if (!checkEmail(emailId)) {
        alert("Por favor ingrese un e-mail válido");
        return;
      }
      
      // Serialize form values to be submitted with POST
      var str = $("form#subForm").serialize();
      
      // Add form action to end of serialized data
      // CDATA is used to avoid validation errors
      var serialized = str + "&action=" + formAction;
      
      // Submit the form via ajax
      $.ajax({
        url: "/subscribeproxy.php",
        type: "POST",
        data: serialized,
        success: function(data){
          // Server-side validation
          if (data.search(/invalid/i) != -1) {
            alert('El e-mail es inválido, por favor corríjalo e intente de nuevo.');
          }
          else
          {
            $("#theForm").fadeOut(500, function(){$("#confirmation").fadeIn(500)} ); // If successfully submitted hides the form
            $("#confirmation").tabIndex = -1;
            $("#confirmation").focus(); // For screen reader accessibility
            // Fire off Google Analytics fake pageview
            var pageTracker = _gat._getTracker("UA-18274366-2");
            pageTracker._trackPageview("/newsletter_signup");
          }
        }
      });
	  
	  $('#subscribeloading').fadeOut(500);
    };
	function entsub(event) {
			  if (event && event.which == 13)
				ajaxSubscribe();
			  else
				return true;}
				
				
/*MISC*/


jQuery.extend(DateInput.DEFAULT_OPTS, {
  month_names: ["Enero", "Febrero", "Marzo", "Abril", "Mayo", "Junio", "Julio", "Agosto", "Septiembre", "Octubre", "Noviembre", "Diciembre"],
  short_month_names: ["Ene", "Feb", "Mar", "Abr", "May", "Jun", "Jul", "Ago", "Sep", "Oct", "Nov", "Dic"],
  short_day_names: ["Dom", "Lun", "Mar", "Mié", "Jue", "Vie", "Sab"]
});
$.extend(DateInput.DEFAULT_OPTS, {
  stringToDate: function(string) {
    var matches;
    if (matches = string.match(/^(\d{4,4})-(\d{2,2})-(\d{2,2})$/)) {
      return new Date(matches[1], matches[2] - 1, matches[3]);
    } else {
      return null;
    };
  },
  
  dateToString: function(date) {
    var month = (date.getMonth() + 1).toString();
    var dom = date.getDate().toString();
    if (month.length == 1) month = "0" + month;
    if (dom.length == 1) dom = "0" + dom;
    return date.getFullYear() + "-" + month + "-" + dom;
  }
});
	

	$(function(){ 
	// find all the input elements with title attributes
		$('input[title!=""]').hint();
	//remove unsuitable titles
		$('.nice-menu a').removeAttr("title");
	//make unclickable links unclickable 
		$('#menu-285 > a').removeAttr("href");
		$('#menu-315 > a').removeAttr("href");
		$('#menu-320 > a').removeAttr("href");
		$('#menu-321 > a').removeAttr("href");
		//english
		$('#menu-974 > a').removeAttr("href");
		$('#menu-975 > a').removeAttr("href");
		$('#menu-976 > a').removeAttr("href");
	
	//date input
		$("#edit-created-min").date_input();
		$("#edit-created-max").date_input();

	});

$(document).ready(function(){
	/*theme press room filter*/
		$("#edit-submit-pressroom").val('Buscar');
		$("#edit-term-node-tid-depth option:first").html('Todas');
});
	
	
/*CALENDAR*/

