function CountryRegionForm() {

}

CountryRegionForm.prototype.setCountryElement = function(el) {
  this.countryElement = el;
}

CountryRegionForm.prototype.setComboBoxPrefix = function(prefix) {
  this.comboBoxPrefix = prefix;
}

CountryRegionForm.prototype.setTableRowPrefix = function (prefix) {
  this.tableRowPrefix = prefix;
}

CountryRegionForm.prototype.setCityRow = function(el) {
  this.cityRow = el;
}

CountryRegionForm.prototype.setCountry = function(countryId)
{
  var len = this.countryElement.options.length;

  for (i=0; i < len; i++)
  {
    if (this.countryElement.options[i].value == countryId)
    {
      this.countryElement.selectedIndex = i;
    }
  }

  this.showHideRegion();
}

CountryRegionForm.prototype.setRegion = function(region)
{
  var countryId = this.countryElement.value;
  var el        = this.comboBoxPrefix + '_' + countryId;
  var len       = 0;

  if (document.getElementById(el))
  {
    el  = document.getElementById(el);
    len = el.length;
    for (i=0; i < el.length; i++)
    {
      if (el.options[i].text == region)
      {
        el.selectedIndex = i;
      }
    }
  }

  else
  {
    document.getElementById(this.tableRowPrefix).value = region;
  }
}

CountryRegionForm.prototype.showHideRegion = function() {

  var country = this.countryElement;
  var found   = false;
  var el, val, i;
  var prefix = this.tableRowPrefix;
  var combobox_prefix = this.comboBoxPrefix;
  var len;

  if (document.getElementById(prefix))
    Element.hide(prefix); //hides the table row containing the freetext region format

  len = country.options.length;

  for (i=0; i < len; i++)
  {
    val = country.options[i].value;
    el  = prefix + '_' + val;

    if (document.getElementById(el))
    {
      Element.hide(el);

      if (val == country.value)
      {
        Element.show(el);
        found = true;
      }
    }
  }

  if (!found && document.getElementById(prefix) && country.value > 0)
    Element.show(prefix);

  if (country.value > 0 && document.getElementById(this.cityRow))
    Element.show(this.cityRow);

  else if (document.getElementById(this.cityRow))
    Element.hide(this.cityRow);
}