   	//<![CDATA[

		//-- Global variables
		
		var map = null;
		var xmlDoc=null;
		var request=null;
		var geocoder = null;
		var activeMarker = null;
		var allowedBounds = null;
		 
		var defaultValues = new FormDefaults ();

		
		// --- Client side objects
		
		function FormDefaults ()
		{
			this.defaults = new Object();
			
			this.defaults["tbFindAddress"] = "";
			this.defaults["tbName"] = "Name";
			this.defaults["tbAddress"] = "Address";
			this.defaults["tbComments"] = "";
			this.defaults["tbDetails"] = "";
			this.defaults["tbDateInitiated"] = "";
			this.defaults["tbDateComplete"] = "";
			this.defaults["tbCurrentStatus"] = "";
			this.defaults["tbCity"] = "Ann Arbor";
			this.defaults["tbState"] = "MI";
			this.defaults["tbZip"] = "Zip";
			this.defaults["tbPhone"] = "Phone Number";
			this.defaults["tbEmail"] = "Email Address";
			this.defaults["tbRequestId"] = "REQUEST ID";
			this.defaults["tbIncidentId"] = "INCIDENT ID";
			this.defaults["tbRequestID"] = "";
			this.defaults["tbRequestLatitude"] = "0.0";
			this.defaults["tbRequestLongitude"] = "0.0";
			
			this.getDefault = function ( control )
								{
									var value = null;
									for ( key in this.defaults )
									{
										if ( control.id.indexOf ( key ) != -1 )
										{
											value = this.defaults[key];
											break;
										}
									}
									return value;
								}
		}
			
		function ValidateRequiredField ( source, arg )
		{
			arg.IsValid = ( 0==arg.Value.length )? false:true;
		
		}
		
		// --- Client-side ASP.NET validator
		
		function ValidateForm ( source, arg )
		{
				var msg = validateFormFields ();
				arg.IsValid = ( 0 == msg.length );
				
				if (!arg.IsValid)
				{
					source.style.display="inline";				
					source.innerHTML=msg;
				}
		}
		
		function validateEmail ( emailCtl )
		{
		        //--- Email is optional and no longer validated on the client 10/11/2007
				return true; //(emailCtl.value.indexOf ( "@" ) == -1 || emailCtl.value == defaultValues.getDefault (emailCtl) ) ? false : true;
			
		}
		
		function validatePhone ( phoneCtl )
		{
			var value = phoneCtl.value;
			if ( value == defaultValues.getDefault(phoneCtl) )
			{
				return true;
			}
			
			var re =  /^\s*\({0,1}(\d{3})\){0,1}\s*(\d{3})\s*\-{0,1}\s*(\d{4})\s*(\d*)$/ ;
			var matches = re.exec ( value );
			
			if (  null == matches )
			{
				return false;
			}
			else
			{
				var area = matches[1];
				var exch = matches[2];
				var number = matches[3];
				
				var ext  = ( 5 == matches.length) ?  matches[4] : "" ;
				
				phoneCtl.value = "(" + area + ") " + exch + "-" + number;
				
				if ( ext.length > 0 ) 
				{
					phoneCtl.value = phoneCtl.value + "x" + ext;
				}
				
				return true;
			}
		}
		
		// --- Validation function for non-IE browsers
		
		function validateInputs ()
		{
			var msg = validateFormFields ();
			var isValid = ( 0 == msg.length )
			if ( !isValid )
			{
				alert ( msg );
			}
			
			return isValid;
		}


		function validateFormFields ()
		{
			var tb = getFormElementByLocalName("tbEmail");
			var isValid = false;
			var msg = "";
			
			if (tb && tb!= null )
			{
				isValid = validateEmail ( tb );
				if ( !isValid )
				{
					msg = msg + "Invalid email; e.g. address@domain.tla\n";
				}				
			}


			tb = getFormElementByLocalName("tbPhone");
			if (tb && tb!= null )
			{
				isValid = validatePhone ( tb );
				if ( !isValid )
				{
					msg = msg + "Invalid phone number; e.g. (555) 555-5555 x5555\n";
				}	
			}
			
			
			tb = getFormElementByLocalName("tbRequestLatitude");

			if (tb && tb!= null )
			{
				var lat = 0.0;
				var lon = 0.0;
				
				try
				{
					var lat = parseFloat ( tb.value );
					tb = getFormElementByLocalName("tbRequestLongitude");
					var lon = parseFloat  ( tb.value );
				}
				catch ( ex )
				{
					lat = 0.0;
					lon = 0.0;
				}
				
				if ( 0.0 == lat || 0.0 == lon )
				{
					msg = msg + "You must select a map location\n";
				}
			}
			
						
			return msg;
		}
		
		
		function reqData ()
		{
			this.RequestId			= null;
			this.DomainId			= null;
			this.ProjectSid			= null;
			this.ProblemCode		= null;
			this.Details			= null;
			this.ReqCategory		= null;
			this.Description		= null;
			this.Priority			= null;
			this.SRX				= null;
			this.SRY				= null;
			this.ProblemSid			= null;
			this.ReqCustFieldCatId	= null;
			this.ProbAddress		= null;
			this.ProbCity			= null;
			this.ProbZip			= null;
			this.ProbAddType		= null;
			this.InitiatedBy		= null;
			this.DateTimeInit		= null;
			this.SubmitToPager		= null;
			this.SubmitToPhone		= null;
			this.SubmitTo			= null;
			this.SubmitToEmail		= null;
			this.ClosedBy			= null;
			this.DateTimeClosed		= null;
			this.WorkOrderId		= null;
			this.ProjectName		= null;
			this.DateSubmitTo		= null;
			this.SubmitToOpenBy		= null;
			this.DateSubmitToOpen	= null;
			this.DispatchTo			= null;
			this.DateDispatchTo		= null;
			this.DispatchOpenBy		= null;
			this.DateDispatchOpen	= null;
			this.MapPage			= null;
			this.Shop				= null;
			this.Status				= null;
			this.Cancel				= null;
			this.CancelledBy		= null;
			this.DateCancelled		= null;
			this.LaborCost			= null;
			this.FieldInvtDone		= null;
			this.DateInvtDone		= null;
			this.WONeeded			= null;
			this.Excursion			= null;
			this.TileNo				= null;
			this.PrjCompleteDate	= null;
			this.Comments			= null;
			this.CustomerCalls = new Array ();
		}
		
		function CustomerCallData ()
		{
			this.IncidentNum		= null;
			this.RequestId			= null;
			this.FirstName			= null;
			this.LastName			= null;
			this.Title				= null;
			this.MiddleInitial		= null;
			this.AcctNum			= null;
			this.CCX				= null;
			this.CCY				= null;
			this.AptNum				= null;
			this.CustAddress		= null;
			this.CustCity			= null;
			this.CustZip			= null;
			this.CustAddType		= null;
			this.HomePhone			= null;
			this.DateTimeCall		= null;
			this.OtherPhone			= null;
			this.Email				= null;
			this.WorkPhone			= null;
			this.IsResident			= null;
			this.IsFollowUpCall		= null;
			this.CallerType			= null;
			this.Comments			= null;
			this.CustContact		= null;
			this.DateTimeContact	= null;
			this.CustCallback		= null;
			this.DateTimeCallback	= null;
			this.ProbDetails		= null;
			this.CustCallQuestions	= null;
			this.CustomerCallData	= null;
		}
		
		function onClick_resetForm ( control )
		{
			removeMarkers();
			
			control.reset();
			
 			var inputs = control.getElementsByTagName("input");
			 for ( var i=0; i<inputs.length; i++ )
			 {
				var inputctl = inputs[i];
				if ( "text" == inputctl.type || "hidden" == inputctl.type )
				{
					var def = defaultValues.getDefault ( inputctl );
					if ( null != def )
					{
						inputctl.value = def;
					}
				}
			}
			
				
			var ta = getFormElementByLocalName ( "tbComments" );		// --- This renders as a textarea, not an input[type=text]
			if ( ta && null != ta )
			{
				ta.value= defaultValues.getDefault ( ta );
			}
			
			var ta = getFormElementByLocalName ( "tbDetails" );		// --- This renders as a textarea, not an input[type=text]
			if ( ta && null != ta )
			{
				ta.value= defaultValues.getDefault ( ta );
			}
			var dd = getFormElementByLocalName ( "ddProblemTypes" );
			if ( dd && null != dd)
			{
					dd.selectedIndex = 0;
					dd.options[0].selected = true;
					control.submit();				// --- this will repopulate the question blocks on the Add Form
			}
			else
			{
				if (map && null != map)				// --- Re-center and zooom out on the status form
				{
					map.setCenter(new GLatLng(42.281428, -83.748493), 11);
				}
			}
		}


		function getFormElementByLocalName ( localname )
		{
			var retctl = null;
			
 			var forms = document.forms;
			 for ( var i=0; i<forms.length; i++ )
			 {
				var f = forms[i];
				var elements = f.elements;
				
				for ( var j=0; j< elements.length; j++ )
				{
					var element = elements[j];
					var elementname = element.name;
					if ( elementname.indexOf ( ":" ) != -1 )
					{
						elementname = elementname.split(":")[1];		// 1.1.4 asp.net
					}
					else if ( elementname.indexOf ( "\$" ) != -1 )
					{
						elementname = elementname.split("\$")[1];		// 2 asp.net
					}

					if ( localname == elementname )
					{
						retctl = element;
						break;
					}
				}
			}		
			return retctl;
		}
		
		
		function onClick_clearDefaultText ( control )
		{
			var def = defaultValues.getDefault ( control );
			if ( control.value == def )
			{
				control.value = "";
			}
			else
			{
				control.select();
			}
		}
		
		function showNextQuestion ( control)
		{
			 var parentid = control.id;
			 
			 var inputs = control.getElementsByTagName("input");
			 for ( var i=0; i<inputs.length; i++ )
			 {
				var inputctl = inputs[i];
				
				if ( inputctl.type=="checkbox" )
				{
					var fullvalue = inputctl.value;
					if ( fullvalue )
					{
							//---	The actual value is a csv string that 
							//		contains the answer id and the nextquestion id 
							//		(e.g. 33,12)
							
							var splitarray  = fullvalue.split ( "," );
							if ( 2 == splitarray.length )
							{
								// --- The divs are identified by the question id prefixed by the parent control id.
								var nextqid = splitarray[1];
								if ( "0" != nextqid )
								{	
									var parentArray = parentid.split ( "_" );
									if ( parentArray.length >0 )
									{
										parentArray[parentArray.length-1] = nextqid;
										divid = parentArray.join ( "_" );				
									}
									else
									{
										divid = "-1";
									}
									
									var div = document.getElementById ( divid );
									if ( div )
									{
										
										if ( inputctl.checked )
										{
											div.style.display = "block";
										}
										else
										{
											div.style.display = "none";
										}
									}
								}
							}
					}														
				}
			 }
		}
		
				


		function removeMarkers()
		{
			if ( map )
			{
				if (map != null )
				{
					map.clearOverlays ();
				}
			}
		}
		

		// --- XML callback functions
		
		function locateAddress( point ) 
		{
			if ( point )
			{
					try
					{
							map.setCenter (point, 16);
							var html = "<b>" + "Fill-out form and click Add Request " + "</b><br/>" +
											" to request service here" + "</b>";
						
							map.openInfoWindowHtml(point, html);
							getFormElementByLocalName ( "tbRequestLatitude" ).value = point.lat().toString();
							getFormElementByLocalName ("tbRequestLongitude" ).value = point.lng().toString();

					}
					catch ( ex )
					{
						window.alert ( "Address not found " + ex );
						getFormElementByLocalName ( "tbRequestLatitude" ).value = "0.0";
						getFormElementByLocalName ( "tbRequestLongitude" ).value = "0.0";
					}
			}
			else
			{
				alert ( "Address not found" );
				getFormElementByLocalName ( "tbRequestLatitude" ).value = "0.0";
				getFormElementByLocalName ("tbRequestLongitude" ).value = "0.0";
				
			}
		}
		

		function mapAddresses(response) 
		{
		      if (!response || response.Status.code != 200) 
		      {
				setStatusMessage ( "Address not found" );
		      } 
		      else
		      {
				place = response.Placemark[0];
				point = new GLatLng (place.Point.coordinates[1], place.Point.coordinates[0]);
				

				map.setCenter(point, 16);
				var html = "<b>" + "Fill-out form and click insert " + "</b><br/>" +
								" to post a complaint here" + "</b>";
						
				map.openInfoWindowHtml(point, html);												
			}
		 }


		function cbFindAddressButton_click(  )
		{
			if (geocoder) 
			{
				var address = document.getElementById("reqForm_tbFindAddress").value;
				var addressValue = address + " Ann Arbor, MI";
			
				geocoder.getLatLng ( addressValue, locateAddress );
		
			}
		}

		function newInfoMarker ( inputPoint, inputHTML )
		{
			var marker = new GMarker(inputPoint);

  			GEvent.addListener( marker, 
  								"click", 
								function() 
									{
										marker.openInfoWindowHtml(inputHTML);
									}
								);
			return marker;	
		}


		function createRequestMarker ( markerElement )
		{
			var point = new GLatLng(
							parseFloat(markerElement.getAttribute("lat")),
							parseFloat(markerElement.getAttribute("lng"))
						);
						
			var  html = 	"<p style=\"width:120pt;\"><b>" + 
						"Category: " + markerElement.getAttribute("cat") + "<br/>" +
						"Description: " + markerElement.getAttribute("desc") + "<br/>" +
						"Details: " + markerElement.getAttribute("det") + "<br/>" +
						"Status: " + markerElement.getAttribute("stat") + "<br/>" +
						"Location: " + markerElement.getAttribute("addr") + "<br/>" +
						"Notify?" + markerElement.getAttribute("call") + "<br/>" +
						"Name: " + markerElement.getAttribute("name") + "<br/>" +
						"Phone: " + markerElement.getAttribute("phone") + "<br/>" + 
						"Email: " + markerElement.getAttribute("email")	+ "<br/>"										
					"</b></p>";

			return newInfoMarker ( point, html );	
		}
						
		function mapLoad()
		{
			if (GBrowserIsCompatible()) 
			{
					map = new GMap2( document.getElementById("map") );

					var mt = map.getMapTypes();
					// Overwrite the getMinimumResolution() and getMaximumResolution() methods
					for (var i=0; i<mt.length; i++) 
					{
						mt[i].getMinimumResolution = function() {return 11;}
						mt[i].getMaximumResolution = function() {return 17;}
					}

					geocoder = new GClientGeocoder();
					
					map.addControl( new GSmallMapControl() );
					map.addControl( new GMapTypeControl() );	
					
					map.setCenter(new GLatLng(42.281428, -83.748493), 11);

					allowedBounds = map.getBounds();


					if ( null != activeMarker )
					{
						map.setCenter ( activeMarker.getPoint(), 16 );
						map.addOverlay( activeMarker );
					}
					else
					{
						var lat = getFormElementByLocalName ( "tbRequestLatitude" );
						var lon = getFormElementByLocalName ( "tbRequestLongitude" );
						if ( lat && lon )
						{
							if ( lat.value != 0.0 && lon.value != 0.0)
							{
								var p = new GLatLng ( lat.value, lon.value );
								var reqid = "unassigned"
								var probtypelist = getFormElementByLocalName( "ddProblemTypes" );
								var probdesc = probtypelist.options[probtypelist.selectedIndex].text;
								//if ( reqid.length == 0 || "REQUESTID" ==reqid) { reqid = "unassigned"; }
								
								map.setCenter ( p, 16 );
								map.openInfoWindowHtml(p, "<b>" + "Request=" + reqid + "<br/>Problem=" + probdesc +"<br/></b>" );								
							}
						}					
					}
					
					if ( getFormElementByLocalName ( "tbFindAddress" ) != null )
					{
						GEvent.addListener( map, 'click', 
							function(overlay, point) 
							{
								if (point) 
								{
									// --- Get Attributes from the form and post to database
									var html = "<b>" + "Fill-out form and click Add Request" + "</b><br/>" +
										" to request service here" + "</b><br/>";
									map.openInfoWindowHtml(point, html);
									getFormElementByLocalName ( "tbRequestLatitude" ).value = point.lat().toString();
									getFormElementByLocalName ("tbRequestLongitude" ).value = point.lng().toString();
									getFormElementByLocalName ("tbFindAddress" ).value = "Location Selected From Map";

								}
							}
						);
					}
					
					// --- This move event listener prevents panning too far from Ann Arbor
					//			Coded taken verbatim from Google-recommended tutorials authored at
					//			http://www.econym.demon.co.uk/googlemaps/range.htm 
					GEvent.addListener(map, "move", 
										function()
										{ 
											onmove_checkBounds();
										}
					);

					// The allowed region which the whole map must be within
      

			}
			//loadOptions_problemTypeCode (   );
		}
		  
	  
		// If the map position is out of range, move it back
		function onmove_checkBounds() 
		{
			// Perform the check and return if OK
			if (allowedBounds.contains(map.getCenter())) 
			{
				return;
			}
			
			// It`s not OK, so find the nearest allowed point and move there
			var C = map.getCenter();
			var X = C.lng();
			var Y = C.lat();

			var AmaxX = allowedBounds.getNorthEast().lng();
			var AmaxY = allowedBounds.getNorthEast().lat();
			var AminX = allowedBounds.getSouthWest().lng();
			var AminY = allowedBounds.getSouthWest().lat();

			if (X < AminX) {X = AminX;}
			if (X > AmaxX) {X = AmaxX;}
			if (Y < AminY) {Y = AminY;}
			if (Y > AmaxY) {Y = AmaxY;}
			//alert ("Restricting "+Y+" "+X);
			map.setCenter(new GLatLng(Y,X));
		}

		
		function showXML ( xmldoc )
		{
			if ( xmldoc.xml)    		// IE
				alert(xmldoc.xml);
			else    					// MOZ
				alert((new XMLSerializer()).serializeToString(xmldoc));
		}
 
 //]]>
