

function BuildaList(rayRay, attainer, sector)
{
	var HoldinCoffield = new Array();
	var coiffer = 0;
	for ( goGo = 0; goGo<rayRay.length; goGo++)
		{
			if ( rayRay[goGo][2] == sector) { 
				var spotted = 0;
				var tester = rayRay[goGo][16].length;
				for ( skipper = 0; skipper<HoldinCoffield.length; skipper++)
					{
				 	if (HoldinCoffield[skipper] == rayRay[goGo][attainer] || rayRay[goGo][attainer] == "" || rayRay[goGo][attainer] == null || rayRay[goGo][attainer] == " " || rayRay[goGo][attainer].length < 1) { spotted++;}
					}
				if (spotted <1) {HoldinCoffield[HoldinCoffield.length] =rayRay[goGo][attainer];} 
			}
		}
		if(attainer ==9 || attainer == 10)  {return Selectionator(HoldinCoffield.reverse());}
		else {return Selectionator(HoldinCoffield.sort());}

}

function Selectionator ( rayRay )
{
var CrustyCriteria ="<option value='All...'>All...</option>";
for (biglin = 0; biglin < rayRay.length; biglin++)
	{
	if ( rayRay[biglin] != "" && rayRay[biglin] != null && rayRay[biglin] !=" " && rayRay[biglin].length >0 )
		{CrustyCriteria = CrustyCriteria + "<option value='" + rayRay[biglin] + "' >"+rayRay[biglin]+"</option>";}
	} 
	return CrustyCriteria;
}

function ParsePrimaryString() 
{   
    var _groahged = TotalByte;
	var _endLine = _groahged.indexOf("\r\n") + 1;
	if (_endLine <= 1) {_endLine = _groahged.indexOf("\n")+1 ;}
	var _tempHandler;
	var _RowArray = new Array();
	var _startNext = _groahged.indexOf("\t", 0);
	var _startIndex = 0;
	var _valueCounter = 0;
	var _bigStart = 0;
	var _counter = 0;
	var endders= "";
	while ( _endLine > 5) 
		{
		  	_tempHandler = _groahged.substring(_bigStart, _endLine);
		  	endders = _tempHandler;
		  	_RowArray[_counter] = new Array();
	  		while (_valueCounter < 24) 
			/* forceful termination 
			 * MAINTENANCE NOTE : must adjust
			 * count.
			 */
   			 {
 				   	var _endIndex = _tempHandler.indexOf("\t", _startIndex);
 				   	if (_endIndex >= 0 ) 
 				   	{
 				   		if (_valueCounter == 0 ) { _startIndex = 0; }
 				   	 _RowArray[_counter][_valueCounter] = _tempHandler.substring(_startIndex, _endIndex);	
    				}
    			else { 
    				  _RowArray[_counter][_valueCounter] = _tempHandler.substring(_startIndex);
    				   }
    				_startIndex = _endIndex + 1; 
    			  _valueCounter++;
   			 	}
   			 _valueCounter = 0;
   			 _startIndex = 0;
   			 _bigStart = _endLine +1;
   			 _endLine = _groahged.indexOf("\r\n", _bigStart);
			 if (_endLine <= 0) {_endLine = _groahged.indexOf("\n", _bigStart); } //unix hax
			if (_counter == 0 ) {_bigStart -=1; } // bizarre unix work around
   			 _counter++;
   	}
	coffeePot = _RowArray;
	return _RowArray;
   }
   
 function ParseIntString(_ourBiggin) 
{   
    var _groahged = _ourBiggin;
	var _endLine = _groahged.indexOf("\r\n") + 1;
	if (_endLine <= 1) {_endLine = _groahged.indexOf("\n")+1 ;}
	var _tempHandler;
	var _RowArray = new Array();
	var _startNext = _groahged.indexOf("\t", 0);
	var _startIndex = 0;
	var _valueCounter = 0;
	var _bigStart = 0;
	var _counter = 0;
	var endders= "";
	while ( _endLine > 5) 
		{
		  	_tempHandler = _groahged.substring(_bigStart, _endLine);
		  	endders = _tempHandler;
		  	_RowArray[_counter] = new Array();
	  		while (_valueCounter < 24) 
			/* forceful termination 
			 * MAINTENANCE NOTE : must adjust
			 * count.
			 */
   			 {
 				   	var _endIndex = _tempHandler.indexOf("\t", _startIndex);
 				   	if (_endIndex >= 0 ) 
 				   	{
 				   		if (_valueCounter == 0 ) { _startIndex = 0; }
 				   	 _RowArray[_counter][_valueCounter] = _tempHandler.substring(_startIndex, _endIndex);	
    				}
    			else { 
    				  _RowArray[_counter][_valueCounter] = _tempHandler.substring(_startIndex);
    				   }
    				_startIndex = _endIndex + 1; 
    			  _valueCounter++;
   			 	}
   			 _valueCounter = 0;
   			 _startIndex = 0;
   			 _bigStart = _endLine +1;
   			 _endLine = _groahged.indexOf("\r\n", _bigStart);
			 if (_endLine <= 0) {_endLine = _groahged.indexOf("\n", _bigStart); } //unix hax
			if (_counter == 0 ) {_bigStart -=1; } // bizarre unix work around
   			 _counter++;
   	}

	interNational = _RowArray;
	return interNational;
   }  
   
   

function CoffeeFilter()
{	

var gastation = dumpLord;
var CupOCoffee = coffeePot;
var WhatItDoes = new Array();
var states = document.Refinery.State.options.selectedIndex; 
WhatItDoes[0] = document.Refinery.State.options[states].text;
var retailers = document.Refinery.RetailerT.options.selectedIndex;
WhatItDoes[1] = document.Refinery.RetailerT.options[retailers].text;
var citys = document.Refinery.City.options.selectedIndex;
WhatItDoes[2] = document.Refinery.City.options[citys].text;
var zips = document.Refinery.Zip.options.selectedIndex;
WhatItDoes[3] = document.Refinery.Zip.options[zips].text;
var areaCodes= document.Refinery.ACODE.options.selectedIndex;
WhatItDoes[4] = document.Refinery.ACODE.options[areaCodes].text;
/*var ACVs= document.Refinery.ACV.options.selectedIndex;
WhatItDoes[5] = document.Refinery.ACV.options[ACVs].text;
var ACVs= document.Refinery.LA.options.selectedIndex;
WhatItDoes[6] = document.Refinery.LA.options[ACVs].text;
var ACVs= document.Refinery.OO.options.selectedIndex;
WhatItDoes[7] = document.Refinery.OO.options[ACVs].text;
var ACVs= document.Refinery.SD.options.selectedIndex;
WhatItDoes[8] = document.Refinery.SD.options[ACVs].text;
var ACVs= document.Refinery.HS.options.selectedIndex;
WhatItDoes[9] = document.Refinery.HS.options[ACVs].text;
var ACVs= document.Refinery.BK.options.selectedIndex;
WhatItDoes[10] = document.Refinery.BK.options[ACVs].text;
*/
var WhatItIs = new Array()
var nimble = 0;
for (what = 0; what < coffeePot.length; what++)
	{
		var spotter = 0;
		if ( CupOCoffee[what][2] == dumpLord) 
			{
				if (WhatItDoes[0] == "All") {}else if (CupOCoffee[what][3] == WhatItDoes[0] || CupOCoffee[what][3] == WhatItDoes[0] + " ") {} else {spotter++;}  //pay no attention to the man behind the curtains
				if (WhatItDoes[1] == "All") {}else if (CupOCoffee[what][6] == WhatItDoes[1] || CupOCoffee[what][6] == WhatItDoes[1]+ " ") {}else {spotter++;}
				if (WhatItDoes[2] == "All") {}else if (CupOCoffee[what][8] == WhatItDoes[2] || CupOCoffee[what][8] == WhatItDoes[2] + " ") {}else {spotter++;}
				if (WhatItDoes[3] == "All") {}else if (CupOCoffee[what][9] == WhatItDoes[3] || CupOCoffee[what][9] == WhatItDoes[3] + " ") {}else {spotter++;}
				if (WhatItDoes[4] == "All") {}else if (CupOCoffee[what][10] == WhatItDoes[4] || CupOCoffee[what][10] == WhatItDoes[4] + " ") {}else {spotter++;}
				/*if (WhatItDoes[5] == "All") {}else if (CupOCoffee[what][14] == WhatItDoes[5]) {}else {spotter++;}
				if (WhatItDoes[6] == "All") {}else if (CupOCoffee[what][15] == WhatItDoes[6]) {}else {spotter++;}
				if (WhatItDoes[7] == "All") {}else if (CupOCoffee[what][16] == WhatItDoes[7]) {}else {spotter++;}
				if (WhatItDoes[8] == "All") {}else if (CupOCoffee[what][17] == WhatItDoes[8]) {}else {spotter++;}
				if (WhatItDoes[9] == "All") {}else if (CupOCoffee[what][18] == WhatItDoes[9]) {}else {spotter++;}
				if (WhatItDoes[10] == "All") {}else if (CupOCoffee[what][19] == WhatItDoes[10]) {}else {spotter++;} */
			}
			else {spotter++;}
			if (spotter >0) {}
			else {WhatItIs[nimble] = CupOCoffee[what]; nimble++;}
	}	
ForceFeed(WhatItIs, dumpLord);
WhatItIs = null;

}


function internationalBuffet()

{
var bowlofcereal = "";
var topPart = "<table id='locatorResults'  class='locatorTable'><tr ><th colspan='15' align='center'  onClick='ShowOff();' class='main_body'>Click Here to return to the US Region map</th></tr><tr><th class='white_12'>Country</th><th class='white_12'>State</th><th class='white_12'>Store Name</th><th class='white_12'>Retailer Type</th><th class='white_12'>Address</th><th class='white_12'>City</th><th class='white_12'>ZIP</th><th class='white_12'>Area Code</th><th class='white_12'>Phone</th><th class='white_12'>ACV</th><th class='white_12'>LA</th><th class='white_12'>OO</th><th class='white_12'>SD</th><th class='white_12'>HS</th><th class='white_12'>CBK</th><th class='white_12'>website</th></tr><tr>"

for (countDracula = 0; countDracula <interNational.length; countDracula++ )
	{
	 var test2 = interNational[countDracula].length;
	 bowlofcereal = bowlofcereal + "<tr>"
	  var tdClass;
      if((countDracula % 2) == 0 ) {tdClass="locatorTableEven";}else{tdClass="locatorTableOdd";}
 	  for (captnCrunch=0; captnCrunch < interNational[countDracula].length; captnCrunch++ )
	 			{
					if (captnCrunch ==1 ||  captnCrunch ==3 || captnCrunch ==4 || captnCrunch ==6 || captnCrunch ==7 || captnCrunch ==8 || captnCrunch ==9 || captnCrunch ==10|| captnCrunch ==11 || captnCrunch ==14 || captnCrunch ==15 || captnCrunch ==16 || captnCrunch ==17 || captnCrunch ==18 || captnCrunch ==19 || captnCrunch ==20)
					{    var _ohOK = interNational[countDracula][captnCrunch];
						if (_ohOK.length <1) {_ohOK = "&nbsp;";}
						if ( interNational[countDracula][captnCrunch] == "" || interNational[countDracula][captnCrunch] == null ) { _ohOK = "&nbsp;";}
						if ( interNational[countDracula][captnCrunch] == "Y") { _ohOK = "<center style='font-size: 72px;'>&#149;</center>";}
						if ( captnCrunch == 20  && interNational[countDracula][captnCrunch] !="&nbsp;" ) {_ohOK = "<a class='bold' href='http://" + interNational[countDracula][captnCrunch] + "' target='_BLANK' class='bold' alt='Visit A Retailers Site'>"+ interNational[countDracula][captnCrunch] +" </a>";}
	     				bowlofcereal = bowlofcereal + "<td>" + _ohOK + "</td>";
					}	
				}
					bowlofcereal = bowlofcereal + "</tr>";

 }
bowlofcereal =  topPart + bowlofcereal  + "<tr><th colspan='15' align='center'   onclick='ShowOff();' class='bold'>Click Here to return to the US Region map</center></th></tr></table>";
document.getElementById("Map").style.display = "none";
document.getElementById("scrollcontent").style.display = "none";
document.getElementById("MapImg").style.display = "none";
for (q = 0; q<document.getElementsByTagName("area").length; q++)
{
document.getElementsByTagName("area")[q].style.diplay = "none";
}
document.getElementById("ResultSet").innerHTML = bowlofcereal;
var naples = document.getElementById("locatorResults");
var napleTR = naples.getElementsByTagName("tr");
for (quade = 0; quade < napleTR.length; quade++)
{
  var tdClass;
  var napleTD = napleTR[quade].getElementsByTagName("td");
  if((quade % 2) == 0 ) {tdClass="locatorTableEven";}else{tdClass="locatorTableOdd";}
  	for (wesly = 0; wesly < napleTD.length; wesly++)
   	{ napleTD[wesly].className = tdClass;}
}





}

function ForceFeed(_broDown, napkin)

{//</th><th valign='top' class='locatorHeader'>Store Name</th><th valign='top' class='locatorHeader'>Retailer Type</th><th valign='top' class='locatorHeader'>Address</th><th valign='top' class='locatorHeader'>City</th><th valign='top' class='locatorHeader'>Zip</th><th valign='top' class='locatorHeader'>Area Code</th><th valign='top' class='locatorHeader'>Phone #</th><th valign='top' class='locatorHeader'>ACV</th><th valign='top' class='locatorHeader'>LA</th><th valign='top' class='locatorHeader'>OO</th><th valign='top' class='locatorHeader'>SD</th><th valign='top' class='locatorHeader'>HS</th><th valign='top' class='locatorHeader'>BK</th><th valign='top' class='locatorHeader'>Store Website</th>
if ( isFirst == true) { document.getElementById("selectorR").style.display = "block"; }
var _spoon = new Array();
dumpLord = napkin;
var _WhereYouAre = new Array(0);
_spoon = _broDown;
var PickeyChoosey = "<form name='selectory'><table id='locatorResults'  class='locatorTable'><tr ><th colspan='15' align='center'  onClick='ShowOff();' class='main_body' >Click Here to return to the US Region map</th></tr><tr><th  class='locatorHeader'>State</th><th  class='locatorHeader'>Store Name</th><th  class='locatorHeader'>Retailer Type</th><th  class='locatorHeader'>Address</th><th  class='locatorHeader'>City</th>"+ "<th  class='locatorHeader'>Zip</th><th  class='locatorHeader'>Area Code</th><th  class='locatorHeader'>Phone #</th><th  class='locatorHeader'>ACV</th><th  class='locatorHeader'>LA</th><th  class='locatorHeader'>OO</th><th  class='locatorHeader'>SD</th><th class='locatorHeader'>HS</th><th  class='locatorHeader'>BK</th><th  class='locatorHeader'>Store Website</th></tr>";
var countDracula = 0;
var captnCrunch =0;
var bowlofcereal ="";
var _test = _spoon.length;
var WhereCounter = 0;
for (countDracula = 0; countDracula <_spoon.length; countDracula++ )
	{
	 var test2 = _spoon[countDracula].length;
	 if (_spoon[countDracula][2] == napkin)  
	 	{   bowlofcereal = bowlofcereal + "<tr>";
	
        _WhereYouAre[WhereCounter] =  _spoon[countDracula];
		WhereCounter++;
		var tdClass;
		    if((countDracula % 2) == 0 ) {tdClass="locatorTableEven";}else{tdClass="locatorTableOdd";}
			
	  		for (captnCrunch=0; captnCrunch < _spoon[countDracula].length; captnCrunch++ )
	 			{
					if (captnCrunch ==3 ||  captnCrunch ==4 || captnCrunch ==6 || captnCrunch ==7 || captnCrunch ==8 || captnCrunch ==9 || captnCrunch ==10 || captnCrunch ==11 || captnCrunch ==14 || captnCrunch ==15 || captnCrunch ==16 || captnCrunch ==17 || captnCrunch ==18 || captnCrunch ==19 || captnCrunch ==20)
					{    var _ohOK = _spoon[countDracula][captnCrunch];
						if (_ohOK.length <1) {_ohOK = "&nbsp;";}
						if ( _spoon[countDracula][captnCrunch] == "" || _spoon[countDracula][captnCrunch] == null ) { _ohOK = "&nbsp;";}
						if ( _spoon[countDracula][captnCrunch] == "Y") { _ohOK = "<center style='font-size: 72px;'>&#149;</center>";}
						if ( captnCrunch == 20  && _spoon[countDracula][captnCrunch] !="&nbsp;" ) {_ohOK = "<a class='bold'  href='http://" + _spoon[countDracula][captnCrunch] + "' target='_BLANK' alt='Visit A Retailers Site'>"+_spoon[countDracula][captnCrunch] +" </a>";}
	     				bowlofcereal = bowlofcereal + "<td class='main_body'>" + _ohOK + "</td>";
					}	
				}	
		bowlofcereal = bowlofcereal +"</tr>";
		}
	  else {}
	}
bowlofcereal =  PickeyChoosey + bowlofcereal  + "<tr><th colspan='15' align='center'   onclick='ShowOff();' class='main_body'>Click Here to return to the US Region map</center></th></tr></table></form>";
document.getElementById("Map").style.display = "none";
document.getElementById("scrollcontent").style.display = "none";
document.getElementById("MapImg").style.display = "none";
for (var q = 0; q<document.getElementsByTagName("area").length; q++)
{
document.getElementsByTagName("area")[q].style.diplay = "none";
}
document.getElementById("ResultSet").innerHTML = bowlofcereal;
var naples = document.getElementById("locatorResults");
var napleTR = naples.getElementsByTagName("tr");
for (var quade = 0; quade < napleTR.length; quade++)
{
  var tdClass;
  var napleTD = napleTR[quade].getElementsByTagName("td");
  if((quade % 2) == 0 ) {tdClass="locatorTableEven";}else{tdClass="locatorTableOdd";}
  	for (wesly = 0; wesly < napleTD.length; wesly++)
   	{ napleTD[wesly].className = tdClass; }
}

if ( isFirst == true ) {
document.getElementById("ControlSet").style.display = "block";
//document.getElementById("ControlSet").style.class = "main_body";
// pop u late the combos
BuildOptions(_WhereYouAre, 3, "State");
document.getElementById("Statem").innerHTML = "State : <select name=State id='Stater' onchange='CoffeeFilter();'>" +comboLove+"</select>" 
BuildOptions(_WhereYouAre, 6, "RetailerTm")
document.getElementById("RetailerTm").innerHTML = "| Retailer Type: <select name='RetailerT' onchange='CoffeeFilter();'>" +comboLove+"</select>" 
BuildOptions(_WhereYouAre, 8, "City")
document.getElementById("Citym").innerHTML = "| City : <select name=City onchange='CoffeeFilter();'>" +comboLove+"</select>" 
BuildOptions(_WhereYouAre, 9, "Zip")
document.getElementById("Zipm").innerHTML = "| Zip : <select name=Zip onchange='CoffeeFilter();'>" +comboLove+"</select>" 
BuildOptions(_WhereYouAre, 10, "ACODE")
document.getElementById("ACODEm").innerHTML = "| Area Code : <select name=ACODE onchange='CoffeeFilter();'>" +comboLove+"</select>" 
isFirst = false;
}
else {}


_spoon = null;


}














function ShowOff()
{
document.getElementById("Map").style.display = "block";
document.getElementById("MapImg").style.display = "block";
document.getElementById("scrollcontent").style.display = "block";

for (q = 0; q<document.getElementsByTagName("area").length; q++)
{
document.getElementsByTagName("area")[q].style.diplay = "block";
}
document.getElementById("ResultSet").innerHTML ="";
if (isFirst == false) 
{
document.getElementById("Statem").innerHTML = "";
document.getElementById("selectorR").style.display = "none";
document.getElementById("RetailerTm").innerHTML ="";
document.getElementById("Citym").innerHTML ="";
document.getElementById("Zipm").innerHTML = "";
document.getElementById("ACODEm").innerHTML = "";
isFirst = true;
}
}




function BuildOptions(_array, _index, _id)
{
// Takes the newly built smaller array and works out an options set from there
var _returnArray = new Array(1);
var counter_one = 0;
var counter_two = 0;
while (counter_one < _array.length)
{
	var isFound = 0;
	while (counter_two < _returnArray.length)
	{
	   var _thisResult = _array[counter_one][_index].replace("\n", "");
	 if (_returnArray[counter_two] == _thisResult || _thisResult =="" || _thisResult == undefined || _thisResult =="\n"  || _thisResult == null )
	 { isFound++;}
	 counter_two++;
	}
	if (isFound == 0) { _returnArray[counter_two] = _thisResult;} // assign it to the list
	counter_two =0;
	isFound = 0;
	counter_one++;
}


_returnArray = _returnArray.sort();

comboLove = "<option value=\"All\">All</option>";
for (i =0 ; i < _returnArray.length; i++)
	{
		comboLove = comboLove +  "<option value='"+ _returnArray[i]+ "'>" +  _returnArray[i] +"</option>";
	}
	comboLove =  comboLove.replace("<option value='undefined'>undefined</option>", "");
}



