//Это прикрепляем к iframe, чтобы он поддерживал стили, которые мы создали
var EditFieldHeaderOut =
"<html><head><style>\n"+
"body{font-family:Arial;font-size:10pt;font-weight:normal;color:#595854;margin-top:0px;margin-bottom:0px;margin-left:0px;text-decoration:none;}\n"+
"h1{font-family:Arial;font-size:10pt;font-weight:normal;color:#595854;margin-top:0px;margin-bottom:0px;margin-left:0px;text-decoration:none;}\n"+
"h2{font-family:Arial;font-size:10pt;font-weight:bold;color:#595854;margin-top:0px;margin-bottom:0px;margin-left:0px;text-decoration:none;}\n"+
"h3{font-family:Arial;font-size:10pt;font-weight:normal;color:#d2581e;margin-top:0px;margin-bottom:0px;margin-left:0px;text-decoration:none;}\n"+
"h4{font-family:Arial;font-size:17px;color:#595854;margin-top:25px;margin-bottom:10px;margin-left:0px;font-weight:normal;text-decoration:none;}\n"+
"h5{background-color:#f3f3eb;font-family:Arial;font-size:10pt;font-weight:normal;color:#595854;padding:5px;text-decoration:none;margin:0px;}\n"+
"h6{font-family:Arial;font-size:10pt;color:#baae98;margin-top:0px;margin-bottom:0px;margin-left:0px;font-weight:normal;text-decoration:none;}\n"+
"a{font-family:Arial;font-size:10pt;color:#d2581e;text-decoration:underline;}\n"+
"ul{font-family:Arial;font-size:10pt;color:font-weight:normal;#595854;text-decoration:none;margin-bottom:10px;margin-left:0px;}\n"+
"ol{font-family:Arial;font-size:10pt;color:font-weight:normal;#595854;text-decoration:none;margin-bottom:10px;margin-left:0px;}\n"+
"ul li{font-family:Arial;font-size:10pt;color:#595854;font-weight:normal;text-decoration:none;margin-bottom:5px;margin-left:20px;list-style-image:url('tire.gif');list-style-position:outside}\n"+
"ol li{font-family:Arial;font-size:10pt;color:#595854;font-weight:normal;text-decoration:none;margin-bottom:5px;margin-left:20px;list-style-position:outside}\n"+
"</style></head>";
//раскрываем менюшку
function showsub(num)
{
	var targetId,i;
	targetId = "submenu" + num;
	if(document.getElementById(targetId).style.display=='none')
   	{
	document.getElementById(targetId).style.display='block';
	for(i=1;i<150;i++) if(document.getElementById('show'+num+''+i)!=null){document.getElementById('show'+num+''+i).value=1;}
	}
   	else
  	{
	document.getElementById(targetId).style.display='none';
	for(i=1;i<150;i++) if(document.getElementById('show'+num+''+i)!=null){document.getElementById('show'+num+''+i).value=0;}
 	}
}

function set_id(r)
{
	document.getElementById('id_section').value=r;
}

function Read_id()
{
	if (document.getElementById('id_section').value==0)
	return false;
	else return true;
}
//Общаемся с серваком по ajax
function baster(keyword,table,name_div)
{
	var req;
	var sss;
	if (window.XMLHttpRequest)
	{
		req=new XMLHttpRequest();
	}
	else if (window.ActiveXObject)
	{
		try	{req=new ActiveXObject('MSXML2.XMLHTTP.3.0');}
		catch(e){}
	}
	if(req)
	{
		req.open("post","ajax2.php",true);
		req.setRequestHeader("Content-Type"," application/x-www-form-urlencoded;");
		req.onreadystatechange=function()
		{
	   	 if (req.readyState==4 && req.status==200)
	    	{
	    		sss=req.responseText;
	    		document.getElementById(name_div).display='block';
	    		document.getElementById(name_div).innerHTML=sss;

	    	}
		}
		req.send('keyword='+table+'|'+encodeURIComponent(keyword));
	}
}
//Показываем раздел пользователю
function ShowSection(nomer,im)
{
	var url="url(logo"+im+".jpg)";
	var targetId,i;
	i=1;
	document.getElementById('information').display='none';
	while (i<100)
{
	if(document.getElementById("nosel"+i)!=null)
	{
	document.getElementById("nosel"+i).style.display='block';
	document.getElementById("sel"+i).style.display='none';
	}
	i++;
}

	document.getElementById("sel"+nomer).style.display='block';
	document.getElementById("nosel"+nomer).style.display='none';
	document.getElementById("r1").style.backgroundImage=url;
	baster(nomer,'nomer','information');
}
//Показываем Шапку в начале
function ShowHead2(im)
{
	var url="url(logo"+im+".jpg)";
	document.getElementById("r1").style.backgroundImage=url;
}
function Showdel(id_frame)
{
	document.getElementById("sub"+id_frame).style.display='block';
	document.getElementById("sup"+id_frame).style.display='block';
}
function Hidedel(id_frame)
{
	document.getElementById("sub"+id_frame).style.display='none';
	document.getElementById("sup"+id_frame).style.display='none';
}
function HideSection()
{
	document.getElementById('information').display='none';
}
//Показываем раздел админу
function ShowSection1(nomer,im)
{
	var url="url(logo"+im+".jpg)";
	var targetId,i;
	i=1;
	document.getElementById('information').display='none';
	while (i<100)
{
	if(document.getElementById("nosel"+i)!=null)
	{
	document.getElementById("nosel"+i).style.display='block';
	document.getElementById("sel"+i).style.display='none';
	}
	i++;
}
	document.getElementById("sel"+nomer).style.display='block';
	document.getElementById("nosel"+nomer).style.display='none';
	document.getElementById("tempsectionvalue").value=nomer;
	document.getElementById("r1").style.backgroundImage=url;
	baster(nomer,'adm_nomer','information');
}
//Показываем панель инструментов для редактирования текста
function Tools (m,iframe_id) 
{
	var TStyle = '';
	if (navigator.userAgent.match(/msie/i)) TStyle = new Array('textline','boldtext','orangetext','headline','selecttext','lighttext','orderlist','marklist','link','file');
	if (navigator.userAgent.match(/gecko/i)) TStyle = new Array('textline','boldtext','orangetext','headline','selecttext','lighttext','orderlist','marklist','link','file');
	var TTitle = new Array('Обычный текст','Жирный текст','Оранжевый текст','Заголовок','Выделенный текст','Бежевый текст','1. Нумерованный список','&#151 Маркированный список','Ссылка','Прикрепить файл');
	var Toolkit = "<Table cellpadding=0 cellspacing=0 border=0 width=460px><Tr>\n";
	Toolkit += "<Td><button id=toolbutton onclick=\"setStyle('"+TStyle[0]+"','"+iframe_id+"')\" onmouseover=\"this.style.cursor='pointer'\"  title=\""+TTitle[0]+"\"><p id=pb1>"+TTitle[0]+"</p></button></Td>\n";
	Toolkit += "<Td><button id=toolbutton onclick=\"setStyle('"+TStyle[1]+"','"+iframe_id+"')\" onmouseover=\"this.style.cursor='pointer'\"  title=\""+TTitle[1]+"\"><p id=pb2>"+TTitle[1]+"</p></button></Td>\n";
	Toolkit += "<Td><button id=toolbutton onclick=\"setStyle('"+TStyle[2]+"','"+iframe_id+"')\" onmouseover=\"this.style.cursor='pointer'\"  title=\""+TTitle[2]+"\"><p id=pb3>"+TTitle[2]+"</p></button></Td></tr>\n";
	Toolkit += "<tr><Td><button id=toolbutton onclick=\"setStyle('"+TStyle[3]+"','"+iframe_id+"')\" onmouseover=\"this.style.cursor='pointer'\"  title=\""+TTitle[3]+"\"><p id=pb4>"+TTitle[3]+"</p></button></Td>\n";
	Toolkit += "<Td><button id=toolbutton onclick=\"setStyle('"+TStyle[4]+"','"+iframe_id+"')\" onmouseover=\"this.style.cursor='pointer'\"  title=\""+TTitle[4]+"\"><p id=pb5>"+TTitle[4]+"</p></button></Td>\n";
	Toolkit += "<Td><button id=toolbutton onclick=\"setStyle('"+TStyle[5]+"','"+iframe_id+"')\" onmouseover=\"this.style.cursor='pointer'\"  title=\""+TTitle[5]+"\"><p id=pb6>"+TTitle[5]+"</p></button></Td></tr>\n";
	Toolkit += "<tr><Td><button id=toolbutton onclick=\"setStyle('"+TStyle[6]+"','"+iframe_id+"')\" onmouseover=\"this.style.cursor='pointer'\"  title=\""+TTitle[6]+"\"><p id=pb1>"+TTitle[6]+"</p></button></Td>\n";
	Toolkit += "<Td colspan=2><button id=toolbutton onclick=\"setStyle('"+TStyle[7]+"','"+iframe_id+"')\" onmouseover=\"this.style.cursor='pointer'\"  title=\""+TTitle[7]+"\"><p id=pb1>"+TTitle[7]+"</p></button></Td></Tr>\n";	
	Toolkit += "<Tr><Td><button id=toolbutton onclick=\"setStyle('"+TStyle[8]+"','"+iframe_id+"')\" onmouseover=\"this.style.cursor='pointer'\"  title=\""+TTitle[8]+"\"><p id=pba>"+TTitle[8]+"</p></button></Td>\n";		
	Toolkit += "<Td><button id=toolbutton onclick=\"setStyle('"+TStyle[9]+"','"+iframe_id+"')\" onmouseover=\"this.style.cursor='pointer'\"  title=\""+TTitle[9]+"\"><p id=pba>"+TTitle[9]+"</p></button></Td>\n";	
	if(iframe_id!=0)
	document.getElementById('tools'+iframe_id).innerHTML = Toolkit+"</Tr></Table>";
	else
	document.getElementById('tools').innerHTML = Toolkit+"</Tr></Table>";
}

function ParHead(i,id_frame)
{
var targetID;
if(i==1)
{
	document.getElementById('ifth11'+id_frame).style.display='none'
	document.getElementById('ifth12'+id_frame).style.display='block'
	document.getElementById('ifth22'+id_frame).style.display='none'
	document.getElementById('ifhead'+id_frame).value=1
	document.getElementById('ifth21'+id_frame).style.display='block'
}
else
{
	document.getElementById('ifth12'+id_frame).style.display='none'
	document.getElementById('ifth11'+id_frame).style.display='block'
	document.getElementById('ifth21'+id_frame).style.display='none'
	document.getElementById('ifth22'+id_frame).style.display='block'
	document.getElementById('ifhead'+id_frame).value=2
}
}

function ParCol(i,id_frame)
{
var targetID;
if(i==1)
{
	document.getElementById('col11'+id_frame).style.display='none'
	document.getElementById('col12'+id_frame).style.display='block'
	document.getElementById('col22'+id_frame).style.display='none'
	document.getElementById('countcols'+id_frame).value=2
	document.getElementById('col21'+id_frame).style.display='block'
}
else
{
	document.getElementById('col12'+id_frame).style.display='none'
	document.getElementById('col11'+id_frame).style.display='block'
	document.getElementById('col21'+id_frame).style.display='none'
	document.getElementById('col22'+id_frame).style.display='block'
	document.getElementById('countcols'+id_frame).value=3
}
}

//Показать текстовый блок для редактирования
function ShowTextline(id_frame)
{
	var targetId;
	targetId = "div" + id_frame;
	document.getElementById(targetId).style.display='block';
	var iframe;
   	var Content = document.getElementById("old_text"+id_frame).value;
	if (navigator.userAgent.match(/msie/i)) iframe = frames['TextArea'+id_frame].document;
	else if (navigator.userAgent.match(/gecko/i)) iframe = document.getElementById('TextArea'+id_frame).contentDocument;
	targetId = "text" + id_frame;
	document.getElementById(targetId).style.display='none';
	document.getElementById('temp_area').value='TextArea'+id_frame;
	iframe.body.contentEditable = true;
	setTimeout( function() { iframe.designMode = "on"; }, 10 );
	iframe.open();
	iframe.writeln(EditFieldHeaderOut); 
	iframe.writeln(Content); 
	iframe.close();
	Tools(1,id_frame);
}
//Добавить Текстовый блок
function InsTextBlock()
{
	var targetId;
	var m=document.getElementById('m').value;
	targetId = "div" + m;
	document.getElementById(targetId).style.display='block';
	var iframe;
   	var Content='';
	if (navigator.userAgent.match(/msie/i)) iframe = frames['TextArea'+m].document;
	else if (navigator.userAgent.match(/gecko/i)) iframe = document.getElementById('TextArea'+m).contentDocument;
	document.getElementById('temp_area').value='TextArea'+m;
	targetId = "text" + m;
	document.getElementById(targetId).style.display='none';
	iframe.body.contentEditable = true;
	setTimeout( function() { iframe.designMode = "on"; }, 10 );
	iframe.open();
	iframe.writeln(EditFieldHeaderOut); 
	iframe.writeln(Content); 
	iframe.close();
	Tools(1,m);
	m++;
	document.getElementById('m').value=m;
}

//Показать таблицу для вставки (т.е. новая таблица)
function InsTableLine()
{
	var targetId;
	var m=document.getElementById('m').value;
	targetId = "divtable" + m;
	document.getElementById(targetId).style.display='none';	
	targetId = "tablered" + m;
	document.getElementById(targetId).style.display='none';	
	targetId = "tableblock" + m;
	document.getElementById(targetId).style.display='none';
	targetId = "parametre" + m;
	document.getElementById(targetId).style.display='block';
}
//Устанавливаем стили в текстовом блоке
function setStyle (TStyle,id_frame) 
{
	var iframe;
	if (navigator.userAgent.match(/msie/i)) iframe = frames['TextArea'+id_frame].document;
	else if (navigator.userAgent.match(/gecko/i)) iframe = document.getElementById('TextArea'+id_frame).contentDocument;
	iframe.execCommand('RemoveFormat', false, true)
	if (TStyle.match(/textline/i)) 
	{
		iframe.execCommand("FormatBlock",false,'<h1>');
	}
	else if (TStyle.match(/boldtext/i)) 
	{
		iframe.execCommand("formatBlock",false,'<h2>');
	}
	else if (TStyle.match(/orangetext/i)) 
	{
		iframe.execCommand("formatBlock",false,'<h3>');
	}
	if (TStyle.match(/headline/i)) 
	{
		iframe.execCommand("formatBlock",false,'<h4>');
	}
	if (TStyle.match(/selecttext/i)) 
	{
		iframe.execCommand("formatBlock",false,'<h5>');
	}
	if (TStyle.match(/link/i)) 
	{
		var url = prompt("Введите URL ссылки", "http://");
		if (url) 
		{
			iframe.execCommand("CreateLink", null, url);
		}
	}
	if (TStyle.match(/lighttext/i)) 
	{
		iframe.execCommand("formatBlock",false,'<h6>');
	}
	if (TStyle.match(/orderlist/i)) 
	{
		iframe.execCommand("insertorderedlist",false,'null');
	}
	if (TStyle.match(/marklist/i)) 
	{
		iframe.execCommand("insertunorderedlist",false,'null');
	}	
	if (TStyle.match(/file/i)) 
	{
		uploadFile(1);
	}
}
//Меняем заголовок
function RedHead()
{
	var targetId;
	targetId = "headline";
	document.getElementById(targetId).style.display='none';
	targetId = "headlinered";
	document.getElementById(targetId).style.display='block';
}
//Сохраняем заголовок
function SaveHead(id_section)
{
	var targetId,head,head2;
	targetId = "headlinered";
	document.getElementById(targetId).style.display='none';
	head=document.getElementById('head').value;
	head2="<table cellpadding=0 cellspacing=0><tr><td style='word-wrap:break-word;font-family: Arial;font-size: 10pt;color: #d2581e;text-decoration:underline;'>"+head+"</td></tr></table>";
	document.getElementById('sel'+id_section).innerHTML=head2;
	document.getElementById('nosel'+id_section).innerHTML=head2;
	targetId = "headline";
	document.getElementById(targetId).style.display='block';
	var head=head.replace(/"/g,'qwq');	
	baster(head+'|'+id_section,'head','headline');
}
//Меняем картинку шапки
function ChageHead()
{
	var im;
	im=document.getElementById('img_num').value;
	var id_section=document.getElementById('tempsectionvalue').value
	if(im<5)im++;
	else im=1;
	document.getElementById('img_num').value=im;
	var url="url(logo"+im+".jpg)";
	document.getElementById("r1").style.backgroundImage=url;
	baster(im+'|'+id_section,'img_num','empty');
}
//Сохраняем текстовое поле
function SaveText(id_frame,id_section)
{
	var targetId,head,EditField;
	var iframe;
	if (navigator.userAgent.match(/msie/i)) iframe = frames['TextArea'+id_frame].document;
	else if (navigator.userAgent.match(/gecko/i)) iframe = document.getElementById('TextArea'+id_frame).contentDocument;
	EditField = iframe.body.innerHTML;
	iframe.designMode = 'off';
	targetId = "text"+id_frame;
	document.getElementById(targetId).style.display='block';
	targetId = "old_text"+id_frame;
	document.getElementById(targetId).value=EditField;
	targetId = "div"+id_frame;
	document.getElementById(targetId).style.display='none';
	var tttt=EditField.replace(/"/g,'qwq');	
	baster(tttt+'|'+id_frame+'|'+id_section,'textLine','text'+id_frame);
}
//Добавляем новый текстовый блок в базу данных
function InsText(id_frame,id_section)
{
	var targetId,head,EditField;
	var iframe;
	if (navigator.userAgent.match(/msie/i)) iframe = frames['TextArea'+id_frame].document;
	else if (navigator.userAgent.match(/gecko/i)) iframe = document.getElementById('TextArea'+id_frame).contentDocument;
	EditField = iframe.body.innerHTML;
	iframe.designMode = 'off';
	targetId = "text"+id_frame;
	document.getElementById(targetId).style.display='block';
	targetId = "old_text"+id_frame;
	document.getElementById(targetId).value=EditField;
	targetId = "div"+id_frame;
	document.getElementById(targetId).style.display='none';
	var tttt=EditField.replace(/"/g,'qwq');	
	baster(tttt+'|'+id_frame+'|'+id_section,'InsLine','text'+id_frame);
	document.getElementById("newb"+id_frame).style.display='none';
	document.getElementById("redb"+id_frame).style.display='block';
}

//Удаляем текстовый блок (в принципе и для таблицы подойдет)
function DelText(id_frame,id_section)
{
	if(confirm('Точно удалить текст?')==true)
{	
	var targetId,head,EditField;
	var iframe;
	if (navigator.userAgent.match(/msie/i)) iframe = frames['TextArea'+id_frame].document;
	else if (navigator.userAgent.match(/gecko/i)) iframe = document.getElementById('TextArea'+id_frame).contentDocument;
	EditField = iframe.body.innerHTML;
	iframe.designMode = 'off';
	targetId = "text"+id_frame;
	document.getElementById(targetId).style.display='none';
	targetId = "old_text"+id_frame;
	document.getElementById(targetId).value="";
	targetId = "div"+id_frame;
	document.getElementById(targetId).style.display='none';
	baster(EditField+'|'+id_frame+'|'+id_section,'DelText','empty');
}
}

//Удаляем текстовый блок (в принципе и для таблицы подойдет)
function CancelText(id_frame,id_section)
{
	var targetId,head,EditField;
	var iframe;
	if (navigator.userAgent.match(/msie/i)) iframe = frames['TextArea'+id_frame].document;
	else if (navigator.userAgent.match(/gecko/i)) iframe = document.getElementById('TextArea'+id_frame).contentDocument;
	iframe.designMode = 'off';
	targetId = "text"+id_frame;
	document.getElementById(targetId).style.display='block';
	targetId = "old_text"+id_frame;
	document.getElementById(targetId).value=document.getElementById("text"+id_frame).innerHTML;
	targetId = "div" + id_frame;
	document.getElementById(targetId).style.display='none';
}
function DelTable(id_frame,id_section)
{
if(document.getElementById("newtextnull").value==0)
{
	if(confirm('Точно удалить таблицу?')==true)
{	
	var targetId,head,EditField;
	var iframe;
	EditField = '';
	document.getElementById('divtable'+id_frame).innerHTML='';
	targetId = "tablered"+id_frame;
	document.getElementById(targetId).style.display='none';
	targetId = "temp_table";document.getElementById(targetId).value="";
	targetId = "temp_count_cols";document.getElementById(targetId).value=0;
	targetId = "temp_count_rows";document.getElementById(targetId).value=0;
	targetId = "numblock";document.getElementById(targetId).value=0;
	targetId = "divtable"+id_frame;
	document.getElementById(targetId).style.display='none';
	baster(EditField+'|'+id_frame+'|'+id_section,'DelText','empty');
	}
}
}
//отмена изменений в таблице
function CancelTable(id_frame,id_section)
{

	document.getElementById('numblock').value=0
	document.getElementById('divtable'+id_frame).innerHTML='';
	targetId = "temp_count_cols";document.getElementById(targetId).value=0;
	targetId = "temp_count_rows";document.getElementById(targetId).value=0;
	document.getElementById('temp_table').value="";
	document.getElementById('tablered'+id_frame).style.display='none';
	document.getElementById('divtable'+id_frame).innerHTML=document.getElementById('old_table'+id_frame).value;		
	document.getElementById('divtable'+id_frame).style.display='none';		
	document.getElementById('tableblock'+id_frame).style.display='block';		
	document.getElementById("newtextnull").value=0
}
//Отмена создания таблицы
function CancelTableNew(id_frame,id_section)
{

	document.getElementById('numblock').value=0
	document.getElementById('divtable'+id_frame).innerHTML='';
	targetId = "temp_count_cols";document.getElementById(targetId).value=0;
	targetId = "temp_count_rows";document.getElementById(targetId).value=0;
	document.getElementById('temp_table').value="";
	document.getElementById('divtable'+id_frame).innerHTML='';
	document.getElementById('old_table'+id_frame).value='';		
	document.getElementById('two'+id_frame).style.display='none';		
	document.getElementById('three'+id_frame).style.display='none';
	document.getElementById('tablered'+id_frame).style.display='none';
	document.getElementById('divtable'+id_frame).style.display='none';		
	document.getElementById('tableblock'+id_frame).style.display='none';		
	document.getElementById("newtextnull").value=0
}
//Сохранение таблицы
function InsTable(id_frame,id_section)
{
if(document.getElementById("newtextnull").value==0)
{
	var targetId,head,EditField;
	var iframe;
	EditField = document.getElementById("tablenew"+id_frame).innerHTML;
	targetId = "tableblock"+id_frame;
	document.getElementById(targetId).style.display='block';
	targetId = "old_table"+id_frame;
	document.getElementById(targetId).value=EditField;
	targetId = "divtable"+id_frame;
	document.getElementById(targetId).style.display='none';
	baster(EditField+'|'+id_frame+'|'+id_section,'InsTable','tableblock'+id_frame);
}
}
//Показать таблицу для редактирования
function ShowTable(id_frame)
{
	var cols=document.getElementById('countcols'+id_frame).value;
	var rows=document.getElementById('countrows'+id_frame).value;
	var s=document.getElementById('width_min'+id_frame).value;
	var lastie=document.getElementById('lastie'+id_frame).value;
	var i;
	if(document.getElementById('numblock').value==0)	
	{
		document.getElementById('numblock').value=id_frame;
		document.getElementById('temp_count_cols').value=cols;
		document.getElementById('temp_count_rows').value=rows;
		if(cols==2)
		{
			if((window.navigator.appName == "Microsoft Internet Explorer") && lastie==1)s=s;
			if((window.navigator.appName != "Microsoft Internet Explorer") && lastie==1) {s++;s++;s++;s++;};
			document.getElementById('s').value=s;
			document.getElementById('two'+id_frame).style.display='block';		
		}
		else
		{
			document.getElementById('s').value=s;
			document.getElementById('three'+id_frame).style.display='block';		
		}
//		document.getElementById('divtable'+id_frame).innerHTML=document.getElementById('old_table'+id_frame).value;
		document.getElementById('temp_table').value=document.getElementById("divtable"+id_frame).innerHTML
		document.getElementById('tablered'+id_frame).style.display='block';
		document.getElementById('divtable'+id_frame).style.display='block';		
		document.getElementById('tableblock'+id_frame).style.display='none';		
	}

//else alert(document.getElementById('numblock').value);
}
//Показать таблицу для редактирования
function ShowStatic(id_frame)
{
	if(document.getElementById('numblock').value==0)	
	{
		document.getElementById('numblock').value=id_frame;
		document.getElementById('temp_table').value=document.getElementById("divtable"+id_frame).innerHTML
		document.getElementById('tablered'+id_frame).style.display='block';
		document.getElementById('divtable'+id_frame).style.display='block';		
		document.getElementById('tableblock'+id_frame).style.display='none';		
	}
}
//Сохранить таблицу
function SaveTable(id_frame,id_section)
{
if(document.getElementById("newtextnull").value==0)
{
	var text=document.getElementById("divtable"+id_frame).innerHTML;
	var cols=document.getElementById('temp_count_cols').value;
	var rows=document.getElementById('temp_count_rows').value;
	var lastie;
	document.getElementById('countrows'+id_frame).value=rows;
	document.getElementById('countcols'+id_frame).value=cols;
	var s=document.getElementById('s').value;
	if(window.navigator.appName == "Microsoft Internet Explorer"){lastie=1;} 
	else {lastie=2;}
	document.getElementById('lastie'+id_frame).value=lastie;
	var width=s
	document.getElementById('width_min'+id_frame).value=width;
	document.getElementById('old_table'+id_frame).value=text;
	var tttt=text.replace(/"/g,'qwq');
	baster(tttt+'|'+id_frame+'|'+id_section+'|'+cols+'|'+rows+'|'+width+'|'+lastie,'STable','tableblock'+id_frame);
	document.getElementById("tableblock"+id_frame).style.display='block';
	document.getElementById('numblock').value=0;
	document.getElementById('tablered'+id_frame).style.display='none';
	document.getElementById('divtable'+id_frame).style.display='none';	
}	
}//Сохранить таблицу
function SaveStatic(id_frame,id_section)
{
if(document.getElementById("newtextnull").value==0)
{
	var text=document.getElementById("divtable"+id_frame).innerHTML;
	document.getElementById('old_table'+id_frame).value=text;
	var tttt=text.replace(/"/g,'qwq');
	baster(tttt+'|'+id_frame+'|'+id_section,'SStatic','tableblock'+id_frame);
	document.getElementById("tableblock"+id_frame).style.display='block';
	document.getElementById('numblock').value=0;
	document.getElementById('tablered'+id_frame).style.display='none';
	document.getElementById('divtable'+id_frame).style.display='none';	
}	
}
//Сохранить новую таблицу
function SaveNewTable(id_frame,id_section)
{
if(document.getElementById("newtextnull").value==0)
{
	var text=document.getElementById("divtable"+id_frame).innerHTML;
	var cols=document.getElementById('temp_count_cols').value;
	var rows=document.getElementById('temp_count_rows').value;
	var width=document.getElementById('s').value;
	if((window.navigator.appName == "Microsoft Internet Explorer"))lastie=1;
	else lastie=2;

	document.getElementById('width_min'+id_frame).value=width;
	document.getElementById('countrows'+id_frame).value=rows;
	document.getElementById('countcols'+id_frame).value=cols;
	document.getElementById('old_table'+id_frame).value=text;
	var tttt=text.replace(/"/g,'qwq');
	baster(tttt+'|'+id_frame+'|'+id_section+'|'+cols+'|'+rows+'|'+width+'|'+lastie,'STable','tableblock'+id_frame);
	document.getElementById("tableblock"+id_frame).style.display='block';
	document.getElementById("newt"+id_frame).style.display='none';
	document.getElementById("redt"+id_frame).style.display='block';
	document.getElementById('numblock').value=0;
	var m=document.getElementById('m').value;
	m++;
	document.getElementById('m').value=m;
	document.getElementById('tablered'+id_frame).style.display='none';
	document.getElementById('divtable'+id_frame).style.display='none';	
	setTimeout("ShowSection1("+id_section+",1);",2000);
}
}
//Создать новую таблицу по указанным параметрам
function CreateTable(id_frame)
{
var tablenew;
tablenew='<table id="table'+id_frame+'" border="1" width="480" class="table"><tbody>';
document.getElementById('numblock').value=id_frame;
if (document.getElementById('countcols'+id_frame).value==2)
{
	if(document.getElementById('ifhead'+id_frame).value==1)
	{
		tablenew+='<tr height="2"><td id="win" width="50%"></td><td id="win" width="50%"></td></tr>'+
		'<tr height="100%"><th class=w id="cell1_1_'+id_frame+'"><div id="c1_1_'+id_frame+'" onclick="insTextTH(1,1,'+id_frame+')" style="width: 100%; height: 100%;"><br></div></th>'+
		'<th id="cell2_1_'+id_frame+'"><div id="c2_1_'+id_frame+'" onclick="insTextTH(2,1,'+id_frame+')" style="width: 100%; height: 100%;"><br></div></th></tr>'+
		'<tr height="100%"><td class=w id="cell1_2_'+id_frame+'"><div id="c1_2_'+id_frame+'" onclick="insTextCell(1,2,'+id_frame+')" style="width: 100%; height: 100%;"><br></div></td>'+
		'<td id="cell2_2_'+id_frame+'"><div id="c2_2_'+id_frame+'" onclick="insTextCell(2,2,'+id_frame+')" style="width: 100%; height: 100%;"><br></div></td>'+
		'<td onclick="DeleteRow(this,'+id_frame+')" id="win" width=2%><img src="img/crest.png" width="10px"></td></tr>'+
		'<tr height="100%"><td class=w id="cell1_3_'+id_frame+'"><div id="c1_3_'+id_frame+'" onclick="insTextCell(1,3,'+id_frame+')" style="width: 100%; height: 100%;"><br></div></td>'+
		'<td id="cell2_3_'+id_frame+'"><div id="c2_3_'+id_frame+'" onclick="insTextCell(2,3,'+id_frame+')" style="width: 100%; height: 100%;"><br></div></td>'+
		'<td onclick="DeleteRow(this,'+id_frame+')" id="win" width=2%><img src="img/crest.png" width="10px"></td></tr></tbody></table>';
	}
	else
	{
		tablenew+='<tr height="2"><td id="win" width="50%"></td><td id="win" width="50%"></td></tr>'+
		'<tr height="100%"><td class=w id="cell1_1_'+id_frame+'"><div id="c1_1_'+id_frame+'" onclick="insTextCell(1,1,'+id_frame+')" style="width: 100%; height: 100%;"><br></div></td>'+
		'<td id="cell2_1_'+id_frame+'"><div id="c2_1_'+id_frame+'" onclick="insTextCell(2,1,'+id_frame+')" style="width: 100%; height: 100%;"><br></div></td>'+
		'<td onclick="DeleteRow(this,'+id_frame+')" id="win" width=2%><img src="img/crest.png" width="10"></td></tr>'+
		'<tr height="100%"><td class=w id="cell1_2_'+id_frame+'"><div id="c1_2_'+id_frame+'" onclick="insTextCell(1,2,'+id_frame+')" style="width: 100%; height: 100%;"><br></div></td>'+
		'<td id="cell2_2_'+id_frame+'"><div id="c2_2_'+id_frame+'" onclick="insTextCell(2,2,'+id_frame+')" style="width: 100%; height: 100%;"><br></div></td>'+
		'<td onclick="DeleteRow(this,'+id_frame+')" id="win" width=2%><img src="img/crest.png" width="10"></td></tr>'+
		'<tr height="100%"><td class=w id="cell1_3_'+id_frame+'"><div id="c1_3_'+id_frame+'" onclick="insTextCell(1,3,'+id_frame+')" style="width: 100%; height: 100%;"><br></div></td>'+
		'<td id="cell2_3_'+id_frame+'"><div id="c2_3_'+id_frame+'" onclick="insTextCell(2,3,'+id_frame+')" style="width: 100%; height: 100%;"><br></div></td>'+
		'<td onclick="DeleteRow(this,'+id_frame+')" id="win" width=2%><img src="img/crest.png" width="10"></td></tr></tbody></table>';
	}
document.getElementById('temp_count_cols').value=2;
document.getElementById('countcols'+id_frame).value=2;
document.getElementById('countrows'+id_frame).value=3;
document.getElementById('temp_count_rows').value=3;
document.getElementById('s').value=133;
document.getElementById('two'+id_frame).style.display='block';
}
else
{
	if(document.getElementById('ifhead'+id_frame).value==1)
	{
		tablenew+='<tr height="2"><td id="win" width="33%"></td><td id="win" width="33%"></td><td id="win" width="33%"></td></tr>'+
		'<tr height="100%"><th class=w id="cell1_1_'+id_frame+'"><div id="c1_1_'+id_frame+'" onclick="insTextTH(1,1,'+id_frame+')" style="width: 100%; height: 100%;"><br></div></th>'+
		'<th id="cell2_1_'+id_frame+'"><div id="c2_1_'+id_frame+'" onclick="insTextTH(2,1,'+id_frame+')" style="width: 100%; height: 100%;"><br></div></th>'+
		'<th id="cell3_1_'+id_frame+'"><div id="c3_1_'+id_frame+'" onclick="insTextTH(3,1,'+id_frame+')" style="width: 100%; height: 100%;"><br></div></th></tr>'+
		'<tr height="100%"><td class=w id="cell1_2_'+id_frame+'"><div id="c1_2_'+id_frame+'" onclick="insTextCell(1,2,'+id_frame+')" style="width: 100%; height: 100%;"><br></div></td>'+
		'<td id="cell2_2_'+id_frame+'"><div id="c2_2_'+id_frame+'" onclick="insTextCell(2,2,'+id_frame+')" style="width: 100%; height: 100%;"><br></div></td>'+
		'<td id="cell3_2_'+id_frame+'"><div id="c3_2_'+id_frame+'" onclick="insTextCell(3,2,'+id_frame+')" style="width: 100%; height: 100%;"><br></div></td>'+
		'<td onclick="DeleteRow(this,'+id_frame+')" id="win" width=2%><img src="img/crest.png" width="10"></td></tr>'+
		'<tr height="100%"><td class=w id="cell1_3_'+id_frame+'" class=w><div id="c1_3_'+id_frame+'" onclick="insTextCell(1,3,'+id_frame+')" style="width: 100%; height: 100%;"><br></div></td>'+
		'<td id="cell2_3_'+id_frame+'"><div id="c2_3_'+id_frame+'" onclick="insTextCell(2,3,'+id_frame+')" style="width: 100%; height: 100%;"><br></div></td>'+
		'<td id="cell3_3_'+id_frame+'"><div id="c3_3_'+id_frame+'" onclick="insTextCell(3,3,'+id_frame+')" style="width: 100%; height: 100%;"><br></div></td>'+
		'<td onclick="DeleteRow(this,'+id_frame+')" id="win" width=2%><img src="img/crest.png" width="10"></td></tr></tbody></table>';
	}
	else
	{
		tablenew+='<tr height="2"><td id="win" width="33%"></td><td id="win" width="33%"></td><td id="win" width="33%"></td></tr>'+
		'<tr height="100%"><td class=w id="cell1_1_'+id_frame+'"><div id="c1_1_'+id_frame+'" onclick="insTextCell(1,1,'+id_frame+')" style="width: 100%; height: 100%;"><br></div></td>'+
		'<td id="cell2_1_'+id_frame+'"><div id="c2_1_'+id_frame+'" onclick="insTextCell(2,1,'+id_frame+')" style="width: 100%; height: 100%;"><br></div></td>'+
		'<td id="cell3_1_'+id_frame+'"><div id="c3_1_'+id_frame+'" onclick="insTextCell(3,1,'+id_frame+')" style="width: 100%; height: 100%;"><br></div></td>'+
		'<td onclick="DeleteRow(this,'+id_frame+')" id="win" width=2%><img src="img/crest.png" width="10"></td></tr>'+
		'<tr height="100%"><td class=w id="cell1_2_'+id_frame+'"><div id="c1_2_'+id_frame+'" onclick="insTextCell(1,2,'+id_frame+')" style="width: 100%; height: 100%;"><br></div></td>'+
		'<td id="cell2_2_'+id_frame+'"><div id="c2_2_'+id_frame+'" onclick="insTextCell(2,2,'+id_frame+')" style="width: 100%; height: 100%;"><br></div></td>'+
		'<td id="cell3_2_'+id_frame+'"><div id="c3_2_'+id_frame+'" onclick="insTextCell(3,2,'+id_frame+')" style="width: 100%; height: 100%;"><br></div></td>'+
		'<td onclick="DeleteRow(this,'+id_frame+')" id="win" width=2%><img src="img/crest.png" width="10"></td></tr>'+
		'<tr height="100%"><td class=w id="cell1_3_'+id_frame+'"><div id="c1_3_'+id_frame+'" onclick="insTextCell(1,3,'+id_frame+')" style="width: 100%; height: 100%;"><br></div></td>'+
		'<td id="cell2_3_'+id_frame+'"><div id="c2_3_'+id_frame+'" onclick="insTextCell(2,3,'+id_frame+')" style="width: 100%; height: 100%;"><br></div></td>'+
		'<td id="cell3_3_'+id_frame+'"><div id="c3_3_'+id_frame+'" onclick="insTextCell(3,3,'+id_frame+')" style="width: 100%; height: 100%;"><br></div></td>'+
		'<td onclick="DeleteRow(this,'+id_frame+')" id="win" width=2%><img src="img/crest.png" width="10"></td></tr></tbody></table>';
	}
document.getElementById('temp_count_cols').value=3;
document.getElementById('temp_count_rows').value=3;
document.getElementById('countcols'+id_frame).value=3;
document.getElementById('countrows'+id_frame).value=3;
document.getElementById('s').value=161;
document.getElementById('three'+id_frame).style.display='block';
}
//tablenew+="</table>";
document.getElementById("divtable"+id_frame).innerHTML=tablenew;   
document.getElementById('temp_table').value=document.getElementById("divtable"+id_frame).innerHTML
document.getElementById('parametre'+id_frame).style.display='none';
document.getElementById('tablered'+id_frame).style.display='block';
document.getElementById('divtable'+id_frame).style.display='block';
}
//Загрузка файлов на сервер
function uploadFile(x)
{
 window.open('uploader.php', 'upload','width=500px,height=180px,toolbar=0')
}
//Удалить ряд
function DeleteRow(obj,id_frame) 
{ 
	var dt = document.getElementById("table"+id_frame); 
	var num_tr=obj.parentNode.sectionRowIndex; 
	dt.deleteRow(num_tr) 
	var table=document.getElementById("divtable"+id_frame).innerHTML;
	document.getElementById("temp_table").value=table;	
} 
//вставить iframe  в ячейку
function insTextCell(i,j,id_frame)
{
	if(document.getElementById("newtextnull").value==0)
	{
	var text=document.getElementById("c"+i+"_"+j+"_"+id_frame).innerHTML;  
	if(text=='<br>')text='';
	document.getElementById("cell"+i+"_"+j+"_"+id_frame).innerHTML="<iframe width='100%' height='100px'  id='newtext' name='newtext'></iframe>"+
	"<button onclick=uploadFile("+id_frame+") id='subbutton2' onmouseover=this.style.cursor='pointer'>Прикрепить файл</button>"+
	"<button onclick=SaveTextCell("+i+","+j+","+id_frame+") id='subbutton2' onmouseover=this.style.cursor='pointer'>ОК</button>";
	var iframe;
	if (navigator.userAgent.match(/msie/i)) iframe = frames['newtext'].document;
	else if (navigator.userAgent.match(/gecko/i)) iframe = document.getElementById('newtext').contentDocument;
	else iframe = document.getElementById('newtext');
	document.getElementById('temp_area').value='newtext';
	setTimeout( function() { iframe.designMode = "on"; }, 10 );
	iframe.open();
	iframe.writeln(EditFieldHeaderOut); 
	iframe.writeln(text); 
	iframe.close();
	document.getElementById("newtextnull").value=1;
	}
}
//вставить iframe  в ячейку заголовка
function insTextTH(i,j,id_frame)
{
	if(document.getElementById("newtextnull").value==0)
	{
	var text=document.getElementById("c"+i+"_"+j+"_"+id_frame).innerHTML;  
	if(text=='<br>')text='';
	document.getElementById("cell"+i+"_"+j+"_"+id_frame).innerHTML="<iframe width='100%' height='100px'  id='newtext' name='newtext'></iframe>"+
	"<button onclick=SaveTextTH("+i+","+j+","+id_frame+") id='subbutton2' onmouseover=this.style.cursor='pointer' style='font-weight:normal'>ОК</button>";
	var iframe;
	if (navigator.userAgent.match(/msie/i)) iframe = frames['newtext'].document;
	else if (navigator.userAgent.match(/gecko/i)) iframe = document.getElementById('newtext').contentDocument;
	else iframe = document.getElementById('newtext');
	setTimeout( function() { iframe.designMode = "on"; }, 10 );
	iframe.open();
	iframe.writeln(EditFieldHeaderOut); 
	iframe.writeln(text); 
	iframe.close();
	document.getElementById("newtextnull").value=1;
	}
}

//сохранить, то что ввели в ячейку
function SaveTextCell(i,j,id_frame)
{
	var iframe;
	var text;    
	if (navigator.userAgent.match(/msie/i)) iframe = frames['newtext'].document;
	else if (navigator.userAgent.match(/gecko/i)) iframe = document.getElementById('newtext').contentDocument;
	else iframe = document.getElementById('newtext');
	text = iframe.body.innerHTML;
	if(text=='')text='<br>';
	iframe.designMode = 'off';
	document.getElementById("cell"+i+"_"+j+"_"+id_frame).innerHTML="<div id=c"+i+"_"+j+"_"+id_frame+" onclick=insTextCell("+i+","+j+","+id_frame+") style='width:100%;height:100%'>"+text+"</div>";
	document.getElementById("newtextnull").value=0;
}


//сохранить, то что ввели в ячейку
function SaveTextTH(i,j,id_frame)
{
	var iframe;
	var text;    
	if (navigator.userAgent.match(/msie/i)) iframe = frames['newtext'].document;
	else if (navigator.userAgent.match(/gecko/i)) iframe = document.getElementById('newtext').contentDocument;
	else iframe = document.getElementById('newtext');
	text = iframe.body.innerHTML;
	if(text=='')text='<br>';
	iframe.designMode = 'off';
	document.getElementById("cell"+i+"_"+j+"_"+id_frame).innerHTML="<div id=c"+i+"_"+j+"_"+id_frame+" onclick=insTextTH("+i+","+j+","+id_frame+") style='width:100%;height:100%'>"+text+"</div>";
	document.getElementById("newtextnull").value=0;
}

//вставить iframe  в ячейку заголовка
function insTextSCA(i)
{
	if(document.getElementById("newtextnull").value==0)
	{
	var text=document.getElementById("sc"+i).innerHTML;  
	if(text=='<br>')text='';
	document.getElementById("sca"+i).innerHTML="<input type=text width='100%' height='100px'  id='newtext' name='newtext' value='"+text+"'>"+
	"<button onclick=SaveTextSCA("+i+") id='subbutton2' onmouseover=this.style.cursor='pointer' style='font-weight:normal;'>ОК</button>";
	var iframe;
//	if (navigator.userAgent.match(/msie/i)) iframe = frames['newtext'].document;
//	else if (navigator.userAgent.match(/gecko/i)) 
/*	iframe = document.getElementById('newtext').contentDocument;
	else iframe = document.getElementById('newtext');
	setTimeout( function() { iframe.designMode = "on"; }, 10 );
	iframe.open();
	iframe.writeln(EditFieldHeaderOut); 
	iframe.writeln(text); 
	iframe.close();*/
	document.getElementById("newtextnull").value=1;
	}
}

//сохранить, то что ввели в ячейку
function SaveTextSCA(i)
{
	var iframe;
	var text;    
//	if (navigator.userAgent.match(/msie/i)) iframe = frames['newtext'].document;
//	else if (navigator.userAgent.match(/gecko/i)) 
	iframe = document.getElementById('newtext');
//	else iframe = document.getElementById('newtext');
	text = iframe.value;
	if(text=='')text='<br>';
	iframe.designMode = 'off';
	var t="<div id=sc"+i+" onclick=insTextSCA("+i+") style='width:100%;height:100%;";
	if((i==8 || i==5))
	{	
		var tttt=text.substr(0,1);
		if(tttt=='-') {t+="color:red";}
		if(tttt!='-') {t+="color:green";}
	}
	t+="'>"+text+"</div>";
	document.getElementById("sca"+i).innerHTML=t;
	document.getElementById("newtextnull").value=0;
	baster(text+'|'+i,'sca_fond','empty');
}
//запрос на удаление раздела
function feedbackSubmit()
{
	if(confirm('Точно удалить раздел?')==true)
	{return true;}
	else {return false;}
}

//вставка строки
function InsRow(id_frame)
{
if(document.getElementById("newtextnull").value==0)
{
var i,table;
var td_cols=document.getElementById("temp_count_cols").value;
var td_rows=document.getElementById("temp_count_rows").value;
var len=document.getElementById("divtable"+id_frame).innerHTML.length;
table=document.getElementById("divtable"+id_frame).innerHTML.substr(0,len-16);
table+='<tr height=100%>';
td_rows++;
	for (i=1;i<=td_cols;i++)
	{
	table+="<td ";
	if(i==1)table+=" class=w ";
	table+="id=cell"+i+"_"+td_rows+"_"+id_frame+"><div id=c"+i+"_"+td_rows+"_"+id_frame+
	" onclick=insTextCell("+i+","+td_rows+","+id_frame+") style='width:100%;height:100%'><br></div></td>";
	}
	table+='<td onclick=DeleteRow(this,'+id_frame+') id=win width="2%"><img src=img/crest.png width=10px></td>'+
	'</tr></table>';
document.getElementById("temp_count_rows").value=td_rows;
document.getElementById("divtable"+id_frame).innerHTML=table;
document.getElementById("temp_table").value=table;
}
}
//регулируем ширину столбцов для двух 
function setWidth(l) 
{
if(document.getElementById("newtextnull").value==0)
{
	var id_frame=document.getElementById('numblock').value;
	if(id_frame!=0)
	{
	var m,s=133,r=460-l,i;
	m=document.getElementById('s').value;
	//alert(id_frame);
		var t = document.getElementById('divtable'+id_frame).innerHTML;
		var len=document.getElementById('divtable'+id_frame).innerHTML.length;
		if(window.navigator.appName == "Microsoft Internet Explorer")for(i=1;i<=4;i++) m++;
		else 
		{for(i=1;i<=10;i++) m++;}
		if(id_frame>=10)m++;
		if(id_frame>=100)m++;
		var tablenew="<table id=table"+id_frame+" width=480px border=1 class=table>";
		t=t.substr(m,len);
		l=Math.round(l/5);r=Math.round(r/5);
		if(l<10)s--;
		if(r<10)s--;
		document.getElementById('s').value=s;
		tablenew+='<tr height=5px><td width='+l+'% id=win></td><td width='+r+'% id=win></td></tr>';
		tablenew+=t;
		document.getElementById('divtable'+id_frame).innerHTML=tablenew;	
		document.getElementById("temp_table").value=document.getElementById('divtable'+id_frame).innerHTML;
	}
}
}
//регулируем ширину столбцов для трех
function setWidth3(l,r) 
{
if(document.getElementById("newtextnull").value==0)
{
	var m,s=161,n=460-r,i;
	r=r-l;
	m=document.getElementById('s').value;
	if(window.navigator.appName == "Microsoft Internet Explorer")for(i=1;i<=8;i++) m++;
	else 
	for(i=1;i<=12;i++) m++;
	var id_frame=document.getElementById('numblock').value;
	if(id_frame!=0)
	{
		var t = document.getElementById('divtable'+id_frame).innerHTML;
		var len=document.getElementById('divtable'+id_frame).innerHTML.length;
		if(id_frame>=10)m++;
		if(id_frame>=100)m++;
		var tablenew="<table id=table"+id_frame+" width=480px border=1 class=table>";
		l=Math.round(l/5);r=Math.round(r/5);n=Math.round(n/5);
		if(l<10){s--;if(window.navigator.appName == "Microsoft Internet Explorer")s--;}
		if(r<10){s--;if(window.navigator.appName == "Microsoft Internet Explorer")s--;}
		if(n<10){s--;if(window.navigator.appName == "Microsoft Internet Explorer")s--;}		
		if(l==0){if(window.navigator.appName == "Microsoft Internet Explorer")s--;}
		if(r==0){if(window.navigator.appName == "Microsoft Internet Explorer")s--;}
		if(n==0){if(window.navigator.appName == "Microsoft Internet Explorer")s--;}
		t=t.substr(m,len); 
		document.getElementById('s').value=s;
		tablenew+='<tr height=5px><td width='+l+'% id=win></td><td width='+r+'% id=win></td><td width='+n+'% id=win></td></tr>';
		tablenew+=t;
		document.getElementById('divtable'+id_frame).innerHTML=tablenew;	
		document.getElementById("temp_table").value=document.getElementById('divtable'+id_frame).innerHTML;
	}
	}
}
//Ползаем ползунком 1
function insScroll(id)
{
//<![CDATA[
if(document.getElementById('countcols'+id).value==2)
{
trackbar.getObject('two'+id).init({
	onMove : function() {
	setWidth(this.leftValue);
	},
	dual : false, 
	width : 445,
	leftLimit : 10, 
	leftValue : 230,
	rightLimit : 455, 
	rightValue : 230, 
	hehe : ":-)"
},'two'+id);
}
else
{
	trackbar.getObject('one'+id).init({
	onMove : function() {
	setWidth3(this.leftValue,this.rightValue);
	},
	width : 445, // px
	leftLimit : 10, // unit of value
	leftValue : 153, // unit of value
	rightLimit : 450, // unit of value
	rightValue : 306, // unit of value
	roundUp : 1, // unit of value
	hehe : ":-)"
},'three'+id);
}
}
//Ползаем ползунком 2
function insScroll3(id)
{
if(document.getElementById('countcols'+id).value==2)
{
trackbar.getObject('two'+id).init({
	onMove : function() {
	setWidth(this.leftValue);
	},
	dual : false, 
	width : 445,
	leftLimit : 10, 
	leftValue : 230,
	rightLimit : 450, 
	rightValue : 230, 
	hehe : ":-)"
},'two'+id);
}
else
{
	trackbar.getObject('one'+id).init({
	onMove : function() {
	setWidth3(this.leftValue,this.rightValue);
	},
	width : 445, // px
	leftLimit : 10, // unit of value
	leftValue : 153, // unit of value
	rightLimit : 450, // unit of value
	rightValue : 306, // unit of value
	roundUp : 1, // unit of value
	hehe : ":-)"
},'three'+id);
}
}
//Сперто у какого-то очень умного человека
/***************************************************************
 *  JS-TrackBar
 *
 *   Copyright (C) 2008 by Alexander Burtsev - webew.ru
 *   and abarmot - http://abarmot.habrahabr.ru/
 *   desing: Светлана Соловьева - http://my.mail.ru/bk/concur/
 *
 *  This code is a public domain.
 ***************************************************************/

var trackbar = { // NAMESPACE
	archive : {},
	getObject : function(id) {
		if (typeof this.archive[id] == "undefined") {
			this.archive[id] = new this.hotSearch(id);
		}
		return this.archive[id];
	}
};

trackbar.hotSearch = function(id) { // Constructor
	// Vars
	this.id = id;
	
	this.leftWidth = 0; // px
	this.rightWidth = 0; // px
	this.width = 0; // px
	this.intervalWidth = 0; // px
	
	this.leftLimit = 0;
	this.leftValue = 0;
	this.rightLimit = 0;
	this.rightValue = 0;
	this.valueInterval = 0;
	this.widthRem = 6;
	this.valueWidth = 0;
	this.roundUp = 0;
	
	this.x0 = 0; this.y0 = 0;
	this.blockX0 = 0; 
	this.rightX0 = 0; 
	this.leftX0 = 0;
	// Flags
	this.dual = true;
	this.moveState = false;
	this.moveIntervalState = false;
	this.debugMode = false;
	this.clearLimits = false;
	this.clearValues = false;
	this.nodeInit = false;
	// Handlers
	this.onMove = null;
	// Nodes
	this.leftBlock = null;
	this.rightBlock = null;
	this.leftBegun = null;
	this.rightBegun = null;
	this.centerBlock = null;
	this.itWasMove = false;
}

trackbar.hotSearch.prototype = {
// Const
	ERRORS : {
		1 : "Ошибка при инициализации объекта",
		2 : "Левый бегунок не найден",
		3 : "Правый бегунок не найден",
		4 : "Левая область ресайза не найдена",
		5 : "Правая область ресайза не найдена",
		6 : "Не задана ширина области бегунка",
		7 : "Не указано максимальное изменяемое значение",
		8 : "Не указана функция-обработчик значений",
		9 : "Не указана область клика"
	},
	LEFT_BLOCK_PREFIX : "leftBlock_",
	RIGHT_BLOCK_PREFIX : "rightBlock_",
	LEFT_BEGUN_PREFIX : "leftBegun_",
	RIGHT_BEGUN_PREFIX : "rightBegun_",
	CENTER_BLOCK_PREFIX : "centerBlock_",
// Methods
	// Default
	gebi : function(id) {
		return document.getElementById(id);
	},
	addHandler : function(object, event, handler, useCapture) {
		if (object.addEventListener) {
			object.addEventListener(event, handler, useCapture ? useCapture : false);
		} else if (object.attachEvent) {
			object.attachEvent('on' + event, handler);
		} else alert(this.errorArray[9]);
	},
	defPosition : function(event) { 
		var x = y = 0; 
		if (document.attachEvent != null) {
			x = window.event.clientX + document.documentElement.scrollLeft + document.body.scrollLeft; 
			y = window.event.clientY + document.documentElement.scrollTop + document.body.scrollTop; 
		} 
		if (!document.attachEvent && document.addEventListener) { // Gecko 
			x = event.clientX + window.scrollX; 
			y = event.clientY + window.scrollY; 
		} 
		return {x:x, y:y}; 
	},
	absPosition : function(obj) { 
		var x = y = 0; 
		while(obj) { 
			x += obj.offsetLeft; 
			y += obj.offsetTop; 
			obj = obj.offsetParent; 
		} 
		return {x:x, y:y}; 
	},
	/* 
		Method domReady - Copyright http://ajaxian.com/
		More fun with DOMContentLoaded
		http://ajaxian.com/archives/more-fun-with-domcontentloaded
	*/
	domReady : function(i) {
		var u =navigator.userAgent;
		var e=/*@cc_on!@*/false;
		var st = setTimeout;
		if (/webkit/i.test(u)) {
			st(
				function() {
					var dr=document.readyState;
					if(dr=="loaded"||dr=="complete"){
						i()
					} else {
						st(arguments.callee,10);
					}
				},
				10
			);
		} else if ((/mozilla/i.test(u)&&!/(compati)/.test(u)) || (/opera/i.test(u))) {
			document.addEventListener("DOMContentLoaded", i, false);
		} else if (e) {(
			function(){
				var t=document.createElement('doc:rdy');
				try {
					t.doScroll('left');
					i();
					t=null;
				} catch(e) {
					st(arguments.callee,0);
				}
			})();
		} else {
			window.onload=i;
		}
	},
	// Common
	debug : function(keys) {
		if (!this.debugMode) return;
		var mes = "";
		for (var i = 0; i < keys.length; i++) mes += this.ERRORS[keys[i]] + " : ";
		mes = mes.substring(0, mes.length - 3);
		alert(mes);
	},
	init : function(hash, node) {
		if (typeof node != "undefined" && !this.nodeInit) {
			this.nodeInit = true;
			var _this = this;
			this.domReady(
				function() {_this.init(hash, node)}
			);
			return;
		}
		if (typeof node == "string") node = this.gebi(node);
		else node = false;
		try {
			this.dual = typeof hash.dual != "undefined" ? !!hash.dual : this.dual;
			this.leftLimit = hash.leftLimit || this.leftLimit;
			this.rightLimit = hash.rightLimit || this.rightLimit;
			this.width = hash.width || this.width;
			this.onMove = hash.onMove || this.onMove;
			this.clearLimits = hash.clearLimits || this.clearLimits;
			this.clearValues = hash.clearValues || this.clearValues;
			this.roundUp = hash.roundUp || this.roundUp;
			// HTML Write
			var cc=this.width+5;
			var code = '<table' + (cc ? ' style="width:'+cc+'px;"' : '') + 'class="trackbar" onSelectStart="return false;">\
				<tr>\
					<td class="l"><div id="leftBlock_' + this.id + '"><span  style="display:none"></span><span class="limit"  style="display:none"></span><img id="leftBegun_' + this.id + '" ondragstart="return false;" src="imgtrackbar/b_l.gif" width="12" height="18" alt="" /></div></td>\
					<td class="c" id="centerBlock_' + this.id + '"></td>\
					<td class="r"><div id="rightBlock_' + this.id + '"><span  style="display:none"></span><span class="limit"  style="display:none"></span><img id="rightBegun_' + this.id + '" ondragstart="return false;" src="imgtrackbar/b_r.gif" width="11" height="18" alt="" /></div></td>\
				</tr>\
			</table>';
			if (node) node.innerHTML = code;
			else document.write(code)
			// Is all right?
			if (this.onMove == null) {
				this.debug([1,8]);
					return;
			}
			// ---
			this.leftBegun = this.gebi(this.LEFT_BEGUN_PREFIX + this.id);
			if (this.leftBegun == null) {
				this.debug([1,2]);
					return;
			}
			this.rightBegun = this.gebi(this.RIGHT_BEGUN_PREFIX + this.id);
			if (this.rightBegun == null) {
				this.debug([1,3]);
					return;
			}
			this.leftBlock = this.gebi(this.LEFT_BLOCK_PREFIX + this.id);
			if (this.leftBlock == null) {
				this.debug([1,4]);
					return;
			}
			this.rightBlock = this.gebi(this.RIGHT_BLOCK_PREFIX + this.id);
			if (this.rightBlock == null) {
				this.debug([1,5]);
					return;
			}
			this.centerBlock = this.gebi(this.CENTER_BLOCK_PREFIX + this.id);
			if (this.centerBlock == null) {
				this.debug([1,9]);
					return;
			}
			// ---
			if (!this.width) {
				this.debug([1,6]);
					return;
			}
			if (!this.rightLimit) {
				this.debug([1,7]);
					return;
			}
			// Set default
			this.valueWidth = this.width - 2 * this.widthRem;
			this.rightValue = hash.rightValue || this.rightLimit;
			this.leftValue = hash.leftValue || this.leftLimit;
			if (!this.dual) this.rightValue = this.leftValue;
			this.valueInterval = this.rightLimit - this.leftLimit;
			this.leftWidth = parseInt((this.leftValue - this.leftLimit) / this.valueInterval * this.valueWidth) + this.widthRem;
			this.rightWidth = this.valueWidth - parseInt((this.rightValue - this.leftLimit) / this.valueInterval * this.valueWidth) + this.widthRem;
			// Set limits
			if (!this.clearLimits) {
				this.leftBlock.firstChild.nextSibling.innerHTML = this.leftLimit;
				this.rightBlock.firstChild.nextSibling.innerHTML = this.rightLimit;
			}
			// Do it!
			this.setCurrentState();
			this.onMove();
			// Add handers
			var _this = this;
			this.addHandler (
				document,
				"mousemove",
				function(evt) {
					if (_this.moveState) _this.moveHandler(evt);
					if (_this.moveIntervalState) _this.moveIntervalHandler(evt);
				}
			);
			this.addHandler (
				document,
				"mouseup",
				function() {
					_this.moveState = false;
					_this.moveIntervalState = false;
				}
			);
			this.addHandler (
				this.leftBegun,
				"mousedown",
				function(evt) {
					evt = evt || window.event;
					if (evt.preventDefault) evt.preventDefault();
					evt.returnValue = false;
					_this.moveState = "left";
					_this.x0 = _this.defPosition(evt).x;
					_this.blockX0 = _this.leftWidth;
				}
			);
			this.addHandler (
				this.rightBegun,
				"mousedown",
				function(evt) {
					evt = evt || window.event;
					if (evt.preventDefault) evt.preventDefault();
					evt.returnValue = false;
					_this.moveState = "right";
					_this.x0 = _this.defPosition(evt).x;
					_this.blockX0 = _this.rightWidth;
				}
			);
			this.addHandler (
				this.centerBlock,
				"mousedown",
				function(evt) {
					evt = evt || window.event;
					if (evt.preventDefault) evt.preventDefault();
					evt.returnValue = false;
					_this.moveIntervalState = true;
					_this.intervalWidth = _this.width - _this.rightWidth - _this.leftWidth;
					_this.x0 = _this.defPosition(evt).x;
					_this.rightX0 = _this.rightWidth; 
					_this.leftX0 = _this.leftWidth;
				}
			),
			this.addHandler (
				this.centerBlock,
				"click",
				function(evt) {
					if (!_this.itWasMove) _this.clickMove(evt);
					_this.itWasMove = false;
				}
			);
			this.addHandler (
				this.leftBlock,
				"click",
				function(evt) {
					if (!_this.itWasMove)_this.clickMoveLeft(evt);
					_this.itWasMove = false;
				}
			);
			this.addHandler (
				this.rightBlock,
				"click",
				function(evt) {
					if (!_this.itWasMove)_this.clickMoveRight(evt);
					_this.itWasMove = false;
				}
			);
		} catch(e) {this.debug([1]);}
	},
	clickMoveRight : function(evt) {
		evt = evt || window.event;
		if (evt.preventDefault) evt.preventDefault();
		evt.returnValue = false;
		var x = this.defPosition(evt).x - this.absPosition(this.rightBlock).x;
		var w = this.rightBlock.offsetWidth;
		if (x <= 0 || w <= 0 || w < x || (w - x) < this.widthRem) return;
		this.rightWidth = (w - x);
		this.rightCounter();

		this.setCurrentState();
		this.onMove();
	},
	clickMoveLeft : function(evt) {
		evt = evt || window.event;
		if (evt.preventDefault) evt.preventDefault();
		evt.returnValue = false;
		var x = this.defPosition(evt).x - this.absPosition(this.leftBlock).x;
		var w = this.leftBlock.offsetWidth;
		if (x <= 0 || w <= 0 || w < x || x < this.widthRem) return;
		this.leftWidth = x;
		this.leftCounter();

		this.setCurrentState();
		this.onMove();
	},
	clickMove : function(evt) {
		evt = evt || window.event;
		if (evt.preventDefault) evt.preventDefault();
		evt.returnValue = false;
		var x = this.defPosition(evt).x - this.absPosition(this.centerBlock).x;
		var w = this.centerBlock.offsetWidth;
		if (x <= 0 || w <= 0 || w < x) return;
		if (x >= w / 2) {
			this.rightWidth += (w - x);
			this.rightCounter();
		} else {
			this.leftWidth += x;
			this.leftCounter();
		}
		this.setCurrentState();
		this.onMove();
	},
	setCurrentState : function() {
		this.leftBlock.style.width = this.leftWidth + "px";
		if (!this.clearValues) this.leftBlock.firstChild.innerHTML = (!this.dual && this.leftWidth > this.width / 2) ? "" : this.leftValue;
		if(!this.dual) {
			var x = this.leftBlock.firstChild.offsetWidth;
			this.leftBlock.firstChild.style.right = (this.widthRem * (1 - 2 * (this.leftWidth - this.widthRem) / this.width) - ((this.leftWidth - this.widthRem) * x / this.width)) + 'px';
		}
		this.rightBlock.style.width = this.rightWidth + "px";
		if (!this.clearValues) this.rightBlock.firstChild.innerHTML = (!this.dual && this.rightWidth >= this.width / 2) ? "" : this.rightValue;
		if(!this.dual) {
			var x = this.rightBlock.firstChild.offsetWidth;
			this.rightBlock.firstChild.style.left = (this.widthRem * (1 - 2 * (this.rightWidth - this.widthRem) / this.width) - ((this.rightWidth - this.widthRem) * x / this.width)) + 'px';
		}
	},
	moveHandler : function(evt) {
		this.itWasMove = true;
		evt = evt || window.event;
		if (evt.preventDefault) evt.preventDefault();
		evt.returnValue = false;
		if (this.moveState == "left") {
			this.leftWidth = this.blockX0 + this.defPosition(evt).x - this.x0;
			this.leftCounter();
		}
		if (this.moveState == "right") {
			this.rightWidth = this.blockX0 + this.x0 - this.defPosition(evt).x;
			this.rightCounter();
		}
		this.setCurrentState();
		this.onMove();
	},
	moveIntervalHandler : function(evt) {
		this.itWasMove = true;
		evt = evt || window.event;
		if (evt.preventDefault) evt.preventDefault();
		evt.returnValue = false;
		var dX = this.defPosition(evt).x - this.x0;
		if (dX > 0) {
			this.rightWidth = this.rightX0 - dX > this.widthRem ? this.rightX0 - dX : this.widthRem;
			this.leftWidth = this.width - this.rightWidth - this.intervalWidth;
		} else {
			this.leftWidth = this.leftX0 + dX > this.widthRem ? this.leftX0 + dX : this.widthRem;
			this.rightWidth = this.width - this.leftWidth - this.intervalWidth;
		}
		this.rightCounter();
		this.leftCounter();
		this.setCurrentState();
		this.onMove();
	},
	updateRightValue : function(rightValue) {
		try {
			this.rightValue = parseInt(rightValue);
			this.rightValue = this.rightValue < this.leftLimit ? this.leftLimit : this.rightValue;
			this.rightValue = this.rightValue > this.rightLimit ? this.rightLimit : this.rightValue;
			if (this.dual) {
				this.rightValue = this.rightValue < this.leftValue ? this.leftValue : this.rightValue;
			} else this.leftValue = this.rightValue;
			this.rightWidth = this.valueWidth - parseInt((this.rightValue - this.leftLimit) / this.valueInterval * this.valueWidth) + this.widthRem;
			this.rightWidth = isNaN(this.rightWidth) ? this.widthRem : this.rightWidth;
			if (!this.dual) this.leftWidth = this.width - this.rightWidth;
			this.setCurrentState();
		} catch(e) {}
	},
	rightCounter : function() {
		if (this.dual) {
			this.rightWidth = this.rightWidth > this.width - this.leftWidth ? this.width - this.leftWidth : this.rightWidth;
			this.rightWidth = this.rightWidth < this.widthRem ? this.widthRem : this.rightWidth;
			this.rightValue = this.leftLimit + this.valueInterval - parseInt((this.rightWidth - this.widthRem) / this.valueWidth * this.valueInterval);
			if (this.roundUp) this.rightValue = parseInt(this.rightValue / this.roundUp) * this.roundUp;
			if (this.leftWidth + this.rightWidth >= this.width) this.rightValue = this.leftValue;
		} else {
			this.rightWidth = this.rightWidth > (this.width - this.widthRem) ? this.width - this.widthRem : this.rightWidth;
			this.rightWidth = this.rightWidth < this.widthRem ? this.widthRem : this.rightWidth;
			this.leftWidth = this.width - this.rightWidth;
			this.rightValue = this.leftLimit + this.valueInterval - parseInt((this.rightWidth - this.widthRem) / this.valueWidth * this.valueInterval);
			if (this.roundUp) this.rightValue = parseInt(this.rightValue / this.roundUp) * this.roundUp;
			this.leftValue = this.rightValue;
		}
	},
	updateLeftValue : function(leftValue) {
		try {
			this.leftValue = parseInt(leftValue);
			this.leftValue = this.leftValue < this.leftLimit ? this.leftLimit : this.leftValue;
			this.leftValue = this.leftValue > this.rightLimit ? this.rightLimit : this.leftValue;
			if (this.dual) {
				this.leftValue = this.rightValue < this.leftValue ? this.rightValue : this.leftValue;
			} else this.rightValue = this.leftValue;
			this.leftWidth = parseInt((this.leftValue - this.leftLimit) / this.valueInterval * this.valueWidth) + this.widthRem;
			this.leftWidth = isNaN(this.leftWidth) ? this.widthRem : this.leftWidth;
			if (!this.dual) this.rightWidth = this.width - this.leftWidth;
			this.setCurrentState();
		} catch(e) {}
	},
	leftCounter : function() {
		if (this.dual) {
			this.leftWidth = this.leftWidth > this.width - this.rightWidth ? this.width - this.rightWidth : this.leftWidth;
			this.leftWidth = this.leftWidth < this.widthRem ? this.widthRem : this.leftWidth;
			this.leftValue = this.leftLimit + parseInt((this.leftWidth - this.widthRem) / this.valueWidth * this.valueInterval);
			if (this.roundUp) this.leftValue = parseInt(this.leftValue / this.roundUp) * this.roundUp;
			if (this.leftWidth + this.rightWidth >= this.width) this.leftValue = this.rightValue;
		} else {
			this.leftWidth = this.leftWidth > (this.width - this.widthRem) ? this.width - this.widthRem : this.leftWidth;
			this.leftWidth = this.leftWidth < this.widthRem ? this.widthRem : this.leftWidth;
			this.rightWidth = this.width - this.leftWidth;
			this.leftValue = this.leftLimit + parseInt((this.leftWidth - this.widthRem) / this.valueWidth * this.valueInterval);
			if (this.roundUp) this.leftValue = parseInt(this.leftValue / this.roundUp) * this.roundUp;
			this.rightValue = this.leftValue;
		}
	}
}

