var badBrowser = (/MSIE ((5\.5)|6)/.test(navigator.userAgent) && navigator.platform == "Win32");
var badBrowser7 = (/MSIE ((5\.5)|6|7)/.test(navigator.userAgent) && navigator.platform == "Win32");

$(function(){
	$("#box3 .version_animada").click(function(){location.href="http://www.pululart.es";});
	//$("#box3 .horario_verano").click(function(){location.href="http://www.pululart.info/horario-de-verano-2010/2010/07/";});
  	// BAJAR AREA CLIENTE
   	$("#open").click(function(){$("div#panel").slideDown("slow");});	
	$("#close").click(function(){$("div#panel").slideUp("slow");});
	$(".area_cliente a").click(function (){$(".area_cliente a").toggle();});
	/* HOVER FORMULARIO */
	$("label").inFieldLabels();
	/* HOVER Y CLICK MENÚ */
	$(".quickcontact").children().hover(function(){$(this).siblings().stop().fadeTo(500,0.3);}, function(){$(this).siblings().stop().fadeTo(500,1);});
	
	if (!badBrowser7) {
		// CAMBIO DE IMAGEN EN MENU SUBHEADER
		$(".menu_soluciones_internet img").hover(function(){$(".menu_soluciones_internet img").stop().animate({opacity:0},'slow');}, function(){$(".menu_soluciones_internet img").stop().animate({opacity:1},'slow');});
		$(".menu_creacion_digital img").hover(function(){$(".menu_creacion_digital img").stop().animate({opacity:0},'slow');}, function(){$(".menu_creacion_digital img").stop().animate({opacity:1},'slow');});
		$(".menu_contacto img").hover(function(){$(".menu_contacto img").stop().animate({opacity:0},'slow');}, function(){$(".menu_contacto img").stop().animate({opacity:1},'slow');});
	}
	if (!badBrowser){
		// INICIALIZAMOS PRETTYPHOTO
		$("a[rel^='prettyPhoto']").prettyPhoto({animationSpeed: 'normal', padding: 30, opacity: 0.50, showTitle: true, allowresize: true, counter_separator_label: '/', theme: 'dark_rounded', callback: function(){}});
	}else{
		// INICIALIZAMOS PRETTYPHOTO
		$("a[rel^='prettyPhoto']").prettyPhoto({animationSpeed: 'normal', padding: 20, opacity: 0.80, showTitle: true, allowresize: true, counter_separator_label: '/', theme: 'light_square', callback: function(){}});
	}

	$("#enviar_newsletter").click(function(){validar_newsletter(); return false;});
	$("#enviar_login").click(function(){return validar_login();});

	$(".dropdown dt a").click(function() {$(".dropdown dd ul").toggle();});
	$(document).bind('click', function(e) {
		var $clicked = $(e.target);
		if (! $clicked.parents().hasClass("dropdown"))
			$(".dropdown dd ul").hide();
	});
});

/* FUNCIÓN PARA REDIMENSIONAR EL FOOTER */
function resizeflash(){margen_error = 14; altura_footer = $("body").height() - 578 + margen_error; if (altura_footer < 264){altura_footer=264;} $("#footer2").css('height', ''+altura_footer+'px');}
/* ENVIO DE FORMULARIOS */
function reemplazar(texto){
	texto = texto.toLowerCase();
	texto = texto.replace(/[áÁ]/gi, 'a');
	texto = texto.replace(/[éÉ]/gi, 'e');
	texto = texto.replace(/[íÍ]/gi, 'i');
	texto = texto.replace(/[óÓ]/gi, 'o');
	texto = texto.replace(/[úÚ]/gi, 'u');
	texto = texto.replace(/[ñÑ]/gi, 'n');
	return texto;
}

function validar_envio(){
var mensaje = "";var fallo = 0;div_mensaje_quito = document.getElementById("mensaje_final_contacto");
var nombre=reemplazar(document.contacto_form.nombre.value);var empresa=reemplazar(document.contacto_form.empresa.value);var email=reemplazar(document.contacto_form.email.value);var telefono=reemplazar(document.contacto_form.telefono.value);var mensaje1=reemplazar(document.contacto_form.mensaje.value);
if (!badBrowser){padre = div_mensaje_quito.parentNode;padre.removeChild(div_mensaje_quito);div_mensaje = document.createElement("div");div_mensaje.setAttribute("id", "mensaje_final_contacto");div_mensaje.setAttribute("class", "mensaje_final");
if (document.contacto_form.nombre.value.length <= 2){mensaje = "Tiene que escribir su nombre.";fallo = 1;span_error = document.createElement("span");span_error.setAttribute("class", "error_form");mensaje_texto = document.createTextNode(mensaje);span_error.appendChild(mensaje_texto);br = document.createElement("br");div_mensaje.appendChild(span_error);div_mensaje.appendChild(br);document.contacto_form.nombre.focus();}
if (document.contacto_form.email.value.length <= 5){mensaje = "Tiene que escribir su email.";fallo = 1;span_error = document.createElement("span");span_error.setAttribute("class", "error_form");mensaje_texto = document.createTextNode(mensaje);span_error.appendChild(mensaje_texto);br = document.createElement("br");div_mensaje.appendChild(span_error);div_mensaje.appendChild(br);document.contacto_form.email.focus();
}else{
if (!(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(document.contacto_form.email.value))){mensaje = "El email introducido es inválido.";fallo = 1;span_error = document.createElement("span");span_error.setAttribute("class", "error_form");mensaje_texto = document.createTextNode(mensaje);span_error.appendChild(mensaje_texto);br = document.createElement("br");div_mensaje.appendChild(span_error);div_mensaje.appendChild(br);document.contacto_form.email.focus();}}
if (document.contacto_form.telefono.value.length <= 5){mensaje = "Tiene que escribir su teléfono.";fallo = 1;span_error = document.createElement("span");span_error.setAttribute("class", "error_form");mensaje_texto = document.createTextNode(mensaje);span_error.appendChild(mensaje_texto);div_mensaje.appendChild(span_error);br = document.createElement("br");div_mensaje.appendChild(br);document.contacto_form.telefono.focus();}
if (document.contacto_form.mensaje.value.length <= 5){mensaje = "Tiene que escribir su mensaje.";fallo = 1;span_error = document.createElement("span");span_error.setAttribute("class", "error_form");mensaje_texto = document.createTextNode(mensaje);span_error.appendChild(mensaje_texto);div_mensaje.appendChild(span_error);document.contacto_form.mensaje.focus();}
if (fallo == 0){
if (!document.contacto_form.cb_condicion_uso.checked){mensaje = "Debe aceptar las condiciones de uso.";span_error = document.createElement("span");span_error.setAttribute("class", "error_form");mensaje_texto = document.createTextNode(mensaje);span_error.appendChild(mensaje_texto);div_mensaje.appendChild(mensaje_texto);}else{var param = "nombre="+nombre+"&empresa="+empresa+"&email="+email+"&telefono="+telefono+"&mensaje="+mensaje1;cargando = document.createElement("span");cargando.setAttribute("class", "cargando");mensaje="Confirmando el envío del email...";mensaje_texto = document.createTextNode(mensaje);cargando.appendChild(mensaje_texto);div_mensaje.appendChild(cargando);br = document.createElement("br");div_mensaje.appendChild(br);br = document.createElement("br");div_mensaje.appendChild(br);$.ajax({type: "GET",url: "../comun/envio_email.php",contentType: "application/x-www-form-urlencoded",data: param,cache: false,success: getmessage = function(envio){mensaje = "* Tu mensaje ha sido enviado. Te contestaremos lo antes posible, muchas gracias.";mensaje_correcto = document.createElement("span");mensaje_correcto.setAttribute("class", "envio_correcto");mensaje_texto = document.createTextNode(mensaje);mensaje_correcto.appendChild(mensaje_texto);div_mensaje.appendChild(mensaje_correcto);}});}}padre.appendChild(div_mensaje);
}else{
if (document.contacto_form.nombre.value.length <= 2){mensaje += "<span class=\"error_form\">Tiene que escribir su nombre.</span><br />";fallo = 1; document.contacto_form.nombre.focus();}
if (document.contacto_form.email.value.length <= 5){mensaje += "<span class=\"error_form\">Tiene que escribir su email.</span><br />"; fallo = 1; document.contacto_form.email.focus();
}else{if (!(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(document.contacto_form.email.value))){mensaje = "<span class=\"error_form\">El email introducido es inválido.</span><br />"; fallo = 1; document.contacto_form.email.focus();}}
if (document.contacto_form.telefono.value.length <= 5){	mensaje += "<span class=\"error_form\">Tiene que escribir su teléfono.</span><br />"; fallo = 1; document.contacto_form.telefono.focus();}
if (document.contacto_form.mensaje.value.length <= 5){ mensaje += "<span class=\"error_form\">Tiene que escribir su mensaje.</span><br />"; fallo = 1; document.contacto_form.mensaje.focus();}
if (fallo == 0){var param = "nombre="+nombre+"&empresa="+empresa+"&email="+email+"&telefono="+telefono+"&mensaje="+mensaje1;mensaje="<span class=\"cargando\">Confirmando el envío del email...</span><br /><br />";div_mensaje_quito.innerHTML=mensaje;$.ajax({type: "GET",url: "../comun/envio_email.php",contentType: "application/x-www-form-urlencoded",data: param,cache: false,success: getmessage = function(envio){mensaje += "<span class=\"envio_correcto\">* Tu mensaje ha sido enviado. Te contestaremos lo antes posible, muchas gracias.</span>";}});}div_mensaje_quito.innerHTML=mensaje;}return false;}

function validar_newsletter(){
	var fallo = 0;
	var mensaje = "";
	if (document.newsletter_form.email_newsletter.value.length <= 5){
		document.newsletter_form.email_newsletter.focus();
		fallo = 1;
		$.prettyPhoto.open('../_img_comun/error_email.jpg','','');
	}else{
		if (!(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(document.newsletter_form.email_newsletter.value))){
			document.newsletter_form.email_newsletter.focus();
			fallo = 1;
			$.prettyPhoto.open('../_img_comun/error_email.jpg','','');
		}else{
			if (!document.newsletter_form.cb_condicion_uso1.checked){
				fallo = 1;
				$.prettyPhoto.open('../_img_comun/error_condiciones.jpg','','');
			}
		}
	}
	if (fallo == 0){
		document.location.href="http://pululart.es/mailing/user/subscribe.php?Email="+document.newsletter_form.email_newsletter.value;
	}
}
function validar_login(){if ((document.login_form.usuario.value.length < 2) || (document.login_form.pass.value.length < 2)){$.prettyPhoto.open('./_img_comun/error_usuario.jpg','',''); return false;}else{return true;}}
