// JavaScript Document

// there is still a timing issue with the balloons where scrollbars are being displayed when not actually needed, re-clicking
// the location will remove the scrollbars

var bsofftop = 10;
var bsoffleft = 10;

var blofftop = 10;
var bloffleft = 10;

var bsdeftop = 10;
var bsdefleft = 10;

var bldeftop = 10;
var bldefleft = 10;

var currentLocation = null;
var currentStore = null;
var adjLocHeight = 0;
var trimLocHeight = 10;
var adjStHeight = 0;

var bssizeofftop = 10;
var bssizeoffleft = 10;

var blsizeofftop = 10;
var blsizeoffleft = 10;

var scr;

var firstOne = true;
var myMouse = new xMouse();

var leftRightDirection 	= {"u":"up", "c":"center","d":"down"};
var topBottomDirection 	= {"l":"left", "c":"center","r":"right"};

var leftRightAlignment 	= {"t":"top", "m":"middle","b":"bottom"};
var topBottomAlignment 	= {"l":"left", "c":"center","r":"right"};

var soloStore = false;

var lastClicked = '';

function highlightStore(thisOne)
{
	if (lastClicked != '' && document.getElementById('launch_' + lastClicked))
	{
		document.getElementById('launch_' + lastClicked).style.backgroundColor = 'transparent';
	}
	lastClicked = thisOne;
	if (document.getElementById('launch_' + thisOne))
	{
		if (thisOne != '')
		{
			document.getElementById('launch_' + thisOne).style.backgroundColor = pageHighlight;
		}
	}
}

function setLocationOffset(whichOne) {
	if (df == null) {
		document.getElementById('bloc').className = 'snagSize';
		}
	// if the tail is at the top, adjust the top position for the contents
	// if the tail is at the left, adjust the left position for the contents
	blofftop = bldeftop;
	bloffleft = bldefleft;

	if (pa[whichOne].location['balloon'].edge == 'l') {
		bloffleft = parseInt(document.getElementById('blocla').width) + bldefleft;
		blofftop = parseInt(document.getElementById('bloctlc').height);
		}
	else if (pa[whichOne].location['balloon'].edge == 't') {
		bloffleft = parseInt(document.getElementById('bloctlc').width);
		blofftop = parseInt(document.getElementById('blocta').height)+ bldeftop;
		}
	else {
		bloffleft = parseInt(document.getElementById('bloctlc').width);
		blofftop = parseInt(document.getElementById('bloctlc').height);
		}
	if (df != null) {
		if (setFromForm == true) {
			blsizeoffleft = (parseInt(document.getElementById('innerLocation').style.width) + parseInt(bloffleft)) - parseInt(document.getElementById('sizeLocation').style.width);
			blsizeofftop = (parseInt(document.getElementById('innerLocation').style.height) + parseInt(blofftop) + parseInt(adjLocHeight)) - parseInt(document.getElementById('sizeLocation').style.height);
			}
		else {
			blsizeoffleft = (parseInt(document.getElementById('innerLocation').style.width) + parseInt(bloffleft)) - parseInt(document.getElementById('sizeLocation').style.width);
			blsizeofftop = (parseInt(document.getElementById('innerLocation').style.height) + parseInt(blofftop) + parseInt(adjLocHeight)) - parseInt(document.getElementById('sizeLocation').style.height);
			}
		}
	if (df == null) {
		document.getElementById('bloc').className = 'hideItem';
		}
	}
function setStoreOffset(whichOne) {
	if (df == null) {
		document.getElementById('bst').className = 'snagSize';
		}
	// if the tail is at the top, adjust the top position for the contents
	// if the tail is at the left, adjust the left position for the contents
	bsofftop = bsdeftop;
	bsoffleft = bsdefleft;
	
	if (pa[whichOne].store['balloon'].edge == 'l') {
		bsoffleft = bsdefleft + document.getElementById('bstla').width;
		bsofftop = parseInt(document.getElementById('bstta').height) + parseInt(document.getElementById('bsttlc').height);
		}
	else if (pa[whichOne].store['balloon'].edge == 't') {
		bsoffleft = parseInt(document.getElementById('bstla').width) + parseInt(document.getElementById('bsttlc').width);
		bsofftop = bsdeftop + document.getElementById('bstta').height;
		}
	else {
		bsoffleft = parseInt(document.getElementById('bstla').width) + parseInt(document.getElementById('bsttlc').width);
		bsofftop = parseInt(document.getElementById('bstta').height) + parseInt(document.getElementById('bsttlc').height);
		}
	if (df != null) {
		if (setFromForm == true) {
			bssizeoffleft = (parseInt(document.getElementById('innerStore').style.width) + parseInt(bsoffleft)) - parseInt(document.getElementById('sizeStore').style.width);
			bssizeofftop = (parseInt(document.getElementById('innerStore').style.height) + parseInt(bsofftop) + parseInt(adjStHeight)) - parseInt(document.getElementById('sizeStore').style.height);
			}
		else {
			bssizeoffleft = (parseInt(document.getElementById('innerStore').style.width) + parseInt(bsoffleft)) - parseInt(document.getElementById('sizeStore').style.width);
			bssizeofftop = (parseInt(document.getElementById('innerStore').style.height) + parseInt(bsofftop) + parseInt(adjStHeight)) - parseInt(document.getElementById('sizeStore').style.height);
			}
		}
	if (df == null) {
		document.getElementById('bst').className = 'hideItem';
		}
	}
function setPositions(thisId) {
	currentLocation = thisId;
	if (document.getElementById('hints'))
	{
		document.getElementById('hints').style.display='none';
	}
	if (document.getElementById('sunsetFinley'))
	{
		document.getElementById('sunsetFinley').style.display='none';
	}
	if (document.getElementById('transMap')) {
		document.getElementById('transMap').style.cursor='wait';
		}
	else {
		document.body.style.cursor='wait';
		}
	if (document.getElementById('stats') && document.getElementById('stats').className=='showBlock') {
		document.getElementById('stats').className='hideItem';
		}
	if (df != null) {
		df.storelocationid.value = thisId;
		document.getElementById('locationid_' + thisId).checked = 1;
		document.getElementById('locationid_' + thisId).focus();
		}
	if (!pa[thisId].store['balloon']) {
		// append the js, it will call actualSetPositions(thisId)
		scr = document.createElement('script');
		if (upsize != null) {
			scr.src="http://www.nodds.org/js/getLocPosStInfo.php?nid=10010&slid=" + thisId + "&upsize=" + upsize;
			}
		else {
			scr.src="http://www.nodds.org/js/getLocPosStInfo.php?nid=10010&slid=" + thisId;
			}
		window.setTimeout("delayScriptAppend()", 2);
		}
	else {
		window.setTimeout("actualSetPositions()", 200);
		}
	}
function delayScriptAppend() {
	document.body.appendChild(scr);
	}
function actualSetPositions() {
	var thisId = null;
	if (currentLocation != null) {
		thisId = currentLocation;
		}
	if (thisId != null && pa[thisId].location['balloon']) {
		// set the form inputs 
		if (df != null) {
			df.ltop.value = pa[thisId].location['balloon'].topx;
			df.lleft.value = pa[thisId].location['balloon'].leftx;
			df.lcontentheight.value = pa[thisId].location['balloon'].contentheight;
			df.lcontentwidth.value = pa[thisId].location['balloon'].contentwidth;
			df.stop.value = pa[thisId].store['balloon'].topx;
			df.sleft.value = pa[thisId].store['balloon'].leftx;
			df.scontentheight.value = pa[thisId].store['balloon'].contentheight;
			df.scontentwidth.value = pa[thisId].store['balloon'].contentwidth;
			for(var i=0;i<df.ledge.length;i++) {
				if (df.ledge[i].value == pa[thisId].location['balloon'].edge) {
					df.ledge.selectedIndex = i;
					break;
					}
				}
			setDirectionAlignment('ledge');
			for(var i=0;i<df.ldirection.length;i++) {
				if (df.ldirection[i].value == pa[thisId].location['balloon'].direction) {
					df.ldirection.selectedIndex = i;
					break;
					}
				}
			for(var i=0;i<df.lalignment.length;i++) {
				if (df.lalignment[i].value == pa[thisId].location['balloon'].alignment) {
					df.lalignment.selectedIndex = i;
					break;
					}
				}
			for(var i=0;i<df.columns.length;i++) {
				if (df.columns[i].value == pa[thisId].location['balloon'].columns) {
					df.columns.selectedIndex = i;
					break;
					}
				}
			for(var i=0;i<df.sedge.length;i++) {
				if (df.sedge[i].value == pa[thisId].store['balloon'].edge) {
					df.sedge.selectedIndex = i;
					break;
					}
				}
			setDirectionAlignment('sedge');
			for(var i=0;i<df.sdirection.length;i++) {
				if (df.sdirection[i].value == pa[thisId].store['balloon'].direction) {
					df.sdirection.selectedIndex = i;
					break;
					}
				}
			for(var i=0;i<df.salignment.length;i++) {
				if (df.salignment[i].value == pa[thisId].store['balloon'].alignment) {
					df.salignment.selectedIndex = i;
					break;
					}
				}
			}
		// then set the balloons
		setTail('bloc', pa[thisId].location['balloon'].edge, pa[thisId].location['balloon'].direction, pa[thisId].location['balloon'].alignment, 'redline');
		setTail('bst', pa[thisId].store['balloon'].edge, pa[thisId].store['balloon'].direction, pa[thisId].store['balloon'].alignment, 'redline');
		
		setStoreOffset(thisId);
		setLocationOffset(thisId);

		moveBalloonTo('bloc', pa[thisId].location['balloon'].leftx + 'px', pa[thisId].location['balloon'].topx + 'px');
		moveBalloonTo('bst', pa[thisId].store['balloon'].leftx + 'px', pa[thisId].store['balloon'].topx + 'px');
		moveBalloonTo('moveLocation', pa[thisId].location['balloon'].leftx + 'px', pa[thisId].location['balloon'].topx + 'px');
		moveBalloonTo('moveStore', pa[thisId].store['balloon'].leftx + 'px', pa[thisId].store['balloon'].topx + 'px');
		
		moveBalloonTo('blocContents', (parseInt(pa[thisId].location['balloon'].leftx) + parseInt(bloffleft)) + 'px', (parseInt(pa[thisId].location['balloon'].topx) + parseInt(blofftop)) + 'px');
		moveBalloonTo('bstContents', (parseInt(pa[thisId].store['balloon'].leftx) + parseInt(bsoffleft)) + 'px', (parseInt(pa[thisId].store['balloon'].topx) + parseInt(bsofftop)) + 'px');
		
		moveBalloonTo('sizeLocation', (parseInt(pa[thisId].location['balloon'].leftx) + parseInt(blsizeoffleft)) + 'px', (parseInt(pa[thisId].location['balloon'].topx) + parseInt(blsizeofftop)) + 'px');
		moveBalloonTo('sizeStore', (parseInt(pa[thisId].store['balloon'].leftx) + parseInt(bssizeoffleft)) + 'px', (parseInt(pa[thisId].store['balloon'].topx) + parseInt(bssizeofftop)) + 'px');		
				
		window.setTimeout("showLocation()",300);
		if (df != null) {
			showStore(thisId);
			}
		else {
			hideStore();
			}
		}
	}
function showLocation() {
	var whichOne = null;
	soloStore = false;
	if (currentLocation != null) {
		whichOne = currentLocation;
		}
	// first hide the rest
	if (df == null) {
		hideLocation();
		}
	var thisText = makeInnerList(whichOne);
	document.getElementById('innerLocationList').innerHTML = thisText;
	document.getElementById('bloc').className='bloc';
	document.getElementById('blocContents').className='blocContents';
	document.getElementById('locationName').innerHTML = '<a href="location.php?storelocationid=' + whichOne + '"style="font-size:16px;" class="greenBold" onMouseOver="showText(\'Click To View Profile\');" onMouseOut="hideName();">' + pa[whichOne].location['name1'] + '<img src="/images/icons/NN-P.gif" border="0" align="bottom" style="margin-left:3px;"><\/a><br><span style="font-family:Arial, Helvetica, sans-serif;color:#000000;font-weight:normal;">' + pa[whichOne].location['name2'] + '<\/span>';
	// set the compensation for the extra rows in the table
	adjLocHeight = parseInt(document.getElementById('hideLocation').offsetHeight) + parseInt(document.getElementById('locationName').offsetHeight) + parseInt(document.getElementById('locFooter').offsetHeight) + parseInt(document.getElementById('locFooterCel').offsetHeight) - trimLocHeight;
	
	document.getElementById('blocFiller').style.height = parseInt(pa[whichOne].location['balloon'].contentheight)+ 'px';
	document.getElementById('innerLocation').style.height = (parseInt(pa[whichOne].location['balloon'].contentheight) - adjLocHeight) + 'px';
	document.getElementById('blocFiller').style.width = parseInt(pa[whichOne].location['balloon'].contentwidth)+ 'px';
	document.getElementById('innerLocation').style.width = parseInt(pa[whichOne].location['balloon'].contentwidth) + 'px';
	
	setScrollForLayer('innerLocation');
	if (firstOne == true) {
		firstOne = false;
		showLocation(whichOne);
		}
	}
function actualShowStore() {
	var fromLocation = currentLocation;
	var whichOne = currentStore;
	var contentString = '';
	// first hide the rest
	if (df == null) {
		if (soloStore == true)
		{
			hideLocation();
		}
		hideStore();
		}
	highlightStore(currentStore);
	// then set the balloons
	setTail('bst', pa[fromLocation].store['balloon'].edge, pa[fromLocation].store['balloon'].direction, pa[fromLocation].store['balloon'].alignment, 'redline');
	
	setStoreOffset(fromLocation);

	moveBalloonTo('bst', pa[fromLocation].store['balloon'].leftx + 'px', pa[fromLocation].store['balloon'].topx + 'px');
	moveBalloonTo('moveStore', pa[fromLocation].store['balloon'].leftx + 'px', pa[fromLocation].store['balloon'].topx + 'px');
	
	moveBalloonTo('bstContents', (parseInt(pa[fromLocation].store['balloon'].leftx) + parseInt(bsoffleft)) + 'px', (parseInt(pa[fromLocation].store['balloon'].topx) + parseInt(bsofftop)) + 'px');
	
	moveBalloonTo('sizeStore', (parseInt(pa[fromLocation].store['balloon'].leftx) + parseInt(bssizeoffleft)) + 'px', (parseInt(pa[fromLocation].store['balloon'].topx) + parseInt(bssizeofftop)) + 'px');		

	document.getElementById('bst').className='bst';
	document.getElementById('bstContents').className='bstContents';
	if (document.getElementById('bst') && pa[fromLocation] && pa[fromLocation].store[whichOne]) {
		contentString = '<p style="margin:0px;color:#006600;font-weight:bold;">' + pa[fromLocation].store[whichOne].storeinfoname + '<\/p>';
		}
	document.getElementById('storeName').innerHTML = contentString;
	if (document.getElementById('innerStore') && pa[fromLocation] && pa[fromLocation].store[whichOne]) {
		contentString = '<p style="margin:0px;"><img src="/images/greenbullet.gif" align="absmiddle"> ' + pa[fromLocation].store[whichOne].notes + '<\/p>';
		if (pa[fromLocation].store[whichOne].imagepath) {
			contentString += '<div style="border: 1px solid #006600;padding:1px;width:150px;"><img id="storeimage" src="' + pa[fromLocation].store[whichOne].imagepath + '" ' + pa[fromLocation].store[whichOne].imagesize + '" border="0"><\/div>';
			}
		if (pa[fromLocation].store[whichOne].hours1) {
			contentString += '<p style="margin:0px;">' + pa[fromLocation].store[whichOne].hours1 + '<\/p>';
			}
		if (pa[fromLocation].store[whichOne].hours2) {
			contentString += '<p style="margin:0px;">' + pa[fromLocation].store[whichOne].hours2 + '<\/p>';
			}
		if (pa[fromLocation].store[whichOne].hours3) {
			contentString += '<p style="margin:0px;">' + pa[fromLocation].store[whichOne].hours3 + '<\/p>';
			}
		if (pa[fromLocation].store[whichOne].hours4) {
			contentString += '<p style="margin:0px;">' + pa[fromLocation].store[whichOne].hours4 + '<\/p>';
			}
		if (pa[fromLocation].store[whichOne].storeinfophone) {
			contentString += '<p style="background-color:#006600;color:#ffffff;font-weight:bold;margin:0px;border-top:1px solid #006600;padding-left:2px;">Phone: ' + pa[fromLocation].store[whichOne].storeinfophone + '<\/p>';
			}
		else {
			contentString += '<p style="background-color:#006600;color:#ffffff;font-weight:bold;margin:0px;border-top:1px solid #006600;padding-left:2px;">Phone:&nbsp;<\/p>';
			}
		if (pa[fromLocation].store[whichOne].website) {
			if (pa[fromLocation].store[whichOne].tagline) {
				contentString += '<p style="margin:0px;border-top:1px solid #006600;"><a href="\/passThrough.php?url=http://' + pa[fromLocation].store[whichOne].website + '" target="_blank">' + pa[fromLocation].store[whichOne].tagline + '<\/a><\/p>';
			}
			else {
				contentString += '<p style="margin:0px;border-top:1px solid #006600;"><a href="\/passThrough.php?url=http://' + pa[fromLocation].store[whichOne].website + '" target="_blank">' + pa[fromLocation].store[whichOne].website + '<\/a><\/p>';
			}
		}
		else if (pa[fromLocation].store[whichOne].tagline) {
			contentString += '<p style="margin:0px;border-top:1px solid #006600;">' + pa[fromLocation].store[whichOne].tagline + '<\/p>';
			}
		}
	adjStHeight = parseInt(document.getElementById('hideStore').offsetHeight) + parseInt(document.getElementById('storeName').offsetHeight);
	document.getElementById('bstFiller').style.height = parseInt(pa[fromLocation].store['balloon'].contentheight) + 'px';
	document.getElementById('innerStore').style.height =  (parseInt(pa[fromLocation].store['balloon'].contentheight) - adjStHeight) + 'px';
	document.getElementById('bstFiller').style.width = parseInt(pa[fromLocation].store['balloon'].contentwidth) + 'px';
	document.getElementById('innerStore').style.width =  parseInt(pa[fromLocation].store['balloon'].contentwidth) + 'px';

	document.getElementById('innerStore').innerHTML = contentString;
	window.setTimeout("ieImageMoronity()", 200);
	setScrollForLayer('innerStore');
	}
function logAndShowStore(fromLocation,whichOne)
{
// first is there an iframe called 

	if (document.getElementById('trackStore'))
	{
        document.getElementById('trackStore').src = '/innerLogger.php?storelocationid=' + fromLocation + '&storeinfoid=' + whichOne;
	}
        showStore(fromLocation,whichOne);
}

function showStore(fromLocation,whichOne)
{
	currentLocation = fromLocation;
	currentStore = whichOne;
	if (document.getElementById('hints'))
	{
		document.getElementById('hints').style.display='none';
	}
	if (document.getElementById('sunsetFinley'))
	{
		document.getElementById('sunsetFinley').style.display='none';
	}
	if (!pa[fromLocation].store['balloon']) {
		// append the js, it will call actualSetPositions(fromLocation)
		scr = document.createElement('script');
		scr.src="http://www.nodds.org/js/getLocPosStInfo.php?nid=10010&slid=" + fromLocation + '&sid=' + whichOne;
		window.setTimeout("delayScriptAppend()", 2);
		}
	else {
		window.setTimeout("actualShowStore()", 200);
		}
}
function ieImageMoronity() {
	document.getElementById('innerStore').innerHTML = document.getElementById('innerStore').innerHTML;
	}
function showLongStore(whichOne,offsetCount) {
	// hideLocation();
	document.getElementById('longStore').className='longStore';
	document.getElementById('longStoreDescription').innerHTML='<p>' + storeLongDescription[whichOne].descriptionlong + '<\/p>';
	moveBalloonTo('longStore', leftOfSearchSection + 'px', (topOfSearchSection + (offsetCount * searchSectionOffset)) + 'px');
	}
function hideLongStore(fromLocation,whichOne) {
	if (df == null) {
		document.getElementById('longStore').className='hideItem';
		}
	}
function hideLocation() 
{
	highlightStore('');
	// no need to show the stores if the locations are hidden
	if (document.getElementById('hints'))
	{
		document.getElementById('hints').style.display='none';
	}
	if (document.getElementById('sunsetFinley'))
	{
		document.getElementById('sunsetFinley').style.display='none';
	}
	if (document.getElementById('stats') && document.getElementById('stats').className=='showBlock') 
	{
		document.getElementById('stats').className='hideItem';
		}
	if (document.getElementById('weatherBalloon') && document.getElementById('weatherBalloon').className=='showBlock') 
	{
		document.getElementById('weatherBalloon').className='hideItem';
	}
	if (df == null) 
	{
		hideStore();
		if (document.getElementById('blocContents'))
		{
			document.getElementById('blocContents').className='hideItem';
		}
		if (document.getElementById('bloc'))
		{
			document.getElementById('bloc').className='hideItem';
		}
	}
}
function hideStore() {
	highlightStore('');
	if (df == null) {
		document.getElementById('bstContents').className='hideItem';
		document.getElementById('bst').className='hideItem';
		}
	}
function moveBalloonTo(balloonId, posX, posY) {
	if (document.getElementById(balloonId)) {
		document.getElementById(balloonId).style.top=posY;
		document.getElementById(balloonId).style.left=posX;
		}
	}
function setScrollForLayer(layerID) {
	if (document.getElementById(layerID)) {
		document.getElementById(layerID).style.overflow = 'auto';
		var contentHeight = document.getElementById(layerID).offsetHeight;
		// get this from the class height - padding top and bottom...
		var spaceWeHave = 150;
		if (currentLocation != null) {
			if (layerID == 'innerLocation') {
				if (setFromForm == true) {
					spaceWeHave = parseInt(df.lcontentheight.value) - adjLocHeight;
					}
				else {
					spaceWeHave = parseInt(pa[currentLocation].location['balloon'].contentheight) - adjLocHeight;
					}
				}
			else if (layerID == 'innerStore') {
				if (setFromForm == true) {
					spaceWeHave = parseInt(df.scontentheight.value) - adjStHeight;
					}
				else {
					spaceWeHave = parseInt(pa[currentLocation].store['balloon'].contentheight) - adjStHeight;
					}
				}
			}
		if (contentHeight > spaceWeHave) {
			if(navigator.appName.indexOf("Netscape") != -1) {
				document.getElementById(layerID).style.overflow = '-moz-scrollbars-vertical';
				}
			document.getElementById(layerID).style.overflowX = 'hidden';
			document.getElementById(layerID).style.overflowY = 'scroll';
			}
		}
	}
function previewSettings() {
	setPositionsFromForm(false);
	}
function addToList() {
	pa[df.storelocationid.value].location['balloon'].edge = df.ledge[df.ledge.selectedIndex].value;
	pa[df.storelocationid.value].location['balloon'].direction = df.ldirection[df.ldirection.selectedIndex].value;
	pa[df.storelocationid.value].location['balloon'].alignment = df.lalignment[df.lalignment.selectedIndex].value;
	pa[df.storelocationid.value].location['balloon'].leftx = df.lleft.value;
	pa[df.storelocationid.value].location['balloon'].topx = df.ltop.value;
	pa[df.storelocationid.value].location['balloon'].columns = df.columns.value;
	pa[df.storelocationid.value].location['balloon'].contentheight = df.lcontentheight.value;
	pa[df.storelocationid.value].location['balloon'].contentwidth = df.lcontentwidth.value;
	
	pa[df.storelocationid.value].store['balloon'].edge = df.sedge[df.sedge.selectedIndex].value;
	pa[df.storelocationid.value].store['balloon'].direction = df.sdirection[df.sdirection.selectedIndex].value;
	pa[df.storelocationid.value].store['balloon'].alignment = df.salignment[df.salignment.selectedIndex].value;
	pa[df.storelocationid.value].store['balloon'].leftx = df.sleft.value;
	pa[df.storelocationid.value].store['balloon'].topx = df.stop.value;
	pa[df.storelocationid.value].store['balloon'].contentheight = df.scontentheight.value;
	pa[df.storelocationid.value].store['balloon'].contentwidth = df.scontentwidth.value;

	document.getElementById('list_' + df.storelocationid.value).style.backgroundColor='#EEFFEE';
	document.sendThis.jsContents.value = pa.toJSONString();
	}
function setDirectionAlignment(thisId, calledFor) {
	var tse = document.getElementById('sedge')
	var tsd = document.getElementById('sdirection')
	var tsa = document.getElementById('salignment')

	var tle = document.getElementById('ledge')
	var tld = document.getElementById('ldirection')
	var tla = document.getElementById('lalignment')
	
	var tsdVal = tsd[tsd.selectedIndex].value;
	var tsaVal = tsa[tsa.selectedIndex].value;
	var tldVal = tld[tld.selectedIndex].value;
	var tlaVal = tla[tla.selectedIndex].value;

	if (thisId == 'sedge') {
		// store
		if (tse[tse.selectedIndex].value == 't' || tse[tse.selectedIndex].value == 'b') {
			clearSelect(tsd);
			for(var x in topBottomDirection) {
				if (typeof(topBottomDirection[x]) != 'function') {
					addopt(tsd, x, topBottomDirection[x])
					if (calledFor == 'array' && x == pa[df.storelocationid.value].store['balloon'].direction) {
						tsd.selectedIndex = tsd.length - 1;
						}
					else if (x == tsdVal) {
						tsd.selectedIndex = tsd.length - 1;
						}
					}
				}
			clearSelect(tsa);
			for(var x in topBottomAlignment) {
				if (typeof(topBottomAlignment[x]) != 'function') {
					addopt(tsa, x, topBottomAlignment[x])
					if (calledFor == 'array' && x == pa[df.storelocationid.value].store['balloon'].alignment) {
						tsa.selectedIndex = tsa.length - 1;
						}
					else if (x == tsaVal) {
						tsa.selectedIndex = tsa.length - 1;
						}
					}
				}
			}
		else {
			clearSelect(tsd);
			for(var x in leftRightDirection) {
				if (typeof(leftRightDirection[x]) != 'function') {
					addopt(tsd, x, leftRightDirection[x])
					if (calledFor == 'array' && x == pa[df.storelocationid.value].store['balloon'].direction) {
						tsd.selectedIndex = tsd.length - 1;
						}
					else if (x == tsdVal) {
						tsd.selectedIndex = tsd.length - 1;
						}
					}
				}
			clearSelect(tsa);
			for(var x in leftRightAlignment) {
				if (typeof(leftRightAlignment[x]) != 'function') {
					addopt(tsa, x, leftRightAlignment[x])
					if (calledFor == 'array' && x == pa[df.storelocationid.value].store['balloon'].alignment) {
						tsa.selectedIndex = tsa.length - 1;
						}
					else if (x == tsaVal) {
						tsa.selectedIndex = tsa.length - 1;
						}
					}
				}
			}
		}
	else {
		// must be ledge -- location
		if (tle[tle.selectedIndex].value == 't' || tle[tle.selectedIndex].value == 'b') {
			clearSelect(tld);
			for(var x in topBottomDirection) {
				if (typeof(topBottomDirection[x]) != 'function') {
					addopt(tld, x, topBottomDirection[x])
					if (calledFor == 'array' && x == pa[df.storelocationid.value].store['balloon'].direction) {
						tld.selectedIndex = tld.length - 1;
						}
					else if (x == tldVal) {
						tld.selectedIndex = tld.length - 1;
						}
					}
				}
			clearSelect(tla);
			for(var x in topBottomAlignment) {
				if (typeof(topBottomAlignment[x]) != 'function') {
					addopt(tla, x, topBottomAlignment[x])
					if (calledFor == 'array' && x == pa[df.storelocationid.value].store['balloon'].alignment) {
						tla.selectedIndex = tla.length - 1;
						}
					else if (x == tlaVal) {
						tla.selectedIndex = tla.length - 1;
						}
					}
				}
			}
		else {
			clearSelect(tld);
			for(var x in leftRightDirection) {
				if (typeof(leftRightDirection[x]) != 'function') {
					addopt(tld, x, leftRightDirection[x])
					if (calledFor == 'array' && x == pa[df.storelocationid.value].store['balloon'].direction) {
						tld.selectedIndex = tld.length - 1;
						}
					else if (x == tldVal) {
						tld.selectedIndex = tld.length - 1;
						}
					}
				}
			clearSelect(tla);
			for(var x in leftRightAlignment) {
				if (typeof(leftRightAlignment[x]) != 'function') {
					addopt(tla, x, leftRightAlignment[x])
					if (calledFor == 'array' && x == pa[df.storelocationid.value].store['balloon'].alignment) {
						tla.selectedIndex = tla.length - 1;
						}
					else if (x == tlaVal) {
						tla.selectedIndex = tla.length - 1;
						}
					}
				}
			}
		}
	}   
function onDragStart(e) {
		if (!e) var e = window.event;
		var x = ((e.x)?e.x:e.pageX);
		var y = ((e.y)?e.y:e.pageY);
		var target = ((e.srcElement)?e.srcElement:e.target);
		if (document.onselectstart) { document.body.onselectstart = function() {return(false);}};
		// Mozilla
		document.body.onmousemove = onDragGo;
		document.body.onmouseup = onDragStop;

		target.beginX = target.offsetLeft;
		target.beginY = target.offsetTop;
		
		window.status = "beginX: "+target.beginX+" | beginY: "+target.beginY;
		
		target.startX = target.offsetLeft - x;
		target.startY = target.offsetTop -y;

		globals['activeTarget'] = target;
		setPositionsFromForm(false);
}

function onDragGo(e) {
		if (!e) var e = window.event;
		var target = globals['activeTarget']; //((e.srcElement)?e.srcElement:e.target);
		var x = ((e.x)?e.x:e.pageX);
		var y = ((e.y)?e.y:e.pageY);
		target.style.left = (x+target.startX)+"px";
		target.style.top = (y+target.startY)+"px";
		if (target.id == 'moveLocation') {
			df.lleft.value=x+target.startX;
			df.ltop.value=y+target.startY;
			}
		if (target.id == 'moveStore') {
			df.sleft.value=x+target.startX;
			df.stop.value=y+target.startY;
			}
		if (target.id == 'sizeLocation') {
			df.lcontentwidth.value=(x+target.startX) - parseInt(df.lleft.value);
			df.lcontentheight.value=(y+target.startY) - parseInt(df.ltop.value);
			}
		if (target.id == 'sizeStore') {
			df.scontentwidth.value=(x+target.startX) - parseInt(df.sleft.value);
			df.scontentheight.value=(y+target.startY) - parseInt(df.stop.value);
			}

		target.style.opacity = .5;
		target.style.filter = "progid:DXImageTransform.Microsoft.Alpha(opacity=50)";
		setPositionsFromForm(false);
	}

function onDragStop(e) {
	if (!e) var e = window.event;
	var target =  globals['activeTarget']; //((e.srcElement)?e.srcElement:e.target);
	// Mozilla
	document.body.onmousemove = null;
	document.body.onmouseup = null;
	target.style.opacity = 1;
	target.style.filter = "progid:DXImageTransform.Microsoft.Alpha(opacity=100)";
	globals['activeTarget'] = null;
	setPositionsFromForm(false);
	}
function makeInnerList(fromLocation) {
	var retval='<table border="0" cellpadding="0" cellspacing="0" style="width:100%;"><tr>';
	var tmpArray = {};
	var sortArray = new Array();
	var colCount = 0;
	var howManyColumns = 1;
	var oneStyle = 'border-top: 1px solid #EEEEEE;border-bottom: 1px solid #EEEEEE;background-color:#EEEEEE;';
	var anotherStyle = 'border-top: 1px solid #000000;border-bottom: 1px solid #000000;background-color:#FFFFFF;';
	var thisStyle = oneStyle;
	var basicColor = '';
	var i;
	var tA;
	var padding ='';
	var rightBorder='';
if (setFromForm == true) {
		howManyColumns = df.columns[df.columns.selectedIndex].value;
		}
	else {
		howManyColumns = pa[fromLocation].location['balloon'].columns;
		}
	if (pa[fromLocation].store) {
		tmpArray = pa[fromLocation].store;
		
		for (var x in tmpArray) {
			sortArray.push(''+tmpArray[x].storeinfoname+'-:|:-'+x);
		}
		sortArray.sort();
		for (var j=0;j<sortArray.length;j++) {
			tA = sortArray[j].split('-:|:-');
			i = tA[1];
			if (i != 'balloon' && typeof(tmpArray[i]) != 'function' && (tmpArray[i].storeinfoname != null && tmpArray[i].storeinfoname != 'null' && tmpArray[i].storeinfoname != '')) {
				colCount++;
				padding = 'padding-right:4px;';
				rightBorder = 'border-right:1px solid #CCCCCC;';
				if (colCount == 1 && howManyColumns != 1) {
					padding = 'padding-right:5px;';
					rightBorder = 'border-right:1px solid #CCCCCC;';
					}
				else if (colCount == howManyColumns) {
					padding = 'padding-right:2px;padding-left:3px;';
					rightBorder = '';
					}
				else {
					padding = 'padding-right:2px;padding-left:2px;';
					rightBorder = 'border-right:1px solid #CCCCCC;';
					}
				if (tmpArray[i].profileflag == 'f') {
					basicColor = '';
					if (tmpArray[i].basicflag == 't') {
							basicColor = ' class="redBold"';
							}
					retval += '<td valign="top" style="' + padding + rightBorder + thisStyle + '"><a href="javascript:;" id="launch_' + i + '" onClick="logAndShowStore(\'' + fromLocation + '\',\'' +  i + '\');" style="display:block;margin:0px;width:100%;"' + basicColor + '>' + tmpArray[i].storeinfoname + '<\/a><\/td>';
					}
				else {
					retval += '<td valign="top" style="' + padding + rightBorder + thisStyle + '"><a href="/profile.php?storeinfoid=' + i + '" style="display:block;margin:0px;width:100%;" class="redBold">' + tmpArray[i].storeinfoname + '<img src="/images/icons/NN-P.gif" border="0" align="absmiddle" style="margin-left:3px;"><\/a><\/td>';
					}
				if (colCount == howManyColumns) {
					retval += '<\/tr><tr>';
					colCount = 0;
					if (thisStyle == oneStyle) {
						thisStyle = anotherStyle;
						}
					else {
						thisStyle = oneStyle;
						}
					}
				}
			}
		while (colCount != 0 && colCount < howManyColumns) {
			retval += '<td style="' + thisStyle + '">&nbsp;<\/td>';
			colCount++;
			}
		}
	retval += '<\/tr><\/table>';
	return retval;
	}
function unSetAllTails(balloonId, whichStyle) {
	// set the edge and the arrow
	var thisEdge = '';
	var thisArrow = '';
	var thisEdgeImage = '';
	var thisArrowImage = '';
	
	thisEdge = balloonId + 'te';
	thisArrow = balloonId + 'ta';
	thisEdgeImage = '/balloons/' + whichStyle + '/te.gif';
	thisArrowImage = '/balloons/' + whichStyle + '/ta.gif';
	if (document.getElementById(thisEdge)) {
		document.getElementById(thisEdge).src=thisEdgeImage;
		}
	if (document.getElementById(thisArrow)) {
		document.getElementById(thisArrow).src=thisArrowImage;
		}
	thisEdge = balloonId + 're';
	thisArrow = balloonId + 'ra';
	thisEdgeImage = '/balloons/' + whichStyle + '/re.gif';
	thisArrowImage = '/balloons/' + whichStyle + '/ra.gif';
	if (document.getElementById(thisEdge)) {
		document.getElementById(thisEdge).src=thisEdgeImage;
		}
	if (document.getElementById(thisArrow)) {
		document.getElementById(thisArrow).src=thisArrowImage;
		}
	thisEdge = balloonId + 'be';
	thisArrow = balloonId + 'ba';
	thisEdgeImage = '/balloons/' + whichStyle + '/be.gif';
	thisArrowImage = '/balloons/' + whichStyle + '/ba.gif';
	if (document.getElementById(thisEdge)) {
		document.getElementById(thisEdge).src=thisEdgeImage;
		}
	if (document.getElementById(thisArrow)) {
		document.getElementById(thisArrow).src=thisArrowImage;
		}
	thisEdge = balloonId + 'le';
	thisArrow = balloonId + 'la';
	thisEdgeImage = '/balloons/' + whichStyle + '/le.gif';
	thisArrowImage = '/balloons/' + whichStyle + '/la.gif';
	if (document.getElementById(thisEdge)) {
		document.getElementById(thisEdge).src=thisEdgeImage;
		}
	if (document.getElementById(thisArrow)) {
		document.getElementById(thisArrow).src=thisArrowImage;
		}
	}
function setTail(balloonId, whichOne, whichWay, whereAt, whichStyle) {
	// set the edge and the arrow
	var thisEdge = '';
	var thisArrow = '';
	var thisEdgeImage = '';
	var thisArrowImage = '';
	unSetAllTails(balloonId,whichStyle);
	thisEdge = balloonId + whichOne + 'e';
	thisArrow = balloonId + whichOne + 'a';
	thisEdgeImage = '/balloons/' + whichStyle + '/' + whichOne + 'e' + whichWay + '.gif';
	thisArrowImage = '/balloons/' + whichStyle + '/' + whichOne + 'a' + whichWay + '.gif';

	if (document.getElementById(thisEdge)) {
		document.getElementById(thisEdge).src=thisEdgeImage;
		}
	if (document.getElementById(thisArrow)) {
		document.getElementById(thisArrow).src=thisArrowImage;
		}
	if (whichOne == 't' || whichOne == 'b') {
		if (whereAt == 'l') {
			document.getElementById(thisEdge).parentNode.style.textAlign = 'left';
			document.getElementById(thisArrow).parentNode.style.textAlign = 'left';
			}
		else if (whereAt == 'r') {
			document.getElementById(thisEdge).parentNode.style.textAlign = 'right';
			document.getElementById(thisArrow).parentNode.style.textAlign = 'right';
			}
		else if (whereAt == 'c') {
			document.getElementById(thisEdge).parentNode.style.textAlign = 'center';
			document.getElementById(thisArrow).parentNode.style.textAlign = 'center';
			}
		}
	else if (whichOne == 'l' || whichOne == 'r') {
		if (whereAt == 't') {
			document.getElementById(thisEdge).parentNode.style.verticalAlign = 'top';
			document.getElementById(thisArrow).parentNode.style.verticalAlign = 'top';
			}
		else if (whereAt == 'b') {
			document.getElementById(thisEdge).parentNode.style.verticalAlign = 'bottom';
			document.getElementById(thisArrow).parentNode.style.verticalAlign = 'bottom';
			}
		else if (whereAt == 'm') {
			document.getElementById(thisEdge).parentNode.style.verticalAlign = 'middle';
			document.getElementById(thisArrow).parentNode.style.verticalAlign = 'middle';
			}
		}
	}
function showName(whichOne) {
	document.getElementById('transMap').style.cursor='pointer';
	// document.getElementById('nameBalloon').innerHTML = whichOne + ' ' + pa[whichOne].location['name1'];
	document.getElementById('nameBalloon').innerHTML = pa[whichOne].location['name1'];
	document.getElementById('nameBalloon').style.visibility = 'visible';
	if (navigator.appName.indexOf("Netscape") != -1) {
		// Firefox is well behaved
		document.getElementById('nameBalloon').style.top = (myMouse.Y - 10) + 'px';
		document.getElementById('nameBalloon').style.left = (myMouse.X + 20) + 'px';
		}
	else if (navigator.appName.indexOf("Opera") != -1) {
		// Opera is well behaved
		document.getElementById('nameBalloon').style.top = (myMouse.Y - 10) + 'px';
		document.getElementById('nameBalloon').style.left = (myMouse.X + 20) + 'px';
		}
	else if (/MSIE [789]/.test(navigator.userAgent) && navigator.platform == "Win32") {
		// And IE is well behaved now too
		document.getElementById('nameBalloon').style.top = (myMouse.Y - 10) + 'px';
		document.getElementById('nameBalloon').style.left = (myMouse.X + 20) + 'px';
		}
	else if (document.all) {
		if (window.event.srcElement.parentNode.parentNode.parentNode) {
			document.getElementById('nameBalloon').style.top = ((myMouse.Y - 10) + window.event.srcElement.parentNode.parentNode.parentNode.offsetTop) + 'px';
			document.getElementById('nameBalloon').style.left = ((myMouse.X + 20) + window.event.srcElement.parentNode.parentNode.parentNode.offsetLeft) + 'px';
			}
		}
	}
function showText(thisText) {
	var defText = "Click To View Profile";
	if (thisText && thisText != '') {
		defText = thisText;
		}
	document.getElementById('transMap').style.cursor='pointer';
	// document.getElementById('nameBalloon').innerHTML = whichOne + ' ' + pa[whichOne].location['name1'];
	document.getElementById('nameBalloon').innerHTML = defText;
	document.getElementById('nameBalloon').style.visibility = 'visible';
	if (navigator.appName.indexOf("Netscape") != -1) {
		// Firefox is well behaved
		document.getElementById('nameBalloon').style.top = (myMouse.Y - 10) + 'px';
		document.getElementById('nameBalloon').style.left = (myMouse.X + 20) + 'px';
		}
	else if (document.all) {
		if (window.event.srcElement.parentNode.parentNode.parentNode) {
			document.getElementById('nameBalloon').style.top = ((myMouse.Y - 10) + window.event.srcElement.parentNode.parentNode.parentNode.offsetTop) + 'px';
			document.getElementById('nameBalloon').style.left = ((myMouse.X + 20) + window.event.srcElement.parentNode.parentNode.parentNode.offsetLeft) + 'px';
			}
		}
	}
function hideName() {
	document.getElementById('nameBalloon').style.visibility = 'hidden';
	}

function getDefaultOffsets() {
	if (df == null) {
		document.getElementById('bloc').className = 'snagSize';
		document.getElementById('bst').className = 'snagSize';
		}
	bsofftop = parseInt(document.getElementById('bsttrc').height);
	bsoffleft = parseInt(document.getElementById('bsttrc').width);
	
	blofftop = parseInt(document.getElementById('bloctrc').height);
	bloffleft = parseInt(document.getElementById('bloctrc').width);
	if (bsofftop > 0) {
		bsdeftop = bsofftop;
		}
	if (bsoffleft > 0) {
		bsdefleft = bsoffleft;
		}
	if (blofftop > 0) {
		bldeftop = blofftop;
		}
	if (bloffleft > 0) {
		bldefleft = bloffleft;
		}
	if (df == null) {
		document.getElementById('bloc').className = 'hideItem';
		document.getElementById('bst').className = 'hideItem';
		}
	if (showOne!=null) {
		setPositions(showOne);
		}
	/*
	if (showStore!=null) {
		showStore(showThisStore);
		}
	*/
	document.getElementById('blocContents').style.width = '1px';
	}

function setPositionsFromForm(calledBySelf) {	
	setFromForm=true;
	
	// showLocation(df.storelocationid.value);
	// showStore(df.storelocationid.value);
	
	setTail('bloc', df.ledge[df.ledge.selectedIndex].value, df.ldirection[df.ldirection.selectedIndex].value, df.lalignment[df.lalignment.selectedIndex].value, 'redline');
	setTail('bst', df.sedge[df.sedge.selectedIndex].value, df.sdirection[df.sdirection.selectedIndex].value, df.salignment[df.salignment.selectedIndex].value, 'redline');
	moveBalloonTo('bloc', df.lleft.value + 'px', df.ltop.value + 'px');
	moveBalloonTo('bst', df.sleft.value + 'px', df.stop.value + 'px');
	setDirectionAlignment('sedge');
	setDirectionAlignment('ledge');
	
	setStoreOffset(df.storelocationid.value);
	setLocationOffset(df.storelocationid.value);
	adjStHeight = parseInt(document.getElementById('hideStore').offsetHeight) + parseInt(document.getElementById('storeName').offsetHeight);
	document.getElementById('bstFiller').style.height = df.scontentheight.value + 'px';
	document.getElementById('innerStore').style.height =  (parseInt(df.scontentheight.value) - adjStHeight) + 'px';
	document.getElementById('bstFiller').style.width = df.scontentwidth.value + 'px';
	document.getElementById('innerStore').style.width =  df.scontentwidth.value + 'px';
	
	adjLocHeight = parseInt(document.getElementById('hideLocation').offsetHeight) + parseInt(document.getElementById('locationName').offsetHeight) + parseInt(document.getElementById('locFooter').offsetHeight) + parseInt(document.getElementById('locFooterCel').offsetHeight) - trimLocHeight;
	document.getElementById('blocFiller').style.height = df.lcontentheight.value+ 'px';
	document.getElementById('innerLocation').style.height = (parseInt(df.lcontentheight.value) - adjLocHeight) + 'px';
	document.getElementById('blocFiller').style.width = df.lcontentwidth.value + 'px';
	document.getElementById('innerLocation').style.width = df.lcontentwidth.value + 'px';
	
	moveBalloonTo('blocContents', (parseInt(df.lleft.value) + parseInt(bloffleft)) + 'px', (parseInt(df.ltop.value) + parseInt(blofftop)) + 'px');
	moveBalloonTo('bstContents', (parseInt(df.sleft.value) + parseInt(bsoffleft)) + 'px', (parseInt(df.stop.value) + parseInt(bsofftop)) + 'px');
	
	if (globals['activeTarget'] && globals['activeTarget'].id == 'moveLocation') {
		moveBalloonTo('sizeLocation', (parseInt(df.lleft.value) + parseInt(blsizeoffleft)) + 'px', (parseInt(df.ltop.value) + parseInt(blsizeofftop)) + 'px');
		}
	
	if (globals['activeTarget'] && globals['activeTarget'].id == 'moveStore') {
		moveBalloonTo('sizeStore', (parseInt(df.sleft.value) + parseInt(bssizeoffleft)) + 'px', (parseInt(df.stop.value) + parseInt(bssizeofftop)) + 'px');		
		}
	
	setScrollForLayer('innerLocation');
	setScrollForLayer('innerStore');
	setFromForm=false;
	if(calledBySelf == false) {
		setPositionsFromForm(true)
		}
	}
