/**
 *	Copyright 2002-2006 by Earth Resource Mapping Ltd.  All rights reserved.
 *	Image Integration Framework generated pages may only be served by organizations that have
 *	a license for the Image Integration Framework product. Image Integration Framework may only be used by
 *	Application Service Providers (ASPs) with a license for the Image Integration Framework ASP Edition product.
 *
 *  @fileoverview Extension to SIX.Access.ArcXML class containing project specific functionality
 */
 
SIX.Access.ArcXML.prototype.searchLotDP = function ()
{
	var bGotLot = false;//Optional
	var bGotSection = false;//Optional
	var bGotPlan = false;//Mandatory
	
	if (this.service.currentSearch > -1) 
	{
		var search = this.service.searches[this.service.currentSearch];	
		search.decodeForm();
		
		for( var i=0; i<search.fields.length; i++ ) 
		{				
			switch(search.fields[i].key.toLowerCase())
			{
				case "delivsdm:geodb.lot.lotnumber":
					if (search.fields[i].value != "")
						bGotLot= true;
					break;
				case "delivsdm:geodb.lot.sectionnumber":
					if (search.fields[i].value != "")
						bGotSection = true;
					break;
				case "delivsdm:geodb.lot.plannumber":
					if (search.fields[i].value != "")
						bGotPlan = true;
					break;
				default:
					break;
			}	
		}		

		var sErrorText = "";
		if (bGotPlan == false) 
			sErrorText += "Plan must be specified.\n";
			
		if (sErrorText != "")
			alert(sErrorText);
		else
		{
			var catalog = this.service.catalog;	
			if (catalog.maps.length)
				this.searchMap(catalog.maps[0],search);
		}
	}		
}

SIX.Access.ArcXML.prototype.searchMapSheetBoundaries = function ()
{
	var bGotMapTitle = false;//Mandatory if no map number
	var bGotMapNumber = false;//Mandatory if no map title
	
	if (this.service.currentSearch > -1) 
	{	
		var search = this.service.searches[this.service.currentSearch];	
		search.decodeForm();
		
		for( var i=0; i<search.fields.length; i++ ) 
		{				
			switch(search.fields[i].key.toLowerCase())
			{
				case "delivsdm:geodb.mapindex100k.maptitle":
				case "delivsdm:geodb.mapindex250k.maptitle":
					if (search.fields[i].value != "")
						bGotMapTitle = true;
					break;
				case "delivsdm:geodb.mapindex100k.mapnumber":
				case "delivsdm:geodb.mapindex250k.mapnumber":
					if (search.fields[i].value != "")
						bGotMapNumber = true;
					break;				
				default:
					break;
			}		
		}		
	
		var sErrorText = "";
		if ((bGotMapTitle == false) && (bGotMapNumber == false))
			sErrorText += "Map title or map number must be specified.\n";
			
		if (sErrorText != "")
			alert(sErrorText);
		else
		{
			var catalog = this.service.catalog;	
			if (catalog.maps.length)
				this.searchMap(catalog.maps[0],search);
		}
	}
}

SIX.Access.ArcXML.prototype.search = function ()
{	
	if (this.service.currentSearch > -1) 
	{	
		var search = this.service.searches[this.service.currentSearch];	
		search.decodeForm();
		var catalog = this.service.catalog;	
		if (catalog.maps.length)
			this.searchMap(catalog.maps[0],search);
	}
}

/**
*	PURPOSE: Displays current view as well as planning properties query results.
*/
SIX.Access.ArcXML.prototype.printPreviewPlanningProperties = function ()
{
	/* 
	** We need to determine whether the local image created via the control's CaptureView() function (see below)
	** has been blocked by the browser.  Unfortunately, the img onerror event does not get fired when 
	** local content is blocked.  So we do the following instead: 
	** 1. Display the error text after a timeout (say 1 second) which allows the local image time to load. 
	** 2. Call hideError() in the img onload event which hides the error text if the timeout has expired
	**	  and sets the bImageLoaded flag to true which prevents the error text being displayed if the timeout
	**	  has not expired.
	*/
	
	var catalog = this.service.catalog;
	var map = catalog.maps[0];
    var control = document[map.uid];
    var filename = control.CaptureView(".png");
    
	var sScript = "<script>" + 
				"var bImageLoaded = false;" + 
				"function hideError()" + 
				"{var elemError = document.getElementById(\"error\");" + 
				"if (elemError) elemError.style.display = \"none\";}" + 
				"function showError()" + 
				"{var elemError = document.getElementById(\"error\");" + 
				"if (elemError) elemError.style.display = \"block\";}" + 				
				"</script>";    
    var oWin = window.open();
    oWin.document.writeln("<!DOCTYPE HTML PUBLIC '-//W3C//DTD HTML 4.01 Transitional//EN' >");
	oWin.document.writeln("<html><head>");
	oWin.document.write("<title>Planning Properties</title>");
	oWin.document.write("<link rel='stylesheet' type='text/css' href='SIX.css'>");	
	oWin.document.write("<script language='JavaScript' src='sorttable.js' type='text/javascript'></script>");
	oWin.document.writeln(sScript);
	oWin.document.writeln("</head><body onload='setTimeout(\"if (!bImageLoaded) showError();\",1000)'>");
    oWin.document.writeln("<img onload='bImageLoaded=true;hideError();' src='file:///" + filename + "'>");
	oWin.document.writeln("<div id='error' style='display:none'><p>")
	oWin.document.writeln("<b>NOTE:</b> Your browser settings have prevented the map print preview from being displayed.");
	oWin.document.writeln("To display the print preview, copy and paste the below filename into your browser's address bar:<br><br>")
    oWin.document.writeln(filename);
    oWin.document.writeln("</p></div>");
 	oWin.document.writeln("<div id='results' style='position:relative'>");
 	var queries = this.service.queries;
	var nodeQueryResultsContainer = document.getElementById(queries.resultsContainerUid);
	if (nodeQueryResultsContainer)
		oWin.document.writeln(nodeQueryResultsContainer.innerHTML);
 	oWin.document.writeln("</div>");
    oWin.document.writeln("</body></html>");
    oWin.document.close();
}