//
// (c)2008 The Andra Group, Inc.
//

var iconPlus = new Image;
var iconMinus = new Image;
iconPlus.src = 'images/plus.gif';
iconMinus.src = 'images/minus.gif';
var stateMfr = 1;
var stateKeywords = 0;
var stateColors = 0;
var stateSizes = 0;

function initLinks() {document.getElementById('cellMfr').style.background = 'white'}

function toggleMfr(catID, section, cols, linkText, mode) {
	if (stateMfr == 0) {
		clearAll();
		document.getElementById('divDisplay').style.visibility = "visible";
		document.getElementById('divDisplay').style.display = "inline";
		document.getElementById('iconMfr').src = iconMinus.src;
		document.getElementById('cellMfr').style.background = 'white';
		stateMfr = 1;
		showDiv(catID, section, cols, linkText, mode)
	} else {
		clearAll();
		document.getElementById('divDisplay').style.visibility = "hidden";
		document.getElementById('divDisplay').style.display = "none";
	}
}

function toggleKeywords(catID, section, cols, linkText, mode) {
	if (stateKeywords == 0) {
		clearAll();
		document.getElementById('divDisplay').style.visibility = "visible";
		document.getElementById('divDisplay').style.display = "inline";
		document.getElementById('iconKeywords').src = iconMinus.src;
		document.getElementById('cellKeywords').style.background = 'white';
		stateKeywords = 1;
		showDiv(catID, section, cols, linkText, mode)
	} else {
		clearAll();
		document.getElementById('divDisplay').style.visibility = "hidden";
		document.getElementById('divDisplay').style.display = "none";
	}
}

function toggleColors(catID, section, cols, linkText, mode) {
	if (stateColors == 0) {
		clearAll();
		document.getElementById('divDisplay').style.visibility = "visible";
		document.getElementById('divDisplay').style.display = "inline";
		document.getElementById('iconColors').src = iconMinus.src;
		stateColors = 1;
		document.getElementById('cellColors').style.background = 'white';
		showDiv(catID, section, cols, linkText, mode)
	} else {
		clearAll();
		document.getElementById('divDisplay').style.visibility = "hidden";
		document.getElementById('divDisplay').style.display = "none";
	}
}
function toggleSizes(catID, section, cols, linkText, mode) {
	if (stateSizes == 0) {
		clearAll();
		document.getElementById('divDisplay').style.visibility = "visible";
		document.getElementById('divDisplay').style.display = "inline";
		document.getElementById('iconSizes').src = iconMinus.src;
		stateSizes = 1;
		document.getElementById('cellSizes').style.background = 'white';
		showDiv(catID, section, cols, linkText, mode)
	} else {
		clearAll();
		document.getElementById('divDisplay').style.visibility = "hidden";
		document.getElementById('divDisplay').style.display = "none";
	}
}

function clearAll() {
	stateMfr = 0;
	stateKeywords = 0;
	stateColors = 0;
	stateSizes = 0;
	document.getElementById('cellMfr').style.background = '';
	document.getElementById('cellKeywords').style.background = '';
	document.getElementById('cellColors').style.background = '';
	document.getElementById('cellSizes').style.background = '';
	document.getElementById('iconMfr').src = iconPlus.src;
	document.getElementById('iconKeywords').src = iconPlus.src;
	document.getElementById('iconColors').src = iconPlus.src;
	document.getElementById('iconSizes').src = iconPlus.src;
}

	var xmlHttp;
	var requestURL;
	if (window.location.pathname.toLowerCase().indexOf('herroom3') == -1) {requestURL = 'http://' + window.location.hostname + '/dept-links-2.aspx'} else {requestURL = 'http://localhost/HerRoom3/dept-links-2.aspx'}
	var is_ie = (navigator.userAgent.indexOf('MSIE') >= 0) ? 1 : 0;
	var is_ie5 = (navigator.appVersion.indexOf("MSIE 5.5")!=-1) ? 1 : 0;
	var is_opera = ((navigator.userAgent.indexOf("Opera6")!=-1)||(navigator.userAgent.indexOf("Opera/6")!=-1)) ? 1 : 0;
// netscape, safari, mozilla behave the same???
	var is_netscape = (navigator.userAgent.indexOf('Netscape') >= 0) ? 1 : 0;
	var divID = 'divDisplay';

    function showDiv(catID, section, cols, linkText, mode) {
        if (catID.length > 0) {
            document.getElementById(divID).innerHTML = '<b><font color=blue><blink>&nbsp;&nbsp;Loading...</blink></font></b><br><br>';
            //Append the name to search for to the requestURL
            var url = requestURL + "?catid=" + catID + "&section=" + section + "&cols=" + cols + "&linktext=" + linkText + "&mode=" + mode;
            
            //Create the xmlHttp object to use in the request
            //stateChangeHandler will fire when the state has changed, i.e. data is received back
            // This is non-blocking (asynchronous)
            xmlHttp = GetXmlHttpObject(stateChangeHandler);
            
            //Send the xmlHttp get to the specified url
            xmlHttp_Get(xmlHttp, url);
        }
        else {
            //Textbox blanked out, clear the results
            document.getElementById(divID).innerHTML = '';
        }
    }

    //stateChangeHandler will fire when the state has changed, i.e. data is received back
    // This is non-blocking (asynchronous)
    function stateChangeHandler()
    {
        //readyState of 4 or 'complete' represents that data has been returned
        if (xmlHttp.readyState == 4 || xmlHttp.readyState == 'complete'){
            //Gather the results from the callback
            var str = xmlHttp.responseText;

            //Populate the innerHTML of the div with the results
            document.getElementById(divID).innerHTML = str;
        }
    }

    // XMLHttp send GET request
    function xmlHttp_Get(xmlhttp, url) {
        xmlhttp.open('GET', url, true);
        xmlhttp.send(null);
    }

    function GetXmlHttpObject(handler) {
        var objXmlHttp = null;    //Holds the local xmlHTTP object instance

        //Depending on the browser, try to create the xmlHttp object
        if (is_ie){
            //The object to create depends on version of IE
            //If it isn't ie5, then default to the Msxml2.XMLHTTP object
            var strObjName = (is_ie5) ? 'Microsoft.XMLHTTP' : 'Msxml2.XMLHTTP';
            
            //Attempt to create the object
            try{
                objXmlHttp = new ActiveXObject(strObjName);
                objXmlHttp.onreadystatechange = handler;
            }
            catch(e){
            //Object creation errored
                alert('IE detected, but object could not be created. Verify that active scripting and activeX controls are enabled');
                return;
            }
        }
        else if (is_opera){
            //Opera has some issues with xmlHttp object functionality
            //alert('Opera detected. The page may not behave as expected.');
            return;
        }
        else{
            // Mozilla | Netscape | Safari
            objXmlHttp = new XMLHttpRequest();
            objXmlHttp.onload = handler;
            objXmlHttp.onerror = handler;
        }
        
        //Return the instantiated object
        return objXmlHttp;
    }

    function UseValue(strVal){
//        document.frmStuff.txtName.value = strVal;
    }
