/**
 *
 * @access public
 * @return void
 **/ // wykonanie platności
function Platnosci(ses_id,amount){	$('#error').html('<span style="color: #FFFFFF;">Przetwarzanie...</span>');    //alert(ses_id);	$.post('/panel/interface/auth.php?req=Platnosc', {"ses_id" : ses_id , "amount" : amount},function(data) {		$('#error').html('<span style="color: #FFFFFF;">Przejscie do platnosci.pl...</span>');			var obj = $.json.decode(data);	        if (obj.passed == 1) {			   document.forms["payform"].submit();	        }else{			    $('#error').html('<span style="color: #FFFFFF;"> Błąd weryfikacji faktury... </span>');			}	});	//$.post('https://www.mobilna-faktura.pl/panel/interface/auth.php?req=Platnosc', {"ses_id" : ses_id , "amount" : amount}, PlatnosciResult);	//$.post('https://www.mobilna-faktura.pl/panel/interface/auth.php?req=Platnosc', {"ses_id" : ses_id , "amount" : amount}, PlatnosciResult);}function login(u,p) {	$('#error').html('<span style="color: #FFFFFF;">logowanie ...</span>');	$.post('https://www.mobilna-faktura.pl/panel/do-login.php', {'user':u, 'password':p}, function(){		$.post('https://www.mobilna-faktura.pl/panel/interface/auth.php?req=login', {"user": u, "password" : hex_md5(p)}, loginResult);	});}function logout() {	$.post('interface/auth.php?req=logout', function() {location.href='../index.html';});}function loginToken(u,p) {	$('#error').html('<span style="color: #FFFFFF;">logowanie ...</span>');		$.post('https://www.mobilna-faktura.pl/panel/do-login.php',{'user':u, 'password':p},  function() {	     	   //location.href='../index.html';	   $.post('https://www.mobilna-faktura.pl/panel/interface/auth.php?req=login', {"user": u, "password" : hex_md5(p)}, loginResult);	   }	);	/*	$.post('https://www.mobilna-faktura.pl/panel/do-login.php', {'user':u, 'password':p}, function(){	  	    $('#error').html('<span style="color: #FFFFFF;">logowanie 2...</span>');		$.post('https://www.mobilna-faktura.pl/panel/interface/auth.php?req=login', {"user": u, "password" : hex_md5(p)}, loginResult);	});/**/}
function loginResultToken(res) {	var obj = $.json.decode(res);	if (obj.passed == 1) {		document.cookie = 'session_key='+obj.key;        $('#error').html('');				if (payType > 0) {            $('#error').html('<span style="color: green;">logowanie pomyślne <a href="panel/index2.php?req=settings&pay='+payType+'">Kliknij</a> </span>');			document.location = 'panel/index2.php?req=settings&pay='+payType;		} else {            $('#error').html('<span style="color: green;">logowanie pomyślne <a href="panel/index2.php">Kliknij</a> </span>');			document.location = 'panel/index2.php?token=';		}	} else {		$('#error').html('Wprowadzono błędne dane. Proszę spróbować ponownie !');	}}
/** * * @access public * @return void **/function loginResult(res) {    var obj = $.json.decode(res);	if (obj.passed == 1) {		document.cookie = 'session_key='+obj.key;        $('#error').html('');		if (importdok!=''){            $('#error').html('<span style="color: green;">logowanie pomyślne <a href="panel/index2.php?req=showDocuments&token='+importdok+'">Kliknij</a> </span>');			document.location = 'panel/index2.php?req=showDocuments&token='+importdok;		}else if (payType > 0) {            $('#error').html('<span style="color: green;">logowanie pomyślne <a href="panel/index2.php?req=settings&pay='+payType+'">Kliknij</a> </span>');			document.location = 'panel/index2.php?req=settings&pay='+payType;		} else {            $('#error').html('<span style="color: green;">logowanie pomyślne <a href="panel/index2.php">Kliknij</a> </span>');			document.location = 'panel/index2.php';		}	} else {		$('#error').html('Wprowadzono błędne dane. Proszę spróbować ponownie !');	}}

function register(form_id) {
	var v = true;
	if ($("input[name=haslo1]").val() == '') {v = false;$("input[name=haslo1]").addClass('invalid_data');}
	if ($("input[name=haslo2]").val() == '' && $('#abonament').val() > 0) {v = false;$("input[name=haslo2]").addClass('invalid_data');}
   if (($("input[name=haslo2]").val() != $("input[name=haslo1]").val()) &&  $('#abonament').val() > 0) {v = false;$("input[name=haslo2]").addClass('invalid_data');$("input[name=haslo1]").addClass('invalid_data');}
	if ($("input[name=login1]").val() == ''  && $('#abonament').val() > 0) {v = false;$("input[name=login1]").addClass('invalid_data');}
	if ($("input[name=email]").val() == '') {v = false;$("input[name=email]").addClass('invalid_data');}
	if ($("input[name=name]").val() == '' && $('#abonament').val() > 0) {v = false;$("input[name=name]").addClass('invalid_data');}

	if (v) {
		$("input[name=haslo1]").val(hex_md5($("input[name=haslo1]").val()));		if ($('#abonament').val() > 0)
			$("input[name=haslo2]").val(hex_md5($("input[name=haslo2]").val()));		else			$("input[name=haslo2]").val(hex_md5($("input[name=haslo1]").val()));

		//$.post('https://www.mobilna-faktura.pl/panel/interface/auth.php?req=register', $('#'+form_id).serialize(),registerResult);

var dForm = $('#'+form_id).serialize();
 $.ajax({
    type: "POST",
    url: 'https://www.mobilna-faktura.pl/panel/interface/auth.php?req=register',
    data: dForm,
        success: function(msg){
            registerResult(msg);
    }
});


		$("input[name=haslo1]").val('');
		$("input[name=haslo2]").val('');
	} else {
		$('#error').html('* Uzupełnij wymagane pola');
	}
}

function registerResult(res) {
	$("input[name=haslo1]").removeClass('invalid_data');
	$("input[name=haslo2]").removeClass('invalid_data');
	$("input[name=email]").removeClass('invalid_data');
	$("input[name=name]").removeClass('invalid_data');
	$("input[name=login]").removeClass('invalid_data');

	var obj = $.json.decode(res);
	if (obj.passed == 0) {
		var html = '';
		if (obj.err_password == 1) {html += '- Podane hasła nie są identyczne<br/>';$("input[name=haslo2]").addClass('invalid_data');$("input[name=haslo1]").addClass('invalid_data');}
		if (obj.err_login == 1) {html += '- Podany login jest nieprawidłowy lub został już wykorzystany<br/>';$("input[name=login1]").addClass('invalid_data');}
		if (obj.err_email == 1) {html += '- Podany e-mail jest niepoprawny lub został już wykorzystany<br/>';$("input[name=email]").addClass('invalid_data');}
		$('#error').html(html);
	} else {
            $('#error').html('');
		if (payType > 0) {
                    $('#confirmation').html('Rejestracja zakończona pomyślnie <a href="https://www.mobilna-faktura.pl/index.php?option=login&success=1&pay='+payType+'"> ZAPRASZAMY </a>');
			location.href='https://www.mobilna-faktura.pl/index.php?option=login&success=1&pay='+payType;
		} else {
                    $('#confirmation').html('Rejestracja zakończona pomyślnie <a href="https://www.mobilna-faktura.pl/index.php?option=login&success=1"> ZAPRASZAMY </a>');
			location.href='https://www.mobilna-faktura.pl/index.php?option=login&success=1';
		}
	}
}
function showForgotten() {
	document.getElementById('forgotten').style.display = 'block';
}

function sendForgotten() {
	$('#error').html('<span style="color: #FFFFFF;">resetowanie hasła ...</span>');
	$.post('https://www.mobilna-faktura.pl/panel/interface/auth.php?req=restart', {"email" : $('input[name=forgotten_email]').val()}, forgottenResult);
}

function forgottenResult(res) {
	var obj = $.json.decode(res);
	if (obj.error == 0) {
		$('#error').html('<span style="color: #FFFFFF;">Hasło zresetowane pomyślnie. Proszę sprawdzić pocztę.</span>');
	} else {
		$('#error').html('<span style="color: red;">Podany adres e-mail nie istnieje.</span>');
	}
}

