function openPage(pagina){
	//alert("ok");
	p = window.open(pagina,'JELA','width=600, height=640, menubar=no, statusbar=no, scrollbars=no');
	if (window.focus) {p.focus()} //Checar las funciones en el template
}

function OpenCalendar(FieldName,idCal)
{
	var curdate = new Date();
	var YearToUse = curdate.getFullYear();
	var MonthToUse = curdate.getMonth() + 1;
	var DateToUse = curdate.getDay();
	$.post("calendar.php", { year: YearToUse, month: MonthToUse, date: DateToUse, field: FieldName, id: idCal},
  	function(data)
	{
    		$('#' + FieldName + 'Calendar').html(data);
  	});
}

function ProcessCalendar(YearToUse, MonthToUse, FieldName, idCal)
{
	$.post("calendar.php", { year: YearToUse, month: MonthToUse, field: FieldName, id: idCal },
  	function(data)
	{
		$('#' + FieldName + 'Calendar').fadeOut("fast");
    		$('#' + FieldName + 'Calendar').html(data);
		$('#' + FieldName + 'Calendar').fadeIn("slow");
  	});
	document.getElementById('fecha' + idCal).value = "";
}

function UpdateTextField(FieldName, DayDate)
{
	$('#' + FieldName).val(DayDate);
}

function changeClass(divIdSelected)
{
	var aux = new Array();
	aux = divIdSelected.split('-');
	var className = 'class'; //for Firefox
	//Detect browser
	if (/MSIE (\d+\.\d+);/.test(navigator.userAgent))
		className = 'className';
	if(aux[0] == '1') //Calendario 1
	{
		try {
			document.getElementById(idLast1.id).setAttribute(className,"DateNumber");
		}
		catch (e){
			//alert(e);
		}
		ds = document.getElementById(divIdSelected)
		ds.setAttribute(className, "DateToday");
		idLast1 = ds;	
	}
	else
	{
		try {
			document.getElementById(idLast2.id).setAttribute(className,"DateNumber");
		}
		catch (e){
			//alert(e);
		}
		ds = document.getElementById(divIdSelected)
		ds.setAttribute(className, "DateToday");
		idLast2 = ds;
	}
}

function check(fieldName)
{
	try
	{
		if(document.getElementById(fieldName).value=="")
		{
			alert("Por favor introduce el Monto");
			document.getElementById(fieldName).focus();
			document.getElementById(fieldName).select();
			return false;
		}
		else
		{
			if (isNaN(document.getElementById(fieldName).value) == true)
			{
				alert("Introduce únicamente números");
				document.getElementById(fieldName).focus();
				document.getElementById(fieldName).select();
				return false;
			}
			else
				return true;
		}
	}
	catch (e){
		alert(e);
		return false;
	}
}

function clearFechas()
{
	document.getElementById('fecha1').value = "";
	document.getElementById('fecha2').value = "";
}

function doClick(buttonName,e)
{
        var key;
        if(window.event)
             key = window.event.keyCode;     //IE
        else
              key = e.which;     //firefox
        if (key == 13)
        {
            //Get the button the user wants to have clicked
			doAction();
        }
}

function doAction()
{
	if(check('txtMonto'))
	{
		ajaxFunction();
	}
}

function ajaxFunction()
{
	var ajaxRequest;  // The variable that makes Ajax possible!
	try
	{
		// Opera 8.0+, Firefox, Safari
		ajaxRequest = new XMLHttpRequest();
	}
	catch (e)
	{
		// Internet Explorer Browsers
		try
		{
			ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e)
		{
			try
			{
				ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch (e)
			{
				// Something went wrong
				alert("Tu navegador no soporta AJAX");
				return false;
			}
		}
	}
	// Create a function that will receive data sent from the server
	ajaxRequest.onreadystatechange = function()
	{
		//alert('ReadyStateChange');
		if(ajaxRequest.readyState == 4){
			var ajaxDisplay = document.getElementById('ajaxDiv');
			ajaxDisplay.innerHTML = ajaxRequest.responseText;
		}
	}
	var monto = document.getElementById('txtMonto').value;
	var fechaHaberPagado = document.getElementById('fecha1').value;
	var fechaPagara = document.getElementById('fecha2').value;
	var queryString = "?monto=" + monto + "&f1=" + fechaHaberPagado + "&f2=" + fechaPagara;
	//alert('RecAct.php' + queryString);
	ajaxRequest.open("GET", "RecAct.php" + queryString, true);
	
	//ajaxRequest.open("POST", "RecAct.php", true);
	ajaxRequest.send(null); 
}