function checkEmail (email) {
      invalid = " /:,;";
      if (email=="") { return false }
      for (i=0; i<invalid.length; i++) {
        bad = invalid.charAt(i);
        if (email.indexOf (bad, 0) != -1) { return false }
      }
      at = email.indexOf ("@", 0);
      if ((at == -1) || (at == 0)) { return false }
      if (email.indexOf ("@", at+1) != -1) { return false }
      period = email.indexOf (".", at);
      if ((period == -1) || (period == at+1)) { return false }
	  znak = email.charAt(email.length - 1);
      if (znak ==  ".") { return false }
      at = email.indexOf (".",email.length - 4);
      if (at == -1) { return false };
      return true;
}

function zapisz(form,msg) {
	if (!(checkEmail(form.email.value))) {
		alert(msg);
		form.email.focus();
		form.email.select();
		return false;
	}
	else {
		return true;
	}
}


function zapiszCustomer(form,msg) {
	var ifNewsletter = form.newsletter.checked;

	if (ifNewsletter) {
		if (!(checkEmail(form.email.value))) {
			alert(msg);
			form.email.focus();
			form.email.select();
			return false;
		} else {
			return true;
		}
	} else {
		if (!(checkCustomerEmail(form.email.value))) {
			alert(msg);
			form.email.focus();
			form.email.select();
			return false;
		} else {
			return true;
		}
	}
}


function checkCustomerEmail (email) {
      invalid = " /:,;";
      if (email=="") { return true }
      for (i=0; i<invalid.length; i++) {
        bad = invalid.charAt(i);
        if (email.indexOf (bad, 0) != -1) { return false }
      }
      at = email.indexOf ("@", 0);
      if ((at == -1) || (at == 0)) { return false }
      if (email.indexOf ("@", at+1) != -1) { return false }
      period = email.indexOf (".", at);
      if ((period == -1) || (period == at+1)) { return false }
	  znak = email.charAt(email.length - 1);
      if (znak ==  ".") { return false }
      at = email.indexOf (".",email.length - 4);
      if (at == -1) { return false };
      return true;
}


//czy zaznaczono odpowiedz w sondzie
function sendOpinion(nazwa,msg) {

	// czy po nazwie czy po wskazniku
	if (document.forms[nazwa]) {
		form = document.forms[nazwa];
	} else {
		form = nazwa;
	}

	var key = 0;
	for (var i = 0; i < form.my_opinion.length; i++){
		if (form.my_opinion[i].checked){
			key = form.my_opinion[i].value;
			break;
		}
	}

	if (key == 0) {
		alert(msg);
		return false;
	} else {
		if (key == form.klucz.value) {
			form.action.value = "form";
		} else {
//			form.set.value = "tak";
		}
	}

	return true;
}

function submitForm(name){
	if (document.forms[name])   {
		document.forms[name].submit();
	}
}
