function Descargar(obj,usu,cnt,maxd,rol,len){
	nombre=obj.getAttribute("nombre");
	if (usu == null){
		if (len == 'ESP'){
			document.location = "../log_doc.html";
		} else {
			if (len == 'ING'){
				document.location = "loguin_user.html";
			} else {
			}
		}
	} else {
		if (((cnt - maxd) >= 0)){
			alert("Ya llego al maximo de descargas permitidas, contactese con el administrador para liberarle mas descargas");
			return false;
		} else {
			// guardamos en los renglones los archivos descargados
			// sumamos 1 al contador de descargas
			cnt++;

			GuardoDescarga(nombre,usu,cnt,maxd);

			// guardamos la session de cantidad de descargas

			//alert('descargas.Descargas ='+cnt);			

			GuardoSession("cntdescargas",cnt);

			if (cnt == maxd){

				miPeticion=new peticionAJAX('get','usu='+usu,xxx);

				//url=config.URLBASE+"../php/setLimieteDescargas.php";  // COMENTAR CUANDO SUBA AL SERVER

				url=config.URLBASE+"../php/setLimiteDescarga.php";				

				aRequest=new Ajax.Request(url,miPeticion);			

			}

			return true;

		}

	}

}



function GuardoDescarga(arc,usu,cnt,maxdes){

	miPeticion=new peticionAJAX('get','arc='+arc+'&usu='+usu+'&cnt='+cnt+'&max='+maxdes,xxx);

	url=config.URLBASE+"../php/setDescargas.php";

	aRequest=new Ajax.Request(url,miPeticion);

}



function GuardoSession(ses,val){

	miPeticion=new peticionAJAX('get','ses='+ses+'&val='+val,xxx);

	url=config.URLBASE+"../php/setSession.php";

	aRequest=new Ajax.Request(url,miPeticion);

}



function xxx(aRequest){}





function DescargaDeUsu(ema,pre){

	miPeticion=new peticionAJAX('get','ema='+ema,DescargaDeUsu2);

	url=config.URLBASE+pre+"php/getDescDeUsu.php";

	aRequest=new Ajax.Request(url,miPeticion);

}



function DescargaDeUsu2(aRequest){		

	jUnaCol=aRequest.responseText;

	if (jUnaCol != 'NO_HAY_DATOS'){

		obj=$('contenedor');

		txt = "";

		txt = txt + "<table width='650' border='0' cellpadding='0'>";

		txt = txt + "<tr>";

		txt = txt + "<td width='7'>&nbsp;</td>";

		txt = txt + "<td><table width='633' border='1' cellpadding='0' bordercolor='#CCCCCC'>";

		txt = txt + "<tr>";

		txt = txt + "<td width='172' align='center'>Descarga de Documentos </td>";

		txt = txt + "<td width='105' align='center'>Fecha</td>";

		txt = txt + "<td width='340' align='center'>Documento</td>";

		txt = txt + "</tr>";

		vec = jUnaCol.parseJSON(); 

		for (i=0; i<vec.length; i++) { 

			txt = txt + "<tr>";

			txt = txt + "<td>&nbsp;</td>";

			fecha = formateofech(vec[i].parseJSON().FCH);

			txt = txt + "<td>" + fecha +"</td>";

			txt = txt + "<td>" + vec[i].parseJSON().ARC + "</td>";

			txt = txt + "</tr>";

		}	

		txt = txt + "</table>";

		obj.innerHTML = txt;

	}

}





/*

txt = txt + "<tr>";

txt = txt + "<td rowspan='2'>&nbsp;</td>";

txt = txt + "<td>" + vec[i].parseJSON().FCH +"</td>";

txt = txt + "<td>" + vec[i].parseJSON().ARC + "</td>";

txt = txt + "</tr>";

txt = txt + "</table></td>";

txt = txt + "</tr>";

txt = txt + "</table>";

*/
