var validStyleColor = "black";
var validStyleBgColor = "white";

var invalidStyleColor = "red";
var invalidStyleBgColor = "yellow";

//----------------------------------------------------------------------

function trim( val ) {
  return ( val.replace(/^\s*/, "").replace(/\s*$/, "") );
}

//----------------------------------------------------------------------

function isValidEmailAddress( obj )
{
  var re = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,})+$/;
  obj.value = trim(obj.value);
  
  return ( obj.value == "" || obj.value.match(re) != null );
}

//----------------------------------------------------------------------

function isRequired( obj )
{
  return ( trim(obj.value).length > 0 );
}

//----------------------------------------------------------------------

function isValidSelectOption( obj )
{
  return ( isRequired(obj[obj.selectedIndex]) );
}

//----------------------------------------------------------------------

function matchOptionByText( objID, sText )
{
  var obj = document.getElementById(objID);
  var sValue = "";
  
  if ( obj ) {
    for ( var i=0; i<obj.options.length; i++ ) {
      if ( obj[i].text == sText ) {
        obj.selectedIndex = i;
        sValue = obj[obj.selectedIndex].value;
        break;
      }
    }
  }
  
  return sValue;
}

//----------------------------------------------------------------------

function matchOptionByValue( objID, sValue )
{
  var obj = document.getElementById(objID);
  var sText = "";
  
  if ( obj ) {
    for ( var i=0; i<obj.options.length; i++ ) {
      if ( obj[i].value == sValue ) {
        obj.selectedIndex = i;
        sText = obj[obj.selectedIndex].text;
        break;
      }
    }
  }
  
  return sText;
}


