var xmlhttp;
var elementId;

/*
Solicitud de Citas
Paso 1. Mostrar datos del usuario
*/
function citas01(id, id2)
{
elementId=id;
loadProcessing(id2);
xmlhttp=GetXmlHttpObject();
if (xmlhttp==null)
  {
  alert ("Browser does not support HTTP Request");
  return;
  }
var url="db/citas01.php";
//url=url+"?fecha_nacimiento="+document.getElementById('fechanaci_act').value;
url=url+"?contrasena="+document.getElementById('contrasena').value;
url=url+"&cedula="+document.getElementById('cedula_act').value;
url=url+"&sid="+Math.random();
xmlhttp.onreadystatechange=stateChanged;
xmlhttp.open("GET",url,true);
// wait 3 seconds
setTimeout(function(){xmlhttp.send(null);},2000);
//xmlhttp.send(null)
setTimeout(	function(){
	if (document.getElementById('id').value!=""){
		changeSelectedOption(document.getElementById('estadocivil'), document.getElementById('vestado_civil').value);
		changeSelectedOption(document.getElementById('pais'), document.getElementById('vpais').value);
		SelectEstado(document.getElementById('pais'),document.formulario_de_actualizacion.estado);
		changeSelectedOption(document.getElementById('estado'), document.getElementById('vestado').value);
		// Sexo
		if(document.getElementById('vsexo').value=="Masculino"){
			document.getElementById('sexoMasculino').checked=true;
			document.getElementById('sexoFemenino').checked=false;
		}
		else if(document.getElementById('vsexo').value=="Femenino"){
			document.getElementById('sexoMasculino').checked=false;
			document.getElementById('sexoFemenino').checked=true;
		}
	}
},5000);
clearSection(id2);
clearSection('03_calendario');
clearSection('04_dias');
clearSection('05_servicio');
clearSection('06_confirmacion');
}

/*
Solicitud de Citas
Paso 2. Mostrar Calendario
*/
function citas02(id, id2)
{
elementId=id;
loadProcessing(id2);
xmlhttp=GetXmlHttpObject();
if (xmlhttp==null)
  {
  alert ("Browser does not support HTTP Request");
  return;
  }
var url="db/citas02.php";
url=url+"?user_id="+document.getElementById('id').value;
url=url+"&sid="+Math.random();
xmlhttp.onreadystatechange=stateChanged;
xmlhttp.open("GET",url,true);
// wait 3 seconds
setTimeout(function(){xmlhttp.send(null);},2000);
//xmlhttp.send(null)
clearSection(id2);
clearSection('04_dias');
clearSection('05_servicio');
clearSection('06_confirmacion');
}

/*
Solicitud de Citas
Paso 3. Mostrar Horas
*/
function citas03(year, month, day, user_id, id, id2)
{
elementId=id;
loadProcessing(id2);
xmlhttp=GetXmlHttpObject();
if (xmlhttp==null)
  {
  alert ("Browser does not support HTTP Request");
  return;
  }
var url="db/citas03.php";
url=url+"?user_id="+user_id;
url=url+"&year="+year;
url=url+"&month="+month;
url=url+"&day="+day;
url=url+"&sid="+Math.random();
xmlhttp.onreadystatechange=stateChanged;
xmlhttp.open("GET",url,true);
// wait 3 seconds
setTimeout(function(){xmlhttp.send(null);},2000);
//xmlhttp.send(null)
clearSection(id2);
clearSection('05_servicio');
clearSection('06_confirmacion');
}

/*
Solicitud de Citas
Paso 4. Seleccionar Servicio
*/
function citas04(year, month, day, hour, user_id, id, id2)
{
elementId=id;
loadProcessing(id2);
xmlhttp=GetXmlHttpObject();
if (xmlhttp==null)
  {
  alert ("Browser does not support HTTP Request");
  return;
  }
var url="db/citas04.php";
url=url+"?user_id="+user_id;
url=url+"&year="+year;
url=url+"&month="+month;
url=url+"&day="+day;
url=url+"&hour="+hour;
url=url+"&sid="+Math.random();
xmlhttp.onreadystatechange=stateChanged;
xmlhttp.open("GET",url,true);
// wait 3 seconds
setTimeout(function(){xmlhttp.send(null);},2000);
//xmlhttp.send(null)
clearSection(id2);
clearSection('04_dias');
clearSection('06_confirmacion');
}

/*
Solicitud de Citas
Paso 5. Guardar cita en la BD
*/
function citas05(id, id2)
{
elementId=id;
loadProcessing(id2);
xmlhttp=GetXmlHttpObject();
if (xmlhttp==null)
  {
  alert ("Browser does not support HTTP Request");
  return;
  }
var url="db/citas05.php";
url=url+"?user_id="+document.getElementById('id').value;
url=url+"&year="+document.getElementById('year').value;
url=url+"&month="+document.getElementById('month').value;
url=url+"&day="+document.getElementById('day').value;
url=url+"&hour="+document.getElementById('hour').value;
url=url+"&tramite="+document.getElementById('tramite').value;
url=url+"&sid="+Math.random();
xmlhttp.onreadystatechange=stateChanged;
xmlhttp.open("GET",url,true);
// wait 3 seconds
setTimeout(function(){xmlhttp.send(null);},2000);
//xmlhttp.send(null)
clearSection(id2);
clearSection('03_calendario');
clearSection('04_dias');
clearSection('05_servicio');
}

/*
Actualizacion de Citas
Paso 1. Mostrar Citas del usuario
*/
function cambio_citas01(id, id2)
{
elementId=id;
loadProcessing(id2);
xmlhttp=GetXmlHttpObject();
if (xmlhttp==null)
  {
  alert ("Browser does not support HTTP Request");
  return;
  }
var url="db/cambio_citas01.php";
//url=url+"?fecha_nacimiento="+document.getElementById('fechanaci_act').value;
url=url+"?contrasena="+document.getElementById('contrasena').value;
url=url+"&cedula="+document.getElementById('cedula_act').value;
url=url+"&sid="+Math.random();
xmlhttp.onreadystatechange=stateChanged;
xmlhttp.open("GET",url,true);
// wait 3 seconds
setTimeout(function(){xmlhttp.send(null);},2000);
//xmlhttp.send(null)

clearSection(id2);
clearSection('01_calendario');
clearSection('02_dias');
clearSection('03_servicio');
clearSection('04_confirmacion');
}

/*
Actualizacion de Citas
Cambiar Cita - 1 - Mostrar Calendarios
*/
function cambio_citas02(id)
{
elementId="01_calendario";
loadProcessing(id);
xmlhttp=GetXmlHttpObject();
if (xmlhttp==null)
  {
  alert ("Browser does not support HTTP Request");
  return;
  }
var url="db/cambio_citas02a.php";
//url=url+"?fecha_nacimiento="+document.getElementById('fechanaci_act').value;
url=url+"?cita="+id;
url=url+"&sid="+Math.random();
xmlhttp.onreadystatechange=stateChanged;
xmlhttp.open("GET",url,true);
// wait 3 seconds
setTimeout(function(){xmlhttp.send(null);},2000);
//xmlhttp.send(null)

clearSection(id);
clearSection("02_dias");
clearSection("03_servicio");
clearSection("04_confirmacion");
}

/*
Actualizacion de Citas
Cambiar Cita - 2 - Mostrar Horas
*/
function cambio_citas02b(year, month, day, cita, id, id2)
{
elementId=id;
loadProcessing(id2);
xmlhttp=GetXmlHttpObject();
if (xmlhttp==null)
  {
  alert ("Browser does not support HTTP Request");
  return;
  }
var url="db/cambio_citas02b.php";
url=url+"?cita="+cita;
url=url+"&year="+year;
url=url+"&month="+month;
url=url+"&day="+day;
url=url+"&sid="+Math.random();
xmlhttp.onreadystatechange=stateChanged;
xmlhttp.open("GET",url,true);
// wait 3 seconds
setTimeout(function(){xmlhttp.send(null);},2000);
//xmlhttp.send(null)
clearSection(id2);
clearSection('03_servicio');
clearSection('04_confirmacion');
}

/*
Actualizacion de Citas
Cambiar Cita - 3 - Seleccionar Servicio
*/
function cambio_citas02c(year, month, day, hour, cita, id, id2)
{
elementId=id;
loadProcessing(id2);
xmlhttp=GetXmlHttpObject();
if (xmlhttp==null)
  {
  alert ("Browser does not support HTTP Request");
  return;
  }
var url="db/cambio_citas02c.php";
url=url+"?cita="+cita;
url=url+"&year="+year;
url=url+"&month="+month;
url=url+"&day="+day;
url=url+"&hour="+hour;
url=url+"&sid="+Math.random();
xmlhttp.onreadystatechange=stateChanged;
xmlhttp.open("GET",url,true);
// wait 3 seconds
setTimeout(function(){xmlhttp.send(null);},2000);
//xmlhttp.send(null)
clearSection(id2);
clearSection('02_dias');
clearSection('04_confirmacion');
}

/*
Actualizacion de Citas
Cambiar Cita - 4 - Guardar cita en la BD
*/
function cambio_citas02d(id, id2)
{
elementId=id;
loadProcessing(id2);
xmlhttp=GetXmlHttpObject();
if (xmlhttp==null)
  {
  alert ("Browser does not support HTTP Request");
  return;
  }
var url="db/cambio_citas02d.php";
url=url+"?cita="+document.getElementById('cita').value;
url=url+"&year="+document.getElementById('year').value;
url=url+"&month="+document.getElementById('month').value;
url=url+"&day="+document.getElementById('day').value;
url=url+"&hour="+document.getElementById('hour').value;
url=url+"&tramite="+document.getElementById('tramite').value;
url=url+"&sid="+Math.random();
xmlhttp.onreadystatechange=stateChanged;
xmlhttp.open("GET",url,true);
// wait 3 seconds
setTimeout(function(){xmlhttp.send(null);},2000);
//xmlhttp.send(null)
clearSection(id2);
clearSection('01_calendario');
clearSection('02_dias');
clearSection('03_servicio');
}

/*
Actualizacion de Citas
Cancelar Cita del usuario
*/
function cambio_citas03(id)
{
elementId=id;
//loadProcessing(id);
xmlhttp=GetXmlHttpObject();
if (xmlhttp==null)
  {
  alert ("Browser does not support HTTP Request");
  return;
  }
var url="db/cambio_citas03.php";
//url=url+"?fecha_nacimiento="+document.getElementById('fechanaci_act').value;
url=url+"?cita="+id;
url=url+"&sid="+Math.random();
xmlhttp.onreadystatechange=stateChanged;
xmlhttp.open("GET",url,true);
// wait 3 seconds
//setTimeout(function(){xmlhttp.send(null);},2000);
xmlhttp.send(null)

//clearSection(id);
//clearSection('03_calendario');
//clearSection('04_dias');
//clearSection('05_servicio');
//clearSection('06_confirmacion');
}

function disableButton(id){
    document.getElementById(id).disabled=true;
}

function stateChanged()
{
if (xmlhttp.readyState==4 || xmlhttp.readyState=="complete")
{
//	alert(elementId);
	document.getElementById (elementId).innerHTML=xmlhttp.responseText;
}
}

function GetXmlHttpObject()
{
if (window.XMLHttpRequest)
  {
  // code for IE7+, Firefox, Chrome, Opera, Safari
  return new XMLHttpRequest();
  }
if (window.ActiveXObject)
  {
  // code for IE6, IE5
  return new ActiveXObject("Microsoft.XMLHTTP");
  }
return null;
}

function clearSection(element){
	document.getElementById (element).innerHTML="";
}

function loadProcessing(id2){
	document.getElementById (elementId).innerHTML="<p align=\"center\"><img src=\"images/ajax-loading-graphics/globe64.gif\" width=\"64\" height=\"64\" /><br />Procesando. . .</p>";
}