
// dodaj do koszyka
function dodaj(idp) {
    var ile = $('#il' + idp).val();
    ile = parseInt(ile, 10);
    if (isNaN(ile)) {
	msg('Wartość musi być większa od 0');
    } else {

	$.get("/ajax.php", { act: 'add', id: idp, ilosc: ile } );

	// jezeli dajemy parametr 1 to robi sie reload strony i przeliczenie zawartosci koszyka
	if (arguments[1] == 1) document.location.reload();

	// jezeli nie to dodajemy standardowo do koszyka
	msg('dodano do koszyka');
    }
}

// usun z koszyka i listy
function usun(idp) {
    $.get("/ajax.php", { act: 'rem', id: idp } );
    if (arguments[1] == 1) document.location.reload();
}


// wysyla zamowienie dalej
function finalizuj() {
    var answer = confirm ("Czy na pewno chcesz wysłać to zamówienie ?")
    if (answer) {
		var suwagi = $("#uwagi").val();
		var transport = $("#transport").val();

		$.ajax({
			url: "/ajax.php?act=add_uwagi",
			async: true,
			type: 'POST',
			data: "uwagi=" + suwagi + "&transport=" + transport,
			success: function(html) {
				document.location.href = '/final.html';
			}
		});
    }
}

// wyswietlamy ladny komunikat
function msg(txt) {
    $("#msg").fadeIn();
    $("#msg").html(txt);
    setTimeout('$(\'#msg\').fadeOut()', 5000);
}

function test(form) {
    if (form.nazwa.value=="") {
        alert("Musisz podać nazwę salonu.");
        form.nazwa.focus();
        return false;
    }
    else if (form.login.value=="") {
        alert("Musisz podać swój login.");
        form.login.focus();
        return false;
    }
    else if (form.haslo.value=="") {
	alert("Musisz podać hasło.");
	form.haslo.focus();
	return false;
    }
    else if (form.haslo.value != form.haslop.value) {
	alert("Hasło i jego powtórzenie muszą być identyczne.");
	form.haslop.focus();
	return false;
    }
    else if (form.telefon.value == "") {
	alert("Musisz podać numer telefonu.");
	form.telefon.focus();
	return false;
    }
    else if (form.kodr.value == "") {
	alert("Musisz podać kod rejestracji");
	form.kodr.focus();
	return false;
    }
    else {
    	return true;
    }
}
