function Abre(page) {
	OpenWin = this.open(page, "Ventana", "toolbar=no,menubar=no,location=no,status=yes,scrollbars=yes,resizable=yes,width=400px,height=300px");
}

function Activacapa(nombrecapa,accion,retardo) {
	if (!retardo || retardo=="") {
		retardo=10;
		}
		
	if ((document.getElementById(nombrecapa).style.display == "none" && accion!="mostrar" && accion!="ocultar") || (accion == "mostrar")) {
      		setTimeout(document.getElementById(nombrecapa).style.display = "",retardo);
	      	if (nombrecapa=='buscador') {
	      		document.getElementById(nombrecapa+'txt').innerHTML="Ocultar";
	      		}
	     } else if ((document.getElementById(nombrecapa).style.display !== "none" && accion!="mostrar" && accion!="ocultar") || (accion == "ocultar")) {
		       document.getElementById(nombrecapa).style.display = "none";
			       if (nombrecapa=='buscador') {
			       document.getElementById(nombrecapa+'txt').innerHTML="Mostrar";
			       }   
      	 }
}


function Enviar() {
	setTimeout(	document.formulario.submit(),2000);
}




function vaciacampo(control){
	if(!control.texto_predeterminado){
		control.texto_predeterminado=control.value;
	}
	
	if(control.value==control.texto_predeterminado){
		control.value='';
	}
}

/*
 * Restaurar el contenido de un control de formulario, pero sólo si no se ha modificado
 * Nota: el control debe tener parámetro value
 */


function campooriginal(control){
	if(control.texto_predeterminado){
	}
	
	if(control.texto_predeterminado && control.value==''){
		control.value=control.texto_predeterminado;
	}
}


function muestracapaninos(valor){
	if (valor=='0') {
	document.getElementById("capan1").style.display = "none";
	document.getElementById("capan2").style.display = "none";
	}
	if (valor=='1') {
	document.getElementById("capan1").style.display = "";
	document.getElementById("capan2").style.display = "none";
	}
	if (valor=='2') {
	document.getElementById("capan1").style.display = "";
	document.getElementById("capan2").style.display = "";
	}
}










// Cuando una imagen no se ha cargado, la oculta.
function ErrorCargarImagen(imagen) {
var fichero=imagen.src;
//imagen.src=fichero+"&fecha="+Date();
var aleat=Math.floor(Math.random()*50)
setTimeout(imagen.src=fichero+"&aleat="+aleat,1000);
// imagen.style.display = "none";
}


// MONTA EL OBJETO DE AJAX
var peticion = false;
var  testPasado = false;
  try {
   peticion = new XMLHttpRequest();
   } catch (trymicrosoft) {
   try {
   peticion = new ActiveXObject("Msxml2.XMLHTTP");
  } catch (othermicrosoft) {
 try {
  peticion = new ActiveXObject("Microsoft.XMLHTTP");
  } catch (failed) {
 peticion = false;
  }
     }
   }
   if (!peticion)
   alert("ERROR AL INICIALIZAR!");
   


// AJAX . Reemplazar el contenido de un DIV con una URL
   function cargarDIV (url, comboAnterior, element_id) {
       //Obtenemos el contenido del div
       //donde se cargaran los resultados
    var element =  document.getElementById(element_id);

    Activacapa(element_id,'mostrar',10);
    
       //Obtenemos el valor seleccionado del combo anterior
       if (comboAnterior) {
	      var valordepende = document.getElementById(comboAnterior)
	       var x = escape(valordepende.value)

	       //construimos la url definitiva
	       //pasando como parametro el valor seleccionado
	       // habría que mirara que si url lleva ya ? añada & en vez de ? para encadenar el dato valor=X del formulario
	       var fragment_url = url+'?valor='+x;
         }
      	else
      	{
      		var fragment_url = url
      	}

       element.innerHTML = '<img src="../imag_general/loading.gif" />';
       //abrimos la url
       peticion.open("GET", fragment_url);
       peticion.onreadystatechange = function() {
           if (peticion.readyState == 4 || peticion.readyState=="complete") {
			   //escribimos la respuesta
			   element.innerHTML = peticion.responseText;
           }
       }
      peticion.send(null);
   }



/* ENVIA FORMULARIO POR AJAX */
function enviarFormularioAJAX(url, formid,element_id){
             var Formulario = document.getElementById(formid);
             var longitudFormulario = Formulario.elements.length;
             var cadenaFormulario = ""
             var sepCampos
             sepCampos = ""
             for (var i=0; i <= Formulario.elements.length-1;i++) {
             cadenaFormulario += sepCampos+Formulario.elements[i].name+'='+encodeURI(Formulario.elements[i].value);
             sepCampos="&";
   }

 	var fragment_url = url+'?'+cadenaFormulario;
 	 var element =  document.getElementById(element_id);
     element.innerHTML = '<p class=avisoAJAX><img src="../imag/loading.gif" /> Cargando datos...</p>';
       //abrimos la url
       peticion.open("GET", fragment_url);
       peticion.onreadystatechange = function() {
           if (peticion.readyState == 4 || peticion.readyState=="complete") {
   			//escribimos la respuesta
			element.innerHTML = peticion.responseText;
   			}
       }
     
      peticion.send(null);
}




/* Funciones de búsqueda en tiempo real */

var tempora = null;

function lanzabusquedareal() {
if (tempora) { window.clearTimeout(tempora); }
	tempora = window.setTimeout("busquedareal()",350);
}

function busquedareal(){
	cargarDIV('../AJAX/AJAXbuscador.asp', 'cadena', 'resultadosajax');
}



/* *********************** */

/* Funcion para agregar a favoritos */

function agregar(){
   if ((navigator.appName=="Microsoft Internet Explorer") && 
         (parseInt(navigator.appVersion)>=4)) {
      var url="http://www.tenisburgos.es/"; 
      var titulo="Tenis Burgos";
      window.external.AddFavorite(url,titulo);
   } else { 
      if(navigator.appName == "Netscape") 
         alert("Presione Crtl+D para agregar este sitio en sus Bookmarks"); 
   }
} 
/* *********************** */


/*
 * Easy Retweet Button
 * http://ejohn.org/blog/retweet/
 *   by John Resig (ejohn.org)
 *
 * Licensed under the MIT License:
 * http://www.opensource.org/licenses/mit-license.php
 */

(function(){

window.RetweetJS = {
	// Your Bit.ly Username
	bitly_user: "menosdiez",

	// Your Bit.ly API Key
	// Found here: http://bit.ly/account
	bitly_key: "R_c85869bf541d1754168aff0e7e621ed3",

	// The text to replace the links with
	link_text: (/windows/i.test( navigator.userAgent) ? "&#9658;" : "&#9851;") +
		"&nbsp;Retweet",

	// What # to show (Use "clicks" for # of clicks or "none" for nothing)
	count_type: "clicks",

	// Tweet Prefix text
	// "RT @jeresig " would result in: "RT @jeresig Link Title http://bit.ly/asdf"
	prefix: "",

	// Style information
	styling: "a.retweet { font: 12px Helvetica,Arial; color: #000; text-decoration: none; border: 0px; }" +
		"a.retweet span { color: #FFF; background: #94CC3D; margin-left: 2px; border: 1px solid #43A52A; -moz-border-radius: 3px; -webkit-border-radius: 3px; border-radius: 3px; padding: 3px; }" +
		"a.vert { display: block; text-align: center; font-size: 16px; float: left; margin: 0px; }" +
		"a.retweet strong.vert { display: block; margin-bottom: 4px; background: #F5F5F5; border: 1px solid #EEE; -moz-border-radius: 3px; -webkit-border-radius: 3px; border-radius: 3px; padding: 3px; }" +
		"a.retweet span.vert { display: block; font-size: 12px; margin-left: 0px; }"
};

//////////////// No Need to Configure Below Here ////////////////

var loadCount = 1;

// Asynchronously load the Bit.ly JavaScript API
// If it hasn't been loaded already
if ( typeof BitlyClient === "undefined" ) {
	var head = document.getElementsByTagName("head")[0] ||
		document.documentElement;
	var script = document.createElement("script");
	script.src = "http://bit.ly/javascript-api.js?version=latest&login=" +
		RetweetJS.bitly_user + "&apiKey=" + RetweetJS.bitly_key;
	script.charSet = "utf-8";
	head.appendChild( script );

	var check = setInterval(function(){
		if ( typeof BitlyCB !== "undefined" ) {
			clearInterval( check );
			head.removeChild( script );
			loaded();
		}
	}, 10);

	loadCount = 0;
}

if ( document.addEventListener ) {
	document.addEventListener("DOMContentLoaded", loaded, false);

} else if ( window.attachEvent ) {
	window.attachEvent("onload", loaded);
}

function loaded(){
	// Need to wait for doc ready and js ready
	if ( ++loadCount < 2 ) {
		return;
	}

	var elems = [], urlElem = {}, hashURL = {};

	BitlyCB.shortenResponse = function(data) {
		for ( var url in data.results ) {
			var hash = data.results[url].userHash;
			hashURL[hash] = url;

			var elems = urlElem[ url ];

			for ( var i = 0; i < elems.length; i++ ) {
				elems[i].href += hash;
			}

			if ( RetweetJS.count_type === "clicks" ) {
				BitlyClient.stats(hash, 'BitlyCB.statsResponse');
			}
		}
	};

	BitlyCB.statsResponse = function(data) {
		var clicks = data.results.clicks, hash = data.results.userHash;
		var url = hashURL[ hash ], elems = urlElem[ url ];

		if ( clicks > 0 ) {
			for ( var i = 0; i < elems.length; i++ ) {
				var strong = document.createElement("strong");
				strong.appendChild( document.createTextNode( clicks + " " ) );
				elems[i].insertBefore(strong, elems[i].firstChild);

				if ( /(^|\s)vert(\s|$)/.test( elems[i].className ) ) {
					elems[i].firstChild.className = elems[i].lastChild.className = "vert";
				}
			}
		}

		hashURL[ hash ] = urlElem[ url ] = null;
	};

	if ( document.getElementsByClassName ) {
		elems = document.getElementsByClassName("retweet");
	} else {
		var tmp = document.getElementsByTagName("a");
		for ( var i = 0; i < tmp.length; i++ ) {
			if ( /(^|\s)retweet(\s|$)/.test( tmp[i].className ) ) {
				elems.push( tmp[i] );
			}
		}
	}

	if ( elems.length && RetweetJS.styling ) {
		var style = document.createElement("style");
		style.type = "text/css";

		try {
			style.appendChild( document.createTextNode( RetweetJS.styling ) );
		} catch (e) {
			if ( style.styleSheet ) {
				style.styleSheet.cssText = RetweetJS.styling;
			}
		}

		document.body.appendChild( style );
	}

	for ( var i = 0; i < elems.length; i++ ) {
		var elem = elems[i];

		if ( /(^|\s)self(\s|$)/.test( elem.className ) ) {
			elem.href = window.location;
			elem.title = document.title;
		}

		var origText = elem.title || elem.textContent || elem.innerText,
			href = elem.href;

		elem.innerHTML = "<span>" + RetweetJS.link_text + "</span>";
		elem.title = "";
		elem.href = "http://twitter.com/home?status=" +
			encodeURIComponent(RetweetJS.prefix + origText + " http://bit.ly/");

		if ( urlElem[ href ] ) {
			urlElem[ href ].push( elem );
		} else {
			urlElem[ href ] = [ elem ];
			BitlyClient.shorten(href, 'BitlyCB.shortenResponse');
		}
	}

}

})();

