iX=-1
iXnc=-1
autor= new Array()
titulo= new Array()
materia= new Array()

function getSel()
{
	var txt = '';
	var foundIn = '';
	if (window.getSelection)
	{
		txt = window.getSelection();
		foundIn = 'window.getSelection()';
	}
	else if (document.getSelection)
	{
		txt = document.getSelection();
		foundIn = 'document.getSelection()';
	}
	else if (document.selection)
	{
		txt = document.selection.createRange().text;
		foundIn = 'document.selection.createRange()';
	}
	else return;
	re=/á/gi
	txt=txt.replace(re,"a")
	re=/é/gi
	txt=txt.replace(re,"e")
	re=/í/gi
	txt=txt.replace(re,"i")
	re=/ó/gi
	txt=txt.replace(re,"o")
	re=/ú/gi
	txt=txt.replace(re,"u")
	re=/Ñ/gi
	txt=txt.replace(re,"N")
	
	
	return txt
}


function MateriaSeleccionada(iX){
	if (iXnc>0){
		document.forma1.autores[iX].checked=false
		document.forma1.titulo[iX].checked=false
		document.forma1.seleccion[iX].checked=false
	}else{
		document.forma1.autores.checked=false
		document.forma1.titulo.checked=false
		document.forma1.seleccion.checked=false
	}
	EjecutarBusquedaGoogle(iX,1)
}

function AutorSeleccionado(iX){
	if (iXnc>0){
		document.forma1.materias[iX].checked=false
		document.forma1.titulo[iX].checked=false
		document.forma1.seleccion[iX].checked=false
	}else{
		document.forma1.materias.checked=false
		document.forma1.titulo.checked=false
		document.forma1.seleccion.checked=false
	}
	EjecutarBusquedaGoogle(iX,1)
}

function TituloSeleccionado(iX){
	if (iXnc>0){
		document.forma1.materias[iX].checked=false
		document.forma1.autores[iX].checked=false
		document.forma1.seleccion[iX].checked=false
	}else{
		document.forma1.materias.checked=false
		document.forma1.autores.checked=false
		document.forma1.seleccion.checked=false
	}
	EjecutarBusquedaGoogle(iX,1)
	
}


function TextoSeleccionado(iX){
	if (iXnc>0){
		document.forma1.autores[iX].checked=false
		document.forma1.titulo[iX].checked=false
		document.forma1.materias[iX].checked=false
	}else{
		document.forma1.autores.checked=false
		document.forma1.titulo.checked=false
		document.forma1.materias.checked=false
	}
	EjecutarBusquedaGoogle(iX,1)
}

function PrepararGoogle(a,Operador){
	if (a!=""){
		campo=a.split("|")
		Expresion=""
		for (i=0;i<campo.length;i++){
			re=/ /gi
			a=campo[i]
			if (Expresion==""){
//				Expresion='"'+a+'"'
				Expresion=a
			}else{
				Expresion=Expresion+" "+Operador+ ' "'+a+'"'
			}
		}
	}
		re=/á/gi
		Expresion=Expresion.replace(re,"a")
		re=/é/gi
		Expresion=Expresion.replace(re,"e")
		re=/í/gi
		Expresion=Expresion.replace(re,"i")
		re=/ó/gi
		Expresion=Expresion.replace(re,"o")
		re=/ú/gi
		Expresion=Expresion.replace(re,"u")
		re=/Ñ/gi
		Expresion=Expresion.replace(re,"N")
		return Expresion
}


function EjecutarBusquedaGoogle(iX,google){
	autores=""
	a=""
	Oper=" OR "
	Expresion=""

	if  (iXnc>0){
		if (document.forma1.autores[iX].checked)    a=autor[iX]
		if (document.forma1.titulo[iX].checked)	    a=titulo[iX]
		if (document.forma1.materias[iX].checked)	a=materia[iX]
		if (document.forma1.seleccion[iX].checked)  a=getSel()
	}else{
		if (document.forma1.autores.checked)    a=autor[iX]
		if (document.forma1.titulo.checked)	    a=titulo[iX]
		if (document.forma1.materias.checked)	a=materia[iX]
		if (document.forma1.seleccion.checked)  a=getSel()
	}
	
	Oper=""
	if (a!="") Expresion=PrepararGoogle(a,Oper)
		if (Expresion!=""){
		a=Expresion.replace("/","")
		a=a.replace(":","")
		if (a.length<20 || autores=="s"){
			a='"'+a+'"'
		}
		a=escape(a)	
		if (google==2){
			msgwin=window.open("http://scholar.google.com/scholar?name=f&q="+a+"&ie=UTF-8&oe=UTF-8&hl=es","bcv","menu=no,toolbar=yes, status=yes, scrollbars=yes, resizable=yes")
		}else{
			msgwin=window.open("http://www.google.com/search?name=f&q="+a+"&ie=UTF-8&oe=UTF-8&hl=es","bcv","menu=no,toolbar=yes, status=yes, scrollbars=yes, resizable=yes")
		}
		msgwin.focus()
	}else{
		alert("Debe seleccionar autor o materia o marcar un texto para la búsqueda en google")
	}
	if (iXnc>0){
		document.forma1.autores[iX].checked=false
		document.forma1.titulo[iX].checked=false
		document.forma1.materias[iX].checked=false
		document.forma1.seleccion[iX].checked=false
	}else{
		document.forma1.autores.checked=false
		document.forma1.titulo.checked=false
		document.forma1.materias.checked=false
		document.forma1.seleccion.checked=false
	}
}

function EjecutarBusquedaGoogleRevista(Expresion){
	a=Expresion.replace("/","")
	a=a.replace(":","")
	if (a.length<20){
		a='"'+a+'"'
	}
	a=escape(a)
//	msgwin=window.open("http://scholar.google.com/scholar?name=f&q="+a+"&ie=UTF-8&oe=UTF-8&hl=en","ivic","menu=no,toolbar=yes, status=yes, scrollbars=yes, resizable=yes")
	msgwin=window.open("http://www.google.com/search?name=f&q="+a+"&ie=UTF-8&oe=UTF-8&hl=es","ivic","menu=no,toolbar=yes, status=yes, scrollbars=yes, resizable=yes")
	msgwin.focus()
}

function EjecutarBusquedaScirus(Expresion){
	a=Expresion.replace("/","")
	a=a.replace(":","")
	a='"'+a+'"'
	a=escape(a)
	msgwin=window.open("http://www.scirus.com/srsapp/search?q="+a+"&ds=jnl&ds=web&t=phrase&g=s&t=all","ivic","menu=no,toolbar=yes, status=yes, scrollbars=yes, resizable=yes")
	msgwin.focus()
}

function EjecutarBusquedaPubMed(Expresion){
	a=Expresion.replace("/","")
	a=a.replace(":","")
	a=escape(a)
	msgwin=window.open("http://www.ncbi.nlm.nih.gov/entrez/query.fcgi?CMD=Clipboard&DB=journals&term="+a,"ivic","menu=no,toolbar=yes, status=yes, scrollbars=yes, resizable=yes")
	msgwin.focus()
}
