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("komunikat")
	
	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 wma == "undefined") wma = new Object()
if(typeof wma.valid == "undefined") wma.valid = new Object()

wma.valid.invalidMail = function(s){
	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])+)*))$/
	str = new String(s.value)
	return str.match(re)== null
}

wma.valid.isNull = function(o){
	return o.value.length == 0
}

wma.valid.isSelected = function(o){
	if(typeof o == "undefined" || o.selectedIndex == 0) return true
	return false 
}

frmSendForm = new Object()
frmSendForm.errNo = 0
frmSendForm.addIfNotValid = function(o, f, errMsg){
	if(f(o)){
		msgWriter.add(errMsg);
		if (typeof o != "undefined")
			o.style.backgroundColor = "#FFD3D3"
		this.errNo++
	}
}

frmSendForm.isValid = function(){
	msgWriter.clear()
	f = document.forms['frm_zam']
		
	// ustalenie wartosci standardowych kolorow inputow
	
	f.ulica.style.backgroundColor = "#ffffff"
	f.miasto.style.backgroundColor = "#ffffff"
	f.ilosc.style.backgroundColor = "#ffffff"
	f.przeznaczenie.style.backgroundColor = "#ffffff"
	f.kod.style.backgroundColor = "#ffffff"
	f.telefon.style.backgroundColor = "#ffffff"
	f.email1.style.backgroundColor = "#ffffff"
	f.imie_nazwisko.style.backgroundColor = "#ffffff"
	f.email2.style.backgroundColor = "#ffffff"
	f.telefon_kontaktowy.style.backgroundColor = "#ffffff"
	

	this.errNo = 0;

	this.addIfNotValid(f.ilosc, wma.valid.isNull, "ilość");
	this.addIfNotValid(f.przeznaczenie, wma.valid.isNull, "przeznaczenie");
	
	this.addIfNotValid(f.ulica, wma.valid.isNull, "dane teleadresowe: ulica i numer domu")
	this.addIfNotValid(f.miasto, wma.valid.isNull, "dane teleadresowe: miasto")
	this.addIfNotValid(f.kod, wma.valid.isNull, "dane teleadresowe: kod pocztowy")
	this.addIfNotValid(f.telefon, wma.valid.isNull, "dane teleadresowe: telefon");
	this.addIfNotValid(f.email1, wma.valid.invalidMail, "dane teleadresowe: email");
	
	this.addIfNotValid(f.imie_nazwisko, wma.valid.isNull, "osoba kontaktowa: imie nazwisko")
	this.addIfNotValid(f.telefon_kontaktowy, wma.valid.isNull, "osoba kontaktowa: telefon kontaktowy");
	this.addIfNotValid(f.email2, wma.valid.invalidMail, "osoba kontaktowa: email");
	
	if(this.errNo != 0) msgWriter.show(); else msgWriter.hide();
	if(this.errNo == 0) return true;
	
	return false;
}


frmAuctions = new Object()
frmAuctions.errNo = 0
frmAuctions.addIfNotValid = function(o, f, errMsg){
	if(f(o)){
		msgWriter.add(errMsg);
		if (typeof o != "undefined")
			o.style.backgroundColor = "#FFD3D3"
		this.errNo++
	}
}

frmAuctions.isValid = function(){
	msgWriter.clear()
	f = document.forms['frm_auctions']
		
	// ustalenie wartosci standardowych kolorow inputow
	
	f.nazwa_urzedu.style.backgroundColor = "#ffffff"
	f.ulica.style.backgroundColor = "#ffffff"
	f.www.style.backgroundColor = "#ffffff"
	f.kod.style.backgroundColor = "#ffffff"
	f.miasto.style.backgroundColor = "#ffffff"
	f.charakterystyka_przetargu.style.backgroundColor = "#ffffff"
	f.termin_skladania.style.backgroundColor = "#ffffff"
	f.wartosc_przetargu.style.backgroundColor = "#ffffff"
	f.telefon_kontaktowy.style.backgroundColor = "#ffffff"
	

	this.errNo = 0;

	this.addIfNotValid(f.nazwa_urzedu, wma.valid.isNull, "nazwa urzędu")
	this.addIfNotValid(f.ulica, wma.valid.isNull, "dane teleadresowe: ulica")
	this.addIfNotValid(f.www, wma.valid.isNull, "www")
	this.addIfNotValid(f.kod, wma.valid.isNull, "dane teleadresowe: kod");
	this.addIfNotValid(f.miasto, wma.valid.isNull, "dane teleadresowe: miasto");
	
	
	this.addIfNotValid(f.charakterystyka_przetargu, wma.valid.isNull, "charakterystyka przetargu")
	this.addIfNotValid(f.wartosc_przetargu, wma.valid.isNull, "wartość przetargu");
	this.addIfNotValid(f.telefon_kontaktowy, wma.valid.isNull, "telefon kontaktowy");
	this.addIfNotValid(f.termin_skladania, wma.valid.isNull, "termin składania ofert");
	
	if(this.errNo != 0) msgWriter.show(); else msgWriter.hide();
	if(this.errNo == 0) return true;
	
	return false;
}
