function SwitchDisplay(eid) {
  if (document.getElementById(eid)!=undefined) {
    if (document.getElementById(eid).style.display == "none") {
      document.getElementById(eid).style.display = "block"
    }
    else {
      document.getElementById(eid).style.display = "none"
    }
  }
}

function Jump(length, from, to) {
  to=document.getElementById(to);
  if (from.value.length==length) {
    to.focus();
  }
}

rows = new Array();
rows['zakmob']=1;
rows['zakrab']=3;
rows['polmob']=1;
rows['polrab']=3;

numbers = new Array();
numbers['zakmob']=2;
numbers['zakrab']=2;
numbers['polmob']=2;
numbers['polrab']=2;

function AddNumber(person, type) {
  names = new Array();
  names['mob'] = 'мобильный:';
  names['rab'] = 'рабочий:';
  num=numbers[person+type];
  numbers[person+type]++;
  tblBody = document.getElementById(person+'phones').tBodies[0];

  newRow = tblBody.insertRow(rows[person+type]);
  rows[person+'rab']++;
  if (type=='mob') {
    rows[person+'mob']++;
  }
  newCell0 = newRow.insertCell(0);
  newCell0.innerHTML = names[type];
  newCell1 = newRow.insertCell(1);
  newCell1.innerHTML = '\
   (<input type=text name='+person+'_'+type+'_'+num+'_phone_code id='+type+'_'+num+'_phone_code size=3 maxlength=3 onKeyUp="Jump(3, this, \''+type+'_'+num+'_phone_1\');">)\n\
    <input type=text name='+person+'_'+type+'_'+num+'_phone_1    id='+type+'_'+num+'_phone_1    size=3 maxlength=3 onKeyUp="Jump(3, this, \''+type+'_'+num+'_phone_2\');">-\n\
    <input type=text name='+person+'_'+type+'_'+num+'_phone_2    id='+type+'_'+num+'_phone_2    size=2 maxlength=2 onKeyUp="Jump(2, this, \''+type+'_'+num+'_phone_3\');">-\n\
    <input type=text name='+person+'_'+type+'_'+num+'_phone_3    id='+type+'_'+num+'_phone_3    size=2 maxlength=2>\n';

  if (type=='rab') {
    newRow = tblBody.insertRow(rows[person+type]);
    rows[person+type]++;
    newCell0 = newRow.insertCell(0);
    newCell0.innerHTML = 'добавочный:';
    newCell1 = newRow.insertCell(1);
    newCell1.innerHTML = '&nbsp;<input type=text name='+person+'_rab_'+num+'_phone_dob  id=rab_'+num+'_phone_dob  size=5 maxlength=7>';
  }
}

function TimeSpan(from, to) {
  tf=document.getElementById("time_from");
  tt=document.getElementById("time_to");
  tf_index=tf.selectedIndex;
  tt_index=tt.selectedIndex;

  if (from) {
    if (tt_index>0 && tt_index<tf_index) {
      tt.selectedIndex=tf_index
    }
  }
  else {
    if (tf_index>tt_index) {
      tf.selectedIndex=tt_index
    }
  }
}

function loadXMLDoc(url, htmlName) {
  /* Создание нового объекта XMLHttpRequest для общения с Web-сервером */
  var xmlHttp = false;
  var innerDH=document.getElementById(htmlName);
  /*@cc_on @*/
  /*@if (@_jscript_version >= 5)
  try {
    xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
  } catch (e) {
    try {
      xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
    } catch (e2) {
      xmlHttp = false;
    }
  }
  @end @*/
  if (!xmlHttp && typeof XMLHttpRequest != 'undefined') {
    xmlHttp = new XMLHttpRequest();
  }
  /* --- */

  xmlHttp.onreadystatechange=function() {
    if(xmlHttp.readyState==4) {
      innerDH.innerHTML=xmlHttp.responseText
    }
  }

  myRand=parseInt(Math.random()*99999999);  // cache buster

  xmlHttp.open("GET", url + "&rand=" + myRand, true);
  xmlHttp.send(null);
}

function GetCityByIndeks(indeks) {
  loadXMLDoc('site.cgi?m=indeks&indeks='+indeks, 'city');
}

function SelectAddress() {
  rad=document.addrform.addrtype;
  if (document.getElementById('rabaddr').style.display == "block") {
    rad[0].checked=true;
  }
  else if (document.getElementById('domaddr').style.display == "block") {
    rad[1].checked=true;
  }
}

