function findLeftPos(obj,type) {
	var curleft = 0;

	if (obj.offsetParent) {
		curleft = obj.offsetLeft

		while (obj = obj.offsetParent) {
			curleft += obj.offsetLeft
		}
	}

	return curleft;
}

function award_show ( id ) {
	$('award_' + id).style.display = 'block';
	$('award_' + id).style.width = '600px';
	$('award_' + id).style.left = ( findLeftPos($('award_td_'+id), 'left') + 150 ) + 'px';
}

function award_hide ( id ) {
	$('award_' + id).style.display = 'none';
}

function showhide ( id ) {
	if ( $(id).className == 'hide' )
		$(id).className = 'show';
	else
		$(id).className = 'hide';

	return true;
}

function show ( id ) {
	$(id).className = 'show';
}

function hide ( id ) {
	$(id).className = 'hide';
}


function expand(id) {
	var link_id = 'expand-link-'+id;
	var element_id = 'expand-'+id;

	if (document.getElementById(element_id) && document.getElementById(link_id)) {
		var l = document.getElementById(link_id);
		var e = document.getElementById(element_id);

		if (e.className == 'expand_visible') {
			e.className = 'expand_hidden';
			l.className = 'expand';
		}
		else {
			e.className = 'expand_visible';
			l.className = 'contract';
		}

		return true;
	}
	else
		return false;
}


function get_cookie (Name) {
	var re = new RegExp(Name+"=[^;]+", "i"); //construct RE to search for target name/value pair

	if (document.cookie.match(re)) //if cookie found
		return document.cookie.match(re)[0].split("=")[1]; //return its value

	return "";
}


function set_cookie (name, value) {
	document.cookie = name+"="+value; //cookie value is domain wide (path=/)
}


function preload() {
  var  x,y = [], i = 0;
  while (x = arguments[i]) {
  	y[i] = new Image();
  	y[i++].src = x
  }
}


function insert_flag(field_flag, field_destination) {
	var flag = document.getElementById(field_flag) ? document.getElementById(field_flag).value : '';

	if (flag != '') {
		document.getElementById(field_destination).value += flag;
	}

	return true;
}


function mail(user, domain) {
	window.location = 'mailto:'+user+'@'+domain;
}

/* jQuery */
$(document).ready(
	function() {
		$("div.expand_wrapper").children("a.expand").click(function() {
			$(this).next("div.expand_text").toggle();
			$(this).toggleClass('contract', 'expand');
		});

		$("dl.expandable dt a").click(function() {
			$(this).parent("dt").next("dd:visible").hide("fast");
			$(this).parent("dt").next("dd:hidden").show("fast");
		});
	});
/* /jQuery */


preload('/public/images/layout/menu_item_on.gif', '/public/images/layout/news_komentarze_on.gif', '/public/images/layout/news_czytaj_on.gif', '/public/images/layout/main_bottom_more_on.gif', '/public/images/layout/contract.gif');
