function findControl(ctrl, tag, trim_left_only, retrieve_type, node) {
  var RETRIEVE_BY_ID   = 1;
  var RETRIEVE_BY_NAME = 2;
  var RETRIEVE_BY_ANY  = 3;
  try {
    if (retrieve_type == null) {
      retrieve_type = RETRIEVE_BY_ANY;
    }
    if (trim_left_only == null) {
      trim_left_only = true;
    }

	  if ( node == null )
		  node = document;
	  if ( tag == null )
		  tag = '*';
    
	  var elem = getElementsByTag(node, tag);
  
    for (var j = 0; j < elem.length; j++) {
      if ( (retrieve_type && RETRIEVE_BY_ID) == RETRIEVE_BY_ID ){
        if (!trim_left_only) {
          if (elem[j].id != null && elem[j].id.indexOf(ctrl) != -1)  {
            return elem[j];
          }
        }
        else {          
          if (elem[j].id != null && elem[j].id.substring(elem[j].id.length - ctrl.length, elem[j].id.length) == ctrl) {
            return elem[j];
          }
        }
      }
      if ((retrieve_type && RETRIEVE_BY_NAME) == RETRIEVE_BY_NAME ){
        if (!trim_left_only) {
          if (elem[j].name != null && elem[j].name.indexOf(ctrl) != -1)  {
            return elem[j];
          }
        }
        else {
          if (elem[j].name != null && elem[j].name.substring(elem[j].name.length - ctrl.length, elem[j].name.length) == ctrl) {
            return elem[j];
          }
        }
      }
    }
    return null;
  }
  catch(e) {
    return null;
  }
  finally{
  }
}
function getElementsByTag(parentobj, tag){

	if (typeof parentobj.getElementsByTagName != 'undefined') return parentobj.getElementsByTagName(tag);
	if (parentobj.all && parentobj.all.tags) return parentobj.all.tags(tag);
	return null;

}
