$(document).ready(function(){
	$(".long").parent().addClass("long");

/* SLIDE PRZY SZUKANIU */
	$(".advanced").click(function(){
		$(".moreOptions").slideToggle();
	});
	
	$(".sendRelease").click(function(){
		$(".mailtoFriend").slideToggle();
	});

/* WALIDACJA PRZY REJESTRACJI */
	var ident = $("body").attr("id");

	if (ident==="PressRegister") {
		$.validator.addMethod('myphone', function(value) {
			return value.match(/^[0-9 \+]*$/);
		});
		
		$.validator.addMethod('bracket', function(value) {
			return !value.match(/[<>]/);
		});
		
		var v = $("#regform").validate({
			onkeyup: false,
			onblur: false, 
			rules: { 
				first_name: {
					required: true,
					bracket: true
				},
				surname: {
					required: true,
					bracket: true
				},
				editors_office: {
					bracket: true,
					required: true
				},
				password: {
					required: true, 
					minlength: 5
				}, 
				password2: {
					required: true, 
					minlength: 5, 
					equalTo: "#password" 
				}, 
				mail: {
					required: true, 
					email: true
				},
				telephone: {
					myphone: true,
					required: true
				},
				telephone2: { 
					myphone: true
				},
				agree: "required",
				agree2: "required"
			}, 
			messages: { 
				first_name: {
					required: "Podaj imię",
					bracket: "Pole zawiera niepoprawny znak"
				}, 
				surname:  {
					required: "Podaj nazwisko",
					bracket: "Pole zawiera niepoprawny znak"
				},
				editors_office: {
					bracket: "Pole zawiera niepoprawny znak",
					required: "Pole jest wymagane"
				},
				password: { 
					required: "Podaj hasło", 
					minlength: jQuery.format("Podaj przynajmniej {0} znaków") 
				}, 
				password2: { 
					required: "Powtórz hasło", 
					minlength: jQuery.format("Podaj przynajmniej {0} znaków"), 
					equalTo: "Hasła nie zgadzają się" 
				}, 
				mail: { 
					required: "Podaj adres e-mail", 
					email: "Adres jest niepoprawny"
				},
				telephone: {
					myphone: 'Pole zawiera niepoprawny znak. Proszę użyć cyfr, spacji lub znaku "+"',
					required: "Pole jest wymagane"
				},
				telephone2: {
					myphone: 'Pole zawiera niepoprawny znak. Proszę użyć cyfr, spacji lub znaku "+"'
				},
				agree: " " ,
				agree2: " " 
			}, 
			// the errorPlacement has to take the table layout into account 
			errorPlacement: function(error, element) { 
				if (element.is(":checkbox")) { 
					error.appendTo(element.parent());
					$(element.parent().parent()).addClass("errorColor");
				} else { 
					error.appendTo(element.next());
				}
			}
		});
		
		$("#PressRegisterForm button.type_6").click(function() {
			if (v.form()) { 
				$(".errorColor").removeClass("errorColor");
			}
		});
	}
/* /\/\/\ */
/* USUWANIE KONTA */
	$(".confirmDelete").click(function(){
		var form = $(this).parents("form");
		var action = form.attr("action");
		form.attr("action",action+"?deleteAccount=true");
		
		$(this).fadeOut(function(){
			$(".deleteMyAccount").fadeIn();
		});
	});
	
	$(".cancelDelete").click(function(){
		var form = $(this).parents("form");
		var action = form.attr("action").split("?");
		form.attr("action",action[0]);
		
		$(".deleteMyAccount").fadeOut(function(){
			$(".confirmDelete").fadeIn();
		});
	});
	
/* TABELKA */
	var table = $(".staticC table");
	table.find("tr:eq(0) td").addClass("firstRow");
	table.find("tr:gt(0) td:first-child").addClass("firstCol");
	table.find("tr:gt(0) td:last-child").addClass("lastCol");
	//table.find("tr:eq(0) td:first-child").addClass("zeroCell");
/* /\/\/\ */
});

