
function target() {
for (var i=0; i<document.links.length; i++)
	if (document.links[i].className=="blank") {
		document.links[i].target="_blank";
	}
}


function choose_firma(katid,fid) {
	var sel = document.getElementById('firma_select');
	sel.disabled = true;
	document.location.href='/list/'+katid+'?ogfirma='+fid+'&pokaz=pelna_lista';
}
function galeria(prodid) {
	newwindow=window.open( 'http://gallery.kidsplanet24.co.uk/?produkt=' + prodid, 'galeria', 'height=570,width=700,scrollbars=no,resizable=no,menubar=no' )
	if (window.focus) {newwindow.focus()}
	return false;
}

function porownaj_kategorie(katid) {
	newwindow=window.open( 'http://kidsplanet24.co.uk/compare/kategoria/' + katid +'.html', 'porownaj', 'height=800,width=1000,scrollbars=no,resizable=yes,menubar=no,top=0,left=0' )
	if (window.focus) {newwindow.focus()}
	return false;
}

function porownaj_wybrane() {
	newwindow=window.open( 'http://kidsplanet24.co.uk/compare/wybrane.html', 'porownaj', 'height=800,width=1000,scrollbars=no,resizable=yes,menubar=no,top=0,left=0' )
	if (window.focus) {newwindow.focus()}
	return false;
}

function check_value(quantity,prodid) {
	var elem = document.getElementById('i_'+prodid);
	if( Number(elem.value) != Number(prodid) ) {
		elem.style.background = "#FF9999";
		elem.style.color = "#FFF";
	}
}

function add_basket(prodid,opt) {
	var elem = document.getElementById('i_'+prodid);
	switch( opt ) {
		case '0':
			if( elem.value < 2 ) return;
			document.location.href='/basket.html?po='+prodid;
		break;
		case '1':
			if( elem.value > 98 ) return;
			document.location.href='/basket.html?pd='+prodid;
		break;
	}
}


function submit_search() {
	var search_field = document.getElementById('sfraza');
	if( search_field.value == ' szukana fraza' ) {
		search_field.value = '';
	}
}


function nowy_adres(num) {
	var div 	= document.getElementById('nowy_adres');
	var ld_1 	= document.getElementById('ld_1');
	var ld_2 	= document.getElementById('ld_2');
	if( num == 0 ) {
		div.style.display = "none";
		ld_1.style.fontWeight = 'bold';
		ld_2.style.fontWeight = 'normal';
	} else {
		div.style.display = "block";
		ld_1.style.fontWeight = 'normal';
		ld_2.style.fontWeight = 'bold';
	}
}


function zamawiam() {
	var RadioDostawaN1 = document.getElementById('d_1');
	var RadioDostawaN2 = document.getElementById('d_2');
	if( RadioDostawaN1.checked == true ) {
		//alert("Wybrano adres ten sam, co na fakture");
	}
	if( RadioDostawaN2.checked == true ) {
		//alert("Wybrano nowy adres");
		if( document.forms[1] ) {
			if( !validate_form( document.forms[1].imie_n ) ) {
				alert('Proszę wpisać imię');
				return;
			}
			if( !validate_form( document.forms[1].nazwisko_n ) ) {
				alert('Proszę wpisać nazwisko');
				return;
			}
			if( !validate_form( document.forms[1].adres_n ) ) {
				alert('Proszę wpisać adres');
				return;
			}
			if( !validate_form( document.forms[1].miasto_n ) ) {
				alert('Proszę wpisać nazwę miasta');
				return;
			}
			if( !validate_form( document.forms[1].kod_n ) ) {
				alert('Proszę wpisać kod pocztowy');
				return;
			}
		} else {
			//alert("Nie ma formularza");
		}
	}
	document.forms[1].submit();
}


function validate_form( object, text ) {
	if( !object || object.value == '' ) {
		object.focus();
		return false;
	}
	return true;
}


function zaloguj_sie() {
	var DivElem = document.getElementById('login_info');
	if( typeof( DivElem ) != "undefined" ) {
		DivElem.style.display = "block";
		document.location.href = "#body";
	}
}

function zapisz_komentarz() {
	if( document.forms[1] ) {
		var Ocena = document.forms[1].ocena;
		var Komentarz = document.forms[1].komentarz;
		//alert(Ocena.value);
		if( Ocena.value > 0 && Ocena.value < 6 ) {
			if( Komentarz.value != '' ) {
				document.forms[1].submit();
				return true;
			
			} else {
				alert('Proszę wpisać uzasadnienie oceny.');
				return false;
			}
		} else {
			alert('Proszę wybrać ocenę produktu.');
			return false;
		}
		return true;
	}
	//alert("Error!");
	return false;
}



var elementListx = new Array();
var nameListx 	= new Array();

function addElementToListEmpty( element, ename ) {
	elementList[elementList.length] = element;
	nameList[nameList.length] 	= ename;
}

var varErrorStringx = '';

function validateForm() {
	varErrorString = "";
	for(i=0;i<elementList.length;i++) {
		if( !isNotEmptyField( elementList[i] ) ) {
			varErrorStringx = varErrorStringx + 'Field "' +nameList[i]+ '" is empty\n';
		}
	}
	if( varErrorString =='' ) {
		return true;
	}
	alert("Please complete the following details:\n"+varErrorString);
	return false;
}


function submitPlaceOrder() {
	varErrorStringx = '';
	if( document.getElementById('d_2').checked == true ) {
		if( document.getElementById('imie_n').value == '' ) {
			varErrorStringx = varErrorStringx + 'Please write in your first name\n';
		}
		if( document.getElementById('nazwisko_n').value == '' ) {
			varErrorStringx = varErrorStringx + 'Please write in your last name\n';
		}
		if( document.getElementById('adres_n').value == '' ) {
			varErrorStringx = varErrorStringx + 'Please write in your address\n';
		}
		if( document.getElementById('miasto_n').value == '' ) {
			varErrorStringx = varErrorStringx + 'Please write in your city\n';
		}
		if( document.getElementById('kod_n').value == '' ) {
			varErrorStringx = varErrorStringx + 'Please write in your zip code\n';
		}
	}
	if( varErrorStringx =='' ) {
		document.getElementById('submit_this_form').submit();
		return true;
	}
	alert("Please complete the following details:\n"+varErrorStringx);
	return false;
}

