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 CheckForm()
{
var firma=getValue("form_ko", "firma");
var adres=getValue("form_ko", "adres");
var tel=getValue("form_ko", "tel");
var email=getValue("form_ko", "email");
var imie=getValue("form_ko", "imie");
if (!isEmpty(firma)){alert("Pole które jest wymagane jest puste.");document.forms["form_ko"].elements["firma"].focus();return false;}
if (!isEmpty(adres)){alert("Pole które jest wymagane jest puste.");document.forms["form_ko"].elements["adres"].focus();return false;}
if (!isEmpty(tel)){alert("Pole które jest wymagane jest puste.");document.forms["form_ko"].elements["tel"].focus();return false;}
if (!isEmpty(email)){alert("Pole które jest wymagane jest puste.");document.forms["form_ko"].elements["email"].focus();return false;}
if (!isEmpty(imie)){alert("Pole które jest wymagane jest puste.");document.forms["form_ko"].elements["imie"].focus();return false;}
return true;
}