

/* javascript file: 2dmenu.js */

/*
 	Lukasz Podkalicki
	menu
*/

var menu = {
	
	// menu vars
	ID					: 'menu_2dh_sub',
	CONTAINER_PREFIX 	: 'container_submenu_', //id_str
	PREFIX				: 'menu_', 				//id_str
	PID 				: -1,
	LAST_PID			: -1,
	PARSED_PID			: -1,
	
	// pokazuje menu wraz z podmenu
	show : function(pid) {
		try {
			if(
				(mobj = document.getElementById(this.PREFIX + pid)) 			&&
				(cobj = document.getElementById(this.CONTAINER_PREFIX + pid)) 	&&
				true
				) {
				mobj.className="selected";	
				cobj.style.display = 'block';
			}
		}
		catch(e) {
			
		}
	},
	
	// ukrywa menu wraz z podmenu
	hide : function(pid) {
		try {
			if(
				(mobj = document.getElementById(this.PREFIX + pid)) 			&&
				(cobj = document.getElementById(this.CONTAINER_PREFIX + pid))   &&
				true
				) {
				mobj.className="deselected";
				cobj.style.display = 'none';
			}
		}
		catch(e) {
			
		}
	},
	
	// parser pid'a
	parse_pid : function(pid) {
		var m = sm = -1;
        
		if((pid.length>0))  {
			ppid = pid.split('_');
            if(ppid.length >= 2) {
                m = ppid[0] + '_' + ppid[1];
                if(ppid.length == 3) {
                    sm = m + '_' + ppid[2];
                }
            }
        }
		tmpTab = new Array(m, sm);
		return tmpTab;
	},
	
	// glowna funkcja wyzwalajaca :) 
	set : function(pid) {
		if(this.PID == pid) {
			return false;
		}
		else {
			this.LAST_PID = this.PID
			this.PID = pid;
            m = menu.parse_pid(this.LAST_PID);
			menu.hide(m[0]);
            m2 = menu.parse_pid(this.PID);
			menu.show(m2[0]);
            menu.submenu.show(this.submenu.PID);
			return true;
		}
	},
	
	// funkcja inicjujaca menu
	init : function(){
        m = this.parse_pid(menu.PID);
		this.show(m[0]);
        this.submenu.PID = m[1];

        this.submenu.show(this.submenu.PID);
	},
	
	// submenu 
	submenu : {
		ID					: 'menu_2dh_sub',	
		PREFIX      		: 'a_submenuitem_', 		//id_str
		PID					: -1,
		LAST_PID			: -1,
		
		// pokazuje podmenu
		show : function(pid) {
            try {
                if(
                    (mobj = document.getElementById(this.PREFIX + pid))             &&
                    true
                    ) {
                    mobj.style.color="#c0e3ff";
                }
            }
            catch(e) {
                
            }
		},
		
		hide : function(pid) {
		    try {
                if(
                    (mobj = document.getElementById(this.PREFIX + pid))             &&
                    true
                    ) {
                    mobj.style.backgroundColor="";
                }
            }
            catch(e) {

            }
		},
		
		set : function(pid) {
			
		}
	}
}


/* javascript file: flexiweb.js */

/**
*   Bibliotek funkcji JS dla FlexiWeb
*
*/
function init() {
    if(obj=document.getElementsByTagName('a')){
        for(i=0;i<obj.length;i++){
            //alert(obj[i].href);
            //obj[i].onfocus = new Function("return false");
            if(obj.addEventListener)
                obj.addEventListener('focus',blur());
            else if(obj.attachEvent)
                obj.attachEvent('onfocus',blur());
            else
                obj.onfocus=blur;
        }
    }
}

function setCookie(name, value, expires, path, domain, secure){
//ustawia cookie
    var d=new Date();
    dat=new Date(d.getTime() + expires*1000);
    var cookieString = name + "=" +escape(value) + 
        ((expires) ? ";expires="+dat : "") +
               ( (path) ? ";path=" + path : "") +
               ( (domain) ? ";domain=" + domain : "") +
               ( (secure) ? ";secure" : "");
        document.cookie = cookieString;
    }

function getCookie(name){
//pobiera cookie
    var start = document.cookie.indexOf(name+"=");
    var len = start+name.length+1;
    if ((!start) && (name != document.cookie.substring(0,name.length))) return null;
    if (start == -1) return null;
    var end = document.cookie.indexOf(";",len);
    if (end == -1) end = document.cookie.length;
    return unescape(document.cookie.substring(len,end));
    }

function delCookie(name,path,domain) {
//usuwa cookie
       if (getCookie(name)) document.cookie = name + "=" +
      ( (path) ? ";path=" + path : "") +
      ( (domain) ? ";domain=" + domain : "") +
      ";expires=Thu, 01-Jan-70 00:00:01 GMT";
}

function create_pass(id_source, id_target) {
// pobiera string z id_source, hashuje z id sesji, zapisuje do id_target
    var hashed_pass = hex_sha1(document.getElementById(id_source).value);
    var sesid       = getCookie('SID');
    document.getElementById(id_target).value = hex_sha1(sesid+hashed_pass);
}

function openWindow(w_href,w_width,w_height)
{
    window.open(w_href,'Image', 'scrollbars=yes,menubar=no,status=no,location=no,top=200,left=200,width='+(w_width+40)+',height='+(w_height+40));
}


$(document).ready(function(){
   
    // banner w górnej części strony
    var banner = $('#banner_box');

    if(banner.length && banner.data('swf')) {
        swfobject.embedSWF(
            banner.data('swf'),
            banner.attr('id'),
            banner.data('width') || 600,
            banner.data('height') || 100,
            '10.0.0',
            '/swf/expressInstall.swf',
            null,
            {wmode: 'opaque'}
        );
    }

    // bannery w formie popup
    var bannerURL = $('#banner_box').data('popup-banner');
    if(bannerURL) {
        $.colorbox({
            href: bannerURL,
            opacity: 0.5,
            photo: true,
            fixed: true,
            scalePhotos: true,
            maxWidth: "90%",
            maxHeight: "90%" 
        });
    }



});


/* javascript file: hide_show.js */

var  actTab = 0;
var tabs = {
    version:            '2007.04.27',

    // const
    CONTAINER_ID:       'tabs_container',
    PRFX:               'tab_',
    PRFX_MIN:           'tabmin_',
    START_TAB :         1,
    CNT :               0,

    setup: function(count) {
        tabs.CNT=(count > 0 ? count : 0);
        tabs.set(tabs.START_TAB);
    },

    set: function(tab) {
       if(
            actTab>0        &&
            (tab>0)         && 
            (tab<=tabs.CNT)
            ) {
            tabs.unset(actTab);
        }
        // podmiana styli
        try {
            var obj=document.getElementById(tabs.PRFX + tab);
            var mobj=document.getElementById(tabs.PRFX_MIN + tab);
            if(obj){
                //obj
                mobj.className = "selected";
                obj.style.display = "block";
                actTab = tab;
           }
        }
        catch(e){
            return false;
        }
    },

    unset: function(tab) {
        if(
            (tab>0)         && 
            (tab<=tabs.CNT)
            ){
            // podmiana styli
            try {
                var obj=document.getElementById(tabs.PRFX + tab);
                var mobj=document.getElementById(tabs.PRFX_MIN + tab);
                if(obj){
                    //obj
                    mobj.className = "";
                    obj.style.display="none";
                }
            }
            catch(e){
                return false;
            }
        }
    }
}



/* javascript file: ieupdate.js */

theObjects = document.getElementsByTagName("object");
for (var i = 0; i < theObjects.length; i++)
{
theObjects[i].outerHTML = theObjects[i].outerHTML;
}

/* javascript file: maps.js */

/*
 *  Project: Google Mapper
 *  Description: Helper plugin for handling google maps for JHM development
 */

// the semi-colon before function invocation is a safety net against concatenated 
// scripts and/or other plugins which may not be closed properly.
;(function ($, window, document, undefined) {

    var pluginName = 'googleMapper',
        
        // default settings
        defaults = {
            longitude: 21.003036,
            latitude: 52.135628,
            zoom: 8,
            autoload: false,
            sensor: false,
            editable: false,
            zoomInput: "",
            longitudeInput: "",
            latitudeInput: "",
        };

    
    // The actual plugin constructor
    function Plugin(element, options) {
        this.element = element;
        this.marker = null;
        this.zoomInput = null;
        this.latitudeInput = null;
        this.longitudeInput = null;

        // override default settings if necessary
        this.options = $.extend( {}, defaults, options) ;
        
        // keep reference to default options and plugin name
        this._defaults = defaults;
        this._name = pluginName;

        // initialize plugin
        this.init();
    }

    /**
    * Map initialization
    */
    Plugin.prototype.init = function() {
        var o = this.options;

        // setup initial zoom
        if(o.zoomInput) {
            this.zoomInput = $(o.zoomInput);
            var zoomValue = this.zoomInput.val();

            if(zoomValue) o.zoom = parseInt(zoomValue);
            else this.zoomInput.val(o.zoom);
        }

        // setup initial latitude
        if(o.latitudeInput) {
            this.latitudeInput = $(o.latitudeInput);
            var latitudeValue = this.latitudeInput.val();

            if(latitudeValue) o.latitude = parseFloat(latitudeValue);
            else this.latitudeInput.val(o.latitude);
        }

        // setup initial longitude
        if(o.longitudeInput) {
            this.longitudeInput = $(o.longitudeInput);
            var longitudeValue = this.longitudeInput.val();

            if(longitudeValue) o.longitude = parseFloat(longitudeValue);
            else this.longitudeInput.val(o.longitude);
        }


        if(o.autoload) this.showMap();
        this.bindInputs();
    };



    Plugin.prototype.showMap = function() {
        var o = this.options;

        // map setup
        this.map = new google.maps.Map(document.getElementById(this.element.id), {
            zoom: o.zoom,
            center: new google.maps.LatLng(o.latitude, o.longitude),
            mapTypeId: google.maps.MapTypeId.ROADMAP,
            streetViewControl: false,
            mapTypeControl: false
        });
    
        // show default set of markers on the map
        this.addMarker();
    }


    Plugin.prototype.addMarker = function() {
        var o = this.options,
            point =  new google.maps.LatLng(o.latitude, o.longitude);

        this.marker = new google.maps.Marker({
            position: point,
            animation: google.maps.Animation.DROP,
            draggable: o.editable,
            map: this.map
        });

    };


    Plugin.prototype.bindInputs = function() {
        var o = this.options,
            self = this;

        if(o.zoomInput) {
            // zoom change
            self.zoomInput.change(function(){
                var value = parseInt($(this).val());
                if(! isNaN(value))
                    self.map.setZoom(value);
            })
        
            google.maps.event.addListener(this.map, 'zoom_changed', function() {
                self.zoomInput.val(this.getZoom());
            });
        
        }

        // allow to edit map data if requested
        if(o.editable) {
            // handle value update after marker was dropped
            google.maps.event.addListener(this.marker, 'position_changed', function() {
                var point = this.getPosition();
                self.longitudeInput.val(point.lng());
                self.latitudeInput.val(point.lat());
            });

            // handle longitude & latitude changes
            self.longitudeInput.on("change", this, this.updateMarkerPosition);
            self.latitudeInput.on("change", this, this.updateMarkerPosition);
        }
    };


    Plugin.prototype.updateMarkerPosition = function(event) {
            var self = event.data,
                input = $(this),
                rawValue = input.val(),
                value = parseFloat(rawValue),
                coordinate = input.attr('name').split('_').pop(),
                markerPosition = self.marker.getPosition(),
                longitude  = markerPosition.lng(),
                latitude = markerPosition.lat();

            // ignore invalid values
            if(isNaN(value))return false;
            
            // update longitude if necessary
            if(coordinate == 'longitude' && value != longitude) {
                longitude = value;
            }
            
            // update latitude if necessary
            if(coordinate == 'latitude' && value != latitude) {
                latitude = value;
            }

            // move map and marker to given location
            var point = new google.maps.LatLng(latitude, longitude);
            self.map.setCenter(point);
            self.marker.setPosition(point);
    };

    // A really lightweight plugin wrapper around the constructor, 
    // preventing against multiple instantiations
    $.fn[pluginName] = function(options) {
        return this.each(function() {
            if (!$.data(this, 'plugin_' + pluginName)) {
                $.data(this, 'plugin_' + pluginName, new Plugin(this, options));
            }
        });
    }

})(jQuery, window, document);




/* javascript file: search.js */

function insert_select(selectName) {

        var form = $('#searchForm'),
            voivodeshipSelect = form.find('select[name=voivodeship]');
            citySelect = form.find('select[name=city]');
            typeSelect = form.find('select[name=type]');
            deadlineSelect = form.find('select[name=deadline]');

        // resetujemy podrzędne pola
        switch(selectName) {
            case 'voivodeship':
                citySelect.empty();
            case 'city':
                typeSelect.empty();
            case 'type':
                deadlineSelect.empty();
        }

        // zapisujemy dane wybrane za pośrednictwem pól select formularza
        selectedVoivodeship = voivodeshipSelect.val();
        selectedCity = citySelect.val() || "";
        selectedType = typeSelect.val() || "";

        // pobieramy dane spełniające wybrane kryteria
        $.getJSON('/index.php', {
            module: 'products',
            view: 'json',
            voivodeship: selectedVoivodeship,
            city: selectedCity,
            inv_type: selectedType,
            box : selectName
        }).done(function(data){
            var i = 0,
                cities = $('#city').prop('options'),
                types = $('#type').prop('options'),
                deadlines = $('#deadline').prop('options');
        
            // aktualizacja pól typu select z danymi inwestycji
            switch(data.box) {
                case 'voivodeship':
                    for (i = 0; i<data.city.length; i++) {
                        cities[i] = new Option(data.city[i], data.city[i]);
                    }
                case 'city':
                    for (i = 0; i<data.i_type.length; i++) {
                        types[i] = new Option(data.i_type[i].cname, data.i_type[i].id);
                    }
                case 'type':
                    for (i = 0; i<data.deadline.length; i++) {
                        deadlines[i] = new Option(data.deadline[i].dname, data.deadline[i].id);
                    }
            }
        }).fail(function(){
            alert('Wystąpił nieoczekiwany błąd podczas wyszukiwania. Spróbuj ponownie za parę chwil...');
        });
}



/* javascript file: sha1.js */

/*
 * A JavaScript implementation of the Secure Hash Algorithm, SHA-1, as defined
 * in FIPS PUB 180-1
 * Version 2.1a Copyright Paul Johnston 2000 - 2002.
 * Other contributors: Greg Holt, Andrew Kepert, Ydnar, Lostinet
 * Distributed under the BSD License
 * See http://pajhome.org.uk/crypt/md5 for details.
 */

/*
 * Configurable variables. You may need to tweak these to be compatible with
 * the server-side, but the defaults work in most cases.
 */
var hexcase = 0;  /* hex output format. 0 - lowercase; 1 - uppercase        */
var b64pad  = ""; /* base-64 pad character. "=" for strict RFC compliance   */
var chrsz   = 8;  /* bits per input character. 8 - ASCII; 16 - Unicode      */

/*
 * These are the functions you'll usually want to call
 * They take string arguments and return either hex or base-64 encoded strings
 */
function hex_sha1(s){return binb2hex(core_sha1(str2binb(s),s.length * chrsz));}
function b64_sha1(s){return binb2b64(core_sha1(str2binb(s),s.length * chrsz));}
function str_sha1(s){return binb2str(core_sha1(str2binb(s),s.length * chrsz));}
function hex_hmac_sha1(key, data){ return binb2hex(core_hmac_sha1(key, data));}
function b64_hmac_sha1(key, data){ return binb2b64(core_hmac_sha1(key, data));}
function str_hmac_sha1(key, data){ return binb2str(core_hmac_sha1(key, data));}

/*
 * Perform a simple self-test to see if the VM is working
 */
function sha1_vm_test()
{
  return hex_sha1("abc") == "a9993e364706816aba3e25717850c26c9cd0d89d";
}

/*
 * Calculate the SHA-1 of an array of big-endian words, and a bit length
 */
function core_sha1(x, len)
{
  /* append padding */
  x[len >> 5] |= 0x80 << (24 - len % 32);
  x[((len + 64 >> 9) << 4) + 15] = len;

  var w = Array(80);
  var a =  1732584193;
  var b = -271733879;
  var c = -1732584194;
  var d =  271733878;
  var e = -1009589776;

  for(var i = 0; i < x.length; i += 16)
  {
    var olda = a;
    var oldb = b;
    var oldc = c;
    var oldd = d;
    var olde = e;

    for(var j = 0; j < 80; j++)
    {
      if(j < 16) w[j] = x[i + j];
      else w[j] = rol(w[j-3] ^ w[j-8] ^ w[j-14] ^ w[j-16], 1);
      var t = safe_add(safe_add(rol(a, 5), sha1_ft(j, b, c, d)),
                       safe_add(safe_add(e, w[j]), sha1_kt(j)));
      e = d;
      d = c;
      c = rol(b, 30);
      b = a;
      a = t;
    }

    a = safe_add(a, olda);
    b = safe_add(b, oldb);
    c = safe_add(c, oldc);
    d = safe_add(d, oldd);
    e = safe_add(e, olde);
  }
  return Array(a, b, c, d, e);

}

/*
 * Perform the appropriate triplet combination function for the current
 * iteration
 */
function sha1_ft(t, b, c, d)
{
  if(t < 20) return (b & c) | ((~b) & d);
  if(t < 40) return b ^ c ^ d;
  if(t < 60) return (b & c) | (b & d) | (c & d);
  return b ^ c ^ d;
}

/*
 * Determine the appropriate additive constant for the current iteration
 */
function sha1_kt(t)
{
  return (t < 20) ?  1518500249 : (t < 40) ?  1859775393 :
         (t < 60) ? -1894007588 : -899497514;
}

/*
 * Calculate the HMAC-SHA1 of a key and some data
 */
function core_hmac_sha1(key, data)
{
  var bkey = str2binb(key);
  if(bkey.length > 16) bkey = core_sha1(bkey, key.length * chrsz);

  var ipad = Array(16), opad = Array(16);
  for(var i = 0; i < 16; i++)
  {
    ipad[i] = bkey[i] ^ 0x36363636;
    opad[i] = bkey[i] ^ 0x5C5C5C5C;
  }

  var hash = core_sha1(ipad.concat(str2binb(data)), 512 + data.length * chrsz);
  return core_sha1(opad.concat(hash), 512 + 160);
}

/*
 * Add integers, wrapping at 2^32. This uses 16-bit operations internally
 * to work around bugs in some JS interpreters.
 */
function safe_add(x, y)
{
  var lsw = (x & 0xFFFF) + (y & 0xFFFF);
  var msw = (x >> 16) + (y >> 16) + (lsw >> 16);
  return (msw << 16) | (lsw & 0xFFFF);
}

/*
 * Bitwise rotate a 32-bit number to the left.
 */
function rol(num, cnt)
{
  return (num << cnt) | (num >>> (32 - cnt));
}

/*
 * Convert an 8-bit or 16-bit string to an array of big-endian words
 * In 8-bit function, characters >255 have their hi-byte silently ignored.
 */
function str2binb(str)
{
  var bin = Array();
  var mask = (1 << chrsz) - 1;
  for(var i = 0; i < str.length * chrsz; i += chrsz)
    bin[i>>5] |= (str.charCodeAt(i / chrsz) & mask) << (32 - chrsz - i%32);
  return bin;
}

/*
 * Convert an array of big-endian words to a string
 */
function binb2str(bin)
{
  var str = "";
  var mask = (1 << chrsz) - 1;
  for(var i = 0; i < bin.length * 32; i += chrsz)
    str += String.fromCharCode((bin[i>>5] >>> (32 - chrsz - i%32)) & mask);
  return str;
}

/*
 * Convert an array of big-endian words to a hex string.
 */
function binb2hex(binarray)
{
  var hex_tab = hexcase ? "0123456789ABCDEF" : "0123456789abcdef";
  var str = "";
  for(var i = 0; i < binarray.length * 4; i++)
  {
    str += hex_tab.charAt((binarray[i>>2] >> ((3 - i%4)*8+4)) & 0xF) +
           hex_tab.charAt((binarray[i>>2] >> ((3 - i%4)*8  )) & 0xF);
  }
  return str;
}

/*
 * Convert an array of big-endian words to a base-64 string
 */
function binb2b64(binarray)
{
  var tab = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
  var str = "";
  for(var i = 0; i < binarray.length * 4; i += 3)
  {
    var triplet = (((binarray[i   >> 2] >> 8 * (3 -  i   %4)) & 0xFF) << 16)
                | (((binarray[i+1 >> 2] >> 8 * (3 - (i+1)%4)) & 0xFF) << 8 )
                |  ((binarray[i+2 >> 2] >> 8 * (3 - (i+2)%4)) & 0xFF);
    for(var j = 0; j < 4; j++)
    {
      if(i * 8 + j * 6 > binarray.length * 32) str += b64pad;
      else str += tab.charAt((triplet >> 6*(3-j)) & 0x3F);
    }
  }
  return str;
}

