// JavaScript Document

function incluir(tira)
{
    document.writeln(tira);
}

/*
 * Hace el submit de la forma form
 *
 */
function enviarforma(form) {
    form.submit();
}

function addFlash(ruta,width,height)
{
    document.writeln("<object classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0\"  width=\"" +  width + "\" height=\"" + height + "\">");
    document.writeln("<param name=\"movie\" value=\"" + ruta + "\" />");
    document.writeln("<param name=\"quality\" value=\"high\" />");
    document.writeln("<embed src=\"" + ruta + "\" quality=\"high\" pluginspage=\"http://www.macromedia.com/go/getflashplayer\" type=\"application/x-shockwave-flash\" width=\"" + width + "\" height=\"" + height + "\"></embed>");
    document.writeln("</object>");
}
/*
* addFlash : este agregar el objeto flash a la pagina
* ruta : ruta que tiene el .swf
* width : ancho del swf
* height : largo del swf
* name : nombre para identificar el objeto
*/
function addFlash(ruta,width,height,name)
{
    document.writeln("<object id=\""+name +"\" classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0\"  width=\"" + width + "\" height=\"" + height + "\">");
    document.writeln("<param name=\"movie\" value=\"" + ruta + "\" />");
    document.writeln("<param name=\"quality\" value=\"high\" />");
    document.writeln("<embed name=\""+name+"\" src=\"" + ruta + "\" quality=\"high\" pluginspage=\"http://www.macromedia.com/go/getflashplayer\" type=\"application/x-shockwave-flash\" width=\"" + width + "\" height=\"" + height + "\"></embed>");
    document.writeln("</object>");
}
/*
* addFlash : este agregar el objeto flash a la pagina
* ruta : ruta que tiene el .swf
* width : ancho del swf
* height : largo del swf
* name : nombre para identificar el objeto
* parametros : Parametros con su valor, que quieres pasarle al objeto flash.
* Ej. de parametros: parametro1=valor&parametro2=valor&parametro3=valor&.....
*/
function addFlash(ruta,width,height,name,parametros){
	document.writeln("<object name=\""+name+"\" id=\""+name+"\" classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0\" onclick=\"alert('prueba');\"  width=\""+width+"\" height=\""+height+"\">");
    document.writeln("<param name=\"movie\" value=\""+ruta+"?"+parametros+"\" />");
    document.writeln("<param name=\"FlashVars\" value=\""+parametros+"\"/>");
    document.writeln("<param name=\"quality\" value=\"high\" />");
    document.writeln("<embed FlashVars=\""+parametros+"\" name=\""+name+"\" swliveconnect=\"true\"  src=\""+ruta+"?"+parametros+"\" quality=\"high\" pluginspage=\"http://www.macromedia.com/go/getflashplayer\" type=\"application/x-shockwave-flash\" width=\""+width+"\" height=\""+height+"\">");
	document.writeln("</embed>");
    document.writeln("</object>");
}
/*
* aleatorio : Segun un rango dado te da un numero aleatorio entre el rango dado
* inferior : Numero inferior del rango
* superior : Numero superior del rango
*/

function aleatorio(inferior,superior){

    numPosibilidades = superior - inferior;
    aleat = Math.random() * numPosibilidades;
    return Math.round(parseInt(inferior) + aleat);
}

/*
* imagenAleatorio : A traves de un arreglo donde tiene todas las imagenes, retorna una de ellas aleatoriamente
* imagenes: arreglo con la ruta imagenes
* var imagenes = new Array("imagen1","imagen2","imagen3")
*/

function imagenAleatorio(imagenes){
    aleat = Math.random() * imagenes.length;
    aleat = Math.floor(aleat);
    return imagenes[aleat];
} 

/*
* imagenAleatorio : A traves de un arreglo donde tiene todas las imagenes, retorna una de ellas aleatoriamente
* imagenes: arreglo con la ruta imagenes
* var imagenes = new Array("imagen1","imagen2","imagen3")
* OJO: esta funcion usa la funcion "aleatorio"
*/

function imagenAleatorio1(imagenes){
    length = imagenes.length;
    aleat = aleatorio(0,length-1);
    return imagenes[aleat];
} 


/*
* MM_findObj : Ubica una imagen dentro de un Array en la posicion n
*/
function MM_findObj(n, d) { //v4.01
  var p,i,x;  
  if(!d) 
  	d=document; 
  if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);
  }
  if(!(x=d[n])&&d.all) 
  	x=d.all[n]; 
  for (i=0;!x&&i<d.forms.length;i++) 
	x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) 
	x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) 
	x=d.getElementById(n); 
  return x;
}

/*
* MM_preloadImages : Permite precargar las imagenes necesarias dentro del sitio
*/
function MM_preloadImages() { //v3.0
  var d=document; 
  if(d.images){ 
  	if(!d.MM_p) 
		d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; 
	for(i=0; i<a.length; i++)
    	if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}
  }
}


/*
* MM_swapImgRestore : Permite realizar el swap entre imagenes
*/
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; 
  for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) 
  	x.src=x.oSrc;
}

/*
* MM_swapImage : Permite realizar el swap entre imagenes
*/
function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; 
  document.MM_sr=new Array; 
  for(i=0;i<(a.length-2);i+=3)
   	if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

 //Funcion que se encarga de cargar el mp3 en el flash de reproductor
function cargar(valor) {
    movie = document.reproductor;
    movie.SetVariable('entrada',valor);
}

//Funcion se encarga de abrir la informacion de ayuda del perro perez
function cargarInfo(url){
	window.opener.location = url;
	window.close();
}

//Llama al buscador
function goToSearch(text, countryCod){
  if(text.value.length < 3){ // para que valide un mínimo de 3 caracteres
        alert("Introduzca una busqueda válida con al menos 3 caracteres");
  }
  else {
        top.location = "/cgi-bin/htsearch?words="+text.value+"&method=and&config=taguara-"+countryCod
  }
}

//Estas funciones se encargan de adicionar los nuevos archivos al Editor
function adicionarFila(){
	var cont = document.getElementById("file");
	cont.setAttribute("value", parseInt(cont.value,0)+1);
	var tabla = document.getElementById("contenido").tBodies[0];

	var fila = document.createElement("TR");

	var celda1 = document.createElement("TD");
	celda1.innerHTML = "Subir Archivo "+cont.value+" :";


	var celda2 = document.createElement("TD");
	var valorA = document.createElement("INPUT");
	valorA.setAttribute("type","file");
	valorA.setAttribute("name",""+ cont.value);
	celda2.appendChild(valorA);

	var celda3 = document.createElement('TD');
	var boton = document.createElement('INPUT');
	boton.setAttribute('type','button');
	boton.setAttribute('value','Eliminar');
	boton.onclick=function(){borrarFila(this);}
	celda3.appendChild(boton);

	fila.appendChild(celda1);
	fila.appendChild(celda2);
	fila.appendChild(celda3);

	tabla.appendChild(fila);
}

function borrarFila(button){
	var fila = button.parentNode.parentNode;
	var tabla = document.getElementById('contenido').getElementsByTagName('tbody')[0];
	tabla.removeChild(fila);
}
