
/*
** Captura de eventos para controlar si se invierte o no el destino de ventanas 
** que se abren utilizando la función openWindow() o sus variantes.
*/
var bInvertOpenWindowTarget = false;
var oInvertOpenWindowTargetTimeout = null;
if (document) {
	// Ctrl Key = 17
	function eF_OnKeyDown(e) {
		var iKeyCode = ((document.all) ? event.keyCode : e.which);
    
    if (iKeyCode == 17) {
			
			if (oInvertOpenWindowTargetTimeout) {
				clearTimeout(oInvertOpenWindowTargetTimeout);
				oInvertOpenWindowTargetTimeout = null;
			};
			
			bInvertOpenWindowTarget = true;
			
		} else {
			
			// 20071129 ddignazi
			bInvertOpenWindowTarget = false;
			
		};
	};
	
	function eF_OnKeyUp(e) {
    var iKeyCode = ((document.all) ? event.keyCode : e.which);
    
    if (iKeyCode == 17) {
			oInvertOpenWindowTargetTimeout = window.setTimeout("bInvertOpenWindowTarget = false;", 10);
		};
	};
	
	try {
		Event.observe(document, "keydown", eF_OnKeyDown, false);
		Event.observe(document, "keyup", eF_OnKeyUp, false);
	} catch (e) {
		// missing prototype.js ?
	};
};

/*
** Control de una especie de "velo" para bloquear las acciones sobre 
** la página mientras existe un diálogo abierto.
*/
var oVeil = null;
function showVeil() {
	if (!oVeil) {
		oVeil = document.createElement("div");
		oVeil.className = "VeilStyle1";
		oVeil.style.zIndex = 10000;
		oVeil.innerHTML = "&nbsp;";
		document.body.appendChild(oVeil);
	};
	resizeVeil();
	oVeil.style.display = "block";
	try {
		Event.observe(window, "resize", resizeVeil, false);
	} catch (e) {
		// missing prototype.js ?
	};
};
function resizeVeil() {
	if (oVeil) {
		oVeil.style.width = document.body.scrollWidth;
		oVeil.style.height = document.body.scrollHeight;
	};
};
function hideVeil() {
	if (oVeil) {
		oVeil.style.display = "none";
		document.body.removeChild(oVeil);
		oVeil = null;
	};
};

/*
** Reconocimiento del contexto de ejecución (framed o frameless)
*/
function isContextVisible() {
	return isFrameVisible('MenuBar');
};

function isFrameVisible(sFrameName) {
	try {
		var oTopWnd = window;
		var bSearch = true;
		var iIndex = 0;
		var bContextVisible = false;
		
		if (oTopWnd.dialogTop) return true;
		
		while (bSearch && !bContextVisible) {
			oTopWnd = oTopWnd.top;
			
			for(iIndex=0; iIndex<oTopWnd.frames.length; iIndex++) {
				if (oTopWnd.frames[iIndex].name == sFrameName) bContextVisible = true;
			};
			
			if (oTopWnd.opener && oTopWnd.opener != oTopWnd) {
				oTopWnd = oTopWnd.opener;
			} else {
				bSearch = false;
			};
		};
		
		return bContextVisible;
	} catch(e) {
		return true;
	};
};

if (isContextVisible()) {
	document.cookie = 'eFrameworkVisible=1;path=/';
};

/*
** Funciones para abrir ventanas o diálogos
*/
var oCurrentCallbackFunction = null;

function notifyDialogUnload() {
	var oInCallback;
	hideVeil();
	if (oCurrentCallbackFunction) {
		oInCallback = oCurrentCallbackFunction;
		oCurrentCallbackFunction.call();
		if (oInCallback == oCurrentCallbackFunction) {
			oCurrentCallbackFunction = null;
		};
		oInCallback = null;
	};
};

function openWindow(sURL, sName, sFeatures, bReplace, bAudit, bPOST, bUnescapeURL) {
	var oWnd;
	var oForm, sTargetWnd = '';
	
	oForm = getInternalForm();
	
	if (!sName || sName == 'undefined') sName = '_blank';
	sFeatures = parseWindowFeatures(sFeatures);
	if (bReplace != true && bReplace != false) bReplace = true;
	if (bPOST != true && bPOST != false) bPOST = true;
	
	// 20071227 ddignazi: compatibilidad con el protocolo "mailto:" cuando el argumento "body" contiene saltos de línea
	if (bUnescapeURL != true && bUnescapeURL != false) bUnescapeURL = false;
	if (bUnescapeURL) sURL = unescape(sURL);
	sURL = replaceAll(sURL, new RegExp('\n'), '%0a');
	
	// Invierte el destino de la página que se intenta navegar.
	if (bInvertOpenWindowTarget) {
		if (sName == '_blank') {
			sName = '_self';
		} else if (sName == '_self' || sName == 'Main') {
			sName = '_blank';
		};
		bInvertOpenWindowTarget = false;
	};
	
	// Si no se habilita o deshabilita la auditoría en forma explícita se considera 
	// la configuración para el sistema vigente (parámetro NivelAuditoriaActivo).
	if (bAudit != false && bAudit != true) bAudit = parAuditarURLs;
	
	// Deshabilita la auditoría cuando se navega "run.asp".
	if (isRunPage(sURL)) bAudit = false;
	
	// Deshabilita la auditoría en los paneles reservados de eFramework.
	if (sName == 'Header' || sName == 'TopBar' || sName == 'MenuBar' || sName == 'RightBar') bAudit = false;
	
	// Si la URL ya había sido accedida y no previene el caché del navegador, se fuerza el acceso
	// al servidor incorporando un argumento "nocache" con valor aleatorio. Esto no impide
	// que el navegador guarde el resultado en caché y permita la navegación con los botones "Back" y "Forward"
	// (si la página lo permite).
	if (!(bPOST && oForm)) {
		sURL = addParamToURL(sURL, 'nocache', parseInt(Math.random() * 50000, 10));
	};
	
	// Si la auditoría está habilitada siempre se redirecciona la llamada a "run.asp".
	if (bAudit) sURL = parRoot + 'run.asp?url=' + escape(sURL);
	
	// Parámetros que le indican a eFramework como se procesó orignalmente
	// la página que está invocando a otra.
	document.cookie = 'sistemaOriginal=' + escape(parSistemaOriginal) + ';path=/';
	document.cookie = 'paginaProcesada=' + escape(parPaginaProcesada) + ';path=/';
	
	// Parámetro que informa el contexto de ejecución de la nueva página (framed o frameless).
	if (isContextVisible()) {
		document.cookie = 'eFrameworkVisible=1;path=/';
	};

	// Parámetro para indicarle a eFramework que la petición HTTP GET no fue escrita
	// por el usuario en la barra de direcciones del navegador.
	document.cookie = 'urlPeticion=' + escape(sURL) + ';path=/';
	
	// Invoca la URL recibida como argumento.
	if (bPOST && oForm) {
		
		if (sName == '_blank') {
			
			sTargetWnd = 'eF' + parseInt(Math.random() * 50000, 10);
			
			oWnd = window.open('about:blank', sTargetWnd, sFeatures, bReplace);
			
			// Intenta dar foco a la nueva ventana.
			try {	
				if (oWnd && !oWnd.closed) oWnd.focus();
			} catch(e) {
				 // 
			};
			
		} else {		
			
			sTargetWnd = sName;
			
		};
		
		oForm.action = sURL;
		oForm.target = sTargetWnd;
		oForm.submit();
		
	} else {
		
		oWnd = window.open(sURL, sName, sFeatures, bReplace);
		
		// Intenta dar foco a la nueva ventana.
		try {	
			if (oWnd && !oWnd.closed) oWnd.focus();
		} catch(e) {
			 // Si la ventana destino se trata de un <FRAME> no se puede dar el foco.
		};
	
	};
	
	// Retorna el objeto "window" que se creó para invocar la URL.
	return oWnd;
};

function openWindowCallback(sURL, pfNotify, bUseDialog, sFeatures, bAudit, sName) {
	var oWnd = null;
	
	// 20070907 ddignazi: bUseDialog deprecated
	
	// Muestra una especie de "velo" en la página que bloquea los eventos de la misma
	// hasta tanto no se cierre la ventana de diálogo que se intenta abrir.
	showVeil();
	
	sURL = parRoot + 'utils/dialog.asp?url=' + escape(sURL);
	
	// Parámetro para indicar a eFramework que se está invocando a una ventana de diálogo
	// la cual no puede auditarse a través de "run.asp" porque la redirección de esta última
	// dispararía un evento "unload" que interfiere con la necesidad de "callback".
	if (bAudit) {
		document.cookie = 'ventanaDialogo=1;path=/';
	};
	
	oWnd = openWindow(sURL, sName, sFeatures, true, false, false);
	
	if (oWnd) {
		oCurrentCallbackFunction = pfNotify;
	} else {
		oWnd = null;
		oCurrentCallbackFunction = null;
		hideVeil();
	};
	
	return oWnd;
};

function submitForm(oForm) {
	// Parámetro que informa el contexto de ejecución de la nueva página (framed o frameless).
	if (isContextVisible()) {
		document.cookie = 'eFrameworkVisible=1;path=/';
	};
	
	// Envía el formulario mediante un HTTP POST.
	oForm.submit();
};

function openModalDialog(sURL, vArguments, sFeatures, bAudit) {
	var vReturn;
	
	if (!vArguments) vArguments = null;
	sFeatures = parseDialogFeatures(sFeatures);

	// Si la URL ya había sido accedida y no previene el caché del navegador, se fuerza el acceso
	// al servidor incorporando un argumento "nocache" con valor aleatorio. Esto no impide
	// que el navegador guarde el resultado en caché y permita la navegación con los botones "Back" y "Forward"
	// (si la página lo permite).
	sURL = addParamToURL(sURL, 'nocache', parseInt(Math.random() * 50000, 10));
	
	// Parámetros que le indican a eFramework como se procesó orignalmente
	// la página que está invocando a otra.
	document.cookie = 'sistemaOriginal=' + escape(parSistemaOriginal) + ';path=/';
	document.cookie = 'paginaProcesada=' + escape(parPaginaProcesada) + ';path=/';
	
	// Parámetro que informa el contexto de ejecución de la nueva página (framed o frameless).
	if (isContextVisible()) {
		document.cookie = 'eFrameworkVisible=1;path=/';
	};

	// Parámetro para indicarle a eFramework que la petición HTTP GET no fue escrita
	// por el usuario en la barra de direcciones del navegador.
	document.cookie = 'urlPeticion=' + escape(sURL) + ';path=/';

	// Parámetro para indicar a eFramework que se está invocando a una ventana de diálogo
	// la cual no puede auditarse a través de "run.asp" porque la redirección de esta última
	// dispararía un evento "unload" que interfiere con la necesidad de callback.
	if (bAudit) {
		document.cookie = 'ventanaDialogo=1;path=/';
	};
	
	// Invoca la URL recibida como argumento en una ventana de diálogo "modal".
	vReturn = window.showModalDialog(sURL, vArguments, sFeatures);
	
	// Retorna el valor que devolvió la ventana de diálogo.
	return vReturn;
};

function openModelessDialog(sURL, vArguments, sFeatures, bAudit) {
	var oWnd;
	
	if (!vArguments) vArguments = null;
	sFeatures = parseDialogFeatures(sFeatures);

	// Si la URL ya había sido accedida y no previene el caché del navegador, se fuerza el acceso
	// al servidor incorporando un argumento "nocache" con valor aleatorio. Esto no impide
	// que el navegador guarde el resultado en caché y permita la navegación con los botones "Back" y "Forward"
	// (si la página lo permite).
	sURL = addParamToURL(sURL, 'nocache', parseInt(Math.random() * 50000, 10));
	
	// Parámetros que le indican a eFramework como se procesó orignalmente
	// la página que está invocando a otra.	
	document.cookie = 'sistemaOriginal=' + escape(parSistemaOriginal) + ';path=/';
	document.cookie = 'paginaProcesada=' + escape(parPaginaProcesada) + ';path=/';
	
	// Parámetro que informa el contexto de ejecución de la nueva página (framed o frameless).
	if (isContextVisible()) {
		document.cookie = 'eFrameworkVisible=1;path=/';
	};

	// Parámetro para indicarle a eFramework que la petición HTTP GET no fue escrita
	// por el usuario en la barra de direcciones del navegador.
	document.cookie = 'urlPeticion=' + escape(sURL) + ';path=/';

	// Parámetro para indicar a eFramework que se está invocando a una ventana de diálogo
	// la cual no puede auditarse a través de "run.asp" porque la redirección de esta última
	// dispararía un evento "unload" que interfiere con la necesidad de callback.
	if (bAudit) {
		document.cookie = 'ventanaDialogo=1;path=/';
	};
	
	// Invoca la URL recibida como argumento en una ventana de diálogo.
	oWnd = window.showModelessDialog(sURL, vArguments, sFeatures);
	if (oWnd) oWnd.focus();
	
	// Retorna el objeto "window" que se creó para la ventana de diálogo.
	return oWnd;
};

function navigateURL(sURL, bAudit, bPOST, bUnescapeURL) {
	openWindow(sURL, '_self', null, null, bAudit, bPOST, bUnescapeURL);
};

function openLink(oAnchor, sURL, sFeatures, bAudit, bPOST, bUnescapeURL) {
	var oWnd = null;
	
	if (oAnchor) {
		if (sURL) 
			oWnd = openWindow(sURL, oAnchor.target, sFeatures, null, bAudit, bPOST, bUnescapeURL);
		else
			oWnd = openWindow(oAnchor.href, oAnchor.target, sFeatures, null, bAudit, bPOST, bUnescapeURL);
	};
	
	return oWnd;
};

function openLinkTarget(sURL, sTarget, sFeatures, bAudit, bPOST, bUnescapeURL) {
	if (sTarget) 
		openWindow(sURL, sTarget, sFeatures, null, bAudit, bPOST, bUnescapeURL);
	else
		openWindow(sURL, '_blank', sFeatures, null, bAudit, bPOST, bUnescapeURL);
};

function noop() {};

/*
** Funciones para invocar buscadores y navegadores básicos.
*/
function browseTemplatesFolder(sFolder) {
	browseFolder(sFolder);
};

function browseFolder(sFolder) {
	var sURL = parRoot + 'utils/fsExplorer/fsExplorer.asp';
	
	sURL = addParamToURL(sURL, 'carpetaRuta', sFolder);
	
	openWindow(sURL, '_blank', 'height=500px, width=700px');
};

function openOption(iId, sName, sParams, sFeatures, bReplace, bAudit) {
	var sURL = parRoot + 'run.asp';
	
	sURL = addParamToURL(sURL, 'opcion', iId);
	if (sParams && sParams != '') {
		sURL += '&' + sParams;
	};
	
	openWindow(sURL, sName, sFeatures, bReplace, bAudit);
};

function openMenu(iContainer, sId, sParams, sName, sFeatures, bReplace, bAudit) {
	var sURL = parRoot + 'run.asp';
	
	sURL = addParamToURL(sURL, 'sistema', iContainer);
	if (isNaN(sId)) {
		sURL = addParamToURL(sURL, 'menuId', sId);
	} else {
		sURL = addParamToURL(sURL, 'menu', sId);
	};
	if (sParams && sParams != '') {
		sURL += '&' + sParams;
	};
	
	openWindow(sURL, sName, sFeatures, bReplace, bAudit);
};

function searchByExplorer(sId, sCallbackFunctionName, bMultipleSelection, sTitle, sParams, sDefaultFilter) {
	var oSearch, oFilter;
	
	oSearch = reCreateObject("");
	with (oSearch) {
		Title = (sTitle) ? sTitle : 'Buscar'
		SelectMode = (bMultipleSelection) ? 'multi' : 'single'
		KeyField = 'KeyField'
		SourceType = 'xml'
		SourceData = sId
		NoFilter = true
		LocalSort = true
		AutoRefreshAfterListFilterChange = false
	};
	
	oFilter = oSearch.AddFilter();
	with (oFilter) {
		Field = 'criterio'
		Caption = 'Texto'
		Operator = 'like'
		DefaultValue = (sDefaultFilter) ? sDefaultFilter : null;
	};
	
	reOpen(oSearch, sParams, '_blank', sCallbackFunctionName);
};

function search(sId, pfNotify, bMultipleSelection, sTitle, sParams, sDefaultFilter) {
	var sURL = parRoot + 'utils/search/search.asp'
	var vParams, vParam;
	
	sURL = addParamToURL(sURL, 'idBusqueda', sId);
	if (sTitle) {
		sURL = addParamToURL(sURL, 'titulo', sTitle);
	};
	if (sDefaultFilter) {
		sURL = addParamToURL(sURL, 'criterioDefecto', sDefaultFilter);
	};
	
	document.cookie = 'sistemaOriginal=' + escape(parSistemaOriginal) + ';path=/';
	document.cookie = 'paginaProcesada=' + escape(parPaginaProcesada) + ';path=/';
	
	if (sParams) {
		
		vParams = sParams.split('|');
		if (vParams.length) {
			
			for(i = 0; i < vParams.length; i++){
				vParam = vParams[i].split('=');
				if (vParam.length) {
					sURL = addParamToURL(sURL, vParam[0], vParam[1]);
				};
			};
			
		} else if (sParams != '') {
			
			vParam = sParams.split('=');
			if (vParam.length) {
				sURL = addParamToURL(sURL, vParam[0], vParam[1]);
			};
			
		};
		
	};
	
	if (bMultipleSelection) {
		sURL = addParamToURL(sURL, 'multiple', '1');		
	};
	
	return openWindowCallback(sURL, pfNotify, false, 'height=600px, width=' + screen.availWidth * 0.5 + 'px');
};

function selectMenu(pfNotify, bAllowChangeLocation, iContext) {
	var sURL = parRoot + 'mapaSitio.asp';
	if (bAllowChangeLocation != true && bAllowChangeLocation != false) bAllowChangeLocation = true;
	
	sURL = addParamToURL(sURL, 'seleccionar', '1');
	if (bAllowChangeLocation) {
		sURL = addParamToURL(sURL, 'cambiarUbicacion', '1');
	} else {
		sURL = addParamToURL(sURL, 'cambiarUbicacion', '0');
	};
	
	if (iContext && !isNaN(iContext)) {
		sURL = addParamToURL(sURL, 'sistema', iContext);
	};
	
	return openWindowCallback(sURL, pfNotify, true, 'height=500px, width=500px;');
};

function selectFile(sFolder, pfNotify) {
	var sURL = parRoot + 'utils/fsExplorer/fsExplorer.asp';
	
	document.cookie = 'carpetaSeleccionada=;path=/';
	document.cookie = 'archivoSeleccionado=;path=/';
	
	sURL = addParamToURL(sURL, 'carpetaRuta', sFolder);
	sURL = addParamToURL(sURL, 'seleccionarArchivo', '1');
	
	return openWindowCallback(sURL, pfNotify, true, 'height=500px, width=700px;');
};

function selectFolder(sFolder, pfNotify) {
	var sURL = parRoot + 'utils/fsExplorer/fsExplorer.asp';
	
	document.cookie = 'carpetaSeleccionada=;path=/';
	document.cookie = 'archivoSeleccionado=;path=/';
	
	sURL = addParamToURL(sURL, 'carpetaRuta', sFolder);
	sURL = addParamToURL(sURL, 'seleccionarCarpeta', '1');
	
	return openWindowCallback(sURL, pfNotify, true, 'height=500px, width=700px;');
};

function selectTreeView(sId, pfNotify, sParams, sTitle) {
	// 20080417 ddignazi
	//var sURL = parRoot + 'utils/treeView.asp';
	var sURL = parRoot + 'compatible/treeView/treeView.asp';
	
	sURL = addParamToURL(sURL, 'seleccionar', '1');
	sURL = addParamToURL(sURL, 'idBusqueda', sId);
	sURL = addParamToURL(sURL, 'title', sTitle);
	if (sParams && sParams != '') {
		sURL += '&' + sParams;
	}
	
	return openWindowCallback(sURL, pfNotify, true, 'height=500px, width=500px;');
};

/*
** Funciones para traducción de textos en sitios multiidioma
*/
function newMessage(iContainer, sId) {
	var sURL = parRoot + 'utils/dataInput/dataInput.asp';
	sURL += '?diMetadataContext=1';
	sURL += '&diMetadata=abmTraducciones';
	sURL += '&diTransactionType=insert';
	if (parseInt(sId, 10) > 0) {
		sURL += '&IMJ_CODIGO=' + sId;
	} else if (sId) {
		sURL += '&IMJ_ID=' + sId;
	};
	
	openWindow(sURL, '_blank');
};

function editMessage(iContainer, iId) {
	var sURL = parRoot + 'utils/dataInput/dataInput.asp';
	sURL += '?diMetadataContext=1';
	sURL += '&diMetadata=abmTraducciones';
	sURL += '&diTransactionType=update';
	sURL += '&IMJ_CODIGO=' + iId;
	
	openWindow(sURL, '_blank');
};

/*
** Funciones de utilidad general.
*/
var oInternalForm = null;

function getInternalForm() {
	if (!oInternalForm) {
		oInternalForm = document.forms['eF'];
	};
	return oInternalForm;
};

function replaceRoot(sURL) {
	var sAux;
	
	while (true) {
		sAux = sURL.replace(new RegExp("[$]ROOT[$]/", "i"), parRoot);
		if (sAux == sURL) break;
		sURL = sAux;
	}
	
	while (true) {
		sAux = sURL.replace(new RegExp("[$]ROOT[$]\\\\", "i"), parRoot);
		if (sAux == sURL) break;
		sURL = sAux;
	};
	
	while (true) {
		sAux = sURL.replace(new RegExp("[$]ROOT[$]", "i"), parRoot);
		if (sAux == sURL) break;
		sURL = sAux;
	};
	
	while (true) {
		sAux = sURL.replace(new RegExp("[$]SITE_ROOT[$]/", "i"), parSiteRoot);
		if (sAux == sURL) break;
		sURL = sAux;
	}
	
	while (true) {
		sAux = sURL.replace(new RegExp("[$]SITE_ROOT[$]\\\\", "i"), parSiteRoot);
		if (sAux == sURL) break;
		sURL = sAux;
	};
	
	while (true) {
		sAux = sURL.replace(new RegExp("[$]SITE_ROOT[$]", "i"), parSiteRoot);
		if (sAux == sURL) break;
		sURL = sAux;
	};
	
	return sURL;
};

function isRunPage(sURL) {
	var sRunPageURL1 = parRoot + 'run.asp';
	var sRunPageURL2 = 'run.asp';
	
	if (sURL.substr(0, sRunPageURL1.length) == sRunPageURL1 || sURL.substr(0, sRunPageURL2.length) == sRunPageURL2) 
		return true
	else
		return false;
};

function getOpenerWindow() {
	if (window.top) {
		return window.top.opener;
	} else {
		return self.opener;
	};
};

function closeWindow() {
	if (self.name == 'Main') { // 20090707 ddignazi: evita que se cierre eFramework completamente cuando una página que se navega dentro de los marcos invoca esta función.
		openWindow(parRoot + 'main.asp', '_self');
	} else if (window.top) {
		window.top.close();
	} else {
		self.close();
	};
};

function historyBack(iDistance) {
	if (isNaN(iDistance)) iDistance = -1;
	if (iDistance >= 0) iDistance = -1;
	if (window.history.length == 0) {
		closeWindow();
	} else {
		window.history.go(iDistance);
	};
};

function replaceAll(sText, oRegExp, sReplaceWith) {
	var sAux;
	while (true) {
		sAux = sText.replace(oRegExp, sReplaceWith);
		if (sAux == sText) break;
		sText = sAux;
	};
	return sText;
};

function centerWindow(oWnd) {
	try {
		var iHeight = parseInt(oWnd.document.body.scrollHeight, 10);
		var iWidth = parseInt(oWnd.document.body.scrollWidth, 10);
		
		var iTop = parseInt((screen.availHeight - iHeight) / 2, 10);
		var iLeft = parseInt((screen.availWidth - iWidth) / 2, 10);
		
		oWnd.moveTo(iLeft, iTop);
	} catch(e) {
		//
	};	
};

function setSiteAsHomePage() {
	var oAux = document.body;
	var sPreviousBehavior;
	
	if (oAux) {
		sPreviousBehavior = oAux.style.behavior;
		
		oAux.style.behavior = "url('#default#homepage')";
		if (!oAux.isHomePage(parSite)) oAux.setHomePage(parSite);
		
		oAux.style.behavior = sPreviousBehavior;
	};	
};

function addSiteToFavorites(sTitle) {
	if (sTitle == 'undefined') {
		if (window.parent) 
			sTitle = window.parent.document.title;
		else
			sTitle = document.title;
	};
	window.external.AddFavorite(parSite, sTitle);
};

function savePageValue(sName, vValue, sPage) {
	if (!sPage || sPage == '' || sPage == 'undefined') sPage = parPaginaProcesada;

	sName = sPage + '_' + sName;
	document.cookie = escape(sName) + '=' + escape(vValue) + ';path=/;';
	return true;
};

function getQueryStringParams(sURL) {
	var vResults = new Array();
	var iQuestionMarkPos = sURL.indexOf("?");
	var sInput = sURL.substr(iQuestionMarkPos + 1);
	
	if (sInput) {
		var vSrchArray = sInput.split("&");
		var vTempArray = new Array();
		for (i = 0; i < vSrchArray.length; i++) {
			vTempArray = vSrchArray[i].split("=");
			vResults[vTempArray[0]] = vTempArray[1];
		};
	};
	
	return vResults;
};

function mergeQueryStringParam(sURL, sKey, sValue) {
	var bKeyFound;	
	var iQuestionMarkPos = sURL.indexOf("?");
	var sNewURL = sURL.substr(0, iQuestionMarkPos);
	var sInput = sURL.substr(iQuestionMarkPos+1);
	var i = 0;
	var j = 0;
	
	bKeyFound = false;
	
	if (sInput) {
		if(iQuestionMarkPos != -1){
				var vSrchArray = sInput.split("&");
				var vTempArray = new Array();
				for (i = 0; i < vSrchArray.length; i++) {
					// Interpreta el fragmento de la URL como 'clave=valor'
					vTempArray = vSrchArray[i].split("=");
					
					if(i == 0){
						
						// Primer parámetro en la URL
						sNewURL += '?';
						
					} else if (vTempArray.length == 1) {
						
						// El fragmento de la URL no es del tipo 'clave=valor'
						// Concatena el fragmento como parte del valor del parámetro anterior.
						sNewURL += escape('&');
						
					} else {
						
						// Otro parámetro en la URL
						sNewURL += '&';
						
					}
					
					if (vTempArray.length == 1) {
						
						// El fragmento de la URL no es del tipo 'clave=valor'
						// Concatena el fragmento como parte del valor del parámetro anterior.
						sNewURL += vTempArray[0];
						
					} else {
						
						// Clave del parámetro
						sNewURL += vTempArray[0] + '=';
					
						if(vTempArray[0] == sKey){
							
							// El parámetro ya existía en la URL. Se reemplaza su valor.
							bKeyFound = true
							sNewURL += sValue;
							
						}else{
							
							// Se conserva el valor del parámetro en la URL.
							for(j = 1; j < vTempArray.length; j++) {
								if (j > 1) sNewURL += '=';
								sNewURL += vTempArray[j];
							};
							
						}
						
					}
				}
		}else{
				sNewURL = sURL;
		}
		
		if(!bKeyFound){
			// El parámetro no existía en la URL. Se agrega.
			if(i == 0){
				sNewURL += '?';
			}else{
				sNewURL += '&';
			}
		
			sNewURL += sKey + '=' + sValue;
		}		
		
	}
	return sNewURL;
};

function addParamToURL(sURL, sName, vValue) {
	var iQuestionMarkPos = sURL.indexOf("?");
	
	if (iQuestionMarkPos < 0) {
		sURL = sURL + '?' + escape(sName) + '=' + escape(vValue);
	} else {
		sURL = sURL + '&' + escape(sName) + '=' + escape(vValue);
	};
	
	return sURL;
};

function removeBlanks(s) {
	if (s) {
		return s.replace(/(^\s*)|(\s*$)/g, "");	
	} else {
		return '';
	};
};

function parseWindowFeatures(sFeatures, iWidthScale, iHeightScale) {
	var iHeight = null;
	var iWidth = null;
	var vFeature;
	var iIndex = 0;

	if (!iWidthScale && isNaN(iWidthScale)) iWidthScale = 0.8;
	if (!iHeightScale && isNaN(iHeightScale)) iHeightScale = 0.8;

	if (!sFeatures) sFeatures = '';
	sFeatures = removeBlanks(sFeatures);
	sFeatures = sFeatures.toLowerCase();
	
	if (sFeatures.indexOf('channelmode') == -1) {
		sFeatures += (sFeatures != '') ? ', ':'';
		sFeatures += 'channelmode=no';
	};
	if (sFeatures.indexOf('directories') == -1) {
		sFeatures += (sFeatures != '') ? ', ':'';
		sFeatures += 'directories=no';
	};
	if (sFeatures.indexOf('fullscreen') == -1) {
		sFeatures += (sFeatures != '') ? ', ':'';
		sFeatures += 'fullscreen=no';
	};
	if (sFeatures.indexOf('location') == -1) {
		sFeatures += (sFeatures != '') ? ', ':'';
		sFeatures += 'location=no';
	};
	if (sFeatures.indexOf('menubar') == -1) {
		sFeatures += (sFeatures != '') ? ', ':'';
		sFeatures += 'menubar=no';
	};
	if (sFeatures.indexOf('resizable')) {
		sFeatures += (sFeatures != '') ? ', ':'';
		sFeatures += 'resizable=yes';
	};
	if (sFeatures.indexOf('scrollbars') == -1) {
		sFeatures += (sFeatures != '') ? ', ':'';
		sFeatures += 'scrollbars=yes';
	};
	if (sFeatures.indexOf('status') == -1) {
		sFeatures += (sFeatures != '') ? ', ':'';
		sFeatures += 'status=yes';
	};
	if (sFeatures.indexOf('titlebar') == -1) {
		sFeatures += (sFeatures != '') ? ', ':'';
		sFeatures += 'titlebar=yes';
	};
	if (sFeatures.indexOf('toolbar') == -1) {
		sFeatures += (sFeatures != '') ? ', ':'';
		sFeatures += 'toolbar=no';
	};
	
	var vFeatures = sFeatures.split(',');
	
	for(iIndex = 0; iIndex < vFeatures.length; iIndex++) {
		if (removeBlanks(vFeatures[iIndex]) != '') {
			vFeature = vFeatures[iIndex].split('=');
		
			vFeature[0] = removeBlanks(vFeature[0]);
			vFeature[1] = removeBlanks(vFeature[1]);
			
			if (vFeature[0] == 'width') {
				iWidth = parseInt(vFeature[1], 10);
			};
		};
	};
	
	for(iIndex = 0; iIndex < vFeatures.length; iIndex++) {
		if (removeBlanks(vFeatures[iIndex]) != '') {
			vFeature = vFeatures[iIndex].split('=');

			vFeature[0] = removeBlanks(vFeature[0]);
			vFeature[1] = removeBlanks(vFeature[1]);
		
			if (vFeature[0] == 'height') {
				iHeight = parseInt(vFeature[1], 10);
			};
		};
	};

	if (!iWidth) {
		iWidth = parseInt(screen.availWidth * iWidthScale, 10);
		
		if (sFeatures != '') sFeatures += ',';
		sFeatures += 'width=' + iWidth + 'px';
	};
	if (!iHeight) {
		iHeight = parseInt(screen.availHeight * iHeightScale, 10);
		
		if (sFeatures != '') sFeatures += ',';	
		sFeatures += 'height=' + iHeight + 'px';
	};

	if (sFeatures.indexOf('top') == -1 &&
			sFeatures.indexOf('left') == -1) {
		
		var iTop = parseInt((screen.availHeight - iHeight) / 2, 10);
		var iLeft = parseInt((screen.availWidth - iWidth) / 2, 10);
		
		if (sFeatures != '') sFeatures += ',';
		sFeatures += ('top=' + iTop + 'px');
		
		if (sFeatures != '') sFeatures += ',';
		sFeatures += ('left=' + iLeft + 'px');
	};
	
	return sFeatures;
};

function parseDialogFeatures(sFeatures, iWidthScale, iHeightScale) {
	var iHeight = null; 
	var iWidth = null;
	var vFeature;
	var iIndex = 0;

	if (!iWidthScale && isNaN(iWidthScale)) iWidthScale = 0.8;
	if (!iHeightScale && isNaN(iHeightScale)) iHeightScale = 0.8;

	if (!sFeatures) sFeatures = '';
	sFeatures = removeBlanks(sFeatures);
	sFeatures = sFeatures.toLowerCase();
	
	if (sFeatures.indexOf('edge') == -1) {
		sFeatures += (sFeatures != '') ? ', ':'';
		sFeatures += 'edge:raised';
	};
	if (sFeatures.indexOf('help') == -1) {
		sFeatures += (sFeatures != '') ? ', ':'';
		sFeatures += 'help:no';
	};
	if (sFeatures.indexOf('resizable') == -1) {
		sFeatures += (sFeatures != '') ? ', ':'';
		sFeatures += 'resizable:no';
	};
	if (sFeatures.indexOf('scroll') == -1) {
		sFeatures += (sFeatures != '') ? ', ':'';
		sFeatures += 'scroll:yes';
	};
	if (sFeatures.indexOf('status') == -1) {
		sFeatures += (sFeatures != '') ? ', ':'';
		sFeatures += 'status:yes';
	};
	if (sFeatures.indexOf('unadorned') == -1) {
		sFeatures += (sFeatures != '') ? ', ':'';
		sFeatures += 'unadorned:no';
	};
	
	var vFeatures = sFeatures.split(';');
		
	for(iIndex = 0; iIndex < vFeatures.length; iIndex++) {
		if (removeBlanks(vFeatures[iIndex]) != '') {
			vFeature = vFeatures[iIndex].split(':');
			
			vFeature[0] = removeBlanks(vFeature[0]);
			vFeature[1] = removeBlanks(vFeature[1]);

			if (vFeature[0] == 'dialogwidth') {
				iWidth = parseInt(vFeature[1], 10);
			};
		};
	};
	
	for(iIndex = 0; iIndex < vFeatures.length; iIndex++) {
		if (removeBlanks(vFeatures[iIndex]) != '') {
			vFeature = vFeatures[iIndex].split(':');
			
			vFeature[0] = removeBlanks(vFeature[0]);
			vFeature[1] = removeBlanks(vFeature[1]);

			if (vFeature[0] == 'dialogheight') {
				iHeight = parseInt(vFeature[1], 10);
			};
		};
	};

	if (!iWidth) {
		iWidth = parseInt(screen.availWidth * iWidthScale, 10);
		
		if (sFeatures != '') sFeatures += ';';
		sFeatures += 'dialogwidth:' + iWidth + 'px';
	};
	if (!iHeight) {
		iHeight = parseInt(screen.availHeight * iHeightScale, 10);
		
		if (sFeatures != '') sFeatures += ';';
		sFeatures += 'dialogheight:' + iHeight + 'px';
	};

	if (sFeatures.indexOf('center') == -1 &&
			sFeatures.indexOf('dialogtop') == -1 &&
			sFeatures.indexOf('dialogleft') == -1) {
		
		var iTop = parseInt((screen.availHeight - iHeight) / 2, 10);
		var iLeft = parseInt((screen.availWidth - iWidth) / 2, 10);
		
		if (sFeatures != '') sFeatures += ';';
		sFeatures += ('dialogtop:' + iTop + 'px');
		
		if (sFeatures != '') sFeatures += ';';
		sFeatures += ('dialogleft:' + iLeft + 'px');
	};
	
	return sFeatures;
};

function dialog2WindowFeatures(sFeatures) {
	var iTop = null;
	var iLeft = null; 
	var bCenter = false;
	
	if (!sFeatures) sFeatures = '';
	sFeatures = removeBlanks(sFeatures);
	sFeatures = sFeatures.toLowerCase();
	
	var vFeatures = sFeatures.split(';');
	
	sFeatures = '';
		
	for(iIndex = 0; iIndex < vFeatures.length; iIndex++) {
		if (removeBlanks(vFeatures[iIndex]) != '') {
			vFeature = vFeatures[iIndex].split(':');
			
			vFeature[0] = removeBlanks(vFeature[0]);
			vFeature[1] = removeBlanks(vFeature[1]);
			
			switch (vFeature[0]) {
				
				case 'dialogheight':
					vFeature[0] = 'height';
					break;
					
				case 'dialogleft':
					vFeature[0] = 'left';
					iLeft = parseInt(vFeature[1], 10);
					break;
					
				case 'dialogtop':
					vFeature[0] = '';
					iTop = parseInt(vFeature[1], 10);
					break;
					
				case 'dialogwidth':
					vFeature[0] = 'width';
					break;
					
				case 'center':
					vFeature[0] = '';
					bCenter = true;
					break;
					
				case 'resizable':
					if (vFeature[1] == 'on') {
						vFeature[1] = 'yes';
					} else if (vFeature[1] == 'off') {
						vFeature[1] = 'no';
					};
					break;
					
				case 'scroll':
					vFeature[0] = 'scrollbars';
					if (vFeature[1] == 'on') {
						vFeature[1] = 'yes';
					} else if (vFeature[1] == 'off') {
						vFeature[1] = 'no';
					};
					break;
				
				case 'status':
					if (vFeature[1] == 'on') {
						vFeature[1] = 'yes';
					} else if (vFeature[1] == 'off') {
						vFeature[1] = 'no';
					};
					break;

				default:
					vFeature[0] = '';
					break;			
			
			};
			
			if (vFeature[0] != '') {
				if (sFeatures != '') sFeatures += ',';
				sFeatures += (vFeature[0] + '=' + vFeature[1]);
			};
		};
	};
	
	if (!bCenter && iTop) {
		if (sFeatures != '') sFeatures += ',';
		sFeatures += ('top=' + iTop + 'px');
	};
	if (!bCenter && iLeft) {
		if (sFeatures != '') sFeatures += ',';
		sFeatures += ('left=' + iLeft + 'px');
	};
	
	sFeatures = parseWindowFeatures(sFeatures);
	
	return sFeatures;
};

function getAttribute(obj, attribute) {
	try {
		return obj.attributes.getNamedItem(attribute).value;
	} catch(e) {
		return obj.getAttribute(attribute, 1);
	};
};

function setAttribute(obj, attribute, newValue) {
	try {
		obj.setAttribute(attribute, newValue, 0);
	} catch(e) {
		obj.setAttribute(attribute, newValue);
	};
};

function getElementByIdOrName(s) {
	var oElement = document.getElementById(s);
	if (!oElement) {
		oElement = document.getElementsByName(s);
		oElement = (oElement.length > 0) ? oElement[0] : undefined;
	};
	return oElement;
};


/*
** 
*/

function isNumeric(sValue, bFormattedOutput, iMinValue, iMaxValue, iDecimals) {
	var sNumber = '';
	var sIntegerPart = '';
	var sDecimalPart = '';
	var bNegativeValue = false;
	var iDecimalPartStartPos = 0;
	
	// String analysis...
	for (i = 0; i < sValue.length; i++) {
		if (sValue.charCodeAt(i) >= 48 && sValue.charCodeAt(i) <= 57) {
			
			// Valid number [0-9]
			sNumber = sNumber + sValue.charAt(i);
			
		} else if (sValue.charAt(i) == '-' && !bNegativeValue) {
			
			// Negative symbol [-]
			sNumber = '-' + sNumber; 
			bNegativeValue = true;
			
		} else if (sValue.charAt(i) == '.' && iDecimalPartStartPos == 0) {
			
			// Decimal part separator [.]
			sNumber = sNumber + '.';
			iDecimalPartStartPos = sNumber.length;
			
		};
	};
	
	if (iDecimals != null && !isNaN(iDecimals) && iDecimals >= 0) {
		if (iDecimalPartStartPos > 0) {
			sIntegerPart = sNumber.substr(0, iDecimalPartStartPos - 1);
			sDecimalPart = sNumber.substr(iDecimalPartStartPos);
		} else {
			sIntegerPart = sNumber;
			sDecimalPart = '';
		};
		
		sDecimalPart = sDecimalPart.substr(0, iDecimals);
		while (sDecimalPart.substr(sDecimalPart.length - 1, 1) == '0') sDecimalPart = sDecimalPart.substr(0, sDecimalPart.length - 1);
		if (sDecimalPart == '' && iDecimals > 0) sDecimalPart = '0';
		
		while (bFormattedOutput == true && sDecimalPart.length < iDecimals) sDecimalPart += '0';
		
		sNumber = sIntegerPart + '.' + sDecimalPart;
	};
	
	if (sNumber.charAt(sNumber.length - 1) == '.') sNumber = sNumber.substr(0, sNumber.length - 1);
	if (sNumber.charAt(0) == '.') sNumber = '0' + sNumber;
	if (iMinValue != null && !isNaN(iMinValue) && parseFloat(sNumber, 10) < iMinValue) sNumber = '';
	if (iMaxValue != null && !isNaN(iMaxValue) && parseFloat(sNumber, 10) > iMaxValue) sNumber = '';
	
	return sNumber;	
};

function isDate(sValue, bFormattedOutput, sFormat, iMinYear, iMaxYear) {
	var vDateParts, sDatePart;
	
	var varDatePartsSeparators = new Array('-', ' ', '/', '.');
	var blnDatePartsSeparatorFound = false;
	var sOutputSeparator = '/';
	
	var iDay, iMonth, iYear;
	var bLeapYear = false;
	
	var vReturnDate;
	
	if (isNaN(iMinYear)) iMinYear = parConfigMinYear;
	if (isNaN(iMaxYear)) iMaxYear = parConfigMaxYear;
	
	vReturnDate = (bFormattedOutput == true) ? '':false;
	
	if (sValue.length < 1) return vReturnDate;
	
	// Format with valid date-part separator: dd[s]mm[s]yyyy
	for (i = 0; i < varDatePartsSeparators.length; i++) {
		if (sValue.indexOf(varDatePartsSeparators[i]) != -1) {
			vDateParts = sValue.split(varDatePartsSeparators[i]);
			
			if (vDateParts.length == 3) {
				sOutputSeparator = varDatePartsSeparators[i];
				iDay = parseInt(vDateParts[0], 10);
				iMonth = parseInt(vDateParts[1], 10);
				iYear = parseInt(vDateParts[2], 10);
			} else if (vDateParts.length == 2) {
				sOutputSeparator = varDatePartsSeparators[i];
				iDay = parseInt(vDateParts[0], 10);
				iMonth = parseInt(vDateParts[1], 10);
				iYear = new Date();
				iYear = iYear.getFullYear();
			} else {
				return vReturnDate;
			}
			
			blnDatePartsSeparatorFound = true;
		};
	};
	
	// Format without date-part separator: ddmmyyyy
	if (!blnDatePartsSeparatorFound) {
		if (sValue.length > 5) {
			iDay = parseInt(sValue.substr(0, 2), 10);
			iMonth = parseInt(sValue.substr(2, 2), 10);
			iYear = parseInt(sValue.substr(4), 10);
		};
	};

	if (isNaN(iDay) || isNaN(iMonth) || isNaN(iYear)) return vReturnDate;
	
	if (iYear >= 0 && iYear <= 50) {
		iYear = iYear + 2000;
	} else if (iYear >= 51 && iYear <= 99) {
		iYear = iYear + 1900;
	};
	
	if (iYear % 100 == 0) {
		if (iYear % 400 == 0) bLeapYear = true;
	} else {
		if ((iYear % 4) == 0) bLeapYear = true;
	};
	
	if (iYear < iMinYear) return vReturnDate;
	if (iYear > iMaxYear) return vReturnDate;
	if (iMonth > 12 || iMonth < 1) return vReturnDate;
	if (iDay < 1)	return vReturnDate;
	if ((iMonth == 1 || iMonth == 3 || iMonth == 5 || iMonth == 7 || iMonth == 8 || iMonth == 10 || iMonth == 12) && (iDay > 31)) return vReturnDate;
	if ((iMonth == 4 || iMonth == 6 || iMonth == 9 || iMonth == 11) && (iDay > 30)) return vReturnDate;
	if (iMonth == 2 && bLeapYear == false && iDay > 28) return vReturnDate;
	if (iMonth == 2 && bLeapYear == true && iDay > 29) return vReturnDate;
	
	if (bFormattedOutput == true) {
		
		vReturnDate = '';
		
		if (sFormat == 'dd/mm') {
			
			sDatePart = new String(iDay);
			while (sDatePart.length < 2) sDatePart = '0' + sDatePart;
			vReturnDate += sDatePart + sOutputSeparator;
			
			sDatePart = new String(iMonth);
			while (sDatePart.length < 2) sDatePart = '0' + sDatePart;
			vReturnDate += sDatePart;
			
		} else {
			
			sDatePart = new String(iDay);
			while (sDatePart.length < 2) sDatePart = '0' + sDatePart;
			vReturnDate += sDatePart + sOutputSeparator;
			
			sDatePart = new String(iMonth);
			while (sDatePart.length < 2) sDatePart = '0' + sDatePart;
			vReturnDate += sDatePart + sOutputSeparator;
			
			sDatePart = new String(iYear);
			while (sDatePart.length < 4) sDatePart = '0' + sDatePart;
			vReturnDate += sDatePart;
			
		};
		
	} else {
		
		vReturnDate = true;
		
	};
	
	return vReturnDate;
};

function isTime(sValue, bFormattedOutput, sFormat) {
	var vTimeParts, sTimePart;
	
	var vTimePartsSeparators = new Array(':', '.', ' ');
	var bTimePartSeparatorFound = false;
	var sOutputSeparator = ':';
	
	var iHour, iMinute, iSecond;
	var bValueHasSecondsPart = false;
	
	var vReturnTime;
	
	vReturnTime = (bFormattedOutput == true) ? '':false;
	
	if (sValue.length < 1) return vReturnTime;
	
	for (i = 0; i < vTimePartsSeparators.length; i++) {
		if (sValue.indexOf(vTimePartsSeparators[i]) != -1) {
			vTimeParts = sValue.split(vTimePartsSeparators[i]);
			
			if (vTimeParts.length == 3) {
				iHour = parseInt(vTimeParts[0], 10);
				iMinute = parseInt(vTimeParts[1], 10);
				iSecond = parseInt(vTimeParts[2], 10);
				bValueHasSecondsPart = true;
			} else if (vTimeParts.length == 2) {
				iHour = parseInt(vTimeParts[0], 10);
				iMinute = parseInt(vTimeParts[1], 10);
				iSecond = 0;
			} else {
				return vReturnTime;
			};
			
			bTimePartSeparatorFound = true;
		};
	};
	
	if (!bTimePartSeparatorFound) {
		if (sValue.length > 5) {
			iHour = parseInt(sValue.substr(0, 2), 10);
			iMinute = parseInt(sValue.substr(2, 2), 10);
			iSecond = parseInt(sValue.substr(4), 10);
			bValueHasSecondsPart = true;
		} else if (sValue.length > 3) {
			iHour = parseInt(sValue.substr(0, 2), 10);
			iMinute = parseInt(sValue.substr(2), 10);
			iSecond = 0;
		} else {
			iHour = parseInt(sValue, 10);
			iMinute = 0;
			iSecond = 0;
		};
	};
	
	if (isNaN(iHour) || isNaN(iMinute) || isNaN(iSecond)) return vReturnTime;
	
	if (iHour > 23 || iHour < 0) return vReturnTime;
	if (iMinute > 59 || iMinute < 0) return vReturnTime;
	if (iSecond > 59 || iSecond < 0) return vReturnTime;
	
	if (bFormattedOutput == true) {
		
		vReturnTime = '';

		if (sFormat == 'hh:nn') {
			
			sTimePart = new String(iHour);
			while (sTimePart.length < 2) sTimePart = '0' + sTimePart;
			vReturnTime += sTimePart + sOutputSeparator;
			
			sTimePart = new String(iMinute);
			while (sTimePart.length < 2) sTimePart = '0' + sTimePart;
			vReturnTime += sTimePart;
			
		} else {
			
			sTimePart = new String(iHour);
			while (sTimePart.length < 2) sTimePart = '0' + sTimePart;
			vReturnTime += sTimePart + sOutputSeparator;
			
			sTimePart = new String(iMinute);
			while (sTimePart.length < 2) sTimePart = '0' + sTimePart;
			vReturnTime += sTimePart;
			
			if (sFormat == 'hh:nn:ss' || bValueHasSecondsPart) {
				sTimePart = new String(iSecond);
				while (sTimePart.length < 2) sTimePart = '0' + sTimePart;
				vReturnTime += sOutputSeparator + sTimePart;
			};
			
		};
		
	} else {
		
		vReturnTime = true;
		
	};
	
	return vReturnTime;
};

function toDate(sValue, iMinYear, iMaxYear) {
	var vParts;
	var sDatePart = '';
	var sTimePart = '';
	var oDate = null;
	
	vParts = trim(sValue).split(' ');
	
	sDatePart = isDate(vParts[0], true, 'dd/mm/yyyy', iMinYear, iMaxYear);
	
	if (sDatePart != '') {
		
		oDate = new Date( 
											parseInt(sDatePart.substr(6, 4), 10), 
											parseInt(sDatePart.substr(3, 2), 10) - 1, 
											parseInt(sDatePart.substr(0, 2), 10) 
										);
		
		if (vParts.length > 1) {
			
			sTimePart = isTime(vParts[1], true, 'hh:nn:ss');
			
			oDate.setHours(parseInt(sTimePart.substr(0, 2), 10));
			oDate.setMinutes(parseInt(sTimePart.substr(3, 2), 10));
			oDate.setSeconds(parseInt(sTimePart.substr(6, 2), 10));
			
		};
		
	};
	
	return oDate;
};

function isValidDateRange(sValue1, sValue2, bAllowEqualDates) {
	var oDate1, oDate2;
	
	if (bAllowEqualDates != false && bAllowEqualDates != true) bAllowEqualDates = true;
	
	oDate1 = toDate(sValue1);
	oDate2 = toDate(sValue2);
	
	if (!oDate1 || !oDate2) 
		return false;
	else if (oDate1 == oDate2)
		return bAllowEqualDates;
	else if (oDate1 > oDate2)
		return false;
	else
		return true;
};

function inpText(iMaxLength) {
	inpText2(event, iMaxLength); 
};

function inpText2(e, iMaxLength) {
	if (document.all) { // IE
		if (e.srcElement.value.length >= parseInt(iMaxLength, 10)) {
			e.returnValue = false; 
		};
	} else { // FF
		if (e.target.value.length >= parseInt(iMaxLength, 10)) {
			e.preventDefault();
		};
	};
};

function inpDate(sDatePartsSeparator) {
	inpDate2(event, sDatePartsSeparator);
};

function inpDate2(e, sDatePartsSeparator) {
  var iKeyCode;
	var bReturnValue;
	
  iKeyCode = (document.all) ? e.keyCode:e.which;
	
	if (
			((iKeyCode > 31 && iKeyCode < 48) || iKeyCode > 57) && String.fromCharCode(iKeyCode) != sDatePartsSeparator
			)
  {
		bReturnValue = false;
	} else {
    bReturnValue = true;
	};
	
  if (document.all) {
    e.returnValue = bReturnValue;
	} else if (!bReturnValue) {
		e.preventDefault();
	};
	
  return bReturnValue;
};

function inpNumeric(bAllowDecimals) {
  inpNumeric2(event, bAllowDecimals);
};

function inpNumeric2(e, bAllowDecimals) {
  var iKeyCode;
	var bReturnValue;
	
	iKeyCode = (document.all) ? e.keyCode:e.which;
  
  bReturnValue = true;
	
	if (bAllowDecimals == true) {
		
		if (
				((iKeyCode > 31 && iKeyCode < 48) || iKeyCode > 57) && iKeyCode != 45 && iKeyCode != 46
				)
		{
      bReturnValue = false;
		};
		
	} else {
		
		if (
				((iKeyCode > 31 && iKeyCode < 48) || iKeyCode > 57) && iKeyCode != 45
				)
		{
      bReturnValue = false;
		};
		
	};
	
  if (document.all) {
    e.returnValue = bReturnValue;
	} else if (!bReturnValue) {
		e.preventDefault();
	};
	
  return bReturnValue;
};

