// funciones ajax para la obtencion de las marcas de una cerveceria
var req;

function ajaxActualizarColeccion( capID, userID ){
	actColecc( capID, userID );
}

function ajaxActualizarRepetidas( capID, userID ){
	actRep( capID, userID );
}

function actColecc( capID, userID ){
	var url;
	//Construimos la URL para llamar al mŽtodo de actualizaci—n
	url = 'catalog_caps_xml.php';
	url = url + '?id=' + capID + '&user=' + userID + '&type=C';
	actExecAjax(url);
}

function actRep( capID, userID ){
	var url;
	//Construimos la URL para llamar al mŽtodo de actualizaci—n
	url = 'catalog_caps_xml.php';
	url = url + '?id=' + capID + '&user=' + userID + '&type=R';
	actExecAjax(url);
}


function actExecAjax( url ){
	if (window.XMLHttpRequest) {
        req = new XMLHttpRequest();
		req.onreadystatechange = cambiarImagen;
        req.open("GET", url, true);
        req.send(null);
    } else if (window.ActiveXObject) {
        req = new ActiveXObject("Microsoft.XMLHTTP");
        if (req) {
            req.onreadystatechange = cambiarImagen;
			req.open("GET", url, true);
            req.send();
        }
    }
}

function cambiarImagen(){
		
	var capid;
	var colid;
	var state;
	var imagen;
	var t;
	var i=0;

	if (req.readyState == 4) { // Complete
		if (req.status == 200) { // OK response
			xml =  req.responseXML;
			if( xml != null ) {
				t = xml.getElementsByTagName("entity");
				if ( t.length > 0 ) {
					for ( i = 0 ; i < t.length ; i++ ) {
						capid = t[i].getAttribute('capid');
						colid = t[i].getAttribute('colid');
						state = t[i].getAttribute('state');
						
						imagen = document.getElementById( colid + "_" +capid );
						if( colid == 'rep'){
							if( state == 'ON'){
								imagen.src="../common/tengo.gif";
							} else {
								imagen.src="../common/notengo.gif";
							}
						} else {
							if( state == 'ON'){
								imagen.src="../common/tengo.gif";
							} else {
								imagen.src="../common/notengo.gif";
							}
						}
					}
				}			
			}
		}
	}	
}