﻿var req;
var keyLetter = "";

function Initialize()
{
    try
    {
        req=new ActiveXObject("Msxml2.XMLHTTP");
    }
    catch(e)
    {
        try
        {
            req=new ActiveXObject("Microsoft.XMLHTTP");
        }
        catch(oc)
        {
            req=null;
        }
    }

    if(!req&&typeof XMLHttpRequest!="undefined")
    {
        req=new XMLHttpRequest();
    }

}


function SendQuery(key)
{
    keyLetter = key;
    //alert(key);
    Initialize();
    var url="process.aspx?k="+key;
    //alert(url);
    if(req!=null)
    {
        req.onreadystatechange = Process;
        req.open("GET", url, true);
        req.send(null);
    }

}

function Process()
{
    //alert("inside process");
    if (req.readyState == 4)
        {
        // only if "OK"
          if (req.status == 200)
            {
                //alert ("correct");
                if(req.responseText=="")
                {
                    HideDiv("searchFrame");
                   
                    }
                else
                {
                    //alert("result");
                    //alert(req.responseText);
                    //ShowDiv("searchFrame");
                    ShowDiv("searchFrame");
                    if(keyLetter == "")
                         HideDiv("searchFrame");                
                    else
                        ShowDiv("searchFrame");   
                    
                    document.getElementById("autoComplete").innerHTML = req.responseText;
                    
                }
            }
            else
            {
                document.getElementById("autoComplete").innerHTML=
                    "There was a problem retrieving data:<br>" 
                    + req.statusText;
            }
        }
}

function ShowDiv(divid)
{ 

   if (document.layers)
   {
  
       document.layers[divid].visibility="show";
       }
   else {

        document.getElementById(divid).style.visibility="visible";
         }
  
}

function HideDiv(divid)
{
   if (document.layers)
    document.layers[divid].visibility="hide";
   else 
   document.getElementById(divid).style.visibility="hidden";
}

function BodyLoad()
{
   HideDiv("autoComplete");
    //document.form1.keyword.focus();

}

/*function SetTextbox( TextboxID, data, MyDiv )
{

    document.getElementById(TextboxID).value = data;
    //document.getElementById('searchHidden').value = data;
    HideDiv( "autoComplete" );
    window.location.href = 'http://localhost:51786/TractorProject/.?search/'+data;
   
 
}*/



function showhide(id)
{
   obj = getobj(id);
   if (!obj) return false;
   if (obj.style.display == '')
       obj.style.display = 'none'
   else
      obj.style.display = '';
   if (document.timer)
	   clearTimeout(document.timer);
   
   getobj('shadow').style.height = Viewport() + "px";
   document.timer = setTimeout('setShadow()',1050);
   return false;
}
function setShadow()
{
   getobj('shadow').style.height = Viewport() + "px";
}
function getobj(id)
{
    if ((typeof(plus2id)=="undefined")&&(document.getElementById('plusId')))
        plus2id=document.getElementById('plusId').value + '_';
    if(typeof(plus2id)=="undefined")
        plus2id='';
    if (document.getElementById(plus2id+id))
        return document.getElementById(plus2id+id);
    return document.getElementById(id);
}
 function Viewport()
 { 
  this.windowX = (document.documentElement && document.documentElement.clientWidth) || window.innerWidth || self.innerWidth || document.body.clientWidth; 
  this.windowY = (document.documentElement && document.documentElement.clientHeight) || window.innerHeight || self.innerHeight || document.body.clientHeight; 
  this.scrollX = (document.documentElement && document.documentElement.scrollLeft) || window.pageXOffset || self.pageXOffset || document.body.scrollLeft; 
  this.scrollY = (document.documentElement && document.documentElement.scrollTop) || window.pageYOffset || self.pageYOffset || document.body.scrollTop; 
  this.pageX = (document.documentElement && document.documentElement.scrollWidth) ? document.documentElement.scrollWidth : (document.body.scrollWidth < document.body.offsetWidth) ? document.body.scrollWidth : document.body.offsetWidth; 
  this.pageY = document.all ? Math.max(Math.max(document.documentElement.offsetHeight, document.documentElement.scrollHeight), Math.max(document.body.offsetHeight, document.body.scrollHeight)) : (document.body ? document.body.scrollHeight : ((document.documentElement.scrollHeight != 0) ? document.documentElement.scrollHeight : 0));
  if (this.pageY < 10)
  this.pageY = (document.documentElement && document.documentElement.scrollHeight) ? document.documentElement.scrollHeight : (document.body.scrollHeight < document.body.offsetHeight) ? document.body.scrollHeight : document.body.offsetHeight;
  //if (this.pageY < document.documentElement.clientHeight) return document.documentElement.clientHeight;
  return this.pageY;
  }
  
function setReport(obj,name)
{
    setShadow();
    getobj('reporthere').src = name;
    document.move2id(obj,'reporthere',-287,-260);
}

function change_parent_url(url)
{
    document.location=url;
}	
