// JavaScript Document


function drawHeader2(tekst,width){
	var stringFlashDraw = '';
	stringFlashDraw += '<object style="z-index:-1;" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" width="'+width+'" height="20" id="header_element" align="middle"><param name="allowScriptAccess" value="sameDomain" />';
	stringFlashDraw += '<param name="movie" value="/gfx/header_'+width+'.swf?tekst='+tekst+'" />';
	stringFlashDraw += '<param name="wmode" value="transparent"><param name="quality" value="high" /><param name="bgcolor" value="white" />';
	stringFlashDraw += '<embed src="/gfx/header_'+width+'.swf?tekst='+tekst+'" wmode="transparent" quality="high" bgcolor="white" width="'+width+'" height="20" name="header_element" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />';
	stringFlashDraw += '</object>';	
	return stringFlashDraw;
}

function replace(){	
	if(hasFlash){
		elements = document.getElementsByTagName('h2');
	 	for (i=0; i < elements.length; i++) {
	 		elements[i].innerHTML = drawHeader2(elements[i].innerHTML, elements[i].className);
	 	}	
	}
}


function isValidEmail(oEmail){
		oRegExp=/^\w+((-\w+)|(\.\w+))*\@\w+((\.|-)\w+)*\.\w+$/
	return oRegExp.test(oEmail)
}

var hasFlash=function(){
	var a=8;
	if(navigator.appVersion.indexOf("MSIE")!=-1&&navigator.appVersion.indexOf("Windows")>-1){
		document.writeln('<script language="VBScript"\> \n');
		document.writeln('on error resume next \n');
		document.writeln('hasFlash = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash." & '+a+'))) \n');
		document.writeln('</script\> \n');
		if(window.hasFlash!=null){return window.hasFlash;};
	};
	if(navigator.mimeTypes&&navigator.mimeTypes["application/x-shockwave-flash"]&&navigator.mimeTypes["application/x-shockwave-flash"].enabledPlugin){
		var b=(navigator.plugins["Shockwave Flash 2.0"]||navigator.plugins["Shockwave Flash"]).description;
		var c=parseInt(b.charAt(b.indexOf(".")-1));
		return c>=a;
	};
	return false;
}();


function drawFlash(filename, id, width, height, align, quality, bgcolor){
	var stringFlashDraw = '';
	stringFlashDraw += '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" ';
	stringFlashDraw += 'width="'+width+'" height="'+height+'" id="'+id+'" align="'+align+'">';
	stringFlashDraw += '<param name="allowScriptAccess" value="sameDomain" />';
	stringFlashDraw += '<param name="movie" value="'+filename+'" />';
	stringFlashDraw += '<param name="quality" value="'+quality+'" />';
	stringFlashDraw += '<param name="wmode" value="transparent">';
	stringFlashDraw += '<param name="bgcolor" value="'+bgcolor+'" />';
	stringFlashDraw += '<embed src="'+filename+'" quality="'+quality+'" bgcolor="'+bgcolor+'"';
	stringFlashDraw += 'width="'+width+'" height="'+height+'" name="'+id+'" align="'+align+'" ';
	stringFlashDraw += 'allowScriptAccess="sameDomain" wmode="transparent" type="application/x-shockwave-flash"'; 
	stringFlashDraw += 'pluginspage="http://www.macromedia.com/go/getflashplayer" />';
	stringFlashDraw += '</object>';	
	document.writeln(stringFlashDraw);	
}

function drawFlash2(filename, id, width, height, align, quality, bgcolor, flv){
	var stringFlashDraw = '';
	stringFlashDraw += '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" ';
	stringFlashDraw += 'width="'+width+'" height="'+height+'" id="'+id+'" align="'+align+'">';
	stringFlashDraw += '<param name="allowScriptAccess" value="sameDomain" />';
	stringFlashDraw += '<param name="movie" value="'+filename+'" />';
	stringFlashDraw += '<param name="quality" value="'+quality+'" />';
	stringFlashDraw += '<param name="wmode" value="transparent">';
	stringFlashDraw += '<param name="bgcolor" value="'+bgcolor+'" />';
	stringFlashDraw += '<param name="FlashVars" value="'+flv+'" />';
	stringFlashDraw += '<embed src="'+filename+'" quality="'+quality+'" bgcolor="'+bgcolor+'"';
	stringFlashDraw += 'width="'+width+'" height="'+height+'" name="'+id+'" align="'+align+'" ';
	stringFlashDraw += 'allowScriptAccess="sameDomain" FlashVars="'+flv+'" wmode="transparent" type="application/x-shockwave-flash"'; 
	stringFlashDraw += 'pluginspage="http://www.macromedia.com/go/getflashplayer" />';
	stringFlashDraw += '</object>';	
	document.writeln(stringFlashDraw);	
}

function drawMap(){
	var str = '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0" width="150" height="180" id="mapa" align="middle">';
	str += '<param name="allowScriptAccess" value="sameDomain" />';
	str += '<param name="FlashVars" value="zachodnio=/?action%3DshowArticle%26id%3D348&amp;pomorskie/?action%3DshowArticle%26id%3D343&amp;warminsko/?action%3DshowArticle%26id%3D346&amp;podlaskie/?action%3DshowArticle%26id%3D341&amp;lubuskie/?action%3DshowArticle%26id%3D335&amp;wielkopolskie/?action%3DshowArticle%26id%3D347&amp;kujawsko/?action%3DshowArticle%26id%3D334&amp;mazowieckie/?action%3DshowArticle%26id%3D338&amp;lubelskie/?action%3DshowArticle%26id%3D337&amp;dolnoslaskie/?action%3DshowArticle%26id%3D333&amp;lodzkie/?action%3DshowArticle%26id%3D336&amp;swietokrzyskie/?action%3DshowArticle%26id%3D345&amp;opolskie/?action%3DshowArticle%26id%3D340&amp;slaskie/?action%3DshowArticle%26id%3D344&amp;malopolskie/?action%3DshowArticle%26id%3D339&amp;podkarpackie/?action%3DshowArticle%26id%3D342" />';
	str += '<param name="movie" value="gfx/mapa.swf" /><param name="quality" value="high" /><param name="bgcolor" value="#ffffff" /><embed src="gfx/mapa.swf" FlashVars="&amp;zachodnio=/?action%3DshowArticle%26id%3D348&amp;pomorskie/?action%3DshowArticle%26id%3D343&amp;warminsko/?action%3DshowArticle%26id%3D346&amp;podlaskie/?action%3DshowArticle%26id%3D341&amp;lubuskie/?action%3DshowArticle%26id%3D335&amp;wielkopolskie/?action%3DshowArticle%26id%3D347&amp;kujawsko/?action%3DshowArticle%26id%3D334&amp;mazowieckie/?action%3DshowArticle%26id%3D338&amp;lubelskie/?action%3DshowArticle%26id%3D337&amp;dolnoslaskie/?action%3DshowArticle%26id%3D333&amp;lodzkie/?action%3DshowArticle%26id%3D336&amp;swietokrzyskie/?action%3DshowArticle%26id%3D345&amp;opolskie/?action%3DshowArticle%26id%3D340&amp;slaskie/?action%3DshowArticle%26id%3D344&amp;malopolskie/?action%3DshowArticle%26id%3D339&amp;podkarpackie/?action%3DshowArticle%26id%3D342" quality="high" bgcolor="#ffffff" width="150" height="180" name="mapa" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />';
	str += '</object>';
	document.writeln(str);
}

function showCommentForm(id,x,y){
	$('div#blockCommentFormOuter').css("left",(document.documentElement.clientWidth/2)+"px");
	$('div#blockCommentFormOuter').css("top",(document.documentElement.clientHeight/2+document.documentElement.scrollTop+50)+"px");
	document.getElementById('id_article').value = id;
	var ts = new Date; ts = ts.getTime();
	document.getElementById('commentImg').src = 'libs/hn_captcha/getImage.php?id='+id+'&ts='+ts;
	$('div#blockCommentFormOuter').show();
	return false;
}

function showBigPhoto(id){
	window.open ("?action=showBigPhoto&id="+id,"photo_window","location=0,status=0,toolbar=0,scrollbars=0,width=680,height=680");
	
}

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;
}


function drawBanner(id, filename, url, target, width, height){
	var ext = filename.split('.').pop();
	if(ext == 'swf'){
		drawFlash(filename,'banner_'+id, width, height, 'center','high', 'transparent');
	}else{
		document.writeln('<a href="'+url+'" target="'+target+'"><img src="'+filename+'" alt="" /></a>');		
	}
	
}

function checkPoll(){
	if((document.getElementById('answer_1') && document.getElementById('answer_1').checked) || (document.getElementById('answer_2') && document.getElementById('answer_2').checked) || (document.getElementById('answer_3') && document.getElementById('answer_3').checked) || (document.getElementById('answer_4') && document.getElementById('answer_4').checked) || (document.getElementById('answer_5') && document.getElementById('answer_5').checked) || (document.getElementById('answer_6') && document.getElementById('answer_6').checked)){
		return true;
	}	
	alert('Proszę zaznaczyć jedną z odpwiedzi i dopiero oddać głos');
	return false;		
}

function checkComment(){
	var name = $('#c_name').val();
	var lastname = $('#c_lastname').val();
	var email = $('#c_email').val();
	var code = $('#c_code').val();
	if (name == '') {
		alert('Proszę podać imię')
		return false;
	}
	if (lastname == '') {
		alert('Proszę podać nazwisko')
		return false;
	}
	if(email == '' || email.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) == -1) {
		alert('Proszę podać prawidłowy adres e-mail')
		return false;
	}
	if (code == '') {
		alert('Proszę podać kod z obrazka')
		return false;
	}
	return true;
}


function checkContact(){
	var error = false;
	if(document.getElementById('nameContact').value ==''){ 
		document.getElementById('errorNameContact').style.display = 'inline';
		document.getElementById('nameContact').style.backgroundColor= '#ffcccc';
		error = true;
	}else{
		document.getElementById('nameContact').style.backgroundColor= '#ffffff';
		document.getElementById('errorNameContact').style.display = 'none';		
	}
	
	if(document.getElementById('lastnameContact').value ==''){ 
		document.getElementById('errorLastnameContact').style.display = 'inline';
		document.getElementById('lastnameContact').style.backgroundColor= '#ffcccc';
		error = true;
	}else{
		document.getElementById('lastnameContact').style.backgroundColor= '#ffffff';
		document.getElementById('errorLastnameContact').style.display = 'none';		
	}	
	
	if(document.getElementById('emailContact').value ==''){ 
		document.getElementById('errorEmailContact').style.display = 'inline';
		document.getElementById('emailContact').style.backgroundColor= '#ffcccc';
		error = true;
	}else{
		document.getElementById('emailContact').style.backgroundColor= '#ffffff';
		document.getElementById('errorEmailContact').style.display = 'none';		
	}		
	
	if(document.getElementById('messageContact').value ==''){ 
		document.getElementById('errorMessageContact').style.display = 'inline';
		document.getElementById('messageContact').style.backgroundColor= '#ffcccc';
		error = true;
	}else{
		document.getElementById('messageContact').style.backgroundColor= '#ffffff';
		document.getElementById('errorMessageContact').style.display = 'none';
		
	}			
	
	if(document.getElementById('c2_code').value ==''){ 
		document.getElementById('errorCode').style.display = 'inline';
		document.getElementById('c2_code').style.backgroundColor= '#ffcccc';
		error = true;
	}else{
		document.getElementById('c2_code').style.backgroundColor= '#ffffff';
		document.getElementById('errorCode').style.display = 'none';
		
	}			
	
	if(error)return false;	
	return true;
}

function showContactForm(){
	$('div#blockContactFormOuter').css("left",(document.documentElement.clientWidth/2)+"px");
	$('div#blockContactFormOuter').css("top",(document.documentElement.clientHeight/2+document.documentElement.scrollTop+50)+"px");
	var ts = new Date; ts = ts.getTime();
	document.getElementById('contactImg').src = 'libs/hn_captcha/getImage.php?id=cf&ts='+ts;
	$('div#blockContactFormOuter').show();
	return false;
}


function escape(str) {
  str = str.replace(/=/g, '%3D'); 
  str = str.replace(/&/g, '%26');
  str = str.replace(/"/g, '%22');
  return str;
}
