/*
version = '0014 2014-04-02'
*/
timgoff = new Array();
timgon = new Array();
timghover = new Array();
var TG_site_lang = 'ru';	// текущий язык сайта
var TG_curid;				// id текущей страницы
var TG_jmid;				// id текущего модуля jm

var w3cDOM = (typeof document.getElementById != "undefined" && typeof document.createElement != "undefined") ? true : false;
var initjs = function() {};

//добавляет атрибуты data-useragent и data-platform к тегу html, и класс touch к touch-устройствам
//использование (вызов в head):
//setNavigator();
//в css:
//html[data-useragent*='Chrome/13.0'] ...
//html[data-platform='iPad'] ...
function setNavigator()
{
	var b = document.documentElement;
	b.setAttribute('data-useragent', navigator.userAgent);
	b.setAttribute('data-platform', navigator.platform );
	b.className += ((!!('ontouchstart' in window) || !!('onmsgesturechange' in window))?' touch':'');
}

function listenEvent(target, type, listener)
{
	if( target==window && type=='load' )
	{
		var tmp = initjs;
		initjs = function() {tmp(); listener();};
	}
	else if (typeof target.addEventListener != "undefined")
	{
		target.addEventListener (type, listener, false);
	}
	else if (typeof target.attachEvent != "undefined")
	{
		target.attachEvent ("on" + type, listener);
	}
}

function hideall()
{
	var divs = document.getElementsByTagName("div");
	if(divs)
		for(j=0;j<divs.length;++j)
			if(divs[j].id && divs[j].id.substring(0,7)=='submenu')
				divs[j].style.visibility = 'hidden';
	for(k=0;k<timgoff.length;++k)
		if(timgoff[k]) document.images['timg' + k].src = timgoff[k].src;
}

function tshow(i)
{
	obj = document.getElementById('submenu'+i);
	if(obj) obj.style.visibility = 'visible';

	// 02.03.2006
	if(obj) obj.style.display = 'block';

	if(timghover[i]) document.images['timg' + i].src = timghover[i].src;
	else if(timgon[i]) document.images['timg' + i].src = timgon[i].src;

	var divs = document.getElementsByTagName("div");
	if(divs)
		for(j=0;j<divs.length;++j)
			if(divs[j].id && divs[j] != obj && divs[j].id.substring(0,7)=='submenu')
				divs[j].style.visibility = 'hidden';
}

function thide(i)
{
	obj = document.getElementById('submenu'+i);
	if(obj) obj.style.visibility = 'hidden';
	if(obj) obj.style.display = 'none';
	if(timgoff[i]) document.images['timg' + i].src = timgoff[i].src;
}

function openwin(url)
{
	var OpenWin;
	OpenWin=window.open(url);
	OpenWin.focus();
}

function showhelp(key)
{
	showsmallwin('http://www.graphit.ru/help?help=' + key,'help',10980,10780,1,'resizable=yes');
	return false;
}

function showsmallwin(url,winname,wid,hei,winclose,winresize)
{
	var SmallWin;
	var w = screen.width;
	var h = screen.height;
	var scroll;
	if(wid > 10000 && hei > 10000)
	{
		wid = wid-10000; hei = hei-10000;
		scroll = 'scrollbars=yes';
	}
	else if (w < wid)
	{
		wid = w;
		scroll = 'scrollbars=yes';
	}
	else if (h < hei)
	{
		hei = h;
		scroll = 'scrollbars=yes';
	}
	else if (wid==0 && hei==0)
	{
		scroll = 'scrollbars=yes';
	}
	else
		scroll = 'scrollbars=no';
	url = url.replace(/`/g,"'");
	SmallWin=window.open(url,winname,'toolbar=no,directories=no,status=no,'+scroll+','+winresize+',menubar=no,width='+wid+',height='+hei);
	SmallWin.focus();
}

var ImageWin;
function showimage(url,wid,hei)
{
	ImageWin=window.open('','imagewin','scrollbars=no,toolbar=no,directories=no,location=no,status=no,0,resizable=no,copyhistory=no,menubar=no,width='+wid+',height='+hei+',top=50,left=50');
	ImageWin.document.clear();
	ImageWin.resizeTo(wid+10,hei+60);
	ImageWin.document.write("<html>");
	var title = url.replace('/_data/objects/','');
	ImageWin.document.write("<head><title>"+title+"</title></head>");
	ImageWin.document.write("<body style='margin-left:0px; margin-right:0px; margin-top:0px; margin-bottom:0px; top:0; left:0; padding:0; border-width:0;'>");
	ImageWin.document.write("<img src='"+url+"' width="+wid+" height="+hei+">");
	ImageWin.document.write("</body>");
	ImageWin.document.write("</html>");
	ImageWin.document.close();
	ImageWin.focus();
}

var ImageWin2;
function showimage2(url,wid,hei,header)
{
	ImageWin2=window.open('','imagewin2','toolbar=no,directories=no,location=no,status=no,0,resizable=no,copyhistory=no,menubar=no,width='+wid+',height='+hei+',top=50,left=50');
	ImageWin2.document.clear();
	ImageWin2.resizeTo(wid+10,hei+60);
	ImageWin2.document.write("<html>");
	ImageWin2.document.write("<head><title>"+header+"</title></head>");
	ImageWin2.document.write("<body style='margin-left:0px; margin-right:0px; margin-top:0px; margin-bottom:0px; top:0; left:0; padding:0; border-width:0;'>");
	ImageWin2.document.write("<img src='"+url+"' width="+wid+" height="+hei+">");
	ImageWin2.document.write("</body>");
	ImageWin2.document.write("</html>");
	ImageWin2.document.close();
	ImageWin2.focus();
}

var ImageWin3;
function showimage3(url,wid,hei,header)
{
	ImageWin3=window.open('','imagewin3','toolbar=no,directories=no,location=no,status=no,0,resizable=no,copyhistory=no,menubar=no,width='+wid+',height='+hei+',top=50,left=50');
	ImageWin3.document.clear();
	ImageWin3.resizeTo(wid+10,hei+67);
	ImageWin3.document.write("<html>");
	ImageWin3.document.write("<head><title>"+header+"..</title></head>");
	ImageWin3.document.write("<body style='margin-left:0px; margin-right:0px; margin-top:0px; margin-bottom:0px; top:0; left:0; padding:0; border-width:0;'>");
	ImageWin3.document.write("<img src='"+url+"' width='"+wid+"' height='"+hei+"' border='0' alt='close'>");
	ImageWin3.document.write("<p align='center'><a href='javascript:window.close()'><b>Close</b></a></p>");
	ImageWin3.document.write("</body>");
	ImageWin3.document.write("</html>");
	ImageWin3.document.close();
	ImageWin3.focus();
}

var ImageWin4;
function showimage4(url,wid,hei,winwid,winhei)
{
	ImageWin4=window.open('','imagewin','scrollbars=no,toolbar=no,directories=no,location=no,status=no,0,resizable=no,copyhistory=no,menubar=no,width='+wid+',height='+hei+',top=50,left=50');
	ImageWin4.document.clear();
	ImageWin4.resizeTo(winwid,winhei);
	ImageWin4.document.write("<html>");
	ImageWin4.document.write("<body style='margin-left:0px; margin-right:0px; margin-top:0px; margin-bottom:0px; top:0; left:0; padding:0; border-width:0;'>");
	ImageWin4.document.write("<table width='100%' height='100%' cellspacing='0' cellpadding='0' border='0'><tr><td align='center'>");
	ImageWin4.document.write("<img src='"+url+"' width="+wid+" height="+hei+">");
	ImageWin4.document.write("</td></tr></table>");
	ImageWin4.document.write("</body>");
	ImageWin4.document.write("</html>");
	ImageWin4.document.close();
	ImageWin4.focus();
}


var ImageW = new Array();
function showimage1(url,wid,hei,header,win)
{
	if(!header) header = '';
	if(!win) win = 0;
	ImageW[win]=window.open('','imagewin'+win,'toolbar=no,directories=no,location=no,status=no,0,resizable=no,copyhistory=no,menubar=no,width='+wid+',height='+hei+',top=50,left=50');
	ImageW[win].document.clear();
	ImageW[win].resizeTo(wid+10,hei+60);
	ImageW[win].document.write("<html>");
	ImageW[win].document.write("<head><title>"+header+"</title></head>");
	ImageW[win].document.write("<body style='margin-left:0px; margin-right:0px; margin-top:0px; margin-bottom:0px; top:0; left:0; padding:0; border-width:0;'>");
	ImageW[win].document.write("<img src='"+url+"' width="+wid+" height="+hei+">");
	ImageW[win].document.write("</body>");
	ImageW[win].document.write("</html>");
	ImageW[win].document.close();
	ImageW[win].focus();
}



function trim(str)
{
  return( (""+str).replace(/^\s*([\s\S]*\S+)\s*$|^\s*$/,'$1') );
}

function formcheck(form)
{
	var checktag = new Array('input','textarea','select','radio');
	var text1 = new Array();
	text1['ru'] = 'Заполните обязательные поля ';
	text1['en'] = 'Fill required fields ';
	var errfields = '';
	var desc;
	var error;
	var required;
	var disabled;
	var readonly;
	var val;
	var saveradio;

	for(i=0;i<checktag.length;++i)
	{
		if(inp = form.getElementsByTagName(checktag[i]))
		{
			for(j=0;j<inp.length;++j)
			{
				required = inp[j].getAttribute('required');
				disabled = inp[j].getAttribute('disabled');
				readonly = inp[j].getAttribute('readonly');
				error = 0;
				if((required==1 || required=='true' || required=='yes') && !disabled && !readonly)
				{
					if(inp[j].type == 'select-one')
					{
						if(sel = inp[j].options[inp[j].selectedIndex])
						{
							val = sel.value;
							cl_code_is = sel.getAttribute('cl_code_is');
							error = (val==0 || val=='' || cl_code_is=='yes') ? 1 : 0;
						}
					}
					else if(inp[j].type == 'radio')
					{
						if(inp[j].name == saveradio)
							continue;
						error = 1;
						brothers = document.getElementsByName(inp[j].name);
						for(n=0;n < brothers.length;++n)
						{
							if(brothers[n].checked)
							{
								error = 0;
								break;
							}
						}
						saveradio = inp[j].name;
					}
					else if(inp[j].type == 'checkbox')
					{
						error = (inp[j].checked==0) ? 1 : 0;
					}
					else
					{
						minlength = inp[j].getAttribute('minlength');
						if(!minlength) minlength = 1;
						maxlength = inp[j].getAttribute('maxlength');
						if(!maxlength) maxlength = 99999;
						vlen = trim(inp[j].value).length;
						error = (vlen<minlength || vlen>maxlength) ? 1 : 0;
					}

					inp[j].className = inp[j].className.replace(/ terbg/g,'');
					if(error == 1)
					{
						inp[j].className += ' terbg';
						if(!errfields)
							inp[j].focus();
						desc = inp[j].getAttribute('description');
						errfields += (desc) ? '\n"' + desc + '"' : "\n";
					}
				}
			}
		}
	}
	if(typeof(jshttp_checkfield)=='function')
	{
		var url = (form.id) ? '/?id=' + form.id.value : '';
		var user_id = document.getElementById('user_id');
		if(user_id && url)
			url += '&user_id=' + user_id.value;

		var userfield;
		userfield = document.getElementById('p__name');
		if(userfield && userfield.value)
			jshttp_checkfield(userfield,url);
		userfield = document.getElementById('p__login');
		if(userfield && userfield.value)
			jshttp_checkfield(userfield,url);
		userfield = document.getElementById('p__user_nick');
		if(userfield && userfield.value)
			jshttp_checkfield(userfield,url);
	}
	
	if(errfields)
		alert(text1[TG_site_lang] + errfields);

	if(form && form.elements)
	{
		for(j=0; j<form.elements.length;++j)
		{
			ch = form.elements[j];
			if(onsubmitfunc = ch.getAttribute('onsubmitfunc'))
			{
				eval("ret = " + onsubmitfunc + "(ch,form);");
				if(!ret)
					return false;
			}
		}
	}
	if(errfields)
		return false;
	return true;
}


function inputdeftext(id,act,deftext)
{
	var input = document.getElementById(id);
	if(input)
	{
		var val = trim(input.value);
		if(act=='click' && val==deftext)
		{
			input.value = '';
		}
		else if(act=='blur' && val=='')
		{
			input.value = deftext;
		}
		else if(act=='submit' && val==deftext)
		{
			input.value = '';
			input.focus();
			return false;
		}
	}
	return true;
}


function votecheck(form,ans_id,warn)
{
	var inp = new Array();
	inp = form.getElementsByTagName('input');
	if(inp)
	{
		for(j=0;j < inp.length;++j)
		{
			if(inp[j].checked)
			{
				alert(ans_id);
				return formcheck(form);
			}
		}
	}
	warn = 'Выберите вариант ответа!';
	alert(warn);
	return false;
}


function checkemail(field)
{
	var ret = true;
	var text1 = new Array();
	text1['ru'] = 'Неправильный e-mail: %s';
	text1['en'] = 'Incorrect e-mail: %s';
	if(field)
	{
		var val = field.value;
		var required = field.getAttribute('required');
		if(required!=1 && required!='true' && required!='yes' && val.length == 0) return ret;
		if (val.indexOf('@') < 1 ) ret = false;
		if (val.lastIndexOf('.') < val.indexOf('@')) ret = false;
		if (val.length - val.lastIndexOf('.') <= 2) ret = false;
		if (val.indexOf(' ') != -1) ret = false;
		field.className = field.className.replace(/ terbg/g,'');
		if (ret == false)
		{
			field.className += ' terbg';
			field.focus();
			alert(text1[TG_site_lang].replace(/%s/,val));
		}
	}
	return ret;
}

function checknumber(field,form)
{
	var ret = true;
	var text1 = new Array();
	text1['ru'] = 'Недопустимый символ в "%s"';
	text1['en'] = 'Incorrect symbol in "%s"';
	if(field)
	{
		var val = field.value;
		var required = field.getAttribute('required');
		if(required!=1 && required!='true' && required!='yes' && val.length == 0) return ret;
		if (!allDigitsSpec(val)) ret = false;
		field.className = field.className.replace(/ terbg/g,'');
		if (ret == false)
		{
			field.className += ' terbg';
			field.focus();
			alert(text1[TG_site_lang].replace(/%s/,val));
		}
	}
	return ret;
}

function check_subscribe(field)
{
	//fiels - p__subscribe_active ���
	//fiels - p__subscribe_rubs[XXX]
	if(field)
	{
		var ischecked = 0;
		rubs = new Array();
		tags = document.getElementsByTagName('input');
		for(i=0,j=0; i<tags.length; i++)
		{
			if(tags[i].type == 'checkbox' && tags[i].getAttribute('name') && tags[i].getAttribute('name').indexOf("p__subscribe_rubs") != -1)
				rubs[j++] = tags[i];
		}
		for(i=0; i<rubs.length; i++)
			if(rubs[i].checked)
				ischecked = 1;
		if(field.getAttribute('name')=='p__subscribe_active')
		{
			if(!field.checked)
				for(i=0; i<rubs.length; i++)
					rubs[i].checked = 0;
			else if(field.checked && !ischecked)
				for(i=0; i<rubs.length; i++)
					rubs[i].checked = 1;
		}
		else
		{
			if(activ = document.getElementsByName('p__subscribe_active'))
			{
				var cactiv = (activ[0].type=='checkbox') ? activ[0] : activ[1];
				cactiv.checked = ischecked;
			}
		}

	}
	return true;
}

function selectdepend(form)
{
	if(!form) return;
	var depname = form.getAttribute('dependmaster');
	var val = null;
	if(depname)
	{
		dep = document.getElementById('p__' + depname);
		cop = document.getElementById('c__' + depname);
		if(dep && cop)
		{
			if(form.options.length)
				val = form.options[form.selectedIndex].value;

			if(dep.options)
			{
				for(j=0; j<dep.options.length; ++j)
					dep.options[j] = null;
				dep.options.length = 0;

				for(j=0, i=0; j<cop.options.length; ++j)
				{
					if(val != null && cop.options[j].getAttribute('parent_id') == val)
					{
						dep.options[i] = new Option(cop.options[j].text,cop.options[j].value);
						if(cop.selectedIndex && cop.selectedIndex==j)
							dep.selectedIndex = i;
						i++;
					}
				}
			}
			if(dep.getAttribute('dependmaster'))
				selectdepend(dep);
		}
	}
}


function allDigits(str)
{
	return inValidCharSet(str,"0123456789");
}

function allDigitsSpec(str)
{
	return inValidCharSet(str,"0123456789.+-");
}

function inValidCharSet(str,charset)
{
	for (i=0; i<str.length; i++)
		if (charset.indexOf(str.substr(i,1))<0)
			return false;
	return true;
}

function CopyContent()
{
	a = document.getElementById('Content');
	if(a && window.clipboardData)
	{
		window.clipboardData.setData('Text', objtext(a));
	}
}
function CopyPage()
{
	document.execCommand("SelectAll");
	document.execCommand("Copy");
	document.body.focus();
}
function PrintPage()
{
	window.print();
}

window.onscroll = function ()
{
	lmscroll_stand();
}

window.onresize = function ()
{
	lmscroll_stand();
}

function lmscroll_stand()
{
	rsptail = document.getElementById('rasptail');
	if(rsptail)
	{
		scheck = document.getElementById('lmscrollcheck');
		if(scheck && scheck.checked==true)
		{
			rsptail.height = (document.body.scrollTop) ? document.body.scrollTop + 0 : document.documentElement.scrollTop + 0;
		}
	}
}

function lmscroll_switch()
{
	div = document.getElementById('divtail');
	if(div)
	{
		if(div.style.position == 'absolute')
		{
			div.style.position = 'static';
			rsptail = document.getElementById('rasptail');
			if(rsptail) rsptail.height = 0;
		}
		else
		{
			div.style.position = 'absolute';
		}
		document.body.scrollTop = document.documentElement.scrollTop = 0;
		document.cookie = 'lmscroll=' + div.style.position + '; expires=Fri, 25 Dec 2099 23:59:59 GMT;';
	}
}

function toggle_div(a)
{
	var title;
	obj = a.parentNode.nextSibling;
	while (obj.tagName!='DIV')
		obj = obj.nextSibling;
	if(obj)
	{
		title = a.getAttribute('title');
		if(obj.style.visibility=='visible')
		{
			obj.style.visibility='hidden';
			obj.style.display='none';
			if(title=='close')		a.setAttribute('title','open',0);
			if(title=='закрыть')	a.setAttribute('title','открыть',0);
			if(a.firstChild.data.substring(a.firstChild.data.length-3) != '...')
				a.firstChild.data +='...';
			if(a.firstChild.data.substring(0,1) == '-')
				a.firstChild.data = a.firstChild.data.replace('--','+');
			savevalue = "h";
		}
		else
		{
			obj.style.visibility='visible';
			obj.style.display='block';
			if(title=='open')		a.setAttribute('title','close',0);
			if(title=='открыть')	a.setAttribute('title','закрыть',0);
			if(a.firstChild.data.substring(a.firstChild.data.length-3) == '...')
				a.firstChild.data = a.firstChild.data.substring(0, a.firstChild.data.length-3);
			if(a.firstChild.data.substring(0,1) == '+')
				a.firstChild.data = a.firstChild.data.replace('+','--');
			savevalue = "v";
		}
		inp = document.getElementById('f_div_' + obj.id);
		if(inp)
			inp.value = savevalue;
		lmscroll_stand();
	}
	return false;
}

function autotoggle_div(divattr,showact)
{
	if(legends = document.getElementsByTagName('legend'))
	{
		for(j=0; j < legends.length; j++)
		{
			cur = legends[j];
			if(cur.getAttribute(divattr)=='yes')
			{
				if (showact==0 || (showact==1 && cur.nextSibling.style.visibility=='hidden') || (showact==2 && cur.nextSibling.style.visibility=='visible'))
					toggle_div(cur.firstChild);
			}
		}
	}
}

function switch_div(id)
{
	var user_agt = navigator.userAgent.toLowerCase();
	var user_is_opera6 = (user_agt.indexOf("opera 6") != -1);
	if(user_is_opera6)
	{
		id = id.replace('id_','');
		document.location.href='/?id=' + id;
		return;
	}
	obj = document.getElementById(id);
	if(obj)
	{
		if(obj.style.visibility=='visible')
		{
			obj.style.visibility='hidden';
			obj.style.display='none';
		}
		else
		{
			obj.style.visibility='visible';
			obj.style.display='block';
		}
	}
}

function switch_form_elem(param,show)
{
	var e1 = document.getElementById('d1__' + param);
	var e2 = document.getElementById('d2__' + param);
	var ef = document.getElementById('p__'  + param);

	if(e1 && !e1.getAttribute('saveclassName'))
		e1.setAttribute('saveclassName',e1.className);
	if(e2 && !e2.getAttribute('saveclassName'))
		e2.setAttribute('saveclassName',e2.className);

	if(show)
	{
		if(e1)
			e1.className = e1.getAttribute('saveclassName');
		if(e2)
			e2.className = e2.getAttribute('saveclassName');
		if(ef)
		{
			ef.removeAttribute('disabled');
			brothers = document.getElementsByName(ef.name);
			for(n=0;n < brothers.length;++n)
				brothers[n].removeAttribute('disabled');
		}
	}
	else
	{
		if(e1)
			e1.className = 'divhidden';
		if(e2)
			e2.className = 'divhidden';
		if(ef)
		{
			ef.setAttribute('disabled',true);
			brothers = document.getElementsByName(ef.name);
			for(n=0;n < brothers.length;++n)
			{
				brothers[n].setAttribute('disabled',true);
			}
		}
	}
}

function textcounter(area)
{
	var maxl = area.getAttribute('maxlength');
	if(!maxl) return;
	var len = area.value.length;
	if(len > maxl)
	{
		area.value = area.value.substring(0,maxl);
		len = maxl;
	}
	if (area.createTextRange)
		area.caretPos = document.selection.createRange().duplicate();
	var counter = document.getElementById(area.name + '_counter');
	if(counter)
	{
		objtext(counter,maxl-len);
		counter.className = (maxl>len) ? '' : 'ter';
	}
}

function getval(form)
{
	return getvalbyid(form);
}

// sel - элемент (объект) формы или id
function getvalbyid(sel)
{
	var val;
	var elem = (typeof(sel)=='object') ? sel : document.getElementById(sel);
	if(!elem) return false;

	var tp = elem.getAttribute('type');
	if(tp == 'hidden')
	{
		brothers = document.getElementsByName(elem.name);
		for(j=0;j < brothers.length;++j)
		{
			elem = brothers[j];
			tp = elem.getAttribute('type');
			if(tp != 'hidden')
			{
				break;
			}
		}
	}
	if(tp == 'checkbox')
	{
		val = (elem.checked) ? 1 : 0;
	}
	else if(tp == 'radio')
	{
		if(elem.checked)
		{
			val = elem.value;
		}
		else
		{
			for(j=0;j < brothers.length;++j)
			{
				if(brothers[j].checked)
				{
					val = brothers[j].value;
					break;
				}
			}
		}
	}
	else if(tp == 'select')
	{
		val = elem.options[elem.selectedIndex].value;
	}
	else
	{
		subtype = elem.getAttribute('subtype');
		if(subtype == 'number')
			val = (elem.value) ? elem.value : 0;
		else
			val = elem.value;
	}
	return val;
}

function objtext(obj,text)
{
	if(obj)
	{
		if(typeof(text)!='undefined')
		{
			if(typeof(obj.textContent)!='undefined')
				obj.textContent=text;
			else
				obj.innerText=text;
		}
		else
		{
			if(typeof(obj.textContent)!='undefined')
				obj=obj.textContent;
			else
				obj=obj.innerText;
		}
	}
	return obj;
}

function rf()
{
	return false;
}

function changeimagekey3(img,modekey,wid,hei,d,c,eff)
{
	var fid = 0;
	if(img && img.src)
	{
		var obj = img.parentNode;
		while(obj && obj.tagName!='FORM')
			obj = obj.parentNode;
		if(obj)
			fid = obj.getAttribute('name');
		if(eff=='')
			eff = 'w';
		img.onload = '';
		img.src = '/comm/imagekey.php?rand=' + Math.random() + '&form_name=' + fid + '&modekey=' + modekey + '&wid=' + wid + '&hei=' + hei + '&d=' + d + '&c=' + c + '&e=' + eff;
	}
}


// Добавление элемента к параметру custom
function add_element(elem,elemmax)
{
	var n;
	var c;
	var no = document.getElementById('n_fe_'+elem);	// td с form_element из образца
	var co = document.getElementById('c_fe_'+elem);	// td с form_element из установленного параметра
	var alltags = new Array('input','textarea','select','hidden','checkbox','file','radio');
	if(no && co)
	{
		cnt = cnt_element(elem);
		if(elemmax > 0 && cnt >= elemmax)
		{
			alert('max = ' + elemmax);
			return;
		}
		n = no.getElementsByTagName('div');	// массив элементов (div-ов с формами) из образца
		c = co.getElementsByTagName('div');	// массив элементов (div-ов с формами) из установленного параметра (может быть пустой)
		ind_last = (c && c.length > 0 && c[c.length-1].getAttribute('id')) ? c[c.length-1].getAttribute('id').replace('e_'+elem, '') : 0;

		for(i=0; i<n.length; i++)
		{
			ind_old = n[i].getAttribute('id');
			if(ind_old && ind_old.substring(0,2) == 'e_')
			{
				ind_old = ind_old.replace('e_'+elem, '');
				ind_new = parseInt(ind_last) + parseInt(ind_old) + 1;
				newelem = n[i].cloneNode(true);
				newelem.setAttribute('id','e_'+elem+ind_new);
				for(t=0; t<alltags.length; t++)
				{
					tags = newelem.getElementsByTagName(alltags[t]);
					for(j=0; j<tags.length; j++)
					{
						tags[j].setAttribute('name',tags[j].getAttribute('name').replace(elem+'['+ind_old+']', elem+'['+ind_new+']'));
						tags[j].removeAttribute('disabled');
	
						ii = tags[j].getAttribute('name');
						ii = ii.substring(ii.length-3,ii.length);
						if(ii == '[i]')
							tags[j].value = ind_new;
					}
				}
				co.appendChild(newelem);
			}
		}
		cnt_element(elem);
	}
}

// Подсчет элементов параметра custom
function cnt_element(elem)
{
	var cnt = 0;
	var co = document.getElementById('c_fe_'+elem);
	if(co && (d = co.getElementsByTagName('div')))
	{
		for(i=0; i<d.length; i++)
			if((ind_old = d[i].getAttribute('id')) && (ind_old.substring(0,2) == 'e_'))
				cnt++;
		tags = co.getElementsByTagName('span');
		for(j=0; j<tags.length; j++)
			if(tags[j].getAttribute('id') == 'cnt_'+elem)
				tags[j].innerHTML = cnt;
	}
	return cnt;
}

// Удаление элемента из параметра custom
function del_element(elem,prnt)
{
	var id;	// id div-а удаляемого элемента
	var co = document.getElementById('c_fe_'+elem);	// td с form_element из установленного параметра
	if(prnt && (id = prnt.getAttribute('id')) && co && (d = co.getElementsByTagName('div')))
	{
		for(i=0; i<d.length; i++)
			if(d[i].getAttribute('id') == id && (par = d[i].parentNode))
				par.removeChild(d[i]);
		cnt_element(elem);
	}
}

// Перемещение элемента из параметра custom выше-ниже
function move_element(name, parelem, where)
{
	var regex = new RegExp('.*'+name+'.*');
	var par = parelem.parentNode;
	if (where == 'up' && regex.test(parelem.previousElementSibling.id))
	{
		var prev = parelem.previousElementSibling;
		var cur = parelem.parentNode.removeChild(parelem);
		par.insertBefore(cur, prev);
	}
	else if (where == 'down' && parelem.nextElementSibling !== null)
	{
		var next = parelem.nextElementSibling;
		var cur = parelem.parentNode.removeChild(parelem);
		par.insertBefore(cur, next.nextSibling);
	}
	var divs = par.getElementsByTagName('DIV');
	for (i = 0; i < divs.length; i++)
	{
		if (regex.test(divs[i].id))
		{
			divs[i].setAttribute('id', 'e_'+name+i);
			var inputs = divs[i].getElementsByTagName('INPUT');
			for (k = 0; k < inputs.length; k++)
			{
				var iname = inputs[k].name;
				var regex1 = /\[\d+\]/;
				inputs[k].setAttribute('name', iname.replace(regex1,'['+i+']'));
			}
			var textareas = divs[i].getElementsByTagName('TEXTAREA');
			for (k = 0; k < textareas.length; k++)
			{
				var iname = textareas[k].name;
				var regex1 = /\[\d+\]/;
				textareas[k].setAttribute('name', iname.replace(regex1,'['+i+']'));
			}
		}
	}
	return false;
}


// Получение тегов tag внутри элемента id
function getInnerTagsById(id, tag)
{
	var element = document.getElementById(id);
	if(element)
		return element.getElementsByTagName(tag);
	return false;
}

// Задание прозрачности элемента
function setOpacity(element, opacity)
{
	if(element)
	{	
		element.style.opacity = opacity;
		element.style.filter = 'alpha(opacity='+(opacity*100)+')';
	}
}

function showtime(div,interval)
{
	if(!interval)
		interval = 1000;
	var today	= new Date();
	var h = today.getHours();
	var m = today.getMinutes();
	var s = today.getSeconds();
    if (h < 10) h = "0" + h;
    if (m < 10) m = "0" + m;
    if (s < 10) s = "0" + s;
	if(a = document.getElementById(div))
	{
		a.innerHTML = h + ":" + m;
		if(interval == 1000)
			a.innerHTML += ":" + s;
	}
	window.setTimeout('showtime("' + div + '")', interval);
}

function parseGetString()
{
	var get = location.search;
	var tmp = new Array();
	var tmp2 = new Array();
	var param = new Array();   
	if(get != '')   
	{   
	    tmp = (get.substr(1)).split('&');
	    for(var i=0; i < tmp.length; i++)   
	     {   
	         tmp2 = tmp[i].split('=');
	         param[tmp2[0]] = tmp2[1];
	     }   
	}
	return param;
}

function in_array(needle, haystack)
{
    for(var i=0; i<haystack.length; i++)
        if(haystack[i] == needle)
            return true;
    return false;
}


var IncludFiles   = new Array();
var isIncludFiles = new Array();

function include_dom(url, oCallback)
{
	if(!in_array(url,IncludFiles))
	{
		var html_doc = document.getElementsByTagName('head').item(0);
		var js = document.createElement('script');
		js.setAttribute('language', 'javascript');
		js.setAttribute('type', 'text/javascript');
		js.setAttribute('src', url);
		if (oCallback != null)
		{
			// most browsers
			js.onload = oCallback(url);
			// IE 6 & 7
			js.onreadystatechange = function()
			{
				if (this.readyState == 'loaded')
				{
					oCallback(url);
				}
			}
		}
		html_doc.appendChild(js);
		IncludFiles[IncludFiles.length] = url;
	}
	return false;
}

function loadedjs(url)
{
	isIncludFiles[isIncludFiles.length] = url;
	return false;
}

function waiting_loaded(files)
{
	for(var k in files)
	{
		if(!in_array(files[k],isIncludFiles))
			setTimeout('waiting_loaded(' + files + ')', 10);
	}
}

function viewObject(name)
{
	var obj = eval(name), i;
	if(!obj)
	{
		alert("\""+name+"\" ia not an object");
		return;
	}
	var w_Test = open("","Test","width=600,height=500,scrollbars=1");
	if(!w_Test)
	{
		alert("Cannot open window for "+name);
		return;
	}
	w_Test.document.open();
	for(i in obj)
		w_Test.document.write(name+"."+i+"="+obj+"<br>");
	w_Test.document.close();
}

