function $(id) {
  return document.getElementById(id);
}

function Show(id) {
  if ($(id)) $(id).style.display = '';
}

function Hide(id) {
  if ($(id)) $(id).style.display = 'none';
}

function ovMenu(num) {
  Show('Menu1');
}

String.prototype.trim = new Function("return this.replace(/^\\s+|\\s+$/g,'')");


function setCookie (name, value, path) {
  if (path == undefined) path=""; else path="; path="+path;
  var expDate=new Date();
  expDate.setTime(expDate.getTime()+2592000000);
  document.cookie=name+"="+escape(value)+"; expires="+expDate.toGMTString()+path;
}

function HideFlash() {
  if ($('FlashTB').style.display == 'none') {
    Show('FlashTB');
    Hide('FlashTB2');
    $('FlashTB3').src = '/img/-.gif';

    $('hdline').style.top = 484;
    $('hdimg').src = '/img/arr_top.gif';
    $('hdimg').alt = 'Скрыть флеш';
    setCookie('hdfl', 0, '/');
  } else {
    Hide('FlashTB');
    Show('FlashTB2');
    $('FlashTB3').src = '/img/god8.gif';

    $('hdline').style.top = 210;
    $('hdimg').src = '/img/arr_bottom.gif';
    $('hdimg').alt = 'Отобразить флеш';
    setCookie('hdfl', 1, '/');
  }

  return false;
}

function mov(obj) {
  if (obj.className == 'ac') return false;
  if (obj.src.indexOf('menu/_') == -1)
    obj.src = obj.src.replace('menu/', 'menu/_');
}

function mou(obj) {
  if (obj.className == 'ac') return false;
  if (obj.src.indexOf('menu/_') > -1)
    obj.src = obj.src.replace('menu/_', 'menu/');
}


var lastmenu = null;

function Alpha(obj, num) {
  num = num+0.1;
  $(obj).style.opacity=num;
  $(obj).style.filter='alpha(opacity='+(num*100)+')';
  if (num < 1)
    setTimeout('Alpha("'+obj+'",'+num+')', 30);
}

function expand(num) {
  if (!$('MM'+num)) return false;

  if ($('Sub'+num).style.display == 'none') {
    if (lastmenu) {
      Hide('Sub'+lastmenu);
      $('MM'+lastmenu).className = '';
      mou($('MM'+lastmenu));
    }  
    lastmenu = num;
    $('MM'+num).className = 'ac';

    $('Sub'+num).style.opacity=0.1;
    $('Sub'+num).style.filter="alpha(opacity=10)";
    Show('Sub'+num);
    setTimeout('Alpha("Sub'+num+'",0.1)', 30);
  } else {
    Hide('Sub'+num);
    $('MM'+num).className = '';
    mou($('MM'+num));
    lastmenu = null;
  }  

  return false;
}

function InitPages() {
  document.onkeydown = KeyHook;
}

function KeyHook(e) {
  var code;
  if (!e) var e = window.event;
  if (e.keyCode) code = e.keyCode;
    else if (e.which) code = e.which;

  if ((code == 37) && (e.ctrlKey == true)) {
    var dest = document.getElementById('prev');
    if (dest) location.href = dest.href;
  } else if ((code == 39) && (e.ctrlKey == true)) {
    var dest = document.getElementById('next');
    if (dest) location.href = dest.href;
  }
}


function previm(obj, x, y) {
  var s = obj.src.replace('/x_', '/m_');
  s = s.replace('.png', '.jpg');

  document.getElementById('CatMfirst').rel = 'lightbox[cat]';
  document.getElementById('CatMlink').rel = '';
               
  if (document.getElementById('CatMimg').src != s) {
    document.getElementById('CatMimg').src = s;     
    document.getElementById('CatMimg').width = x;
    document.getElementById('CatMimg').height = y;
  }  
}  
               
function catover() {
  if (document.getElementById('CatMfirst')) {
    document.getElementById('CatMfirst').rel = '';
    document.getElementById('CatMlink').rel = 'lightbox[cat]';
  }  
}

function removeChildrenRecursively(node)
{
  if (!node) return;
  while (node.hasChildNodes()) {
    removeChildrenRecursively(node.firstChild);
    node.removeChild(node.firstChild);
  }
}

prdelta = null;
sizes = null;
function ch_options(obj) {
    var aa = $$('td.smallfoto>a');
    for (var i = 0; i < aa.length; i++) {
        if (aa[i].readAttribute('title').toUpperCase() == obj.value.toUpperCase()) {
            aa[i].down('img').onmouseover();
            break;
        }
    }
  if (prdelta != null && prdelta[obj.value]) {
    document.getElementById('MPRSP').innerHTML = '<div><div>' + prdelta[obj.value] + '</div></div>';
  }
  if (sizes != null && sizes[obj.selectedIndex]) {
	removeChildrenRecursively(document.getElementById('selsize'));
	if (sizes[obj.selectedIndex].length > 1 || sizes[obj.selectedIndex][0] != "") {
    for (var i = 0; i < sizes[obj.selectedIndex].length; i++) {
		option = document.createElement('option');
		option.setAttribute('value', sizes[obj.selectedIndex][i]);
		optiontext = document.createTextNode(sizes[obj.selectedIndex][i]);
		option.appendChild(optiontext);
		document.getElementById('selsize').appendChild(option);
    }
	document.getElementById('sizepanel').style.display = 'inline';
	}
	else
		document.getElementById('sizepanel').style.display = 'none';
  }
}

var movxx = 0;
var movyy = 1;
function imov(obj, str) {
  movxx++;
  if (movxx < 20) return false;
            
  var x = str.split(',');
  obj.src = '/image/catalog/s_'+x[movyy]+'.jpg';
  
  movyy++;
  if (movyy >= x.length) movyy = 0;
  movxx = 0;
}

function searchs(frm) {
  frm.search.value = frm.search.value.trim();
  if (frm.search.value.length < 3 ) { alert('Строка поиска должна содержать минимум 3 символа'); return false; }
  return true;
}


