function getXMLHttpRequest() {
	var request = false;
	try {
		request = new XMLHttpRequest();
	} catch(err1) {
		try {
			request = new ActiveXObject('Msxml2.XMLHTTP');
		} catch(err2) {
			try {
				request = new ActiveXObject('Microsoft.XMLHTTP');
			} catch(err3) {
				request = false;
			}
		}
	}
	return request;
}
function showData() {
		var block = document.getElementById('facture_data');
		if (block.style.display == 'none') {
			block.style.display = 'block';
		} else {
			block.style.display = 'none';
		}	
		return false;	
	}
function setSPAN(rid, spp) {
	var t; 
	if ((t = typeof document.getElementById) == "function" 
		|| (t == "object" && document.getElementById))
	{ 
	  var o = document.getElementById(rid);
	  if (o
		  && typeof (o = o.style) != "undefined"
		  && typeof o.display != "undefined")
	  { 
		o.display = spp;
	  } 
	} 
}
function checkEmail(email) {
	var re = /^[a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)*@([a-zA-Z0-9_-]+)(\.[a-zA-Z0-9_-]+)*(\.[a-zA-Z]{2,4})$/i;
	if (email.match(re) == null)
		return false;
	else
		return true;
}
var r;
r = getXMLHttpRequest();

function sprawdzEmail(value) {
	kom = document.getElementById('komunikacik1');
	ico = document.getElementById('iconka1');
	if (value == '') {
		ico.className='ico_er';
		document.getElementById('d_email').className='txt2 czerwona_ramka';
		kom.innerHTML = '<font style="color:#FF0000;">Wpisz adres e-mail</font>';
		return false;
	} else {
		if (checkEmail(value)) {
			document.getElementById('d_email').className='txt2';
			ico.className='ico_ok';
			kom.innerHTML = '';
			return true;
		} else {
			ico.className='ico_er';
			document.getElementById('d_email').className='txt2 czerwona_ramka';
			kom.innerHTML = '<font style="color:#FF0000;">Błędny adres email. Proszę wpisać poprawny.</font>';
			return false;
		}
	}
}
function sprawdzPass(value,id) {
	if (id == 1) {
		kom = document.getElementById('komunikacik2');
		ico = document.getElementById('iconka2');
		if (value.length == 0) {
			ico.className='ico_er';
			document.getElementById('d_haslo').className='txt czerwona_ramka';
			kom.innerHTML = '<font style="color:#FF0000;">Nie podano hasła.<br />Hasło musi zawierać minimum 6 znaków.</font>';
			return false;
		} else if (value.length <6) {
			ico.className='ico_er';
			document.getElementById('d_haslo').className='txt czerwona_ramka';
			kom.innerHTML = '<font style="color:#FF0000;">Podane hasło jest za krótkie.<br />Hasło musi zawierać minimum 6 znaków.</font>';
			return false;
		} else {
			ico.className='ico_ok';
			document.getElementById('d_haslo').className='txt';
			kom.innerHTML = '';
			return true;
		}
	} else if (id == 2) {
		kom = document.getElementById('komunikacik3');
		ico = document.getElementById('iconka3');
		if (document.getElementById('d_haslo').value != value) {
			document.getElementById('d_haslo2').className='txt czerwona_ramka';
			ico.className='ico_er';
			kom.innerHTML = '<font style="color:#FF0000;">Podane hasła nie pasują do siebie</font>';
			return false;
		} else {
			if (value.length == 0) {
				document.getElementById('d_haslo2').className='txt czerwona_ramka';
				ico.className='ico_er';
				kom.innerHTML = '<font style="color:#FF0000;">Nie podano hasła</font>';
				return false;
			} else if (value.length <6) {
				document.getElementById('d_haslo2').className='txt czerwona_ramka';
				ico.className='ico_er';
				kom.innerHTML = '<font style="color:#FF0000;">Podane hasło jest za krótkie</font>';
				return false;
			} else {
				document.getElementById('d_haslo2').className='txt';
				ico.className='ico_ok';
				kom.innerHTML = '';
				return true;
			}
		}
	}
}
function notempty(value,id,pole,kom_txt) {
	kom = document.getElementById('komunikacik'+id);
	ico = document.getElementById('iconka'+id);
	if (value == '') {
		ico.className='ico_er';
		document.getElementById(pole).className='txt2 czerwona_ramka';
		kom.innerHTML = '<font style="color:#FF0000;">'+kom_txt+'</font>';
		return false;
	} else {
		document.getElementById(pole).className='txt2';
		ico.className='ico_ok';
		kom.innerHTML = '';
		return true;
	}
}
function notempty2(value,id,pole,kom_txt) {
	kom = document.getElementById('komunikacik'+id);
	ico = document.getElementById('iconka'+id);
	if (value == '') {
		ico.className='ico_er';
		document.getElementById(pole).className='txt3 czerwona_ramka';
		kom.innerHTML = '<font style="color:#FF0000;">'+kom_txt+'</font>';
		return false;
	} else {
		document.getElementById(pole).className='txt3';
		ico.className='ico_ok';
		kom.innerHTML = '';
		return true;
	}
}
function adres() {
	kom = document.getElementById('komunikacik6');
	ico = document.getElementById('iconka6');
	ulica = document.getElementById('d_street');
	numer = document.getElementById('d_home_no');
	if (ulica.value.length == 0) {
		ico.className='ico_er';
		document.getElementById('d_street').className='txt2 czerwona_ramka';
		kom.innerHTML = '<font style="color:#FF0000;">Wpisz dokładny adres</font>';
	} else {
		document.getElementById('d_street').className='txt2';
	}
	if (numer.value.length == 0) {
		ico.className='ico_er';
		document.getElementById('d_home_no').className='txt2 czerwona_ramka';
		kom.innerHTML = '<font style="color:#FF0000;">Wpisz dokładny adres</font>';
	} else {
		document.getElementById('d_home_no').className='txt2';
	}
	if ((numer.value.length != 0) && (ulica.value.length != 0)) {
		ico.className='ico_ok';
		kom.innerHTML = '';
		return true;
	} else {
		return false;
	}
}
function sprawdzForm(form) {
	er = 0;
	if (form['zalogowany'].value == 0) {
		if (!sprawdzEmail(form['d_email'].value)) {
			er++;
		}
		if (!sprawdzPass(form['d_haslo'].value,1)) {
			er++;
		}
		if (!sprawdzPass(form['d_haslo2'].value,2)) {
			er++;
		}
	}
	if (!notempty(form['d_firstname'].value,4,'d_firstname','Wpisz swoje imię')) {
		er++;
	}
	if (!notempty(form['d_lastname'].value,5,'d_lastname','Wpisz swoje nazwisko')) {
		er++;
	}
	if (!adres()) {
		er++;
	}
	if (!notempty2(form['d_city'].value,7,'d_city','Podaj nazwę miasta')) {
		er++;
	}
	if (!notempty2(form['d_postcode'].value,8,'d_postcode','Podaj kod pocztowy')) {
		er++;
	}
	if (!notempty(form['d_telephone'].value,9,'d_telephone','Podaj numer telefonu')) {
		er++;
	}
	if (er>0) {
		alert('Proszę wypełnić wszystkie wymagane pola');
		return false;
	} else {
		return true;		
	}
}
