if(typeof msgWriter == "undefined") msgWriter = new Object()

msgWriter.add = function(msg){
 	if(typeof this.messages == "undefined"){ this.messages = new Array(); this.msgCount = 0; }
	this.messages[this.msgCount++] = msg
}

msgWriter.clear = function(){
	this.messages = new Array()
	this.msgCount = 0
}

msgWriter.show = function(){
	o = document.getElementById("mod_blad")
	
	doc = '';
	for(key in this.messages){
		doc += "<li>"+this.messages[key]+"</li>"
	}
	
	msg = document.getElementById("msgToAdd");
	msg.innerHTML = doc
	
	
	if(o.style) {
		o.style.display = ''
		o.style.backgroundColor = '';
	} else {
		o.visibility = "show"
	}
}

msgWriter.hide = function(){
	o = document.getElementById("komunikat")
	
	if(o.style) {
		o.style.display = 'none'
	} else {
		o.visibility = "hide"
	}
}

if(typeof frmOrder  == "undefined") frmOrder = new Object()
frmOrder.isValid = function(){
	msgWriter.clear();
	
	f=document.forms['cart'];
	
	done = false;
	for(i=0; i<3; i++)
		if(f.sposob_platnosci[i].checked){ done = true; break; }
	
	if(done == false){
		msgWriter.add('wybierz sposób płatności');
		msgWriter.show();
	} else {
		 msgWriter.hide();
	}
	
	return done;
}


if(typeof frmChangePass  == "undefined") frmChangePass = new Object()
frmChangePass.isValid = function(){
	msgWriter.clear()
	f = document.getElementById('FromChangePass')
	
	errNo = 0;
	var re = /^([\w\-])+(\.([\w\-])+)*@((\[(((([0-1])?([0-9])?[0-9])|(2[0-4][0-9])|(2[0-5][0-5])))\.(((([0-1])?([0-9])?[0-9])|(2[0-4][0-9])|(2[0-5][0-5])))\.(((([0-1])?([0-9])?[0-9])|(2[0-4][0-9])|(2[0-5][0-5])))\.(((([0-1])?([0-9])?[0-9])|(2[0-4][0-9])|(2[0-5][0-5]))\]))|((([a-zA-Z0-9])+(([\-])+([a-zA-Z0-9])+)*\.)+([a-zA-Z])+(([\-])+([a-zA-Z0-9])+)*))$/
	
	if(f.email.value.match(re) == null) 
 	{
		 f.email.style.backgroundColor = "#FFEF7A"
		 msgWriter.add('wpisz adres email podany przy rejestracji')
		 errNo++
	}else{
		f.email.style.backgroundColor = "#FFFFFF"
	}
	
	if(errNo != 0) msgWriter.show(); else msgWriter.hide();
	if(errNo == 0) return true;
	
	return false;
}

if(typeof frmRegister  == "undefined") frmRegister = new Object()
frmRegister.isValid = function(checkpass){
	msgWriter.clear()
	f = document.getElementById('FromRegisterUser')
		
	// ustalenie wartosci standardowych kolorow inputow
	if(typeof f.login != "undefined") f.login.style.backgroundColor = "#f4eed4"
	f.pass.style.backgroundColor = "#f4eed4"
	f.pass2.style.backgroundColor = "#f4eed4"
	f.email.style.backgroundColor = "#f4eed4"
	f.imie_nazwisko.style.backgroundColor = "#f4eed4"
	f.ulica.style.backgroundColor = "#f4eed4"
	f.kod.style.backgroundColor = "#f4eed4"
	f.miejscowosc.style.backgroundColor = "#f4eed4"
	f.telefon.style.backgroundColor = "#f4eed4"
	
	errNo = 0;
	
	if(checkpass && f.login.value.length < 3){ 
		f.login.style.backgroundColor = "#FFEF7A"
		msgWriter.add('login powinien mieć więcej niż 3 znaki')
		errNo++
	}
	
	if((checkpass || f.pass.value.length > 0) && f.pass.value.length < 4){
		 msgWriter.add('hasło powinno posiadać więcej niż 4 znaki')
		 f.pass.style.backgroundColor = "#FFEF7A"
		 errNo++
	}
	
	if((checkpass || f.pass.value.length > 0) && f.pass2.value != f.pass.value){
		 msgWriter.add('wpisane hasła są różne')
		 f.pass2.style.backgroundColor = "#FFEF7A"
		 errNo++
	}
	
    var re = /^([\w\-])+(\.([\w\-])+)*@((\[(((([0-1])?([0-9])?[0-9])|(2[0-4][0-9])|(2[0-5][0-5])))\.(((([0-1])?([0-9])?[0-9])|(2[0-4][0-9])|(2[0-5][0-5])))\.(((([0-1])?([0-9])?[0-9])|(2[0-4][0-9])|(2[0-5][0-5])))\.(((([0-1])?([0-9])?[0-9])|(2[0-4][0-9])|(2[0-5][0-5]))\]))|((([a-zA-Z0-9])+(([\-])+([a-zA-Z0-9])+)*\.)+([a-zA-Z])+(([\-])+([a-zA-Z0-9])+)*))$/	
	
	if(f.email.value.match(re) == null) 
 	{
		 msgWriter.add('wpisany adres e-mail jest niepoprawny')
		 f.email.style.backgroundColor = "#FFEF7A"
		 errNo++
	}
	
	if(f.imie_nazwisko.value.length == 0){
		 msgWriter.add('wpisz dane w pole imię i nazwisko lub nazwa firmy')
		 f.imie_nazwisko.style.backgroundColor = "#FFEF7A"
		 errNo++
	}
	
	if(f.ulica.value.length == 0){
		 msgWriter.add('wpisz dane w pole ulica i nr domu')
		 f.ulica.style.backgroundColor = "#FFEF7A"
		 errNo++
	}
	
	if(f.kod.value.length == 0){
		 msgWriter.add('wpisz poprawny kod pocztowy')
		 f.kod.style.backgroundColor = "#FFEF7A"
		 errNo++
	}
	
	if(f.miejscowosc.value.length == 0){
		 msgWriter.add('wpisz poprawną miejscowość')
		 f.miejscowosc.style.backgroundColor = "#FFEF7A"
		 errNo++
	}
	
	if(f.telefon.value.length == 0){
		 msgWriter.add('wpisz poprawny numer telefonu stacjonarnego')
		 f.telefon.style.backgroundColor = "#FFEF7A"
		 errNo++
	}
	
	if(errNo != 0) msgWriter.show(); else msgWriter.hide();
	if(errNo == 0) return true;
	
	return false;
}

// Radio Button Validation
// copyright Stephen Chapman, 15th Nov 2004,14th Sep 2005
// you may copy this function but please keep the copyright notice with it

function valButton(btn) {
var cnt = -1;
for (var i=btn.length-1; i > -1; i--) {
   if (btn[i].checked) {cnt = i; i = -1;}
   }
if (cnt > -1) return btn[cnt].value;
else return null;
}

if(typeof frmSurveyRegister  == "undefined") frmSurveyRegister = new Object()
frmSurveyRegister.isValid = function(){

	msgWriter.clear()
	f = document.getElementById('FormSurvey');
	// ustalenie wartosci standardowych kolorow inputow
	
	document.getElementById('ulkontakt').style.backgroundColor = "#FFFFFF"
	document.getElementById('ulceny').style.backgroundColor = "#FFFFFF"
	document.getElementById('ulterminy').style.backgroundColor = "#FFFFFF"
	document.getElementById('uljakosc').style.backgroundColor = "#FFFFFF"
	document.getElementById('ulczytelnosc').style.backgroundColor = "#FFFFFF"
	document.getElementById('ulgwarancja').style.backgroundColor = "#FFFFFF"
	document.getElementById('ulzrodla').style.backgroundColor = "#FFFFFF"
	document.getElementById('ulzainteresowani').style.backgroundColor = "#FFFFFF"
	document.getElementById('ulprodukty').style.backgroundColor = "#FFFFFF"
	document.getElementById('ulskad').style.backgroundColor = "#FFFFFF"
	document.getElementById('ulznana').style.backgroundColor = "#FFFFFF"
	
	errNo=0
	
	
	
	
	if (!valButton(f.zadowoleni_kontakt)) {errNo++; msgWriter.add('kontakt z działem handlowym'); 
	  document.getElementById('ulkontakt').style.backgroundColor="#FFEF7A"; }
	  
	if (!valButton(f.zadowoleni_ceny)) {errNo++; msgWriter.add('oferta cenowa');
	  document.getElementById('ulceny').style.backgroundColor="#FFEF7A";}
	  
	if (!valButton(f.zadowoleni_terminy)) {errNo++; msgWriter.add('terminy realizacji');
  	  document.getElementById('ulterminy').style.backgroundColor="#FFEF7A";}
	
	if (!valButton(f.zadowoleni_jakosc)) {errNo++; msgWriter.add('jakość wyrobów');
  	  document.getElementById('uljakosc').style.backgroundColor="#FFEF7A";}
	
	if (!valButton(f.zadowoleni_czytelnosc)) {errNo++; msgWriter.add('czytelność instrukcji');
	  document.getElementById('ulczytelnosc').style.backgroundColor="#FFEF7A";}		
	  	
	if (!valButton(f.zadowoleni_gwarancja)) {errNo++; msgWriter.add('gwarancja');
	  document.getElementById('ulgwarancja').style.backgroundColor="#FFEF7A";}
	  
	if (!valButton(f.zrodla_wyboru)) {errNo++; msgWriter.add('źródła wyboru');
	  document.getElementById('ulzrodla').style.backgroundColor="#FFEF7A";}
    			
    if (!valButton(f.zainteresowani)) {errNo++; msgWriter.add('zainteresowanie');
      document.getElementById('ulzainteresowani').style.backgroundColor="#FFEF7A";}
    
    if (!valButton(f.nowe_produkty)) {errNo++; msgWriter.add('nowe produkty');
      document.getElementById('ulprodukty').style.backgroundColor="#FFEF7A";}		
	
	if (f.skad_prasa.checked==false&&f.skad_reklama.checked==false&&
	f.skad_targi.checked==false&&f.skad_internet.checked==false&&
	f.skad_od_innych.checked==false&&f.skad_inne.checked==false) 
	  {errNo++; msgWriter.add('skąd');
      document.getElementById('ulskad').style.backgroundColor="#FFEF7A";}	 
	
	if (f.znana_przyczep.checked==false&&f.znana_agd.checked==false&&
	f.znana_produkcja.checked==false&&f.znana_bron.checked==false) 
	  {errNo++; msgWriter.add('znajomość grup produktów');
      document.getElementById('ulznana').style.backgroundColor="#FFEF7A";}
	 
	if(errNo != 0) {msgWriter.show();} else {msgWriter.hide()};
	if(errNo == 0) {document.FormSurvey.submit()};
	
	return false;
	
}