function findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function setTextOfLayer(objName,x,newText) { //v4.01
  if ((obj=findObj(objName))!=null) with (obj)
    if (document.layers) {document.write(unescape(newText)); document.close();}
    else innerHTML = unescape(newText);
}

function showhide(id){ 
	if (document.getElementById){ 
		obj = document.getElementById(id); 
		if (obj.style.display == "none"){ 
			obj.style.display = ""; 
		} else { 
			obj.style.display = "none"; 
		} 
	} 
} 

// browser detection

var agt = navigator.userAgent.toLowerCase();
var major = parseInt(navigator.appVersion);

macos = (agt.indexOf('mac') != -1);

nav  = ((agt.indexOf('mozilla') != -1) && (agt.indexOf('spoofer') == -1)
	&& (agt.indexOf('compatible') == -1) && (agt.indexOf('opera') == -1)
	&& (agt.indexOf('webtv') == -1) && (agt.indexOf('hotjava') == -1));
nav4 = nav && (major >= 4);
opera = (agt.indexOf('opera') != -1);

ie = ((agt.indexOf('msie') != -1) && (agt.indexOf('opera') == -1));
ie3 = (ie && (major < 4));
ie4 = (ie && (major == 4) && (agt.indexOf('msie 5') == -1) && (agt.indexOf('msie 6') == -1));

konq = (agt.indexOf('konqueror') != -1);

// array events function pointers to run on page load event
var dhtmlRunArray = new Array();

// array of settings
var dhtmlSettings = new Array();

function exists(a) {
	return typeof(a) != 'undefined';
}

// this gets ran on window.onLoad event
function dhtmlHandler() {
	for (var i = 0; i < dhtmlRunArray.length; i++) {
		eval(dhtmlRunArray[i] + '()');
	}
}

// add method to run when page has loaded
function dhtmlPush(what) {
	dhtmlRunArray[dhtmlRunArray.length] = what;
}

function dhtmlSet(which, what) {
//	if (typeof(dhtmlSettings[which]) == 'undefined') {
	if (!exists(dhtmlSettings[which])) {
		dhtmlSettings[which] = what;
	}
}

function dhtmlGet(what) {
	return dhtmlSettings[what];
}

// cookie-related
var dhtmlTheDomain = '.spnavitas.ee';

function dhtmlSetCook(name, t, exp) {
	var d = new Date();
	d.setTime(d.getTime() + exp * 60 * 1000);

	var c = name + '=t='+ t + '; expires=' + d.toGMTString() + '; domain=' + dhtmlTheDomain + '; path=/';

	document.cookie = c;

	// PUs by pu, note: no expire, so it's session cookie
	document.cookie = name + 's=1';
}

var DHTML_NO_COOKIES = -1;
var DHTML_IGNORE_COOKIES = -2;

// checks if browser has cookies disabled by setting tmp cookie and querying it.
// ideas from: http://www.rgagnon.com/jsdetails/js-0092.html
function dhtmlCookiesAvail() {
	var t = 'dhtmlQuery=';
	var c = t + '1' + '; path=/; domain=' + dhtmlTheDomain + '; path=/';
	document.cookie = c;
	if (document.cookie.indexOf(t, 0) < 0) {
		return false;
	}

	// clear that cookie
	var d = new Date();
	d.setTime(d.getTime() - 1);
	document.cookie = c + '; expires=' + d.toGMTString();
	return true;
}

function dhtmlGetCook(x) {
	var i,j,a,b,s,e,d,f;
	a = document.cookie;

	// this assumes we always have dcid cookie
	// and our test could fail if user has rejected cookies from t.delfi.xx

	if (a == '') {
		// no cookies. disabled or just none?
		if (!dhtmlCookiesAvail()) {
			return DHTML_NO_COOKIES;
		}
	}

	s = a.indexOf(x + '=');
	if (s == -1) {
		return false;
	}
	s += x.length+1;
	e = a.indexOf(';',s);
	if (e == -1) {
		e = a.length;
	}
	return a.substring(s,e);
}

// returns value for 't' from query-string alike string
function dhtmlGetCount(c) {
	c = c.split('&');
	for (i = 0; i < c.length; i++) {
		d = c[i].split('=');
		if (d == "t") {
			last;
		}
	}
	return d[1];
}

window.onload = dhtmlHandler;


