// detect browser
var isIE = (window.navigator.appName.toLowerCase().indexOf("microsoft")>=0);
// extend Document class in non-IE standards compliant browsers to have a loadXML method similar to IE
	if ( isIE != true )
	{
		//add the loadXML() method to the Document class
		Document.prototype.loadXML = function(strXML)
		{
			//create a DOMParser
			var objDOMParser = new DOMParser();

			//create new document from string
			var objDoc = objDOMParser.parseFromString(strXML, "text/xml");

			//make sure to remove all nodes from the document
			while (this.hasChildNodes())
				this.removeChild(this.lastChild);

			//add the nodes from the new document
			for (var i=0; i < objDoc.childNodes.length; i++)
			{
				//import the node
				var objImportedNode = this.importNode(objDoc.childNodes[i], true);

				//append the child to the current document
				this.appendChild(objImportedNode);

			} //End: for
		}

		// apply xml property to all nodes in xml document
		Node.prototype.__defineGetter__("xml", _Node_getXML);

	}

// only in Mozilla and Netscape
function _Node_getXML() {
    
    //create a new XMLSerializer
    var objXMLSerializer = new XMLSerializer;
    
    //get the XML string
    var strXML = objXMLSerializer.serializeToString(this);
    
    //return the XML string
    return strXML;
}

function exists (theVar)
{ 
alert('MapFunctions::exists');
    var varExists = true;
    try
    {
        var newVar = theVar;
    } 
    catch(e)
    {
        varExists = false;
    } 
    
    return varExists; 
} 

var xmlHttp=null;

function XMLHttpHandler(url,queryString, formDataString,callBack)
{
	alert('MapFunctions::XMLHttpHandler');
	if(xmlHttp==null || xmlHttp.readyState==4)
	{
		if(window.ActiveXObject)
			xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
		else if(window.XMLHttpRequest)
			xmlHttp=new XMLHttpRequest(); 
    	
		if(xmlHttp!=null)
		{
			xmlHttp.open("POST",url,true);
			xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=UTF-8");
			xmlHttp.onreadystatechange=callBack;						
			xmlHttp.send(formDataString);
		}	
	}
	else if(xmlHttp.readyState!=4)
		alert("Please wait. Processing the previous request");
}

function IdentifyTool_Clicked(shape)
{
    if(shape != null && shape.xmin != null && shape.ymin != null)
    {
	    ShowInfoWindow(shape.xmin , shape.ymin, null);
	}	
	return false;
}

function ShowInfoWindow(locationX, locationY, layerId)
{
    var path = "/Webpages/Info/Info.aspx";   
    if(window.NGServerUrl)
    {
        path = NGServerUrl() + path;
	}
	else
	{
	    var protocol = window.location.protocol;
		var theHost = window.location.hostname;
		var port = window.location.port;
		
		if (port)
		{
		    port=":"+ port;
		}
		
		var ThePath = window.location.pathname;    
		ThePath = ThePath.substring(0, ThePath.indexOf("/", 1));    
		path = protocol + "//" + theHost + port + ThePath + path;
			
    }
    var infoUrl = path + "?XMIN=" + locationX + "&YMIN=" + locationY;
    if(layerId != null )
    {
        infoUrl += "&INFOLAYERID=" + layerId;
    }
	 //If the function to open this in a iFrame exist then call it else open to a new window.        
	if(window.HandleInfoToolFrame)
	{
	    HandleInfoToolFrame(infoUrl);
    }
	else
	{
   	    window.open(infoUrl,"InfoWindow","toolbar=no, directories=no, location=no,status=yes, menubar=no, resizable=yes, scrollbars=auto, width=550, height=500");
	}	
}
