// Обновление капчи
function reloadCaptcha(captcha_req) {
    document.images['captcha'].src =
        '/captcha/image?' + captcha_req + Math.random()
}

// Смена основной фотографии
function imageChange(url, w, h) {
  document.getElementById("photobig").src = url;
  document.getElementById("photobig").width = w;
  document.getElementById("photobig").height = h;
}

//Ссылка в новом окне
function open_window(link,w,h) {
 var win = "width="+w+",height="+h+",menubar=no,location=no,resizable=no,scrollbars=yes";
 newWin = window.open(link,'newWin'+1000+h,win);
}

//Картинка в новом окне
function imagePopup(url, w, h, iw, ih) {
    var imgWin = window.open('', 'url', "width="+w+", height="+h+", menubar=no,location=no,resizable=yes,scrollbars=yes");
    imgWin.document.write(
        '<html>'+
            '<head>'+
                '<title>Генплан коттеджного посёлка</title>'+
            '</head>'+
        '<body style="margin: 0px;">'+
            '<img src="'+url+'" width="'+iw+'" height="'+ih+'" />'+
        '</body>'+
        '</html>'
        );
    imgWin.document.close();
}

var countOfFields = 1; // Текущее число полей
var curFieldNameId = 1; // Уникальное значение для атрибута name
var maxFieldLimit = 8; // Максимальное число возможных полей

function deleteField(a) {
    var contDiv = a.parentNode; // Получаем доступ к ДИВу, содержащему поле
    contDiv.parentNode.removeChild(contDiv); // Удаляем этот ДИВ из DOM-дерева
    countOfFields--; // Уменьшаем значение текущего числа полей
    return false; // Возвращаем false, чтобы не было перехода по сслыке
}

function addField() {
    if (countOfFields >= maxFieldLimit) { // Проверяем максимум
        alert("Максимальное число фотографий " + maxFieldLimit);
        return false;
    }
    // Увеличиваем текущее значение числа полей
    countOfFields++; // Увеличиваем текущее значение числа полей
    curFieldNameId++; // Увеличиваем ID
    var div = document.createElement("div"); // Создаем элемент ДИВ
    // Добавляем HTML-контент с пом. свойства innerHTML
    div.innerHTML = "<input type=\"file\" name=\"Image_" + curFieldNameId + "\" /> <a onclick=\"return deleteField(this)\" href=\"#\" class=\"white12\">удалить</a>";
    // div.innerHTML = "<input name=\"name_" + curFieldNameId + "\" type=\"text\" /> <a onclick=\"return deleteField(this)\" href=\"#\">[X]</a>";
    document.getElementById("parentId").appendChild(div); // Добавляем новый узел в конец списка полей
    return false; // Возвращаем false, чтобы не было перехода по сслыке
}

function showAddBlock(el)
{
  if (el.options[el.selectedIndex].value=='cottage') {
      document.getElementById('add_ext_cottage').style.display='block';
      document.getElementById('add_ext_area').style.display='none';
      document.getElementById('add_ext_village').style.display='none';
  }
  if (el.options[el.selectedIndex].value=='area') {
      document.getElementById('add_ext_cottage').style.display='none';
      document.getElementById('add_ext_area').style.display='block';
      document.getElementById('add_ext_village').style.display='none';
  }
  if (el.options[el.selectedIndex].value=='village') {
      document.getElementById('add_ext_cottage').style.display='none';
      document.getElementById('add_ext_area').style.display='none';
      document.getElementById('add_ext_village').style.display='block';
  }
}

function showFindBlock(el)
{
  if (el.options[el.selectedIndex].value=='cottage') {
      document.getElementById('add_ext_cottage').style.display='block';
      document.getElementById('add_ext_area').style.display='none';
  }
  if (el.options[el.selectedIndex].value=='area') {
      document.getElementById('add_ext_cottage').style.display='none';
      document.getElementById('add_ext_area').style.display='block';
  }
}



