
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+'';
}
function galeria(prodid) {
	newwindow=window.open( 'http://galeria.zarma.pl/?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( '/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( '/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,kolor,rozmiar) {
	var elem = document.getElementById('i_'+prodid);
	var adString = '';
	if( kolor != 'NULL' ) {
		adString = adString + '&prod_kolor=' + kolor;
	}
	if( rozmiar != 'NULL' ) {
		adString = adString + '&prod_rozmiar=' + rozmiar;
	}
	switch( opt ) {
		case '0':
			if( elem.value < 2 ) return;
			document.location.href='/basket.html?po='+prodid+adString;
		break;
		case '1':
			if( elem.value > 98 ) return;
			document.location.href='/basket.html?pd='+prodid+adString;
		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[2] ) {
		var Ocena = document.forms[2].ocena;
		var Komentarz = document.forms[2].komentarz;
		//alert(Ocena.value);

			if( Komentarz.value != '' ) {
				document.forms[2].submit();
				return true;
			
			} else {
				alert('Proszę wpisać uzasadnienie oceny.');
				return false;
			}
		return true;
	}
	//alert("Error!");
	return false;
}




function addToBasket( itemID, quantity ) {
	var stringOptons = '';
	if( document.getElementById('prod_kolor') ) {
		stringOptons = stringOptons + '&prod_kolor=' + document.getElementById('prod_kolor').value;
		//alert('Jest kolor');
	}
	if( document.getElementById('prod_rozmiar') ) {
		stringOptons = stringOptons + '&prod_rozmiar=' + document.getElementById('prod_rozmiar').value;
		//alert('Jest rozmiar');
	}
	document.location.href='/basket.html?to_basket='+itemID+'&quantity='+quantity+stringOptons;
}




function sprawdzTresc(objectElem,tresc) {
	if( objectElem.value == tresc ) {
		objectElem.value="";
		return;
	}
	if( objectElem.value == "" ) {
		objectElem.value=tresc;
		return;
	}
}


function pokazWszystkie() {
	for(var i=5;document.getElementById('lista_'+i);i++) {
		document.getElementById('lista_'+i).style.display="block";
	}
	document.getElementById('hide_wszystkie').style.display="none";
	document.getElementById('show_wszystkie').style.display="block";
}
function hideWszystkie() {
	for(var i=5;document.getElementById('lista_'+i);i++) {
		document.getElementById('lista_'+i).style.display="none";
	}
	document.getElementById('hide_wszystkie').style.display="block";
	document.getElementById('show_wszystkie').style.display="none";
}

function pokazWszystkie2() {
	for(var i=5;document.getElementById('lista2_'+i);i++) {
		document.getElementById('lista2_'+i).style.display="block";
	}
	document.getElementById('hide_wszystkie2').style.display="none";
	document.getElementById('show_wszystkie2').style.display="block";
}
function hideWszystkie2() {
	for(var i=5;document.getElementById('lista2_'+i);i++) {
		document.getElementById('lista2_'+i).style.display="none";
	}
	document.getElementById('hide_wszystkie2').style.display="block";
	document.getElementById('show_wszystkie2').style.display="none";
}



function zmienGrafike( elemID ) {
	if( typeof( imageGalery[elemID] ) != "undefined" ) {
		main = imageGalery[0];
		// set main
		imageGalery[0] = imageGalery[elemID];
		document.getElementById('bigprimage').style.backgroundImage='url(/Thumb.php?src=upload/'+imageGalery[elemID]+')';
		// set back from main
		imageGalery[elemID] = main;
		document.getElementById('galsmall_'+elemID).style.backgroundImage='url(/upload/small_min_'+main+')';
	}
}



function isValidEmailxx(email, required) {
    if (required==undefined) {   // if not specified, assume it's required
        required=true;
    }
    if (email==null) {
        if (required) {
            return false;
        }
        return true;
    }
    if (email.length==0) {  
        if (required) {
            return false;
        }
        return true;
    }
    if (! allValidChars(email)) {  // check to make sure all characters are valid
        return false;
    }
    if (email.indexOf("@") < 1) { //  must contain @, and it must not be the first character
        return false;
    } else if (email.lastIndexOf(".") <= email.indexOf("@")) {  // last dot must be after the @
        return false;
    } else if (email.indexOf("@") == email.length) {  // @ must not be the last character
        return false;
    } else if (email.indexOf("..") >=0) { // two periods in a row is not valid
	return false;
    } else if (email.indexOf(".") == email.length) {  // . must not be the last character
	return false;
    }
    return true;
}

function allValidChars(email) {
  var parsed = true;
  var validchars = "abcdefghijklmnopqrstuvwxyz0123456789@.-_";
  for (var i=0; i < email.length; i++) {
    var letter = email.charAt(i).toLowerCase();
    if (validchars.indexOf(letter) != -1)
      continue;
    parsed = false;
    break;
  }
  return parsed;
}



function dodajDoNewslettera() {
	if( isValidEmailxx(document.getElementById('newslettermail').value ) ) {
		document.getElementById('nForm').submit();
		return;
	}
	alert('Brak lub zły adres e-mail');
}

function wypiszZNewslettera() {
	if( isValidEmailxx(document.getElementById('newslettermail').value ) ) {
		document.getElementById('ndelete').value=1;
		document.getElementById('nForm').submit();
		return;
	}
	alert('Brak lub zły adres e-mail');
}


