//PRECARGA DE IMAGENES
var i;
var imagenes = new Array("./cpt4/gcodigo.gif","./cpt4/actualizar.gif","./cpt4/actualizar2.gif");
var lista_imagenes = new Array();

function cargarimagenes(){
for(i in imagenes){
 lista_imagenes[i] = new Image();
 lista_imagenes[i].src = imagenes[i];
}
}

//DEFINE OBJETOS DOOM 2
function element(id) { 
     if (document.getElementById != null) {      // 1st choice
          return document.getElementById(id);    // no N4,IE4
     }
     if (document.all != null) {                 // 2nd choice
          return document.all[id];               // IE only
     }
     if (document.layers != null) {              // 3rd choice
          return document.layers[id];            // N4 only
     }
     return null;                                // give up
}

//DEFINE OBJETO "AJAX" XMLHTTPREQUEST 2
function getHTTPObject() {
var xmlhttp;
if (window.XMLHttpRequest) { //no es IE
xmlhttp = new XMLHttpRequest();
}else if (window.ActiveXObject) { //es IE o no tiene el objeto
try {
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}catch (elerror) {
if (elerror.description){
      alert('El navegador utilizado no soporta el objeto XMLHTTPREQUEST. Error: '+elerror.description); //para IE
}else{
      alert('El navegador utilizado no soporta el objeto XMLHTTPREQUEST. Error: '+elerror); //para FF
}
}
}
return xmlhttp;
}

var xmlhttp = getHTTPObject();
var xmlhttp2 = getHTTPObject();

//ENVIO DE LOS DATOS
function evento(){
 var elemHtml=element("ice1");
 var botact=element("ice3");
 var botenvio=element("envio");
 //elemStyle.style.width= 'estilo como variable' //elemStyle.style.cssText= 'estilo como texto' //elemHtml.innerHTML= 'texto'	
  elemHtml.innerHTML="<img src=\"./cpt4/gcodigo.gif\">";
  document.formorigen.envio.disabled=true;
  botenvio.setAttribute('class', 'botones2');
 	botenvio.setAttribute('className', 'botones2');
  botact.innerHTML="<img src=\"./cpt4/actualizar2.gif\" border=\"0\">";
  xmlhttp.open("GET","./cpt4/gcodigo.php",true);
  xmlhttp.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
  xmlhttp.onreadystatechange=function() {
  if (xmlhttp.readyState==4) {
   cadenarespuesta=xmlhttp.responseText;
   elemHtml.innerHTML=cadenarespuesta;
   document.formorigen.envio.disabled=false;
   botenvio.setAttribute('class', 'botones');
 	 botenvio.setAttribute('className', 'botones');
   botact.innerHTML="<a href=\"#\" onclick=\"javascript:evento();return false;\" style=\"text-decoration:none;\"><img src=\"./cpt4/actualizar.gif\" border=\"0\"></a>";
  }
 }
 xmlhttp.send(null);
}

function eventof(idformu){
	var elemHtml=element("ice2");
	var botact=element("ice3");
  var botenvio=element("envio");
	if(ValidarDatos()){ 
  //elemStyle.style.width= 'estilo como variable' //elemStyle.style.cssText= 'estilo como texto' //elemHtml.innerHTML= 'texto'	
  elemHtml.innerHTML="<span class=\"mjeverifica\">Verificando c&oacute;digo de seguridad...</span>";
  document.formorigen.envio.disabled=true;
  botenvio.setAttribute('class', 'botones2');
 	botenvio.setAttribute('className', 'botones2');
  botact.innerHTML="<img src=\"./cpt4/actualizar2.gif\" border=\"0\">";
  xmlhttp2.open("GET","./cpt4/vcodigo.php?pass="+document.formorigen.codigoseguridad.value,true);
  xmlhttp2.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
  xmlhttp2.onreadystatechange=function() {
  if (xmlhttp2.readyState==4) {
   cadenarespuesta=xmlhttp2.responseText;
   //elemHtml.innerHTML=cadenarespuesta;
   if(esvacio(cadenarespuesta)){
    elemHtml.innerHTML="&nbsp;";
    //elemHtml.innerHTML="<span class=\"mjeacepta\">El c&oacute;digo de seguridad ingresado es correcto.</span>";
    document.formorigen.submit();
   }else{
   	//elemHtml.innerHTML="<span class=\"mjerechaza\">El c&oacute;digo de seguridad ingresado es err&oacute;neo.</span>";
   	elemHtml.innerHTML="&nbsp;";
   	document.formorigen.envio.disabled=false;
    botenvio.setAttribute('class', 'botones');
 	  botenvio.setAttribute('className', 'botones');
    botact.innerHTML="<a href=\"#\" onclick=\"javascript:evento();return false;\" style=\"text-decoration:none;\"><img src=\"./cpt4/actualizar.gif\" border=\"0\"></a>";
   	alert("Por favor ingrese el Código de Seguridad correcto.");
   	document.formorigen.codigoseguridad.focus();
   	document.formorigen.codigoseguridad.select();
   }
  }
 }
 xmlhttp2.send(null);
 }
}	
