﻿// JScript File
var xmlHttp;
var indA = 0;

function createOptions(str1)
{
  
  indA = 1;
  xmlHttp = GetXmlHttpObject();
  if (xmlHttp==null)
  {
    alert ("Your browser doesn't support AJAX!");
    return;
  }
  
  var url = "../bbKnowDB/getTerms.php";
  
  url = url+"?wq="+str1;
  xmlHttp.open("GET", url, true);
  xmlHttp.onreadystatechange = stateChanged;
  xmlHttp.send(null);
  
}


function readContent(str2)
{
  var tOpt = document.getElementById('select1');
  var valueOfContent;

  if (str2 == "0"){
    tOpt.selectedIndex = 0;
    valueOfContent = tOpt.value;
  }
  else
  {
   valueOfContent = tOpt.value;
  }
    
  indA = 2;  
  xmlHttp = GetXmlHttpObject();
  if (xmlHttp==null)
  {
    alert ("Your browser doesn't support AJAX!");
    return;
  }
  
  var url = "../bbKnowDB/getTermContent.php";
  url = url+"?iq="+valueOfContent;
  url = url+"&sid="+Math.random();
  xmlHttp.open("GET", url, true);
  xmlHttp.onreadystatechange = stateChanged;
  xmlHttp.send(null);

}



  
function stateChanged() 
{ 
  if ((xmlHttp.readyState==4) || (xmlHttp.readyState=="complete"))
  { 
    if (indA == 1){
      document.getElementById("selectTerms1").innerHTML=xmlHttp.responseText;
    } 
    if (indA == 2){
      document.getElementById("content1").innerHTML=xmlHttp.responseText;
    } 
    if (indA == 3){
      document.getElementById("completeBox").innerHTML=xmlHttp.responseText;
    } 
    if (indA == 4){
      document.getElementById("content2").innerHTML=xmlHttp.responseText;
    } 

    indA = 0;
  } 
}



function GetXmlHttpObject()
{
var xmlHttp = null;

  try
  {
   // Firefox, Opera 8.0+, Safari
    xmlHttp=new XMLHttpRequest();
  }
  catch (exception)
  {
   //Internet Explorer
    try
    {
      xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
    }
    catch (exception)
    {
      xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
  }
  
  
  return xmlHttp;
}


function completeTerms()
{

  var str3, strT;
  var len;
  
  indA = 3;

  str3 = document.getElementById("txtInput").value;
  len = str3.length;
  
  strT = str3.substr(0, len);
  
  str3 = strT;
  if (len > 0){
    document.getElementById("completeBox").style.border = "solid 1px #2a7fff" ;
    //document.getElementById("completeBox").style.backgroundColor = "#ffeeaa" ;
  }
  else
  {
    document.getElementById("completeBox").style.border = "solid 0px #ffffff" ;
    document.getElementById("completeBox").innerHTML = "" ;
    document.getElementById("content2").innerHTML = "" ;
    return;
  }

  xmlHttp = GetXmlHttpObject();
  if (xmlHttp==null)
  {
    alert ("Your browser doesn't support AJAX!");
    return;
  }
  
  var url = "../bbKnowDB/complteWords.php";
  
  url = url+"?tyInput="+str3;
  xmlHttp.open("GET", url, true);
  xmlHttp.onreadystatechange = stateChanged;
  xmlHttp.send(null);

}


function findTerm(str4, strContent)
{

  document.getElementById("txtInput").value = strContent;
  document.getElementById("completeBox").style.border = "solid 0px #ffffff" ;
  document.getElementById("completeBox").innerHTML = "" ;

  indA = 4;
  xmlHttp = GetXmlHttpObject();
  if (xmlHttp==null)
  {
    alert ("Your browser doesn't support AJAX!");
    return;
  }
  
  var url = "../bbKnowDB/getTermContent.php";
  
  url = url+"?iq="+str4;
  xmlHttp.open("GET", url, true);
  xmlHttp.onreadystatechange = stateChanged;
  xmlHttp.send(null);
  
}


function changeColor(chgClr)
{
  var temp = "";
  temp = chgClr;
  
 // document.getElementById(chgClr).style.backgroundColor = "#d0937f";
  document.getElementById(temp).style.textDecoration = "underline";

}


function changeBack(chgClr)
{

  document.getElementById(chgClr).style.textDecoration = "none";
}