// JavaScript Document

	//********************************************
	//* General Map Functions Start
	//********************************************
	function getId(theID){
		return document.getElementById(theID);
	}
		
	function initializeMap(radiusMilesLookup, postalLookupCode) {
		
		if (radiusMilesLookup.length <= 0 || postalLookupCode.length <5) {
		    document.getElementById("introNoInfo").style.display = "block";
			document.getElementById("intro").style.display = "none";
			document.getElementById("locator").style.visibility = "hidden";
			document.getElementById("listings").style.visibility = "hidden";
		} else {
		    document.getElementById("introNoInfo").style.display = "none";
			document.getElementById("intro").style.display = "none";
			document.getElementById("locator").style.visibility = "visible";
			document.getElementById("listings").style.visibility = "visible";

			if (GBrowserIsCompatible()) {
				//Set up the map
				var mapDiv = getId("masterMap");
				map = new GMap2(mapDiv, {size:new GSize(453,453)}); // {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(intClientLat, intClientLng), 8);

				//Add inital pushpins
				getListingsUsingXML(radiusMilesLookup, postalLookupCode);

			}
		}
  	  
	  return true;
	} 
	
	
	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();			
		}
	}
	
	//********************************************
	//* 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 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'	
	}

	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 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 "";
	}
