function popUp(URL) {
day = new Date();
id = day.getTime();
eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=0,location=0,statusbar=1,menubar=0,resizable=0,width=790,height=440,left = 325,top = 235');");
}

isValidEmailAddress = function (emailAddress) {
	var pattern = new RegExp(/^(("[\w-\s]+")|([\w-]+(?:\.[\w-]+)*)|("[\w-\s]+")([\w-]+(?:\.[\w-]+)*))(@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][0-9]\.|1[0-9]{2}\.|[0-9]{1,2}\.))((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){2}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\]?$)/i);
	return pattern.test(emailAddress);
}

validateContactForm = function validate(formData, jqForm, options) {
		var ok = true;
		jQuery.each(formData, function() {

			  if(this.name == 'nombre' || this.name == 'apellido' || this.name == 'pais' || this.name == 'email' || this.name == 'ciudad'){
			      if(!this.value || this.value.charAt(0) == '*'){
			      	alert('Los campos marcados con * son obligatiorios');
			      	ok = false;
			      	return false;
			      }

			      if(this.name == 'email'){
				      if(!isValidEmailAddress(this.value)){
				      	alert('La dirección de email no es válida');
				      	ok = false;
   				      	return false;
				      }
			      }
			  }
		});

       return ok;
   }

ajaxRq = function(element, ishm){

	var link = element.attr('href');

	$("div.Content").html('Cargando...');

	$.ajax({
	  url: link,
	  cache: false,
	  dataType: "html",
	  success: function(html){

			if(ishm){
				$("div#secondary-menu ul li a").removeClass('selected');
			}
			element.addClass('selected');

		  	$("div.Content").html($("div.Content", html).html());

			if(link == 'galeria-fotos.html'){
				$.getScript("js/jquery.fancybox-1.2.6.pack.js", function(){
				  initPhotoGallery();
				});
			}

	  }
	});

}

$(document).ready(function() {

	$("ul#main-menu li:not(.intranet) li:not(.contact) a").click(function(event) {
	    event.preventDefault();
	    $("div#secondary-menu ul li a").removeClass('selected');
	    ajaxRq($(this), false);
  	});
  	$("div#secondary-menu ul li a").click(function(event) {
	    event.preventDefault();
	    ajaxRq($(this), true);
  	});
  	$("h1 a").click(function(event) {
	    event.preventDefault();
	    ajaxRq($(this), true);
  	});

});


initPhotoGallery = function(){
	$("a.zoom").fancybox({
		'overlayOpacity'	:	0.7,
		'overlayColor'		:	'#000'
	});

	$("a.zoom1").fancybox({
		'overlayOpacity'	:	0.7,
		'overlayColor'		:	'#000'
	});

	$("a.zoom2").fancybox({
		'overlayOpacity'	:	0.7,
		'overlayColor'		:	'#000'
	});
}