

var checkboxHeight = "25";
var radioHeight = "25";
var selectWidth1 = "169";
var selectWidth2 = "270";
var selectWidth3 = "270";
var selectWidth4 = "55";

/* No need to change anything after this */



document.write('<style type="text/css">input.styled { display: none; } select.styled { position: relative; width: ' + selectWidth1 + 'px; opacity: 0; filter: alpha(opacity=0); z-index: 5; } .disabled { opacity: 0.5; filter: alpha(opacity=50); }</style>');
document.write('<style type="text/css">input.styled { display: none; } select.styled2 { position: relative; width: ' + selectWidth2 + 'px; opacity: 0; filter: alpha(opacity=0); z-index: 5; } .disabled { opacity: 0.5; filter: alpha(opacity=50); }</style>');
document.write('<style type="text/css">input.styled { display: none; } select.styled3 { position: relative; width: ' + selectWidth3 + 'px; opacity: 0; filter: alpha(opacity=0); z-index: 5; } .disabled { opacity: 0.5; filter: alpha(opacity=50); }</style>');
document.write('<style type="text/css">input.styled { display: none; } select.styled4 { position: relative; width: ' + selectWidth4 + 'px; opacity: 0; filter: alpha(opacity=0); z-index: 5; } .disabled { opacity: 0.5; filter: alpha(opacity=50); }</style>');

var Custom = {
	init: function() {
		var inputs = document.getElementsByTagName("input"), span = Array(), textnode, option, active;
		for(a = 0; a < inputs.length; a++) {
			if((inputs[a].type == "checkbox" || inputs[a].type == "radio") && inputs[a].className == "styled") {
				span[a] = document.createElement("span");
				span[a].className = inputs[a].type;

				if(inputs[a].checked == true) {
					if(inputs[a].type == "checkbox") {
						position = "0 -" + (checkboxHeight*2) + "px";
						span[a].style.backgroundPosition = position;
					} else {
						position = "0 -" + (radioHeight*2) + "px";
						span[a].style.backgroundPosition = position;
					}
				}
				inputs[a].parentNode.insertBefore(span[a], inputs[a]);
				inputs[a].onchange = Custom.clear;
				if(!inputs[a].getAttribute("disabled")) {
					span[a].onmousedown = Custom.pushed;
					span[a].onmouseup = Custom.check;
				} else {
					span[a].className = span[a].className += " disabled";
				}
			}
		}
		inputs = document.getElementsByTagName("select");
		for(a = 0; a < inputs.length; a++) {
		    if ((inputs[a].className == "styled") || (inputs[a].className == "styled2") || (inputs[a].className == "styled3") || (inputs[a].className == "styled4")) {
				option = inputs[a].getElementsByTagName("option");
				active = option[0].childNodes[0].nodeValue;
				textnode = document.createTextNode(active);
				for(b = 0; b < option.length; b++) {
					if(option[b].selected == true) {
						textnode = document.createTextNode(option[b].childNodes[0].nodeValue);
					}
				}
				span[a] = document.createElement("span");
				span[a].className = "select";
				span[a].id = "select" + inputs[a].name;
				span[a].appendChild(textnode);
				inputs[a].parentNode.insertBefore(span[a], inputs[a]);
				if(!inputs[a].getAttribute("disabled")) {
					inputs[a].onchange = Custom.choose;
				} else {
					inputs[a].previousSibling.className = inputs[a].previousSibling.className += " disabled";
				}
			}
		}
		document.onmouseup = Custom.clear;
	},
	pushed: function() {
		element = this.nextSibling;
		if(element.checked == true && element.type == "checkbox") {
			this.style.backgroundPosition = "0 -" + checkboxHeight*3 + "px";
		} else if(element.checked == true && element.type == "radio") {
			this.style.backgroundPosition = "0 -" + radioHeight*3 + "px";
		} else if(element.checked != true && element.type == "checkbox") {
			this.style.backgroundPosition = "0 -" + checkboxHeight + "px";
		} else {
			this.style.backgroundPosition = "0 -" + radioHeight + "px";
		}
	},
	check: function() {
		element = this.nextSibling;
		if(element.checked == true && element.type == "checkbox") {
			this.style.backgroundPosition = "0 0";
			element.checked = false;
		} else {
			if(element.type == "checkbox") {
				this.style.backgroundPosition = "0 -" + checkboxHeight*2 + "px";
			} else {
				this.style.backgroundPosition = "0 -" + radioHeight*2 + "px";
				group = this.nextSibling.name;
				inputs = document.getElementsByTagName("input");
				for(a = 0; a < inputs.length; a++) {
					if(inputs[a].name == group && inputs[a] != this.nextSibling) {
						inputs[a].previousSibling.style.backgroundPosition = "0 0";
					}
				}
			}
			element.checked = true;
		}
	},
	clear: function() {
		inputs = document.getElementsByTagName("input");
		for(var b = 0; b < inputs.length; b++) {
			if(inputs[b].type == "checkbox" && inputs[b].checked == true && inputs[b].className == "styled") {
				inputs[b].previousSibling.style.backgroundPosition = "0 -" + checkboxHeight*2 + "px";
			} else if(inputs[b].type == "checkbox" && inputs[b].className == "styled") {
				inputs[b].previousSibling.style.backgroundPosition = "0 0";
			} else if(inputs[b].type == "radio" && inputs[b].checked == true && inputs[b].className == "styled") {
				inputs[b].previousSibling.style.backgroundPosition = "0 -" + radioHeight*2 + "px";
			} else if(inputs[b].type == "radio" && inputs[b].className == "styled") {
				inputs[b].previousSibling.style.backgroundPosition = "0 0";
			}
		}
	},
	choose: function() {
		option = this.getElementsByTagName("option");
		for(d = 0; d < option.length; d++) {
			if(option[d].selected == true) {
				document.getElementById("select" + this.name).childNodes[0].nodeValue = option[d].childNodes[0].nodeValue;
			}
		}
	}
}
window.onload = Custom.init;


/***************************************************************************
					  SUB-MENU
***************************************************************************/

function submMenuDisplay(){
		$(".menu>ul>li").hover(function(){
			$(this).find('ul:first').css({visibility: "visible",display:"none"}).fadeIn(250);
		},function(){
			$(this).find('ul:first').fadeOut(250);
		});
}


/***************************************************************************
					  Definiciones funciones Lightbox
***************************************************************************/
//esta funcion llama la URL por Ajax cuando el lightbox ya ha sido 
//construido. Decidido así por portabilidad
function lightbox(laurl,multi,callback){
	var $lightCont = buildLightbox(multi);
	$.ajax({
		type: "POST",
		url: laurl,
		async: false,
		success: function(html){
			//eliminar imagen cargando
			$lightCont.empty();
			//agregar el nuevo contenido y animar
			$lightCont.append("<div id='lightnovisible'></div>");
			$('#lightnovisible').append(html);
			$('#lightnovisible').show(500,function(){
				if(callback){
					eval(callback);
				}
			});
		}
	});
}
function buildLightbox(multi){//agregar link opcional a multimedia
	//obtener alto y ancho actual
	var ancho = $('body').outerWidth();
	var alto = $('.interiorgeneral').outerHeight();
	//crear el Lightbox.
	//crear tabla contenedora dentro de lightcont
	var tabla = "<div id='lightcont'><table cellspacing='0' cellpadding='0'>";
	tabla += "<tr height='20'><td width='20' id='light_img_lt' ></td><td id='light_img_ct'></td><td width='20' id='light_img_rt'></td></tr>";
	tabla += "<tr><td id='light_img_lm'></td><td bgcolor='white'>";
	tabla += "<div id='navcont'><a href='javascript:dropLightbox();'><div id='bot_cerr_light'></div></a>";
	if(!multi || multi==0){	
		tabla += "</div>";
	}else{
		tabla += "<a href='"+multi+"'><div id='bot_mult_light'></div></a></div>";
	}
	tabla += "<div id='ajaxCont'><img src='imagenes/loading.gif'/></div></td><td id='light_img_rm'></td></tr>";
	tabla += "<tr height='20'><td id='light_img_lb'></td><td id='light_img_cb'></td><td id='light_img_rb'></td></tr></table></div>";
	//crear fondo obscuro
	var html = "<div id='lightbox'></div>";
	//agregar elementos al documento
	$(".contidogeneral").prepend(tabla);
	$(".contidogeneral").prepend(html);
	//animar su aparición
	$("#lightbox").css({width:ancho, height:alto, opacity:0.0}).animate({opacity: 0.7},500);
	$("#lightcont").css({width:ancho, height:alto, top:$(this).scrollTop()}).fadeIn(500);
	//retornar contenedor a escribir
	return $("#ajaxCont");
}
function dropLightbox(){
	$("#lightcont").fadeOut(500);
	$("#lightbox").animate({opacity: 0.0},500,function(){
		$("#lightbox").remove();
		$("#lightcont").remove();
	});
	//if(galintervalo){	
		//clearInterval(galintervalo);//en caso de que sea una galeria
		//galintervalo=0;
	//}
}
function buscar()
{
	var texto_busqueda= document.getElementById("caja_busqueda");
	var opcion=document.getElementById("combo_categorias");
	if (texto_busqueda==null)
	{
			alert("error");
	}
	else
	{
			var texto=texto_busqueda.value;
			
				if (opcion!=null)
				{
					var opcion_cat=opcion.value;
				}
				else
				{
					var opcion_cat="0";
				}
				
	
	//alert(text);
			if (texto=="")
			{
					alert("Debe ingresar un texto");
			}
			
			else
			{
				//alert(texto);
				var direccion;
				direccion="buscador.aspx?texto=" + texto+ "&opt=" + opcion_cat;
				//alert(direccion);
				lightbox(direccion);
			}
	}
	
	}
	
	
function leer_tecla(e)
{
		if (e.keyCode == 13)
		{
				buscar();
		}

}	

function cambiar_tarifas(tarifa,antiguo)
{
		var combo_tarifa;
		
		combo_tarifa=document.getElementById("combo_tarifas");
		alert(combo_tarifa.value);
		alert(antiguo);
		
		
		if (tarifa.value!=antiguo )
		{
			var direccion;
			direccion="tarifas.aspx?id=" + tarifa;
			document.location=direccion;
		}		

}
