
function checkPlainText(textBox)
{
	var alphaExp = /^[0-9a-zA-ZąćęłńóśźżĄĆĘŁŃÓŚŹŻ\-\_\,\.\-\_\s\;\:\)\(\?\!\"]+$/;
	
	while (textBox.value.length > 0 && !textBox.value.match(alphaExp)) {
		textBox.value = textBox.value.substring(0, textBox.value.length - 1)
	}
}


function trim(str)
{
	return str.replace(/^\s+|\s+$/g,'');
}


function isEmpty(formElement, message) {
	formElement.value = trim(formElement.value);
	
	_isEmpty = false;
	if (formElement.value == '') {
		_isEmpty = true;
		alert(message);
		formElement.focus();
	}
	
	return _isEmpty;
}



function checkNumber(textBox)
{
	while (textBox.value.length > 0 && isNaN(textBox.value)) {
		textBox.value = textBox.value.substring(0, textBox.value.length - 1)
	}
	
	textBox.value = trim(textBox.value);
}



function validatePassword(fld) {
    var error = "";
    var illegalChars = /[\W_]/; // allow only letters and numbers 
 
    if (fld.value == "") {
        fld.style.background = '#149ACF';
				fld.style.color = '#ffffff';
        error = "Wprowadź hasło\n";
    } else if ((fld.value.length < 8) || (fld.value.length > 20)) {
        error = "Wprowadzone hasło jest niepoprawnej długości\n";
        fld.style.background = '#149ACF';
				fld.style.color = '#ffffff';
    } else if ( (fld.value.search(/[a-zA-Z]+/)==-1) || (fld.value.search(/[0-9]+/)==-1) ) {
        error = "Hasło musi zawierać co najmniej 1 cyfrę oraz litery\n";
        fld.style.background = '#149ACF';
				fld.style.color = '#ffffff';
    } else {
        fld.style.background = '#FAF3D6';
				fld.style.color = '#626262';
    }
   return error;
}

function validateUsername(fld) {
    var error = "";
    var illegalChars = /[\W_]/; // allow only letters and numbers 
 
    if (fld.value == "") {
        fld.style.background = '#149ACF';
        error = "Wprowadź nazwę użytkownika\n";
    } else if ((fld.value.length < 4) || (fld.value.length > 15)) {
        error = "Nazwa użytkownika powinna mieć od 5 do 16 znaków\n";
        fld.style.background = '#149ACF';
				fld.style.color = '#ffffff';
    } else if (illegalChars.test(fld.value)) {
        error = "Nazwa użytkownika zawiera niepoprawne znaki\n";
        fld.style.background = '#149ACF';
				fld.style.color = '#ffffff';
    } else {
        fld.style.background = '#FAF3D6';
				fld.style.color = '#626262';
    }
   return error;
}    

function validateEmail(fld) {
    var error="";
    var tfld = trim(fld.value);                        // value of field with whitespace trimmed off
    var emailFilter = /^[^@]+@[^@.]+\.[^@]*\w\w$/ ;
    var illegalChars= /[\(\)\<\>\,\;\:\\\"\[\]]/ ;
   
    if (fld.value == "") {
        fld.style.background = '#149ACF';
				fld.style.color = '#ffffff';
        error = "Proszę wprowadzić adres e-mail\n";
    } else if (!emailFilter.test(tfld)) {              //test email for illegal characters
        fld.style.background = '#149ACF';
				fld.style.color = '#ffffff';
        error = "Proszę wprowadzić prawidłowy adres e-mail\n";
    } else if (fld.value.match(illegalChars)) {
        fld.style.background = '#149ACF';
				fld.style.color = '#ffffff';
        error = "Wprowadzony adres e-mail zawiera niedozwolone znaki\n";
    } else {
        fld.style.background = '#FAF3D6';
				fld.style.color = '#626262';
    }
    return error;
}

function validateEmailNow(fld) {
    var error="";
    var tfld = trim(fld.value);                        // value of field with whitespace trimmed off
    var emailFilter = /^[^@]+@[^@.]+\.[^@]*\w\w$/ ;
    var illegalChars= /[\(\)\<\>\,\;\:\\\"\[\]]/ ;
		
		myButton = document.getElementById('btnAdd');
   
    if (fld.value == "") {
        fld.style.background = '#149ACF';
				fld.style.color = '#ffffff';
        error = "Proszę wprowadzić adres e-mail\n";
				myButton.style.display = 'none';
    } else if (!emailFilter.test(tfld)) {              //test email for illegal characters
        fld.style.background = '#149ACF';
				fld.style.color = '#ffffff';
        error = "Proszę wprowadzić prawidłowy adres e-mail\n";
				myButton.style.display = 'none';
    } else if (fld.value.match(illegalChars)) {
        fld.style.background = '#149ACF';
				fld.style.color = '#ffffff';
        error = "Wprowadzony adres e-mail zawiera niedozwolone znaki\n";
				myButton.style.display = 'none';
    } else {
        fld.style.background = '#FAF3D6';
				fld.style.color = '#626262';
				myButton.style.display = 'inline';
    }
    return error;
}

function validateEmpty(fld) {
    var error="";
    var tfld = trim(fld.value);
   
    if (fld.value == "") {
        fld.style.background = '#149ACF';
				fld.style.color = '#ffffff';
        error = "Pole nie moze być puste\n";
    } else {
        fld.style.background = '#FAF3D6';
				fld.style.color = '#626262';
    }
    return error;
}

function validateCheckbox(chk){
	var error = "";
  if (chk.checked == 0)
    error = "Musisz zaakceptować regulamin\n";
  return error;
}


var min=9;
var max=12;

function powiekszCzcionke() {
   var p = document.getElementsByTagName('p');
   for(i=0;i<p.length;i++) {
      if(p[i].style.fontSize) {
         var s = parseInt(p[i].style.fontSize.replace("px",""));
      } else {
         var s = 11;
      }
      if(s!=max) {
         s += 1;
      }
      p[i].style.fontSize = s+"px"
   }
}
function pomniejszCzcionke() {
   var p = document.getElementsByTagName('p');
   for(i=0;i<p.length;i++) {
      if(p[i].style.fontSize) {
         var s = parseInt(p[i].style.fontSize.replace("px",""));
      } else {
         var s = 11;
      }
      if(s!=min) {
         s -= 1;
      }
      p[i].style.fontSize = s+"px"
   }   
}



function checkAddFanForm()
{
	with (window.document.frmAddFan) {
	
		if(validateUsername(txtLogin) != "") {
			var message = validateUsername(txtLogin);
			alert(message);
			return;
		}
		
		else if(validatePassword(txtPass) != "") {
			var message1 = validatePassword(txtPass);
			alert(message1);
			return;
		}
		else if(validatePassword(txtPass2) != "") {
			var message2 = validatePassword(txtPass2);
			alert(message2);
			return;
		}
		else if(txtPass.value != txtPass2.value) {
			alert('Wprowadzone hasła są od siebie różne');
			return;
		}
		
		else if(validateEmail(txtEmail) != "") {
			var message3 = validateEmail(txtEmail);
			alert(message3);
			return;
		}
		
		else {
			//alert('zarejestrowany');
			submit();
		}
	}
}

function checkNewsletterAddForm() {
	with (window.document.newsletterAdd) {

		if(validateEmail(newsletterInput) != "") {
			var message = validateEmail(newsletterInput);
			alert(message);
			return;
		}
	
		else {
			//alert('zarejestrowany');
			submit();
		}
	}
}

function checkTypujForm() {
  with (window.document.frmTwojTyp) {
		if (isEmpty(txtWynik1, 'Wprowadź wynik 1')) {
			return;
		}
		else if (isEmpty(txtWynik2, 'Wprowadź wynik 2')) {
			return;
		}
		else {
			submit();
		}
	}
	submit();
}


/*AJAX*/

	 var http_request = false;
	 function makePOSTRequest_main(url, parameters) {
		http_request = false;
		if (window.XMLHttpRequest) { // Mozilla, Safari,...
		 http_request = new XMLHttpRequest();
		 if (http_request.overrideMimeType) {
			// set type accordingly to anticipated content type
			http_request.overrideMimeType('text/xml');
			//http_request.overrideMimeType('text/html');
			//http_request.overrideMimeType('text/xml; charset=utf-8');
		 }
		} else if (window.ActiveXObject) { // IE
		 try {
			http_request = new ActiveXObject("Msxml2.XMLHTTP");
		 } catch (e) {
			try {
				 http_request = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e) {}
		 }
		}
		if (!http_request) {
		 alert('Cannot create XMLHTTP instance');
		 return false;
		}
		
		http_request.onreadystatechange = alertContents_main;
		http_request.open('POST', url, true);
		http_request.setRequestHeader("Content-type", "application/x-www-form-urlencoded; charset=utf-8");
		http_request.setRequestHeader("Content-length", parameters.length);
		http_request.setRequestHeader("Connection", "close");
		http_request.send(parameters);
	 }

	 function alertContents_main() {
		if (http_request.readyState == 4) {
		 if (http_request.status == 200) {
			//alert(http_request.responseText);
			result = http_request.responseText;
			document.getElementById('aktualnosci_box').innerHTML = result;
		 } else {
			alert('There was a problem with the request.');
		 }
		}
	 }

	function get_main() {
			var poststr = "strona=" + encodeURI( document.getElementById("wartosc_strona_main").value ) + "&typ=" + encodeURI( document.getElementById("wartosc_typ_main").value );
			makePOSTRequest_main('ajax_news.php', poststr);
	}

	
