//********************************************************
//*           CONTENIDO.JS: FUNCIONES JAVASCRIPT         *
//********************************************************
var cautr="Dirección y diseño de Jesús Quílez Bielsa. "
var cnavg="Microsoft Internet Explorer"
var posdiviniy=0
var cvern="4"
var lsuenamusica=false
var csepcads=""
var csepcars=""
var nscr=0
var nsct=0
var ncierra=0
var esqvis=false
var posratx=-1
var posraty=-1
var cnavegador=navigator.appName
var intlinant=""

window.onerror = trataerror;
window.onbeforeprint = preparaprint;
window.onafterprint = revierteprint;
 
if (cnavegador=="Netscape"){
window.captureEvents(Event.MOUSEMOVE | Event.MOUSEDOWN | Event.MOUSEUP);
document.onmousemove=mueveraton
}

function preparaprint(){
var contenido=""
if (document.all) {
 if (document.all["contenido"]){
  contenido = document.all["contenido"].innerHTML
 }
} 
if (document.getElementById){
 if (document.getElementById("contenido")){
  contenido = document.getElementById("contenido").innerHTML
 }
}
if (contenido>""){ 
 document.body.background = " "
 document.body.leftMargin = 100
 document.body.innerHTML = contenido
}
}
 
function revierteprint(){
setTimeout("window.location.reload()",50)
}


function mueveraton(e){
posratx=e.pageX
posraty=e.pageY
}

function trataerror(){
return true;
}

function compruebanavegador(){
cnavegador=navigator.appName
}

function navegador(ntip) {
cnavact=navigator.appName
nveract=navigator.appVersion
if (ntip==2) {
if (cnavact!=cnavg) {
alert("Esta página está preparada para "+cnavg+".  Es posible que con su navegador no se vea bien")
}
}
else {
if (ntip==1) {
if (nveract<cvern) {
alert("Esta página está preparada para versión "+cvern+" ó superior.  Es posible que con la versión de su navegador: "+nveract+" No se vea bien")
}
}
}
}

function enviarformulario(){
npts=0
if (document.QT0){ccal=document.QT0.tx00.value}
if (document.QS0){ccal=document.QS0.tx00.value}
if (document.QA0){
   ccal=document.QA0.tx00.value
   nttl= ntextot
   }
else {
     nttl=respuestas.length
}
nfal=estaen(ccal," ")+1
if (estaen(ccal,"uy ")>0){npts=10}
else {
     if (nfal>0){
	cflt=ccal.substring(nfal,nfal+2)
	nflt=parseInt(cflt,10)
	npts=nttl-nflt
	npts=parseInt((npts/nttl)*10)
     }
}
if (lsolucion ){npts=0}
if (npts>10){npts=10}
if (document.QA0){
	document.QA0.total.value=npts
	document.QA0.submit()
}
if (document.QT0){
	document.QT0.total.value=npts
	document.QT0.submit()
}
if (document.QS0){
	document.QS0.total.value=npts
	document.QS0.submit()
}
}


//***********************************************
//*     FUNCIONES DE ABRIR Y CERRAR VENTANAS    *
//***********************************************

function nvotex(loc) {
cnav=navigator.appName
tx=document.body.clientWidth
ty=document.body.scrollHeight
if (cnavegador=="Netscape") {
x=posratx
y=posraty
}
else {
x=window.event.screenX
y=window.event.screenY
}
if (x+480>tx) {x=x-480}
if (y+200>ty) {y=y-200}
opc="scrollbars=yes,width=480,height=200,top="+y+",left="+x+""
if (loc=="esvn01.htm"){opc="scrollbars=no,width=500,height=470,top="+y+",left="+x+""}
nuevo=window.open(loc,"",opc)
}

function nvaven(loc,anc,lar) {
if (cnavegador=="Netscape"){
	if (estaen(loc,"qt")>5){
		loc=loc+"l"
	}
}
if (anc==0) {anc=750}
if (lar==0) {lar=500}
opc="scrollbars=yes,width="+anc+",height="+lar+",top=20,left=20"
nuevo=window.open(loc,'',opc)
}

function vertraduc(loc) {
cnav=navigator.appName
tx=document.body.clientWidth
ty=document.body.scrollHeight
if (cnavegador=="Netscape") {
x=posratx
y=posraty
}
else {
x=window.event.screenX
y=window.event.screenY
}
if (x+480>tx) {x=x-480}
opc="scrollbars=yes,width=480,height=200,top="+y+",left="+x+""
nuevo=window.open(loc,"",opc)
}

function abrelista(){
var cpagina = drop.texto.options[drop.texto.selectedIndex].value
var cclave = cpagina.substring(6,8)
parent.textos.location.href = cpagina
if (estaen("qt;ac;ej;ap;",cclave+";")>-1) {
	nvaven(cpagina,0,0)
	}
return (false)
}

function vuelveaorigen(){
         history.back()
}

//** NOTAS **

function abrenota(loc){
cnta="d"+loc
if (cnavegador=="Netscape"){
tx=window.innerWidth
ty=window.innerHeight
nvax = posratx
nvay = posraty
}
else {
tx=document.body.clientWidth
ty=document.body.scrollHeight
nvax = window.event.clientX + document.body.scrollLeft
nvay = window.event.clientY + document.body.scrollTop
}
ancnot=ancdiv(cnta)
altnot=altdiv(cnta)
if (nvax+ancnot>tx) {nvax=nvax-ancnot}
if (nvay+altnot>ty) {nvay=nvay-altnot}
camina(cnta,nvax,nvay)
verdiv(cnta)
}

function cierranota(cnota){
ocudiv(cnota)
}

function abremapa(loc){
opc="scrollbars=no,width=780,height=420,top=40,left=5"
nuevo=window.open("swf/"+loc,'',opc)
}

function nvoind(loc,anc) {
//if (anc==undefined) {anc=320}
anc=320
//posiniy=fincab()+window.screenTop
posiniy=120
opc="scrollbars=yes,width="+anc+",height=500,top="+posiniy+",left=0"
nuevo=window.open(loc,'',opc)
}

function hazpag(dts,tit) {
cnav=navigator.appName
tx=screen.width
ty=screen.height
if (cnav=="Netscape") {
x=parseInt(tx/3,10)
y=parseInt(ty/3,10)
}
else {
x=window.event.screenX
y=window.event.screenY
}
if (x+400>tx) {x=x-400}
if (y+200>ty) {y=y-200}
opc="scrollbars=yes,width=400,height=200,top="+y+",left="+x+""
dts="<html><head><title>"+tit+"</title></head><body bgcolor='#CCCCFF'>"+dts+"</body><html>"
nuevo=window.open("","",opc)
nuevo.document.write(dts)
nuevo.document.close()
}

function dicphp(plbbus) {
plbbus=cambiacadena(plbbus,".","")
plbbus=cambiacadena(plbbus,",","")
plbbus=cambiacadena(plbbus,";","")
plbbus=cambiacadena(plbbus,":","")
plbbus=cambiacadena(plbbus,")","")
plbbus=cambiacadena(plbbus,"(","")
plbbus=plbbus.toLowerCase()
cnav=navigator.appName
tx=screen.width
ty=screen.height
if (cnav=="Netscape") {
x=parseInt(tx/3,10)
y=parseInt(ty/3,10)
}
else {
x=window.event.screenX
y=window.event.screenY
}
if (x+400>tx) {x=x-400}
if (y+200>ty) {y=y-200}
opc="scrollbars=yes,width=400,height=200,top="+y+",left="+x+""
dts="<html><head><title>Diccionario latino</title></head>"
dts=dts+"<body bgcolor='#CCCCFF' onload=document.datos.submit()>"
dts=dts+"<FONT face='Verdana' size=2>"
dts=dts+"Buscando el término '"+plbbus+"', espera por favor...</font>"
dts=dts+"<FORM name=datos action='../diclat/diclat.php' method=post>"
dts=dts+"<input name=tx00 type=hidden value='"+plbbus+"'></form>"
dts=dts+"</body><html>"
nuevo=window.open("","",opc)
nuevo.document.write(dts)
nuevo.document.close()
}

function cierra(){
window.close()
}

function descargadoc(){
diract=window.location.href
dirdoc=cambiacadena(diract,".html",".doc")
dirdoc=cambiacadena(diract,".htm",".doc")
window.location=dirdoc
}

function iradoc(destino) {
nuevo=window.open(destino)
}

//************************************************
//* FUNCIONES GENERALES                          *
//************************************************

function estaen(cad,ter) {
pos=-1
lng=cad.length
lnt=ter.length
for (con=0;con+lnt-1<lng;++con) {
if (cad.substring(con,con+lnt)==ter) {
pos=con
return (pos);
}
}
return (pos);
}

function estaenarray(nomarr,datos){
nposicion=-1
nelementos=eval(nomarr+".length")
for (neleact=0;neleact<nelementos;++neleact){
	celemento=eval(nomarr+"["+neleact+"]")
	nposicion=estaen(celemento,datos)
	if (nposicion>-1){
		return (neleact)
		}
	}
return (-1)
}

function cambiacadena(pal,ori,des) {
nLp=pal.length
orb=ori
nLo=orb.length
nSd=estaen(pal,orb)
nLo=orb.length
if (nSd>-1){
	pal=pal.substring(0,nSd)+des+pal.substring(nSd+nLo)
	pal=cambiacadena(pal,ori,des)
}
return (pal)
}

function cambiauna(pal,ori,des) {
nLp=pal.length
orb=ori
nLo=orb.length
nSd=estaen(pal,orb)
nLo=orb.length
if (nSd>-1){
	pal=pal.substring(0,nSd)+des+pal.substring(nSd+nLo)
}
return (pal)
}

function rellena(caracter,veces){
var crelleno=""
for (nlonact=1;nlonact<=veces;++nlonact){
	crelleno=crelleno+caracter
}
return (crelleno)
}


function daazar(valormax) {
  var ahora = new Date()
  var nazar = ahora.getTime() * ahora.getSeconds() * Math.random()
  return Math.round(nazar % valormax)
}

function trim(cadena){
	return rtrim(ltrim(cadena))
}

function ltrim (cadena){
	return cadena.replace( /^\s*/, "" );
}

function rtrim (cadena){
	return cadena.replace( /\s*$/, "" );
}

function interlineado(objeto){
	if (document.all) {
		parrafo=document.all[objeto]
	} 
	else {
		if (document.getElementById) {
			parrafo=document.getElementById(objeto)
		}
	}
	if (parrafo){
		if (parrafo.style.lineHeight<"40px") {
		        intlinant=parrafo.style.lineHeight
                        parrafo.style.lineHeight="40px"
                        }
		else {parrafo.style.lineHeight=intlinant}
	}
}

function dapalabras(cadena,separador){
if (!cadena){}
else {
      csepcads=cadena
      if (!separador){csepcars=";"}
      else {csepcars=separador}
}
npos=estaen(csepcads,csepcars)
if (npos==0){
   csepcads=csepcads.substring(1)
   npos=estaen(csepcads,";")
}
if (npos>0){
   cpalabra=csepcads.substring(0,npos)
   csepcads=csepcads.substring(npos+1)
}
else {cpalabra=""}
return(cpalabra)
}
//************************************************
//* FUNCIONES DE SONIDO                          *
//************************************************

function oir(snd){
lsuenamusica=true
document.oye.cane(snd);
}
function rep(snd){
lsuenamusica=true
document.oye.canta(snd)
}
function calla() {
if (lsuenamusica){
document.oye.tace();
lsuenamusica=false
}
}

//************************************************
//* FUNCIONES DE MANIPULACIÓN DE DIVS            *
//************************************************

//** POSICIÓN **

function camina(cap,x,y) {
	if (document.all) {
		document.all[cap].style.left = x    
		document.all[cap].style.top = y
	} 
	if (document.layers) {
    		document.layers[cap].moveTo(x, y)
	}
	if (document.getElementById) {
		document.getElementById(cap).style.left = x
		document.getElementById(cap).style.top = y 
	}
}

function posdivx(cap) {
  	if (document.all) {
		x = document.all[cap].style.left
	} 
	if (document.layers) {
		x = document.layers[cap].left
	}
	if (document.getElementById) {
		x = document.getElementById(cap).style.left
	}
  return (parseInt(x,10))
}

function posdivy(cap) {
	if (document.all) {
		y = document.all[cap].style.top
	} 
	if (document.layers) {
		y = document.layers[cap].clip.top
	}
	if (document.getElementById){
		y = document.getElementById(cap).style.top
	}
	return (parseInt(y,10))
}

function mantendiv(cnomdiv) {
if (posdiviniy==0) {posdiviniy=posdivy(cnomdiv)}
camina(cnomdiv,posdivx(cnomdiv),document.body.scrollTop+(posdiviniy-10))
}

function arrastradiv(cap){
	if (cnavegador=="Netscape"){
		tx=window.innerWidth
		ty=window.innerHeight
		nvax = posratx
		nvay = posraty
	}
	else {
		tx=document.body.clientWidth
		ty=document.body.scrollHeight
		nvax = window.event.clientX + document.body.scrollLeft
		nvay = window.event.clientY + document.body.scrollTop
	}
	nvax=nvax-20
	nvay=nvay+10
	//andiv=ancdiv(cap)
	//aldiv=altdiv(cap)
	andiv=50
	aldiv=50
	if (nvax+andiv<tx) {
		if (nvay+aldiv<ty) {
			camina(cap,nvax,nvay)
		}
	}
}

//** ALTO Y ANCHO **

function altdiv(cap) {
	if(document.all) {
		y = document.all[cap].style.height 
  	} 
	if (document.getElementById){
		y = document.getElementById(cap).style.height
	}
	if (document.layers){
		y = document.layers[cap].clip.height
	}
  return (parseInt(y,10))
}

function ancdiv(cap){
  	if (document.all){
		x = document.all[cap].style.width 
	} 
	if (document.getElementById){
		x = document.getElementById(cap).style.width
	}
	if (document.layers){
		x = document.layers[cap].clip.width 
	}
	return (parseInt(x,10))
}

function hazaltdiv(cap,alt) {
  	if (document.all) {
		document.all[cap].style.height = alt
  	}
	if (document.layers) {
    		document.layers[cap].clip.height = alt
	}
	if (document.getElementById) {
		document.getElementById(cap).style.height = alt
	}
}

function hazancdiv(cap,anc) {
  	if (document.all) {
		document.all[cap].style.width = anc
  	}
	if (document.layers) {
		document.layers[cap].clip.width = anc
	}
	if (document.getElementById) {
		document.getElementById(cap).style.width = anc
	}
}

//** COLORES **

function hazcolordiv(cap,color) {
  	if (document.all){
		document.all[cap].style.backgroundColor = color
	} 
	if (document.getElementById){
		document.getElementById(cap).style.backgroundColor = color
	}
	if (document.layers){
		document.layers[cap].clip.backgroundColor = color
	}
}

function dacolordiv(cap){
  	if (document.all){
		color = document.all[cap].style.backgroundColor
	} 
	if (document.getElementById){
		color = document.getElementById(cap).style.backgroundColor
	}
	if (document.layers){
		color = document.layers[cap].clip.backgroundColor
	}
	return (color)
}

//** VISIBILIDAD **

function esvisiblediv(cnomdiv) {
	var esvisible=false
	if(document.all) {
		if(document.all[cnomdiv].style.visibility=="visible"){esvisible=true}
	} 
	if(document.layers) {
		if(document.layers[cnomdiv].visibility=="visible"){esvisible=true}
	}
	if(document.getElementById){
		if(document.getElementById(cnomdiv).style.visibility=="visible"){esvisible=true}
	}
return (esvisible)
}

function verdiv(cnomdiv) {
	if (document.getElementById){
		document.getElementById(cnomdiv).style.visibility="visible"
	}
	if(document.all) {
		document.all[cnomdiv].style.visibility="visible"
	} 
	if(document.layers) {
		document.layers[cnomdiv].visibility="visible"
	}
}

function ocudiv(cnomdiv) {
	if (document.getElementById){
		document.getElementById(cnomdiv).style.visibility="hidden"
	}
	else {
		if(document.all) {
			document.all(cnomdiv).style.visibility="hidden"
		}
		else {
			if(document.layers) {
				document.layers[cnomdiv].visibility="hidden"
			}
		}
	}
}

function estadivendiv(divnum1,divnum2){
posx1=posdivx(divnum1)
posy1=posdivy(divnum1)
posx2=posdivx(divnum2)
posy2=posdivy(divnum2)
if (posx1>posx2){
	if (posx1<posx2+ancdiv(divnum2)){
		if (posy1>posy2){	
			if (posy1<posy2+altdiv(divnum2)){
				return (true)
			}
		}
	}
}
return (false)
}

