var xhr;

function CreateXmlHttp(){
    // Probamos con IE
    try{        // FuncionarÃ¡ para JavaScript 5.0
        xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
    }
    catch(e){
        try{
            xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
        }
        catch(oc){
            xmlHttp = null;
        }
    }
    // Si no se trataba de un IE, probamos con esto
    if(!xmlHttp && typeof XMLHttpRequest != "undefined")
    {
        xmlHttp = new XMLHttpRequest();
    }

    return xmlHttp;
}

//-----------------------------------------------------
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 comprobar_codigo(){

    var cod=document.getElementById('codigo').value;

    var parametros = {"accion":'info_comp_codigo',"codigo":cod};
        $.ajax({
                data:  parametros,
                url:"app/model/insertar_boletin.php",
                type:  'post',
                success:function (response){

                    if(response=='no'){
                       alert('No registrado');
                       document.getElementById('codigo').focus();
                       

                    }else {
                        var res = response.split("+");
                        document.getElementById('nombres').value=res[0];
                        document.getElementById('g_id1').value=res[1];
                        document.getElementById('g_id2').value=res[2];
                        document.getElementById('c_id1').value=res[3];
                        document.getElementById('c_id2').value=res[4];
                        document.getElementById('j_id1').value=res[5];
                        document.getElementById('j_id2').value=res[6];
                        document.getElementById('s_id1').value=res[7];
                        document.getElementById('s_id2').value=res[8];

                   }
            }
        });

}

//-------------------------------------

function limiar_info_boletin_2(){

    document.getElementById('codigo').value='';
    document.getElementById('nombres').value='';

    document.getElementById('g_id1').value='';
    document.getElementById('g_id2').value='';

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

    document.getElementById('j_id1').value='';
    document.getElementById('j_id2').value='';

    var frame = document.getElementById("preview2"),
    frameDoc = frame.contentDocument || frame.contentWindow.document;
    frameDoc.documentElement.innerHTML = "";

    document.getElementById('s_id1').value='';
    document.getElementById('s_id2').value='';

}


function limiar_info_boletin(){

    document.getElementById('codigo').value='';
    document.getElementById('nombres').value='';

    document.getElementById('g_id1').value='';
    document.getElementById('g_id2').value='';

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

    document.getElementById('j_id1').value='';
    document.getElementById('j_id2').value='';
    
    var frame = document.getElementById("preview2"),
    frameDoc = frame.contentDocument || frame.contentWindow.document;
    frameDoc.documentElement.innerHTML = "";


    document.getElementById('s_id1').value='';
    document.getElementById('s_id2').value='';

}


function limiar_info_boletin_curso(){

    var frame = document.getElementById("preview2"),
    frameDoc = frame.contentDocument || frame.contentWindow.document;
    frameDoc.documentElement.innerHTML = "";

    document.getElementById('g_id1').value='';
    document.getElementById('g_id2').value='';

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

    document.getElementById('s_id1').value='';
    document.getElementById('s_id2').value='';
    


}

function pdf(){


    var cod=get('codigo');
    var folio=get('folio');
   
    if(cod==''){
        alert('Ingrese C\u00F3digo');
        exit();
    }
  
    if(folio==''){
        alert('Ingrese No. de Folio');
        exit();
    }
    var x=Math.random() * (50 - 10) + 10;   
    window.open("app/model/reportes/boletin_academico.php?cod="+cod+"&folio="+folio+"&x="+x, "preview2");

}

//----------------------

function html(){

    var cod=get('codigo');
    
    
    if(cod==''){
        alert('Ingrese C\u00F3digo');
        exit();
    }
 
    

    window.open("app/model/reportes/boletin_academico.php?ver=2&cod="+cod,'popup','width=600,height=500');

}


function pdf_curso(){

   // alert("GENERAR PROCESO LOCALMENTE");
   // exit();

  
    var grad=get('g_id1');
    var curs=get('c_id1');

    
    if(grad==''){
        alert('Ingrese Grado');
        exit();
    }
    
    if(curs==''){
        alert('Ingrese Curso');
        exit();
    }
    
  
    window.open("app/model/reportes/boletin_academico_curso.php?grado="+grad+"&curso="+curs,'preview2');
    

}

//-----------------------------------

function pdf_curso_indice(){

var p=get('p1');  
var q=get('p2'); 

window.open("app/model/reportes/boletin_academico_indice.php?pagina="+p,'preview2');

}

//-----------------------------------

function paginas(){
         
       var parametros = {"accion":'paginas'};
                    $.ajax({
                    data:  parametros,
                    url:"app/model/catalogos.php",
                    type: "POST",
                success: function(opciones){
                 
                   var elem=opciones.split('/');
                
                   document.getElementById('p1').value=0;
                   document.getElementById('p2').value=elem[0]-1;
                                     
                }
            })

        
}

//-----------------------------------

function menos(){
          
var p=get('p1');  


if (p>0){
    p=parseInt(p)-1;
    document.getElementById('p1').value=p;
}
    
        
}

//-----------------------------------

function mas(){
          
var p=get('p1');  
var q=get('p2');

p=parseInt(p)+1;
document.getElementById('p1').value=p;

    
        
}
//-----------------------------------

function consecutivo_folio(){
    
       
       var parametros = {"accion":'no_folio'};
                    $.ajax({
                    data:  parametros,
                    url:"app/model/catalogos.php",
                    type: "POST",
                success: function(opciones){
                   document.getElementById('folio').value=opciones;
                   
                                     
                }
            })

        
}

//-----------------------------------

function actualizar_folio(){

    var grado=get('g_id1');
    var curso=get('c_id1');
    var folio=get('folio');
    

       var parametros = {"accion":'actualizar_folio',"grado":grado,"curso":curso,"numero":folio};
                    $.ajax({
                    data:  parametros,
                    url:"app/model/catalogos.php",
                    type: "POST",
                success: function(opciones){
                   document.getElementById('folio').value=opciones;
                   
                                     
                }
            })

}