﻿
function getNotas(idUsuario){

	ocultar_botones();

	var aleatorio=Math.random();

	new Ajax.Request(_URL_mapUtilsPetitions+"?sec=getNotas&idUsuario="+idUsuario+"&nocache="+aleatorio,
	{
		method:'get',
		onSuccess: function(transport){
			var response = transport.responseText || "no response text";
			//alert("Success! \n\n" + response);
			
			var equisemeele = getXMLObject(response);
			
			var html= notas_XML_to_HTML(equisemeele);
			$('administrarDIV').innerHTML= html;
		},
		onFailure: function(){ 
			alert(txtErrorRecuperandoNotas[idioma]);
		}
	});

}

function notas_XML_to_HTML(xml){

	var html='';

	if(xml.getElementsByTagName("nota")[0]!=null){
		html+='<table width="100%" border="0"><tr><td rowspan="2" align="center" style="background-color: #FFFBD1">';
		html+='<select name="comboNotas" id="comboNotas">';
		var i=0;
		while(xml.getElementsByTagName("nota")[i]!=null){
			var nota= xml.getElementsByTagName('nota').item(i);
	        var cadena= nota.attributes[1].nodeValue;
			if(cadena.length>25)
				cadena= cadena.substr(0, 25);
			html+='<option value="'+nota.attributes[0].nodeValue+'" title="'+nota.attributes[1].nodeValue+'">'+cadena+'</option>';
			i++;
		}
		html+='</select></td><td align="center" style="background-color: #FFFBD1"><input type="button" class="boton" id="borrarNota" value="'+butBorrarNota[idioma]+'" onclick="borrarNota()" title="'+titleBorrarNota[idioma]+'" /></td></tr>';
		html+='<tr><td align="center" style="background-color: #FFFBD1"><input type="button" class="boton" id="borrar_notas" value="'+titleBorrarTodasNotas[idioma]+'" onclick="borrarNotasAlPlano()" title="'+titleBorrarTodasNotas[idioma]+'" /></td></tr></table>';
	}else{
		html+='<table width="100%" border="0"><tr><td align="center" style="background-color: #FFFBD1">'+txtNoHayNotas[idioma]+'</td></tr></table>';
	}
	
	return html;
}


function addNotaAlPlano(){

		oEstadisticas.setEstadisticasNotaAlPlano();

        var nota = document.getElementById("nota_al_plano").value;
        var x=document.getElementById("xcapturada").value;
        var y=document.getElementById("ycapturada").value;
        var usuario = document.getElementById("idUsuario").value;
//alert(x+" "+y)
        document.getElementById("div_nota_al_plano").style.visibility="hidden";
        opciones='?sec=notaplano&x='+x+'&y='+y+'&nota='+nota+'&idUsuario='+usuario;

        addNota(opciones);
}

function cerrarNotasAlPlano(){

    document.getElementById("div_nota_al_plano").style.visibility="hidden";
	mostrar_botones();

}

function borrarNota(){

	var idUsuario= $('idUsuario').value;
	var gid= $('comboNotas')[$('comboNotas').selectedIndex].value;
	var aleatorio=Math.random();
	
	new Ajax.Request(_URL_mapUtilsPetitions+"?sec=borrarNota&idUsuario="+idUsuario+"&gid="+gid+"&nocache="+aleatorio,
	{
		method:'get',
		onSuccess: function(transport){
			var response = transport.responseText || "no response text";
			//alert("Success! \n\n" + response);
			
			var equisemeele = getXMLObject(response);
			
			var html= notas_XML_to_HTML(equisemeele);
			$('administrarDIV').innerHTML= html;
			
			refrescarPantalla("notas");
		},
		onFailure: function(){ 
			alert(txtErrorBorrandoNota[idioma]);
		}
	});

}

function borrarNotasAlPlano(){
        //document.getElementById("div_nota_al_plano").style.visibility="hidden";
        var usuario = document.getElementById("idUsuario").value;
        opciones='?sec=notaplano&x=1&y=0&nota=&idUsuario='+usuario;
                
        addNota(opciones);
		
		$('administrarDIV').innerHTML= '<table width="100%" border="0"><tr><td align="center" style="background-color: #FFFBD1">'+txtNoHayNotas[idioma]+'</td></tr></table>';
}

function addNota(opciones){

    document.getElementById("cartel").style.visibility="visible";
    ocultar_botones();

	var aleatorio=Math.random();

	new Ajax.Request(_URL_mapUtilsPetitions+opciones+"&nocache="+aleatorio,
	{
		method:'get',
		onSuccess: function(transport){
			var response = transport.responseText || "no response text";
			//alert("Success! \n\n" + response);
			
			var equisemeele = getXMLObject(response);
			
			document.getElementById("cartel").style.visibility="hidden";
			refrescarPantalla("notas");
			mostrar_botones();
		},
		onFailure: function(){ 
			document.getElementById("cartel").style.visibility="hidden";
			mostrar_botones();
			alert(txtErrorInsertandoNota[idioma]);
		}
	});
}


function notasTab(opcion)
{
	if(opcion=='insertar'){
		document.getElementById("notasTDTabAdministrar").style.fontWeight= 'normal'
		document.getElementById("notasTDTabInsertar").style.fontWeight= 'bold'
				
		document.getElementById('notasTDTabAdministrar').style.borderBottom= '1px solid #CF6663'
		document.getElementById('notasTDTabInsertar').style.borderBottom= '0px'
		
		document.getElementById('notasTDTabAdministrar').style.backgroundColor= '#FFFBD1'
		document.getElementById('notasTDTabInsertar').style.backgroundColor= '#FFDC50'
		
		document.getElementById('administrarDIV').style.display= 'none'
		document.getElementById('insertarDIV').style.display= 'inline'
	}
	else if(opcion=='administrar'){
		document.getElementById("notasTDTabInsertar").style.fontWeight= 'normal'
		document.getElementById("notasTDTabAdministrar").style.fontWeight= 'bold'
		
		document.getElementById('notasTDTabInsertar').style.borderBottom= '1px solid #CF6663'
		document.getElementById('notasTDTabAdministrar').style.borderBottom= '0px'
		
		document.getElementById('notasTDTabAdministrar').style.backgroundColor= '#FFDC50'
		document.getElementById('notasTDTabInsertar').style.backgroundColor= '#FFFBD1'
		
		document.getElementById('insertarDIV').style.display= 'none'
		document.getElementById('administrarDIV').style.display= 'inline'
	}

}


