var currentYear="2010"


empty= 'void(null)'

onStatusBlank=' onmouseout="window.status=\'\';return true"'+
' onmouseover="window.status=\'\';return true"'+
' onmousemove="window.status=\'\';return true"'

	
function getCookie(name)
{
	var nameValue = ""
	var nStart, nEnd
	nStart=document.cookie.indexOf(name)
	nEnd=document.cookie.indexOf(";",nStart)
	if (nStart == -1)
		return ""
	if (nEnd == -1)
		nEnd=document.cookie.length
		
	nameValue=document.cookie.substring(nStart,nEnd)
	if (nameValue.length == 0)
		return ""
	//add quotes to value then evaluate
	nameValue = nameValue.replace(/=/,"='")
	nameValue += "'"
	eval(nameValue)
	return eval(name)
}



 
function submitForm(s)  
{
	if (s.value=="Submit")
	{
     	s.value = " Sending... ";
	   	return true;
	}     	
	else
	{
     	s.value = "Submit";
		parent.left.document.frmSearch.reset();
     	return false;
	}		
}

function setTableWidth()
{
     if (screen.width < "650")
          return 384
     else if (screen.width < "810")
          return 550
     else
          return 590
}     


function validateQuery(theForm, queryType, subButton)
{    
    var retValue=true;
    var queryName=""
    var queryMessage=""
    var showyear = parseInt(parent.currentYear) - eval("theForm.queryYear.selectedIndex")
    
    //searchString used by "No data to Display" message
     switch (queryType)
     {
     case "tax" :
          retValue=validateLengthTaxMapNo(theForm,"querytax", "map",'Enter complete "Tax Map Number".', 2)
          if (retValue != false)  retValue=validateTaxMapNo(theForm, "map")
          if (retValue != false)  retValue=validateTaxMapNo(theForm, "insert")
          if (retValue != false)  retValue=validateTaxMapNo(theForm, "dblcircle")
          if (retValue != false)  retValue=validateTaxMapNo(theForm, "block")
          if (retValue != false)  retValue=validateTaxMapNo(theForm, "lot")
          if (retValue != false)  retValue=validateTaxMapNo(theForm, "sublot")
          eval("theForm.searchString.value = 'Year ' + showyear + ', ' + theForm.querytax.value")
          break;
     case "taxRange" :
          retValue=validateLengthTaxMapNo(theForm,"queryTaxStart", "map1", '"Start" must be at least 2 characters.', 2)

          if (retValue != false)  retValue=validateTaxMapNo(theForm, "map1")
          if (retValue != false)  retValue=validateTaxMapNo(theForm, "insert1")
          if (retValue != false)  retValue=validateTaxMapNo(theForm, "dblcircle1")
          if (retValue != false)  retValue=validateTaxMapNo(theForm, "block1")
          if (retValue != false)  retValue=validateTaxMapNo(theForm, "lot1")
          if (retValue != false)  retValue=validateTaxMapNo(theForm, "sublot1")

          if (retValue != false)
               retValue=validateLengthTaxMapNo(theForm,"queryTaxEnd", "map2",'"End" must be at least 2 characters.', 2)

          if (retValue != false)  retValue=validateTaxMapNo(theForm, "map2")
          if (retValue != false)  retValue=validateTaxMapNo(theForm, "insert2")
          if (retValue != false)  retValue=validateTaxMapNo(theForm, "dblcircle2")
          if (retValue != false)  retValue=validateTaxMapNo(theForm, "block2")
          if (retValue != false)  retValue=validateTaxMapNo(theForm, "lot2")
          if (retValue != false)  retValue=validateTaxMapNo(theForm, "sublot2")

          eval("theForm.searchString.value = 'Year ' + showyear + ', ' + theForm.queryTaxStart.value")
          eval("theForm.searchString.value += ' to ' ")
          eval("theForm.searchString.value += theForm.queryTaxEnd.value"  )//used in no data message
          break;
     case "property" :
          queryName='queryproperty'
          queryMessage='"Property Address" must be at least 3 characters.'
          queryTextLen=3
          searchFor = new String()
          countPct = 0

          theForm.queryproperty.value = theForm.queryproperty.value.toUpperCase()
          searchFor = theForm.queryproperty.value.toString()
          //count how many astericks or percents signs in searchFor
          for (var i=0; i< searchFor.length; i++)
               if (searchFor.charAt(i) == "*" || searchFor.charAt(i) == "%")
                   countPct++
          //remove asterick when only 1 asterick
          if (countPct == 1)
               searchFor = searchFor.replace(/\*/g,"")
          //convert * to % 
          theForm.queryPropertyHidden.value = searchFor.replace(/\*/g,"%")
          //if only 1 % then remove
          break;
     case "pin" : 
          queryName='querypin'
          queryMessage='"Parcel ID Number" must be at least 3 characters.'
          queryTextLen=3

          searchFor = new String()

          searchFor = theForm.querypin.value.toString()
          searchFor = searchFor.toUpperCase()
          //convert - to blanks
          theForm.queryPinHidden.value =  searchFor.replace(/-/g,"")
          break;
     case "owner" :
          queryName='queryowner'
          queryMessage= '"'+ "Owner's" + ' Name" must be at least 3 characters.'
          queryTextLen=3
          break;
     case "ownerJan1" :
          queryName='queryownerJan1'
          queryMessage='"Owner Name" must be at least 3 characters.'
          queryTextLen=3
          break;
     default :
          break;
     } //end switch case


     if (retValue != false && queryName.length > 0)
            retValue = noDollarSigns(theForm,queryName)

     if (retValue != false && queryName.length > 0)
            retValue = validateLength(theForm,queryName, queryMessage, queryTextLen)

     if (retValue != false && queryName.length > 0)
            retValue = validateNoLeadSpaces(theForm,queryName)
      
     if (retValue != false && queryName.length > 0)
            retValue = validateNoTrailSpaces(theForm,queryName)

          

          
     //when data is sent to server, change the look of submit button 
     if (retValue == true )
     {
          //used in no data message
          if ( queryType != "taxRange" && queryType != "tax"  )
          {
               eval("theForm.searchString.value = " + "'Year ' + showyear + ', '")
               eval("theForm.searchString.value += theForm." + queryName + ".value" )
          }
		  if (parent.webRequest!="weblogis")
				retValue = submitForm(subButton)
     }
           
     return retValue;    


}


function noDollarSigns(theForm, queryName)
{
     var retValue=true
     var strValue=eval("theForm." + queryName + ".value") 
     var i
     
     for (i=0; i<strValue.length; i++)
          if ( strValue.charAt(i) == "$")
               retValue = false
          
     if ( retValue == false)
          alert('Please do not enter $ sign.')

     return retValue
 }


function validateLength(theForm, queryName, queryMessage, queryTextLen)
{
     var retValue=true
     var realSize=0;
     var strValue=eval("theForm." + queryName + ".value") 

     // must be at least queryTextLen chars
     //get length & subtract * or %
     
     for (i=0; i < eval("theForm." + queryName + ".value.length") ; i++)
          if ( strValue.charAt(i) != "*" && strValue.charAt(i) != "%")
             realSize++;
     
     if ( realSize < queryTextLen)
     {
          alert (queryMessage)
          eval("theForm." + queryName +".focus()")
          retValue = false;
     }
     else
         eval("theForm." + queryName + ".value = theForm." + queryName + ".value.toUpperCase()")

     return retValue
 }
 
function validateLengthTaxMapNo(theForm, queryName, queryFocus, queryMessage, queryTextLen)
{
     // must be at least queryTextLen chars
     var retValue=true
     
     //count slashes in TaxMapNo
     cntSlash=0
     strData= eval("theForm." + queryName + ".value")
     for (i=0; i< strData.length; i++)
          if ( strData.charAt(i) != "/")
              cntSlash++;
          
     
     if ( cntSlash < queryTextLen)
     {
          alert (queryMessage)
          eval("theForm." + queryFocus +".focus()")
          retValue = false;
     }
     else
         eval("theForm." + queryName + ".value = theForm." + queryName + ".value.toUpperCase()")

     return retValue
 }

function validateTaxMapNo(theForm, queryName)
{
     var retValue=true
     
     //count slashes in TaxMapNo
     var cntSlash=0
     var strData= eval("theForm." + queryName + ".value")
     var charI=""
     
     strData=strData.toUpperCase()
     for (i=0; i< strData.length; i++)
     {
          charI = strData.charAt(i)
          if (  charI != "/" &&  charI != "-"   &&
                !(charI >= "A" && charI <= "Z" ) &&
                !(charI >= "0" && charI <= "9" ))
          {
              alert("Please do not use: " + charI+" \n\nEnter any of the following: \nA to Z or 0 to 9\n / (slash) or - (dash)")
              eval("theForm." + queryName +".focus()")
              retValue = false;
              i = strData.length;
          }
     }
     
     if (retValue == true)
         eval("theForm." + queryName + ".value = theForm." + queryName + ".value.toUpperCase()")

     return retValue
 }

  
function validateNoLeadSpaces(theForm, queryName)
{
     //find first alpha-numeric
     //then check the characters preceding the first alpha numeric for spaces
     var retValue=true
     newstr = eval("new String(theForm." + queryName +".value)" ) //copy string 
     FirstAlphaNum=0;
     
     for (i=0; i< newstr.length; i++)
          if ( newstr.charAt(i)!== "*" && newstr.charAt(i) != "%" && newstr.charAt(i) != " ")
          {
             FirstAlphaNum=i;
             i=newstr.length;
          }
          
     for (i=0; i< FirstAlphaNum; i++)
          if (newstr.charAt(i)== " ")
          {
               alert ("Leading spaces not permitted.")
               eval("theForm." + queryName + ".focus()")
               retValue = false;
               i=FirstAlphaNum;
          }
     return retValue
}

function validateNoTrailSpaces(theForm, queryName)
{
     //find first alpha-numeric
     //then check the characters preceding the first alpha numeric for spaces
     var retValue=true
     newstr = eval("new String(theForm." + queryName +".value)" ) //copy string 
     LastAlphaNum=0;
     
     for (i=newstr.length-1; i >= 0; i--)
          if ( newstr.charAt(i)!== "*" && newstr.charAt(i) != "%" && newstr.charAt(i) != " ")
          {
             LastAlphaNum=i;
             i=-1;
          }
          
     for (i=newstr.length-1; i > LastAlphaNum; i--)
          if (newstr.charAt(i)== " ")
          {
               alert ("Trailing spaces not permitted.")
               eval("theForm." + queryName + ".focus()")
               retValue = false;
               i=LastAlphaNum;
          }

     return retValue
}

//---------------------

function commaIt(num) 
{
		 num=''+ num						 
     if (num.length > 3) 
     {
          var mod = num.length % 3;
          var output = (mod > 0 ? (num.substring(0,mod)) : '');
          for (i=0 ; i < Math.floor(num.length / 3); i++) 
          {
               if ((mod == 0) && (i == 0))
                    output += num.substring(mod+ 3 * i, mod + 3 * i + 3);
               else
                    output+= ',' + num.substring(mod + 3 * i, mod + 3 * i + 3);
          }
          return output;
     }
     else return num;
}

function commaDec2(num) 
{
	 num=''+ num
	 decimal=".00"
	 //format decimal numbers too
	 for (var i=0; i < num.length; i++)
	 		 if (num.charAt(i) == ".")
			 {
			    decimal=""
			 	  for (var k=i; k <= num.length; k++)
							decimal+=num.charAt(k)
				  if (decimal.length < 3)
					    decimal+="0"							
					break;
			 }

		 num=''+parseInt(num)						 
     if (num.length > 3) 
     {
          var mod = num.length % 3;
          var output = (mod > 0 ? (num.substring(0,mod)) : '');
          for (i=0 ; i < Math.floor(num.length / 3); i++) 
          {
               if ((mod == 0) && (i == 0))
                    output += num.substring(mod+ 3 * i, mod + 3 * i + 3);
               else
                    output+= ',' + num.substring(mod + 3 * i, mod + 3 * i + 3);
          }
          return (output + decimal);
     }
     else return num + decimal;
}

function dateIt(sDate) 
{                         
     //date is in the format yyyy-mm-dd and needs to be mm/dd/yyyy
     if (sDate.length > 0) 
     {
          sYear= sDate.substr(0,4)
          sMon=sDate.substr(5,2)
          sDay=sDate.substr(8,2)
          sDate = sMon + "/" + sDay + "/" + sYear
     }
     return sDate
}

//---------------------

function pinIt(nPin)
{               
     //format of pin number needs dashes:  012 34 5678 901
     return nPin.substr(0,3) + "-" + nPin.substr(3,2) + "-" + nPin.substr(5,4) + "-" + nPin.substr(9,3)
}


function menu(winname, showdefault)
{
	var pd=""
	if (showdefault == "y")
		pd=parent.document
	else if  (typeof parent[winname] == "undefined")
		pd=parent.document
	else						 
		pd=parent[winname].document

	pd.write('<table border="0" cellpadding="0" cellspacing="0" bgcolor="#FFFFFF">'+
		'<tr><td align="left" nowrap bgcolor="#336699" height="25"><font face="verdana,arial,helvetica" size="2" color="#FFFFFF">&nbsp;<b>Loudoun County Assessment '+
		'\& Parcel Database &nbsp;</b><\/font>'+
		'<\/td><\/tr>'+ 
		'<tr><td align="left" nowrap><font face="verdana,arial,helvetica" size="2"><b>')

	if (showdefault != "y")
	{
		pd.write('&nbsp;<a href="/webpdbs" target="_parent">Home<\/a>&nbsp;&nbsp;|&nbsp;&nbsp;')
		if (typeof parent.left != "undefined")  //not weblogis
			pd.write('<a href="/cgi-bin/db2www.exe/webpdbs/re.d2w/LEFT" target="left">Search By<\/a>&nbsp;&nbsp;|&nbsp;&nbsp;')
		else
			pd.write('<a href="/cgi-bin/db2www.exe/webpdbs/re.d2w/INDEX" target="_parent">Search By<\/a>&nbsp;&nbsp;|&nbsp;&nbsp;')
	}
		
	pd.write('<a href="http://www.loudoun.gov/finserv/home.htm" target="_top">Contact Us<\/a>'+
		'</b></font></td></tr><\/table>')
}



function slashes(somestring, makeThisSize)
{
     strSlash=""

     needslashes = makeThisSize - somestring.length
     for (i=0; i < needslashes; i++)
          strSlash = strSlash.concat("/")
     somestring =  strSlash + somestring 
     return somestring
}
 

function mergeTaxMapNo()
{
	if (typeof parent.left != "undefined") 	
	{
      parent.left.document.frmSearch.querytax.value = 
           parent.left.document.frmSearch.map.value + 
           parent.left.document.frmSearch.insert.value + 
           parent.left.document.frmSearch.dblcircle.value + 
           parent.left.document.frmSearch.block.value + 
           parent.left.document.frmSearch.lot.value + 
           parent.left.document.frmSearch.sublot.value;
           
     parent.left.document.frmSearch.querytax.value= parent.left.document.frmSearch.querytax.value.toUpperCase()           
     }
}


function mergeTaxMapNoStart()
{
	if (typeof parent.left != "undefined") 	
	{
      parent.left.document.frmSearch.queryTaxStart.value = 
           parent.left.document.frmSearch.map1.value + 
           parent.left.document.frmSearch.insert1.value + 
           parent.left.document.frmSearch.dblcircle1.value + 
           parent.left.document.frmSearch.block1.value + 
           parent.left.document.frmSearch.lot1.value + 
           parent.left.document.frmSearch.sublot1.value;
           
     parent.left.document.frmSearch.queryTaxStart.value= parent.left.document.frmSearch.queryTaxStart.value.toUpperCase()           
	}
}


function mergeTaxMapNoEnd()
{
	if (typeof parent.left != "undefined") 	
	{
      parent.left.document.frmSearch.queryTaxEnd.value = 
           parent.left.document.frmSearch.map2.value + 
           parent.left.document.frmSearch.insert2.value + 
           parent.left.document.frmSearch.dblcircle2.value + 
           parent.left.document.frmSearch.block2.value + 
           parent.left.document.frmSearch.lot2.value + 
           parent.left.document.frmSearch.sublot2.value;
           
     parent.left.document.frmSearch.queryTaxEnd.value= parent.left.document.frmSearch.queryTaxEnd.value.toUpperCase()           
	}
}


function writeLeftWebPDBS()
{
	var pld=parent.left.document
	
	if (parent.webRequest=="webpdbs")
	{
 		pld.open("text/html")
		pld.write('<html><head>')
		pld.write('<title>Loudoun County Assessment &amp; Parcel Database<\/title>')
		pld.write('<base target="content"><\/head>')
		
		pld.write('<body text="#FFFFFF" bgcolor="#336699" link="#FFFFFF" vlink="#FFFFFF" alink="#FFFFFF" topmargin="5" leftmargin="0" marginwidth="0" marginheight="5" >')
		pld.write('<p align="center"><a href="/cgi-bin/db2www.exe/webpdbs/re.d2w/INDEX" target="_top" title="click here to display search menu">')
		
		
		//if (screen.width < "810") 
			pld.write('<img border="0" src="/webpdbs/sealsmall.gif" width="110" height="110">')
//		else 
	//		pld.write('<img border="0" src="/webpdbs/sealbig.gif" width="140" height="140">')
		
		pld.write('<\/a><br><br>')
	}		

	pld.write('<form name=frmContent>')
	
	if (parent.webRequest=="webpdbs")
	{
		pld.write('<center>')
		alignVal="center"
	}		
	else
		alignVal="left"
	
	pld.write('<table><tr><td align='+ alignVal+ ' nowrap><font face="arial" size="5"><b>Search by:<\/b><\/font><\/td>')
	
	var serverLoc=""
	serverLoc+=location.hostname
	//var bIntranet = (serverLoc.search(/devarcims/i) >= 0  || serverLoc.search(/gisintra1/i) >= 0 || serverLoc.search(/intranet/i) >= 0 || serverLoc.search(/10.2.21.20/i) >= 0)
	//QM 03/27/06 for testing of intrAnet
	var bIntranet = (serverLoc.search(/10.3.8.23/i) >= 0  || serverLoc.search(/gisintra1/i) >= 0 || serverLoc.search(/intranet/i) >= 0 || serverLoc.search(/10.2.21.20/i) >= 0)
	if ( bIntranet == false)
	     pld.write('<br>')

	if (parent.webRequest=="webpdbs")
	{
		if (  bIntranet == true )
		{
	  		 pld.write('<tr><td align='+ alignVal+ ' nowrap><a href="/webpdbs/search.htm?queryType=owner" target="left" onclick="status=\'\';return true" onmouseover="status=\'Search by Owner Name\';return true" onmouseout="status=\'\';return true" ><font face="arial" size="2"><b>Owner\'s Name<\/b><\/font><\/a><\/td>')
			 pld.write('<tr><td align='+ alignVal+ ' nowrap><a href="/webpdbs/search.htm?queryType=ownerJan1" target="left" onclick="status=\'\';return true" onmouseover="status=\'Search by Owner Name as of January 1\';return true" onmouseout="status=\'\';return true" ><font face="arial" size="2"><b>Owner as of Jan 1<\/b><\/font><\/a><\/td>')
		}	     
		pld.write('<tr><td align='+ alignVal+ ' nowrap><a href="/webpdbs/search.htm?queryType=pin" target="left" onclick="status=\'\';return true" onmouseover="status=\'Search by Parcel Identification Number (PIN)\';return true" onmouseout="status=\'\';return true" ><font face="arial" size="2"><b>Parcel ID Number (PIN)<\/b><\/font><\/a><\/td>')
		pld.write('<tr><td align='+ alignVal+ ' nowrap><a href="/webpdbs/search.htm?queryType=property" target="left" onclick="status=\'\';return true" onmouseover="status=\'Search by Property Address\';return true" onmouseout="status=\'\';return true" ><font face="arial" size="2"><b>Property Address<\/b><\/font><\/a><\/td>')
		pld.write('<tr><td align='+ alignVal+ ' nowrap><a href="/webpdbs/search.htm?queryType=tax" target="left" onclick="status=\'\';return true" onmouseover="status=\'Search by Tax Map Number\';return true" onmouseout="status=\'\';return true" ><font face="arial" size="2"><b>Tax Map Number<\/b><\/font><\/a><\/td>')
		pld.write('<tr><td align='+ alignVal+ ' nowrap><a href="/webpdbs/search.htm?queryType=taxRange" target="left" onclick="status=\'\';return true" onmouseover="status=\'Search by Tax Map Number Range\';return true" onmouseout="status=\'\';return true" ><font face="arial" size="2"><b>Tax Map Range<\/b><\/font><\/a><\/td>')

	}
	else if (parent.webRequest=="weblogis")
	{
		if (  bIntranet == true )
		{
  			
		    pld.write('<tr><td nowrap><a href="javascript:parent.empty" onclick="status=\'\';parent.queryType=\'owner\';parent.updateleft();return false;" onmouseover="status=\'Search by Owner Name\';return true" onmousemove="window.status=\'Search by Owner Name\';return true" onmouseout="status=\'\';return true" ><font face="arial" size="2"><b>Owner\'s Name<\/b><\/font><\/a><\/td>')
		    pld.write('<tr><td nowrap ><a href="javascript:parent.empty" onclick="status=\'\';parent.queryType=\'ownerJan1\';parent.updateleft();return false;" onmouseover="status=\'Search by Owner Name as of January 1\';return true" onmousemove="window.status=\'Search by Owner Name as of January 1\';return true" onmouseout="status=\'\';return true" ><font face="arial" size="2"><b>Owner as of Jan 1<\/b><\/font><\/a><\/td>')
		}	     
		pld.write('<tr><td nowrap><a href="javascript:parent.empty" onclick="status=\'\';parent.queryType=\'pin\';parent.updateleft();return false;" onmouseover="status=\'Search by Parcel Identification Number (PIN)\';return true" onmousemove="window.status=\'Search by Parcel Identification Number (PIN)\';return true" onmouseout="status=\'\';return true" ><font face="arial" size="2"><b>Parcel ID Number (PIN)<\/b><\/font><\/a><\/td>')
		pld.write('<tr><td nowrap><a href="javascript:parent.empty" onclick="status=\'\';parent.queryType=\'property\';parent.updateleft();return false;" onmouseover="status=\'Search by Property Address\';return true" onmousemove="window.status=\'Search by Property Address\';return true" onmouseout="status=\'\';return true" ><font face="arial" size="2"><b>Property Address<\/b><\/font><\/a><\/td>')
		pld.write('<tr><td nowrap><a href="javascript:parent.empty" onclick="status=\'\';parent.queryType=\'tax\';parent.updateleft();return false;" onmouseover="status=\'Search by Tax Map Number\';return true" onmousemove="window.status=\'Search by Tax Map Number\';return true" onmouseout="status=\'\';return true" ><font face="arial" size="2"><b>Tax Map Number<\/b><\/font><\/a><\/td>')
		pld.write('<tr><td nowrap><a href="javascript:parent.empty" onclick="status=\'\';parent.queryType=\'taxRange\';parent.updateleft();return false;" onmouseover="status=\'Search by Tax Map Number Range\';return true" onmousemove="window.status=\'Search by Tax Map Number Range\';return true" onmouseout="status=\'\';return true" ><font face="arial" size="2"><b>Tax Map Range<\/b><\/font><\/a><\/td>')
		if (  bIntranet == true )
			pld.write('<tr><td nowrap><a href="javascript:parent.empty" onclick="status=\'\';parent.queryType=\'longitude\';parent.updateleft();return false;" onmouseover="status=\'Search by Longitude and Latitude\';return true" onmousemove="window.status=\'Search by Longitude and Latitude\';return true" onmouseout="status=\'\';return true" ><font face="arial" size="2"><b>Longitude/Latitude<\/b><\/font><\/a><\/td>')
	}
		
	pld.write('<\/table><\/center><\/form>')


	if (parent.webRequest=="webpdbs")
	{
		pld.write('<\/body>')
		pld.writeln('<\/html>')
		pld.close()
	}		
}	
