﻿$(window).load(function(){ 
		/*$(".image_info").each(function() { 
			var img = new Image();	
			var padre = $(this);	
			$(this).hide();    
			if($(this).css("backgroundImage")=='none') {   
				img.src = $(this).css("backgroundImage").replace(/\.(.+)$/i, "_on.$1"); 
				$(img).load(function () {
					padre.show();
				});
			}
		});*/
});

$(document).ready(function() {
	$('.box_show > .title_box').hover(function() {
   	$(this).find('.sdt_box').show().stop(true,true).animate({ left: '220px' }, 500);
  }, function() {
		$(this).find('.sdt_box').hide();
   	$(this).find('.sdt_box').stop().animate({ left: '0px' }, 500);
  });

	$("#faded").faded({
		speed: 500,
		crossfade: true,
		bigtarget: false,
		loading: false,
		loadingimg: "",
		autoplay: 12000,
		autorestart: 8000,
		random: false,
		autopagination:false
	});
});

$(document).ready(function(){
  $(".caja_fade").hover(function() {
  	$(this).css("display", "block");
  	$(this).stop().animate({opacity:0.4,backgroundColor:"#8fccde"},300);
	},function() {
  	$(this).stop().animate({opacity:0,backgroundColor:"#fff"},300);
  });
}); 

function onRelease(name) {
 $(name).slideUp('normal');
 if($(name).is(':hidden') == true) {
  $(name).slideDown('normal');
 } 
}

var acepto=0;
function aceptar() {
	if (acepto==0) acepto=1;
	else acepto=0;
}

function validar_dudas() {
  var regex=new RegExp("^[^@ ]+@([a-zA-Z0-9\-]+\.)+([a-zA-Z0-9\-]{2}|net|com|gov|mil|org|edu|int|biz|info|name|pro)$");
	if ($('#form_dudas #t_nombre').val()=="") {
		alert("Debe completar su Nombre");
		$('#form_dudas #t_nombre').focus();
		return false;
	}
	if ($('#form_dudas #t_email').val()=="" || $('#form_dudas #t_email').val()=="Email") {
		alert("Debe completar su Email");
		$('#form_dudas #t_email').focus();
		return false;
	}
	if (regex.test($('#form_dudas #t_email').val())==false) {
		alert("Debe ingresar un Email válido");
		$('#form_dudas #t_email').focus();
		return false;
	}
	if ($('#form_dudas #t_consulta').val()=="" || $('#form_dudas #t_consulta').val()=="Consulta") {
		alert("Debe completar su Consulta");
		$('#form_dudas #t_consulta').focus();
		return false;
	}
	if (acepto==0) {
		alert("Debe aceptar la Pólitica de Privacidad del Sitio");
		return false;
	}	
	return true;
}

function validar_contacto() {
  var regex=new RegExp("^[^@ ]+@([a-zA-Z0-9\-]+\.)+([a-zA-Z0-9\-]{2}|net|com|gov|mil|org|edu|int|biz|info|name|pro)$");
	if ($('#form_contacto #t_nombre').val()=="") {
		alert("Debe completar su Nombre");
		$('#form_contacto #t_nombre').focus();
		return false;
	}
	if ($('#form_contacto #t_email').val()=="") {
		alert("Debe completar su Email");
		$('#form_contacto #t_email').focus();
		return false;
	}
	if (regex.test($('#form_contacto #t_email').val())==false) {
		alert("Debe ingresar un Email válido");
		$('#form_contacto #t_email').focus();
		return false;
	}
	if ($('#form_contacto #t_mensaje').val()=="") {
		alert("Debe completar su Consulta");
		$('#form_contacto #t_mensaje').focus();
		return false;
	}
	if (acepto==0) {
		alert("Debe aceptar la Pólitica de Privacidad del Sitio");
		return false;
	}	
	return true;
}

$(document).ready(function() {
	//nombre
	$('#form_dudas #t_nombre').keydown(function() {
	  $(this).css("color","#1d4b6a");
	});
	$('#form_dudas #t_nombre').keyup(function() {
	});
	$('#form_dudas #t_nombre').focus(function() {
	  if($(this).val()=="") $(this).val("Nombre");
	  else if($(this).val()=="Nombre") $(this).val("");
	});
	$('#form_dudas #t_nombre').blur(function() {
	  if($(this).val()=="") {
 		  $(this).css("color","#c3c3c3");
	  	$(this).val("Nombre");
	  }	else if($(this).val()=="Nombre") $(this).val("");
	});
	// email
	$('#form_dudas #t_email').keydown(function() {
	  $(this).css("color","#1d4b6a");
	});
	$('#form_dudas #t_email').keyup(function() {
	});
	$('#form_dudas #t_email').focus(function() {
	  if($(this).val()=="") $(this).val("Email");
	  else if($(this).val()=="Email") $(this).val("");
	});
	$('#form_dudas #t_email').blur(function() {
	  if($(this).val()=="") {
 		  $(this).css("color","#c3c3c3");
	  	$(this).val("Email");
	  }	else if($(this).val()=="Email") $(this).val("");
	});
	// consulta
	$('#form_dudas #t_consulta').keydown(function() {
	  $(this).css("color","#1d4b6a");
	});
	$('#form_dudas #t_consulta').keyup(function() {
	});
	$('#form_dudas #t_consulta').focus(function() {
	  if($(this).val()=="") $(this).val("Consulta");
	  else if($(this).val()=="Consulta") $(this).val("");
	});
	$('#form_dudas #t_consulta').blur(function() {
	  if($(this).val()=="") {
 		  $(this).css("color","#c3c3c3");
	  	$(this).val("Consulta");
	  }	else if($(this).val()=="Consulta") $(this).val("");
	});
});

$(document).ready(function() {
	//funcion enviar email
	$('#form_contacto').submit(function() {
		var validar = validar_contacto();
		if(validar) {
			$.ajax({
				type: 'POST',
				url: $(this).attr('action'),
				data: $(this).serialize(),
				success: function(data) {
					$('#form_contacto').find("input:text").val("");
					$('#form_contacto').find("textarea").val("");
					$("#t_acepto").removeAttr("checked");
					$('#formulario').hide();
					$('#result').html(data);
					$('#mensaje').show();
				}
			});
		}
		return false;
	}); 
});
	
$(document).ready(function() {
	$('#form_dudas').submit(function() {
		var validar1 = validar_dudas();
		if(validar1) {
			$.ajax({
				type: 'POST',
				url: $(this).attr('action'),
				data: $(this).serialize(),
				success: function(data) {
					$('#form_dudas').find("input:text").val("");
					$('#form_dudas').find("textarea").val("");
					$("#t_acepto").removeAttr("checked");
					$('#formulario').hide();
					$('#result').html(data);
					$('#mensaje').show();
				}
			});
		}
		return false;
	}); 
	
	$('a[rel=external]').attr('target','_blank');
	
});

function mostrar_contacto() {
	$('#formulario').show();
	$('#mensaje').hide();
}
