<!--
var dummy=0;
var _app = navigator.appName;
var filterdata=new Array();
var filterpopn=new Array();
var croll=0;
var codeTable=new Array();
var var2by2;
document.title=phisHead[word]+" "+modulename[word]+" "+enqHead[word];
var graphGpVarRowLabel;
var graphGpVarColLabel;
var graphCatRowDesc=new Array();
var graphCatColDesc=new Array();
var graphCatRowCode=new Array();
var graphCatColCode=new Array();
var graphStatcntLabel;
var graphCellvar=new Array();
var graphCellvarDisplay=new Array();
var graphCatRowSubtot=new Array();
var graphCatColSubtot=new Array();
var graphCatRowSubtotDisplay=new Array();
var graphCatColSubtotDisplay=new Array();
var chartTitle;
var xDoc;
var xmlData;
var txtData
var compChk;
if (_app=='Microsoft Internet Explorer') compChk=setInterval("testComplete()",1000)
var minYear;
var maxYear;
var dataDate;
var gis=false;
var mapTitle;
var mapHtml;
for (var x=0;x<codesetVar.length;x++) if (codesetVar[x]==54) gis=true
var critStr="";
var graphGrandTot;
var compJsLoad;
var _timer1,_timer2;
if (note1[word].length==0) noteHead[word]=""
var codeHash=new Array();
var hashCrit=new Array();
var indexArr=new Array();
var nowDate=new Date();
for (x=0;x<criteriafield.length;x++) hashCrit[criteriafield[x]]=x
if (_app!='Microsoft Internet Explorer') dataloaded=true

function codeTableHash(){
var ff;
var opv;
for (ff=0;ff<fieldCount;ff++){
if (codeTable[codesetVar[ff]]){
codeHash[ff]=[];
for (opv=0;opv<codeTable[codesetVar[ff]].length;opv++) codeHash[ff][codeTable[codesetVar[ff]][opv][0]]=opv;
} 
}
}


function verifySupport(xFile) {
if (document.implementation && document.implementation.createDocument) {
	xDoc = document.implementation.createDocument("","theXdoc",null);
} else if (typeof ActiveXObject !="undefined") {
	if (document.getElementById("msxml").async) {
		xDoc = new ActiveXObject("Msxml.DOMDocument");
	}
}
if (xDoc && typeof xDoc.load !="undefined") {
	xDoc.load(xFile);
	return true;
} else alert(optBrowser[word])
return false;
}

function testComplete(){
try {
if (_app=='Microsoft Internet Explorer' && dataloaded==true) clearInterval(compChk)
var pElement=document.createElement("P");
var msgNode=document.createTextNode(dDateLabel[word]+dataDate);
pElement.appendChild(msgNode);
document.getElementsByTagName("H1")[0].removeChild(document.getElementsByTagName("H1")[0].childNodes[1]);
document.getElementsByTagName("H1")[0].appendChild(pElement);
checker();
codeTableHash();
alert(readyMsg[word]+"\n"+(dDateLabel[word]+dataDate));
dataloaded=true;
return dataloaded;
}
catch (ex) {
//alert (ex);
if (_app=='Microsoft Internet Explorer') dataloaded==false
return dataloaded;
}
}

function init(xFile) {
var pElement=document.createElement("P");
var imgNode=document.createElement("IMG");
imgNode.setAttribute("src","images/loading.gif");
var msgNode=document.createTextNode(" "+loadWaitMsg[word]);
pElement.appendChild(imgNode);
pElement.appendChild(msgNode);
document.getElementsByTagName("H1")[0].appendChild(pElement);
try {
if (_app=='Microsoft Internet Explorer') {
if (dataloaded==true) {
if (dataDate==undefined) dataDate = "30/6/2046"
testComplete();
}
} else {
if (phisdata.length>0) {
dataloaded=true;
if (dataDate==undefined) dataDate = "30/6/2046"
testComplete();
}
}
}
catch (ex) {
dataloaded==false;
}
if (gis==true) {
var gisCue=document.createElement("p");
gisCue.appendChild(document.createTextNode(" ("+mapAvailableLabel[word]+") "));
gisCue.style.color=gisPromptColor;
gisCue.style.fontSize=16;
gisCue.style.fontStyle="italic";
document.getElementsByTagName("h2")[1].appendChild(gisCue);
var newIcon=document.createElement("img");
newIcon.src="/phisweb/images/en_new.gif";
if (nowDate<expNewMapDate) document.getElementsByTagName("h2")[1].lastChild.appendChild(newIcon)
var cHead=document.createElement("h2");
cHead.appendChild(document.createTextNode(chartHead[word]));
document.getElementById("graphChoose").insertBefore(cHead,document.getElementById("graphChoose").childNodes[0]);
}
}

function callApp1(){
}

function callApp2(){
}

function checker() {
var yrFld = "f"+yearScopeVar;
var yrArr = new Array();
var roll;
var croll;
var dum;
if (_app=='Microsoft Internet Explorer') {
mstxt.Sort="+"+yrFld;
mstxt.Reset();
txtData=mstxt.recordset;
txtData.moveFirst();
minYear=txtData.Fields(yearScopeVar).value;
txtData.moveLast();
maxYear=txtData.Fields(yearScopeVar).value;
} else {
phisdata.sort(sortyear);
minYear=phisdata[0][yearScopeVar];
maxYear=phisdata[parseInt(phisdata.length)-1][yearScopeVar];
}
if (codesetVar[indexFld]==22) for (croll=minYear;croll<=maxYear;croll++) indexArr[croll]=[]
else for (croll=0;croll<codeTable[codesetVar[indexFld]].length;croll++) indexArr[codeTable[codesetVar[indexFld]][croll][0]]=[]
for (croll=0;croll<phisdata.length;croll++) {
indexArr[phisdata[croll][indexFld]].push(croll);
}
for (croll=0;croll<critCount;croll++) optSetup(croll)
for (croll=0;croll<critCount;croll++) resetCrit(croll)
}

function writeCritLabel(cbo){
if (varFieldName[criteriafield[cbo]] && codesetVar[criteriafield[cbo]]==78) document.write(varFieldName[criteriafield[cbo]][word]+"&nbsp&nbsp&nbsp&nbsp<SPAN style='font-family: Arial; color: blue; vertical-align: sub; font-weight:normal' onclick='openIcdPanel();'>["+searchDxButton[word]+"]</SPAN>")
else if (varFieldName[criteriafield[cbo]]) document.write(varFieldName[criteriafield[cbo]][word])
}

function optSetup(cbo){
if (!isNaN(criteriafield[cbo])){
var opv;
document.forms["criteria"].elements[cbo].multiple=critMultSelect[cbo];
switch (codesetVar[criteriafield[cbo]])
{
  case 10:
	document.forms["criteria"].elements[cbo].options.length=0;
	for (opv=0;opv<codeTable[codesetVar[(criteriafield[cbo])]].length;opv++){
	document.forms["criteria"].elements[cbo].options[opv]= new Option(codeTable[codesetVar[criteriafield[cbo]]][opv][parseInt(word)+1], codeTable[codesetVar[(criteriafield[cbo])]][opv][0], false, false);
	}
	break;

  case 22:
// to know the year scope of data
	document.forms["criteria"].elements[cbo].options.length=0;
	for (opv=minYear;opv<=maxYear;opv++){
	document.forms["criteria"].elements[cbo].options[opv-minYear]= new Option(opv, opv, false, false);
	}
	break;

  case 54:
	document.getElementById("dcd_hk").label=optGp[codesetVar[(criteriafield[cbo])]][0][word];
	document.getElementById("dcd_k").label=optGp[codesetVar[(criteriafield[cbo])]][1][word];
	document.getElementById("dcd_nt").label=optGp[codesetVar[(criteriafield[cbo])]][2][word];
	document.getElementById("dcd_oth").label=optGp[codesetVar[(criteriafield[cbo])]][3][word];
	for (opv=0;opv<codeTable[codesetVar[(criteriafield[cbo])]].length;opv++){
	document.forms["criteria"].elements[cbo].options[opv].text=codeTable[codesetVar[(criteriafield[cbo])]][opv][parseInt(word)+1];
	document.forms["criteria"].elements[cbo].options[opv].value=codeTable[codesetVar[(criteriafield[cbo])]][opv][0];
	}
	if (document.forms["criteria"].elements[cbo].options.length!=codeTable[codesetVar[(criteriafield[cbo])]].length) {
	document.forms["criteria"].elements[cbo].options.length=codeTable[codesetVar[(criteriafield[cbo])]].length;
	}
	break;

  default:
	document.forms["criteria"].elements[cbo].options.length=0;
	for (opv=0;opv<codeTable[codesetVar[(criteriafield[cbo])]].length;opv++){
	var newOpt = document.createElement("option");
	newOpt.text=codeTable[codesetVar[(criteriafield[cbo])]][opv][parseInt(word)+1];
	newOpt.value=codeTable[codesetVar[(criteriafield[cbo])]][opv][0];
	document.forms["criteria"].elements[cbo].options.add(newOpt,opv);
	document.forms["criteria"].elements[cbo].options[parseInt(opv)+1]=null;
	}
	break;

}

}
}

function resetCrit(cbo){
document.forms["criteria"].elements[cbo].selectedIndex=-1;
if (masterCrit[cbo]==true) {
var csroll;
for (csroll=0;csroll<critRelation[cbo].length;csroll++){
var cboname="cbo"+critRelation[cbo][csroll];
document.getElementById(cboname).options.length=0;
}
}
remindSubmit();
}

function selAll(cbo){
var opv;
for (opv=0;opv<document.forms["criteria"].elements[cbo].options.length;opv++){
document.forms["criteria"].elements[cbo].options[opv].selected=true;
}
remindSubmit();
}

function selReset(cbo){
var opv;
optSetup(cbo);
}

function delCrit(){
var del;
for (del=critCount;del<(document.forms["criteria"].elements.length)/3;del++){
document.forms["criteria"].elements[del].style.display="none";
document.forms["criteria"].elements[parseInt(del*2)+parseInt((document.forms["criteria"].elements.length)/3)].style.display="none";
document.forms["criteria"].elements[parseInt(del*2)+parseInt((document.forms["criteria"].elements.length)/3)+1].style.display="none";
document.forms["criteria"].getElementsByTagName("TD")[del].style.backgroundColor="transparent";
document.forms["criteria"].getElementsByTagName("TD")[parseInt(del)+5].style.backgroundColor="transparent";
document.forms["criteria"].getElementsByTagName("TD")[parseInt(del)+10].style.backgroundColor="transparent";
}
}

function disableButton(){
for (del=0;del<critCount;del++){
//alert(document.forms["criteria"].elements[parseInt(del*2)+parseInt((document.forms["criteria"].elements.length)/3)].type);
if (critMultSelect[del]==false) document.forms["criteria"].elements[parseInt(del*2)+parseInt((document.forms["criteria"].elements.length)/3)].disabled=true
}
var croll;
for (croll=0;croll<critCount;croll++){
if (masterCrit[croll]==true) {
var csroll;
for (csroll=0;csroll<critRelation[croll].length;csroll++){
var cboname="cbo"+critRelation[croll][csroll];
document.getElementById(cboname).options.length=0;
}
}
}
}

function cbochange(cbo){
var opv;
remindSubmit();
if (masterCrit[cbo]==true) {
var csroll;
for (csroll=0;csroll<critRelation[cbo].length;csroll++){
var cboname="cbo"+critRelation[cbo][csroll];
document.getElementById(cboname).options.length=0;

switch (codesetVar[criteriafield[critRelation[cbo][csroll]]])
{
  case 22:
// to know the year scope of data
	var maxDataYear;
	if (critScope[codesetVar[criteriafield[cbo]]][codesetVar[criteriafield[critRelation[cbo][csroll]]]][getselections(criteria.elements[cbo])[0]][1]<maxYear) maxDataYear=critScope[codesetVar[criteriafield[cbo]]][codesetVar[criteriafield[critRelation[cbo][csroll]]]][getselections(criteria.elements[cbo])[0]][1]
	else maxDataYear=maxYear
	for (opv=critScope[codesetVar[criteriafield[cbo]]][codesetVar[criteriafield[critRelation[cbo][csroll]]]][getselections(criteria.elements[cbo])[0]][0];opv<=maxDataYear;opv++){
	document.getElementById(cboname).options[opv-critScope[codesetVar[criteriafield[cbo]]][codesetVar[criteriafield[critRelation[cbo][csroll]]]][getselections(criteria.elements[cbo])[0]][0]]= new Option(opv, opv, false, false);
	}
	break;

  default:
	for (opv=0;opv<critScope[codesetVar[criteriafield[cbo]]][codesetVar[criteriafield[critRelation[cbo][csroll]]]][getselections(criteria.elements[cbo])[0]].length;opv++) {
	document.getElementById(cboname).options[opv]= new Option(codeTable[codesetVar[(criteriafield[critRelation[cbo][csroll]])]][codeHash[criteriafield[critRelation[cbo][csroll]]][critScope[codesetVar[criteriafield[cbo]]][codesetVar[criteriafield[critRelation[cbo][csroll]]]][getselections(criteria.elements[cbo])[0]][opv]]][parseInt(word)+1], critScope[codesetVar[criteriafield[cbo]]][codesetVar[criteriafield[critRelation[cbo][csroll]]]][getselections(criteria.elements[cbo])[0]][opv], false, false);

	}
	break;

}

}
}

}

function clearresult(){
result1.innerHTML="";
result2.innerHTML="";
result3.innerHTML="";
resultG.innerHTML="";
resultM.innerHTML="";
hideGraph();
resultGall="";
chartTitle="";
mapTitle="";
seasonButton.innerHTML="";
statButton();
showGraph.disabled=true;
graphStatcntLabel="";
graphGpVarRowLabel="";
graphGpVarColLabel="";
graphCatRowDesc.length=0;
graphCatColDesc.length=0;
graphCellvar.length=0;
graphCellvarDisplay.length=0;
graphCatRowCode.length=0;
graphCatColCode.length=0;
graphCatRowSubtot.length=0;
graphCatColSubtot.length=0;
graphCatRowSubtotDisplay.length=0;
graphCatColSubtotDisplay.length=0;
}

function iefilter(){
var croll;
var csroll;
critStr="<TABLE><TR><TH COLSPAN=21><U>"+critHeader[word]+"</U></TD></TR><BR>";
var critDescArray=new Array();
var selCritStr=new Array();
var selCritLabelStr=new Array();
var cFilterExpr="";
for(var x=0;x<criteriafield.length;x++)
{
var cFilterSubexpr=submitcriteria(this,criteria.elements[x].id,"f"+criteriafield[x]);
if (cFilterExpr=="") cFilterExpr=cFilterSubexpr
else cFilterExpr=cFilterExpr +" & " +cFilterSubexpr
}
//alert (cFilterExpr);
mstxt.object.filter=cFilterExpr;
mstxt.Reset();
//alert (mstxt.recordset.recordCount);
for (croll=0;croll<critCount;croll++){
selCritStr[croll]=getselections(criteria.elements[croll]);
selCritLabelStr[croll]=getselectionsLabel(criteria.elements[croll]);
if (codesetVar[criteriafield[croll]]==78) {
critDescArray[croll]="";
for (csroll=0;csroll<selCritStr[croll].length;csroll++) {
critDescArray[croll]+= selCritLabelStr[croll][csroll]+" ("+codeTable[78][codeHash[criteriafield[croll]][selCritStr[croll][csroll]]][4]+")<BR>";
}
} else critDescArray[croll]=selCritLabelStr[croll].join("@").split("@").join(", ")
var inBracket="";
if (codesetVar[criteriafield[croll]]==78) inBracket=("("+icdName[word]+") ").split(" ").join("&nbsp&nbsp&nbsp<BR>")
critStr+="<TR><TH ALIGN=RIGHT VALIGN=TOP>"+varFieldName[criteriafield[croll]][word]+" : <BR>"+inBracket+"</TH><TD NOWRAP WIDTH=600 COLSPAN=20>"+critDescArray[croll]+"</TD></TR>";
}
critStr+="</TABLE>";
if (popnbase==true){
filterpopn.length=0;
var critDescArray=new Array();
var roll;
var csroll;
croll=0;
var critArray=new Array();
for (croll=0;croll<popnCal;croll++){
if (popnCrit[croll]!=999) critArray[croll]="@"+getselections(criteria.elements[hashCrit[popnCrit[croll]]]).join("@")+"@"
else critArray[croll]="@@"
}

var iCounter = 0;
var CritString = "";

for (roll=0;roll<phispopn.length;roll++) {
	CritString = "";
	for(iCounter=0;iCounter<popnCal;iCounter++)
		CritString += "critArray["+(iCounter)+"].indexOf(\"@\"+phispopn[roll]["+(iCounter)+"]+\"@\")!=-1 && ";
	CritString = CritString.substring(0,CritString.length - 3);
	//alert (CritString);
if (eval(CritString)) {
filterpopn.push(phispopn[roll]);
}
}
}

}

function jsfilter(){
filterdata=[];
critStr="<TABLE><TR><TH COLSPAN=21><U>"+critHeader[word]+"</U></TD></TR><BR>";
var critDescArray=new Array();
var roll;
var csroll;
croll=0;
var critArray=new Array();
var matchArray;
var selCritStr=new Array();
var selCritLabelStr=new Array();

for (croll=0;croll<critCount;croll++){
selCritStr[croll]=getselections(criteria.elements[croll]);
selCritLabelStr[croll]=getselectionsLabel(criteria.elements[croll]);
critArray[croll]="@"+selCritStr[croll].join("@")+"@";
if (codesetVar[criteriafield[croll]]==78) {
critDescArray[croll]="";
for (csroll=0;csroll<selCritStr[croll].length;csroll++) {
critDescArray[croll]+= selCritLabelStr[croll][csroll]+" ("+codeTable[78][codeHash[criteriafield[croll]][selCritStr[croll][csroll]]][4]+")<BR>";
}
} else critDescArray[croll]=selCritLabelStr[croll].join("@").split("@").join(", ")
var inBracket="";
if (codesetVar[criteriafield[croll]]==78) inBracket=("("+icdName[word]+") ").split(" ").join("&nbsp&nbsp&nbsp<BR>")
critStr+="<TR><TH ALIGN=RIGHT VALIGN=TOP>"+varFieldName[criteriafield[croll]][word]+" : <BR>"+inBracket+"</TH><TD NOWRAP WIDTH=600 COLSPAN=20>"+critDescArray[croll]+"</TD></TR>";
}
critStr+="</TABLE>";

if (popnbase==true){
filterpopn.length=0;
var critDescArray=new Array();
var roll;
var csroll;
croll=0;
var critArray2=new Array();
for (croll=0;croll<popnCal;croll++){
if (popnCrit[croll]!=999) critArray2[croll]="@"+getselections(criteria.elements[hashCrit[popnCrit[croll]]]).join("@")+"@"
//if (popnCrit[croll]!=999) critArray2[croll]="@"+getselections(criteria.elements[hashCrit[popnCrit[croll]]]).join("@")+"@"
else critArray2[croll]="@@"
}
for (roll=0;roll<phispopn.length;roll++) {
	CritString = "";
	for(iCounter=0;iCounter<popnCal;iCounter++)
		CritString += "critArray["+(iCounter)+"].indexOf(\"@\"+phispopn[roll]["+(iCounter)+"]+\"@\")!=-1 && ";
	CritString = CritString.substring(0,CritString.length - 3);
if (eval(CritString)) {
filterpopn.push(phispopn[roll]);
}
}
}

var selAllBln="true ";
var selCritBln=new Array();
for (croll=0;croll<critCount;croll++) {
selCritBln[croll]=(criteria.elements[croll].length==selCritStr[croll].length);
selAllBln=selAllBln && selCritBln[croll];
}
if (selAllBln==true) {
filterdata=phisdata;
return;
}

var indexSelected=new Array();
indexSelected=[];
for (croll=0;croll<selCritStr[hashCrit[indexFld]].length;croll++) indexSelected=indexSelected.concat(indexArr[selCritStr[hashCrit[indexFld]][croll]])

switch (hashCrit[indexFld])
{
case 0:

	switch (selCritBln.toString())
	{	
	case "false,true":
	case "false,true,true":
	case "false,true,true,true":
	case "false,true,true,true,true":
	case "false,true,true,true,true,true":
	for (roll=0;roll<indexSelected.length;roll++) filterdata.push(phisdata[indexSelected[roll]])
	break;

	default:

	switch (critCount)
	{
	case 1:
	for (roll=0;roll<indexSelected.length;roll++) filterdata.push(phisdata[indexSelected[roll]])
	break;

	case 2:
	for (roll=0;roll<indexSelected.length;roll++) {
	if (critArray[1].indexOf("@"+phisdata[indexSelected[roll]][(criteriafield[1])]+"@")!=-1) {
	filterdata.push(phisdata[indexSelected[roll]]);
	}
	}
	break;

	case 3:
	for (roll=0;roll<indexSelected.length;roll++) {
	if (critArray[1].indexOf("@"+phisdata[indexSelected[roll]][(criteriafield[1])]+"@")!=-1 && critArray[2].indexOf("@"+phisdata[indexSelected[roll]][(criteriafield[2])]+"@")!=-1) {
	filterdata.push(phisdata[indexSelected[roll]]);
	}
	}
	break;

	case 4:
	for (roll=0;roll<indexSelected.length;roll++) {
	if (critArray[1].indexOf("@"+phisdata[indexSelected[roll]][(criteriafield[1])]+"@")!=-1 && critArray[2].indexOf("@"+phisdata[indexSelected[roll]][(criteriafield[2])]+"@")!=-1 && critArray[3].indexOf("@"+phisdata[indexSelected[roll]][(criteriafield[3])]+"@")!=-1) {
	filterdata.push(phisdata[indexSelected[roll]]);
	}
	}
	break;

	case 5:
	for (roll=0;roll<indexSelected.length;roll++) {
	if (critArray[1].indexOf("@"+phisdata[indexSelected[roll]][(criteriafield[1])]+"@")!=-1 && critArray[2].indexOf("@"+phisdata[indexSelected[roll]][(criteriafield[2])]+"@")!=-1 && critArray[3].indexOf("@"+phisdata[indexSelected[roll]][(criteriafield[3])]+"@")!=-1 && critArray[4].indexOf("@"+phisdata[indexSelected[roll]][(criteriafield[4])]+"@")!=-1) {
	filterdata.push(phisdata[indexSelected[roll]]);
	}
	}
	break;
	
	case 6:
	for (roll=0;roll<indexSelected.length;roll++) {
	if (critArray[1].indexOf("@"+phisdata[indexSelected[roll]][(criteriafield[1])]+"@")!=-1 && critArray[2].indexOf("@"+phisdata[indexSelected[roll]][(criteriafield[2])]+"@")!=-1 && critArray[3].indexOf("@"+phisdata[indexSelected[roll]][(criteriafield[3])]+"@")!=-1 && critArray[4].indexOf("@"+phisdata[indexSelected[roll]][(criteriafield[4])]+"@")!=-1&& critArray[5].indexOf("@"+phisdata[indexSelected[roll]][(criteriafield[5])]+"@")!=-1) {
	filterdata.push(phisdata[indexSelected[roll]]);
	}
	}
	break;
	
	case 7:
	for (roll=0;roll<indexSelected.length;roll++) {
	if (critArray[1].indexOf("@"+phisdata[indexSelected[roll]][(criteriafield[1])]+"@")!=-1 && critArray[2].indexOf("@"+phisdata[indexSelected[roll]][(criteriafield[2])]+"@")!=-1 && critArray[3].indexOf("@"+phisdata[indexSelected[roll]][(criteriafield[3])]+"@")!=-1 && critArray[4].indexOf("@"+phisdata[indexSelected[roll]][(criteriafield[4])]+"@")!=-1&& critArray[5].indexOf("@"+phisdata[indexSelected[roll]][(criteriafield[5])]+"@")!=-1 && critArray[6].indexOf("@"+phisdata[indexSelected[roll]][(criteriafield[6])]+"@")!=-1) {
	filterdata.push(phisdata[indexSelected[roll]]);
	}
	}
	break;

	}
	}
break;

case 1:

	switch (selCritBln.toString())
	{	
	case "true,false":
	case "true,false,true":
	case "true,false,true,true":
	case "true,false,true,true,true":
	case "true,false,true,true,true,true":
	for (roll=0;roll<indexSelected.length;roll++) filterdata.push(phisdata[indexSelected[roll]])
	break;

	default:

	switch (critCount)
	{
	case 2:
	for (roll=0;roll<indexSelected.length;roll++) {
	if (critArray[0].indexOf("@"+phisdata[indexSelected[roll]][(criteriafield[0])]+"@")!=-1) {
	filterdata.push(phisdata[indexSelected[roll]]);
	}
	}
	break;

	case 3:
	for (roll=0;roll<indexSelected.length;roll++) {
	if (critArray[0].indexOf("@"+phisdata[indexSelected[roll]][(criteriafield[0])]+"@")!=-1 && critArray[2].indexOf("@"+phisdata[indexSelected[roll]][(criteriafield[2])]+"@")!=-1) {
	filterdata.push(phisdata[indexSelected[roll]]);
	}
	}
	break;

	case 4:
	for (roll=0;roll<indexSelected.length;roll++) {
	if (critArray[0].indexOf("@"+phisdata[indexSelected[roll]][(criteriafield[0])]+"@")!=-1 && critArray[2].indexOf("@"+phisdata[indexSelected[roll]][(criteriafield[2])]+"@")!=-1 && critArray[3].indexOf("@"+phisdata[indexSelected[roll]][(criteriafield[3])]+"@")!=-1) {
	filterdata.push(phisdata[indexSelected[roll]]);
	}
	}
	break;

	case 5:
	for (roll=0;roll<indexSelected.length;roll++) {
	if (critArray[0].indexOf("@"+phisdata[indexSelected[roll]][(criteriafield[0])]+"@")!=-1 && critArray[2].indexOf("@"+phisdata[indexSelected[roll]][(criteriafield[2])]+"@")!=-1 && critArray[3].indexOf("@"+phisdata[indexSelected[roll]][(criteriafield[3])]+"@")!=-1 && critArray[4].indexOf("@"+phisdata[indexSelected[roll]][(criteriafield[4])]+"@")!=-1) {
	filterdata.push(phisdata[indexSelected[roll]]);
	}
	}
	break;
	
	case 6:
	for (roll=0;roll<indexSelected.length;roll++) {
	if (critArray[1].indexOf("@"+phisdata[indexSelected[roll]][(criteriafield[1])]+"@")!=-1 && critArray[2].indexOf("@"+phisdata[indexSelected[roll]][(criteriafield[2])]+"@")!=-1 && critArray[3].indexOf("@"+phisdata[indexSelected[roll]][(criteriafield[3])]+"@")!=-1 && critArray[4].indexOf("@"+phisdata[indexSelected[roll]][(criteriafield[4])]+"@")!=-1&& critArray[5].indexOf("@"+phisdata[indexSelected[roll]][(criteriafield[5])]+"@")!=-1) {
	filterdata.push(phisdata[indexSelected[roll]]);
	}
	}
	break;
	
	case 7:
	for (roll=0;roll<indexSelected.length;roll++) {
	if (critArray[1].indexOf("@"+phisdata[indexSelected[roll]][(criteriafield[1])]+"@")!=-1 && critArray[2].indexOf("@"+phisdata[indexSelected[roll]][(criteriafield[2])]+"@")!=-1 && critArray[3].indexOf("@"+phisdata[indexSelected[roll]][(criteriafield[3])]+"@")!=-1 && critArray[4].indexOf("@"+phisdata[indexSelected[roll]][(criteriafield[4])]+"@")!=-1&& critArray[5].indexOf("@"+phisdata[indexSelected[roll]][(criteriafield[5])]+"@")!=-1 && critArray[6].indexOf("@"+phisdata[indexSelected[roll]][(criteriafield[6])]+"@")!=-1) {
	filterdata.push(phisdata[indexSelected[roll]]);
	}
	}
	break;

	}
	}
break;

case 2:

	switch (selCritBln.toString())
	{	
	case "true,true,false":
	case "true,true,false,true":
	case "true,true,false,true,true":
	case "true,true,false,true,true,true":
	for (roll=0;roll<indexSelected.length;roll++) filterdata.push(phisdata[indexSelected[roll]])
	break;

	default:
	switch (critCount)
	{
	case 3:
	for (roll=0;roll<indexSelected.length;roll++) {
	if (critArray[0].indexOf("@"+phisdata[indexSelected[roll]][(criteriafield[0])]+"@")!=-1 && critArray[1].indexOf("@"+phisdata[indexSelected[roll]][(criteriafield[1])]+"@")!=-1) {
	filterdata.push(phisdata[indexSelected[roll]]);
	}
	}
	break;

	case 4:
	for (roll=0;roll<indexSelected.length;roll++) {
	if (critArray[0].indexOf("@"+phisdata[indexSelected[roll]][(criteriafield[0])]+"@")!=-1 && critArray[1].indexOf("@"+phisdata[indexSelected[roll]][(criteriafield[1])]+"@")!=-1 && critArray[3].indexOf("@"+phisdata[indexSelected[roll]][(criteriafield[3])]+"@")!=-1) {
	filterdata.push(phisdata[indexSelected[roll]]);
	}
	}
	break;

	case 5:
	for (roll=0;roll<indexSelected.length;roll++) {
	if (critArray[0].indexOf("@"+phisdata[indexSelected[roll]][(criteriafield[0])]+"@")!=-1 && critArray[1].indexOf("@"+phisdata[indexSelected[roll]][(criteriafield[1])]+"@")!=-1 && critArray[3].indexOf("@"+phisdata[indexSelected[roll]][(criteriafield[3])]+"@")!=-1 && critArray[4].indexOf("@"+phisdata[indexSelected[roll]][(criteriafield[4])]+"@")!=-1) {
	filterdata.push(phisdata[indexSelected[roll]]);
	}
	}
	break;
	
	case 6:
	for (roll=0;roll<indexSelected.length;roll++) {
	if (critArray[1].indexOf("@"+phisdata[indexSelected[roll]][(criteriafield[1])]+"@")!=-1 && critArray[2].indexOf("@"+phisdata[indexSelected[roll]][(criteriafield[2])]+"@")!=-1 && critArray[3].indexOf("@"+phisdata[indexSelected[roll]][(criteriafield[3])]+"@")!=-1 && critArray[4].indexOf("@"+phisdata[indexSelected[roll]][(criteriafield[4])]+"@")!=-1&& critArray[5].indexOf("@"+phisdata[indexSelected[roll]][(criteriafield[5])]+"@")!=-1) {
	filterdata.push(phisdata[indexSelected[roll]]);
	}
	}
	break;
	
	case 7:
	for (roll=0;roll<indexSelected.length;roll++) {
	if (critArray[1].indexOf("@"+phisdata[indexSelected[roll]][(criteriafield[1])]+"@")!=-1 && critArray[2].indexOf("@"+phisdata[indexSelected[roll]][(criteriafield[2])]+"@")!=-1 && critArray[3].indexOf("@"+phisdata[indexSelected[roll]][(criteriafield[3])]+"@")!=-1 && critArray[4].indexOf("@"+phisdata[indexSelected[roll]][(criteriafield[4])]+"@")!=-1&& critArray[5].indexOf("@"+phisdata[indexSelected[roll]][(criteriafield[5])]+"@")!=-1 && critArray[6].indexOf("@"+phisdata[indexSelected[roll]][(criteriafield[6])]+"@")!=-1) {
	filterdata.push(phisdata[indexSelected[roll]]);
	}
	}
	break;

	}
	}
break;

case 3:

	switch (selCritBln.toString())
	{	
	case "true,true,true,false":
	case "true,true,true,false,true":
	case "true,true,true,false,true,true":
	for (roll=0;roll<indexSelected.length;roll++) filterdata.push(phisdata[indexSelected[roll]])
	break;

	default:

	switch (critCount)
	{
	case 4:
	for (roll=0;roll<indexSelected.length;roll++) {
	if (critArray[0].indexOf("@"+phisdata[indexSelected[roll]][(criteriafield[0])]+"@")!=-1 && critArray[1].indexOf("@"+phisdata[indexSelected[roll]][(criteriafield[1])]+"@")!=-1 && critArray[2].indexOf("@"+phisdata[indexSelected[roll]][(criteriafield[2])]+"@")!=-1) {
	filterdata.push(phisdata[indexSelected[roll]]);
	}
	}
	break;

	case 5:
	for (roll=0;roll<indexSelected.length;roll++) {
	if (critArray[0].indexOf("@"+phisdata[indexSelected[roll]][(criteriafield[0])]+"@")!=-1 && critArray[1].indexOf("@"+phisdata[indexSelected[roll]][(criteriafield[1])]+"@")!=-1 && critArray[2].indexOf("@"+phisdata[indexSelected[roll]][(criteriafield[2])]+"@")!=-1 && critArray[4].indexOf("@"+phisdata[indexSelected[roll]][(criteriafield[4])]+"@")!=-1) {
	filterdata.push(phisdata[indexSelected[roll]]);
	}
	}
	break;
	
	case 6:
	for (roll=0;roll<indexSelected.length;roll++) {
	if (critArray[0].indexOf("@"+phisdata[indexSelected[roll]][(criteriafield[0])]+"@")!=-1 && critArray[1].indexOf("@"+phisdata[indexSelected[roll]][(criteriafield[1])]+"@")!=-1 && critArray[2].indexOf("@"+phisdata[indexSelected[roll]][(criteriafield[2])]+"@")!=-1 && critArray[3].indexOf("@"+phisdata[indexSelected[roll]][(criteriafield[3])]+"@")!=-1&& critArray[5].indexOf("@"+phisdata[indexSelected[roll]][(criteriafield[5])]+"@")!=-1) {
	filterdata.push(phisdata[indexSelected[roll]]);
	}
	}
	break;
	
	case 7:
	for (roll=0;roll<indexSelected.length;roll++) {
	if (critArray[1].indexOf("@"+phisdata[indexSelected[roll]][(criteriafield[1])]+"@")!=-1 && critArray[2].indexOf("@"+phisdata[indexSelected[roll]][(criteriafield[2])]+"@")!=-1 && critArray[3].indexOf("@"+phisdata[indexSelected[roll]][(criteriafield[3])]+"@")!=-1 && critArray[4].indexOf("@"+phisdata[indexSelected[roll]][(criteriafield[4])]+"@")!=-1&& critArray[5].indexOf("@"+phisdata[indexSelected[roll]][(criteriafield[5])]+"@")!=-1 && critArray[6].indexOf("@"+phisdata[indexSelected[roll]][(criteriafield[6])]+"@")!=-1) {
	filterdata.push(phisdata[indexSelected[roll]]);
	}
	}
	break;

	}
	}
break;

case 4:
	
	switch (selCritBln.toString())
	{	
	case "true,true,true,true,false":
	case "true,true,true,true,false,true":
	for (roll=0;roll<indexSelected.length;roll++) filterdata.push(phisdata[indexSelected[roll]])
	break;
	
	default:
	
	switch (critCount)
	{
	case 5:
	for (roll=0;roll<indexSelected.length;roll++) {
	if (critArray[0].indexOf("@"+phisdata[indexSelected[roll]][(criteriafield[0])]+"@")!=-1 && critArray[1].indexOf("@"+phisdata[indexSelected[roll]][(criteriafield[1])]+"@")!=-1 && critArray[2].indexOf("@"+phisdata[indexSelected[roll]][(criteriafield[2])]+"@")!=-1 && critArray[4].indexOf("@"+phisdata[indexSelected[roll]][(criteriafield[4])]+"@")!=-1) {
	filterdata.push(phisdata[indexSelected[roll]]);
	}
	}
	break;
	
	case 6:
	for (roll=0;roll<indexSelected.length;roll++) {
	if (critArray[0].indexOf("@"+phisdata[indexSelected[roll]][(criteriafield[0])]+"@")!=-1 && critArray[1].indexOf("@"+phisdata[indexSelected[roll]][(criteriafield[1])]+"@")!=-1 && critArray[2].indexOf("@"+phisdata[indexSelected[roll]][(criteriafield[2])]+"@")!=-1 && critArray[3].indexOf("@"+phisdata[indexSelected[roll]][(criteriafield[3])]+"@")!=-1 && critArray[5].indexOf("@"+phisdata[indexSelected[roll]][(criteriafield[5])]+"@")!=-1) {
	filterdata.push(phisdata[indexSelected[roll]]);
	}
	}
	break;
	
	case 7:
	for (roll=0;roll<indexSelected.length;roll++) {
	if (critArray[0].indexOf("@"+phisdata[indexSelected[roll]][(criteriafield[0])]+"@")!=-1 && critArray[1].indexOf("@"+phisdata[indexSelected[roll]][(criteriafield[1])]+"@")!=-1 && critArray[2].indexOf("@"+phisdata[indexSelected[roll]][(criteriafield[2])]+"@")!=-1 && critArray[3].indexOf("@"+phisdata[indexSelected[roll]][(criteriafield[3])]+"@")!=-1&& critArray[5].indexOf("@"+phisdata[indexSelected[roll]][(criteriafield[5])]+"@")!=-1 && critArray[6].indexOf("@"+phisdata[indexSelected[roll]][(criteriafield[6])]+"@")!=-1) {
	filterdata.push(phisdata[indexSelected[roll]]);
	}
	}
	break;

	default:
	for (roll=0;roll<indexSelected.length;roll++) {
	if (critArray[0].indexOf("@"+phisdata[indexSelected[roll]][(criteriafield[0])]+"@")!=-1 && critArray[1].indexOf("@"+phisdata[indexSelected[roll]][(criteriafield[1])]+"@")!=-1 && critArray[2].indexOf("@"+phisdata[indexSelected[roll]][(criteriafield[2])]+"@")!=-1 && critArray[3].indexOf("@"+phisdata[indexSelected[roll]][(criteriafield[3])]+"@")!=-1) {
	filterdata.push(phisdata[indexSelected[roll]]);
	}
	}
	break;
	}
	}

}

}

function sortNode(a,b){
a=a.firstChild.nodeValue;
b=b.firstChild.nodeValue;
return ((a<b)?-1:((a>b)?1:0));
}

function sortByCrit(a,b){
a=a[indexFld];
b=b[indexFld];
return ((a<b)?-1:((a>b)?1:0));
}

function sortTheCrit(a,b){
a=a[1];
b=b[1];
return ((a<b)?-1:((a>b)?1:0));
}

function sortTheNum(a,b){
a=parseFloat(a[1]);
b=parseFloat(b[1]);
return ((a<b)?-1:((a>b)?1:0));
}

function sortyear(a,b){
a=a[yearScopeVar];
b=b[yearScopeVar];
return ((a<b)?-1:((a>b)?1:0));
}

///////////////////////////////////////////////////////////////////////////////////
function submitcriteria(elm,cboName,fieldName) {
var variSel = elm.criteria.elements[cboName];
var selectedVari = getselections(variSel);
var filterVari="(";
// test run through of returned array
for(var k=0;k<selectedVari.length;k++)
{
filterVari= filterVari + fieldName + "=" + selectedVari[k];
if (k==selectedVari.length-1){
filterVari+=" ) ";
}
else
{
filterVari+=" | ";
}
}
if (filterVari=="("){
filterVari="";
}
return filterVari;
}

// returns references to the actual option elements (not values) 
function getselections(selCrit) {
var sOptions = [];
var opt;
var k=0;
while (k<selCrit.options.length){
opt=selCrit.options[k];
if(opt.selected)sOptions[sOptions.length] = opt.value
k+=1
}
return sOptions;
}

function getselectionsLabel(selCrit) {
var sOptionsLabel = [];
var opt;
var k=0;
while (k<selCrit.options.length){
opt=selCrit.options[k];
if(opt.selected)sOptionsLabel[sOptionsLabel.length] = opt.text
k+=1
}
return sOptionsLabel;
}


function submitCrit(){
if (dataloaded==false) {
alert (loadWaitMsg[word]);
return;
}
_timer1=new Date();
showGraph.disabled=true;
var empty=true;
var toofull=false;
var croll;
croll=0;
while(croll<critCount){
if (criteria.elements[croll].selectedIndex==-1) {
empty=true;
break;
}
else if (getselections(criteria.elements[croll]).length>=optLimit) {
toofull=true;
break;
} else {
empty=false;
croll+=1;
continue;
}
}
if (empty==true){
  alert(redSign[word]);
  variselected=false;
  selstatus.innerHTML="<FONT COLOR=RED SIZE=4><B>"+redSign[word]+"</B></FONT>";
  clearresult();
  location="#criteriaanchor"; 
} else if (toofull==true) {
  alert(optLimitMsg[word]);
  variselected=false;
  selstatus.innerHTML="<FONT COLOR=RED SIZE=4><B>"+redSign[word]+"</B></FONT>";
  clearresult();
  location="#criteriaanchor"; 
} else {
  variselected=true;
  selstatus.innerHTML="<FONT COLOR=GREEN SIZE=4><B>"+greenSign[word]+"</B></FONT>";
  if (_app=='Microsoft Internet Explorer') {
	iefilter();
	iecountcase();
  } else {
	jsfilter();
	countcase();
  }
  location="#resultanchor";
  _timer2=new Date();
  result3.innerHTML=(timeMsg[word]+((_timer2-_timer1)/1000));

}
}


function countcase(){
var r;
var resultStr="";
var stat=new Array();
var z;
for (r=0;r<statvar.length;r++)stat[r]=0
if (filterdata.length==0){
result1.innerHTML=noRecordMsg[word];
alert(noRecordMsg[word]);
} else {
for (t=0;t<filterdata.length;t++)
{
for (z=0;z<statvar.length;z++){
if (statvarDisplay[z]==true && !isNaN(filterdata[t][(statvar[z][0])])) stat[z]+=parseFloat(filterdata[t][(statvar[z][0])])
else if (statvarDisplay[z]==true && isNaN(filterdata[t][(statvar[z][0])]) && statvarNullToZero[z]!=true) stat[z]="---"
}
}
for (z=0;z<statvar.length;z++){
if (isNaN(stat[z]) && statvarNullToZero[z]!=true) stat[z]="---"
}
for (r=0;r<statvar.length;r++) if (statvarDisplay[r]==true) resultStr+=totalLabel[word]+varFieldName[statvar[r][0]][word]+" = "+stat[r]+"<BR>"
result1.innerHTML=critStr+"<BR>";
result2.innerHTML=resultStr;
result3.innerHTML="";
resultG.innerHTML="";
resultM.innerHTML="";
hideGraph();
statButton();
}
}

function iecountcase(){
var r;
var resultStr="";
var stat=new Array();
var z;
for (r=0;r<statvar.length;r++)stat[r]=0
if (mstxt.recordset.recordCount==0){
result1.innerHTML=noRecordMsg[word];
alert(noRecordMsg[word]);
} else {
mstxt.recordset.moveFirst();
for (t=0;t<mstxt.recordset.recordCount;t++)
{
for (z=0;z<statvar.length;z++){
if (statvarDisplay[z]==true && !isNaN(parseFloat(mstxt.recordset.Fields(statvar[z][0]).value))) stat[z]+=parseFloat(mstxt.recordset.Fields(statvar[z][0]).value)
else if (statvarDisplay[z]==true && isNaN(mstxt.recordset.Fields(statvar[z][0]).value) && statvarNullToZero[z]!=true) stat[z]="---"
}
mstxt.recordset.moveNext();
}
for (z=0;z<statvar.length;z++){
if (isNaN(stat[z]) && statvarNullToZero[z]!=true) stat[z]="---"
}
for (r=0;r<statvar.length;r++) if (statvarDisplay[r]==true) resultStr+=totalLabel[word]+varFieldName[statvar[r][0]][word]+" = "+stat[r]+"<BR>"
result1.innerHTML=critStr+"<BR>";
result2.innerHTML=resultStr;
result3.innerHTML="";
resultG.innerHTML="";
resultM.innerHTML="";
hideGraph();
statButton();
}
}

function gpVarSelect(){
var opv;
var countform=document.getElementById("countform");
document.getElementById("cboRowVar").options.length=0;
document.getElementById("cboColVar").options.length=0;
for (opv=0;opv<gpVarField.length;opv++){
document.getElementById("cboRowVar").options[opv]= new Option(varFieldName[gpVarField[opv]][word], gpVarField[opv], false, false);
document.getElementById("cboColVar").options[opv]= new Option(varFieldName[gpVarField[opv]][word], gpVarField[opv], false, false);
if (codesetVar[gpVarField[opv]]==54 && gis==true) document.getElementById("cboColVar").options[opv].style.color=gisPromptColor;
}
document.getElementById("cboRowVar").options[gpVarField.length]= new Option(noSpecify[word], 999, false, false);
document.getElementById("cboColVar").options[gpVarField.length]= new Option(noSpecify[word], 999, true, true);

for (opv=0;opv<statvarNum.length;opv++){
document.getElementById("cboStat").options[opv]= new Option(statvarLabel[opv][word], opv, false, false);
}
}

function cntby(){
if (variselected==false){
alert(noSelectRemind[word]);
return;
}
if (_app!='Microsoft Internet Explorer' && filterdata.length==0){
alert(noRecordMsg[word]);
return;
}
if (_app=='Microsoft Internet Explorer' && mstxt.recordset.recordCount==0){
alert(noRecordMsg[word]);
return;
}
var cat;
var r;
var s;
var q;
var z;
var catvalue= new Array();
var statcnt = new Array();
var colCount;
var rowCount;
var rowTot=new Array();
var colTot=new Array();
var rowAvg=new Array();
var colAvg=new Array();
var p;
var recordval;
var cellvar;
var hashPopnCrit=new Array();
var popncnt=new Array();
for (z=0;z<statvar.length;z++){
rowTot[z]=[];
colTot[z]=[];
rowAvg[z]=[];
colAvg[z]=[];
}

graphStatcntLabel="";
graphGpVarRowLabel="";
graphGpVarColLabel="";
graphCatRowDesc.length=0;
graphCatColDesc.length=0;
graphCellvar.length=0;
graphCellvarDisplay.length=0;
graphCatRowSubtot.length=0;
graphCatColSubtot.length=0;
graphCatRowSubtotDisplay.length=0;
graphCatColSubtotDisplay.length=0;
chartTitle="";
mapTitle="";

var gpVarRow=document.getElementById("cboRowVar").options[document.getElementById("cboRowVar").selectedIndex].value;
var gpVarRowLabel=document.getElementById("cboRowVar").options[document.getElementById("cboRowVar").selectedIndex].text
var gpVarCol=document.getElementById("cboColVar").options[document.getElementById("cboColVar").selectedIndex].value;
var gpVarColLabel=document.getElementById("cboColVar").options[document.getElementById("cboColVar").selectedIndex].text
var statShown=document.getElementById("cboStat").selectedIndex;
var statcntLabel=document.getElementById("cboStat").options[document.getElementById("cboStat").selectedIndex].text
var hashCrit=new Array();
var hashCritOpt=new Array();
for (var x=0;x<criteriafield.length;x++) hashCrit[criteriafield[x]]=x

if (hashCrit[gpVarRow]>=0) rowCount=getselections(document.getElementById("criteria").elements[hashCrit[gpVarRow]]).length
else if (codeTable[codesetVar[gpVarRow]]) rowCount=codeTable[codesetVar[gpVarRow]].length
else if (gpVarRow==999) rowCount=1
else if (codesetVar[gpVarRow]==136) rowCount=53
else rowCount=100

if (hashCrit[gpVarCol]>=0) colCount=getselections(document.getElementById("criteria").elements[hashCrit[gpVarCol]]).length
else if (codeTable[codesetVar[gpVarCol]]) colCount=codeTable[codesetVar[gpVarCol]].length
else if (gpVarCol==999) colCount=1
else if (codesetVar[gpVarCol]==136) colCount=53
else colCount=100

for (z=0;z<statvar.length;z++){
statcnt[z]=new Array();
for (s=0;s<rowCount;s++) {
statcnt[z][s]=new Array();
graphCellvar[s]=[];
graphCellvarDisplay[s]=[];
if (statvarNullToZero[z]==true) rowTot[z][s]=0
}
if (statvarNullToZero[z]==true) for (r=0;r<colCount;r++) colTot[z][r]=0
}

if (hashCrit[gpVarRow]>=0) {
hashCritOpt[gpVarRow]=[];
for (s=0;s<rowCount;s++) hashCritOpt[gpVarRow][getselections(document.getElementById("criteria").elements[hashCrit[gpVarRow]])[s]]=s
}

if (hashCrit[gpVarCol]>=0) {
hashCritOpt[gpVarCol]=[];
for (s=0;s<colCount;s++) hashCritOpt[gpVarCol][getselections(document.getElementById("criteria").elements[hashCrit[gpVarCol]])[s]]=s
}

for (z=0;z<statvar.length;z++){
if (statvarNullToZero[z]==true) {
for (s=0;s<rowCount;s++){
for (q=0;q<colCount;q++)statcnt[z][s][q]=0
}
}
}

var catRow, catCol;
if (_app!='Microsoft Internet Explorer') {
for (roll=0;roll<filterdata.length;roll++){
if (hashCrit[gpVarRow]>=0) catRow=hashCritOpt[gpVarRow][filterdata[roll][gpVarRow]]
else if (codeHash[gpVarRow]) catRow=codeHash[gpVarRow][filterdata[roll][gpVarRow]]
else if (gpVarRow==999) catRow=0
else if (codesetVar[gpVarRow]==136) catRow=filterdata[roll][gpVarRow]-1
else catRow=filterdata[roll][gpVarRow]

if (hashCrit[gpVarCol]>=0) catCol=hashCritOpt[gpVarCol][filterdata[roll][gpVarCol]]
else if (codeHash[gpVarCol]) catCol=codeHash[gpVarCol][filterdata[roll][gpVarCol]]
else if (gpVarCol==999) catCol=0
else if (codesetVar[gpVarCol]==136) catCol=filterdata[roll][gpVarCol]-1
else catCol=filterdata[roll][gpVarCol]

for (z=0;z<statvar.length;z++){
recordval=1;
for (p=0;p<statvar[z].length;p++) {
if (isNaN(filterdata[roll][statvar[z][p]]) && statvarNullToZero[z]==true) recordval=0
else recordval=recordval*parseInt(filterdata[roll][statvar[z][p]])
}

if (statvarNullToZero[z]==true) {
if (gpVarRow==999 && gpVarCol!=999) statcnt[z][0][catCol]+=recordval
if (gpVarRow!=999 && gpVarCol==999) statcnt[z][catRow][0]+=recordval
if (gpVarRow==999 && gpVarCol==999) statcnt[z][0][0]+=recordval
if (gpVarRow!=999 && gpVarCol!=999) statcnt[z][catRow][catCol]+=recordval
} else {
if (gpVarRow==999 && gpVarCol!=999 && statcnt[z][0][catCol]) statcnt[z][0][catCol]+=recordval
if (gpVarRow==999 && gpVarCol!=999 && !statcnt[z][0][catCol]) statcnt[z][0][catCol]=recordval
if (gpVarRow!=999 && gpVarCol==999 && statcnt[z][catRow][0]) statcnt[z][catRow][0]+=recordval
if (gpVarRow!=999 && gpVarCol==999 && !statcnt[z][catRow][0]) statcnt[z][catRow][0]=recordval
if (gpVarRow==999 && gpVarCol==999 && statcnt[z][0][0]) statcnt[z][0][0]+=recordval
if (gpVarRow==999 && gpVarCol==999 && !statcnt[z][0][0]) statcnt[z][0][0]=recordval
if (gpVarRow!=999 && gpVarCol!=999 && statcnt[z][catRow][catCol]) statcnt[z][catRow][catCol]+=recordval
if (gpVarRow!=999 && gpVarCol!=999 && !statcnt[z][catRow][catCol]) statcnt[z][catRow][catCol]=recordval
}
if (!isNaN(recordval)) {
if (rowTot[z][catRow]) rowTot[z][catRow]+=recordval
else rowTot[z][catRow]=recordval}
if (!isNaN(recordval)) {
if (colTot[z][catCol]) colTot[z][catCol]+=recordval
else colTot[z][catCol]=recordval}
}
}
}

if (_app=='Microsoft Internet Explorer') {
mstxt.recordset.moveFirst();
gpVarRow=parseInt(gpVarRow);
gpVarCol=parseInt(gpVarCol);
for (roll=0;roll<mstxt.recordset.recordCount;roll++){
if (hashCrit[gpVarRow]>=0) catRow=hashCritOpt[gpVarRow][mstxt.recordset.Fields(gpVarRow).value]
else if (codeHash[gpVarRow]) catRow=codeHash[gpVarRow][mstxt.recordset.Fields(gpVarRow).value]
else if (gpVarRow==999) catRow=0
else if (codesetVar[gpVarRow]==136) catRow=mstxt.recordset.Fields(gpVarRow).value-1
else catRow=mstxt.recordset.Fields(parseInt(gpVarRow)).value

if (hashCrit[gpVarCol]>=0) catCol=hashCritOpt[gpVarCol][mstxt.recordset.Fields(gpVarCol).value]
else if (codeHash[gpVarCol]) catCol=codeHash[gpVarCol][mstxt.recordset.Fields(gpVarCol).value]
else if (gpVarCol==999) catCol=0
else if (codesetVar[gpVarCol]==136) catCol=mstxt.recordset.Fields(gpVarCol).value-1
else catCol=mstxt.recordset.Fields(gpVarCol).value

for (z=0;z<statvar.length;z++){
recordval=1;
for (p=0;p<statvar[z].length;p++) {
if (isNaN(parseFloat(mstxt.recordset.Fields(statvar[z][p]).value)) && statvarNullToZero[z]==true) recordval=0
else recordval=recordval*parseInt(mstxt.recordset.Fields(statvar[z][p]).value)
}
if (statvarNullToZero[z]==true) {
if (gpVarRow==999 && gpVarCol!=999) statcnt[z][0][catCol]+=recordval
if (gpVarRow!=999 && gpVarCol==999) statcnt[z][catRow][0]+=recordval
if (gpVarRow==999 && gpVarCol==999) statcnt[z][0][0]+=recordval
if (gpVarRow!=999 && gpVarCol!=999) statcnt[z][catRow][catCol]+=recordval
} else {
if (gpVarRow==999 && gpVarCol!=999 && statcnt[z][0][catCol]) statcnt[z][0][catCol]+=recordval
if (gpVarRow==999 && gpVarCol!=999 && !statcnt[z][0][catCol]) statcnt[z][0][catCol]=recordval
if (gpVarRow!=999 && gpVarCol==999 && statcnt[z][catRow][0]) statcnt[z][catRow][0]+=recordval
if (gpVarRow!=999 && gpVarCol==999 && !statcnt[z][catRow][0]) statcnt[z][catRow][0]=recordval
if (gpVarRow==999 && gpVarCol==999 && statcnt[z][0][0]) statcnt[z][0][0]+=recordval
if (gpVarRow==999 && gpVarCol==999 && !statcnt[z][0][0]) statcnt[z][0][0]=recordval
if (gpVarRow!=999 && gpVarCol!=999 && statcnt[z][catRow][catCol]) statcnt[z][catRow][catCol]+=recordval
if (gpVarRow!=999 && gpVarCol!=999 && !statcnt[z][catRow][catCol]) statcnt[z][catRow][catCol]=recordval
}
if (!isNaN(recordval)) {
if (rowTot[z][catRow]) rowTot[z][catRow]+=recordval
else rowTot[z][catRow]=recordval}

if (!isNaN(recordval)) {
if (colTot[z][catCol]) colTot[z][catCol]+=recordval
else colTot[z][catCol]=recordval}
}
mstxt.recordset.moveNext();
}
}

var rowSubLabel;
var colSubLabel;
if (statvarDenom[statShown]!="NA" && statvarDenom[statShown]!="PO") {
rowSubLabel=avgLabel[word]+gpVarColLabel;
colSubLabel=avgLabel[word]+gpVarRowLabel;
}
else if (statvarDenom[statShown]=="PO") {
if (codesetVar[gpVarRow]==22 && codesetVar[gpVarCol]!=22) {
rowSubLabel=allLabel[word]+gpVarColLabel;
colSubLabel=avgLabel[word]+gpVarRowLabel;
} 
else if (codesetVar[gpVarRow]==22 && codesetVar[gpVarCol]==22) {
rowSubLabel=avgLabel[word]+gpVarColLabel;
colSubLabel=avgLabel[word]+gpVarRowLabel;
}
else if (codesetVar[gpVarCol]==22 && codesetVar[gpVarRow]!=22) {
rowSubLabel=avgLabel[word]+gpVarColLabel;
colSubLabel=allLabel[word]+gpVarRowLabel;
}
else if (codesetVar[gpVarCol]!=22 && codesetVar[gpVarRow]!=22) {
rowSubLabel=allLabel[word]+gpVarColLabel;
colSubLabel=allLabel[word]+gpVarRowLabel;
}

}
else
{
rowSubLabel=rowTotLabel[word];
colSubLabel=colTotLabel[word];
}

if (popnbase==true) {
	for (x=0;x<fieldCount;x++) hashPopnCrit[x]=999
	hashPopnCrit[999]=999;
	for (x=0;x<popnCrit.length;x++) if (popnCrit[x]!=999) hashPopnCrit[popnCrit[x]]=x
	for (s=0;s<rowCount;s++) {
	popncnt[s]=[];
	for (r=0;r<colCount;r++) popncnt[s][r]=0
	}
	if (hashPopnCrit[gpVarRow]==999 && hashPopnCrit[gpVarCol]==999) {
	var popnAll=0;
	for (roll=0;roll<filterpopn.length;roll++){
		popnAll+=Math.round(filterpopn[roll][popnCal]);
		//popnAll+=parseInt(filterpopn[roll][popnCal]);
	}
	for (s=0;s<rowCount;s++) {
	for (r=0;r<colCount;r++) popncnt[s][r]=popnAll
	}
	}

	if (hashPopnCrit[gpVarRow]!=999 && hashPopnCrit[gpVarCol]!=999) {
	for (roll=0;roll<filterpopn.length;roll++){
	if (hashCrit[gpVarRow]>=0) catRow=hashCritOpt[gpVarRow][filterpopn[roll][hashPopnCrit[gpVarRow]]]
	else if (codeHash[gpVarRow]) catRow=codeHash[gpVarRow][filterpopn[roll][hashPopnCrit[gpVarRow]]]
	else if (gpVarRow==999) catRow=0
	else catRow=filterpopn[roll][hashPopnCrit[gpVarRow]]
	if (hashCrit[gpVarCol]>=0) catCol=hashCritOpt[gpVarCol][filterpopn[roll][hashPopnCrit[gpVarCol]]]
	else if (codeHash[gpVarCol]) catCol=codeHash[gpVarCol][filterpopn[roll][hashPopnCrit[gpVarCol]]]
	else if (gpVarCol==999) catCol=0
	else catCol=filterpopn[roll][hashPopnCrit[gpVarCol]]
	//recordval=parseInt(filterpopn[roll][popnCal]);
	//recordval=Math.round(filterpopn[roll][popnCal]);
	recordval=filterpopn[roll][popnCal];
	if (gpVarRow==999 && gpVarCol!=999) popncnt[0][catCol]+=recordval
	if (gpVarRow!=999 && gpVarCol==999) popncnt[catRow][0]+=recordval
	if (gpVarRow==999 && gpVarCol==999) popncnt[0][0]+=recordval
	if (gpVarRow!=999 && gpVarCol!=999) popncnt[catRow][catCol]+=recordval
	}
	}

	if (hashPopnCrit[gpVarRow]!=999 && hashPopnCrit[gpVarCol]==999) {
	for (roll=0;roll<filterpopn.length;roll++){
	if (hashCrit[gpVarRow]>=0) catRow=hashCritOpt[gpVarRow][filterpopn[roll][hashPopnCrit[gpVarRow]]]
	else if (codeHash[gpVarRow]) catRow=codeHash[gpVarRow][filterpopn[roll][hashPopnCrit[gpVarRow]]]
	else if (gpVarRow==999) catRow=0
	else catRow=filterpopn[roll][hashPopnCrit[gpVarRow]]
	// use direct value instead of trunc value
	//recordval=parseInt(filterpopn[roll][popnCal]);
	recordval=filterpopn[roll][popnCal];
	
	if (gpVarRow==999) popncnt[0][0]+=recordval
	else popncnt[catRow][0]+=recordval
	}
	if (colCount>1) {
	for (s=0;s<rowCount;s++) {
	for (r=1;r<colCount;r++) popncnt[s][r]=popncnt[s][0]
	}
	}
	}

	if (hashPopnCrit[gpVarRow]==999 && hashPopnCrit[gpVarCol]!=999) {
	for (roll=0;roll<filterpopn.length;roll++){
	if (hashCrit[gpVarCol]>=0) catCol=hashCritOpt[gpVarCol][filterpopn[roll][hashPopnCrit[gpVarCol]]]
	else if (codeHash[gpVarCol]) catCol=codeHash[gpVarCol][filterpopn[roll][hashPopnCrit[gpVarCol]]]
	else if (gpVarCol==999) catCol=0
	else catCol=filterpopn[roll][hashPopnCrit[gpVarCol]]
	// use direct value instead of trunc value
	//recordval=parseInt(filterpopn[roll][popnCal]);
	recordval=filterpopn[roll][popnCal];
	if (gpVarCol==999) popncnt[0][0]+=recordval
	else {
		popncnt[0][catCol]+=recordval
	}
	}
	if (rowCount>1) {
	for (r=0;r<colCount;r++) {
	for (s=1;s<rowCount;s++) popncnt[s][r]=popncnt[0][r]
	}
	}
	}

}

//write the results on the HTML
var catRowDesc=new Array();
var catColDesc=new Array();

if (hashCrit[gpVarRow]>=0) {
	if (codeTable[codesetVar[gpVarRow]]){
	for (r=0;r<rowCount;r++) catRowDesc[r]=codeTable[codesetVar[gpVarRow]][codeHash[gpVarRow][getselections(document.getElementById("criteria").elements[hashCrit[gpVarRow]])[r]]][parseInt(word)+1]
	} else {
	for (r=0;r<rowCount;r++) catRowDesc[r]=getselections(document.getElementById("criteria").elements[hashCrit[gpVarRow]])[r]
	}
} else {
	if (codeTable[codesetVar[gpVarRow]]){
	for (r=0;r<rowCount;r++) catRowDesc[r]=codeTable[codesetVar[gpVarRow]][r][parseInt(word)+1]
	} else if (gpVarRow==999) {
	catRowDesc[0]="";
	} else if (codesetVar[gpVarRow]==136) {
	for (r=0;r<rowCount;r++) catRowDesc[r]=(parseInt(r)+1).toString()
	} else {
	for (r=0;r<rowCount;r++) catRowDesc[r]=r
	}
}

if (hashCrit[gpVarCol]>=0) {
	if (codeTable[codesetVar[gpVarCol]]){
	for (s=0;s<colCount;s++) catColDesc[s]=codeTable[codesetVar[gpVarCol]][codeHash[gpVarCol][getselections(document.getElementById("criteria").elements[hashCrit[gpVarCol]])[s]]][parseInt(word)+1]
	} else {
	for (s=0;s<colCount;s++) catColDesc[s]=getselections(document.getElementById("criteria").elements[hashCrit[gpVarCol]])[s]
	}
} else {
	if (codeTable[codesetVar[gpVarCol]]){
	for (s=0;s<colCount;s++) catColDesc[s]=codeTable[codesetVar[gpVarCol]][s][parseInt(word)+1]
	} else if (gpVarCol==999) {
	catColDesc[0]="";
	} else if (codesetVar[gpVarCol]==136) {
	for (s=0;s<colCount;s++) catColDesc[s]=(parseInt(s)+1).toString()
	} else {
	for (s=0;s<colCount;s++) catColDesc[s]=s
	}
}

resultGall="<P>\n<TABLE ID='bivartab'><THEAD><TR ALIGN=CENTER><TD ROWSPAN=2 COLSPAN=2>"+statcntLabel+"</TD>";
/*
 *  Fixing for wrong rowspan
 *  Added: check colCount = 1 or not
 */
if (colCount == 1)
resultGall+="<TH ROWSPAN=2 COLSPAN="+colCount;
else
resultGall+="<TH COLSPAN="+colCount;
resultGall+="><DIV><B>"+gpVarColLabel+"</B></DIV></TH><TH ROWSPAN=2 VALIGN=BOTTOM>"+rowSubLabel+"</TH></TR><TR>";

/*
 *  Fixing for wrong rowspan
 *  Added: check colCount = 1 or not
 */
if (colCount != 1){
for (s=0;s<colCount;s++) resultGall+="<TH><DIV><B>"+catColDesc[s]+"</B></DIV></TH>"
resultGall+="</TR></THEAD><TBODY>";
}


/*
 *  Fixing for wrong colspan
 *  Added: check rowCount = 1 or not
 */
if (rowCount != 1)
resultGall+="<TR><TH ROWSPAN="+parseInt(rowCount)+" VALIGN=CENTER>"
else
resultGall+="<TR><TH COLSPAN=2 ROWSPAN="+parseInt(rowCount)+" VALIGN=CENTER>"


if (word==0) resultGall+=gpVarRowLabel.split(' ').join('<BR>\n')
else resultGall+=gpVarRowLabel.split('').join('<BR>\n')

/*
 *  Fixing for wrong colspan
 *  Added: check rowCount = 1 or not
 */
if (rowCount != 1)
resultGall+="</TH><TH ALIGN=CENTER>"+catRowDesc[0]+"</TH>";
else
resultGall+="</TH>";

if (popnbase==true) {
var rowTotPopn=new Array();
var colTotPopn=new Array();
for (r=0;r<rowCount;r++) {
rowTotPopn[r]=0;
for (s=0;s<colCount;s++) rowTotPopn[r]+=popncnt[r][s]
}
for (s=0;s<colCount;s++) {
colTotPopn[s]=0;
for (r=0;r<rowCount;r++) colTotPopn[s]+=popncnt[r][s]
}
}

for (s=0;s<colCount;s++){
if (statvarDenom[statShown]=="NA") cellvar=statcnt[statvarNum[statShown]][0][s]*statvarNumMultiply[statShown]
else if (statvarDenom[statShown]=="PO") {
	cellvar=statcnt[statvarNum[statShown]][0][s]*statvarNumMultiply[statShown]/popncnt[0][s];
}
else cellvar=statcnt[statvarNum[statShown]][0][s]/statcnt[statvarDenom[statShown]][0][s]*statvarNumMultiply[statShown]
if (isNaN(cellvar) || !isFinite(cellvar)) cellvar="---"
graphCellvar[0][s]=cellvar;
if (!isNaN(cellvar) && isFinite(cellvar)){
	cellvar=(Math.round(cellvar*Math.pow(10,statvarDecimal[statShown]))/Math.pow(10,statvarDecimal[statShown])).toFixed(statvarDecimal[statShown])
}
graphCellvarDisplay[0][s]=cellvar;
resultGall+="<TD ALIGN=RIGHT>"+cellvar+"</TD>";
}
if (statvarDenom[statShown]=="NA") cellvar=rowTot[statvarNum[statShown]][0]*statvarNumMultiply[statShown]
else if (statvarDenom[statShown]=="PO") {
cellvar=rowTot[statvarNum[statShown]][0]*statvarNumMultiply[statShown]/rowTotPopn[0];
if (isNaN(cellvar) || !isFinite(cellvar)) cellvar="---"
if (hashPopnCrit[gpVarCol]==999 && codesetVar[gpVarCol]!=10) cellvar=cellvar*colCount
}
else cellvar=rowTot[statvarNum[statShown]][0]/rowTot[statvarDenom[statShown]][0]*statvarNumMultiply[statShown]
graphCatRowSubtot[0]=cellvar;
cellvar=(Math.round(cellvar*Math.pow(10,statvarDecimal[statShown]))/Math.pow(10,statvarDecimal[statShown])).toFixed(statvarDecimal[statShown]);
if (isNaN(cellvar) || !isFinite(cellvar)) cellvar="---"
graphCatRowSubtotDisplay[0]=cellvar;
resultGall+="<TD ALIGN=RIGHT><B>"+cellvar+"<B></TD></TR>";
for (r=1;r<rowCount;r++){
resultGall+="<TR><TH ALIGN=CENTER>"+catRowDesc[r]+"</TH>";
for (s=0;s<colCount;s++){
if (statvarDenom[statShown]=="NA") cellvar=statcnt[statvarNum[statShown]][r][s]*statvarNumMultiply[statShown]
else if (statvarDenom[statShown]=="PO") cellvar=statcnt[statvarNum[statShown]][r][s]*statvarNumMultiply[statShown]/popncnt[r][s]
else cellvar=statcnt[statvarNum[statShown]][r][s]/statcnt[statvarDenom[statShown]][r][s]*statvarNumMultiply[statShown]
if (isNaN(cellvar) || !isFinite(cellvar)) cellvar="---"
graphCellvar[r][s]=cellvar;
cellvar=(Math.round(cellvar*Math.pow(10,statvarDecimal[statShown]))/Math.pow(10,statvarDecimal[statShown])).toFixed(statvarDecimal[statShown]);
if (isNaN(cellvar) || !isFinite(cellvar)) cellvar="---"
graphCellvarDisplay[r][s]=cellvar;
resultGall+="<TD ALIGN=RIGHT>"+cellvar+"</TD>";
}
//alert(statvarNum[statShown]);
//alert(rowTot[statvarNum[statShown]][r]);
if (statvarDenom[statShown]=="NA") cellvar=rowTot[statvarNum[statShown]][r]*statvarNumMultiply[statShown]
else if (statvarDenom[statShown]=="PO") {
cellvar=rowTot[statvarNum[statShown]][r]*statvarNumMultiply[statShown]/rowTotPopn[r];
if (hashPopnCrit[gpVarCol]==999 && codesetVar[gpVarCol]!=10) cellvar=cellvar*colCount
}
else cellvar=rowTot[statvarNum[statShown]][r]/rowTot[statvarDenom[statShown]][r]*statvarNumMultiply[statShown]
graphCatRowSubtot[r]=cellvar;
cellvar=(Math.round(cellvar*Math.pow(10,statvarDecimal[statShown]))/Math.pow(10,statvarDecimal[statShown])).toFixed(statvarDecimal[statShown]);
if (isNaN(cellvar) || !isFinite(cellvar)) cellvar="---"
graphCatRowSubtotDisplay[r]=cellvar;
//alert(cellvar);
resultGall+="<TD ALIGN=RIGHT><B>"+cellvar+"<B></TD></TR>";
}

var grandTot=new Array();
for (z=0;z<statvar.length;z++){
if (statvarNullToZero[z]==true) grandTot[z]=0
}

if (popnbase==true) {
var grandTotPopn=0;
for (s=0;s<colCount;s++) grandTotPopn+=colTotPopn[s]
}

resultGall+="<TR><TH COLSPAN=2>"+colSubLabel+"</TH>";

for (z=0;z<statvar.length;z++){
for (s=0;s<colCount;s++){
if (!colTot[z][s] && statvarNullToZero[z]==true) colTot[z][s]=0
if (!isNaN(colTot[z][s]) && grandTot[z]) grandTot[z]+=colTot[z][s]
if (!isNaN(colTot[z][s]) && !grandTot[z]) grandTot[z]=colTot[z][s]
}
}

for (s=0;s<colCount;s++){
if (statvarDenom[statShown]=="NA") cellvar=colTot[statvarNum[statShown]][s]*statvarNumMultiply[statShown]
else if (statvarDenom[statShown]=="PO") {
cellvar=colTot[statvarNum[statShown]][s]*statvarNumMultiply[statShown]/colTotPopn[s];
if (isNaN(cellvar) || !isFinite(cellvar)) cellvar="---"
if (hashPopnCrit[gpVarRow]==999 && codesetVar[gpVarRow]!=10) cellvar=cellvar*rowCount
}
else cellvar=colTot[statvarNum[statShown]][s]/colTot[statvarDenom[statShown]][s]*statvarNumMultiply[statShown]
graphCatColSubtot[s]=cellvar;
cellvar=(Math.round(cellvar*Math.pow(10,statvarDecimal[statShown]))/Math.pow(10,statvarDecimal[statShown])).toFixed(statvarDecimal[statShown]);
if (isNaN(cellvar) || !isFinite(cellvar)) cellvar="---"
graphCatColSubtotDisplay[s]=cellvar;
resultGall+="<TD ALIGN=RIGHT><B>"+cellvar+"</B></TD>";
}
if (statvarDenom[statShown]=="NA") cellvar=grandTot[statvarNum[statShown]]*statvarNumMultiply[statShown]
else if (statvarDenom[statShown]=="PO") {
cellvar=grandTot[statvarNum[statShown]]*statvarNumMultiply[statShown]/grandTotPopn;
if (isNaN(cellvar) || !isFinite(cellvar)) cellvar="---"
if (hashPopnCrit[gpVarCol]==999 && codesetVar[gpVarCol]!=10) cellvar=cellvar*colCount
if (hashPopnCrit[gpVarRow]==999 && codesetVar[gpVarRow]!=10) cellvar=cellvar*rowCount
}
else cellvar=grandTot[statvarNum[statShown]]/grandTot[statvarDenom[statShown]]*statvarNumMultiply[statShown]
cellvar=(Math.round(cellvar*Math.pow(10,statvarDecimal[statShown]))/Math.pow(10,statvarDecimal[statShown])).toFixed(statvarDecimal[statShown]);
if (isNaN(cellvar) || !isFinite(cellvar)) cellvar="---"
graphGrandTot=cellvar;
resultGall+="<TD ALIGN=RIGHT><B>"+cellvar+"</B></TD></TR>";

resultGall+="</TBODY></TABLE>";
var resultVT="<P>"+"<INPUT TYPE=BUTTON VALUE='"+copyTableButton[word]+"' ONCLICK='openTable();'>";
resultG.innerHTML=resultGall+resultVT;
resultC.innerHTML="";
resultC.style.height="0px";
resultC.style.border="white 0px";
document.getElementById("showGraph").value=showGraphButton[word];
document.getElementById("showGraph").onclick=graphTheTable;
graphStatcntLabel=statcntLabel;
graphGpVarRowLabel=gpVarRowLabel;
graphGpVarColLabel=gpVarColLabel;
graphCatRowDesc=catRowDesc;
graphCatColDesc=catColDesc;
showGraph.disabled=false;
statButton();

document.forms["graphChoose"].elements["graphType"].options.length=0;
document.forms["graphChoose"].elements["graphType"].options[0]= new Option(graphTypeName[0][word], 0, false, false);
if (statvarDenom[statShown]=="NA") {
document.forms["graphChoose"].elements["graphType"].options[1]= new Option(graphTypeName[1][word], 1, false, false);
document.forms["graphChoose"].elements["graphType"].options[2]= new Option(graphTypeName[2][word], 2, false, false);
}
resultM.innerHTML="";
if (codesetVar[gpVarCol]==54) {
var mHead=document.createElement("h2");
mHead.appendChild(document.createTextNode(mapHead[word]));
var newIcon=document.createElement("img");
newIcon.src="/phisweb/images/en_new.gif";
if (nowDate<expNewMapDate) mHead.appendChild(newIcon)

var mSel=document.createElement("select");
if (gpVarRow==999) mSel.options[0]=new Option(colSubLabel,r,false,false)
else {
for (r=0;r<rowCount;r++) mSel.options[r]=new Option(graphCatRowDesc[r],r,false,false);
mSel.options[rowCount]=new Option(colSubLabel,r,true,true);
}
graphCatColCode.length=0;
graphCatColCode=getselections(document.getElementById("criteria").elements[hashCrit[gpVarCol]])
resultM.appendChild(mHead);
resultM.appendChild(document.createTextNode(graphGpVarRowLabel+" : "));
resultM.appendChild(mSel);
resultM.lastChild.id="mapSel";
var mBut=document.createElement("input");
mBut.type="button";
mBut.value=showMapButton[word];
resultM.appendChild(mBut);
resultM.lastChild.id="showMap";
document.getElementById("showMap").onclick=mapper;
document.getElementById("mapSel").onchange=mapper;
var mTitleDiv=document.createElement("div");
mTitleDiv.style.position="relative";
mTitleDiv.style.width="800px";
resultM.appendChild(mTitleDiv);
resultM.lastChild.id="mTitleDiv";
var mDiv0=document.createElement("div");
mDiv0.style.position="relative";
resultM.appendChild(mDiv0);
resultM.lastChild.id="mDiv0";
}
location="#tableanchor";
}

function mapper(doc){
if (document.getElementById("mapTitleText")) mapTitle=document.getElementById("mapTitleText").value;
if (!mapTitle) mapTitle=inputTitle[word]+" \n"+modulename[word].toUpperCase()
var mapStatHash=new Array();
var mapStat=new Array();
var mapStatUnique=new Array();
var mapStatSeq=new Array();
var mapStatRank=new Array();
var hashMapStatUnique=new Array();
var mapTot;
var mapNotNullCount=0;
var p;
var s;
var csroll;
var mapLegendDisc=new Array();
for (csroll=0;csroll<5;csroll++) mapLegendDisc[csroll]=[]
var dcdDiv=new Array();
var dcdAlt=new Array();
for (s=0;s<graphCatColSubtotDisplay.length;s++) {
if (graphCatColCode[s].length==1 && graphCatColCode[s]!="Y") {
if (document.getElementById("mapSel").selectedIndex!=document.getElementById("mapSel").length-1) mapStatHash[graphCatColCode[s]]=graphCellvarDisplay[document.getElementById("mapSel").selectedIndex][s]
else mapStatHash[graphCatColCode[s]]=graphCatColSubtotDisplay[s]
if (!isNaN(mapStatHash[graphCatColCode[s]])) {
mapNotNullCount+=1;
mapStat.push([graphCatColCode[s],mapStatHash[graphCatColCode[s]]]);
}
}
}
mapStat.sort(sortTheNum);
if (mapStat.length>0) {
mapStatUnique[0]=mapStat[0][1];
if (mapStat.length>1) {
for (p=1;p<mapStat.length;p++) {
if (mapStat[p][1]!=mapStat[p-1][1]) {
mapStatUnique.push(mapStat[p][1]);
}
}
}
for (p=0;p<mapStatUnique.length;p++) hashMapStatUnique["@"+mapStatUnique[p]]=p
for (s=0;s<mapStat.length;s++) {
mapStatSeq[mapStat[s][0]]=Math.floor(((Math.pow((hashMapStatUnique["@"+mapStat[s][1]]/mapStatUnique.length*2)-1,3)+1)*1.16/2)*4)+1;
mapStatRank[mapStat[s][0]]=Math.floor(((Math.pow((hashMapStatUnique["@"+mapStat[s][1]]/mapStatUnique.length*2)-1,3)+1)*1.16/2)*4)+1;
}
}
document.getElementById("mDiv0").innerHTML="";
document.getElementById("mTitleDiv").innerHTML="";
if (document.getElementById("openMapButton")) document.getElementById("resultM").removeChild(document.getElementById("resultM").lastChild)
document.getElementById("mDiv0").style.width="800px";
document.getElementById("mDiv0").style.height="650px";
var mapTitleP=document.createElement("textarea");
mapTitleP.style.scrollbarFaceColor="white";
mapTitleP.style.scrollbarArrowColor="white";
mapTitleP.style.scrollbarShadowColor="white";
mapTitleP.style.scrollbarDarkShadowColor="white";
mapTitleP.style.scrollbar3dLightColor="white";
mapTitleP.style.width="750px";
mapTitleP.style.height="120px";
mapTitleP.style.padding="10px";
mapTitleP.style.border="0px";
mapTitleP.style.fontSize="18";
mapTitleP.style.fontFamily="Arial";
mapTitleP.style.fontWeight="Bold";
mapTitleP.appendChild(document.createTextNode(mapTitle));
document.getElementById("mTitleDiv").appendChild(mapTitleP);
document.getElementById("mTitleDiv").lastChild.id="mapTitleText";
document.getElementById("mTitleDiv").appendChild(document.createElement("a"));
document.getElementById("mTitleDiv").lastChild.name="anchormap";
var bgMap=document.createElement("img");
bgMap.src="map/bgmap.jpg";
document.getElementById("mDiv0").appendChild(bgMap);
for (csroll=0;csroll<18;csroll++) {
if (isNaN(mapStatHash[codeTable[54][csroll][0]])) mapStatHash[codeTable[54][csroll][0]]=noDataText[word];
dcdDiv[codeTable[54][csroll][0]]=document.createElement("div");
dcdDiv[codeTable[54][csroll][0]].style.position="absolute";
dcdDiv[codeTable[54][csroll][0]].style.left=dcdGrid[codeTable[54][csroll][0]][0]+"px";
dcdDiv[codeTable[54][csroll][0]].style.top=dcdGrid[codeTable[54][csroll][0]][1]+"px";
var dcdGif=document.createElement("img");
if (!mapStatSeq[codeTable[54][csroll][0]]) mapStatSeq[codeTable[54][csroll][0]]=0
dcdGif.src="map/"+codeTable[54][csroll][0].toLowerCase()+"0"+mapStatSeq[codeTable[54][csroll][0]]+".gif";
dcdDiv[codeTable[54][csroll][0]].appendChild(dcdGif);
document.getElementById("mDiv0").appendChild(dcdDiv[codeTable[54][csroll][0]]);
document.getElementById("mDiv0").lastChild.id="dcdDiv"+codeTable[54][csroll][0];
}
var mapBorder=document.createElement("img");
mapBorder.src="map/border.gif";
mapBorder.useMap="#dcd_shapes";
mapBorder.style.position="absolute";
mapBorder.style.left="4px";
mapBorder.style.top="9px";
mapBorder.border="0px";
mapBorder.zIndex=20;
document.getElementById("mDiv0").appendChild(mapBorder);

if (document.getElementsByTagName("map").length>0) {
while (document.getElementById("dcd_shapes").childNodes.length>0) document.getElementById("dcd_shapes").removeChild(document.getElementById("dcd_shapes").lastChild)
var dcdMap=document.getElementById("dcd_shapes");
} else {
var dcdMap=document.createElement("map");
document.body.appendChild(dcdMap);
document.body.lastChild.id="dcd_shapes";
document.body.lastChild.name="dcd_shapes";
}
var dcdPieces=new Array();

for (csroll=0;csroll<18;csroll++) {
dcdPieces[csroll]=document.createElement("area");
dcdPieces[csroll].shape="poly";
dcdPieces[csroll].coords=dcdCoords[codeTable[54][csroll][0]];
dcdPieces[csroll].alt=prepIn_uc[word]+" "+codeTable[54][csroll][parseInt(word)+1]+" "+nounDCD[word]+", "+graphStatcntLabel+verbIs_1[word]+mapStatHash[codeTable[54][csroll][0]]+fullStop[word];
dcdPieces[csroll].href="javascript:alert('"+prepIn_uc[word]+" "+codeTable[54][csroll][parseInt(word)+1]+" "+nounDCD[word]+", "+graphStatcntLabel+verbIs_1[word]+mapStatHash[codeTable[54][csroll][0]]+fullStop[word]+"');";
dcdMap.appendChild(dcdPieces[csroll]);
}

if (document.getElementById("mapSel").selectedIndex!=document.getElementById("mapSel").length-1) mapTot=graphCellvarDisplay[document.getElementById("mapSel").selectedIndex]
else mapTot=graphCatColSubtotDisplay
var mapLegendDiv=document.createElement("div");
mapLegendDiv.style.position="absolute";
mapLegendDiv.style.left="0px";
mapLegendDiv.style.top="0px";
mapLegendDiv.style.zIndex=0;
mapLegendDiv.style.width="190px";
mapLegendDiv.style.padding="5px";
//mapLegendDiv.style.backgroundColor="#f0f0f0";

if (mapNotNullCount!=18) mapLegendDisc[0].push(noDataText[word])
for (p=0;p<mapStatUnique.length;p++) {
mapLegendDisc[Math.floor(((Math.pow((hashMapStatUnique["@"+mapStatUnique[p]]/mapStatUnique.length*2)-1,3)+1)*1.16/2)*4)+1].push(mapStatUnique[p])
}
var mapLegendTable=document.createElement("table");
mapLegendTable.style.width="180px";
var mapLegendTbody=document.createElement("tbody");
mapLegendTable.createCaption();
mapLegendTable.caption.align="center";
mapLegendTable.caption.style.fontWeight="bold";
mapLegendTable.caption.style.fontFamily="Bookman Old Style";
mapLegendTable.caption.style.fontSize=18;
mapLegendTable.caption.appendChild(document.createTextNode(mapLegendHead[word].split("").join(" ")));
var mapLegendStat=document.createElement("tr");
var mapLegendStatCell=document.createElement("td");
mapLegendStatCell.colSpan=3;
mapLegendStatCell.appendChild(document.createTextNode(graphStatcntLabel));
mapLegendStat.appendChild(mapLegendStatCell);
mapLegendStat.lastChild.id="mapLegend";
mapLegendTbody.appendChild(mapLegendStat);
for (s=0;s<5;s++) if (mapLegendDisc[s].length>0) {
var mapLegendLine=document.createElement("tr");
var mapLegendColor=document.createElement("td");
mapLegendColor.appendChild(document.createTextNode(legendDisc));
mapLegendColor.style.fontFamily=legendDiscFontFamily;
mapLegendColor.style.color=mapColorScheme[s];
mapLegendColor.style.width="15px";
mapLegendColor.style.backgroundColor=mapColorScheme[s];
var mapLegendSpacer=document.createElement("td");
var mapLegendDesc=document.createElement("td");
if (mapLegendDisc[s].length==1) mapLegendDesc.appendChild(document.createTextNode(mapLegendDisc[s].toString()))
else mapLegendDesc.appendChild(document.createTextNode(mapLegendDisc[s][0]+" - "+mapLegendDisc[s][mapLegendDisc[s].length-1]))
mapLegendLine.style.color="transparent";
mapLegendLine.appendChild(mapLegendColor);
mapLegendLine.lastChild.id="mapLegend";
mapLegendLine.appendChild(mapLegendSpacer);
mapLegendLine.lastChild.id="mapLegend";
mapLegendLine.appendChild(mapLegendDesc);
mapLegendLine.lastChild.id="mapLegend";
mapLegendTbody.appendChild(mapLegendLine);
}
mapLegendTable.appendChild(mapLegendTbody);
mapLegendDiv.appendChild(mapLegendTable);
document.getElementById("mDiv0").appendChild(mapLegendDiv);
mapHtml=document.getElementById("mDiv0").innerHTML;
var mapFoot=document.createElement("div");
var openMapBut=document.createElement("input");
openMapBut.type="button";
openMapBut.value=copyMapButton[word];
mapFoot.appendChild(openMapBut);
mapFoot.lastChild.id="openMapButton";
document.getElementById("resultM").appendChild(mapFoot);
document.getElementById("resultM").lastChild.id="mapFoot";
document.getElementById("openMapButton").onclick=openMap;

//window.scrollBy(0,600);
document.getElementById("mapTitleText").select();
document.getElementById("showMap").value=hideMapButton[word];
document.getElementById("showMap").onclick=hideMap;
}

function graphTheTable(){
if (variselected==false){
alert(noSelectRemind[word]);
return;
}
if (_app!='Microsoft Internet Explorer' && filterdata.length==0 || isNaN(graphGrandTot) || !isFinite(graphGrandTot)){
alert(noGraphMsg[word]);
return;
} 

if (_app=='Microsoft Internet Explorer' && mstxt.recordset.recordCount==0 || isNaN(graphGrandTot) || !isFinite(graphGrandTot)){
alert(noGraphMsg[word]);
return;
} 

var v , vspan;
var arrayPosmax=0;
var arrayNegmax=0;
var xroller;
var yroller;
var xLabelSeries=new Array();
var xSeries;
var ySeries;
var yValueSeries=new Array();
var yLabelSeries=new Array();
var isDecimal=false;
var graphRowTot=new Array();
var statShown=document.getElementById("cboStat").selectedIndex;
for (xroller=0;xroller<graphCellvar.length;xroller++){
if (document.getElementById("graphType").selectedIndex>0) graphRowTot[xroller]=0;
for (yroller=0;yroller<graphCellvar[0].length;yroller++){
if (document.getElementById("graphType").selectedIndex>0) graphRowTot[xroller]+=graphCellvar[xroller][yroller]
else {
if (graphCellvar[xroller][yroller]>arrayPosmax && graphCellvar[xroller][yroller]>0)arrayPosmax=graphCellvar[xroller][yroller]
if (graphCellvar[xroller][yroller]<arrayNegmax && graphCellvar[xroller][yroller]<0)arrayNegmax=graphCellvar[xroller][yroller]
if (Math.floor(graphCellvar[xroller][yroller])!=graphCellvar[xroller][yroller]) isDecimal=true;
}
}
if (document.getElementById("graphType").selectedIndex>0) {
if (graphRowTot[xroller]>arrayPosmax && graphRowTot[xroller]>0)arrayPosmax=graphRowTot[xroller]
if (graphRowTot[xroller]<arrayNegmax && graphRowTot[xroller]<0)arrayNegmax=graphRowTot[xroller]
if (Math.floor(graphRowTot[xroller])!=graphRowTot[xroller]) isDecimal=true;
}
}
if (arrayPosmax==0 && arrayNegmax==0) {
alert(noGraphMsg[word]);
return;
}
var xLabelPixelNeed;
var minGroupWidth=12;
var minBarWidth=6;
if (document.getElementById("graphType").selectedIndex==0) xLabelPixelNeed=Math.max((graphCellvar.length*graphCellvar[0].length)+(graphCellvar.length-1),(graphCellvar.length*minGroupWidth)+(graphCellvar.length-1))
else xLabelPixelNeed=(graphCellvar.length*minGroupWidth)+(graphCellvar.length-1)
var cWidth=Math.max(xLabelPixelNeed,(xLabelPixelNeed-(graphCellvar.length-1))*Math.ceil(screen.availWidth/2/(xLabelPixelNeed-(graphCellvar.length-1)))+(graphCellvar.length-1));
var eachBarWidth;
if (document.getElementById("graphType").selectedIndex==0) eachBarWidth=Math.max(minBarWidth,Math.ceil((cWidth-(graphCellvar.length-1))/(graphCellvar.length*graphCellvar[0].length)))
else eachBarWidth=Math.max(minGroupWidth,Math.ceil((cWidth-(graphCellvar.length-1))/graphCellvar.length))
var eachGroupWidth;
if (document.getElementById("graphType").selectedIndex==0) eachGroupWidth=eachBarWidth*graphCellvar[0].length
else eachGroupWidth=eachBarWidth
cWidth=eachGroupWidth*graphCellvar.length+(graphCellvar.length-1);
if (document.getElementById("chartTitleText")) chartTitle=document.getElementById("chartTitleText").value
if (!chartTitle) chartTitle=inputTitle[word]+" \n"+modulename[word].toUpperCase()
resultC.innerHTML="";
resultC.style.height="0px";
var cTitleDiv=document.createElement("div");
var chartTitleP=document.createElement("textarea");
chartTitleP.style.scrollbarFaceColor="white";
chartTitleP.style.scrollbarArrowColor="white";
chartTitleP.style.scrollbarShadowColor="white";
chartTitleP.style.scrollbarDarkShadowColor="white";
chartTitleP.style.scrollbar3dLightColor="white";
chartTitleP.style.width=screen.availWidth*0.9;
chartTitleP.style.height="100px";
chartTitleP.style.padding="10px";
chartTitleP.style.border="0px";
chartTitleP.style.fontSize="18";
chartTitleP.style.fontFamily="Arial";
chartTitleP.style.fontWeight="Bold";
chartTitleP.appendChild(document.createTextNode(chartTitle));
cTitleDiv.appendChild(chartTitleP);
cTitleDiv.lastChild.id="chartTitleText";
document.getElementById("resultC").appendChild(cTitleDiv);
document.getElementById("resultC").lastChild.id="cTitleDiv";
var cDiv0=document.createElement("div");
cDiv0.style.position="absolute";
cDiv0.style.left="0px";
cDiv0.style.top="0px";
resultC.appendChild(cDiv0);
resultC.lastChild.id="cDiv0";

vspan=arrayPosmax-arrayNegmax;
v=Math.pow(10,Math.ceil(Math.round((Math.log(vspan)/Math.log(10))-1)));
if (v<1 && isDecimal==false) v=1
if((arrayPosmax/v > 10 && arrayPosmax/v <=20) || (arrayNegmax/v < -10 && arrayNegmax/v >=-20))v=v*2
if(arrayPosmax/v >20 || arrayNegmax/v <-20)v=v*5
if (Math.pow(10,(statvarDecimal[statShown])*-1)>v) v=Math.pow(10,(statvarDecimal[statShown])*-1)
var cHeight=(Math.ceil(arrayPosmax/v)+Math.ceil(-1*arrayNegmax/v))*Math.ceil(Math.floor((screen.availHeight-400)/10)*10/(arrayPosmax-arrayNegmax)*v);
var maxLenCatRowDesc="";
var maxCharLenCatRowDesc;
var sp;
var catRowDescArray=new Array();
catRowDescArray=[];





if (word==0) {
for (sp=0;sp<graphCatRowDesc.length;sp++) catRowDescArray=catRowDescArray.concat(graphCatRowDesc[sp].split(" "))
catRowDescArray.sort(sortStrLen);
if (catRowDescArray.length>0) maxCharLenCatRowDesc=catRowDescArray[0].length
} else maxCharLenCatRowDesc=3

for (sp=0;sp<graphCatRowDesc.length;sp++) if (graphCatRowDesc[sp].length>maxLenCatRowDesc.length) maxLenCatRowDesc=graphCatRowDesc[sp]

if ((graphCatRowDesc.length>18) || (word>0 && maxLenCatRowDesc.length*graphCatRowDesc.length>(screen.width/18))) var spliter=""
else var spliter=" "
for (xSeries=0;xSeries<graphCatRowDesc.length;xSeries++) xLabelSeries[xSeries]=graphCatRowDesc[xSeries]
var i = new Graph(cWidth,Math.floor((screen.availHeight-400)/10)*10,cHeight,eachBarWidth,eachGroupWidth,maxCharLenCatRowDesc, maxLenCatRowDesc.length);
i.scale = v;
switch (document.getElementById("graphType").selectedIndex)
{
  case 0:
	i.relative = false;
	i.stacked = false;
	if (word==0)
		graphStatcntLabel = "Number "+ graphStatcntLabel.substring(graphStatcntLabel.indexOf("of"),graphStatcntLabel.length);
	break;

  case 1:
	i.relative = false;
	i.stacked = true;
	if (word==0)
		graphStatcntLabel = "Number "+ graphStatcntLabel.substring(graphStatcntLabel.indexOf("of"),graphStatcntLabel.length);
	break;

  case 2:
	i.relative = true;
	i.stacked = true;
	if (word==0)
		graphStatcntLabel = "Pecentage "+ graphStatcntLabel.substring(graphStatcntLabel.indexOf("of"),graphStatcntLabel.length);
	break;
}

i.setXScaleValues(xLabelSeries);
i.longDate = false;
yLabelSeries=graphCatColDesc;
i.setLegend(yLabelSeries);
for (ySeries=0;ySeries<graphCellvar[0].length;ySeries++){
yValueSeries=[];
for (xSeries=0;xSeries<graphCellvar.length;xSeries++) yValueSeries[xSeries]=graphCellvar[xSeries][ySeries]
i.addRow(yValueSeries);
}
//i.title=prompt(inputChartTitle[word],modulename[word].toUpperCase());
if (!i.title) i.title=" ";
i.xLabel=graphGpVarRowLabel;
i.yLabel=graphStatcntLabel;
i.skip=1
i.bgColor="#DDEEFF";
i.build(v,arrayPosmax,arrayNegmax);
var chartFoot=document.createElement("div");
chartFoot.style.position="relative";
chartFoot.style.top="10px";
chartFoot.style.left="0px";
chartFoot.style.height=i.chartFootHeight+"px";
var openGraphBut=document.createElement("input");
openGraphBut.type="button";
openGraphBut.value=copyGraphButton[word];
chartFoot.appendChild(openGraphBut);
chartFoot.lastChild.id="openGraphButton";
resultC.appendChild(chartFoot);
document.getElementById("openGraphButton").onclick=openGraph;
document.getElementById("showGraph").value=hideGraphButton[word];
document.getElementById("showGraph").onclick=hideGraph;
document.getElementById("chartTitleText").select();
}

function openTable(tab){
var tableWin=open('','stattable','', replace='replace');
tableWin.document.write("<HTML><HEAD><LINK REL='stylesheet' HREF='css/query.css' TYPE='text/css'><TITLE>"+phisHead[word]+"</TITLE></HEAD><BODY>"+critStr+resultGall+"</BODY></HTML>");
tableWin.focus();
tableWin.document.close();
}

function openGraph(tab){
var chartTitleHtml=document.getElementById("cTitleDiv").innerHTML;
var graphWin=open('','statgraph','', replace='replace');
var graphFoot = "<CENTER><TABLE><TR HEIGHT=50 VALIGN=BOTTOM><TD ID='chart'><INPUT TYPE=BUTTON SIZE=10 VALUE='"+printGraphButton[word]+"' ONCLICK='window.print();' LANGUAGE='Javascript'>&nbsp;&nbsp;&nbsp;<INPUT TYPE=BUTTON SIZE=10 VALUE='"+closeWinButton[word]+"' ONCLICK='graphwindow=false;window.close();' LANGUAGE='Javascript'></TD><TR/></TABLE></CENTER>";
graphWin.document.write("<HTML><HEAD><LINK REL='stylesheet' HREF='css/query.css' TYPE='text/css'><TITLE>"+phisHead[word]+"</TITLE></HEAD><BODY>");
graphWin.document.write("<div style='position:relative;'>"+chartTitleHtml+"</div>");
graphWin.document.write("<div style='position:relative; width:"+document.getElementById("chartProper").style.width+"'>"+document.getElementById("chartProper").innerHTML+"</div>");
graphWin.document.write("<div style='position:relative; top:"+document.getElementById("chartProper").style.height+";'>"+critStr+graphFoot+"</div></BODY></HTML>");
graphWin.focus();
graphWin.document.close();
}

function hideGraph(){
if (document.getElementById("chartTitleText")) chartTitle=document.getElementById("chartTitleText").value;
resultC.innerHTML="";
resultC.style.border="white 0px";
resultC.style.height="0px";
document.getElementById("showGraph").value=showGraphButton[word];
document.getElementById("showGraph").onclick=graphTheTable;
}

function openMap(tab){
var mapTitleHtml=document.getElementById("mTitleDiv").innerHTML;
var mapWin=open('','statmap','', replace='replace');
mapWin.document.write("<HTML><HEAD><LINK REL='stylesheet' HREF='css/query.css' TYPE='text/css'><TITLE>"+phisHead[word]+"</TITLE></HEAD><BODY>");
mapWin.document.write("<div style='position: relative; width: 800px;'>"+mapTitleHtml+"</div>");
mapWin.document.write("<div style='position: relative;'>"+mapHtml+"</div>");
mapWin.document.write("<div style='position: relative;'><p><i>"+graphGpVarRowLabel+" : "+document.getElementById("mapSel").options[document.getElementById("mapSel").selectedIndex].text+"</i></p></div>");
mapWin.document.write("<div style='position: relative;'>"+critStr+"</div>");
var mapFoot = "<CENTER><TABLE><TR HEIGHT=50 VALIGN=BOTTOM><TD ID='chart'><INPUT TYPE=BUTTON SIZE=10 VALUE='"+printMapButton[word]+"' ONCLICK='window.print();' LANGUAGE='Javascript'>&nbsp;&nbsp;&nbsp;<INPUT TYPE=BUTTON SIZE=10 VALUE='"+closeWinButton[word]+"' ONCLICK='graphwindow=false;window.close();' LANGUAGE='Javascript'></TD><TR/></TABLE></CENTER>";
mapWin.document.write("<map name='dcd_shapes' id='dcd_shapes'>"+document.getElementById("dcd_shapes").innerHTML+"</map>");
mapWin.document.write(mapFoot);
mapWin.focus();
mapWin.document.close();
}

function hideMap(){
document.getElementById("mDiv0").innerHTML="";
if (document.getElementById("mapFoot")) resultM.removeChild(document.getElementById("mapFoot"))
if (document.getElementById("mapTitleText")) mapTitle=document.getElementById("mapTitleText").value
document.getElementById("mTitleDiv").innerHTML="";
document.getElementById("mDiv0").style.width="0px";
document.getElementById("mDiv0").style.height="0px";
document.getElementById("showMap").value=showMapButton[word];
document.getElementById("showMap").onclick=mapper;
}

function sortByVar(a,b){
if (codeTable[codesetVar[var2by2]]){
a=codeHash[var2by2][a[var2by2]];
b=codeHash[var2by2][b[var2by2]];
} else {
a=a[var2by2];
b=b[var2by2];
}
return ((a<b)?-1:((a>b)?1:0));
}

function sortStrLen(a,b) {
a=a.length;
b=b.length;
return ((a>b)?-1:((a<b)?1:0));
}

function statButton(){
if (resultG.innerHTML=="&nbsp;" || resultG.innerHTML.length<1) showhide.innerHTML="<INPUT TYPE=BUTTON VALUE='"+showStat[word]+"' ONCLICK='showStatTab();'>"
else showhide.innerHTML="<INPUT TYPE=BUTTON VALUE='"+hideStat[word]+"' ONCLICK='resultG.innerHTML=\"\";statButton();'>"
}

function showStatTab(){
if (resultGall.length>0) {
var resultVT="<P>"+"<INPUT TYPE=BUTTON VALUE='"+copyTableButton[word]+"' ONCLICK='openTable();'>";
resultG.innerHTML=resultGall+resultVT;
statButton();
showGraph.disabled=false;
location="#tableanchor"; 
} else cntby();
}
//-->

