var first=1;	//первая позиция по умолчанию = 1
var qnt=6;	//количество позиций на экране = 6
var xmlHttp;	//запомнить ссылку на объект XMLHttpRequest

function topnav_redraw(direction,items_qnt)	//перерисовка прокрутки новинок вверху
{
   //direction: 0-left, 1-right
   //items_qnt: количество товаров всего

   if (direction==0) first++;
   else if (direction==1) first--;
   else first=1;

   if (first<1) first=items_qnt-qnt+1;  //1;
   if (first>items_qnt-qnt+1) first=1;  //num_rows-qnt+1;

   //ширина panel5=86 + margin-right=8 = 94
   document.getElementById("topnav-back").style.left=-(first-1)*94+"px";    

}

function search_item()	//перерисовка поиска на странице поиска
{
   search_string=document.getElementById("search_field").value;
   request_s("s="+encodeURIComponent(search_string));
}

function search_item1()	//переход на страницу поиска и перерисовка поиска
{
   search_string=document.getElementById("search_field").value;
   location.href='search.php?s='+search_string;
   //window.location.replace('search.php?s='+search_string);

}

function createXmlHttpRequestObject(){
    var xml_http = false;
    /*@cc_on
    @if (@_jscript_version >= 5)
        try {
            xml_http = new ActiveXObject("Msxml2.XMLHTTP");
        } catch (e) {
            try {
                xml_http = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (e2) {
                xml_http = false;
            }
        }
    @else
        xml_http = false;
    @end @*/
    if (!xml_http && typeof XMLHttpRequest != 'undefined') {
        try {
            xml_http = new XMLHttpRequest();
        } catch (e) {
            xml_http = false;
        }
    }
    return xml_http;
}

//выполнить асинхронный запрос 
function request(sss)
{
   // Получаем объект XMLHTTPRequest
   var xmlHttp = createXmlHttpRequestObject();

   //продолжать только если xmlHttp не содержит пустую строку
   if (xmlHttp)
   {
      //попытаться соединиться с сервером
      try
      {
         //инициировать чтение файла с сервера
	 //xmlHttp.open("GET", sss, true);
	 xmlHttp.open("POST", "request1.php", true);
         xmlHttp.onreadystatechange = function() {
		if (xmlHttp.readyState == 4)
		{
		   if (xmlHttp.status == 200)
		   {
			resdata=xmlHttp.responseText;
	
			//xmlResponse=xmlHttp.responseXML;
			//xmlRoot=xmlResponse.documentElement;
 			
			//resdata=decodeURIComponent(xmlRoot.getElementsByTagName("resdata")[0].childNodes[0].nodeValue);
			//resdata=decodeURIComponent(xmlRoot.getElementsByTagName("resdata").item(0).firstChild.data);
			//resdata=xmlRoot.firstChild.data;	

			//document.getElementById("search_field").value=resdata;
			//document.getElementById("central-container").className="search-container";
			document.getElementById("central-container").innerHTML=resdata;
	
		   }
		 else
		   {
			alert("При обращении к серверу возникли проблемы: " + http.statusText);
		   }
		 }
	 }
	 xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
	 //xmlHttp.send(null);
	 xmlHttp.send(sss);

      }
      //вывести сообщение об ошибке в случае неудачи\
      catch (e)
      {
	 alert("Невозможно соединиться с сервером:\n" + e.toString());
      }
   }
   else               
      alert("Ошибка при создании XMLHTTP объекта\n");
}

//выполнить синхронный запрос 
function request_s(sss)
{
   document.body.style.cursor='progress';
   // Получаем объект XMLHTTPRequest
   var xmlHttp = createXmlHttpRequestObject();

   //продолжать только если xmlHttp не содержит пустую строку
   if (xmlHttp)
   {
      //попытаться соединиться с сервером
      try
      {
         //инициировать чтение файла с сервера
	 //xmlHttp.open("GET", sss, true);
	 xmlHttp.open("POST", "request1.php", false);
	 xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
	 //xmlHttp.send(null);
	 xmlHttp.send(sss);
	 if (xmlHttp.status == 200)
	 {
		resdata=xmlHttp.responseText;
		document.getElementById("central-container").innerHTML=resdata;
	   	document.body.style.cursor='default';
	 }
	 else
	 {
   		document.body.style.cursor='default';
		alert("При обращении к серверу возникли проблемы: " + http.statusText);
	 }
      }
      //вывести сообщение об ошибке в случае неудачи
      catch (e)
      {
   	 document.body.style.cursor='default';
	 alert("Невозможно соединиться с сервером:\n" + e.toString());
      }
   }
   else
   {
      document.body.style.cursor='default';
      alert("Ошибка при создании XMLHTTP объекта\n");
   }
}



                       

