function select_type()
{
  var select = document.forms[1].stype_id;
  var stype_id = select.options[select.selectedIndex].value;
  url = "index.php3?stype_id="+stype_id;
  window.location.href=url;
}

function select_type2(sbrand_id)
{
  var forma = document.forms[0];
  var type_id = forma.type_id.options[forma.type_id.selectedIndex].value;

  forma.brand_id.length = 0;

  for (var i = 0; i < a1.length; i++)
  {
    if (a1[i] == type_id)
    {
      if (sbrand_id == a2[i])
      {
        forma.brand_id.options[forma.brand_id.length] = new Option(a3[i], a2[i], true, true);
      }
      else
      {
        forma.brand_id.options[forma.brand_id.length] = new Option(a3[i], a2[i]);
      }
    }
  }
}

function select_brand(stype_id)
{
  var select = document.forms[1].sbrand_id;
  var sbrand_id = select.options[select.selectedIndex].value;
  url = "index.php3?stype_id="+stype_id+"&sbrand_id="+sbrand_id;
  window.location.href=url;
}

function select_city(stype_id, sbrand_id)
{
  var select = document.forms[1].scity_id;
  var scity_id = select.options[select.selectedIndex].value;
  url = "index.php3?stype_id="+stype_id+"&sbrand_id="+sbrand_id+"&scity_id="+scity_id;
  window.location.href=url;
}

function check_order(frm)
{
 re = /\S/;
 if( frm.your_name.value=="" || !re.test(frm.your_name.value))
 {
   alert("Поле 'Имя' является обязательным и не может быть пустым!");
   frm.your_name.focus();
   frm.your_name.select();
   return false;
 }
 if( !frm.your_email.value.match(/^[-!#$%&\'*+\\.\/0-9=?A-Z^_`a-z{|}~]+@[-!#$%&\'*+\\\/0-9=?A-Z^_`a-z{|}~]+\.[-!#$%&\'*+\\\/0-9=?A-Z^_`a-z{|}~][-!#$%&\'*+\\.\/0-9=?A-Z^_`a-z{|}~]+$/) )
 {
   alert("Поле 'E-mail' является обязательным и должно иметь вид somebody@somehost.com!");
   frm.your_email.focus();
   frm.your_email.select();
   return false;
 }

}


function CheckRegionsForm(frm)
{
 re = /\S/;
 if( frm.city.value=="" || !re.test(frm.city.value))
 {
   alert("Поле 'Город' является обязательным и не может быть пустым!");
   frm.city.focus();
   frm.city.select();
   return false;
 }
}


function order_window(id)
{
 bkv=window.open("order.php?id="+id, "_blank" ,"resizable=0,width=485,height=570,top=50,left=100,toolbar=0,directories=0,menubar=0,status=0,location=0,scrollbars=yes, resizable=yes");
 bkv.focus();
}

function check_link(obj)
{
  var d = obj.value;
  if (
    (d.toLowerCase().indexOf("kiev.ua") != -1)
    || (d.toLowerCase().indexOf("com.ua") != -1)
    || (d.toLowerCase().indexOf("киев.уа") != -1)
    || (d.toLowerCase().indexOf("ком.уа") != -1)
    || (d.toLowerCase().indexOf("net.ua") != -1)
    || (d.toLowerCase().indexOf("нет.уа") != -1)
    || (d.toLowerCase().indexOf("www") != -1)
    || (d.toLowerCase().indexOf(".ru") != -1)
    || (d.toLowerCase().indexOf(".com") != -1)
    || (d.toLowerCase().indexOf(".org") != -1)
    // || (d.toLowerCase().indexOf("ввв.") != -1)
    // || (d.toLowerCase().indexOf("ццц.") != -1)
  )
  {
    return false;
  }
  else
  {
    return true;
  }
}

function check_add_form()
{
  frm = eval("document.registration")
  re = /\S/;
  if( frm.your_name.value=="" || !re.test(frm.your_name.value))
  {
    alert("Поле 'Ваше имя (ник)' является обязательным и не может быть пустым!");
    frm.your_name.focus();
    frm.your_name.select();
    return false;
  }

  if( !frm.email.value.match(/^[-!#$%&\'*+\\.\/0-9=?A-Z^_`a-z{|}~]+@[-!#$%&\'*+\\\/0-9=?A-Z^_`a-z{|}~]+\.[-!#$%&\'*+\\\/0-9=?A-Z^_`a-z{|}~][-!#$%&\'*+\\.\/0-9=?A-Z^_`a-z{|}~]+$/) )
  {
    alert("Поле 'E-mail' является обязательным и должно иметь вид somebody@somehost.com!");
    frm.email.focus();
    frm.email.select();
    return false;
  }

  if( !frm.price.value.match(/^[0-9]+[\.,][0-9]+$|^[0-9]+$/) )
  {
    alert("Поле 'Цена (у. е.)' является обязательным и должно иметь вид 10.00 или 10,00!");
    frm.price.focus();
    frm.price.select();
    return false;
  }

  if( frm.model_id.value=="-2" )
  {
    if( frm.other_model.value=="" || !re.test(frm.other_model.value))
    {
      alert("Поле 'Модель' является обязательным и не может быть пустым!");
      frm.other_model.focus();
      frm.other_model.select();
      return false;
    }
  }

  var select = frm.condition_id;
  var selected_condition_id = select.options[select.selectedIndex].value;
  if( selected_condition_id=="-1" )
  {
    alert("Вы не указали состояние!");
    select.focus();
    return false;
  }

  var select = frm.type_id;
  var selected_type_id = select.options[select.selectedIndex].value;
  if( selected_type_id=="-1" )
  {
    alert("Вы не указали наименование!");
    select.focus();
    return false;
  }

  var select = frm.brand_id;
  var selected_brand_id = select.options[select.selectedIndex].value;
  if( selected_brand_id=="-1" )
  {
    alert("Вы не указали марку!");
    select.focus();
    return false;
  }

  var select = frm.description;
  if (!check_link(select))
  {
    alert("В объявлении запрещено указывать ссылку на сайт!");
    select.focus();
    return false;
  }

  var select = frm.other_model;
  if (!check_link(select))
  {
    alert("В объявлении запрещено указывать ссылку на сайт!");
    select.focus();
    return false;
  }

  frm.action.value = "add";
  frm.submit();
}


function check_delete_form()
{
 frm = eval("document.registration")
 re = /\S/;
 if( !frm.email.value.match(/^[-!#$%&\'*+\\.\/0-9=?A-Z^_`a-z{|}~]+@[-!#$%&\'*+\\\/0-9=?A-Z^_`a-z{|}~]+\.[-!#$%&\'*+\\\/0-9=?A-Z^_`a-z{|}~][-!#$%&\'*+\\.\/0-9=?A-Z^_`a-z{|}~]+$/) )
 {
   alert("Для удаления своих записей нужно ввести свой e-mail в поле 'E-mail' в виде somebody@somehost.com!");
   frm.email.focus();
   frm.email.select();
   return false;
 }

 frm.action.value = "delete";
 frm.submit();
}

