var xmlHttp = createXmlHttpRequestObject();
 

function createXmlHttpRequestObject() {

    var xmlHttp;
    try {

        xmlHttp = new XMLHttpRequest();
    }
    catch(e)  {

        var XmlHttpVersions = new Array("MSXML2.XMLHTTP.6.0",
                                        "MSXML2.XMLHTTP.5.0",
                                        "MSXML2.XMLHTTP.4.0",
                                        "MSXML2.XMLHTTP.3.0",
                                        "MSXML2.XMLHTTP",
                                        "Microsoft.XMLHTTP");

    for (var i=0; i<XmlHttpVersions.length && !xmlHttp; i++) {
          try { 

              xmlHttp = new ActiveXObject(XmlHttpVersions[i]);
          } 
          catch (e) {}
    }
}

  if (!xmlHttp) alert("Ошибка создания XMLHttpRequest");
  else return xmlHttp;
}


function Reg() {

        if (xmlHttp) {
            try {
		$login = document.getElementById('login').value;
		$pass1 = document.getElementById('pass1').value;
		$pass2 = document.getElementById('pass2').value;
		$email = document.getElementById('email').value;
		
                xmlHttp.open("GET", "/cmd/reg.php?login="+encodeURI($login)+"&pass1="+encodeURI($pass1)+"&pass2="+encodeURI($pass2)+"&email="+encodeURI($email), true);
                xmlHttp.onreadystatechange = handlerReg;
                xmlHttp.send(null);

        }
        catch(e) {}
    }
}

function handlerReg() {
    if (xmlHttp.readyState == 4) {
        if (xmlHttp.status == 200) {
            try {
                var content = xmlHttp.responseText;
		if (content==101) document.getElementById('status_line').innerHTML  = '<span id="form_top">Пользователь с таким именем уже существует</span>';
		if (content==102) document.getElementById('status_line').innerHTML  = '<span id="form_top">Пароль должен быть длиной от 6 до 20 символов</span>';    
                if (content==103) document.getElementById('status_line').innerHTML  = '<span id="form_top">Введенные пароли не совпадают</span>';
		if (content==104) document.getElementById('status_line').innerHTML  = '<span id="form_top">Неверный формат E-mail</span>';
		    if (content==200) {
		    document.getElementById('status_line').innerHTML   = '';
		    document.getElementById('form_in').innerHTML       = '<p>Спасибо за регистрацию!<br />Вам выслано активизационное письмо.</p><p>Чтобы завершить регистрацию, Вам будет необходимо перейти по ссылке, которая находится в отправленном Вам письме.</p><div style="height: 20px">&nbsp;</div>';
	            }
                }
            catch(e) {}
        }
        else {}
  }
}



function switch_state($kind,$article_id){

document.getElementById('form_comment').innerHTML = '';

    if ($kind==1){
    document.getElementById('reg_link').innerHTML = '';
    document.getElementById('form_comment').innerHTML = '<form method="post" action="/cmd/post.php"><input type="hidden" name="article_id" value="'+$article_id+'"><input type="hidden" name="kind" value="registered"><div class="line"><label>Логин</label><input name="login" id="login" type="text" class="text" /></div><div class="line"><label>Пароль</label><input name="pass" id="pass" type="password" class="text" /></div><div class="line"><label>Комментарий</label><textarea name="comment" cols="" rows=""></textarea></div><div class="line"><input name="" type="submit" class="button" value="Добавить комментарий" /></div></form>';
    }
    
    if ($kind==2){
    document.getElementById('reg_link').innerHTML = '<a href="/times/register/">Зарегистрироваться</a>';
    document.getElementById('form_comment').innerHTML = '<form method="post" action="/cmd/post.php"><input type="hidden" name="kind" value="guest"><input type="hidden" name="article_id" value="'+$article_id+'"><div class="line"><label>Имя гостя</label><input name="login" type="text" class="text" /></div><div class="line"><label>Комментарий</label><textarea name="comment" cols="" rows=""></textarea></div><div class="line"><label class="stat">Ввод контрольных цифр</label><div id="code_block"><div class="left"><img src="/cmd/captcha.php" width="80" height="65" alt="code" /></div><div class="right">Если вы не можете прочесть текст - <a href="#">воспользуйтесь аудио</a><input name="check" type="text" class="text" /></div></div></div><div class="line"><input name="" type="submit" class="button" value="Добавить комментарий" /></div></form>';
    }




}



function switch_rec_state($kind){

document.getElementById('form_comment').innerHTML = '';

    if ($kind==1){
    document.getElementById('reg_link').innerHTML = '';
    document.getElementById('form_comment').innerHTML = '';
    }

    if ($kind==2){
    document.getElementById('reg_link').innerHTML = '<a href="/times/register/">Зарегистрироваться</a>';
    document.getElementById('form_comment').innerHTML = '';
    }

}


 


function onf(id){


    if (id!=document.getElementById('active_icon').value && document.getElementById('active_icon').value!=0){
    document.getElementById(id).style.border="#fff solid 2px";
    document.getElementById(id).style.position="relative";
    document.getElementById(id).style.margin = "-2px";
    }

}

function ons(id){

    if (id!=document.getElementById('active_icon').value && document.getElementById('active_icon').value!=0){
    document.getElementById(id).style.border="none";
    document.getElementById(id).style.position="relative";
    document.getElementById(id).style.margin = "0";
    }
}



function NextFoto($art_id,$foto_id,$kind){

        if (xmlHttp) {
            try {


		var stl = 'mid_foto' + $foto_id;
                var slink = 'link' + $foto_id;

		var zooms1 = 'zooms' + $foto_id;
		var fotka1 = 'fotka' + $foto_id;

		var spanel = 'panel' + document.getElementById('active_icon').value;

                document.getElementById(spanel).innerHTML = '<a href="javascript:void(0);" onclick="SelectFoto('+$art_id+','+document.getElementById('active_icon').value+',2);" id="link'+document.getElementById('active_icon').value+'" onMouseOver="onf(this.id);" onMouseOut="ons(this.id);"><img src="'+document.getElementById('active_file').value+'" width="80" height="60" alt="img"  /></a>';




		document.getElementById(zooms1).style.display="none";
		document.getElementById(fotka1).style.display="none";

	
    
                document.getElementById(slink).style.border="none";
                document.getElementById(slink).style.position="relative";
                document.getElementById(slink).style.margin = "0";



                xmlHttp.open("GET", "/cmd/next_article_foto.php?art_id="+$art_id+"&foto_id="+$foto_id+"&kind="+$kind, true);
                xmlHttp.onreadystatechange = handlerNextFoto;
                xmlHttp.send(null);

        }
        catch(e) {}
    }

}

function SelectFoto($art_id,$foto_id,$kind){

        if (xmlHttp) {
            try {

                var stl    = 'mid_foto' + document.getElementById('current_foto').value;
		var zooms1 = 'zooms' + document.getElementById('current_foto').value;
		var spanel = 'panel' + document.getElementById('active_icon').value;
		var fotka1 = 'fotka' + document.getElementById('current_foto').value;


		document.getElementById(spanel).innerHTML = '<a href="javascript:void(0);" onclick="SelectFoto('+$art_id+','+document.getElementById('active_icon').value+',2);" id="link'+document.getElementById('active_icon').value+'" onMouseOver="onf(this.id);" onMouseOut="ons(this.id);"><img src="'+document.getElementById('active_file').value+'" width="80" height="60" alt="img"  /></a>';


		document.getElementById(zooms1).style.display="none";
		document.getElementById(fotka1).style.display="none";


                xmlHttp.open("GET", "/cmd/select_article_foto.php?art_id="+$art_id+"&foto_id="+$foto_id+"&kind="+$kind, true);
                xmlHttp.onreadystatechange = handlerNextFoto;
                xmlHttp.send(null);

        }
        catch(e) {}
    }

}



function handlerNextFoto() {
    if (xmlHttp.readyState == 4) {
        if (xmlHttp.status == 200) {
            try {
                var content = xmlHttp.responseText;

		a = content.split("|");

		$count = document.getElementById('count_fotos').value;		


		var stl1 = 'mid_foto' + a[0];
    		var slink = 'link' + a[0];
		var spanel = 'panel' + a[0];

		var zooms = 'zooms' + a[0];
		var fotka = 'fotka' + a[0];


		//**
	//        document.okno.src = '/img2.php?mod=article_img&fname='+a[0]+'_'+a[1];


		if (a[8]>=648 && a[9]>=425)    
	        document.getElementById(zooms).style.display="block";
		//**

		document.getElementById(fotka).style.display="block";


		document.getElementById('current_foto').value = a[0];

		document.getElementById(slink).style.border="#949383 solid 5px";
		document.getElementById(slink).style.position="relative";
		document.getElementById(slink).style.margin = "-5px";


		document.getElementById('active_icon').value = a[0];
		document.getElementById('active_file').value = '/files/article_img/'+a[0]+'_'+a[1];
	


		document.getElementById(spanel).innerHTML = '';
		document.getElementById(spanel).innerHTML = '<img src="'+document.getElementById('active_file').value+'" width="80" height="60" alt="img" style="border: #949383 solid 5px; position: relative; margin: -5px" />';


		document.getElementById('bot').innerHTML = '';


		if ($count>7)
		{

		
		if (a[10]==1) document.getElementById('sprev').innerHTML = '<img src="/images/ru_times/gall_prev_one.gif" class="prev_image">';
		if (a[10]==2) document.getElementById('sprev').innerHTML = '<a href="javascript:stepcarousel.stepBy(\'mygallery\', -1)" id="gall_prev" class="gall_nav" title="предыдущая"><strong>предыдущая</strong></a>';
		if (a[11]==1) document.getElementById('snext').innerHTML = '<img src="/images/ru_times/gall_next_one.gif" class="next_image">';
		if (a[11]==2) document.getElementById('snext').innerHTML = '<a href="javascript:stepcarousel.stepBy(\'mygallery\', 1)" id="gall_next" class="gall_nav" title="следующая"><strong>следующая</strong></a>';


		if (a[4]>0) document.getElementById('bot').innerHTML = '<a href="javascript:void(0);" onclick="NextFoto('+a[2]+','+a[0]+',1);stepcarousel.stepBy(\'mygallery\', -1);" class="left">Предыдущая</a><a href="javascript:void(0);" onclick="NextFoto('+a[2]+','+a[0]+',2);stepcarousel.stepBy(\'mygallery\', 1);" class="right">Следующая</a>';
		if (a[4]==0 & a[6]==2) document.getElementById('bot').innerHTML = '<a href="javascript:void(0);" onclick="NextFoto('+a[2]+','+a[0]+',1);stepcarousel.stepBy(\'mygallery\', -1);" class="left">Предыдущая</a><span class="right">Следующая</span>';
		if (a[4]==0 & a[6]==1) document.getElementById('bot').innerHTML = '<span class="left">Предыдущая</span><a href="javascript:void(0);" onclick="NextFoto('+a[2]+','+a[0]+',2);stepcarousel.stepBy(\'mygallery\', 1);" class="right">Следующая</a>';
		if (a[7]==0 & a[6]==2) document.getElementById('bot').innerHTML = '<span class="left">Предыдущая</span><a href="javascript:void(0);" onclick="NextFoto('+a[2]+','+a[0]+',2);stepcarousel.stepBy(\'mygallery\', 1);" class="right">Следующая</a>';

		} else {

	if (a[4]>0)
	document.getElementById('bot').innerHTML = '<a href="javascript:void(0);" onclick="NextFoto('+a[2]+','+a[0]+',1);" class="left">Предыдущая</a><a href="javascript:void(0);" onclick="NextFoto('+a[2]+','+a[0]+',2);" class="right">Следующая</a>';
	if (a[4]==0 & a[6]==2) document.getElementById('bot').innerHTML = '<a href="javascript:void(0);" onclick="NextFoto('+a[2]+','+a[0]+',1);" class="left">Предыдущая</a><span class="right">Следующая</span>';
	if (a[4]==0 & a[6]==1) document.getElementById('bot').innerHTML = '<span class="left">Предыдущая</span><a href="javascript:void(0);" onclick="NextFoto('+a[2]+','+a[0]+',2);" class="right">Следующая</a>';
	if (a[7]==0 & a[6]==2) document.getElementById('bot').innerHTML = '<span class="left">Предыдущая</span><a href="javascript:void(0);" onclick="NextFoto('+a[2]+','+a[0]+',2);" class="right">Следующая</a>';



		}


	        document.getElementById('foto_name').innerHTML = '';
		document.getElementById('foto_name').innerHTML = a[3];
                }
            catch(e) {}
        }
        else {}
  }
}










