// tlumaczenie kalendarza jui
    $.datepicker.regional['pl'] = {
        closeText: 'Zamknij',
        prevText: '&#x3c;Poprzedni',
        nextText: 'Następny&#x3e;',
        currentText: 'Dziś',
        monthNames: ['Styczeń','Luty','Marzec','Kwiecień','Maj','Czerwiec',
        'Lipiec','Sierpień','Wrzesień','Październik','Listopad','Grudzień'],
        monthNamesShort: ['Sty','Lu','Mar','Kw','Maj','Cze',
        'Lip','Sie','Wrz','Pa','Lis','Gru'],
        dayNames: ['Niedziela','Poniedziałek','Wtorek','Środa','Czwartek','Piątek','Sobota'],
        dayNamesShort: ['Nie','Pn','Wt','Śr','Czw','Pt','So'],
        dayNamesMin: ['N','Pn','Wt','Śr','Cz','Pt','So'],
        weekHeader: 'Tydz',
        dateFormat: 'dd.mm.yy',
        firstDay: 1,
        isRTL: false,
        showMonthAfterYear: false,
        yearSuffix: ''};
    $.datepicker.setDefaults($.datepicker.regional['pl']);

/**
 * POPUP
 */
var popupStatus = 0;

function loadPopup()
{
    if(popupStatus==0){
        $("#backgroundPopup").css({
                "opacity": "0.7"
        });
        $("#backgroundPopup").fadeIn("slow");
        $("#popup").fadeIn("slow");
        popupStatus = 1;
    }
}

function disablePopup()
{
    if(popupStatus==1){
        $("#backgroundPopup").fadeOut("slow");
        $("#popup").fadeOut("slow");
        popupStatus = 0;
        window.location.hash = '';
    }
}
jQuery.fn.center = function () {
    this.css("position","absolute");
    this.css("top", (($(window).height() - this.outerHeight()) / 2) + $(window).scrollTop() + "px");
    this.css("left", (($(window).width() - this.outerWidth()) / 2) + $(window).scrollLeft() + "px");
    return this;
}

function centerPopup(){
//    var windowWidth = document.documentElement.clientWidth;
    var windowHeight = document.documentElement.clientHeight;
//    var popupHeight = $("#popup").height();
//    var popupWidth = $("#popup").width();
//    var popupTop = windowHeight/2-popupHeight/2;
//    if(popupTop < 50) popupTop = 50;
    $("#popup").center();
//    $("#popup").css({
//        "position": "absolute",
//        "margin-left": -(popupWidth/2),
//        "margin-top": -(popupHeight/2),
//        "top": "50%",
//        "left": "50%"
//    });
    $("#backgroundPopup").css({
        "height": windowHeight
    });

}
function insertOfferPopup(url)
{
    $('#popup').html('<a href="#" id="popupClose" onclick="disablePopup(); return false;">Zamknij</a><iframe src="'+url+'" frameborder="0"></iframe>');
}

function openOfferPopup(url)
{
    insertOfferPopup(url);
    centerPopup();
    loadPopup();
}

function getInternetExplorerVersion()// Returns the version of Windows Internet Explorer or a -1
{
    var rv = -1; // Return value assumes failure.
    if (navigator.appName == 'Microsoft Internet Explorer') {
        var ua = navigator.userAgent;
        var re = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");
        if (re.exec(ua) != null)
            rv = parseFloat(RegExp.$1);
    }
    return rv;
}

 function initMenu() {
     $('.leftSideBlueList ul').hide();
     $('.leftSideBlueList li a').click(
         function() {
             var checkElement = $(this).next();
             if((checkElement.is('ul')) && (checkElement.is(':visible'))) {
                return false;
             }
             if((checkElement.is('ul')) && (!checkElement.is(':visible'))) {
                 $('.leftSideBlueList ul:visible').slideUp('normal');
                 checkElement.slideDown('normal');
                 return false;
             }
         }
     );
 	 $('.withSubClassActive ul').show();
}
var actualSlide = 0;
var allSlides = new Array();
var allAlidesTitle = new Array();
allSlides[0] = '<a href="#" class="snimage" id="sn1" style="display:none;position:absolute;"><img src="/nimages/slide-1.png"/></a>';
allSlides[1] = '<a href="#" class="snimage" id="sn2" style="display:none;position:absolute;"><img src="/nimages/slide-2.png"/></a>';
allSlides[2] = '<a href="#" class="snimage" id="sn3" style="display:none;position:absolute;"><img src="/nimages/slide-3.png"/></a>';
allSlides[3] = '<a href="#" class="snimage" id="sn4" style="display:none;position:absolute;"><img src="/nimages/slide-4.png"/></a>';
allAlidesTitle[0] = 'Misją Urzędu jest dostarczanie usług najwyższej jakości';
allAlidesTitle[1] = 'Poradnictwo zawodowe - Doradcy zawodowi dla Ciebie';
allAlidesTitle[2] = 'CAZ w Opolu – nowa lokalizacja nowa jakość usług';
allAlidesTitle[3] = 'Pośrednictwo pracy - pomożemy znaleźć dobrą pracę';
function headerSlider(id)
{
    actualSlide = id;
    if(actualSlide >= allSlides.length) actualSlide = 0;
    if(actualSlide < 0) actualSlide = allSlides.length-1;
//    $('#headerSlideContent .snimage').fadeOut(300);
    $('#headerSlideContent').append(allSlides[actualSlide]);
    $('#headerSlideTitle').html(allAlidesTitle[actualSlide]);
    $('#headerSlideNumbers a').removeClass('selectedSlider');
    $('#headerSlideNumber'+(actualSlide+1)).addClass('selectedSlider');
    $('#headerSlideContent .snimage img').load(function(){
        $('#headerSlideContent .snimage').fadeIn(500, function() {
            if($('#headerSlideContent .snimage img').length > 1)
            $('#headerSlideContent').find('.snimage:first').remove();


        });
    });
}

function headerSliderNext()
{
    actualSlide++;
    headerSlider(actualSlide);
}

function headerSliderPrev()
{
    actualSlide--;
    headerSlider(actualSlide);
}


$(document).ready(function(){
    headerSlider(0);
    $("#backgroundPopup").click(function(){
        disablePopup();
    });
    $(document).keypress(function(e){
        if(e.keyCode==27 && popupStatus==1){
                disablePopup();
        }
    });
   $('.inputTitle').example(function() {
    return $(this).attr('title');
   });
    initMenu();


    var browserName = navigator.appName;
    var browserVer = getInternetExplorerVersion();
    var selectedClass = '';
    var selectedStyle = '';
	
	
	$('.downMenuLi').children("a").click(function(){
		$(this).parent("li").children("ul").show();
	},function(){
		$(this).parent("li").children("ul").hide();		
	});


    if (browserName == 'Microsoft Internet Explorer' & browserVer == '6') {
        /* IE6 PNG FIX */
        $('div.ltm').ifixpng();
    }

    $(".removeAction").click(function(){
        return confirm('Czy na pewno chcesz usunąć wybrany element');
    });

    $('#galleryContentDiv .oneGalleryElement').each(function(){
        $('#'+$(this).attr('id')+' a').lightBox({fixedNavigation:true});
    });

    // Obsługa wyświetlania podstrony
    $('#gallery a').lightBox({fixedNavigation:true});
    $('.galleryContainerBottom a').lightBox({fixedNavigation:true});

    $('#ckSubpageContent img').click(function(el){
        var fullPath = $(this).attr('src');
        var filename = fullPath.split('\\').pop().split('/').pop();
        $('#'+filename.substring(0, 32)).click();
    });
    
    $('.closeIco').click(function(){
             $(this).parent("div").css('display','none');
    })

    //lightbox dla podstron
    $('.newsDescription img').each(function(){
        if ( ! $(this).parent('a').hasClass('nolightbox')) {
            $(this).parent('a').lightBox({fixedNavigation:true})
        }
    });

    //img src dla podstron
    $('#ckSubpageContent img').each(function(){
        $(this).attr('src', $(this).attr('src').replace(/\.\.\//gi, '/'));
    });
    $('.textField img').each(function(){
        $(this).attr('src', $(this).attr('src').replace(/\.\.\//gi, '/'));
    });

    // wyszukiwarka na stronie głównej
//    $('#subpageSearchButton').click(manageSubpageSearchForm);
    $('#subpageSearchForm').submit(manageSubpageSearchForm);
    $('#subpageSearchPhrase').click(function() {
        if ($(this).val() == 'tu wpisz informacje') {
            $(this).val('');
        }
    });
    $('#subpageSearchPhrase').blur(function() {
        if ($(this).val() == '') {
            $(this).val('tu wpisz informacje');
        }
    });
    
    getNextRow();
    getNextCVRows();
}); //end ready function
	

function resizeTextTo(size)
{
    $('span.newsDescription span').css('font-size', size);
    $('div.newsMainCont span').css('font-size', size);
    $('span.newsDescription p').css('font-size', size);
    $('div.newsMainCont p').css('font-size', size);
    $('div.textField span').css('font-size', size);
    $('div.textField p').css('font-size', size);
    $('.mapInfo').css('font-size', size);
}

function trim(str, chars) {
	return ltrim(rtrim(str, chars), chars);
}

function ltrim(str, chars) {
	chars = chars || "\\s";
	return str.replace(new RegExp("^[" + chars + "]+", "g"), "");
}

function rtrim(str, chars) {
	chars = chars || "\\s";
	return str.replace(new RegExp("[" + chars + "]+$", "g"), "");
}

function removeManySpaces(str, chars) {
	chars = "\\s";
	return str.replace(new RegExp("[" + chars + "]{1,}", "g"), "+");
}

function manageSubpageSearchForm() {
    var phrase = $('#subpageSearchPhrase').val();
    if (phrase != '' && phrase != 'tu wpisz informacje') {
        var action = rtrim($('#subpageSearchForm').attr('action'), '/');
        action = action + '/' + $('#subpageSearchPhrase').val();
        $('#subpageSearchForm').attr('action', removeManySpaces(trim(action)).toLowerCase());
//        $('#subpageSearchForm').submit();
    } else {
        return false;
    }
}
function getNextRow()
{
    $('.getNewRowLink').click(function(){
            $(this).prev("div").after($(this).prev("div").clone());
    });
}

/**
 * FORMULARZ CV
 */
var nextRowEducation = 1;

function getNextRowEducation()
{
    if(nextRowEducation>1)
        $('#NextRowEducationDelete'+nextRowEducation).hide();
    nextRowEducation++;
    if(nextRowEducation>=50)
    {
        $('.getNewEducationLink').hide();
    }
    var row = '<div id="NextRowEducation'+nextRowEducation+'"><div class="singleFormLine singleFormLineBack"><label class="width70">&nbsp;</label>';
    row    += '<div class="subFormLineBackInfo"><label class="smallTextLabe30">od:</label><input type="hidden" value="1" name="education_count[]"/>';
    row    += '<input class="smallInput45" type="text" value="" name="education_from_'+nextRowEducation+'"/><label class="smallTextLabe30">do:</label>';
    row    += '<input class="smallInput45" type="text" value="" name="education_to_'+nextRowEducation+'"/>';
    row    += '<input class="input352" type="text" value="" name="education_'+nextRowEducation+'"/><a id="NextRowEducationDelete'+nextRowEducation+'" class="deleteInputButton" onclick="removeRowEducation();return false;">usuń</a></div><div class="clear"></div></div>';
    return row;
}
function removeRowEducation()
{
    $('#NextRowEducationDelete'+(nextRowEducation-1)).show();
    $('#NextRowEducation'+nextRowEducation).remove();
    nextRowEducation--;
    $('.getNewEducationLink').show();
}
// doswiadczenie
var nextRowExperience = 1;
function getNextRowExperience()
{
    if(nextRowExperience>1)
        $('#NextRowExperienceDelete'+nextRowExperience).hide();
    nextRowExperience++;
    if(nextRowExperience>=50)
    {
        $('.getNewExperienceLink').hide();
    }
    var row = '<div id="NextRowExperience'+nextRowExperience+'"><div class="singleFormLine singleFormLineBack"><label class="width70">&nbsp;</label>';
    row    += '<div class="subFormLineBackInfo"><label class="smallTextLabe30">od:</label><input type="hidden" value="1" name="experience_count[]"/>';
    row    += '<input class="smallInput45" type="text" value="" name="experience_from_'+nextRowExperience+'"/><label class="smallTextLabe30">do:</label>';
    row    += '<input class="smallInput45" type="text" value="" name="experience_to_'+nextRowExperience+'"/>';
    row    += '<input class="input352" type="text" value="" name="experience_'+nextRowExperience+'"/><a id="NextRowExperienceDelete'+nextRowExperience+'" class="deleteInputButton" onclick="removeRowExperience();return false;">usuń</a></div><div class="clear"></div></div>';
    return row;
}
function removeRowExperience()
{
    $('#NextRowExperienceDelete'+(nextRowExperience-1)).show();
    $('#NextRowExperience'+nextRowExperience).remove();
    nextRowExperience--;
    $('.getNewExperienceLink').show();
}
// jezyki
var nextRowLanguage = 1;
function getNextRowLanguage()
{
    if(nextRowLanguage>1)
        $('#NextRowLanguageDelete'+nextRowLanguage).hide();
    nextRowLanguage++;
    if(nextRowLanguage>=50)
    {
        $('.getNewLanguageLink').hide();
    }
    var row = '<div id="NextRowLanguage'+nextRowLanguage+'"><div class="singleFormLine singleFormLineBack"><label class="width70">Język</label>';
    row    += '<div class="subFormLineBackInfo"><input type="hidden" value="1" name="language_count[]"/>';
    row    += '<input class="input164" type="text" value="" name="language_'+nextRowLanguage+'"/><label class="smallTextLabe50">stopień:</label>';
    row    += '<input class="input120" type="text" value="" name="language_degree_'+nextRowLanguage+'"/>';
    row    += '<a id="NextRowLanguageDelete'+nextRowLanguage+'" class="deleteInputButton" onclick="removeRowLanguage();return false;">usuń</a></div><div class="clear"></div></div>';
    return row;
}
function removeRowLanguage()
{
    $('#NextRowLanguageDelete'+(nextRowLanguage-1)).show();
    $('#NextRowLanguage'+nextRowLanguage).remove();
    nextRowLanguage--;
    $('.getNewLanguageLink').show();
}
// umiejetnosci
var nextRowSkill = 1;
function getNextRowSkill()
{
    if(nextRowSkill>1)
        $('#NextRowSkillDelete'+nextRowSkill).hide();
    nextRowSkill++;
    if(nextRowSkill>=50)
    {
        $('.getNewSkillLink').hide();
    }
    var row = '<div id="NextRowSkill'+nextRowSkill+'"><div class="singleFormLine singleFormLineBack"><label class="width100">umiejętność:</label>';
    row    += '<div class="subFormLineBackInfo"><input type="hidden" value="1" name="skill_count[]"/>';
    row    += '<input class="input508" type="text" value="" name="skill_'+nextRowSkill+'"/>';
    row    += '<a id="NextRowSkillDelete'+nextRowSkill+'" class="deleteInputButton" onclick="removeRowSkill();return false;">usuń</a></div><div class="clear"></div></div>';
    return row;
}
function removeRowSkill()
{
    $('#NextRowSkillDelete'+(nextRowSkill-1)).show();
    $('#NextRowSkill'+nextRowSkill).remove();
    nextRowSkill--;
    $('.getNewSkillLink').show();
}



function getNextCVRows()
{
    $('.getNewEducationLink').click(function(){
            $(this).prev("div").after(getNextRowEducation());
    });
    $('.getNewExperienceLink').click(function(){
            $(this).prev("div").after(getNextRowExperience());
    });
    $('.getNewLanguageLink').click(function(){
            $(this).prev("div").after(getNextRowLanguage());
    });
    $('.getNewSkillLink').click(function(){
            $(this).prev("div").after(getNextRowSkill());
    });
}
