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; 
}

function actualizaCampoBD(idCampo, tabla, campo, codigo, obligatorio){
	var valor = document.getElementById(idCampo).value;
	var aleatorio=Math.floor(Math.random()*10001);

	if (valor == "" && obligatorio){
		document.getElementById(idCampo).style.backgroundColor = "#ff0000";
		return false;
	}else{
		ajax = nuevoAjax();
		ajax.open("GET", "../../funciones/actualizacampobd.asp?tabla=" + tabla + "&campo=" + campo + "&valor=" + valor + "&codigo=" + codigo + "&rnd=" + aleatorio, true);
		ajax.onreadystatechange = function(){ 
			if (ajax.readyState == 4){
				if (ajax.responseText != "OK"){
					document.getElementById(idCampo).style.backgroundColor = "#ff0000";
					alert(ajax.responseText);
				}else{
					document.getElementById(idCampo).style.backgroundColor = "#ffffff";
				}
			} 
		}
		ajax.send(null);
	}
}
