
$(document).ready(function(){

	// PNG Fix
	$("#header").pngFix();
	$("#menu_logo").pngFix();
	$("#menu_opciones").pngFix();
	
	// Solicita informacion
	$("#menu_dudas a").bind("click", toggleInfo);
	$("#menu_form").bind("submit", validateMenuForm);
	
	// Contacto
	$("#contact_form").bind("submit", validateContactoForm);
	
	// Seguros
	$("#seguros_form").bind("submit", validateSegurosForm);
	
	// Área de Clientes
	$("#menu_area a").bind("click", toggleArea);
	$("#menu_clientes").bind("submit", validateArea);
	
	
	// Volver atras
	$("a.returnback").bind("click", returnBack);
	
	
});

function returnBack(event){
	history.back();
	return false;
}

// SIDEBAR
function toggleInfo(event){
	$("#menu_dudas").slideUp("slow", function(){ $("#menu_form").slideDown() } );
	return false;
}

function toggleArea(event){
	$("#menu_area").slideUp("slow", function(){ $("#menu_clientes").slideDown() } );
	return false;
}

// AREA DE CLIENTES
function validateArea(event){
	var login = $("#menu_clientes_login").val();
	var pass = $("#menu_clientes_password").val();
	
	if (login=="" || pass==""){
		alert($("#menu_clientes_aviso1").val());	
	}else{
		var param = "login=" + login + "&pass=" + pass;
		$.ajax({
			async:true,
			type: "post",
			dataType: "xml",
			contentType: "application/x-www-form-urlencoded",
			url: $("#menu_clientes_server").val() + "/seguridad-sc_validar_area.php",
			data:param,
			success:validateAreaSc,
			timeout:10000,
			error:null
		});	
	}
	
	return false;
}
function validateAreaSc(t){
	var error = $("error", t).text();
	if (error == "ko"){
		alert($("#menu_clientes_aviso2").val());	
	}else{
		document.getElementById("menu_clientes").submit();
	}
	
}

// FORM DE MENU
function validateMenuForm(event){
	var nombre = $("#menu_form_nombre").val();
	var apellidos = $("#menu_form_apellidos").val();
	var telefono = $("#menu_form_telefono").val();
	var email = $("#menu_form_email").val();
	
	var patron=/^[^@ ]+@[^@ ]+.[^@ .]+$/;
	var t1=patron.test(email);
	
	if (nombre==""){
		alert($("#menu_form_aviso1").val());
	}else{
		
		if (t1 == false){
			alert($("#menu_form_aviso2").val());
		}else{
			var param = "nombre=" + nombre + "&apellidos=" + apellidos + "&telefono=" + telefono + "&email=" + email + "&comentarios=";
			$.ajax({
				async:true,
				type: "post",
				dataType: "xml",
				contentType: "application/x-www-form-urlencoded",
				url: $("#menu_form_server").val() + "/seguridad-sc_mail_contacto.php",
				data:param,
				success:validateMenuFormSc,
				timeout:10000,
				error:null
			});	
		}
	}
	
	return false;
}
function validateMenuFormSc(t){
	var error = $("error", t).text();
	if (error == "ok"){
		alert($("#menu_form_aviso3").val());	
		document.getElementById("menu_form").reset();
	}
	
}

// CONTACTO
function validateContactoForm(event){
	var nombre = $("#contacto_form_nombre").val();
	var apellidos = $("#contacto_form_apellidos").val();
	var telefono = $("#contacto_form_telefono").val();
	var email = $("#contacto_form_email").val();
	var comentarios = $("#contacto_form_mensaje").val();
	
	var patron=/^[^@ ]+@[^@ ]+.[^@ .]+$/;
	var t1=patron.test(email);
	
	if (nombre==""){
		alert($("#contacto_form_aviso1").val());
	}else{
		
		if (t1 == false){
			alert($("#contacto_form_aviso2").val());
		}else{
			var param = "nombre=" + nombre + "&apellidos=" + apellidos + "&telefono=" + telefono + "&email=" + email + "&comentarios=" + comentarios;
			$.ajax({
				async:true,
				type: "post",
				dataType: "xml",
				contentType: "application/x-www-form-urlencoded",
				url: $("#contacto_form_server").val() + "/seguridad-sc_mail_contacto.php",
				data:param,
				success:validateContactoFormSc,
				timeout:10000,
				error:null
			});	
		}
	}
	
	return false;
}
function validateContactoFormSc(t){
	var error = $("error", t).text();
	if (error == "ok"){
		alert($("#contacto_form_aviso3").val());	
		document.getElementById("contacto_form").reset();
	}
	
}

// SEGUROS
function validateSegurosForm(event){
	var nombre = $("#seguros_form_nombre").val();
	var apellidos = $("#seguros_form_apellidos").val();
	var direccion = $("#seguros_form_direccion").val();
	var codigo = $("#seguros_form_codigo").val();
	var poblacion = $("#seguros_form_poblacion").val();
	var dni = $("#seguros_form_dni").val();
	var email = $("#seguros_form_email").val();
	var telefono = $("#seguros_form_telefono").val();
	var fecha = $("#seguros_form_fecha").val();
	var tipo = $("#seguros_form_tipo").val();
	var observaciones = $("#seguros_form_observaciones").val();
	
	var patron=/^[^@ ]+@[^@ ]+.[^@ .]+$/;
	var t1=patron.test(email);
	
	if (nombre==""){
		alert($("#seguros_form_aviso1").val());
	}else{
		
		if (t1 == false){
			alert($("#seguros_form_aviso2").val());
		}else{
			var param = "nombre=" + nombre + "&apellidos=" + apellidos + "&telefono=" + telefono + "&email=" + email + "&direccion=" + direccion + "&codigo=" + codigo + "&poblacion=" + poblacion + "&dni=" + dni + "&fecha=" + fecha + "&tipo=" + tipo + "&observaciones=" + observaciones;
			$.ajax({
				async:true,
				type: "post",
				dataType: "xml",
				contentType: "application/x-www-form-urlencoded",
				url: $("#seguros_form_server").val() + "/seguridad-sc_mail_seguros.php",
				data:param,
				success:validateSegurosFormSc,
				timeout:10000,
				error:null
			});	
		}
	}
	
	return false;
}
function validateSegurosFormSc(t){
	var error = $("error", t).text();
	if (error == "ok"){
		alert($("#seguros_form_aviso3").val());	
		document.getElementById("seguros_form").reset();
	}
	
}


// CAJAS FUERTES
function showCaja(obj){
	var so = new SWFObject(obj,"cajasfuertes_clip","100%","100%","7","#FFFFFF");
	so.addParam("play", "true");
	so.addParam("loop", "true");
	so.write("cajasfuertes_box");
	return false;
}