function mywrite(flash)
{
//	alert(flash);
	document.write(flash)
}


function $(name)
{
	obj =  document.getElementById(name);
	return obj;
}

function ShowHide(id)
{
//	alert
	if ($(id).style.display == "none")
		$(id).style.display = "block"
	else
		$(id).style.display = "none";
}


var last;
function SetOne(name)
{
	last = name;
}

function ShowOne(name)
{
	$(last).style.display = "none";
	$(name).style.display = "block";
	$("bt_"+last).style.fontWeight = "normal";
	$("bt_"+name).style.fontWeight = "bold";
	last = name;
}




function CheckEMail(address) {
	return address != "" 	&& address.match(/^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9])+$/);	
}

function myMail(f)
{
	if (!CheckEMail(f.email.value))
	{
		alert("Prosze podać poprawnie adres e-mail...");
		f.email.focus();
		return false;
	}

	return true;
}


function checkForm(f)
{
	if (!f.imie_nazwisko.value)
	{
		alert("Prosze podać imię i nazwisko...");
		f.imie_nazwisko.focus();
		return false;
	}

	if (!f.email.value && !f.telefon.value)
	{
		alert("Prosze podać adres e-mail lub telefon kontaktowy...");
		f.telefon.focus();
		return false;
	}
	
	if (f.email.value && !CheckEMail(f.email.value))
	{
		alert("Prosze podać poprawnie adres e-mail...");
		f.email.focus();
		return false;
	}
	
	if (!f.tresc.value)
	{
		alert("Prosze podać treść wiadomości...");
		f.tresc.focus();
		return false;
	}

	if (!f.zgoda.checked)
	{
		alert("Prosze wyrazić zgodę na przetwarzanie danych...");
		f.zgoda.focus();
		return false;
	}

	return true;
}



function powieksz(el, fname, s, w)
{
	wys = w + 5;
	szer = s + 25;

	  if(window.screen){
		aw=screen.availWidth;
		ah=screen.availHeight;
	  }else{
		aw=640;
		ah=450;
	  }

	  if (szer>810) szer = 810;
	  if (wys>610) wys = 610;

	str = "foto.php?dir="+escape(el)+"&ph="+escape(fname);
	var win = window.open(str,"zoom","width="+szer+", height="+wys+", left="+(aw-szer)/2+", top="+ (ah-wys)/2+", titlebar=no, status=no, toolbar=no, menubar=no, location=no, resizable=yes, scrollbars=yes, fullscreen=no");
	win.focus();

}


var ie4=document.all&&navigator.userAgent.indexOf("Opera")==-1
var ns6=document.getElementById&&!document.all
var ns4=document.layers

var selected;

function initMenu(str, sel)
{
	if (navigator.appVersion.indexOf("MSIE")>0)
	{
		str = str.split(",");
		for (var i in str)
		{			
			obj = $("submenu"+str[i]);
			if (obj) obj.style.left = obj.offsetLeft + "px";	
		}
	}

	selected = "submenu"+sel;
	if (sel)
	{
		selected = "submenu"+sel;
		showmenu("",selected);
	}
}


z = 1000;
function showmenu(e,object)
{
	
	if (!document.all&&!document.getElementById&&!document.layers) 
		return;

	if (window.menuobj) 
		hidemenu(object);

	clearhidemenu();
	
	menuobj=$(object);
	if (menuobj)
	{
		menuobj.className = "submenu_on";
//		if (object == selected ) menuobj.className = "submenu_on submenu_sel";
	}

return false
}

function hidemenu(object)
{
	if (window.menuobj)
	{
//		menuobj.thestyle.visibility=(ie4||ns6)? "hidden" : "hide"
		menuobj.className = "submenu";
	}
	
	if (!object)
	{
//		delayhide=setTimeout('showmenu("",selected);',500)
		showmenu("",selected);
	}
}

function dynamichide(e)
{
	delayhidemenu();
}

function delayhidemenu()
{
	if (ie4||ns6||ns4)
		delayhide=setTimeout("hidemenu()",500)
}

function clearhidemenu()
{
	if (window.delayhide)
		clearTimeout(delayhide)
}


function sel_change(object)
{
	clearhidemenu();

	if (object.className=='zmien_on')
		object.className='zmien_off';
	else
		object.className='zmien_on';
}

if (ie4||ns6)
	document.onClick=hidemenu();
	

var act_odp;
function odp(id)
{
	if ($("odp_"+act_odp))
	{
		$("odp_"+act_odp).style.display = "none";
	}

	if ($("odp_"+id))
	{
		$("odp_"+id).style.display = "block";
		act_odp = id;
	}
	return;
}


function checkZamowienie2()
{
	
		
	if (!$("forma_1").checked && !$("forma_2").checked)
	{
		alert("Proszę wybrać formę płatności...");
		$("forma_1").focus();
		return false;
	}
	
	if (!$("nazwisko").value)
	{
		alert("Proszę podać imię i nazwisko...");
		$("nazwisko").focus();
		return false;
	}

	
	if (!$("email").value && !$("telefon").value)
	{
		alert("Proszę podać adres e-mail lub telefon kontaktowy...");
		$("email").focus();
		return false;
	}
	
	if ($("email").value && !CheckEMail($("email").value))
	{
		alert("Proszę podać poprawnie adres e-mail...");
		$("email").focus();
		return false;
	}
	
	
	var frmobj = document.getElementById('f');
	
	if (frmobj["source[]"].length)
	{
		
		var ischk = false;
		var nr = false;
		
		
		
		for (i = 0; i < frmobj["source[]"].length; i++)
		{
		      if (frmobj["source[]"][i].checked)
		      {
		       		ischk = true
		       		
		       		if (i==7)
		       		{
		       			nr=true;
		       		}
		       		
		       		if (i==4 && frmobj.magazine.value == 0)
		       		{
		       			alert("Proszę wybrać czasopismo ...");
		       			return false;
		       		}
		      }
		}
		
		if (!ischk)
		{
			alert("Proszę zaznaczyć żródło informacji...");
			return false;
		}
		else
		{
			if (nr)
			{
				if (!frmobj.advother.value)
				{
					alert("Proszę wpisać jakie to było źródło...");
					frmobj.advother.focus();
					return false;
				}
			}
		}
		
		

	}
	else
	{
		return false;
	}
	

	if (!$("zgoda").checked)
	{
		alert("Proszę zapoznać się i zaakceptować regulamin...");
		//f.zgoda.focus();
		return false;
	}

	if (!$("zgoda2").checked)
	{
		alert("Proszę wyrazić zgodę na przetwarzanie danych...");
		//f.zgoda2.focus();
		return false;
	}

	return true;
}


var sound = true;
function soundSwitch()
{	
//	getFlashMovieObject("drzewo_v2").SetVariable("nauka", "leo_maluch.php"); 
	//window.document.drzewo_v2.SetVariable("nauka", "leo_maluch.php"); 

	if ( $("main") || $("small_clear") ) // wylaczenie dzwieku w drzewku
	{
		if (sound)
		{
			if ($("main")) getFlashMovieObject("main").ls_stopmusic();
//			if ($("small_clear")) getFlashMovieObject("small_clear").ls_stopmusic();
			$("nutka").src = "images/dzwiek_off.gif";
			sound = false
			setCookie('shopmusic', 0,365);
		}
		else
		{
			if ($("main")) getFlashMovieObject("main").ls_startmusic();
//			if ($("small_clear")) getFlashMovieObject("small_clear").ls_startmusic();
			$("nutka").src = "images/dzwiek.gif";
			sound = true
			setCookie('shopmusic', 1,365);
		}
	}

}


function soundshopSwitch()
{	
	//alert(sound);
		var obj = getPlayer('player1');
		
		if (sound)
		{
			
			if (obj)
			{	
				obj.stopMusic();
				sound = false
				setCookie('shopmusic', 0,365);
			}
			
			$("nutka").src = "images/dzwiek_off.gif";
		}
		else
		{
			if (obj)
			{
				obj.playMusic();
				sound = true
				setCookie('shopmusic', 1,365);
			}
			
			$("nutka").src = "images/dzwiek.gif";
		}
	

}




function getCookie(c_name)
{
if (document.cookie.length>0)
  {
  c_start=document.cookie.indexOf(c_name + "=");
  if (c_start!=-1)
    {
    c_start=c_start + c_name.length+1;
    c_end=document.cookie.indexOf(";",c_start);
    if (c_end==-1) c_end=document.cookie.length;
    return unescape(document.cookie.substring(c_start,c_end));
    }
  }
return "";
}

function setCookie(c_name,value,expiredays)
{
var exdate=new Date();
exdate.setDate(exdate.getDate()+expiredays);
document.cookie=c_name+ "=" +escape(value)+
((expiredays==null) ? "" : ";expires="+exdate.toUTCString());
}

function checkCookie()
{
var shopmusic=getCookie('shopmusic');

if (shopmusic!=null && shopmusic!="")
{
	if (shopmusic == 1)
	{
		sound = false;
	}
}
else
{
    setCookie('shopmusic', 1,365);
    sound = false;
}
	soundshopSwitch();
	soundSwitch();
}



function getPlayer(movieName)
{
if (navigator.appName.indexOf("Microsoft") != -1)
{
return window[movieName];
}
else
{
return document[movieName];
}
}


function getFlashMovieObject(movieName)
{
	if(document.embeds[movieName])
	return document.embeds[movieName];
	if(window.document[movieName])
	return window.document[movieName];
	if(window[movieName])
	return window[movieName];
	if(document[movieName])
	return document[movieName];
	return null;
}

function mDelete(id)
{
	$("delete").value = id;
	$("del").submit();
}


function przelicz_koszyk()
{
	$("del").submit();
}



function input_text(obj, text)
{
	if (obj.value == text)
		obj.value = "";
	else if (obj.value == "")
		obj.value = text;
}


function centerWindow2(element) {
     if($(element) != null) {
          if(typeof window.innerHeight != 'undefined') {
               $(element).style.top = 
                    Math.round(document.viewport.getScrollOffsets().top + 
                    ((window.innerHeight - $(element).getHeight()))/2)+'px';
               $(element).style.left = 
                    Math.round(document.viewport.getScrollOffsets().left + 
                    ((window.innerWidth - $(element).getWidth()))/2)+'px';
          } else {
               $(element).style.top = 
                    Math.round(document.body.scrollTop + 
                    (($$('body')[0].clientHeight - $(element).getHeight()))/2)+'px';
               $(element).style.left = 
                    Math.round(document.body.scrollLeft + 
                    (($$('body')[0].clientWidth - $(element).getWidth()))/2)+'px';
          }
     }
}

function centerWindow(elem)
{
	var s = $(elem);
	
	var ie=(document.all);
	var ns=(document.layers);
	var ns6=(document.getElementById && !ie);
	var calculate=ns? "" : "px"
	var agent=navigator.userAgent.toLowerCase();
	var winw = s.offsetWidth;
	var winh = s.offsetHeight;
	
	if (ie){
		documentWidth = (centerElement().offsetWidth)/2+centerElement().scrollLeft-(winw/2);
		documentHeight = (centerElement().offsetHeight)/2+centerElement().scrollTop-(winh/2);
	}
	else if (ns){
		documentWidth=window.innerWidth/2+window.pageXOffset-(winw/2);
		documentHeight=window.innerHeight/2+window.pageYOffset-(winh/2);
	}
	else if (ns6){
		documentWidth=self.innerWidth/2+window.pageXOffset-(winw/2);
		documentHeight=self.innerHeight/2+window.pageYOffset-(winh/2);
	}
	
	s.style.left = documentWidth+calculate;
	s.style.top = (documentHeight<0 ? 5 : documentHeight) +calculate;
}

function centerElement()
{
	return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body;
}


function getPageSize() {
	        
	     var xScroll, yScroll;
		
		if (window.innerHeight && window.scrollMaxY) {	
			xScroll = window.innerWidth + window.scrollMaxX;
			yScroll = window.innerHeight + window.scrollMaxY;
		} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
			xScroll = document.body.scrollWidth;
			yScroll = document.body.scrollHeight;
		} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
			xScroll = document.body.offsetWidth;
			yScroll = document.body.offsetHeight;
		}
		
		var windowWidth, windowHeight;
		
		if (self.innerHeight) {	// all except Explorer
			if(document.documentElement.clientWidth){
				windowWidth = document.documentElement.clientWidth; 
			} else {
				windowWidth = self.innerWidth;
			}
			windowHeight = self.innerHeight;
		} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
			windowWidth = document.documentElement.clientWidth;
			windowHeight = document.documentElement.clientHeight;
		} else if (document.body) { // other Explorers
			windowWidth = document.body.clientWidth;
			windowHeight = document.body.clientHeight;
		}	
		
		// for small pages with total height less then height of the viewport
		if(yScroll < windowHeight){
			pageHeight = windowHeight;
		} else { 
			pageHeight = yScroll;
		}
	
		// for small pages with total width less then width of the viewport
		if(xScroll < windowWidth){	
			pageWidth = xScroll;		
		} else {
			pageWidth = windowWidth;
		}

		return [pageWidth,pageHeight];
	}
	
	
	function fcclear()
	{
		new Effect.Fade($('overlay'), { duration: 0.4 });
		$('flashcontent').hide();
		$$('select', 'object', 'embed').each(function(node){ node.style.display = 'block' });
		$('swf').update();
		$('text').innerHTML = '';
	}
	
	
