var lockLoading = $("<div/>").addClass("lockLoading").text("Trwa wysyłanie. Proszę czekać.");

$(function()
{
    $("#leftMenu a").live('click',function(e){
        var next = $(this).next();
        if (next.is("ul")) {
            e.preventDefault();
            next.slideToggle(200);
        }
    });

});

function initLangSelector() {
    $("#langSlctr").change(function() {
        getPageLang($(this).find("option:selected").val());
    });
}

function showLoading() {
    //console.log("showLoading");
    $("body").append(lockLoading);
}

function hideLoading() {
    //console.log("hideLoading");
    lockLoading.detach();
}

function initFontSizeChange() {
    $(".fontSize .big").click(function(e){
				e.preventDefault();																			 
        $(".fontChangeArea").contents().addClass("fontBig");
    });
    $(".fontSize .normal").click(function(e){
				e.preventDefault();																												
        $(".fontChangeArea").contents().removeClass("fontBig");
    });
}


function refreshCameraImage() {
    $("#camera-image").attr('src',$("#camera-image").attr('alt') + '&r=' + Math.random());
    setTimeout('refreshCameraImage()',2000); // refresh every 5 secs
}

function faqMainChange() {
    $("#faq-cat").change(function() {
        $.ajax({
            type: "GET",
            url: '/show/_show_fcat.php',
            data: ({
                fcat: $("#faq-cat").val()
                }),
            success: function(msg){
                $('#cont-fcat').html(msg);
            }
        });
    });
}

function faqSubChange() {
    $("#faq-subcat").change(function() {
        $.ajax({
            type: "GET",
            url: '/show/_show_faqs.php',
            data: ({
                fcat: $("#faq-subcat").val()
                }),
            success: function(msg){
                $('#cont-faqs').html(msg);
            }
        });
    });
}

function wthrChange() {
    $("#wthr-city").change(function() {
        $.ajax({
            type: "GET",
            url: '/show/_show_wthr.php',
            data: ({
                city: $("#wthr-city").val()
                }),
            success: function(msg){
                $('#cont-wthr').html(msg);
            }
        });
    });
}

function initMailIt() {
    $("#mailIt").click(function() {
        $("#camera-cont").show();
    });
    $("#closeMailIt").click(function() {
        $("#camera-cont").hide();
    });
}

if ($)
    $(function() {
        $("#show-camera").live('click',function() {
            $("#camera-cont").show();
        });
        $("#hide-camera").live('click',function() {
            $("#camera-cont").hide();
        });
    });

function change_parent_url(url) {
    document.getElementById('poz').src = url;
}
function reload_parent_url(url) {
    document.getElementById('list').contentDocument.location.reload();
// document.getElementById('list').src = url;
}

function lm_resize(x) {
    $('#leftmenu').css("height",x+'px')
}

function loadGM(x) {
    if (GBrowserIsCompatible()) {
        var map = new GMap2(document.getElementById("map"));
        map.setCenter(new GLatLng(54.380832,18.468549), 14);
        map.addControl(new GLargeMapControl());
        map.addControl(new GMapTypeControl());
        map.openInfoWindow(map.getCenter(),document.createTextNode(x));
        var pas = new GPolygon([
            new GLatLng(54.380089,18.465089),
            new GLatLng(54.381101,18.465807),
            new GLatLng(54.380232,18.46938),
            new GLatLng(54.380739,18.469756),
            new GLatLng(54.380845,18.471247),
            new GLatLng(54.380426,18.47173),
            new GLatLng(54.380245,18.471644),
            new GLatLng(54.379483,18.474605),
            new GLatLng(54.378027,18.473554),
            new GLatLng(54.37877,18.470163),
            new GLatLng(54.37847,18.469841),
            new GLatLng(54.378133,18.469187),
            new GLatLng(54.377995,18.468189),
            new GLatLng(54.377377,18.469101),
            new GLatLng(54.376883,18.470217),
            new GLatLng(54.376333,18.472631),
            new GLatLng(54.376189,18.475742),
            new GLatLng(54.375896,18.47585),
            new GLatLng(54.375802,18.474959),
            new GLatLng(54.371421,18.49234),
            new GLatLng(54.370965,18.491975),
            new GLatLng(54.38097,18.451506),
            new GLatLng(54.381395,18.451871),
            new GLatLng(54.381413,18.452203),
            new GLatLng(54.381801,18.452225),
            new GLatLng(54.381795,18.452783),
            new GLatLng(54.381438,18.452911),
            new GLatLng(54.381001,18.453695),
            new GLatLng(54.379933,18.458083),
            new GLatLng(54.38042,18.457568),
            new GLatLng(54.380576,18.457997),
            new GLatLng(54.37997,18.458941),
            new GLatLng(54.379133,18.461312),
            new GLatLng(54.378395,18.464445),
            new GLatLng(54.378239,18.467031),
            new GLatLng(54.378933,18.466408),
            new GLatLng(54.379345,18.466494),
            new GLatLng(54.379626,18.466516),
            new GLatLng(54.380089,18.465089)
            ], "#0072bb", 0, 0, "#0072bb", 1);
        map.addOverlay(pas);
        var blueIcon = new GIcon(G_DEFAULT_ICON);
        blueIcon.image = "http://glwa.caogroup.pl/img/arrows_up.jpg";
        blueIcon.iconSize = new GSize(20, 20);
        markerOptions = {
            icon:blueIcon
        };
        var latlng = new GLatLng(54.380832,18.468549);
        map.addOverlay(createMarker(latlng,1, markerOptions));
    }
}

function createMarker(latlng, number,markerOptions) {
    var marker = new GMarker(latlng,markerOptions);
    marker.value = number;
    GEvent.addListener(marker,"click", function() {
        var myHtml = "<b>#" + number + "</b><br/>" + message[number -1];
        map.openInfoWindowHtml(latlng, myHtml);
    });
    return marker;
}

function ToggleFlights() {
    try {
    //console.log('ToggleFlights')
    } catch (e) {}
    $('#more-view').toggle();
    $('.show-more').toggle();
}

function initLogout(x) {
    $("#sign-out").click(function () {
        try {
        //console.log('initLogout');
        } catch (e) {}
        if(confirm(x)) {
            getPageLogout();
        }
    });
}

function searchMiniInit(a,x) {
    $("#mwords").focus(function () {
        if ($(this).val() == a ) $(this).val('') ;
    });
    $("#mwords").blur( function () {
        if ($.trim($(this).val()) == '' ) $(this).val(a) ;
    });

    $("#mwords").unbind('keypress').keypress(function(event){
        if ((event.which && event.which == 13) || (event.keyCode && event.keyCode == 13)) {
            $("#mgo-search").trigger('click');
        }
    });

    $("#mgo-search").click(function() {
        if ($.trim($("#mwords").val()) == '' || $.trim($("#mwords").val()) == a) {
            alert(x);
            $("#mwords").focus();
        } else {
            var url="/show/_show_search.php?" + $("#msearch-form").serialize();
            getPage('search','');
            xmlreqGET('search-result', url);
        }
        return false;
    }
    );
}


function searchInit(a,x) {
    $("#words").focus(function () {
        if ($(this).val() == a ) $(this).val('') ;
    });
    $("#words").blur( function () {
        if ($.trim($(this).val()) == '' ) $(this).val(a) ;
    });

    $("#words").unbind('keypress').keypress(function(event){
        if ((event.which && event.which == 13) || (event.keyCode && event.keyCode == 13)) {
            $("#go-search").trigger('click');
            return false;
        }
    });

    $("#go-search").click(function() {
        if ($.trim($("#words").val()) == '' || $.trim($("#words").val()) == a) {
            alert(x);
            $("#words").focus();
        } else {
            var url="/show/_show_search.php?" + $("#search-form").serialize();
            xmlreqGET('search-result', url);
        }
    }
    );
}

function setCompetition(a,b,c,d,e, f1, g1, h1, i1, j1) {

    $("#cf_first_name").focus(function () {
        if ($(this).val() == f1 ) $(this).val('') ;
    });
    $("#cf_first_name").blur(function () {
        if ($.trim($(this).val()) == '' ) $(this).val(f1) ;
    });

    $("#cf_last_name").focus(function () {
        if ($(this).val() == g1 ) $(this).val('') ;
    });
    $("#cf_last_name").blur(function () {
        if ($.trim($(this).val()) == '' ) $(this).val(g1) ;
    });

    $("#cf_email").focus(function () {
        if ($(this).val() == h1 ) $(this).val('') ;
    });
    $("#cf_email").blur(function () {
        if ($.trim($(this).val()) == '' ) $(this).val(h1) ;
    });

    $("#cf_tel").focus(function () {
        if ($(this).val() == i1 ) $(this).val('') ;
    });
    $("#cf_tel").blur(function () {
        if ($.trim($(this).val()) == '' ) $(this).val(i1) ;
    });

    $("#cf_slogan").focus(function () {
        if ($(this).val() == j1 ) $(this).val('') ;
    });
    $("#cf_slogan").blur(function () {
        if ($.trim($(this).val()) == '' ) $(this).val(j1) ;
    });


    $("#clear-form").click(function () {
        $("#competition-form").resetForm();
    });

    $("#send-form").click(function () {
        if ($.trim($("#cf_first_name").val()) == ''   || $.trim($("#cf_first_name").val()) ==  f1) {
            alert(a);
            $("#cf_first_name").focus();
        }
        else if ($.trim($("#cf_last_name").val()) == ''   || $.trim($("#cf_last_name").val()) ==  g1) {
            alert(b);
            $("#cf_last_name").focus();
        }
        else if (!isEmail($.trim($("#cf_email").val()))) {
            alert(c);
            $("#cf_email").focus();
        }
        else if ($.trim($("#cf_slogan").val()) == '' || $.trim($("#cf_slogan").val()) == j1) {
            alert(d);
            $("#cf_slogan").focus();
        }
        else if (!$("#cf_agree:checked").length) {
            alert(e);
            $("#cf_agree").focus();
        }
        else  {
            var url="/_competition.php?" + $("#competition-form").serialize();
            xmlreqGET('competition-msg',url);
        }
    });
}


function setNotification(a,b,c,a1,b1,c1) {
    $("#nf_email_to").focus(function () {
        if ($(this).val() == a1 ) $(this).val('') ;
    });
    $("#nf_email_to").blur(function () {
        if ($.trim($(this).val()) == '' ) $(this).val(a1) ;
    });

    $("#nf_email").focus(function () {
        if ($(this).val() == b1 ) $(this).val('') ;
    });
    $("#nf_email").blur(function () {
        if ($.trim($(this).val()) == '' ) $(this).val(b1) ;
    });

    $("#nf_content").focus(function () {
        if ($(this).val() == c1 ) $(this).val('') ;
    });
    $("#cf_content").blur(function () {
        if ($.trim($(this).val()) == '' ) $(this).val(c1) ;
    });

    $("#send-form").click(function () {
        if (!isEmail($("#nf_email_to").val())) {
            alert(a);
            $("#nf_email_to").focus();
        } else
        if (!isEmail($("#nf_email").val())) {
            alert(b);
            $("#nf_email").focus();
        } else
        if ($.trim($("#nf_content").val()) == '' || $.trim($("#nf_content").val()) == c1) {
            alert(c);
            $("#nf_content").focus();
        } else
{
            $("#notification-form").submit();
        }
    });
}

function removeError()
{
    $(this).removeClass('inputError').parents().removeClass('inputError');
}

function scrollTop(x)
{
    $(document).scrollTop(x.offset().top - 40);
}

function setPRM(a,b)
{
    var prm_first_name = $("#prm_first_name").keyup(removeError);
    var prm_last_name = $("#prm_last_name").keyup(removeError);

    var prm_direction = $("[name='prm_direction']").change(removeError);

    var prm_date = $("#prm_date").keyup(removeError).blur(removeError);
    var prm_hour = $("#prm_hour").change(removeError);
    var prm_minutes = $("#prm_minutes").change(removeError);
    var prm_flight_number_1 = $("#prm_flight_number_1").keyup(removeError);
    var prm_flight_number_2 = $("#prm_flight_number_2").keyup(removeError);

    var prm_have_company = $("[name='prm_have_company']").change(removeError);
    var prm_assist = $("[name='prm_assist[]']").change(removeError);
    var prm_use_wheelchair = $("[name='prm_use_wheelchair']").change(removeError);
    var prm_need_wheelchair = $("[name='prm_need_wheelchair']").change(removeError);
    var prm_have_guide = $("[name='prm_have_guide']").change(removeError);

    $("#clear-form").click(function () {
        $("#prm-form").resetForm();
    });
    $("#send-form").click(function () {
    {
        if ($.trim(prm_first_name.val())=="")
        {
            alert(a);
            prm_first_name.addClass("inputError").focus();
            scrollTop(prm_first_name);
            return;
        }
        else
        if ($.trim(prm_last_name.val())=="")
        {
            alert(a);
            prm_last_name.addClass("inputError").focus();
            scrollTop(prm_last_name);
            return;
        }
        else
        if (!prm_direction.filter(':checked').size())
        {
            alert(a);
            prm_direction.parents("fieldset").addClass("inputError");
            scrollTop(prm_direction.eq(0).focus());
            return;
        }
        else
        if ($.trim(prm_date.val())=="")
        {
            alert(a);
            prm_date.addClass("inputError").focus();
            scrollTop(prm_date);
            return;
        }
        else
        if (prm_hour.val() == '-')
        {
            alert(a);
            prm_hour.addClass("inputError").focus();
            scrollTop(prm_hour);
            return;
        }
        else
        if (prm_minutes.val() == '-')
        {
            alert(a);
            prm_minutes.addClass("inputError").focus();
            scrollTop(prm_minutes);
            return;
        }
        else
        if ($.trim(prm_flight_number_1.val())=="")
        {
            alert(a);
            prm_flight_number_1.addClass("inputError").focus();
            scrollTop(prm_flight_number_1);
            return;
        }
        else
        if ($.trim(prm_flight_number_2.val())=="")
        {
            alert(a);
            prm_flight_number_2.addClass("inputError").focus();
            scrollTop(prm_flight_number_2);
            return;
        }
        else
        if (!prm_have_company.filter(':checked').size())
        {
            alert(a);
            prm_have_company.parents("fieldset").addClass("inputError");
            scrollTop(prm_have_company.eq(0).focus());
            return;
        }
        else
        if (!prm_assist.filter(':checked').size())
        {
            alert(b);
            prm_assist.parents("fieldset").addClass("inputError");
            scrollTop(prm_assist.eq(0).focus());
            return;
        }
        else
        if (!prm_use_wheelchair.filter(':checked').size())
        {
            alert(a);
            prm_use_wheelchair.parents("fieldset").addClass("inputError");
            scrollTop(prm_use_wheelchair.eq(0).focus());
            return;
        }
        else
        if (!prm_need_wheelchair.filter(':checked').size())
        {
            alert(a);
            prm_need_wheelchair.parents("fieldset").addClass("inputError");
            scrollTop(prm_need_wheelchair.eq(0).focus());
            return;
        }
        else
        if (!prm_have_guide.filter(':checked').size())
        {
            alert(a);
            prm_have_guide.parents("fieldset").addClass("inputError");
            scrollTop(prm_have_guide.eq(0).focus());
            return;
        }
        else
        {
            var url="/_prm.php?" + $("#prm-form").serialize();
            xmlreqGET('prm-form',url);
            $(document).scrollTop(0);
        }
    }
    });
}

function setContact(d,e,t,c,e1,t1,c1) {
    $("#cf_email").focus(function () {
        if ($(this).val() == e1 ) $(this).val('') ;
    });
    $("#cf_email").blur(function () {
        if ($.trim($(this).val()) == '' ) $(this).val(e1) ;
    });
    //	$("#cf_subject").focus(function () {	if ($(this).val() == t1 ) $(this).val('') ;					});
    //	$("#cf_subject").blur(function () {		if ($.trim($(this).val()) == '' ) $(this).val(t1) ;	});
    $("#cf_content").focus(function () {
        if ($(this).val() == c1 ) $(this).val('') ;
    });
    $("#cf_content").blur(function () {
        if ($.trim($(this).val()) == '' ) $(this).val(c1) ;
    });
    $("#clear-form").click(function () {
        $("#contact-form").resetForm();
    } );
    $("#send-form").click(function () {
        if (!$("input:checked").length) {
            alert(d);
            $("#sub0").focus();
        }
        else if ($.trim($("#cf_email").val()) == ''   || $.trim($("#cf_email").val()) ==   e1) {
            alert(e);
            $("#cf_email").focus();
        }
        //		else if ($.trim($("#cf_subject").val()) == '' || $.trim($("#cf_subject").val()) == t1) { alert(t); $("#cf_subject").focus();  }
        else if ($.trim($("#cf_content").val()) == '' || $.trim($("#cf_content").val()) == c1) {
            alert(c);
            $("#cf_content").focus();
        }
        else {
            var url="/_contact.php?" + $("#contact-form").serialize();
            xmlreqGET('contact-form',url);
            $(document).scrollTop(0);
        }
    });
}

function buyInit(page_link, x) {
    var url="/show/_show_page.php?page_link=" + page_link;
    var query;
    $("#where").focus(function () {
        if ($(this).val() == x ) $(this).val('') ;
    });
    $("#where").blur(function () {
        if ($.trim($(this).val()) == '' ) $(this).val(x) ;
    });
    $("#go-mini").click(function() {
        if ($.trim($("#where").val()) == x) $("#where").val('');
        query = "&how=" + $(":checked").val();
        query = query + "&where=" + $("#where").val();
        query = query + "&d1=" + $("#d1").val();
        query = query + "&m1=" + $("#m1").val();
        query = query + "&d2=" + $("#d2").val();
        query = query + "&m2=" + $("#m2").val();
        query = query + "&adults=" + $("#adults").val();
        query = query + "&children=" + $("#children").val();
        query = query + "&infants=" + $("#infants").val();
        url = url + query;
        xmlreqGET('adiv',url);
    });
}


function contactInit() {
    $("#clear-form").click(function() {
        $("#cf_content").val('');
        $("#cf_subject").val('');
        $("#cf_main_subject").val('');
    });

}
function titleUpdate(t) {
    document.getElementsByTagName("title")[0].text = t;
}

function initSubs(x) {
    $("#inNewsletter").focus(function () {
        if ($(this).val() == x ) $(this).val('') ;
    });
    $("#inNewsletter").blur(function () {
        if ($.trim($(this).val()) == '' ) $(this).val(x) ;
    });
}

function initLogin(x,y) {
    $("#login").focus(function () {
        if ($(this).val() == x ) $(this).val('') ;
    });
    $("#login").blur(function () {
        if ($.trim($(this).val()) == '' ) $(this).val(x) ;
    });

    $("#passt").focus(function () {
        $(this).toggle();
        $("#pass").toggle().focus();
    })
    $("#pass").blur(function () {
        if ($.trim($(this).val()) == '' ) {
            $(this).toggle();
            $(this).val('');
            $("#passt").toggle().blur();
        }
    });
}

var xmlreqs = new Array();

function CXMLReq(freed) {
    this.freed = freed;
    this.xmlhttp = false;
    this.xmlhttp = GetXmlHttpObject();
}

function xmlreqGET(para,url) {
    var pos = -1;
    for (var i=0; i<xmlreqs.length; i++) {
        if (xmlreqs[i].freed == 1) {
            pos = i;
            break;
        }
    }
    if (pos == -1) {
        pos = xmlreqs.length;
        xmlreqs[pos] = new CXMLReq(1);
    }
    if (xmlreqs[pos].xmlhttp) {
        xmlreqs[pos].freed = 0;
        xmlreqs[pos].xmlhttp.open("GET",url,true);
        xmlreqs[pos].xmlhttp.onreadystatechange = function() {
            if (typeof(xmlhttpChange) != 'undefined') {
                xmlhttpChange(pos,para);
            }
        }
        if (window.XMLHttpRequest) {
            xmlreqs[pos].xmlhttp.send(null);
        } else if (window.ActiveXObject) {
            xmlreqs[pos].xmlhttp.send();
        }
    }
}

function xmlreqPOST(para,url,data) {
    var pos = -1;
    for (var i=0; i<xmlreqs.length; i++) {
        if (xmlreqs[i].freed == 1) {
            pos = i;
            break;
        }
    }
    if (pos == -1) {
        pos = xmlreqs.length;
        xmlreqs[pos] = new CXMLReq(1);
    }
    if (xmlreqs[pos].xmlhttp) {
        xmlreqs[pos].freed = 0;
        xmlreqs[pos].xmlhttp.open("POST",url,true);
        xmlreqs[pos].xmlhttp.onreadystatechange = function() {
            if (typeof(xmlhttpChange) != 'undefined') {
                xmlhttpChange(pos,para);
            }
        }
        xmlreqs[pos].xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
        xmlreqs[pos].xmlhttp.send(data);
    }
}

function handleResponse(responseText, para) {
    $("#" + para).html(responseText);

}

function xmlhttpChange(pos,para) {
    if (typeof(xmlreqs[pos]) != 'undefined' && xmlreqs[pos].freed == 0 ) {
        if (xmlreqs[pos].xmlhttp.readyState == 4 ) {
            if (xmlreqs[pos].xmlhttp.status == 200 || xmlreqs[pos].xmlhttp.status == 304) {
                handleResponse(xmlreqs[pos].xmlhttp.responseText, para);
            } else {
                alert('Proszę odświeżyć stronę.');
            }
            xmlreqs[pos].freed = 1;
        }
    }
}
function goToSchedule(dir) {
    SWFAddress.setValue('schedule/' + dir + '&open=1');
}

function getPage(page_link, params) {
    try {
    //console.log('getPage',page_link, params)
    } catch (e) {}
    var url="/show/_show_page.php?page_link=" + page_link;
    if (params.length) url += params;
    xmlreqGET('adiv',url);
}

function getRecord(what,id,opts) {
    var url="/show/_show_"+ what +".php?" + what + "=" +id + "&options=" + opts;
    //		alert(what);
    xmlreqGET('cont-'+what,url);
}
function getPageEdit(edit) {
    var url="/show/_show_page.php?edit=" + edit;
    xmlreqGET('adiv',url);
}
function getPageLang(lang) {
    var url="/show/_show_page.php?lang=" + lang;
    xmlreqGET('adiv',url);
}
function getPageSubs(email) {
    var url="/show/_show_subs.php";
    if (isEmail(email)) url = url + "?email=" + email;
    xmlreqGET('bxNewsletterForm',url);
}
function getPageTop() {
    var url="/show/_show_top.php";
    xmlreqGET('menu-user',url);
}
function getPageBottom() {
    var url="/show/_show_bottom.php";
    xmlreqGET('containerFooter',url);
}
function getPageLogin(login, pass) {
    var url="/show/_show_page.php";
    url = url + "?login=" + login;
    url = url + "&pass=" + pass;
    xmlreqGET('adiv',url);
}
function getPageLogout() {
    var url="/show/_show_page.php?logout=1";
    xmlreqGET('adiv',url);
}

function GetXmlHttpObject() {
    var xmlHttpObject=null;
    try {
        xmlHttpObject = new ActiveXObject("Msxml2.XMLHTTP");
    } catch (e) {
        try {
            xmlHttpObject = new ActiveXObject("Microsoft.XMLHTTP");
        } catch (E) {
            xmlHttpObject = false;
        }
    }
    if (!xmlHttpObject && typeof XMLHttpRequest != "undefined") {
        try {
            xmlHttpObject = new XMLHttpRequest();
        } catch (e) {
            xmlHttpObject = false;
        }
    }
    return xmlHttpObject;
}

function menuUpdate(I,l){
    try {
    //console.log('menuUpdate')
    } catch (e) {}
    getPageSubs();
    /* try {
        getSWF("leftmenu").updateMenu(I,l);
    } catch (e) {}*/
    try {
        getSWF("topmenu").updateMenu(I,l);
    } catch (e) {}
}
function menuRefresh(I,l){
    try {
    //console.log('menuRefresh')
    } catch (e) {}
    getPageSubs();
    /*try {
        getSWF("leftmenu").refreshMenu(I,l);
    } catch (e) {}*/
    try {
        getSWF("topmenu").refreshMenu(I,l);
    } catch (e) {}
}

function handleChange(event) {
    var parameters = '';
    for (var p in event.parameters) {
        parameters += '&' + p + '=' + event.parameters[p];
    }
    if (event.path !=  '/') getPage( event.path.substring(1), parameters);
}

function getSWF(i){
    try{
        if(top.document.embeds&&top.document.embeds[i]){
            return top.document.embeds[i]
        }else{
            return top.document.getElementById(i)
        }
    }
    catch(e){
        if(e.toString().indexOf("cyclic __proto__ value")>-1)getSWF(i)
    }
}

function sho_hid(I,l){
    var i=document.getElementById(I);
    i.className=l?"visy":"vis"
}

var isIE=(navigator.appVersion.indexOf("MSIE")!=-1)?true:false,isWin=(navigator.appVersion.toLowerCase().indexOf("win")!=-1)?true:false,isOpera=(navigator.userAgent.indexOf("Opera")!=-1)?true:false;
function js_check_group(I){
    elements=document.forms[I].elements;
    for(var i=0;i<elements.length;i++){
        if(elements[i].type=="checkbox"){
            elements[i].onclick=sel_down
        }
    }
}
function sel_down(){
    var o=this,I=Array(),i=o.form.elements,l=o.id.match(/rel_\d+_(\d+)/i);
    for(var O=0;O<i.length;O++){
        if(i[O].type=="checkbox"){
            I=i[O].id.match(/rel_(\d+)_\d+/i);
            if(I[1]==l[1]){
                if(o.checked){
                    i[O].checked=true
                }else{
                    i[O].checked=false
                }
            }
        }
    }
}
function isEmail(i){
    return /^[\w-]+(\.[\w-_]+)*@([\w-]+\.)+[a-zA-Z]{2,7}$/.test(i);
}
function fu(){
    x=document.kont.eml.selectedIndex;
    y=document.kont.imnaz;
    y.options[x].selected=true
}
function tot(){
    x=document.kont.imnaz.selectedIndex;
    y=document.kont.eml;
    y.options[x].selected=true
}
function myk(I){
    var i=I.parentNode.nextSibling.nextSibling;
    if(i.className=='visy'){
        i.className='vis'
    }else{
        i.className='visy'
    }
}

var hexcase=0,b64pad="",chrsz=8;
function hex_md5(i){
    return binl2hex(core_md5(str2binl(i),i.length*chrsz))
}
function b64_md5(i){
    return binl2b64(core_md5(str2binl(i),i.length*chrsz))
}
function str_md5(i){
    return binl2str(core_md5(str2binl(i),i.length*chrsz))
}
function hex_hmac_md5(i,I){
    return binl2hex(core_hmac_md5(i,I))
}
function b64_hmac_md5(i,I){
    return binl2b64(core_hmac_md5(i,I))
}
function str_hmac_md5(i,I){
    return binl2str(core_hmac_md5(i,I))
}
function md5_vm_test(){
    return hex_md5("abc")=="900150983cd24fb0d6963f7d28e17f72"
}
function core_md5(V,X){
    V[X>>5]|=0x80<<((X)%32);
    V[(((X+64)>>>9)<<4)+14]=X;
    var x=1732584193,I=-271733879,i=-1732584194,l=271733878;
    for(var o=0;o<V.length;o+=16){
        var O=x,c=I,C=i,v=l;
        x=md5_ff(x,I,i,l,V[o+0],7,-680876936);
        l=md5_ff(l,x,I,i,V[o+1],12,-389564586);
        i=md5_ff(i,l,x,I,V[o+2],17,606105819);
        I=md5_ff(I,i,l,x,V[o+3],22,-1044525330);
        x=md5_ff(x,I,i,l,V[o+4],7,-176418897);
        l=md5_ff(l,x,I,i,V[o+5],12,1200080426);
        i=md5_ff(i,l,x,I,V[o+6],17,-1473231341);
        I=md5_ff(I,i,l,x,V[o+7],22,-45705983);
        x=md5_ff(x,I,i,l,V[o+8],7,1770035416);
        l=md5_ff(l,x,I,i,V[o+9],12,-1958414417);
        i=md5_ff(i,l,x,I,V[o+10],17,-42063);
        I=md5_ff(I,i,l,x,V[o+11],22,-1990404162);
        x=md5_ff(x,I,i,l,V[o+12],7,1804603682);
        l=md5_ff(l,x,I,i,V[o+13],12,-40341101);
        i=md5_ff(i,l,x,I,V[o+14],17,-1502002290);
        I=md5_ff(I,i,l,x,V[o+15],22,1236535329);
        x=md5_gg(x,I,i,l,V[o+1],5,-165796510);
        l=md5_gg(l,x,I,i,V[o+6],9,-1069501632);
        i=md5_gg(i,l,x,I,V[o+11],14,643717713);
        I=md5_gg(I,i,l,x,V[o+0],20,-373897302);
        x=md5_gg(x,I,i,l,V[o+5],5,-701558691);
        l=md5_gg(l,x,I,i,V[o+10],9,38016083);
        i=md5_gg(i,l,x,I,V[o+15],14,-660478335);
        I=md5_gg(I,i,l,x,V[o+4],20,-405537848);
        x=md5_gg(x,I,i,l,V[o+9],5,568446438);
        l=md5_gg(l,x,I,i,V[o+14],9,-1019803690);
        i=md5_gg(i,l,x,I,V[o+3],14,-187363961);
        I=md5_gg(I,i,l,x,V[o+8],20,1163531501);
        x=md5_gg(x,I,i,l,V[o+13],5,-1444681467);
        l=md5_gg(l,x,I,i,V[o+2],9,-51403784);
        i=md5_gg(i,l,x,I,V[o+7],14,1735328473);
        I=md5_gg(I,i,l,x,V[o+12],20,-1926607734);
        x=md5_hh(x,I,i,l,V[o+5],4,-378558);
        l=md5_hh(l,x,I,i,V[o+8],11,-2022574463);
        i=md5_hh(i,l,x,I,V[o+11],16,1839030562);
        I=md5_hh(I,i,l,x,V[o+14],23,-35309556);
        x=md5_hh(x,I,i,l,V[o+1],4,-1530992060);
        l=md5_hh(l,x,I,i,V[o+4],11,1272893353);
        i=md5_hh(i,l,x,I,V[o+7],16,-155497632);
        I=md5_hh(I,i,l,x,V[o+10],23,-1094730640);
        x=md5_hh(x,I,i,l,V[o+13],4,681279174);
        l=md5_hh(l,x,I,i,V[o+0],11,-358537222);
        i=md5_hh(i,l,x,I,V[o+3],16,-722521979);
        I=md5_hh(I,i,l,x,V[o+6],23,76029189);
        x=md5_hh(x,I,i,l,V[o+9],4,-640364487);
        l=md5_hh(l,x,I,i,V[o+12],11,-421815835);
        i=md5_hh(i,l,x,I,V[o+15],16,530742520);
        I=md5_hh(I,i,l,x,V[o+2],23,-995338651);
        x=md5_ii(x,I,i,l,V[o+0],6,-198630844);
        l=md5_ii(l,x,I,i,V[o+7],10,1126891415);
        i=md5_ii(i,l,x,I,V[o+14],15,-1416354905);
        I=md5_ii(I,i,l,x,V[o+5],21,-57434055);
        x=md5_ii(x,I,i,l,V[o+12],6,1700485571);
        l=md5_ii(l,x,I,i,V[o+3],10,-1894986606);
        i=md5_ii(i,l,x,I,V[o+10],15,-1051523);
        I=md5_ii(I,i,l,x,V[o+1],21,-2054922799);
        x=md5_ii(x,I,i,l,V[o+8],6,1873313359);
        l=md5_ii(l,x,I,i,V[o+15],10,-30611744);
        i=md5_ii(i,l,x,I,V[o+6],15,-1560198380);
        I=md5_ii(I,i,l,x,V[o+13],21,1309151649);
        x=md5_ii(x,I,i,l,V[o+4],6,-145523070);
        l=md5_ii(l,x,I,i,V[o+11],10,-1120210379);
        i=md5_ii(i,l,x,I,V[o+2],15,718787259);
        I=md5_ii(I,i,l,x,V[o+9],21,-343485551);
        x=safe_add(x,O);
        I=safe_add(I,c);
        i=safe_add(i,C);
        l=safe_add(l,v)
    }
    return Array(x,I,i,l)
}
function md5_cmn(O,I,i,l,o,c){
    return safe_add(bit_rol(safe_add(safe_add(I,O),safe_add(l,c)),o),i)
}
function md5_ff(c,I,i,l,o,O,C){
    return md5_cmn((I&i)|((~I)&l),c,I,o,O,C)
}
function md5_gg(c,I,i,l,o,O,C){
    return md5_cmn((I&l)|(i&(~l)),c,I,o,O,C)
}
function md5_hh(c,I,i,l,o,O,C){
    return md5_cmn(I^i^l,c,I,o,O,C)
}
function md5_ii(c,I,i,l,o,O,C){
    return md5_cmn(i^(I|(~l)),c,I,o,O,C)
}
function core_hmac_md5(O,C){
    var c=str2binl(O);
    if(c.length>16)c=core_md5(c,O.length*chrsz);
    var I=Array(16),i=Array(16);
    for(var l=0;l<16;l++){
        I[l]=c[l]^0x36363636;
        i[l]=c[l]^0x5C5C5C5C
    }
    var o=core_md5(I.concat(str2binl(C)),512+C.length*chrsz);
    return core_md5(i.concat(o),512+128)
}
function safe_add(i,o){
    var l=(i&0xFFFF)+(o&0xFFFF),I=(i>>16)+(o>>16)+(l>>16);
    return(I<<16)|(l&0xFFFF)
}
function bit_rol(i,I){
    return(i<<I)|(i>>>(32-I))
}
function str2binl(o){
    var l=Array(),I=(1<<chrsz)-1;
    for(var i=0;i<o.length*chrsz;i+=chrsz)l[i>>5]|=(o.charCodeAt(i/chrsz)&I)<<(i%32);
    return l
}
function binl2str(o){
    var l="",I=(1<<chrsz)-1;
    for(var i=0;i<o.length*32;i+=chrsz)l+=String.fromCharCode((o[i>>5]>>>(i%32))&I);
    return l
}
function binl2hex(o){
    var l=hexcase?"0123456789ABCDEF":"0123456789abcdef",I="";
    for(var i=0;i<o.length*4;i++){
        I+=l.charAt((o[i>>2]>>((i%4)*8+4))&0xF)+l.charAt((o[i>>2]>>((i%4)*8))&0xF)
    }
    return I
}
function binl2b64(c){
    var O="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",I="";
    for(var i=0;i<c.length*4;i+=3){
        var l=(((c[i>>2]>>8*(i%4))&0xFF)<<16)|(((c[i+1>>2]>>8*((i+1)%4))&0xFF)<<8)|((c[i+2>>2]>>8*((i+2)%4))&0xFF);
        for(var o=0;o<4;o++){
            if(i*8+o*6>c.length*32)I+=b64pad;else I+=O.charAt((l>>6*(3-o))&0x3F)
        }
    }
    return I
}

function window_open(i,I){
    newWindow=window.open(i,I,"height=570,width=770");
    newWindow.focus();
}

function mod97(l){
    var I=0;
    var i=[];
    var O=[];
    i[1]=1;
    O[1]=parseInt(l.substring(29,30));
    I=i[1]*O[1];
    for(var o=2;o<=30;o+=1){
        i[o]=(i[o-1]*10)%97;
        O[o]=parseInt(l.substring(30-o,30-o+1));
        I=I+i[o]*O[o]
    }
    return(I%97)
}

function validate_agreement(){
    var i=document.declaration;
    al='Aby wysłać deklarację, należy zaakceptować warunki.';
    if(i.agree&&!i.agree.checked){
        alert(al);
        i.agree.focus();
        return false
    }
    if(i.agree2&&!i.agree2.checked){
        alert(al);
        i.agree2.focus();
        return false
    }
    if(i.agree3&&!i.agree3.checked){
        alert(al);
        i.agree3.focus();
        return false
    }else return true
}
function is_postal_code(l){
    var i=l.value,I=/^[0-9]{2}-[0-9]{3}$/;
    if(i.match(I))return true;else return false
}
function checkSum(i){
    if(i.length==26)i="PL"+i;
    country=i.substring(0,2);
    cc=i.substring(2,4);
    rest=i.substring(4,28);
    base=replaceAlpha(rest+country+cc);
    if(mod97(base)==1)return true;else
        return false
}
function replaceAlpha(I){
    I=I.toUpperCase();
    var i="";
    for(var l=0;l<I.length;l++)i+=(I.charCodeAt(l)>=65?Number(I.charCodeAt(l)-55):I.charAt(l));
    return(i)
}
function is_IBANAccount(l){
    var i=/\d{26}/,I=/[a-zA-Z]{2}\d{26}/ig;
    if(l.match(i))return checkSum(l);
    return false
}
function is_pesel(l){
    var i=l.value,I=/^[0-9]{11}$/;
    if(i.match(I))return true;else return false
}
function is_decimal(l){
    var i=l.value,I=/^[0-9]+$/;
    if(i.match(I))return true;else return false
}
function is_id_number(l){
    var i=l.value,I=/^[a-zA-Z]{3}[0-9]{6}$/;
    if(i.match(I))return true;else return false
}
function is_currency(i,o){
    var l=i.value,I=/(^\d+$)|(^\d+\.\d+$)|(^\d+\,\d+$)/;
    if(l.match(I)&&(parseInt(l)>=parseInt(o)))return true;else return false
}

