var gaRoweDocType = new Array()
var nSelectedDocTypeIndex = 0;
var searchingWin = null;

function oRoweDocType(){
	this.EntityNum = null
	this.DocName = null
	this.TableName = null
	this.TFields = null
	this.TLabel1 = null
	this.TLabel2 = null
	this.TLabel3 = null
	this.FValue1 = ""
	this.FValue2 = ""
	this.FValue3 = ""
	this.Sql = null
	this.Sql1 = null
	this.Sql2 = null
	this.Sql3 = null
	this.SortBy = null
	this.GetSqlQry = buildSql
	// these members are for spatial search only
	this.bSelected = false;
	this.dblPagePrice = 2.35;	// set this price to -1 if not for sale
	this.nShownInSite = 2;		// shown in which site, 0 - intranet, 1 - internet, 2 - both
	this.nSearchType = 2;		// 0 - by type, 1 - by shape, 2 - both
}
	var xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
	xmlDoc.async="false"
	var url = "GetRowePara.aspx?type=ROWEDocTypes&QueryType=DocQuery";
	xmlDoc.load(url);

	if ( xmlDoc.parseError.errorCode != 0 )
	{
		alert("Error in getting response from web service in GetRowePara.\n\n" + xmlDoc.parseError.reason);
	    delete xmlDoc;		
	}
	
    if (xmlDoc)
    {
		var strResponse = xmlDoc.xml.replace(/&lt;/g, "<");
		strResponse = strResponse.replace(/&gt;/g, ">");		
		xmlDoc.loadXML(strResponse);

		if ( xmlDoc.parseError.errorCode != 0 )
		{
			alert("[GetRowePara] Error in getting response from web service.\n\n" + xmlDoc.parseError.reason);
			delete xmlDoc;		
		}
	}
    if (xmlDoc)
    {
		var nodeList = xmlDoc.getElementsByTagName("GetRoweParameters");
		if(nodeList != null && nodeList.length > 0)
		{
			if (nodeList.item(0).getAttribute("error-desc") != null && nodeList.item(0).getAttribute("error-desc").match(/\S/))
			{
				alert("[GetParcelTypeList] " + nodeList.item(0).getAttribute("error-desc"));
				delete xmlDoc;
				
			}
		}
	}
	if (xmlDoc)
	{
		nodeList = xmlDoc.getElementsByTagName("DocQuery");
		if(nodeList == null || nodeList.length < 1)
		{
			alert("Error in getting ROWE document type list: No ROWE documnet type found.");		
			delete xmlDoc;			
		}		
	}
	if (xmlDoc)
	{
		for (var i = 0; i < nodeList.length; i++)
		{
		    var oRoweDoc = new oRoweDocType();	
			var strValue = nodeList.item(i).getAttribute("EntityNum");
			if (strValue && strValue.length>1)
			{			    
	            oRoweDoc.EntityNum = strValue;	
			}
			strValue = nodeList.item(i).getAttribute("DocName");
			if (strValue && strValue.length>1)
			{			    
	            oRoweDoc.DocName = strValue;	
			}
			strValue = nodeList.item(i).getAttribute("TableName");
			if (strValue && strValue.length>1)
			{			    
	            oRoweDoc.TableName = strValue;	
			}
			strValue = nodeList.item(i).getAttribute("TFields");
			if (strValue && strValue.length>1)
			{			    
	            oRoweDoc.TFields = strValue;	
			}
			strValue = nodeList.item(i).getAttribute("TLabel1");
			if (strValue && strValue.length>1)
			{			    
	            oRoweDoc.TLabel1 = strValue;	
			}
			strValue = nodeList.item(i).getAttribute("TLabel2");
			if (strValue && strValue.length>1)
			{			    
	            oRoweDoc.TLabel2 = strValue;	
			}
			strValue = nodeList.item(i).getAttribute("TLabel3");
			if (strValue && strValue.length>1)
			{			    
	            oRoweDoc.TLabel3 = strValue;
			}
			strValue = nodeList.item(i).getAttribute("FValue1");
			if (strValue && strValue.length>1)
			{			    
	            oRoweDoc.FValue1 = strValue;	
			}
			strValue = nodeList.item(i).getAttribute("FValue2");
			if (strValue && strValue.length>1)
			{			    
	            oRoweDoc.FValue2 = strValue;	
			}
			strValue = nodeList.item(i).getAttribute("FValue3");
			if (strValue && strValue.length>1)
			{			    
	            oRoweDoc.FValue1 = strValue;	
			}
			strValue = nodeList.item(i).getAttribute("FValue3");
			if (strValue && strValue.length>1)
			{			    
	            oRoweDoc.FValue1 = strValue;	
			}
			strValue = nodeList.item(i).getAttribute("Sql0");
			if (strValue && strValue.length>1)
			{			    
	            oRoweDoc.Sql0 = strValue;	
			}
			strValue = nodeList.item(i).getAttribute("Sql");
			if (strValue && strValue.length>1)
			{			    
	            oRoweDoc.Sql = strValue;	
			}
			strValue = nodeList.item(i).getAttribute("Sql1");
			if (strValue && strValue.length>1)
			{			    
	            oRoweDoc.Sql1 = strValue;	
			}
			strValue = nodeList.item(i).getAttribute("Sql2");
			if (strValue && strValue.length>1)
			{			    
	            oRoweDoc.Sql2 = strValue;	
			}
			strValue = nodeList.item(i).getAttribute("Sql3");
			if (strValue && strValue.length>1)
			{			    
	            oRoweDoc.Sql3 = strValue;	
			}
			strValue = nodeList.item(i).getAttribute("SortBy");
			if (strValue && strValue.length>1)
			{			    
	            oRoweDoc.SortBy = strValue;	
			}
			strValue = nodeList.item(i).getAttribute("PagePrice");
			if (strValue && strValue.length>1)
			{			    
	            oRoweDoc.dblPagePrice = strValue;	
			}
			strValue = nodeList.item(i).getAttribute("ShownInSite");
			if (strValue && strValue.length>1)
			{			    
	            oRoweDoc.nShownInSite = strValue;	
			}
			strValue = nodeList.item(i).getAttribute("SearchType");
			if (strValue && strValue.length>1)
			{			    
	            oRoweDoc.nSearchType = strValue;	
			}
			gaRoweDocType[gaRoweDocType.length] = oRoweDoc;			
		}
		delete xmlDoc;
	}

	
	
	
/*	
1	TRACT MAP	TR	1
2	PARCEL MAP	PM	2
3	RECORD OF SURVEY	RS	3
4	GRANT DEED	GD	4
5	EASEMENT DEED	ED	5
6	QUITCLAIM	QC	6
7	BOARD RESOLUTION	BR	7
8	IRREVOCABLE OFFER OF DEDICATION	IO	8
9	TITLE POLICY	TP	9
10	LEASE AGREEMENT	LA	10
11	AGREEMENTS AND AMENDMENTS	AA	11
12	LIEN	LN	12
13	TRUST DEED	TD	13
14	LOTLINE ADJUSTMENT	LLA	14
15	OTHER	OT	15
16	N/A	N/A	16
*/	
	


function compare(a, b)
{
	if (a.DocName > b.DocName)
		return 1;
	else if (a.DocName == b.DocName)
		return 0;
	else
		return -1;
}

	gaRoweDocType.sort(compare);

function buildSql(oRoweDoc){
	var sSql = ""

	if (oRoweDoc.FValue1)
		sSql += oRoweDoc.Sql1 + oRoweDoc.FValue1 +"%'";
	
	if (oRoweDoc.FValue2)
	{
		if (sSql != "")
			sSql += " AND ";

		sSql += oRoweDoc.Sql2 + oRoweDoc.FValue2 +"%'";
	}
	
	if (oRoweDoc.FValue3)
	{
		if (sSql != "")
			sSql += " AND ";

		sSql += oRoweDoc.Sql3 + oRoweDoc.FValue3 +"%'";
	}
	
	if (sSql == "")
		sSql = oRoweDoc.Sql0;
	else {
		sSql = oRoweDoc.Sql + " WHERE " + sSql;
	
		if(oRoweDoc.SortBy) sSql += oRoweDoc.SortBy;
	}

	if(sSql !=""){ return sSql } else { return null }
}

function getDocTypeObj(entnum){
	for(var i=0;i<gaRoweDocType.length;i++){
		if(gaRoweDocType[i].EntityNum == entnum){
			return gaRoweDocType[i]
		}
	}
	return null
}

function ShowInputFields(nIndex)
{
	eval("top.fraLeftFrame.pnlInput" + nSelectedDocTypeIndex + ".style.display='none'");
	eval("top.fraLeftFrame.pnlInput" + nIndex + ".style.display='inline'");
		
	nSelectedDocTypeIndex = nIndex;
}

function ShowInputFieldsA(nIndex)
{
	eval("top.fraLeftFrame.pnlInputA" + nSelectedDocTypeIndex + ".style.display='none'");
	eval("top.fraLeftFrame.pnlInputA" + nIndex + ".style.display='inline'");
		
	nSelectedDocTypeIndex = nIndex;
}

function ShowInputFieldsB(nIndex)
{
	eval("top.fraLeftFrame.pnlInputB" + nSelectedDocTypeIndex + ".style.display='none'");
	eval("top.fraLeftFrame.pnlInputB" + nIndex + ".style.display='inline'");
		
	nSelectedDocTypeIndex = nIndex;
}

function openSearchingWin()
{
	var nLeft, nTop;
	with (screen)
	{
		nLeft = Math.round((width - 250) / 2);
		nTop = Math.round((height - 130) / 2);
	}
			
	searchingWin = window.open("wait.htm","wait","left=" + nLeft + ",top=" + nTop + ",height=130,width=250");
	top.AddWindow(searchingWin);
}

function closeSearchingWin()
{
	if (searchingWin != null && !searchingWin.closed)
		searchingWin.close();
}

function SearchRoweByType(form, nIndex)
{
	var objDoc = gaRoweDocType[nIndex];
	if (objDoc.TLabel1)
	{
		eval("objDoc.FValue1=form.f" + nIndex + "7.value");
		objDoc.FValue1 = objDoc.FValue1.replace("'", "''");
		objDoc.FValue1 = objDoc.FValue1.replace("%", "\%");
		objDoc.FValue1 = objDoc.FValue1.replace("_", "\_");
	}
	if (objDoc.TLabel2)
	{
		eval("objDoc.FValue2=form.f" + nIndex + "8.value");
		objDoc.FValue2 = objDoc.FValue2.replace("'", "''");
		objDoc.FValue2 = objDoc.FValue2.replace("%", "\%");
		objDoc.FValue2 = objDoc.FValue2.replace("_", "\_");
	}
	if (objDoc.TLabel3)
	{
		eval("objDoc.FValue3=form.f" + nIndex + "9.value");
		objDoc.FValue3 = objDoc.FValue3.replace("'", "''");
		objDoc.FValue3 = objDoc.FValue3.replace("%", "\%");
		objDoc.FValue3 = objDoc.FValue3.replace("_", "\_");
	}

	openSearchingWin();	
	var strSQL = buildSql(objDoc);
	if (strSQL)
	{
		var win = window.open("SearchRoweDocByType.aspx?sql=" + escape(strSQL) + "&entnum=" + objDoc.EntityNum, "DocumentSearch", "width=800,height=600,scrollbars=1,resizable=1");
		win.focus(win);
		top.AddWindow(win);
	}
	else
		alert("Can not get search criteria.");
}

var aryPanels;
function InitPanelArray()
{
	aryPanels = new Array();
	aryPanels[top.MENU_DOC_SEARCH] = top.fraLeftFrame.document.all.pnlDocSearch;
	aryPanels[top.MENU_PARCEL_SEARCH] = top.fraLeftFrame.document.all.pnlParcelSearch;
	aryPanels[top.MENU_GEODETIC_VIEW] = top.fraLeftFrame.document.all.pnlGeoView;
	aryPanels[top.MENU_GET_VIEW] = top.fraLeftFrame.document.all.pnlGetView;
	aryPanels[top.MENU_MEASURE] = top.fraLeftFrame.document.all.pnlMeasTools;
	aryPanels[top.MENU_MAP_ARCHIVE] = top.fraLeftFrame.document.all.pnlMapArchive;
	aryPanels[top.MENU_HBP_PARCELS] = top.fraLeftFrame.document.all.pnlHBPParcels;
	aryPanels[top.MENU_SHOPPING_CART] = top.fraLeftFrame.document.all.pnlShoppingCart;
	aryPanels[top.MENU_DOWNLOAD] = top.fraLeftFrame.document.all.pnlDownload;
	aryPanels[top.MENU_HELP] = top.fraLeftFrame.document.all.pnlHelp;
	aryPanels[top.MENU_ECOMMERCE] = top.fraLeftFrame.document.all.pnlECom;
	aryPanels[top.MENU_ROWE_PARCELDOC] = top.fraLeftFrame.document.all.pnlRowe;
}
var nPanelIndex = 0;

function SelectMenu(nIndex)
{
	aryPanels[nPanelIndex].style.display = 'none';
	aryPanels[nIndex].style.display = 'inline';

	nPanelIndex = nIndex;

	if (nIndex == top.MENU_SHOPPING_CART) top.ShowShoppingCart();
	else if (nIndex == top.MENU_DOWNLOAD) top.DownloadShopping();
	else if (nIndex == top.MENU_ECOMMERCE) top.GoECommerce();
	else if (nIndex == top.MENU_GEODETIC_VIEW)
	{
		var group = top.FindGroupByName("Horizontal and Vertical Control");
		if (!group.bVisible)
		{
			top.setGroupVisible(group.nGroupIndex, true);
			if (top.vScale > top.g_nMinGPSScale && top.vScale < top.g_nMaxGPSScale)
				top.reloadSVGMap();
		}
	}
	else if (nIndex == top.MENU_HBP_PARCELS)
	{
		var group = top.FindGroupByName("ROWE Parcel Group"); //HBP Parcel Group //090902
		if (!group.bVisible)
		{
			top.setGroupVisible(group.nGroupIndex, true);
			if (top.vScale > 3000 && top.vScale < 100000)
				top.reloadSVGMap();
		}
	}
}

var aryGetViewPanels;
function InitGetViewPanelArray()
{
	aryGetViewPanels = new Array();
	aryGetViewPanels[0] = top.fraLeftFrame.document.all.pnlGetViewByPageAndGrid;
	aryGetViewPanels[1] = top.fraLeftFrame.document.all.pnlGetViewByCity;
	aryGetViewPanels[2] = top.fraLeftFrame.document.all.pnlGetViewByIntersection;
	aryGetViewPanels[3] = top.fraLeftFrame.document.all.pnlGetViewByCoordinate;
}
var nGVPanelIndex = 0;

function SelectGVPanel(nIndex)
{
	aryGetViewPanels[nGVPanelIndex].style.display = 'none';
	aryGetViewPanels[nIndex].style.display = 'inline';
	
	nGVPanelIndex = nIndex;
}

var aryHBPPanels;
function InitHBPPanelArray()
{
	aryHBPPanels = new Array();
	aryHBPPanels[0] = top.fraLeftFrame.document.all.pnlHBPParcelSearch;
	aryHBPPanels[1] = top.fraLeftFrame.document.all.pnlHBPParcelReport;
}

var nHBPPanelIndex = 0;
function SelectHBPPanel(nIndex)
{
	aryHBPPanels[nHBPPanelIndex].style.display = 'none';
	aryHBPPanels[nIndex].style.display = 'inline';
	
	nHBPPanelIndex = nIndex;
}

var aryHBPReports;
function InitHBPReportsArray()
{
	aryHBPReports = new Array();
	aryHBPReports[0] = top.fraLeftFrame.document.all.pnlHBPReport0;
	aryHBPReports[1] = top.fraLeftFrame.document.all.pnlHBPReport1;
}

var nHBPReportsIndex = 0;
function SelectHBPReport(nIndex)
{
	aryHBPReports[nHBPReportsIndex].style.display = 'none';
	aryHBPReports[nIndex].style.display = 'inline';
	
	nHBPReportsIndex = nIndex;
}