var rtAtiImg;

function comprobar(){

if(  document.forms[0].imgSalida)
    {
        document.getElementById('infoimg').value='si';
    }else{

        document.getElementById('infoimg').value='no';
    }
}


//-----------------------------------------------------
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];
}
//no
function grabar(){
    var ins=get('ins');
    var bsdt=get('bsd');
    var enc=get('enc');
    var enc1=get('enc1');
    var dcr=get('dcr');
    var mcp=get('mcp');
    var redu=get('redu');
    var cdne=get('dn');
    var leyen=get('leyen');


    var sede=get('sede');
    var escudo=get('escudo');
    var conare=get('conare');
    var conasig=get('conasig');
    var defare=get('defare');
    var codalum=get('secodalumde');

   alert(ins+" - "+bsdt+"  - "+enc+"   - "+enc1+"  - "+dcr+"  - "+mcp+"   - "+redu+"   - "+cdne+"  - "+leyen);


    var parametros = {"accion":'guardar_registros',"ins":ins,
                                                   "bsdt":bsdt,
                                                   "enc":enc,
                                                   "enc1":enc1,
                                                   "dcr":dcr,
                                                   "mcp":mcp,
                                                   "redu":redu,
                                                   "cdne":cdne,
                                                   "leyen":leyen,
                                                   "sede":sede,
                                                   "escudo":escudo,
                                                   "conare":conare,
                                                   "conasig":conasig,
                                                   "defare":defare,
                                                   "codalum":codalum

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

        });
}







function limpiarprin(){
    document.getElementById('ins').value="";
    document.getElementById('bsd').value="";
    document.getElementById('enc').value="";
    document.getElementById('enc1').value="";
    document.getElementById('dcr').value="";
    document.getElementById('mcp').value="";
    document.getElementById('redu').value="";
    document.getElementById('dn').value="";
    document.getElementById('leyen').value="";


    document.getElementById('sede').value="";
    document.getElementById('defare').value="";
    document.getElementById('codalum').value="";
    document.getElementById('sede').value="";


    document.getElementById('pla').value="";
    document.getElementById('reg').value="";


    document.getElementById('nom_rec').value="";
    document.getElementById('ced_rec').value="";
    document.getElementById('nom_sec').value="";
    document.getElementById('ced_sec').value="";
    document.getElementById('ncer').value="";
    document.getElementById('nf').value="";
    document.getElementById('ncons').value="";

    document.getElementById('escu').innerHTML=" <br><center>                                <table border='0' cellspacing='4' cellpadding='2' >     <tr><td colspan='2'><br><br><br></td></tr>                           <tr>                                    <th>                                       &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; Escudo                                    </th>                                    <td>                                  <input type='file' id='imagen' name='imagen' />                                      </td>                                </tr>                               <tr>                                    <td align='center' colspan='2'>                                       &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;  <output id='list'></output>                                    </td>                                </tr>                                </table>";
}





function cancelImg()
{
    document.getElementById("botones").innerHTML='<input type="button" value="Cambiar Imagen" style="margin: 0px 5px 0px 5px" onclick="btncambiarImg()">';
    document.getElementById("file").innerHTML="";


    document.getElementById("imgSalida").src=rtAtiImg;

}

function btncambiarImg()
{

    rtAtiImg=document.getElementById("imgSalida").src;

    document.getElementById("botones").innerHTML='<input type="button" value="Cancelar" style="margin: 0px 5px 0px 5px" onclick="cancelImg()">';

    document.getElementById("file").innerHTML=' <center><table><tr><td> <input name="imagen" id="imagen" type="file" /></td></tr></table></center>';

    cambio();
}





function cambio(){

function archivo(evt) {
      var imagen = evt.target.files; // FileList object

      // Obtenemos la imagen del campo "file".
      for (var i = 0, f; f = imagen[i]; i++) {
        //Solo admitimos imágenes.
        if (!f.type.match('image.*')) {
            continue;
        }

        var reader = new FileReader();

        reader.onload = (function(theFile) {
            return function(e) {
              // Insertamos la imagen
             document.getElementById("list").innerHTML = ['<img class="thumb" src="', e.target.result,'" title="', escape(theFile.name), '" name="imgSalida" id="imgSalida" height="100" width="400">'].join('');

            };
        })(f);

        reader.readAsDataURL(f);
      }
  }

  document.getElementById('imagen').addEventListener('change', archivo, false);


}

function menueditar(){

    window.location="../menu.php";
}