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 dbfromValid(f) {
	
	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 == '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' && t.type == 'foto'  && i.value == '' && document.getElementById('__http__dbformF'+t.field).value != '' ) {
				al.innerHTML = ''; //t.info;
				if  (i.parentNode.parentNode.className == 'alertRow') i.parentNode.parentNode.className = 'formRow';	
			}
			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)) {
				//alert (t.field);
				al.innerHTML = t.alert2; //t.js + ':' + eval(t.js); ;
				i.focus(); 
				i.parentNode.parentNode.className = 'alertRow';
				return false;		
			}
			else {
				al.innerHTML = ''; //t.info;
				if  (i.parentNode.parentNode.className == 'alertRow') i.parentNode.parentNode.className = 'formRow';	
			}
		}
		
	}
	if (document.getElementById('alertmsg') && document.getElementById('alertwin')) {
		document.getElementById('alertmsg').innerHTML = 'Trwa wysyłanie formularza...';
		document.getElementById('alertwin').style.display = 'block';
		//alert(document.body.scrollTop);
		if (document.documentElement.scrollTop) document.getElementById('alertwin').style.top = (document.documentElement.scrollTop + 200) + 'px'; 
		else document.getElementById('alertwin').style.top = (document.body.scrollTop + 200) + 'px';
		
	}
	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)
}