var useplayer = false;

function check_form( form, lang )
{
	var str = form.email.value;
	var filter= /^([a-zA-Z0-9_.-])+@(([a-zA-Z0-9-])+.)+([a-zA-Z0-9]{2,4})+$/;

if (lang == "pl")
{
	if ((form.imie.value == "") || (form.imie.value == "Imię i nazwisko")) {
		alert("Podaj imię i nazwisko");
		return false;
	}

	if (!filter.test(str)) {
		alert("Podaj e-mail");
		return false;
	}

	if ((form.title.value == "") || (form.title.value == "Tytuł")) {
		alert("Podaj tytuł wiadomości");
		return false;
	}

	if ((form.tresc.value == "") || (form.tresc.value == "Treść wiadomości")) {
		alert("Podaj treść wiadomości");
		return false;
	}
}

if (lang == "en")
{
	if ((form.imie.value == "") || (form.imie.value == "Name and surname")) {
		alert("Please provide name and surname");
		return false;
	}

	if (!filter.test(str)) {
		alert("Please provide valid e-mail address");
		return false;
	}

	if ((form.title.value == "") || (form.title.value == "Title")) {
		alert("Please provide message title");
		return false;
	}

	if ((form.tresc.value == "") || (form.tresc.value == "Message content")) {
		alert("Please provide message content");
		return false;
	}
}

if (lang == "de")
{
	if ((form.imie.value == "") || (form.imie.value == "Name and surname")) {
		alert("Please provide name and surname");
		return false;
	}

	if (!filter.test(str)) {
		alert("Please provide valid e-mail address");
		return false;
	}

	if ((form.title.value == "") || (form.title.value == "Title")) {
		alert("Please provide message title");
		return false;
	}

	if ((form.tresc.value == "") || (form.tresc.value == "Message content")) {
		alert("Please provide message content");
		return false;
	}
}

	return true;
}



function prepareRegulationMenu()
{
	jQuery("#r_menu div a").unbind("click").click(function() {
		jQuery("#r_menu div").removeClass("selected");
		var link = jQuery(this).attr("href");
		jQuery("#sub_reg").load(link);
		var obj = $(this);
		jQuery(obj.parent()).addClass("selected");
		return false;
	});
}

function prepareProductsMenu(popup)
{
	jQuery("div.p_menu div a").unbind("click").click(function() {
  		jQuery("div.p_menu div a").removeClass("produkty_selected");
 		jQuery("div.p_menu div a").addClass("produkty");
  		jQuery(this).removeClass("produkty");
 		jQuery(this).addClass("produkty_selected");

		var obj = jQuery("div.p_menu div a.produkty");
 		jQuery(obj.parent()).stop(true, true).animate({opacity: 0.3}, 200);

		obj = jQuery("div.p_menu div a.produkty_selected");
 		jQuery(obj.parent()).stop(true, true).animate({opacity: 1.0}, 200);

 		var link = jQuery(this).attr("href");
		if (jQuery(obj.parent()).hasClass("p_konturowka") ||
                    jQuery(obj.parent()).hasClass("p_oznakowanie") ||
                    jQuery(obj.parent()).hasClass("p_inne")) {
 			jQuery("div.p_content").load(link, callbackFunction);
			useplayer = true;
		}
                else {
                    jQuery("div.p_content").load(link);
                    useplayer = false;
                }

                if (popup != 'disabled')
                    $("html, body").animate({scrollTop: $("div.p_content").offset().top}, 500, function() {$('a.' + popup).click();});
                else
                    $("html, body").animate({scrollTop: $("div.p_content").offset().top}, 500); 
		
		var img_link = $(this).attr("rel");
		$("div#menu div.banner img:first").attr("src", img_link);

		return false;
	});

	$("div.p_menu div a p").hover(function() {
		var obj = jQuery(this);
		if (obj.parent().hasClass('produkty')) { 		
			jQuery((obj.parent()).parent()).stop(true, true);
			jQuery((obj.parent()).parent()).animate({opacity: 1.0}, 200);
		}
		return false;
	});

	$("div.p_menu div a p").mouseout(function() {
		var obj = jQuery(this);
		if (obj.parent().hasClass('produkty')) { 
			jQuery((obj.parent()).parent()).stop(true, true);
			jQuery((obj.parent()).parent()).animate({opacity: 0.3}, 200);
		}
		return false;
	});
}

function callbackFunction()
{
	jQuery(function(){
		$f("player", "/flowplayer/flowplayer-3.2.2.swf", {
			clip: {
				autoPlay: false, 
				autoBuffering: true // <- do not place a comma here  
			}			
		});
                
	});
}

function prepareProductsPopup()
{
	jQuery("div.p_content div.p_c_img a").unbind("click").click(function() {

 		var link = jQuery(this).attr("href");
		jQuery("div#popup").load(link);
		jQuery("div#zciemnienie").css({'display': 'block'});
		jQuery("div#zciemnienie").stop(true, true);
		jQuery("div#zciemnienie").animate({opacity: 0.8}, 200);
		jQuery("div#popup").css({'display': 'block'});
		jQuery("div#popup_close").css({'display': 'block'});

		if (useplayer == true)
			$f().hide();
		return false;
	});

	jQuery("div#popup_close").unbind("click").click(function() {

		jQuery("div#zciemnienie").stop(true, true);
		jQuery("div#zciemnienie").animate({opacity: 0.0}, 200);
		jQuery("div#zciemnienie").css({'display': 'none'});
		jQuery("div#popup_close").css({'display': 'none'});
		jQuery("div#popup").css({'display': 'none'});
		if (useplayer == true)
			$f().show();
		return false;
	});

}

function preparePlayer()
{
	jQuery(function() {
		$f("player", "/flowplayer/flowplayer-3.2.2.swf", {
			clip: {
				autoPlay: false, 
				autoBuffering: true // <- do not place a comma here  
			}			
		});
                
	});
}

function prepareForm(lang)
{
	if (lang == "pl") {
		jQuery("input.kontakt").unbind("click").click(function() {
			if ((this.value == "Imię i nazwisko") || (this.value == "Twój e-mail") || (this.value == "Tytuł")) {
				this.value = "";
			}
			return false;
		});
		jQuery("textarea.kontakt").unbind("click").click(function() {
			if (this.value == "Treść wiadomości") {
				this.value = "";
			}
			return false;
		});
	}

	if (lang == "en") {
		jQuery("input.kontakt").unbind("click").click(function() {
			if ((this.value == "Name and surname") || (this.value == "E-mail address") || (this.value == "Title")) {
				this.value = "";
			}
			return false;
		});
		jQuery("textarea.kontakt").unbind("click").click(function() {
			if (this.value == "Message content") {
				this.value = "";
			}
			return false;
		});
	}

	if (lang == "de") {
		jQuery("input.kontakt").unbind("click").click(function() {
			if ((this.value == "Name and surname") || (this.value == "E-mail address") || (this.value == "Title")) {
				this.value = "";
			}
			return false;
		});
		jQuery("textarea.kontakt").unbind("click").click(function() {
			if (this.value == "Message content") {
				this.value = "";
			}
			return false;
		});
	}


}

function showWest()
{
	$("div.mapa_flash div.right p.east").addClass("hidden");
	$("div.mapa_flash div.right p.west").removeClass("hidden");
}

function showEast()
{
	$("div.mapa_flash div.right p.west").addClass("hidden");
	$("div.mapa_flash div.right p.east").removeClass("hidden");
}

