jQ(document).ready(function() {
	jQ("#signInForm").submit(function(ev,ui){
		ev.preventDefault();		
		data = {
				tx_voputilities_pi1: ({
					username : jQ.trim(jQ("#user_email").val()),
					password : jQ.trim(jQ("#user_password").val()),
					ref_object : jQ.trim(jQ("#ref_object").val()),
					code : "ajax_do_login"
				})
			};
		if(jQ("#check").attr("checked")){
			data.tx_voputilities_pi1.remember = 1;
		}
		jQ('<div/>', {id: 'authDiv',text:LABEL_WAITING_AUTH}).insertAfter(jQ("#submitBtn").parent());
		jQ("#submitBtn").parent().hide();		
		
		jQ.post(document.location.protocol+"//"+document.location.host + '/index.php?id='+jQ("#current_page_id").val()+'&type=8200',data,function(answer){
			try{
				var objJson = jQ.parseJSON(answer);
				if(objJson.error){
					jQ('#authDiv').remove();
					jQ("#submitBtn").parent().show();					
					alert(objJson.err_message);
				}else{
					if(objJson.redirect_url){						
						document.location = objJson.redirect_url;  
					}else{
						document.location = document.location;
					}
				}
			}catch(e){
				alert("Server Error");
			}
		})
	});
});
