// JavaScript Document

	//********************************************
	//* General Map Functions Start
	//********************************************
	function getId(theID){
		return document.getElementById(theID);
	}
	
	
	
	function initializeMap() {
//return;
		//Load up the HierMenus since our onLoad event seems to override theirs
		setTimeout("HM_f_FrameLoad()",10);
		
		populatePhoneCarriers(getId("fldCarrier"))
		
  	  if (GBrowserIsCompatible()) {
	  	//Set up the map
		var mapDiv = getId("masterMap");
        map = new GMap2(mapDiv, {size:new GSize(549,480)}); // {size:new GSize(920,270)});
		map.addControl(new GLargeMapControl()); //zoom level
		map.addControl(new GMapTypeControl()); //Street, satellite
		/*
		map.enableScrollWheelZoom();
		GEvent.addDomListener(mapDiv, "DOMMouseScroll", wheelevent); 
		mapDiv.onmousewheel = wheelevent; 
		*/
		map.setCenter(new GLatLng(visCenterLat, visCenterLng), 12);
		/* I've opted not to use the mgr due to lack of remove functionality for events
		var mgrOptions = { borderPadding: 1, maxZoom: 17, trackMarkers: false };
		mgr = new MarkerManager(map, mgrOptions);
		GEvent.addListener(mgr, "changed", function() {
			//Track marger manager events so we can
			//loop through our makers and make sure we don't display any that are supposed to be hidden								
			hideHiddenMarkers();
		});*/


		//If member specified, get the member info and display the marker
		if (inMemberID > 0){
		
			addPointToMarkerList(inMemLat, inMemLng, inMemTitle, arrAllPins, "member", inMemType, inMemberID, "", "", "", "", "", "", "", "", "")
			addMarkerGroupToMap(arrAllPins, inMemType);
			getMemberInfoUsingXML(arrAllPins[inMemType].markers[0], inMemberID, true);
			//check zoom and set it to 15 if it was not set
			//If(Len(Request.QueryString("Zoom"))==0) Then
			//	inZoom = 15
			//End If
			
		}

		//load the map to the proper location
		//handle member id being passed into this page
		setInitialMapLocation(inZoom); //requires inLat, inLng, etc to be set
		
		
		//Add Visitors Center to map  525 dev server 1050 live server
		addPointToMarkerList(visCenterLat, visCenterLng, "PA Dutch Country Visitors Center", arrAllPins, "information", informationGroupID, 1050, "501 Greenfield Road", "Route 30 at the Greenfield Road Exit", "Lancaster", "PA", "17601", "717-299-8901", "", "", "")

		addMarkerGroupToMap(arrAllPins, informationGroupID);
				
		//Populate the travel plan drop down selectors
		getTravelPlansUsingXML();
		
		//List the destinations in the current travel planner
		getTravelPlannerListUsingXML();

		//Add inital pushpins
		
		//toggleIconGroup(0);
		//toggleIconGroup(1);
		//toggleIconGroup(2);
		//toggleIconGroup(3);
		
		//toggleIconGroup(3); //events
		//toggleIconGroup(5); //travel planner	
		
		//Show any requested groups
		if (showDining){
			toggleIconGroup(0);
			selectTab('Dining', 0);
		}
		if (showLodging){
			toggleIconGroup(1);
			selectTab('Lodging', 1);
		}
		if (showShopping){
			toggleIconGroup(2);
			selectTab('Shopping', 2);
		}
		if (showThings){
			toggleIconGroup(3);
			selectTab('ThingsToDo', 3);
		}
		if (showEvents){
			toggleIconGroup(4);
			selectTab('Events', 4);
		}
		if (showTravelPlanner){
			toggleIconGroup(5);
		}
		if (showTravelPlannerIntro){
			toggleIconGroup(5);
			toggleMapClosed();
		}
		
		//If travel planner is being used in some way
		//if(showTravelPlanner || showTravelPlannerIntro || (boolAddToTP == "true" && inMemberID > 0)){
			toggleTravelPlannerOpen();
		//} else{
		//	toggleTravelPlannerClosed();
		//}
		
		//If user is addind a member to the travel planner 
		if(boolAddToTP == "true" && inMemberID > 0){
			addTPMemberUsingXML(inMemberID);
		}
			
  	  }
	  return true;
	} 
	
	function toggleMap(){
		if ($("#mapAndControls").css("display") == "block") {
			toggleMapClosed();			
		} else {
			toggleMapOpen();
		}
	}
	function toggleMapOpen(){
			$("#mapAndControls").css("display","block");
			$("#mapWelcome").css("display","none");
			$("#arrowMap").attr("src","/maps/images/arrow_f2.gif");
	}
	function toggleMapClosed(){
			$("#mapAndControls").css("display","none");
			$("#mapWelcome").css("display","block");
			$("#arrowMap").attr("src","/maps/images/arrow.gif");
	}
	
	function toggleTravelPlanner(){
		if ($("#travelPlanner").css("display") == "block") {
			toggleTravelPlannerClosed();
		} else {
			toggleTravelPlannerOpen();
		}
	}
	function toggleTravelPlannerOpen(){
			$("#travelPlanner").css("display","block");
			$("#arrowTP").attr("src","/maps/images/arrow_f2.gif");
	}
	function toggleTravelPlannerClosed(){
			$("#travelPlanner").css("display","none");
			$("#arrowTP").attr("src","/maps/images/arrow.gif");
	}
	
	function check4EnterBtn(evt, actn){
		var keyCode = evt.keyCode ? evt.keyCode :
		evt.charCode ? evt.charCode : evt.which;
		if (keyCode == 13)
			actn;
		else
			return true;
	}
	
	function noenter(evt){
		var keyCode = evt.keyCode ? evt.keyCode :
		evt.charCode ? evt.charCode : evt.which;
		//prevent enter button from being used
		return (keyCode != 13);
	}
	
	function sendInfoWinEmailCheck(strMemberId, strEvtId, emailField){
		if (checkEmail(emailField, "Email")){
			sendMapInfoUsingXML(0, emailField.value, "", "", strMemberId, strEvtId);
			hideEmailInfoWin();
		}
	}
	
	function sendInfoWinPhoneCheck(strMemberId, strEvtId){
		if (getId("fldInfoWinPhoneNum").value.length < 10 || getId("fldInfoWinPhoneNum").value == "##########"){
			alert("Invalid Phone #");
		}else if (getId("fldInfoWinCarrier").selectedIndex == 0){
			alert("You must select a carrier");
		}else{
			sendMapInfoUsingXML(0, "", getId("fldInfoWinPhoneNum").value, getId("fldInfoWinCarrier").value, strMemberId, strEvtId);
			hidePhoneInfoWin();			
		}
	}
	
	function sendTPEmailWinCheck(){
		if (checkEmail(getId('fldSTEEmail'), "Email")){
			sendMapInfoUsingXML(0, getId('fldSTEEmail').value, '', '', 0, 0); 
			tb_remove();
		}
	}
	function sendTPWinPhoneCheck(){
		if (getId("fldNumber").value.length < 10 || getId("fldNumber").value == "##########"){
			alert("Invalid Phone #");
		}else if (getId("fldCarrier").selectedIndex == 0){
			alert("You must select a carrier");
		}else{
			sendMapInfoUsingXML(0, '', getId('fldNumber').value, getId('fldCarrier').value, 0, 0); 
			tb_remove();
		}
	}
	
	
	//********************************************
	//* General Map Functions End
	//********************************************

	function showEmailInfoWin(){
		getId('infoWinEmail').style.display="block";
		getId('infoWinInfo').style.display="none";
		
		//Autopopulate any values stored in cookies.
		checkTPEmailCookie('fldWinEmail');

	}
	function hideEmailInfoWin(){
		getId('infoWinEmail').style.display="none";
		getId('infoWinInfo').style.display="block";
	}
	function showPhoneInfoWin(){
		getId('infoWinPhone').style.display="block";
		getId('infoWinInfo').style.display="none";
	
		//populate field fldInfoWinCarrier with options
		populatePhoneCarriers(getId("fldInfoWinCarrier"));
		
		//Autopopulate any values stored in cookies.
		checkTPPhoneCookie('fldInfoWinPhoneNum', 'fldInfoWinCarrier')		
	}
	
	function hidePhoneInfoWin(){
		getId('infoWinPhone').style.display="none";
		getId('infoWinInfo').style.display="block";
	}
	function showDirectionsInfoWin(){
		getId('infoWinDirections').style.display="block";
		getId('infoWinInfo').style.display="none";
		
		//Autopopulate any values stored in cookies.
		if (getCookie('tp_dirAdd').length > 0){
			getId('fldUserAddress').value = getCookie('tp_dirAdd');
		}		
	}
	function hideDirectionsInfoWin(){
		getId('infoWinDirections').style.display="none";
		getId('infoWinInfo').style.display="block";
	}
	
	function checkTPEmailCookie(theFieldId){
		if (getCookie('tp_em').length > 0){
			getId(theFieldId).value = getCookie('tp_em');
		}
	}
	function checkTPPhoneCookie(theNumFieldId, theCarFieldId){
		//Autopopulate any values stored in cookies.
		if (getCookie('tp_ph').length > 0){
			getId(theNumFieldId).value = getCookie('tp_ph');
		}
		if (getCookie('tp_car').length > 0){
			var theSelect = getId(theCarFieldId);
			for (i = 0; i < theSelect.length; i++) {
				if (theSelect.options[i].value == getCookie('tp_car')){
					theSelect.options[i].selected = true
				} else {
					theSelect.options[i].selected = false
				}				
			}
		}		
	}
	
	function populatePhoneCarriers(theField){
		theField.length=34;
		theField.options[0].value = ''
		theField.options[1].value = 'ACS'
		theField.options[2].value = 'ALASKA_WIRELESS_US'
		theField.options[3].value = 'ALLTEL'			
		theField.options[4].value = 'APPALACHIAN_WIRELESS'			
		theField.options[5].value = 'ATT'
		theField.options[6].value = 'ATT-CINGULAR'
		theField.options[7].value = 'BLUECELL_US'
		theField.options[8].value = 'CELLCOM_US'
		theField.options[9].value = 'CELL_SOUTH'
		theField.options[10].value = 'CELLULARONE'			
		theField.options[11].value = 'SLO_CELLULAR_US'			
		theField.options[12].value = 'CENTENNIAL'
		theField.options[13].value = 'CINCINNATI_BELL'
		theField.options[14].value = 'COPPER_VALLEY_US'			
		theField.options[15].value = 'EDGE'			
		theField.options[16].value = 'EINSTEIN_WIRELESS_US'			
		theField.options[17].value = 'HELIO'
		theField.options[18].value = 'METROPCS'
		theField.options[19].value = 'MIDWEST_WIRELESS'
		theField.options[20].value = 'NEXTEL'
		theField.options[21].value = 'NTELOS_US'
		theField.options[22].value = 'OMNIPOINT'
		theField.options[23].value = 'QWEST'
		theField.options[24].value = 'SRT_US'			
		theField.options[25].value = 'SPRINT'
		theField.options[26].value = 'SUNCOM'
		theField.options[27].value = 'SUREWEST_US'
		theField.options[28].value = 'TMOBILE'
		theField.options[29].value = 'RCC'
		theField.options[30].value = 'USCELLULAR'
		theField.options[31].value = 'VERIZON'			
		theField.options[32].value = 'VIRGIN'
		theField.options[33].value = 'WESTERN_WIRELESS'	
		theField.options[0].text = 'Select your carrier'
		theField.options[1].text = 'Alaska Communications Systems'
		theField.options[2].text = 'Alaska Wireless'
		theField.options[3].text = 'Alltel'			
		theField.options[4].text = 'Appalchian Wireless'			
		theField.options[5].text = 'AT&T'
		theField.options[6].text = 'AT&T (Previously Cingular)'
		theField.options[7].text = 'Bluegrass Cellular'
		theField.options[8].text = 'Cellcom'
		theField.options[9].text = 'Cellular South'
		theField.options[10].text = 'CellularOne'			
		theField.options[11].text = 'Cellular One of San Luis Obispo'			
		theField.options[12].text = 'Centennial Wireless'
		theField.options[13].text = 'Cincinnati Bell'
		theField.options[14].text = 'Copper Valley'			
		theField.options[15].text = 'Edge Wireless'			
		theField.options[16].text = 'Einstein Wireless'			
		theField.options[17].text = 'Helio'
		theField.options[18].text = 'MetroPCS'
		theField.options[19].text = 'Midwest Wireless'
		theField.options[20].text = 'Nextel'
		theField.options[21].text = 'nTelos'
		theField.options[22].text = 'Omnipoint'
		theField.options[23].text = 'Qwest'
		theField.options[24].text = 'SRT Wireless'			
		theField.options[25].text = 'Sprint'
		theField.options[26].text = 'SunCom Wireless'
		theField.options[27].text = 'SureWest'
		theField.options[28].text = 'T-Mobile'
		theField.options[29].text = 'Unicel'
		theField.options[30].text = 'US Cellular'
		theField.options[31].text = 'Verizon'			
		theField.options[32].text = 'Virgin Mobile'
		theField.options[33].text = 'Western Wireless'	
	}

	//********************************************
	//* Tab Functions Start
	//********************************************
	var lastDisplayedMapTab = "mapTabDining"
	function selectTab(strTabName, groupID){
		if (lastDisplayedMapTab != "mapTab"+strTabName){
			//change the header image
			$("#mapTabHeader").css("background-image","url(/maps/images/header_" + strTabName + ".gif)");
			//hide the current tab selections and show the clicked one
			$("#" + lastDisplayedMapTab).css("display","none");
			$("#mapTab" + strTabName).css("display","block");
			
			toggleIconGroupOn(groupID);
				
			lastDisplayedMapTab = "mapTab" + strTabName;
		}		  
	}
	
	function checkIconsInTab(groupID, parentDivID){
			toggleIconGroupOn(groupID);
			selectAllSubTypes(groupID, parentDivID);	
	}
	
	function uncheckIconsInTab(groupID, parentDivID){
			toggleIconGroupOff(groupID);
			deselectAllSubTypes(groupID, parentDivID);	
	}
	//********************************************
	//* Tab Functions End
	//********************************************


	//********************************************
	//* Travel Planner Functions Start
	//********************************************
	function savePlan(boolCreateNewPlan){
		showSaveModal();
		
		//Check if we are creating a new plan
		if(boolCreateNewPlan){
			getId('saveType').value = -1; //new plan
		}else{
			getId('saveType').value = 0; //existing plan
		}
		
		if(boolCreateNewPlan && getId("fldCurrentTravelPlanID").selectedIndex == 0){
			if(! confirm("This will remove any destinations you may have in your unsaved Travel Plan!")){
				hideSaveModal();
			}
		}
	}
	
	function showSaveModal(){		
		//getId('modalSave').style.display="block";
		//getId('modalBackground').style.display="block";
	}
	function hideSaveModal(){
		getId('modalSave').style.display="none";
		getId('modalBackground').style.display="none";
	}

	var lastMouseX = 0;
	var lastMouseY = 0;
	var algor;
	//Capture mouse movement events
	document.onmousemove = getMouseXY;
	function getMouseXY(e){
		if (!e) e = window.event; // works on IE, but not NS (we rely on NS passing us the event)
		 
		  if (e)
		  { 
			if (e.pageX || e.pageY)
			{ // this doesn't work on IE6!! (works on FF,Moz,Opera7)
			  lastMouseX = e.pageX;
			  lastMouseY = e.pageY;
			  algor = '[e.pageX]';
			  if (e.clientX || e.clientY) algor += ' [e.clientX] '
			}
			else if (e.clientX || e.clientY)
			{ // works on IE6,FF,Moz,Opera7
			  // Note: I am adding together both the "body" and "documentElement" scroll positions
			  //       this lets me cover for the quirks that happen based on the "doctype" of the html page.
			  //         (example: IE6 in compatibility mode or strict)
			  //       Based on the different ways that IE,FF,Moz,Opera use these ScrollValues for body and documentElement
			  //       it looks like they will fill EITHER ONE SCROLL VALUE OR THE OTHER, NOT BOTH 
			  //         (from info at http://www.quirksmode.org/js/doctypes.html)
			  lastMouseX = e.clientX + document.body.scrollLeft + document.documentElement.scrollLeft;
			  lastMouseY = e.clientY + document.body.scrollTop + document.documentElement.scrollTop;
			  algor = '[e.clientX]';
			  if (e.pageX || e.pageY) algor += ' [e.pageX] '
			}
		  }  	
	}
	
	function displayTPAddSequence(destXoffset, destYoffset){
		//alert(lastMouseY + " " + lastMouseX);
		//use jQuery to set css parameters
		$("#TPAddImage").css( {height: "100px",
			width: "100px",
			opacity: 100.0,
			position: "absolute",
			top: eval(lastMouseY-50) + "px",
			left: eval(lastMouseX-50) + "px"}
		);
		
		//use jQuery to set css parameters
		$("#TPAddImage").animate({ 
			height: "0px",
			width: "0px",
			opacity: 0.0,
			top: eval(lastMouseY+destYoffset) + "px",
			left: eval(lastMouseX+destXoffset) + "px"}, 
			500 
		 );
	}
	
	function remove_verify(intID){
		if (confirm("Are you sure you want to remove this address from your Travel Plan?"))
			removeTPMemberUsingXML(intID);
	}
	
	function setNewDefaultPlan(){
		setDefaultTPUsingXML( document.getElementById('fldCurrentTravelPlanID').options[document.getElementById('fldCurrentTravelPlanID').selectedIndex].value);
	}
	
	function change_map_value(intID){
		var strAction
		var strCheckBox
		strCheckBox = eval("document.frmTPAddress.fldAddToMap_" + intID)
		if (strCheckBox.checked == true)
			strAction = "Add";
		else
			strAction = "Remove";
		
		window.location = "/maps/scripts/map_check_change.asp?fldItemID=" + intID + "&fldAction=" + strAction
	}
	
	function validateAddress(){
		var noErrors = true;
		if (document.getElementById('fldAddAddress1').value.length <= 0) {
			alert("Please enter a street address.")
			document.getElementById('fldAddAddress1').focus
			noErrors = false;
		}
		else if (document.getElementById('fldAddCity').value.length <= 0) {
			alert("Please enter a city.")
			document.getElementById('fldAddCity').focus
			noErrors = false;
		}
		else if (document.getElementById('fldAddState').selectedIndex == 0) {
			alert("Please enter a state.")
			document.getElementById('fldAddState').focus
			noErrors = false;
		}
		else if (document.getElementById('fldAddZip').value.length <= 0) {
			alert("Please enter a zip code.")
			document.getElementById('fldAddZip').focus
			noErrors = false;
		}
		else if (isZIPCode(document.getElementById('fldAddZip').value) == false || document.getElementById('fldAddZip').value.length > 5) {
			alert("This is not a valid zip code. Please use format #####.")
			document.getElementById('fldAddZip').focus
			noErrors = false;
		}
		
		if (noErrors == true) {
			displayTPAddSequence(0, 200);
			addTPMemberUsingXML(0);
			
			tb_remove();
			//Clear fields
			document.getElementById('fldAddName').value = "";
			document.getElementById('fldAddAddress1').value = "";
			document.getElementById('fldAddAddress2').value = "";
			document.getElementById('fldAddCity').value = "";
			document.getElementById('fldAddState').selectedIndex = 0;
			document.getElementById('fldAddZip').value = "";
			
		}
	}
	
	function deleteTravelPlanCheck(){
		if (document.getElementById("fldCurrentTravelPlanID").selectedIndex == 0){
			alert("You can not delete an unsaved Travel Plan. ");
		}else{
			if (confirm("Are you sure you want to delete this Travel Plan?"))
				deleteTPUsingXML(document.getElementById("fldCurrentTravelPlanID").options[document.getElementById("fldCurrentTravelPlanID").selectedIndex].value);	
		}
	}
	
	function checkTPSaveAvail(){
		if(getId('fldCurrentTravelPlanID').selectedIndex == 0){
			$("#modalSaveForm").css("display","block");
			$("#modalSaveMsg").css("display","none"); 
			savePlan(false);
		}else{
			$("#modalSaveForm").css("display","none");
			$("#modalSaveMsg").css("display","block"); 
		};
	}
	
	function updateTravelPlannerTitleBar(){
		//set travel planner title
		if (document.getElementById("fldCurrentTravelPlanID")){					
			var tmpText = document.getElementById("fldCurrentTravelPlanID").options[document.getElementById("fldCurrentTravelPlanID").selectedIndex].text;
			tmpText = tmpText.replace("<", "&lt;").replace(">", "&gt;")
			document.getElementById('TPTitle').innerHTML = tmpText;
		}
	}
	
	function displayTravelPlannerDirections(){
		//first check if we are displaying more than one entry by counting the number of remove links
		var arrSplitDirs = document.getElementById('tpList').innerHTML.split("Remove<")
		if (arrSplitDirs.length <= 2){
			alert("More than one destination is required to display directions.");
		}else{
			openPopupMenuName('travel_planner_map', '/maps/directions.asp', 520, 610, 100, 100, 0, 1, 1, 1, 0, 0, 0, 0);
		}
	}
	//********************************************
	//* Travel Planner Functions End
	//********************************************

	
	function setCookie(c_name,value,expiredays)
	{
		var exdate=new Date();
		exdate.setDate(exdate.getDate()+expiredays);
		document.cookie=c_name+ "=" +escape(value)+
		((expiredays==null) ? "" : ";expires="+exdate.toGMTString());
	}
	
	function getCookie(c_name)
	{
		if (document.cookie.length>0)
		{
			c_start=document.cookie.indexOf(c_name + "=");
			if (c_start!=-1)
			{ 
				c_start=c_start + c_name.length+1; 
				c_end=document.cookie.indexOf(";",c_start);
				
				if (c_end==-1) c_end=document.cookie.length;
				
				return unescape(document.cookie.substring(c_start,c_end));
			} 
		}
		return "";
	}
