function crearobjetus() {
    var objetus;
    try {
        objetus = new ActiveXObject("Msxml2.XMLHTTP");
    } catch (e) {
        try {
            objetus= new ActiveXObject("Microsoft.XMLHTTP");
        } catch (E) {
            objetus= false;
        }
    }

    if (!objetus && typeof XMLHttpRequest!='undefined') {
        objetus = new XMLHttpRequest();
    }
    return objetus;
}

function ajaxPost(opcions) {
    var _objetus=crearobjetus(); //crear objeto
    var _values_send=opcions; //variables
    var _URL_="ajax.php?"; //URL
    _objetus.open("POST",_URL_,true); //abrir procesador
    _objetus.setRequestHeader('Content-Type','application/x-www-form-urlencoded'); //cabeceras POST
    _objetus.send('&'+_values_send); //enviar variables
    return _objetus;
}

/*function calcularPuntos(opcions)
{
    var conexio = ajaxPost(opcions);

    conexio.onreadystatechange=function() { //funcion controlador
        if (conexio.readyState==4) //control de estados del proceso
        {
            //si se da un status 200 (TERMINADO CON EXITO)
            if(conexio.status==200)
            {
                //procesos que se realizaran con los datos obtenidos
                var respuesta=conexio.responseXML;
                var _tot = respuesta.getElementsByTagName('puntos_totales').item(0).firstChild.data;
                var _dsp = respuesta.getElementsByTagName('puntos_disponibles').item(0).firstChild.data;
                var _tmp = respuesta.getElementsByTagName('puntos_temporales').item(0).firstChild.data;
                //var _precio = respuesta.getElementsByTagName('precio').item(0).firstChild.data;
                //var _alert = respuesta.getElementsByTagName('alerta').item(0).firstChild.data;

                document.getElementById('puntos_totales').innerHTML=_tot;
                document.getElementById('punts_disponibles').innerHTML=_dsp;
                document.getElementById('punts_temporales').innerHTML=_tmp;
            }
        }
    }
}*/

function calcularPuntos() {
    var doc = document;
    var totalSuma = 0;
    var disponibles = 0;
    var _pdsp = doc.getElementById('puntos_disponibles').innerHTML;
    var _ptot = doc.getElementById('puntos_totales').innerHTML;
    var _ptmp = doc.getElementById('puntos_temporales').innerHTML;

    var x=document.getElementsByName("respuesta");
    for (var i=0;i<x.length;i++)
    {
        if(x[i].value && parseInt(x[i].value))
            totalSuma += parseInt(x[i].value);
    }
    disponibles = _ptot - totalSuma;

    if(disponibles < 0)
        doc.getElementById('puntos_disponibles').style.color = "#f00";
    else
        doc.getElementById('puntos_disponibles').style.color = "#000";

    doc.getElementById('puntos_disponibles').innerHTML = disponibles;
    doc.getElementById('puntos_temporales').innerHTML = totalSuma;
}