﻿
// Copyright 2006-2007 javascript-array.com

function menuShowHide(id)
{	
	menuitem = document.getElementById(id);

	if(menuitem.style.display == 'none') { menuitem.style.display = 'block'; }
	else { menuitem.style.display = 'none'; }
}

var timeout	= 500;
var closetimer	= 0;
var ddmenuitem	= 0;

// open hidden layer
function mopen(id)
{	
	// cancel close timer
	mcancelclosetime();

	// close old layer
	//if(ddmenuitem) ddmenuitem.style.display = 'none';

	// get new layer and show it
	ddmenuitem = document.getElementById(id);
	ddmenuitem.style.display = 'block';

}
// close showed layer
function mclose()
{
	if(ddmenuitem) ddmenuitem.style.display = 'none';
}

function mclose2(id)
{	
	ddmenuitem = document.getElementById(id);
	ddmenuitem.style.display = 'none';

}

function menu_rozwin()
{
	for(x=2;x<12;x++) {
		mopen('m' + x + '');
	}  
}

function menu_zwin()
{
	for(x=2;x<12;x++) {
		mclose2('m' + x + '');
	}  
}


// go close timer
function mclosetime()
{
	closetimer = window.setTimeout(mclose, timeout);
}

// cancel close timer
function mcancelclosetime()
{
	if(closetimer)
	{
		window.clearTimeout(closetimer);
		closetimer = null;
	}
}

// close layer when click-out
//document.onclick = mclose; 




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ąćęłńóśźżĄĆĘŁŃÓŚŹŻ\-\_\,\.\-\_\s\;\:\)\(\?\!\"\+]+$/;
	
	while (textBox.value.length > 0 && !textBox.value.match(alphaExp)) {
		textBox.value = textBox.value.substring(0, textBox.value.length - 1)
	}
	
	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 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(txtRok, 'Wprowadź rok urodzenia')) {
			return;
		}
		
		else {
			//alert('zarejestrowany');
			submit();
		}
	}
}

function checkChangePasswordForm()
{
	with (window.document.frmChangePassword) {
	
		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 {
			//alert('zarejestrowany');
			submit();
		}
	}
}

function checkModifyFanForm() 
{
	with (window.document.frmModifyFan) {
		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 {
			submit();
		}
	}
}

function checkAddKomForm() {
  with (window.document.frmAddKom) {
		if (isEmpty(txtTresc, 'Wprowadź treść')) {
			return;
		}
		else {
			submit();
		}
	}
	submit();
}

function checkAddKomFormTopNL() {
  with (window.document.frmAddKomTop) {
		if (isEmpty(txtNick, 'Wprowadź nick')) {
			return;
		}
		else if (isEmpty(txtTresc, 'Wprowadź treść')) {
			return;
		}
		else {
			submit();
		}
	}
	submit();
}

function checkAddKomFormTop() {
  with (window.document.frmAddKomTop) {
		if (isEmpty(txtTresc, 'Wprowadź treść')) {
			return;
		}
		else {
			submit();
		}
	}
	submit();
}

function checkAddKomFormS() {
  with (window.document.frmAddKomS) {
		if (isEmpty(txtTresc, 'Wprowadź treść')) {
			return;
		}
		else {
			submit();
		}
	}
	submit();
}

function checkAddKomFormNoLogin() {
  with (window.document.frmAddKomNoLogin) {
		checkPlainTextUserName(txtNick);
		if (isEmpty(txtNick, 'Wprowadź nick')) {
			return;
		}
		else if (isEmpty(txtTresc, 'Wprowadź treść')) {
			return;
		}
		else {
			submit();
		}
	}
	submit();
}

function checkAddKomFormNoLoginS() {
  with (window.document.frmAddKomNoLoginS) {
		checkPlainTextUserName(txtNick);
		if (isEmpty(txtTresc, 'Wprowadź treść')) {
			return;
		}
		else if (isEmpty(txtNick, 'Podaj swój nick')) {
			return;
		}
		else {
			submit();
		}
	}
	submit();
}

function urlencode(str) {
return escape(str).replace(/\+/g,'%2B').replace(/%20/g, '+').replace(/\*/g, '%2A').replace(/\//g, '%2F').replace(/@/g, '%40');
}

function urldecode(str) {
return unescape(str.replace('+', ' '));
}


function zmienDiv(id,flagit) {
if (flagit=="1"){
if (document.layers) document.layers[''+id+''].visibility = "show"
else if (document.all) document.all[''+id+''].style.visibility = "visible"
else if (document.getElementById) document.getElementById(''+id+'').style.visibility = "visible"
}
else
	if (flagit=="0"){
	if (document.layers) document.layers[''+id+''].visibility = "hide"
	else if (document.all) document.all[''+id+''].style.visibility = "hidden"
	else if (document.getElementById) document.getElementById(''+id+'').style.visibility = "hidden"
	}
}
