//
// -- Standard HTML - Javascript routines which are needed on several places!
// -- to avoid confusion
//
// -- rasc
//
//


//
// Get Element By ID  (NS & IE)
//
function bbGetElementByID (eid) {
	if (document.all) {
		return document.all[eid];
	}
	if (document.getElementById) {
		return document.getElementById(eid);
	}

	return null;
}





//
// -- sets Focus for objectID to item named with value  or by index (option[i])
// -- when text is used, text may be a regular expression!
// -- return: true/false
//
function bbSelectOptionByValue(objID, v) {

  var o = bbGetElementByID(objID)


	if(!o || typeof(o)!="object" || typeof(o["options"])=="undefined" || !o.options.length) {
		return false;
	};


	for (var i=0; i < o.options.length; i++)  {
		if (o.options[i].value == v) {
   			o.options[i].selected = true;
			return true;
		}
	}

	return false;
}


function bbSelectOptionByIndex(objID, i_nr) {

  var o = bbGetElementByID(objID)

	i_nr = (i_nr) ? i_nr : 0;

	if(!o || typeof(o)!="object" || typeof(o["options"])=="undefined" || !o.options.length) {
		return false;
	};

   	o.options[i_nr].selected = true;
	return true;
}





//
// -- sets Focus for objectID to item named with value  or by index (option[i])
// -- when text is used, text may be a regular expression!
// -- return: true/false
//
function bbInputByValue(objID, v) {

  var o = bbGetElementByID(objID)


      o.value=v;
        return true;
}



//
// -- sets Focus for objectID to item named with value  or by index (option[i])
// -- when text is used, text may be a regular expression!
// -- return: true/false
//
function bbOutputByValue(objID) {

  var o = bbGetElementByID(objID)

  return o.value;
}



//
// -- set the standard help message text for an edit field
// -- return: true
//
function setHelpEDT (id, init, text, helpMSG)
{
  edtValue = bbOutputByValue(id);

  if((text != '') || ((edtValue != '') && (edtValue != helpMSG)))
  {
    if((text != '') && (edtValue == ''))
    {
      bbInputByValue(id, text);
    }
    else
    {
      bbInputByValue(id, edtValue);
    }
  }
  else
  {
    if(!init)
    {
      bbInputByValue(id, '');
    }
    else
    {
      if(edtValue == helpMSG)
      {
        bbInputByValue(id, '');
      }
      else
      {
        bbInputByValue(id, helpMSG);
      }
    }
  }

  return true;
}

