var acc='x';
var arr='';

function informacion_tabla_reg(dia,grado,curso){

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


    document.getElementById('i_h').value='';
    document.getElementById('ds').value='';

    document.getElementById('laborac').innerHTML='';


    var parametros = {"accion":'tabla',"grado":grado,"curso":curso,"dia":dia};
                $.ajax({
                data:  parametros,
                url:"app/model/insertar_horario.php",
                type: "POST",
            success: function(res){
                document.getElementById('laborac').innerHTML=res;
           }})

}


function lpagprin(){
    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('i_h').value='';

    document.getElementById('laborac').innerHTML='';
    document.getElementById('p_id1').focus();
}

//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

function eliminar(dia,grado,curso,asignatura,codigo){


var parametros = {"accion":'eliminar_horario',
                          "dia":dia,
                          "grado":grado,
                          "curso":curso,
                          "asignatura":asignatura,
                          "codigo":codigo

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

                            alert(response);
                            informacion_tabla_reg(dia,grado,curso);
                    
                }
        });
}

//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

function grabar(){

var dia=get("p_id1");
var grad=get("g_id1");
var cur=get("c_id1");
var asig=get("a_id1");
var i_h=get("i_h");
var ds=get("ds");

if(dia==''){
    alert("Ingrese D&iacute;a");
    exit();
}
if(grad==''){
    alert("Ingrese Grado");
    exit();
}
if(cur==''){
    alert("Ingrese Curso");
    exit();
}
if(asig==''){
    alert("Ingrese Asigantura");
    exit();
}

var op='';
var datos='';

if(acc=='x'){
   op='x';
   arr='';
}else{
     op=acc;
     acc='x';
     datos=arr;
     arr='';
}

var parametros = {"accion":'grabar_horario',
                          "operacion":op,
                          "dia":dia,
                          "grado":grad,
                          "curso":cur,
                          "asignatura":asig,
                          "i_h":i_h,
                          "orden":ds,
                          "datos":datos
                           };

        $.ajax({
                data:  parametros,
                url:"app/model/insertar_horario.php",
                type:  'post',
                success:function (response){
//                         alert(response);
                        if(response==0){

                            alert("Horario Existente");
                            informacion_tabla_reg();

                        }else if(response==1){

                            alert("Horario Registrado");
                            informacion_tabla_reg(dia,grad,cur);

                        }else if(response==2){

                            alert("Horario Actualizado");
                            informacion_tabla_reg();
                        }
                }
        });

}

//-----------------------------------------------------
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 retornar_menu(){
  document.location.href="../menu.php";
}

