$().ready(function() {
	$("#rejForm").validate({
		rules: {
			nick: {
				required: true,
				minLength: 3,
				maxLength: 15
			},
			imie: {
				required: true,
				minLength: 3,
				maxLength: 15
			},
			nazwisko: {
				required: true,
				minLength: 3,
				maxLength: 20
			},
			miasto: {
				required: true,
				minLength: 3,
				maxLength: 25
			},
			haslo: {
				required: true,
				minLength: 4,
				maxLength: 12
			},
			phaslo: {
				required: true,
				minLength: 4,
				maxLength: 12,
				equalTo: "#haslo"
			},
			email: {
				required: true,
				email: true
			},
			pemail: {
				required: true,
				email: true,
				equalTo: "#email"
			},
			aregulamin: {
				required: true
			}
		},
		messages: {
			nick: {
				required: "Proszę wprowadzić nazwę użytkownika",
				minlength: "Nazwa użytkownika musi zawierać min 3 znaki",
				maxlength: "Nazwa użytkownika może zawierać max 15 znaków"
			},
			imie: {
				required: "Proszę wprowadzić Imię",
				minlength: "Imię musi zawierać min 3 znaki",
				maxlength: "Imię może zawierać max 15 znaków"
			},
			nazwisko: {
				required: "Proszę wprowadzić Nazwisko",
				minlength: "Nazwisko musi zawierać min 3 znaki",
				maxlength: "Nazwisko może zawierać max 20 znaków"
			},
			miasto: {
				required: "Proszę wprowadzić Miasto",
				minlength: "Miasto musi zawierać min 3 znaki",
				maxlength: "Miasto może zawierać max 25 znaków"
			},
			haslo: {
				required: "Proszę wprowadzić hasło",
				minlength: "Hasło musi zawierać min 4 znaki",
				maxlength: "Hasło może zawierać max 12 znaków"
			},
			phaslo: {
				required: "Proszę wprowadzić hasło",
				minlength: "Hasło musi zawierać min 4 znaki",
				maxlength: "Hasło może zawierać max 12 znaków",
				equalTo: "Hasła nie zgadzają się"
			},
			email: "Proszę podać poprawny email",
			pemail: {
				email: "Proszę podać poprawny email",
				equalTo: "Podane adresy nie zgadzają się"
			},
			aregulamin: {
				required: "Akceptacja wymagana"
			}
		}
	});

	$("#phForm").validate({
		rules: {
			email: {
				required: true,
				email: true
			}
		},
		messages: {
			email: "Proszę podać poprawny email"
		}
	});

	$("#zmhForm").validate({
		rules: {
			stareh: {
				required: true,
				minLength: 4,
				maxLength: 12
			},
			noweh: {
				required: true,
				minLength: 4,
				maxLength: 12
			},
			pnoweh: {
				required: true,
				minLength: 4,
				maxLength: 12,
				equalTo: "#noweh"
			}
		},
		messages: {
			stareh: {
				required: "Proszę wprowadzić hasło",
				minlength: "Hasło musi zawierać min 4 znaki",
				maxlength: "Hasło może zawierać max 12 znaków"
			},
			noweh: {
				required: "Proszę wprowadzić hasło",
				minlength: "Hasło musi zawierać min 4 znaki",
				maxlength: "Hasło może zawierać max 12 znaków"
			},
			pnoweh: {
				required: "Proszę wprowadzić hasło",
				minlength: "Hasło musi zawierać min 4 znaki",
				maxlength: "Hasło może zawierać max 12 znaków",
				equalTo: "Hasła nie zgadzają się"
			}
		}
	});

	$("#logowanie-form").validate({
		rules: {
			login: {
				required: true,
				minLength: 3,
				maxLength: 15
			},
			lhaslo: {
				required: true,
				minLength: 4,
				maxLength: 12
			}
		},
		messages: {
			login: {
				required: "Proszę wprowadzić nazwę użytkownika",
				minlength: "Nazwa użytkownika musi zawierać min 3 znaki",
				maxlength: "Nazwa użytkownika może zawierać max 15 znaków"
			},
			lhaslo: {
				required: "Proszę wprowadzić hasło",
				minlength: "Hasło musi zawierać min 4 znaki",
				maxlength: "Hasło może zawierać max 12 znaków"
			}
		}
	});
});



// ----------------------------------------------------------------------------
// markItUp!
// ----------------------------------------------------------------------------
// Copyright (C) 2008 Jay Salvat
// http://markitup.jaysalvat.com/
// ----------------------------------------------------------------------------
// BBCode tags example
// http://en.wikipedia.org/wiki/Bbcode
// ----------------------------------------------------------------------------
// Feel free to add more tags
// ----------------------------------------------------------------------------
mySettings = {
	previewParserPath:	'', // path to your BBCode parser
	markupSet: [
		{name:'Pogrubienie', openWith:'[b]', closeWith:'[/b]'},
		{name:'Pochylenie', openWith:'[i]', closeWith:'[/i]'},
		{name:'Podkreślenie', openWith:'[u]', closeWith:'[/u]'},
		{separator:'---------------' },
		{name:'Obrazek', replaceWith:'[img][![Url]!][/img]'},
		{name:'Link', openWith:'[url=[![Adres]!] title=[![Tytuł]!]]', closeWith:'[/url]', placeHolder:'Nazwa wyświetlana...'},
		{separator:'---------------' },
		{name:'Rozmiar', openWith:'[size=[![Rozmiar tekstu]!]]', closeWith:'[/size]',
		dropMenu :[
			{name:'Big', openWith:'[size=200]', closeWith:'[/size]' },
			{name:'Normal', openWith:'[size=100]', closeWith:'[/size]' },
			{name:'Small', openWith:'[size=50]', closeWith:'[/size]' }
		]},
		{separator:'---------------' },
		{name:'Lista domyślna', openWith:'[list]\n', closeWith:'\n[/list]'},
		{name:'Lista numeryczna', openWith:'[list=[![Znak lub numer rozpoczęcia]!]]\n', closeWith:'\n[/list]'}, 
		{name:'Punkt listy', openWith:'[*] ', closeWith:'[/*]'},
		{separator:'---------------' },
		{name:'Cytat', openWith:'[quote]', closeWith:'[/quote]'},
		{name:'Cytat z autorem', openWith:'[quote=[![Autor cytatu]!]]', closeWith:'[/quote]', placeHolder:'Cytat...'},
		{name:'Kod', openWith:'[code]', closeWith:'[/code]'}, 
		{separator:'---------------' },
		{	name:'Flagi', 
			className:'flags',  
				dropMenu: [
					{name:'Andorra', openWith:'[ad]', className:"flag-ad" },
					{name:'United Arab Emirates', openWith:'[ae]', className:"flag-ae" },
					{name:'Afghanistan', openWith:'[af]', className:"flag-af" },
					{name:'Antigua and Barbuda', openWith:'[ag]', className:"flag-ag" },
					{name:'Albania', openWith:'[al]', className:"flag-al" },
					{name:'Armenia', openWith:'[am]', className:"flag-am" },
					{name:'Netherlands Antilles', openWith:'[an]', className:"flag-an" },
					{name:'Angola', openWith:'[ao]', className:"flag-ao" },
					{name:'Argentina', openWith:'[ar]', className:"flag-ar" },
					{name:'Austria', openWith:'[at]', className:"flag-at" },
					{name:'Australia', openWith:'[au]', className:"flag-au" },
					{name:'Azerbaijan', openWith:'[az]', className:"flag-az" },
					{name:'Bosnia and Herzegovina', openWith:'[ba]', className:"flag-ba" },
					{name:'Barbados', openWith:'[bb]', className:"flag-bb" },
					{name:'Bangladesh', openWith:'[bd]', className:"flag-bd" },
					{name:'Belgium', openWith:'[be]', className:"flag-be" },
					{name:'Burkina Faso', openWith:'[bf]', className:"flag-bf" },
					{name:'Bulgaria', openWith:'[bg]', className:"flag-bg" },
					{name:'Bahrain', openWith:'[bh]', className:"flag-bh" },
					{name:'Burundi', openWith:'[bi]', className:"flag-bi" },
					{name:'Benin', openWith:'[bj]', className:"flag-bj" },
					{name:'Bermuda', openWith:'[bm]', className:"flag-bm" },
					{name:'Brunei Darussalam', openWith:'[bn]', className:"flag-bn" },
					{name:'Bolivia', openWith:'[bo]', className:"flag-bo" },
					{name:'Brazil', openWith:'[br]', className:"flag-br" },
					{name:'Bahamas', openWith:'[bs]', className:"flag-bs" },
					{name:'Bhutan', openWith:'[bt]', className:"flag-bt" },
					{name:'Botswana', openWith:'[bw]', className:"flag-bw" },
					{name:'Belarus', openWith:'[by]', className:"flag-by" },
					{name:'Belize', openWith:'[bz]', className:"flag-bz" },
					{name:'Canada', openWith:'[ca]', className:"flag-ca" },
					{name:'Central African Republic', openWith:'[cf]', className:"flag-cf" },
					{name:'Congo', openWith:'[cg]', className:"flag-cg" },
					{name:'Switzerland', openWith:'[ch]', className:"flag-ch" },
					{name:'Chile', openWith:'[cl]', className:"flag-cl" },
					{name:'Cameroon', openWith:'[cm]', className:"flag-cm" },
					{name:'China', openWith:'[cn]', className:"flag-cn" },
					{name:'Colombia', openWith:'[co]', className:"flag-co" },
					{name:'Costa Rica', openWith:'[cr]', className:"flag-cr" },
					{name:'Cuba', openWith:'[cu]', className:"flag-cu" },
					{name:'Cyprus', openWith:'[cy]', className:"flag-cy" },
					{name:'Czech Republic', openWith:'[cz]', className:"flag-cz" },
					{name:'District of Columbia', openWith:'[dc]', className:"flag-dc" },
					{name:'Germany', openWith:'[de]', className:"flag-de" },
					{name:'Djibouti', openWith:'[dj]', className:"flag-dj" },
					{name:'Denmark', openWith:'[dk]', className:"flag-dk" },
					{name:'Dominica', openWith:'[dm]', className:"flag-dm" },
					{name:'Algeria', openWith:'[dz]', className:"flag-dz" },
					{name:'Ecuador', openWith:'[ec]', className:"flag-ec" },
					{name:'Estonia', openWith:'[ee]', className:"flag-ee" },
					{name:'Egypt', openWith:'[eg]', className:"flag-eg" },
					{name:'Western Sahara', openWith:'[eh]', className:"flag-eh" },
					{name:'Eritrea', openWith:'[er]', className:"flag-er" },
					{name:'Spain', openWith:'[es]', className:"flag-es" },
					{name:'Ethiopia', openWith:'[et]', className:"flag-et" },
					{name:'European Union', openWith:'[eu]', className:"flag-eu" },
					{name:'Finland', openWith:'[fi]', className:"flag-fi" },
					{name:'Fiji', openWith:'[fj]', className:"flag-fj" },
					{name:'France', openWith:'[fr]', className:"flag-fr" },
					{name:'Gabon', openWith:'[ga]', className:"flag-ga" },
					{name:'United Kingdom', openWith:'[gb]', className:"flag-gb" },
					{name:'Grenada', openWith:'[gd]', className:"flag-gd" },
					{name:'Georgia', openWith:'[ge]', className:"flag-ge" },
					{name:'Ghana', openWith:'[gh]', className:"flag-gh" },
					{name:'Gambia', openWith:'[gm]', className:"flag-gm" },
					{name:'Guinea', openWith:'[gn]', className:"flag-gn" },
					{name:'Equatorial Guinea', openWith:'[gq]', className:"flag-gq" },
					{name:'Greece', openWith:'[gr]', className:"flag-gr" },
					{name:'Guatemala', openWith:'[gt]', className:"flag-gt" },
					{name:'Guinea-Bissau', openWith:'[gw]', className:"flag-gw" },
					{name:'Guyana', openWith:'[gy]', className:"flag-gy" },
					{name:'Hong Kong', openWith:'[hk]', className:"flag-hk" },
					{name:'Honduras', openWith:'[hn]', className:"flag-hn" },
					{name:'Croatia', openWith:'[hr]', className:"flag-hr" },
					{name:'Haiti', openWith:'[ht]', className:"flag-ht" },
					{name:'Hungary', openWith:'[hu]', className:"flag-hu" },
					{name:'Indonesia', openWith:'[id]', className:"flag-id" },
					{name:'Ireland', openWith:'[ie]', className:"flag-ie" },
					{name:'Israel', openWith:'[il]', className:"flag-il" },
					{name:'India', openWith:'[in]', className:"flag-in" },
					{name:'Iraq', openWith:'[iq]', className:"flag-iq" },
					{name:'Iran, Islamic Republic of', openWith:'[ir]', className:"flag-ir" },
					{name:'Iceland', openWith:'[is]', className:"flag-is" },
					{name:'Italy', openWith:'[it]', className:"flag-it" },
					{name:'Jamaica', openWith:'[jm]', className:"flag-jm" },
					{name:'Jordan', openWith:'[jo]', className:"flag-jo" },
					{name:'Japan', openWith:'[jp]', className:"flag-jp" },
					{name:'Kenya', openWith:'[ke]', className:"flag-ke" },
					{name:'Kyrgyzstan', openWith:'[kg]', className:"flag-kg" },
					{name:'Cambodia', openWith:'[kh]', className:"flag-kh" },
					{name:'Kiribati', openWith:'[ki]', className:"flag-ki" },
					{name:'Comoros', openWith:'[km]', className:"flag-km" },
					{name:'Saint Kitts and Nevis', openWith:'[kn]', className:"flag-kn" },
					{name:'Kuwait', openWith:'[kw]', className:"flag-kw" },
					{name:'Cayman Islands', openWith:'[ky]', className:"flag-ky" },
					{name:'Kazakhstan', openWith:'[kz]', className:"flag-kz" },
					{name:'Lao People\'s Democratic Republic', openWith:'[la]', className:"flag-la" },
					{name:'Lebanon', openWith:'[lb]', className:"flag-lb" },
					{name:'Saint Lucia', openWith:'[lc]', className:"flag-lc" },
					{name:'Liechtenstein', openWith:'[li]', className:"flag-li" },
					{name:'Sri Lanka', openWith:'[lk]', className:"flag-lk" },
					{name:'Liberia', openWith:'[lr]', className:"flag-lr" },
					{name:'Lithuania', openWith:'[lt]', className:"flag-lt" },
					{name:'Luxembourg', openWith:'[lu]', className:"flag-lu" },
					{name:'Latvia', openWith:'[lv]', className:"flag-lv" },
					{name:'Libyan Arab Jamahiriya', openWith:'[ly]', className:"flag-ly" },
					{name:'Morocco', openWith:'[ma]', className:"flag-ma" },
					{name:'Monaco', openWith:'[mc]', className:"flag-mc" },
					{name:'Moldova', openWith:'[md]', className:"flag-md" },
					{name:'Madagascar', openWith:'[mg]', className:"flag-mg" },
					{name:'Macedonia, the former Yugoslav Republic of', openWith:'[mk]', className:"flag-mk" },
					{name:'Mali', openWith:'[ml]', className:"flag-ml" },
					{name:'Mongolia', openWith:'[mn]', className:"flag-mn" },
					{name:'Macao', openWith:'[mo]', className:"flag-mo" },
					{name:'Mauritania', openWith:'[mr]', className:"flag-mr" },
					{name:'Malta', openWith:'[mt]', className:"flag-mt" },
					{name:'Mauritius', openWith:'[mu]', className:"flag-mu" },
					{name:'Maldives', openWith:'[mv]', className:"flag-mv" },
					{name:'Malawi', openWith:'[mw]', className:"flag-mw" },
					{name:'Mexico', openWith:'[mx]', className:"flag-mx" },
					{name:'Malaysia', openWith:'[my]', className:"flag-my" },
					{name:'Mozambique', openWith:'[mz]', className:"flag-mz" },
					{name:'Namibia', openWith:'[na]', className:"flag-na" },
					{name:'Niger', openWith:'[ne]', className:"flag-ne" },
					{name:'Nigeria', openWith:'[ng]', className:"flag-ng" },
					{name:'Nicaragua', openWith:'[ni]', className:"flag-ni" },
					{name:'Netherlands', openWith:'[nl]', className:"flag-nl" },
					{name:'Norway', openWith:'[no]', className:"flag-no" },
					{name:'Nepal', openWith:'[np]', className:"flag-np" },
					{name:'Nauru', openWith:'[nr]', className:"flag-nr" },
					{name:'New Zealand', openWith:'[nz]', className:"flag-nz" },
					{name:'Oman', openWith:'[om]', className:"flag-om" },
					{name:'Panama', openWith:'[pa]', className:"flag-pa" },
					{name:'Peru', openWith:'[pe]', className:"flag-pe" },
					{name:'Papua New Guinea', openWith:'[pg]', className:"flag-pg" },
					{name:'Philippines', openWith:'[ph]', className:"flag-ph" },
					{name:'Pakistan', openWith:'[pk]', className:"flag-pk" },
					{name:'Poland', openWith:'[pl]', className:"flag-pl" },
					{name:'Puerto Rico', openWith:'[pr]', className:"flag-pr" },
					{name:'Portugal', openWith:'[pt]', className:"flag-pt" },
					{name:'Paraguay', openWith:'[py]', className:"flag-py" },
					{name:'Qatar', openWith:'[qa]', className:"flag-qa" },
					{name:'Romania', openWith:'[ro]', className:"flag-ro" },
					{name:'Russian Federation', openWith:'[ru]', className:"flag-ru" },
					{name:'Rwanda', openWith:'[rw]', className:"flag-rw" },
					{name:'Saudi Arabia', openWith:'[sa]', className:"flag-sa" },
					{name:'Solomon Islands', openWith:'[sb]', className:"flag-sb" },
					{name:'Seychelles', openWith:'[sc]', className:"flag-sc" },
					{name:'Sudan', openWith:'[sd]', className:"flag-sd" },
					{name:'Sweden', openWith:'[se]', className:"flag-se" },
					{name:'Singapore', openWith:'[sg]', className:"flag-sg" },
					{name:'Slovenia', openWith:'[si]', className:"flag-si" },
					{name:'Slovakia', openWith:'[sk]', className:"flag-sk" },
					{name:'Sierra Leone', openWith:'[sl]', className:"flag-sl" },
					{name:'Senegal', openWith:'[sn]', className:"flag-sn" },
					{name:'Somalia', openWith:'[so]', className:"flag-so" },
					{name:'Suriname', openWith:'[sr]', className:"flag-sr" },
					{name:'Sao Tome and Principe', openWith:'[st]', className:"flag-st" },
					{name:'El Salvador', openWith:'[sv]', className:"flag-sv" },
					{name:'Syrian Arab Republic', openWith:'[sy]', className:"flag-sy" },
					{name:'Chad', openWith:'[td]', className:"flag-td" },
					{name:'Togo', openWith:'[tg]', className:"flag-tg" },
					{name:'Thailand', openWith:'[th]', className:"flag-th" },
					{name:'Tajikistan', openWith:'[tj]', className:"flag-tj" },
					{name:'Turkmenistan', openWith:'[tm]', className:"flag-tm" },
					{name:'Tunisia', openWith:'[tn]', className:"flag-tn" },
					{name:'Tonga', openWith:'[to]', className:"flag-to" },
					{name:'Turkey', openWith:'[tr]', className:"flag-tr" },
					{name:'Trinidad and Tobago', openWith:'[tt]', className:"flag-tt" },
					{name:'Tuvalu', openWith:'[tv]', className:"flag-tv" },
					{name:'Taiwan, Province of China', openWith:'[tw]', className:"flag-tw" },
					{name:'Tanzania, United Republic of', openWith:'[tz]', className:"flag-tz" },
					{name:'Ukraine', openWith:'[ua]', className:"flag-ua" },
					{name:'Uganda', openWith:'[ug]', className:"flag-ug" },
					{name:'United States', openWith:'[us]', className:"flag-us" },
					{name:'Uruguay', openWith:'[uy]', className:"flag-uy" },
					{name:'Uzbekistan', openWith:'[uz]', className:"flag-uz" },
					{name:'Venezuela', openWith:'[ve]', className:"flag-ve" },
					{name:'Viet Nam', openWith:'[vn]', className:"flag-vn" },
					{name:'Vanuatu', openWith:'[vu]', className:"flag-vu" },
					{name:'Yemen', openWith:'[ye]', className:"flag-ye" },
					{name:'South Africa', openWith:'[za]', className:"flag-za" },
					{name:'Zambia', openWith:'[zm]', className:"flag-zm" },
					{name:'Zimbabwe', openWith:'[zw]', className:"flag-zw" }
				]
		},
		{name:'Kolory', 
			className:'colors', 
			openWith:'[color=[![Kolor]!]]', 
			closeWith:'[/color]', 
				dropMenu: [
					{name:'Żółty',	openWith:'[color=yellow]', 	closeWith:'[/color]', className:"col1-1" },
					{name:'Pomarańczowy',	openWith:'[color=orange]', 	closeWith:'[/color]', className:"col1-2" },
					{name:'Czerwony', 	openWith:'[color=red]', 	closeWith:'[/color]', className:"col1-3" },
					
					{name:'Niebieski', 	openWith:'[color=blue]', 	closeWith:'[/color]', className:"col2-1" },
					{name:'Fioletowy', openWith:'[color=purple]', 	closeWith:'[/color]', className:"col2-2" },
					{name:'Zielony', 	openWith:'[color=green]', 	closeWith:'[/color]', className:"col2-3" },
					
					{name:'Biały', 	openWith:'[color=white]', 	closeWith:'[/color]', className:"col3-1" },
					{name:'Szary', 	openWith:'[color=gray]', 	closeWith:'[/color]', className:"col3-2" },
					{name:'Czarny',	openWith:'[color=black]', 	closeWith:'[/color]', className:"col3-3" }
				]
		},
		{separator:'---------------' },
		{name:'Zapisz', className:'save', beforeInsert:function(markItUp) { miu.save(markItUp) } },
        {name:'Załaduj', className:'load', beforeInsert:function(markItUp) { miu.load(markItUp) } }
	]
}

miu = {
    save: function(markItUp) {
        data = markItUp.textarea.value;
        ok = confirm("Zapisać treść?");
        if (!ok) {
            return false;
        }
        $.post(markItUp.root+"../inc/quicksave/save.php", "data="+data, function(response) {
                if(response === "MIU:OK") {
                    alert("Zapisane!");
                }
            }
        );
    },
	
    load: function(markItUp) {
        $.get(markItUp.root+"../inc/quicksave/load.php", function(response) {
                if(response === "MIU:EMPTY") {
                    alert("Brak treści do załadowania");
                } else {
                    ok = confirm("Załadować poprzednio zapisaną treść?");
                    if (!ok) {
                        return false;
                    }
                    markItUp.textarea.value = response;
                    alert("Treść załadowano pomyślnie!");
                }
            }
        );
    }      
}