// promoDJ.ru
//
// partially (c) by sergey korowkin, 2005.
//
// http://korowkin.ru

function Debug(s)
 {
  d = document.getElementById('debugger');
  d.innerHTML = d.innerHTML + s + ' ';
 }

// just the popup

function SimplePopup(swidth, sheight, title, url)
 {
  width = swidth + 16;
  height = sheight + 16;

  var left = Math.round((document.body.clientWidth - width) / 2);
  var top = Math.round((document.body.clientHeight - height) / 2);

  var win = window.open('about:blank', 
                        '', 
                        'toolbar=no,' +
                        'scrollbars=no,' + 
                        'status=no,' +
                        'height=' + height + ',' + 
                        'width=' + width + ',' + 
                        'top=' + top + ',' + 
                        'left=' + left);

  win.document.write('<title>' + title + '</title>' +
                     '<body topmargin=0 leftmargin=0>' +
                     '<table width=100% height=100% border=0 cellspacing=0 cellpaddin=0>' +
                     '<td align=center valign=middle>' +
                     '<a href="javascript:window.close();"><img src="' + url + '" width=' + swidth + ' height=' + sheight + ' border=0 alt="' + title + '"></a>' +
                     '</td>' +
                     '</table>' +
                     '</body>');

  win.focus();
 }

// gods finger

function TheyKnowWhatIsWhat(kind, id)
 {
  width = 600;
  height = 500;

  var left = Math.round((document.body.clientWidth - width) / 2);
  var top = Math.round((document.body.clientHeight - height) / 2);

  var win = window.open('http://promodj.ru/godsfinger.html?kind=' + kind + '&id=' + id, 
                        '', 
                        'toolbar=no,' +
                        'scrollbars=auto,' + 
                        'status=no,' +
                        'height=' + height + ',' + 
                        'width=' + width + ',' + 
                        'top=' + top + ',' + 
                        'left=' + left);

  win.focus();
 }

// gallery worker

function OpenGalleryFoto(userID, galleryID, fotoID, width, height)
 {
  width = width + 50;
  height = height + 80;

  if (height > 700)
   height = 700;

  var left = Math.round((document.body.clientWidth - width) / 2);
  var top = Math.round((document.body.clientHeight - height) / 2);

  var win = window.open('/gallery/view/' + userID + '/' + galleryID + '/' + fotoID + '/',
                        'pdjfoto', 
                        'toolbar=no,' +
                        'scrollbars=yes,' +
                        'status=no,' +
                        'height=' + height + ',' +
                        'width=' + width + ',' + 
                        'top=' + top + ',' +
                        'left=' + left);

  win.focus();
 }

// objects finder

function findObj(id)
 {
  if (document.all)
   return document.all[id];
  else
  return document.getElementById(id);
 }

// photos manager

function PM_MoveUp()
 {
  po = findObj('PhotosManagerOrder');

  if (po.selectedIndex > 0) 
   {
    var s = po.selectedIndex;
    var option = new Object();

    option.text = po.options[s].text;
    option.value = po.options[s].value;

    po.options[s].text = po.options[s - 1].text;
    po.options[s].value = po.options[s - 1].value;

    po.options[s - 1].text = option.text;
    po.options[s - 1].value = option.value;

    po.selectedIndex = s - 1;

    PM_SetContainer();
   }
 }

function PM_MoveDown()
 {
  po = findObj('PhotosManagerOrder');

  if ((po.selectedIndex < po.options.length - 1) && (po.selectedIndex >= 0))
   {
    var s = po.selectedIndex;
    var option = new Object();

    option.text = po.options[s].text;
    option.value = po.options[s].value;

    po.options[s].text = po.options[s + 1].text;
    po.options[s].value = po.options[s + 1].value;

    po.options[s + 1].text = option.text;
    po.options[s + 1].value = option.value;

    po.selectedIndex = s + 1;

    PM_SetContainer();
   }
 }

function PM_SetContainer()
 {
  cont = findObj('PhotosManagerOrder');

  if (cont.length > 0)
   for (var i = 0; i < cont.length; i++) 
    {
     qc = findObj('data' + i);

     if (qc)
      qc.value = cont.options[i].value;
    }
 }

// dynamic selects supplement

var exchangerTarget = false;
var exchangerCallAfter = false;

function ExchangerLoaded()
 {
  target = document.getElementById(exchangerTarget);
  target.length = 0;

  x = document.getElementById("exchangerd").innerHTML.split("<ITEM>");

  for (k = 0; k < x.length - 1; k++)
   { 
    y = x[k].split("<KEY>");

    o = new Option();
    o.text = y[1];
    o.value = y[0];
    target.options[target.length] = o;
   }

  if (exchangerCallAfter)
   eval(exchangerCallAfter);
 }

function UpdateControl(source, target, url, callafter)
 {
  source = document.getElementById(source);

  exchangerTarget = target;
  exchangerCallAfter = callafter;

  url = url + "&value=" + escape(source.value);
  url = url + "&rand=" + Math.random() * 280883;

  ex = document.getElementById("exchanger");
  ex.innerHTML = "<iframe width=1 height=1 id=\"exchangeri\" src=\"" + url + "\" frameborder=0></iframe>";

  document.ExchangerLoaded = ExchangerLoaded;
 }

function UpdateCitySelect()
 {
  UpdateControl('countryID', 'cityID', '/dsgateway.html?mode=cities', 'UpdateDistrictSelect()');
 }

function UpdateDistrictSelect()
 {
  UpdateControl('cityID', 'districtID', '/dsgateway.html?mode=districts', false);
 }

// promoDJ main menu
// (based on www.juno.co.uk dropdown concept: RESPECT! :)

var hidetimeout = showtimeout = currentmenu = '';

function HideMenuDelayed(id)
 {
  window.clearTimeout(showtimeout);
  hidetimeout = window.setTimeout("HideMenu('" + id + "')", 500);
 }

function HideMenu(id)
 {
  i = document.getElementById(id);
  i.style.visibility = 'hidden';
 }

function ShowMenuDelayed(id)
 {
  if (currentmenu == id)
   window.clearTimeout(hidetimeout);

  showtimeout = setTimeout("ShowMenu('" + id + "')", 250);
 }

function ShowMenu(id) 
 {
  window.clearTimeout(showtimeout);
  window.clearTimeout(hidetimeout);

  currentmenu = id;

  k = 0;

  while (true)
   {
    if (!(d = document.getElementById(mid = 'mm' + k)))
     break

    d.style.visibility = mid == id ? 'visible' : 'hidden';

    k++;
   }
 }
