/*
Funkcja ukrywajaca adres email przed spam botami wypisuje nastepujacy kod
<a href="beforeAt@afterAt" class="cssClass">beforeAt@afterAt</a>
@author   Mikolaj Krawczyk
*/
function scramble(beforeAt, afterAt, cssClass)
{
    var a,b,c,d,e;
    a = '<a ';
    if (cssClass != null)
    {
        a += 'class="' + cssClass + '" ';
    }
    a += 'href="mai';
    b = beforeAt;
    c = '">';
    a += 'lto:';
    b += '@';
    e = '</a>';
    b += afterAt;
    d = b;

    document.write(a + b + c + d + e);
}

/*
Funkcja ukrywajaca adres email przed spam botami wypisuje nastepujacy kod
<a href="beforeAt@afterAt" class="cssClass">linkName</a>
@author   Mikolaj Krawczyk
*/
function scrambleWithLink(beforeAt, afterAt, linkName, cssClass)
{
    var a,b,c;
    a = '<a ';
    if (cssClass != null)
    {
        a += 'class="' + cssClass + '" ';
    }
    a += 'href="mai';
    b = beforeAt;
    c = '">'+ linkName +'</a>';
    a += 'lto:';
    b += '@';
    b += afterAt;

    document.write(a + b + c);
}

function writeCookie(uri)
{
    var date = new Date();
    date.setTime(date.getTime()+(356*24*60*60*1000));
    var res_cookie = "users_res="+screen.width +"x"+ screen.height+"; expires="+date.toGMTString()+"; path=/"
    document.cookie = res_cookie;

    if (readCookie("users_res") === null )
    {
        location = uri;
    }
}

/**
 * Funkcja odczytuje wszystki ciastka po nazwie
 */
function readCookie(name) {
    var nameEQ = name + "=";
    var ca = document.cookie.split(";");
    for(var i=0;i < ca.length;i++) {
        var c = ca[i];
        while (c.charAt(0)==" ") c = c.substring(1,c.length);
        if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
    }
    return null;
}


function checkRes( i_width, i_height)
{
    if(i_width != screen.width || i_height != screen.height)
    {
        writeCookie();
    }
    else
    {
        return true;
    }
}
/*
    Funkcja sprawdza ilosc wpisanych znakow w podanym polu (i_fieldName) 
    i jesli zostal przekroczony limit (i_MaxLength) to wyswietla ostrzezenie
    (alertMessage) - jesli zostalo ustalone. 
    @author Mikolaj Krawczyk
*/
function checkFieldValueLength( i_fieldName, i_maxLength, alertMessage )
{
    var field = null;
    var maxLength = parseInt(i_maxLength);
    
    field = document.getElementById( i_fieldName );
    if( null != field)
    {
        if( i_maxLength < field.value.length )
        {
            text = new String(field.value);
            
            if( null != alertMessage )
            {
                alert( alertMessage );
            }
            
            field.value = text.substr(0, maxLength);
        }
        
    }
    
}