﻿// JScript File
var currentTimer=0;

document.onmousedown=function(e){
var e=e? e : window.event;
var event_element=e.target? e.target : e.srcElement;
if (event_element.id.indexOf("divTagDropDown") <0 && event_element.className != 'high') {
    for (var i=1;i<3;i++)
    try {
      getElement("divTagDropDown" + i).style.visibility='hidden';
    }
    catch (e) {}
  }
}

function getXmlHttpObject()
{
  var xmlHttp=null;
  try
    {
    // Firefox, Opera 8.0+, Safari
    xmlHttp=new XMLHttpRequest();
    }
  catch (e)
    {
    // Internet Explorer
    try
      {
      xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
      }
    catch (e)
      {
      xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
      }
    }
  return xmlHttp;
}

function showTagList(pControl, pTagCategory, pQuery, pPage, pInstance) {
  clearTimeout(currentTimer);  
  currentTimer=setTimeout('getTags("' + pControl + '",' + pTagCategory + ',"' + pQuery + '",' + pPage + ',' + pInstance + ')',500);
}

function getTags(pControl,pTagCategory, str, pPage, pInstance)
{
  if (str.length==0)
    { 
     str="%";
    }
  xmlHttp=getXmlHttpObject()
  if (xmlHttp==null)
    {
    window.alert ("Your browser does not support AJAX!");
    return;
    } 
  var url="/community/ajax/tagddl.aspx";
  url=url+"?q="+escape(str)+"&control="+pControl+"&tcid="+pTagCategory+"&p="+pPage+"&instance="+pInstance;
  url=url+"&sid="+Math.random();

  document.body.style.cursor = "wait";
  getElement('divTagDropDown' + pInstance).style.left=getPosX(getElement(pControl)) - 0 + 'px';
  getElement('divTagDropDown' + pInstance).style.top=getPosY(getElement(pControl)) + getElement(pControl).offsetHeight + 'px';
  getElement('divTagDropDown' + pInstance).style.width=getElement(pControl).offsetWidth - 5 + 'px';
  getElement('masterSpinner').style.display='block';

  xmlHttp.onreadystatechange=function()
    {
    if(xmlHttp.readyState==4)
      {
      if (xmlHttp.responseText.length > 0) 
        { 
        getElement('divTagDropDown' + pInstance).innerHTML=xmlHttp.responseText;
        getElement('divTagDropDown' + pInstance).style.visibility='visible';
        getElement(pControl).focus();
        }
      else 
        {
        getElement('divTagDropDown' + pInstance).innerHTML="";
        getElement('divTagDropDown' + pInstance).style.visibility='hidden';
        }  
      getElement('masterSpinner').style.display='none';
      document.body.style.cursor = "default";
      }
    }
  xmlHttp.open("GET",url,true);
  xmlHttp.send(null);
}

function selectTag(pControl, pTagName, pInstance) 
{
  getElement(pControl).value=pTagName;
  getElement(pControl).focus();
  getElement(pControl).select();
  getElement('divTagDropDown' + pInstance).style.visibility='hidden';
}


function validKey(e) {
var evt = (e) ? e : window.event;
var key = (evt.keyCode) ? evt.keyCode : evt.which;
if (key == 60 || key == 62 || key == 37) {
  return false;
}
return true;
}

function hideList(pInstance) {
  getElement('divTagDropDown' + pInstance).style.visibility='hidden';
}