var cn_imgSrc='';
var cn_n=0;
var win='';

var cn_liga='';
var cn_textoliga='';

function EditarImagen(n,imgSrc){
cn_n=n;
cn_imgSrc=imgSrc;
w=400;
h=500;
l=(screen.width-w)/2;
t=(screen.height-h)/2;
win=window.open('SelImagen.php','SelImagen','scrollbars=yes,resizable=yes,width='+w+',height='+h+',left='+l+',top='+t);
//win.moveTo(l,t);
win.focus();
}

function SeleccionarImg(file){
if (cn_n>0){
if (win) win.close();
imgObject=ObtenerObjeto('img'+cn_n);
bObject=ObtenerObjeto('b'+cn_n);
bObject.value=file;
imgObject.src='pub/'+file;
window.focus();
}
cn_imgSrc='';
cn_n=0;
win='';
}

function EditarImagenGaleria(n,imgSrc){
cn_n=n;
cn_imgSrc=imgSrc;
w=400;
h=500;
l=(screen.width-w)/2;
t=(screen.height-h)/2;
win=window.open('SelImagenGaleria.php','SelImagen','scrollbars=yes,resizable=yes,width='+w+',height='+h+',left='+l+',top='+t);
//win.moveTo(l,t);
win.focus();
}

function SeleccionarImgGaleria(file){
if (cn_n>0){
if (win) win.close();
imgObject=ObtenerObjeto('img'+cn_n);
bObject=ObtenerObjeto('b'+cn_n);
bObject.value=file;
imgObject.src='pub/galeria/'+file;
window.focus();
}
cn_imgSrc='';
cn_n=0;
win='';
}

function AbrirEditor(n){
cn_n=n;
//cn_imgSrc=imgSrc;
imgObject=ObtenerObjeto('texto'+cn_n);
w=400;
h=500;
l=(screen.width-w)/2;
t=(screen.height-h)/2;
var texto=escape(imgObject.value);
win=window.open('editor/editor.php?valor='+texto,'editor','scrollbars=yes,resizable=yes,width='+w+',height='+h+',left='+l+',top='+t);
//win.foo.innerHTML=imgObject.value;
//win.moveTo(l,t);
win.focus();
}

function CerrarEditor(texto){
if (cn_n>0){
if (win) win.close();
imgObject=ObtenerObjeto('texto'+cn_n);

texto=texto.replace(/<BR>/g,'\n');
texto=texto.replace(/&nbsp;/g,' ');
texto=texto.replace(/<STRONG>/g,'<B>');
texto=texto.replace(/<\/STRONG>/g,'<\/B>');

imgObject.value=texto;
}
cn_n=0;
win='';
}

function EditarLiga(n,liga,textoliga) {
cn_n=n;
cn_liga=liga;
cn_textoliga=textoliga;
tipoliga=1; //falta identificar 1 0 3
w=440;
h=440;
l=(screen.width-w)/2;
t=(screen.height-h)/2;
win=window.open('editarligas.php?liga='+liga+'&textoliga='+textoliga,'editarligas','scrollbars=yes,resizable=yes,width='+w+',height='+h+',left='+l+',top='+t);
//win.moveTo(l,t);
win.focus();
//alert("n="+n+" , liga="+liga+" , textoliga="+textoliga);
}

function SeleccionarLiga(liga,textoliga){
if (cn_n>0){
if (win) win.close();
lObject=ObtenerObjeto('l'+cn_n);
tlObject=ObtenerObjeto('tl'+cn_n);
alObject=ObtenerObjeto('al'+cn_n);
lObject.value=liga;
tlObject.value=textoliga;
alObject.innerText='liga: '+textoliga;
window.focus();
}
cn_liga='';
cn_textoliga='';
cn_n=0;
win='';
}

function Cerrar(){
if (win) win.close();
window.focus();
cn_imgSrc='';
cn_liga='';
cn_textoliga='';
cn_n=0;
win='';
}




function button_over(eButton){
if(eButton.alternar==undefined) eButton.alternar=0;
if (eButton.alternar<2){
eButton.style.borderBottom = "buttonshadow solid 1px";
eButton.style.borderLeft = "buttonhighlight solid 1px";
eButton.style.borderRight = "buttonshadow solid 1px";
eButton.style.borderTop = "buttonhighlight solid 1px";
}
}

function button_out(eButton){
if(eButton.alternar==undefined) eButton.alternar=0;
if (eButton.alternar<2) eButton.style.borderColor = "threedface";
}

function button_down(eButton){
eButton.style.borderBottom = "buttonhighlight solid 1px";
eButton.style.borderLeft = "buttonshadow solid 1px";
eButton.style.borderRight = "buttonhighlight solid 1px";
eButton.style.borderTop = "buttonshadow solid 1px";
}

function marcar(n,valor){
//valor=document.forms[0].cheqtipo[n].value;
result=document.forms[0].cheqtipo[n].checked;
nf=document.forms[0].cheqtipo.length;
for(i=n;i<nf;i++) {
valor2=document.forms[0].cheqtipo[i].value;
valor2=valor2.substring(0,valor.length);
if(valor==valor2)
document.forms[0].cheqtipo[i].checked=!result;
else i=nf;
}
}



var origentexto;
var destinocombo;
function autocompletarini(origen,destino) {
origentexto=origen;
destinocombo=destino;
if(event.keyCode == 13) origentexto.form.submit();
else setTimeout('autocompletar()',30);
}


function autocompletar() {
if(!origentexto || !destinocombo) return;
var n=destinocombo.options.length;
var indice = 0;
var valor = '';
var str = origentexto.value;
if(str) for (i=1;i<n;i++) {
valor=destinocombo.options[i].text;
if(valor.length>=str.length) {
strcomp=valor.substring(0,str.length);
if(strcomp.toLowerCase()==str.toLowerCase()){
indice=i; i=n;
}
}
}
if(destinocombo.options.selectedIndex!=indice)
destinocombo.options.selectedIndex=indice;
document.forms[0].opexistente.checked=(indice>0);
}

function autocompletarfin() {
/*
if(!origentexto || !destinocombo) return;
var str=origentexto.value;
var indice=destinocombo.options.selectedIndex;
var valor=destinocombo.options[indice].text;
if(valor!=str) destinocombo.options.selectedIndex=0;
*/
}

function autocompletarver(destinocombo,nombrediv){
objdiv=document.all[nombrediv];
var indice=destinocombo.options.selectedIndex;
if(indice>0) objdiv.style.visibility="hidden";
else objdiv.style.visibility="visible";
}

