

/*

// constants
var NORMAL_STATE = 4;

// Global variables
var http = getHTTPObject(); // We create the HTTP Object


*/



/**
*	Used to limit textareas to a certain number of characters
*/
function CheckMaxLength(ObjectID, MaxLen, CounterID){
	if(!ObjectID || !MaxLen)
		return;

	var l_obj = document.getElementById(ObjectID);
	var l_curr_len = l_obj.value.length;
	var counter = document.getElementById(CounterID);

	counter.innerHTML = eval(MaxLen) - l_curr_len;

	if(l_curr_len > eval(MaxLen))
		l_obj.value = l_obj.value.substring(0, MaxLen);
}

function findPos(obj) {
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		curleft = obj.offsetLeft
		curtop = obj.offsetTop
		while (obj = obj.offsetParent){
			curleft += obj.offsetLeft
			curtop += obj.offsetTop
		}
	}
	return [curleft,curtop];
}

function PostData(dest_url, params, fn, args){

	// open up the path
	http.open('POST', dest_url, true);
		
	http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	http.setRequestHeader("Content-length", params.length);
	http.setRequestHeader("Cache-Control", "no-cache");
	http.setRequestHeader("Connection", "close");

	http.onreadystatechange = function() { 
        if (http.readyState == 4)
            if (http.status == 200)
                fn(http, args);
    }
	http.send(params);
}


// Function to edit titles
function EditTitle(title_id){
	var titleObj = document.getElementById(title_id);
	if(!titleObj)
		return;
	
	var titleObjonclick = titleObj.onclick;		// Keep the onclick value to restore later
	titleObj.onclick=null;
	
	var titleValue = titleObj.innerHTML;
	titleObj.innerHTML = "<input id='input"+title_id+"' type='text' value='"+titleValue+"' style='width:120px' maxlength='32' />";
	var inputElm=titleObj.firstChild;
	inputElm.focus();
	inputElm.select();
	inputElm.onblur =function(){
		titleObj.innerHTML = inputElm.value;
		titleObj.onclick = titleObjonclick;
		UpdateGroup(title_id, titleObj.innerHTML);
	}
}

// Function to edit texts
function EditText(textObj){
  if(!textObj)
    return;
  
  var el_1 = null;
  var el_2 = null;
  for(var i = 0; i < textObj.childNodes.length; i++){
    if(textObj.childNodes[i].tagName && textObj.childNodes[i].tagName.toLowerCase() == "span"){
      if(!el_1){
        el_1 = textObj.childNodes[i];
      }else{
        el_2 = textObj.childNodes[i];
        break;
      }
    }
  }
  
  var textObjonclick = el_2.onclick;    // Keep the onclick value to restore later
  el_2.onclick=null;
  
  var textValue = el_1.innerHTML;
  //el_1.innerHTML = "<input class=\"input"+textObj.class+"\" type=\"text\" value=\""+textValue+"\" style=\"width:32px;\" maxlength=\"32\" />";
  el_1.innerHTML = "<textarea class=\"input"+textObj.class+"\" type=\"text\" cols=\"60\" rows=\"10\"  />"+textValue+"</textarea>";
  var inputElm=el_1.firstChild;
  inputElm.focus();
  inputElm.select();
  inputElm.onblur =function(){
    var new_text = inputElm.value;
    el_1.innerHTML = new_text;
    el_2.onclick = textObjonclick;
    UpdateText(textObj.className+'_-_text', new_text);
  }
}

function trim(str){
	return str.replace(/^\s*|\s*$/g,'');
}
