function zagielwindow(shopid, fid) {
	amount = document.forms[fid].elements['price'].value;
	amount = amount.replace(' PLN', '');
	url = 'https://www.zagiel.com.pl/kalkulator/index_smart.php?action=getklientdet_si_rata&shopNo='+shopid+'&goodsValue='+amount;
	window.open(url, 'zagielwindow', 'width=650, height=650, toolbar=no, scrollbars=yes');
}

function zagielwindow2(shopid, amount) {
	url = 'https://www.zagiel.com.pl/kalkulator/index_smart.php?action=getklientdet_si_rata&shopNo='+shopid+'&goodsValue='+amount;
	window.open(url, 'zagielwindow', 'width=650, height=650, toolbar=no, scrollbars=yes');
}

function opensmallwindow(w, h) {
	if (window.smallwindow) {smallwindow.close();}
	smallwindow = window.open('', 'smallwindow', 'width='+w+', height='+h+', toolbar=no, scrollbars=yes')
	smallwindow.focus();
}

function openimgwindow(w, h) {
	if (window.imgwindow) {imgwindow.close();}
	imgwindow = window.open('', 'imgwindow', 'width='+w+', height='+h+', toolbar=no, scrollbars=no')
	imgwindow.focus();
}

function openimglibwindow(w, h) {
	if (window.imglibwindow) {imglibwindow.close();}
	imglibwindow = window.open('', 'imglibwindow', 'width='+w+', height='+h+', toolbar=no, scrollbars=yes')
	imglibwindow.focus();
}

function openhelpwindow(w, h) {
	if (window.helpwindow) {helpwindow.close();}
	helpwindow = window.open('', 'helpwindow', 'width='+w+', height='+h+', toolbar=no, scrollbars=yes')
	helpwindow.focus();
}

function se(a,b) {
	window.location.href = 'mailto:'+a+'@'+b+'.eu';
}

function validateform() {
 for(var i=0; i<fields.length; i++) {
  if (document.f.elements[fields[i]].value == '' || document.f.elements[fields[i]].value == 0) {
   alert(fields_info[i]);
   document.f.elements[fields[i]].focus();
   return false;
  }
 }
 if (!validateemail(document.f.elements['email'].value)) {
  return false;
 }
 if (!validatepass()) {
  return false;
 }
 return true;
}

function validateemail(t) {
  maska = /^[0-9a-z_.-]+@([0-9a-z-]+.)+[a-z]{2,4}$/;
  if (maska.test(t)==false) { 
    alert("Podaj poprawny adres e-mail");
    document.f.elements['email'].focus();
    return false;
  }
  return true;
}

function validatepass(t) {
  if (document.f.elements['pass'].value != document.f.elements['pass2'].value) { 
    alert('Pola "Hasło" i "Powtórz hasło" muszą być równe');
    document.f.elements['pass2'].focus();
    return false;
  }
  return true;
}

function p(x) {
   return x.toString().replace(/\,/,'.');
}

function checkext(name) {
  var ext = document.f.elements[name].value;
  if (ext.length > 0) {
  	ext = ext.substring(ext.length-3,ext.length);
  	ext = ext.toLowerCase();
  	if(ext != 'jpg') {
      alert('Akceptowane są wyłącznie pliki JPG.');
      return false;
    } else {
      return true;
    }
  }
  return true;
}

function _clear() {
	for (i = document.f.selout.length; i > 0; i--) {
		document.f.selout.options[i-1] = null
	}
	for (i = document.f.elements['selin[]'].length; i > 0; i--) {
		document.f.elements['selin[]'].options[i-1] = null
	}
}

function _newoutoption(selvalue) {
	selaccept = 1;
	for (i=0; i<document.f.selout.length; i++) {
		if (document.f.selout[i].value == selvalue) {
			selaccept = 0;
		}
	}
	if (selaccept == 1) {
		tblseloutvalue[selvalue] = tblselinvalue[selvalue];
		tblselinvalue[selvalue] = '';
	}
	_clear()
	_fill();
}

function _alloutoption() {
	for (var i in tblselinvalue) {
		_newoutoption(i)
	}
}

function _allinoption() {
	for (var i in tblseloutvalue) {
		_newinoption(i)
	}
}

function _newinoption(selvalue) {
	selaccept = 1;
	for (i=0; i<document.f.elements['selin[]'].length; i++) {
		if (document.f.elements['selin[]'][i].value == selvalue) {
			selaccept = 0;
		}
	}
	if (selaccept == 1) {
		tblselinvalue[selvalue] = tblseloutvalue[selvalue];
		tblseloutvalue[selvalue] = '';
	}
	_clear()
	_fill();
}

function _fill() {
	for (var i in tblselinvalue) {
		if (tblselinvalue[i] != '') {
			var newoption = new Option(tblselinvalue[i], i);
			document.f.elements['selin[]'].options[document.f.elements['selin[]'].length] = newoption;
		}
	}

	for (var i in tblseloutvalue) {
		selaccept = 1;
		for (j=0; j<document.f.elements['selin[]'].length; j++) {
			if (document.f.elements['selin[]'][j].value == i) {
				selaccept = 0;
			}
		}
		if (selaccept == 1) {
			if (tblseloutvalue[i] != '') {
				var newoption = new Option(tblseloutvalue[i], i);
				document.f.selout.options[document.f.selout.length] = newoption;
			}
		}
	}
}

function _selallin() {
	for (j=0; j<document.f.elements['selin[]'].length; j++) {
		document.f.elements['selin[]'][j].selected = 1;
	}
}
