var m_grupos = ["PERSONAL_DE_OFICIOS","AUXILIARES"]

var PERSONAL_DE_OFICIOS = {"PERSONAL_DE_OFICIOS___CONTESTACIONES_AL_PROGRAMA":36,
"PERSONAL_DE_OFICIOS___CUESTONARIO_DE_TEST_PSICOTECNICOS":20,
"PERSONAL_DE_OFICIOS___COLECCION_COMPLETA":56}

var AUXILIARES = {"AUXILIARES___CONTESTACIONES_AL_PROGRAMA":50,
"AUXILIARES___TEST_DEL_TEMARIO":35,
"AUXILIARES___COLECCION_COMPLETA":50}


function calcular(){
	/*Recorremos las matrices*/
	var precio_total = 0;
	for (aux in m_grupos){
		/*Obtenemos el array*/
		m_nombres = eval(m_grupos[aux])
		
		/*Obtenemos las unidades seleccionadas*/
		var precio_total_grupo = 0
		for (campo in m_nombres){
			objInputText = eval("window.document.forms[0]." + campo);
			// Unidades seleccionadas
			unidades = objInputText.value;
			unidades = parseInt(unidades)
			if (isNaN(unidades)){
				unidades = 0;
			}
			if (unidades == 0){
				objInputText.value = "";
			}
			
			//Precio por unidad
			precio = m_nombres[campo];

			valor = unidades * precio; 
			
			//Ponemos el valor
			objTotal = document.getElementById(campo + "_TOTAL");
			if (valor != 0){
				objTotal.innerText = convertirEnDecimal(valor);
			}
			else{
				objTotal.innerText = "-";
			}
			
			//Sumamos al total
			precio_total_grupo += valor;
			
			
		}
		objAgTotal = document.getElementById(m_grupos[aux] + "_TOTAL");
		if (precio_total_grupo != 0){
			objAgTotal.innerText = convertirEnDecimal(precio_total_grupo);
		}
		else{
			objAgTotal.innerText = " ";
		}
	
	}
	
}

function convertirEnDecimal(qvalor){
	/*Ponemos tres decimales*/
	qvalor += 0.001;
	
	/*Lo convertimos en string*/
	//qvalor += "";
	var aux = new String(qvalor);
	
	/*Sustituimos el punto por una coma*/
	posicion = aux.indexOf(".");
	parteEntera = aux.substring(0, posicion)
	parteDecimal = aux.substring(posicion + 1, aux.length)
	aux = parteEntera + "," + parteDecimal;
	
	/*Eliminamos el último caracter*/
	aux = aux.substring(0, aux.length - 1);
	
	return aux;
}
