//script by yvoschaap.com
//freely useable
//optional link back would be very web 2.0 :)
function datosServidor() {
};
datosServidor.prototype.iniciar = function() {
try {
// Mozilla / Safari
this._xh = new XMLHttpRequest();
} catch (e) {
// Explorer
var _ieModelos = new Array(
'MSXML2.XMLHTTP.5.0',
'MSXML2.XMLHTTP.4.0',
'MSXML2.XMLHTTP.3.0',
'MSXML2.XMLHTTP',
'Microsoft.XMLHTTP'
);
var success = false;
for (var i=0;i < _ieModelos.length && !success; i++) {
try {
this._xh = new ActiveXObject(_ieModelos[i]);
success = true;
} catch (e) {
// Implementar manejo de excepciones
}
}
if ( !success ) {
// Implementar manejo de excepciones, mientras alerta.
return false;
}
return true;
}
}
datosServidor.prototype.ocupado = function() {
estadoActual = this._xh.readyState;
return (estadoActual && (estadoActual < 4));
}
datosServidor.prototype.procesa = function() {
if (this._xh.readyState == 4 && this._xh.status == 200) {
this.procesado = true;
}
}
datosServidor.prototype.enviar = function(urlget,datos) {
if (!this._xh) {
this.iniciar();
}
if (!this.ocupado()) {
this._xh.open("GET",urlget,false);
this._xh.send(datos);
if (this._xh.readyState == 4 && this._xh.status == 200) {
return this._xh.responseText;
}
}
return false;
}
var urlBase = "update.php";
var formVars = "";
var changing = false;
function fieldEnter(campo,evt,idfld) {
evt = (evt) ? evt : window.event;
if (evt.keyCode == 13 && campo.value!="") {
elem = document.getElementById( idfld );
remotos = new datosServidor;
nt = remotos.enviar(urlBase + "?fieldname=" +escape(elem.id)+ "&content="+escape(campo.value)+"&"+formVars,"");
//remove glow
noLight(elem);
elem.innerHTML = nt;
changing = false;
return false;
} else {
return true;
}
}
function fieldBlur(campo,idfld) {
if (campo.value!="") {
elem = document.getElementById( idfld );
remotos = new datosServidor;
nt = remotos.enviar(urlBase + "?fieldname=" +escape(elem.id)+ "&content="+escape(campo.value)+"&"+formVars,"");
elem.innerHTML = nt;
changing = false;
return false;
}
}
//edit field created
function cambia(actual) {
if(!changing){
width = widthEl(actual.id) + 20;
height =heightEl(actual.id) + 2;
if(width < 100)
width = 150;
if(height < 40)
actual.innerHTML = "";
else
actual.innerHTML = "";
changing = true;
}
actual.firstChild.focus();
}
//find all span tags with class editText and id as fieldname parsed to update script. add onclick function
function editbox_init(){
if (!document.getElementsByTagName){ return; }
var spans = document.getElementsByTagName("span");
// loop through all span tags
for (var i=0; i