
//declaration of arrays
var arrInst_Dis = new Array();
var arrAENormalDis = new Array();
var arrAEIVE_STDis = new Array();
var arrAEIVE_LWLDis = new Array();
var arrAEIVE_KTDis = new Array();
var arrAEIVE_TYDis = new Array();
var arrAEIVE_MHDis = new Array();
var arrAEIVE_HWDis = new Array();
var arrAEIVE_KCDis = new Array();
var arrAEIVE_TMDis = new Array();
var arrAEIVE_CWDis = new Array();
var arrAEHKIEDDis = new Array();
var arrAEPPDHDis = new Array();
var arrAEAPADis = new Array();

var arrULevel = new Array("--Select a level--", "", "Sub-degree or below", "Sub-degree or below", "Undergraduate", "Undergraduate", "Postgraduate", "Postgraduate");
var arrAPALevel = new Array("--Select a level--", "", "Subdegree", "Subdegree", "Degree", "Degree");

var arrAENormalUnder = new Array();
var arrAENormalPost = new Array();
var arrAEIVE_STUnder = new Array();
var arrAEIVE_STPost = new Array();
var arrAEIVE_LWLUnder = new Array();
var arrAEIVE_LWLPost = new Array();
var arrAEIVE_KTUnder = new Array();
var arrAEIVE_KTPost = new Array();
var arrAEIVE_TYUnder = new Array();
var arrAEIVE_TYPost = new Array();
var arrAEIVE_MHUnder = new Array();
var arrAEIVE_MHPost = new Array();
var arrAEIVE_HWUnder = new Array();
var arrAEIVE_HWPost = new Array();
var arrAEIVE_KCUnder = new Array();
var arrAEIVE_KCPost = new Array();
var arrAEIVE_TMUnder = new Array();
var arrAEIVE_TMPost = new Array();
var arrAEIVE_CWUnder = new Array();
var arrAEIVE_CWPost = new Array();
var arrAEHKIEDUnder = new Array();
var arrAEHKIEDPost = new Array();
var arrAEPPDHUnder = new Array();
var arrAEPPDHPost = new Array();
var arrAEAPASub = new Array();
var arrAEAPADeg = new Array();

var arrGLBound = new Array();
var arrGPer = new Array();
var arrLPer = new Array();
var arrAssetBound = new Array();
var arrAssetPer = new Array();
var arrTFee = new Array();
var curMaxLoan=0;
var curMaxME=0;
var datestr = "";
var datestr2 = "";
var MaxMedicalExpense = 0;

var yearStart = "";
var yearLast = "";
var yearBeforeStart = "";


//declaration of reference node variables
var calculator_node, institutions_node, ae_node, subjects_node;
var grantandloan_node, asset_node, fee_node, maxloan_node, maxME_node;
var normal_subject_node, IVE_ST_subject_node, IVE_LWL_subject_node, IVE_KT_subject_node; 
var IVE_TY_subject_node, IVE_MH_subject_node, IVE_HW_subject_node, IVE_KC_subject_node;
var IVE_TM_subject_node, IVE_CW_subject_node, HKIED_subject_node, PPDH_subject_node;
var apa_subject_node;
var datestr_node;

//Regular expression used to match any non-whitespace character
var notWhitespace = /\S/


//load xml file
if (window.ActiveXObject)
{
	var xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
	xmlDoc.async = false; //Enforce download of XML file first. IE only.
	//alert("Internet Explorer");
}
else if (document.implementation && document.implementation.createDocument)
{
	var xmlDoc = document.implementation.createDocument("","doc",null);
	//alert("Netscape Navigator");
}

if (typeof xmlDoc!="undefined")
{
	//xmlDoc.load("dailynews.xml");	
	xmlDoc.load("data.xml");	
	//alert(xmlDoc);	//ok
}


if (typeof xmlDoc!="undefined")
{
	if (window.ActiveXObject) //if IE, simply execute script (due to async prop).
		iegetdata()
	else
	{	
		//else if NS6, execute script when XML object has loaded
		xmlDoc.onload=nsgetdata
	}
}


////////////////////////////////////ie getdata functions///////////////////////////////////////////////
function iegetdata()
{
	//Cache "messages" element of xml file
	//var msgobj=xmlDoc.getElementsByTagName("messages")[0]
	var msgobj=xmlDoc.getElementsByTagName("calculator")[0]
		
	//REMOVE white spaces in XML file. Intended mainly for NS6/Mozilla
	for (i=0;i<msgobj.childNodes.length;i++)
	{
		if ((msgobj.childNodes[i].nodeType == 3)&&(!notWhitespace.test(msgobj.childNodes[i].nodeValue)))
		{
			// that is, if it's a whitespace text node
			msgobj.removeChild(msgobj.childNodes[i])
			i--
		}
	}

	/////////////////////////////////////////////////// Sample code //////////////////////////////////////////////////////////////////
	//var dateobj=new Date()
	//var today=dateobj.getDay() //returns 0-6. 0=Sunday
	//Get today's message and display it in DIV:
	//document.getElementById("container").innerHTML=xmlDoc.getElementsByTagName("messages")[0].childNodes[today].firstChild.nodeValue
	//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
		
	calculator_node = xmlDoc.documentElement;
	institutions_node = calculator_node.firstChild;
	ae_node = institutions_node.nextSibling;
	grantandloan_node = ae_node.nextSibling;
	asset_node = grantandloan_node.nextSibling;
	fee_node = asset_node.nextSibling;
	maxloan_node = fee_node.nextSibling;
	maxME_node = maxloan_node.nextSibling;
	datestr_node = maxME_node.nextSibling;
	
	normal_subject_node = ae_node.firstChild;	
	IVE_ST_subject_node = normal_subject_node.nextSibling;
	IVE_LWL_subject_node = IVE_ST_subject_node.nextSibling;
	IVE_KT_subject_node = IVE_LWL_subject_node.nextSibling;
	IVE_TY_subject_node = IVE_KT_subject_node.nextSibling;
	IVE_MH_subject_node = IVE_TY_subject_node.nextSibling;
	IVE_HW_subject_node = IVE_MH_subject_node.nextSibling;	
	IVE_KC_subject_node = IVE_HW_subject_node.nextSibling;
	IVE_TM_subject_node = IVE_KC_subject_node.nextSibling;
	IVE_CW_subject_node = IVE_TM_subject_node.nextSibling;
	HKIED_subject_node = IVE_CW_subject_node.nextSibling;
	PPDH_subject_node = HKIED_subject_node.nextSibling;
	apa_subject_node = ae_node.lastChild;
	
		
	iereadinstitution();
	
	iereadNormalDisName();
	iereadIVE_ST_DisName();
	iereadIVE_LWL_DisName();
	iereadIVE_KT_DisName();
	iereadIVE_TY_DisName();
	iereadIVE_MH_DisName();
	iereadIVE_HW_DisName();
	iereadIVE_KC_DisName();
	iereadIVE_TM_DisName();
	iereadIVE_CW_DisName();
	iereadHKIEDDisName();
	iereadPPDHDisName();
	iereadAPADisName();
	
	iereadNormalAE();
	iereadIVE_ST_AE();
	iereadIVE_LWL_AE();
	iereadIVE_KT_AE();
	iereadIVE_TY_AE();
	iereadIVE_MH_AE();
	iereadIVE_HW_AE();
	iereadIVE_KC_AE();
	iereadIVE_TM_AE();
	iereadIVE_CW_AE();
	iereadHKIEDAE();
	iereadPPDHAE();
	iereadAPAAE();
		
	iereadgrantloan();
	iereadasset();
	iereadfee();
	iereadmaxloan();
	iereadmaxME();
	iereaddatestr();
}


function iereadinstitution()
{
	var i;
	
	arrInst_Dis[0] = "--Select an institution--";
	arrInst_Dis[1] = "";
	
	for (i=2; i<(parseInt(institutions_node.childNodes.length) + 1)*2; i++)
	{
		arrInst_Dis[i] = institutions_node.childNodes[(i/2)-1].attributes.getNamedItem("name").value;
		//alert(arrInst_Dis[i]);
		arrInst_Dis[i+1] = institutions_node.childNodes[(i/2)-1].attributes.getNamedItem("type").value;
		//alert(arrInst_Dis[i+1]);
		i++;
	}
}


function iereadNormalDisName()
{
	var i;
	
	arrAENormalDis[0] = "--Select a discipline--";
	arrAENormalDis[1] = "";
	for (i=2; i<(normal_subject_node.childNodes.length + 1)*2; i++)
	{
		arrAENormalDis[i] = normal_subject_node.childNodes[(i/2)-1].attributes.getNamedItem("discipline").value;
		arrAENormalDis[i+1] = "";
		i++;
	}
}


function iereadIVE_ST_DisName()
{
	var i;
	
	arrAEIVE_STDis[0] = "--Select a discipline--";
	arrAEIVE_STDis[1] = "";
	for (i=2; i<(IVE_ST_subject_node.childNodes.length + 1)*2; i++)
	{
		arrAEIVE_STDis[i] = IVE_ST_subject_node.childNodes[(i/2)-1].attributes.getNamedItem("discipline").value;
		arrAEIVE_STDis[i+1] = "";
		i++;
	}
}


function iereadIVE_LWL_DisName()
{
	var i;
	
	arrAEIVE_LWLDis[0] = "--Select a discipline--";
	arrAEIVE_LWLDis[1] = "";
	for (i=2; i<(IVE_LWL_subject_node.childNodes.length + 1)*2; i++)
	{
		arrAEIVE_LWLDis[i] = IVE_LWL_subject_node.childNodes[(i/2)-1].attributes.getNamedItem("discipline").value;
		arrAEIVE_LWLDis[i+1] = "";
		i++;
	}
}


function iereadIVE_KT_DisName()
{
	var i;
	
	arrAEIVE_KTDis[0] = "--Select a discipline--";
	arrAEIVE_KTDis[1] = "";
	for (i=2; i<(IVE_KT_subject_node.childNodes.length + 1)*2; i++)
	{
		arrAEIVE_KTDis[i] = IVE_KT_subject_node.childNodes[(i/2)-1].attributes.getNamedItem("discipline").value;
		arrAEIVE_KTDis[i+1] = "";
		i++;
	}
}


function iereadIVE_TY_DisName()
{
	var i;
	
	arrAEIVE_TYDis[0] = "--Select a discipline--";
	arrAEIVE_TYDis[1] = "";
	for (i=2; i<(IVE_TY_subject_node.childNodes.length + 1)*2; i++)
	{
		arrAEIVE_TYDis[i] = IVE_TY_subject_node.childNodes[(i/2)-1].attributes.getNamedItem("discipline").value;
		arrAEIVE_TYDis[i+1] = "";
		i++;
	}
}


function iereadIVE_MH_DisName()
{
	var i;
	
	arrAEIVE_MHDis[0] = "--Select a discipline--";
	arrAEIVE_MHDis[1] = "";
	for (i=2; i<(IVE_MH_subject_node.childNodes.length + 1)*2; i++)
	{
		arrAEIVE_MHDis[i] = IVE_MH_subject_node.childNodes[(i/2)-1].attributes.getNamedItem("discipline").value;
		arrAEIVE_MHDis[i+1] = "";
		i++;
	}
}


function iereadIVE_HW_DisName()
{
	var i;
	
	arrAEIVE_HWDis[0] = "--Select a discipline--";
	arrAEIVE_HWDis[1] = "";
	for (i=2; i<(IVE_HW_subject_node.childNodes.length + 1)*2; i++)
	{
		arrAEIVE_HWDis[i] = IVE_HW_subject_node.childNodes[(i/2)-1].attributes.getNamedItem("discipline").value;
		arrAEIVE_HWDis[i+1] = "";
		i++;
	}
}


function iereadIVE_KC_DisName()
{
	var i;
	
	arrAEIVE_KCDis[0] = "--Select a discipline--";
	arrAEIVE_KCDis[1] = "";
	for (i=2; i<(IVE_KC_subject_node.childNodes.length + 1)*2; i++)
	{
		arrAEIVE_KCDis[i] = IVE_KC_subject_node.childNodes[(i/2)-1].attributes.getNamedItem("discipline").value;
		arrAEIVE_KCDis[i+1] = "";
		i++;
	}
}


function iereadIVE_TM_DisName()
{
	var i;
	
	arrAEIVE_TMDis[0] = "--Select a discipline--";
	arrAEIVE_TMDis[1] = "";
	for (i=2; i<(IVE_TM_subject_node.childNodes.length + 1)*2; i++)
	{
		arrAEIVE_TMDis[i] = IVE_TM_subject_node.childNodes[(i/2)-1].attributes.getNamedItem("discipline").value;
		arrAEIVE_TMDis[i+1] = "";
		i++;
	}
}


function iereadIVE_CW_DisName()
{
	var i;
	
	arrAEIVE_CWDis[0] = "--Select a discipline--";
	arrAEIVE_CWDis[1] = "";
	for (i=2; i<(IVE_CW_subject_node.childNodes.length + 1)*2; i++)
	{
		arrAEIVE_CWDis[i] = IVE_CW_subject_node.childNodes[(i/2)-1].attributes.getNamedItem("discipline").value;
		arrAEIVE_CWDis[i+1] = "";
		i++;
	}
}


function iereadHKIEDDisName()
{
	var i;
	
	arrAEHKIEDDis[0] = "--Select a discipline--";
	arrAEHKIEDDis[1] = "";
	for (i=2; i<(HKIED_subject_node.childNodes.length + 1)*2; i++)
	{
		arrAEHKIEDDis[i] = HKIED_subject_node.childNodes[(i/2)-1].attributes.getNamedItem("discipline").value;
		arrAEHKIEDDis[i+1] = "";
		i++;
	}
}


function iereadPPDHDisName()
{
	var i;
	
	arrAEPPDHDis[0] = "--Select a discipline--";
	arrAEPPDHDis[1] = "";
	for (i=2; i<(PPDH_subject_node.childNodes.length + 1)*2; i++)
	{
		arrAEPPDHDis[i] = PPDH_subject_node.childNodes[(i/2)-1].attributes.getNamedItem("discipline").value;
		arrAEPPDHDis[i+1] = "";
		i++;
	}
}


function iereadAPADisName()
{
	var i;
	
	arrAEAPADis[0] = "--Select a discipline--";
	arrAEAPADis[1] = "";
	for (i=2; i<(apa_subject_node.childNodes.length + 1)*2; i++)
	{
		arrAEAPADis[i] = apa_subject_node.childNodes[(i/2)-1].attributes.getNamedItem("discipline").value;
		arrAEAPADis[i+1] = "";
		i++;
	}
}


function iereadNormalAE()
{
	var i;
	for (i=0; i<normal_subject_node.childNodes.length; i++)
	{
		arrAENormalUnder[i] = normal_subject_node.childNodes[i].attributes.getNamedItem("undergrad").value;
		arrAENormalPost[i] = normal_subject_node.childNodes[i].attributes.getNamedItem("postgrad").value;
	}
}


function iereadIVE_ST_AE()
{
	var i;
	for (i=0; i<IVE_ST_subject_node.childNodes.length; i++)
	{
		arrAEIVE_STUnder[i] = IVE_ST_subject_node.childNodes[i].attributes.getNamedItem("undergrad").value;
		arrAEIVE_STPost[i] = IVE_ST_subject_node.childNodes[i].attributes.getNamedItem("postgrad").value;
	}
}


function iereadIVE_LWL_AE()
{
	var i;
	for (i=0; i<IVE_LWL_subject_node.childNodes.length; i++)
	{
		arrAEIVE_LWLUnder[i] = IVE_LWL_subject_node.childNodes[i].attributes.getNamedItem("undergrad").value;
		arrAEIVE_LWLPost[i] = IVE_LWL_subject_node.childNodes[i].attributes.getNamedItem("postgrad").value;
	}
}


function iereadIVE_KT_AE()
{
	var i;
	for (i=0; i<IVE_KT_subject_node.childNodes.length; i++)
	{
		arrAEIVE_KTUnder[i] = IVE_KT_subject_node.childNodes[i].attributes.getNamedItem("undergrad").value;
		arrAEIVE_KTPost[i] = IVE_KT_subject_node.childNodes[i].attributes.getNamedItem("postgrad").value;
	}
}


function iereadIVE_TY_AE()
{
	var i;
	for (i=0; i<IVE_TY_subject_node.childNodes.length; i++)
	{
		arrAEIVE_TYUnder[i] = IVE_TY_subject_node.childNodes[i].attributes.getNamedItem("undergrad").value;
		arrAEIVE_TYPost[i] = IVE_TY_subject_node.childNodes[i].attributes.getNamedItem("postgrad").value;
	}
}


function iereadIVE_MH_AE()
{
	var i;
	for (i=0; i<IVE_MH_subject_node.childNodes.length; i++)
	{
		arrAEIVE_MHUnder[i] = IVE_MH_subject_node.childNodes[i].attributes.getNamedItem("undergrad").value;
		arrAEIVE_MHPost[i] = IVE_MH_subject_node.childNodes[i].attributes.getNamedItem("postgrad").value;
	}
}
		

function iereadIVE_HW_AE()
{
	var i;
	for (i=0; i<IVE_HW_subject_node.childNodes.length; i++)
	{
		arrAEIVE_HWUnder[i] = IVE_HW_subject_node.childNodes[i].attributes.getNamedItem("undergrad").value;
		arrAEIVE_HWPost[i] = IVE_HW_subject_node.childNodes[i].attributes.getNamedItem("postgrad").value;
	}
}


function iereadIVE_KC_AE()
{
	var i;
	for (i=0; i<IVE_KC_subject_node.childNodes.length; i++)
	{
		arrAEIVE_KCUnder[i] = IVE_KC_subject_node.childNodes[i].attributes.getNamedItem("undergrad").value;
		arrAEIVE_KCPost[i] = IVE_KC_subject_node.childNodes[i].attributes.getNamedItem("postgrad").value;
	}
}


function iereadIVE_TM_AE()
{
	var i;
	for (i=0; i<IVE_TM_subject_node.childNodes.length; i++)
	{
		arrAEIVE_TMUnder[i] = IVE_TM_subject_node.childNodes[i].attributes.getNamedItem("undergrad").value;
		arrAEIVE_TMPost[i] = IVE_TM_subject_node.childNodes[i].attributes.getNamedItem("postgrad").value;
	}
}


function iereadIVE_CW_AE()
{
	var i;
	for (i=0; i<IVE_CW_subject_node.childNodes.length; i++)
	{
		arrAEIVE_CWUnder[i] = IVE_CW_subject_node.childNodes[i].attributes.getNamedItem("undergrad").value;
		arrAEIVE_CWPost[i] = IVE_CW_subject_node.childNodes[i].attributes.getNamedItem("postgrad").value;
	}
}


function iereadHKIEDAE()
{
	var i;
	for (i=0; i<HKIED_subject_node.childNodes.length; i++)
	{
		arrAEHKIEDUnder[i] = HKIED_subject_node.childNodes[i].attributes.getNamedItem("undergrad").value;
		arrAEHKIEDPost[i] = HKIED_subject_node.childNodes[i].attributes.getNamedItem("postgrad").value;
	}
}


function iereadPPDHAE()
{
	var i;
	for (i=0; i<PPDH_subject_node.childNodes.length; i++)
	{
		arrAEPPDHUnder[i] = PPDH_subject_node.childNodes[i].attributes.getNamedItem("undergrad").value;
		arrAEPPDHPost[i] = PPDH_subject_node.childNodes[i].attributes.getNamedItem("postgrad").value;
	}
}


function iereadAPAAE()
{
	var i;
	for (i=0; i<apa_subject_node.childNodes.length; i++)
	{
		arrAEAPASub[i] = apa_subject_node.childNodes[i].attributes.getNamedItem("subdegree").value;
		arrAEAPADeg[i] = apa_subject_node.childNodes[i].attributes.getNamedItem("degree").value;
	}
}


function iereadgrantloan()
{
	var i;
	for (i=0; i<grantandloan_node.childNodes.length; i++)
	{
		arrGLBound[i] = grantandloan_node.childNodes[i].attributes.getNamedItem("lbound").value;
		arrGPer[i] = grantandloan_node.childNodes[i].attributes.getNamedItem("grantpercent").value;
		arrLPer[i] = grantandloan_node.childNodes[i].attributes.getNamedItem("loanpercent").value;
	}
}


function iereadasset()
{
	var i;
	for (i=0; i<asset_node.childNodes.length; i++)
	{
		arrAssetBound[i] = asset_node.childNodes[i].attributes.getNamedItem("lbound").value;
		arrAssetPer[i] = asset_node.childNodes[i].attributes.getNamedItem("assetpercent").value;
	}
}


function iereadfee()
{
	var i;
	for (i=0; i<fee_node.childNodes.length; i++)
	{
		arrTFee[i] = fee_node.childNodes[i].firstChild.nodeValue;
	}
}


function iereadmaxloan()
{
	curMaxLoan = maxloan_node.firstChild.nodeValue;
	//alert("max loan = " + curMaxLoan);
}


function iereadmaxME()
{
	curMaxME = maxME_node.firstChild.nodeValue;
	//alert("max ME = " + curMaxLoan);
}


function iereaddatestr()
{
	datestr = datestr_node.firstChild.nodeValue;
	yearStart = datestr.substring(0,4) + "";
	yearLast = datestr.substring(5,7) + "";
	yearBeforeStart = parseInt(yearStart) - 1;
	
	var temp1 = parseInt(yearStart)+1 + "";
	var temp2 = parseInt(yearStart)+2 + "";
	datestr2 = temp1 + "/" + temp2.substring(2,4) + "";
	//alert("datestr = " + datestr);
	//alert("datestr2 = " + datestr2);
	//alert(yearStart);
	//alert(yearLast);
	//alert(yearBeforeStart);
}


//////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////


////////////////////////////////////netscape getdata functions///////////////////////////////////////////////
function nsgetdata()
{
	//Cache "messages" element of xml file
	//var msgobj=xmlDoc.getElementsByTagName("messages")[0]
	var msgobj=xmlDoc.getElementsByTagName("calculator")[0]
	
	//REMOVE white spaces in XML file. Intended mainly for NS6/Mozilla
	for (i=0;i<msgobj.childNodes.length;i++)
	{
		if ((msgobj.childNodes[i].nodeType == 3)&&(!notWhitespace.test(msgobj.childNodes[i].nodeValue)))
		{
			// that is, if it's a whitespace text node
			msgobj.removeChild(msgobj.childNodes[i])
			i--
		}
	}

	/////////////////////////////////////////////////// Sample code //////////////////////////////////////////////////////////////////
	//var dateobj=new Date()
	//var today=dateobj.getDay() //returns 0-6. 0=Sunday
	//Get today's message and display it in DIV:
	//document.getElementById("container").innerHTML=xmlDoc.getElementsByTagName("messages")[0].childNodes[today].firstChild.nodeValue
	//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	
	
	//document.getElementById("container").innerHTML=
	//xmlDoc.getElementsByTagName("subjects")[1].childNodes[5].attributes.getNamedItem("discipline").value + "<br>" +
	//xmlDoc.getElementsByTagName("asset")[0].childNodes[3].attributes.getNamedItem("lbound").value + "<br>" + 	//work
	//xmlDoc.getElementsByTagName("fee")[0].childNodes[1].firstChild.nodeValue + "<br>" + 		//work
	//xmlDoc.getElementsByTagName("calculator")[0].childNodes[5].firstChild.nodeValue + "<br>" 	//work
	//
	//xmlDoc.getElementsByTagName("calculator")[0].childNodes[6].firstChild.nodeValue;
	//fee_node.childNodes[0].firstChild.nodeValue;
	//xmlDoc.getElementsByTagName("test1")[0].childNodes[0].firstChild.nodeValue

	//institutions_node = xmlDoc.getElementsByTagName("institutions")[0].childNodes;
	//xmlDoc.getElementsByTagName("asset")[0].childNodes[3].attributes.getNamedItem("lbound").value + "<br>" + 	//work
	//xmlDoc.getElementsByTagName("fee")[0].childNodes[1].firstChild.nodeValue + "<br>" + 		//work
	//xmlDoc.getElementsByTagName("calculator")[0].childNodes[5].firstChild.nodeValue + "<br>" 	//work
	//
	//xmlDoc.getElementsByTagName("calculator")[0].childNodes[6].firstChild.nodeValue;
	//fee_node.childNodes[0].firstChild.nodeValue;
	//xmlDoc.getElementsByTagName("test1")[0].childNodes[0].firstChild.nodeValue

	nsreadinstitution();
	
	nsreadNormalDisName();
	nsreadIVE_STDisName();
	nsreadIVE_LWLDisName();
	nsreadIVE_KTDisName();
	nsreadIVE_TYDisName();
	nsreadIVE_MHDisName();
	nsreadIVE_HWDisName();
	nsreadIVE_KCDisName();
	nsreadIVE_TMDisName();
	nsreadIVE_CWDisName();
	nsreadHKIEDDisName();
	nsreadPPDHDisName();
	nsreadAPADisName();
	
	nsreadNormalAE();
	nsreadIVE_STAE();
	nsreadIVE_LWLAE();
	nsreadIVE_KTAE();
	nsreadIVE_TYAE();
	nsreadIVE_MHAE();
	nsreadIVE_HWAE();
	nsreadIVE_KCAE();
	nsreadIVE_TMAE();
	nsreadIVE_CWAE();
	nsreadHKIEDAE();
	nsreadPPDHAE();
	nsreadAPAAE();
	
	nsreadgrantloan();
	nsreadasset();
	nsreadfee();
	nsreadmaxloan();
	nsreadmaxME();
	nsreaddatestr();
}


function nsreadinstitution()
{
	var i,j=1;
	
	arrInst_Dis[0] = "--Select an institution--";
	arrInst_Dis[1] = "";      
                                    
	for (i=2; i<parseInt(xmlDoc.getElementsByTagName("institutions")[0].childNodes.length + 1); i++)
	{				
		arrInst_Dis[i] = xmlDoc.getElementsByTagName("institutions")[0].childNodes[j].attributes.getNamedItem("name").value;
		//alert(arrInst_Dis[i]);
		arrInst_Dis[i+1] = xmlDoc.getElementsByTagName("institutions")[0].childNodes[j].attributes.getNamedItem("type").value;
		//alert(arrInst_Dis[i+1]);
		i++;
		j = j + 2;
	}
}


function nsreadNormalDisName()
{
	var i,j=1;
	
	arrAENormalDis[0] = "--Select a discipline--";
	arrAENormalDis[1] = "";

	for (i=2; i<parseInt(xmlDoc.getElementsByTagName("subjects")[0].childNodes.length + 1); i++)
	{	
		arrAENormalDis[i] = xmlDoc.getElementsByTagName("subjects")[0].childNodes[j].attributes.getNamedItem("discipline").value;
		arrAENormalDis[i+1] = "";
		i++;
		j = j + 2;
	}
}


function nsreadIVE_STDisName()
{
	var i,j=1;
	
	arrAEIVE_STDis[0] = "--Select a discipline--";
	arrAEIVE_STDis[1] = "";

	for (i=2; i<parseInt(xmlDoc.getElementsByTagName("subjects")[1].childNodes.length + 1); i++)
	{	
		arrAEIVE_STDis[i] = xmlDoc.getElementsByTagName("subjects")[1].childNodes[j].attributes.getNamedItem("discipline").value;
		arrAEIVE_STDis[i+1] = "";
		i++;
		j = j + 2;
	}
}


function nsreadIVE_LWLDisName()
{
	var i,j=1;
	
	arrAEIVE_LWLDis[0] = "--Select a discipline--";
	arrAEIVE_LWLDis[1] = "";

	for (i=2; i<parseInt(xmlDoc.getElementsByTagName("subjects")[2].childNodes.length + 1); i++)
	{	
		arrAEIVE_LWLDis[i] = xmlDoc.getElementsByTagName("subjects")[2].childNodes[j].attributes.getNamedItem("discipline").value;
		arrAEIVE_LWLDis[i+1] = "";
		i++;
		j = j + 2;
	}
}


function nsreadIVE_KTDisName()
{
	var i,j=1;
	
	arrAEIVE_KTDis[0] = "--Select a discipline--";
	arrAEIVE_KTDis[1] = "";

	for (i=2; i<parseInt(xmlDoc.getElementsByTagName("subjects")[3].childNodes.length + 1); i++)
	{	
		arrAEIVE_KTDis[i] = xmlDoc.getElementsByTagName("subjects")[3].childNodes[j].attributes.getNamedItem("discipline").value;
		arrAEIVE_KTDis[i+1] = "";
		i++;
		j = j + 2;
	}
}


function nsreadIVE_TYDisName()
{
	var i,j=1;
	
	arrAEIVE_TYDis[0] = "--Select a discipline--";
	arrAEIVE_TYDis[1] = "";

	for (i=2; i<parseInt(xmlDoc.getElementsByTagName("subjects")[4].childNodes.length + 1); i++)
	{	
		arrAEIVE_TYDis[i] = xmlDoc.getElementsByTagName("subjects")[4].childNodes[j].attributes.getNamedItem("discipline").value;
		arrAEIVE_TYDis[i+1] = "";
		i++;
		j = j + 2;
	}
}


function nsreadIVE_MHDisName()
{
	var i,j=1;
	
	arrAEIVE_MHDis[0] = "--Select a discipline--";
	arrAEIVE_MHDis[1] = "";

	for (i=2; i<parseInt(xmlDoc.getElementsByTagName("subjects")[5].childNodes.length + 1); i++)
	{	
		arrAEIVE_MHDis[i] = xmlDoc.getElementsByTagName("subjects")[5].childNodes[j].attributes.getNamedItem("discipline").value;
		arrAEIVE_MHDis[i+1] = "";
		i++;
		j = j + 2;
	}
}


function nsreadIVE_HWDisName()
{
	var i,j=1;
	
	arrAEIVE_HWDis[0] = "--Select a discipline--";
	arrAEIVE_HWDis[1] = "";

	for (i=2; i<parseInt(xmlDoc.getElementsByTagName("subjects")[6].childNodes.length + 1); i++)
	{	
		arrAEIVE_HWDis[i] = xmlDoc.getElementsByTagName("subjects")[6].childNodes[j].attributes.getNamedItem("discipline").value;
		arrAEIVE_HWDis[i+1] = "";
		i++;
		j = j + 2;
	}
}


function nsreadIVE_KCDisName()
{
	var i,j=1;
	
	arrAEIVE_KCDis[0] = "--Select a discipline--";
	arrAEIVE_KCDis[1] = "";

	for (i=2; i<parseInt(xmlDoc.getElementsByTagName("subjects")[7].childNodes.length + 1); i++)
	{	
		arrAEIVE_KCDis[i] = xmlDoc.getElementsByTagName("subjects")[7].childNodes[j].attributes.getNamedItem("discipline").value;
		arrAEIVE_KCDis[i+1] = "";
		i++;
		j = j + 2;
	}
}


function nsreadIVE_TMDisName()
{
	var i,j=1;
	
	arrAEIVE_TMDis[0] = "--Select a discipline--";
	arrAEIVE_TMDis[1] = "";

	for (i=2; i<parseInt(xmlDoc.getElementsByTagName("subjects")[8].childNodes.length + 1); i++)
	{	
		arrAEIVE_TMDis[i] = xmlDoc.getElementsByTagName("subjects")[8].childNodes[j].attributes.getNamedItem("discipline").value;
		arrAEIVE_TMDis[i+1] = "";
		i++;
		j = j + 2;
	}
}


function nsreadIVE_CWDisName()
{
	var i,j=1;
	
	arrAEIVE_CWDis[0] = "--Select a discipline--";
	arrAEIVE_CWDis[1] = "";

	for (i=2; i<parseInt(xmlDoc.getElementsByTagName("subjects")[9].childNodes.length + 1); i++)
	{	
		arrAEIVE_CWDis[i] = xmlDoc.getElementsByTagName("subjects")[9].childNodes[j].attributes.getNamedItem("discipline").value;
		arrAEIVE_CWDis[i+1] = "";
		i++;
		j = j + 2;
	}
}


function nsreadHKIEDDisName()
{
	var i,j=1;
	
	arrAEHKIEDDis[0] = "--Select a discipline--";
	arrAEHKIEDDis[1] = "";

	for (i=2; i<parseInt(xmlDoc.getElementsByTagName("subjects")[10].childNodes.length + 1); i++)
	{	
		arrAEHKIEDDis[i] = xmlDoc.getElementsByTagName("subjects")[10].childNodes[j].attributes.getNamedItem("discipline").value;
		arrAEHKIEDDis[i+1] = "";
		i++;
		j = j + 2;
	}
}


function nsreadPPDHDisName()
{
	var i,j=1;
	
	arrAEPPDHDis[0] = "--Select a discipline--";
	arrAEPPDHDis[1] = "";

	for (i=2; i<parseInt(xmlDoc.getElementsByTagName("subjects")[11].childNodes.length + 1); i++)
	{	
		arrAEPPDHDis[i] = xmlDoc.getElementsByTagName("subjects")[11].childNodes[j].attributes.getNamedItem("discipline").value;
		arrAEPPDHDis[i+1] = "";
		i++;
		j = j + 2;
	}
}


function nsreadAPADisName()
{
	var i,j=1;
	
	arrAEAPADis[0] = "--Select a discipline--";
	arrAEAPADis[1] = "";

	for (i=2; i<parseInt(xmlDoc.getElementsByTagName("subjects")[12].childNodes.length + 1); i++)
	{
		arrAEAPADis[i] = xmlDoc.getElementsByTagName("subjects")[12].childNodes[j].attributes.getNamedItem("discipline").value;
		arrAEAPADis[i+1] = "";
		i++;
		j = j + 2;
	}
}


function nsreadNormalAE()
{
	var i, j=1;
	for (i=0; i<parseInt((xmlDoc.getElementsByTagName("subjects")[0].childNodes.length - 1)/2); i++)
	{
		arrAENormalUnder[i] = xmlDoc.getElementsByTagName("subjects")[0].childNodes[j].attributes.getNamedItem("undergrad").value;
		arrAENormalPost[i] = xmlDoc.getElementsByTagName("subjects")[0].childNodes[j].attributes.getNamedItem("postgrad").value;
		j = j + 2;
	}
}


function nsreadIVE_STAE()
{
	var i, j=1;
	for (i=0; i<parseInt((xmlDoc.getElementsByTagName("subjects")[1].childNodes.length - 1)/2); i++)
	{
		arrAEIVE_STUnder[i] = xmlDoc.getElementsByTagName("subjects")[1].childNodes[j].attributes.getNamedItem("undergrad").value;
		arrAEIVE_STPost[i] = xmlDoc.getElementsByTagName("subjects")[1].childNodes[j].attributes.getNamedItem("postgrad").value;
		j = j + 2;
	}
}


function nsreadIVE_LWLAE()
{
	var i, j=1;
	for (i=0; i<parseInt((xmlDoc.getElementsByTagName("subjects")[2].childNodes.length - 1)/2); i++)
	{
		arrAEIVE_LWLUnder[i] = xmlDoc.getElementsByTagName("subjects")[2].childNodes[j].attributes.getNamedItem("undergrad").value;
		arrAEIVE_LWLPost[i] = xmlDoc.getElementsByTagName("subjects")[2].childNodes[j].attributes.getNamedItem("postgrad").value;
		j = j + 2;
	}
}


function nsreadIVE_KTAE()
{
	var i, j=1;
	for (i=0; i<parseInt((xmlDoc.getElementsByTagName("subjects")[3].childNodes.length - 1)/2); i++)
	{
		arrAEIVE_KTUnder[i] = xmlDoc.getElementsByTagName("subjects")[3].childNodes[j].attributes.getNamedItem("undergrad").value;
		arrAEIVE_KTPost[i] = xmlDoc.getElementsByTagName("subjects")[3].childNodes[j].attributes.getNamedItem("postgrad").value;
		j = j + 2;
	}
}


function nsreadIVE_TYAE()
{
	var i, j=1;
	for (i=0; i<parseInt((xmlDoc.getElementsByTagName("subjects")[4].childNodes.length - 1)/2); i++)
	{
		arrAEIVE_TYUnder[i] = xmlDoc.getElementsByTagName("subjects")[4].childNodes[j].attributes.getNamedItem("undergrad").value;
		arrAEIVE_TYPost[i] = xmlDoc.getElementsByTagName("subjects")[4].childNodes[j].attributes.getNamedItem("postgrad").value;
		j = j + 2;
	}
}


function nsreadIVE_MHAE()
{
	var i, j=1;
	for (i=0; i<parseInt((xmlDoc.getElementsByTagName("subjects")[5].childNodes.length - 1)/2); i++)
	{
		arrAEIVE_MHUnder[i] = xmlDoc.getElementsByTagName("subjects")[5].childNodes[j].attributes.getNamedItem("undergrad").value;
		arrAEIVE_MHPost[i] = xmlDoc.getElementsByTagName("subjects")[5].childNodes[j].attributes.getNamedItem("postgrad").value;
		j = j + 2;
	}
}


function nsreadIVE_HWAE()
{
	var i, j=1;
	for (i=0; i<parseInt((xmlDoc.getElementsByTagName("subjects")[6].childNodes.length - 1)/2); i++)
	{
		arrAEIVE_HWUnder[i] = xmlDoc.getElementsByTagName("subjects")[6].childNodes[j].attributes.getNamedItem("undergrad").value;
		arrAEIVE_HWPost[i] = xmlDoc.getElementsByTagName("subjects")[6].childNodes[j].attributes.getNamedItem("postgrad").value;
		j = j + 2;
	}
}


function nsreadIVE_KCAE()
{
	var i, j=1;
	for (i=0; i<parseInt((xmlDoc.getElementsByTagName("subjects")[7].childNodes.length - 1)/2); i++)
	{
		arrAEIVE_KCUnder[i] = xmlDoc.getElementsByTagName("subjects")[7].childNodes[j].attributes.getNamedItem("undergrad").value;
		arrAEIVE_KCPost[i] = xmlDoc.getElementsByTagName("subjects")[7].childNodes[j].attributes.getNamedItem("postgrad").value;
		j = j + 2;
	}
}


function nsreadIVE_TMAE()
{
	var i, j=1;
	for (i=0; i<parseInt((xmlDoc.getElementsByTagName("subjects")[8].childNodes.length - 1)/2); i++)
	{
		arrAEIVE_TMUnder[i] = xmlDoc.getElementsByTagName("subjects")[8].childNodes[j].attributes.getNamedItem("undergrad").value;
		arrAEIVE_TMPost[i] = xmlDoc.getElementsByTagName("subjects")[8].childNodes[j].attributes.getNamedItem("postgrad").value;
		j = j + 2;
	}
}


function nsreadIVE_CWAE()
{
	var i, j=1;
	for (i=0; i<parseInt((xmlDoc.getElementsByTagName("subjects")[9].childNodes.length - 1)/2); i++)
	{
		arrAEIVE_CWUnder[i] = xmlDoc.getElementsByTagName("subjects")[9].childNodes[j].attributes.getNamedItem("undergrad").value;
		arrAEIVE_CWPost[i] = xmlDoc.getElementsByTagName("subjects")[9].childNodes[j].attributes.getNamedItem("postgrad").value;
		j = j + 2;
	}
}


function nsreadHKIEDAE()
{
	var i, j=1;
	for (i=0; i<parseInt((xmlDoc.getElementsByTagName("subjects")[10].childNodes.length - 1)/2); i++)
	{
		arrAEHKIEDUnder[i] = xmlDoc.getElementsByTagName("subjects")[10].childNodes[j].attributes.getNamedItem("undergrad").value;
		arrAEHKIEDPost[i] = xmlDoc.getElementsByTagName("subjects")[10].childNodes[j].attributes.getNamedItem("postgrad").value;
		j = j + 2;
	}
}


function nsreadPPDHAE()
{
	var i, j=1;
	for (i=0; i<parseInt((xmlDoc.getElementsByTagName("subjects")[11].childNodes.length - 1)/2); i++)
	{
		arrAEPPDHUnder[i] = xmlDoc.getElementsByTagName("subjects")[11].childNodes[j].attributes.getNamedItem("undergrad").value;
		arrAEPPDHPost[i] = xmlDoc.getElementsByTagName("subjects")[11].childNodes[j].attributes.getNamedItem("postgrad").value;
		j = j + 2;
	}
}


function nsreadAPAAE()
{
	var i, j=1;
	for (i=0; i<parseInt((xmlDoc.getElementsByTagName("subjects")[12].childNodes.length - 1)/2); i++)
	{
		arrAEAPASub[i] = xmlDoc.getElementsByTagName("subjects")[12].childNodes[j].attributes.getNamedItem("subdegree").value;
		arrAEAPADeg[i] = xmlDoc.getElementsByTagName("subjects")[12].childNodes[j].attributes.getNamedItem("degree").value;		
		j = j + 2;
	}
}


function nsreadgrantloan()
{
	var i,j=1;
	for (i=0; i<parseInt((xmlDoc.getElementsByTagName("grantandloan")[0].childNodes.length - 1)/2); i++)
	{
		arrGLBound[i] = xmlDoc.getElementsByTagName("grantandloan")[0].childNodes[j].attributes.getNamedItem("lbound").value;
		arrGPer[i] = xmlDoc.getElementsByTagName("grantandloan")[0].childNodes[j].attributes.getNamedItem("grantpercent").value;
		arrLPer[i] = xmlDoc.getElementsByTagName("grantandloan")[0].childNodes[j].attributes.getNamedItem("loanpercent").value;
		j = j + 2;
	}
}


function nsreadasset()
{
	var i,j=1;
	for (i=0; i<parseInt((xmlDoc.getElementsByTagName("asset")[0].childNodes.length -1)/2); i++)
	{
		arrAssetBound[i] = xmlDoc.getElementsByTagName("asset")[0].childNodes[j].attributes.getNamedItem("lbound").value;
		arrAssetPer[i] = xmlDoc.getElementsByTagName("asset")[0].childNodes[j].attributes.getNamedItem("assetpercent").value;
		j = j + 2;
	}
}


function nsreadfee()
{
	var i,j=1;
	//alert(parseInt((xmlDoc.getElementsByTagName("fee")[0].childNodes.length -1)/2));
	for (i=0; i<parseInt((xmlDoc.getElementsByTagName("fee")[0].childNodes.length -1)/2); i++)
	{
		arrTFee[i] = xmlDoc.getElementsByTagName("fee")[0].childNodes[j].firstChild.nodeValue;
		j = j + 2;
	}
}


function nsreadmaxloan()
{
	curMaxLoan = xmlDoc.getElementsByTagName("calculator")[0].childNodes[5].firstChild.nodeValue;
	//alert("max loan = " + curMaxLoan);
}


function nsreadmaxME()
{
	curMaxME = xmlDoc.getElementsByTagName("calculator")[0].childNodes[6].firstChild.nodeValue;;
	//alert("max ME = " + curMaxLoan);
}


function nsreaddatestr()
{
	datestr = xmlDoc.getElementsByTagName("calculator")[0].childNodes[7].firstChild.nodeValue;
	yearStart = datestr.substring(0,4) + "";
	yearLast = datestr.substring(5,7) + "";
	yearBeforeStart = parseInt(yearStart) - 1;
	
	var temp1 = parseInt(yearStart)+1 + "";
	var temp2 = parseInt(yearStart)+2 + "";
	datestr2 = temp1 + "/" + temp2.substring(2,4) + "";
	//alert("datestr = " + datestr);
	//alert("datestr2 = " + datestr2);
	//alert(yearStart);
	//alert(yearLast);
	//alert(yearBeforeStart);
}


