function getElementsByClass(searchClass,node,tag) {
  var classElements = new Array();
  if ( node == null )
      node = document;
  if ( tag == null )
      tag = '*';
  var els = node.getElementsByTagName(tag);
  var elsLen = els.length;
  var pattern = new RegExp("(^|\\\\s)"+searchClass+"(\\\\s|$)");
  for (i = 0, j = 0; i < elsLen; i++) {
      if ( pattern.test(els[i].className) ) {
          classElements[j] = els[i];
          j++;
      }
  }
  return classElements;
}

function doIdAction(val){
	/*
	var inputs = document.getElementsByTagName('input');
	for(i=0; i<inputs.length; i++){
		if(inputs[i].name == 'homePageForm:_idcl'){
			inputs[i].value = val;
			inputs[i].setAttribute("value", val);			
			break;
		}			
	}	
	document.forms['homePageForm'].submit();
	return false;
	*/
	
	document.getElementsByName('homePageForm:_idcl')[0].setAttribute("name", "_X");
	var iH = document.createElement("input");
	iH.setAttribute("type", "hidden");
	iH.setAttribute("name", "homePageForm:_idcl");
	iH.setAttribute("id", "homePageForm:_idcl");
	iH.setAttribute("value", val);
	document.getElementsByName('homePageForm')[0].appendChild(iH);
	document.forms['homePageForm'].submit();
}

function findJSFCmdLinkId(element){
	var clickVal = element.getAttribute("onclick");
	if( typeof(clickVal) == 'function' ) //IE takes onclick as anonymous function.
		clickVal = element.outerHTML;
		
	var fIdx = clickVal.lastIndexOf("value=") + 7;
	var _t = clickVal.substring(fIdx);
	var _qIdx = _t.indexOf("'");
	var id = _t.substring(0, _qIdx);
	return id;
}

function reAssignLinks(){
	document.getElementById('homePageForm').setAttribute("name", "homePageForm");
}

function reAssignLinksAAA(){
	var spans = getElementsByClass('actionListnerLink');
	for(i=0; i<spans.length; i++){
		var a = spans[i].getElementsByTagName('a');
		var id = findJSFCmdLinkId(a[0]);
		a[0].setAttribute("onclick", "doIdAction('"+id+"')");
		
		var newA = document.createElement("a");		
		newA.innerHTML = a[0].innerHTML;
		newA.setAttribute("onclick", "doIdAction('"+id+"')");
		//newA.setAttribute("href", "javascript:void(0)");
		newA.setAttribute("href", "javascript:doIdAction('"+id+"')");
		spans[i].appendChild(newA);
		
		a[0].style.display = 'none';
		
		/*
		try{
			a[0].setAttribute("onclick", "doIdAction('"+id+"')");
		}catch(e){
			alert(e);
			a[0].onclick = function(id){ alert(id); };
		}
		*/
	}
	//alert(spans.length);
	
	//alert(document.getElementsByName('homePageForm:_idcl')[0].value);
	
	document.getElementsByName('homePageForm:_idcl')[1].setAttribute("name", "")
}