var pics = 0;
newpics = new Array(100);
newpicnodes = new Array(100);

// стили
var  s_checkbox=" style=\"margin-bottom: 5px;\"";
var  s_span=" style=\"margin-left: 5px; margin-right: 12px; position: relative; top: -7px;\"";
var  s_input_url=" style=\"margin: 0px 0px 0px 5px; width: 181px; font-family:Tahoma,Verdana,Arial; font-size:12px;\"";
var  s_input_file=" style=\"margin: 0px 0px 0px 5px; width: 250px; font-family:Tahoma,Verdana,Arial; font-size:12px;\"";
var  s_urlcomment=" style=\"margin: 0px 0px 0px 0px;font-family:Tahoma,Verdana,Arial; font-size:12px;\"";
var  s_filecomment=" style=\"margin: 0px 0px 0px 0px;font-family:Tahoma,Verdana,Arial; font-size:12px;\"";
  
function n_pics() 
{
	n_pics=document.createElement("val"); // создаем элемент - текущее количество филиалов
}

// добавление картинки с диска
function addfilepic() 
{
  div=document.getElementById("pics");
  button=document.getElementById("dellastpic");
  pics++;

	// чекбокс для отметки
	//newpics[pics]="<input type=\"checkbox\" id=\"r" + pics + "\" " + s_checkbox + ">";
	
	newpics[pics]="<table><tr>";
	// поле для ввода картинки
	newpics[pics]+="<td style=\"width: 260px;\"><input name=\"pic" + pics + "\" ";
	newpics[pics]+="size=\"33\"  type=\"file\" id=\"pic" + pics + "\"" + s_input_file + "></td>";		
	// поле для ввода комментария к картинке
	newpics[pics]+="<td style=\"\"><input name=\"comment" + pics + "\" ";
	newpics[pics]+="size=\"50\" type=\"text\" id=\"comment" + pics + "\"" + s_filecomment + "></td>";
	newpics[pics]+="<input type=\"hidden\" name=\"type" + pics + "\" value=\"file\">";
	newpics[pics]+="</tr></table>";
  
  newpicnodes[pics]=document.createElement("span");
  newpicnodes[pics].innerHTML=newpics[pics];
  div.insertBefore(newpicnodes[pics], button);
  
  // запоминаем текущее количество картинок
  n_pics.innerHTML="<input type=\"hidden\" name=\"n_pics\" value=\"" + pics + "\">";
  div.insertBefore(n_pics, button);
}

// добавление картинки из сети
function addurlpic() 
{
  div=document.getElementById("pics");
  button=document.getElementById("dellastpic");
  pics++;

	// чекбокс для отметки
	//newpics[pics]="<input type=\"checkbox\" id=\"r" + pics + "\" " + s_checkbox + ">";
	// поле для ввода картинки
	
	newpics[pics]="<table><tr>";
	newpics[pics]+='<td style=\"width: 260px\;"><input name="pic' + pics + '" value="http://" ';
	newpics[pics]+=" type=\"text\" id=\"pic" + pics + "\"" + s_input_url + "></td>";		
	// поле для ввода комментария к картинке
	newpics[pics]+="<td style=\"\"><input name=\"comment" + pics + "\" ";
	newpics[pics]+="size=\"50\" type=\"text\" id=\"comment" + pics + "\"" + s_urlcomment + "></td>";
	newpics[pics]+="<input type=\"hidden\" name=\"type" + pics + "\" value=\"url\">";
	newpics[pics]+="</tr></table>";
  
  newpicnodes[pics]=document.createElement("span");
  newpicnodes[pics].innerHTML=newpics[pics];
  div.insertBefore(newpicnodes[pics], button);
  
  // запоминаем текущее количество картинок
  n_pics.innerHTML="<input type=\"hidden\" name=\"n_pics\" value=\"" + pics + "\">";
  div.insertBefore(n_pics, button);
}

function delpic() 
{
	div = document.getElementById("pics");
	button = document.getElementById("dellastpic");
	
	// удаляем последнюю картинку
	if (pics>=1)
	{
		newpics[pics] = '';
		newpicnodes[pics].innerHTML = newpics[pics];
		div.insertBefore(newpicnodes[pics], button);
		pics = pics - 1;
	
		// запоминаем текущее количество картинок
		n_pics.innerHTML="<input type=\"hidden\" name=\"n_pics\" value=\"" + pics + "\">";
		div.insertBefore(n_pics, button);
		if (pics == 0) addfilepic();
	}
}
