var xPos = 0;
var yPos = 0;
var showProgress = true;


var isIE = (navigator.appName == "Microsoft Internet Explorer");
var isFF = (!isIE && !(navigator.appVersion.indexOf("MSIE")>-1));
var isOPR = (navigator.userAgent.indexOf("Opera")!=-1);
if (isOPR) { isIE = false; }



if (isFF)
     {
     document.onmousedown = function(e)
          {
          xPos = e.pageX;
          yPos = e.pageY;
          }
     }
else
     {
     document.onmousedown = function()
          {
          xPos = event.clientX + document.body.scrollLeft;
          yPos = event.clientY + document.body.scrollTop;
          }
     }


function startProgress()
      {
      document.getElementById('cursorProgress').style.left = xPos + 15;
      document.getElementById('cursorProgress').style.top = yPos + 0;
      document.onmousemove = moveProgressImage;
      document.getElementById('cursorProgress').style.display = "block";
      }




function moveProgressImage()
      {
      if (isFF)
          {
          document.onmousemove = function(e)
              {
              document.getElementById('cursorProgress').style.left = e.pageX + 15;
              document.getElementById('cursorProgress').style.top = e.pageY + 0;
              }
          }
      else
          {
          document.getElementById('cursorProgress').style.posLeft = event.clientX + document.body.scrollLeft + 15;
          document.getElementById('cursorProgress').style.posTop = event.clientY + document.body.scrollTop + 0;
          }
      return false;
      }

function stopProgress()
      {
      document.getElementById('cursorProgress').style.display = "none";
      document.onmousemove = null;
      }



    function fotoFull(file,w,h)
         {
         var infoWin = new Dialog.info({url: '/win/foto.html?file='+file, options: {method: 'get'}},
                           {windowParameters: {className: "nashi", width:w, height:h, draggable:false, resizable: false}}
                           );
         }

    function infoWord(id)
         {
         var infoWin = new Dialog.info({url: '/win/word.html?id='+id, options: {method: 'get'}},
                           {windowParameters: {className: "nashi", width:640, height:480, draggable:false, resizable: false}}
                           );
         }

function getHTTP()
      {
      var xmlhttp;
      /*@cc_on
      @if (@_jscript_version >= 5)
          try
               {
               xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
               }
          catch (e)
               {
               try
                    {
                    xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
                    }
               catch (E)
                    {
                    xmlhttp = false;
                    }
               }
      @else
          xmlhttp = false;
      @end @*/
      if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
          try
               {
               xmlhttp = new XMLHttpRequest();
               }
          catch (e)
               {
               xmlhttp = false;
               }
          }
      return xmlhttp;
      }


function lookupProcess(lookupSettings)
      {
      if (!lookupSettings) lookupSettings = new Object();

      if (!lookupSettings.values)         lookupSettings.values   = '';
      if (!lookupSettings.postFunction)   lookupSettings.postFunction   = '';
      if (!lookupSettings.dest)           lookupSettings.dest = false;
  /*
      try {
          destHeight = document.getElementById(lookupSettings.dest).offsetHeight;
          document.getElementById(lookupSettings.dest).innerHTML = "<div>&nbsp;</div>";
          document.getElementById(lookupSettings.dest).style.height = destHeight;
          }
      catch (e) { destObj = false; }
  */
      if (lookupSettings.url)
           {
           this.working = false;
           if (!this.working && (this.http = getHTTP()))
                {
                if (showProgress) startProgress();
                var http = this.http;
                this.http.open("POST", lookupSettings.url, true);
                this.http.onreadystatechange = function()
                     {
                     if (http.readyState == 4)
                          {
                          if (showProgress) stopProgress();
                          showProgress = true;
                          re = /^Location: ([a-zA-Z0-9._-]+)/;
                          ReLocation = re.exec(http.responseText);
                          try { destObj = document.getElementById(lookupSettings.dest); }
                          catch (e) { destObj = false; }
                          if ( !ReLocation && destObj )
                               {
                               destObj.style.display = "block";
                               destObj.style.height = '';
                               destObj.innerHTML = http.responseText;
                               if (lookupSettings.postFunction) eval(lookupSettings.postFunction);
                               }
                          else
                               {
                               if ( ReLocation )
                                    {
                                    document.location.href = ReLocation[1];
                                    }
                               else
                                    {
                                    return http.responseText;
                                    }
                               }
                          this.working = false;
                          this.http = false;
                          }
                     }
                this.working = true;
                this.http.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
                this.http.send(lookupSettings.values);
                }
           if(!this.http)
                {
                alert('Ошибка при создании XMLHTTP объекта. Ваш браузер не поддерживается системой!')
                }
           }
      }

function lookup(lookupSettings)
      {
      if (!lookupSettings) lookupSettings = new Object();

      if (!lookupSettings.values)         lookupSettings.values   = '';
      if (!lookupSettings.postFunction)   lookupSettings.postFunction   = '';
      if (!lookupSettings.dest)           lookupSettings.dest = false;

      if (lookupSettings.url)
           {
           this.working = false;
           if (!this.working && (this.http = getHTTP()))
                {
//                if (showProgress) startProgress();
                var http = this.http;
                this.http.open("POST", lookupSettings.url, true);
                this.http.onreadystatechange = function()
                     {
                     if (http.readyState == 4)
                          {
//                          if (showProgress) stopProgress();
//                          showProgress = true;
                          re = /^Location: ([a-zA-Z0-9._-]+)/;
                          ReLocation = re.exec(http.responseText);
                          try { destObj = document.getElementById(lookupSettings.dest); }
                          catch (e) { destObj = false; }
                          if ( !ReLocation && destObj )
                               {
                               destObj.style.display = "block";
                               destObj.innerHTML = http.responseText;
                               if (lookupSettings.postFunction) eval(lookupSettings.postFunction);
                               }
                          else
                               {
                               if ( ReLocation )
                                    {
                                    document.location.href = ReLocation[1];
                                    }
                               else
                                    {
                                    return http.responseText;
                                    }
                               }
                          this.working = false;
                          this.http = false;
                          }
                     }
                this.working = true;
                this.http.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
                this.http.send(lookupSettings.values);
                }
           if(!this.http)
                {
                alert('Ошибка при создании XMLHTTP объекта. Ваш браузер не поддерживается системой!')
                }
           }
      }
