﻿
var AsyncRequestFirstBestServingCellId = new WebWizardHTTPRequest("text");
AsyncRequestFirstBestServingCellId.ResponseListner=LaunchSiteReport;


//Loads the XML response from the web service into an XMLDocument
function getXmlDocument(response)
{
    var xmlDocumentTemp = new ActiveXObject( "Microsoft.XMLDOM" );

    xmlDocumentTemp.async="false";
    xmlDocumentTemp.loadXML(response);

    var xmlDocument = new ActiveXObject( "Microsoft.XMLDOM" );
    xmlDocument.loadXML(xmlDocumentTemp.text);
    return xmlDocument;	
}

function parseXMLResult(xmltext)
{
    if(xmltext==null)
    {
        return;
    }
    
    var doc;
    // code for IE
    if (window.ActiveXObject)
    {
       doc=new ActiveXObject("Microsoft.XMLDOM");
       doc.async="false";
       doc.loadXML(xmltext);
    }
    // code for Mozilla, Firefox, Opera, etc.
    else
    {
       var parser=new DOMParser();
       doc=parser.parseFromString(xmltext,"text/xml");
    }// documentElement always represents the root node
    var x=doc.documentElement;
    var s = "";
    if(x.childNodes[0])
    s = x.childNodes[0].nodeValue;
    return s;
}


var gWnd = null;

//This is the response entry-point for an AJAX request
function LaunchSiteReport(response,state,status)
{	
	try
	{	
		if(response == null)
		{	
			throw('Invalid Response From WebWizard  server.');
		}
		else 
		{
            var cellID;																	
			var strResult = parseXMLResult(response);
			
			if(strResult!=null && strResult.indexOf("Error")!=-1)
			{
			    throw strResult;
			}
			else if(strResult == "")
			{
			    throw "There are no serving cells for this location";
			}
			else
			{
			    cellID = strResult;
			}
			
			var SiteReportURL = document.getElementById('SiteReportURL').value;

			if(SiteReportURL == "")
			{
			    throw('Failed to launch report. ReportURL configuration entry is missing from Operations.xml');
			    
			}
			
		    var SiteReportParam = document.getElementById('SiteReportParam').value;
		    
		    if(SiteReportParam == "")
			{
			    throw('Failed to launch report. ParamName configuration entry is missing from Operations.xml');
			}
		    
		    var url = SiteReportURL + '&' + SiteReportParam + '=' + cellID + '&paramId=' + SiteReportParam;
		    ShowGISProgressImage(false);
		    ShowWaitCursor(false);
		    
		    if ( gWnd != null )
			{
				gWnd.close();
				gWnd = null;
			}
			
			gWnd = window.open(url,'SiteReport','width=800,fullscreen=no,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes');
            
            aircomMap.SetState("siteReport",cursor);            
        }
			
	}										
	catch(strError)
	{
	    alert(strError);
	    ShowGISProgressImage(false);
	    ShowWaitCursor(false);
	    aircomMap.SetState("siteReport",cursor);
	}
}


