//
//	COPYRIGHT NOTICE:
// 	Copyright 2002 - 2006 Barry Saxifrage. Stonebreaker Designs. All Rights Reserved.
//	By using this code you agree to indemnify Barry Saxifrage and Stonebreaker Designs 
//	from any liability that might arise from its use. Selling this code or distributing 
//	this code without prior written consent is expressly forbidden. Copyright notice  
//	must remain with this code. For more information: www.stonebreakerdesigns.com	
//

	
		function map_showXInfo(idClickedPin,xShow,yShow,iPin, idTopic, nStatusShow) {
			for (var i = 0; i < aMapXs.length - 1; i++ ){
				var aX = aMapXs[i].split('|');
				var idX 	 		= aX[0];
				if (idX != idClickedPin) { continue; }
				var strPinType 		= aX[2];
				var strAuthor 		= aX[5];
				var strTitle	  	= aX[6];
				var strText  		= aX[7];
				var urlPhoto	 	= aX[8];
				var strEmail	 	= aX[9];
				var urlWebsite	 	= aX[10];
				var strDate			= aX[11];
				var nModifiedDays	= aX[12];
				strText = shortenText(strText,300);
				
				// create info box html
				var str = '';
					// x
					str += '<div id="xi_pop_x"><a href="javascript:map_hideXInfo();"><img src="bits/x.gif" width="9" height="9" alt="" border="0"></a></div>';
					// title
					str += '<div class="mx_pintype">'+strPinType+'</div>';
					str += '<div class="mx_title"><a class="mx_title" href="javascript:showBigMapX('+idTopic+',\''+ idX +'\')">';
						str += strTitle;
						if (nModifiedDays <= gnModifiedDaysNew ) { str += '<img src="bits/updated2.gif" width="11" height="11" alt="New or Updated" title="New or Updated" border="0">'; }
					str += '</a></div>';
					// pix
					if (urlPhoto != '') {
						str += '<div class="mx_pix">';
							str += '<a href="javascript:showBigMapX('+idTopic+','+idX+')" alt="view full size...">';
							str += '<img src="maps/x_'+idX+'/thumb_'+urlPhoto+'" alt="Click to view full size..."  title="Click to view full size..." border="1">';
							str += '</a>';
						str += '</div>';
					}
					// text
					str += '<div class="mx_text">';
						str += makeURLsHot(strText);
					str += '</div>';
					// ftr
					str += '<div class="mx_ftr_area">';
						var fShowDivider = false;
						// f. byline
						str += '<span class="mx_ftr">by '+strAuthor+'</span>';
						fShowDivider = true;
						// f. email
						if (strEmail != "") {
							if (fShowDivider) { str += getFooterDivider(); }
							str += '<a class="mx_ftr" href="' + createMailString(strEmail) + '">email</a>';
							fShowDivider = true;
						}
						if (nStatusShow >= 0) {
							// f. show big 
							// if (urlPhoto != '') {
							//if (fShowDivider) { str += getFooterDivider(); }
							str += '<br><a class="mx_ftr" href="javascript:showBigMapX('+idTopic+',\''+ idX +'\')">view big</a>';
							fShowDivider = true;
							//}
						}
						// f. website
						if (urlWebsite != "") {
							if (fShowDivider) { str += getFooterDivider(); }
							str += '<a class="mx_ftr" ';
							str += getWebsiteHref(urlWebsite);
							str += '>website</a>';
							fShowDivider = true;
						}
						if (fCanPost && (nStatusShow >= 0)) {
							// move
							if (fShowDivider) { str += getFooterDivider(); }
							str += '<a class="mx_ftr" href="javascript:moveMapX('+ idX + ')">move pin</a>';
							fShowDivider = true;

							// edit
							if (fShowDivider) { str += getFooterDivider(); }
							str += '<a class="mx_ftr" href="javascript:editMapX('+ idX + ')">edit</a>';
							fShowDivider = true;

							// delete
							if (fShowDivider) { str += getFooterDivider(); }
							str += '<a class="mx_ftr" href="javascript:deleteMapX('+ idX + ')">del</a>';
							fShowDivider = true;
						}
						if (fCanPost && (nStatusShow < 0)) {
							// undelete
							if (fShowDivider) { str += getFooterDivider(); }
							str += '<a class="mx_ftr" href="javascript:undeleteMapX('+ idX + ')">undelete</a>';
							fShowDivider = true;
						
						}
					str += '</div>';
				
				// CLEAN UP OLD STUFF
				if (giCurPin >= 0) {
					// show old label
					if (fShowLabel) {
						var domLOld = getDOM('label'+giCurPin,1);
						domLOld.visibility = 'visible';
					}
					// lower old pin
					if (gzCurPin >= 300) {
						var domPOld = getDOM('pin'+giCurPin,1);
						domPOld.zIndex = 300+giCurPin;
					}
				}
				
				// SET UP NEW STUFF
				giCurPin = iPin;
				if (fShowLabel) {
					// hide new label
					var domL = getDOM('label'+iPin,1);
					domL.visibility = 'hidden';
				}
				// raise new pin
				var domPin = getDOM('pin'+iPin,1);
				gzCurPin = domPin.zIndex;
				domPin.zIndex = 602;
				
				// decide if showing on left or right side of pin
				var fOnRight = true;
				if (xShow >= 400) { fOnRight = false; }
				
				// show info
				var dom1 	  = getDOM('xi_pop_inner',0);
				var dom2Style  = getDOM('xi_pop',1);
				var dom3 	  = getDOM('xi_pop_stem',0);
				var dom3Style = getDOM('xi_pop_stem',1);
				xShow = xShow - 10;
				var xPop = xShow + 19;
				var yPop = yShow - 10;
				if (xShow > 400) {
					xPop = xShow - 190;
					dom3.src = 'maps/xi_stem2.gif';
				} else {
					dom3.src = 'maps/xi_stem.gif';
				}
				dom1.innerHTML = str;
				dom2Style.top 	= yPop+'px';
				dom2Style.left 	= xPop+'px';
				dom2Style.zIndex = 600;
				dom3Style.top 	= yPop+'px';
				dom3Style.left 	= xShow+'px';
				dom3Style.zIndex = 601;
				dom3Style.visibility = 'visible';
				dom2Style.visibility = 'visible';
			}
		}
		function map_hideXInfo() {
			// hide info
			var domStyle = getDOM('xi_pop',1);
			domStyle.visibility = 'hidden';		
			var domStyle2 = getDOM('xi_pop_stem',1);
			domStyle2.visibility = 'hidden';		
			// lower pin
			if (gzCurPin >= 300) {
				var domPOld = getDOM('pin'+giCurPin,1);
				domPOld.zIndex = 300+giCurPin;
				gzCurPin = -1;
			}
			// show label
			if (fShowLabel && giCurPin >= 0) {
				var domL = getDOM('label'+giCurPin,1);
				domL.visibility = 'visible';
				giCurPin = -1;
			}

		}
		function map_upLabel(i) {
			var domS = getDOM('label'+i,1);
			domS.zIndex = 500;		
		}
		function map_downLabel(i) {
			var zD = parseInt(i) + 0;
			var domS = getDOM('label'+i,1);
			domS.zIndex = zD;		
		}
		
		function addMapX(idMap, idPin) {
			var strCGI = "dlg_mapx_new1.cgi?ID="+idMap+"&PIN="+idPin;
			showDialogCGI("NewMapX",590,720,strCGI);
		}
		function moveMapX(idMapX) {
			var strCGI = "dlg_mapx_move.cgi?ID="+idMapX;
			showDialogCGI("MoveMapX",590,720,strCGI);
		}
		// editMapX moved to all.js so can be called from review board
		function deleteMapX(idMapX) {
			var strCGI = "dlg_mapx_del.cgi?ID="+idMapX;
			showDialogCGI("DelMapX",590,300,strCGI);
		}
		function undeleteMapX(id) {
			var fOK = confirm('Are you sure you want to UNDELETE this? Readers will be able to see it.');
			if (fOK) {
				var strCGI = "submit_mapx_undel.cgi?ID="+id;
				showDialogCGI("UndeleteItem",590,300,strCGI);
			}
		}
		function showMapPinWorkshop() {
			location = gCGIPath + 'show_mappin_workshop.cgi';
		}
		function addMapPin(idPinType) {
			var strCGI = "dlg_mappin_new.cgi?TYPE="+idPinType;
			showDialogCGI("NewMapPin",590,670,strCGI);
		}
		function editMapPinInfo(idPin) {
			var strCGI = "dlg_mappin_editinfo.cgi?ID="+idPin;
			showDialogCGI("EditMapPin",590,400,strCGI);
		}
		function editMapPinImage(idPin) {
			var strCGI = "dlg_mappin_editimage.cgi?ID="+idPin;
			showDialogCGI("EditMapPin",590,670,strCGI);
		}
		function delMapPin(idPin) {
			var	fOK = confirm('This map pin will be removed permanently. Continue?');
			if (fOK) {
				var strCGI = "submit_mappin_del.cgi?ID="+idPin;
				showDialogCGI("DelMapPin",590,300,strCGI);
			}
		}
		function addMapPinType() {
			var strCGI = "dlg_mappintype_new.cgi";
			showDialogCGI("NewMapPinType",590,300,strCGI);
		}
		function editMapPinType(idPinType) {
			var strCGI = "dlg_mappintype_edit.cgi?ID="+idPinType;
			showDialogCGI("EditMapPinType",590,300,strCGI);
		}
		function delMapPinType(idPinType) {
			var	fOK = confirm('This map pin category will be removed permanently. Continue?');
			if (fOK) {
				var strCGI = "submit_mappintype_del.cgi?ID="+idPinType;
				showDialogCGI("DelMapPinType",590,300,strCGI);
			}
		}
		function addMap(idTopic) {
			var strCGI = "dlg_map_new.cgi?TOPIC="+idTopic;
			showDialogCGI("NewMap",590,620,strCGI);
		}
		function editMap(idMap) {
			var strCGI = "dlg_map_edit.cgi?ID="+idMap;
			showDialogCGI("EditMap",590,620,strCGI);
		}
		function deleteMap(idMap) {
			var strCGI = "dlg_map_del.cgi?ID="+idMap;
			showDialogCGI("DeleteMap",590,350,strCGI);
		}
		function undeleteMap(id) {
			var fOK = confirm('Are you sure you want to UNDELETE this? Readers will be able to see it.');
			if (fOK) {
				var strCGI = "submit_map_undel.cgi?ID="+id;
				showDialogCGI("UndeleteItem",590,300,strCGI);
			}
		}
		function hideMap(idMap) {
			var strCGI = "dlg_map_hide.cgi?ID="+idMap;
			showDialogCGI("HideMap",590,350,strCGI);
		}
		function setMapStatus(idMap, nStatus) {
			var strA = "CLOSE MAP: Readers will be able to see this map, but will NOT be able to add or change items on it. Editors always can. Continue?";
			if (nStatus == 2) { strA = 'OPEN MAP: Readers will be to see this map, and WILL be able to add or change items on it. Continue?'; }
			var	fOK = confirm(strA);
			if (fOK) {
				var strCGI = "submit_map_restore.cgi?ID="+idMap+"&S="+nStatus;
				showDialogCGI("SetMapStatus",590,300,strCGI);
			}
		}
		function showMapOnFP(idMap, fShow, fIsGeneral, nCurStatus) {
			var strA = '';
			if ((!fIsGeneral) && fShow) {
				strA = "NOTE: Before a map can appear on the frontpage, it must be assigned to the main frontpage section. This map is not. You can change this using the 'edit map' command."
				alert(strA);
			} 
			else if ((nCurStatus <= 0) && fShow) {
				strA = "NOTE: This map is hidden. Hidden maps can NOT appear on the frontpage. You need to first unhide this map using the 'unhide...' command."
				alert(strA);
			} 
			else {
				strA = "SHOW ON FRONTPAGE: This map will be marked for display on the frontpage. You must also make sure the Map Preferences are set to show maps on the frontpage. Continue?";
				if (fShow == 0) { strA = 'REMOVE FROM FRONTPAGE: This map will no longer appear on the frontpage. Continue?'; }
				var	fOK = confirm(strA);
				if (fOK) {
					var strCGI = "submit_map_onfp.cgi?ID="+idMap+"&S="+fShow;
					showDialogCGI("SetMapOnFP",590,300,strCGI);
				}
			}
		}
		function editMapFilter(idMap) {
			var strCGI = "dlg_mapfilter_edit.cgi?ID="+idMap;
			showDialogCGI("EditMapFilter",590,400,strCGI);
		}
		function moveMap(id,n) {
			var strCGI = "submit_map_move.cgi?ID="+id+"&N="+n;
			showDialogCGI("MoveMap",590,300,strCGI);
		}
		function arrangeMaps() {
			var strCGI = "dlg_map_arrange.cgi?";
			showDialogCGI("ArrangeMaps",590,500,strCGI);
		}

		
		
