/* Newsletter
--------------------------------------------------*/
/*
function val() {
    with (document.getElementById("newsletter_form")) {
        if (!isValidEmail(newsletter_email.value)) {
            alert("Proszę wprowadzić poprawny adres email.");
            newsletter_email.focus();
            return;
        }
    submit();
    }
    return false;
}
function isValidEmail(str) {
    var reg = /^([a-zA-Z0-9_\.\-])+\@([a-zA-Z0-9\-_\.])+\.([a-zA-Z_\.]){2,3}$/;
    return isValidReg(str,reg);
}
function isValidReg(str,reg) {
    reg = new RegExp(reg);
    if (reg.test(str)) return true;
    return false;
}
*/


function Trim(text)
{
	if (text=='')
		return text;
	while (text.charAt(0) == " ")
		text = text.substring(1,text.length);
	while (text.charAt(text.length-1) == " ")
		text = text.substring(0,text.length-2);
	return text;
}

function validateMail(eMail)
{
	eMail=Trim(eMail);
	flag = true;
	
	if (eMail == '')
		flag=false;
	
	if (eMail.indexOf('@') < 1)
		flag=false;
	
	if (eMail.indexOf('@') != eMail.lastIndexOf('@'))
		flag=false;
	
	if (eMail.indexOf(' ') != -1)
		flag=false;
	
	if (eMail.lastIndexOf('.')<(eMail.indexOf('@')+2))
		flag=false;
	
	if (eMail.lastIndexOf('.')==(eMail.length-1))
		flag=false;
	
	return flag;   
}

function isAlphaNumeric(toCheck)
{
	isOK=true;
	for (i=0; i<toCheck.length; i++)
	{
		var charac=toCheck.charAt(i);
		if ((!isLetter(charac)) && ((charac<'0') || (charac>'9')))
		{
			isOK=false;
		}
	}
	return isOK;
}

function isLetter(charac)
{
	var okString="aąbcćdeęfghijklłmnńoópqrsśtuvwxyzźżAĄBCĆDEĘFGHIJKLŁMNŃOÓPQRSŚTUVWXYZŹŻęó±łĽńĘÓˇŁ¬Ń";
	if (okString.indexOf(charac)>-1)
	{
		return true;
	}
	return false;
}

function getValue(formName, fieldName)
{
	return document.forms[formName].elements[fieldName].value;
}

function bigSmall(formInput)
{
	var textInside = formInput.value;
	if (textInside.length>0)
	{
		textInside=textInside.toLowerCase();
		textInside=toUpper(textInside, 0);
		var indexOfDash=0;
		while ((textInside.indexOf("-", indexOfDash)>-1) && (indexOfDash>-1))
		{
			textInside=toUpper(textInside, textInside.indexOf("-", indexOfDash+1)+1);
			indexOfDash=textInside.indexOf("-", indexOfDash+1);
		}
		var indexOfDash=0;
		while ((textInside.indexOf(" ", indexOfDash)>-1) && (indexOfDash>-1))
		{
			textInside=toUpper(textInside, textInside.indexOf(" ", indexOfDash+1)+1);
			indexOfDash=textInside.indexOf(" ", indexOfDash+1);
		}
		formInput.value=textInside;
	}	
}

function toUpper(text, index)
{
	return text.substring(0, index)+text.charAt(index).toUpperCase()+text.substring(index+1, text.length);
}

function isEmpty(toCheck)
{
	if (toCheck != null) {
		return (toCheck.length>0);
	}
	else {
		return false
	}
		
}

function isOneLetter(toCheck)
{
	return (toCheck.length!=1);
}

function isLetterAndDash(toCheck)
{
	isOK=true;
	for (i=0; i<toCheck.length; i++)
	{
		var charac=toCheck.charAt(i);
		if ((!isLetter(charac)) && (charac!='-'))
		{
			isOK=false;
		}
	}
	return isOK;
}

function isNumberAndDash(toCheck)
{
	isOK=true;
	for (i=0; i<toCheck.length; i++)
	{
		var charac=toCheck.charAt(i);
		if (((charac<'0') || (charac>'9')) && (charac!='-'))
		{
			isOK=false;
		}
	}
	return isOK;
}

function has3SameLetters(toCheck)
{
	isOK=true;
	toCheck=toCheck.toLowerCase();
	for (i=0; i<toCheck.length-2; i++)
	{
		var charac1=toCheck.charAt(i);
		var charac2=toCheck.charAt(i+1);
		var charac3=toCheck.charAt(i+2);
		if ((charac1==charac2) && (charac2==charac3))
		{
			isOK=false;
		}
	}
	return isOK;
}

function checkDayOfMonth(dayNo, monthNo, yearNo)
{
	isOK=true;
	if ((monthNo==1) || (monthNo==3) || (monthNo==5) || (monthNo==7) || (monthNo==8) || (monthNo==10) || (monthNo==12))
	{
		if (dayNo>31)
		{
			isOK=false;
		}
	}
	else if (monthNo==2)
	{
		if (((yearNo % 4)==0) && ((!((yearNo % 100)==0)) || ((yearNo % 400) == 0)))
		{
			if (dayNo>29)
			{
				isOK=false;
			}
		}
		else
		{
			if (dayNo>28)
			{
				isOK=false;
			}
		}
	}
	else
	{
		if (dayNo>30)
		{
			isOK=false;
		}
	}
	return isOK;
}

function isNumberOK(toCheck)
{
	isOK=true;
	for (i=0; i<toCheck.length; i++)
	{
		var charac=toCheck.charAt(i);
		if (((charac<'A') || (charac>'Z')) && ((charac<'a') || (charac>'z')) && (charac!='-') && (charac!='/') && (charac!=' ') && (charac!='.') && ((charac<'0') || (charac>'9')))
		{
			isOK=false;
		}
	}
	return isOK;
}

function changePhone1(formInput)
{
	var textInside = formInput.value;
	if (textInside.length>0)
	{
		textInside=replace(textInside, "-", ".");
		textInside=replace(textInside, "(", ".");
		textInside=replace(textInside, ")", ".");
		formInput.value=textInside;
	}	
}

function changePhone2(formInput)
{
	var textInside = formInput.value;
	if (textInside.length>0)
	{
		for (i=0; i<textInside.length; i++)
		{
			if ((textInside.charAt(i)<'0') || (textInside.charAt(i)>'9'))
			{
				if (i+1<textInside.length)
				{
					textInside=textInside.substring(0, i)+textInside.substring(i+1, textInside.length);
				}
				else
				{
					textInside=textInside.substring(0, i);
				}
				i--;
			}
		}
		formInput.value=textInside;
	}
}

function replace(text, toReplace, replaceBy)
{
	while (text.indexOf(toReplace)>-1)
	{
		text=text.substring(0, text.indexOf(toReplace))+replaceBy+text.substring(text.indexOf(toReplace)+toReplace.length, text.length);
	}
	
	return text;
}

function readSelect(formName, fieldName)
{
	return document.forms[formName].elements[fieldName].options[document.forms[formName].elements[fieldName].selectedIndex].value;
}

function readSelectNumber(formName, fieldName)
{
	return new Number(document.forms[formName].elements[fieldName].options[document.forms[formName].elements[fieldName].selectedIndex].value);
}

function isRightLength(toCheck, minSize, maxSize)
{
	isOK=true;
	if ((toCheck.length<minSize) || (toCheck.length>maxSize))
	{
		isOK=false;
	}
	return isOK;
}

function isNumber(toCheck)
{
	isOK=true;
	for (i=0; i<toCheck.length; i++)
	{
		if ((toCheck.charAt(i)<'0') || (toCheck.charAt(i)>'9'))
		{
			isOK=false;
		}
	}
	return isOK;
}


function val()
{
	var newsletter_email=getValue("newsletter_form", "newsletter_email");
	if (!isEmpty(newsletter_email))
	{
		alert("Podaj adres E-mail");
		document.forms["newsletter_form"].elements["newsletter_email"].focus();
		return false;
	}
if (!validateMail(newsletter_email))
	{
		alert("Niepoprawny E-mail");
		document.forms["newsletter_form"].elements["newsletter_email"].focus();
		return false;
	}
	return true;
}



/* Fotki
--------------------------------------------------*/
function Powieksz(theURL,winName,szerOkna,wysOkna) { 
window.open(theURL,winName,'toolbar=no,location=no,status=yes,menubar=no,scrollbars=no,resizable=yes,width='+szerOkna+',height='+wysOkna+',left='+(screen.width/2-(szerOkna/2))+',top='+(screen.height/2-(wysOkna/2))+'');
}