function Erase2()
{
	document.getElementById('father').innerHTML = '';
	document.getElementById('dp').innerHTML = '';
	document.getElementById('cancelar').innerHTML = '';
	document.getElementById("modulos").innerHTML="";
	document.getElementById("modulos").style.border="";
}
var contador = 0;
function showmy2(ids,name,vector,con){
	vec = vector.split(",");
	con = con.split(",");
	cuerpo = "";
	check = "";
	color = "";
	disabled = "";
	contador = vec.length/2; 
	for(i=0;i<vec.length;i+=2)
	{
		for(j=0;j<con.length;j+=2)
		{
			if(vec[i]==con[j+1] && ids == con[j])
			{
				check = "checked";
				break;
			}
			if(vec[i]==con[j+1])
			{
				disabled = "disabled";
				color = "green";
			}
		}
		cuerpo = cuerpo+"<input type='radio' name='modulo' id='modulo' value='"+vec[i]+"' "+check+" "+disabled+"/><span style='color:"+color+"'>"+vec[i+1]+"</span>";
		check = "";
		color = "";
		disabled = "";
	}
	if(document.getElementById("msgbox"))
	document.getElementById("msgbox").innerHTML = "";
	document.getElementById("modulos").style.border="1px solid green";
	document.getElementById("modulos").style.background="";
	document.getElementById("modulos").innerHTML = cuerpo+"<input type='submit' value='Grabar' id='btn_modulos' onclick='Join2(this); return false;' />";
	document.getElementById("dp").innerHTML = ids;
	document.getElementById("father").innerHTML = name;
	if(document.getElementById('father').innerHTML != '')
	{
		document.getElementById('cancelar').innerHTML = "<input type = 'button' value = 'Cancelar' id='Cancel' onclick='Erase2();' />";
	}
}

function Join2(d)
{
	if(d.id == 'insert')
		boton = d.value;
	if(d.id == 'delete')
		boton = d.value;
	if(d.id == 'update')
		boton = d.value;
	document.getElementById('insert').value = 'Crear';
	document.getElementById('menu').disabled = '';
	if(d.id != 'btn_modulos')
		datos = 'menus='+document.getElementById('menu').value+'&padre='+document.getElementById('father').innerHTML+'&dp='+document.getElementById('dp').innerHTML+'&boton='+boton;
	else
	{
		boton = d.value;
		var i
	    for (i=0;i<=contador;i++)
		{
    	   if (document.menus.modulo[i].checked)
		   {
        	  break;
		   }
	    }
    	Modulo = document.menus.modulo[i].value+'&id='+document.getElementById('dp').innerHTML
		datos = 'modulo='+Modulo+'&boton='+boton;
	}
	FAjax2('include/inserta.php','show',datos,'POST');
}

function creaXMLHttpRequest2(){
  var objetoXML=false;
  try {
   objetoXML = new ActiveXObject("Msxml2.XMLHTTP");
  } catch (e) {
   try {
     objetoXML = new ActiveXObject("Microsoft.XMLHTTP");
     } 
     catch (E) {
     objetoXML = false;
   }
  }

  if (!objetoXML && typeof XMLHttpRequest!='undefined') {
   objetoXML = new XMLHttpRequest();
  }
  return objetoXML;
}

 function FAjax2 (url,capa,valores,metodo)
{
   var ajax=creaXMLHttpRequest2();
   var capaContenedora = document.getElementById(capa);
   

/* metodo POST*/
 if(metodo.toUpperCase()=='POST'){
    ajax.open ('POST', url, true);
    ajax.onreadystatechange = function() {
         if (ajax.readyState==1) {
                 capaContenedora.innerHTML="Cargando.......";
         }
         else if (ajax.readyState==4){
            if(ajax.status==200)
            {
                 document.getElementById(capa).innerHTML=ajax.responseText; 
            }
            else if(ajax.status==404)
                 {

                     capaContenedora.innerHTML = "La direccion existe";
                 }
             else
                 {
                     capaContenedora.innerHTML = "Error: ".ajax.status;
                 }
        }
    }
    ajax.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
    ajax.send(valores);
    return;
}
/* metodo GET*/
if (metodo.toUpperCase()=='GET'){

    ajax.open ('GET', url, true);
    ajax.onreadystatechange = function() {
         if (ajax.readyState==1) {
                 capaContenedora.innerHTML="Cargando.......";
         }
         else if (ajax.readyState==4){
            if(ajax.status==200){ 
                 document.getElementById(capa).innerHTML=ajax.responseText; 
            }
            else if(ajax.status==404)
                 {

                     capaContenedora.innerHTML = "La direccion existe";
                 }
                 else
                 {
                     capaContenedora.innerHTML = "Error: ".ajax.status;
                 }
        }
    }
    ajax.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
    ajax.send(null);
    return
}
}