var max_ta_poi = '500';
var icons = 'http://mapping.redata.com/mapping_v2006/jsps/COMMON/images/poi/';

function buildTAPoiWhere() {
	
	var w = "";
	var list = "";

	if (document.getElementById('TA_POI_A')) {
		if (document.getElementById('TA_POI_A').checked) {
			list = "icon = 'transportation'";
		}
	}

	if (document.getElementById('TA_POI_B')) {
		if (document.getElementById('TA_POI_B').checked) {
			list += (list.length > 0 ? " OR " : "") + "icon = 'groceries'"; 
		}
	}

	if (document.getElementById('TA_POI_C')) {
		if (document.getElementById('TA_POI_C').checked) {
			list += (list.length > 0 ? " OR " : "") + "icon = 'restaurants'";
		}
	}

	if (document.getElementById('TA_POI_D')) {
		if (document.getElementById('TA_POI_D').checked) {
			list += (list.length > 0 ? " OR " : "") + "icon = 'recreation'";
		}
	}
	if (document.getElementById('TA_POI_E')) {
		if (document.getElementById('TA_POI_E').checked) {
			list += (list.length > 0 ? " OR " : "") + "icon = 'retail'";
		}
	}

	if (document.getElementById('TA_POI_F')) {
		if (document.getElementById('TA_POI_F').checked) {
			list += (list.length > 0 ? " OR " : "") + "icon = 'education'";
		}
	}

	if (document.getElementById('TA_POI_G')) {
		if (document.getElementById('TA_POI_G').checked) {
			list += (list.length > 0 ? " OR " : "") + "icon = 'worship'";
		}
	}
	
	if (document.getElementById('TA_POI_H')) {
		if (document.getElementById('TA_POI_H').checked) {
			list += (list.length > 0 ? " OR " : "") + "icon = 'health'";
		}
	}

	if (document.getElementById('TA_POI_I')) {
		if (document.getElementById('TA_POI_I').checked) {
			list += (list.length > 0 ? " OR " : "") + "icon = 'daycare'";
		}
	}

	if (document.getElementById('TA_POI_J')) {
		if (document.getElementById('TA_POI_J').checked) {
			list += (list.length > 0 ? " OR " : "") + "icon = 'municipal'";
		}
	}

	if (document.getElementById('TA_POI_K')) {
		if (document.getElementById('TA_POI_K').checked) {
			list += (list.length > 0 ? " OR " : "") + "icon = 'financial'";
		}
	}

	if (document.getElementById('TA_POI_L')) {
		if (document.getElementById('TA_POI_L').checked) {
			list += (list.length > 0 ? " OR " : "") + "icon = 'services'";
		}
	}

	if (list.length > 0) {
		w = "(" + list + ")";
	}

	if (document.getElementById('full_text')) {
		if (document.getElementById('full_text').value.length > 0) {
			var text = document.getElementById('full_text').value.replace("'", "''");
        	        if (text.indexOf('"') > -1) {
                	        w = " MATCH(STD_NAME,SIC_DESC1) AGAINST ('" + text + "' IN BOOLEAN MODE)";
	                } else {
        	                w = " MATCH(STD_NAME,SIC_DESC1) AGAINST ('\"" + text + "\"' IN BOOLEAN MODE)";
                	}
        	}
	}

	return w;
}

function processTAPois(props)
{
	
	for (var i = 0; i < props.length; i++) {
		var x = parseInt(props[i].getAttribute('x'));
		var y = parseInt(props[i].getAttribute('y'));
	
                var x1 = x;
                var y1 = y;

                var icon_type = "";

                if (x > (width / 2)) {
                        if (y > (height / 2)) {
                                icon_type = "BR";
                                x = x - icon_w;
                                y = y - icon_h;
                        } else {
                                icon_type = "TR";
                                x = x - icon_w + 6;
                                y = y + 4;
                        }
                } else {
                        if (y > (height / 2)) {
                                icon_type = "BL";
                                y = y - icon_h;
                                x = x + 5;
                        } else {
                                icon_type = "TL";
                                x = x + 5;
                                y = y + 3;
                        }
                }

		var myDiv = document.createElement('DIV');
		myDiv.id = "TA_POI_" + i;
		myDiv.style.position='absolute';
		myDiv.style.visibility='hidden';
		myDiv.style.left =x + 'px';
		myDiv.style.top = y + 'px';
		myDiv.style.width = icon_w + 'px';
		myDiv.style.height= icon_h + 'px';
		myDiv.style.zIndex=2;

                var balloon = '<div class="balloon_' + icon_type + '">';
                balloon += '<div class="inner_balloon_ta_poi">';
                balloon += '<div class="close_icon"><a href="javascript:hideAll();"><img border="0" src="images/close_icon.gif" style="width:17px;"></a></div>';
                

		balloon += '<br><table width="150"><tr>';
		balloon += '<td><span class="ta_poi_small">';

		balloon += '<b>' + cleanString(props[i].getAttribute('STD_NAME')) + '</b>';
	
		balloon += '<br><br>' + cleanString(props[i].getAttribute('PHONE'));
		balloon += '<br>' + cleanString(props[i].getAttribute('HOUSE_NUMBER')) + ' ' + cleanString(props[i].getAttribute('STREET'));
		balloon += '<br>' + cleanString(props[i].getAttribute('CITY')) + ' ' + cleanString(props[i].getAttribute('STATE_ABBR')) + ' ' + cleanString(props[i].getAttribute('ZIP'));
		balloon += '<br><br>' + cleanString(props[i].getAttribute('SIC_DESC1'));


		balloon += '<br><br><a target="_blank" href="http://www.bing.com/search?q=' + cleanString(props[i].getAttribute("STD_NAME")) + ' ' + cleanString(props[i].getAttribute("ZIP")) + '&go=&form=QBLH&qs=n"><img src="' + icons + 'bing.png" style="width:20px;border:0px"></a> <a target="_blank" href="http://clusty.com/search?input-form=clusty-simple&v%3Asources=webplus&query=' + cleanString(props[i].getAttribute("STD_NAME")) + ' ' + cleanString(props[i].getAttribute("ZIP")) + '"><img src="' + icons + 'clusty.png" style="width:20px;border:0"></a> <a target="_blank" href="http://www.google.com/#hl=en&source=hp&q=' + cleanString(props[i].getAttribute("STD_NAME")) + ' ' + cleanString(props[i].getAttribute("ZIP")) + '"><img src="' + icons + 'google.png" style="width:20px;border:0"></a> <a target="_blank" href="http://search.yahoo.com/search?p=' + cleanString(props[i].getAttribute("STD_NAME")) + ' ' + cleanString(props[i].getAttribute("ZIP")) + '"><img src="' + icons + 'yahoo.png" style="width:20px;border:0"></a>';
 
		if (props[i].getAttribute('icon') == 'restaurants') {
		balloon += '<a target="_blank" href="http://www.yelp.com/search?find_desc=' + cleanString(props[i].getAttribute("STD_NAME")) + '&ns=1&find_loc=' + cleanString(props[i].getAttribute("ZIP")) + '"><img src="' + icons + 'yelp.png" style="width:20px;border:0"></a>';
		}
	
		balloon += '</span></td></tr></table>';
 
		balloon += '</div>';
                balloon += '</div>';

                myDiv.innerHTML = balloon;

		mapContainer.appendChild(myDiv);
	
		var area = document.createElement('DIV');
		area.id = i;
	
  		if (props.length < 100) {
			area.innerHTML = '<img src="' + icons + props[i].getAttribute("icon") + '.png" width="20" border="0">';
		} else {
			
			area.innerHTML = '<img src="' + icons + props[i].getAttribute("icon") + '.png" width="15" border="0">';
		}

		area.style.left=x1 + 'px';
		area.style.top=y1 + 'px';
		area.style.position='absolute';
		area.style.zIndex=1;
		area.onmouseover = function() {
			if (!dragging) {
				hideAll();
        	                document.getElementById('TA_POI_' + this.id).style.visibility = 'visible';
                	        open_div = document.getElementById('TA_POI_' + this.id);
                        	document.onmousemove = checkPosition;
			}
		}

		mapContainer.appendChild(area);
	
	}
}


