var req, xml;

function processReqChange() {
    // only if req shows "loaded"
    if (req.readyState == 4) {
        // only if "OK"
        if (req.status == 200) {
            // ...processing statements go here...
	    xml = req.responseXML.documentElement;
	    xmlOnLoad_01();
	    if (splitloan == true ){xmlOnLoad_02();}
        } else {
            alert("There was a problem retrieving the XML data:\n" +
                req.statusText);
        }
    }
}

function loadXMLDoc(url) {
    // branch for native XMLHttpRequest object
    if (window.XMLHttpRequest) {
        req = new XMLHttpRequest();
        req.onreadystatechange = processReqChange;
        req.open("GET", url, true);
        req.send(null);
    // branch for IE/Windows ActiveX version
    } else if (window.ActiveXObject) {
        req = new ActiveXObject("Microsoft.XMLHTTP");

        if (req) {
            req.onreadystatechange = processReqChange;
            req.open("GET", url, true);
            req.setRequestHeader( "If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT" );
            req.send();
        }
    }
}



function getProductNode( id )
{
	var products = xml.getElementsByTagName("product");
	for (i=0; i<products.length; i++)
	{
		if (products[i].getAttribute("id") == id) return products[i];
	}
	return false;
}

function getInterestRate( id )
{
	var product = getProductNode(id);
	return product.childNodes[1].firstChild.nodeValue;
}
function getMaturityInterestRate( id, prefix )
{
	 switch(brand)
	 {
		case "cba":
			if (id ==2 || id == 10) {
				document.getElementById("rowMaturityInterestRate"+prefix).style.display="none";
				document.getElementById("rowMaturityInterestRate"+prefix).value = "";
			} else {
				document.getElementById("rowMaturityInterestRate"+prefix).style.display=vistoken;				
			}
			break;
		case "homepath":
			if (id == 12) {
				document.getElementById("rowMaturityInterestRate"+prefix).style.display="none";
				document.getElementById("rowMaturityInterestRate"+prefix).value = "";
			} else {
				document.getElementById("rowMaturityInterestRate"+prefix).style.display=vistoken;				
			}
			break;
	 }
	
	var product = getProductNode(id);
	switch( product.childNodes[3].firstChild.nodeValue)
	{
		case "SVR":
			if (brand == "cba") {
				return getInterestRate(2);
			} else {
				return getInterestRate(12);	
			}
			break;
		
		case "BVR":
			return getInterestRate(10);		
			break;
		default:
			return "";
			break;
	}
}

function getInterestRate( id )
{
	var product = getProductNode(id);
	return product.childNodes[1].firstChild.nodeValue;
}
function getLoanTerm( id )
{
	var product = getProductNode(id);
	if (product.childNodes[2].hasChildNodes()) {
		return parseInt(product.childNodes[2].firstChild.nodeValue);
	} else {
		return 0;	
	}
}

