function objetoAjax(){
	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;
}
function vali(form){
	var ing=validador(form);//(nuevo_Noticias);
	if(ing==true){
		enviarDatosEmail();
		
	}
	}
function enviarDatosEmail(){
	//donde se mostrará lo resultados
	divResultado = document.getElementById('resultado');
	divResultado.innerHTML = '<img src="../images/loader.gif">'
	//valores de los inputs
	nom=document.nuevo_empleado.nom.value;
	ape=document.nuevo_empleado.ape.value;
	doc=document.nuevo_empleado.doc.value;
	numdoc=document.nuevo_empleado.numdoc.value;
	lnac=document.nuevo_empleado.lnac.value;
	fnac=document.nuevo_empleado.fnac.value;
	cant=document.nuevo_empleado.cant.value;
	csol=document.nuevo_empleado.csol.value;
	nomp1=document.nuevo_empleado.nomp1.value;
	apep1=document.nuevo_empleado.apep1.value;
	cc=document.nuevo_empleado.cc.value;
	prof=document.nuevo_empleado.prof.value;
	nomp2=document.nuevo_empleado.nomp2.value;
	apep2=document.nuevo_empleado.apep2.value;
	cc1=document.nuevo_empleado.cc1.value;
	prof2=document.nuevo_empleado.prof2.value;
	tel=document.nuevo_empleado.tel.value;
	dir=document.nuevo_empleado.dir.value;
	telo=document.nuevo_empleado.telo.value;
	cel=document.nuevo_empleado.cel.value;
	fax=document.nuevo_empleado.fax.value;
	ema=document.nuevo_empleado.ema.value;
	trans=document.nuevo_empleado.trans.value;
	liv=document.nuevo_empleado.liv.value;
	/*var i 
    for (i=0;i<document.nuevo_empleado.ent.length;i++){ 
       if (document.nuevo_empleado.ent[i].checked) 
          break; 
    } 
	ent= document.nuevo_empleado.ent[i].value ;
	cam_com=document.nuevo_empleado.cam_com.value;*/
	//instanciamos el objetoAjax
	ajax=objetoAjax();
	//uso del medotod POST
	//archivo que realizará la operacion
	//registro.php
	ajax.open("POST", "email/registro.php",true);
	ajax.onreadystatechange=function() {
		if (ajax.readyState==4) {
			//mostrar resultados en esta capa
			divResultado.innerHTML = ajax.responseText
			//llamar a funcion para limpiar los inputs
			LimpiarCampos78();
		}
	}
	ajax.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
	//enviando los valores
	ajax.send("nom="+nom+"&ape="+ape+"&doc="+doc+"&numdoc="+numdoc+"&lnac="+lnac+"&fnac="+fnac+"&cant="+cant+"&csol="+csol+"&nomp1="+nomp1+"&apep1="+apep1+"&cc="+cc+"&prof="+prof+"&nomp2="+nomp2+"&apep2="+apep2+"&cc1="+cc1+"&prof2="+prof2+"&tel="+tel+"&dir="+dir+"&telo="+telo+"&cel="+cel+"&fax="+fax+"&ema="+ema+"&trans="+trans+"&liv="+liv)
}

function LimpiarCampos78(){
	document.nuevo_empleado.nom.value="";
	document.nuevo_empleado.ape.value="";
	document.nuevo_empleado.doc.value="";
	document.nuevo_empleado.numdoc.value="";
	document.nuevo_empleado.lnac.value="";
	document.nuevo_empleado.fnac.value="";
	document.nuevo_empleado.cant.value="";
	document.nuevo_empleado.csol.value="";
	document.nuevo_empleado.nomp1.value="";
	document.nuevo_empleado.apep1.value="";
	document.nuevo_empleado.cc.value="";
	document.nuevo_empleado.prof.value="";
	document.nuevo_empleado.nomp2.value="";
	document.nuevo_empleado.apep2.value="";
	document.nuevo_empleado.cc1.value="";
	document.nuevo_empleado.prof2.value="";
	document.nuevo_empleado.tel.value="";
	document.nuevo_empleado.dir.value="";
	document.nuevo_empleado.telo.value="";
	document.nuevo_empleado.cel.value="";
	document.nuevo_empleado.fax.value="";
	document.nuevo_empleado.ema.value="";
	document.nuevo_empleado.trans.value="";
	document.nuevo_empleado.liv.value="";
	document.nuevo_empleado.nom.focus();
}
function validador(nuevo_Noticias) {
  var nom = document.nuevo_empleado.nom.value;
  var ape = document.nuevo_empleado.ape.value;
  var doc = document.nuevo_empleado.doc.value;
  var numdoc = document.nuevo_empleado.numdoc.value;
  var lnac = document.nuevo_empleado.lnac.value;
  var fnac = document.nuevo_empleado.fnac.value;
  var cant = document.nuevo_empleado.cant.value;
  var csol = document.nuevo_empleado.csol.value;
   var nomp1 = document.nuevo_empleado.nomp1.value;
  var apep1 = document.nuevo_empleado.apep1.value;
  var cc = document.nuevo_empleado.cc.value;
  var prof = document.nuevo_empleado.prof.value;
    var nomp2 = document.nuevo_empleado.nomp2.value;
  var apep2 = document.nuevo_empleado.apep2.value;
  var cc1 = document.nuevo_empleado.cc1.value;
  var prof2 = document.nuevo_empleado.prof2.value;
    var tel = document.nuevo_empleado.tel.value;
  var dir = document.nuevo_empleado.dir.value;
  var telo = document.nuevo_empleado.telo.value;
  var cel = document.nuevo_empleado.cel.value;
  var fax = document.nuevo_empleado.fax.value;
  var ema = document.nuevo_empleado.ema.value;
  var trans = document.nuevo_empleado.trans.value;
  var liv = document.nuevo_empleado.liv.value;
  var nomRegex = /^[a-zA-Z]+(([\'\,\.\- ][a-zA-Z ])?[a-zA-Z]*)*$/;
  var emaRegex= /\w{1,}[@][\w\-]{1,}([.]([\w\-]{1,})){1,3}$/;
 
  if(nom == "") {
    inlineMsg('nom','Debes Ingresar un Nombre.',5);
    return false;
  }
  if(ape == "") {
    inlineMsg('ape','Debes Ingresar un Apellido.',5);
    return false;
  }
   if(doc == "") {
    inlineMsg('doc','Debes Escojer.',5);
    return false;
  }
  if(isNaN(numdoc)) {
    inlineMsg('numdoc','Debes Ingresar un Numero Valido.',5);
    return false;
  }
  if(lnac == "") {
    inlineMsg('lnac','Debes Escribir lugar.',5);
    return false;
  }
    if(fnac == "") {
    inlineMsg('fnac','Debes Escribir Fecha.',5);
    return false;
  }
  if(cant == "") {
    inlineMsg('cant','Debes Escribir Colegio Anterior.',5);
    return false;
  }
   if(csol == "") {
    inlineMsg('csol','Debes Escribir Curso Solicitado.',5);
    return false;
  }
   if(nomp1 == "") {
    inlineMsg('nomp1','Debes Escribir Nombre.',5);
    return false;
  }
   if(apep1 == "") {
    inlineMsg('apep1','Debes Escribir Apellido.',5);
    return false;
  }
   if(cc == "") {
    inlineMsg('cc','Debes Escribir Numero de Cedula.',5);
    return false;
  }
  if(prof == "") {
    inlineMsg('prof','Debes Escribir Profesion.',5);
    return false;
  }
   if(nomp2 == "") {
    inlineMsg('nomp2','Debes Escribir Nombre.',5);
    return false;
  }
   if(apep2 == "") {
    inlineMsg('apep2','Debes Escribir Apellido.',5);
    return false;
  }
   if(cc1 == "") {
    inlineMsg('cc1','Debes Escribir Numero de Cedula.',5);
    return false;
  }
  if(prof2 == "") {
    inlineMsg('prof2','Debes Escribir Profesion.',5);
    return false;
  }
  if(isNaN(tel)) {
    inlineMsg('tel','Debes Ingresar un Telefono.',5);
    return false;
  }
  if(isNaN(cel)) {
    inlineMsg('cel','Debes Ingresar un Celular.',5);
    return false;
  }
  if(cel == "") {
    inlineMsg('cel','Debes Ingresar un Celular.',5);
    return false;
  }
  if(dir == "") {
    inlineMsg('dir','Debes Ingresar una Direccion.',5);
    return false;
  }
  if(trans == "") {
    inlineMsg('trans','Debes Ingresar un Nombre Completo.',5);
    return false;
  }
  if(liv == "") {
    inlineMsg('liv','Debes Ingresar un Numero de licencia.',5);
    return false;
  }
   if(ema == "") {
    inlineMsg('ema','Debes Ingresar un Numero de licencia.',5);
    return false;
  }
 /* if(!ema.match(nomRegex)) {
    inlineMsg('ema','Debes ingresar un email Valido.',5);
    return false;
  }*/
   if(isNaN(fax)) {
    inlineMsg('fax','Debes Ingresar un Numero de Fax.',5);
    return false;
  }
  if(isNaN(telo)) {
    inlineMsg('telo','Debes Ingresar un Numero de Fax.',5);
    return false;
  }
  return true;
}

// START OF MESSAGE SCRIPT //

var MSGTIMER = 20;
var MSGSPEED = 5;
var MSGOFFSET = 3;
var MSGHIDE = 3;

// build out the divs, set attributes and call the fade function //
function inlineMsg(target,string,autohide) {
  var msg;
  var msgcontent;
  if(!document.getElementById('msg')) {
    msg = document.createElement('div');
    msg.id = 'msg';
    msgcontent = document.createElement('div');
    msgcontent.id = 'msgcontent';
    document.body.appendChild(msg);
    msg.appendChild(msgcontent);
    msg.style.filter = 'alpha(opacity=0)';
    msg.style.opacity = 0;
    msg.alpha = 0;
  } else {
    msg = document.getElementById('msg');
    msgcontent = document.getElementById('msgcontent');
  }
  msgcontent.innerHTML = string;
  msg.style.display = 'block';
  var msgheight = msg.offsetHeight;
  var targetdiv = document.getElementById(target);
  targetdiv.focus();
  var targetheight = targetdiv.offsetHeight;
  var targetwidth = targetdiv.offsetWidth;
  var topposition = topPosition(targetdiv) - ((msgheight - targetheight) / 2);
  var leftposition = leftPosition(targetdiv) + targetwidth + MSGOFFSET;
  msg.style.top = topposition + 'px';
  msg.style.left = leftposition + 'px';
  clearInterval(msg.timer);
  msg.timer = setInterval("fadeMsg(1)", MSGTIMER);
  if(!autohide) {
    autohide = MSGHIDE;  
  }
  window.setTimeout("hideMsg()", (autohide * 1000));
}

// hide the form alert //
function hideMsg(msg) {
  var msg = document.getElementById('msg');
  if(!msg.timer) {
    msg.timer = setInterval("fadeMsg(0)", MSGTIMER);
  }
}

// face the message box //
function fadeMsg(flag) {
  if(flag == null) {
    flag = 1;
  }
  var msg = document.getElementById('msg');
  var value;
  if(flag == 1) {
    value = msg.alpha + MSGSPEED;
  } else {
    value = msg.alpha - MSGSPEED;
  }
  msg.alpha = value;
  msg.style.opacity = (value / 100);
  msg.style.filter = 'alpha(opacity=' + value + ')';
  if(value >= 99) {
    clearInterval(msg.timer);
    msg.timer = null;
  } else if(value <= 1) {
    msg.style.display = "none";
    clearInterval(msg.timer);
  }
}

// calculate the position of the element in relation to the left of the browser //
function leftPosition(target) {
  var left = 0;
  if(target.offsetParent) {
    while(1) {
      left += target.offsetLeft;
      if(!target.offsetParent) {
        break;
      }
      target = target.offsetParent;
    }
  } else if(target.x) {
    left += target.x;
  }
  return left;
}

// calculate the position of the element in relation to the top of the browser window //
function topPosition(target) {
  var top = 0;
  if(target.offsetParent) {
    while(1) {
      top += target.offsetTop;
      if(!target.offsetParent) {
        break;
      }
      target = target.offsetParent;
    }
  } else if(target.y) {
    top += target.y;
  }
  return top;
}

// preload the arrow //
if(document.images) {
  arrow = new Image(7,80); 
  arrow.src = "../imagenes/msg_arrow.gif"; 
}