// JavaScript Document
function linkup(){
	var xmlHttp;
	var transfercode;
	try{
		xmlHttp = new XMLHttpRequest();
	}catch(e){
		try{
			xmlHttp = new ActiveXObject(Msxml2.XMLHTTP);
		}catch(e){
			try{
				xmlHttp = new ActiveXObject(Microsoft.XMLHTTP);
			}catch(e){
				xmlHttp = false;
			}
		}
	}
	if(!xmlHttp){
		return false;
	}else{
		return xmlHttp;
	}
}

function getIndustries(){
	var xmlHttp = linkup();
	if(xmlHttp.readyState == 4 || xmlHttp.readyState == 0){
		xmlHttp.open('GET', '../../plugins/bbnrm/remote/industries.php', true);
		xmlHttp.send(null);
		xmlHttp.onreadystatechange = function(){
			var response;
			if(xmlHttp.readyState != 4){
				document.getElementById("openVacs").innerHTML = '<img src="media/images/loading_black.gif" border="0" />';
			}else if(xmlHttp.readyState == 4){
				if(xmlHttp.status == 200){
					var response = xmlHttp.responseText;
					if(response.indexOf("ERRNO") >= 0 || response.indexOf("Error:") >=0 || response.length ==0){
						throw(response.length == 0 ? "Server Error. " : response);
					}
					responseXml = xmlHttp.responseXML;
					var xmlDoc = responseXml.documentElement;
					//alert(xmlDoc.getElementsByTagName("industry")[0].getElementsByTagName("iname")[0].firstChild.data);
					resultLength = xmlDoc.getElementsByTagName("industry").length;
					var sF = "<table bgcolor=\"#666666\" cellpadding=\"3\" cellspacing=\"0\" border=\"0\" width=\"100%\">";
					for(var j=1; j<(resultLength+1); j++){
						counter = j - 1;
						sF += "<tr><td width=\"10\" bgcolor=\"white\"><a href=\"#\" onclick=\"getOpenings('industry','"+(xmlDoc.getElementsByTagName("industry")[counter].getElementsByTagName("iid")[0].firstChild.data)+"', 0, 25, '')\">"+(xmlDoc.getElementsByTagName("industry")[counter].getElementsByTagName("iname")[0].firstChild.data)+" ("+(xmlDoc.getElementsByTagName("industry")[counter].getElementsByTagName("inumvacs")[0].firstChild.data)+")</a></td>";
					}
					document.getElementById("openVacs").innerHTML = sF+"</table>"; //+"</tr><tr><td colspan='5' align='left'><br /><label><a href='javascript: checkAll()'>Check All</a> | <a href='javascript: uncheckAll()'>Uncheck All</a></label></td></tr></table>";
				}else{
					document.getElementById("openVacs").innerHTML = "Sorry! An error occured while attempting server connection";
				}
			}
		}
	}else{
		alert('error');
	}
}

function readResponse(){
	var response = xmlHttp.responseText;
	if(response.indexOf("ERRNO") >= 0 || response.indexOf("Error:") >=0 || response.length ==0){
		throw(response.length == 0 ? "Server Error. " : response);
	}
	
	responseXml = xmlHttp.responseXML;
	xmlDoc = responseXml.documentElement;
	result = xmlDoc.getElementsByTagName("state")[0].firstChild.data;
	return result;
}