
/*
 *	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');
		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;
		}
		if(gotowkamoze){
			gotowka.disabled = false;	
		}else{
			gotowka.disabled = true;	
		}
		
		przedplata.checked 	= true;
		suma_tmp.value 		= sumai;
		suma_tmp_kw.value 	= pobranie_val;
		
		
		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){
		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;
		}
		wpis.innerHTML = sumai + ' PLN';
	}
	
	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;
}

	
function new_window(link) {
	window.open(link,'Galeria','menubar=no,toolbar=no,scrollbar=no,resizable=no,status=no,width=600,height=650');
}

function czyscArea(ob) {
	if (ob.value == 'Twoje pytanie...') {
		ob.value = '';
	}
}
