window.onload = function() {
	external_links();
	popup_init();
}

/** 
 * external links, v.1.0
 * ustawienie \target="_blank"\ dla wszystkich linkow zawierajacych \rel="external"\
*/
function external_links() {
	if (!document.getElementsByTagName) {return false;}
	var anchors = document.getElementsByTagName("a");
	for (var i=0; i<anchors.length; i++)
		if (anchors[i].getAttribute("href") && anchors[i].getAttribute("rel") == "external")
			anchors[i].target = "_blank";
}

/** 
 * popup, v.1.0
 * dla linków z klasą "pupup" otwiera zdjęcie lub stronę w nowym oknie, ustala jego wielkość z tagu "rel"
*/
function popup_init()
{
	if (!document.getElementsByTagName) {return false;}
	var anchors = document.getElementsByTagName('a');
	for(i=0; i<anchors.length; i++)
		if (anchors[i].className == 'popup')
			anchors[i].onclick = popup;
	return true;
}
function popup()
{
	var size = this.getAttribute('rel');
	var url = this.getAttribute('href');
	if (/png|gif|jpg|jpe|jpeg/.exec(this.href)) 
		var img = true;

	/* computes dimensions passed from "rel" tag; format: <width>x<height>, output: width=<width>,height=<height> */
	if (size) {
		size = size.split('x');
		popup_size = 'width='+size[0]+',height='+size[1];
	}
	else {
		var popup_size = 'width=640,height=480';
	}

	/* window options */
	var win_options = 'dependent=1,resizable=1,scrollbars=0,location=0,menubar=0,statusbar=0,'+popup_size;

	/* creates new window */
  if (win = window.open(this.href,'_blank',win_options)) {
		if (img) {
			var imgs = this.getElementsByTagName('img');
			if (imgs[0]) {
				var title = imgs[0].getAttribute('title');
				var alt = imgs[0].getAttribute('alt');
			}
			else {
				var title = this.getAttribute('title');
				var alt = title;
			}
			win.document.open();
			win.document.write('<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">');
			win.document.write('<html xmlns="http://www.w3.org/1999/xhtml">');
			win.document.write('<head><title>'+title+'</title>');
			win.document.write('<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />');
			win.document.write('<style type="text/css">body {margin:0; padding:0; background:#fff;}</style>');
			win.document.write('</head><body>');
			win.document.write('<img src="'+this.href+'" alt="'+alt+'" title="'+title+'" onclick="window.close()" />');
			win.document.write('</body></html>');
			win.document.close();
		}
		return false;
  }
	
  /* follows link on failure */
	return true; 
}

function checkContactForm(form)
{
    if (form.message.value.length<1)
    {
        alert("Proszę wypełnić pole 'Treść pytania'.");
        return false;
    }

    if ((form.name.value.length<1))
    {
        alert("Proszę wypełnić pole 'Imię i nazwisko'.");
        return false;
    }
    if ((form.phone.value.length<1) && (form.email.value.length<1))
    {
        alert("Proszę wypełnić pole 'Telefon' lub pole 'Email'.");
        return false;
    }

    return true;
}


function showPic(picfile)
{
    win=window.open("","corsario","width=500,height=200,scrollbars=no,titlebar=no,toolbar=no,location=no,menubar=no,status=no");
    win.moveTo(0,0);
    win.document.close();
    win.document.open();
    win.document.write('<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">');
    win.document.write('<html xmlns="http://www.w3.org/1999/xhtml"><head>');
    win.document.write('<meta http-equiv="content-type" content="text/html; charset=ISO-8859-2" />');
    win.document.write("<title>wooden.pl</title>");
    win.document.write("<style type='text/css'>");
    win.document.write("#ha1 {position: absolute; width: 500px; height: 200px; padding-top: 60px; background-color: #fff; text-align: center; font-size: 18px; font-family: Tahoma, Verdana, Arial, Helvetica, sans-serif;}");
    win.document.write("body {background-color: #fff; margin: 0; padding: 0; overflow: hidden;}");
    win.document.write("img {position: absolute; left: 10px; top: 10px; border: 0; padding: 0; margin: 0; overflow: hidden; display: block; cursor: pointer;}");
    win.document.write("</style>");
    win.document.write("</head>");
    win.document.write("<body>");
    win.document.write("<img src='"+picfile+"' alt='' onload='this.style.top=\"10px\"; document.getElementById(\"ha1\").style.display=\"none\"; window.self.resizeTo(this.width+30, this.height+70); window.self.moveTo(Math.round((screen.availWidth-this.width)/2), Math.round((screen.availHeight-this.height)/2));' onclick='window.self.close();' />");
    win.document.write("<div id='ha1'>trwa ładowanie zdjęcia...<br />copyright &copy; 2006 wooden.pl</div>");
    win.document.write("</body></html>");
    win.focus();
    win.document.close();
}
