/**************************/
/* Identifica el navegador */
/**************************/

var IE = 1;

if (navigator.appName.indexOf("Netscape")>(-1))
	IE = 0;

/**************************/
/* Para el menu */
/**************************/
var Escape = 27;
/*
function KeyDownPage(e)
{
	var k = e.keyCode || e.which;
	
	if (k == Escape)
	{
		if (window.opener != 'undefined' && window.opener != null)
			window.close();
		else
			if (parent.menusecundario != null)
				parent.menusecundario.CerrarMenuSecundario();
	}
}

if (IE == 1)
	document.body.attachEvent('onkeypress', KeyDownPage, false);
else
{
	document.addEventListener('keydown', KeyDownPage, false);
}
*/

/**********************************/
/* Para Controles Web - LinkPopUp */
/**********************************/
function SimplePopUp(url, width, height)
{
	PopUp(url, "", 0, 0, width, height, true, false, true, false, false, false, false);  
}

function PopUp(url, id, left, top, width, height, center, menubar, resizable, status, scrollbars, location, modal)
{
	var sMenuBar = 'no';
	var sResizable = 'no';
	var sStatus = 'no';
	var sScrollBars = 'no';
	var sLocation = 'no';
	var sReturnValue = '';

	if (menubar) sMenuBar = 'yes';
	if (resizable) sResizable = 'yes';
	if (status) sStatus = 'yes';
	if (scrollbars) sScrollBars = 'yes';
	if (location) sLocation = 'yes';

	if (center)
	{
		left = (screen.width / 2) - (width / 2);
		top = (screen.height / 2) - (height / 2) - 50;
	}

	if (modal)
	{
		if (IE == 1)
			sReturnValue = window.showModalDialog(url, id, 'help: No;resizable:' + sResizable + ';status:' + sStatus + ';scroll:' + sScrollBars + ';dialogWidth: ' + width + 'px;dialogHeight:' + height + 'px;dialogLeft:' + left + 'px;dialogTop:' + top + 'px');
		else
			sReturnValue = window.open(url, id, 'menubar=no, resizable=' + sResizable + ', status=' + sStatus + ', scrollbars=' + sScrollBars + ', location=' + sLocation + ', width=' + width + ', height=' + height + ', left=' + left + ', top=' + top + ", modal=yes");
	}		
	else 
	{
		var win = window.open(url, id, 'menubar=' + sMenuBar + ', resizable=' + sResizable + ', status=' + sStatus + ', scrollbars=' + sScrollBars + ', location=' + sLocation + ', width=' + width + ', height=' + height + ', left=' + left + ', top=' + top);

		try
		{
			win.focus();
		}
		catch(e)
		{
		}
	}

	return sReturnValue;
}

function ReturnValueEmpty(value)
{
	return;
}


/**************************/
/* Generales */
/**************************/

function clickEnter(e, buttonid)
{
	var bt = document.getElementById(buttonid);
 
	if (typeof bt == 'object' && bt != null)
	{
		if (e.keyCode == 13)
		{
			if (bt.tagName == "A")
				if (IE == 1)
					bt.click();
				else
					eval(bt.href);
			else
				eval(bt.href);
			
			return false;
		}
	}
}

function clickEnterEval(e, postback)
{
	if (e.keyCode == 13)
	{
		eval(postback);
		
		return false;
	}
}

function SetFocus(ctl)
{
	var c = document.getElementById(ctl);
	
	if (c != null)
	{
		try		
		{
			c.focus();
		}
		catch(e)
		{
		}
	}
}

function ResizeWindow(width, height)
{
	var left;
	var top;

	left = screen.width / 2 - width / 2;
	top = screen.height / 2 - height / 2;

	var activeElement = window.document.activeElement;

	window.focus();

	window.moveTo(left, top);
	window.resizeTo(width, height);

	if (activeElement != null)
		activeElement.focus();
}


function CheckMaxLength(e, textarea_id, max) 
{
	var theTextArea = document.getElementById(textarea_id);
	
	if (!e.which) 
		keyCode = event.keyCode; // ie5+ op5+
	else 
		keyCode = e.which; // nn6+

	if (theTextArea.value.length>max)
	{
		theTextArea.value = theTextArea.value.substring(0,max);
	}
}

/**************************/
/* RefreshOpener	 	  */
/**************************/
function RefreshOpener(doRelod)
{
	var win = window.opener;
	
	if (!doRelod && (typeof win.__doReload == 'object' || typeof win.__doReload == 'function') )
		win.__doReload();
	else
		window.opener.location.reload();
		
	window.focus();
}

/**************************/
/* Funciones de fecha */
/**************************/
function FormatearFecha(ctl)
{
	var f = ctl.value;

	if (f.length == 8)
	{
		var dia = f.substring(0, 2);
		var mes = f.substring(2, 4);
		var anio = f.substring(4, 8);
		
		ctl.value = dia + "/" + mes + "/" + anio;
	}
}

function FormatearHora(ctl)
{
	var h = ctl.value;

	if (h.length == 4)
	{
		var hora = h.substring(0, 2);
		var minutos = h.substring(2, 4);
	
		ctl.value = hora + ":" + minutos;
	}
}

/**************************/
/* Funciones de numero */
/**************************/
var separadorDecimal = ',';
var separadorMiles = '.';

function NumeroOnBlur(ctl)
{
	if (ctl.className == "NumeroEntero")
		ctl.value = formatNumberInteger(convertToDecimal(ctl.value));
	else
		ctl.value = formatNumberDecimal(convertToDecimal(ctl.value));
}

function convertToDecimal(value)
{
	var idxComa = value.lastIndexOf(',');
	var idxPunto = value.lastIndexOf('.');

	if (value != "")
	{
		while (value.indexOf(separadorMiles) > 0)
			value = value.replace(separadorMiles, '');

		value = value.replace(separadorDecimal, '.');
	}
	else 
		value = 0;
	
	return parseFloat(value);
}

function formatNumberDecimal(num) 
{
	num = num.toString().replace(/\$|\,/g,'');

	if(isNaN(num))
		num = "0";
		
	var sign = (num == (num = Math.abs(num)));
	
	num = Math.floor(num*100+0.50000000001);
	
	var cents = num%100;
	
	num = Math.floor(num/100).toString();
	
	if(cents<10)
		cents = "0" + cents;
		
	for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
		num = num.substring(0,num.length-(4*i+3)) + separadorMiles + num.substring(num.length-(4*i+3));
		
	return (((sign)?'':'-') + num + separadorDecimal + cents);
}

function formatNumberInteger(num) 
{
	num = num.toString().replace(/\$|\,/g,'');

	if(isNaN(num))
		num = "0";
		
	var sign = (num == (num = Math.abs(num)));
	
	num = Math.floor(num*100+0.50000000001);
	num = Math.floor(num/100).toString();
	
	for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
		num = num.substring(0,num.length-(4*i+3)) + separadorMiles + num.substring(num.length-(4*i+3));
		
	return (((sign)?'':'-') + num);
}

function NumeroKeyPress(ctl, e)
{
	// Caracter "."
	if (typeof(e.which) != "undefined")
	{
		// FIREFOX
		if (e.which == 46)
		{
			e.preventDefault();
			
			ctl.value += separadorDecimal;
			
			return false;
		}
	}
	else
	{
		// IE
		if (e.keyCode == 46)
		{
			e.cancelBubble = true;
		
			ctl.value += separadorDecimal;
			
			return false;
		}
	}
	
	return true;
}



/**** FIN - funciones de números ****/

/****************************************
* Deshabilita el boton derecho del mouse
******************************************/
/*
function clickIE() 
{
	var message="";

	if (document.all)
	{
		(message);
		return false;
	}
}

function clickNS(e)
{
	var message="";

	if(document.layers||(document.getElementById&&!document.all))
	{
		if (e.which==2||e.which==3)
		{
			(message);
			return false;
		}
	}
}

if (document.layers)
{
	document.captureEvents(Event.MOUSEDOWN);
	document.onmousedown=clickNS;
}
else
{
	document.onmouseup=clickNS;
	document.oncontextmenu=clickIE;
}

document.oncontextmenu=new Function("return false")
*/