window.onload = function(){
	BlurLinks();
	// WYkrywamy, czy aby nie mamy do czynienia z IE5.0x, który
	// wywala wyszukiwarkę lokalizacji
	if (browser.isIE && browser.versionMinor < 5.5 && document.getElementById("lokalizacja")) {
		var elements = document.getElementById("lokalizacja").childNodes;
		for (var i=0;i<elements.length;i++ ) {
			if (elements[i].nodeName == "FORM" || elements[i].nodeName == "H2" || elements[i].id == "dane") {
				elements[i].style.display = "none";
			}
		}
		var info = document.createElement("P");
		info.style.color = "#000000";
		info.style.margin = "20px";
		infoContent = "Niestety, przeglądarka Internet Explorer w wersji mniejszej niż 5.5 nie obsługuje możliwości wyszukiwania Centrów Dekoracyjnych. Skorzystaj z <a href=\"lokalizacja.php\">listy centrów</a> lub zainstaluj <a href=\"http://www.microsoft.com/windows/ie/downloads/critical/ie6sp1/default.asp\">nowszą wersję przeglądarki</a>."
		info.innerHTML = infoContent;
		document.getElementById("lokalizacja").appendChild(info);
	} else {
		if(document.getElementById("lokalizacja")){
			setCityInfo();
		}
	}
}
window.onunload = function() {
	if(document.getElementById("lokalizacja")){
		saveCityInfo();
	}
}


function PLWon(inputString) {
	var i=0,
		tmp_str = '',
		currentChar = '',
		tmp_char;

/*
	if ( typeof(inputString) != 'string' ) {
		alert('typeof(inputString)' + typeof(inputString));
	}
*/

/*
	if ( inputString.length ) {
		for (i=0 ; i<inputString.length ; i++) {
//			alert(inputString.charAt(i));
			currentChar = inputString.charAt(i);
			tmp_char = '';
			switch ( currentChar ) {
				case 'ą':{tmp_char += 'a';break;}
				case 'ć':{tmp_char += 'c';break;}
				case 'ę':{tmp_char += 'e';break;}
				case 'ł':{tmp_char += 'l';break;}
				case 'ń':{tmp_char += 'n';break;}
				case 'ó':{tmp_char += 'o';break;}
				case 'ś':{tmp_char += 's';break;}
				case 'ź':{tmp_char += 'z';break;}
				case 'ż':{tmp_char += 'z';break;}

				case 'Ľ':{tmp_char += 'A';break;}
				case 'Ć':{tmp_char += 'C';break;}
				case 'Ę':{tmp_char += 'E';break;}
				case 'Ł':{tmp_char += 'L';break;}
				case 'Ń':{tmp_char += 'N';break;}
				case 'Ó':{tmp_char += 'O';break;}
				case 'Ś':{tmp_char += 'S';break;}
				case 'Ź':{tmp_char += 'Z';break;}
				case 'Ż':{tmp_char += 'Z';break;}
				default:tmp_char += inputString.charAt(i);
			}
			tmp_str += tmp_char;
		}
	}

//	alert(tmp_str);
*/

	return inputString;
}

/*
	Funkcja odczytująca cookis'y z danymi centrów - moduł: "znajdź lokalizację"
*/
function setCityInfo() {
	var cookie = GetCookie("centreInfo");

	if (cookie) {
/*
		cookieArray = cookie.split(",");
		getAllProvinces(cookieArray[0]);
		getAllCityForTheProvince(cookieArray[0],cookieArray[1]);
		showInfoForTheCity(cookieArray[1]);
*/
		getAllProvinces("dolnośląskie");
		getAllCityForTheProvince("dolnośląskie","Wrocław");
		showInfoForTheCity("Wrocław");
	} else {
		getAllProvinces("dolnośląskie");
		getAllCityForTheProvince("dolnośląskie","Wrocław");
		showInfoForTheCity("Wrocław");
	}
	
}

/*
	Funkcja stawiająca cookis'y z danymi centrów - moduł: "znajdź lokalizację"
*/
function saveCityInfo() {
	var info = new Array();
	if (document.getElementById('region').selectedIndex != 0 && document.getElementById('miasto').selectedIndex != 0 ) {
		info[0] = document.getElementById('region').options[document.getElementById('region').selectedIndex].value;
		info[1] = document.getElementById('miasto').options[document.getElementById('miasto').selectedIndex].value;
		SetCookie( "centreInfo" , PLWon(info) , PLWon(exp));
	};
}


/*
	Funkcja do usuwania "blura" z linków
*/

function BlurLinks(){
	if(document.getElementById){
			aElement=document.getElementsByTagName('a');
			for(i=0;i<aElement.length;i++){
				aElement[i].onfocus=new Function("if(this.blur)this.blur()");
			}
	}
}

/*
	Funkcja obsługująca uzupełnianie selectów z rokiem i miesiącem w nowościach
*/

function updateMonths() {
	selectedYear = document.getElementById('y').options[document.getElementById('y').selectedIndex].value;
	tableWithMonths = years[selectedYear];
	with (document.getElementById('m')) {
		for(i=options.length-1;i>0;i--) options[i] = null; // null out in reverse order (bug workarnd)
		for(i=0;i<tableWithMonths.length;i++){
			options[i+1] = new Option(tableWithMonths[i]["label"],tableWithMonths[i]["value"]);
			if (tableWithMonths[i]["selected"] == "true") {
				options[i+1].selected = true;
			}
		}
	}
}

/*
	Funkcja sprawdzająca, czy nie wybrano w selekcie z miesiącami (w nowościach) pierwszego 
	elementu (z napisem "wybierz")
*/

function checkMonth( oSelect ) {
	if (oSelect.selectedIndex != 0) {
		document.getElementById("newsDate").submit();
		return true;
	} else {
		return false;
	}
}
/*
	Funkcja do obcinania białych znaków z końca stringa
*/
		function pad( sString ) {
			var s = new String(sString);
			/*
			startSpace = new RegExp("^ +");
			endSpace = new RegExp(" +$");
			noStartSpace = sString.replace(startSpace,"");
			noSpaceAtAll = noStartSpace.replace(endSpace,"");
			*/
			startSpace = new RegExp("^ +");
			endSpace = new RegExp(" +$");
			noStartSpace = s.replace(startSpace,"");
			noSpaceAtAll = noStartSpace.replace(endSpace,"");
			return noSpaceAtAll;
		}

/*
	Funkcja do validacji formularza - moduł: "stali klienci"
*/
	
function validateLogowanieForm(ID) {
	var error = '';		
	// Nie podano loginu
	if (document.getElementById('login').value == '') {
		error += '\n* Nie podano loginu';
		//changeProperty('login');
	}
	// Nie podano hasła
	if (document.getElementById('haslo').value == '') {
		error += '\n* Nie podano hasła';
		//changeProperty('haslo');
	}

	// Wyswietlanie komunikatu o błędzie i zwracanie wartości false 
	// lub zwracanie wartości true
	if (error != '') {
		alert('W formularzu wystąpiły następujące błędy:\n'+error);
		return false;
	} else {
		document.getElementById(ID).submit();
		return true;
	}
}
/*
	Funkcja do validacji formularza - moduł: "stali klienci"
*/
	
function validateZamowMaterialyForm(ID) {
	var error = '';		
	// Nie podano tytułu wiadomości
	if (document.getElementById('tytul_wiadomosci').value == '') {
		error += '\n* Nie podano tytułu wiadomości';
	}
	// Nie podano treści wiadomości
	if (document.getElementById('tresc_wiadomosci').value == '') {
		error += '\n* Nie podano treści wiadomości';
	}

	// Wyswietlanie komunikatu o błędzie i zwracanie wartości false 
	// lub zwracanie wartości true
	if (error != '') {
		alert('W formularzu wystąpiły następujące błędy:\n'+error);
		return false;
	} else {
		document.getElementById(ID).submit();
		return true;
	}
}

/*
	Funkcje obsługujące subskrypcję
*/

//Funkcja do otwierania subskrypcji
	function openOpenmail() {
		var width=250;
		var height=161;
		x = (screen.width - width)/2;
		y = (screen.height - height)/2;
		window.open('openmail.htm',name,'width='+width+',height='+height+',left='+x+',top='+y);
	}

function dodaj(){
	with(document.subform) {
		jump=action+'?job=dodaj_email&email='+(email.value)+'&lista='+(lista.value)+'&redirect_brak_emaila='+(redirect_brak_emaila.value)+'&redirect_email_niepraw='+(redirect_email_niepraw.value)+'&redirect_email_juz_jest='+(redirect_email_juz_jest.value)+'&redirect_dodano='+(redirect_dodano.value)+'&redirect_usunieto='+(redirect_usunieto.value)+'&redirect_brak_w_bazie='+(redirect_brak_w_bazie.value)
	}
	location=jump
}
function usun(){
	with(document.subform) {
		jump=action+'?job=usun_email&email='+(email.value)+'&lista='+(lista.value)+'&redirect_brak_emaila='+(redirect_brak_emaila.value)+'&redirect_email_niepraw='+(redirect_email_niepraw.value)+'&redirect_email_juz_jest='+(redirect_email_juz_jest.value)+'&redirect_dodano='+(redirect_dodano.value)+'&redirect_usunieto='+(redirect_usunieto.value)+'&redirect_brak_w_bazie='+(redirect_brak_w_bazie.value)
	}
	location=jump
}
/*
	Funkcja do otwierania wycentrowanego popupa z mapą lokalizacji - moduł: "Znajdź lokalizacje" i strona: "Lokalizacje"
*/
	function popupMapa( swfName , name , width , height ) {
		x = (screen.width - width)/2;
		y = (screen.height - height)/2;
		window.open('popup_mapa_lokalizacji.php?id='+swfName+'&width='+width+'&height='+height,name,'width='+width+',height='+height+',left='+x+',top='+y);
	}
	
/*********************
	Funkcje ogólne
*********************/
/*
	Funkcja do otwierania wycentrowanego popupa 
*/
	function openCenteredPopup( url , name , width , height ) {
		x = (screen.width - width)/2;
		y = (screen.height - height)/2;
		window.open(url,name,'width='+width+',height='+height+',status=yes,left='+x+',top='+y);
	}
/*
*	Funkcja do jump menu 
*/

function MM_jumpMenuMain(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}	



