//<script> 
function datos(sUrl,destino,form){
    var content = document.getElementById(destino)
    var retorno = {
          success : function(o) {
                     content.innerHTML = o.responseText;
                     content.style.visibility = "visible";
                   },
       failure : function(o) {
                    content.innerHTML = o.responseText;
                     content.style.visibility = "visible";
                     content.innerHTML = 'Error en Respuesta Base de Datos';
                    }
        }
    if(form!=""){
       var formObject=document.getElementById(form);
       YAHOO.util.Connect.setForm(formObject);
    }
    var respuesta = YAHOO.util.Connect.asyncRequest('GET', sUrl, retorno);
    document.getElementById(destino).style.visibility="visible";
}

$(document).ready(function() {


	

	$("img.img-intro").animate({
	    width: "30%",
	    opacity:1,
	    marginLeft: "0.55in",
	    fontSize: "10px",
	    borderWidth: "0px"
	  }, 1500 );


//	$("img.logo-intro").fadeIn('slow');


	// Muestra y oculta los menús 
   $('ul li:has(ul)').hover( 
      function(e) 
      { 
         $(this).find('ul').css({display: "block"}); 
      }, 
      function(e) 
      { 
         $(this).find('ul').css({display: "none"}); 
      } 
   ); 
	
	
	$("a.gallery").fancybox({
		'transitionIn'	:	'elastic',
		'transitionOut'	:	'elastic',
		'speedIn'		:	200, 
		'speedOut'		:	100, 
		'overlayShow'	:	true
	});


	$("#selprod").change(function(){
		var prod=$(this).attr('value') 
		prod=prod.split('-');
		
	
		if(prod[0] != ''){
			//alert(prod[0]);
			$("input#sop-active").attr("value",prod[1]);
			if(prod[1] == "0" ) {
			  $("div.soporte").hide();
			} else {
			  $("div.soporte").show();
			} 
			switch(prod[0]){
				case "1":
				case "2":
				case "3":
				case "4":
				case "5":
				case "6":
				case "7":
				case "8":
				case "9":
				case "10":
				case "11":
				case "13":
					$("div#cotizacion div.subcolums div.col2 img").attr("src",'images/prodtipo/torre.jpg');
					$("div#cotizacion div.subcolums div.col2 img").css("width",'200px');
					$("div#cotizacion div.subcolums div.col2 img").css("height",'280px');
				break;
				case "12":
					/*hamaca*/
					$("div#cotizacion div.subcolums div.col2 img").attr("src",'images/prodtipo/hamaca.jpg');
					$("div#cotizacion div.subcolums div.col2 img").css("width",'300px');
					$("div#cotizacion div.subcolums div.col2 img").css("height",'280px');
				break;
				case "14":
					/*plataforma**/
					$("div#cotizacion div.subcolums div.col2 img").attr("src",'images/prodtipo/plataforma.jpg');
					$("div#cotizacion div.subcolums div.col2 img").css("width",'200px');
					$("div#cotizacion div.subcolums div.col2 img").css("height",'280px');
				break;
				case "15":
					/*ruedas*/
					$("div#cotizacion div.subcolums div.col2 img").attr("src",'images/prodtipo/torre.jpg');
					$("div#cotizacion div.subcolums div.col2 img").css("width",'200px');
					$("div#cotizacion div.subcolums div.col2 img").css("height",'280px');
				break;
				case "16":
					/*escalera interna*/
					$("div#cotizacion div.subcolums div.col2 img").attr("src",'images/prodtipo/escaleraInterna.jpg');
					$("div#cotizacion div.subcolums div.col2 img").css("width",'200px');
					$("div#cotizacion div.subcolums div.col2 img").css("height",'280px');
				break;
				case "17":
					/*refuerzo diagonal*/
					$("div#cotizacion div.subcolums div.col2 img").attr("src",'images/prodtipo/refuerzoDiagonal.jpg');
					$("div#cotizacion div.subcolums div.col2 img").css("width",'200px');
					$("div#cotizacion div.subcolums div.col2 img").css("height",'280px');
				break;
				case "18":
					/*tornillo base*/
					$("div#cotizacion div.subcolums div.col2 img").attr("src",'images/prodtipo/tornillo.jpg');
					$("div#cotizacion div.subcolums div.col2 img").css("width",'200px');
					$("div#cotizacion div.subcolums div.col2 img").css("height",'280px');
				break;
			}
		}  else {
		   $("div.soporte").show();
		   $("input#sop-active").attr("value","1");
		}
	});




	function validateForm(){
		var  res=true;
		if($("form#frmcotizacion select[name='estado']").attr("value") == ""){
			alert("Por favor selecciona el lugar");
			 res=false;
		} else {
			
			if($("form#frmcotizacion select[name='estructura']").attr("value") == ""){
				alert("Por favor selecciona el tipo de estructura");
				res=false
			} else {			
				if($("form#frmcotizacion input[name='soporte']").attr("value") == ""){
					alert("Por favor selecciona el tipo de soporte");
					res=false
				} else {				
					if($("form#frmcotizacion select[name='dias']").attr("value") == ""){
						alert("Por favor selecciona el numero de dias de renta");
						res=false
					} else {
						res=true
					}
				}
			}
		}
		return res;
	}


	$("input.btnCotizar").click( function(){
		
		
		if(validateForm()){	
			//alert("es valido");
   			var url="r_cotizacion.php";

			var formdata=$("form#frmcotizacion").serialize();
	
  			$.ajax({
	  			type: 'POST',
	  			url: url,
	  			data: formdata,
	  			success: function(data){
				//alert(data);
					//alert("funcionoooo!!" + data.producto);
					$("div.res_cotizacion span.producto").text(data.producto);
					$("div.res_cotizacion span.estado").text(data.estado);
					$("div.res_cotizacion span.dias").text(data.dias);
					if(data.accesorio_id!=0){
						$("div.res_cotizacion span.soporte").text("( " + data.soporte + " )");
					} else {
						$("div.res_cotizacion span.soporte").text('');
					}
					$("div.res_cotizacion span.totalprice").text(data.preciototal);
					//alert(data.preciototal);
					if(data.preciototal == "0" || data.id=="0"){
						$("div.res_cotizacion").hide();	
						$("div.no_info").show();						
					} else {
						$("div.no_info").hide();	
						$("div.res_cotizacion").show();
					}
				},
	 			error: function(){
					alert("was not posible to connect with the page");
				},
	  			dataType:"json"
			});
		}
	});
 }); 

//</script>
