function vacio (palabra){
	
	
	for ( i = 0; i < palabra.length; i++ ) {
                if ( palabra.charAt(i) != " " ) {
                        return true;
                }
        }
       
		return false;	
}


function validaBusqueda(id) {

        var F = document.getElementById(id);
        if( vacio(F.palabras.value) == false || F.palabras.value == 'Buscar por palabra clave' ) {
                alert("Por Favor Introduzca la(s) palabra(s) a buscar");
                return false;
        } 
		else {
               F.submit();
				//return true;
        }
        
}

function muestraBloque(objeto,accion)
{ 
	var theObj;
	//alert(objeto);
	theObj = document.getElementById(objeto);//eval(document.all[objeto]);
	if (theObj)
	{
		if(accion == 'auto')
		{
			if (theObj.style.display == 'none')
				accion='block';
			else
				accion='none';			
		}
	//	alert("objeto "+ objeto + " accion " + accion);
		theObj.style.display = accion;
	}		
}

//Quita los espacios sobrantes a izquierda y derecha en un input
function trim(x)
{
	while(x.value.substring(0,1)==" "){x.value = x.value.substring(1, x.value.length);}
	while(x.value.substring(x.value.length-1,x.value.length)==" "){x.value = x.value.substring(0, x.value.length-1);}
}
//valida que no deje un input vacio
function vacio(x, msg)
{
	trim(x);
	if(x.value == ""){Action(x, msg); return true}
}

//Valida que se capture un Email con @ y .
function wrongEmail(x, msg)
{
	if(x.value.indexOf("@") == -1){Action(x, msg); return true}
	if(x.value.indexOf(".") == -1){Action(x, msg); return true}
}
//Envia un mensaje y enfoca al elemento x
function Action(x, msg){alert(msg); x.focus(); /*x.select();*/}
//Valida que el input contenga sólo números enteros
function noEntero(x, msg){ if(isNaN(x.value) || x.value.indexOf(".")!=-1 || x.value.indexOf("-")!=-1){Action(x, msg); return true}}

//Valida que el input contenga sólo números (enteros o flotantes) no negativos
function noNumero(x, msg){ 
if(isNaN(x.value) || x.value.indexOf("-")!=-1){
	Action(x, msg); return true;
	}
}

//Valida que el input contenga menos de i caracteres
function ValLenMax(x, i, msg) { if(x.value.length > i){Action(x, msg); return true} }

//Valida que el input contenga al menos i caracteres
function ValLenMin(x, i, msg) { if(x.value.length < i){Action(x, msg); return true} }

//Valida que el input contenga exactamente i caracteres
function ValLenExact(x, i, msg) { if(x.value.length != i){Action(x, msg); return true} }

//Valida que se seleccione una opción en una lista o combo
function noSel(x, msg){ if(x.selectedIndex==0){Action(x, msg); return (true);}}

//Valida que se cheque un checkbox y optionbox
function noCheck(x, msg)
{
	var i;
	for(i=0; i<x.length; i++)
	{
		if(x[i].checked)
		{
			return false;
		}
	}
	Action(x[0], msg);
	return true;
}

//Valida que no se capturen acentos en los inputs
function noAccents(x, msg)
{
	if( x.value.indexOf("á")!=-1 || x.value.indexOf("é")!=-1 || x.value.indexOf("í")!=-1 || x.value.indexOf("ó")!=-1 || x.value.indexOf("ú")!=-1 ){Action(x, msg); return true}
	if( x.value.indexOf("Á")!=-1 || x.value.indexOf("É")!=-1 || x.value.indexOf("Í")!=-1 || x.value.indexOf("Ó")!=-1 || x.value.indexOf("Ú")!=-1 ){Action(x, msg); return true}
}

//Valida que no se capturen espacios en los inputs
function noSpaces(x, msg)
{
	if( x.value.indexOf(" ")!= -1 ){Action(x, msg); return true}
}

//Valida que no se capturen caracteres especiales que
//corrompan las consultas SQL
function noSpecial(x, msg)
{
	if( x.value.indexOf('"')!=-1 || x.value.indexOf("'")!=-1 || x.value.indexOf("%")!=-1 || x.value.indexOf("#")!=-1  || x.value.indexOf("*")!=-1 ){Action(x, msg); return true}
}

//verifica que un campo no se haya llenado unicamente con espacios en blanco

function checarVacio(q) {
	   for ( i = 0; i < q.length; i++ ) {
                if ( q.charAt(i) != " " ) {
                        return true
                }
        }
        return false
}

