function MsgCancel()
{
    //Mensaje a mostrar cuando se cancela la operacion
}
function Check_Cantidad(value)
		{
			var Newvalue = value + String.fromCharCode(event.keyCode);
			if ((Newvalue != "-") && isNaN(Newvalue))
			{
					if (isNaN(String.fromCharCode(event.keyCode)) || 
							String.fromCharCode(event.keyCode) ==".")
					{
						event.returnValue = false;
					}
			}
			//no permite ingresar negativos
			if (String.fromCharCode(event.keyCode)=="-")
			{
				event.returnValue = false;
			}
		}

function pause(milisg)
{
	d = new Date() //today's date
	while (1)
	{
		mill=new Date() // Date Now
		diff = mill-d //difference in milliseconds
		if( diff > milisg ) {break;}
	}
}

function CloseWindowX()
{
	//alert(document.forms[0].name);
	if ( (window.event.clientY < 0	&& window.event.clientY >= -30 
			&& window.event.clientX >= document.body.offsetWidth - 30
			&& window.event.clientX <= document.body.offsetWidth ) 
			&& (document.forms[0].name != "frmSalir") ) //Para saber que se cierra el browser desde cualquier parte
	{
		//alert("Se cerro con boton X");
		//AbrirWindow("frmSalir.aspx",0,1,1,1,1);
	}
}

function BtnDesabled()
{
	var arrBtn;
	//Deshabilita todos los botones una vez que se presiono Click
	arrBtn = document.getElementsByTagName("input");
	for (i = 0; i < arrBtn.length; i++)
	{
		obj = arrBtn[i];
		if ( obj.type == "image" && obj.name.toUpperCase().indexOf("BTN") >=0)
		{
			//obj.style.visibility="hidden";
			obj.onclick = new Function("return false;");//para que deshabilite el click
		}
	}
}

function OnClick()
{
	if (document.parentWindow.event.srcElement.name != null)
	{
		var ev = document.parentWindow.event ; //Recupera el elemento que produjo el evento click
		if ( ev.srcElement.name.toUpperCase().indexOf("BTN") >=0)
			BtnDesabled();
	}
}

function nothing()
	{
		//return false;
		new Function("return false;");
	}
	
function Salir()
	{	
		//CloseAllWindow();
		window.opener = "Inicial";
		window.close();
	}

function CerrarWindow()
	{	
		//CloseAllWindow();
		//parent.opener.focus();
		window.close();
	}

function GetDate(path,CtrlName)
{
	//alert(path);
	//formulario = path + "frmCalendario.aspx?FormName=" + document.forms[0].name + "&CtrlName=" + CtrlName;
	//Momentaneamente hasta que se compile todo en produccion
	formulario = "../frmCalendario.aspx?FormName=" + document.forms[0].name + "&CtrlName=" + CtrlName;
	
	//alert(formulario);
	window.open(formulario, 'Calendario', 'width=220,height=230,top=200,left=200,toolbars=no,scrollbars=no,status=no,resizable=no');

}

function msgConfirma(obj,msg,id)
{
	//debugger;
	if (confirm (msg))
	{		
		objeto = document.getElementById("ctl00_objctrCmd_txtComando");
		if (objeto == null)
			objeto = document.getElementById(obj);//En caso de no migrado el BarraCmd
		objeto.value = id;
		document.forms[0].submit();
	}
	
}

function SetimgButtonEnabled(imgBtn, estado)
 {  
	//debugger;
	if(estado)  {   
		document.getElementById(imgBtn).onclick = new Function(); 
	 }  
	else  {   
		document.getElementById(imgBtn).onclick = new Function("return false;");
	  }
}
function SetimgButtonDefault(imgBtnEnter) 
{
	if (window.event != null )
	{
		switch (event.keyCode)
		{
			case 13: //Enter
					event.returnValue=false;
					event.cancel = true;
					obj = document.getElementById(imgBtnEnter);
					if ( obj != null )
						obj.click();
					//alert("enter");
					break;
		//	case 27: //Escape
		//			event.returnValue=false;
		//			event.cancel = true;
		//			obj = document.getElementById(imgBtnEscape);
		//			if ( obj != null )
		//				obj.click();
		//			//alert("escape");
		//			break;
	//		default:
	//				alert("default");
				
		}
	}
	//onkeypress="SetimgButtonDefault(imgBtn)"
}


function AbrirWindow(formulario,arg,ancho,alto,margenS,margenI)
{

    //alert(formulario);
	var nombre = "frm";
	var temp= new Date();
			
	var w = 480, h = 340;
	if (document.all || document.layers) {
		w = screen.availWidth;
		h = screen.availHeight;
	}
	if (margenS == -1 )
		margenS = (w-ancho)/2;
	if (margenI == -1)
		margenI = (h-alto)/2;
		
	nombre += temp.getHours();
   	nombre += temp.getMinutes();
   	nombre += temp.getSeconds();
   	nombre += temp.getMilliseconds(); 
   	
	if (arg == 0 )
	{
		window.open(formulario,nombre, "width=" + ancho + ", height=" + alto + ", left=" + margenI + ", top=" + margenS + ", menubar=no, titlebar=no, location=no, status=yes, toolbar=no, scrollbars=yes, resizable=yes");
		Salir();
	}
	else
	{
		window.open(formulario,nombre, "width=" + ancho + ", height=" + alto + ", left=" + margenI + ", top=" + margenS + ", menubar=no, titlebar=no, location=no, status=yes, toolbar=no, scrollbars=yes, resizable=yes");
	}
	
}

function AbrirWindowModal(nombre,formulario,arg,ancho,alto,margenS,margenI)
{
	if (arg == 0 )
	{
		window.open(formulario,nombre, "width=" + ancho + ", height=" + alto + ", left=" + margenI + ", top=" + margenS + ", menubar=no, titlebar=no, location=no, status=yes, toolbar=no, scrollbars=yes, resizable=yes");
		Salir();
	}
	else
	{
		window.open(formulario,nombre, "width=" + ancho + ", height=" + alto + ", left=" + margenI + ", top=" + margenS + ", menubar=no, titlebar=no, location=no, status=yes, toolbar=no, scrollbars=yes, resizable=yes");
	}
	
}

function RetornaConsulta(clave)
{
	//alert("retornaConsulta");
	if ( window.opener && !window.opener.closed)
	{
	parent.opener.focus();
	parent.opener.Consulta(clave);
	}
	window.close();
}

function RetornaConsultaD(clave)
{
	//parent.opener.focus();
	Consulta(clave);
}

function Consulta(clave)
{
	objCons = document.getElementById("ctl00_objctrCmd_txtConsulta"); //En caso de que use MasterPage
    txtargs = document.getElementById("ctl00_txtargs");
    objCons.value = clave;
    objBusq = document.getElementById(txtargs.value);//Boton que produjo la busqueda
	objBusq.click();
}

function txtSearch_OnBlur(id)
{
	//Llama a buscar document.frmRol.item(objeto);
	obj = document.getElementById("ctl00_objctrCmd_txtConsulta");
	obj.value = "F" + id;
	document.forms[0].submit();
}

function Search_OnBlur(id, valor)
{
	//Llama a buscar document.frmRol.item(objeto);
	obj = document.getElementById("ctl00_objctrCmd_txtConsulta");
	if (valor != "")
	{
		obj.value = "F" + id;
		document.forms[0].submit();
	}
}


//VALIDA INGRESO DE VALORES NUMERICOS: OnKeyPress
function CheckNumber(Obj,Separador,Signo)
{
	var Val = Obj.value;
	var Result = true;
	//Valida solo numeros, separador decimal y signo '-'
	if (String.fromCharCode(event.keyCode)==" "
		|| (isNaN(String.fromCharCode(event.keyCode))
			&& String.fromCharCode(event.keyCode)!=Separador
			&& String.fromCharCode(event.keyCode)!="-"))
	{
		Result = false;
	}
	//no permite ingresar más de un separador decimal
	if ((String.fromCharCode(event.keyCode)==Separador && Val.indexOf(Separador)>=0)
		|| (String.fromCharCode(event.keyCode)=="-" && (Val.indexOf("-")>=0 || Signo!=true)))
	{
		Result = false;
	}
	// controla en ingreso del signo '-'
	if (String.fromCharCode(event.keyCode)=="-" && Val.indexOf("-")==-1 && Signo==true)
	{
		Result = false;
		Obj.value = '-' + Val;
	}
	event.returnValue = Result;
}

function CheckCurrency(Obj,SeparadorNum,SeparadorDec,Signo)
{
	var Val = Obj.value;
	var Result = true;
	//Valida solo numeros, separador decimal y signo '-'
	if (String.fromCharCode(event.keyCode)==" "
		|| (isNaN(String.fromCharCode(event.keyCode))
			&& String.fromCharCode(event.keyCode)!=SeparadorDec
			&& String.fromCharCode(event.keyCode)!=SeparadorNum
			&& String.fromCharCode(event.keyCode)!="-"))
	{
		Result = false;
	}
	//no permite ingresar más de un separador decimal
	if ((String.fromCharCode(event.keyCode)==SeparadorDec && Val.indexOf(SeparadorDec)>=0)
		|| (String.fromCharCode(event.keyCode)=="-" && (Val.indexOf("-")>=0 || Signo!=true)))
	{
		Result = false;
	}
		
	// controla en ingreso del signo '-'
	if (String.fromCharCode(event.keyCode)=="-" && Val.indexOf("-")==-1 && Signo==true)
	{
		Result = false;
		Obj.value = '-' + Val;
	}
	event.returnValue = Result;
}

function ValidaEspacioBlanco(value)
{
	if (String.fromCharCode(event.keyCode)==" ")
	{
		event.returnValue = false;
	}
}

function LimpiarControl(Control)
{	
	Obj = document.getElementById(Control);
	Obj.value = '';		
}
