function set_menu_effects() {
	var i = 0;
	var h = 0;
	var l = null;
	while(1) {
		h = document.getElementById('menu_item'+i);
		if(!h)
			break;
		h.setAttribute("onmouseover", "hin(this);");
		h.setAttribute("onmouseout", "hout(this);");
		l = h.getElementsByTagName("a")[0];
		h.setAttribute("onclick", "document.location='"+l.getAttribute("href")+"'"); 
		i++;
	}
}

function hin(e) {
	e.oldClassName = e.className;
	e.className = 'header_menu_hover';
}

function hout(e) {
	e.className = e.oldClassName;
}

function sh_item_hv(obj, c) {
	var colors = Array('#FFD7D9', 'inherit');
	obj.style.backgroundColor = colors[c];
}

function doKoszyka(id) {
	var pcs = document.getElementById('item'+id);
	pcs.style.backgroundColor = "#FFF";
	var tmp = null;
	if(pcs) {
		if(isNumeric(pcs.value, false)) {
			tmp = rawajax('koszyk.if.php?item='+id+'&pcs='+pcs.value);
			if(tmp) {
				alert(tmp);
				var h = document.getElementById('shopNotice');
				if(h) {
					h.innerHTML = '<P style=\"font-weight: bold; font-style: italic; font-size: 12pt; color: #F11; text-align: center;\">Aby zrealizować zamówienie, przejdź do <A href=\"?mod=koszyk\">koszyka &raquo;</A></P>';
				}
			} else {
				alert('Przepraszamy, wystąpił błąd komunikacji z serwerem. Prosimy spróbować ponownie za kilka minut.');
			}
		} else {
			pcs.style.backgroundColor = "#FFD7D9";
			alert('Proszę podać poprawną wartość liczbową');
			return;
		}
	}
}


function zmien_ilosc(id, q) {
	var pcs = prompt('Podaj liczbę sztuk', q);
	if(pcs == null) {
	} else {
		if(!isNumeric(pcs, false)) {
			alert('Podana liczba sztuk nie jest liczbą całkowitą');
			return;
		} else {
			rawajax('koszyk.if.php?item='+id+'&new_pcs='+pcs);
			document.location = '?mod=koszyk';
		}
	}
}

function usun(id) {
	if(confirm('Czy chcesz usunąć ten produkt z koszyka?')) {
		rawajax('koszyk.if.php?remove='+id);
		document.location = '?mod=koszyk';
	}
}

function isNumeric(sText, zero) {
	var ValidChars = "0123456789";
		
	var IsNumber=true;
	var Char;
	for (i = 0; i < sText.length && IsNumber == true; i++) { 
		Char = sText.charAt(i); 
		if (ValidChars.indexOf(Char) == -1) {
			IsNumber = false;
		}
    }
	
	if(zero == false && sText == 0)
		return false;
	else
		return IsNumber;
	return IsNumber;
}


function isEmail(s) {
	var isEmail_re = /^\s*[\w\-\+_]+(\.[\w\-\+_]+)*\@[\w\-\+_]+\.[\w\-\+_]+(\.[\w\-\+_]+)*\s*$/;
	return String(s).search (isEmail_re) != -1;
}

function ch_reg_form() {
	var required_fields = new Array('imie', 'nazwisko', 'ulica', 'miasto', 'kod', 'telefon', 'login', 'nrdomu', 'firma', 'nip');
	var minimum_length = new Array(1, 1, 1, 1, 6, 8, 4, 1, 1, 10);
	var i = required_fields.length;
	var ok = true;
	while(i--) {
		if(document.getElementsByName(required_fields[i])[0].value.length < minimum_length[i]) {
			document.getElementsByName(required_fields[i])[0].style.backgroundColor='#FDE0E0';
			ok = false;
		} else {
			document.getElementsByName(required_fields[i])[0].style.backgroundColor='#FFFFFF';
		}
	}

	if(ok == false) {
		alert("Proszę wypełnić brakujące pola formularza");
	}

	if(ok == true) {
		if(!isEmail(document.getElementsByName('login')[0].value)) {
			alert("Podany adres e-mail nie wydaje się poprawny");
			document.getElementsByName('login')[0].style.backgroundColor='#FDE0E0'
			ok = false;
		}
	}

	document.getElementsByName('pwd1')[0].style.backgroundColor='#FFFFFF';
	document.getElementsByName('pwd2')[0].style.backgroundColor='#FFFFFF';
	//if(document.getElementsByName('pwd1')[0].value.length > 0) {
		if(document.getElementsByName('pwd1')[0].value != document.getElementsByName('pwd2')[0].value) {
			alert("Podane hasła nie są takie same");
			document.getElementsByName('pwd1')[0].style.backgroundColor='#FDE0E0';
			document.getElementsByName('pwd2')[0].style.backgroundColor='#FDE0E0';
			ok = false;
		} else {
			if(document.getElementsByName('pwd1')[0].value.length < 4) {
				alert("Minimalna długość hasła wynosi 4 znaki");
				document.getElementsByName('pwd1')[0].style.backgroundColor='#FDE0E0';
				document.getElementsByName('pwd2')[0].style.backgroundColor='#FDE0E0';
				ok = false;
			}
		}
	//}

	return ok;
}

function ch_order_form() {
	var required_fields = new Array('ulica', 'miasto', 'kod', 'telefon', 'email', 'nrdomu');
	var minimum_length = new Array(1, 2, 6, 8, 3, 1);
	var i = required_fields.length;
	var ok = true;
	while(i--) {
		if(document.getElementsByName(required_fields[i])[0].value.length < minimum_length[i]) {
			document.getElementsByName(required_fields[i])[0].style.backgroundColor='#FDE0E0';
			ok = false;
		} else {
			document.getElementsByName(required_fields[i])[0].style.backgroundColor='#FFFFFF';
		}
	}

	//if(document.getElementById('h_vat').checked) {
		required_fields = new Array('vat_firma', 'vat_nip');
		minimum_length = new Array(1, 10);
		i = required_fields.length;
		while(i--) {
			if(document.getElementsByName(required_fields[i])[0].value.length < minimum_length[i]) {
				document.getElementsByName(required_fields[i])[0].style.backgroundColor='#FDE0E0';
				ok = false;
			} else {
				document.getElementsByName(required_fields[i])[0].style.backgroundColor='#FFFFFF';
			}
		}
	/*} else {
		required_fields = new Array('imie', 'nazwisko');
		minimum_length = new Array(2, 2);
		i = required_fields.length;
		while(i--) {
			if(document.getElementsByName(required_fields[i])[0].value.length < minimum_length[i]) {
				document.getElementsByName(required_fields[i])[0].style.backgroundColor='#FDE0E0';
				ok = false;
			} else {
				document.getElementsByName(required_fields[i])[0].style.backgroundColor='#FFFFFF';
			}
		}
	}*/
	
	if(document.getElementById('ch_inny_adres').checked) {
		required_fields = new Array('i_ulica', 'i_nrdomu', 'i_kod', 'i_miasto', 'i_kraj', 'i_odbiorca');
		minimum_length = new Array(2, 1, 6, 2, 2, 2);
		i = required_fields.length;
		while(i--) {
			if(document.getElementsByName(required_fields[i])[0].value.length < minimum_length[i]) {
				document.getElementsByName(required_fields[i])[0].style.backgroundColor='#FDE0E0';
				ok = false;
			} else {
				document.getElementsByName(required_fields[i])[0].style.backgroundColor='#FFFFFF';
			}
		}
	}

	if(ok == false) {
		alert("Proszę wypełnić brakujące pola formularza");
	}

	if(ok == true) {
		if(!isEmail(document.getElementsByName('email')[0].value)) {
			alert("Podany adres e-mail nie wydaje się poprawny");
			document.getElementsByName('email')[0].style.backgroundColor='#FDE0E0'
			ok = false;
		}
	}
	
	return ok;
}

function faktura(x) {
	if(x) {
		document.getElementById('faktura').style.display='block';
		document.getElementById('klient').style.display='none';
		//document.getElementById('dane_wysylki').style.display='block';
	} else {
		document.getElementById('faktura').style.display='none';
		document.getElementById('klient').style.display='block';
		//document.getElementById('dane_wysylki').style.display='none';
	}
}

function kopiuj_dane() {
	document.getElementsByName('vat_nrdomu')[0].value = document.getElementsByName('nrdomu')[0].value;
	document.getElementsByName('vat_ulica')[0].value = document.getElementsByName('ulica')[0].value;
	document.getElementsByName('vat_kod')[0].value = document.getElementsByName('kod')[0].value;
	document.getElementsByName('vat_miasto')[0].value = document.getElementsByName('miasto')[0].value;
}

function ch_update_form() {
	var required_fields = new Array('imie', 'nazwisko', 'ulica', 'miasto', 'kod', 'telefon', 'nrdomu');
	var minimum_length = new Array(1, 1, 1, 1, 6, 8, 1);
	var i = required_fields.length;
	var ok = true;
	while(i--) {
		if(document.getElementsByName(required_fields[i])[0].value.length < minimum_length[i]) {
			document.getElementsByName(required_fields[i])[0].style.backgroundColor='#FDE0E0';
			ok = false;
		} else {
			document.getElementsByName(required_fields[i])[0].style.backgroundColor='#FFFFFF';
		}
		//alert(required_fields[i]);
	}

	if(ok == false) {
		alert("Proszę wypełnić brakujące pola formularza");
	}

	if(document.getElementsByName('pwd1')[0].value.length > 0 || document.getElementsByName('pwd2')[0].value.length > 0) {
		document.getElementsByName('pwd1')[0].style.backgroundColor='#FFFFFF';
		document.getElementsByName('pwd2')[0].style.backgroundColor='#FFFFFF';
    	if(document.getElementsByName('pwd1')[0].value.length > 0) {
			if(document.getElementsByName('pwd1')[0].value != document.getElementsByName('pwd2')[0].value) {
				alert("Podane hasła nie są takie same");
				document.getElementsByName('pwd1')[0].style.backgroundColor='#FDE0E0';
				document.getElementsByName('pwd2')[0].style.backgroundColor='#FDE0E0';
				ok = false;
			} else {
				if(document.getElementsByName('pwd1')[0].value.length < 4) {
					alert("Minimalna długość hasła wynosi 4 znaki");
					document.getElementsByName('pwd1')[0].style.backgroundColor='#FDE0E0';
					document.getElementsByName('pwd2')[0].style.backgroundColor='#FDE0E0';
					ok = false;
				}
			}
		}
	}

	return ok;
}

function set_menu_effects() {
	var i = 0;
	var h = 0;
	var l = null;
	while(1) {
		h = document.getElementById('menu_item'+i);
		//alert(h);
		if(h == null)
			break;
		h.onmouseover = function() { menuin(this); };
		h.onmouseout = function() { menuout(this); };
		l = document.getElementById("menu_link_"+i);
		if(l)
			h.onclick = function() { 
				var x = this.getElementsByTagName('a');
				if(x != null) {
					document.location = x[0].href;
				}
			};
		i++;
	}
}

function menuin(e) {
	e.oldClassName = e.className;
	e.className = 'main_menu_item_hover';
}

function menuout(e) {
	e.className = e.oldClassName;
}

function innyAdres(i) {
	if(i.checked)
		document.getElementById('innyAdres').style.display='block';
	else
		document.getElementById('innyAdres').style.display='none';
}

function c_register_form() {
	var required_fields = new Array('nazwa', 'ulica', 'miasto', 'kod', 'email', 'nrdomu', 'firma', 'firma_miasto', 'serial');
	var i = required_fields.length;
	var ok = true;
	while(i--) {
		if(document.getElementsByName(required_fields[i])[0].value.length < 1) {
			document.getElementsByName(required_fields[i])[0].style.backgroundColor='#FDE0E0';
			ok = false;
		} else {
			document.getElementsByName(required_fields[i])[0].style.backgroundColor='#FFFFFF';
		}
	}

	if(ok == false) {
		alert("Proszę wypełnić brakujące pola formularza");
	} else if(!isEmail(document.getElementsByName('email')[0].value)) {
			alert("Podany adres e-mail nie wydaje się poprawny");
			document.getElementsByName('email')[0].style.backgroundColor='#FDE0E0'
			ok = false;
	}

	return ok;
}
   
function dostawa(id) {
	rawajax('koszyk.if.php?dostawa='+id);
	document.location='?mod=koszyk';
}

var i=0;
function ami(obj) {
	i=80;
	if(obj.style.opacity != undefined)
		obj.style.opacity=(i/100);
	if(obj.filters != undefined)
		if(obj.filters.alpha != undefined)
			obj.filters.alpha.opacity=i;
}

function amo(obj) {
	i=100;
	if(obj.style.opacity != undefined)
		obj.style.opacity=(i/100);
	if(obj.filters != undefined)
		if(obj.filters.alpha != undefined)
			obj.filters.alpha.opacity=i;
}

function quick_msg() {
	if(!isEmail(document.getElementById('qf_email').value)) {
		alert('Proszę wpisać poprawny adres e-mail');
		return;
	}
	
	if(document.getElementById('qf_nazwa').value.length < 1) {
		alert('Proszę wpisać imię i nazwisko lub nazwę firmy');
		return;
	}
	
	if(document.getElementById('qf_wiadomosc').value.length < 1) {
		alert('Proszę wpisać treść wiadomości');
		return;
	}
	
	var x = rawajax('qmsg.php?from='+document.getElementById('qf_nazwa').value+'&mail='+document.getElementById('qf_email').value+'&phone='+document.getElementById('qf_telefon').value+'&msg='+document.getElementById('qf_wiadomosc').value+'&sid='+document.getElementById('php_sid').value);
	document.getElementById('qf_nazwa').value = '';
	document.getElementById('qf_email').value = '';
	document.getElementById('qf_telefon').value = '';
	document.getElementById('qf_wiadomosc').value = '';
	alert('Dziękujemy, Twoja wiadomość została wysłana.');
}

function loadCategories() {
	var params = {wmode: "transparent"};
	var flashvars = {};
	var attributes = {};
	var h = null;
	var i = 0;
	while(1) {
		h = document.getElementById('cat'+i);
		if(h == null)
			break;
		swfobject.embedSWF("cat.swf?ikona="+imgs[i]+"&opis="+labels[i]+"&link="+links[i], "cat"+i, "202", "170", "8", "expressInstall.swf", flashvars, params, attributes);
		i++;
	}
	
}
