$().ready(function() {
	// validate the comment form when it is submitted

	/*$.validator.addMethod(
		'key_count',
		function(value, element) {
			var key_string = $('#keys').val();
			var key_array = key_string.split("\n");
			var keys = new Array();

			if (key_string.length == 0)
				return false;

			for (var i=0; i<key_array.length; i++) {
				if (key_array[i] != '') {
					keys[keys.length] = key_array[i];
				}
			}

			if (keys.length < 10 || keys.length > 50)
				return false;

			return true;
		},
		'Необходимо ввести ключевые слова &mdash; всего не менее 10 и не более 50 слов!'
	);*/

	// validate signup form on keyup and submit
	$('#checkForm').validate({
		rules: {
			name: 'required',
			email: {
				required: true,
				email: true
			},
			site: {
				required: true,
				url: true
			}/*,
			keys: {
				//required: true,
				key_count: true
			}*/
		},
		messages: {
			name: 'Введите Ваше имя.',
			email: 'Введите правильный E-Mail',
			site: 'Введите корректный адрес сайта'
		}
	});

	// propose username by combining first- and lastname

	//code to hide topic selection, disable for demo
	var newsletter = $("#newsletter");
	// newsletter topics are optional, hide at first
	var inital = newsletter.is(":checked");
	var topics = $("#newsletter_topics")[inital ? "removeClass" : "addClass"]("gray");
	var topicInputs = topics.find("input").attr("disabled", !inital);
	// show when newsletter is checked
	newsletter.click(function() {
		topics[this.checked ? "removeClass" : "addClass"]("gray");
		topicInputs.attr("disabled", !this.checked);
	});
});

