	
	function isEven(num) {
  		return !(num % 2);
	}
	
	tablesArray=null;
	tableLoading=0;
	pf=false;
	
	cZones=0;
	
	function countryZoneShowMulti(z){
		div = document.getElementById('countryZone');
		div.getElementsByTagName('div')[3].className="unscroller";
		div.style.height = '1px';
		div.style.marginTop = '0px';
		
		for(x=1; x<(cZones+2); x++){
			
			document.getElementById('czone'+x).style.display = 'none';
			
			if(document.getElementById('czone'+x).innerHTML != ''){
				//alert(document.getElementById('czone'+x).innerHTML)
				temp = document.getElementById('czone'+x).innerHTML;
				document.getElementById('czone'+x).innerHTML = '';
				//alert(document.getElementById('czone'+x).innerHTML)
			}

		}
		//alert(temp)
		document.getElementById('czone'+z).innerHTML = temp;
		document.getElementById('czone'+z).style.display = 'block';
		countryZoneShow();
	}
	
	function countryZoneShow(){
		div = document.getElementById('countryZone');
		if(div.style.height!='auto'){
			div.style.height = 'auto';
			div.style.marginTop = '35px';
			div.getElementsByTagName('div')[3].style.height="250px";
			div.getElementsByTagName('div')[3].className="scroller";
		}else{
			div.getElementsByTagName('div')[3].className="unscroller";
			div.style.height = '1px';
			div.style.marginTop = '0px';
		}
		document.location="#cz";
	}
	
	
	function tableAligner(){
		for(x=0; x<tablesArray.length; x++){
			tHeight = parseInt(document.getElementById("table" + x + "Container").getElementsByTagName('table')[0].offsetHeight);
			
			if(tHeight<250){
				
				document.getElementById("table" + x + "Container").getElementsByTagName('div')[1].style.height=tHeight;
			}
		}
	}
	
	
	function loadTableCont(tableArr){
		tablesArray = tableArr;
		loadController();
	}

	function loadController(){
		if(tableLoading <= (tablesArray.length-1)){
			requestInit(tablesArray[tableLoading].dataSource,"table" + tableLoading + "Container")	
		}else{
			tableAligner();
		}
	}


	function requestInit(url,dest){
		if (xml_request != null){
			xml_request.abort();
			xml_request = null;
		}
	
		if (window.XMLHttpRequest) { // Mozilla, Safari, ...
    		xml_request = new XMLHttpRequest();
    		
		} else if (window.ActiveXObject) { // IE
			
   		 	xml_request = new ActiveXObject("Microsoft.XMLHTTP");
   		 	
		}
		
		if(url == "thumbs.html"){
			xml_request.overrideMimeType('text/xml');
		}
		
		xml_request.onreadystatechange = function(e) {xml_loaded(e, xml_request, dest);}
	
	
	
		xml_request.open("GET", url);
	
		//xml_request.setRequestHeader("Cache-Control", "no-cache");
		
		xml_request.send(null);
	
	}
	
	
	
	var xml_request = null;
	function xml_loaded (e, request, dest){
		
		if(request.readyState == 4){
			tempString = request.responseText;
			
			tableRows = tempString.split('\n');
			
				if(tablesArray[tableLoading].caption != 'Price Groups by Country'){
					tableRows.splice(1,1);
					tableRows.pop();
					/*			
					tableRows[0] = '<caption>' + tableRows[0].substr(0,tableRows[0].indexOf(',,')) + '</caption>';
					tableRows[0] = tableRows[0].replace(/"/g , '');
					*/	
					tableRows.shift();
				}
			
			
			tableRows[0] = '<tr><th class="firstCell">' + (tableRows[0].replace(/,/g , '</th><th>')) + '</th></tr>';
			tempArray = tableRows[0].split('<th');
			cellCount = tempArray.length-1;
			
			for(x=1; x<tableRows.length; x++){
				
				
				tableRows0Arr = tableRows[x].split(',');
				if(tableRows0Arr[0].length == 1 && tablesArray[tableLoading].caption == 'Price Groups by Country'){
					tableRows0Arr[0] = '<a name="#cz" title="back to alphabetical links"></a><a name="' + tableRows0Arr[0] + '"></a>' + tableRows0Arr[0];
					tableRows[x] = tableRows0Arr.join(',');
				}
				
				
				tableRows[x] = '<tr' + (isEven(x) ? ' class="evenRow"' : ' class="oddRow"') + '><td class="firstCell">' + (tableRows[x].replace(/,/g , '</td><td>')) + '</td></tr>';
				
				tempStr1 = tableRows[x].substr(0, (tableRows[x].lastIndexOf('<td') + 3));
				tempStr2 = tableRows[x].substr((tableRows[x].lastIndexOf('<td') + 3), (tableRows[x].indexOf('</td></tr>') + 10));
				tableRows[x] = tempStr1 + ' class="lastCell"' + tempStr2;

				tempArray2 = tableRows[x].split('<td');
				cellcount2 =  tempArray2.length-1;
				
				if(cellcount2==1){
					tableRows[x] = tempArray2[0] + '<td colspan="' + cellCount + '"' + tempArray2[1]; 
				}
				
			}
			
			
			//alert(tableRows[20]);
			if(tablesArray[tableLoading].caption.indexOf('<')>=0){
				tableSummary = tablesArray[tableLoading].caption.substr(0,tablesArray[tableLoading].caption.indexOf('<'));
			}else{
				tableSummary = tablesArray[tableLoading].caption
			}
			
			newString= '<table cellpadding="0" cellspacing="0" border="0" width="100%" summary="' + tableSummary +'">' + (pf==true ? "<caption class='caption'>" + tablesArray[tableLoading].caption + "</caption>" : "") + (tableRows.join(''));
			
			newString += '<tr><td colspan="' + cellCount + '" class="spacerRow"><div></div></td></tr>'
			
			newString += '</table>';
			
			captionLink ="";
			if(tablesArray[tableLoading].captionLink.linkText!=""){
				
					captionLink =" <span>(<a href='" + tablesArray[tableLoading].captionLink.url + "'" + (tablesArray[tableLoading].captionLink.url.indexOf('cript:') < 0 ? " target='_new'" : "") + ">" + tablesArray[tableLoading].captionLink.linkText + "</a>)</span>";
			}
			
			document.getElementById(dest).getElementsByTagName('div')[0].innerHTML = tablesArray[tableLoading].caption + captionLink;
			
			document.getElementById(dest).getElementsByTagName('div')[1].innerHTML = newString;
			
			printFriend = document.createElement('div');
			printFriend.style.textAlign='right';
			printFriend.style.margin='4px 0px 0px 0px';
			printFriend.style.padding='0px';
			printFriend.style.display='block';
			printFriend.style.whiteSpace='nowrap';
			printFriend.className='fontStyleC';
			printFriend.style.width= (document.getElementById(dest).className.indexOf(1)>=0 ? '528px' : '236px');
			printFriend.innerHTML="<a href='javascript:popWin(\"usps_prices_printTable.html?csvFile=" + tablesArray[tableLoading].dataSource + '&csvTitle=' + tableSummary + "&pfTitle=" + tablesArray[tableLoading].pfTitle + "\");'>Printer Friendly</a>";
			document.getElementById(dest).nextSibling.appendChild(printFriend);
			
			if(pf==true){
				document.title=unescape(tablesArray[tableLoading].pfTitle);
			}
			
			tableLoading++;
			loadController();
		}
		
	}
	
	
	function popWin(st){
			m=Math.round(Math.random() * 2000);
			popWin1(st, 'someName'+m, 'width=600,height=375,resizable=0,menubar=0,toolbar=0,location=0,personalbar=0,status=0,scrollbars=1');
		}

function popWin1(theURL,winName,features) {m=Math.round(Math.random() * 2000); var mywin = window.open(theURL,winName + m,features); mywin.focus();}