// Bloqueo de submit y llamada generica al submit
// Se utiliza en la funcion doSubmit

var  blockSubmit = true; //indica si es posible realizar el submit


// Realiza el submit del formulario
// Si la variable global 'blockSubmit' es cierta, se permitira el submit
// Parametros:
//            formName        objeto formulario html
//			  actionFormName  nombre del hiddenfield que contiene la accion a realizar.
//            actionValue     texto que identifica la accion que se realiza.Este texto es el informara al _action del formulario
//            callFuction     OPCIONAL. Nombre de la funcion que se debe ejcutar antes del submit.
function doSubmit(formName,actionFormName,actionValue,callFuction){
	var i = arguments.length;

	if (i==1){
		if (blockSubmit) {
			blockSubmit = false;
			formName.form.submit();
    } else {
			alert("ˇNo hace falta hacer doble click sobre este botón!");
		}
	}else if (i==3){
		if (blockSubmit) {
			blockSubmit = false;
			formName[actionFormName].value = actionValue;
			formName.submit();
    } else {
			alert("ˇNo hace falta hacer doble click sobre este botón!");
    }
	}else{
		if (blockSubmit) {
			if (eval(callFuction)){
	 			blockSubmit = false;
	  		formName[actionFormName].value = actionValue;
	  		formName.submit();
  		}
    } else {
			alert("ˇNo hace falta hacer doble click sobre este botón!");
 		}
	}
}

//borra espacios en blanco por la derecha y por la izquierda
function trim(s)
{
  // Remove leading spaces and carriage returns
  
  while ((s.substring(0,1) == ' ') || (s.substring(0,1) == '\n') || (s.substring(0,1) == '\r'))
  {
    s = s.substring(1,s.length);
  }

  // Remove trailing spaces and carriage returns

  while ((s.substring(s.length-1,s.length) == ' ') || (s.substring(s.length-1,s.length) == '\n') || (s.substring(s.length-1,s.length) == '\r'))
  {
    s = s.substring(0,s.length-1);
  }
  return s;
}

function comboKeyPressed(submForm) {
   if (window.event.keyCode == 13) {clickSearch(submForm);}
}

// function Connect
// Comprueba que el user y el pwd est?n informados antes de realizar login
function Connect(formLogin,userOblig,pswOblig,action) {
	if ((!isWhitespace(formLogin.j_username.value))&&(!isWhitespace(formLogin.j_password.value))){
		return true;
	}
	else{
		if (isWhitespace(formLogin.j_username.value))
			alert (userOblig)
		else
			alert(pswOblig)
		return false;
	}
}

// whitespace characters
var whitespace = " \t\n\r";

// Check whether string s is empty.
function isEmpty(s)	{
	return ((s == null) || (s.length == 0))
}

// Returns true if string s is empty or
// whitespace characters only.

function isWhitespace (s){
	var i;
    // Is s empty?
   	if (isEmpty(s)) return true;
    // Search through string's characters one by one
   	// until we find a non-whitespace character.
    // When we do, return false; if we don't, return true.

   	for (i = 0; i < s.length; i++){
   	    // Check that current character isn't whitespace.
        var c = s.charAt(i);
        if (whitespace.indexOf(c) == -1) return false;
   	}

    // All characters are whitespace.
   	return true;
}

