function newWindow(url) {
	var nWindow = false;
	nWindow = window.open(url, '', 'menubar=yes, toolbar=yes, location=yes, scrollbars=yes, resizable=yes, status=yes');
	nWindow.focus();
}

function hide_box() {
	var box = document.getElementById('box');
	if(!box)
		return;
	box.style.display = 'none';
	box.innerHTML = '';
	
	if(document.layers) {
		document.releaseEvents(Event.MOUSEMOVE);
	}
	if(document.layers || document.all) {
		document.onmousemove = '';
	}
	if(document.removeEventListener) {
		document.removeEventListener('mousemove', mouseMove, true);
	}
}

function show_box(id) {
	
	var box = document.getElementById('box');
	var cont = document.getElementById('a' + id);
	
	if(!box || !cont) {
		return;
	}
	box.innerHTML = cont.innerHTML;
	box.style.display = 'block';
	if(document.layers) {
		document.captureEvents(Event.MOUSEMOVE);
	}
	if(document.layers || document.all) {
		document.onmousemove = mouseMove;
	}
	if(document.addEventListener) {
		document.addEventListener('mousemove', mouseMove, true);
	}
	
}


function mouseMove(e) {
	var box = document.getElementById('box');
	if(!box)
		return;
	
	var box_w = box.offsetWidth;
	var box_h = box.offsetHeight;
	
	if (document.layers) {
		var cursor_x = e.x;
		var cursor_y = e.y;
	} else if (document.all) {
		var cursor_x = event.clientX;
		var cursor_y = event.clientY;
	} else if (document.getElementById) {
		var cursor_x = e.clientX;
		var cursor_y = e.clientY;
	}
	
	if (document.body) {
		var screen_w =  document.documentElement.clientWidth;
	} else {
		var screen_w = window.innerWidth;
	}
	
	if (document.body) {
		var screen_h =  document.documentElement.clientHeight;
	} else {
		var screen_h =  window.innerHeight;
	}
	
	if (typeof(window.pageXOffset) == 'number' ) {
		var scroll_x = window.pageXOffset;
	} else if (document.body && document.body.scrollLeft) {
		var scroll_x = document.body.scrollLeft;
	} else if (document.documentElement && document.documentElement.scrollLeft) {
		var scroll_x = document.documentElement.scrollLeft;
	} else {
		var scroll_x = 0;
	}
	
	if (typeof(window.pageYOffset) == 'number' ) {
		var scroll_y = window.pageYOffset;
	} else if (document.body && document.body.scrollTop) {
		var scroll_y = document.body.scrollTop;
	} else if (document.documentElement && document.documentElement.scrollTop) {
		var scroll_y = document.documentElement.scrollTop;
	} else {
		var scroll_y = 0;
	}
	
	var offset = 15;
	
	if ((cursor_x + 15 + box_w) > screen_w ) {
		trop = (cursor_x + 15 + box_w) - screen_w;
		box.style.left = (cursor_x + 15 - trop + scroll_x) + 'px';
	} else {
		box.style.left = (cursor_x + 15 + scroll_x) + 'px';
	}
	if ((cursor_y - box_h - 15) < 0 ) {
		box.style.top = (cursor_y + 15 + scroll_y) + 'px';
	} else {
		box.style.top = (cursor_y - box_h - 15 + scroll_y) + 'px';
	}

}
function set_width() {
	
	var screenWidth = false;
	var screenHeight = false;
	var cont = document.getElementById('win_cont');
	
	if(window.innerWidth)
		screenWidth = window.innerWidth;
	else
		screenWidth = document.documentElement.clientWidth;
	
	if(window.innerHeight)
		screenHeight = window.innerHeight;
	else
		screenHeight = document.documentElement.clientHeight;
	
	document.cookie = 'tv_pl_res=' + screenWidth + 'x' + screenHeight + '; expires=Thu, 2 Aug 2009 20:47:11 UTC; path=/';

}

function oldIE() {
	var temp = navigator.appVersion.indexOf("MSIE ");
	if(temp != -1) {
		temp = navigator.appVersion.substr(temp + 5, 1);
		if(temp < 7)
			return true;
	}
	return false;
}

function setBanners() {
	//var temp = navigator.appVersion.indexOf("MSIE ");
	//if(temp != -1) {
	//	temp = navigator.appVersion.substr(temp + 5, 1);
	//	if(temp < 7)
	//		return true;
	//}
	
	var screenWidth = false;
	var screenHeight = false;
	var cont = document.getElementById('win_cont');
	
	if(cont == null)
		return true;
	
	if(window.innerWidth) {
		screenWidth = window.innerWidth;
	} else {
		screenWidth = document.documentElement.clientWidth;
	}
	
	if(window.innerHeight) {
		screenHeight = window.innerHeight;
	} else {
		screenHeight = document.documentElement.clientHeight;
	}
	
	if(screenWidth < 990)
		return true;
	
	temp = widthh = (screenWidth - cont.offsetWidth)/2;

	if(widthh >= 160)
		widthh = 160;
	else if(widthh >= 120)
		widthh = 120;
	else {
		if(document.getElementById('siteH') != undefined) {
			if((widthh + 56) >= 160) {
				widthh = 160;
			} else if((widthh + 56) >= 120) {
				widthh = 120;
			} else {
				widthh = 0;
				return true;
			}
		} else {
			widthh = 0;
			return true;
		}
	}
	if(document.getElementById('siteH') != undefined) {
		temp += 28;
	}

	var leftt = document.getElementById('banner_left');
	var rightt = document.getElementById('banner_right');
	
	if(screenHeight <= 600) {
		var position = 'absolute';
		if(document.getElementById('siteH') != undefined) {
			document.getElementById('siteH').style.position = 'relative';
		} else if(document.getElementById('site') != undefined) {
			document.getElementById('site').style.position = 'relative';
		}
	}
	else {
		var position = 'fixed';
	}
	
	if(oldIE()) {
		position = 'absolute';
	}
	
	leftt.style.display = rightt.style.display = 'block';
	leftt.style.position = rightt.style.position = position;
	
	temp -= widthh;
	temp = parseInt(temp/2);
	
	if(temp >= 0)
		leftt.style.left = rightt.style.right = temp + 'px';
	else
		leftt.style.left = rightt.style.right = '0px';
	
	if(screenHeight == 600) {
		leftt.style.top = rightt.style.top = '0px';
	} else if(screenHeight > 600){
		if((screenHeight - leftt.offsetTop) < 600) {
			var offset = parseInt((screenHeight - 600)/2);
			leftt.style.top = rightt.style.top = offset + 'px';
		}
	}
}

function check_form(form) {
	
	var bol = true;
	
	if(!form.nazwa.value || form.nazwa.value.length < 3) {
		bol = false;
		form.nazwa.focus();
		alert("Pole nazwy jest wymagane!");
	}
	
	if(bol && (!form.file.value && !form.plik.value)) {
		bol = false;
		form.file.focus();
		alert("Jedno z pól: ścieżka lub plik jest wymagane!");
	}
	
	if(bol && (!form.link.value || form.link.value.length < 5)) {
		bol = false;
		form.link.focus();
		alert("Pole linku jest wymagane!");
	}
	
	if(bol && (!form.height.value || form.height.value.length < 2)) {
		bol = false;
		form.height.focus();
		alert("Pole wysokości jest wymagane!");
	}
	
	if(bol && (!form.width.value || form.width.value.length < 2)) {
		bol = false;
		form.width.focus();
		alert("Pole szerokości jest wymagane!");
	}
	
	if(bol && (!form.start_time.value || form.start_time.value.length < 19)) {
		bol = false;
		form.start_time.focus();
		alert("Pole daty rozpoczęcia jest wymagane!");
	}
	
	if(bol && (!form.end_time.value || form.end_time.value.length < 19)) {
		bol = false;
		form.end_time.focus();
		alert("Pole daty zakończenia jest wymagane!");
	}
	
	if(bol) {
		var boll = false;
		
		var start = form.start_time.value.split(" ");
		var end = form.end_time.value.split(" ");
		
		var s_date = start[0].split("-");
		var e_date = end[0].split("-");
		var s_time = start[1].split(":");
		var e_time = end[1].split(":");
		
		if(s_date[0] > e_date[0]) // rok
			boll = true;
		else if(s_date[0] == e_date[0])
			if(s_date[1] > e_date[1]) // miesiac
				boll = true;
			else if(s_date[1] == e_date[1])
				if(s_date[2] > e_date[2]) // dzien
					boll = true;
				else if(s_date[2] == e_date[2])
					if(s_time[0] > e_time[0]) // godzina
						boll = true;
					else if(s_time[0] == e_time[0])
						if(s_time[1] >= e_time[1]) // minuty
							boll = true;
		
		if(boll) {
			bol = false;
			form.end_time.focus();
			alert("Data zakończenia nie może być mniejsza lub równa od daty rozpoczęcia!");
		}
	}
	
	if(bol)
		form.submit();
}

function uncheck(form, co) {
		for(var i = 0; i<form.elements.length; i++) {
			if (form.elements[i].type == "checkbox") {
            	form.elements[i].checked = co;
             	document.getElementById('p_' + form.elements[i].name.substr(2)).disabled = !co;
			}
		}
	}

function change(form) {
	for(var i = 0; i<form.elements.length; i++) {
		if (form.elements[i].type == "checkbox") {
			if(form.elements[i].checked == true) {
				form.elements[i].checked = false;
				document.getElementById('p_' + form.elements[i].name.substr(2)).disabled = true;
			} else {
				form.elements[i].checked = true;
				document.getElementById('p_' + form.elements[i].name.substr(2)).disabled = false;
			}
		}
	}
}

function enablee(form, id) {
	if(document.getElementById('c_' + id).checked == true) {
		document.getElementById('p_' + id).disabled = false;
		document.getElementById('p_' + id).className = '';
	} else {
		document.getElementById('p_' + id).disabled = true;
		document.getElementById('p_' + id).className = 'dd';
	}
}

function subb(form) {
	var temp = document.getElementsByTagName('input');
	var count = temp.length;
	var tab = new Array();
	var j = 0, k = 0;
	var bol = true;
	for(i = 0; i < count; i++) {
		if(temp[i].className == 'input' && temp[i].disabled == false) {
			tab[j++] = temp[i];
			tab[j - 1].style.background = "white";
		}
	}
	var numericExpression = /^[0-9]+$/;
	if(j > 1) {
		for(i = 0; i < j - 1; i++) {
			for(k = i + 1; k < j; k++) {
				if(tab[i].value.length == 0 || !tab[i].value.match(numericExpression)) {
					tab[i].style.background = "red";
					bol = false;
				} else if(tab[i].value == tab[k].value) {
					tab[i].style.background = "red";
					tab[k].style.background = "red";
					bol = false;
				}
				if(tab[k].value.length == 0 || !tab[k].value.match(numericExpression)) {
					tab[k].style.background = "red";
					bol = false;
				}
			}
		}
	} else if(j == 1) {
		if(tab[0].value.length == 0) {
			tab[0].style.background = "red";
			bol = false;
		}
	}
	
	if(!bol)
		alert("Aktywne pola nie mogą być puste.");
	else
		form.submit();
}

function show_img(url) {
	var strWindowFeatures = "height=100,width=100,menubar=no,toolbar=no,location=no,resizable=yes,scrollbars=yes,status=no";
	var wind = window.open(url, '', strWindowFeatures);
	wind.blur();
	wind.focus();
}

function stars(nr) {
	for(var i = 1; i <= 10; i++) {
		if(i <= nr)
			document.getElementById('star_' + i).src = '/images/graphic/gwiazdka_small_y.png';
		else
			document.getElementById('star_' + i).src = '/images/graphic/gwiazdka_small_g.png';
	}
	document.getElementById('count_stars').innerHTML = nr.toString();
}

function change_ig(nr) {
	var ssrc = url_main + 'images/graphic/gwiazdka_small_';
	if(nr == 0)
		ssrc = ssrc + 'g';
	else
		ssrc = ssrc + 'y';
 	ssrc = ssrc + '.png';
	document.getElementById('img').src = ssrc;
}

function change_sign(id, img) {
	var e = document.getElementById(id);
	if(e.style.display == 'none') {
		e.style.display = 'block';
		img.src = url_main + 'images/minus.png';
	} else {
		e.style.display = 'none';
		img.src = url_main + 'images/plus.png';
	}
}