﻿
var timerID = 0;
var tStart  = null;

var req;
var autoDiv;
var AutoText;

// Function to Initialize

function setText(thisText)

{
eval("document.form1." + autoText + ".value = thisText")
HideDiv(autoDiv)
}

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 to pass the queryString

function SendQuery(Like,thisTextBox,thisPage)

{
autoText = thisTextBox;
autoDiv = thisTextBox + 'autocomplete'

	Initialize();

	var url= thisPage + ".aspx?likeString="+Like;

	

	if(req!=null)

	{

		req.onreadystatechange = Process;

		req.open("GET", url, true);

        req.send(null);

	}

}
    // Function to procee the request

function Process(thisDiv)

{

	if (req.readyState == 4) 

        {

        // only if "OK"

			if (req.status == 200) 

			{

				if(req.responseText=="")

					HideDiv(autoDiv);

				else

				{

					ShowDiv(autoDiv);
					document.getElementById(autoDiv).innerHTML =req.responseText;

				}

			}

			else 

			{

				document.getElementById(autoDiv).innerHTML="There was a problem retrieving data:"+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()

{

}

function UpdateTimer() {
   if(timerID) {
      clearTimeout(timerID);
      clockID  = 0;
   }

   if(!tStart)
      tStart   = new Date();

   var   tDate = new Date();
   var   tDiff = tDate.getTime() - tStart.getTime();

   tDate.setTime(tDiff);

   document.getElementById("timer").innerHTML = "" 
                                   + tDate.getMinutes() + ":" 
                                   + tDate.getSeconds();
   
   timerID = setTimeout("UpdateTimer()", 1000);
}

function Start() {
   tStart   = new Date();

   document.getElementById("timer").innerHTML = "0:0";

   timerID  = setTimeout("UpdateTimer()", 1000);
}

function Stop() {
   if(timerID) {
      clearTimeout(timerID);
      timerID  = 0;
   }

   tStart = null;
}
