/**********************************************
** Obtiene la fila padre(<TR>) del objeto dado  
*************************************************/
function getParentRow(object){
	return getParentElement(object,"TR");
}			
/*********************************************************
** Obtiene el elemento padre mas proximo de tipo tag del objeto dado 
*************************************************/
function getParentElement(object, tag){
	var parentObj=object;
	do{
		parentObj=parentObj.parentElement;	
	}while(parentObj.tagName!=tag);	
	return parentObj;			
}

function inArray(start, el){   
   for (i = start; i < this.length; i++)
   {
   if (el == this[i])
		return i;//return the index of the element  
   }
   return -1;//not found
}

Array.prototype.search = inArray;

/*********************************************************
** TRIM
*************************************************/
function str_trim(){
	var x=this;
	var _start,_end;			
		
	for(i=0;i<x.length && x.charAt(i)==' ';i++);
	_start = i;
	
	if(_start==x.length)return '';
	
	for(i=x.length-1;i>=0 && x.charAt(i)==' ';i--);	
	_end=i+1;
	return x.substring(_start,_end);
}
function str_lPad(n,c){
	_t = c + this;
	while(t.length<n)
		_t = c + t;	
	return (this.substr(0,n));
	
}

/**********************************************
** Obtiene un objeto fecha de una cadena dd/mm/yyyy
*************************************************/
function _toDate(){	
	var dp = this.split("/");	
	if(dp.length!=3)return null;	
	return new Date(dp[2],dp[1]-1,dp[0]);
}			

String.prototype.trim=str_trim;
String.prototype.leftPad=str_lPad;
String.prototype.toDate=_toDate;
/*********************************************************
** reemplaza la funcion objetivo de los elemento A hacia una funcion 
* proxy intermedia que puede ser utilizado para realizar validaciones previas.
*************************************************/
function setCmdProxy(dataGrid){
	var datagrid = document.all(dataGrid);
	if(datagrid==null)return; 
	var links = datagrid.getElementsByTagName("A");
	//if(links==null)return;
	for(i=0;i<links.length;i++){
		href = links[i].href;			
		k = href.indexOf("__doPostBack");
		if(k<0)continue;
		h=href.lastIndexOf("_ctl");
		f=href.indexOf("'",h);
		links[i].href='javascript:callPostBack(\"' 
			+ links[i].href.substr(k) + '\",' + href.substring(h+4,f) + ');';										
	}
}

/********************************************************************
*Valida el ingreso de caracteres a un control de texto
*
*********************************************************************/
var DEC_PATTERN=/\d{0,}\.?\d{0,2}/;
var SDEC_PATTERN=/\-?\d{0,}\.?\d{0,2}/;
var DBL_PATTERN=/\d{0,}\.?\d{0,}/;
var INT_PATTERN=/\d{0,}/;
var SINT_PATTERN=/\-?\d{0,}/;
var FEC_PATTERN=/\d{0,2}\/?\d{0,2}\/?\d{0,4}/; 
var TEL_PATTERN=/(\d{0,}\-*)*/; 

function validKey(format){
	var text = event.srcElement.value + String.fromCharCode(event.keyCode);
	var arr = format.exec(text);
	return (arr!=null && text==arr[0]);
}
/********************************************************************
*Valida el texto de un contro de texto como dato fecha
*
*********************************************************************/
function validDate(){
	var text = event.srcElement.value.trim();
	if(text=='')return true;
	var arDate=text.split("/");	
	if(arDate.length==3){
		var aDate = new Date(arDate[2],arDate[1]-1,arDate[0]);
		var blnRet = (aDate.getFullYear()==arDate[2]&&aDate.getMonth()==arDate[1]-1&&aDate.getDate()==arDate[0]);
	}
	if(arDate.length!=3 || !blnRet){
		event.returnValue=false;
		alert("Fecha No Valida");
		event.srcElement.select();
		event.srcElement.focus();
	}
	return blnRet;
}
/********************************************************************
*Compara dos fechas
*********************************************************************/
function date_isBefore(d){	
	d1=this.getFullYear()*10000 + (this.getMonth()+1)*100 + this.getDate();
	d2=d.getFullYear()*10000 + (d.getMonth()+1)*100 + d.getDate();		
	return (d1<d2);
}
Date.prototype.isBefore=date_isBefore;
/**********************************************
** Habilita/Deshabilita un formulario(y todos sus elementos) 
*************************************************/
function enableForm(frm, b){	
	var elems = frm.elements;	
	for(i=0;i<elems.length;i++){		
		if(elems[i].tagName=='INPUT' && (elems[i].type=='image'||elems[i].type=='hidden'))
			continue;		
		elems[i].disabled=!b;		
	}
}			
/**********************************************
** Determina si existe al menos un elemento seleccionado 
*************************************************/
function isAnyChecked(frm, chkFld){
	var chks = frm.elements(chkFld);
	if(chks==null)return false;
	if(typeof chks.length=='undefined') return (chks.checked);
	for(i=0;i<chks.length;i++){
		if(chks[i].checked)return true;
	}
	return false;
}

/**********************************************
** Devuelve el primer elemento seleccionado
*************************************************/
function getSelected(frm, chkFld){
	var chks = frm.elements(chkFld);
	if(chks==null)return null;
	if(typeof chks.length=='undefined') return (chks.checked?chks:null);
	
	for(i=0;i<chks.length;i++){
		if(chks[i].checked)return chks[i];
	}
	return null;
}

/**********************************************
** Limpia el texto del usuario solicitante
*************************************************/
function deleteText(object, control){
	if(event.keyCode==46){
		object.value='';
		control.value='';
	}	
}
/**********************************************
** controla tamaņo de un TEXTAREA
*************************************************/
var _EVT_PASTE=1;
var _EVT_KEYPRESS=2;

function checkSize(size){
	var _txa = event.srcElement;
 if(event.type=='keypress'){
	if(_txa.value.length>=size)event.keyCode=0;	
 }else if(event.type=='paste'){
	var ttp = window.clipboardData.getData("Text");
	if(_txa.value.length+ttp.length>size)
		event.returnValue=false; 
 }

}

/**********************************************
** crea una ventana popup
*************************************************/
function openWindow(url,w,h){
	
	var opciones="toolbar=no,location=no, directories=no,status=yes, menubar=no, scrollbars=yes, resizable=no, width=" + w + ", height=" + h + " ";
    win=window.open(url,"_blank",opciones);
	//win=window.showModalDialog(url,opciones);
	win.moveTo(400,300);
	win.focus();
	
	
	//var win = window.open(url,"_blank","width=" + w + ",height="+ h+ ",status=yes,toolbar=no,scrollbar=yes,menubar=no",true);
	//win.focus();
	return win;	
}

/**********************************************
** Muestra o Oculta filas de una tabla
*************************************************/
function MostrarOcultar(mostrar,ocultar)
{
		
	objM=document.getElementById(mostrar);
	objO=document.getElementById(ocultar);
	
	objM.style.display='block';
	objO.style.display='none';
	
     
}

/**********************************************
** Muestra o Oculta filas de una tabla
*************************************************/
function Expand(mostrar)
{
		
	objM=document.getElementById(mostrar);
	objO=document.getElementById(ocultar);
	
	objM.style.display='block';
	objO.style.display='none';
	
     
}

/**********************************************
** Devuelve false si esta vacio y viceversa
*************************************************/
function esnulo(campo){
  if ( campo == "" ){
	
    return false
  } else {
	
    return true
  }
}

