function SubmitChangedGroup(p_oSelect)
{
 SubmitChanges(p_oSelect.form);
}

function SubmitSortorder(p_strAction, p_strSortorder)
{
 var l_oInput;
 var l_oForm;
 
 l_oInput = document.createElement('input');
 l_oInput.setAttribute('type', 'hidden');
 l_oInput.setAttribute('name', 'SearchOrder');
 l_oInput.setAttribute('value', p_strSortorder);
 l_oForm = document.createElement('form');
 l_oForm.setAttribute('action', p_strAction);
 l_oForm.setAttribute('method', 'post');
 l_oForm.appendChild(l_oInput);
 document.body.appendChild(l_oForm);
 SubmitChanges(l_oForm);
}

function GotoPage(p_oSelect)
{
 location.href = p_oSelect.options[p_oSelect.selectedIndex].value;
}

function SubmitDeletedGroup(p_strGroup, p_strUrl)
{
 var l_oSelect;

 if(p_strGroup == 'eArea')
 {
  SetArea('');
  return;
 }
 if (p_strGroup == 'eRegion')
 {
  SetRegion('');
  return;
 }
 l_oSelect = document.getElementById('sg_' + p_strGroup);
 l_oSelect.selectedIndex = 0;
 SubmitChangedGroup(l_oSelect);
}

function SubmitChanges(p_oForm)
{
 var l_astrValue;
 var l_oGroups = p_oForm.getElementsByTagName('select');
 for(var l_intGroupIndex = 0; l_intGroupIndex < l_oGroups.length; l_intGroupIndex++)
  for(var l_intPropertyIndex = 0; l_intPropertyIndex < l_oGroups[l_intGroupIndex].options.length; l_intPropertyIndex++)
  {
   l_astrValue = l_oGroups[l_intGroupIndex].options[l_intPropertyIndex].value.split('|');
   l_oGroups[l_intGroupIndex].options[l_intPropertyIndex].value = l_astrValue[0];
   if(l_oGroups[l_intGroupIndex].selectedIndex == l_intPropertyIndex && l_astrValue.length == 2)
    p_oForm.action = l_astrValue[1];
  }
 p_oForm.submit();
}

var regions = new Array();
var areas = new Array();

function Loaded()
{
 SetVariables();
}

function GetUrl(p_strType, p_strCode)
{
 if (p_strType == 'Region')
  SetRegion(p_strCode);
 if (p_strType == 'Area')
  SetArea(p_strCode);
}

function SetRegion(value)
{
 document.getElementById('sg_eArea').value = '';
 var hiddenField = document.getElementById('sg_eRegion');
 for (var index = 0; index < areas.length; index++) {
  var splittedValue = areas[index].split('|');
  if (splittedValue[0] == value) {
   if (splittedValue.length == 2)
    hiddenField.form.action = splittedValue[1];
   break;
  }
 }
 hiddenField.value = value;
 SubmitChanges(hiddenField.form);
}

function SetArea(value)
{
 document.getElementById('sg_eRegion').value = '';
 var hiddenField = document.getElementById('sg_eArea');
 for(var index = 0; index < areas.length; index++)
 {
  var splittedValue = areas[index].split('|');
  if(splittedValue[0] == value)
  {
   if (splittedValue.length == 2)
    hiddenField.form.action = splittedValue[1];
   break;
  }
 }
 hiddenField.value = value;
 SubmitChanges(hiddenField.form);
}

function Close()
{
 document.getElementById('region-area-map').style.display = 'none';
}