function myValidate(f) {
        if (document.formvalidator.isValid(f)) {
                f.check.value='<?php echo JUtility::getToken(); ?>';//send token
                if(validaImporte())
                {
                	periodicidadHabilitada(true);
	                return true; 
                }
        }
        else {
                alert('Algunos valores estan vacios o no son correctos. Por favor, revisa tu formulario.');
        }
        return false;
}

function validaImporte()
{
	var importes = document.getElementsByName('importe');
	for (var j in importes)
	{
		if(importes[j].checked)
		{
			if(importes[j].value == 'otro')
			{
				var valor = document.getElementById('valorImporte').value;
				if(valor != '' && isInt(valor)) { return true; }
			}
			else
				return true;
		}
	}
	alert('Debes seleccionar un importe valido');
	return false;
}

function isInt(x) {
	var y=parseInt(x);
	if (isNaN(y)) return false;
	return x==y && x.toString()==y.toString();
}

function periodicidadHabilitada(habilitada)
{
	var elements = document.getElementsByName('periodicidad');
	if(!habilitada)
		document.getElementById('30dias').checked = "checked";
	for(i=0;i<elements.length;i++)
	{
		if(habilitada)
			elements[i].disabled=false;
		else
			elements[i].disabled=true;
	}
}

function ordenarPor(valor)
{
	document.adminForm['order'].value = valor;
	document.adminForm.submit();
}
