var name = "#floatMenu";
var topBanner = null;
$(document).ready(function () {
	
	heightMenu = $("#menu").height();
	heightFoto = $(".imgUp").height();
	heightHead = $(".header").height();
	
	if(heightFoto >= 286){
		$("#menu").height(286); 
	}
	
	if (heightMenu > 286){
		$("#menu").height(heightMenu); 
	}

	$("#subMenu").click(function () {
      $("#subMenu  < .subBotonNormal").show("fast", function () {
        // use callee so don't have to name the function
        $(".subBotonNormal").next().show("fast", arguments.callee); 
      });
    });
	
	
	////+++++++++++++++++++++++++++++++++++++++++++++++++++++++++////
	////                 Validacion formulario                   ////   
	////+++++++++++++++++++++++++++++++++++++++++++++++++++++++++////
	
	
	$("#enviarForm").click(function () {
	
		  var empresa;
		  var nombre; 		
		  var telefono;	
		  var email; 			
		  var idprovincia; 	
		  var id_municipio; 
		  var comentarios; 	


		  empresa 		= $("#empresa").attr("value")
		  nombre 		= $("#nombre").attr("value")
		  telefono 		= $("#telefono").attr("value")
		  email 		= $("#email").attr("value")
		  idprovincia 	= $("#idprovincia").attr("value")
		  id_municipio = $("#id_municipio").attr("value")
		  comentarios 	= $("#comentarios").attr("value")
		  
		  
		  
		  
			$.ajax({
				  async:true,
				  type: "POST",
				  dataType: "html",
				  contentType: "application/x-www-form-urlencoded",
				  url:"codPrespuesto.php",
				  data:"empresa="+empresa+"&nombre="+nombre+"&telefono="+telefono+"&email="+email+"&idprovincia="+idprovincia+"&id_municipio="+id_municipio+"&comentarios="+comentarios,
   			  beforeSend:inicioEnvio,
				  success:llegadaDatos,
				  timeout:4000,
				  error:problemas
			}); 
			
			function inicioEnvio()
			{
					$("#mensajes").css("opacity",0)
					$("#mensajes").html('<div class="errores" style="width:285px;text-align:center"><img src="imagenes/loader.gof"></div>');
					$(this).fadeTo("slow", 1);
					pageTracker._trackPageview("/envio_exitoso.html" );
					
					
			}
	
			function llegadaDatos(datos)
			{
				if(datos == 'ok'){
					window.location.href = "presupuesto-ok.php"
					/*
					$("#mensajes").css("opacity",0)
					$("#mensajes").html(datos);
					$("#mensajes").fadeTo("slow", 1); 
			*/

				} else {
					$("#mensajes").html('');
				}
				
			}
			
			function problemas(datos)
			{
				if(datos){
					$("#mensajes").css("opacity",0)
					$("#mensajes").html('<div class="errores" style="background:#FFE6E7;border:1px solid #FF8083;width:285px;margin:0 20px 20px 20px;padding:10px;font:bold 11px Arial, Helvetica, sans-serif; color:#E10005">Error al enviar, intentelo nuevamente</div>');
					$("#mensajes").fadeTo("slow", 1);
				}
				
			}
			
			if(empresa != undefined && nombre != undefined && telefono != undefined && email != undefined && idprovincia != undefined && id_municipio != undefined && comentarios != undefined){
			
				$("#formPresupuesto input").attr("value", "")
				$("#formPresupuesto textarea").attr("value", "")
			}
			
			
			return false;
	});
	
	
	
	
	////+++++++++++++++++++++++++++++++++++++++++++++++++++++++++////
	////                    Banner presupuesto                   ////   
	////+++++++++++++++++++++++++++++++++++++++++++++++++++++++++////
	
	var heightBann = $(name).height();
	var minTop = heightHead + heightMenu ;
	
	topBanner = $("#floatMenu").css('top',minTop+"px")
	topBanner = $("#floatMenu").css('display','block')
	
	
	
	$(window).scroll(function () { 
		var topBanner = $("#floatMenu").css('top')
		var topBanner = topBanner.substring(0,topBanner.indexOf('px'))
		var topBanner = parseInt(topBanner);
		offset = $(document).scrollTop();
		if(offset > minTop)
		{
			offset =  offset

			$(name).animate({top:offset},{duration:300,queue:false});
		}
	});
	
	
	
	
	
	
});

