//--- 
function validateTextField( document, fieldName, displayName )
{
  var retval = false;
  var msg = "";

  //---
  if ( (textField = document.getElementById( fieldName )) != null )
  {
  	if ( (textField.value != null) && (textField.value != "") )
        retval = true;
    else
    {
  	  msg = "The '" + displayName + "' field is required";
  	  textField.focus();
    }
  }
  else
  	msg = "Couldn't find a field named '" + fieldName + "'";

  if ( retval == false )
    alert( msg );

  return retval;
}

//--- 
function validateDropDownSelection( document, fieldName, displayName )
{
  var retval = false;
  var selectedIndex = -1;
  var msg = "";

  //---
  if ( (ddList = document.getElementById( fieldName )) != null )
  {
	selectedIndex = ddList.selectedIndex;

	if ( selectedIndex > 0 )
      retval = true;
    else
      msg = "Please select a value from the '" + displayName + "' drop-down list";
  }
  else
  	msg = "Couldn't find a drop down field named '" + fieldName + "'";

  if ( retval == false )
    alert( msg );

  return retval;
}

//---
function checkRegForm( allFields )
{
  var retval = false;
  //---
  if ( (retval = validateTextField( document, "firstname", "First Name" )) == true )
  {
    if ( (retval = validateTextField( document, "lastname", "Last Name" )) == true )
    {
      if ( (retval = validateTextField( document, "companyname", "Company Name" )) == true )
      {
        if ( (retval = validateTextField( document, "addr1", "Address" )) == true )
        {
          if ( (retval = validateTextField( document, "City", "City" )) == true )
          {
            if ( (retval = validateDropDownSelection( document, "Country", "Country" )) == true )
            {
              if ( (retval = validateTextField( document, "ZIPCode", "ZIP/Postal Code" )) == true )
              {
                if ( (retval = validateTextField( document, "EMail", "E-Mail" )) == true )
                {
                  if ( allFields )
                  {  
	                if ( (retval = validateTextField( document, "Telephone", "Telephone" )) == true )
                      if ( (retval = validateDropDownSelection( document, "PrimaryAC", "Primary Asset Class Interest" )) == true )
                        retval = validateDropDownSelection( document, "SecondaryAC", "Secondary Asset Class Interest" );
                  }
                }
              }
            }
          }
        }
      }
    }
  }

  return retval;
}

//--- 
function validateCheckboxes( document )
{
  var elem;
  var cb1, cb2, cb3;
  var selectedIndex = -1;
  var msg = "";
  var retval = false;

  //---
  elem = document.getElementById( "PrimaryAC" );
  
  cb1 = document.getElementById( "rates" );
  cb2 = document.getElementById( "credit" );
  cb3 = document.getElementById( "derivs" );
  
  if ( (cb1 != null) && (cb2 != null) && (cb3 != null) )
  {
    if ( (cb1.checked == true) || (cb2.checked == true) || (cb3.checked == true) )
    {
      var selStr = "";
      
      if ( cb1.checked == true )
        selStr += "RATES";
      
      if ( cb2.checked == true )
      {
        if ( selStr.length > 0 )
          selStr += ",";
        selStr += "CREDIT";
      }
          
      if ( cb3.checked == true )
      {
        if ( selStr.length > 0 )
          selStr += ",";
        selStr += "DERIVS";
      }

      elem.value = selStr;
      retval = true;      
    }
    else
      msg = "Please select a product from the product list";
  }
  else
  {
    msg = "Couldn't find the check box element '";
    
    if ( cb1 == null )
      msg += "rates";
    else if ( cb2 == null )
      msg += "credit";
    else if ( cb3 == null )
      msg += "derivs";
      
    msg += "'!";
  }

  if ( retval == false )
    alert( msg );

  return retval;
}

//---
function checkTWRegForm()
{
  var retval = false;

  //---
  if ( (retval = validateCheckboxes( document )) == true )
    if ( (retval = validateTextField( document, "firstname", "First Name" )) == true )
      if ( (retval = validateTextField( document, "lastname", "Last Name" )) == true )
        if ( (retval = validateTextField( document, "companyname", "Company Name" )) == true )
          if ( (retval = validateTextField( document, "EMail", "E-Mail" )) == true )
            retval = validateTextField( document, "Telephone", "Telephone" );

  return retval;
}