function validate_contact(lang){
    imie = document.getElementById('imie')
    imie_nazwisko = document.getElementById('imie_nazwisko')
    telefon_kom_num1 = document.getElementById('FAM-phone-1')
    telefon_kom_num2 = document.getElementById('FAM-phone-2')
    telefon_kom_num3 = document.getElementById('FAM-phone-3')
    inf_handlowa = document.getElementById('inf_handlowa')
    email = document.getElementById('email')
    code1 = document.getElementById('FAM-postal-code-1')
    code2 = document.getElementById('FAM-postal-code-2')
    
    imie_msg = 'Proszę podać imię'
    imie_nazwisko_msg = 'Proszę podać nazwisko'
    telefon_kom_num1_msg = 'Numer telefonu nie jest poprawny'
    telefon_kom_num1_null_msg = 'Numer telefonu nie może być pusty'
    inf_handlowa_msg = 'Proszę wyrazić zgodę na otrzymywanie informacji handlowych'
    email_too_long_msg = 'Email nie może być większy niż 255'
    email_invalid_msg = 'Proszę podać poprawny adres email'
    regions_msg = 'Proszę wybrać oddział'
    phone_type_msg = 'Proszę wybrać rodzaj telefonu'
    code_msg = 'Proszę podać poprawny kod pocztowy'
    
    if (lang == 'en') {
        imie_msg = 'Please type your name'
        imie_nazwisko_msg = 'Please type your surname'
        telefon_kom_num1_msg = 'The phone number is invalid'
        telefon_kom_num1_null_msg = 'Phone number cant be empty'
        inf_handlowa_msg = 'Please check the personal data in accordance'
        email_too_long_msg = 'Email cant be larger than 255 digits'
        email_invalid_msg = 'Please enter the valid email'
        regions_msg = 'Please select departament'
        phone_type_msg = 'Please choice phone type'
        code_msg = 'Postal code is invalids'
    }
    
    if (imie.value == '') {
        alert(imie_msg);
        imie.focus();
        return false;
    }
    
    if (imie_nazwisko.value == '') {
        alert(imie_nazwisko_msg);
        imie_nazwisko.focus();
        return false;
    }
    
    if ($('#FAM-phone-type').val() == 'wybierz' || $('#FAM-phone-type').val() == 'select') {
        alert(phone_type_msg);
        $('#FAM-phone-type').focus();
        return false;
    }
    
    if (telefon_kom_num1.value.length == 0 && telefon_kom_num2.value.length == 0 && telefon_kom_num3.value.length == 0) {
        alert(telefon_kom_num1_null_msg);
        telefon_kom_num1.focus();
        return false;
    }
    
    phone_regexp = /\d{3}/
    
    if (!telefon_kom_num1.value.match(phone_regexp)) {
        alert(telefon_kom_num1_msg);
        telefon_kom_num1.focus();
        return false;
    }
    
    if (!telefon_kom_num2.value.match(phone_regexp)) {
        alert(telefon_kom_num1_msg);
        telefon_kom_num2.focus();
        return false;
    }
    
    l = 3
    if ($('#FAM-phone-area').val() != '48') {
        l = 4
    }
    
    phone_regexp_3 = /\d{3}/
    if (l == 4) {
        phone_regexp_3 = /\d{4}/
    }
    
    if (!telefon_kom_num3.value.match(phone_regexp_3)) {
        alert(telefon_kom_num1_msg);
        telefon_kom_num3.focus();
        return false;
    }
    
    if (email.value.length > 255) {
        alert(email_too_long_msg);
        email.focus();
        return false;
    }
    
    email_regexp = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/g
    if (email.value.length > 0 && !email.value.match(email_regexp)) {
        alert(email_invalid_msg);
        email.focus();
        return false;
    }
    
    if ($('#FAM-id-regions').val() == 'wybierz z listy' || $('#FAM-id-regions').val() == 'select') {
        alert(regions_msg);
        $('#FAM-id-regions').focus();
        return false;
    }
	
	if (code1 != undefined) {
		if ((code1.value + code2.value) != '') {
			if (!code1.value.match(/\d{2}/)) {
				alert(code_msg);
				code1.focus();
				return false;
			}
			
			if (!code2.value.match(/\d{3}/)) {
				alert(code_msg);
				code2.focus();
				return false;
			}
		}
	}
	
    if (!inf_handlowa.checked) {
        alert(inf_handlowa_msg);
        inf_handlowa.focus();
        return false;
    }
    
    return true;
}

function go_next(c, i){
    if (c.value.length >= 3) {
        $('#FAM-phone-' + i).focus();
    }
}

function go_next_code(c){
    if (c.value.length >= 2) {
        $('#FAM-postal-code-2').focus();
    }
}

function set_phones(speed){
    if ($('#FAM-phone-type').val() == 'wybierz' || $('#FAM-phone-type').val() == 'select') {
        $('#phones').hide(speed)
    }
    else {
        $('#phones').show(speed)
        $('input#FAM-phone-1').focus()
    }
}

function set_maxlength3(){
    l = 3
    if ($('#FAM-phone-area').val() != '48') {
        l = 4
    }
    else {
        $('input#FAM-phone-3').val($('input#FAM-phone-3').val().substring(0, 3))
    }
    
    $('input#FAM-phone-3').attr('maxLength', l).keypress(limitMe);
}

function limitMe(e){
    if (e.keyCode == 8) {
        return true;
    }
    return this.value.length < $(this).attr("maxLength");
}

function copy_to_phone_full(){
    $('#FAM-phone-all').val($('#FAM-phone-1').val() + $('#FAM-phone-2').val() + $('#FAM-phone-3').val());
}

function copy_to_code_full(){
    $('#FAM-postal-code-all').val($('#FAM-postal-code-1').val() + $('#FAM-postal-code-2').val())
}

function isEmailValid(val){
	email_regexp = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/g
    if ( val.length == 0 || !val.match(email_regexp) ) {
		alert("Proszę podać poprawny adres email")
		return false
	}
	return true
}

function popup(url) {
	window.open(url , "", "status = 1, resizable = 0" )
}

