
/* Brauser */
var iex	= (document.all);
var nav	= (document.layers);
var n_6	= (window.sidebar);
var old	= (navigator.appName == "Netscape" && !document.layers && !document.getElementById);
var mouse_over_event = null;

/* Objekt */
function getObject(id) {
	var object;

	if (document.getElementById) {
		object = document.getElementById(id);
	} else if (document.all) {
		object = document.all[id];
	} else {
		object = null;
	}

	return object;
}

function getWindowObject(input_id, window) {
	var object;

	if (window.document.getElementById) {
		object = window.document.getElementById(input_id);
	} else if (window.document.all) {
		object = window.document.all[input_id];
	} else {
		object = null;
	}

	return object;
}

/* Objekti sisu kirjutamine */
function writeObjectContent(object, content) {

	if (nav) {
		object.document.open();
		object.document.write(content);
		object.document.close();
	}

	if (iex || n_6) {
		object.innerHTML = content;
	}
}

/* Muuda elemendi näitamist */
function changeDisplay(id) {

	var sect = getObject('sect_'+id);

	if (sect == null) return;

	if (sect.style.display == 'none') {
		sect.style.display	= 'block';
	} else {
		sect.style.display	= 'none';
	}

}

/* Muuda elemendi klass */
function changeClass(element, newclass, timeout) {

	oldclass = element.className;
	element.className = newclass;

	if (timeout > 0) {
		/*setTimeout("changeClass(element, oldclass, 0);", timeout);*/
	}

}

/* Formi checkboxide väärtuste vastupidiseks muutmine */
function margi_vastupidiseks(array_name) {

	var next = true;
	var i = 0;

	while (next) {

		i++;
		var id = array_name + i;
		var object = getObject(id);

		if (object == null) {
			next = false;
		} else {

			if ( object.checked == true ) {
				object.checked = false;
			} else {
				object.checked = true;
			}
		}
	}
}

/* Pildi avamine suurelt uues aknas */
function BigImage(url, width, height) {

	if ( window.BigImageWin && !window.BigImageWin.closed ) {
		window.BigImageWin.close();
		window.BigImageWin = null;
	}

	var BigImageWin = new_window( url, "BigImageWin", -1, -1, width, height, 'no', 'no', 'no', 'no', 'no', 'no' );
}

/* Albumi tegeliku pildi näitamine */
function show_real_album_picture(id, width, height) {

	var url = '?action=user_album_picture&id=' + id;

	var rap = new_window(url, 'rap', -1, -1, width, height, 'no', 'yes', 'no', 'no', 'no', 'no');

	return rap;
}

/* Restrictionite näitamine */
function show_restriction(id)  {

	var input = getObject(id);

	var url = 'restriction_popup.php?result_input=' + id + '&postfix=' + input.value;

	var restriction_window = new_window(url, 'restriction', -1, -1, 500, 400, 'no', 'yes', 'no', 'no', 'no', 'no');

	return restriction_window;
}

/* Helpi näitamine */
function show_help(tunnus)  {

	var url = '?action=help_popup&id=' + tunnus;

	var help_window = new_window(url, 'help', -1, -1, 330, 200, 'no', 'yes', 'no', 'no', 'no', 'no');

	return help_window;
}

/* Kutsete põõsa näitamine */
function show_invitations_bush(type)  {

	var url = '?action=invitations_tree&type=' + type;

	var invitations_window = new_window(url, 'invitations', -1, -1, 800, 600, 'no', 'yes', 'no', 'no', 'no', 'no');

	return invitations_window;
}

/* Akna avamine javascriptiga */
function new_window(url, name, left, top, width, height, resizable, scrollbars, menubar, toolbar, locationbar, statusbar) {

	var features = '';

	if (left != -1) {
		features += 'left='+left+'';
	}

	if (top != -1) {
		features += 'top='+top+'';
	}

	features += 'width='+width+', height='+height+', resizable='+resizable+', scrollbars='+scrollbars+',menubar='+menubar+', toolbar='+toolbar+',location='+locationbar+',status='+statusbar+', alwaysRaised=yes';

	var new_window = window.open( url, name, features );

	return new_window;
}

function findPosX(obj) {
	var curleft = 0;

	if (obj.offsetParent) {
		while (obj.offsetParent) {
			curleft += obj.offsetLeft
			obj = obj.offsetParent;
		}

	} else if (obj.x)
		curleft += obj.x;

	return curleft;
}

function findPosY(obj) {
	var curtop = 0;

	if (obj.offsetParent) {
		while (obj.offsetParent) {
			curtop += obj.offsetTop
			obj = obj.offsetParent;
		}
	} else if (obj.y)
		curtop += obj.y;

	return curtop;
}

/* Soovitud lehele suunamine */
function go(url) {

	document.location.href = url;
}

/* Soovitud lehele ajalise viitega suunamine */
function goInTime(url, seconds) {

	setTimeout("go('"+url+"')", seconds * 1000);
}

function getWindowSize() {
	var myWidth = 0, myHeight = 0;

	if (typeof(window.innerWidth) == 'number') {
		//Non-IE
		myWidth = window.innerWidth;
		myHeight = window.innerHeight;
	} else if (document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)) {
		//IE 6+ in 'standards compliant mode'
		myWidth = document.documentElement.clientWidth;
		myHeight = document.documentElement.clientHeight;
	} else if (document.body && (document.body.clientWidth || document.body.clientHeight)) {
		//IE 4 compatible
		myWidth = document.body.clientWidth;
		myHeight = document.body.clientHeight;
	}
	return {w:myWidth, h:myHeight};
}

function getScrollXY() {
	var scrOfX = 0, scrOfY = 0;

	if (typeof(window.pageYOffset) == 'number') {
		//Netscape compliant
		scrOfY = window.pageYOffset;
		scrOfX = window.pageXOffset;
	} else if (document.body && (document.body.scrollLeft || document.body.scrollTop)) {
		//DOM compliant
		scrOfY = document.body.scrollTop;
		scrOfX = document.body.scrollLeft;
	} else if (document.documentElement && (document.documentElement.scrollLeft || document.documentElement.scrollTop)) {
		//IE6 standards compliant mode
		scrOfY = document.documentElement.scrollTop;
		scrOfX = document.documentElement.scrollLeft;
	}
	return {x:scrOfX, y:scrOfY};
}

function setObjectPosition( object, xposition, yposition ) {
	var window_size = getWindowSize();
	var window_width = window_size.w;
	var window_height = window_size.h;

	if ( isNaN(parseInt(xposition)) ) {

		switch (xposition) {
			case 'left':
				object.style.left		= 20;
			break;

			case 'center':
				object.style.left		= (window_width / 2) - ( parseInt(object.style.width) / 2);
			break;

			case 'right':
				object.style.right		= 30;
			break;
		}
	} else {
		object.style.left = parseInt(xposition);
	}

	if ( isNaN(parseInt(yposition)) ) {

		switch (yposition) {
			case 'top':
				object.style.top		= 20;
			break;

			case 'middle':
				object.style.top		= (window_height / 2) - ( parseInt(object.style.height) / 2);
			break;

			case 'bottom':
				object.style.bottom		= 50;
			break;
		}

	} else {

		object.style.top = parseInt(xposition);
	}

}

/* Vormi submit parameetriga */
function submit_form_with_param(form, param, value) {

	var newHidden = document.createElement("input");

	newHidden.setAttribute("type", "hidden");
	newHidden.setAttribute("name", param);
	newHidden.setAttribute("value", value);

	form.appendChild(newHidden);

	form.submit();
}

function classChangeMouseOverEvent(object_id, class_name) {
	var obj = getObject(object_id);

	if (obj) {
		obj.className = class_name;
		mouse_over_event = object_id;
	}
}

function classChangeMouseOutEvent(object_id, class_name) {

	if (mouse_over_event == object_id) mouse_over_event = null;
	setTimeout("if (mouse_over_event != '"+object_id+"') { var obj=getObject('"+object_id+"'); if (obj) obj.className = '"+class_name+"'; }", 100);
}

function recordUserTimestamp(element) {
	var obj = getObject(element);

	if (obj) {
		var d = new Date()
		obj.value = Math.round(d.getTime() / 1000);
	}
}