// global variables //
var TIMER = 5;
var SPEED = 10;
var WRAPPER = 'content';
 var submitted = 0;
 var decided;
 var thebrowser = navigator.appName
 var id;
 
function verenviados(h){
    from = document.getElementById('from').value
    subject = document.getElementById('subject').value
	a_buscar = document.getElementById('a_buscar').value
	tipo = document.getElementById('tipo').value
	nacion = document.getElementById('nacion').value
	estado = document.getElementById('estado').value
	ciudad = document.getElementById('ciudad').value
	segmer = document.getElementById('segmer').value
	agencia = document.getElementById('agencia').value
	fileatt = document.getElementById('fileatt').value

    def = false;
    sigue = enviados(from,subject,a_buscar,tipo,nacion,estado,ciudad,segmer,agencia,fileatt,h);
	
	def = sigue;
  decided = true
  return def;
}
function verclienteb(h,li,o){
     if(o == "listado"){
       id = document.getElementById('id').value
	   nombre = document.getElementById('nombre').value
	   correo = document.getElementById('correo').value
       sexo = document.getElementById('M').value
       sexof = document.getElementById('F').value
	   fec_nac = document.getElementById('fec_nac').value
       edad = document.getElementById('edad').value
       nacion = document.getElementById('nacion').value
       estado = document.getElementById('estado').value
	   ciudad = document.getElementById('ciudad').value
	   extras = document.getElementById('extras').value
	   victima = li
       modicliente(1,id,nombre,correo,sexo,sexof,fec_nac,edad,nacion,estado,ciudad,extras,victima,h)
	   
	   decided = true
	   var t = setTimeout("window.location='http://www.sisorbe.com/hotel/php/contenido3.php?oper=MODIFICAR&tabla=clientes&ti=Clientes&abrir=agbd_listados.php'",2500)
	   return false;
	 }
	  
     decided = true
	 return false;
 }
function verhabitacionb(h,li,o){
    if(o == "listado"){
	   sube = false
	   codigo = document.getElementById('codigo').value
	   cat = document.getElementById('cat').value
	   desc = document.getElementById('hab').value
	   numhabs = document.getElementById('num').value
	   rate = document.getElementById('precio').value
       foto = document.getElementById('foto').value
	   victima = li
	   sube = modihabitacion(2,codigo,cat,desc,numhabs,rate,foto,h,victima)
	   decided = true
	   if(sube == true){
	     return sube;
	   }else{ 
	     var t = setTimeout("window.location='http://www.sisorbe.com/hotel/php/contenido3.php?oper=MODIFICAR&tabla=cathabs&ti=Habitaciones&abrir=listado_habs.php'",3500)
		 return false
	   }
	 }
	 
 }
function verhotelb(h,li,o){
    if(o == "listado"){
	  nombre = document.getElementById('nombre').value
	  direccion = document.getElementById('direccion').value
	  correo = document.getElementById('correo').value
      habs = document.getElementById('habs').value
	  tel = document.getElementById('tel').value
	  fax = document.getElementById('fax').value
	  zona = document.getElementById('zona').value
      //tipo = document.getElementById('tipo').value
	  foto = document.getElementById('foto').value
      victima = li
      modihotel(3,nombre,direccion,correo,habs,tel,fax,zona,foto,victima,h)
	   decided = true
	   var t = setTimeout("window.location='http://www.sisorbe.com/hotel/php/contenido3.php?oper=MODIFICAR&tabla=hoteles&ti=Hoteles&abrir=listado_hoteles.php'",2500)
	   return false;
	 }
	 
 }
function verocupacionb(h,li,fec,o){
    if(o == "listado"){
	 cliente = document.getElementById('cliente').value
	 tipo = document.getElementById('tipo').value
	 agencia = document.getElementById('agencia').value
	 segmento = document.getElementById('segmento').value
	 paquete = document.getElementById('paquete').value
	 id1 = document.getElementById('id1').value
	 id2 = document.getElementById('id2').value
     num = document.getElementById('num').value
	 cathab = document.getElementById('cathab').value
     monto = document.getElementById('monto').value
	 nota = document.getElementById('nota').value
	 victima_fecha = fec
     victima = li
     modiocupacion(4,cliente,tipo,agencia,segmento,paquete,id1,id2,num,cathab,monto,nota,h,victima,victima_fecha)
	   decided = true
	   //var t = setTimeout("window.location='http://www.sisorbe.com/hotel/php/listado_ocupacion.php?oper=MODIFICAR&tabla=ocupacion&ti=Movimientos'",2500)
	   return false;
	}
	
 }
function versegmentob(h,li,o){
  if(o == "listado"){
      codigo = document.getElementById('codigo').value
      descripcion = document.getElementById('descripcion').value
      victima = li
      modisegmento(5,codigo,descripcion,victima)
	  decided = true
	   var t = setTimeout("window.location='http://www.sisorbe.com/hotel/php/contenido3.php?oper=MODIFICAR&tabla=segmer&ti=Segmentos de Mercado&abrir=listado_segmento.php'",2500)
	   return false;
  }
	 
}
function verzonab(h,li,o){
   if(o == "listado"){
     cod_zona = document.getElementById('cod_zona').value
	 zona = document.getElementById('zona').value
     victima = li
     modizona(6,cod_zona,zona,victima)
	 decided = true
	   var t = setTimeout("window.location='http://www.sisorbe.com/hotel/php/contenido3.php?oper=MODIFICAR&tabla=zonas&ti=Zonas&abrir=listado_zonas.php'",2500)
	   return false;
   }
	 
}
function veragenciab(h,li,o){
     if(o == "listado"){
       agencia = document.getElementById('agencia').value
	   correo = document.getElementById('correo').value
	   pais = document.getElementById('nacion').value
	   estado = document.getElementById('estado').value
	   ciudad = document.getElementById('ciudad').value
	   contacto = document.getElementById('contacto').value
	   telefono = document.getElementById('telefono').value
	   tipo = document.getElementById('tipo').value
	   comision = document.getElementById('comision').value
	   victima = li
       modiagencia(7,agencia,correo,pais,estado,ciudad,contacto,telefono,tipo,comision,victima)
	   decided = true
	   var t = setTimeout("window.location='http://www.sisorbe.com/hotel/php/contenido3.php?oper=MODIFICAR&tabla=agencias&ti=Agencias de Viaje&abrir=listado_agencias.php'",2500)
	   return false;
	 }
	 
}
function verusuariob(h,li,o){
    if(o == "listado"){
	 usuario = document.getElementById('usuario').value
	 pass = document.getElementById('pass').value
	 tipo = document.getElementById('tipo').value
	 hotell = document.getElementById('codhotel').value
     victima = li
     modiusuario(8,usuario,pass,tipo,hotell,victima)
	 decided = true
	   var t = setTimeout("window.location='http://www.sisorbe.com/hotel/php/contenido3.php?oper=MODIFICAR&tabla=usuarios&ti=Usuarios&abrir=listado_usuario.php'",2500)
	   return false;
	}
	
}
function verpaqueteb(h,li,o){
   if(o == "listado"){
     codigo = document.getElementById('codigo').value
	 paquete = document.getElementById('paquete').value
	 descuento = document.getElementById('descuento').value
     victima = li
     modipaquete(9,codigo,paquete,descuento,victima)
	 decided = true
	   var t = setTimeout("window.location='http://www.sisorbe.com/hotel/php/contenido3.php?oper=MODIFICAR&tabla=paquetes&ti=Paquetes&abrir=listado_paquetes.php'",2500)
	   return false;
   }
	
}
function vertipoclienteb(h,li,o){
   if(o == "listado"){
     codigo = document.getElementById('codigo').value
	 tipo = document.getElementById('tipo').value
	 desc = document.getElementById('desc').value
     victima = li
	 
     moditipocliente(10,codigo,tipo,desc,victima,h)
	 decided = true
	   var t = setTimeout("window.location='http://www.sisorbe.com/hotel/php/contenido3.php?oper=MODIFICAR&tabla=tipocliente&ti=Tipos de Cliente&abrir=listado_tipocliente.php'",2500)
	   return false;
   }

}
function clickcliente(h){
     id = document.getElementById('ver'+h).value
     var t = setTimeout("window.location='http://www.sisorbe.com/hotel/movdia.php?click="+id+"'",1000)
     decided = true
	 return false;
 }
function ver(){
   if(document.getElementById('username').value == ""){
	 showDialog('Error','Digite su usuario para poder accesar al sistema!','error',3)
	 decided = true
	 return false;
   }
   else{
     if(document.getElementById('pass').value == ""){
	   var temp = showDialog('Error','Digite su contraseņa para poder accesar al sistema!','error',3)
	   decided = true
	   return false;
	 }else{
	   //showUser(document.getElementById('username').value,document.getElementById('pass').value);
	 //Todo estaba lleno
     submitted++
	 decided = false
	 return true;
	 }
	 return false;
   }
 }
function checkit()
{
if (submitted == 0)
{
if (decided == true && thebrowser == "Microsoft Internet Explorer")
{
location.href = location.href
}
else
{
history.back()
}

}
}
// calculate the current window width //
function pageWidth() {
  return window.innerWidth != null ? window.innerWidth : document.documentElement && document.documentElement.clientWidth ? document.documentElement.clientWidth : document.body != null ? document.body.clientWidth : null;
}

// calculate the current window height //
function pageHeight() {
  return window.innerHeight != null? window.innerHeight : document.documentElement && document.documentElement.clientHeight ? document.documentElement.clientHeight : document.body != null? document.body.clientHeight : null;
}

// calculate the current window vertical offset //
function topPosition() {
  return typeof window.pageYOffset != 'undefined' ? window.pageYOffset : document.documentElement && document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop ? document.body.scrollTop : 0;
}

// calculate the position starting at the left of the window //
function leftPosition() {
  return typeof window.pageXOffset != 'undefined' ? window.pageXOffset : document.documentElement && document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft ? document.body.scrollLeft : 0;
}

// build/show the dialog box, populate the data and call the fadeDialog function //
function showDialog(title,message,type,autohide) {
  if(!type) {
    type = 'error';
  }
  var dialog;
  var dialogheader;
  var dialogclose;
  var dialogtitle;
  var dialogcontent;
  var dialogmask;
  if(!document.getElementById('dialog')) {
    dialog = document.createElement('div');
    dialog.id = 'dialog';
    dialogheader = document.createElement('div');
    dialogheader.id = 'dialog-header';
    dialogtitle = document.createElement('div');
    dialogtitle.id = 'dialog-title';
    dialogclose = document.createElement('div');
    dialogclose.id = 'dialog-close'
    dialogcontent = document.createElement('div');
    dialogcontent.id = 'dialog-content';
    dialogmask = document.createElement('div');
    dialogmask.id = 'dialog-mask';
    document.body.appendChild(dialogmask);
    document.body.appendChild(dialog);
    dialog.appendChild(dialogheader);
    dialogheader.appendChild(dialogtitle);
    dialogheader.appendChild(dialogclose);
    dialog.appendChild(dialogcontent);
    dialogclose.setAttribute('onclick','hideDialog()');
    dialogclose.onclick = hideDialog;
  } else {
    dialog = document.getElementById('dialog');
    dialogheader = document.getElementById('dialog-header');
    dialogtitle = document.getElementById('dialog-title');
    dialogclose = document.getElementById('dialog-close');
    dialogcontent = document.getElementById('dialog-content');
    dialogmask = document.getElementById('dialog-mask');
    dialogmask.style.visibility = "visible";
    dialog.style.visibility = "visible";
  }
  dialog.style.zIndex = 35;
  dialog.style.opacity = .00;
  dialog.style.filter = 'alpha(opacity=0)';
  dialog.alpha = 0;
  var width = pageWidth();
  var height = pageHeight();
  var left = leftPosition();
  var top = topPosition();
  var dialogwidth = dialog.offsetWidth;
  var dialogheight = dialog.offsetHeight;
  var topposition = top + (height / 3) - (dialogheight / 2);
  var leftposition = left + (width / 2) - (dialogwidth / 2);
  dialog.style.top = topposition + "px";
  dialog.style.left = leftposition + "px";
  dialogheader.className = type + "header";
  dialogtitle.innerHTML = title;
  dialogcontent.className = type;
  dialogcontent.innerHTML = message;
  
  var content = document.getElementById(WRAPPER);
  dialogmask.style.height = content.offsetHeight + 'px';
  dialog.timer = setInterval("fadeDialog(1)", TIMER);
   
  if(autohide) {
    dialogclose.style.visibility = "hidden";
    window.setTimeout("hideDialog()", (autohide * 1000));
  } else {
    dialogclose.style.visibility = "visible";
  }
 return false;
}

// hide the dialog box //
function hideDialog() {
  var dialog = document.getElementById('dialog');
  clearInterval(dialog.timer);
  dialog.timer = setInterval("fadeDialog(0)", TIMER);
}

// fade-in the dialog box //
function fadeDialog(flag) {
  if(flag == null) {
    flag = 1;
  }
  var dialog = document.getElementById('dialog');
  var value;
  if(flag == 1) {
    value = dialog.alpha + SPEED;
  } else {
    value = dialog.alpha - SPEED;
  }
  dialog.alpha = value;
  dialog.style.opacity = (value / 100);
  dialog.style.filter = 'alpha(opacity=' + value + ')';
  if(value >= 99) {
    clearInterval(dialog.timer);
    dialog.timer = null;
  } else if(value <= 1) {
    dialog.style.visibility = "hidden";
    document.getElementById('dialog-mask').style.visibility = "hidden";
    clearInterval(dialog.timer);
  }
}