function creaAjax(){ 
	var http;
	var browser = navigator.appName;
	var http_request=false; 
	if (window.XMLHttpRequest)//firefox
		http_request = new XMLHttpRequest();
	else if (window.ActiveXObject){//microsoft
		try {
			http_request = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try {
				http_request = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e) {}
		}
	} else if (!http_request && typeof XMLHttpRequest!="undefined") //any
		http_request = new XMLHttpRequest(); 
	if (!http_request) {
		alert('Falla :( No es posible crear una instancia XMLHTTP');
		return false;
	}
	return http_request; 
}

function crearImagenVerificacion(contenedor){		
	var divContenido = document.getElementById(contenedor);
	divContenido.innerHTML = "<img src='../admin/clases/imagenVerificacion.php' align='absmiddle'/>";	
}

function generarCodigoVerificacion(){	
	ajaxc = creaAjax();
	ajaxc.open("GET","../admin/clases/numeroAleatoreo.php", true);
	ajaxc.onreadystatechange = function(){ 
		if(ajaxc.readyState == 4){			
			var codigo = ajaxc.responseText;			
			setCookie("codigoVerificacionImagine", codigo);				
		} 
	}
	ajaxc.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
	ajaxc.send(null);
	//crearImagenVerificacion();
	return;
}

function setCookie(name, value, expires, path, domain, secure){
  document.cookie =
    name+"="+escape(value)+
    (expires ? "; expires="+expires.toGMTString() : "")+
    (path    ? "; path="   +path   : "")+
    (domain  ? "; domain=" +domain : "")+
    (secure  ? "; secure" : "");
}

function getCookie(name){
  var cookie, offset, end;
  cookie  = " "+document.cookie;
  offset  = cookie.indexOf(" "+name+"=");
  if (offset == -1) return undefined;
  offset += name.length+2;
  end     = cookie.indexOf(";", offset)
  if (end    == -1) end = cookie.length;
  return unescape(cookie.substring(offset, end));
}

function verificarCodigos(codigoEscrito){
	codigo = getCookie("codigoVerificacionImagine");
	valor = true;
	for (i = 0; i < 4; i++) {   
    	if (codigoEscrito.charAt(i) != codigo.charAt(i)) { 			
        	valor = false;  
        }		
    }   
	return valor;  
}