// For submenu

opera = (navigator.userAgent.indexOf('Opera') >= 0)? true : false;
ie = (document.all && !opera)? true : false;
dom = (document.getElementById && !ie && !opera)? true : false;

var expiration = new Date();
expiration.setTime(expiration.getTime() + 3600 * 24 * 365);


function showtranscript(elemId,displayValue) {
  if (dom) {
    if (displayValue) {
      document.getElementById(elemId).style.display = displayValue;
      return 0;
    }

    if (document.getElementById(elemId).style.display == "none") {
      document.getElementById(elemId).style.display = "block";
    } else if (document.getElementById(elemId).style.display == "block") {
      document.getElementById(elemId).style.display = "none";
    } 
  } else if (ie) {
    if (displayValue) {
      document.all[elemId].style.display =  displayValue;
      return 0;
    }

    if (document.all[elemId].style.display == "block") {
      document.all[elemId].style.display = "none";
    } else if (document.all[elemId].style.display == "none") {
      document.all[elemId].style.display = "block";
    }

  }
}

function display(cookie_name, id) {
  var template_category_cookie;

  template_category_cookie = GetCookie(cookie_name);

  if (template_category_cookie) {
    SetCookie(cookie_name, "1", expiration, "", "","") 
      showtranscript(id, 'block');
  } else {
    SetCookie(cookie_name, "", expiration, "", "","") 
      showtranscript(id, 'none');
  }

  return true;                            
}


function onCookieChange(cookie_name, id) {
  if (dom) {
    if (document.getElementById(id).style.display == "none") {
      SetCookie(cookie_name, "", expiration, "", "","") 
    } else if (document.getElementById(id).style.display == "block") {
      SetCookie(cookie_name, "1", expiration, "", "","") 
    } 
  } else if (ie) {
    if (document.all[id].style.display == "block") {
      SetCookie(cookie_name, "1", expiration, "", "","") 
    } else if (document.all[id].style.display == "none") {
      SetCookie(cookie_name, "", expiration, "", "","") 
    }
  }
}


function SetCookie(name, value, expires, path, domain, secure) { 
  var mycookie = name + "=" + escape(value);
  var myexpires = new Date();
  myexpires.setTime(myexpires.getTime() + 5000);
  mycookie = mycookie + "; myexpires=" + myexpires.toGMTString();
  document.cookie = mycookie;
}


function GetCookie(name) { 
  var arg = name + "="; 
  var alen = arg.length; 
  var clen = document.cookie.length; 
  var i = 0; 

  while (i < clen) { 
    var j = i + alen; 
    if (document.cookie.substring(i, j) == arg)  
      return getCookieVal (j); 
    i = document.cookie.indexOf(" ", i) + 1; 
    if (i == 0) 
      break; 
  }

  return null; 
} 


function getCookieVal (offset) { 
  var endstr = document.cookie.indexOf (";", offset); 
  if (endstr == -1) 
    endstr = document.cookie.length; 
  return unescape(document.cookie.substring(offset, endstr)); 
} 

function show_answer(id, arr_id) {
  if (document.getElementById(id).style.display == "") {
    document.getElementById(id).style.display = "block";
  } else if (document.getElementById(id).style.display == "none") {
    document.getElementById(id).style.display = "block";
  } else if (document.getElementById(id).style.display == "block") {
    document.getElementById(id).style.display = "none";
  }
}

function showobj(id, arr_id) {
  if (document.getElementById(id).style.display == "") {
    document.getElementById(id).style.display = "block";
  } else if (document.getElementById(id).style.display == "none") {
    document.getElementById(id).style.display = "block";
    //document.getElementById(arr_id).className = "arr1o";
  } else if (document.getElementById(id).style.display == "block") {
    document.getElementById(id).style.display = "none";
    //document.getElementById(arr_id).className = "arr1c";
  }
/*
  alert(document.getElementById(arr_id).className);
  if (document.getElementById(arr_id).className != "arr1o") {
    document.getElementById(arr_id).className = "arr1o";
  } else {
    document.getElementById(arr_id).className = "arr1c";
  }
*/
}

function showimage(path, width, height) {
  if (width == 0 || height == 0) {
    alert("Картинка не назначена");
    return false;
  }
  sb = "auto";
  width += 30;
  if (width < 600) {
    width = 600;
    sb = "no";
  }
  if (width > 1000) {
    width = 1000;
    sb = "yes";
  }
  height += 140;
  if (height < 320) {
    height = 320;
    sb = "no";
  }
  if (height > 650) {
    height = 650;
    sb = "yes";
  }
  window.open(path, 'imagewindow', 'left=70,top=20,height=' + height + ',width=' + width + ',menubar=no,resizable=yes,status=no,scrollbars=' + sb);
}


function check_search_form(form, lang) {
	if (form.str.value.length < 3) {
    if (lang == "ru" || lang == "rus") {
      alert("Введите слово не короче 3 символов!");
    } else {
      alert("Please enter keyword 3 characters or more!");
    }
    return false;
  } else {
    return true;
  }
}


function searchclear() {
	if ((document.getElementById('topsearch').value =='Поиск по сайту...') || (document.getElementById('topsearch').value =='Search on this site...')) {
    document.getElementById('topsearch').value = '';
  }
}


function highlight(id, level) {
  for (i = 0; i <= topic_ids.length - 1; i++) {
    document.getElementById("bg_" + topic_ids[i]).className = "bgc";
    var c = document.getElementById("arr_" + topic_ids[i]).className;
    if (c == "arr1o" || c == "arr1s") {
      document.getElementById("arr_" + topic_ids[i]).className = "arr1c";
    }
    if (c == "arr2o" || c == "arr2s") {
      document.getElementById("arr_" + topic_ids[i]).className = "arr2c";
    }
    if (c == "arr3o" || c == "arr3s") {
      document.getElementById("arr_" + topic_ids[i]).className = "arr3c";
    }
  }
  document.getElementById("bg_" + id).className = "bga";
  document.getElementById("arr_" + id).className = "arr" + level + "o";
}


function close_first_level(do_it) {
  if (do_it) {
    for (i = 0; i <= topic_ids.length - 1; i++) {
      document.getElementById("menu_" + topic_ids[i]).style.display = "none";
      document.getElementById("bg_" + topic_ids[i]).className = "bgc";
      var c = document.getElementById("arr_" + topic_ids[i]).className;
      if (c == "arr1o" || c == "arr1s") {
        document.getElementById("arr_" + topic_ids[i]).className = "arr1c";
      }
      if (c == "arr2o" || c == "arr2s") {
        document.getElementById("arr_" + topic_ids[i]).className = "arr2c";
      }
    }
  }
}
