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('p_id1').value='';
    document.getElementById('p_id2').value='';

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

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

    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 per=get('p_id1');
    var cod=get('codigo');
    
    if(per==''){
        alert('Ingrese Periodo');
        exit();
    }
    
    if(cod==''){
        alert('Ingrese C\u00F3digo');
        exit();
    }
    window.open("app/model/reportes/boletin_academico.php?per="+per+"&cod="+cod, "preview2");
    //window.open("app/model/reportes/boletin_academico.php?per="+per+"&cod="+cod,'popup','width=300,height=400');

}

function html(){
    var per=get('p_id1');
    var cod=get('codigo');
    
    if(per==''){
        alert('Ingrese Periodo');
        exit();
    }
    
    if(cod==''){
        alert('Ingrese C\u00F3digo');
        exit();
    }
    //window.open("app/model/reportes/boletin_academico.php?ver=1&per="+per+"&cod="+cod, "preview2");
    window.open("app/model/reportes/boletin_academico.php?ver=2&per="+per+"&cod="+cod,'popup','width=600,height=500');

}


function pdf_curso(){
    var per=get('p_id1');
    var grad=get('g_id1');
    var curs=get('c_id1');
    
    if(per==''){
        alert('Ingrese Periodo');
        exit();
    }
    
    if(grad==''){
        alert('Ingrese Grado');
        exit();
    }
    
    if(curs==''){
        alert('Ingrese Curso');
        exit();
    }
    
    window.open("app/model/reportes/boletin_academico_curso.php?per="+per+"&grado="+grad+"&curso="+curs,'preview2');
   //  window.open("app/model/reportes/boletin_academico_curso.php?per="+per+"&grado="+grad+"&curso="+curs,'popup','width=300,height=400');

//    alert('Proceso Finalizado');
// var parametros = {"per":per,"grado":grad,"curso":curs};
// alert('aa');
//                    $.ajax({
//                    data:  parametros,
//                    url:"app/model/reportes/boletin_academico_curso.php",
//                    type: "POST",
//                success: function(opciones){
//                
//                }});

}

