// FUNCTIONS TO WRITE A DROPDOWN BOX WITH ALL PEBBLEPAD INSTITUTIONS

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

var xmlDoc = "";

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

function getOrgData() {
	if (window.XMLHttpRequest) {
        xmlDoc = new XMLHttpRequest();
        xmlDoc.onreadystatechange = processReqChange;
        xmlDoc.open("GET", "servicedata/xml/pporgs.xml", true);
        xmlDoc.send(null);
	} else if (window.ActiveXObject) {
		xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
		xmlDoc.onreadystatechange = function () {
			if (xmlDoc.readyState == 4) {
				compileData();
			}
		};
 	} else {
		alert("Your browser cannot handle this script");
		return;
	}
}

function processReqChange() {
	if (xmlDoc.readyState == 4) {
        if (xmlDoc.status == 200) {
			compileData();
        } else {
            alert("There was a problem retrieving the XML data:\n" + xmlDoc.statusText);
        }
    }
}

function compileData()	{
	var xml = xmlDoc.responseXML;
	var nodeCnt = xml.getElementsByTagName("organisation").length;
	var itemNode = xml.getElementsByTagName("organisation");
	var i = 0;
	var output = "";	
	
	output += "<select style=\"width:270px;\" name=\"institution\" size=\"1\" id=\"institution\" onChange=\"gotoUrl(this.options[this.selectedIndex].value)\" disabled  title=\"Please select your PebblePad Account\"  >";
	output += "<option value=\"\" disabled selected>---- Please Select ----</option>";
	output += "<option value=\"\" disabled>--------------------------------</option>";	
		
	for (i = 0; i < nodeCnt; i++) {
		output += "<option value=\"" + itemNode[i].getElementsByTagName("installurl")[0].childNodes[0].nodeValue + "\">" + itemNode[i].getElementsByTagName("name")[0].childNodes[0].nodeValue + "</option>";		
	}		
		
	output += "</select>";	
	document.getElementById("orgdrop").innerHTML = output;
}



//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//Login dropdown for 404 page

function get404OrgData() {
	if (window.XMLHttpRequest) {
        xmlDoc = new XMLHttpRequest();
        xmlDoc.onreadystatechange = process404ReqChange;
        xmlDoc.open("GET", "servicedata/xml/pporgs.xml", true);
        xmlDoc.send(null);
	} else if (window.ActiveXObject) {
		xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
		xmlDoc.onreadystatechange = function () {
			if (xmlDoc.readyState == 4) {
				compile404Data();
			}
		};
 	} else {
		alert("Your browser cannot handle this script");
		return;
	}
}

function process404ReqChange() {
	if (xmlDoc.readyState == 4) {
        if (xmlDoc.status == 200) {
			compile404Data();
        } else {
            alert("There was a problem retrieving the XML data:\n" + xmlDoc.statusText);
        }
    }
}

function compile404Data()	{
	var xml = xmlDoc.responseXML;
	var nodeCnt = xml.getElementsByTagName("organisation").length;
	var itemNode = xml.getElementsByTagName("organisation");
	var i = 0;
	var output = "";	
	var iURL = ""
	
	output += "<select style=\"width:320px;\" name=\"institution\" size=\"1\" id=\"institution\" onChange=\"gotoUrl(this.options[this.selectedIndex].value)\" title=\"Please select your PebblePad Account\"  >";
	output += "<option value=\"\" disabled selected>---- Please Select ----</option>";
	output += "<option value=\"\" disabled>--------------------------------</option>";	
		
	for (i = 0; i < nodeCnt; i++) {
		iURL = itemNode[i].getElementsByTagName("installurl")[0].childNodes[0].nodeValue
		if (iURL == "http://www.pebblepad.co.uk/pilot/" || iURL == "http://www.pebblepad.com.au/personal/" || iURL == "http://www.pebblepad.co.uk/personal/" || iURL == "http://www.pebblepad.co.uk/leap2a/" || iURL == "http://www.pebblepad.co.uk/personal/" || iURL == "http://www.pebblepad.co.uk/eportfolio/") {
			//dont do anything
		} else {
			output += "<option value=\"" + itemNode[i].getElementsByTagName("installurl")[0].childNodes[0].nodeValue + "\">" + itemNode[i].getElementsByTagName("name")[0].childNodes[0].nodeValue + "</option>";
		}
	}		
		
	output += "</select>";	
	document.getElementById("404orgdrop").innerHTML = output;
}


