var objNav=new clsNav();

function clsNav() {
	var lstrNav='X';
	var lfltVersion=parseFloat(navigator.appVersion);
	switch(navigator.appName) {
		case 'Netscape':
			lstrNav='N';
			break;
		case 'Microsoft Internet Explorer':
			lstrNav='E';
			if(lfltVersion>=4.0)
				lfltVersion=parseFloat(navigator.appVersion.split(';')[1].replace(/\s+/g,'').slice(4));
	}
	this.strType	=	lstrNav;
	this.strVersion	=	lfltVersion;
	this.strStyleDisplayTableRow	=	( lstrNav=='E' ? 'block' : 'table-row' );
}
function popUp(pstrURL,pstrName,pintWidth,pintHeight,pstrAttr) {
	window.open(pstrURL,pstrName,MakeWindowAttrib(pintWidth,pintHeight,pstrAttr));
}
function RemoveSelectedItemFromSelect(pobj) {
	for(lintO=0;lintO<pobj.options.length;lintO++)
		if(pobj.options[lintO].value==pobj.value) {
			pobj.options[lintO]=null;
			break;
		}
}
function fillSelectFilteredBy(pobj,paTable,pstrColKeyToCompare,pstrValueToMatch,pstrDefaultCaption,pstrSelectedValue) {
	var intRows		=	0;
	var aColKeys	=	null;
	clearSelectItems(pobj, pstrDefaultCaption);
	for(var strRowKey in paTable) {
		if(aColKeys==null) {
			var aColKeys=new Array();
			for(var strColKey in paTable[strRowKey])
				aColKeys[aColKeys.length]=strColKey;
		}
		if(paTable[strRowKey][pstrColKeyToCompare]==pstrValueToMatch) {
			pobj.options[pobj.options.length]=new Option(paTable[strRowKey][aColKeys[1]],paTable[strRowKey][aColKeys[0]]);
			if(pstrSelectedValue!=undefined && pstrSelectedValue==paTable[strRowKey][aColKeys[0]])
				pobj.options[pobj.options.length-1].selected=true;
			intRows++;
		}
	}
	pobj.disabled=(intRows==0);
}
function clearSelectItems(pobj, pstrDefaultCaption) {
	if(pobj.options) {
		while(pobj.options.length>0)
			pobj.options[pobj.options.length-1]=null;
		if(pstrDefaultCaption!==undefined)
			pobj.options[0]=new Option(pstrDefaultCaption,'');
	}
}
function addSelectItem(pobj, pstrValue, pstrCaption) {
	pobj.options[pobj.options.length]=new Option(pstrCaption,pstrValue);
}
function AddStringKey(pstrKeys, pstrKey, pstrSep) {
	if(pstrSep===undefined) pstrSep="|";
	pstrKeys=RemoveStringKey(pstrKeys,pstrKey,pstrSep);
	if(pstrKeys!="")
		pstrKeys+=pstrSep;
	pstrKeys+=pstrKey;
	return pstrKeys;
}
function RemoveStringKey(pstrKeys, pstrKey, pstrSep) {
	if(pstrSep===undefined) pstrSep="|";
	aKeys=pstrKeys.split(pstrSep);
	aRes=new Array();
	for(var intK=0;intK<aKeys.length;intK++)
		if(aKeys[intK]!=pstrKey)
			aRes[aRes.length]=aKeys[intK];
	pstrKeys=aRes.join(pstrSep);
	return pstrKeys;
}
function padL(pstr,pintLength,pstrChar) {
	while(pstr.length<pintLength)
		pstr=pstrChar+pstr;
	return pstr;
}
function padR(pstr,pintLength,pstrChar) {
	while(pstr.length<pintLength)
		pstr=pstr+pstrChar;
	return pstr;
}
function trim(str, chars) {
    return ltrim(rtrim(str, chars), chars);
}
function ltrim(str, chars) {
    chars = chars || "\\s";
    return str.replace(new RegExp("^[" + chars + "]+", "g"), "");
}
function rtrim(str, chars) {
    chars = chars || "\\s";
    return str.replace(new RegExp("[" + chars + "]+$", "g"), "");
}
function formatDate(pintY,pintM,pintD) {
	return padL(pintD,2,"0")+"/"+getMonthName(pintM)+"/"+padL(pintY,4,"0");
}
function getMonthName(pintM) {
	return "Ene|Feb|Mar|Abr|May|Jun|Jul|Ago|Set|Oct|Nov|Dic".split("|")[pintM-1];
}
function globalX(pobj) {
	var llngLeft=pobj.offsetLeft;
	if(pobj.offsetParent)
		llngLeft+=globalX(pobj.offsetParent);
	return llngLeft;
}
function globalY(pobj) {
	var llngTop=pobj.offsetTop;
	if(pobj.offsetParent)
		llngTop+=globalY(pobj.offsetParent);
	return llngTop;
}
function objectPosX(pobj) {
	return pobj.offsetLeft;
}
function objectPosY(pobj) {
	return pobj.offsetTop;
}
function objectHeight(pobj) {
	return pobj.offsetHeight;
}
function objectWidth(pobj) {
	return pobj.offsetWidth;
}
function windowScrollTop() {
	var intScrollTop;
	if(window.pageYOffset)
		intScrollTop=window.pageYOffset;
	else if(document.documentElement && document.documentElement.scrollTop)
		intScrollTop=document.documentElement.scrollTop;
	else if(document.body)
		intScrollTop=document.body.scrollTop;
	return intScrollTop;
}
function windowWidth() {
	var intWidth;
	if(window.innerWidth)
		intWidth=window.innerWidth;
	else if(document.documentElement && document.documentElement.clientWidth)
		intWidth=document.documentElement.clientWidth;
	else if(document.body)
		intWidth=document.body.clientWidth;
	return intWidth;
}
function windowHeight() {
	var intHeight;
	if(window.innerHeight)
		intHeight=window.innerHeight;
	else if(document.documentElement && document.documentElement.clientHeight)
		intHeight=document.documentElement.clientHeight;
	else if(document.body)
		intHeight=document.body.clientHeight;
	return intHeight;
}
function moveObjectTo(pobj, pintX, pintY, pintXS, pintYS) {
	pobj.style.left	=	pintX+'px';
	pobj.style.top	=	pintY+'px';
	if(pintXS!==undefined)
		setObjectWidth(pobj, pintXS);
	if(pintYS!==undefined)
		setObjectHeight(pobj, pintYS);
}
function setObjectWidth(pobj, pintWidth) {
	if(pintWidth<0)
		pintWidth=0;
	pstrWidth=''+pintWidth+(pintWidth!='auto' ? 'px' : '');
	pobj.style.width	=	pstrWidth;
}
function setObjectHeight(pobj, pintHeight) {
	if(pintHeight<0)
		pintHeight=0;
	pstrHeight=''+pintHeight+(pintHeight!='auto' ? 'px' : '');
	pobj.style.height	=	pstrHeight;
}
function moveObjectInsideWindow(pobj, pintX, pintY) {
	intWST=windowScrollTop();
	intWSY=windowHeight();
	intSY=objectHeight(pobj);
	if(pintY-intWST+intSY>intWSY)
		pintY=intWST+intWSY-intSY;
	if(pintY<intWST)
		pintY=intWST;
	moveObjectTo(pobj, pintX, pintY);
}
function centerObject(pobj) {
	intSX=objectWidth(pobj);
	intSY=objectHeight(pobj);
	intWSX=windowWidth();
	intWSY=windowHeight();
	intX=Math.floor((intWSX-intSX)/2);
	intY=Math.floor((intWSY-intSY)/2);
	moveObjectTo(pobj, intX, intY);
}
function centerObjectInsideObject(pobj, pobjContainer, pintOffsetX, pintOffsetY) {
	if(pintOffsetX==undefined)	pintOffsetX=0;
	if(pintOffsetY==undefined)	pintOffsetY=0;
	intCSX	=	objectWidth(pobjContainer);
	intCSY	=	objectHeight(pobjContainer);
	intOSX	=	objectWidth(pobj);
	intOSY	=	objectHeight(pobj);
	intOPX	=	globalX(pobjContainer);
	intOPY	=	globalY(pobjContainer);
	intOPX	+=	Math.floor((intCSX-intOSX)/2);
	intOPY	+=	Math.floor((intCSY-intOSY)/2);
	moveObjectTo(pobj,intOPX+pintOffsetX,intOPY+pintOffsetY);
}

/* --- Código para redefinición del Objecto Select Multiple --- */
function fillFieldMultiple(pstrSuffix) {
	var aList				=	eval('fld_'+pstrSuffix);
	var objColLeft			=	document.getElementById('objM_CL_'+pstrSuffix);
	var objFieldHidden		=	document.getElementById('objM_FH_'+pstrSuffix);
	var objFieldSelectGroup	=	document.getElementById('objM_SG_'+pstrSuffix);
	var aKeys				=	objFieldHidden.value.split("|");
	var objKeys				=	new Array();
	var objOption;
	if(objFieldSelectGroup.options) {
		if(objFieldHidden.value=='' && objFieldSelectGroup.options[0].value!='N')
			objFieldHidden.value='0';	// Auto-corregir posible incoherencia de datos. Si estaba grabado '' pero no se permite elegir 'Nadie', entonces debe ser 'Todos'.
		switch(objFieldHidden.value) {
			case ''		:	objFieldSelectGroup.value='N'; break;
			case '0'	:	objFieldSelectGroup.value='T'; break;
			default		:	objFieldSelectGroup.value='A';
		}
	}
	for(var intK=0; intK<aKeys.length; intK++)
		objKeys[aKeys[intK]]='1';
	for(var strKey in aList)
		if(strKey!='' && strKey!='0' && aList[strKey]!='') {
			objOption=new Option(aList[strKey],strKey);
			if(objKeys[strKey])
				objOption.selected=true;
			objColLeft.options[objColLeft.options.length]=objOption;
		}
	addOneToFieldMultiple(pstrSuffix,false);
	hndOnChangeFieldMultiple(pstrSuffix);
}
function addOneToFieldMultiple(pstrSuffix, pblnSyncHidden) {
	moveBetweenFieldMultiple(pstrSuffix, 'objM_CL_', 'objM_CR_', false);
	if(pblnSyncHidden==undefined)
		pblnSyncHidden=true;
	if(pblnSyncHidden)
		hndOnChangeFieldMultiple(pstrSuffix);
}
function hndOnChangeFieldMultiple(pstrSuffix) {
	var objFieldSelectGroup	=	document.getElementById('objM_SG_'+pstrSuffix);
	var objFieldHidden		=	document.getElementById('objM_FH_'+pstrSuffix);
	switch(objFieldSelectGroup.value) {
		case 'N'	:	objFieldHidden.value=''; break;
		case 'A'	:	syncFieldMultipleHidden(pstrSuffix); break;
		case 'T'	:	objFieldHidden.value='0'; break;
	}
	var objColLeft		=	document.getElementById('objM_CL_'+pstrSuffix);
	var objColRight		=	document.getElementById('objM_CR_'+pstrSuffix);
	var objCmdAddOne	=	document.getElementById('objM_A1_'+pstrSuffix);
	var objCmdAddAll	=	document.getElementById('objM_AA_'+pstrSuffix);
	var objCmdDelOne	=	document.getElementById('objM_R1_'+pstrSuffix);
	var objCmdDelAll	=	document.getElementById('objM_RA_'+pstrSuffix);
	objColLeft.disabled=objColRight.disabled=(objFieldSelectGroup.value!='A');
	syncFieldMultipleCommands(pstrSuffix, 'objM_CL_', 'objM_A');
	syncFieldMultipleCommands(pstrSuffix, 'objM_CR_', 'objM_R');
}
function syncFieldMultipleHidden(pstrSuffix) {
	var objSelect		=	document.getElementById('objM_CR_'+pstrSuffix);
	var objFieldHidden	=	document.getElementById('objM_FH_'+pstrSuffix);
	var strKeys			=	'';
	var objOption;
	for(var intO=0; intO<objSelect.options.length; intO++) {
		if(strKeys!='')
			strKeys+='|';
		strKeys+=objSelect.options[intO].value;
	}
	objFieldHidden.value=strKeys;
}
function addAllToFieldMultiple(pstrSuffix) {
	moveBetweenFieldMultiple(pstrSuffix, 'objM_CL_', 'objM_CR_', true);
	hndOnChangeFieldMultiple(pstrSuffix);
}
function delOneFromFieldMultiple(pstrSuffix) {
	moveBetweenFieldMultiple(pstrSuffix, 'objM_CR_', 'objM_CL_', false);
	hndOnChangeFieldMultiple(pstrSuffix);
}
function delAllFromFieldMultiple(pstrSuffix) {
	moveBetweenFieldMultiple(pstrSuffix, 'objM_CR_', 'objM_CL_', true);
	hndOnChangeFieldMultiple(pstrSuffix);
}
function moveBetweenFieldMultiple(pstrSuffix, pstrFrom, pstrTo, pblnAll) {
	var objFrom	=	document.getElementById(pstrFrom+pstrSuffix);
	var objTo	=	document.getElementById(pstrTo+pstrSuffix);
	var objOption;
	for(var intO=0; intO<objFrom.options.length; intO++)
		if(pblnAll || objFrom.options[intO].selected) {
			objOption=new Option(objFrom.options[intO].text, objFrom.options[intO].value);
			objFrom.options[intO]=null;
			objTo.options[objTo.options.length]=objOption;
			intO--;
		}
}
function syncFieldMultipleCommands(pstrSuffix, pstrList, pstrCmd) {
	var objFieldSelectGroup	=	document.getElementById('objM_SG_'+pstrSuffix);
	var objSelect			=	document.getElementById(pstrList+pstrSuffix);
	var objCmdOne			=	document.getElementById(pstrCmd+'1_'+pstrSuffix);
	var objCmdAll			=	document.getElementById(pstrCmd+'A_'+pstrSuffix);
	objCmdOne.disabled		=	(objSelect.options.length==0 || objFieldSelectGroup.value!='A');
	objCmdAll.disabled		=	(objSelect.options.length==0 || objFieldSelectGroup.value!='A');
}
/* --- ---------------------------------------------------- --- */
function setCheckboxes(pobjFormField, pblnStatus) {
	for(var intI=0;intI<pobjFormField.length;intI++)
		pobjFormField[intI].checked=(pblnStatus===null ? !pobjFormField[intI].checked : pblnStatus);
}
/* --- ---------------------------------------------------- --- */
function syncFieldDate(pobj, pstrPrefix) {
	var strDate		=	''+pobj.selection.get();
	var objDay		=	document.getElementById('obj'+pstrPrefix+'_D');
	var objMonth	=	document.getElementById('obj'+pstrPrefix+'_M');
	var objYear		=	document.getElementById('obj'+pstrPrefix+'_Y');
	objDay.value	=	strDate.substr(6,2);
	objMonth.value	=	strDate.substr(4,2);
	objYear.value	=	strDate.substr(0,4);
	if(objDay.onchange)
		objDay.onchange();
	pobj.hide();
}
function hndFieldDate(pstrPrefix,pstrSubField,pblnKeyUp) {
	var objField	=	document.getElementById('obj'+pstrPrefix+'_'+pstrSubField);
	var strNext, intLength;
	if(!pblnKeyUp)
		objField.strOldLength=objField.value.length;
	else {
		switch(pstrSubField) {
			case 'D':	intLength=2; strNext='M'; break;
			case 'M':	intLength=2; strNext='Y'; break;
			case 'Y':	intLength=4; strNext=null; break;
		}
		if(strNext!=null && objField.strOldLength==intLength-1 && objField.value.length==intLength) {
			objField=document.getElementById('obj'+pstrPrefix+'_'+strNext);
			objField.focus();
		}
	}
}
/* --- ---------------------------------------------------- --- */
function setCookie(pstrName, pstrValue) {
	var lobjDate = new Date();
	lobjDate.setTime(lobjDate.getTime()+(365*24*60*60*1000));
	var lstrExpires = 'expires=' + lobjDate.toGMTString() + '; ';
	document.cookie = pstrName + '=' + pstrValue + '; ' + lstrExpires;
}
function getCookie(pstrName) {
	var lstrSearch = pstrName + '=';
	var laCookies = document.cookie.split(';');
	for(var lintI=0; lintI < laCookies.length; lintI++) {
		var lstrCookie = laCookies[lintI];
		while(lstrCookie.charAt(0)==' ')
			lstrCookie = lstrCookie.substring(1,lstrCookie.length);
		if(lstrCookie.indexOf(lstrSearch) == 0)
			return lstrCookie.substring(lstrSearch.length,lstrCookie.length);
	}
	return null;
}
function str_repeat(pstrChar, pintRepeat) {
	var strReturn='';
	for(var intR=1;intR<=pintRepeat;intR++)
		strReturn+=pstrChar;
	return strReturn;
}
/* --- ---------------------------------------------------- --- */
function getFieldValue(pstrFieldName) {
	var objField=document.getElementById(pstrFieldName);
	return ( objField ? objField.value : null );
}
function setFieldValue(pstrFieldName, pstrFieldValue, pblnMustBeNumeric, pblnLock, pintDecimals) {
	var objField=document.getElementById(pstrFieldName);
	if(pblnMustBeNumeric==undefined)	pblnMustBeNumeric	=	false;
	if(pblnLock==undefined)				pblnLock			=	false;
	if(pintDecimals==undefined)			pintDecimals		=	2;
	if(pblnMustBeNumeric) {
		if(isFloat(pstrFieldValue)) {
			pstrFieldValue=formatNumber(floatval(pstrFieldValue),pintDecimals);	//formatNumber(pstrFieldValue,"###'###'###."+str_repeat('0',pintDecimals));
		} else
			pstrFieldValue='';
	}
	objField.value=pstrFieldValue;
	if(pblnLock) {
		if(!objField.readOnly)
			objField.strClassName=objField.className;
		objField.readOnly=true;
		if(objField.className.search(/ReadOnly/)==-1)
			objField.className+=' ReadOnly';
	} else {
		objField.readOnly=false;
		if(objField.strClassName)
			objField.className=objField.strClassName;
	}
}
function getFieldSelectText(pstrFieldName) {
	var objField=document.getElementById(pstrFieldName);
	var strReturn=null;
	if(objField) {
		if(objField.selectedIndex)
			strReturn=(objField.selectedIndex>0 ? objField.options[objField.selectedIndex].text : '');
		else
			strReturn=objField.value;
	}
	return strReturn;
}
function floatval(pstrValue) {
	pstrValue=''+pstrValue;
	pstrValue=pstrValue.replace(/\'/g,'').replace(/,/g,'').replace(/\s/g,'');
	return ( isNaN(pstrValue) ? NaN : parseFloat(pstrValue) );
}
function isFloat(pstrValue) {
	var objRegExp=/^\-?(((((\d{1,3}[\',\s]?\d{3}|\d{1,3})?[,\s]?\d{3}|\d{1,3})?[\',\s]?\d{3}|\d{1,3})?[,\s]?\d{3})|\d{1,3})?(\.\d+)?$/;
	return objRegExp.test(pstrValue);
}
function isFieldFloat(pstrFieldId) {
	var objField=(typeof(pstrFieldId)=='string' ? document.getElementById(pstrFieldId) : pstrFieldId );
	var blnIsFloat=isFloat(objField.value);
	var strClassName=objField.className.replace(' error ','');
	if(!blnIsFloat)
		strClassName+=' error ';
	objField.className=strClassName;
	return blnIsFloat;
}
function getFieldFloatValue(pstrFieldId) {
	var objField=document.getElementById(pstrFieldId);
	isFieldFloat(pstrFieldId);
	return floatval(objField.value);
}
function buildShadow(pobj, pintOffset, pfltOpacity) {
	if(pobj.objShadow==undefined) {
		if(pintOffset==undefined)	pintOffset	=	5;
		if(pfltOpacity==undefined)	pfltOpacity	=	0.1;
		pobj.intShadowOffset	=	pintOffset;
		pobj.fltShadowOpacity	=	pfltOpacity;
		pobj.objShadow=document.createElement('div');
		document.body.appendChild(pobj.objShadow);
		pobj.objShadow.style.backgroundColor='black';
		pobj.objShadow.style.filter='alpha(opacity='+(pfltOpacity*100)+')';
		pobj.objShadow.style.opacity=pfltOpacity;
		pobj.objShadow.style.position='absolute';
		pobj.objShadow.style.zIndex=100;
		pobj.style.zIndex=101;
	}
	refreshShadow(pobj);
}
function refreshShadow(pobj) {
	moveObjectTo(pobj.objShadow, objectPosX(pobj)+pobj.intShadowOffset, objectPosY(pobj)+pobj.intShadowOffset, objectWidth(pobj), objectHeight(pobj) );
	pobj.objShadow.style.display='block';
}
function hideShadow(pobj) {
	pobj.objShadow.style.display='none';
}
function destroyShadow(pobj) {
	if(pobj.objShadow)
		document.body.removeChild(pobj.objShadow);
}
function destroyChild(pobjContainer, pobj) {
	pobjContainer.removeChild(pobj);
}
/* --- ---------------------------------------------------- --- */
function getPathExtension(pstrPath) {
	var intDotPos=pstrPath.lastIndexOf('.');
	if(intDotPos>=0)
		strExtension=pstrPath.substr(intDotPos+1);
	else
		strExtension='';
	return strExtension;
}
/* --- ---------------------------------------------------- --- */
Date.prototype.add = function (sInterval, iNum){
  var dTemp = this;
  if (!sInterval || iNum == 0) return dTemp;
  switch (sInterval.toLowerCase()){
    case "ms":
      dTemp.setMilliseconds(dTemp.getMilliseconds() + iNum);
      break;
    case "s":
      dTemp.setSeconds(dTemp.getSeconds() + iNum);
      break;
    case "mi":
      dTemp.setMinutes(dTemp.getMinutes() + iNum);
      break;
    case "h":
      dTemp.setHours(dTemp.getHours() + iNum);
      break;
    case "d":
      dTemp.setDate(dTemp.getDate() + iNum);
      break;
    case "mo":
      dTemp.setMonth(dTemp.getMonth() + iNum);
      break;
    case "y":
      dTemp.setFullYear(dTemp.getFullYear() + iNum);
      break;
  }
  return dTemp;
}
/* --- ---------------------------------------------------- --- */
function clearSelectOptions(pobjSelect) {
	while(pobjSelect.options.length>1)
		pobjSelect.options[pobjSelect.options.length-1]=null;
}
