<!--

var resolution=1;
var handleHelp=null;
var handleAuxWin=null;
var handleRef=null;
var OnLoad=false;
var dummy, totsec, startsec, lastsec, numsecref, numsecprev, numsecnext, bypass;


function InitScripts()  {
        CheckBrowser();
/*
        handleHelp = window.open("","HelpWin","width=1,height=1,directories=no,status=yes,menubar=no,scrollbars=no,toolbar=no,resizable=no");
        handleHelp.close();

        handleAuxWin = window.open("","AuxWin","width=1,height=1,directories=no,status=yes,menubar=no,scrollbars=no,toolbar=no,resizable=no");
        handleAuxWin.close();

        handleRef = window.open("","RefWin","width=1,height=1,directories=no,status=yes,menubar=no,scrollbars=no,toolbar=no,resizable=no");
        handleRef.close();
*/
}


function CheckBrowser() {
	var i=0;

        if(BrowserVersionGT("4")) {
		if(screen.width >= 800)
			resolution=1;
		if(screen.width > 1000)
			resolution=2;
	} else {
		resolution=0;
	}

        if (FriendBrowser()) {
                if(ExistForm("")) {
			if(!ExistForm("frmquery")) {
				for(i=0;i < document.links.length; i++) {
					if(document.links[i].href.indexOf("=")>=0)
						document.links[i].href+="&debug=0";
				}
			}
		}
	}

	return;
}


function ExistForm(nform) {
	var i=0;

	if (FriendBrowser() && nform!="") {
		for(i=0;i < document.forms.length; i++) {
		 	if(document.forms[i].name.toLowerCase()==nform.toLowerCase())
				 return true;
		}
	}
	return false;
}



function Empty(valor) {
	var i=0;

	for (var i=0; i < valor.length; i++) {
		if (valor.substring(i,i+1) != " ")
			return (false);
	}
	return (true);
}


function SendAlert(idioma,msgid) {
	if (idioma.toLowerCase()=="ingles") {
		if(msgid==1)
			alert("Value empty");
		else if(msgid==2)
			alert("Invalid field type. Report the error");
		else if(msgid==3)
			alert("Form frmquery does not exist. Report the error");
		else if(msgid==4)
			alert("You can't change this value");
		else if(msgid==5)
			alert("You must use only numbers");
		else if(msgid==6)
			alert("You must use only letters");
		else if(msgid==7)
			alert("You must use three or more letters");
                else if(msgid==8)
                        alert("Invalid value");
        } else {
		if(msgid==1)
			alert("Valor en blanco");
		else if(msgid==2)
			alert("Tipo de campo no válido. Reporte el error");
		else if(msgid==3)
			alert("El form  frmquery no existe. Reporte el error");
		else if(msgid==4)
			alert("El valor no puede ser cambiado");
		else if(msgid==5)
			alert("Sólo puede ingresar números");
		else if(msgid==6)
                        alert("Sólo puede ingresar letras");
		else if(msgid==7)
                        alert("Debe ingresar tres o más letras");
                else if(msgid==8)
                        alert("Valor inválido");
        }
}

function OnlyNumbers(valor) {
        var numeros="0123456789,.- ";
	var thischar;
	var i=0;

        for (i=0; i < valor.length; i++) {
		thischar=valor.substring(i,i+1);
		if(numeros.indexOf(thischar)==-1) {
			return false;
		}
	}
	return true;
}

function OnlyLetters(valor) {
        var letras="abcdefghijklmnñopqrstuvwxyzáéíóúü' &+";
	var thischar;

	for (var i=0; i < valor.length; i++) {
		thischar=valor.substring(i,i+1);
		if(letras.indexOf(thischar.toLowerCase())==-1) {
			return false;
		}
	}
	return true;
}

function ValidaReferencias(valor){
	var ret=true;

	if (!OnlyLetters(valor)) {
		SendAlert("CASTELLANO",6);
 		ret=false;
 	} else {
        	if (!CheckLongMinAlpha(valor)) {
			SendAlert("CASTELLANO",7);
 			ret=false;
		}
	}

	if(!ret) {
		naviga.document.naviga.referencias.value="";
	}

       return ret;
}

function ValidaArticulo(valor){
	var ret=true;

	if (!OnlyNumbers(valor)) {
		SendAlert("CASTELLANO",5);
 		ret=false;
 	} else {
        	if (parseInt(valor) <= 0 || parseInt(valor) >= 10000) {
			SendAlert("CASTELLANO",8);
 			ret=false;
		}
	}

       return ret;
}

function CheckLongMinAlpha(palabra) {
	if(!Empty(palabra) && palabra.length < 4)
		return false;
	return true;
}

function CheckLongMinAlphaDoc(palabra) {
	if(!Empty(palabra) && palabra.length <= 2)
		return false;
	return true;
}

function CheckLongMinNumbers(numero) {

        if(!Empty(numero)) {
		if(!numero.length > 1) {
			return false;
		}
	}
	return true;
}

function SubsStr(valor,strsrc,strdes) {
	var str=valor;

	for (pos=str.indexOf(strsrc); pos!=-1; pos=str.indexOf(strsrc)) {
		valor=str.substring(0,pos)+strdes+str.substring(pos+strsrc.length,str.length-pos);
		str=valor;
	}
}

/* Rutina para frame de Navegacion **************************************/

function pageLoaded(pdummy,ptotsec,pstartsec,plastsec,pnumsecref,pnumsecprev,pnumsecnext,pbypass)  {
	dummy=pdummy;
	totsec=ptotsec;
	startsec=pstartsec;
	lastsec=plastsec;
	numsecref=pnumsecref;
	numsecprev=pnumsecprev;
	numsecnext=pnumsecnext;
	bypass=pbypass;

	var auxurl="registro="+top.documento.document.frmquery.registro.value + "&docid="+top.documento.document.frmquery.docid.value + "&debug="+top.documento.document.frmquery.debug.value + "&lang="+top.documento.document.frmquery.lang.value + "&urlback="+top.documento.document.frmquery.urlback.value + "&mquery="+top.documento.document.frmquery.mquery.value + "&padre="+top.documento.document.frmquery.padre.value ;
       auxurl+="&totsec="+totsec + "&startsec="+startsec + "&lastsec="+lastsec + "&numsecref="+numsecref + "&numsecprev="+numsecprev + "&numsecnext="+numsecnext;
       auxurl+= "&articulo="+top.documento.document.frmquery.articulo.value + "&referencias="+top.documento.document.frmquery.referencias.value;
       auxurl+= "&news="+bypass;

	/* 1 es para el diario */
	if(bypass==1) {
		top.naviga.document.location.href="/shared-cgi/" + "wwwgetnaviga?"+ auxurl;
	} else {
		top.naviga.document.location.href="/cgi-bin/" + "wwwgetnaviga?"+ auxurl;
	}
}

function escape_ref(valor) {
	var i=0;

	for (var i=0; i < valor.length; i++) {
		if (valor.substring(i,i+1) == " ")
		    SubsStr(valor," ","%20");
	}
	return (valor);
}

function SubmitNavigaSec()  {
//	if (parent.IsOpenWinHelp() || !top.OnLoad)
//		return false;


	var auxurl="registro="+documento.document.frmquery.registro.value
			      +"&docid="+documento.document.frmquery.docid.value
                              +"&debug="+documento.document.frmquery.debug.value
                              +"&lang="+documento.document.frmquery.lang.value
                              +"&urlback="+documento.document.frmquery.urlback.value
                              +"&mquery="+documento.document.frmquery.mquery.value
                              +"&padre="+documento.document.frmquery.padre.value
			      +"&news="+documento.document.frmquery.news.value
                              +"&articulo="+naviga.document.naviga.articulo.value
                              +"&referencias="+naviga.document.naviga.referencias.value
			      +"&startsec="+startsec
                              +"&boton=Ir";

	/* 1 es para el diario */
	if(documento.document.frmquery.news.value=='1') {
		documento.document.location.href="/shared-cgi/" + "wwwgetdoc?"+ auxurl;
	} else {
		documento.document.location.href="/cgi-bin/" + "wwwgetdoc?"+ auxurl;
	}

	naviga.document.location.href="/load_doc.html";

	return false;
}

function SubmitNavigaNoSec()  {
//	if (parent.IsOpenWinHelp() || !top.OnLoad)
//		return false;


	var auxurl="registro="+documento.document.frmquery.registro.value
			      +"&docid="+documento.document.frmquery.docid.value
                              +"&debug="+documento.document.frmquery.debug.value
                              +"&lang="+documento.document.frmquery.lang.value
                              +"&urlback="+documento.document.frmquery.urlback.value
                              +"&mquery="+documento.document.frmquery.mquery.value
                              +"&padre="+documento.document.frmquery.padre.value
			      +"&news="+documento.document.frmquery.news.value
                              +"&referencias="+naviga.document.naviga.referencias.value
			      +"&startsec="+startsec
                              +"&boton=Ir";

	/* 1 es para el diario */
	if(documento.document.frmquery.news.value=='1') {
		documento.document.location.href="/shared-cgi/" + "wwwgetdoc?"+ auxurl;
	} else {
		documento.document.location.href="/cgi-bin/" + "wwwgetdoc?"+ auxurl;
	}

	naviga.document.location.href="/load_doc.html";

	return false;
}

//-->

