
// ---- onLoad initialisation

$(window).resize(function()
{
 $('#contentPane').width($(document).width() - 660);
 $('#logincell').height($('#logintable').height() - 20);
});


$().ready(function()
{


 $('#contentPane').width($(document).width() - 660);
 $('#logincell').height($('#logintable').height() - 20);


 $('.catalogMenu').mouseover(function()
 {
  $(this).get(0).oldbg = $(this).css('background-color');
  $(this).css('background-color', '#296DA5');
  $('a.catalogMenu', this).css('color', 'white');
 });

 $('.catalogMenu').mouseout(function()
 {
  $(this).css('background-color', $(this).get(0).oldbg);
  $(this).css('color', '#111516');
  $('a.catalogMenu', this).css('color', '#111516');
 });


  $('form').submit
  (
   function()
   {
    isFormValid = true;

    $('input.requiredFormField', this).each
    (
     function()
     {
      if (!isFormValid)
       return;

      with (this)
      {
       if (((type == 'text') || (type == 'textarea') || (type == 'password')) && (value == ''))
       {
        alert('Извините, необходимо заполнить все обязательные поля формы.');
        focus();
        isFormValid = false;
       }
      }
     }
    );

    return isFormValid;
   }
  );


});


// ---- Positioning management

// get object's position from the right of the document
function getElementPosX(obj)
{
 var left = 0;

 do
 {
  left += obj.offsetLeft;
 }
 while (obj = obj.offsetParent);

 return left;
}

// get object's position from the top of the document
function getElementPosY(obj)
{
 var top = 0;

 do
 {
  top += obj.offsetTop;
 }
 while (obj = obj.offsetParent);

 return top;
}


// ---- Menu/submenu

var submenuTimeout = null;

function showSubmenu(submenuId, parentEl)
{
 if (submenuId == null || submenuId == '')
  return false;

 self.clearTimeout(submenuTimeout);

 $('#submenu').hide();

 if (submenuCache[submenuId] != null)
 {
  var out = '';
  var numsubmenu = submenuCache[submenuId].length;

  for (i = 0; i < numsubmenu; ++i)
  {
   out +=
    '<TR><TD CLASS="submenuItem" STYLE="padding-left:18px; padding-top:6px; padding-right:18px; padding-bottom:7px;">' +
    '<A HREF="' + submenuCache[submenuId][i]["link"] + '" CLASS=' +
    ((submenuCache[submenuId][i]["id"] == activeSubmenu) ? "currentSubmenuPane" : "submenuPane") + '>' +
    submenuCache[submenuId][i]["name"] + '</A></TD></TR>\n';

   if (i < (numsubmenu - 1))
    out +=
     '<TR><TD CLASS="submenuItemDiv" STYLE="background:#D6D9E0;">' +
     '<IMG SRC="../img/empty.gif" WIDTH=148 HEIGHT=1 BORDER=0 ALT=""><BR>' +
     '</TD></TR>\n';
  }

  if (out != '')
  {
   $('#submenu').html('<TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0>' + out + '</TABLE>');

   $('#submenu').css('left', getElementPosX(parentEl) + 1);
   $('#submenu').css('top', ((isHome) ? 423 : 184));

   $('td.submenuItem').mouseover( function() { $(this).addClass('submenuHover'); clearTimeout(submenuTimeout); return true; } );
   $('td.submenuItem').mouseout( function() { $(this).removeClass('submenuHover'); hideSubmenu(); return true; } );

   $('td.submenuItemDiv').mouseover( function() { clearTimeout(submenuTimeout); return true; } );
   $('td.submenuItemDiv').mouseout( function() { hideSubmenu(); return true; } );

   $('#submenu').fadeIn('fast');
  }
 }
}

function hideSubmenu()
{
 self.clearTimeout(submenuTimeout);

 submenuTimeout =
  self.setTimeout('$(\'#submenu\').hide();', 850);
}

