﻿// JScript File

var industryloaded = " ";
var lookupfile = "/RaytekWeb/SupportAndDownloads/Faq/GetFaqData.aspx?p=";
var kbdata = " ";
var currentid;
var trackload = 0;

function ExpandSubs()
{

	
	var divs = document.getElementsByTagName("div");
	for (var i=0;i<divs.length;i++) 
	{
		if (document.forms[0].kbtreehidden.value.indexOf(divs[i].id + "|") != -1 && divs[i].name == null) 
		{
			if(divs[i].className == 'hide')
			{
				ToggleDiv(divs[i].id);
			}
		}
	}
	
}

function ExpandTree()
{
	var divs = document.getElementsByTagName("div");
	for (var i=0;i<divs.length;i++) 
	{
		if (document.forms[0].kbtreehidden.value.indexOf(divs[i].id + "|") != -1) 
		{
			if(divs[i].name != null)
			{
					if(divs[i].name.indexOf("raytek") != -1)
						{
							if(industryloaded.indexOf(divs[i].id) == -1)
							{
							ToggleDiv(divs[i].id);
							industryloaded = industryloaded + divs[i].id;
							lookupfile = "/RaytekWeb/SupportAndDownloads/Faq/GetFaqData.aspx?p=";
							lookupfile = lookupfile + divs[i].name;
							currentid = divs[i].id;
							DataLookup();		
							}
						}
			}
		}
	}
	
}


function ToggleDiv(thediv)
{
	if(document.getElementById)
	{
		var div_id = document.getElementById(thediv);
		
		if(div_id.className != 'show')
		{
			div_id.className = 'show';			
			//set hidden box
			if(document.forms[0].kbtreehidden.value.indexOf(thediv) == -1)
			{
				document.forms[0].kbtreehidden.value += thediv + "|";
			}
		
		}
		else
		{
			div_id.className = 'hide';
			//remove from hidden box
			document.forms[0].kbtreehidden.value = document.forms[0].kbtreehidden.value.replace(thediv,"");
		}
	}
}



///////////ajax

var XMLHTTPREQUEST_MS_PROGIDS = new Array(
	"Msxml2.XMLHTTP.7.0",
	"Msxml2.XMLHTTP.6.0",
	"Msxml2.XMLHTTP.5.0",
	"Msxml2.XMLHTTP.4.0",
	"MSXML2.XMLHTTP.3.0",
	"MSXML2.XMLHTTP",
	"Microsoft.XMLHTTP"
);

//-----------------------------------------------------------------------------
// Returns an XMLHttpRequest object.
//-----------------------------------------------------------------------------
function getXMLHttpRequest()
{
	var httpRequest = null;

	// Create the appropriate HttpRequest object for the browser.
	if (window.XMLHttpRequest != null)
		httpRequest = new window.XMLHttpRequest();
	else if (window.ActiveXObject != null)
	{
		// Must be IE, find the right ActiveXObject.
		var success = false;
		for (var i = 0; i < XMLHTTPREQUEST_MS_PROGIDS.length && !success; i++)
		{
			try
			{
				httpRequest = new ActiveXObject(XMLHTTPREQUEST_MS_PROGIDS[i]);
				success = true;
			}
			catch (ex)
			{}
		}
	}

	// Display an error if we couldn't create one.
	if (httpRequest == null)
		alert("Error in HttpRequest():\n\nCannot create an XMLHttpRequest object.");

	// Return it.
	return httpRequest;
}

var xhr = getXMLHttpRequest();

function ExpandIndustry(thediv, p)
{
	if(document.getElementById(thediv).className != 'show')
	    document.getElementById('img' + thediv).src = '/RaytekWeb/images/arrowU.gif';
	else
	document.getElementById('img' + thediv).src = '/RaytekWeb/images/arrowD.gif';
	//get current id
	if(document.getElementById)
	{
		var div_id = document.getElementById(thediv);
		
		if(div_id.className != 'show')
		{
			div_id.className = 'show';
			//set hidden box
			if(document.forms[0].kbtreehidden.value.indexOf(thediv) == -1)
			{
				//on an industry expand, clear values and start over
				document.forms[0].kbtreehidden.value = thediv + "|";
			}
			
			//load if not already
			if(industryloaded.indexOf(thediv) == -1)	    
			{
			    			
				//make sure no other request is going
				if(trackload == 0)
				{
					industryloaded = industryloaded + thediv;
					lookupfile = "/RaytekWeb/SupportAndDownloads/Faq/GetFaqData.aspx?p=";
					lookupfile = lookupfile + p;
					currentid = thediv;
					trackload = 1;
					DataLookup();
				}		
			}
		
		}
		else
		{
			div_id.className = 'hide';
			//remove from hidden box
			document.forms[0].kbtreehidden.value = document.forms[0].kbtreehidden.value.replace(thediv,"");
		}		
		
	}
}

function DataLookup(event)
{
    
		// Abort any currently active request.
		xhr.abort();
	    
		xhr.onreadystatechange = getData;
		xhr.open("GET",lookupfile,true);
		xhr.send(null);
}

function getData()
{
	if(xhr.readyState < 4)
	{
		kbdata = "&nbsp; <img src='/RaytekWeb/images/loading.gif' width='18'> Loading...";
	}
	if(xhr.readyState == 4)
		{
			if(xhr.status == 200)
			{
				kbdata = xhr.responseText;
				trackload = 0;
			}
		}
		
	if(document.getElementById)
	{
		var div_id = document.getElementById(currentid);		
		div_id.innerHTML = kbdata;	
		ExpandSubs(); //on reload with BACK button, expand subchannels
		
	}

}



