 
  
  function LeftTrim(String) {
    String = "" + String
    var Count = 0
    if(String.length == 0)
      return(String)
    for(Count = 0;Count < String.length;Count++) {
      if(!(String.charAt(Count) == " "))
        return(String.substring(Count,String.length))
    }
    return("")
  }

  function RightTrim(String) {
    String = "" + String
    var Count = 0
    if(String.length == 0)
      return(String)
    for(Count = String.length -1;Count >= 0;Count--)
    {
      if(!(String.charAt(Count) == " "))
        return(String.substring(0,Count + 1))
    }
    return("")
  }

  function AllTrim(String) {
    String = "" + String
    return(RightTrim(LeftTrim(String)))
  }


  
  
  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) {
}
}
if ( !success ) {
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 = "/bhive/main/content/update";
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 );
 fldId = elem.id;
 fldId = fldId.substring(0,fldId.length-2);
 remotos = new datosServidor;
 nt = remotos.enviar(urlBase + "?id=" +encodeURI(fldId)+ "&title="+encodeURI(campo.value));
 //remove glow
 noLight(elem);
 elem.innerHTML = campo.value;
 changing = false;
 return false;
 } else {
 return true;
 }


}

function fieldBlur(campo,idfld,fieldName) {
 if (campo.value!="") {
 elem = document.getElementById( idfld );
 fldId = elem.id;
 fldId = fldId.substring(0,fldId.length-2); 
 remotos = new datosServidor;
 title = encodeURI(AllTrim(campo.value));
 title = title.replace(/[&]/g,"%26");
 nt = remotos.enviar(urlBase + "?id=" +encodeURI(fldId)+ "&"+fieldName+"="+title);
 elem.innerHTML = AllTrim(campo.value);
 changing = false;
 // window.location.href=window.location.href;
 return false;

 }
}

//edit field created
function editBox(actual,fieldName) {
 // alert(actual.nodeName+' '+changing);
 if(!changing){
 width = widthEl(actual.id);
 width=width*.98;
 height =heightEl(actual.id);
 if(width < 70) width = 90;
 if(height < 50) height = 50;
 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 + "','" + fieldName + "');\">" + AllTrim(actual.innerHTML) + "</textarea>";
 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<spans.length; i++){
 var spn = spans[i];

 if (((' '+spn.className+' ').indexOf("editTextLink") != -1) && (spn.id)) {
  spanLinkId = spn.id;
 spanLinkId = spanLinkId.substring(0,spanLinkId.length-5);
 spn.onclick = function () { editbox_init1(spanLinkId,''); }
 spn.style.cursor = "pointer";
 spn.title = "Click to edit!";
 }

 }


}

function editbox_init1(spanLinkId1,fieldName){
 if (!document.getElementsByTagName){ return; }
 var spans1 = document.getElementsByTagName("span");

 // loop through all span tags
 for (var i=0; i<spans1.length; i++){
 var spn1 = spans1[i];

 if (spn1.id == spanLinkId1) {
    editBox(spans1[i],fieldName); 
 }

 }


}

//crossbrowser load function
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("Please upgrade your browser to use full functionality on this page");
 }
}

//get width of text element
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;
}

//get height of text element
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;
 }
 h=h+h*0.1;
return h;
}

function highLight(span){
 //span.parentNode.style.border = "2px solid #D1FDCD";
 //span.parentNode.style.padding = "0";
 span.style.border = "1px solid #006699";
}

function noLight(span){
 //span.parentNode.style.border = "0px";
 //span.parentNode.style.padding = "2px";
 span.style.border = "0px";


}

//sets post/get vars for update
function setVarsForm(vars){
 formVars = vars;
}
addEvent(window, "load", editbox_init);
