﻿var i = 0, cssWlaczony, body;

function inicjujJs() {
	klasaCssWartosc = Cookie.read('klasaCss');
	body = $(document.body.getAttribute('id'));
	if (body.getStyle('unicode-bidi') == 'embed') {cssWlaczony = new Boolean(true);}
	if(cssWlaczony) {
		autoCompleter();	
		autoCompleterBip();	
		ie6CssMenu();
	}
	inputyZTekstem();
	popup();
	
}










function ie6CssMenu() {
	if (window.attachEvent) { // funkcja jest potrzebna tylko dla ie6. 
		$$('.menuBoczne li').each(function(item,index) {
			item.addEvents({
					'mouseenter': function() {
						item.addClass('podmenuIE6');
					},
					'mouseleave': function() {
						item.removeClass('podmenuIE6');
					}
			});
		});	
	}
}

function autoCompleter() {
	if ($('wyszukiwarkaAutosuggest')) {
	    new Autocompleter.Request.JSON('wyszukiwarkaAutosuggest', '/wyszukiwarka/json/', {
	        'postVar': 'szukanaFraza',
	        'width' : 300, 
	        'minLength' : 3,
	        'maxChoices' : 10,
	        'cache' : true
	    });
	}	
}

function autoCompleterBip() {
	if ($('wyszukiwarkaAutosuggestBip')) {
	    new Autocompleter.Request.JSON('wyszukiwarkaAutosuggestBip', '/bip/wyszukiwarka/json/', {
	        'postVar': 'szukanaFraza',
	        'width' : 300, 
	        'minLength' : 3,
	        'maxChoices' : 10,
	        'cache' : true
	    });
	}	
}

function accordion() {
	if ($('accordion')) {
		var myAccordion = new Accordion($('accordion'), 'h3.toggler', 'div.element', {
			opacity: false,
			onActive: function(toggler, element){
				toggler.setStyle('color', '#41464D');
			},
			onBackground: function(toggler, element){
				toggler.setStyle('color', '#528CE0');
			}
		});	
		}	
}




function pokazRejestrZmian() {
	if ($('pokaz_rejestr')) {
		$('pokaz_rejestr').setStyle('display', 'none');
		$('rejestr_table').setStyle('display', 'block');
		$('ukryj_rejestr').setStyle('display', 'block');		
	}

}  

function ukryjRejestrZmian() {
	if ($('pokaz_rejestr')) {
		$('pokaz_rejestr').setStyle('display', 'block');
		$('rejestr_table').setStyle('display', 'none');
		$('ukryj_rejestr').setStyle('display', 'none');		
	}

}



function inputyZTekstem() {
	var pola = new Array();

	pola['newsletterEmail'] = 				'..................';
	pola['subskrypcjaEmail'] = 				'e-mail';
	pola['wyszukiwarkaAutosuggest'] = 		'wpisz frazę';
	pola['wyszukiwarkaAutosuggestBip'] = 		'wpisz frazę';

	
	for (var el in pola) {
		ustawValue(el,pola[el]);
	}
}
function ustawValue(id,Value) {
	if ($(id)) { 
		if ($(id).value == '') {
			$(id).value = Value;
		} else {
			Value = $(id).value;
		}
		$(id).addEvents({
			'focus': function() {
				if ($(id).value == Value) {
					$(id).value = '';
				}
			},
			'blur': function() {
				if ($(id).value == '') {
					$(id).value = Value;
				}
			}
		});
	}
}




function tworzCiacho(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}



function popup() {
	var link;
	$$('.popup').each(function(item,index) {
		item.addEvent('click', function() {
			link = item.getAttribute('href');
			if (maKlase(item, 'potwierdzenieUsuniecia') && confirm('Kontynuować usuwanie modułu?')) {
					window.open(link, 'okno_pomocy', 'menubar=0,scrollbars=0,resizable=1,width=773,height=650');					
			} else if (!maKlase(item, 'potwierdzenieUsuniecia')) {
				window.open(link, 'okno_pomocy', 'menubar=0,scrollbars=0,resizable=1,width=773,height=650');
			}
			
            return false;
		});
	});
}



function maKlase (obj, klasaCss) {
    if (typeof obj == 'undefined' || obj==null || !RegExp) { return false; }
    var re = new RegExp("(^|\\s)" + klasaCss + "(\\s|$)");
    if (typeof(obj)=="string") {
      return re.test(obj);
    } else if (typeof(obj)=="object" && obj.className) {
      return re.test(obj.className);
    }
	return false;
}




