var userAgent = navigator.userAgent.toLowerCase();
var is_ns = (userAgent.indexOf("netscape") >= 0);
var is_op = (userAgent.indexOf("opera") >= 0);
var is_ie = ((userAgent.indexOf("msie") >= 0) && !is_op);

function findDOM(objectID, withStyle) {
  var obj = null;
  if (document.getElementById) {
    obj = document.getElementById(objectID);
  } else if (document.all) {
    obj = document.all[objectID];
  }
  if ((withStyle == 1) && (obj != null) && obj.style) {
    obj = obj.style;
  }
  return(obj);
}

function getStyle(objectID, styleName) {
  if ((dom = findDOM(objectID, 1)) != null) return(dom[styleName]);
  return(null);
}

function changeStyle(objectID, styleName, newVal) {
  if ((dom = findDOM(objectID, 1)) != null) dom[styleName] = newVal;
}

function findHeight(objectID) {
  if ((dom = findDOM(objectID, 0)) != null) return(dom.offsetHeight);
  return(null);
}

function findWidth(objectID) {
  if ((dom = findDOM(objectID, 0)) != null) return(dom.offsetWidth);
  return(null);
}

function findLivePageHeight() {
  if (window.innerHeight != null) return(window.innerHeight);
  if (document.body.clientHeight) return(document.body.clientHeight);
  return(null);
}

function simplePreloadGif() { 
  var args = simplePreloadGif.arguments;
  document.imageArray = new Array(args.length);
  document.imageNames = new Array(args.length);
  for(var i = 0; i < args.length; i++) {
		document.imageNames[i] = args[i];
    document.imageArray[i] = new Image;
    document.imageArray[i].src = "/images/gif/" + args[i] + ".gif";
  }
}

function getGifName(img) {
	var s = img.src;
	if ((i = s.lastIndexOf("/")) != -1) s = s.substring(i + 1);
	return(((i = s.lastIndexOf("_")) != -1) ? s = s.substring(0, i):s.substring(0, s.length - 4));
}

function switchGifAnchor(img, st) {
	// 0 - enable, 1 - hover, 2 - disable
	var s = getGifName(img);
	if (1 == st)
		s = s + "_h"
	else
		if (2 == st)
			s = s + "_d";
  for (var i = 0; i < document.imageNames.length; i++)
		if (document.imageNames[i] == s) {
			img.src = document.imageArray[i].src;
			if ("" == img.parentNode.className) {
				if (2 == st) img.parentNode.className = "a_disable";
			}
			else {
				if (2 != st) img.parentNode.className = "";
			}
			break;
		}
}

function switchImage(img, st) {
	// 0 - out, 1 - hover
  if (document.images && img.parentNode && img.parentNode.className != "a_disable") switchGifAnchor(img, st);
}

function disableGifAnchors() {
  var args = disableGifAnchors.arguments;
  for (var i = 0; i < args.length; i++)
	  if ((img = findDOM(args[i], 0)) != null) switchGifAnchor(img, 2);
}

function enableGifAnchors() {
  var args = enableGifAnchors.arguments;
  for (var i = 0; i < args.length; i++)
	  if ((img = findDOM(args[i], 0)) != null) switchGifAnchor(img, 0);
}

function clearInner(id) {
	if ((obj = findDOM(id, 0)) && obj.innerHTML) obj.innerHTML = "&nbsp;";
}
//------------------------------------------------------------------------------
// paziņojuma izdošana par kaut ko...
function Wait(id,msg){
   if ((obj = findDOM(id, 0)) && obj.innerHTML) obj.innerHTML = msg;
}
