/***********************************************
* Bookmark site script- © Dynamic Drive DHTML code library (www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit Dynamic Drive at http://www.dynamicdrive.com/ for full source code
***********************************************/

/* Modified to support Opera */
function bookmarksite(title,url){
if (window.sidebar) // firefox
	window.sidebar.addPanel(title, url, "");
else if(window.opera && window.print){ // opera
	var elem = document.createElement('a');
	elem.setAttribute('href',url);
	elem.setAttribute('title',title);
	elem.setAttribute('rel','sidebar');
	elem.click();
} 
else if(document.all)// ie
	window.external.AddFavorite(url, title);
}



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 checkPlainKomentarzText(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)
		
	}
	if(textBox.value.length > 2000) { textBox.value = textBox.value.substring(0, 2000) }
}


function checkPlainTextUserName(textBox)
{
	var alphaExp = /^[0-9a-zA-Z\-\_]+$/;
	
	while (textBox.value.length > 0 && !textBox.value.match(alphaExp)) {
		textBox.value = textBox.value.substring(0, textBox.value.length - 1)
	}
	
	textBox.value = trim(textBox.value);
}


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);
/*	if (textBox.value.length == 0) {
		textBox.value = 0;		
	} else {
		textBox.value = parseInt(textBox.value);
	}*/
}


function validatePassword(fld) {
    var error = "";
    var illegalChars = /[\W_]/; // allow only letters and numbers 
 
    if (fld.value == "") {
        fld.style.background = '#FF0000';
        error = "WprowadĽ hasło\n";
    } else if ((fld.value.length < 7) || (fld.value.length > 15)) {
        error = "Wprowadzone hasło jest niepoprawnej długo¶ci\n";
        fld.style.background = '#FF0000';
    } 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 = '#FF0000';
    } else {
        fld.style.background = '#FFFFFF';
    }
   return error;
}

function validateUsername(fld) {
    var error = "";
    var illegalChars = /[\W_]/; // allow only letters and numbers 
 
    if (fld.value == "") {
        fld.style.background = '#FF0000';
        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 = '#FF0000';
    } else if (illegalChars.test(fld.value)) {
        error = "Nazwa użytkownika zawiera niepoprawne znaki\n";
        fld.style.background = '#FF0000';
    } else {
        fld.style.background = '#FFFFFF';
    }
   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 = '#FF0000';
        error = "Proszę wprowadzić adres e-mail\n";
    } else if (!emailFilter.test(tfld)) {              //test email for illegal characters
        fld.style.background = '#FF0000';
        error = "Proszę wprowadzić prawidłowy adres e-mail\n";
    } else if (fld.value.match(illegalChars)) {
        fld.style.background = '#FF0000';
        error = "Wprowadzony adres e-mail zawiera niedozwolone znaki\n";
    } else {
        fld.style.background = '#FFFFFF';
    }
    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 = '#FF0000';
        error = "Proszę wprowadzić adres e-mail\n";
				myButton.style.display = 'none';
    } else if (!emailFilter.test(tfld)) {              //test email for illegal characters
        fld.style.background = '#FF0000';
        error = "Proszę wprowadzić prawidłowy adres e-mail\n";
				myButton.style.display = 'none';
    } else if (fld.value.match(illegalChars)) {
        fld.style.background = '#FF0000';
        error = "Wprowadzony adres e-mail zawiera niedozwolone znaki\n";
				myButton.style.display = 'none';
    } else {
        fld.style.background = '#FFFFFF';
				myButton.style.display = 'inline';
    }
    return error;
}

function validateEmptyNow(fld) {
    var error="";
    var tfld = trim(fld.value);                        // value of field with whitespace trimmed off
		
		myButton = document.getElementById('btnAdd');
   
    if (fld.value == "") {
        fld.style.background = '#FF0000';
        error = "Pole nie moze być puste\n";
				myButton.style.display = 'none';
    } else {
        fld.style.background = '#FFFFFF';
				myButton.style.display = 'inline';
    }
    return error;
}


function checkAddKomForm() {
  with (window.document.frmAddKom) {
		checkPlainKomentarzText(txtTresc);
		if (isEmpty(txtTresc, 'WprowadĽ tre¶ć')) {
			return;
		}
		else {
			submit();
		}
	}
	submit();
}

function checkAddKomFormS() {
  with (window.document.frmAddKomS) {
		checkPlainKomentarzText(txtTresc);
		if (isEmpty(txtTresc, 'WprowadĽ tre¶ć')) {
			return;
		}
		else {
			submit();
		}
	}
	submit();
}

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 if (isEmpty(txtImie, 'WprowadĽ imię')) {
			return;
		}
		else if (isEmpty(txtNazwisko, 'WprowadĽ nazwisko')) {
			return;
		}
		else {
			//alert('zarejestrowany');
			submit();
		}
	}
}

function checkAddKomFormNoLogin() {
  with (window.document.frmAddKomNoLogin) {
		
		if (isEmpty(txtTresc, 'WprowadĽ tre¶ć')) {
			return;
		}
		else if (isEmpty(txtNick, 'Podaj swój nick')) {
			return;
		}
		else {
			submit();
		}
	}
	submit();
}

function checkAddKomFormNoLoginS() {
  with (window.document.frmAddKomNoLoginS) {
		checkPlainKomentarzText(txtTresc);
		checkPlainTextUserName(txtNick);
		if (isEmpty(txtTresc, 'WprowadĽ tre¶ć')) {
			return;
		}
		else if (isEmpty(txtNick, 'Podaj swój nick')) {
			return;
		}
		else {
			submit();
		}
	}
	submit();
}

var min=9;
var max=16;

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 checkAddZaproponujForm()
{
	with (window.document.frmZaproponuj) {
	
		if (isEmpty(zap_temat, 'Wpisz temat dyskusji')) {
			return;
		}
		else {
			//alert('zarejestrowany');
			submit();
		}
	}
}

function checkKontaktForm()
{
	with (window.document.frmKontakt) {
	
		if (isEmpty(txtTresc, 'WprowadĽ tre¶ć')) {
			return;
		}
		else if (isEmpty(txtImie, 'WprowadĽ imię')) {
			return;
		}
		else if (isEmpty(txtNazwisko, 'WprowadĽ nazwisko')) {
			return;
		}
		else if(validateEmail(txtEmail) != "") {
			var message3 = validateEmail(txtEmail);
			alert(message3);
			return;
		}
		else {
			//alert('zarejestrowany');
			submit();
		}
	}
}
