var iTotalRows = 0;
var stringArray = new Array();

function createXML(createXMLFor, XMLType, strQueryString) {
	//GLog.write("in createXML");
 
	var url = "./xml/createXML.asp?t=1&createXMLFor="+createXMLFor;

    checkBounds();
    
  	var bounds = googleMap.getBounds();
	var zoom = googleMap.getBoundsZoomLevel(bounds);
		
	
  	//GLog.write("XMLType: " + XMLType);	
  	//send to createXML.asp with the appropriate parameters to get the data
  	//then send the data to the appropriate function to parse and display
  	
  	if (XMLType == "marker") {
  		var xmlMinX = parseInt(minx*1000000);
  		var xmlMaxX = parseInt(maxx*1000000);
  		var xmlMaxY = parseInt(maxy*1000000);
  		var xmlMinY = parseInt(miny*1000000); 
  		//for markers we pass in the checkboxes that are checked so we only grab data for layers that
  		//are active - will consist of incident, construction, and special event
  		url = url + "&" + strQueryString
  	}
  	else if (XMLType == "pnr") {
  		//data in PNR tables is not formatted the same way need a -sign in front of longitude
  		//do this in the sql query
  		var xmlMinX = parseInt(minx*1000000);
  		var xmlMaxX = parseInt(maxx*1000000);
  		var xmlMaxY = parseInt(maxy*1000000);
  		var xmlMinY = parseInt(miny*1000000);
  		
  		//settle different directory issue to avoid rewriting code
  		//need to go to ../xml/... 
  		url = "." + url;	
  	}
  	else {
  		var xmlMinX = minx;
  		var xmlMaxX = maxx;
  		var xmlMaxY = maxy;
  		var xmlMinY = miny; 
  	}
	
	// GLog.write("minX: " + xmlMinX + " , maxx: " + xmlMaxX + " , miny: " + xmlMinY + " , maxy: " + xmlMaxY);
	
	url = url + "&minX="+xmlMinX+"&maxX="+xmlMaxX+"&minY="+xmlMinY+"&maxY="+xmlMaxY

	//GLog.write(url);
	var request = GXmlHttp.create();

	
	request.open("GET", url, true);
	
	request.onreadystatechange = function() {
  		if (request.readyState == 4) {
  			
  			//alert(request.responseText);
  				
			var xmlDoc = null;
			var elem = null;
			xmlDoc = request.responseXML;
			
			//alert(request.responseText);

			if (xmlDoc != null) {
				
			//GLog.write("XMLType: " + XMLType);
			if (XMLType == 'marker') {
				var elem = xmlDoc.documentElement.getElementsByTagName("event");

				if (elem.length > 0) {
				//call function to plot markers
					var eventsExist = true;
					createPopups(elem, xmlDoc);
				}
				else {
					//initialize any existing markers to display false - send type to display false
					//this is if there are no new markers to display and existing are off the screen, we need
					//to clear the existing from the map when hidden from view
                    initializeEventMarkers(eventMarkers);
					
					//functions are in javascript/showHidePleaseWaitScreen.js
					hidePleaseWaitScreen();
					eventsExist = false;
				}
				//window.frames.showEvents.writeResults();
			}//end if XMLType == marker
			else if (XMLType == 'cctvs'){
				var elem = xmlDoc.documentElement.getElementsByTagName("cctv");
				if (elem.length > 0) {
				    //call function to plot markers
					cctvsExist = true;
					createCCTVPopups(elem, xmlDoc);
				}
				else {
					//initialize any existing markers to display false - send type to display false
					//this is if there are no new markers to display and existing are off the screen, we need
					//to clear the existing from the map when hidden from view
					initializeEventMarkers(cctvMarkers);
				    hidePleaseWaitScreen();
					cctvsExist = false;
				}
			}
			else if (XMLType == 'crossings'){
				var elem = xmlDoc.documentElement.getElementsByTagName("crossing");
				if (elem.length > 0) {
				    //call function to plot markers
					crossingsExist = true;
					createCrossingPopups(elem, xmlDoc);
				}
				else {
				    //initialize any existing markers to display false - send type to display false
					//this is if there are no new markers to display and existing are off the screen, we need
					//to clear the existing from the map when hidden from view
				    initializeEventMarkers(crossingMarkers);
					crossingsExist = false;
					hidePleaseWaitScreen();
				}
			}
			else if (XMLType == 'pnr') {
				var elem = xmlDoc.documentElement.getElementsByTagName("pnr");
				if (elem.length > 0) {
				//call function to plot markers
					pnrsExist = true;
					createPNRPopups(elem, xmlDoc);
				}
				else {
					pnrsExist = false;
				}
				
			}//type is pnr
			
			else {
				var elem = xmlDoc.documentElement.getElementsByTagName("link");
				//call function to parse XML and display on map
				if (elem.length > 0) {
				    getLinkData(elem, xmlDoc);
				    linkDataExists = true;
				}
				else {
				    drawingLinks = false;
				    hidePleaseWaitScreen();
				    linkDataExists = false;
				}
				//updateNoOfPoints(iTotalRows);
			}//end else - type is links
  		}//end if xmlDoc != null
    }//end if request.readyState = 4
	}//end request.onreadystatechange = function()
	
	request.send(null);

}//end function createXML


