//nowa funkcja walidująca e-mail - Michał
function validateEmail()
{
  var email = nwsl.txtNewsl.value;
  var re = /^[a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)*@([a-zA-Z0-9_-]+)(\.[a-zA-Z0-9_-]+)*(\.[a-zA-Z]{2,4})$/i;
  var ifValid = true;
  obj = document.getElementById("brak");
  obj1 = document.getElementById("zle");
  inobj = document.getElementById("info_newsl");

  if(email == "Twój e-mail") {
	  obj.style.display = "block";
	  obj1.style.display = "none";
	  inobj.style.display = "none";
	  ifValid = false;
	}
  else if(email.match(re) == null) {
	  obj.style.display = "none";
	  obj1.style.display = "block";
	  inobj.style.display = "none";
	  nwsl.txtNewsl.focus();
      ifValid = false;
	}
  else
      ifValid = true;
  return ifValid;
} 

//funkcja walidująca e-mail Ani, zmieniłem nazwę dodając przedrostek "old_"
//obecnie funkcja nie jest używana
function old_validateEmail() {
	obj = document.getElementById("brak");
	obj1 = document.getElementById("zle");
	inobj = document.getElementById("info_newsl");
if(nwsl.txtNewsl.value == "Twój e-mail") {
	obj.style.display = "block";
	obj1.style.display = "none";
	inobj.style.display = "none";
	return false;
}
else if(nwsl.txtNewsl.value != "") {
	var ifValid = true;
	var tmp_char = "";
	var ile = 0;
	var ile_mniej = 0;
	var od = nwsl.txtNewsl.value.length;
	var czy_jest_malpa = 0;
	var czy_jest_kropka = 0;
	var czy_jest_spacja = 0;
	ile = nwsl.txtNewsl.value.length;
	ile_mniej = ile - 1;
	var od_tmp_k = 0;
	var od_tmp_m = 0;
	for(i=0;i<ile;i++) {
		od--;
		tmp_char = nwsl.txtNewsl.value.substring(od, ile-i);
		if(tmp_char == "@") {
			czy_jest_malpa ++;
			od_tmp_m = od;
		}
		if((tmp_char == "@")&&(i==0)&&(od==ile_mniej)) {czy_jest_malpa = 0;}
		if((tmp_char == "@")&&(i==ile_mniej)&&(od==0)) {czy_jest_malpa = 0;}
		if(tmp_char == ".") {
			czy_jest_kropka = 1;
			od_tmp_k = od;
		}
		if((tmp_char == ".")&&(i==0)&&(od==ile_mniej)) czy_jest_kropka = 0;
		if((tmp_char == ".")&&(i==ile_mniej)&&(od==0)) czy_jest_kropka = 0;
		if(tmp_char == " ") {
			czy_jest_spacja = 1;
			//od_tmp_m = od;
		}
	}
	
	if((czy_jest_malpa == 0) || (czy_jest_malpa >= 2) || (czy_jest_kropka == 0) || (czy_jest_spacja == 1)) {
		obj.style.display = "none";
		obj1.style.display = "block";
		inobj.style.display = "none";
		ifValid = false;
		nwsl.txtNewsl.focus();
	}
	if((czy_jest_malpa == 1)&& (czy_jest_kropka == 1)&& (czy_jest_spacja == 0)) ifValid = true;
    return ifValid;
}
}


function fileBoxOpen(s,where,w,h) {
	var szerekranu = (screen.width-w)/2;
	var wysekranu = (screen.height-h)/2;

	with (window.open('', 'CMSimage', 'resizable=no,width='+w+',height='+h+',toolbar=no,scrollbars=no,top='+wysekranu+',left='+szerekranu+'')) {
		document.open()
		document.write('<html><head><meta http-equiv="Content-Type; charset=iso-8859-2" /><title>Podgl±d obrazka</title></head>')
		document.write('<body style="margin:0px;background-color:#fff;padding:0px 0px 0px 0px;" align="center">')		
			/*
		if (h>70) {
			document.write('<table border="0" cellspacing="0" cellpadding="0" width="100%"><tr>')
			document.write('<td align="center" valign="top">')
		}
		else if (h<=70) {
			document.write('<table border="0" cellspacing="0" cellpadding="0" width="100%" height="100%"><tr>')
			document.write('<td align="center" valign="middle" height="100%">')
			
		}
		*/
		document.write('<img src="' + s + '" alt="" style="cursor:pointer;padding: 0px 0px 0px 0px;" onClick="self.close()" />')
		document.write('</body></html>')
		document.close()
		focus()
	}
}

function sprawdzRejDz(msg1,msg2,msg3,msg4,msg5,msg6,msg7,msg8,msg9,msg10,msg11,msg12,msg13) {
	var ifValid = true;

	var ifVimie = document.formularz_rej.imie.value;
	var ifVnazwisko = document.formularz_rej.nazwisko.value;
	var ifVfirma = document.formularz_rej.firma.value;
	var ifVtel = document.formularz_rej.tel.value;
	var ifVemail = document.formularz_rej.email.value;
	var ifVmedium = document.formularz_rej.medium.value;

	var ifVlogin = document.formularz_rej.login.value;
	var ifVhaslo = document.formularz_rej.haslo.value;
	var ifVrehaslo = document.formularz_rej.rehaslo.value;

	if((ifVimie=='')&&(ifVnazwisko=='')&&(ifVfirma=='')&&(ifVtel=='')&&(ifVemail=='')&&(ifVmedium=='')&&(ifVhaslo=='')&&(ifVrehaslo=='')) {  
		alert(msg1);		
		document.formularz_rej.imie.focus();			
		ifValid = false;
	}
	else if(ifVimie=='') {
		alert(msg2);
		document.formularz_rej.imie.focus();			
		ifValid = false;		
	}
	else if(ifVnazwisko=='') {
		alert(msg3);
		document.formularz_rej.nazwisko.focus();			
		ifValid = false;		
	}
	else if(ifVfirma=='') {
		alert(msg4);
		document.formularz_rej.firma.focus();			
		ifValid = false;		
	}
	else if(ifVtel=='') {
		alert(msg5);
		document.formularz_rej.tel.focus();			
		ifValid = false;		
	}
	else if(ifVemail=='') {
		alert(msg6);
		document.formularz_rej.email.focus();			
		ifValid = false;		
	}
	else if(ifVmedium=='') {
		alert(msg8);
		document.formularz_rej.medium.focus();			
		ifValid = false;		
	}
	else if(ifVlogin=='') {
		alert(msg9);
		document.formularz_rej.login.focus();			
		ifValid = false;		
	}
	else if(ifVhaslo=='') {
		alert(msg10);
		document.formularz_rej.haslo.focus();			
		ifValid = false;		
	}
	else if(ifVrehaslo=='') {
		alert(msg11);
		document.formularz_rej.rehaslo.focus();			
		ifValid = false;		
	}
	
	if((ifVhaslo!='')&&(ifVrehaslo!='')) {
		ifValid = comparePassDz(msg12); 
	}
	if(document.formularz_rej.email.value.length >0) {
		var obiektEmail = /^([a-zA-Z0-9])+([.a-zA-Z0-9_-])*@([a-zA-Z0-9_-])+(.[a-zA-Z0-9_-]+)+/;
		ifVemail = sprawdzPole('formularz_rej', 'email', msg7, obiektEmail);
		if(ifVemail == false) {
			ifValid = false;
			return false;
		}
	}	
	if(ifVhaslo!='') {
		if(document.formularz_rej.haslo.value.length < 6) {
			alert(msg13);
			document.formularz_rej.haslo.focus();			
			ifValid = false;		
		}
	}

	return ifValid;
}

function sprawdzPole(formularz, pole, msg, obiektRegex) {
	var ifValid = true;
	obiektPole = eval("document." + formularz + "." + pole); 
	if(!obiektRegex.test(obiektPole.value))  {
		alert (msg);
		obiektPole.focus();
		ifValid = false;
	}
 
	return ifValid;
}

function comparePassDz(msg) {
	var pass = '';
	var re_pass = '';
	var ifValid = true;
	pass = document.formularz_rej.haslo.value;
	re_pass = document.formularz_rej.rehaslo.value;

	if(pass != re_pass) {
		alert(msg); 
		document.formularz_rej.haslo.focus();
		ifValid = false;
	}
	else ifValid=true;
	return ifValid;
}

function sprawdzLog(msg) {
	var ifValid = true;
	var login = '';
	var haslo = '';

	login = document.formularz_log.login.value;
	haslo = document.formularz_log.haslo.value;

	if((login == '') || (haslo == '')) {
		alert(msg);
		ifValid = false;
	}

	return ifValid;
}
function fullwindow(x,y,url)
{
	okno = 'width=' + x + ',height=' + y + ',toolbar=no,left='+(screen.availWidth-x)/2+',top='+(screen.availHeight-y)/2+',status=1';
	with(window.open(url, '', okno))
	{
  		focus();
	}
}