document.onkeydown = alertkey;
key = 0;

function alertkey(e) {
  if (document.all) {
     key = window.event.keyCode;
  }
  else if(document.getElementById || document.layers){
     key = e.which;
  }
  if( !e ) {
    if( window.event ) {
      e = window.event;
    } else {
      return;
    }
  }  
  return;
}

function keyHandler(e) {
    if (key == 13) {
        return true;
    }
}

//funcion que recibe una variable parameters y una forma y devuelve
//los elementos de tipo hidden y text como parametros para ser aņadidos al url de una jsp o servlet
//si son necesarios algunos parametros extra deben ponerse al inicializar la variable parameters 
//terminado el valor con & o al final sin agregar el valor &
function getParameters(parameters, form){
	var frmElements;
	var i;
	
	frmElements = form.elements;

	for(i=0;i<frmElements.length;i++){
  		var element = frmElements[i];
  		
  		if (element.type == "text" || element.type == "hidden") {
  			parameters +=  element.name+"="+element.value+"&";
  		}
  	}	
  	return parameters;
}

//Devuelve un arreglo con los parametros enviados en el url
function getParams() {
	var idx = document.URL.indexOf('?');
	var params = new Array();
	if (idx != -1) {
		var pairs = document.URL.substring(idx+1, document.URL.length).split('&');
		for (var i = 0; i < pairs.length; i++) {
			nameVal = pairs[i].split('=');
			params[nameVal[0]] = unescape(nameVal[1]);
		}
	}
	return params;
}
//Valida que se halla hecho una seleccion que no sea vacia
function validateSelection(selection){
	if(selection.selectedIndex >= 0){
		var option = selection.options[selection.selectedIndex];
		if(option && option.value!=''){
			return true
		}
	}
	return false;
}
//Envia todos los items seleccionados de la lista multiple 
//como un arreglo de inputs en una peticion AJAX
//el objeto ajax debe existir en la forma
function sendItems(selection, object){
	var selected = new Array(); 
	for (var i = 0; i < selection.options.length; i++){
		if (selection.options[ i ].selected){
			var newInput = document.createElement("input");
			newInput.setAttribute("id", selection.id);
			newInput.setAttribute("value", selection.options[ i ].value);
			selected.push(newInput);
		}
	}
	ajaxRequest.sendActionValues(document.location.pathname,object,selected);
}