function submitHelpForm(companyornot,companyid)
{
  doRequest('','contact','helprequest','&helptext='+document.getElementById('helptext'+companyornot).value+'&helpcontact='+document.getElementById('helpcontact'+companyornot).value+'&assigntocompanyid='+companyid,'helpconfirmation'+companyornot);
  document.getElementById('helptext'+companyornot).value = '';
  document.getElementById('helpcontact'+companyornot).value = '';
}

function resetQuickDial()
{
  document.getElementById('col1head').innerHTML = 'Find a Company';
  document.getElementById('resetquickdial').style.display = 'none';
  document.getElementById("quickdial_initial").style.display = "block";
  document.getElementById("quickdial_search").style.display = "none";
}

function resetSearchResults()
{
  document.getElementById('col3head').innerHTML = 'How To?';
  document.getElementById('resetsearchresults').style.display = 'none';
  document.getElementById("col3body").style.display = "block";
  document.getElementById("col3_search").style.display = "none";
}

function showSearchResults()
{
  document.getElementById('col3head').innerHTML = 'Search Results';
  document.getElementById("col3body").style.display = "none";
  document.getElementById("col3_search").style.display = "block";
  document.getElementById('resetsearchresults').style.display = 'block';
}

function ShowOnlyCertainTitles(elementType,titleListToShow,titleListExtToHide)
{
  var elementList = document.getElementsByTagName(elementType);
  var titlesToShow = titleListToShow.split(",");
  var titlesToHide = titleListExtToHide.split(",");

  for(var a = 0; a < elementList.length; a++) // Step through all 'spans' or whatever
  {
    for(var b = 0; b < titlesToHide.length; b++) // Step through all titles supplied to hide
    {
      if(elementList[a].title.indexOf(titlesToHide[b]) >= 0)
      {
	    elementList[a].style.display='none';
      }
    }
    for(var c = 0; c < titlesToShow.length; c++) // Step through all titles supplied to display
    {
	  if(elementList[a].title == titlesToShow[c])
      {
	    elementList[a].style.display='block';
      }
    }
  }

  document.getElementById("showallsearchresults").style.display = "block";
}

function ShowAllSearchResultTitles(elementType,titleExtListToShow)
{
  var elementList = document.getElementsByTagName(elementType);
  var titlesToShow = titleExtListToShow.split(",");

  for(var a = 0; a < elementList.length; a++) // Step through all 'spans' or whatever
  {
    for(var b = 0; b < titlesToShow.length; b++) // Step through all titles supplied to display
    {
      if(elementList[a].title.indexOf(titlesToShow[b]) >= 0)
      {
	    elementList[a].style.display='block';
      }
    }
  }

  document.getElementById("showallsearchresults").style.display = "none";
}

function validateInput(inputfields,errormessage)
{
  var inputtovalidate = inputfields.split(",");
  var inputvalue;

  for(var i = 0; i < inputtovalidate.length; i++)
  {
    inputvalue = document.getElementById(inputtovalidate[i]).value;
    if (typeof inputvalue == "undefined" || null == inputvalue || undefined == inputvalue || void 0 == inputvalue || inputvalue == "")
    {
      alert(errormessage)
      return false;
    }
  }

  return true;
}

function getHTTPObject()
{
  var xmlHttp = false;

  try
  { // Firefox, Opera 8.0+, Safari
    xmlHttp=new XMLHttpRequest();
  }
  catch (e)
  { // Internet Explorer
    try
    {
      xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
    }
    catch (e)
    {
      try
      {
        xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
      }
      catch (e)
      {
        alert("Your browser does not support AJAX.");
        xmlHttp = false;
      }
    }
  }

  return xmlHttp;
}

function doRequest(searchobj,cgifile,typevalue,extravalues,divstochange)
{
if (cgifile == "search" && searchobj.value == "")
{
}
else
{
  var xmlHttp = getHTTPObject();

  xmlHttp.onreadystatechange=function()
  {
    if(xmlHttp.readyState < 4)
    {
      if (cgifile == 'search')
      {
        document.getElementById("showother").style.display = "none";
        document.getElementById("mainchunk").style.display = "block";
        document.getElementById("quickdial_initial").style.display = "none";
        document.getElementById("quickdial_search").style.display = "block";
        document.getElementById("quickdial_search").innerHTML = "<img src='/images/quickdial.gif' style='margin:0px;'>";
        document.getElementById("col3body").style.display = "none";
        document.getElementById("col3_search").style.display = "block";
        document.getElementById("col3_search").innerHTML = "<img src='/images/loadingsr.gif'>";
	  } else // if (cgifile == 'view')
      {
	    if (divstochange != "")
		{
	      var changedivs = divstochange.split ( "," );
		  for (var i = 0; i < changedivs.length; i++)
		  { 
            document.getElementById(changedivs[i]).innerHTML = "<img src='/images/loading.gif'>";
          }
		} else
		{
          document.getElementById("mainchunk").style.display = "none";
          document.getElementById("showother").style.display = "block";
          document.getElementById("showother").innerHTML = "<img src='/images/loadingcd.gif'>";
		}
      }
    }

    if(xmlHttp.readyState==4)
    {
	  if (xmlHttp.status == 200)
	  {
	    if (cgifile == 'search')
		{
          document.getElementById("col1head").innerHTML = "Filter by Company";
          document.getElementById("col3head").innerHTML = "Search Results";
          document.getElementById("resetquickdial").style.display = "block";
          document.getElementById("resetsearchresults").style.display = "block";
          // document.myForm.time.value=xmlHttp.responseText;
          // document.getElementById("quickdial").innerHTML = xmlHttp.responseText;
	      var response = xmlHttp.responseText.split ("[BRK]");
          document.getElementById("quickdial_search").innerHTML = response[0];
	      document.getElementById("col3_search").innerHTML = response[1];
	      document.getElementById("recentsearches").innerHTML = response[2];
		} else // if (cgifile == 'view')
		{
	      if (divstochange != "")
		  {
	        var response = xmlHttp.responseText.split ("[BRK]");
	        var changedivs = divstochange.split (",");
		    for (var i = 0; i < changedivs.length; i++)
		    { 
              document.getElementById(changedivs[i]).innerHTML = response[i];
            }
          } else
          {
            document.getElementById("showother").innerHTML = xmlHttp.responseText;
          }
        }
      } else
	  {
        alert('There was a problem with the request, status: '+xmlHttp.status);
      }
    }
  }

  var url = "/cgi-bin/";
  if (cgifile == 'search')
  {
//    url = url+"search.cgi?type=searchpopulatequickdial&searchterm="+searchobj.value;
    url = "/html/checkloginstatus.php?loggedinfile=user&loggedintype=searchpopulatequickdial&searchterm="+searchobj.value;
    url = url+"&notloggedinfile=search&notloggedintype=searchpopulatequickdial&searchterm="+searchobj.value;
    url = url+"&sid="+Math.random();
  }else // if (cgifile == 'viewdetails')
  {
    url = url+cgifile+".cgi?type="+typevalue+extravalues;
    url = url+"&sid="+Math.random();
  }

  xmlHttp.open("GET",url,true);
  xmlHttp.send(null);
}
}

function showCompanyProfile(companyid)
{
  var http = getHTTPObject();

  http.onreadystatechange=function()
  {
    if(http.readyState < 4)
    {
      document.getElementById("companyprofilebar").innerHTML = "Loading Company Profile";
      document.getElementById("companyprofilebody").innerHTML = "<img src='/images/loading.gif'>";
	}

    if(http.readyState==4)
    {
      if (http.status == 200)
      {
        document.getElementById("companyprofile").innerHTML = http.responseText;
      } else
      {
        alert('There was a problem with the request, status: '+http.status);
      }
    }
  }

  var url = "/cgi-bin/view.cgi?type=showcompanyprofile&companyid="+companyid;
  url = url+"&sid="+Math.random();

  http.open("GET",url,true);
  http.send(null);
}

function login(form)
{
    var username = document.getElementById(form.id + "-username").value;
    var password = document.getElementById(form.id + "-password").value;
    var http = getHTTPObject();
	var url = form.action;
    http.open("get", url, false, username, password); // form.
    http.send(""); // form.
	if (http.status == 200) {
		document.location = url;
	} else {
        alert("Incorrect username and/or password!");
    }
    return false;
}

function logout(form)
{
    var http = getHTTPObject();
    http.open("get", form.action, false, "null", "null");
    http.send("");
    alert("Please close the browser window to log out completely.");
}

