var sTOC='';
var gTabNum = 0;
function dumpInfo(s)
{
	var w=window.open('','dump','resizable=1,scrollbars=1');
	var d=w.document;
	d.writeln('<html><head><body><textarea style="width:600px;height:400px">');
	d.writeln(s);
	d.writeln('</textarea></body></html>');
	d.close();
}

function clkMapTab1(d)
{
	var t=getTaxType();
	if(t=='F') clkMapTab(d,'F',1,2,1);
	else if(t=='P') clkMapTab(d,'P',3,4,1);
	else if(t=='S') clkMapTab(d,'S',1,3,1);
}

function clkMapTab(d,f,i,t,e,anchor)
{
	var i,ii,z=d.getElementById("aZInfo");
	
	if ( sGeoPt != "")
	{
		var parts = sGeoPt.split(',');
		zoomToIt(parts[0], parts[1], parts[2]);
	}
	else if(null!=z){
		z=decodeURI(z.href);
		i=z.indexOf('('); 
		ii=z.indexOf(')');
		z=z.substring(i+1,ii);
		ii=z.split(',');
		//zoomToIt(ii[0], ii[1], ii[2]);
		zoomToExtent(ii[0], ii[1], ii[2], ii[3], ii[4]);
	}
	else 
	{
		chgTab(d,f,i,t,e,anchor);
	}
}
function chgTab(d,f,i,t,e,anchor)
{
	var n;
	bMap=0;
	gTabNum = i;
	for(n=0;n<t;n++){
		d.getElementById("tblTab"+n).className=((i==n)?"":"Un")+"selected";
		d.getElementById("imgTab"+n+"0").src="/images/tabs/tabL"+((i==n)?"1":"0")+".gif";
		d.getElementById("imgTab"+n+"1").src="/images/tabs/tabR"+((i==n)?"1":"0")+".gif";
		d.getElementById("oDivBox"+n).style.display=((i==n)?"":"none");
	}
	if ( typeof aAddressSearch != "undefined" )
		aAddressSearch.className = "UnSel";
	if ( typeof aLocationCode != "undefined" )
		aLocationCode.className = "UnSel";
	if ( typeof aMapSearch != "undefined" )
		aMapSearch.className = "UnSel";
	if (typeof aSTR != "undefined" )
		aSTR.className = "UnSel";
	if (typeof aLatLon != "undefined" )
		aLatLon.className = "UnSel";
	if (typeof aMap != "undefined" )
		aMap.className = "UnSel";
	if ( typeof anchor != "undefined" )
		anchor.className = "Sel";

    //Sales tax map tab is second to last position
    if (TaxType == 'S')
		bMap|=(i==(t-2));
	//All other tax types have the map tab in the last position
	else 
	    bMap|=(i==(t-1));
		
	n=('F'==f && 0==i)|('P'==f && 3>i)|('S'==f && 2>i);
	d.getElementById("oDivDes").style.display=(n?"":"none");
	
	if(e){
		if('S'==TaxType){
			d.getElementById('tblRet').style.display='none';
			d.getElementById('spInfo').style.display=(0==i)?'':'none';
		}else{
			d.getElementById('spResult').innerHTML='';
			if('P'==TaxType)	d.getElementById('tblResult').style.display='none';
		}
	}else{
		if('S'==TaxType && (0<i)){
			d.getElementById('spInfo').style.display='none';
		}
	}
	
	if (document.title == 'Sales Tax Lookup Tool')
	    parent.autoIframe('MapFrame', i==1?1421:538, i==1?657:536);
	else if (document.title == 'Utilities Apportionment Lookup Tool')
	    parent.autoIframe('MapFrame', (i==1|i==3)?901:538, (i==1|i==3)?677:566);
    else if (document.title == 'Forest tax rate lookup')
        parent.autoIframe('MapFrame', (i==1)?821:421, 657);
    else
        parent.autoIframe('MapFrame');
}

function chkKey(e)
{
	var k=e.keyCode;
	if(0==k) k=e.which;
	if(13==k)return 2;
	else if((48>k && k!=45 && k!=46) || k>57){
		if(e.keyCode)event.returnValue=false;
		return 0;
	}
	return 1;
}

function chkCurrency(e)
{
	//Allows: 0-9  and decimal points, commas and $

	var k=e.keyCode;
	if(0==k) k=e.which;
	if(13==k)return 2;
	else if((48>k && k!=46 && k!=44 && k!=36) || k>57){
		if(e.keyCode)event.returnValue=false;
		return 0;
	}
	return 1;
}

function checkEnter(e,d,f)
{
	var k=e.keyCode;
	if(0==k) k=e.which;
	if(13==k){getRpt(d,f);}
}

function setLL(d,lt,lg)
{
	d.getElementById('txtLat').value=lt;
	d.getElementById('txtLong').value=lg;
	getRpt(d,2);
}
function getItsRpt(d,id,x,y)
{
	var a=document.getElementById('aAddr'+id),ad=a.innerHTML;
	if(""!=ad)ad=ad.replace(/,/g,"[-]");
	sGeoPt=ad+','+x+','+y;
	getRpt(d,-1);
}
function getRpt(d,f)
{
   	var s="Src="+f;

	if(('P'==TaxType && f==1) || ('F'==TaxType && f==0)){
		s+="<|>Twn="+d.getElementById("cboTown").value;
		s+="<|>Rng="+d.getElementById("cboRange").value+d.getElementById("cboRngDir").value;
		s+="<|>Sec="+d.getElementById("cboSection").value;
	}else if('P'==TaxType && f==2){
		s+="<|>Lat="+d.getElementById('txtLat').value+"<|>Long="+d.getElementById('txtLong').value;
	}else if(('P'==TaxType && f==0) || ('S'==TaxType && f==0)){
		var a,c,z,z1;
		a=escape(d.getElementById('txtAddr').value.replace(/&/,"and"));
		c=d.getElementById('txtCity').value;
		z=d.getElementById('txtZip').value;
		z1=d.getElementById('txtZip1').value;

		if ( 'S'==TaxType )
		{
			var t = d.getElementById('txtTaxable').value;
			
			if (t.length != 0)
			{         
                var x, decCnt = 0, dolsgnCnt = 0;
                
                //Check for duplicate decimal points and $ signs
	            for(i = 0 ; i < t.length; i++)
	            {
	               x = t.substr(i, 1); 
	               if (x == ".")
	               {
	                  decCnt = decCnt + 1;
	                  if (decCnt > 1){alert("Only one decimal point is allowed."); return;} 
	               }
	               else if (x == "$")
	               {
	                  dolsgnCnt = dolsgnCnt + 1;
	                  if (dolsgnCnt > 1){alert("Only one dollar sign is allowed."); return;} 
	               }        
	            }
	            // strip out the commas and $ signs	        
	            t = t.replace(/^\$|,/g,""); 
	            t = t.replace(/,/g,""); 
	            
	        }
	        s+="<|>TAXABLE="+t;			
		}
		if(""!=a)
		{
			// the server side code will display the message.
			//if(""==z){alert("Please enter a Zip code.");return;}
		}
		else{
			if(""==c && ""==z && ""==z1) {alert("Please enter a valid Address and Zip code, or a valid Zip Code with a ZIP+4.");return;}
			else if(""==c && ""==z && ""!=z1){alert("Please enter a Zip code.");return;}
		}

		s+="<|>Addr="+a+"<|>City="+c;
		s+="<|>Zip="+z+"<|>Zip1="+z1;
	}else if('S'==TaxType){
		s+="<|>TAXABLE="+d.getElementById("txtTaxable").value;
		if(f==1){
			s+="<|>LCode="+d.getElementById('txtLCode').value;
		}else if(f==2){
			s+="<|>Lat="+d.getElementById('txtLat').value+"<|>Long="+d.getElementById('txtLong').value;
		} else if(f==-1){
			s+="<|>XY="+sGeoPt;
		}
	}

	if('P'==TaxType) s+="<|>Year="+d.getElementById("cboYears").value;
	if('P'==TaxType && f==-1)		s+="<|>XY="+sGeoPt;
	s+=getSInfo(d);
	s+=getTolerance();
    parent.document.getElementById("WorkFrame").src=gappPath+"/TaxReport.aspx?TaxType="+TaxType+"<|>"+s;
 
    //Set the cursor to the wait status while report is being loaded.
    //parent.document.body.style.cursor="wait"; 
    //document.body.style.cursor="wait"; 
}
function clrResult(){
	document.getElementById('spResult').style.display='none';
	parent.autoIframe('MapFrame');
}
function RefRpt(){
	var i,d=parent.MapFrame.document,s=d.getElementById("spResult").innerHTML;
	if(""!=s){
		for(i=0;i<4;i++){
			s=d.getElementById("oDivBox"+i).style.display;
			if(""==s){
				if(3!=i)parent.MapFrame.getRpt(d,i);
				else if(3==i && ""!=sGeoPt){
					s='src=iden<|>eL='+eL+'<|>eT='+eT+'<|>eR='+eR+'<|>eB='+eB;
					s+='<|>oeL='+eL+'<|>oeT='+eT+'<|>oeR='+eR+'<|>oeB='+eB;
					s+=getSInfo(document);
					sendRequest('WF',s);
				}
				break;
			}
		}
	}
}
function getSInfo(d)
{
	var s='';
	if('S'==TaxType){
		s+="<|>Mon="+d.getElementById("cboMonth").value;
		s+="<|>SYear="+d.getElementById("cboYears").value;
	}
	return s;
}
function dbgme(){
	var i=0;
}

function chngtoDefaultCursor()
{
   //Change the cursor back to default pointer after getRpt() runs or report is updated. 
  //parent.document.body.style.cursor='default';
  //document.body.style.cursor='default';
}