var acc='x';
//-----------------------------------------------------
function get(id){
    return document.getElementById(id).value;
}



//-----------------------------------
function parametro( name ){
	var regexS = "[\\?&]"+name+"=([^&#]*)";
	var regex = new RegExp ( regexS );
	var tmpURL = window.location.href;
	var results = regex.exec( tmpURL );
	if( results == null )
		return "";
	else
		return results[1];
}

//*+++++++++++++++++++++


function reportes(){


var parametros = {"accion":'reportes'

                           };
        $.ajax({
                data:  parametros,
                url:"app/model/insertar_log_comp.php",
                type:  'post',
                success:function (response){

                       document.getElementById('content').innerHTML=response;
                    }

        });
}

function retroces(){
    window.location='logros_competencias.php';
}


function pdf(){

    var per=get("p_id1");
    var grad=get("g_id1");
    var cur=get("c_id1");
    var asig=get("a_id1");
    var docent=get("d_id1");

    if((grad=='')&&(cur=='')&&(per=='')&&(asig=='')&&(docent=='')){
        alert("Ingrese  Valores")
        exit();
    }


    var url;

    if((grad!='')&&(cur!='')&&(per!='')&&(asig!='')&&(docent==''))
    {
        
        url='pdf_con1.php?grado='+grad+'&curso='+cur+'&per='+per+'&asig='+asig;
        window.open('app/model/reportes/'+url,"width=1000,height=500,scrollbars=NO");
    
	}
  
  
  
  /*else   if((grad!='')&&(cur!='')&&(per=='')&&(asig!='')&&(docent==''))
   {
       //alert('2');
        url='pdf_con2.php?grado='+grad+'&curso='+cur+'&asig='+asig;
        window.open('app/model/reportes/'+url,"width=1000,height=500,scrollbars=NO");
   
   }else  if((grad=='')&&(cur=='')&&(per!='')&&(asig=='')&&(docent!=''))
   {
       //alert('3');
       url='pdf_con3.php?per='+per+'&docente='+docent;
       window.open('app/model/reportes/'+url,"width=1000,height=500,scrollbars=NO");
   
   }else    if((grad=='')&&(cur=='')&&(per=='')&&(asig=='')&&(docent!=''))
   {
       //alert('4');
       url='pdf_con4.php?docente='+docent;
       window.open('app/model/reportes/'+url,"width=1000,height=500,scrollbars=NO");
   }
*/

    
}



function limpiarpdf(){
    document.getElementById('g_id1').value='';
    document.getElementById('g_id2').value='';

    document.getElementById('c_id1').value='';
    document.getElementById('c_id2').value='';

    document.getElementById('p_id1').value='';
    document.getElementById('p_id2').value='';

    document.getElementById('a_id1').value='';
    document.getElementById('a_id2').value='';

    document.getElementById('d_id1').value='';
    document.getElementById('d_id2').value='';
}



function grabar(){

var p = parametro( 'pos' );

if (p==""){
    p=0;
}

var per=get("p_id1");
var grad=get("g_id1");
var cur=get("c_id1");
var asig=get("a_id1");
var cod=get("cod");
var des=get("des");

if(per==''){
    alert("Ingrese Periodo");
    exit();
}
if(grad==''){
    alert("Ingrese Grado");
    exit();
}
if(cur==''){
    alert("Ingrese Curso");
    exit();
}
if(asig==''){
    alert("Ingrese Asigantura");
    exit();
}
if(cod==''){
    alert("Ingrese Codigo");
    exit();
}
if(des==''){
    alert("Ingrese Descripción");
    exit();
}

var op='';
if(acc=='x')
    {
        op='x';
    }else{
        op=acc;
        acc='x';
    }
//    alert(op+"  "+acc);

var parametros = {"accion":'grabar_log_comp',
                          "operacion":op,
                          "per":per,
                          "grado":grad,
                          "curso":cur,
                          "asignatura":asig,
                          "codigo":cod,
                          "descrip":des

                           };



        $.ajax({
                data:  parametros,
                url:"app/model/insertar_log_comp.php",
                type:  'post',
                success:function (response){
                  

                        if(response==0){
                            alert("Logro ya Ingresado");

                        }else  if(response==1){

                            alert("Registro Grabado");
                            informacion_tabla();

                        }else if(response==2){

                            alert("Registro Actualizado");
                            informacion_tabla();
                        }

                }});

}




function informacion_tabla(){
   
    var per=get("p_id1");
    var grad=get("g_id1");
    var cur=get("c_id1");
    var asig=get("a_id1");

    

   var parametros = {"accion":'mostrar_tabla',"asignatura":asig,"periodo":per,"grado":grad,"curso":cur};
                   $.ajax({
                   data:  parametros,
                   url:"app/model/insertar_log_comp.php",
                   type: "POST",
                   success: function(respuesta){

                        document.getElementById("logrost").innerHTML=respuesta;

            }})

}

function eliminar(orden){


var parametros = {"accion":'eliminar_logros_comp',
                          "orden":orden

                           };
        $.ajax({
                data:  parametros,
                url:"app/model/insertar_log_comp.php",
                type:  'post',
                success:function (response){

                            alert(response);
                            informacion_tabla();

                }
        });
}


function editar(orden){

    acc=orden;
    var parametros = {"accion":'editar_logros_competencias',
                           "orden":orden

                           };
        $.ajax({
                data:  parametros,
                url:"app/model/insertar_log_comp.php",
                type:  'post',
                success:function (response){

                            var arr=response.split(";");

                            document.getElementById('g_id1').value=arr[2];
                            document.getElementById('g_id2').value=arr[3];

                            document.getElementById('c_id1').value=arr[4];
                            document.getElementById('c_id2').value=arr[5];

                            document.getElementById('p_id1').value=arr[0];
                            document.getElementById('p_id2').value=arr[1];

                            document.getElementById('a_id1').value=arr[6];
                            document.getElementById('a_id2').value=arr[7];

                            document.getElementById('cod').value=arr[8];
                            document.getElementById('des').value=arr[9];
                            

                }});
}


function limpiarpp(){
    
    document.getElementById('g_id1').value='';
    document.getElementById('g_id2').value='';

    document.getElementById('c_id1').value='';
    document.getElementById('c_id2').value='';

    document.getElementById('p_id1').value='';
    document.getElementById('p_id2').value='';

    document.getElementById('a_id1').value='';
    document.getElementById('a_id2').value='';

    document.getElementById('cod').value='';
    document.getElementById('des').value='';


    document.getElementById('logrost').innerHTML='';
}

//----------------------------------
function menu_ingresar(){
  document.location.href="../ingresar.php?action=";
}
