
/*
*	Ukrywanie warstw kontaktu w lewym menu
*/

function showContact(id){

	actual = document.getElementById('contact_'+id);
	actual_status = actual.style.display;
	cont = document.getElementById('contact');
	var children = cont.childNodes;
	for (var i = 0; i < children.length; i++) {
		if(children[i].id){
			cont_id = children[i].id;
			if(cont_id.substring(0,8)=='contact_'){
				warstwa = document.getElementById(cont_id);
				warstwa.style.display = 'none';
			}
		}
	}
	warstwa = document.getElementById('contact_'+id);
	if(actual_status == 'block'){
		warstwa.style.display = 'none';
	}else{
		warstwa.style.display = 'block';
	}
}

/*
*	funkcja dodaje element do koszyka
*/

function addCart(id_product){
	document.location.href="index.php?m=ShopCart&add=" + id_product;
}

/*
*	sumowanie ceny dostawy
*/


function sumuj(towary, dostawa, pobranie_val){

	wybrane 	= document.getElementById('wybrane');
	wpis 		= document.getElementById('suma');
	cenaTransportu 		= document.getElementById('cenaTransportu');
	gotowka 	= document.getElementById('gotowka');
	pobranie 	= document.getElementById('pobranie');
	przedplata 	= document.getElementById('przedplata');
	suma_tmp 	= document.getElementById('pobranie_tmp_suma');
	suma_tmp_kw	= document.getElementById('pobranie_tmp_kwota');

	if(wybrane.checked){
		var sumai = towary;
		var gotowkamoze = true;
	}else{
		var sumai = towary + dostawa;
		var gotowkamoze = false;
	}
	
	cenaTransportu.value = dostawa;
	
	if(gotowkamoze){
		gotowka.disabled = false;
	}else{
		gotowka.disabled = true;
	}

	//przedplata.checked 	= true;
	suma_tmp.value 		= sumai;
	suma_tmp_kw.value 	= pobranie_val;

	var sumaDoRat = document.getElementById('suma_do_rat');
	sumaDoRat.value = (sumai);

	wpis.innerHTML = sumai + ' PLN';

	pobranie_t = document.getElementById('pobranie_title');
	if(pobranie_val){
		pobranie_t.innerHTML = '(Opłata '+ pobranie_val +' PLN)';
	}else{
		pobranie_t.innerHTML = '';
	}

}

function sumujPobranie(odb, raty){
	
	wpis 		= document.getElementById('suma');
	suma_tmp 	= document.getElementById('pobranie_tmp_suma');
	suma_tmp_kw	= document.getElementById('pobranie_tmp_kwota');

	kwota1 		= parseFloat(suma_tmp.value);
	kwota2 		= parseFloat(suma_tmp_kw.value);
	if(odb){
		sumai 		= kwota1 + kwota2;
	}else{
		sumai 		= kwota1;
	}


	var sumaDoRat = document.getElementById('suma_do_rat');
	sumaDoRat.value = (sumai);

	wpis.innerHTML = sumai + ' PLN';

	var rt1 			= document.getElementById('raty_zagiel_info');
	if(rt1 != null) {
		rt1.style.display	='none';
	}
	var rt2 			= document.getElementById('raty_lukas_info');
	if(rt2 != null) {
		rt2.style.display	='none';
	}
	if(raty){
		var rt 		= document.getElementById('raty_'+raty+'_info');
		if(rt != null) {
			rt.style.display='block';
		}
	}

}

function open_zagiel() {
	window.open('http://www.zagiel.com.pl/kalkulator/jak_kupic.html', 'nowe_okno','width=600,height=500,directories=no,location=no,menubar=no,resizable=yes,scrollbars=yes,status=no,toolbar=no');
}
function open_lukas() {
	window.open('index.php?m=Product_Details&e=lucas2', 'nowe_okno','width=600,height=500,directories=no,location=no,menubar=no,resizable=yes,scrollbars=yes,status=no,toolbar=no');
}

function aktywuj(val){
	orderb = document.getElementById('orderbutton');
	if(val){
		orderb.disabled = false;
		orderb.src="./design/img/sub_zamow.gif";
	}else{
		alert('Przed wysłaniem zamówienia należy zaakceptować\nregulamin sklepu internetowego!');
		orderb.disabled = true;
		orderb.src="./design/img/sub_zamow_n.gif";
	}
}

/*
*	validacja formularzy
*/

function simpleValidation(id) {

	form = document.getElementById(id);
	fields = form.getElementsByTagName('input');

	for (var i = 0; i < fields.length; i++) {
		if (fields[i].value=='') {
			return false;
		}
	}
	return true;
}


function validateForm(id){

	field = document.getElementById(id);
	toValidate = field.getElementsByTagName('input');

	label = field.getElementsByTagName('label');

	comm = document.getElementById('comm');
	for (var i = 0; i < toValidate.length; i++) {
		if (toValidate[i].value=='' && toValidate[i].id!= 'passwd' ) {
			alert('Uzupełnij brakujące dane');
			return false;
		}
	}
	return true;
}

/*
*	funkcje do obslgi shop cart
*/

function remCart(id,pozycja){
	if(confirm("Czy napewno usunąć pozycję numer "+pozycja+" z koszyka?")){
		document.location.href="index.php?m=ShopCart&rem="+id;
	}
}

function emptyCart(){
	if(confirm("Czy usunąć wszystkie pozycje z koszyka?")){
		document.location.href="index.php?m=ShopCart&empty=1";
	}
}

/*
*validacja callback
*/

function CallProduct(callback) {

	fields = callback.getElementsByTagName('input');

	for (var i = 0; i < fields.length; i++) {
		if (fields[i].value=='') {
			alert('Wpisz swoje imię i nazwisko oraz numer telefonu');
			return false;
		}
	}
	return true;
}
