function backzzz()
{
    var t = document.getElementById('fff');
    c = t.value;
    if (c != 0)
    {
        var y = document.getElementById('str');
        y.innerHTML = '<b>Подождите, идет проверка</b>';
        JsHttpRequest.query(
          'http://auction.conros.ru/cityback.php',                     // the path to backend
          {'city':c},                        // the JavaScript array with data you want to pass
          function(result, errors)
          {
              if (result)
              {
                  var i = 0;
                  var y = document.getElementById("str");
                  y.innerHTML = '';
                  var sel = document.getElementById("ff");
                  sel.style.visibility = "visible";
                  var ttt = document.getElementById("txt");
                  ttt.style.visibility = "hidden";

                  while (sel.lastChild) {
                       sel.removeChild(sel.lastChild);
                  }

                  var sel2 = document.getElementById("ff2");
                  sel2.style.visibility = "hidden";
                  var az = sel.appendChild(document.createElement("option"));
                  az.text = 'Выберите город';
                  az.value = 0;
                  if (result["name"].length == 1)
                  {
                     var y = sel.appendChild(document.createElement("option"));
                     y.text = result["name"][i];
                     y.value = result["code"][i];
                     i = 5;
                  }
                  else
                  {
                      while(i < result["name"].length) {
                         var y = sel.appendChild(document.createElement("option"));
                         y.text = result["name"][i]+' '+result["rayon"][i]+' '+result["reg"][i];
                         y.value = result["code"][i];
                         i++;
                      }
                  }
                  if(i == 0)
                  {
                    y.innerHTML = 'Город не найден';
                    sel.style.visibility = "hidden";
                  }
              }
              else alert('упс');
          },
          false);
    }
};

function streetor(val)
{
    var ttt = document.getElementById("txt");
    if (val == 0) ttt.style.visibility = "visible";
    else ttt.style.visibility = "hidden";   
}
function streetz(val)
{
    c = val;
    if (c != 0)
    {
      var y = document.getElementById("str");
      y.innerHTML='<b>Подождите, строится список улиц</b>';
      JsHttpRequest.query(
              'http://auction.conros.ru/streetback.php',                     // the path to backend
              {'street':c},                        // the JavaScript array with data you want to pass
              function(result, errors)
              {
                  if (result)
                  {
                      var i = 0;
                      var y = document.getElementById("str");
                      y.innerHTML = '';
                      var sel = document.getElementById("ff2");
                      sel.style.visibility = "visible";
                      var ttt = document.getElementById("txt");
                      ttt.style.visibility = "visible";

                      while(sel.lastChild) {
                          sel.removeChild(sel.lastChild);
                      }

                      var ttrr = sel.appendChild(document.createElement("option"));
                      ttrr.text = "Выберите улицу или";
                      ttrr.value = 0;
                      while(i < result["name"].length) {
                          var ty = sel.appendChild(document.createElement("option"));
                          ty.text = result["name"][i];
                          ty.value = result["code"][i];
                          i++;
                      }

                      if (i <= 1)
                      {
                         sel.style.visibility = "hidden";
                      }
                  }
              },
              true);
    }
}
function yu()
{
    var error = "";
    var re =/^[\.\-_A-Za-z0-9]+?@[\.\-A-Za-z0-9]+?\.[A-Za-z0-9]{2,6}$/;
    var kl =/^[0-9]{10,20}$/;
    var res = re.test(document.forms.ttt.mail.value);
    if (document.forms.ttt.login.value == "")
    {
            error += "Вы не ввели логин\n";
    }else
    {
            var log = new JsHttpRequest();

    }
    if(document.forms.ttt.pass.value == "" || document.forms.ttt.pass.value.length<5)
    {
            error += "Слишком короткий пароль\n";
    };
    if(document.forms.ttt.pass.value != document.forms.ttt.conf_pass.value)
    {
            error += "Пароль не совпадает с подтверждением\n";
    };
    sel = false;
    sel1 = false;
    sel2 = false;
    for(var i = 0; i < document.forms.ttt.gender.length; i++)
    {
        if(document.forms.ttt.gender[i].checked)
        {
                sel = true;
                var gend = document.forms.ttt.gender[i].value;
        }
    }
    for(var i = 0; i < document.forms.ttt.receive_method.length; i++)
    {
        if(document.forms.ttt.receive_method[i].checked)
        {
            sel1 = true;
            var receive = document.forms.ttt.receive_method[i].value;
        }
    }
    /*for(var i = 0; i < document.forms.ttt.payment_method.length; i++)
    {
            if(document.forms.ttt.payment_method[i].checked)
            {
                    sel2 = true;
                    var pay = document.forms.ttt.payment_method[i].value;
            }
    }  */
    if(!sel)error += "Вы не указали пол\n";
    if(!sel1)error += "Вы не указали способ получения лотов\n";
    //if(!sel2)error += "Вы не указали способ оплаты лотов\n";
    if (document.forms.ttt.last_name.value == "")
    {
            error += "Вы не ввели Фамилию\n";
    };
    if (document.forms.ttt.frst_name.value == "")
    {
            error += "Вы не ввели Имя\n";
    };
    if (document.forms.ttt.scnd_name.value == "")
    {
            error += "Вы не ввели Отчество\n";
    };
    var c = new Array();
    if(document.forms.ttt.lev4.value!=0)
    {
            c['kladr']=document.forms.ttt.lev4.value;
            c['street']=document.forms.ttt.lev4.value;
    }
    else
    {
            c['kladr']=document.forms.ttt.lev3.value;
            c['street']=document.forms.ttt.street.value;
    }
    if(c['kladr']=='')error+="Вы не указали адрес\n";
    if(document.forms.ttt.lev4.value==0 && document.forms.ttt.street.value=='введите улицу')
    {
            error += "Вы не выбрали Улицу\n";
    }
    /*if(document.forms.ttt.index)
    {    */
        if (document.forms.ttt.index.tagName == "INPUT")
        {
                if (document.forms.ttt.index.value == "")
                {
                        error += "Вы не указали индекс\n";
                }
        }else
        {
                if (document.forms.ttt.index.value == "Индекс")
                {
                        error += "Вы не выбрали индекс\n";
                }
        }
//}
    if(!res)
    {
             error += "Неверный e-mail\n";
    }
    if(document.forms.ttt.phone1.value == "")
    {
            error += "Вы не указали телефон\n";
    }
    if(document.forms.ttt.house.value == "")
    {
            error += "Вы не указали дом\n";
    }
    if(!document.forms.ttt.aggree.checked)
    {
        // document.getElementById("aggree").
            error += "Вы не выразили своего согласия с Правилами и согласия на хранение и обработку Ваших персональных данных\n";
    }
    if(error == "")
    {
	    /*var req = new JsHttpRequest();
		req.onreadystatechange = function()
	    {
	    	 if (req.readyState == 4)
	        {
				if(req.responseJS.error=="")
				{
					if(req.responseJS.complete == "OK")
					{
						document.getElementById("regt").parentNode.removeChild(document.getElementById("regt"));
			        	var x = document.createElement('table');
			        	x.className = "main";
						var y = x.appendChild(document.createElement('tbody'));
						var z = y.appendChild(document.createElement('tr'));
						var a = z.appendChild(document.createElement('td'));
						a.className="main";
						a.appendChild(document.createTextNode('Данные отправлены'));
						var z = y.appendChild(document.createElement('tr'));
						var a = z.appendChild(document.createElement('td'));
						a.className="main";
						a.appendChild(document.createTextNode('Вам на указанный вами e-mail выслано письмо, содержащее ссылку.\nДля завершения регистрации перейдите по ссылке, указанной в письме.'));
						a.appendChild(document.createElement('br'));
						document.getElementById("center").appendChild(x);
					}else
					{
						alert(req.responseJS.complete);
					}
				}else
				{
					 error=req.responseJS.error;
					 alert(req.responseJS.error);
				}
	        }
	    } */

        c['login']=document.forms.ttt.login.value;
        c['pass']=document.forms.ttt.pass.value
        c['gend']=gend;

        c['last']=document.forms.ttt.last_name.value;
        c['frst']=document.forms.ttt.frst_name.value;
        c['scnd']=document.forms.ttt.scnd_name.value;
        c['mail']=document.forms.ttt.mail.value;
        //c['payment']=pay;
        c['receive']=receive;
        c['house']=document.forms.ttt.house.value;
        c['float']=document.forms.ttt.appartment.value;
        c['korp']=document.forms.ttt.korpus.value;
        c['comment']=document.forms.ttt.comment.value;
        c['index']=document.forms.ttt.index.value
        c['phone1']=document.forms.ttt.phone1.value;
        c['phone2']=document.forms.ttt.phone2.value;
        c['letter']=0;

		/*req.open(null, 'regback.php', true);
    	req.send({val : c});*/
    	JsHttpRequest.query(
	  '../regback.php',                     // the path to backend
	  {'val':c},                        // the JavaScript array with data you want to pass
	  function(result, errors)
	  {
             if(result)
             {
                if(result["error"]=="")
                {
                    if(result["complete"] == "OK")
                    {
                        $("#regt").remove();
                        $("#readytext").html('<h3 class="pageHeading">Благодарим за регистрацию!</h3>');
                        $("#readytext").append('<p>На указанный Вами e-mail  отправлено письмо, содержащее ссылку для подтверждения регистрации.</p><p>Если вы не получите письмо (возможно, был неверно указан e-mail), пожалуйста, свяжитесь с нами по телефону (812) 496 25 16 или напишите письмо на <a href="mailto:auction@conros.ru">auction@conros.ru</a></p>');
                    }else
                    {
                        alert(result["complete"]);
                    }
                }else
                {
                     error=result["error"];
                     alert(result["error"]);
                }
            }else alert(errors);

	  }, // the function is called when an answer is ready
	 true                      // if set to TRUE, caching will be disabled
	);
    }
    else alert(error);
};
function chcolor(a)
{
	a.style.color="#ffffff";
	a.style.backgroundColor="#8CC6FF";
}
function chcolorobr(a,t)
{
	a.style.color="#000000";
	if(t==1)
	{
		a.style.backgroundColor="#ffffff";
	}else a.style.backgroundColor="#E0E0E0";
}


function view(n,b,c,elem)
{
	viewvin=window.open("/lotinf.php?id="+n+"&st="+b+"&aid="+c,"_blank","copyhistory=0,top=200,left=100,links=0,toolbar=0,directories=0,status=0,scrollbars=1,resizable=0,menubar=0,width=800,height=580");
	viewvin.focus();
	delete viewvin;
	elem.style.color="red";
	elem.parentNode.style.color="red";
}
function viewprof(n,b,c)
{
	viewwin=window.open("/lotinfprof.php?id="+n+"&st="+b+"&aid="+c,"_blank","copyhistory=0,top=200,left=100,links=0,toolbar=0,directories=0,status=0,scrollbars=1,resizable=0,menubar=0,width=800,height=500");
	viewwin.focus();
	delete viewvin;
}
function viewvip(n,b,c)
{
	viewwin=window.open("/vlotinf.php?id="+n+"&st="+b+"&aid="+c,"_blank","copyhistory=0,top=200,left=100,links=0,toolbar=0,directories=0,status=0,scrollbars=1,resizable=0,menubar=0,width=800,height=500");
	viewwin.focus();
	delete viewvin;
}

function viewm(n,b,c,elem)
{
    viewvin=window.open("/lotinfo.php?id="+n+"&st="+b+"&aid="+c,"_blank","copyhistory=0,top=200,left=100,links=0,toolbar=0,directories=0,status=0,scrollbars=1,resizable=0,menubar=0,width=800,height=580");
    viewvin.focus();
    delete viewvin;
    elem.style.color="red";
    elem.parentNode.style.color="red";
}
function toprof(n,aid,uid,a)
{
    var c = new Array();
    c[0]=n;
    c[1]=aid;
    c[2]=uid;
    JsHttpRequest.query(
    '/backend/toprof.php',
    {'zap' : c},
    function(result,errors)
    {
        if(result)
        {
            if (result["error"]!=0)
            {
                    alert(result["error"]);
                    a.checked=true;
            }
        }
    },
    true);
}

function toprof2(n,aid,uid,a)
{
    var c = new Array();
    c[0]=n;
    c[1]=aid;
    c[2]=uid;
    JsHttpRequest.query(
    '/backend/toprof.php',
    {'zap' : c},
    function(result,errors)
    {
            if(result)
            {
                    if (result["error"]!=0)
                    {
                            alert(result["error"]);
                            a.checked=true;
                    }
                    else{
                    $(a).parent().parent().remove();}
                    //location.reload();
            }
    },
    true);
}

function time()
{
    bt += 1000;
    t.setTime(bt);
    var str = new String(t.toString(t.getTime()));
    document.getElementById('timehere').innerHTML = str.match(/\d\d:\d\d:\d\d/);
    delete str;
}

function doLoad()
{
    JsHttpRequest.query(
    '/backend/time.php',
    null,
    function(result, errors)
    {
        if(result)
        {
            document.getElementById('timehere').innerHTML =  result["time"];
            bt = result["tt"] * 1000 + 3600000 * (4 + (t.getTimezoneOffset())/60);
        }
    },
    true);
}
