//======================================================================
// Global variables
//======================================================================
var lastaction;
var wid = "104,64,57,87,87,80".split(",")//table cell widths
// colheads: the column headings to display.  Note that Companies gets replaced with the doc type
var colheads = "Companies,Categories,Markets,Applications,Products,Solutions".split(",")
// sorttitles: the properties for each column to sort on
var sorttitles = "companies,productcategory,markets,applications,products,solutions".split(",")
var section // keeps track of the section you are in (for sorting)
var n = 0;  // counter used with the dataset constructor
var rowClass = "odd"
var NS6 = false; // for Netscape 6 compatibility
var NS4 = false;
if (!document.all && !document.layers && document.getElementsByTagName("*")) {
  document.all = document.getElementsByTagName("*")
  NS6 = true
}
if (document.layers) { NS4 = true }

var docObj;
var flash4 = false; 
	   
//======================================================================
// getQstring: returns the value of a querystring argument
//======================================================================
function getQstring(v)
{
	var r;
	var s = location.search.split("?") 
	if (s.length <= 1) { return ""; }
	
	var q = s[1].split("&")
	var re = /\(TM\)/gi
	var rePlus = /\+/gi
	for (var i=0;i<q.length;i++)
	{
	    r = q[i].split("=");
		if (unescape(r[0]) == v) { 
			if (document.layers) {
				return unescape(r[1].replace(rePlus,"%20")); 
			} else {
				return unescape(r[1]); 
			}
		}
	}
    return "";
}

//======================================================================
// init: build the category drop down lists for case studies and 
// white papers, also initialize the column sort order flags
//======================================================================
function init(whichPage)
{
	docObj = window
	if (whichPage == "popup" && NS4) { docObj = document.formElements; }

   docObj.document.fHB.ProductCategory.options.length = 2;// for netscape 4
   // build the product category and market segmentsdrop downs
   dropdown(docObj.document.fHB.ProductCategory,ProductCategory,"ProductCategory")
   dropdown(docObj.document.fHB.MarketSegment,MarketSegment,"MarketSegment")
   
   // reload the search value if the page is being loaded from the form
   if (getQstring("s") != "") {document.sf.s.value = getQstring("s")}
	// because each type is its own section, we have to keep track
	// of the sections sortorder
	
	sortorder = new Array();
   for (t in Type)
   {
	   sortorder[t] = new Object();
	   for (c in sorttitles) // set flag for each column
	   {  eval("sortorder["+t+"]."+sorttitles[c]+" = 1");  }
	   sortorder[t].count = 0;  // special case, because it is not a column
	   sortorder[t].lastsorted = "count"
   }
   
}
//======================================================================
// dropdown: list the checkboxes corresponding to the document types
// obj is the select object, ar is array with the value content and qs is
// the querystring value corresponding to the last selected item
//======================================================================
function dropdown(obj,ar,qs)
{

   obj.options.length=2;   
   re = /&#...;/g;
   for (var i=0;i<ar.length;i++)
   {
   	var tempAr = ar[i].replace(re,"®");;
	 ar[i]=ar[i].replace(re,"&#174;");// remove any special &#codes
	 obj.options[obj.options.length] = new Option(tempAr,ar[i]);
	 
	 if (getQstring(qs) != "" && getQstring(qs) == ar[i]) 
	 {
	   obj.selectedIndex = i+2; // reset the selected value if the page has been reloaded
	 } 
   }
   
   // handle the special case of "any" being selected (any is at index location 1)
   if (getQstring(qs) == "*") {obj.selectedIndex = 1;} 
}

//======================================================================
// doIntro: intro descriptive paragraph varies depending on if their are 
// more than just case studies
//======================================================================
function doIntro()
{	var strXtra = "";
	if (Type.length > 1) {
		strXtra = " and checkboxes";
	}
	var strIntro = "<ul><li>Use the <b>pull-down menus"+strXtra+"</b> below to&nbsp;find articles that most closely match your areas of&nbsp;interest.</li><li><b>Search</b> on a <b>key word or phrase</b>.</li><li>Or click the <b>&quot;list all&quot;</b> links to display complete sorted&nbsp;results.</li></ul>";
	 if (NS6) strIntro = strIntro + "<img src='/sites/developer/pix/spacer.gif' width='1' height='2' border='0' alt=''><br>";
	return strIntro;
}
//======================================================================
// doCheckBoxes: list the checkboxes corresponding to the document types
//======================================================================
function doCheckBoxes()
{
	if (Type.length == 1) // then there are no checkboxes
	{
	   var strCheckboxes = "<input type='hidden' name='cb' value='0'>";
	}
	else
	{
	   strCheckboxes = "<p class='margin'>";
	   for (i=0; i<Type.length; i++){
	   		var checkedStatus = testcb(i);
				// if coming from Flash 4 piece
			if (escape(getQstring("cb")) == escape(Type[i])) {
				checkedStatus = " checked";
			}
			
			 strCheckboxes += "<input type='checkbox' name='cb' value='"+i+"' "+checkedStatus+">&nbsp;"+Type[i]+"&nbsp;&nbsp;&nbsp;";
	   }
	  if (NS4) strCheckboxes += "<br><img src='/sites/developer/pix/spacer.gif' width='1' height='9' border='0' alt=''>";
	  strCheckboxes += "</p>";	  
	}
	return strCheckboxes;
}
//======================================================================
// testcb: check to see if the check box should be selected
//======================================================================
function testcb(v)
{
	if (window.location.search.indexOf("cb="+v) != -1) { return " checked" } else { return ""; }
}
//======================================================================
// idoc: constructor for data table
//======================================================================
function idoc(a,b,c,d,e,f,g,h,i,j,k){
   this.count = n*1; // note that this is used to sort by date since the 
   n = n + 1;		 // the array being read in is already sorted by date
   this.doctype=trim(a);
   this.productcategory=trim(b);
   this.markets=trim(c);
   this.dateposted=trim(d);
   this.title=trim(e);
   this.url=trim(f);
   this.applications=trim(g);
   this.products =trim(h);
   this.keywords=trim(i);
   this.solutions=trim(j);
   this.companies=trim(k);
   
}
//======================================================================
// dodisplay: search the category select object for selected values
// for each one, find the data records that match and display them with
// the appropriate headers
//======================================================================
function dodisplay(a,m)
{

   lastaction="sections"; // keep track for sorting
   var j = showdocs(a,m); // get the documents
   if (j != "alert") { // if no errors then ...
		 	if (j == "") { j = "No documents returned; try different categories." };
	   		if (document.all) {
			
				document.all.ds.innerHTML = j;
				
			}
	   		if (document.layers){document.write(j); }
   }
   document.sf.s.value = "";
   repositionPage();
   return false;
}
//======================================================================
//  showdocs: build the table showing the matching documents
//  We need to build a list of critera to test against,
//  first the checkboxes against the d.doctype
//  then the ProductCategory against the d.appliation
//  and finally the markets against d.markets
//======================================================================
function showdocs(a,m)
{
	var j = "";
	var checked = false;	    
	// make sure an application and market segment are selected.
	if (a == -1 || m == -1) {
	
	 		alert("Please select from both drop down lists.");
			return "alert";
	}	   
    // do a section for each Type
	if (Type.length == 1)   // if only one type then there are no checkboxes
	{ 
		if (document.all) { sortit(sortorder[0].lastsorted,0);}
		j = doSection(0,a,m); 
	}
	else
	{   // for each cb checked search the data table
	
		for ( var i=0;i<docObj.document.fHB.cb.length;i++)
		{
			   if ( docObj.document.fHB.cb[i].checked) {	
			   		if (document.all) {sortit(sortorder[docObj.document.fHB.cb[i].value].lastsorted, docObj.document.fHB.cb[i].value);}
			        j = j + doSection(docObj.document.fHB.cb[i].value,a,m); 
					checked=true;
			   }
		}	
	    if (!checked && trim(getQstring("order")) == "") { 
	  	   	alert("Please check one of the check boxes.");
	  		return "alert";
	  	}
	}
	return j;
}	

//======================================================================
// doSection:  displays a section of matching docs (ie. white papers)
//======================================================================
function doSection(t,a, m)
{
	var j = "<table width='500' border='0' cellspacing='0' cellpadding='0'>\n";
	var r = getdocs(t,a,m);
	if (r != "") { j = j + doheader("0",t) + r; }
	else { j = j + doheader("0",t) + "<tr><td colspan='11'><p><img src='/sites/developer/pix/spacer.gif' width='5' height='5' border='0' alt=''><br>No " + Type[t].toLowerCase() + " found.</p></td></tr>" }

	j = j + "</table><br>\n";
	
	return j;
}
//======================================================================
// getdocs: loop through all the documents and return the ones that match 
// the requested section
//======================================================================
function getdocs(t,a,m)
{	
	rowClass="odd";
	var j = "";
	a = unescape(a)
	m = unescape(m)
	var sol = getQstring("sol")
	for (var i=0;i<d.length;i++)
	{  
		if (sol == "" || regTest(escape(d[i].solutions),escape(getQstring("sol")))) {
				
		if (d[i].doctype == Type[t]){//and 
		if (a == "*" || regTest(d[i].productcategory,a)  ){//and 
		if (m == "*" || regTest(d[i].markets,m) ){
			j = j + buildrow(i,"0"); 	
		}}}}
	}
	return j;
}
//======================================================================
// regTest: use a regular expression to test for a string in a multi-field datastring
// (expects the fields to be comma delimited)
//======================================================================
function regTest(a,b)
{	
	var re = /&#174;|&#153;|\(TM\)/gi
	a = a.replace(re,"")
	b = b.replace(re,"")
   eval('re = new RegExp("[^,]*\\s*?'+b+'\\s*?[,$]*","i")');
   return re.test(a);
}


//======================================================================
//  buildrow: Build a row of data.  If f is 0 then skip the column showing the section
//  if f is 1 then show the section and type columns
//======================================================================
function buildrow(i,f)
{
   if (rowClass == "odd") { rowClass="even"; } else { rowClass="odd"; }
   var j = "\n<tr valign='top' class='"+rowClass+"'>\n" ;

   if (NS4) cellSpacer = "<br>";
   else cellSpacer = "";
  
  	strCompany = (d[i].companies != "" && d[i].companies != "None") ? d[i].companies : "No Specific Company";
    strDateposted = (d[i].dateposted != "") ? " (" + d[i].dateposted + ")" : "";
	
	j = j + "<td width='" + wid[0]+ "' class='dataCell'>"+ cellSpacer + strCompany + strDateposted + ": "+"<a href='"+d[i].url+"' target='_blank'>"  + d[i].title + cellSpacer + "</a></td>\n" ;
	
	j = j + "<td bgcolor='#FFFFFF' width='1'></td>\n" ;
	j = j + "<td width='" + wid[1]+ "' class='dataCell'>"+ cellSpacer +getData(d[i].productcategory)+"</td>\n" ;
	j = j + "<td bgcolor='#FFFFFF' width='1'></td>\n" ;
	j = j + "<td width='" + wid[2]+ "' class='dataCell'>"+ cellSpacer + fixSlash(getData(d[i].markets),'<br>')+"</td>\n" ;
	j = j + "<td bgcolor='#FFFFFF' width='1'></td>\n" ;
	j = j + "<td width='" + wid[3]+ "' class='dataCell'>"+ cellSpacer +addBullet(fixSlash(getData(d[i].applications),' '))+"</td>\n" ;
	j = j + "<td bgcolor='#FFFFFF' width='1'></td>\n" ;
	j = j + "<td width='" + wid[4]+ "' class='dataCell'>"+ cellSpacer +addBullet(getData(d[i].products))+"</td>\n" ;
	j = j + "<td bgcolor='#FFFFFF' width='1'></td>\n" ;
	j = j + "<td width='" + wid[5]+ "' class='dataCell'>"+ cellSpacer + findUrl(getData(d[i].solutions))+"</td>\n"  ;
	j = j + "</tr>\n" ;
	
	return j;
}  
//======================================================================
// getData: makes sure that commas have spaces following them so cells
// can break long lines, and also returns a nonbreaking space for netscape
// if the cell is empty
//======================================================================
function getData(a)
{
   var re = new RegExp(",([A-Za-z0-9])","g")
   a = a.replace(re,", $1");
   var re = /174; 4/gi
   a = a.replace(re,"174;&nbsp;4");
   if (a == "") { return "&nbsp;"; } else {return a; }
}
//======================================================================
// fixSlash: put spaces around slash so lines break if needed
//======================================================================
function fixSlash(a,character)
{
   var re = new RegExp("\\/","g")
   a = a.replace(re,"\/"+character);
   if (a == "") { return "&nbsp;"; } else {return a; }
}
//======================================================================
// addBullet: adds bullets in front of each application and technology
//======================================================================
function addBullet(a)
{
	
	if (a == "&nbsp;") return a;
	var tableBegin = "<table border='0' cellpadding='0' cellspacing='0'>";
	var tableEnd = "</table>";
	var spacer = "";
	if (NS6) spacer = "<img src='/sites/developer/pix/spacer.gif' width='3' height='3' alt=''><br>"
var strBulletBegin = "<tr valign='top'><td class='small'><table border='0' cellpadding='0' cellspacing='0' width='6'><tr><td colspan='2' width='6' height='4'></td></tr><tr><td bgcolor='#a6a6a6' width='3' height='3'>"+spacer+"</td><td width='3' height='3'>"+spacer+"</td></tr></table></td><td class='small' width='"+(wid[3]-6)+"'>";
	var strBulletEnd = "<br></td></tr>";
	var strContent = "";
	var strTemp = a.split("|");
	for (i=0; i<strTemp.length; i++) {
		strContent = strContent + strBulletBegin + trim(strTemp[i]) + strBulletEnd;
	}
  
   return tableBegin + strContent + tableEnd;
}
//======================================================================
// findUrl: adds hyperlinks to solutions by referencing array in data.js
//======================================================================
function findUrl(a)
{
	if (a == "&nbsp;") return a;
	var strUrls = "";
	var navArrow = (!NS4) ? "class='navArrow' " : "" 
	var strTemp = a.split(",");
	for (i=0; i<strTemp.length; i++) {
		if (typeof Solutions[trim(strTemp[i])] == "undefined") {
			strUrls = trim(strTemp[i]);
		} else {
		strUrls = strUrls + "<a href='"+Solutions[trim(strTemp[i])]+"' target='_blank' class='solutionUrl'><img src='/design/network/solutions/pix/navarrow_blue_sm.gif' " + navArrow + "width='10' height='11' alt='Learn More' border='0'>&nbsp;" + trim(strTemp[i]) +"</a><br>";
		}
	}
  
   return strUrls;
}

//======================================================================
// doheader: displays the table headers with sorting 
// f is a flag indicating whether or not this is a search listing
// t is the section being displayed
//======================================================================
function doheader(f,t)
{	
   var j = "\n<!-- Start of header tabs -->\n"
   		if (getQstring("cb").length > 1 || getQstring("sol").length > 1) {
			// coming from Flash 4 Case Studies button or Flash 6 Related Solutions
			 j = j + "<tr><td colspan='11' height='8' class='small'>";
			   if (document.all) { j = j + "Click on column headings to sort or <a href='#' class='novisit' onclick='return dosort(\"count\","+t+")'>order by date</a>.<br><br>" }
		   	j = j + "</td></tr>\n";
		} else {
	   	   j = j + "<tr><td colspan='11' class='small'><img src='/sites/developer/pix/spacer.gif' width='1' height='10' alt=''><br><span class='shead'>"+ Type[t] +" Results</span>&nbsp;<img src='/design/network/solutions/pix/arrow_down.gif' width='11' height='7' alt='' border='0'>";
	       if (document.all) { j = j + "&nbsp;Click on column headings to sort or <a href='#' class='novisit' onclick='return dosort(\"count\","+t+")'>order by date</a>." }
	       j = j + doinline(f,t);
		   j = j + "<br><br></td></tr>\n";
	   }
	  	   
   	   	j = j + "<tr valign='top'><td colspan='11'>\n";
	   	j = j + "<img src='/design/network/solutions/pix/tabs_"+sortorder[t].lastsorted+".gif' width='568' height='21' alt='' border='0'"
		if (!document.layers) j = j + " usemap='#tabs"+t+"'"
		j = j + ">";
		j = j + "</td></tr>\n";
		
		if (document.layers) {
		
		j = j + "<tr valign='top'><td><img src='/sites/developer/pix/spacer.gif' width='"+(wid[0]*1+12)+"' height='1' border='0' alt=''></td><td><img src='/sites/developer/pix/spacer.gif' width='1' height='1' border='0' alt=''></td><td><img src='/sites/developer/pix/spacer.gif' width='"+(wid[1]*1+12)+"' height='1' border='0' alt=''></td><td><img src='/sites/developer/pix/spacer.gif' width='1' height='1' border='0' alt=''></td><td><img src='/sites/developer/pix/spacer.gif' width='"+(wid[2]*1+12)+"' height='1' border='0' alt=''></td><td><img src='/sites/developer/pix/spacer.gif' width='1' height='1' border='0' alt=''></td><td><img src='/sites/developer/pix/spacer.gif' width='"+(wid[3]*1+12)+"' height='1' border='0' alt=''></td><td><img src='/sites/developer/pix/spacer.gif' width='1' height='1' border='0' alt=''></td><td><img src='/sites/developer/pix/spacer.gif' width='"+(wid[4]*1+12)+"' height='1' border='0' alt=''></td><td><img src='/sites/developer/pix/spacer.gif' width='1' height='1' border='0' alt=''></td><td><img src='/sites/developer/pix/spacer.gif' width='"+(wid[5]*1+12)+"' height='1' border='0' alt=''></td></tr>\n";
	}
	
		j = j + "<!-- end of header tabs -->\n"		
		
		j = j + "<map name='tabs"+t+"'><area alt='' coords='1,1,115,21' title='sort by documents'"
if (!document.layers) j = j + " href='#' onclick='return dosort(\""+sorttitles[0]+"\","+t+")'"
j = j + "><area alt='' coords='119,1,194,21' title='sort by categories'"
if (!document.layers) j = j + " href='#' onclick='return dosort(\""+sorttitles[1]+"\","+t+")'"
j = j + "><area alt='' coords='198,1,267,21' title='sort by markets'"
if (!document.layers) j = j + " href='#' onclick='return dosort(\""+sorttitles[2]+"\","+t+")'"
j = j + "><area alt='' coords='270,1,369,21' title='sort by applications'"
if (!document.layers) j = j + " href='#' onclick='return dosort(\""+sorttitles[3]+"\","+t+")'"
j = j + "><area alt='' coords='372,1,470,21' title='sort by products'"
if (!document.layers) j = j + " href='#' onclick='return dosort(\""+sorttitles[4]+"\","+t+")'"
j = j + "><area alt='' coords='474,1,565,21' title='sort by solutions'"
if (!document.layers) j = j + " href='#' onclick='return dosort(\""+sorttitles[5]+"\","+t+")'"
j = j + "></map>";

   return j;
}
//======================================================================
// doinline: print inline links to each section
//======================================================================
function doinline(f,t)
{
   var l = "<a name='Section"+t+"'></a>" // links 
   var c = 0// count of number of check boxes checked

   if (Type.length > 1)
   {
		for (i=0;i<docObj.document.fHB.cb.length;i++)
		{	
				if (f==1 && (parseInt(t) != i) || (NS4 && getQstring("s") != "" && (parseInt(t) != i))) {	
					// coming from search button
			   		l = l + "[ <a href='#Section"+i+"'>"+Type[i]+"</a> ]&nbsp;";
					c = c + 1;
			   } else if ( docObj.document.fHB.cb[i].checked && (parseInt(t) != i)) {	
			   		// coming from show button
			   		l = l + "[ <a href='#Section"+i+"'>"+Type[i]+"</a> ]&nbsp;";
					c = c + 1;
			   } 
		}
   }
  
   if (c > 0) { return "&nbsp;&nbsp;&nbsp;"+l;}
   return l;
}

//======================================================================
// sortcolumn: print different header if this column in the one sorted
// a is the  property to sort on
// b is the index in the sortorder array
// c is the text to display as the column head
// k is the offset on the width for the cells
//======================================================================
function sortcolumn(a,b,c,k)
{
  if (a == sortorder[b].lastsorted)
  {
    return "<td align='center' class='head' width='"+wid[k+a]+"'><a class='head' href='#' onclick='return dosort("+'"'+a+'",'+b+")'>["+c+"]</a></td>\n" ; 
  }
  else
  {
    return "<td align='center' class='head' width='"+wid[k+a]+"'><a class='head' href='#' onclick='return dosort("+'"'+a+'",'+b+")'>"+c+"</a></td>\n" ;
  }
}
//======================================================================
// doNSsearch: searches
//======================================================================
function doNSsearch(form)
{	
	xStr = "left=" + eval(screen.width - 655) + ",top=0,width=622,height=540,scrollbars=yes,resizable=no"
	
	docWin = window.open("","docWin",xStr)	
	//} 
	form.action = "popup.htm";
	form.target = "docWin";
	docWin.focus();
	//docWin.reload();
	return;
}
//======================================================================
// stripChar: strips out special characters from data.js to compare
//======================================================================
function stripChar(str)
{
	//var re = /®|™|&#174;|&#153;|\(TM\)|\*/gi
	var re = /&#174;|&#153;|\*|\(TM\)/gi
	str = str.replace(re,"")
	var re = /&nbsp;/gi
	str = str.replace(re," ")
	return escape(str);
}
//======================================================================
// dosearch: searches the table for v
//======================================================================
function dosearch(v)
{	
	if (Type.length > 1) {
		for (var i=0; i<Type.length; i++) {
			docObj.document.fHB.cb[i].checked = false;
		}
	}
	rowClass="odd";
	var t = "";
	if (trim(v) == "") { v = "*"; }
	var specialChars = '^\\+,®,\\*,©,™,"';
	var specials = specialChars.split(",");
	var repl = ",,.*,&copy;,,&quot;".split(",");
	for (var i=0;i<specials.length;i++)
	{
	   var re = new RegExp(specials[i],"g");
	   v = v.replace(re,repl[i]);
	}

	lastaction="search";
	var j = ""
	
	re = new RegExp(escape(v),"i");
		
	for (var k in Type)
	{
		if (document.all) {sortit(sortorder[k].lastsorted,k);}
		var j = j + "<table width='500' border='0' cellspacing='0' cellpadding='0' bgcolor='#FFFFFF'>\n";
		for (var i=0;i<d.length;i++)
		{
			// if querystring includes sol= then filter for those records first
			if (getQstring("sol") == "" || regTest(d[i].solutions,getQstring("sol"))) {
			// search on the type, applications, title, keywords, markets, technolgies and companies
			if ((trim(d[i].doctype) == trim(Type[k])) && (re.test(stripChar(d[i].applications)) || re.test(stripChar(d[i].title)) || re.test(stripChar(d[i].keywords)) || re.test(stripChar(d[i].markets)) || re.test(stripChar(d[i].products)) || re.test(stripChar(d[i].productcategory)) || re.test(stripChar(d[i].solutions)) ||  re.test(stripChar(d[i].companies))))
			{
			t = t + buildrow(i,"1"); }
			}
		}
		if (t == "") { j = j+doheader("1", k)+"<tr><td colspan='11'><p><img src='/sites/developer/pix/spacer.gif' width='5' height='5' border='0' alt=''><br>Search returned no " + Type[k].toLowerCase() + ".</p></td></tr>";}
		else { j = j + doheader("1",k); j = j + t; }
		
		j = j + "</table><br>\n";
		t = "";
	}
	if (document.getElementById) 
	{ 
		document.getElementById('ds').innerHTML = j;
	}
	else { document.write(j); }
	// reset the dropdowns to none on a search
	if (document.all) {
	docObj.document.fHB.ProductCategory.options.selectedIndex = 1;
	docObj.document.fHB.MarketSegment.options.selectedIndex = 1;
	}
	repositionPage();
	
	return false;
}
//======================================================================
// repositionPage: to make sure IE users can see that results have changed
// below the fold
//======================================================================

function repositionPage() {
	if (document.URL.indexOf("popup.htm") > -1) return;
	if (document.all && document.body.scrollTop <= 167 && (document.body.clientHeight - document.body.scrollTop) < 555) {
		document.body.scrollTop = 167;
	}
}
	
//======================================================================
// dosort: set the sorted flag and then redisplay the output
// v is the column being sorted, t is the index into the type table of the
// section
//======================================================================
var newSort = 0;	// to indicate whether different tab was clicked or same

function dosort(v,t)
{
	if (sortorder[t].lastsorted != v) {
		// sorting should always be ascending for new column sorts
		newSort = 1;
	} else {
		newSort = 0;
	}
	sortorder[t].lastsorted = v;
	section = t;

	if (lastaction == "search") { 	dosearch(document.sf.s.value); 	}
	else // reset the dropdown list
	{  
dodisplay(docObj.document.fHB.ProductCategory.options[docObj.document.fHB.ProductCategory.selectedIndex].value,docObj.document.fHB.MarketSegment.options[docObj.document.fHB.MarketSegment.selectedIndex].value) 	
    }
	
	return false;
}

//======================================================================
// sortit: do the actual sorting and set the order flag.
// v is the column being sorted, t is the index into the type table of the
// section
//======================================================================
function sortit(v,t)
{	
	eval("var s = sortorder["+t+"]."+v) 
	BubbleSort(d,"count",1);  // sort first in date order
	
	// ok, if this section is the one that was clicked then toggle the order flag and sort
	
	if (t == section) {
		if (s == 1) 
		{ 	
			BubbleSort(d,v,0); 
			eval("sortorder["+t+"]."+v+" = 0"); 
		} 
		else 
		{  
			BubbleSort(d,v,1); 
			eval("sortorder["+t+"]."+v+" = 1"); 
		} 
	}
	else // just sort as it was
	{
		
		BubbleSort(d,v,s*1)
	}
}
//======================================================================
// bubblesort: The bubble sort has three arguments, 
//		the array of objects to sort, 
//		the property to sort on
//		and the order to sort: 1 to compare with a >, else with a <
//====================================================================== 
function BubbleSort(objArray,prop,order) 
{	
	if (newSort) order=0;
   for (var i=0; i<objArray.length-1; i++)
        for (var j=i+1; j<objArray.length; j++)
		    if (order == 1)
			{
				if (typeof objArray[i][prop]  == "number") 
				{
					if (objArray[j][prop] > objArray[i][prop]) 
					{	 	doswitch(objArray,i,j) 		}
				}
				else 
				{	
					if (objArray[j][prop].toUpperCase() > objArray[i][prop].toUpperCase()) 
					{	 	doswitch(objArray,i,j) 		}
				}
			}
			else
			{
				if (typeof objArray[i][prop]  == "number") 
				{
					if (objArray[j][prop] < objArray[i][prop]) 
					{	 	doswitch(objArray,i,j) 		}
				}
				else 
				{
					if (objArray[j][prop].toUpperCase() < objArray[i][prop].toUpperCase()) 
					{	 	doswitch(objArray,i,j) 		}
				}
			}
}
	
//======================================================================
// doswitch: used by bubblesort to switch two items
//======================================================================
function doswitch(objArray,i,j)	
{
		var dummy = objArray[i];
	  	objArray[i] = objArray[j];
	  	objArray[j] = dummy;
}
//======================================================================
// vbscript like text functions 
//======================================================================
function trim(str) { 
	str = str + "";
	return rtrim(ltrim(str))
}
function ltrim(str) { 
	str = str + "";
	while (str.substring(0,1)==" ") str = str.substring(1);
	return str;
}
function rtrim(str){ 
	str = str + "";
	while (str.substring(str.length-1)==" ") str = str.substring(0,str.length-1);
	return str;
}
//======================================================================
// checkit: make sure the select boxes and check boxes are set before submitting the form
//======================================================================
var docWin;
function checkit(form)
{
	if (Type.length > 1)
	{
	  	var ch = false
	 	for (i=0;i<docObj.document.fHB.cb.length;i++)
		{
	   		if ( docObj.document.fHB.cb[i].checked) {ch=true;	}
		}	
		if (!ch) { alert("Please check one of the check boxes."); return false; }
	}
	
	if (docObj.document.fHB.ProductCategory.selectedIndex == 0 || docObj.document.fHB.MarketSegment.selectedIndex == 0 )
	{
	  alert("Please select from both drop down lists."); return false;
	}
	if (document.all) { return dodisplay(docObj.document.fHB.ProductCategory.options[docObj.document.fHB.ProductCategory.selectedIndex].value,docObj.document.fHB.MarketSegment.options[docObj.document.fHB.MarketSegment.selectedIndex].value);
	} else {

		xStr = "left=" + eval(screen.width - 655) + ",top=0,width=622,height=540,scrollbars=yes,resizable=no"
		
		docWin = window.open("","docWin",xStr)	
		
		form.action = "popup.htm";
		form.target = "docWin";
		
		docWin.focus();
		
		return;
	}
}

//======================================================================
// listAll
//======================================================================
function listAll(sortBy) {
	if (document.all) {
		docObj.document.sf.s.value = "";

		dosearch("");
		for (var i=0; i<Type.length; i++) {
			dosort(sortBy,i);
		}
	}
}

//======================================================================
// checkReload
//======================================================================
function checkReload() {
	if (docObj.name=='docWin' && document.referrer != '' && document.layers) {
		location.reload();
	}
}

//======================================================================
// showProps
//======================================================================
function showProps(obj,objName) {
   var result = ""
   var count = 0
   for (var i in obj) {
      result += objName + "." + i + " = " + obj[i] + "\n"
      count++
      if (count == 25) {
         alert(result)
         result = ""
         count = 0
      }
   }
   if (count != 0) alert(result)
}
