function getID(id)
{
	return document.getElementById(id);
}

// Determine browser and version.

function Browser() {

  var ua, s, i;

  this.isIE    = false;
  this.isNS    = false;
  this.version = null;

  ua = navigator.userAgent;

  s = "MSIE";
  if ((i = ua.indexOf(s)) >= 0) {
    this.isIE = true;
    return;
  }

  s = "Netscape6/";
  if ((i = ua.indexOf(s)) >= 0) {
    this.isNS = true;
    return;
  }

  s = "Gecko";
  if ((i = ua.indexOf(s)) >= 0) {
    this.isNS = true;
    return;
  }
}
var browser = new Browser();

/////////////////////////////////////////////////////////////////////////////////////

// Coded by Waseem Khan
// Developer at PakCoders
// Downloaded from http://blog.pakcoders.com

/////////////////////////////////////////////////////////////////////////////////////
// Dragging Function Starts Here
/////////////////////////////////////////////////////////////////////////////////////

// Global object to hold drag information.

var dragObj = new Object();
function dragStart(event, id) {
  var x, y;
  dragObj.elNode = getID(id);
  // Get cursor position with respect to the page.

  if (browser.isIE) {
    x = window.event.clientX + document.documentElement.scrollLeft
      + document.body.scrollLeft;
    y = window.event.clientY + document.documentElement.scrollTop
      + document.body.scrollTop;
  }
  if (browser.isNS) {
    x = event.clientX + window.scrollX;
    y = event.clientY + window.scrollY;
  }

  // Save starting positions of cursor and element.

  dragObj.cursorStartX = x;
  dragObj.cursorStartY = y;
  dragObj.elStartLeft  = parseInt(dragObj.elNode.style.left, 10);
  dragObj.elStartTop   = parseInt(dragObj.elNode.style.top,  10);

  if (isNaN(dragObj.elStartLeft)) dragObj.elStartLeft = 0;
  if (isNaN(dragObj.elStartTop))  dragObj.elStartTop  = 0;

  // Capture mousemove and mouseup events on the page.

  if (browser.isIE) {
    document.attachEvent("onmousemove", dragGo);
    document.attachEvent("onmouseup",   dragStop);
    window.event.cancelBubble = true;
    window.event.returnValue = false;
  }
  if (browser.isNS) {
    document.addEventListener("mousemove", dragGo,   true);
    document.addEventListener("mouseup",   dragStop, true);
    event.preventDefault();
  }
}

function dragGo(event) {

  var x, y;

  // Get cursor position with respect to the page.

  if (browser.isIE) {
    x = window.event.clientX + document.documentElement.scrollLeft
      + document.body.scrollLeft;
    y = window.event.clientY + document.documentElement.scrollTop
      + document.body.scrollTop;
  }
  if (browser.isNS) {
    x = event.clientX + window.scrollX;
    y = event.clientY + window.scrollY;
  }

  // Move drag element by the same amount the cursor has moved.

  dragObj.elNode.style.left = (dragObj.elStartLeft + x - dragObj.cursorStartX) + "px";
  dragObj.elNode.style.top  = (dragObj.elStartTop  + y - dragObj.cursorStartY) + "px";

  if (browser.isIE) {
    window.event.cancelBubble = true;
    window.event.returnValue = false;
  }
  if (browser.isNS)
    event.preventDefault();
}

function dragStop(event) {

  // Stop capturing mousemove and mouseup events.

  if (browser.isIE) {
    document.detachEvent("onmousemove", dragGo);
    document.detachEvent("onmouseup",   dragStop);
  }
  if (browser.isNS) {
    document.removeEventListener("mousemove", dragGo,   true);
    document.removeEventListener("mouseup",   dragStop, true);
  }
}


      function getHttpRequest()
      {
      var http_request = false;
      if (window.XMLHttpRequest)
      {
      http_request = new XMLHttpRequest();
      if (http_request.overrideMimeType)
      {
      http_request.overrideMimeType('text/xml');
      }
      }
      else if (window.ActiveXObject)
      {
      try
      {
      http_request = new ActiveXObject("Msxml2.XMLHTTP");
      }
      catch (e)
      {
      try
      {
      http_request = new ActiveXObject("Microsoft.XMLHTTP");
      }
      catch (e)
      {
      }
      }
      }
      return http_request;
      }

      function makeRequest(aId, aURL)
      {
      var http_request = getHttpRequest();
      try
      {
      http_request.overrideMimeType('text/html');
      }
      catch (e)
      {
      }
      if (aId != null)
      {
      http_request.onreadystatechange = function() { renderContent(aId, http_request); };
      }


      var tmpElement = document.getElementById(aId);

      var height;
      var width;
      if (document.all)
      {
        height = document.all[aId].offsetHeight;
        width = document.all[aId].offsetWidth
      }
      else if (document.defaultView.getComputedStyle)
      {
      height = document.defaultView.getComputedStyle(tmpElement,'').height;
      width =  document.defaultView.getComputedStyle(tmpElement,'').width;
      }
      tmpElement.innerHTML = '<div class="loading" style="padding: 0px;magin: 0px;height: ' + height + ';width: ' + width + '"><center>&nbsp;<p><img src=images/loading.gif></div>'

      http_request.open('GET', aURL, true);
      http_request.send(null);


      }



      function makeRequestPost(aURL, aParameters, aRedirectId, aRedirectUrl)
      {
      var http_request = getHttpRequest();
      try
      {
      http_request.overrideMimeType('text/html');
      }
      catch (e)
      {
      }
      http_request.onreadystatechange = function() { renderContent(aRedirectId, http_request); };
      http_request.open('POST', aURL, true);
      http_request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
      http_request.setRequestHeader("Content-length", aParameters.length);
      http_request.setRequestHeader("Connection", "close");
      http_request.send(aParameters);
      }

      function redirectOnReady(aHttpRequest, aRedirectId, aRedirectUrl)
      {
      if (aHttpRequest.readyState == 4)
      {
      //var tmpElement = document.getElementById(aRedirectId);
      //tmpElement.innerHTML = aHttpRequest.responseText
      makeRequest(aRedirectId, aRedirectUrl);
      }
      }

      function renderContent(aId, aHttpRequest) {
      //alert(aHttpRequest.readyState);
      if (aHttpRequest.readyState == 4) {
      var tmpElement = document.getElementById(aId);
      tmpElement.innerHTML = aHttpRequest.responseText
      }
      //alert( aHttpRequest.responseText );
      }

      function addComment(aId)
      {
      var parameters = '';
      parameters += "message=" + document.forms['comment_' + aId].elements['message'].value;
      parameters += "&object_id=" + document.forms['comment_' + aId].elements['object_id'].value;
				parameters += "&comment_type_id=" + document.forms['comment_' + aId].elements['comment_type_id'].value;
				parameters += "&name=" + document.forms['comment_' + aId].elements['name'].value;
				parameters += "&password=" + document.forms['comment_' + aId].elements['password'].value;
				parameters += "&action=insert";

				makeRequestPost("kill_comment.php", parameters, "kill_detail_" + aId, "kill_comment.php?id=" + aId);
			}

			function registerKill()
			{
				var parameters = '';
				parameters += "kill_mail=" + document.forms['register_mail_form'].elements['kill_mail'].value;
				parameters += "&password=" + document.forms['register_mail_form'].elements['password'].value;
				parameters += "&action=insert";
				makeRequestPost("kill_add.php", parameters, "kill_list", "kill_add.php");
			}

				var detailType = new Array();
				function itemInfo(aId, aURL, aType)
				{
					var tmpElement = document.getElementById(aId);
					//alert(aId);
                                        //aURL = "gettxt.php?f=" + aURL;
                                        if (aId.substring(0, 8)=="goodDesc" && tmpElement.innerHTML.length > 0 ) {
                                          tmpElement.innerHTML = "";
                                          return;
                                        }
					if (detailType[aId] != aType && tmpElement.innerHTML.length > 0 || 1==1)
					{
						makeRequest(aId, aURL);
						detailType[aId] = aType;
					}
					else if (detailType[aId] == aType)
					{
							//tmpElement.innerHTML = "";
							//detailType[aId] = 0;
					}
					else
					{
						if (tmpElement.innerHTML.length > 0)
						{
							tmpElement.innerHTML = "";
							detailType[aId] = 0;
						}
						else
						{
							makeRequest(aId, aURL);
							detailType[aId] = aType;
						}
					}

				}

				var previousSearchQuery = "";
				function searchFormOnChange()
				{
					var query = document.forms['search_form'].elements['query'].value;
					if (query != previousSearchQuery)
					{

						var http_request = getHttpRequest();
						try
						{
							http_request.overrideMimeType('text/html');
						}
						catch (e)
						{
						}

						http_request.onreadystatechange = function() { renderDropDown(http_request); };
						http_request.open('GET', "search_result.php?type=1&query=" + query, true);
						http_request.send(null);

						previousSearchQuery = query;
					}
				}

				function searchSelectItem(aQuery)
				{
					var tmpElement = document.getElementById("search_drop_down");
					tmpElement.style.visibility='hidden';

					updateFilter(aQuery);
				}

				function renderDropDown(http_request)
				{
					if (http_request.readyState == 4)
					{
						eval(http_request.responseText);
					}
				}

				function updateDropDown(aResult, aType, aQuery)
				{
					var tmpElement = document.getElementById("search_drop_down");
					tmpHtml = '';
					for (i = 0; i < aResult.length; i++)
					{
						tmpHtml += '<div class=\"search_drop_down_item\" onclick=\"searchSelectItem(\'' + aQuery[i].replace('\'', '\\\'') + '\')\">' + aResult[i] + ' <span class=\"search_drop_down_item_stats\">(' + aType[i] + ')' + '</span></div>';
					}
					tmpElement.innerHTML = tmpHtml;	
					if (tmpHtml.length > 0)
					{
						tmpElement.style.visibility='visible';				
					}
					else
					{
						tmpElement.style.visibility='hidden';
					}
					
				}

				function submitForm()
				{
					makeRequest("kill_list", "search_result_list.php?type=1&query=" + document.forms['search_form'].elements['query'].value);
					var tmpElement = document.getElementById("search_drop_down");
					tmpElement.innerHTML = ''
					tmpElement.style.visibility='hidden';
				}