﻿function $(name)
{
	return document.getElementById(name);
}


	function pokaz()
	{
		if(window.screen){
			aw=screen.availWidth;
			ah=screen.availHeight;
		}else{
			aw=640;
			ah=450;
		}
		
		if (document.layers)
			div = document.layesr["popap"];
		else
			div = document.getElementById("popap")
		
		if (div)
		{
			w = div.style.width.replace('px', '');
			div.style.left = (aw-w)/2;
		}
	}
	
	function ukryj()
	{
		div = document.getElementById("popap")
		div.style.display="none";
	}





nn4 = (document.layers) ? true:false
ie4 = (document.all) ? true:false


function spr(obj)
{
  if(nn4) {  // przeglądarką jest Navigator
    l = obj.left;
    t = obj.top;
  } else if(ie4) {  // przeglądarką jest Explorer
    l = obj.left;
    t = obj.style.pixelTop;
  }
//  alert('Położenie pierwszyDiv: od lewej = ' + l + ', od góry = ' + t);	// rezultaty
}



var widok;
function kontakt(p)
{
	if (widok && widok!=p) 
	{
		document.getElementById("kontakt_"+widok).style.display = "none";
		document.getElementById("mapa_"+widok).style.height = "0";
	}
	
	document.getElementById("kontakt_"+p).style.display = "block";
	document.getElementById("mapa_"+p).style.height = "430px";

	widok = p;
};


noweOkienko = null;
function wnd(src, nazwa, w, h)
{
  if(window.screen){
	  if (w>800 || h>600)
	  {
	    aw=800;
		ah=600;
	  }
	  else
	  {
	    aw=screen.availWidth;
		ah=screen.availHeight;
	  }
  }else{
    aw=640;
    ah=450;
  }
  //if(noweOkienko==null || noweOkienko.closed){
    ustawienia=
     "left=" + (aw-w)/2 + ", "
    +"top=" + (ah-h)/2 + ", "
    +"screenX=" + (aw-w)/2 + ", "
    +"screenY=" + (ah-h)/2 + ", "
    +"width=" + w + ", "
    +"height=" + h + ", "
    +"innerWidth=" + w + ", "
    +"innerHeight=" + h + ", "
    +"toolbar=no, "
    +"location=no, "
    +"directories=no, "
    +"status=no, "
    +"menubar=no, "
    +"scrollbars=auto, "
    +"resizable=yes, "
	+"status=no";
	noweOkienko = window.open(src,nazwa,ustawienia);

  //}
  noweOkienko.focus();
  return noweOkienko;
}


function getFlashMovieObject(movieName)
{
  if (window.document[movieName]) 
  {
      return window.document[movieName];
  }
  if (navigator.appName.indexOf("Microsoft Internet")==-1)
  {
    if (document.embeds && document.embeds[movieName])
      return document.embeds[movieName]; 
  }
  else // if (navigator.appName.indexOf("Microsoft Internet")!=-1)
  { 
    return document.getElementById(movieName);
  }
}
 
function SendDataToFlashMovie()
{
     setTimeout("SendDataToFlashMovie()",1000);
	 var flashMovie=getFlashMovieObject( "mytimer");
     
	 if( flashMovie != null )
	 {
     	flashMovie.SetVariable("/:time_left", time_left);
		time_left--;
		if (time_left==0)
		{
			if (next_min == 56)
				time_left = 12*60;
			else 
				time_left = 8*60;
			next_min = 0;	
		}
	}
	
	 
} 



var ie4=document.all&&navigator.userAgent.indexOf("Opera")==-1
var ns6=document.getElementById&&!document.all
var ns4=document.layers

var act = "";

function showmenu(e)
{
	if (!document.all&&!document.getElementById&&!document.layers)
		return

	hidemenu();
	clearhidemenu();

	div = document.getElementById(e)
	div.style.display="block";
	act = div;
	
/*
	menuobj=ie4? document.all.popmenu : ns6? document.getElementById("popmenu") : ns4? document.popmenu : ""
	menuobj.thestyle=(ie4||ns6)? menuobj.style : menuobj

	if (ie4||ns6)
	{
		menuobj.innerHTML=which[0]
	}
	else
	{
		menuobj.document.write('<layer name=gui bgColor=#E6E6E6 width=165 onmouseover="clearhidemenu()" onmouseout="hidemenu()">'+which[0]+'</layer>')
		menuobj.document.close()
	}

	menuobj.thestyle.left = which[1];
	menuobj.thestyle.top = which[2];
	menuobj.thestyle.visibility="visible"
*/

return false
}



function hidemenu(a)
{
//	alert("hidemenu "+a);
	if (act)
	{
		div.style.display="none";
	}
	return;
}

function dynamichide(e)
{
	if (ie4&&!menuobj.contains(e.toElement))
		delayhidemenu()
	else if (ns6&&e.currentTarget!= e.relatedTarget&& !contains_ns6(e.currentTarget, e.relatedTarget))
		delayhidemenu()
	return;
}

function delayhidemenu()
{
	if (ie4||ns6||ns4)
	delayhide=setTimeout("hidemenu()",500)
	return;
}

function clearhidemenu(a)
{
//	alert("clearhidemenu "+a);
	if (window.delayhide)
	clearTimeout(delayhide)
	return;
}

if (ie4||ns6)
	document.onclick=hidemenu



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>800) szer = 830;
	  if (wys>600) wys = 630;

	str = "foto.php?id="+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();
}

function wnd_print(src)
{
	w = 678;
	h = 400;
  if(window.screen){
	  if (w>900 || h>600)
	  {
	    aw=900;
		ah=600;
	  }
	  else
	  {
	    aw=screen.availWidth;
		ah=screen.availHeight;
	  }
  }else{
    aw=640;
    ah=450;
  }
  //if(noweOkienko==null || noweOkienko.closed){
    ustawienia=
     "left=" + (aw-w)/2 + ", "
    +"top=" + (ah-h)/2 + ", "
    +"screenX=" + (aw-w)/2 + ", "
    +"screenY=" + (ah-h)/2 + ", "
    +"width=" + w + ", "
    +"height=" + h + ", "
    +"innerWidth=" + w + ", "
    +"innerHeight=" + h + ", "
    +"toolbar=yes, "
    +"location=no, "
    +"directories=no, "
    +"status=no, "
    +"menubar=yes, "
    +"scrollbars=yes, "
    +"resizable=yes, "
	+"status=no";
	noweOkienko = window.open(src,'printwww',ustawienia);

  //}
  noweOkienko.focus();
  return noweOkienko;
}


function myMail(f)
{
	if (!CheckEMail(f.email.value))
	{
		alert("Prosze podać poprawnie adres e-mail...");
		f.email.focus();
		return false;
	}

	return true;
}

function dodajDaty(f)
{
	var jest = false;
	for (i=1; i<=10; i++)
	{
		pom_imie = "imie_"+i+"";
		pom_adres = "adres_"+i+"";
		pom_nazwa = "nazwa_"+i+"";
				
		if ($(pom_nazwa) && ($(pom_imie).value || $(pom_adres).value) && !$(pom_nazwa).value)
		{
			alert("Prosze podać nazwę święta...");
			$(pom_nazwa).focus();
			return false;
		}
		
		if ($(pom_nazwa) && $(pom_nazwa).value)
		{
			jest = true;
		}
		
	}

	if (!jest)
	{
		alert("Nie wpisałeś żadnych danych");
		pom_nazwa = "nazwa_1";
		$(pom_nazwa).focus();
		return false;
	}
	return true;
}

function mthSet(sel)
{
	$("month").value = sel;
	mthChange($("month"));
}

function mthChange(mth)
{
//	alert(mth.value + mth[mth.value-1].text);
	$("mth_name").innerHTML = mth[mth.value-1].text;
	for(i=1; i<=12; i++ )
	{
		m = "msc"+i;
		if (i==mth.value)
			$(m).style.display = "";
		else
			$(m).style.display = "none";
	}
//	alert(($("ilosc_"+mth.value).value * 32)+40*1)
	$("div_table").style.height = ($("ilosc_"+mth.value).value * 25 + 50*1) + "px";
//	alert($("div_table").style.height);
}



function SelImg(img)
{
/*	
	if ($("sel"))
	{
		$("sel").className = "";
		$("sel").id = "";
	}
	img.id = "sel";
	img.className = "sel";
*/
	
	if ($("kartka").value)
	{
		tmp = $("kartka").value;
		$(tmp).className = "";
	}
	img.className = "sel";

	$("kartka").value = img.id;
//	alert($("kartka").value);
}




function Next(nr)
{
	 document.navi.start.value = nr;
	 document.navi.submit();
}





function Reset(f)
{
	if (confirm("Czy na pewno chcesz wyczyścić formularz?"))
	{
		f.reset();
	}
}


function mySend(f)
{
	if (!CheckEMail(f.email.value))
	{
		alert("Prosze podać poprawnie adres e-mail...");
		f.email.focus();
		return false;
	}

	if (!f.imienazw.value)
	{
		alert("Prosze podać imię i nazwisko...");
		f.imienazw.focus();
		return false;
	}

	if (f.profil && f.profil.value && f.pass1.value && f.pass1.value!="********" && f.pass1.value==f.pass2.value)
	{
		f.password.value = MD5(f.pass1.value); 		
		f.pass1.value="";
		f.pass2.value="";
	}
	else if (f.profil && f.profil.value)
	{
		
	}
	else if (!f.pass1.value || f.pass1.value!=f.pass2.value)
	{
		alert("Hasła nie są zgodne...");
		f.pass1.value="";
		f.pass2.value="";
		f.pass1.focus();
		return false;
	}
	else
	{
		f.password.value = MD5(f.pass1.value); 		
		f.pass1.value="";
		f.pass2.value="";
	}

	if (!f.zgoda.checked)
	{
		alert("Prosze wyrazić zgodę na przetwarzanie danych...");
		f.zgoda.focus();
		return false;
	}

	if (!f.regulamin.checked)
	{
		alert("Prosze zaakceptować regulamin...");
		f.regulamin.focus();
		return false;
	}

	return true;
}



function Kontakt(f)
{
	if (!CheckEMail(f.email.value))
	{
		alert("Prosze podać poprawnie adres e-mail...");
		f.email.focus();
		return false;
	}

	if (!f.imienazw.value)
	{
		alert("Prosze podać imię i nazwisko...");
		f.imienazw.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;
	}

	if (!f.regulamin.checked)
	{
		alert("Prosze zaakceptować regulamin...");
		f.regulamin.focus();
		return false;
	}

	return true;
}

function myDelete(id)
{
	if (confirm("Czy chcesz usunąć ten wpis"))
	{
		pom = document.getElementById("del");
		pom.dlt.value = id;
		pom.submit();
	}
}


function myChange(f)
{
	if (!f.pass1.value || !f.pass2.value || f.pass1.value!=f.pass2.value)
	{
		alert("Hasła nie są zgodne...");
		f.pass1.value="";
		f.pass2.value="";
		f.pass1.focus();
		return false;
	}
	else
	{
		f.password.value = MD5(f.pass1.value); 		
		f.pass1.value="";
		f.pass2.value="";
	}

	return true;
}


function myLogin(f)
{
	if (f.email.value && f.pass.value)
	{
		f.password.value = MD5(f.pass.value); 		
		f.pass.value="";
		return true;
	}
	else
	{
		return false;
	}
}


function CheckEMail(adres)
{
	if (adres.indexOf('@') == -1)
		return false;
	if (adres.length < 4)
		return false;
	if (adres.indexOf('@') != adres.lastIndexOf('@'))
		return false;
	if (adres.indexOf(' ') != -1)
		return false;
	return true;
}




function addBookmark(title,url) 
{
	if (window.sidebar)
		window.sidebar.addPanel(title, url,"");
	else if( document.all )
		window.external.AddFavorite( url, title);
	else
		return true;
}

function mywrite(flash)
{
	document.write(flash)
}



function xstooltip_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 xstooltip_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;
}



var pom;
var topen = false;
function tooltip_show(parentId, occ_d, occ_m, occ_y, im, cl)
{
	window.clearTimeout(pom);
	func = "tooltip_show2('"+parentId+"', "+occ_d+", "+occ_m+", "+occ_y+", '"+im+"', '"+cl+"')";
	pom = window.setTimeout(func,200);
	topen = true;
}

function tooltip_clear()
{
	topen = false;
}


function tooltip_hide()
{
	if (topen)
	{
		window.clearTimeout(pom);
		window.setTimeout("tooltip_hide2()",200);
		topen = false;
	}
}


function tooltip_show2(parentId, occ_d, occ_m, occ_y, im, cl)
{
	 tooltip_hide2();
	 topen = false;
	 
	var tooltipId = "tooltip";
	var tooltipId2 = "tooltip2";
	var posX = 55;
	var posY = 5;
	 
    it = document.getElementById(tooltipId);
    it2 = document.getElementById(tooltipId2);

	
//	alert(it.className);


	if (cl!="") 
		it2.className = cl; 
	else
		it2.className = "tooltip"; 


//	alert(it.className);
//	it.style.visibility = 'hidden'; 

    if ((it.style.top == '' || it.style.top == 0) 
        && (it.style.left == '' || it.style.left == 0))
    {
        // need to fixate default size (MSIE problem)
        it.style.width = it.offsetWidth + 'px';
        it.style.height = it.offsetHeight + 'px';
        
        img = document.getElementById(parentId); 
    	

if (document.body.clientWidth)
	szerokosc_okna = document.body.clientWidth;
else
	szerokosc_okna = window.innerWidth;



		// if tooltip is too wide, shift left to be within parent 
//        if (posX + it.offsetWidth > img.offsetWidth) posX = img.offsetWidth - it.offsetWidth;
//        if (posX < 0 ) posX = 0; 
        
		x = xstooltip_findPosX(img) + posX;
        y = xstooltip_findPosY(img) + posY;

//		alert(posX + " "+ x + " "+posY + " " + y)
		
//		alert(it.style.top + ' ' + it.style.left);

//		if (x+)

//alert(szerokosc_okna + " " + it.offsetWidth + " " + x);
		it.style.visibility = 'visible';
		
		if (it.offsetWidth+x > szerokosc_okna )
		{
			it.style.left = (x - it.offsetWidth - posX +10) + "px";
//			alert(it.style.left);
			it2.className = "tooltipr "+cl;

//			alert("za szeroko");
		}
		else
		{
	        it.style.left = x + 'px';
		}

		it.style.top = y + 'px';
//		alert(it.className +" - "+ it2.className);
}
    


	if (document.getElementById("add"))
	{
		it2.className = cl; 
//		alert(it.className);
		document.getElementById('date').innerHTML = occ_d +"." + occ_m +"."+ occ_y;
	    document.getElementById("occ_d").value = occ_d;
	    document.getElementById("occ_m").value = occ_m;
		document.getElementById("occ_y").value = occ_y;
		document.getElementById("occasion").focus();
	}

	if (document.getElementById("imieniny"))
	{
		document.getElementById('imieniny').innerHTML = im;
	}

}



function tooltip_hide2()
{
    it = document.getElementById("tooltip"); 
    it.style.visibility = 'hidden'; 
	it.style.top = '';
	it.style.left = '';
	it.style.width = '';
	it.style.height = '';
	if (document.getElementById("add"))
		document.getElementById("add").reset();
}
