// FELLERS Hybrid Script
// Combining scripts from two Web sites into one
// Pressed into service 4/14/10

// globals

var ipos = null;
var curralbum = null;
var clickx = -1;
var clicky = -1;
var trans = null;
var add = (Browser.Engine.trident) ? 2 : 0;
var wraptablerow = 1;
var logon = 0;

// fellers.js
// Created for Fellers by Christopher Casey
// First version started 2/21/08
// altered for the October Surprise on 10/22/08

// We use MooTools' "domready" function to mess with the DOM before graphics begin to load.
// Note that pages should be semantically correct and useable even if this event doesn't fire
// or if JavaScript is turned off. It's not nearly as pretty, of course, but you can't have
// everything.

// goBright, goDark
// Mouseover/mouseout for the tabs at the top of the page

function goBright(btn) {
	$(btn).src = '/images/designoct08/tabs/' + btn + 'o.gif';
}
function goDark(btn) {
	$(btn).src = '/images/designoct08/tabs/' + btn + 'd.gif';
}

// showdeal
// Displays the flyout boxes for the FELLERS Location map

function showdeal(thing,text,x,y) {
	thingid = thing.id.substr(3);
	loc = $('installersearchtext');
	inx = $('installerx');
	loc.innerHTML = "<p id=\"instname\">" + text + "</p>";
	if (x <= 350) {
		loc.setStyles({
			position: 'absolute',
			top: (y - 9) + 'px',
			left: (x - 9) + 'px',
			padding: '5px',
			paddingTop: '14px',
			paddingLeft: '14px',
			width: '180px',
			fontSize: '12px',
			textAlign: 'left',
			color: 'white',
			overflow: 'hidden',
			backgroundImage: 'url(/images/starbg.png)',
			backgroundPosition: 'top left',
			display: 'block'
		});
	} else {
		loc.setStyles({
			position: 'absolute',
			top: (y - 9) + 'px',
			left: (x - 190) + 'px',
			padding: '5px',
			paddingTop: '14px',
			paddingLeft: '14px',
			width: '180px',
			fontSize: '12px',
			lineHeight: '14px',
			textAlign: 'left',
			color: 'white',
			overflow: 'hidden',
			backgroundImage: 'url(/images/starbg2.png)',
			backgroundPosition: 'top right',
			display: 'block'
		});	
	}
	loc.addEvent('mouseleave', function(){
		inst.setStyle('display', 'none');
	});
	loc.addEvent('click', function(){
		inst.setStyle('display', 'none');
	});
}

// showdeal2, awaydeal2, clickdeal2
// Displays and otherwise manages the tiny flyout boxes on the Wrap Training Providers map

function showdeal2(thing,text,x,y) {
	thingid = thing.id.substr(3);
	document.getElementById('installersearchtext').innerHTML = "<p id=\"instname\">" + text + "</p><p id=\"installerx\"></p>";
	var inst = $('instname');
	var inx = $('installerx');
	inst.style.position = "absolute";
	inx.style.position = "absolute";
	inx.style.display = "block";
	inst.style.top = (y * 0.7 - 4) + "px";
	inx.style.top = (y * 0.7) + "px";
	if (x > 350) {
		inst.style.left = (x * 0.7 - 170) + "px";
		inx.style.left = (x * 0.7 - 168) + "px";
		inst.style.backgroundImage = "url('http://www.fellerscertified.com/images/general/arrowur2.gif')";
		inst.style.backgroundPosition = "top right";
	} else {
		inst.style.left = (x * 0.7 - 4) + "px";
		inx.style.left = (x * 0.7 + 158) + "px";
		inst.style.backgroundImage = "url('http://www.fellerscertified.com/images/general/arrowul2.gif')";
		inst.style.backgroundPosition = "top left";
	}
	inst.style.backgroundRepeat = "no-repeat";
	inst.style.padding = "20px 8px 10px 8px";
	inst.style.width="160px";
	inx.style.width="10px";
	inx.style.height="10px";
	inx.style.cursor = "pointer";
	inst.style.overflow = "hidden";
	inst.style.fontSize = "10px";
	inst.style.lineHeight = "13px";
	inst.style.color = "white";
	inst.style.cursor = "pointer";
	inst.style.zIndex = 120;
	inx.style.zIndex = 130;
	inst.addEvent('mouseleave', function(){
		inst.setStyle('display', 'none');
		inx.setStyle('display', 'none');
		awaydeal2(thing);
	});
	inst.addEvent('click', function(){
		inst.setStyle('display', 'none');
		inx.setStyle('display', 'none');
		clickdeal2(thingid);
	});
	inx.addEvent('click', function(){
		inst.setStyle('display', 'none');
		inx.setStyle('display', 'none');
		awaydeal2(thing);
	});
}
function awaydeal2(thing) {
	if (document.getElementById(thing.id).style.backgroundImage == "url(/images/general/blue9.gif)")
		document.getElementById(thing.id).style.backgroundImage = "url('/images/general/bluepulse9.gif')"
	else
		document.getElementById(thing.id).style.backgroundImage = "url('/images/general/blue5.gif')";
}
function clickdeal2(id) {
	locale = "http://www.fellerscertified.com/index.cfm/spKey/gallery.htm?installerID=" + id;
	window.location = locale;
}

// getParams
// Utility function to retrieve GET parameters
// Not sure if it's even used at the moment, but it's handy

function getParams() {
	var idx = document.URL.indexOf('?');
	var params = new Array();
	if (idx != -1) {
		var pairs = document.URL.substring(idx+1, document.URL.length).split('&');
		for (var i=0; i<pairs.length; i++) {
		nameVal = pairs[i].split('=');
		params[nameVal[0]] = nameVal[1];
		}
	}
	return params;
}

// Functions from FELLERS Certified site
// Begun circa March 2009

// getInstDetail
// Called when someone clicks a wrap provider on the map sidebar

function getInstDetail(spid) {
	setUpAlbum();
	var JSONinst = new Request.JSON({ // Holy cow do I ever love these Request.JSON things
		url: "/json/installerInfo.cfm",
		onSuccess: function(obj,txt) {
			curralbum = obj.ALBUM;
			$('windowbartext').set('text','FELLERS Certified Provider: ' + obj.COMPANY + ', ' + obj.CITY + ' ' + obj.STATE);
			$('titleholder').set('html','<h2>' + obj.COMPANY + '</h2>');
			$('addressholder').set('html',obj.ADDRESSHTML);
			$('detailholder').set('html',obj.DETAILHTML);
			setUpThumbs();
		}
	}).post({'spid': spid}).send();
}

// setUpAlbum
// Creates the wrap provider info "window" popup

function setUpAlbum() {
	var vpos = window.getScroll();
	if (!($defined($('albumholder')))) {
		var albumdiv = new Element('div', { 'id': 'albumholder', 'styles': { 'top': vpos.y + 50 }}).inject('placeholder');
		var topdiv = new Element('div', { 'id': 'windowbar' }).inject(albumdiv);
		var toptext = new Element('p', { 'id': 'windowbartext', 'html': 'Loading ...' }).inject(topdiv);
		var closebutton = new Element('div', { 'id': 'closebutton',
			'events': {
				'mouseover': function(){
					$('closebutton').setStyle('backgroundColor', '#fc0');
				},
				'mouseout': function() {
					$('closebutton').setStyle('backgroundColor', 'orange');
				}
			}
		}).inject(topdiv);
		var closex = new Element('img', { 'src': '/images/designapr09/xbox.gif', 'height': 16, 'width': 16, 'border': 0 }).inject(closebutton);
		var leftdiv = new Element('div', { 'id': 'contentarea' }).inject(albumdiv);
		var txtdiv = new Element('div', { 'id': 'titleholder' }).inject(leftdiv);
		var adddiv = new Element('div', { 'id': 'addressholder' }).inject(leftdiv);
		var detdiv = new Element('div', { 'id': 'detailholder' }).inject(leftdiv);
		var pixdiv = new Element('div', { 'id': 'bigimage' }).inject(leftdiv);
		var blkdiv = new Element('div', { 'id': 'blackout' }).inject(leftdiv);
		var imgdiv = new Element('div', { 'id': 'imageholder' }).inject(pixdiv);
		var capdiv = new Element('div', { 'id': 'captionholder' }).inject(pixdiv);
		var rightdiv = new Element('div', { 'id': 'rightscroller' }).inject(albumdiv);
		closebutton.addEvent('click', function(){ $('albumholder').setStyle('display', 'none'); });
		pixdiv.addEvent('click', function(){
			$('bigimage').setStyle('display', 'none');
			$('blackout').setStyle('display', 'none');
			if ($('albumholder').getStyle('height').toInt() > 450) {
				$('albumholder').setStyle('height',450);
				$('contentarea').setStyle('height', 423);
				$('addressholder').setStyle('height', 423);
				$('rightscroller').setStyle('height', 423);	
			}
		});
		var newDrag = new Drag($('albumholder'), { handle: $('windowbar') });
		$('albumholder').pin();
	} else {
		$('windowbartext').set('html','Loading ...');
		$('titleholder').set('text','');
		$('addressholder').set('text','');
		$('detailholder').set('text','');
		$('rightscroller').set('text','');
		$('contentarea').setStyle('display','block');
		$('bigimage').setStyle('display','none');
		$('blackout').setStyle('display','none');
		$('albumholder').setStyle('display', 'block');
	}
}

// setUpThumbs
// Downloads and builds out the thumbnails on the right of the album popup

function setUpThumbs() {
	if (curralbum != null && curralbum.length > 0) {
		for (x = 0; x < curralbum.length; x++) {
			o = curralbum[x];
			im = new Element('img', {
				'src': o.TSRC,
				'height': o.THEIGHT,
				'width': o.TWIDTH,
				'border': 0,
				'title': o.CAPTION,
				'alt': x,
				'events': {
					'click': function() {
						$('bigimage').empty();
						var blockheight = $('addressholder').getStyle('height').toInt();
						var x = this.alt.toInt();
						var hgt = curralbum[x].HEIGHT;
						var wdt = curralbum[x].WIDTH;
						im = new Element('img', {
							'src': curralbum[x].SRC,
							'height': hgt,
							'width': wdt,
							'border': 0,
							'title': curralbum[x].CAPTION
						}).inject($('bigimage'));
						cp = new Element('p', {
							'align': 'center',
							'html': curralbum[x].CAPTION + '<br /><span style="font-size: 10px">(click image to return)</span>',
							'styles': { 'color': 'white', 'fontWeight': 'bold', 'marginTop': '3px' }
						}).inject($('bigimage'));
						hgt += 33;
						var imgx = (700 - wdt) / 2;
						if (hgt <= 423) {
							var imgy = (423 - hgt) / 2;
							$('albumholder').setStyle('height', 450);
							$('contentarea').setStyle('height', 423);
							$('addressholder').setStyle('height', 423);
							$('rightscroller').setStyle('height', 423);
							blockheight= 423;
						} else {
							var imgy = 0;
							$('albumholder').setStyle('height', hgt + 27);
							$('contentarea').setStyle('height', hgt);
							$('addressholder').setStyle('height', hgt);
							$('rightscroller').setStyle('height', hgt);
							blockheight = hgt;
						}
						$('blackout').setStyles({
							'top': 32,
							'left': 5,
							'width': 700,
							'height': blockheight,
							'display': 'block'
						});
						$('bigimage').setStyles({
							'top': imgy + 32,
							'left': imgx + 5,
							'display': 'block'
						});
					}
				},
				'styles': {
					'padding': '0 0 5px',
					'marginLeft': 'auto',
					'marginRight': 'auto'
				}
			}).inject($('rightscroller'));
		}
	}
}

// addWrapTableRow
// Adds a row to the table of options on the Request a Quote form

function addWrapTableRow() {
	if (wraptablerow < 10) {
		wraptablerow++;
		var tr = new Element('tr').inject($('additemrow'),'before');
		var td1 = new Element('td', {
			html: '<select id="itemtype' + wraptablerow.toString() + '" name="itemtype' + wraptablerow.toString() + '"><option value=""></option><option value="Automobile">Automobile</option><option value="Boat">Boat</option><option value="Building">Building</option><option value="Bus/RV">Bus or RV</option><option value="Cycle/ATV">Cycle or ATV</option><option value="Floor">Floor</option><option value="Trailer">Trailer</option><option value="Truck">Truck</option><option value="Van">Van</option><option value="Wall (Smooth)">Smooth Wall</option><option value="Wall (Rough)">Rough Wall</option><option value="Window">Window</option><option value="Other">Other (Please describe)</option></select>'
		}).inject(tr);
		var td2 = new Element('td', {
			html: '<input id="itemyear' + wraptablerow.toString() + '" name="itemyear' + wraptablerow.toString() + '" type="text" maxlength="4" size="5" />'
		}).inject(tr);
		var td3 = new Element('td', {
			html: '<input id="itemmake' + wraptablerow.toString() + '" name="itemmake' + wraptablerow.toString() + '" type="text" maxlength="50" size="10" />'
		}).inject(tr);
		var td4 = new Element('td', {
			html: '<input id="itemmodel' + wraptablerow.toString() + '" name="itemmodel' + wraptablerow.toString() + '" type="text" maxlength="50" size="10" />'
		}).inject(tr);
		var td7 = new Element('td', {
			html: '<input id="itemsize' + wraptablerow.toString() + '" name="itemsize' + wraptablerow.toString() + '" type="text" maxlength="40" size="10" class="required" />'
		}).inject(tr);
		var td5 = new Element('td', {
			html: '<input id="itemqty' + wraptablerow.toString() + '" name="itemqty' + wraptablerow.toString() + '" type="text" maxlength="4" size="5" />'
		}).inject(tr);
		var td6 = new Element('td', {
			html: '<input id="itemdesc' + wraptablerow.toString() + '" name="itemdesc' + wraptablerow.toString() + '" type="text" maxlength="150" size="20" />'
		}).inject(tr);
		if (wraptablerow == 10) {
			$('additemrow').destroy();
		}
	}
}

// zipFinder, alphaFinder, stateFinder
// Searches/displays wrap providers on the big map by various criteria

function zipFinder() {
	clearBrightDots();
	$('statedefault').selected = true;
	$('alphadefault').selected = true;
	var ntext = $('zipformzip').value.replace(/[\D]/g,'');
	if (ntext.length < 5) {
		$('zipformzip').setStyle('backgroundColor', '#fcc');
		$('zipformzip').addEvent('keydown', function() { this.setStyle('backgroundColor', 'white'); });
		return false;
	}
	$('mres').setStyle('display', 'block');
	$('mres').setStyles({ 'top': 100, 'left': 785, 'height': 428 });
	$('mres').set('html','<p>One moment please ...</p>');
	var JSON = new Request.JSON({
		url: "/json/returnInstallers.cfm",
		onSuccess: function(obj,txt) {
			if (obj.SCS == 'a') {
				ipos = $('mapholder').getPosition();
				var mousex = obj.XPO - 17;
				var mousey = obj.YPO - 13;
				$('xline').setStyles({'position': 'absolute', 'top': mousey, 'height': 1, 'width': 810, 'backgroundColor': '#1769a6', 'display': 'block'});
				$('yline').setStyles({'position': 'absolute', 'left': mousex, 'height': 538, 'width': 1, 'backgroundColor': '#1769a6', 'display': 'block'});
				$('clickbox').setStyles({ 'position': 'absolute', 'top': mousey - 5, 'left': mousex - 5, 'height': 9, 'width': 9, 'display': 'block', 'border': '1px solid white' });
				var arlen = obj.RES.length;
				var outtext = '';
				for (i = 0; i < arlen; i++) {
					var spid = obj.RES[i][0];
					var comp = obj.RES[i][1];
					var addr = obj.RES[i][2];
					var dist = obj.RES[i][3];
					//var punch = '<p><a href="/index.cfm/spKey/gallery?spid=' + spid + '"><b>' + comp + '</b></a><br />' + addr + '</p>';
					var punch = '<p><a href="#" onclick="getInstDetail(\'' + spid + '\'); return false;"><b>' + comp + '</b></a><br />' + addr + '</p>';
					outtext = outtext + punch;
					addBrightDot(spid);
				}
				if (outtext != '') {
					$('mres').set('html', '<p><strong>Search Results for ZIP code ' + ntext + '</strong></p>' + outtext);
				} else {
					$('mres').set('html','<p>No FELLERS Certified providers were found within 250 miles of your selected location.</p>');
					$('clickbox').setStyles({'backgroundImage': 'none', 'border': '1px solid #1769a6'});
				}
			} else {
				$('mres').set('html','<p>You have entered an unknown 5-digit U.S. ZIP postal code. Please try again.</p>');
			}
		}
	}).post({'localzip': ntext, 'mapwidth': 842, 'offsetx': 0, 'offsety': 0 }).send();
	return false;
}

function alphaFinder() {
	$('statedefault').selected = true;
	$('zipformzip').value = '';
	$('xline').setStyle('display','none');
	$('yline').setStyle('display','none');
	$('clickbox').setStyle('display','none');
	clearBrightDots();
	var ntext = $('alphaformalpha').value;
	$('mres').setStyle('display', 'block');
	$('mres').setStyles({ 'top': 100, 'left': 785, 'height': 428 });
	$('mres').set('html','<p>One moment please ...</p>');
	var JSON = new Request.JSON({
		url: "/json/returnInstallers.cfm",
		onSuccess: function(obj,txt) {
			if (obj.SCS == 'a') {
				ipos = $('mapholder').getPosition();
				var arlen = obj.RES.length;
				var outtext = '';
				for (i = 0; i < arlen; i++) {
					var spid = obj.RES[i][0];
					var comp = obj.RES[i][1];
					var addr = obj.RES[i][2];
					var dist = obj.RES[i][3];
					var punch = '<p><a href="#" onclick="getInstDetail(\'' + spid + '\'); return false;"><b>' + comp + '</b></a><br />' + addr + '</p>';
					outtext = outtext + punch;
					addBrightDot(spid);
				}
				if (outtext != '') {
					if (ntext == '0') { ntext = '0-9'; }
					$('mres').set('html', '<p><strong>Alpha Search Results: ' + ntext + '</strong></p>' + outtext);
				} else {
					$('mres').set('html','<p>No FELLERS Certified providers found that match your search criteria.</p>');
				}
			} else {
				$('mres').set('html','<p>You have entered an unknown code. Please try again.</p>');
			}
		}
	}).post({'alpha': ntext, 'mapwidth': 842, 'offsetx': 0, 'offsety': 0 }).send();
	return false;
}

function stateFinder() {
	$('alphadefault').selected = true;
	$('zipformzip').value = '';
	$('xline').setStyle('display','none');
	$('yline').setStyle('display','none');
	$('clickbox').setStyle('display','none');
	clearBrightDots();
	var ntext = $('stateformstate').value;
	if (ntext.length != 2) {
		$('alphaformalpha').setStyle('backgroundColor', '#fcc');
		$('alphaformalpha').addEvent('keydown', function() { this.setStyle('backgroundColor', 'white'); });
		return false;
	}
	$('mres').setStyles({ 'display': 'block', 'top': 100, 'left': 785, 'height': 428 });
	$('mres').set('html','<p>One moment please ...</p>');
	var JSON = new Request.JSON({
		url: "/json/returnInstallers.cfm",
		onSuccess: function(obj,txt) {
			if (obj.SCS == 'a') {
				var arlen = obj.RES.length;
				var outtext = '';
				for (i = 0; i < arlen; i++) {
					var spid = obj.RES[i][0];
					var comp = obj.RES[i][1];
					var addr = obj.RES[i][2];
					var dist = obj.RES[i][3];
					var punch = '<p><a href="#" onclick="getInstDetail(\'' + spid + '\'); return false;"><b>' + comp + '</b></a><br />' + addr + '</p>';
					outtext = outtext + punch;
					addBrightDot(spid);
				}
				if (outtext != '') {
					$('mres').set('html', '<p><strong>Search Results by State: ' + ntext + '</strong></p>' + outtext);
				} else {
					$('mres').set('html','<p>No FELLERS Certified providers matched your search criteria.</p>');
				}
			} else {
				$('mres').set('html','<p>You have entered an unknown code. Please try again.</p>');
			}
		}
	}).post({'state': ntext, 'mapwidth': 842, 'offsetx': 0, 'offsety': 0 }).send();
	return false;
}

// clearBrightDots
// Turns all the selected providers on the big map into unselected ones

function clearBrightDots() {
	$$('div').each( function(itm,idx) {
		if (itm.getStyle('backgroundImage').search('brightdot2') != -1) {
			itm.setStyle('backgroundImage','url(/images/designapr09/mapdot3.png)');
		}
	});
}

// addBrightDot
// Selects a particular wrap provider on the big map

function addBrightDot(spid) {
	if ($defined($(spid))) {
		$(spid).setStyle('backgroundImage','url(/images/designapr09/brightdot2.png)');
	}
}

// geoLocate
// Finds where the user is and sets that location as their initial position on the big providers map

function geoLocate() {
	var JSON = new Request.JSON({
		url: "/json/geoLocate.cfm",
		onSuccess: function(obj,txt) {
			if (obj.OK == 'yes') {
				var ipos = $('mapholder').getPosition();
				var xpos = obj.XPOS + ipos.x + add + 5;
				var ypos = obj.YPOS + ipos.y + add;
				$('mapholder').fireEvent('click', {page: {x: xpos, y: ypos}});
			}
		}
	}).send();
}

// preload
// Alters the document after loading the HTML but before images, using MooTools' ultra-handy domready function

function preload() {
	// var params = getParams(); May be useful at some point, but not right now
	
	// Sets up and loads the big FELLERS Certified Provider map
	if ($defined($('mapholder'))) {
		var mh = $('mapholder');
		
		mh.empty(); // Clears out the anchor tag and img, giving us a nice clean slate
		
		var cb = new Element('div', { 'id': 'clickbox' }).inject(mh);
		var px = new Element('div', { 'id': 'xline' }).inject(mh);
		var py = new Element('div', { 'id': 'yline' }).inject(mh);
		
		// Adding points to the map, speedy style (I hope)
		var loadingdiv = new Element('div', {
			'id': 'loadingdiv',
			'styles': {
				'position': 'absolute',
				'top': '240px',
				'left': '305px',
				'height': '19px',
				'width': '220px',
				'color': 'white',
				'backgroundImage': 'url(/images/designapr09/loadbar.gif)'
			}
		}).inject(mh);
		var mapJSON = new Request.JSON({
			url: "/json/installersMap.cfm",
			onSuccess: function(obj, txt) {
				mapj = obj;
				var arlen = obj.RES.length;
				var outtext = '';
				$('loadingdiv').setStyle('display','none');
				for (i = 0; i < arlen; i++) {
					var spid = obj.RES[i][0];
					var xpos = obj.RES[i][1] - 28;
					var ypos = obj.RES[i][2] - 31;
					var comp = obj.RES[i][3];
					var loca = obj.RES[i][4];
					var lat  = obj.RES[i][5];
					var lng  = obj.RES[i][6];
					
					if (ypos < 0) { // Alaska ... not sure if this works for any location but Fairbanks, to be honest
						xpos += 100;
						ypos += 785;
					}
					
					if (xpos < 0) { // Hawaii's map is a Mercator projection, so we get to do this one the easy way
						ypos = (lat * -21.872) + 932;
						xpos = (lng * 22.857) + 3915;
					}
					
					var ndiv = new Element('div', { 
						'class':	'mapPoint',
						'id':		spid,
						'styles': {
							'position': 'absolute',
							'height': '20px',
							'width': '18px',
							'backgroundImage': 'url(/images/designapr09/mapdot3.png)',
							'zIndex': 3,
							'top': ypos,
							'left': xpos
						}
					}).inject(mh);
				}
				geoLocate();
			}
		// As it turns out, the math only works if there's padding exactly (10 / 370) * width pixels around the outside of the map.
		// By stunning coincidence, that's the size of the padding around the minimap, which is the first implementation of this
		// algorithm that I did. What are the chances.
		// ... anyway, that's why the map width is set differently from the actual map and we do some funky stuff with the return values.
		}).post({'mapwidth': 842, 'offsetx': 0, 'offsety': 0}).send();
	
		// Full-sized map functionality
		mh.addEvents({
			'click': function(ev) {
				clearBrightDots();
				$('zipformzip').value = '';
				$('alphadefault').selected = true;
				$('statedefault').selected = true;
				ipos = mh.getPosition();
				var mousex = ev.page.x - ipos.x - add;
				var mousey = ev.page.y - ipos.y - add;
				$('xline').setStyles({'position': 'absolute', 'top': mousey, 'height': 1, 'width': 810, 'backgroundColor': '#1769a6', 'display': 'block'});
				$('yline').setStyles({'position': 'absolute', 'left': mousex, 'height': 538, 'width': 1, 'backgroundColor': '#1769a6', 'display': 'block'});
				$('clickbox').setStyles({ 'position': 'absolute', 'top': mousey - 5, 'left': mousex - 5, 'height': 9, 'width': 9, 'backgroundImage': 'url(/images/designapr09/spinball.gif)','display': 'block', 'border': 'none' });
				$('mres').setStyles({'display': 'block', 'top': 100, 'left': 785, 'height': 428 });
				$('mres').set('html', '<p>One moment please ...</p>');
				//mapSlide.slideIn();
				var JSON = new Request.JSON({
					url: "/json/returnInstallers.cfm",
					onSuccess: function(obj,txt) {
						var arlen = obj.RES.length;
						var outtext = '';
						for (i = 0; i < arlen; i++) {
							var spid = obj.RES[i][0];
							var comp = obj.RES[i][1];
							var addr = obj.RES[i][2];
							var dist = obj.RES[i][3];
							var punch = '<p><a href="#" onclick="getInstDetail(\'' + spid + '\'); return false;"><b>' + comp + '</b></a><br />' + addr + '</p>';
							outtext = outtext + punch;
							addBrightDot(spid);
							$('clickbox').setStyles({'backgroundImage': 'none', 'border': '1px solid white'});
						}
						if (outtext != '') {
							$('mres').set('html', outtext);
						} else {
							$('mres').set('html','<p>No FELLERS Certified providers were found within 250 miles of your selected location.</p>');
							$('clickbox').setStyles({'backgroundImage': 'none', 'border': '1px solid #1769a6'});
						}
					}
				}).post({'mousex': mousex + 14 + add, 'mousey': mousey + 14 + add, 'mapwidth': 842, 'offsetx': 0, 'offsety': 0 }).send();
			}
		});
		// End megamap
	}
}

window.addEvent('domready', function() {
	preload();
});

// fellersSSO: A "single signon" routine for various routines
//             NOTE: To change what happens on various pages when you sign on, fix /scripts/checksso.cfm

function fellersSSO() {
	if ($defined($('ssologout'))) {
		return true;
	} else {
		var cno = $('ssocno').value.trim();
		var zip = $('ssozip').value.trim();
		var tpg = $('tpage').value;
		
		$('ssohidden').set('html', '<p>Sending request ...</p>');
		
		var hreq = new Request.HTML({
			url: '/scripts/checksso.cfm',
			onSuccess: function(tree, elem, html, js) {
				$('ssohidden').set('html', html);
				if (html.substr(0,8) != '<p>Error') {
					Cookie.write('SSOCNO', cno);
					Cookie.write('SSOZIP', zip);
					var scno = new Element('span', { 'class': 'loggedin', 'html': cno, 'id': 'cnorep' }).replaces($('ssocno'));
					var szip = new Element('span', { 'class': 'loggedin', 'html': zip, 'id': 'ziprep' }).replaces($('ssozip'));
					var gred = new Element('input', { 'id': 'ssologout', 'type': 'hidden', 'name': 'logout', 'value': 'logout' }).inject($('fellerssso'));
					$('loginbutton').set('src','/images/general/fellersloginlogout.gif');
				}
				logon = 1;
			},
			onFailure: function() {
				$('ssohidden').set('html', '<p>Error: There was a network error. Please try again.</p>');
				logon = 0;
			}
		}).post({'ssocno': cno, 'ssozip': zip, 'tpage': tpg});
	}
	return false;
}
