 
 
var changing = false;

function editByAjax(params,campo)
{
		if(params[0] == "tag")
		{
			Tag.edit(params[2],campo.value,returnDefault);
		}
		else if(params[0] == "urlDesc")
		{
			URL.editDescription(params[2],campo.value,returnDefault);
		}
		else if(params[0] == "urlName")
		{
			URL.editName(params[2],campo.value,returnDefault);
		}
		else if(params[0] == "urlTags")
		{
			URL.editTags(params[1],params[2],campo.value,returnDefault);
		}
}

function fieldEnter(campo,evt,idfld) 
{
	evt = (evt) ? evt : window.event;
	if (evt.keyCode == 13 && campo.value!="") 
	{
		elem = document.getElementById( idfld );
		//envia pro dwr
		var params = idfld.split('_');
		editByAjax(params,campo);
		//remove glow
		elem.innerHTML = campo.value;
		changing = false;
		return false;
	}
	else
	{
		return true;
	}


}

function fieldBlur(campo,idfld) {
	if (campo.value!="") {
		elem = document.getElementById( idfld );
		//envia pro dwr
		var params = idfld.split('_');
		editByAjax(params,campo);
		elem.innerHTML = campo.value;
		changing = false;
		return false;
	}
}

//edit field created
function editBox(actual) {
	//alert(actual.nodeName+' '+changing);
	if(!changing){
		width = widthEl(actual.id)*1.3;
		width  = (width > 500)?500:width;
		width  = (width < 150)?150:width;
		height =  25; // heightEl(actual.id) * 1.2;
		actual.innerHTML  = actual.innerHTML.replace(/\n/g , "");
		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 + "');\" />";
		changing = true;
	}

		actual.firstChild.focus();
}

//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;
	}
return h;
}

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";   

}
