function showFields(opt) {
	argv = showFields.arguments;
	a = 1;
	while (argv[a]) {
		if (document.getElementById('dbformF'+argv[a])) {
			tr = document.getElementById('dbformF'+argv[a]).parentNode;
			while (tr.tagName.toUpperCase() != 'TR') tr = tr.parentNode;
//			tr.style.display = (opt)?'':'none';
//			alert(tr.className);
			tr.className = (opt)?'formRow':'hidden';
		
		}
			++a;
	}
	footReset();	
}

function footReset() {
	f = document.getElementById('footer').style.position="relative";
	f = document.getElementById('footer').style.position="absolute";
}

function clearField(f,p,t) {

	var fnazwa = document.getElementById('dbformFA@nazwa');
	var opis = document.getElementById('dbformFA@opis_krotki');
	var fkod = document.getElementById('dbformFA@kod');
	var tytogl = document.getElementById('dbformFA@tytul');
	var togl = document.getElementById('dbformFA@tresc');
	var nazwa = document.getElementById('dbformFR@nazwa');
	var termin = document.getElementById('dbformFA@termin::min');
	var nazwaszk = document.getElementById('dbformFA@nazwa_szkolenia');

	try {
	if ((fnazwa.value == f) && (opis.value == p) && (fkod.value == t)) {
		fnazwa.value = '';
		opis.value = '';
		fkod.value = ''; }
	} catch(e){}
	
	try {
	if ((fnazwa.value == f) && (opis.value == p)) {
		fnazwa.value = '';
		opis.value = ''; }
	} catch(e){}

	try {
	if ((fnazwa.value == f) && (fkod.value == t)) {
		fnazwa.value = '';
		fkod.value = ''; }
	} catch(e){}

	try {
	if ((opis.value == p) && (fkod.value == t)) {
		opis.value = '';
		fkod.value = ''; }
	} catch(e){}

	try {
	if (fnazwa.value == f)  {
		fnazwa.value = ''; }
	} catch(e){}

	try {
	if (opis.value == p)  {
		opis.value = ''; }
	} catch(e){}	

	try {
	if (fkod.value == t)  {
		fkod.value = ''; }
	} catch(e){}
	
	try {
	if ((fnazwa.value == f) && (opis.value == p) && (nazwa.value == t)) {
		fnazwa.value = '';
		opis.value = '';
		nazwa.value = ''; }
	} catch(e){}

	try {
	if ((fnazwa.value == f) && (opis.value == p)) {
		fnazwa.value = '';
		opis.value = ''; }
	} catch(e){}

	try {
	if ((fnazwa.value == f) && (nazwa.value == t)) {
		fnazwa.value = '';
		nazwa.value = ''; }
	} catch(e){}

	try {
	if ((opis.value == p) && (nazwa.value == t)) {
		opis.value = '';
		nazwa.value = ''; }
	} catch(e){}

	try {
	if (fnazwa.value == f) {
		fnazwa.value = ''; }
	} catch(e){}

	try {
	if (opis.value == p) {
		opis.value = ''; }
	} catch(e){}

	try {
	if (nazwa.value == t) {
		nazwa.value = ''; }
	} catch(e){}

	try {
	if ((tytogl.value == f) && (togl.value == p)) {
		tytogl.value = '';
		togl.value = ''; }
	} catch(e){}
	
	try {
	if (tytogl.value == f) {
		tytogl.value = ''; }
	} catch(e){}

	try {
	if (togl.value == p) {
		togl.value = ''; }
	} catch(e){}

	try {
	if ((nazwa.value == f) && (nazwaszk.value == p) && (termin.value == t)) {
		nazwa.value = '';
		nazwaszk.value = '';
		termin.value = ''; }
	} catch(e){}

	try {
	if ((nazwa.value == f) && (nazwaszk.value == p)) {
		nazwa.value = '';
		nazwaszk.value = ''; }
	} catch(e){}
	
	try {
	if ((nazwa.value == f) && (termin.value == t)) {
		nazwa.value = '';
		termin.value = ''; }
	} catch(e){}

	try {
	if ((nazwaszk.value == p) && (termin.value == t)) {
		nazwaszk.value = '';
		termin.value = ''; }
	} catch(e){}

	try {
	if (nazwa.value == f) {
		nazwa.value = ''; }
	} catch(e){}

	try {
	if (termin.value == t) {
		termin.value = ''; }
	} catch(e){}
 
	try {
	if (nazwaszk.value == p) {
		nazwaszk.value = ''; }
	} catch(e){}
}

function authValid(v,m,b) {

	var l = document.getElementById('loginEmail');
	var r = document.getElementById('loginInfo');
	var p = document.getElementById('loginPass');

	try{
	if (l.value.indexOf('@',0) == -1 || l.value.indexOf('.',0) == -1){
		r.innerHTML = m;
		l.focus();
		l.parentNode.parentNode.className = 'alertRow';
		return false;
	}
	}catch(e){}

	try{
	if (p.value == ''){
		r.innerHTML = b;
		p.focus();
		p.parentNode.parentNode.className = 'alertRow';
		return false;
	}
	}catch(e){}
}

function authValidLogin(v,m,b) {

	var l = document.getElementById('emailLogin');
	var r = document.getElementById('infoLogin');
	var p = document.getElementById('passLogin');

	try{
	if (l.value.indexOf('@',0) == -1 || l.value.indexOf('.',0) == -1){
		r.innerHTML = m;
		l.focus();
		l.parentNode.parentNode.className = 'alertRow';
		return false;
	}
	}catch(e){}

	try{
	if (p.value == ''){
		r.innerHTML = b;
		p.focus();
		p.parentNode.parentNode.className = 'alertRow';
		return false;
	}
	}catch(e){}
}

function emailValid(t,g) {
	
	var mail = document.getElementById('newsEmailF');
	var er = document.getElementById('newsEmailI');
	
	try{
	if (mail.value.indexOf('@',0) == -1 || mail.value.indexOf('.',0) == -1){
		er.innerHTML = g;
		mail.focus(); 
		mail.parentNode.parentNode.className = 'alertRow';
		return false;
	}
	}catch(e){}
}

function emailPassValid(t,g) {
	
	var email = document.getElementById('emailF');
	var eror = document.getElementById('emailI');
	
	try{
	if (email.value.indexOf('@',0) == -1 || email.value.indexOf('.',0) == -1){
		eror.innerHTML = g;
		email.focus(); 
		email.parentNode.parentNode.className = 'alertRow';
		return false;
	}
	}catch(e){}
}

function dbfromValid(f) {
	
	var m = document.getElementById('dbformF'+mmm);
	var tr = document.getElementById('dbformI'+mmm);

	try{
	if (m.value.indexOf('@',0) == -1 || m.value.indexOf('.',0) == -1){
     		tr.innerHTML = '"Nieprawidłowy email"';
		m.focus(); 
		m.parentNode.parentNode.className = 'alertRow';
		return false;
	}
	}
	catch(e){}

	for (a = 0; a < dbformFields.length; ++a) {
		t = dbformFields[a];
		//alert (t.req);
		if (t.req == '1' || t.js != '') {
			i = document.getElementById('dbformF'+t.field);
			al = document.getElementById('dbformI'+t.field);
		
			if (t.req == '1' && t.type == 'checkbox' && document.getElementById('dbformFprywatnosc').checked == false){
			document.getElementById('dbformIprywatnosc').innerHTML = '"Zaakceptuj politykę prywatności"';
			document.getElementById('dbformFprywatnosc').focus(); 
			document.getElementById('dbformFprywatnosc').parentNode.parentNode.className = 'alertRow';
			return false;
			}

			if (t.req == '1' && t.type == 'checkboxes') {
				cl = 1;
				tf = 0;
				while (ic = document.getElementById('dbformF'+t.field+cl)) {
					tf += ic.checked?1:0;
					++cl; 
				}
				if (tf == 0) { 
					i.parentNode.parentNode.className = 'alertRow';
					al.innerHTML = t.alert1;
					return false;
				}
				else {
					i.parentNode.parentNode.className = 'formRow';
					al.innerHTML = '';
				}	
			}
			else if (t.req  == '1' && i.tagName.toUpperCase() == "SELECT" && i.selectedIndex == 0) {
				al.innerHTML = t.alert1;
				i.focus(); 
				i.parentNode.parentNode.className = 'alertRow';
				return false;
				
			}
			else if (t.req == '1' && i.tagName.toUpperCase() != "SELECT" && i.value == '') {
				al.innerHTML = t.alert1;
				i.focus(); 
				i.parentNode.parentNode.className = 'alertRow';
				return false;
			}
			else if (t.js != '' && !eval(t.js)) {
			   try{
				al.innerHTML = t.alert2; //t.js + ':' + eval(t.js); ;
				i.focus(); 
				i.parentNode.parentNode.className = 'alertRow';
				return false;		
			   }
			catch(e){}

			}
			else {
				al.innerHTML = ''; //t.info;
				if  (i.parentNode.parentNode.className == 'alertRow') i.parentNode.parentNode.className = 'formRow';	
			}
		}

	}
	return true;
}

function addTLine(tableID) {
	//trs = document.getElementById(slineID);
	tbl = document.getElementById(tableID).firstChild;
	dupli = false;
	kids = tbl.childNodes;
	//alert(kids.length+kids[0].tagName);
 	for (var i = 0; i < kids.length; i++) {
		t = kids[i].tagName;
		//alert(t+':'+kids[i].id);
		if (t == 'TR' && dupli && kids[i].className == 'eline') {
			frename(dupli);
			dupli.style.display = '';
			tbl.insertBefore(dupli,kids[i]);
			break;		
		}

 		if (t == 'TR') {
			dupli = kids[i].cloneNode(true); 
		}
		
		
	}
	//reLp(tableID);
	void(0);
}
function delrow(timg,ob) {
	timg.parentNode.firstChild.value = 1;
	timg.parentNode.parentNode.style.display = 'none';
	timg.parentNode.parentNode.firstChild.innerHTML = '1;';
	reLp(ob);
	void(0);
}

function frename(ob) {
	var d = ob.childNodes;
	//alert (d.length);
	for (var i = 0; i < d.length; i++) {
		//alert (i + d[i].tagName);
		if (d[i].nodeType == 3) continue;
		

		if (d[i].tagName == 'TD' && d[i].innerHTML.match(/\d+[:;]/)) {
			no = d[i].innerHTML.match(/\d+[:;]/);
			no = parseInt(no) + 1;
			d[i].innerHTML = no+':';
		}
		if (d[i].tagName == 'INPUT') {
			no = d[i].name.match(/\d+/);
			no = parseInt(no) + 1;
			d[i].name = d[i].name.replace(/\[\d+\]/,'['+no+']');
			d[i].id = d[i].id.replace(/\d+$/,no);
			d[i].value = '';
		}
		else if (d[i].tagName == 'SELECT') {
			no = d[i].name.match(/\d+/);
			no = parseInt(no) + 1;
			d[i].name = d[i].name.replace(/\[\d+\]/,'['+no+']');
			d[i].id = d[i].id.replace(/\d+$/,no);
			d[i].selectedIndex = 0;
			d[i].onfocus = function () {}
			d[i].onchange = function () {}
		}
		else if (d[i].firstChild) frename(d[i]);
	}
}

function testCheckboxes(f) { 
				cl = 1;
				tf = 0;
				while (ic = document.getElementById('dbformF'+f+cl)) {
					tf += ic.checked?1:0;
					++cl; 
				}
				return tf;
}

function dbfield(a) {
	return document.getElementById('form')[a];
}


function ismaxlength(obj){
var mlength=obj.getAttribute? parseInt(obj.getAttribute("maxlength")) : ""
if (obj.getAttribute && obj.value.length>mlength)
obj.value=obj.value.substring(0,mlength)
}

