
//function called when user clicks on the plus icon.
//this function takes care of
//a) closing the plus icon div.
//b) opening the minus icon div.
//c) opening the answer div.

function descriptionHandler(id_on,id_button,id_button_negative)
{
	document.getElementById(id_on).style.display="block";
	document.getElementById(id_button_negative).style.display="block";
	document.getElementById(id_button).style.display="none";
}

//function called when user clicks on the minus icon.
//this function takes care of
//a) closing the minus icon div.
//b) opening the answer div.
//c) opening the plus icon div.

function descriptionHandlerOff(id_off,id_button,id_button_positive)
{
	document.getElementById(id_off).style.display="none";
	document.getElementById(id_button).style.display="none";
	document.getElementById(id_button_positive).style.display="block";

}

function validate(entry) {
	if (entry.charAt(0) == "+") {
		entry = entry.substring(1,entry.length);
		searchType = SEARCHALL;
		}
	else if (entry.substring(0,4) == "url:") {
		entry = entry.substring(5,entry.length);
		searchType = SEARCHURL;
		}
	else { searchType = SEARCHANY; }
	while (entry.charAt(0) == ' ') {
		entry = entry.substring(1,entry.length);
		document.forms[0].query.value = entry;
		}
	while (entry.charAt(entry.length - 1) == ' ') {
		entry = entry.substring(0,entry.length - 1);
		document.forms[0].query.value = entry;
		}
	if (entry.length < 3) {
		alert("You cannot search strings that small. Elaborate a little.");
		document.forms[0].query.focus();
		return;
		}
	convertString(entry);
	}

function convertString(reentry) {
	var searchArray = reentry.split(" ");
	if (searchType == (SEARCHANY | SEARCHALL)) { requireAll(searchArray); }
	else { allowAny(searchArray); }
	}

function splitArray(joinedString, splitString) {
	var tempArray = new Array(0);
	var arrayCounter		= 0;
	var elementBoolean	= true;
	for (var i = 0; i < joinedString.length; i++) {
		if(elementBoolean) {
			tempArray[arrayCounter] = "";
			elementBoolean 		  = false;
			}
		if(joinedString.charAt(i) == splitString) {
			arrayCounter++;
			elementBoolean = true;
			continue;
			}
		tempArray[arrayCounter] += joinedString.charAt(i);
		}
	return tempArray;
	}

/*
This function gets called from the bench when the application has only a one-match minimum.
comparing strings with nested for loops.
The first for loop has the task of iterating through each of the profiles array elements (from the source file).
For each profiles element, the second for loop iterates through each of the query terms passed to it from convertString().
*/

function allowAny(t) {
	var findings = new Array(0);
	for (i = 0; i < profiles.length; i++) {
		var compareElement  = profiles[i].toUpperCase();
		if(searchType == SEARCHANY) { var refineElement  = compareElement.substring(0,compareElement.indexOf('|HTTP')); }
		else { var refineElement = compareElement.substring(compareElement.indexOf('|HTTP'), compareElement.length); }
		for (j = 0; j < t.length; j++) {
			var compareString = t[j].toUpperCase();
			if (refineElement.indexOf(compareString) != -1) {
				findings[findings.length] = profiles[i];
				break;
				}
			}
		}
	verifyManage(findings);
	}

/*
Put a + in front of your search terms, and requireAll()gets the call.
This function is nearly identical to allowAny(), except that all terms the user enters must match the search.
With allowAny(), records were added to the result set as soon as one term matched. 
In this function, we have to wait until all terms have been compared to each record before deciding to add anything to the result set.
*/

function requireAll(t) {
	var findings = new Array(0);
	for (i = 0; i < profiles.length; i++) {
		var allConfirmation = true;
		var allString       = profiles[i].toUpperCase();
		var refineAllString = allString.substring(0,allString.indexOf('|HTTP'));
		for (j = 0; j < t.length; j++) {
			var allElement = t[j].toUpperCase();
			if (refineAllString.indexOf(allElement) == -1) {
				allConfirmation = false;
				continue;
				}
			}
		if (allConfirmation) {
			findings[findings.length] = profiles[i];
			}
		}
	verifyManage(findings);
	}

/*
This function determines whether the user's search produced any record matches
and calls one of two printout functions pending the result.
Both allowAny() and requireAll() call verifyManage() after running the respective course and pass the findings array as an argument.
*/

function verifyManage(resultSet) {
	if (resultSet.length == 0) { noMatch(); }
	else {
		copyArray = resultSet;
		formatResults(copyArray, currentMatch, showMatches);
		}
	}
	
	
var agent_isIE = true;
var agent_isNS = 0;
var agent_isMac = 0;
var agent_isAOL = 0;
//alert(agent_isIE);

if (((agent_isNS) || (agent_isIE) || (agent_isMac)) &&
   (navigator.appVersion.indexOf("4.")>=0))
    bScreen = true;
else {
    bScreen = false;
}
bScreen = true;

function DoHelp(cfcode) {

//set defaults for Help window size
// (for browsers that don't access the screen object)
    help_w=220;
    help_h=460;
    help_l=640-help_w;
    help_t=0;

if(bScreen == true)
{
    if (agent_isMac==true)
    {
        if(agent_isAOL==true)
        {
            WIDTH = 248
        }
        else
        {
            WIDTH = 255
        }
    }
    else
    {
        if(screen.width <= 800)
        {
            WIDTH = 180
            //alert(WIDTH)
        }
        else
        {
            WIDTH = 220
        }
    }

	help_w = WIDTH;
    help_h = screen.availHeight;
    help_l = screen.availWidth - WIDTH;

    w_dressing ="toolbar=0,status=0,menubar=0,width="+help_w+", left="+help_l+", height="+help_h+", top="+help_t+",resizable=no";
}

else

{
    w_dressing ="toolbar=0,status=0,menubar=0,width="+help_w+",height="+help_h+"resizable=no";
}


myURL = "/s/storehelp?page=index&helpIndex=" +cfcode;


//check for bScreen (4+ browser) since IE3 and Nav3 puke on close

//open the help window with URL and dressing and named _help
h_win=window.open(myURL,"_help", w_dressing);

if (bScreen == true)
{

    if (agent_isMac==true)
    {
        mac_heightoffset = 1.7
        if (agent_isAOL==true)
        {
            aoltoolbar = 70
        }
        else
        {
            aoltoolbar=0
        }
        startbarH = (screen.height-screen.availHeight)
        startbarW = (screen.width-screen.availWidth)
    }
    else
    {
        mac_heightoffset = 0
        if (agent_isAOL==true)
        {
            aoltoolbar=105
        }
        else
        {
            aoltoolbar=0
        }
        startbarH = 0
        startbarW = 0
 	}
    startbarH=startbarH
    startbarW=startbarW
    if(agent_isNS==true)
    {

    	top.window.resizeTo(screen.availWidth - WIDTH - (window.outerWidth - window.innerWidth), screen.availHeight - (window.outerHeight-window.innerHeight))
    }
    else
    {

		top.window.resizeTo(screen.availWidth - WIDTH - startbarW*4, screen.availHeight - startbarH-aoltoolbar)
    }

    	top.window.moveTo(0,(startbarH * mac_heightoffset)+aoltoolbar)
}
}


