//
//  (ñ) SiteLeader, 2005-2009 || http://www.siteleader.ru
//

var isMSIE = (navigator.userAgent && (navigator.userAgent.indexOf("MSIE") >= 0) && (navigator.appVersion.indexOf("Win") != -1)) ? 1 : 0;
var getEl = function(id) { return document.getElementById(id) }

window.$$ = function() {
  var els = new Array();
  for (var i = 0; i < arguments.length; i++) {
    var el = arguments[i];
    if (typeof el == 'string') el = document.getElementById(el);
    if (arguments.length == 1) return el;
    els.push(el);
  }
  return els;
}

function get_cookie(name) {
  var start = document.cookie.indexOf(name + "=");
  var len = start + name.length + 1;
  if ((!start) && (name != document.cookie.substring(0, name.length))) return null;
  if (start == -1) return null;
  var end = document.cookie.indexOf(';', len);
  if (end == -1) end = document.cookie.length;
  return unescape(document.cookie.substring(len, end));
}
 
function set_cookie(name, value, expires, path, domain, secure) {
  var today = new Date();
  today.setTime(today.getTime());
  if (expires) expires = expires * 1000 * 60 * 60 * 24;
  var expires_date = new Date(today.getTime() + expires);
  document.cookie = name + '=' + escape(value) +
    (expires ? ';expires=' + expires_date.toGMTString() : '') + //expires.toGMTString()
    (path ? ';path=' + path : '') +
    (domain ? ';domain=' + domain : '') +
    (secure ? ';secure' : '');
}
 
function deleteCookie(name, path, domain) {
  if (get_cookie(name)) document.cookie = name + '=' +
    (path ? ';path=' + path : '') +
    (domain ? ';domain=' + domain : '') + ';expires=Thu, 01-Jan-1970 00:00:01 GMT';
}

function js_startup() { return paint_tables() }

function js_obj_adjust(tag_name, class_name, max_width, max_height) {
  var imgs = document.getElementsByTagName(tag_name);
  for (i = 0; i < imgs.length; i++) {
    if (imgs[i].className.indexOf(class_name) != -1) {
      var rate = imgs[i].width / imgs[i].height;
      if (imgs[i].width > max_width) {
        imgs[i].width = max_width;
        imgs[i].height = max_width / rate;
      } else if (imgs[i].height > max_height) {
        imgs[i].height = max_height;
        imgs[i].width = max_height * rate;
      }
    }
  }
}

function js_adjust_me(obj, max_width, max_height) {
  if (!obj) return;
  var rate = obj.width / obj.height;
  if (obj.width > max_width) {
    obj.width = max_width;
    obj.height = max_width / rate;
  } else if (obj.height > max_height) {
    obj.height = max_height;
    obj.width = max_height * rate;
  }
}

function post_form(form_id, mode_id, mode) {
  var form = document.getElementById(form_id);
  if (!form_id) return;
  var form_mode = document.getElementById(mode_id);
  if (form_mode) form_mode.value = mode;
  form.submit();
}

function paint_tables() {
  var tbl=document.getElementsByTagName('table');
  for (i = 0; i < tbl.length; i++) {
    var lc = tbl[i].className.toLowerCase();
    if (lc.match('default'))
      for(j = 0; j < tbl[i].rows.length; j++) tbl[i].rows[j].style.backgroundColor = j & 1 ? '#ffffff' : '#efefef';
  }
  return false;
}

function paint_tables_old() {
  var tbl=document.getElementsByTagName('table');
  for (i = 0; i < tbl.length; i++) {
    if (tbl[i].id == 'zebra-0') {
      for(j = 0; j < tbl[i].rows.length; j++) tbl[i].rows[j].style.backgroundColor = j & 1 ? '#ffffff' : '#efefef';
    } else if (tbl[i].id == 'zebra-1') {
      for(j = 0; j < tbl[i].rows.length; j++) tbl[i].rows[j].style.backgroundColor = j & 1 ? '#efefef' : '#ffffff';
    }
  }
  return false;
}
