/////////////////////////////////////////////////////////////////////////////////////////////////////////////
//  salesrep contact database
var salesrep = new Array();
salesrep.push( new Array("Chicago Lighting","Chicago#Illinois (Northern)","517 W. Golf Rd.","Arlington Heights","IL","60005","847-439-5030","847-671-9498  ","Larry Bisaillon, Principal","www.chicagolighting.com") );
salesrep.push( new Array("Techlite Corp.","Indiana","7718 Loma Court","Fishers","IN","46038","317-578-2626","317-578-2727","Dave McDowell, Principal","www.techlitecorp.com") );
salesrep.push( new Array("Visual Impact Lighting","Wisconsin#Michigan (Upper Peninsula)","1724 Industrial Dr.","Green Bay","WI","54302","920-437-2069","920-437-9140","Dave Zochert, Principal","www.visualimpactlighting.com") );
salesrep.push( new Array("Turilli Business Development","Arizona#Nevada (Las Vegas)","4148 N. Arcadia Dr.","Phoenix","AZ","85018","602-889-2328","602-889-2299 ","John Turilli, Principal","") );
salesrep.push( new Array("Lighting Solutions of Iowa","Iowa#Illinois(West)","121 S.E. Shurfine Drive Suite #7  ","Ankeny","IA","50021","","","","www.lsiowa.com") );
salesrep.push( new Array("Gateway Electrical Sales, Inc.","Missouri (East)#Illinois (South)","9120 Watson Rd.  Suite 200 ","St. Louis","MO","63126","314-842-4374","314-842-3850","Jim Will, Principal","www.gatewayelectrical.com") );
salesrep.push( new Array("Stellar Sales","California (South)","14300 Alondra Blvd.","La Mirada","CA","90638","714-690-6400","714-690-6410","Dan Dockry, Principal","www.stellarsalesinc.com") );
salesrep.push( new Array("Western  Florida Lighting, Inc.","Florida (North)#Florida (West)","2533 Permit Place","New Port Richie","FL","34655","727-733-7000","727-733-4008","Bill Donati, Principal","www.wfli.com") );
salesrep.push( new Array("Blankenship& Assoc.","Idaho#Washington#Wyoming#Oregon","5517 E. Trent","Spokane","WA","99212","509-535-6006","509-535-6514 ","David Blankenship, Principal","www.blankenship&associates.com") );
salesrep.push( new Array("Lone Star Lighting","Texas (South East)","12107 Colwick","San Antonio","TX","78216","210-344-4334  ","210-344-3484","Brian McBrearty, Principal","www.lonestarltg.com") );
salesrep.push( new Array("Lighting Partnership","Alabama","3421 5th Ave.","Birmingham","AL","35222","205-322-4774","205-322-4852","Bill Delong, Principal","www.lpal.com") );
salesrep.push( new Array("Texas Lighting Sales","Texas (North)#Texas (West)","831 W. Euless Blvd.","Euless","TX","76040","817-267-9300","817-267-2698","Jim Weathers, Principal","www.texaslighting.com") );
salesrep.push( new Array("eLumen8","Oregon#Washington (South)","2240 N. Interstate Ave. Suite 150","Portland","OR","97227","503-296-5885","503-432-7338","Jim Potts, Principal","www.elumen8.com ") );
salesrep.push( new Array("Jack Duffy & Assoc.","Ohio (North East)","95 Executive Pkwy. Suite 100","Hudson","OH","44236","234-380-1690","234-380-1699","Patrick Duffy, Principal","www.duffylighting.com") );
salesrep.push( new Array("Michigan Lighting Systems","Michigan","3055 Hilton Suite A","Ferndale","MI","48220","248-542-2200","248-542-7110","Rob Carr, Principal","www.michiganlightingsystems.com") );
salesrep.push( new Array("Ohio Lighting Systems","Ohio (North East)","3055 Hilton Suite A","Ferndale","MI","48220","248-542-2200","248-542-7110","Rob Carr, Principal","") );
salesrep.push( new Array("MLS-West","Michigan (West)","N. Ridge NW  ","Grand Rapids","MI","49544","616-785-1415","616-785-1282","Jeff Adams, Principal","www.michiganlightingsystems.com") );
salesrep.push( new Array("Close Associates, Inc.","Texas (South East)","3200 Texas Ave.","Houston","TX","77003","713-23600316","713-233-9857","Jerry Delso, Principal","") );
salesrep.push( new Array("Legacy Lighting","Texas (Austin)","612 B Winfo","Austin","TX ","78703","512-481-9971","512-481-9988","Shawna Sieck, Principal","") );
salesrep.push( new Array("Electrical Midwest, Inc.","Kansas#Missouri (Western)","9205 Bond St.","Overland Park","KS ","66214","913-599-1000","913-599-0044","Scott Marlo, Principal","") );
salesrep.push( new Array("CK Lighting","Georgia (South East)","3911 Old Louisville Rd. Suite 110","Garden City","GA","31408","912-629-0500","912-629-0507","Kurt Kuster, Principal","") );


/////////////////////////////////////////////////////////////////////////////////////////////////////////////
// array of menu options / sort alpha
var repmenu = new Array();

for(i = 0; i < salesrep.length; i++) {
    var locations = salesrep[i][1].split("#");
    
    for(j = 0; j < locations.length; j++) {
    	if(locations[j] != "") {
        	repmenu.push( locations[j] );
        }
    }
}
repmenu = unique( repmenu.sort() );




/////////////////////////////////////////////////////////////////////////////////////////////////////////////
// build selectmenu options
var territories = document.getElementById('territories');
territories.options[0] = new Option("", "");
    
for(i = 0; i < repmenu.length; i++) {
    territories.options[(i +1)] = new Option(repmenu[i], repmenu[i]);
}





/////////////////////////////////////////////////////////////////////////////////////////////////////////////
// event function to search selectmenu::event::[onchange]
territories.onchange = function(e) {
	 
    var matched = new Array();
    var results = document.getElementById('results');
    results.innerHTML = '';
    
    var eTarget = e ? e.target : window.event.srcElement;
    
    if(eTarget.value == '') {
    	return;
    }

    results.innerHTML = '<p><span class="ppStan1">Your local MHT Lighting Sales Representive is</span><span class="HeTePLsm">;</span></p>';
    
    for(i = 0; i < salesrep.length; i++) {
        var locations = salesrep[i][1].split("#");
        
        for(j = 0; j < locations.length; j++) {
            if(locations[j] == eTarget.value) {
                results.innerHTML += '<p><span class="ppStan1">'
                                        +salesrep[i][8]
                                        +'<br>'+salesrep[i][0]
                                        +'<br>'+salesrep[i][2]
                                        +'<br>'+salesrep[i][3]+', '+salesrep[i][4]+' '+salesrep[i][5]
                                        +'<br>Phone: '+salesrep[i][6]
                                        +'<br>Fax: '+salesrep[i][7]
                                     +'</span></p>';
            }
        }
    }
    
};




/////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Libary ///////////////////////////////////////////////////////////////////////////////////////////////////
/**
 * Removes duplicates in the array 'a'
 * @author Johan Känngård, http://dev.kanngard.net
 */
function unique(a) {
	tmp = new Array(0);
	for(i=0;i<a.length;i++){
		if(!contains(tmp, a[i])){
			tmp.length+=1;
			tmp[tmp.length-1]=a[i];
		}
	}
	return tmp;
}

/**
 * Returns true if 's' is contained in the array 'a'
 * @author Johan Känngård, http://dev.kanngard.net
 */
function contains(a, e) {
	for(j=0;j<a.length;j++)if(a[j]==e)return true;
	return false;
}
