var tick;

function stop() {
 clearTimeout(tick);
 }

function usnotime() {

	var ut=new Date();
	var h,m,s;
	var time="      ";
	h=ut.getHours();
	m=ut.getMinutes();
	s=ut.getSeconds();
	if(s<=9) s="0"+s;
	if(m<=9) m="0"+m;
	if(h<=9) h="0"+h;
//	time+=h+":"+m+":"+s + " UTC";
	time+=h+":"+m+":"+s;
	document.datos.rtime.value=time;
	tick=setTimeout("usnotime()",1000);    
}


// tomado de arch conf php (debe ser equivalente)
var estatus = new Array();
estatus[0] = "Pendiente AutorizaciÃ³n";
estatus[1] = "Autorizado";
estatus[2] = "Rechazado";
//estatus[3] = "Cancelada";

var estatusTorneo = new Array();
estatusTorneo[0] = "Finalizado";
estatusTorneo[1] = "En Progreso";

var estatusEquipo = new Array();
estatusEquipo[0] = "Sin Torneo";
estatusEquipo[1] = "Asignado a Torneo Finalizado";
estatusEquipo[2] = "Asignado a Torneo en Progreso";

var estatusJornada = new Array();
estatusJornada[0] = "Sin registrar";
estatusJornada[1] = "Sin registrar";
estatusJornada[2] = "Registrada";
estatusJornada[3] = "Cerrada";

var estatusQuiniela = new Array();
estatusQuiniela[0] = "Activada";
estatusQuiniela[1] = "Bloqueada";


var nujmax = 100;
var nujmin = 2;

var nuemax = 100;
var nuemin = 10;
// ------------------------------------------------


/* AJAX
--------------------------------------------------------------------------------------
*/

var req=null;
//var console=null;
var READY_STATE_UNINITIALIZED=0;
var READY_STATE_LOADING=1;
var READY_STATE_LOADED=2;
var READY_STATE_INTERACTIVE=3;
var READY_STATE_COMPLETE=4;

function sendRequest(url,params,HttpMethod) {

  if (!HttpMethod) {
    HttpMethod = "GET";
  }
  
  req = initXMLHTTPRequest();
  if (req) {

    req.onreadystatechange=onReadyState;
    req.open(HttpMethod, url, true);
    req.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
    req.send(params);
  }
}

function initXMLHTTPRequest() {

  var xRequest=null;
  if (window.XMLHttpRequest) {
    xRequest = new XMLHttpRequest();
  } else if (window.ActiveXObject) {
    xRequest = new ActiveXObject("Microsoft.XMLHTTP");
  }

  return xRequest;
}

function onReadyState() {

  var ready= req.readyState;
  var data = null;
  var xmlDoc = null;
  var valor = null;
  var fn = null;
  var fnval = null;
  
  if (ready == READY_STATE_COMPLETE) {
 
//    data = req.responseText;
    xmlDoc = req.responseXML;

    fn = xmlDoc.getElementsByTagName('fn').item(0);
    if (xmlDoc.hasChildNodes()) { fnval = fn.firstChild.data; }  




    switch(fnval) {
    case 'ab_postAsesoriaResp':
      ab_postAsesoriaResp(xmlDoc);

    break;
        
    case 'ab_idproResp':
      ab_idproResp(xmlDoc);

    break;
        
    case 'ab_marcodResp':
      ab_marcodResp(xmlDoc);

    break;
        
    case 'hlpdsk_cartasResp':
      hlpdsk_cartasResp(xmlDoc);

    break;
        
    case 'hlpdsk_seleccionarInventarioResp':
      hlpdsk_seleccionarInventarioResp(xmlDoc);

    break;
        
    case 'hlpdsk_sugerirInventarioResp':
      hlpdsk_sugerirInventarioResp(xmlDoc);

    break;
        
    case 'hlpdsk_sugerirNombreEquipoResp':
      hlpdsk_sugerirNombreEquipoResp(xmlDoc);

    break;
        
    case 'hlpdsk_cdpaddResp':
      hlpdsk_cdpaddResp(xmlDoc);

    break;
        
    case 'hlpdsk_cdpverResp':
      hlpdsk_cdpverResp(xmlDoc);

    break;
        
    case 'cnc_conciliarResp':
      cnc_conciliarResp(xmlDoc);

    break;
        
    case 'iss_descargarmovimientosResp':
      iss_descargarmovimientosResp(xmlDoc);

    break;
        
    case 'iss_procesarmovimientosResp':
      iss_procesarmovimientosResp(xmlDoc);

    break;

    case 'hlpdsk_getEquipoResp':
      hlpdsk_getEquipoResp(xmlDoc);

    break;
        
    case 'iss_llenarCliente':
      iss_llenarCliente(xmlDoc);

    break;

    case 'hlpdsk_getUsuarioResp':
      hlpdsk_getUsuarioResp(xmlDoc);

    break;
    
    case 'hlpdsk_getClienteResp':
      hlpdsk_getClienteResp(xmlDoc);

    break;

    case 'hlpdsk_getSedeResp':
      hlpdsk_getSedeResp(xmlDoc);

    break;

    case 'hlpdsk_getSedesResp':
      hlpdsk_getSedesResp(xmlDoc);

    break;    
    
    case 'hlpdsk_asignarResp':
      hlpdsk_asignarResp(xmlDoc);

    break;

    case 'hlpdsk_quitarResp':
      hlpdsk_quitarResp(xmlDoc);

    break;

    case 'hlpdsk_cerrarResp':
      hlpdsk_cerrarResp(xmlDoc);

    break;
        
    case 'hlpdsk_autorizarResp':
      hlpdsk_autorizarResp(xmlDoc);

    break;
    
    case 'hlpdsk_gasaddResp':
      hlpdsk_gasaddResp(xmlDoc);

    break;
        
    case 'hlpdsk_gasverResp':
      hlpdsk_gasverResp(xmlDoc);

    break;    
            
    case 'toConsole':

      registro = xmlDoc.getElementsByTagName('registro').item(0);
      if (registro.hasChildNodes()) { data = registro.firstChild.data; } else { data = ''; }
      

      toConsole(data);
    break;

    default:
      alert('ERROR JS: No existe fn');
    break;
  }


  } else {

//    data = "Cargando...";
    data = "";

  }

//  toConsole(data);

}


function ab_postAsesoria(asenom,niv1,aselab,asetel,asemail,asedes,idpro) {


  if (asenom == '') {
    alert('Favor de especificar [Nombre]');
    document.getElementById('asenom').focus();
    return false;    
  }
  if (niv1 == 0) {
    alert('Favor de especificar [Institución]');
    document.getElementById('niv1').focus();
    return false;    
  }
  if (asedes == '') {
    alert('Favor de especificar [Problema]');
    document.getElementById('asedes').focus();
    return false;    
  }
    
  var params = 'asenom=' + asenom + '&niv1=' + niv1 + '&aselab=' + aselab + '&asetel=' + asetel + '&asemail=' + asemail + '&asedes=' + asedes + '&idpro=' + idpro; 
  var url = 'ajax/postAsesoria.php';
  
  document.getElementById('panelAsesoria').innerHTML = 'Espere...';
  
  sendRequest(url,params,'post');

}

function ab_postAsesoriaResp(xmlDoc){

    //document.getElementById('marcod').innerHTML = xmlDoc.getElementsByTagName('html').item(0).firstChild.data;
   
  var flag = xmlDoc.getElementsByTagName('flag').item(0).firstChild.data;
    
  if (flag == 1) { // proceso exitoso

    document.getElementById('panelAsesoria').innerHTML = xmlDoc.getElementsByTagName('html').item(0).firstChild.data;
    
  }
  else { // proceso fallo
    alert('ERROR: Itentar nuevamente, en caso de persistir el error contactar a soporte.');
    
  } 
  
  //document.getElementById('idpro').disabled = false;  
  
}



function ab_idpro(idpro) {

  var params = 'idpro=' + idpro; 
  var url = 'ajax/idpro.php';
  
  document.getElementById('idpro').disabled = true;
  
  sendRequest(url,params,'post');

}

function ab_idproResp(xmlDoc){

    //document.getElementById('marcod').innerHTML = xmlDoc.getElementsByTagName('html').item(0).firstChild.data;
   
  var flag = xmlDoc.getElementsByTagName('flag').item(0).firstChild.data;
    
  if (flag == 1) { // proceso exitoso

    document.getElementById('productoDetalle').innerHTML = xmlDoc.getElementsByTagName('html').item(0).firstChild.data;
    
  }
  else { // proceso fallo
    alert('ERROR: Itentar nuevamente, en caso de persistir el error contactar a soporte.');
    
  } 
  
  document.getElementById('idpro').disabled = false;  
  
}


function ab_marcod(marcod) {

  var params = 'marcod=' + marcod; 
  var url = 'ajax/marcod.php';
  
  document.getElementById('marcod').disabled = true;
  
  sendRequest(url,params,'post');

}

function ab_marcodResp(xmlDoc){

    //document.getElementById('marcod').innerHTML = xmlDoc.getElementsByTagName('html').item(0).firstChild.data;
   
  var flag = xmlDoc.getElementsByTagName('flag').item(0).firstChild.data;
    
  if (flag == 1) { // proceso exitoso

    document.getElementById('productoLista').innerHTML = xmlDoc.getElementsByTagName('html').item(0).firstChild.data;
    
  }
  else { // proceso fallo
    alert('ERROR: Itentar nuevamente, en caso de persistir el error contactar a soporte.');
    
  } 
  
  document.getElementById('marcod').disabled = false;  
  
}



function hlpdsk_cartas(idemp) {

  var params = 'idemp=' + idemp; 
  var url = 'ajax/cartas.php';
  document.getElementById('btnCartas_' + idemp).value = 'Espere...';
  document.getElementById('btnCartas_' + idemp).disabled = true;
  
  sendRequest(url,params,'post');

}

function hlpdsk_cartasResp(xmlDoc){

  var flag = parseInt(xmlDoc.getElementsByTagName('flag').item(0).firstChild.data);
      var idemp = xmlDoc.getElementsByTagName('idemp').item(0).firstChild.data;
      document.getElementById('btnCartas_' + idemp).value = 'Terminado.';
          
  switch(flag) {
  case -1:
          alert('ERROR: Cliente no tiene sedes.');
  break;
  
    case 1:
    

    break;
    
    case 2:
        alert('ERROR: Cliente no tiene equipos que apliquen para mantenimiento.');
    break;
    
    default:
        alert('ERROR: Itentar nuevamente, en caso de persistir el error contactar a soporte.');
    break;
    
  }
}


function hlpdsk_seleccionarInventario(idinv) {

  var params = "idinv=" + idinv; 
  var url = 'ajax/seleccionarInventario.php';
//  alert(url);
  
  sendRequest(url,params,'post');

}


function hlpdsk_seleccionarInventarioResp(xmlDoc){

    document.getElementById('sugerirInventario').innerHTML = "";
    document.getElementById('eqnom').value = xmlDoc.getElementsByTagName('eqnom').item(0).firstChild.data;
    document.getElementById('idmar').value = xmlDoc.getElementsByTagName('idmar').item(0).firstChild.data;
    document.getElementById('eqmod').value = xmlDoc.getElementsByTagName('eqmod').item(0).firstChild.data;
    document.getElementById('invns').value = xmlDoc.getElementsByTagName('invns').item(0).firstChild.data;
    document.getElementById('invnib').value = xmlDoc.getElementsByTagName('invnib').item(0).firstChild.data;
    document.getElementById('idinv').value = xmlDoc.getElementsByTagName('idinv').item(0).firstChild.data;
  
}



function hlpdsk_sugerirInventario(dato) {

  var params = "dato=" + dato; 
  var url = 'ajax/sugerirInventario.php';
//  alert(url);
  
  sendRequest(url,params,'post');

}

function hlpdsk_sugerirInventarioResp(xmlDoc){

    document.getElementById('sugerirInventario').innerHTML = xmlDoc.getElementsByTagName('html').item(0).firstChild.data;
  
}




function hlpdsk_sugerirNombreEquipo(dato) {

  var params = "dato=" + dato; 
  var url = 'ajax/sugerirNombreEquipo.php';
//  alert(url);
  
  sendRequest(url,params,'post');

}

function hlpdsk_sugerirNombreEquipoResp(xmlDoc){

    document.getElementById('sugerirNombreEquipo').innerHTML = xmlDoc.getElementsByTagName('html').item(0).firstChild.data;
    
  
}


/*
*************************************************************************
*/

function hlpdsk_gasdel(idsol,idgas,gasval,gasref) {

  var params = "idsol=" + idsol + '&idgas=' + idgas + '&gasval=' + gasval + '&gasref=' + gasref; 
  var url = 'ajax/gasdel.php';
//  alert(url);
  
  sendRequest(url,params,'post');

}

function hlpdsk_gasadd(idsol,idgas,gasval,gasref) {

  var params = "idsol=" + idsol + '&idgas=' + idgas + '&gasval=' + gasval + '&gasref=' + gasref; 
  var url = 'ajax/gasadd.php';
  //alert(url);
  
  sendRequest(url,params,'post');

}

function hlpdsk_gasaddResp(xmlDoc){

  var flag = parseInt(xmlDoc.getElementsByTagName('flag').item(0).firstChild.data);
  
    
  switch(flag){
  case 1:
    document.getElementById('divsolgas').innerHTML = xmlDoc.getElementsByTagName('html').item(0).firstChild.data;
  break;
  
  case 2:
    alert('AVISO: Gasto ya ingresado.');
  break;
  
  default:
    alert('ERROR: Itentar nuevamente, en caso de persistir el error contactar a soporte.');
  break;
  }
  
  if (flag == 1) { // proceso exitoso

    
    
  }
  else { // proceso fallo
    
    
  }
  
}



function hlpdsk_gasver(idsol,idgas) {

  //var params = "idsol=" + idsol + '&user=' + user; 
  var url = 'ajax/gasver.php?idsol=' + idsol + '&idgas=' + idgas;
//  alert(url);
  
  sendRequest(url);

}

function hlpdsk_gasverResp(xmlDoc){

  var flag = xmlDoc.getElementsByTagName('flag').item(0).firstChild.data;
    
  if (flag == 1) { // proceso exitoso

    document.getElementById('divgasver').innerHTML = xmlDoc.getElementsByTagName('html').item(0).firstChild.data;
    
  }
  else { // proceso fallo
    alert('ERROR: Itentar nuevamente, en caso de persistir el error contactar a soporte.');
    
  }
  
}

/*
************************************************************************
*/

function hlpdsk_cdpdel(idsol,idcdp) {

  var params = "idsol=" + idsol + '&idcdp=' + idcdp; 
  var url = 'ajax/cdpdel.php';
//  alert(url);
  
  sendRequest(url,params,'post');

}

function hlpdsk_cdpadd(idsol,idcdp) {

  var params = "idsol=" + idsol + '&idcdp=' + idcdp; 
  var url = 'ajax/cdpadd.php';
//  alert(url);
  
  sendRequest(url,params,'post');

}

function hlpdsk_cdpaddResp(xmlDoc){

  var flag = parseInt(xmlDoc.getElementsByTagName('flag').item(0).firstChild.data);
  
    
  switch(flag){
  case 1:
    document.getElementById('divsolcdp').innerHTML = xmlDoc.getElementsByTagName('html').item(0).firstChild.data;
  break;
  
  case 2:
    alert('AVISO: Código ya ingresado.');
  break;
  
  default:
    alert('ERROR: Itentar nuevamente, en caso de persistir el error contactar a soporte.');
  break;
  }
  
  if (flag == 1) { // proceso exitoso

    
    
  }
  else { // proceso fallo
    
    
  }
  
}



function hlpdsk_cdpver(idsol,idcdp) {

  //var params = "idsol=" + idsol + '&user=' + user; 
  var url = 'ajax/cdpver.php?idsol=' + idsol + '&idcdp=' + idcdp;
//  alert(url);
  
  sendRequest(url);

}

function hlpdsk_cdpverResp(xmlDoc){

  var flag = xmlDoc.getElementsByTagName('flag').item(0).firstChild.data;
    
  if (flag == 1) { // proceso exitoso

    document.getElementById('divcdpver').innerHTML = xmlDoc.getElementsByTagName('html').item(0).firstChild.data;
    
  }
  else { // proceso fallo
    alert('ERROR: Itentar nuevamente, en caso de persistir el error contactar a soporte.');
    
  }
  
}


function hlpdsk_idtec(id) {

//alert(id);



  document.getElementById("divotro").style.visibility="hidden";
  document.getElementById("divcdp").style.visibility="hidden";
//  document.getElementById("divsolcdp").style.visibility="hidden";
  document.getElementById("divcdpver").style.visibility="hidden";
  
  document.getElementById("divgas").style.visibility="hidden";
  document.getElementById("divgasver").style.visibility="hidden";  
  
  switch(id) {
  
    
    case '-1':
      document.getElementById("divotro").style.visibility="visible";
    break;
    case '1':
      document.getElementById("divcdp").style.visibility="visible";
//      document.getElementById("divsolcdp").style.visibility="visible";
      document.getElementById("divcdpver").style.visibility="visible";
      
      document.getElementById("divgas").style.visibility="visible";
      document.getElementById("divgasver").style.visibility="visible";      
    break;
  }
}

function hlpdsk_excel(op) {

  var sql = document.datos.sql.value;
  var idloc = document.datos.idloc.value;
  document.location.href = 'php_excel.php?sql=' + sql + '&idloc=' + idloc;
/*  document.datos.action = 'php_excel.php';
  document.datos.target = '_blank';
  document.datos.submit();
  document.datos.location = '_self';
  document.datos.action = 'admin.php';*/
  
  
  
}


function hlpdsk_PDF(id,pdf) {

  
  archivo = pdf + '?idsol=' + id; 
  
  window.open(archivo,'pdfwin','width=500,height=400,toolbar=yes,menubar=no,status=no,resizable=yes,scrollbars=yes,screenX=0,screenY=0,top=0,left=0')
}


function hlpdsk_imprimirPDF(op,id) {

  
  if (op == "callcenter") { archivo = 'imprimirPDF.php?idsol=' + id; }
  
  window.open(archivo,'imprimirPDF','width=500,height=400,toolbar=yes,menubar=no,status=no,resizable=yes,scrollbars=yes,screenX=0,screenY=0,top=0,left=0')
}

function hlpdsk_reportePDF(op,id) {

  
  if (op == "callcenter") { archivo = 'reportePDF.php?idsol=' + id; }
  
  window.open(archivo,'reportePDF','width=500,height=400,toolbar=yes,menubar=no,status=no,resizable=yes,scrollbars=yes,screenX=0,screenY=0,top=0,left=0')
}

function hlpdsk_quitar(idsol,user) {

  var params = "idsol=" + idsol + '&user=' + user; 
  var url = 'ajax/quitar.php';
  
  sendRequest(url,params,'post');

}



function hlpdsk_asignar(idsol,user) {

  var params = "idsol=" + idsol + '&user=' + user; 
  var url = 'ajax/asignar.php';
  
  sendRequest(url,params,'post');

}

function hlpdsk_asignarResp(xmlDoc){

  var flag = xmlDoc.getElementsByTagName('flag').item(0).firstChild.data;
    
  if (flag == 1) { // proceso exitoso
    var idsol = xmlDoc.getElementsByTagName('idsol').item(0).firstChild.data;
    
    document.getElementById('divasignados_' + idsol).innerHTML = xmlDoc.getElementsByTagName('html').item(0).firstChild.data;
    document.getElementById('st_' + idsol).src = 'img/amarillo.png';
    document.getElementById('st_' + idsol).title = 'ASIGNADO';
    
  }
  else { // proceso fallo
    alert('ERROR: Itentar nuevamente, en caso de persistir el error contactar a soporte.');
    
  }
  
}




function hlpdsk_autorizar(idsol,idsta) {

  var params = "idsol=" + idsol + "&idsta=" + idsta; 
  var url = 'ajax/autorizar.php';
  
  sendRequest(url,params,'post');

}

function hlpdsk_autorizarResp(xmlDoc){

  var flag = xmlDoc.getElementsByTagName('flag').item(0).firstChild.data;
    
  if (flag > 0) { // proceso exitoso
    var idsol = xmlDoc.getElementsByTagName('idsol').item(0).firstChild.data;
    
    //document.getElementById('divasignados_' + idsol).innerHTML = xmlDoc.getElementsByTagName('html').item(0).firstChild.data;
    document.getElementById('st_' + idsol).src = 'img/azul.png';
    document.getElementById('st_' + idsol).title = 'CERRADO';
    document.getElementById('divAutorizar_' + idsol).innerHTML = xmlDoc.getElementsByTagName('stanom').item(0).firstChild.data;;
    
  }
  else { // proceso fallo
    alert('ERROR: Itentar nuevamente, en caso de persistir el error contactar a soporte.');
    
  }
  
}



function hlpdsk_cerrar(idsol) {

  var params = "idsol=" + idsol; 
  var url = 'ajax/cerrar.php';
  
  sendRequest(url,params,'post');

}

function hlpdsk_cerrarResp(xmlDoc){

  var flag = xmlDoc.getElementsByTagName('flag').item(0).firstChild.data;
    
  if (flag == 1) { // proceso exitoso
    var idsol = xmlDoc.getElementsByTagName('idsol').item(0).firstChild.data;
    
    //document.getElementById('divasignados_' + idsol).innerHTML = xmlDoc.getElementsByTagName('html').item(0).firstChild.data;
    document.getElementById('st_' + idsol).src = 'img/azul.png';
    document.getElementById('st_' + idsol).title = 'CERRADO';
    document.getElementById('divCerrar_' + idsol).innerHTML = '';
    
  }
  else { // proceso fallo
    alert('ERROR: Itentar nuevamente, en caso de persistir el error contactar a soporte.');
    
  }
  
}


function hlpdsk_getUsuario(user) {

  var params = "user=" + user; 
  var url = 'ajax/getUsuario.php';
  
  sendRequest(url,params,'post');

}

function hlpdsk_getUsuarioResp(xmlDoc){

  var flag = xmlDoc.getElementsByTagName('flag').item(0).firstChild.data;
    
  if (flag == 1) { // proceso exitoso
    
    if (xmlDoc.getElementsByTagName('nombre').item(0).firstChild) { document.getElementById('nombre').innerHTML = xmlDoc.getElementsByTagName('nombre').item(0).firstChild.data; }
    if (xmlDoc.getElementsByTagName('empresa').item(0).firstChild) { document.getElementById('empresa').innerHTML = xmlDoc.getElementsByTagName('empresa').item(0).firstChild.data; }
    if (xmlDoc.getElementsByTagName('telefono').item(0).firstChild) { document.getElementById('telefono').innerHTML = xmlDoc.getElementsByTagName('telefono').item(0).firstChild.data; }
    if (xmlDoc.getElementsByTagName('email').item(0).firstChild) { document.getElementById('email').innerHTML = xmlDoc.getElementsByTagName('email').item(0).firstChild.data; }
    
  }
  else { // proceso fallo
    alert('ERROR: Itentar nuevamente, en caso de persistir el error contactar a soporte.');
    
  }
  
}


function hlpdsk_getEquipo(tipo,serial) {

  var params = "tipo=" + tipo + "&serial=" + serial; 
  var url = 'ajax/getEquipo.php';
  
  sendRequest(url,params,'post');

}

function hlpdsk_getEquipoResp(xmlDoc){

  var flag = xmlDoc.getElementsByTagName('flag').item(0).firstChild.data;
    
  if (flag == 1) { // proceso exitoso
    document.getElementById('eqnom').value = xmlDoc.getElementsByTagName('eqnom').item(0).firstChild.data;
    document.getElementById('idmar').value = xmlDoc.getElementsByTagName('idmar').item(0).firstChild.data;
    document.getElementById('eqmod').value = xmlDoc.getElementsByTagName('eqmod').item(0).firstChild.data;
    document.getElementById('invnib').value = xmlDoc.getElementsByTagName('invnib').item(0).firstChild.data;
    document.getElementById('invns').value = xmlDoc.getElementsByTagName('invns').item(0).firstChild.data;
    
  }
  else { // proceso fallo
  
    
    //alert('ERROR: Itentar nuevamente, en caso de persistir el error contactar a soporte.');
    alert('ERROR: Número de serie o número de inventario no existe. Favor de verificar.');
    
  }
  
}


function hlpdsk_getSede(idemp) {

  var params = "idemp=" + idemp; 
  var url = 'ajax/getSede.php';
  
  sendRequest(url,params,'post');

}

function hlpdsk_getSedeResp(xmlDoc){

  var flag = xmlDoc.getElementsByTagName('flag').item(0).firstChild.data;
    
  if (flag == 1) { // proceso exitoso
    document.getElementById('dividloc').innerHTML = xmlDoc.getElementsByTagName('html').item(0).firstChild.data;
    
    
  }
  else { // proceso fallo
    alert('ERROR: Itentar nuevamente, en caso de persistir el error contactar a soporte.');
    
  }
  
}


function hlpdsk_getSedes(idemp) {

  var params = "idemp=" + idemp; 
  var url = 'ajax/getSedes.php';
  
  sendRequest(url,params,'post');

}

function hlpdsk_getSedesResp(xmlDoc){

  var flag = xmlDoc.getElementsByTagName('flag').item(0).firstChild.data;
    
  if (flag == 1) { // proceso exitoso
    document.getElementById('divsedes').innerHTML = xmlDoc.getElementsByTagName('html').item(0).firstChild.data;
    
    
  }
  else { // proceso fallo
    alert('ERROR: Itentar nuevamente, en caso de persistir el error contactar a soporte.');
    
  }
  
}




function hlpdsk_getCliente(idloc,soluser) {

  if (soluser == null) { soluser = 0; }
  
  var params = "idloc=" + idloc + "&soluser=" + soluser; 
  var url = 'ajax/getCliente.php';
  
  sendRequest(url,params,'post');

}

function hlpdsk_getClienteResp(xmlDoc){

  var flag = xmlDoc.getElementsByTagName('flag').item(0).firstChild.data;
  var soluser;
    
  if (flag == 1) { // proceso exitoso
    //var tipo = xmlDoc.getElementsByTagName('tipo').item(0).firstChild.data;
    if (xmlDoc.getElementsByTagName('empnom').item(0).firstChild) { document.getElementById('empnom').innerHTML = xmlDoc.getElementsByTagName('empnom').item(0).firstChild.data; }
    if (xmlDoc.getElementsByTagName('direccion').item(0).firstChild) {  document.getElementById('direccion').innerHTML = xmlDoc.getElementsByTagName('direccion').item(0).firstChild.data; }
    if (xmlDoc.getElementsByTagName('responsable').item(0).firstChild) {  document.getElementById('responsable').innerHTML = xmlDoc.getElementsByTagName('responsable').item(0).firstChild.data; }

    if (xmlDoc.getElementsByTagName('soluser').item(0).firstChild) { 
      soluser = xmlDoc.getElementsByTagName('soluser').item(0).firstChild.data;
    }
    
    if (soluser != 0) {
      hlpdsk_getUsuario(soluser);
      
    }
    
  }
  else { // proceso fallo
    alert('ERROR: Itentar nuevamente, en caso de persistir el error contactar a soporte.');
    
  }
  
}



function toConsole(data){
  if (console!=null){

//  console.innerHTML = data;

    console.value = data;

  }
}




function iss_campo(tabla,llave,llave_valor,campo) {

  var url = 'ajax/campo.php?tabla=' + tabla + '&llave=' + llave + '&llave_valor=' + llave_valor + '&campo=' + campo;
  console = document.getElementById(campo);

  sendRequest(url);

}








function iss_mesnom(mes) {
var mesnom;

    switch (mes) {
    case '01':
      mesnom = 'Ene';
    break;
    case '02':
      mesnom = 'Feb';
    break;
    case '03':
      mesnom = 'Mar';
    break;
    case '04':
      mesnom = 'Abr';
    break;
    case '05':
      mesnom = 'May';
    break;
    case '06':
      mesnom = 'Jun';
    break;
    case '07':
      mesnom = 'Jul';
    break;
    case '08':
      mesnom = 'Ago';
    break;
    case '09':
      mesnom = 'Sep';
    break;
    case '10':
      mesnom = 'Oct';
    break;
    case '11':
      mesnom = 'Nov';
    break;
    case '12':
      mesnom = 'Dic';
    break;
    }

return mesnom;

}














function iss_validarText(campo) {

re = new RegExp("^ *\n*$");
rews = new RegExp(' ','g');
rewlf = new RegExp('\n','g');
rewcr = new RegExp('\r','g');

campows = campo.replace(rews,'');
campows = campows.replace(rewlf,'');
campows = campows.replace(rewcr,'');
campolen = campows.length;

if ((campo.search(re) != -1) || (campolen < 1)) { return false; }
return true;

}


/*
function iss_opcion(op) {

  document.datos.op.value = op
  document.datos.submit();
}
*/
function iss_opcion(op,accion) {

  document.datos.op.value = op
  document.datos.accion.value = accion
  document.datos.submit();
}

function iss_consulta(op) {

  document.datos.op.value = op
  document.datos.accion.value = 'CONSULTA';
  document.datos.submit();
}


function iss_alta(op) {

  var archivo;
  var scrollbars = 'yes';
  var resizable = 'no';
  var winwd = 500;
  var winhg = 400;

  switch(op) {
    case 'calendario': archivo = 'torneo.php?qrytipo=INSERT'; break;
    case 'equipo': archivo = 'equipo.php?qrytipo=INSERT'; winhg=150; break;
    case 'callcenter': archivo = 'solicitud.php?qrytipo=INSERT'; winhg=600; winwd=600; break;
    case 'clientes': archivo = 'cliente.php?qrytipo=INSERT'; winhg=150; winwd=750; break;
    case 'sedes': archivo = 'sede.php?qrytipo=INSERT'; winhg=500; winwd=750; break;
    case 'usuarios': archivo = 'usuario.php?qrytipo=INSERT'; winhg=400; winwd=420; break;
    case 'inventario': archivo = 'inventario.php?qrytipo=INSERT'; winhg=400; winwd=420; break;
    case 'marcas': archivo = 'marca.php?qrytipo=INSERT'; winhg=150; winwd=750; break;

  }

  var parms = 'width=' + winwd + ',height=' + winhg + ',location=no,toolbar=no,menubar=yes,status=yes,resizable=' + resizable + ',scrollbars=' + scrollbars + ',screenX=0,screenY=0,top=0,left=0';

  window.open(archivo,'hlpdsk_ticket',parms)

}

function iss_editar(op,id) {

  var archivo;
  var scrollbars = 'yes';
  var resizable = 'no';
  var winwd = 500;
  var winhg = 400;


  switch(op) {
    case 'pass': archivo = 'pass.php?qrytipo=UPDATE&usucla=' + id; winhg=200; winwd=420; break;
    case 'inventario': archivo = 'inventario.php?qrytipo=UPDATE&idinv=' + id; winhg=400; winwd=420; break;
    case 'usuarios': archivo = 'usuario.php?qrytipo=UPDATE&usucla=' + id; winhg=400; winwd=420; break;
    case 'clientes': archivo = 'cliente.php?qrytipo=UPDATE&idemp=' + id; winhg=150; winwd=750; break;
    case 'callcenter': archivo = 'solicitud.php?qrytipo=UPDATE&idsol=' + id; winhg=600; winwd=600; break;
    case 'callcentertecnico': archivo = 'solicitudtecnico.php?qrytipo=UPDATE&idsol=' + id; winhg=600; winwd=600; break;
    case 'callcentercliente': archivo = 'solicitudcliente.php?qrytipo=UPDATE&idsol=' + id; winhg=600; winwd=600; break;
    case 'sedes': archivo = 'sede.php?qrytipo=UPDATE&idloc=' + id; winhg=500; winwd=750; break;
    case 'marcas': archivo = 'marca.php?qrytipo=UPDATE&idmar=' + id; winhg=150; winwd=750; break;

  }


  var parms = 'width=' + winwd + ',height=' + winhg + ',toolbar=no,menubar=no,status=no,resizable=' + resizable + ',scrollbars=' + scrollbars + ',screenX=0,screenY=0,top=0,left=0';

  window.open(archivo,'crmalta',parms)

}

function iss_ver(op,id) {

  var archivo;
  var scrollbars = 'yes';
  var resizable = 'no';
  var winwd = 500;
  var winhg = 400;

  switch(op) {
    case 'clientes': archivo = 'vercliente.php?idcli=' + id; break;
    case 'analistas': archivo = 'veranalista.php?idana=' + id; break;
    case 'asociados': archivo = 'verempresa.php?idemp=' + id; break;
    case 'transacciones': archivo = 'vertransaccion.php?idtra=' + id; break;
  }

  var parms = 'width=' + winwd + ',height=' + winhg + ',toolbar=no,menubar=no,status=no,resizable=' + resizable + ',scrollbars=' + scrollbars + ',screenX=0,screenY=0,top=0,left=0';

  window.open(archivo,'crmver',parms)

}


function iss_borrar(op) {

// Â·Los registros seleccionados se perderan y no podrÃ· recuperarlos! Â¿Esta seguro de continuar?

  if (confirm('·Los registros seleccionados se perderan y no podrá recuperarlos! ¿Esta seguro de continuar?')) {

    document.datos.accion.value = 'BORRAR';
    document.datos.op.value = op;
    document.datos.submit();
  }

  return false;

}

function iss_disabled(campo) {

  var str = 'document.datos.' + campo + '.disabled = true';
  eval(str);
}















function consulta(op) {

  document.location.href = '$PHP_SELF?op=' + op;
}



function muestra_url(url) {
  // url = 'muestra_url.php?url=' + url
  window.open(url,'muestra_url','width=800,height=500,toolbar=no,menubar=no,status=yes,resizable=yes,scrollbars=yes,screenX=0,screenY=0,top=0,left=0')
}



function alta(op) {

  var archivo;
  var scrollbars = 'no';
  var resizable = 'no';
  var winwd = 500;
  var winhg = 350;

  if (op == 12) { archivo = 'callcenter.php?qrytipo=INSERT'; winhg = 500; scrollbars = 'yes'; winwd = 750; }
  if (op == 3) { archivo = 'usuarios.php?qrytipo=INSERT'; }
  if (op == 4) { archivo = 'anuncios.php?qrytipo=INSERT'; }

  if (op == 2) { archivo = 'oferta.php?qrytipo=INSERT'; winhg=400; }

  var parms = 'width=' + winwd + ',height=' + winhg + ',toolbar=no,menubar=no,status=no,resizable=' + resizable + ',scrollbars=' + scrollbars + ',screenX=0,screenY=0,top=0,left=0';

  window.open(archivo,'registro',parms)
}


function editar(op,id) {

  scrollbars = 'no';
  resizable = 'no';
  winwd = 500;
  winhg = 400;


  if (op == 12) { archivo = 'noticias.php?qrytipo=UPDATE&idnot=' + id; winhg = 500; scrollbars = 'yes'; winwd = 750; }
  if (op == 3) { archivo = 'usuarios.php?qrytipo=UPDATE&usucta=' + id;  }
  if (op == 4) { archivo = 'anuncios.php?qrytipo=UPDATE&upid=' + id;  }


  if (op == 11) { archivo = 'pubmedios.php?qrytipo=UPDATE&idpub=' + id; }
  if (op == 10) { archivo = 'tipocom.php?qrytipo=UPDATE&idtipo=' + id; }
  if (op == 9) { archivo = 'marcas.php?qrytipo=UPDATE&idmarca=' + id; }
  if (op == 8) { archivo = 'tipotarifas.php?qrytipo=UPDATE&idtipo=' + id; }
  if (op == 2) { archivo = 'oferta.php?qrytipo=UPDATE&ofeid=' + id; }


  window.open(archivo,'proselcom','width=' + winwd + ',height=' + winhg + ',toolbar=yes,menubar=no,status=no,resizable=' + resizable + ',scrollbars=' + scrollbars + ',screenX=0,screenY=0,top=0,left=0')
}



function enviar(op) {

  document.datos.accion.value = 'ENVIAR';

  if (op == 1) { document.datos.accion.value = 'BOLETIN'; }

  document.datos.submit();
}

function ordenar(qry,op,paso,tipoNota) {

tipo = document.datos.tipo.options[document.datos.tipo.selectedIndex].value;
buscar = document.datos.buscar.value;

  if (paso == 0)
  {
    ptpag = 1;
  }
  else
  {
    if (paso == -2)
    {
      paso = 0;
    }

    ptpag = document.datos.ptpag.value;
    ptpag = Number(ptpag);
  }

  ptpag = ptpag + paso;


  if (tipoNota != 1) {
    document.location.href = '$PHP_SELF?op=' + op + '&criteriaord=' + qry + '&ptpag=' + ptpag + '&buscar=' + buscar + '&tipo=' + tipo + '&tipoNota=' + tipoNota;

  }
  else {

    document.datos.op.value = op;
    document.datos.criteriaord.value = qry;
    document.datos.ptpag.value = ptpag;

    document.datos.submit();

  }



}

/*
++++++++++++++++++++++++++++
*/
function iss_procesarmovimientos(idcar,promocod,carst) {
  // alert("idcar:" + idcar +",promocod:" + promocod + ",carst:" + carst);
	var msg;
	
	if (carst == 0) {
		
		msg = "¿Esta seguro de continuar?";
	}
	else {
		msg = "Recargar de archivo.\n\n¿Esta seguro de continuar?";
	}
	if (confirm(msg)) {	

		var flgproc = parseInt(document.getElementById('flgproc').value);
  
		if (flgproc == 0) {
			document.getElementById('btnProcesar_' + idcar).value = 'Procesando...';
			document.getElementById('btnProcesar_' + idcar).disabled = true;
			document.getElementById('flgproc').value = 1;
			var url = 'ajax/procesar.php?idcar=' + idcar + '&promocod=' + promocod;

			sendRequest(url);
		}
		else {

			alert('ERROR: Existe una carga en proceso. Favor de esperar a que finalize.');  
		}
	}

}

function iss_procesarmovimientosResp(xmlDoc){

  var flag = xmlDoc.getElementsByTagName('flag').item(0).firstChild.data;
  //var flagval = flag.firstChild.data;
  var idcar = xmlDoc.getElementsByTagName('idcar').item(0).firstChild.data;
  
  if (flag == 1) { // proceso exitoso
  
    var ct = xmlDoc.getElementsByTagName('ct').item(0).firstChild.data;
    alert('AVISO: El proceso de carga termino con éxito.\nSe cargaron ' + ct + ' registros.');
    
    document.getElementById('imgProcesar_' + idcar).src = 'img/verde.gif'
    document.getElementById('btnHTML_' + idcar).innerHTML = "<input class='forma' type='button' name='btnProcesar_" + idcar + "' id='btnProcesar_" + idcar + "' onclick='iss_descargarmovimientos(" + idcar + ",\"" + xmlDoc.getElementsByTagName('promocod').item(0).firstChild.data + "\",1)' value='Descargar'>";    
    
    
  }
  else { // proceso fallo
    alert('ERROR: Fallo en el proceso de carga.\nFavor de verificar archivo e intentar nuevamente.');
    
  }
                  
//  var btnhtml = "<input class='forma' type='button' name='btnProcesar_" + idcar + "' id='btnProcesar_" + idcar + "' onclick='iss_descargarmovimientos(" + idcar + ",\"" + xmlDoc.getElementsByTagName('promocod').item(0).firstChild.data + "\",1)' value='Descargar'>";
  //alert(btnhtml);  
  //document.getElementById('btnProcesar_' + idcar).disabled = false;
  //document.getElementById('btnProcesar_' + idcar).value = 'Descargar';

  document.getElementById('flgproc').value = 0;
  
}


function iss_descargarmovimientos(idcar,promocod,carst) {

  //alert("idcar:" + idcar +",promocod:" + promocod + ",carst:" + carst);
	var msg;
	
	if (carst == 0) {
		
		msg = "¿Esta seguro de continuar?";
	}
	else {
		msg = "IMPORTANTE. Al descargar archivo se borraran los movimientos cargados previamente, así como las conciliaciones registradas!!!\n\n¿Esta seguro de continuar?";
	}
	if (confirm(msg)) {	

		var flgproc = parseInt(document.getElementById('flgproc').value);
  
		if (flgproc == 0) {
			document.getElementById('btnProcesar_' + idcar).value = 'Procesando...';
			document.getElementById('btnProcesar_' + idcar).disabled = true;
			document.getElementById('flgproc').value = 1;
			var url = 'ajax/descargar.php?idcar=' + idcar + '&promocod=' + promocod;

			sendRequest(url);
		}
		else {

			alert('ERROR: Existe una carga en proceso. Favor de esperar a que finalize.');  
		}
	}

}

function iss_descargarmovimientosResp(xmlDoc){

  var flag = xmlDoc.getElementsByTagName('flag').item(0).firstChild.data;
  //var flagval = flag.firstChild.data;
  var idcar = xmlDoc.getElementsByTagName('idcar').item(0).firstChild.data;
  
  if (flag == 1) { // proceso exitoso
  
    var ct = xmlDoc.getElementsByTagName('ct').item(0).firstChild.data;
    alert('AVISO: El proceso de descarga termino con éxito.\nSe quitaron ' + ct + ' registros.');
    
    document.getElementById('imgProcesar_' + idcar).src = 'img/rojo.gif';
    document.getElementById('btnHTML_' + idcar).innerHTML = "<input class='forma' type='button' name='btnProcesar_" + idcar + "' id='btnProcesar_" + idcar + "' onclick='iss_procesarmovimientos(" + idcar + ",\"" + xmlDoc.getElementsByTagName('promocod').item(0).firstChild.data + "\",2)' value='Cargar'>";
    
     /*  no aplica idcarant
    var idcarant = parseInt(xmlDoc.getElementsByTagName('idcarant').item(0).firstChild.data);
    if (idcarant > 0) {
      document.getElementById('imgProcesar_' + idcarant).src = 'img/rojo.gif'
    }  */
    
  }
  else { // proceso fallo
    alert('ERROR: Fallo en el proceso de carga.\nFavor de verificar archivo e intentar nuevamente.');
    
  }
                  
  //document.getElementById('btnProcesar_' + idcar).disabled = false;
  //document.getElementById('btnProcesar_' + idcar).value = 'Cargar';
  
  document.getElementById('flgproc').value = 0;
  
}  

function cnc_conciliar(idcnc) {

  var params = "idcnc=" + idcnc + "&cncemp=" + document.getElementById('cncemp_' + idcnc).value + "&cncof=" + document.getElementById('cncof_' + idcnc).value + "&cncobs=" + document.getElementById('cncobs_' + idcnc).value + "&cncfac=" + document.getElementById('cncfac_' + idcnc).value; 
  var url = 'ajax/conciliar.php';
  
  sendRequest(url,params,'post');

}

function cnc_conciliarResp(xmlDoc){

  var flag = xmlDoc.getElementsByTagName('flag').item(0).firstChild.data;
  var idcnc = xmlDoc.getElementsByTagName('idcnc').item(0).firstChild.data;
  
  if (flag == 1) { // proceso exitoso

  
  
    document.getElementById('divcncst_' + idcnc).innerHTML = "<img border=0 src='img/verde.gif' title='Conciliada'>";
   // alert('si paso');
    document.getElementById('divcncemp_' + idcnc).innerHTML = xmlDoc.getElementsByTagName('cncempnom').item(0).firstChild.data;
    document.getElementById('divcncof_' + idcnc).innerHTML = xmlDoc.getElementsByTagName('cncofnom').item(0).firstChild.data;
    document.getElementById('divcncobs_' + idcnc).innerHTML = xmlDoc.getElementsByTagName('cncobs').item(0).firstChild.data;
    document.getElementById('divcncfac_' + idcnc).innerHTML = xmlDoc.getElementsByTagName('cncfac').item(0).firstChild.data;
    document.getElementById('divcncuser_' + idcnc).innerHTML = xmlDoc.getElementsByTagName('user').item(0).firstChild.data;
    //alert('El movimiento se concilio con éxito');
    
    //document.getElementById('imgProcesar_' + idcar).src = 'img/rojo.gif';
    
    
  }
  else { // proceso fallo
    alert('ERROR: Itentar nuevamente, en caso de persistir el error contactar a soporte.');
    
  }
                  
 
  
}  


