function nuevoAjax(){
var xmlhttp=false;
 try {
  xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
 } catch (e) {
  try {
   xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
  } catch (E) {
   xmlhttp = false;
  }
 }

if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
  xmlhttp = new XMLHttpRequest();
}
return xmlhttp;
}

//***************FUNCION LOGIN*********************//
function EnviaLogin(){
	var c = document.getElementById('resultado')
	var usuario = document.frmlogin.usuario.value;
	var password = document.frmlogin.password.value;
	
	if(usuario.length == 0){
		alert('Ingrese el nombre de usuario de acceso.');
		document.frmlogin.usuario.focus();
		return false;
	}
	
	if(password.length == 0){
		alert('Ingrese su clave de acceso.');
		document.frmlogin.password.focus();
		return false;
	}
			
	ajax=nuevoAjax();
	c.innerHTML = '<img src="images/sending.gif" width="16" height="16" align="absmiddle">';
	ajax.open("POST", "recibe_login.php",true);
	ajax.onreadystatechange=function(){
			if (ajax.readyState==4) {	
				c.innerHTML = ajax.responseText; 
				if(ajax.responseText == "success") {
					window.location='drdent.system/panel.html'; 
				}
				else if(ajax.responseText == "block"){
					window.location='chau.html'; 
				}
				
			}
	}
	ajax.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
	ajax.send("usuario="+usuario+"&password="+password+"&control=enviado");
}

//***************FUNCION GENERAL PARA PARAMETROS GET*********************//
function fAjax(archivo,vars,divid){
	ajax = nuevoAjax();
	myRand = parseInt(Math.random()*999999999999999);
	var modurl = archivo +"?rand=" + myRand + vars; 
	ajax.open("GET", modurl, true);
    ajax.onreadystatechange = function() {
         if (ajax.readyState==1) {
             document.getElementById(divid).innerHTML='<img src="images/sending2.gif" width="16" height="16" align="absmiddle">';
         }
         else if (ajax.readyState==4){
			 document.getElementById(divid).innerHTML=ajax.responseText;
         }
    }
    ajax.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
    ajax.send(null);
    return	
}


//***************FUNCION INSCRIPCION*********************//
function EnviaRegistro(){
	var c = document.getElementById('resultado');
	var nombre = document.frmregistro.nombre.value;
	var apellido = document.frmregistro.apellido.value;
	var especialidad = document.frmregistro.especialidad.value;
	var documento = document.frmregistro.documento.value;
	var pais = document.frmregistro.pais.value;
	var direccion = document.frmregistro.direccion.value;
	var razon = document.frmregistro.razon.value;
	var ruc = document.frmregistro.ruc.value;
	var telefono = document.frmregistro.telefono.value;
	var movil = document.frmregistro.movil.value;
	var email = document.frmregistro.email.value;
	var website = document.frmregistro.website.value;
	
	if(nombre.length == 0){
		alert('Ingrese los nombres del representante.');
		document.frmregistro.nombre.focus();
		return false;
	}
	
	if(apellido.length == 0){
		alert('Ingrese los apellidos del representante.');
		document.frmregistro.apellido.focus();
		return false;
	}
	
	if(especialidad.length == 0){
		alert('Ingrese la especialidad m\xe9dica del representante.');
		document.frmregistro.especialidad.focus();
		return false;
	}
	
	if(documento.length == 0){
		alert('Ingrese el documento de identidad del representante.');
		document.frmregistro.documento.focus();
		return false;
	}
	
	if(pais == 0){
		alert('Seleccione el pa\xeds de procedencia.');
		document.frmregistro.pais.focus();
		return false;
	}
	
	if(direccion.length == 0){
		alert('Ingrese la direcci\xf3n de procedencia.');
		document.frmregistro.direccion.focus();
		return false;
	}
	
	if(razon.length == 0){
		alert('Ingrese el nombre o raz\xf3n social de su consultorio');
		document.frmregistro.razon.focus();
		return false;
	}
	
	if(ruc.length == 0){
		alert('Ingrese el R.U.C. o c\xf3digo tributario del representante o su consultorio.');
		document.frmregistro.ruc.focus();
		return false;
	}
	
	if(telefono.length == 0){
		alert('Ingrese el n\xfamero telef\xf3nico del representante.');
		document.frmregistro.telefono.focus();
		return false;
	}
	
	if(email.length == 0){
		alert('Ingrese el E-mail del representante.');
		document.frmregistro.email.focus();
		return false;
	}else{
		var arr=0;pun=0;
		for (m=0;m<document.frmregistro.email.value.length;m++){  
			switch (document.frmregistro.email.value.charAt(m)) {   
				case " ":
					window.alert("Formato de E-mail incorrecto.");
					document.frmregistro.email.focus();
					document.frmregistro.email.select();
					return false;
					break;
			     case ".":pun++;break;
			     case "@":arr++;break;   
	        }   
	    }   
		if ((arr==0) || (pun==0)){
			window.alert("Formato de E-mail incorrecto.");
			document.frmregistro.email.focus();
			document.frmregistro.email.select();
			return false;
		}
	}
	
	if(document.frmregistro['chterminos'].checked == false) {
		alert('Debe aceptar los t\xe9rminos de uso y privacidad.');
		return false;
	}
	
	if(document.frmregistro['chinfo'].checked == false) {
		alert('Debe aceptar la declaraci\xf3n.');
		return false;
	}
			
	ajax=nuevoAjax();
	c.innerHTML = '<img src="images/sending2.gif" width="16" height="16" align="absmiddle">';
	ajax.open("POST", "recibe_inscripcion.php",true);
	ajax.onreadystatechange=function(){
		if (ajax.readyState==4) {
			c.innerHTML = ajax.responseText
		}
	}
	ajax.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
	/*"&checkboxes="+checkboxes.join("&")*/
	ajax.send("nombre="+nombre+"&apellido="+apellido+"&especialidad="+especialidad+"&documento="+documento+"&pais="+pais+"&direccion="+direccion+"&razon="+razon+"&ruc="+ruc+"&telefono="+telefono+"&movil="+movil+"&email="+email+"&website="+website+"&control=enviado");
}

//***************FUNCION CONTACTENOS********************//
function EnviaContactenos(){
	var c = document.getElementById('envia_resultado');
	var nombre = document.frmcontacto.nombre.value;
	var direccion = document.frmcontacto.direccion.value;
	var telefonos = document.frmcontacto.telefonos.value;
	var email = document.frmcontacto.email.value;
	var requerimiento = document.frmcontacto.requerimiento.value;

	
	if(nombre.length == 0){
		alert('Ingrese su nombre o raz\xf3n social de su consultorio');
		document.frmcontacto.nombre.focus();
		return false;
	}
	
	
	if(telefonos.length == 0){
		alert('Ingrese su n\xfamero telef\xf3nico.');
		document.frmcontacto.telefonos.focus();
		return false;
	}
	
	if(email.length == 0){
		alert('Ingrese su E-mail .');
		document.frmcontacto.email.focus();
		return false;
	}else{
		var arr=0;pun=0;
		for (m=0;m<document.frmcontacto.email.value.length;m++){  
			switch (document.frmcontacto.email.value.charAt(m)) {   
				case " ":
					window.alert("Formato de E-mail incorrecto.");
					document.frmcontacto.email.focus();
					document.frmcontacto.email.select();
					return false;
					break;
			     case ".":pun++;break;
			     case "@":arr++;break;   
	        }   
	    }   
		if ((arr==0) || (pun==0)){
			window.alert("Formato de E-mail incorrecto.");
			document.frmcontacto.email.focus();
			document.frmcontacto.email.select();
			return false;
		}
	}
	
	if(requerimiento.length == 0){
		alert('Ingrese su requerimiento.');
		document.frmcontacto.requerimiento.focus();
		return false;
	}
			
	ajax=nuevoAjax();
	c.innerHTML = '<img src="images/sending2.gif" width="16" height="16" align="absmiddle">';
	ajax.open("POST", "recibe_contactenos.php",true);
	ajax.onreadystatechange=function(){
		if (ajax.readyState==4) {
			c.innerHTML = ajax.responseText
		}
	}
	ajax.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
	/*"&checkboxes="+checkboxes.join("&")*/
	ajax.send("nombre="+nombre+"&direccion="+direccion+"&telefonos="+telefonos+"&email="+email+"&requerimiento="+requerimiento+"&control=enviado");
}

