<?php 
include 'ini.php';
include 'funciones.php';
session_start();
session_validation();
?>
<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title><?php echo $sAppName;?> <?php echo $BRANCHNAME;?></title>
  
<!-- EXTJS -->
    <link rel="stylesheet" type="text/css" href="extjs/resources/css/ext-all.css" />
    <link rel="stylesheet" type="text/css" href="extjs/resources/css/xtheme-gray.css" />
	<link rel="stylesheet" type="text/css" href="extjs/gridsummary.css"/>
    <link rel="stylesheet" type="text/css" href="layout-browser.css">
    
    <script type="text/javascript" src="js/init.js"></script>
	
    <script type="text/javascript" src="extjs/adapter/ext/ext-base.js"></script>
    <script type="text/javascript" src="extjs/ext-all.js"></script>
    <script type="text/javascript" src="js/gridsummary.js"></script>
	<script type="text/javascript" src="js/checkcolumn.js"></script>
	
	<script type="text/javascript" src="extjs/examples/ux/RowExpander.js"></script>
	<script type="text/javascript" src="extjs/Ext.ux.GridPrinter.js"></script>
    
<!-- JQuery -->
    <script type="text/javascript" src="js/jquery.min.js"></script>
    <script type="text/javascript" src="js/jquery-ui.min.js"></script>

    <link rel="stylesheet" href="//code.jquery.com/ui/1.10.4/themes/smoothness/jquery-ui.css">
    <script src="//code.jquery.com/ui/1.10.4/jquery-ui.js"></script>

    <link rel="stylesheet" href="css/jquery.mobile-1.4.5.css">
    <script src="//code.jquery.com/jquery-1.10.2.min.js"></script>
    <script src="//code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.js"></script>
  
  	<script type="text/javascript">
		var gbIntIdUsuario = <?php echo $_SESSION['user_id'];?>;
		if(gbIntIdUsuario=='' || gbIntIdUsuario==null){ document.location.href="index.php"; }
		
		var objUsuario = new Persona(<?php echo $_SESSION['user_id'];?>, '<?php echo $_SESSION['user_name'];?>', '', <?php echo $_SESSION['user_type'];?>, 0, <?php echo $_SESSION['intEmpresa'];?>);
		
		var intPagina = 0;
		
		function cargarPagina(intCase){
			$("#divDatos").html('<img src="images/cargando2.gif"/>');
			
			if(intCase!=null){
				var arrAlfabeto = ["A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"];
				var strTerm = arrAlfabeto[intPagina];
				
				var strUrl1 = "http://root.menu-digital.com.mx/expediente-clinico2/code/file_get_contents.php?strTerm=" + strTerm;
			}else{
				var strUrl1 = "http://root.menu-digital.com.mx/expediente-clinico2/code/file_get_contents.php?intPagina=" + intPagina;
			}
			
			console.log("strUrl1 = " + strUrl1);
			
			$.post(strUrl1, function(dataNew){
									 
				$("#divDatos").html(dataNew);
				
				if(dataNew!=""){
					extraerDivs(2);
				}else{
					$("#divDatos").html("Termino ");	
				}
				
			});		
		}
		
		function extraerDivs(intTipo){

			if(intTipo==1){
				
				var sHtml = "<table>";
				$(".Row").each(function(i,e){ 
					sHtml += "<tr>";
					$(e).children('div').each(function () {
						sHtml += "<td>"+ $(this).html() + "<td>";
					});
					sHtml += "</tr>";
				});
				sHtml += "</table>";
				
				$("#divDatos").html(sHtml);
				
			}else if(intTipo==2){ //Extraer CIEO10
			
				var j = 0;
				
				$(".Row").each(function(i,e){
										
					if(j>0){
						var strUrl = "http://root.menu-digital.com.mx/expediente-clinico2/code/data/catCie10.php?method=modificar&intMode=1";
						
						var n = 0;
						$(e).children('div').each(function () {
							if(n==0){
								strUrl += "&txtClave=" + encodeURIComponent($.trim( $(this).html() ));
							}else if(n==1){
								strUrl += "&txtEnfermedad=" + encodeURIComponent($.trim( $(this).html() ));
							}
													
							n++;
						});
		
						strUrl += "&rnd=" + Math.random();
					
						console.log(strUrl);
						
						$.post(strUrl, function(dataNew){ });
					}
					
					j++;
				});
				
				intPagina++;
				cargarPagina(2);
				

			}else{  //Extraer MEDICAMENTOS
				var j = 0;
				
				$(".Row").each(function(i,e){
										
					if(j>0){
						var strUrl = "http://root.menu-digital.com.mx/expediente-clinico2/code/data/catMedicamentos.php?method=modificar&intMode=1";
						
						var n = 0;
						$(e).children('div').each(function () {
							if(n==0){
								strUrl += "&txtMedicamento=" + encodeURIComponent($.trim( $(this).html() ));
							}else if(n==1){
								strUrl += "&txtSustancia=" + encodeURIComponent($.trim( $(this).html() ));
							}else if(n==2){
								strUrl += "&txtForma=" + encodeURIComponent($.trim( $(this).html() ));
							}else if(n==3){
								strUrl += "&txtPresentacion=" + encodeURIComponent($.trim( $(this).html() ));
							}else if(n==4){
								strUrl += "&txtLaboratorio=" + encodeURIComponent($.trim( $(this).html() ));
							}
													
							n++;
						});
		
						strUrl += "&rnd=" + Math.random();
					
						console.log(strUrl);
						
						$.post(strUrl, function(dataNew){ });
					}
					
					j++;
				});
				
				intPagina++;
				cargarPagina();
				
			}
		}

		$(document).ready(function(){
			
			cargarPagina(2);
		
		});
		
    </script>

<!-- GENERAL -->
    <link rel="stylesheet" type="text/css" href="styles.css">

  <style>
  .panel-content {
    padding: 0px;
    margin: 0px;
  }
  </style>
</head>
<body>
 

  	<div id="divDatos"><img src="images/cargando2.gif"/></div>
 
</body>
</html>