﻿///<reference path="jquery.intellisense.js"/>

//returns array of queryString parameters
//USAGE:
//var qs_params = new Array();
//qs_params = get_querystring_params();
function get_querystring_params() 
{
    var qsParm = new Array();
    var query = window.location.search.substring(1);
    var parms = query.split('&');
    for (var i=0; i<parms.length; i++) 
    {
        var pos = parms[i].indexOf('=');
        if (pos > 0) 
        {
            var key = parms[i].substring(0,pos);
            var val = parms[i].substring(pos+1);
            qsParm[key] = val;
        }
    }
    return qsParm;
}


jQuery.fn.centerInClient = function(options) {
    /// <summary>Centers the selected items in the browser window. Takes into account scroll position.
    /// Ideally the selected set should only match a single element.
    /// </summary>    
    /// <param name="fn" type="Function">Optional function called when centering is complete. Passed DOM element as parameter</param>    
    /// <param name="forceAbsolute" type="Boolean">if true forces the element to be removed from the document flow 
    ///  and attached to the body element to ensure proper absolute positioning. 
    /// Be aware that this may cause ID hierachy for CSS styles to be affected.
    /// </param>
    /// <returns type="jQuery" />
    var opt = { forceAbsolute: false,
        container: window,    // selector of element to center in
        completeHandler: null
    };
    $.extend(opt, options);

    return this.each(function(i) {
        var el = $(this);
        var jWin = $(opt.container);
        var isWin = opt.container == window;

        // force to the top of document to ENSURE that 
        // document absolute positioning is available
        if (opt.forceAbsolute) {
            if (isWin)
                el.remove().appendTo("body");
            else
                el.remove().appendTo(jWin.get(0));
        }

        // have to make absolute
        el.css("position", "absolute");

        // height is off a bit so fudge it
        var heightFudge = isWin ? 2.0 : 1.8;

        var x = (isWin ? jWin.width() : jWin.outerWidth()) / 2 - el.outerWidth() / 2;
        var y = (isWin ? jWin.height() : jWin.outerHeight()) / heightFudge - el.outerHeight() / 2;

        el.css("left", x + jWin.scrollLeft());
        el.css("top", y + jWin.scrollTop());

        // if specified make callback and pass element
        if (opt.completeHandler)
            opt.completeHandler(this);
    });
}


function round_number(num, dec) {
    var result = Math.round(num * Math.pow(10, dec)) / Math.pow(10, dec);
    return result;
}

//function display message in blan texbox (from title), and clears it when focused
jQuery.fn.hint = function() {
    return this.each(function() {
        
        var t = jQuery(this); // get jQuery version of 'this'
        var title = t.attr('title');// get it once since it won't change
        // only apply logic if the element has the attribute
        if (title) {
            t.blur(function() {// on blur, set value to title attr if text is blank
                if (t.val() == '') {
                    t.val(title);
                    t.addClass('blur');
                }
            });
            // on focus, set value to blank if current value 
            // matches title attr
            t.focus(function() {
                if (t.val() == title) {
                    t.val('');
                    t.removeClass('blur');
                }
            });
            // clear the pre-defined text when form is submitted
            t.parents('form:first()').submit(function() {
                if (t.val() == title) {
                    t.val('');
                    t.removeClass('blur');
                }
            });
            // now change all inputs to title
            t.blur();
        }
    });
}

function show_hide_element(selector) {
    $(selector).slideToggle();
}



jQuery(document).ready(function () {


    //skrij vse "openable boxe"
    $(".openable").hide();
    $("div.izbira_opened .openable").show();

    //prikaži/skrij "openable textbox" z klikom na "opener" element
    $(".opener").click(function (e1) {
        e1.preventDefault();
        $(this).children("a").click(function (e) {
            e.preventDefault();
        });
        $(this).next(".openable").slideToggle();
        $(this).next(".openable2").slideToggle();
    });


    /*$("a.opener").toggle(function() {
    $(".stuff").hide('slow');
    }, function() {
    $(".stuff").show('fast');
    });*/

});


function shade_screen() {
    $("body").css("overflow", "hidden");

    var shade = $("DIV#shade_div");
    shade.css({'bottom': '-1000px', 'height':'500%'});
    shade.show();
    
    
    var message = $("DIV#waiting_message");
    message.centerInClient();
    message.fadeIn();
}





function remove_nonnumeric(pstrSource) {
    var m_strOut = new String(pstrSource);
    m_strOut = m_strOut.replace(/[^0-9]/g, '');

    return m_strOut;
}


