jQuery(document).ready(function($){
	if($("#contactsForm").length > 0 ){
		$("#contactsForm input[name=arrival]").datepicker();
		$("#contactsForm").submit(function(evt){
			//remove error from fields
			var re_text = /^.{3,}$/;
			var re_mail = /^[a-z0-9._+-]+@[a-z0-9._+-]{3,}\.[a-z.]{2,6}$/;
			var re_telephone = /^[0-9a-zA-Z .#+-]{5,20}$/;
			var re_date = /^\d{2}\/\d{2}\/\d{4}$/;
			var error = false;
			$("#contactsForm .error").removeClass("error");
			if(!re_text.test($("#contactsForm input[name=name]")[0].value)){
				$("#contactsForm input[name=name]").addClass('error');
				error |= true;
			}
			if(!re_text.test($("#contactsForm input[name=surname]")[0].value)){
				$("#contactsForm input[name=surname]").addClass('error');
				error |= true;
			}
			if(!re_mail.test($("#contactsForm input[name=email]")[0].value.toLowerCase())){
				$("#contactsForm input[name=email]").addClass('error');
				error |= true;
			}
			if(!re_mail.test($("#contactsForm input[name=email-retype]")[0].value.toLowerCase())){
				$("#contactsForm input[name=email-retype]").addClass('error');
				error |= true;
			}
			if($("#contactsForm input[name=email-retype]")[0].value.toLowerCase() != $("#contactsForm input[name=email]")[0].value.toLowerCase()){
				$("#contactsForm input[name=email-retype]").addClass('error');
				error |= true;
			}
			if(!re_telephone.test($("#contactsForm input[name=telephone]")[0].value.toLowerCase())){
				$("#contactsForm input[name=telephone]").addClass('error');
				error |= true;
			}
			if(!re_text.test($("#contactsForm textarea[name=reason]")[0].value)){
				$("#contactsForm textarea[name=reason]").addClass('error');
				error |= true;
			}
			if(!$("#contactsForm input[name=privacy]").is(':checked')){
				$("#contactsForm input[name=privacy]").parent().addClass('error');
				error |= true;
			}
			$("#contactsForm input[name=js]")[0].value = 1;
			if(error){
				$("#dialog").dialog({
					//bgiframe: true,
					modal: true,
					resizable: false,
					draggable: false,
					buttons: {
						Ok: function() {
							$(this).dialog('destroy');
						}
					}
				});
		
				evt.preventDefault();
			}
		});
	}
	//re_lang = /https?:\/\/[^\/]+\/([^\/]+)\/.*/;
	//reg_result = re_lang.exec(window.location.href);
	//if(reg_result != null && reg_result[1] != ''){
	//	SelectSetValue($("#selectLanguage")[0], reg_result[1]);
	//}
	//
	//$("#selectLanguage").change(function(e){
	//	window.location.href = '/'+$("#selectLanguage option:selected")[0].value+'/';
	//});
});
