$(function(){
	
$('#fa_cont li p').each(function(){
	var inalt = -$(this).height() / 2;
	$(this).css({
		'margin-top': inalt + 1,
		'position'	: 'relative',
		'top'		: 19
	});
});
$('#fa_cont input:first').focus();
$('#fa_cont li.alt').addClass('check');

$('.check').click(function(e){
	e.stopImmediatePropagation();
	if (e.target.nodeName != "A") {
		if ($(this).find('label').hasClass('checked')) {
			$(this).find('label').removeClass('checked');
			$(this).find('input').removeAttr('checked');
		}
		else {
			$(this).find('label').addClass('checked');
			$(this).find('input').attr('checked', 'checked');
		}
	}
	if(e.target.nodeName == "LABEL" || e.target.nodeName == "INPUT")
		return false;
});

	$("#fa_cont").validate({
		errorElement: "span",
   		errorClass: "err",
		submitHandler: function(form) {
			$(form).ajaxSubmit(function(data){
				if(data == "ok"){
					$('#inregistrare_ok').modal({
						closeHTML: ('<a class="modal_inchide" href="#" title="&Icirc;nchide (ESC)"></a>'),
						opacity: 87,
						overlayCss: {
							opacity: .87,
							background: 'url(assets/img/overlay.png)'
						},
						containerCss: {
							width: 479,
							height: 279,
							padding: '0',
							backgroundColor: 'transparent'
						},
						onClose: function(){
							$.modal.close();
						}
					});
				}else{
					$('#inregistrare_bad').modal({
						closeHTML: ('<a class="modal_inchide" href="#" title="&Icirc;nchide (ESC)"></a>'),
						opacity: 87,
						overlayCss: {
							opacity: .87,
							background: 'url(assets/img/overlay.png)'
						},
						containerCss: {
							width: 479,
							height: 279,
							padding: '0',
							backgroundColor: 'transparent'
						},
						onClose: function(){
							$.modal.close();
						}
					});
				}
			});
	   	},
		rules: {
			email: {
				required: true,
				email: true,
				remote: {
					url: "signup.php?action=check_email",
					type: "post"
				}
			},
			password: {
				required: true,
				minlength: 6
			},
			password_confirm: {
				equalTo: "#password"
			},
			company_name: {
				required:true
			},
			captcha: {
				required: true,
				remote: "signup.php?action=process"
			},
			agree_to_terms: {
				required:true
			}
		},
		messages: {
			email : {
				required : "Trebuie introdus&#259; adresa de e-mail. Cu aceasta  te vei autentifica.",
				email : "Adresa de e-mail nu este corect&#259;.Verific&#259; te  rog &icirc;nc&#259; odat&#259;.",
				remote : "Aceast&#259; adres&#259; de e-mail exist&#259; deja &icirc;n baza  de date."
			},
			password : {
				required : "Pentru a crea un cont este absolut necesar &#351;i o  parol&#259;. Logic.",
				minlength : "Pentru a asigura un minim de protec&#355;ie, e  necesar ca parola s&#259; fie compus&#259; din minim 6 caractere."
			},
			password_confirm : {
				equalTo : "Parola introdus&#259; aici nu chiar corespunde cu  cea introdus&#259; anterior."
			},
			company_name : {
				required : "Pentru a te &icirc;nregistra trebuie introdus &#351;i  numele companiei."
			},
			captcha: {
				required : "Introduce&#355;i corect codul de securitate din imaginea al&#259;turat&#259;"	
			},
			agree_to_terms : {
				required : "Pentru a putea face publicitate &icirc;n re&#355;eaua Status Pimp este  nevoie s&#259; fi de acord cu termenii &#351;i condi&#355;iile de utilizare."
			}
		},
		errorPlacement: function(error, element) {
			if(element.attr("name")=="agree_to_terms"){
				error.css({'display':'block',"clear":"both","marginLeft":"-153px"}).insertAfter($("#agree_to_terms_label"));
			}else{
				$(element).parent().parent().addClass('err');
				$(element).parent().parent().append(error);
			}
		},
		onkeyup: false
	});
	
	$('#fa_cont input').each(function(){
		$(this).blur(function(){
			if( $('#fa_cont').validate().element($(this)) ) {
				$(this).parent().parent().removeClass('err');
			}
		});
	});

	
});