function e(id) {
	return document.getElementById(id);
}

// steady js post
function sjsp(a, id) {
	e(id).value=document.documentElement.scrollTop + " "; // __REGETME__
	e(id).parentNode.action = a.href;
	e(id).parentNode.submit();
	return false;
}

function debug(o) {
	var r = "";
/*	for (var k in o) {
		r = r + "\n" + k + ": " + o[k];
	]
	alert(r);*/alert(o);
}

function qs_q(o) {
	var r = "";
	var e = /[?&](lang)=([^&]+)/g;
	var s = location.href;
	var m;
	while ((m = e.exec(s)) != null) r += (r ? "&" : "") + escape(m[1]) + "=" + escape(m[2]);
	for (var p in o) r += (r ? "&" : "") + escape(p) + "=" + escape(o[p]);
	return r ? "?" + r : "";
}

function popup(a) {
	w = 700;
	h = 600;
	s = "yes";
	if (a.target == "juk") {w = 672; h = 300; s = "no";}
	if (a.target == "vid") {w = 660; h = 500; s = "no";}
	if (a.target == "buy") {w = 580; h = 450;/* s = "no";*/}
	p = window.open(a.href, a.target, "width=" + w + ", height=" + h + ", left=100, top=110, location=no, menubar=no, scrollbars=" + s + ", toolbar=no, resizable=yes", false); // Op baigi labprāt arī norij ritjoslas
	if (p.focus) p.focus();
	return false;
}

function popup_buy_cosmos(x) {
	return popup({href: qs_q({buy: 'cosmos_' + x}), target: 'buy'});
}

function link_oc() {
	var a = document.links;
	for (i = 0; i < a.length; i++) {
		if (a[i].target == "tip" || a[i].target == "img" || a[i].target == "vid" || a[i].target == "juk" || a[i].target == "buy") {
			a[i].onclick = function() {return popup(this);};
		}
		if (a[i].className.indexOf("grptr") != -1) {
			var p = a[i];
			
			while (p && p.tagName != "TR") p = p.parentElement;
			if (p) {
//				var c = p.childNodes;
				var c = p.getElementsByTagName("TD");

				for (j = 0; j < c.length; j++) if (c[j].tagName == "TD"/* && c[j].childNodes[0].tagName != "A"*/) {
//					alert(c[j].childNodes[0].onclick);
//					alert(c[j].childNodes[0].getAttribute);
//					if (c[j].childNodes[0].getAttribute("onClick")) alert(j);
					// nu lab pagaidām neko nedarām, nav degoši TODO
				} else alert("OI");
			}
		}
	}
}

// populāras lietas, kas jādara uz onload
function commol() {
	link_oc();
}

function check_boxes(name, value) {
	var c = document.getElementsByTagName("input");
	for (var i = 0; i < c.length; i++) {
		if (c[i].name == name) c[i].checked = value;
	}
}
