function orderformtest () {
	var person = document.getElementById ('person');
	var phone = document.getElementById ('phone');
	var mail = document.getElementById ('mail');
	var site = document.getElementById ('site');
	var data = document.getElementById ('data');
	var subm = document.getElementById ('submit');
	if (person && phone && mail && site && data && subm) {
		var emailreg = new RegExp('^[a-z0-9\._-]+@[a-z0-9][a-z0-9_-]*(\.[a-z0-9_-]+)*'+'[\.]{1}([a-z]{2}|aero|arpa|biz|com|coop|edu|gov|info|'+'int|mil|museum|name|net|org|pro|travel)$', 'i');
		subm.disabled = !person.value || !phone.value || !mail.value || !site.value || !data.value || !emailreg.test(mail.value);
	}
}

function changefilenames(node){
	var begin=node;
	var par=begin.parentNode;
	var name=begin.firstChild.firstChild.name;
	name = name.substring(4, name.length);
	var num=parseInt(name)-1;
	do {
		num=num+1;
		begin=begin.nextSibling;
		begin.firstChild.firstChild.name = 'file'+num;
		begin.firstChild.firstChild.id = 'file'+num;
	}
	while (begin != par.lastChild);
}


function dropfile(btn){
	var active=btn;
	active=active.parentNode.parentNode;
	var par=active.parentNode;
	if (par.firstChild != par.lastChild){
		if (active == par.firstChild) {
			if (par.lastChild == active.nextSibling){
				active.nextSibling.lastChild.removeChild(active.nextSibling.lastChild.lastChild);
			}
		}
		else {
			if (active == par.lastChild) {
				if (par.firstChild == active.previousSibling){
					active.previousSibling.lastChild.removeChild(active.previousSibling.lastChild.lastChild);
				}
			}
		}
		if (active != par.lastChild){
			changefilenames(active);
		}
		par.removeChild(active);
	}
}

function addfile(){
	if(document.getElementById('file')){
		var par=document.getElementById('file').firstChild;
		var template=document.createElement('tr');
		var number=par.lastChild.firstChild.firstChild.name;
		number = number.substring(4, number.length);
		var str=parseInt(number)+1;
		if (par.firstChild == par.lastChild){
			par.firstChild.lastChild.innerHTML = "<a class=\"none\" onClick=\"addfile(); return false;\" href=\"#\" title=\"Добавить поле\">+</a><a onClick=\"dropfile(this); return false;\" href=\"#\" title=\"Удалить поле\">\&minus;</a>";
		}
		par.appendChild(template);
		var td1=document.createElement('td');
		td1.className = "filetd";
		td1.innerHTML = "<input type=\"file\" id=\"file"+str+"\" name=\"file"+str+"\" />";
		var td2=document.createElement('td');
		td2.className='control';
		td2.innerHTML = "<a onClick=\"addfile(); return false;\" href=\"#\" title=\"Добавить поле\">+</a><a onClick=\"dropfile(this); return false;\" href=\"#\" title=\"Удалить поле\">\&minus;</a>";
		template.appendChild(td1);
		template.appendChild(td2);
	}
}
