// 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 = '.delfi.lt';

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 domain, no expire, so it's session cookie
	document.cookie = name + 's=1';
}

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

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

	// better way detecting cookies would be
	// http://www.rgagnon.com/jsdetails/js-0092.html
	if (a == '') {
		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;


