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

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

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

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

function showHideCamera() { 
    jQuery("#show-camera").click(function() {
        jQuery("#camera-cont").show();
    });
    jQuery("#hide-camera").click(function() {
        jQuery("#camera-cont").hide();
    });
}

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

function lm_resize(x) {
    jQuery('#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) {}
    jQuery('#more-view').toggle();
    jQuery('.show-more').toggle();
}

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

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

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

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


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

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

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

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

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


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

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


function contactInit() {
    jQuery("#clear-form").click(function() {
        jQuery("#cf_content").val('');
        jQuery("#cf_subject").val('');
        jQuery("#cf_main_subject").val('');
    });
	
}
function titleUpdate(t) {
    document.getElementsByTagName("title")[0].text = t;
}

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

function initLogin(x,y) {
    jQuery("#login").focus(function () {
        if (jQuery(this).val() == x ) jQuery(this).val('') ;
    });
    jQuery("#login").blur(function () {
        if (jQuery.trim(jQuery(this).val()) == '' ) jQuery(this).val(x) ;
    });
	
    jQuery("#passt").focus(function () {
        jQuery(this).toggle();
        jQuery("#pass").toggle().focus();
    })
    jQuery("#pass").blur(function () {
        if (jQuery.trim(jQuery(this).val()) == '' ) {
            jQuery(this).toggle();
            jQuery(this).val('');
            jQuery("#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 handle_response(responseText, para) {
    jQuery("#" + 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) {
                handle_response(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) {
    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 (is_em(email)) url = url + "?email=" + email;
    xmlreqGET('subs_form',url);
}
function getPageTop() {
    var url="/show/_show_top.php";
    xmlreqGET('menu-user',url);
}
function getPageBottom() {
    var url="/show/_show_bottom.php";
    xmlreqGET('container-bot',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) {}
    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) {}
    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 is_em(i){
    var I=/^[\w-]+(\.[\w-_]+)*@([\w-]+\.)+[a-zA-Z]{2,7}$/;if(i.match(I))return true;else return false
}
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=700,width=500");newWindow.focus()
}
function is_radio_checked(I){
    for(i=0;i<I.length;i++)if(I[i].checked)return true;return false
}
function validate_declaration(I){
    var i=document.declaration;if(i.surname.value==''){
        alert('Podaj nazwisko.');i.surname.focus();return false
    }else if(i.name.value==''){
        alert('Podaj imię.');i.name.focus();return false
    }else if(!is_id_number(i.id_number)){
        alert('Podaj prawidłowy numer i serię dowodu osobistego.');i.id_number.focus();return false
    }else if(!is_pesel(i.pesel)){
        alert('Podaj prawidłowy numer PESEL.');i.pesel.focus();return false
    }else if(i.birth_place.value==''){
        alert('Podaj miejsce urodzenia.');i.birth_place.focus();return false
    }else if(i.tel1.value.length+i.tel2.value.length<9){
        alert('Podaj prawidłowy numer telefonu w formacie XX XXXXXXX lub XXX XXXXXX.');i.tel1.focus();return false
    }else if(!is_em(i.email)){
        alert('Podaj prawidłowy adres e-mail.');i.email.focus();return false
    }else if(i.p_street.value==''){
        alert('Podaj ulicę.');i.p_street.focus();return false
    }else if(i.p_street_number.value==''&&i.p_local_number.value==''){
        alert('Podaj numer ulicy i/lub numer loklau.');i.p_street_number.focus();return false
    }else if(!is_postal_code(i.p_postal_code)){
        alert('Podaj prawidłowy kod pocztowy w formacie XX-XXX.');i.p_postal_code.focus();return false
    }else if(i.p_city.value==''){
        alert('Podaj miasto.');i.p_city.focus();return false
    }else if(i.delivery_time&&!is_radio_checked(i.delivery_time)){
        alert('Podaj godziny odbioru przesyłki.');i.delivery_time_1.focus();return false
    }else if(i.amount&&!is_currency(i.amount,parseInt(I))){
        alert('Podaj prawidłową kwotę inwestycji.');i.amount.focus();return false
    }else if(i.account_number&&!is_IBANAccount(i.account_number.value)){
        alert('Podaj prawidłowy numer konta bankowego w formacie NRB (26 cyfr).');i.account_number.focus();return false
    }else return true
}
function validate_contact(){
    var i=document.contact;if(i.surname.value==''){
        alert('Podaj nazwisko.');i.surname.focus();return false
    }else if(i.name.value==''){
        alert('Podaj imię.');i.name.focus();return false
    }else if(i.tel1.value.length+i.tel2.value.length<9){
        alert('Podaj prawidłowy numer telefonu w formacie XX XXXXXXX lub XXX XXXXXX.');i.tel1.focus();return false
    }else if(!is_em(i.email)){
        alert('Podaj prawidłowy adres e-mail.');i.email.focus();return false
    }else if(i.city.value==''){
        alert('Podaj miasto.');i.city.focus();return false
    }else if(i.content.value==''){
        alert('Podaj treść zapytania.');i.content.focus();return false
    }else if(!i.agree_contact.checked){
        alert('Aby wysłać zapytanie, należy zaakceptować warunki.');i.agree_contact.focus();return false
    }else if(!i.agree_contact2.checked){
        alert('Aby wysłać zapytanie, należy zaakceptować warunki.');i.agree_contact2.focus();return false
    }else return true
}
function validate_sal(){
    var i=document.declaration;if(i.surname.value==''){
        alert('Podaj nazwisko.');i.surname.focus();return false
    }else if(i.name.value==''){
        alert('Podaj imię.');i.name.focus();return false
    }else if(!is_pesel(i.pesel)){
        alert('Podaj numer PESEL.');i.pesel.focus();return false
    }else if(!is_decimal(i.participation)){
        alert('Podaj procentowy udział w uposażeniu. Suma musi być równa 100%.');i.participation.focus();return false
    }else if(i.street.value==''){
        alert('Podaj ulicę.');i.street.focus();return false
    }else if(i.street_number.value==''&&i.local_number.value==''){
        alert('Podaj numer ulicy i/lub numer loklau.');i.street_number.focus();return false
    }else if(!is_postal_code(i.postal_code)){
        alert('Podaj prawidłowy kod pocztowy w formacie XX-XXX.');i.postal_code.focus();return false
    }else if(i.city.value==''){
        alert('Podaj miasto.');i.city.focus();return false
    }else return true
}
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
}
