﻿// JScript File
var detailArray = new Array()

var zoomReqID=0;
var printTable
var results
var arrTable
var parcelArray = new Array()
var singlePoint=null;
var searchstring ="";
function FindAddress(id)
{
  
    mapServices.FindAddress(id,fillDropDown,ontimeout,onerror);
    
}


   
function fillDropDown(response)
{

	var a = new Array();
	a=response.split("|");

			 document.getElementById('ddlStreetNum').options[0] = new Option("ALL", 0, true, true);

	
	
         for(i=0;i<a.length;i++) 
         {		
                  document.getElementById('ddlStreetNum').options[i+1] = new Option(a[i], i, false, false);
		 }
		
}





//sends search string to the server.. 
function FindPositions(string1,string1a,string2,string2a,string3,string3a,string4,string4a)
{	
    mapServices.advancedQuery(string1,string1a,string2,string2a,string3,string3a,string4,string4a,ListPositions,ontimeout,onerror);
}


//input an id.. listpositions is a callback function	
	//receives the xml from the server
	
function ListPositions(response)
{

    //clear out the results of the previous query
    top.mapframe.parcelArray.length = 0;  //uncomment this eventually
    
	
	if (response != null && response.length>1) 
	{

      newResults = true;
	  //loop through the parcels tag to get the info out
	  var arrTable = new Array();
	  parent.postbackframe.document.getElementById('txtQueryString').value = response[0];
		for(var i =1;i<response.length;i++)
		{
			var sr = response[i];
			//create another loop to push the above values into
			var myArray = new Array();
			myArray[0] = "<img src='images/details.gif'/> | getDataDetails('"+sr.parcelid+"',this)";
			myArray[1] = sr.parcelid; //parcedid
			myArray[2] = sr.address; //location
			
			var myDate
			
	            if(sr.saledate!="")
		       { 
		      
		       var vdate = new Date(sr.saledate);
		        myDate =(vdate.getMonth()+1)+"/"+ vdate.getDate()+"/"+ vdate.getYear()
		    }
		       else
		         {
		       myDate ="&nbsp;";
		       }
		     //  if (myDate == "1/11/1111") {
		     //  myDate = " "
		     //  }

			myArray[3] = myDate;
			myArray[4] =  new String(sr.saleprice);  //saleprice
			myArray[5] = new String(sr.appraisedvalue); //value;
			myArray[6] = parseFloat(sr.size)+" Acres"; //size		    
		   	var qry1 = new query(myArray[1],myArray[3],myArray[4],myArray[5],myArray[6],parseFloat(sr.x),parseFloat(sr.y))
			top.mapframe.parcelArray.push(qry1);
			
			//now push the first array to the arrTable array
			arrTable.push(myArray);
		}
			printTable= arrTable
		//	pointTable = parcelArray
	
	top.mapframe.buildResultsTable(arrTable)
//	top.mapframe.setPoints();
	 } 
	 else
	  {
  //alert(parcels.length)
    alert("No records found")
    //clear the points out here...
    top.mapframe.clearPoints();
   }

 }



//creates the query string..
function downloadCSV() {
var queryString = parent.postbackframe.document.getElementById('txtQueryString').value
var sFeatures = "width=400,height=400,top=20,left=50,toolbar=no,menubar=no,scrollbars=yes,status=no,resizable=yes";
window.open('csvQuery.htm?query='+queryString,'',sFeatures);
}




// this function is called when a user clicks on the info button of one of the result items------------------------------------------------------------------------
function getDataDetails(pid,cell)
{
var id = cell.parentNode.id
var tbl = cell.parentNode.parentNode;
var idx = cell.parentNode.rowIndex;


//alert(idx + " is the index of the row")
if(tbl.rows[idx+1] && tbl.rows[idx+1].id == "detailRow"+id)
	{
		if(tbl.rows[idx+1].style.display =="none")
		{
			tbl.rows[idx+1].style.display ="block"
		}
	else
		{
			tbl.rows[idx+1].style.display ="none"
		}
	}
	else
	{ 
	
	    var wait = document.createElement("img")
		wait.id = "wait";
		
		wait.style.position = "absolute";
		wait.style.top = cell.parentNode.style.top;
		wait.style.left = cell.parentNode.style.left;
		wait.src = "images/wait.gif"
		rootCell = cell;
		cell.appendChild(wait);
		
	FindDetailPositions(pid)
		
	}

}
function FindDetailPositions(id)
{	
	mapServices.getDetails(id,ListDetailPositions,ontimeout,onerror);
}

function ListDetailPositions(response)
{

     var newid = rootCell.id;
     var id = rootCell.parentNode.id;  
     var tbl = rootCell.parentNode.parentNode;
     var idx = rootCell.parentNode.rowIndex;
 	    var vRow = tbl.insertRow(rootCell.parentNode.rowIndex+1);
		var vs = document.createElement("span");
		vRow.setAttribute("id","detailRow"+ id)
		vs.style.width="618px"
		var vc = vRow.insertCell(0);
		vc.colSpan = 7;
		vs.className="details"
		vs.setAttribute("id","details"+ response[0]);
		vc.appendChild(vs)
		
		detailArray[response.parcelid] = response;
	
	    if(vs)
	    {
              var dtls = "<table style='width:620px' border='0' cellspacing='0' cellpadding='0' id=\"detailTable"+response.parcelid+"\">"
              dtls += "<tr class='rowDetails'><td style='width:100px'><b>Parcel ID:</b></td>"
               dtls += " <td style='width:100px' id='pid"+response.parcelid+"' class='detailText'>"+response.parcelid+"</td>"
               
               dtls += " <td style='width:100px' ><b>Parcel Address: </b></td>"
               dtls += " <td style='width:100px' id='address"+response.address+"' class='detailText' >"+response.address+"</td>"
               dtls += " <td style='width:100px'>&nbsp;</td>"
             dtls += " </tr>"
              
              dtls += "<tr class='rowDetails'>"
              dtls += "  <td><b>Owner Name: </b></td>"
              dtls += "  <td id='Name"+response.name+"' class='detailText'>"+response.owner+"</td>"
             
                   
	            if(response.saledate!="")
		        {
		         var vdate = new Date(response.saledate);
		       
		        var myDate =(vdate.getMonth()+1)+"/"+ vdate.getDate()+"/"+ vdate.getYear()
		        }
		        else
		         {
		        myDate ="&nbsp;";
		       }
		       
              dtls += "  <td><b>Sale Date: </b></td>"
              dtls += "  <td style='width:100px' id='appBuild"+myDate+"' class='detailText'>"+myDate+"</td>"
               dtls += " <td width='118' rowspan='6' colspan='2' style='border-left: solid 1px #999' id='tools"+response.parcelid+"'><h1>Tools</h1>"
          
            //add x and y coord here to zoom to the parcel locations
             dtls +="<img src = 'images/Find.gif' onmousedown=\"zoomToRequest("+response.x+","+response.y+",'"+response.parcelid+"')\" class='imageButton'/>"
             dtls +="<img src = 'images/Print2.gif' onmousedown=\"createDetailPage('"+response.parcelid+"')\"   class='imageButton'/>"
         
             dtls += " </td></tr>"
             dtls += " <tr class='rowDetails'>";
              dtls +=   " <td  valign='top'><b>Owner Address:</b></td>"
             dtls += "   <td id='Address1"+response.address1+"'class='detailText'>"+response.address1+"</td>"
              dtls += "  <td><b>Sale Price: </b></td>"
              dtls += "  <td id='price"+response.saleprice+"' class='detailText'>$"+CommaFormatted(response.saleprice)+"</td>"
             dtls += " </tr>"
             
             dtls += " <tr class='rowDetails'>"
             dtls +=   " <td  valign='top'><b>&nbsp;</b></td>"
             dtls += "  <td id='map' class='detailText'>"+response.address3+"</td>"
              
             dtls += "   <td><b>Size:</b></td>"
             dtls += "   <td id='appOut"+response.size+"' class='detailText'>"+response.size+" Acres</td>" 
             dtls += " </tr>"
             
            dtls += "  <tr class='rowDetails'>"
             dtls += "   <td><b>Map:</b></td>"
             dtls += "   <td id='block"+" "+"' class='detailText'>"+response.map+"</td>"
             
               dtls += " <td><b>Appriased Building:</b></td>"
              dtls += "  <td id='test' class='detailText'>$"+CommaFormatted(response.appbuilding)+"</td>"

             dtls += " </tr>"
             dtls += " <tr class='rowDetails'>"
              dtls += "   <td><b>Block:</b></td>"
             dtls += "   <td id='lot"+" "+"' class='detailText'>"+response.block+"</td>"
             
                dtls += " <td><b>Appraised Extra Features:</b></td>"
              dtls += "  <td id='test2' class='detailText'>$"+CommaFormatted(response.appextra)+"</td>"

            dtls += "  </tr>"
            dtls += " <tr class='rowDetails'>"
               dtls += " <td><b>Lot:</b></td>"
               dtls += " <td id='lot"+" "+"' class='detailText'>"+response.lot+"</td>"
               
               dtls += "  <td><b>Appraised Land:</b></td>"
               dtls += " <td  id='Description"+response.appland+"' class='detailText'>$"+CommaFormatted(response.appland)+"</td>"
              //dtls += "  <td colspan='2'>&nbsp;</td>"
              dtls += "</tr>"
              
             dtls += " <tr class='rowDetails'>"
              dtls += " <td><b>Topo Desc:</b></td>"
               dtls += " <td id='topodesc"+response.desc+"' class='detailText'>&nbsp;"+response.desc+"</td>"

    
             dtls += "   <td><b>Appraised Outfeatures:</b></td>"
             dtls += "   <td id='block"+response.appout+"' class='detailText'>$"+CommaFormatted(response.appout)+"</td>"
              dtls += " <td><b>&nbsp;</b></td>"
              dtls += " </tr>"
             
             dtls += " <tr class='rowDetails'>"
               dtls += " <td><b>&nbsp;</b></td>"
              dtls += "  <td id='test' class='detailText'>&nbsp;</td>"

              dtls += "   <td><b>Total Value:</b></td>"
             dtls += "   <td id='value"+response.appraised+"' class='detailText'>$"+CommaFormatted(response.appraised)+"</td>"
              dtls += " <td><b>&nbsp;</b></td>"
              dtls += " </tr>"
             

            		
               dtls += "</table>"
            
                vs.innerHTML = dtls;
                rootCell.removeChild(document.getElementById("wait"));
	}
}

function showHideResults()
	{
		parent.currenttool = "";
		var dv = document.getElementById('spnResults');
		if(dv.style.display =="block") {
			dv.style.display = "none";
		}else{
			dv.style.display = "block";
		}
	}


function zoomToRequest(X,Y,reqID)
{
clearPoints();
zoomReqID = reqID;
var resp = new Array();
var loc= new Object()
loc.X = X;
loc.Y = Y;
//drawPoints = true
singlePoint = reqID;
calcExtents(loc);
}


//function to print the individual request details---------------------------------------------

 function createDetailPage(pid) 
    {   

    var resp = detailArray[pid];
    var dtls=""
    dtls += "<table class='fwFrame' style='width:620px' border='0' cellspacing='0' cellpadding='3' id='detailTable' >"
	  dtls+= " <tr><p class='printtitle' colspan='4' align='center'>Detail List</p> </tr>"
	    
              dtls += "<tr class='rowDetails'><td style='width:100px'><b>Parcel ID:</b></td>"
               dtls += " <td style='width:100px' id='pid' class='detailText'>"+resp.parcelid+"</td>"
               
               dtls += " <td style='width:100px' colspa='3'><b>Parcel Address: </b></td>"
               dtls += " <td style='width:100px' id='address' class='detailText'>"+resp.address1+"</td>"
             dtls += " </tr>"
              
              dtls += "<tr class='rowDetails'>"
              dtls += "  <td><b>Owner Name: </b></td>"
              dtls += "  <td id='Name' class='detailText'>"+resp.owner+"</td>"
             
              dtls += "  <td><b>Sale Date: </b></td>"
              
               
           if(resp.saledate!="")
		        {
		         var vdate = new Date(resp.saledate);
		       
		        var myDate =(vdate.getMonth()+1)+"/"+ vdate.getDate()+"/"+ vdate.getYear()
		        }
		        else
		         {
		        myDate ="&nbsp;";
		        }
              
              dtls += "  <td style='width:100px' id='appBuild' class='detailText'>"+myDate+"</td>"
               
         
             dtls += " </td></tr>"
             dtls += " <tr class='rowDetails'>";
              dtls +=   " <td rowspan='2' valign='top'><b>Owner Address:</b></td>"
             dtls += "   <td id='Address1'class='detailText'>"+resp.address1+"</td>"
              dtls += "  <td><b>Sale Price: </b></td>"
              dtls += "  <td id='price' class='detailText'>$"+CommaFormatted(resp.saleprice)+"</td>"
             dtls += " </tr>"
             
             dtls += " <tr class='rowDetails'>"
           // dtls += "   <td></td>"
             dtls += "  <td id='map' class='detailText'>"+resp.address3+"</td>"
              
             dtls += "   <td><b>Size:</b></td>"
             dtls += "   <td id='size' class='detailText'>"+resp.size+" Acres</td>" 
             dtls += " </tr>"
             
            dtls += "  <tr class='rowDetails'>"
             dtls += "   <td><b>Map:</b></td>"
             dtls += "   <td id='block' class='detailText'>"+CommaFormatted(resp.map)+"</td>"
             
               dtls += " <td><b>Appraised Building:</b></td>"
              dtls += "  <td id='test' class='detailText'>$"+CommaFormatted(resp.appbuilding)+"</td>"

             dtls += " </tr>"
             dtls += " <tr class='rowDetails'>"
              dtls += "   <td><b>Block:</b></td>"
             dtls += "   <td id='lot' class='detailText'>"+CommaFormatted(resp.block)+"</td>"
             
                dtls += " <td><b>Appraised Extra Features:</b></td>"
              dtls += "  <td id='test2' class='detailText'>$"+CommaFormatted(resp.appextra)+"</td>"
              
              
            

            dtls += "  </tr>"
            dtls += " <tr class='rowDetails'>"
               dtls += " <td><b>Lot:</b></td>"
               dtls += " <td id='lot' class='detailText'>"+CommaFormatted(resp.lot)+"</td>"
               
               dtls += "  <td><b>Appraised Land:</b></td>"
               dtls += " <td  id='land' class='detailText'>$"+CommaFormatted(resp.appland)+"</td>"
              //dtls += "  <td colspan='2'>&nbsp;</td>"
              dtls += "</tr>"
              
             dtls += " <tr class='rowDetails'>"
              dtls += " <td><b>Topodesc:</b></td>"
               dtls += " <td id='topodesc' class='detailText'>"+resp.desc+"</td>"

    
             dtls += "   <td><b>Appraised Outfeatures:</b></td>"
             dtls += "   <td id='out' class='detailText'>$"+CommaFormatted(resp.appout)+"</td>"
              dtls += " </tr>"
             
             dtls += " <tr class='rowDetails'>"
               dtls += " <td><b></b></td>"
              dtls += "  <td id='test' class='detailText'>&nbsp;</td>"

              dtls += "   <td><b>Total Value:</b></td>"
             dtls += "   <td id='value' class='detailText'>$"+CommaFormatted(resp.appraised)+"</td>"
              dtls += " </tr>"
              dtls+="</table>"

 var disp_setting="toolbar=yes,location=no,directories=yes,menubar=yes,resizable=yes,"; 
      disp_setting+="scrollbars=yes,width=650, height=600, left=100, top=25"; 
 // var content_value = document.getElementById("print_content").innerHTML; 
  
  var docprint=window.open("","",disp_setting); 
   docprint.document.open(); 
   docprint.document.write('<html><head>'); 
   docprint.document.write('<LINK media="all" href="_includes/styles.css" type="text/css" rel="stylesheet">')
   docprint.document.write('</head><body>');          
   docprint.document.write(dtls);          
   docprint.document.write('</body></html>'); 
   docprint.document.close(); 
   docprint.focus();
}
	

//closes out the results window
function closeResults() {
	var e = document.getElementById("Results");
	e.style.display = 'none';

}

function showSearchString(sender)
{
var spnsearchstring = document.getElementById("spnSearchString");
spnsearchstring.innerHTML = "<strong>Search:</strong><br>" + searchstring;
sender.onmouseout = hideSearchString;
spnsearchstring.style.display = "block";

}

function hideSearchString()
{
var spnsearchstring = document.getElementById("spnSearchString");
spnsearchstring.style.display = "none";
}


function CommaFormatted(amount)
{
	var delimiter = ","; // replace comma if desired
	var a = amount.split('.',2)
	var d = a[1];
	var i = parseInt(a[0]);
	if(isNaN(i)) { return ''; }
	var minus = '';
	if(i < 0) { minus = '-'; }
	i = Math.abs(i);
	var n = new String(i);
	var a = [];
	while(n.length > 3)
	{
		var nn = n.substr(n.length-3);
		a.unshift(nn);
		n = n.substr(0,n.length-3);
	}
	if(n.length > 0) { a.unshift(n); }
	n = a.join(delimiter);
	 amount = n; 
	//amount = n + '.' + d; 
	amount = minus + amount;
	return amount;
}
