	var v;

	$(function() {
		$('.password').pstrength();
		$('.accounttype').click(function (){ companyAccount(); });
	});
	
	function companyAccount()
	{
		if(document.getElementById('accounttype2').checked) {
			$('#companyAccount').slideDown('slow');
			validateFirm();
		} else {
			$('#companyAccount').slideUp('slow');
			validateUser();
		}
	}
	
	function checkPass()
	{		
		if($('#pass1').val() == $('#pass2').val())
			$('#okico').css("display","block");
	}
	
	function validateFirm()
	{
		if(document.getElementById('firmCountry').options[document.getElementById('firmCountry').selectedIndex].value==1)	//polska
			var myFields = {
				'firstName':{'l':'Imię','r':true,'f':'alphanum','t':'firstNameLabel'},
				'lastName':{'l':'Nazwisko','r':true,'f':'alphanum','t':'lastNameLabel'},
				'emailAddress':{'l':'Adres e-mail','r':true,'f':'email','t':'emailAddressLabel'},
				'firmNip':{'l':'Numer NIP','r':true,'f':'alphanum','t':'firmNipLabel'},
				'firmName':{'l':'Nazwa firmy','r':true,'f':'alphanum','t':'firmNameLabel'},
				'firmAddress':{'l':'Adres','r':true,'f':'alphanum','t':'firmAddressLabel'},
				'firmZip':{'l':'Miasto','r':true,'f':'alphanum','t':'firmZipLabel'},
				'firmPhoneNumber':{'l':'Miasto','r':true,'f':'alphanum','t':'firmPhoneNumberLabel'},
				'firmCity':{'l':'Miasto','r':true,'f':'alphanum','t':'firmCityLabel'}
			}
		else
			var myFields = {
				'firstName':{'l':'Imię','r':true,'f':'alphanum','t':'firstNameLabel'},
				'lastName':{'l':'Nazwisko','r':true,'f':'alphanum','t':'lastNameLabel'},
				'emailAddress':{'l':'Adres e-mail','r':true,'f':'email','t':'emailAddressLabel'},
				'firmName':{'l':'Nazwa firmy','r':true,'f':'alphanum','t':'firmNameLabel'},
				'firmAddress':{'l':'Adres','r':true,'f':'alphanum','t':'firmAddressLabel'},
				'firmZip':{'l':'Miasto','r':true,'f':'alphanum','t':'firmZipLabel'},
				'firmPhoneNumber':{'l':'Miasto','r':true,'f':'alphanum','t':'firmPhoneNumberLabel'},
				'firmCity':{'l':'Miasto','r':true,'f':'alphanum','t':'firmCityLabel'}
			}
																												
		o_config = {
		  'to_disable' : ['Submit'],
		  'alert' : 1
		}
		
		v = new validator('register_user_form', myFields, o_config);
	}
	
	function validateUser()
	{
		var myFields = {
			'firstName':{'l':'Imię','r':true,'f':'alphanum','t':'firstNameLabel'},
			'lastName':{'l':'Nazwisko','r':true,'f':'alphanum','t':'lastNameLabel'},
			'emailAddress':{'l':'Adres e-mail','r':true,'f':'email','t':'emailAddressLabel'}
		}
																												
		o_config = {
		  'to_disable' : ['Submit'],
		  'alert' : 1
		}
		
		v = new validator('register_user_form', myFields, o_config);
	}
	
	function validationPass()
	{
		if($('#pass1').val().length<6)
		{
			alert('Podane hasło ma za mało znaków!');
			return false;
		}
		
		if($('#pass1').val() != $('#pass2').val())
		{
			alert('Podane hasła są różne!');
			return false;
		}
		
		return true;
	}
	
	function checkRules()
	{
		if(!document.getElementById('rules').checked)
		{
			alert('Aby dokonać rejestracji, należy zaakceptować warunki rezerwacji!');
			return false;
		}
			
		return true;
	}
	
	function registerUser()
	{		
		$.post("/ajax/userloginserver/register",{ 
				emailAddress: $("#emailAddress").val(),
				password: $("#pass1").val(),
				firstName: $("#firstName").val(),
				lastName: $("#lastName").val(),
				address: $("#address").val(),
				country: $("#country").val(),
				city: $("#city").val(),
				zip: $("#zip").val(),
				firmPhoneNumber: $("#firmPhoneNumber").val(),
				firmCountry: $("#firmCountry").val(),
				firmName: $("#firmName").val(),
				firmAddress: $("#firmAddress").val(),
				firmCity: $("#firmCity").val(),
				firmZip: $("#firmZip").val(),
				firmPhoneNumber: $("#firmPhoneNumber").val(),
				firmFaxNumber: $("#firmFaxNumber").val(),
				firmNip: $("#firmNip").val()
			},
			function(data){
				$("#registerbox").html(data);
			});
			
		return false;
	}
	
	validateUser();