﻿function wysz(prefix) {
    var rodz = document.getElementById("ctl00_lstRodzaje");

    rodz.onclick = function() {
       var pok = document.getElementById("ctl00_trpokoje");
            
       if (this.value == "2") {
           pok.style.visibility = "hidden";
           pok.style.display = "none";
       } else {
           pok.style.visibility = "visible";
           pok.style.display = "table-row";
       }
    };
}

var a=0;

function step2(){
	var b = new Browser;
	a+=1;
	if (a>9) {a=1;}
	var grafika=document.getElementById("grafika");
	grafika.src="img/foto"+String(a)+".jpg";
}
function skrol(){
	var kol=document.getElementById("kol");
	if (kol) {
		if (document.body.scrollTop>40) {kol.style.marginTop=document.body.scrollTop-40;} else {
			kol.style.marginTop=0;
		}
	}
}
var dfggty=window.setInterval("skrol()",100);

function start() {
}

// var scroll=0;
// var scrollValue = 0;
// var scrollrodzaj=1;
// var gal=document.getElementById("galeria");

// function scrolldown(i){
	// scroll=1;
	// scrollrodzaj=i;	
// }
// function scrollout(){
	// scroll=0;	
// }
// function startscroll(){
	// gal=document.getElementById("galeria");
	// var dcx=window.setInterval("step()",50); 
	
	// scrollValue = 0;
// }
// function step(){
	// if (scroll==1){
	    // gal=document.getElementById("galeria");
	    
	    // scrollValue += scrollrodzaj;
	    
	    // if (scrollValue < 0) scrollValue = 0;
	    // gal.style.marginLeft = -scrollValue*20 + "px"	 
	// }
// }

// oferta.js //

var scroll=0;
var scrollValue = 0;
var scrollrodzaj=1;
var o_innerWidth = 0;
var gal=document.getElementById("galeria");
var galc=document.getElementById("galContainer");

function scrolldown(i){
	scroll=1;
	scrollrodzaj=i;	
}
function scrollout(){
	scroll=0;	
}
function startscroll(){
	gal=$("galeria");
	galc=$("galContainer");
	var dcx=window.setInterval("step()",50); 

	if (gal != null) {
	    var imags = gal.select('div');
	    var img;

	    var ll = imags.length;
    	
	    if (ll > 0) img = imags[0];

	    o_innerWidth = (ll * img.getWidth()) - galc.getWidth();
	}

	scrollValue = 0;
}
function step(){
	if (scroll==1){
	    gal=$("galeria");
	    galc=$("galContainer");
	    	    
	    scrollValue += scrollrodzaj;
	    
	    var imags = gal.select('div');
	    var img;

	    var ll = imags.length;
    	
	    if (ll > 0) img = imags[0];

	    o_innerWidth = (ll * img.getWidth()) - galc.getWidth();

	    if (scrollValue < 0) scrollValue = 0;
	    
	    if (scrollValue*20 > o_innerWidth) {
	        if (scrollValue*20 > img.getWidth()) {
	            scrollValue = o_innerWidth/20;
	        } else {
	            scrollValue = 0;
	        }
	    }

	    gal.style.marginLeft = -scrollValue*20 + "px"	 
	}
}

function Taba(i,prefix){
	if (!prefix)prefix="";
	var x=document.getElementById(prefix+"tab"+String(i));
	if (x.style.display!="block"){x.style.display="block"} else {x.style.display="none"};
}
function Pokaz(o){
	var x=document.getElementById(o);
	if (x.style.display!="block"){x.style.display="block"} else {x.style.display="none"};
}
function Big(i){
	window.open("virgobig.ashx?"+String(i));

}

function ZKB(o, i) {
    if (i == 1) {
        o.style.backgroundColor = "#CCC";
    } else {
        o.style.backgroundColor = "";
    }
}



function OpenMap(u, i) {
    var de = window.open(u + "mapa.aspx?id=" + i, "", "width=540,height=380")
}

function ShowPrint(url) {
    var w = window.open(url, "", "width=700,scrollbars=yes,resizable=yes,menubar=yes ");
}

//function OpenMap(i) {
//    var de = window.open("mapa.aspx?id=" + i, "", "width=540,height=380")
//}
//function ShowPrint(url){
//	var w=window.open("wydruk.aspx?id="+url,"","width=700,height=580scrollbars=yes,resizable=yes,menubar=yes ");
//}

function ShowNotatnikPrint(){
    var w = window.open("wydruk_notatnik.aspx", "", "width=700,height=580,scrollbars=yes,resizable=yes,menubar=yes ");
}

function OpenForm(u,i){
    //alert(i);
	var de=window.open(u+"?id="+i,"Formularz","width=660,height=570,menubar=no, toolbar=no, location=no, scrollbars=no, resizable=no,status=no");
	de.focus();
}


function hideTab($tabId) {
    document.getElementById('ctl00_cntMain_div' + $tabId).style.display = "none";
    document.getElementById('ctl00_cntMain_div' + $tabId).className = "";
}
function hideTabs() {
    hideTab('Brief');
    hideTab('Main');
    hideTab('Form');
}
function showTab($tabId) {
    hideTabs();
    document.getElementById('ctl00_cntMain_div' + $tabId).style.display = "block";
    document.getElementById('ctl00_cntMain_div' + $tabId).attributes["class"] = "selected";
}

// ================================= Obsługa onEnter dla całego serwisu ========================= //
    
var KeyID = 0;

document.onkeydown = KeyCheck;       

function KeyCheck(e) {
   KeyID = getEventKeyCode(e);
      
   var inpClass = getEventTarget(e).className;
   if (KeyID == 13) {
        if ($('wyszukiwarkaPanelBox') != null) {
            WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions('ctl00$cntWyszukiwarka$WebWyszukiwarka$wysz_submit', '', true, 'wyszukiwarka', '', false, true));
        }
   }
}

// ================================= Obsługa onEnter dla całego serwisu ========================= //


function DodajDoNotatnika(Id, msg) {
    var c = readCookie("notatnik");
    
    if (c === null) c = "";
    
    if (c.indexOf(","+Id+",") == -1) c += Id+",";
    
    eraseCookie("notatnik");

    createCookie("notatnik", c, 31);

    if ($('aNotatnikDodaj_' + Id)) {
        $('aNotatnikDodaj_' + Id).toggle();
    }

    if ($('aNotatnikUsun_' + Id)) {
        $('aNotatnikUsun_' + Id).toggle();
    }

    if ($('spNotatnikCount')) {
        var count = 0;

        if ($('spNotatnikCount').innerHTML != '') {
            count = parseInt($('spNotatnikCount').innerHTML.replace('(', '').replace(')', ''));
        }

        count += 1;
        $('spNotatnikCount').innerHTML = '(' + count + ')';
    }

    if (msg != "") setTimeout(function () { alert(msg); }, 100);
}

function UsunZNotatnika(Id, msg, reload) {
    var c = readCookie("notatnik");
    
    if (c === null) c = "";
    
    if (c.indexOf(Id+",") > -1) {
        c = c.replace(Id+",", "");
    }
    
    eraseCookie("notatnik");

    createCookie("notatnik", c, 31);

    if ($('aNotatnikDodaj_' + Id)) {
        $('aNotatnikDodaj_' + Id).toggle();
    }

    if ($('aNotatnikUsun_' + Id)) {
        $('aNotatnikUsun_' + Id).toggle();
    }

    if ($('spNotatnikCount')) {
        var count = 0;

        if ($('spNotatnikCount').innerHTML != '') {
            count = parseInt($('spNotatnikCount').innerHTML.replace('(', '').replace(')', ''));
        }

        count -= 1;

        if (count > 0) {
            $('spNotatnikCount').innerHTML = '(' + count + ')';
        } else {
            $('spNotatnikCount').innerHTML = '';
        }
    }

    if (msg != "") setTimeout(function () { alert(msg); }, 100);
    
    if (reload) {
        document.location.reload(false);
    }
}

function loadOferty(dv,par) {
    var lng=GetUrlParam("lng");
    var url = "ofertyspecjalne_ajax.aspx?typ="+par+"&lng="+lng;    
       
    new Ajax.Request(url, {
        onSuccess: function(transport) {
            $(dv).innerHTML = transport.responseText;
        }
    });
}

function WyslijFormularz() {
    $$('.FormContent input[type=text]').each(function (e) {
        var l = new Element('span');
        l.innerHTML = e.value != '' ? e.value : '-';
        
        e.replace(l);
    });
    
    $$('.FormContent input[type=checkbox]').each(function (e) {
        var l = new Element('label');
        l.innerHTML = e.checked ? 'TAK' : 'NIE';
        
        e.replace(l);
    });
    
    $$('.FormContent textarea').each(function (e) {
        var l = new Element('span');
        l.innerHTML = e.value != '' ? e.value : '-';
        
        e.replace(l);
    });
                
    $$('.FormContent br').each(function (e) {          
        e.replace(null);
    });        
    
    if ($$('.btnWyslij')[0]) $$('.btnWyslij')[0].replace(null);
               
    $$('.FormServerContent')[0].value = $$('.FormContent')[0].innerHTML;

    __doPostBack('ctl00$cntMain$btnWyslij','');
}

function updateswf(idfoto) {
    new Ajax.Request("galeriaswf.aspx?idfoto=" + idfoto, {
        method: 'get',
        onSuccess: function (transport) {
            $A(document.getElementsByTagName('object')).each(function (e) {
                e.style.display = "none";
            });
            $('galeriaswf').innerHTML = transport.responseText;
        }
    });
    document.getElementById('galeriaswf').style.display = "block";
}

function Zamknij() {
    $('galeriaswf').innerHTML = "";
    $A(document.body.getElementsByTagName('object')).each(function (e) {
        e.style.display = "block";
    });
    document.getElementById('galeriaswf').style.display = "none";
}

var textsize = 1;

function settextsize(newsize) {
    textsize = newsize;
}

function selectActive() {
    var textSizeIds = ["normalText", "mediumText", "largeText"];
    var arrayPos;
    for (i = 0; i < textSizeIds.length; i++) {
        document.getElementById(textSizeIds[i]).className = "";
    }
    if (textsize == "12") {
        arrayPos = 0;
    } else if (textsize == "14") {
        arrayPos = 1;
    } else if (textsize == "16") {
        arrayPos = 2;
    }
    document.getElementById(textSizeIds[arrayPos]).className = 'activeTextSize';
}

function fsize(size, unit, id) {
    var vfontsize = document.getElementById(id);
    if (vfontsize) {
        vfontsize.style.fontSize = size + unit;
        createCookie("textsizestyle", textsize, 365);
        selectActive();
    }
}

DayName = new Array(7)
DayName[0] = "niedziela"
DayName[1] = "poniedziałek"
DayName[2] = "wtorek"
DayName[3] = "środa"
DayName[4] = "czwartek"
DayName[5] = "piątek"
DayName[6] = "sobota"

MonthName = new Array(12)
MonthName[0] = "stycznia"
MonthName[1] = "lutego"
MonthName[2] = "marca"
MonthName[3] = "kwietnia"
MonthName[4] = "maja"
MonthName[5] = "czerwca"
MonthName[6] = "lipca"
MonthName[7] = "sierpnia"
MonthName[8] = "września"
MonthName[9] = "pa1dziernika"
MonthName[10] = "listopada"
MonthName[11] = "grudnia"

function getDateStr() {
    var Today = new Date()
    var WeekDay = Today.getDay()
    var Month = Today.getMonth()
    var Day = Today.getDate()
    var Year = Today.getFullYear()

    if (Year <= 99)
        Year += 1900

    return DayName[WeekDay] + "," + " " + Day + " " + MonthName[Month] + " " + Year
}

// ----- smooth scrolling ---------------- //
function currentYPosition() {
    if (self.pageYOffset) return self.pageYOffset;
    if (document.documentElement && document.documentElement.scrollTop)
        return document.documentElement.scrollTop;
    if (document.body.scrollTop) return document.body.scrollTop;
    return 0;
}

function elmYPosition(eID) {
    var elm = document.getElementById(eID);
    var y = elm.offsetTop;
    var node = elm;
    while (node.offsetParent && node.offsetParent != document.body) {
        node = node.offsetParent;
        y += node.offsetTop;
    } return y;
}

function smoothScroll(eID) {
    var startY = currentYPosition();
    var stopY = elmYPosition(eID);
    var distance = stopY > startY ? stopY - startY : startY - stopY;
    if (distance < 100) {
        scrollTo(0, stopY); return;
    }
    var speed = Math.round(distance / 100);
    if (speed >= 20) speed = 20;
    var step = Math.round(distance / 25);
    var leapY = stopY > startY ? startY + step : startY - step;
    var timer = 0;
    if (stopY > startY) {
        for (var i = startY; i < stopY; i += step) {
            setTimeout("window.scrollTo(0, " + leapY + ")", timer * speed);
            leapY += step; if (leapY > stopY) leapY = stopY; timer++;
        } return;
    }
    for (var i = startY; i > stopY; i -= step) {
        setTimeout("window.scrollTo(0, " + leapY + ")", timer * speed);
        leapY -= step; if (leapY < stopY) leapY = stopY; timer++;
    }
}

// Zabezpieczenie przed robotami sieciowymi
Event.observe(window, 'load', function () { 
    $('aspnetForm').action = $$('.hform1')[0].value;
    $('aspnetForm').method = "post";
});
