// tworzy obiekt
function formValidator()
{
    // tablica do przechowywania wiadomo�ci o b��dach
    this.errorList = new Array;
    this.errorName = new Array;
 this.errorColor = "#ffffff";
    // metody obiektu
    this.isEmpty = isEmpty;
    this.isNumber = isNumber;
    this.isAlphabetic = isAlphabetic;
    this.isAlphaNumeric = isAlphaNumeric;
    this.isWithinRange = isWithinRange;
    this.isEmailAddress = isEmailAddress;
    this.isChecked = isChecked;
 
    this.raiseError = raiseError;
    this.numErrors = numErrors;
    this.displayErrors = displayErrors;
    this.divErrors = divErrors;
    this.divClean = divClean;
    this.isPostCode = isPostCode;
    this.isNip = isNip;
    this.fireBug = fireBug;
    this.errorForm = errorForm;
}

function fireBug(txt){


    //console.log(txt);
}

function errorForm(color)
{
this.errorColor = color;
    
}

function divErrors(val,msg){

    var Error = "error"+val;
    document.getElementById(Error).innerHTML = msg;
    document.getElementById(Error).style.color = this.errorColor;
    document.getElementById(Error).style.fontWeight = "bold";

    var el = document.getElementById(val);
    el.style.backgroundColor = "#cdbd0f";
    //document.getElementByName(val).style.backgroundColor = "#ff0000";
    this.raiseError(val,msg);
}

function divClean(val){

    var Error = "error"+val;
    document.getElementById(Error).innerHTML = " ";
    document.getElementById(Error).style.color = "#a91203";
    document.getElementById(Error).style.fontWeight = "bold";

    var el = document.getElementById(val);
    el.style.backgroundColor = "#10538C";
   
//document.getElementByName(val).style.backgroundColor = "#ff0000";
//this.raiseError(val,msg);
}



 
// sprawdza, czy podana warto�� jest pusta, lub zawiera tylko bia�e znaki
function isEmpty(val)
{
    if (val.match(/^s+$/) || val == "")
    {
        return true;
    }
    else
    {
        return false;
    }
}
 
// sprawdza, czy podana wartosc jest liczb�
function isNumber(val)
{
    if (!isNaN(val))
    {
        return false;
    }
    else
    {
        return true;
    }
}

function isPostCode(src)
{
    var regex = /^[0-9]{2}\-[0-9]{3}$/;
    return regex.test(src);
}

function isNip(src)
{
    var regex = /^[0-9]{10}$/;
    return regex.test(src);
}


// sprawdza, czy wszystkie znaki s� literami
function isAlphabetic(val)
{
    if (val.match(/^[a-zA-Z]+$/))
    {
        return true;
    }
    else
    {
        return false;
    }
}
 
// sprawdza, czy przes�ane dane zawieraj� tylko litery i cyfry
function isAlphaNumeric(val)
{
    if (val.match(/^[a-zA-Z0-9]+$/))
    {
        return true;
    }
    else
    {
        return false;
    }
}
 
// sprawdza, czy podana warto�� mie�ci si� w zakresie okre�lonym przez zmienne min i max
function isWithinRange(val, min, max)
{
    if (val >= min && val <= max)
    {
        return true;
    }
    else
    {
        return false;
    }
}
 
// sprawdza, czy u�ytkownik wprowadzi� poprawny adres email
function isEmailAddress(val)
{
    if (val.match(/^([a-zA-Z0-9])+([.a-zA-Z0-9_-])*@([a-zA-Z0-9_-])+(.[a-zA-Z0-9_-]+)+/))
    {
        return true;
    }
    else
    {
        return false;
    }
}
 
// sprawdza, czy pole jest zaznaczone
function isChecked(obj)
{
    if (obj.checked)
    {
        return true;
    }
    else
    {
        return false;
    }
}
 
// wy�wietla wszystkie b��dy
// p�tla przez wszystkie elementy tablicy wywo�uj�ca poszczeg�lne okna dialogowe
function displayErrors()
{
    for (x=0; x<this.errorList.length; x++)
    {
        for(y=0; y<this.errorName.length; y++)
        {
		
            document.getElementById(this.errorName[y]).innerHtml = this.errorList[x];
        }
    }
}
 
// dodaje b��d do listy
function raiseError(div,msg)
{
    this.errorList[this.errorList.length] = msg;
    this.errorName[this.errorName.length] = div;
}
 
// zwraca ilo�� b��d�w w tablicy
function numErrors()
{
    return this.errorList.length;
}
