///////////////////////////////////////////////////////////////////////////
//
//  Function-pack: common admin-section functions
//  Copyright (c) 2006 I.W. 380 (http://iw380.com.ua)
//
//      realGVM   (Valeriy Galyant)   (Valeriy.Galyant@gmail.com)
//      Tramp     (Alexis Nabok)      (Alex.Nabok@gmail.com) 
//      Kiev, Ukraine
//
//  Version 1.0
//  Developed for "I.W. 380 administration" ONLY
//  This copyright notice MUST stay intact for use
//
///////////////////////////////////////////////////////////////////////////
$(document).ready(function() {
 $('.checkagenda').click(function(){
  if($(this).is(':checked')){
   $('.agend').css('display','table-row');
  }
  else{$('.agend').hide()}
 })
});
var dictionary = null;

function __(str)
{
  if (!dictionary || !dictionary[str]) return str;
  return dictionary[str]
}

var editors = null;
//-------------------------------------------------------------------------------
//                               Visual Effects
//-------------------------------------------------------------------------------
var id_max = 0;
function rowRemovePre(id)
{
  el = document.getElementById('Rec' + id);
  if (el) el.style.backgroundColor = '#FFD2D2';
}
function rowRemove(id)
{
  el = document.getElementById('Rec' + id);
  if (el) setTimeout(function() {hideRemove('Rec' + id, 100)} );
}
function hideRemove(id, per)
{
  el = document.getElementById(id);
  if (!el) return;
  per -= 10;
  if (!bw.moz || per <= 0)
  {
    el.parentNode.removeChild(el);
  }
  setOpacity(el, per);
  setTimeout(function() {hideRemove(id, per)}, 60);
}
//-------------------------------------------------------------------------------
//                               Group & single operations
//-------------------------------------------------------------------------------
function edit_row(id)
{
  tr = document.getElementById('Rec'+id);
  if (!tr) return;
  i = 0;
  for(j=0; j<tr.childNodes.length; j++)
  {
    td = tr.childNodes[j];
    if (!/td/i.test(td.tagName)) continue;
  	if (oeConfigField[i])
    {
      td.innerHTML = '<input type="text" name="'+oeConfigField[i]+'['+id+']" value="'+td.innerHTML+'" class="input fill" />';
    }
    if (oeConfigButt[i] == 'edit')
    {
      td.innerHTML = '<img src="../images/icon/save.gif" border="0" alt="" onclick="do_action(\'save_row\', \''+id+'\')" />';
    }
    i++;
  }
  oeNumRows++;
}
function new_row()
{
  oeRows++;
  table = document.getElementById('list_body');
  tr = document.createElement('tr');
  tr.className = 'even';
  tr.id = 'Recnew'+oeRows;
  try {
    tr.setAttribute('id','Recnew' + oeRows)
  } catch(e) {}
  for(i=0; i<oeConfigField.length; i++)
  {
    td = document.createElement('td');
  	if (oeConfigField[i])
    {
      td.innerHTML = '<input type="text" name="'+oeConfigField[i]+'[new'+oeRows+']" value="" class="input fill" />';
    }
    else if (oeConfigButt[i] == 'edit')
    {
      td.innerHTML = '<img src="../images/icon/save.gif" border="0" alt="" onclick="do_action(\'save_row\', \'new'+oeRows+'\')" />';
    }
    tr.appendChild(td);
  }
  table.appendChild(tr);
  oeNumRows++;
}
function rowStatus(id, name, val)
{
  if (!id) return;
  el = document.getElementById('Rec' + id);
  if (el)
  {
    for (j in el.childNodes)
    {
      el_ = el.childNodes[j];
      if (/td/i.test(el_.tagName) && el_.innerHTML.indexOf("do_action('" + name) != -1)
      {
        if (val)
        {
          el_.innerHTML = el_.innerHTML.replace('minus', 'plus').replace('1)', '0)');
        }
        else
        {
          el_.innerHTML = el_.innerHTML.replace('plus', 'minus').replace('0)', '1)');;
        }
      }
    }
  }
}
function rowCategory(id, name, val)
{
  if (!id) return;
  td = document.getElementById('Cat' + id);
  cat = document.frm.apply_category;
  if (td)
  {
    for(j=0; j<cat.options.length; j++)
    {
      if (cat.options[j].value == val || cat.options[j].value == -val)
      {
        txt = cat.options[j].parentNode.label + ' &raquo; ' + cat.options[j].innerHTML; //cat.options[i].name ? cat.options[i].name : cat.options[i].innerHTML;
        if (val > 0)
        {
          if (td.innerHTML.indexOf('sel_category=' + val + '"') == -1)
          {
            td.innerHTML = '<a href="su_product.php?sel_category=' + val + '">' + txt + '</a><br />' + td.innerHTML;
          }
        }
        else
        {
          td.innerHTML = td.innerHTML.replace('su_product.php?sel_category=' + (-val) + '"', '#"').replace(/<a href="[^"#]*#">[^<]*<\/a>(<br[^>]*>)?/gi, '');
        }
      }
    }
  }
}
function group_delete()
{
  ids = new Array();
  for (i=0; i<document.frm.elements.length; i++)
  {
    el = document.frm.elements[i];
    if (el.checked && (el.name == 'id[]' || el.name == 'id')) ids[ids.length] = el.value;
  }
  if (ids.length == 0)
  {
    alert(__('Please choose smth to delete'));
  }
  else
  {
    do_action('delete', ids.toString());
  }
}
function group_download()
{
  ids = new Array();
  for (i=0; i<document.frm.elements.length; i++)
  {
    el = document.frm.elements[i];
    if (el.checked && (el.name == 'id[]' || el.name == 'id')) ids[ids.length] = el.value;
  }
  if (ids.length == 0)
  {
    alert(__('Please choose smth to download'));
  }
  else
  {
    do_action('download', ids.toString());
  }
}
function group_status(val, field)
{
  ids = new Array();
  for (i=0; i<document.frm.elements.length; i++)
  {
    el = document.frm.elements[i];
    if (el.checked && (el.name == 'id[]' || el.name == 'id')) ids[ids.length] = el.value;
  }
  if (ids.length == 0)
  {
    alert('Please choose smth to on/off');
  }
  else
  {
    do_action('status', ids.toString(), val, field);
  }
}
function group_category(val, field)
{
  if (!field) field = 'category';
  ids = new Array();
  for (i=0; i<document.frm.elements.length; i++)
  {
    el = document.frm.elements[i];
    if (el.checked && (el.name == 'id[]' || el.name == 'id')) ids[ids.length] = el.value;
  }
  if (val == 0)
  {
    alert('Please choose category');
  }
  else if (ids.length == 0)
  {
    alert('Please choose smth to on/off');
  }
  else
  {
    do_action('category', ids.toString(), val, field);
  }
}
function group_save(field)
{
  if (!field) field = 'manual_order';
  ids = new Array();
  vals = new Array();
  for (i=0; i<document.frm.elements.length; i++)
  {
    el = document.frm.elements[i];
    if (el.value && /(.*)\[(\d+)\]/.test(el.name) && RegExp.$1 == field)
    {
      vals[vals.length] = el.value;
      ids[ids.length] = RegExp.$2;
    }
  }
  if (ids.length == 0)
  {
    alert('Please choose smth to on/off');
  }
  else
  {
    do_action('order', ids.toString(), vals.toString(), field);
  }
}
window.tm_alert = setTimeout(function() {hideRemove('alert', 100)}, 5000)
window.tm_error = setTimeout(function() {hideRemove('error', 100)}, 5000)
//-------------------------------------------------------------------------------
//                             Row heighlight
//-------------------------------------------------------------------------------

function getPos(el)
{
  r = { x: el.offsetLeft, y: el.offsetTop };
  if (el.offsetParent)
  {
    tmp = getPos(el.offsetParent);
    r.x += tmp.x;
    r.y += tmp.y;
  }
  return r;
}
var imgPos = null;
function listenClicks(evt) 
{
  evt = (evt) ? evt : ((event) ? event : null);
  if (evt)
  {
    el = (evt.target) ? evt.target : ((evt.srcElement) ? evt.srcElement : null);
    if (el && el.type == 'checkbox' && el.name == 'id[]')
    {
      rowCheck(el);
    }
    if (el && el.id && el.id=='map')
    {
     if (!imgPos) imgPos = getPos(document.getElementById('map'));
     if (evt.pageX)
     {
       x = evt.pageX;
       y = evt.pageY;
     }
     else if (evt.clientX)
     {
       dx = 0;
       x = evt.clientX;
       y = evt.clientY;
       if (window.pageXOffset || window.pageYOffset) 
       {
         x-= window.pageXOffset;
         y-= window.pageYOffset;
       }
       if (document.body.scrollTop)
       {
         x += document.body.scrollLeft;
         y += document.body.scrollTop;
       }
     }
     if (el3 = document.getElementById('map_pos'))
     {
       el3.style.top = (y - 10) + 'px';
       el3.style.left = (x - 10) + 'px';
     }
     x = x - imgPos.x;
     y = y - imgPos.y;
     document.frm.x.value = x;
     document.frm.y.value = y;
    }
  }
}
document.onclick=listenClicks;
function init_map()
{
  if (!imgPos) imgPos = getPos(document.getElementById('map'));
  if (el3 = document.getElementById('map_pos'))
  {
    el3.style.top = (document.frm.y.value - 10 + imgPos.y) + 'px';
    el3.style.left = (document.frm.x.value - 10 + imgPos.x) + 'px';
  }
}
function rowCheck(el)
{
  el2 = el;
  while (el2 && !/^tr$/i.test(el2.tagName))
  {
    el2 = el2.parentNode;
  }
  if (!el2) return;
  if (el.checked)
  {
    el2.className += ' checked';
  }
  else
  {
    el2.className = el2.className.replace(/ checked/g, '');
  }
}
//-------------------------------------------------------------------------------
function setall(ch)
{
  for(i=0; i<document.frm.elements.length; i++)
  {
    el = document.frm.elements[i];
    if(el.type == 'checkbox' && (el.name == 'id[]' || el.name == 'id'))
    {
      el.checked = ch;
      rowCheck(el);
    }
  }
}
function getHeight()
{
  var h = 550;
  if (window.innerHeight)
  {
    h = window.innerHeight;
  } 
  else if (document.body.clientHeight) h = document.body.clientHeight;
  return h-176;
}
var cdate = null;
var height_prop = 'height';
if (bw.moz) height_prop = 'min-height';
function contentHeight()
{
  var content  = document.getElementById('content');
  var mdate = new Date();
  if (cdate && (mdate - cdate < 500)) return;
  if (content)
  {
  if (bw.moz) content.style.minHeight = getHeight() + 'px'; else content.style.height = getHeight() + 'px';
  }
  cdate = mdate;
}
function contentInit()
{
  if (bw.moz) document.write('<style type="text/css">#content {min-height:' + getHeight() + 'px} </style>'); else document.write('<style type="text/css">#content {height:' + getHeight() + 'px} </style>');
}
//-------------------------------------------------------------------------------
//                             TabBrowsing.class
//-------------------------------------------------------------------------------
var activeTab = 0;
function turnAreasOff(tab)
{
  tab = 'tab'+tab;
  for (i in editors)
  {
    if (_editor_gener[i] && _editor_start[i])
    {
      htmlarea_switch(i);
    }
  }
}
function turnAreasOn()
{
  initEditor();
}
function changeTab(setTab)
{
  if (setTab == activeTab) return;
  if (window.disableTabChange)
  {
    setTimeout('changeTab('+setTab+')', 100);
    //alert('Please wait until HTML editor load');
    return false;
  }
  if (editors)
  {
    turnAreasOff(activeTab);
  }
  document.getElementById('Tab'+activeTab).style.display='none';
  document.getElementById('TabBut'+activeTab).className='tab';
  activeTab = setTab;
  document.getElementById('Tab'+activeTab).style.display='';
  document.getElementById('TabBut'+activeTab).className='tab tab_active';
  if (editors)
  {
    turnAreasOn(setTab);
    //setTimeout(function() {turnAreasOn(setTab);}, 200 );
  }
}
//-------------------------------------------------------------------------------
//                                  Hint
//-------------------------------------------------------------------------------
var basedOn = 'id';
function listenOver(evt) 
{
  evt = (evt) ? evt : ((event) ? event : null);
  if (evt)
  {
   el = (evt.target) ? evt.target : ((evt.srcElement) ? evt.srcElement : null);
   var tipsEl    = document.getElementById('tips');
   var tipsTx    = document.getElementById('tips_inside');
   do_left = true;
   if (!tipsEl) return;
   if (evt.pageX)
   {
     x = evt.pageX;
     y = evt.pageY
   }
   else if (evt.clientX)
   {
     dx = 0;
     x = evt.clientX;
     y = evt.clientY;
     if (window.pageXOffset || window.pageYOffset) 
     {
       x-= window.pageXOffset;
       y-= window.pageYOffset;
     }
     if (document.body.scrollTop)
     {
       x += document.body.scrollLeft;
       y += document.body.scrollTop;
     }
   }
   if (el)
   {
     if (el[basedOn] && (str = new String(el[basedOn])) && str.substring(0, 5) == 'HINT:') 
     {
       tipsTx.innerHTML = txt = str.substring(5, el[basedOn].length);
       tipsEl.style.visibility = 'visible';
       if ((window.innerWidth && (x + Math.floor(txt.length*8) > window.innerWidth - 50)) || (document.body.clientWidth && (x + Math.floor(txt.length*8) > document.body.clientWidth - 50)))
       {
         x-= Math.floor(txt.length*7) + 20;
         tipsEl.style.width = (Math.floor(txt.length*7) + 20)+'px';
       }
       else
       {
         tipsEl.style.width = 'auto';
       }
       //if (!window.hinttm) window.hinttm = SetTimeOut(function () { tipsEl.style.visibility = 'visible'; }, 500 );
     }
     else
     {
       //if (window.hinttm) ClearTimeOut(window.hinttm);
       tipsEl.style.visibility = 'hidden';
       x = 0;
       y = 0;
     }
   }
   tipsEl.style.left = (x+8) + 'px';
   tipsEl.style.top = (y+22) + 'px';
  }
}
document.onmousemove=listenOver;
//-------------------------------------------------------------------------------
//                             Action.Frame
//-------------------------------------------------------------------------------
function do_submit(par)
{
  document.location.replace(document.location.pathname + (par ? '?' + par : ''));
}

var lastAction = null;
var lastActionName = null;
var lastId = null;
var lastVal = null;

function do_action(action, id, val, action_name)
{
  if (/(\w+) as (\w+)/.test(action))
  {
    action_name = RegExp.$1;
    action = RegExp.$2;
  }
  else if (!action_name)
  {
    action_name = action;
  }
  lastAction = action;
  lastActionName = action_name;
  lastId = new String(id);
  lastVal = val;
  switch (lastAction)
  {
    case 'delete':
      ids = lastId.split(',');
      for(i=0; i<ids.length; i++)
      {
        rowRemovePre(ids[i]);
      } 
    break;
    case 'save_row':
      str = '';
      for(i=0; i<oeConfigField.length; i++)
      if (oeConfigField[i])
      {
        str += '&' + oeConfigField[i] + '=' + document.frm.elements[oeConfigField[i] + '[' + id + ']'].value;
      }
      document.getElementById('actionFrame').src = document.location.pathname + '?action=' + action_name + (id ? '&id=' + id : '') + str;
      return true;
    break;
  }
  document.getElementById('actionFrame').src = document.location.pathname + '?action=' + action_name + (id ? '&id=' + id : '') + (val ? '&val=' + val : '');
}
function CreateNote(type, text)
{
  if (window['tm_'+type]) clearTimeout(window['tm_'+type]);
  el = document.getElementById('in_'+type);
  if (!el)
  {
    el2 = document.createElement('div');
    el2.id = type;
    el = document.createElement('div');
    el.id = 'in_'+type;
    el2.appendChild(el);
    document.body.appendChild(el2);
    //document.getElementById('content').insertBefore(el2, document.getElementById('content').childNodes[0]);
  }    
  el.style.display = '';
  el.style.visibility = 'visible';
  setOpacity(el, 95);
  el.innerHTML = text;
  window['tm_'+type] = setTimeout(function() {hideRemove(type, 100)}, 5000)
}
function frameAction()
{
  if (!lastAction) return;
  var content = document.getElementById('actionFrame').contentWindow.document.body.innerHTML;
  ok = false;
  newId = 0;
  if (content.substring(0, 2) == 'OK')
  {
    ok = true;
    sub = content.substring(3, content.length);
    if (sub.indexOf('|') != -1)
    {
      newId = sub.substring(0, sub.indexOf('|'));
      if (document.frm && document.frm.elements['id']) document.frm.elements['id'].value = newId;
      sub = sub.substring(sub.indexOf('|') + 1, sub.length)
    }
    CreateNote('alert', sub);
  }
  if (content.substring(0, 5) == 'ERROR')
  {
    CreateNote('error', content.substring(6, content.length))
  }
  else if (lastAction == 'silent_save')
  {
  	
  }
  else if ( lastAction == 'dirsize')
  {
  	document.getElementById('Size'+lastId).innerHTML = content;
  }
  else if ( lastAction == 'city')
  {
  	document.getElementById('city').innerHTML = content;
  }
  else if ( lastAction == 'check')
  {
  	document.getElementById(lastActionName).style.display = '';
  	document.getElementById(lastActionName).innerHTML = content;
    window.nosubmit = false;
  }
  else if (lastAction == 'save_row')
  {
    tr = document.getElementById('Rec'+lastId);
    tr.id = 'Rec' + newId;
    try {
      tr.setAttribute('id','Rec' + newId)
    } catch(e) {}
    i = 0;
    for(j=0; j<tr.childNodes.length; j++)
    {
      td = tr.childNodes[j];
      if (!/td/i.test(td.tagName)) continue;
      if (oeConfigButt[i] == 'id')
      {
        td.innerHTML = '<input type="checkbox" name="id[]" value="' + newId + '" />';
      }
      if (oeConfigField[i])
      {
        td.innerHTML = document.frm.elements[oeConfigField[i] + '[' + lastId + ']'].value;
      }
      if (oeConfigButt[i] == 'edit')
      {
        td.innerHTML = '<img src="../images/icon/edit.gif" border="0" alt="" onclick="edit_row(' + newId + ')" />';
      }
      if (oeConfigButt[i] == 'delete')
      {
        td.innerHTML = '<img src="../images/icon/delete.gif" border="0" alt="" onclick="if (confirm(\''+__('Do you really want to delete this?')+'\')) do_action(\'delete\', ' + newId + ')" />';
      }
      if (oeConfigButt[i] == 'status' && newId != lastId)
      {
        td.innerHTML = '<img src="../images/icon/plus.gif" border="0" alt="" onclick="do_action(\'status\', ' + newId + ', 0)" />';
      }
	  if (oeConfigButt[i] == 'sub_send' && newId != lastId)
      {
        td.innerHTML = '<img src="../images/icon/plus.gif" border="0" alt="" onclick="do_action(\'sub_send\', ' + newId + ', 0)" />';
      }
      i++;
    }
    oeNumRows--;
    if (oeNumRows == 0) new_row();
  }
  else
  {
    ids = lastId.split(',');
    switch (lastAction)
    {
      case 'delete':
        for(i=0; i<ids.length; i++)
        {
          if (ok) rowRemove(ids[i]);
        } 
        try {
          document.getElementById('int2').innerHTML -= ids.length;
          document.getElementById('int3').innerHTML -= ids.length;
          if (document.getElementById('int2').innerHTML == '0') document.getElementById('int1').innerHTML = '0';
        } catch (e) {}
      break;
      case 'status':
        for(i=0; i<ids.length; i++)
        {
          if (ok) rowStatus(ids[i], lastActionName, lastVal);
        } 
      break;
	  case 'sub_send':
        for(i=0; i<ids.length; i++)
        {
          if (ok) rowStatus(ids[i], lastActionName, lastVal);
        } 
      break;
      case 'category':
        for(i=0; i<ids.length; i++)
        {
          if (ok) rowCategory(ids[i], lastActionName, lastVal);
        } 
      break;
    }
  }
  lastAction = null;
  lastActionName = null;
  lastVal = null;
  lastId = null;
}
function start_search()
{
  if(document.frm.search_it.value!='') { lastAction='check'; lastActionName='check'; document.getElementById('actionFrame').src = 'su_tag.php?action=check&search=' + document.frm.search_it.value; }
}
function hasDisabledParents(id)
{
  el = document.getElementById(id);
  if (!el)
  {
  	return true;
  }
  if (el.style && el.style.display == 'none') return true;
  while (el && el.parentNode)
  {
    el = el.parentNode;
    if (el && el.style && el.style.display == 'none') return true;
  }
  return false;
}
function focusElement(el)
{
  if (typeof el == 'string') el = document.getElementById(id);
  if (!el)
  {
  	return true;
  }
  el_ = el;
  while (el && el.parentNode)
  {
    el = el.parentNode;
    if (el && el.style && el.style.display == 'none' && el.id && el.id.substring(0, 3) == 'Tab')
    {
      changeTab(el.id.substring(3, el.id.length));
      break;
    }
  }
  try {
  el_.focus();
  } catch (e) {}
}
function normal_save()
{
  document.frm.target = '_self';
}
function silent_save()
{
  lastAction = 'silent_save';
  document.frm.target = 'actionFrame';
}
function generate_alias()
{
  str = document.frm.elements['name'].value;
  str = translit(str);
  str = str.toLowerCase();
  str = str.replace(/^[^a-zA-Z01-9]+/g, '');
  str = str.replace(/[^a-zA-Z01-9]+$/g, '');
  str = str.replace(/[^a-zA-Z01-9]+/g, '-');
  document.frm.elements['alias'].value = str;
}
function translit(str)
{
  repl = {
    'À' : 'A',
    'Á' : 'B',
    'Â' : 'V',
    'Ã' : 'H',
    '¥' : 'G',
    'Ä' : 'D',
    'Å' : 'E',
    '¨' : 'Jo',
    'ª' : 'Je',
    'Æ' : 'Zh',
    'Ç' : 'Z',
    'È' : 'Y',
    '²' : 'I',
    '¯' : 'Ji',
    'É' : 'Y',
    'Ê' : 'K',
    'Ë' : 'L',
    'Ì' : 'M',
    'Í' : 'N',
    'Î' : 'O',
    'Ï' : 'P',
    'Ð' : 'R',
    'Ñ' : 'S',
    'Ò' : 'T',
    'Ó' : 'U',
    'Ô' : 'F',
    'Õ' : 'Kh',
    'Ö' : 'Ts',
    '×' : 'Ch',
    'Ø' : 'Sh',
    'Ù' : 'Shch',
    'Ý' : 'E',
    'Þ' : 'Ju',
    'ß' : 'Ja',
    'Û' : 'Y',
    'Ü' : '‘',
    'Ú' : '‘',
    'à' : 'a',
    'á' : 'b',
    'â' : 'v',
    'ã' : 'h',
    '´' : 'g',
    'ä' : 'd',
    'å' : 'e',
    '¸' : 'jo',
    'º' : 'je',
    'æ' : 'zh',
    'ç' : 'z',
    'è' : 'y',
    '³' : 'i',
    '¿' : 'ji',
    'é' : 'y',
    'ê' : 'k',
    'ë' : 'l',
    'ì' : 'm',
    'í' : 'n',
    'î' : 'o',
    'ï' : 'p',
    'ð' : 'r',
    'ñ' : 's',
    'ò' : 't',
    'ó' : 'u',
    'ô' : 'f',
    'õ' : 'kh',
    'ö' : 'ts',
    '÷' : 'ch',
    'ø' : 'sh',
    'ù' : 'shch',
    'ý' : 'e',
    'þ' : 'ju',
    'ÿ' : 'ja',
    'û' : 'y',
    'ü' : '‘',
    'ú' : '‘'
  }
  for (i in repl)
  {
    str = str.replace(i, repl[i], 'g');
  }
  return str;
}
function block_action(action, id, el2)
{
  switch (action)
  {
    case 'status':
      document.getElementById('tr_bl_' + id).className = el2.checked ? '' : 'diz_tr';
    break;
    case 'side':
      el = document.frm.elements['data[action][' + id + ']'];
      el.value = 1 - el.value;
      el2.src = '../images/icon/db_' + ((el.value == 1) ? 'last' : 'first') + '.gif';
    break;
    default:
  }
}
function key_enter(event)
{
  key = event.charCode ? event.charCode : event.keyCode;
  if (key==13)
  {
    window.nosubmit = true;
    start_search();
  }
}
function loadCountry(el)
{
  lastAction = 'city';
  if (el.selectedIndex == 0)
  {
    document.getElementById('tr_city_new').style.display = 'none';
    document.getElementById('tr_city_sel').style.display = 'none';
  }
  else
  {
    document.getElementById('tr_city_sel').style.display = '';
    document.getElementById('tr_city_new').style.display = '';
    document.getElementById('actionFrame').src = 'su_article_edit.php?action=check&id=' + el.options[el.selectedIndex].value;
  }
}
function loadCity(el)
{
  document.getElementById('tr_city_new').style.display = (el.selectedIndex == 0) ? '' : 'none';
}
var NS4 = (navigator.appName == "Netscape" && parseInt(navigator.appVersion) < 5);

function addOption(theSel, theText, theValue)
{
  var newOpt = new Option(theText, theValue);
  var selLength = theSel.length;
  theSel.options[selLength] = newOpt;
}

function deleteOption(theSel, theIndex)
{ 
  var selLength = theSel.length;
  if(selLength>0)
  {
    theSel.options[theIndex] = null;
  }
}

function moveOptions(theSelFrom, theSelTo, theSel, theEl)
{
  
  var selLength = theSelFrom.length;
  var selectedText = new Array();
  var selectedValues = new Array();
  var selectedCount = 0;
  
  var i;
  
  for(i=selLength-1; i>=0; i--)
  {
    if(theSelFrom.options[i].selected)
    {
      selectedText[selectedCount] = theSelFrom.options[i].text;
      selectedValues[selectedCount] = theSelFrom.options[i].value;
      deleteOption(theSelFrom, i);
      selectedCount++;
    }
  }
  
  for(i=selectedCount-1; i>=0; i--)
  {
    addOption(theSelTo, selectedText[i], selectedValues[i]);
  }
  
  str = '';
  for (i=0; i<theSel.options.length; i++)
  {
    if (str!='') str = str + ', ';
    str = str + theSel.options[i].value;
  }
  theEl.value = str;
}
function order_refresh()
{
  var fr = document.getElementById('order_alert');
  if (fr)
  {
    fr.src = 'su_order_alert.php?tm=' + Math.random();
  }
}
window.setInterval('order_refresh()', 60*1000);
