String.prototype.trim = function() {
	var result = '';
	var temp = this;

	result = temp.replace(/^\s+/g, '').replace(/\s+$/g, '');

	return result;
}

function select_url(s) {
	var gourl = s.options[s.selectedIndex].value;
	if(gourl != 'none')	window.top.location.href = gourl;
}

function clear_field(e) {
	e.value = '';
}


/*Subskrypcja*/
function dodaj(){
var elem = document.getElementById('subform');
	if ( validate() ){
		okno = window.open('','','width=370,height=200,left=150,top=150');
		with(elem) {
			okno.location=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);
		}
	}
}

function usun(){
	alert()
var elem = document.getElementById('subform');
	if ( validate() ){
		okno = window.open('','','width=370,height=200,left=150,top=150');
		with(elem) {
			okno.location=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);
		}
	}
}

function validate(){
	var rx=new RegExp("^[\\w\.=-]+@[\\w\\.-]+\\.[a-zA-Z]{2,4}$");
	var errors = "";
	if (document.getElementById("email").value.trim() == "" || !rx.test(document.getElementById("email").value)) {
		alert("Field \"e-mail\" is empty or email address is invalid");
		return false;
	} else {
		return true;
	}
}



// Script for faq
// code idea from www.minimalweb.de
function init_odpowiedzi() {
	odpowiedzi = document.getElementsByTagName("DT");
	for (i=0; i < odpowiedzi.length; i++) {
		odpowiedzi[i].firstChild.onclick = function() {
			this.blur();
			if(this.parentNode.parentNode.className == "live") {
				check = '';

				tresci = document.getElementsByTagName("DD");
/*				for (j=0;j < tresci.length; j++) {
					if(tresci[j].parentNode.className == "live") {
						tresci[j].style.display = 'none';
					}
				}
*/
//				if (this.parentNode.className == 'on') check = 'on';

				tytuly = document.getElementsByTagName("DT");
				for (j=0;j < tytuly.length; j++) {
					//if (tytuly[j] != this.parentNode)
					tytuly[j].className = '';
				}


				if (check != 'on') {
					change_ref(this.parentNode);

					odpowiedz_box = this.parentNode.nextSibling;
					while(odpowiedz_box) {
						if(odpowiedz_box.nodeName == "DD") {
							show_ref(odpowiedz_box);
						} else if(odpowiedz_box.nodeName == "DT") {
							break;
						}
						odpowiedz_box = odpowiedz_box.nextSibling;
					}

				}

				return false;
			}
		}
	}
}

function show_ref(odpowiedz) {
	if(odpowiedz.style.display != 'block') {
		odpowiedz.style.display = 'block';
	} else {
		odpowiedz.style.display = 'none';
	}
}

function change_ref(tar) {
	if(tar.className != 'on') {
		tar.className = 'on';
	} else {
		tar.className = '';
	}
}



function mapa(id){
	okno = window.open('mapa.php?objectId='+id,'','width=436,height=510,left=150,top=50');
}


function IE_FixSrix() {
	var links = document.getElementsByTagName("A");

	for(i=0;i<links.length;i++ ) {
		if(links[i].className == "showImgRoot") {
			links[i].onmouseover=function() {
				for(j=0;j<this.childNodes.length;j++ ) {
					if(this.childNodes[j].nodeName == "IMG") this.childNodes[j].style.display = "block";
				}
			}

			links[i].onmouseout=function() {
				for(j=0;j<this.childNodes.length;j++ ) {
					if(this.childNodes[j].nodeName == "IMG") this.childNodes[j].style.display = "none";
				}
			}
		}
	}
}


var sIndex;
function showOrNot(a){
	if(a.value == 'pobranie') {		
		sIndex = document.getElementById('orNot').selectedIndex;
		document.getElementById('orNot').disabled = 'disabled';
		document.getElementById('orNot').value = '';
		document.getElementById('topOrNot').style.display = 'none';
	}
	else {
		document.getElementById('orNot').disabled = '';
		sIndex = (sIndex != null) ? sIndex : document.getElementById('orNot').selectedIndex;
		document.getElementById('orNot').selectedIndex = sIndex;
		document.getElementById('topOrNot').style.display = 'block';
		sIndex = null;
	}
}
