<!--//comments
//http protocol request object functions taken from mozilla developers site latest version only in spanish for unknown reason, tal es la vida!
//I have tested this with opera, firefox and ie usual idiosyncrasies but works on all ie7 untested as at 03.01.07
//end comments
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
				// Implementing management of exceptions
			}
		}
		if ( !success ) {
			// Implementar manejo de excepciones, mientras alerta.
			// Implementing management of exceptions, while alerts
			return false;
		}
		return true;
	}
}

datosServidor.prototype.ocupado = function() { // datosServidor = data Servant / ocupado = busy
	estadoActual = this._xh.readyState; // estadoActual = statePresent
	return (estadoActual && (estadoActual < 4));
}

datosServidor.prototype.procesa = function() { // procesa = it processes
	if (this._xh.readyState == 4 && this._xh.status == 200) {
		this.procesado = true;
	}
}

datosServidor.prototype.enviar = function(urlget,datos) { // enviar = sending / iniciar = initiating
	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 urlPageset = "upd_page_set.php";
var urlSub = "upd_sub.php";
var urlAddtonew = "upd_new.php";
var urlSuprs = "upd_suprs.php";
var urlIndex = "regen.php";
var urlGenIdx = "idx_new.php";
var urlDelFunc = "del_func.php";
var urlRst = "acc_flg_rst.php";
var urlCt = "addr_ctk.php";
var urlDyu = "dyu_upd.php";
var urlChkd = "chk_del.php";
var formVars = "";
var changing = false;

function test_assoc() {
		remotos = new datosServidor;
		nt = remotos.enviar(urlChkd + "?" + formVars,"");
		document.getElementById('resp_text').value = nt;
}

function reset_flag() {
		remotos = new datosServidor;
		nt = remotos.enviar(urlRst + "?" + formVars,"");
		document.getElementById('resp_text').value = nt;
}

function rm_contact() {
		remotos = new datosServidor;
		nt = remotos.enviar(urlCt + "?" + formVars,"");
		document.getElementById('resp_text').value = nt;
}

function del_idxitem() {
		remotos = new datosServidor;
		nt = remotos.enviar(urlDelFunc + "?" + formVars,"");
		document.getElementById('resp_text').value = nt;
}

function ix_new() {
		remotos = new datosServidor;
		nt = remotos.enviar(urlGenIdx + "?" + formVars,"");
		document.getElementById('resp_text').value = nt;
}

function build_index() { 
		remotos = new datosServidor;
		nt = remotos.enviar(urlIndex + "?" + formVars,"");
		document.getElementById('resp_text').value = nt;
}


function page_set() { 
		remotos = new datosServidor;
		nt = remotos.enviar(urlPageset + "?" + formVars,"");
		document.getElementById('resp_text').value = nt;
}

function sub_set() { 
		remotos = new datosServidor;
		nt = remotos.enviar(urlSub + "?" + formVars,"");
		document.getElementById('resp_text').value = nt;
}

function add_new() {  
		remotos = new datosServidor;
		nt = remotos.enviar(urlAddtonew + "?" + formVars,"");
		document.getElementById('resp_text').value = nt;
}

function suprs_idx() {  
		remotos = new datosServidor;
		nt = remotos.enviar(urlSuprs + "?" + formVars,"");
		document.getElementById('resp_text').value = nt;
}

function diary_upd() {  
		remotos = new datosServidor;
		nt = remotos.enviar(urlDyu + "?" + formVars,"");
		document.getElementById('resp_text').value = nt;
}

function setVarsForm(vars){
	formVars  = vars;
}

// yvo remote field code 
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(urlDyu + "?fieldname=" +escape(elem.id)+ "&content="+escape(campo.value)+"&"+formVars,"");
		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(urlDyu + "?fieldname=" +escape(elem.id)+ "&content="+escape(campo.value)+"&"+formVars,"");
		elem.innerHTML = nt;
		changing = false;
		return false;
	}
}


function cambia(actual) {
	if(!changing){
		width = widthEl(actual.id) + 5;
		height =heightEl(actual.id) + 1;
		width = 655;
		if(height < 40)
			actual.innerHTML = "<input id=\""+ actual.id +"_field\" style=\"width: "+width+"px; height: "+height+"px;\" maxlength=\"254\" type=\"text\" value=\"" + actual.innerHTML + "\" onkeypress=\"return fieldEnter(this,event,'" + actual.id + "')\" onfocus=\"highLight(this);\" onblur=\"noLight(this); return fieldBlur(this,'" + actual.id + "');\" />";
		else
			actual.innerHTML = "<textarea name=\"textarea\" id=\""+ actual.id +"_field\" style=\"width: "+width+"px; height: "+height+"px;\" onfocus=\"highLight(this);\" onblur=\"noLight(this); return fieldBlur(this,'" + actual.id + "');\">" + actual.innerHTML + "</textarea>";
	
		changing = true;
	}

		actual.firstChild.focus();
}

function editbox_init(){
	if (!document.getElementsByTagName){ return; }
	var spans = document.getElementsByTagName("span");
	for (var i=0; i<spans.length; i++){
		var spn = spans[i];

        	if (((' '+spn.className+' ').indexOf("editText") != -1) && (spn.id)) {
			spn.onclick = function () { cambia(this); }
			spn.style.cursor = "pointer";
			spn.title = "Click to edit!";	
       	}
	}

}

function addEvent(elm, evType, fn, useCapture)
{
  if (elm.addEventListener){
    elm.addEventListener(evType, fn, useCapture);
    return true;
  } else if (elm.attachEvent){
    var r = elm.attachEvent("on"+evType, fn);
    return r;
  } else {
    alert("Error None Compatible Browser Upgrade To Latest Version");
  }
}


function widthEl(span){

	if (document.layers){
	  w=document.layers[span].clip.width;
	} else if (document.all && !document.getElementById){
	  w=document.all[span].offsetWidth;
	} else if(document.getElementById){
	  w=document.getElementById(span).offsetWidth;
	}
return w;
}


function heightEl(span){

	if (document.layers){
	  h=document.layers[span].clip.height;
	} else if (document.all && !document.getElementById){
	  h=document.all[span].offsetHeight;
	} else if(document.getElementById){
	  h=document.getElementById(span).offsetHeight;
	}
return h;
}
// jro span block manager 
function highLight(span){
            span.parentNode.style.border = "2px solid #D1FDCD";
            span.parentNode.style.padding = "0";
            span.style.border = "1px solid #54CE43";          
}

function noLight(span){
        span.parentNode.style.border = "0px";
        span.parentNode.style.padding = "2px";
        span.style.border = "0px";
}

addEvent(window, "load", editbox_init);
//-->