// JavaScript Document
function confirmAction() {
	return confirm("Are you sure?");
}

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 checkEmail(email) {
	if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(email) == false) {
		return false;
	}
	return true;
}

function checkZipCode(zipCode) {
	if (zipCode.length < 5) {
		return false;	
	}

	var digits="0123456789";

	for(i=0; i<5; i++) {
		if (digits.indexOf(zipCode.charAt(i))<0) {
			return false;
		}
	}
	return true;
}

function checkAllBoxes(isChecked) {
	for (var i=0;i<document.postForm.elements.length;i++) {
		var e = document.postForm.elements[i];
		if (e.type=='checkbox') {
			e.checked = isChecked;
		}
	}
}


function pOver(id) {
	var el = document.getElementById(id);
	el.src = "images/rmOn.png";
}
function pOut(id) {
	var el = document.getElementById(id);
	el.src = "images/rmOff.png";
}

function wOver(id) {
	var el = document.getElementById(id);
	el.src = "images/wvOn.png";
}
function wOut(id) {
	var el = document.getElementById(id);
	el.src = "images/wvOff.png";
}


function mOver(nr) {
	for (i=1; i<=7; i++) {
		var el = document.getElementById("m"+i.toString());	
		el.src = "images/mOff"+i.toString()+".jpg";
	}
	var el = document.getElementById("m"+nr.toString());	
	el.src = "images/mOn"+nr.toString()+".jpg";
}
function mOut(id) {
	for (i=1; i<=7; i++) {
		var el = document.getElementById("m"+i.toString());	
		el.src = "images/mOff"+i.toString()+".jpg";
	}
	var el = document.getElementById("m"+mActive.toString());	
	el.src = "images/mOn"+mActive.toString()+".jpg";
	
}

// Wyszukiwarka:
function checkSearchForm(form) {
	var zapytanie = form.qt.value.toString();
	if (zapytanie == searchInputText || zapytanie.length < 3) {
		alert(searchWarningMessage);
		return false;
	}
	return true;
}

function rozwin(nrS) {
	document.getElementById("s1").style.display = 'none';
	document.getElementById("s2").style.display = 'none';
	document.getElementById("s3").style.display = 'none';
	document.getElementById("s4").style.display = 'none';
	document.getElementById("s5").style.display = 'none';
	document.getElementById("s6").style.display = 'none';
	
	document.getElementById("n1").style.display = 'inherit';
	document.getElementById("n2").style.display = 'inherit';
	document.getElementById("n3").style.display = 'inherit';
	document.getElementById("n4").style.display = 'inherit';
	document.getElementById("n5").style.display = 'inherit';
	
	document.getElementById("s"+nrS.toString()).style.display = 'inherit';
	document.getElementById("n"+(nrS-1).toString()).style.display = 'none';
}


function showSubmenu(nrS) {
	document.getElementById("sub1").style.display = 'none';
	document.getElementById("sub2").style.display = 'none';
	document.getElementById("sub3").style.display = 'none';
	document.getElementById("sub4").style.display = 'none';
	document.getElementById("sub5").style.display = 'none';
	
	var isIE6 = /msie|MSIE 6/.test(navigator.userAgent);
	
	if (nrS > 0) {
		document.getElementById("sub"+nrS.toString()).style.display = isIE6 ? 'block' : 'table';
		if (isIE6) {
			document.getElementById("sub"+nrS.toString()).style.width = '210px';
			document.getElementById("sub"+nrS.toString()).style.paddingTop = '20px';
		}
	}
}

function hideSubmenu() {
	document.getElementById("sub1").style.display = 'none';
	document.getElementById("sub2").style.display = 'none';
	document.getElementById("sub3").style.display = 'none';
	document.getElementById("sub4").style.display = 'none';
	document.getElementById("sub5").style.display = 'none';
}

function getCheckedValue(radioObj) {
	if (!radioObj) {
		return "";
	}
	var radioLength = radioObj.length;
	if (radioLength == undefined) {
		if(radioObj.checked) {
			return radioObj.value;
		} else {
			return "";
		}
	}
	for(var i = 0; i < radioLength; i++) {
		if (radioObj[i].checked) {
			return radioObj[i].value;
		}
	}
	return "";
}


function showLoginBox() {
	var loginBox = document.getElementById("loginBlack").style.display = 'inline';
	//document.forms[0].login.focus();
}

function hideLoginBox() {
	var loginBox = document.getElementById("loginBlack").style.display = 'none';
	document.forms[0].login.value = "";
	document.forms[0].password.value = "";
}

function checkForm(form) {
	if (trim(form.login.value).length < 1) {
		alert("Please enter your Username.");
		form.login.focus();
		form.login.select();
		return false;
	}
	if (trim(form.password.value).length < 1) {
		alert("Please enter your Password.");
		form.password.focus();
		form.password.select();
		return false;
	}
	return true;
}
