function navimage_on(which) {
	if (!document.getElementById)
		return true;
	var target = document.getElementById("nav" + which);
	if (target != null)
		target.src = target.src.replace("_off", "_on");
}
function navimage_off(which, nodimchoice) {
	if (!document.getElementById)
		return true;
	var target = document.getElementById("nav" + which);
	if (!nodimchoice && target != null)
		target.src = target.src.replace("_on", "_off");
}

function jumpToPage() {
	selObj = document.jumpForm.jumpTo;
	selIndex = selObj.selectedIndex;
	this.location = selObj[selIndex].value;
}

function AceptaNumeros() {
	if ((event.keyCode < 48) || (event.keyCode > 57)) {
		event.keyCode = "";
	}
}

function NoAceptaTexto() {
		event.keyCode = "";
}

function CalculaOpciones() {
	var threshold = 10;
	var creditos = 0;
	var creditoMateria = 6;
	var creditoTaller = 2;
	var costomateria = document.forma.costomateria.value;
	var costotaller = document.forma.costotaller.value;
	
	var numcredmat = document.forma.numcredmat.value;
	var numcredtall = document.forma.numcredtall.value;
	
	var costocont = document.forma.costocont.value;

	var costocred1 = document.forma.costocred1.value;
	var costocred2 = document.forma.costocred2.value;
	var costocred3 = document.forma.costocred3.value;
	var costocred4 = document.forma.costocred4.value;
	var costocred5 = document.forma.costocred5.value;
	var materias;
	var talleres;
	var beca;	
	var opcionRad =0;

	for (var i=0; i < document.forma.radPosgrado.length; i++)
   {
   if (document.forma.radPosgrado[i].checked)
      {
       opcionRad = document.forma.radPosgrado[i].value;
      }
   }	

	// si no marcaron una opcion para calcular
    if (opcionRad ==0)
		{
			alert('Debes de seleccionar un Posgrado');
		}	
	else
		{	
			if (opcionRad ==1)
				{
					if (document.forma.materias_ma.value=='')
					{		materias = 0	}
					else
					{		materias = document.forma.materias_ma.value	}
					if (document.forma.talleres_ma.value=='')
					{		talleres = 0	}
					else
					{		talleres = document.forma.talleres_ma.value	}	
					if (document.forma.beca_ma.value=='')
					{		beca = 0	}
					else
					{		beca = document.forma.beca_ma.value}
				}    
			else
				{
					if (document.forma.materias_es.value=='')
					{		materias = 0	}
					else
					{		materias = document.forma.materias_es.value	}
					if (document.forma.beca_es.value=='')
					{		beca = 0	}
					else
					{		beca = document.forma.beca_es.value}
					talleres = 0;
				}
			
				
			creditos = (materias * creditoMateria) + (talleres * creditoTaller);
			

			if (opcionRad ==1)
				{
					if (creditos < threshold)
					{
					beca = Math.round(creditos / 16 * beca / 5) * 5;
					}
				}

			Opcion1 = ((costocont*materias*numcredmat)+(costocont*talleres*numcredtall)) - (((costocont*materias*numcredmat)+(costocont*talleres*numcredtall))*(beca/100))
			
			Opcion2a = (( ((costocred1*materias*numcredmat)+(costocred1*talleres*numcredtall)) *0.5) - (( ((costocred1*materias*numcredmat)+(costocred1*talleres*numcredtall)) *0.5)*(beca/100)))
			Opcion2b = Opcion2a/3
			
			Opcion3 = (( (((costocred2*materias*numcredmat)-0)+(costocred2*talleres*numcredtall)) *0.25) - (( (((costocred2*materias*numcredmat)-0)+(costocred2*talleres*numcredtall)) *0.25)*(beca/100)))
			
			Opcion4 = (( ((costocred3*materias*numcredmat)+(costocred3*talleres*numcredtall))) - (( ((costocred3*materias*numcredmat)+(costocred3*talleres*numcredtall)))*(beca/100)))
			Opcion4a = Math.round(Opcion4 * 0.33333)
			Opcion4b = Math.round((Opcion4 - Opcion4a)/4)
			
			Opcion5		= (( ((costocred4*materias*numcredmat)+(costocred4*talleres*numcredtall))) - (( ((costocred4*materias*numcredmat)+(costocred4*talleres*numcredtall)))*(beca/100)))
			Opcion5a	= Math.round(Opcion5 * 0.25)
			Opcion5b	= Opcion5 / 6
			Opcion5b    = Math.round(Opcion5b)
			
			Opcion6 = (( ((costocred5*materias*numcredmat)+(costocred5*talleres*numcredtall)) *0.25) - (( ((costocred5*materias*numcredmat)+(costocred5*talleres*numcredtall)) *0.25)*(beca/100)))


			document.forma.Op1.value = Opcion1.toFixed(1);
			
			document.forma.Op2a.value = Opcion2a.toFixed(1);
			document.forma.Op2b1.value = Opcion2b.toFixed(1);
			document.forma.Op2b2.value = Opcion2b.toFixed(1);
			document.forma.Op2b3.value = Opcion2b.toFixed(1);
			
			document.forma.Op3a.value = Opcion3.toFixed(1);
			document.forma.Op3b1.value = Opcion3.toFixed(1);
			document.forma.Op3b2.value = Opcion3.toFixed(1);
			document.forma.Op3b3.value = Opcion3.toFixed(1);
			
			document.forma.Op4a.value = Opcion4a.toFixed(1);
			document.forma.Op4b1.value = Opcion4b.toFixed(1);
			document.forma.Op4b2.value = Opcion4b.toFixed(1);
			document.forma.Op4b3.value = Opcion4b.toFixed(1);
			document.forma.Op4b4.value = Opcion4b.toFixed(1);
			
			document.forma.Op5a.value = "**N.A.**";
			document.forma.Op5b1.value = Opcion5b.toFixed(1);
			document.forma.Op5b2.value = Opcion5b.toFixed(1);
			document.forma.Op5b3.value = Opcion5b.toFixed(1);
			document.forma.Op5b4.value = Opcion5b.toFixed(1);
			document.forma.Op5b5.value = Opcion5b.toFixed(1);
			document.forma.Op5b6.value = Opcion5b.toFixed(1);
	}
}
