

var messages = []

messages['pl'] = {	
	wypelnijPole 	: 'Wypełnij to pole',
	zawieraBledy 	: 'Formularz zawiera błędy. Popraw je, a następnie spróbuj wysłać formularz ponownie.'
};

messages['en'] = {	
	wypelnijPole 	: 'Fill this field up ',
	zawieraBledy 	: 'The form contains errors. Correct them, and then try to send the form again.'
};

messages['de'] = {	
	wypelnijPole 	: 'Bitte dieses Feld ausfüllen',
	zawieraBledy 	: 'Dieses Formular weist Fehler auf. Nach der Korrektur versuchen Sie das Formular noch mal zu senden.'
};

messages['ru'] = {	
	wypelnijPole 	: 'Заполните это поле',
	zawieraBledy 	: 'Бланк содержит ошибки. Исправьте их, а затем попробуйте выслать бланк заново.'
};

messages['ua'] = {	
	wypelnijPole 	: 'Заповніть це поле',
	zawieraBledy 	: 'Бланк містить помилки. Виправте їх, а потім спробуйте вислати бланк ще раз.'
};

messages['lt'] = {	
	wypelnijPole 	: 'Užpildykite šį lauką',
	zawieraBledy 	: 'Užklausimas turi klaidų. Ištaisykite jas, vėliau pabandykite išsiųsti užklausimą dar kartą.'
};

messages['it'] = {	
	wypelnijPole 	: 'Riempire questo campo.',
	zawieraBledy 	: 'Il modulo contiene errori. Correggerli, e quindi provare a inviare il modulo di nuovo.'
};

$(document).ready(
	function()
	{
		$("#zapytanieOfertowe").submit(validateForm);
		addPhpErrors();
	}
);

var fields = ['nazwa', 'adres', 'osoba', 'telefon', 'email', 'uslugiWiele', 'tresc', 'uslugi'];

/**
 * Sprawdź poprawność danych w formularzu. Zwraca true jeśli dane są poprawne i false w p.p. 
 */
function validateForm()
{
	clearErrors(fields);
	
	var isValidate = true;
	
	var elem;
	
	var noEmpty = ['osoba', 'adres', 'nazwa'];
	
	for (var i = 0; i < noEmpty.length; i++)
	{		
		elem = $("#zapytanieOfertowe input[name=" + noEmpty[i] + "]");				
		if (elem.val() == '')
		{
			addError(noEmpty[i], messages[lang].wypelnijPole);
			isValidate = false;									
		}
	}
	
	elem = $("#zapytanieOfertowe textarea[name=tresc]");				
	if (elem.val() == '')
	{
		addError('tresc', messages[lang].wypelnijPole);
		isValidate = false;									
	}
	
	
	
	//elem = $("#zapytanieOfertowe input[name=zgoda]");		
	//if (!elem.attr('checked'))
	//{
	//	addError('zgoda', 'Musisz zaznaczyć to pole');
	//	isValidate = false;
	//}
		
	if (!isValidate)
	{
		alert(messages[lang].zawieraBledy);		
	}
	
	return isValidate;
}
