/*idem para app*/
/*****************************************************************
matchValidationVariable
-----------
Necesario para que funcione el patch de compatibilidad con 
prototype de commons-validator 
*****************************************************************/
  function matchValidationVariable(variable, value)
  {
  		var theRegexp = new RegExp('^a[0-9]*$');
  		return ((typeof value[0] !== undefined) &&
  			(theRegexp.exec(variable) !== null));
  }

/*****************************************************************
get_lastchild
-----------
Utilizada para obtener el ?ltimo hijo v?lido de un nodo
*****************************************************************/
//check if the last node is an element node
function get_lastchild(n)
{
	var x=n.lastChild;
	while (x.nodeType!=1)
	{
	x=x.previousSibling;
	}
	return x;
}

/*****************************************************************
get_childs
-----------
Utilizada para filtrar los hijos de un nodo y obtener los que son v?lidos
*****************************************************************/
function get_childs(n)
{
	var hijos = n.childNodes;
	var i = 0;

	while (i < hijos.length)
	{
		var hijo = hijos.item(i);
		if (hijo.nodeType != 1){
			n.removeChild(hijo);
		}
		i++;
	}

	return hijos;
}

/*****************************************************************
GetElement
----------
Gets an element from the document
Inputs:
	string elementID: ID of the desired element
	obj win: window where the element exists.
Returns:
	obj: Element.
*****************************************************************/
function GetElement(elementID, win)
{
	var time = 0;
	var timeOut = 1000;
	/*
	This loop has been implemented in order to support windows that
	may not have the entire document loaded yet (E.g.: Popups opened just before calling
	this function). timeOut is used to avoid entering in an infinite loop 
	if the element is not found in the document.
	*/
	do
	{
		if (win == null)
			element = document.getElementById(elementID);
		else
		{
			element = win.document.getElementById(elementID);
		}
		time++;
	}
	while (element == null && time < timeOut)
	return element;
}

/*****************************************************************
Redirect
--------
Redirects to the specified URL
Inputs:
	string form: Target URL
*****************************************************************/
function Redirect(form)
{
	document.location = form;
}
/*****************************************************************
validarFecha
-----------
Validaci?n fecha ingresada con los combos
*****************************************************************/
function validarFecha(dia, mes, anio){
	var dteDate = new Date(anio,mes-1,dia);
	return ((dia==dteDate.getDate()) && ((mes-1)==dteDate.getMonth()) && (anio==dteDate.getFullYear()));
}

/*****************************************************************
compararFechas
-----------
Comparacion entre fechas
*****************************************************************/
function compararFechas(inicio, fin){
	return (Date.parse(inicio) <= Date.parse(fin));
}

/*exclusivas de jobs*/
/*****************************************************************
 * GetElementByName()
 * --------------------
 * obtiene el elemento hijo cuyo name es el pasado como parametro (es case sensitive)
 * Inputs:
 *		parent:elemento cuyo hijo se quiere buscar		
 *		name:nombre del elemento
 *		
 *
 *****************************************************************/
 function GetElementByName(parent,name){
 	var children=parent.childNodes;
 	var child=null;
 	//alert(parent.innerHTML+" - "+name); 
 	for(var i=0;i<children.length;i++){
 		//var childName=children[i].getAttribute("name");
 		var childName=children[i].name;
 		//alert("name: "+childName);
 		if(childName==name){
 			child=children[i];
 			break;
 		}
 	}
 	return child;
 }
 /*****************************************************************
 * GetRowById()
 * --------------------
 * obtiene la fila cuyo id es el pasado como parametro (es case sensitive)
 * Inputs:
 *		tabla:tabla cuya fila se quiere buscar		
 *		id:id de la fila.
 *		
 *
 *****************************************************************/
 function GetRowById(tabla,id){
 	var row=null;
 	tbody=tabla.getElementsByTagName("tbody")[0];
 	var elemento;
 	if(tbody!=null) 
 		elemento=tbody;
 	else
 		elemento=tabla;
 	//row=GetElement(id);
 	var filas=elemento.getElementsByTagName("tr");
 	for(var i=0;i<filas.length;i++){
 		if(filas[i].id==id){
 			row=filas[i];
 			break;
 		}
 	}
 	return row;
 }
 /*****************************************************************
 * GetCellById()
 * --------------------
 * obtiene la celda cuyo id es el pasado como parametro (es case sensitive)
 * Inputs:
 *		fila: fila cuya celda se quiere buscar		
 *		id:id de la celda.
 *		
 *
 *****************************************************************/
 function GetCellById(fila,id){
 	var cell=null;
 	var celdas=fila.getElementsByTagName("td");
 	for(var i=0;i<celdas.length;i++){
 		if(celdas[i].id==id){
 			cell=celdas[i];
 			break;
 		}
 	}
 	return cell;
 }
 /*******************************************************************
  * 
  * ----------------------
  * obtiene el indice de la opcion que tiene como value el valor pasado como par&aacute;metro
  * Inputs:
  *		options: array de opciones
  *		value: valor que tiene la op?n buscada	
  *******************************************************************/
 function getIndex(options,value){
		var index=0;
		//alert("opciones: "+options.innerHTML+" valor: "+value);
		for(var i=0;i<options.length;i++){
			if(options[i].value==value){
				index=i;
				break;
			}
		} 
		return index;
	}

function isNotMsie() {
	var navegador = navigator.appName;
	return (navegador!="Microsoft Internet Explorer");
	
//	var gko = navigator.userAgent.toLowerCase();
//	return (gko.indexOf('gecko')!=-1);
}

function validarTexto(texto) {
	if (texto.match(/^[a-zA-Z0-9 \'@_&ãâÂàÀêÊèÈîÎìÌõôÔòÒûÛùÙáéíóúÁÉÍÓÚñÑüÜ€%\.\*\#\+\-\$\/çÇ]*$/) && !texto.match(/^[\\']/) && !texto.match(/[\\']$/)){
		return true;
     } else {
	    alert("El texto ingresado debe ser alfanumérico");
    	return false;
    }
}