var http = getHTTPObject();

var current_device = null;

var vmTestMode = null;

function isalphanumeric(data,strict) { //strict makes '-' and '_' not count as being 'alphanumeric'
	var b;

	for(var a=0; a<data.length; a=a+1) {
		//b=data.charCodeAt(data.substr(a,1));
		b=data.substr(a,1).charCodeAt(0);
		//b=b.charCodeAt(0);

		if(strict==false) {
			if(!(((b>=48)&&(b<=57))||((b>=65)&&(b<=90))||((b>=97)&&(b<=122))||(b==95)||(b==45))) {
				return(false);
			}
		}
		else {
			if(!(((b>=48)&&(b<=57))||((b>=65)&&(b<=90))||((b>=97)&&(b<=122)))) {
				return(false);
			}
		}
	}

	return(true);
}
var device_face = null;
function enableIPUpdate(device) {
	device_face = device;
	document.getElementById("submitIPSettings" + device).disabled=false;
	document.getElementById("ipAddress" + device).disabled=false;
	document.getElementById("netmask" + device).disabled=false;
	document.getElementById("gatewayIP" + device).disabled=false;
	var out = document.getElementById('checker'+device);
	var ip = document.getElementById("ipAddress" + device);
	var ipFormat = /^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/;
	if(ip.value.match(ipFormat)){
		
		out.innerHTML = '<img src="images/ajax-loader2.gif" />'; 
	
		var myurl = "includes/networkhandler.php?ipCheck="+ip.value;
		
		http = getHTTPObject();
		http.open("GET", myurl, true);
		http.onreadystatechange = ipGood;
		http.send(null);
	}
	var success = document.getElementById('ipSuccess' + device);
	var fail = document.getElementById('ipError' + device);
	if (success.style.display != 'none'){
		Effect.Fade(success, {duation: 0.5});
	}
	if (fail.style.display != 'none'){
		Effect.Fade(fail, {duation: 0.5});
	}
	
	
}
function ipGood(){
	if (http.readyState == 4){
		var out = document.getElementById('checker'+device_face);
		if (http.responseText == 'good'){
			out.innerHTML = '<img src="images/check.gif" />' + ' IP Available';
		} else {
			out.innerHTML = '<img src="images/redx.gif" /> ' + http.responseText;
		}
	}
}
function selectIPUpdate(obj){
	obj.focus();
	obj.select();
}

function enableDNSUpdate() {
	document.getElementById("submitDNSSettings").disabled=false;
	var success = document.getElementById('dnsSuccess');
	var fail = document.getElementById('dnsError');
	if (success.style.display != 'none'){
		Effect.Fade(success, {duation: 0.5});
	}
	if (fail.style.display != 'none'){
		Effect.Fade(fail, {duation: 0.5});
	}
}

function enableNTPUpdate() {
	document.getElementById("submitNTPSettings").disabled = false;
	var success = document.getElementById('ntpSuccess');
	var fail = document.getElementById('ntpError');
	if (success.style.display != 'none'){
		Effect.Fade(success, {duation: 0.5});
	}
	if (fail.style.display != 'none'){
		Effect.Fade(fail, {duation: 0.5});
	}
}

function enableWorkgroupUpdate() {
	document.getElementById("submitWorkgroup").disabled=false;
	var success = document.getElementById('workgroupSuccess');
	if (success.style.display != 'none'){
		Effect.Fade(success, {duation: 0.5});
	}
}
function enableHostnameUpdate() {
	document.getElementById("submitHostname").disabled=false;
	var success = document.getElementById('hostnameSuccess');
	if (success.style.display != 'none'){
		Effect.Fade(success, {duation: 0.5});
	}
}

function updateIP(device, fromHome) { // if fromHome is '1', request is made from home.php
	var ip = document.getElementById("ipAddress" + device);
	var netmask = document.getElementById("netmask" + device);
	var gateway = document.getElementById("gatewayIP" + device);
	var ipModeStatic = document.getElementById("ipModeStatic" + device).checked;
	var ipFormat = /^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/;	
	if	(!ip.value.match(ipFormat)){
		alert("You ip address is not formated properly");
		ip.focus();
		ip.select();
		exit0;
	}

	var ipModeManual = 0;

	if(device != 'eth0' && device != 'bond0') // make sure the specified device isn't the main nic, the main nic always needs to be either dhcp or static
		var ipModeManual = document.getElementById("ipModeManual" + device).checked;

	//var ipModeDHCP = document.getElementById("ipModeDHCP" + device).checked;

	
	var modest = 'dhcp'; // set modest to dhcp, if neither static or manual are checked, assume dhcp operation

	if(ipModeStatic == true) // if static checkbox is checked, set mode to static
		modest = 'static';
	else if(ipModeManual == true) // if manual checkbox is checked, set mode to manual
		modest = 'manual';

	document.getElementById("submitIPSettings" + device).disabled=true;

	current_device = device; //set current_device global variable so the proper part of the page is re-enabled after request is done

	var portState = '';

	if(device != 'eth0' && device != 'bond0') { // not eth0 or bond0
		var portStateVal = document.getElementById("portStateEnabled" + device).checked;

		if(portStateVal == true)
			portState = "&portState=true";
		else
			portState = "&portState=false";
	}
	

	var myurl = "includes/networkhandler.php?device=" + device + "&ip="+ip.value+"&netmask="+netmask.value+"&gateway="+gateway.value+"&mode="+modest + portState;
	http = getHTTPObject();
	http.open("GET", myurl, true);

	http.onreadystatechange = updateIPDone;
	http.send(null);
	
}

// function updateIPhome(device,mode){
// 	var ip = document.getElementById("ipAddress" + device);
// 	var netmask = document.getElementById("netmask" + device);
// 	var gateway = document.getElementById("gatewayIP" + device);
// 	var ipFormat = /^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/;	
// 	if	(!ip.value.match(ipFormat)){
// 		alert("You ip address is not formated properly");
// 		ip.focus();
// 		ip.select();
// 		return;
// 	}
// 	var myurl = "includes/networkhandler.php?device=" + device + "&ip="+ip.value+"&netmask="+netmask.value+"&gateway=" + gateway.value + "&mode="+mode+"&junk=" + Math.random();;
// 	http = getHTTPObject();
// 	http.open("GET", myurl, true);
// 	http.onreadystatechange = updateHOMEIPDone;
// 	http.send(null);
// }

// function updateHOMEIPDone(){
// 		if (http.readyState == 4){
// 			if(http.responseText!="bad"){	
// 				restartNetwork();
// 			}else{
// 			
// 				//Something
// 			}
// 		}
// }

function restartNetwork(){
	var myurl = "includes/networkhandler.php?action=restartNetwork&junk=" + Math.random();;
	http = getHTTPObject();
	http.open("GET", myurl, true);
	http.onreadystatechange = networkRestarted;
	http.send(null);

	document.getElementById('reloadNetDiv' + current_device).innerHTML = "Reloading configuration, and attempting to reload page...";
	setTimeout("location.reload(true);", 1000);
}

function networkRestarted(){
	if (http.readyState == 4) {
		//alert(http.responseText);
		//document.getElementById('reloadNetDiv' + current_device).innerHTML = http.responseText;
	}
}

function updateDNS() {
	var dns1=document.getElementById("dns1");
	var dns2=document.getElementById("dns2");
	var dns3=document.getElementById("dns3");

	document.getElementById("submitDNSSettings").disabled=true;

	var myurl = "includes/networkhandler.php?dns1="+dns1.value+"&dns2="+dns2.value+"&dns3="+dns3.value;
	http = getHTTPObject();
	http.open("GET", myurl, true);
	http.onreadystatechange = updateDNSDone;
	http.send(null);
}

function updateNTP() {
	var ntp1 = document.getElementById("ntp1");
	var ntp2 = document.getElementById("ntp2");
	var ntp3 = document.getElementById("ntp3");

	document.getElementById("submitNTPSettings").disabled = true;

	var myurl = "includes/networkhandler.php?ntp1="+ntp1.value+"&ntp2="+ntp2.value+"&ntp3="+ntp3.value;
	http = getHTTPObject();
	http.open("GET", myurl, true);
	http.onreadystatechange = updateNTPDone;
	http.send(null);
}

function updateWorkgroup() {
	var workgroup=document.getElementById("workgroup").value;

	document.getElementById("submitWorkgroup").disabled=true;

	if(workgroup=="") {
		alert("Error: You must enter a workgroup name.");
		return;
	}

	if(isalphanumeric(workgroup,false)==false) {
		alert("Error: Only alphanumeric characters are allowed for the workgroup name.");
		return;
	}

	if(workgroup.length>16) {
		alert("Error: Workgroup name cannot be more than 16 characters in length.");
		return;
	}

	var myurl = "includes/networkhandler.php?workgroup="+workgroup;
	http = getHTTPObject();
	http.open("GET", myurl, true);
	http.onreadystatechange = updateWorkgroupDone;
	http.send(null);
}

function updateHostname() {
	var hostname=document.getElementById("hostname").value;

	document.getElementById("submitHostname").disabled=true;

	if(hostname=="") {
		alert("Error: You must enter a hostname.");
		return;
	}

	if(isalphanumeric(hostname,false)==false) {
		alert("Error: Only alphanumeric characters are allowed for the hostname.");
		return;
	}

	if(hostname.length>16) {
		alert("Error: Hostname cannot be more than 16 characters in length.");
		return;
	}

	var myurl = "includes/networkhandler.php?hostname="+hostname;
	http = getHTTPObject();
	http.open("GET", myurl, true);
	http.onreadystatechange = updateHostnameDone;
	http.send(null);
}

function updateIPDone(){
	if (http.readyState == 4){
		//document.getElementById("submitWorkgroup").disabled=true;
		if(http.responseText!="bad") {
			Effect.Appear('ipSuccess' + current_device, {duration: 0.5});

			var iframe = document.getElementById('iframe');

			var ip = document.getElementById('ipAddress' + current_device).value;
			var netmask = document.getElementById('netmask' + current_device).value;
			var gatewayIP = document.getElementById('gatewayIP' + current_device).value;
			var ipModeStatic = document.getElementById('ipModeStatic' + current_device);

			var modest;

			if(ipModeStatic.checked==true)
				modest="static";
			else
				modest="dynamic";

			if(current_device == 'eth0' || current_device == 'bond0') {
				iframe.src = "https://device.dattobackup.com/networkAlert.php?key=" + http.responseText + "&ip=" + ip + "&netmask=" + netmask + "&gatewayIP=" + gatewayIP + "&ipModeStatic=" + modest;
			}
		} else {
			Effect.Appear('ipError' + current_device, {duration: 0.5});
		}
		
	}
}

function updateDNSDone() {
	if(http.readyState == 4) {
		if(http.responseText=="good") {
			Effect.Appear('dnsSuccess', {duration: 0.5});
		} else {
			Effect.Appear('dnsError', {duration: 0.5});
		}
	}
}

function updateNTPDone() {
	if(http.readyState == 4) {
		if(http.responseText=="good") {
			Effect.Appear('ntpSuccess', {duration: 0.5});
		} else {
			Effect.Appear('ntpError', {duration: 0.5});
		}
	}
}

function updateWorkgroupDone() {
	if(http.readyState == 4) {
		if(http.responseText=="good") {
			Effect.Appear('workgroupSuccess', {duration: 0.5});
		}
	}
}

function updateHostnameDone() {
	if(http.readyState == 4) {
		if(http.responseText=="good") {
			Effect.Appear('hostnameSuccess', {duration: 0.5});
		}
	}
}

/*function confirmWorkgroupRevert() {
	//document.getElementById("confirmWorkgroupRevertDiv").disabled = false;

	var success = document.getElementById('confirmWorkgroupRevertDiv');
	if (success.style.display != 'none'){
		Effect.Fade(success, {duation: 0.5});
	}

}*/

function revertToWorkgroup() {
	var stats = document.getElementById('retnWorkgroup');
	stats.innerHTML='Leaving Domain - <img src="images/ajax-loader2.gif">';
	var myurl = "includes/networkhandler.php?mode=wgRevert&junk=" + Math.random();
	http = getHTTPObject();
	http.open("GET", myurl, true);
	http.onreadystatechange = wgRevertDone;
	http.send(null);
}

function wgRevertDone() {
	if(http.readyState == 4) {
		if(http.responseText != 'good') {
			var stats = document.getElementById('retnWorkgroup');
			stats.innerHTML=http.responseText + '<br><input type="button" value="Leave Domain" onClick="revertToWorkgroup()">';
		}
		else {
			alert('Workgroup revert successful');
			var stats = document.getElementById('retnWorkgroup');
			stats.innerHTML='Please wait, reloading page';
			window.location.reload();
			
		}
	}
}

function changeToDomain() {
	var username = document.getElementById('username').value;
	var password = document.getElementById('password').value;
	var domainName = document.getElementById('domainName').value;
	var pwServer = document.getElementById('pwServer').value;
	var stats = document.getElementById('domainStatus');

	password = Base64.encode(password);

	stats.innerHTML='Joining Domain - <img src="images/ajax-loader2.gif">';
	var myurl = "includes/networkhandler.php?mode=joinDomain&domain=" + domainName + "&username=" + username + "&password=" + password + "&pwServer=" + pwServer + "&junk=" + Math.random();
	http = getHTTPObject();
	http.open("GET", myurl, true);
	http.onreadystatechange = domainChangeDone;
	http.send(null);
}

function domainChangeDone() {
	if(http.readyState == 4) {
		if(http.responseText != 'good') {
			var stats = document.getElementById('domainStatus');
			stats.innerHTML=http.responseText;
		}
		else {
			alert('Domain join successful');
			var stats = document.getElementById('domainStatus');
			stats.innerHTML='Welcome to the domain - Please wait, reloading page';
			window.location.reload();
		}
	}
}

function domainPrompt() {
	Effect.BlindUp('wgChoices',{duration: 0.5});
	Effect.Appear('domainTable',{duration: 0.5});
}

function setTimezone() {
	var s = document.getElementById('tz');
	var x = s.options[s.selectedIndex].value;
	var tz = x;
	alert(tz);
	var myurl = "includes/networkhandler.php?mode=setTZ&tz=" + tz + "&junk=" + Math.random();
	http = getHTTPObject();
	http.open("GET", myurl, true);
	http.onreadystatechange = setTimezoneDone;
	http.send(null);
}

function setTimezoneDone() {
	if(http.readyState == 4) {
		var tzButton = document.getElementById('submitTZ');
		tzButton.disabled = 1;

		if(http.responseText=="good") {
			Effect.Appear('tzSuccess', {duration: 0.5});
		} else {
			Effect.Appear('tzError', {duration: 0.5});
		}
	}
}

function enableSetTimezone() {
	var tzButton = document.getElementById('submitTZ');

	var success = document.getElementById('tzSuccess');
	var fail = document.getElementById('tzError');
	if (success.style.display != 'none'){
		Effect.Fade(success, {duation: 0.5});
	}
	if (fail.style.display != 'none'){
		Effect.Fade(fail, {duation: 0.5});
	}

	tzButton.disabled = 0;
}

function enableBondUpdate() {
	document.getElementById("submitBondSettings").disabled = false;
	var success = document.getElementById('bondSuccess');
	var fail = document.getElementById('bondError');
	if (success.style.display != 'none'){
		Effect.Fade(success, {duation: 0.5});
	}
	if (fail.style.display != 'none'){
		Effect.Fade(fail, {duation: 0.5});
	}
}

function updateBondSettings() {
	var bonded;

	var myurl = "includes/networkhandler.php?mode=setBonding";

	var curInterface;
	var interfaceSetting;

	for(a = 0; a < 9; a++) {
		var bond = document.getElementById('bond0_eth' + a);

		if(bond) {
			curInterface = "eth" + a;

			if(bond.checked == true) {
				interfaceSetting = 1;
			}
			else if(bond.checked == false) {
				interfaceSetting = 0;
			}

			myurl += "&bond0_" + curInterface + '=' + interfaceSetting;
		}
	}

	myurl += "&junk=" + Math.random();

	document.getElementById("submitDNSSettings").disabled = true;

	http = getHTTPObject();
	http.open("GET", myurl, true);
	http.onreadystatechange = updateBondSettingsDone;
	http.send(null);
}

function updateBondSettingsDone() {
	if(http.readyState == 4) {
		if(http.responseText.indexOf('Bonding has ') == 0) {
			var successDiv = document.getElementById('bondSuccess');
	
			successDiv.innerHTML = http.responseText;
	
			Effect.Appear('bondSuccess', {duration: 0.5});

		}
		else {
			var errorDiv = document.getElementById('bondError');
	
			errorDiv.innerHTML = http.responseText;
	
			Effect.Appear('bondError', {duration: 0.5});
		}
	}
}
var intervalID = 0; // used for resetting the search timer, so typing any input info should be flawless (only one request)
function searchTimer() { // handles search box changes so a request will only be made to the server after the textbox hasn't been changed in .75 seconds
	if(intervalID > 0) {
		clearInterval(intervalID);
	}

	intervalID = setTimeout('checkHostname();', 750);
}
function checkHostname(){
	var host = document.getElementsByName('hostN')[0].value;
	var myurl = "includes/networkhandler.php?action=checkhost&hostN="+host+"&junk=" + Math.random();
	var out = document.getElementById('hostGood');
	if(host == ''){
		out.innerHTML = '';
		return false;
	}
	out.style.font='';
	out.innerHTML = '<img src="images/ajax-loader2.gif" />'; 
	
	http = getHTTPObject();
	http.open("GET", myurl, true);
	http.onreadystatechange = writeHostname;
	http.send(null);
	
}
function writeHostname(){
	if (http.readyState == 4){
		var out = document.getElementById('hostGood');
		if (http.responseText == 'good'){
			out.innerHTML = '<img src="images/check.gif" />' + ' Host name found';
			document.getElementsByName("hostAdd")[0].disabled=false;
		} else {
			out.innerHTML = '<img src="images/redx.gif" /> ' + ' Host name not found';
			document.getElementsByName("hostAdd")[0].disabled=true;
		}
	}
}
function addHost(){
	var host = document.getElementsByName('hostN')[0].value;
	var myurl = "includes/networkhandler.php?action=addhost&hostN="+host+"&junk=" + Math.random();
	var out = document.getElementById('hostLine');
	
	//Effect.Fade('hostLine', {duration: 1.5});
	//out.innerHTML = '<img src="images/ajax-loader2.gif" />'; 
	http = getHTTPObject();
	http.open("GET", myurl, true);
	http.onreadystatechange = writeAddhost;
	http.send(null);
}
function writeAddhost(){
	if (http.readyState == 4){
		var out = document.getElementById('hostGood');
		var outEmpty = document.getElementById('hostGood');
		outEmpty.innerHTML ='';
		if(http.responseText == 'ServerExists'){
			out.innerHTML = 'Server Exists, choose another';
			Effect.Appear('hostAgain', {duration: 1.5});
		}
		else if(http.responseText == 'shareExists'){
			out.innerHTML = 'Share name matches host name, please delete the share with the same hostname from <a href="shares.php">users and shares</a> before proceeding';
			Effect.Appear('hostAgain', {duration: 1.5});
		}
		else if(http.responseText == 'noServer'){
			out.innerHTML = 'Host Does Not Exist';
			Effect.Appear('hostAgain', {duration: 1.5});
		} else if(http.responseText == 'good'){
			out.innerHTML = 'Host Saved';
			setTimeout('showSet();', 150);
			updateList();
		}else {
			out.innerHTML = '<img src="images/redx.gif" /> ' + ' Host name not found';
			document.getElementsByName("hostAdd")[0].disabled=true;
		}
	}	
}

/*function updateListOnTimer() {
	if(http.readyState == 4) {
		setTimeout("updateList();", 500);
	}
}*/

function updateListOnSuccess() {
	if(http.readyState == 4) {
		alert(http.responseText);

		if(http.responseText == 'good') {
			updateList();
		}
	}
}

function updateList() {
	//if (http.readyState == 4){
	//	if (http.responseText == 'good'){
		var myurl = "includes/networkhandler.php?action=updateList&junk=" + Math.random();
	
		http = getHTTPObject();
		http.open("GET", myurl, true);
		http.onreadystatechange = writeUpdateList;
		http.send(null);
	//	}
	//}
}
function writeUpdateList(){
	if (http.readyState == 4){
		var out = document.getElementById('serverList');
		out.innerHTML=http.responseText;
	}
}
function replaceHost(){
	var out = document.getElementById('hostLine');
	out.innerHTML = '<span id="hostAgain" style="display:none;"><input name="hostN" type="text" onkeyup="searchTimer()"/><span id="hostGood" />Add another</span>';
	Effect.Appear('hostAgain', {duration: 1.5});
}
function showSet(){
	var out = document.getElementById('hostLine');
	out.innerHTML = '<span id="hostAgain" style="display:none;">Host Saved</span>';
	Effect.Appear('hostAgain', {duration: 1.5});
	setTimeout('replaceHost();', 1550);
}
function removeServer(serverName){
	var answer = confirm ("Removing the server "+serverName+" will delete the Virtual Machine image associated with server "+serverName);
	if (answer)
	var myurl = "includes/networkhandler.php?action=removeServer&hostN="+serverName+"&junk=" + Math.random();
	
	http = getHTTPObject();
	http.open("GET", myurl, true);
	http.onreadystatechange = updateListOnSuccess;
	http.send(null);
	
}
function showSetup(id_element){
	var element = document.getElementById(id_element);
	if(element.style.display == 'none'){
		Effect.BlindDown(id_element, { duration: 1.5 });
	}
	else{
		Effect.BlindUp(id_element, { duration: 1.5 });
	}
}
function changeMem(mem){
	var overRideMem = document.getElementsByName("overRidemem-"+mem)[0];
	var mem = document.getElementsByName("mem-"+mem)[0];
	if(overRideMem.disabled == true){
		var answer = confirm("The default memory is set from your servers config file, please be sure that the change in memory size will not effect your expectation of performance for this server");
		if(answer)
		overRideMem.disabled=false;
		mem.readonly=false;
		mem.disabled=true;
		overRideMem.value=0;
		overRideMem.select();
		totalMemFunc();
	}else{
		var answer = confirm("Switching back to default memory");
		if(answer)
		overRideMem.disabled=true;
		overRideMem.value='';
		mem.readonly=true;
		mem.disabled=false;
		totalMemFunc();
	}
}
function totalMemFunc(){
	var memUsed = document.getElementById('totalMem');
	var inputs = document.getElementsByName('totalInputs')[0].value;
	
	var availMemory = parseInt(document.getElementById('availMem').innerHTML);
	var memOverTotal = 0;
	var memMemTotal = 0;
	var totalMemory = 0;
	
	var startVM = document.getElementsByName('startVMach')[0];
	var testVM = document.getElementsByName('startTest')[0];

	for(i = 1; i < inputs; i++){
	var chk = document.getElementsByName('selected-'+i)[0];
	var mem = parseInt(document.getElementsByName('mem-'+i)[0].value);
	var override = document.getElementsByName('overRidemem-'+i)[0];
	var overRideint = parseInt(document.getElementsByName('overRidemem-'+i)[0].value);
		if(chk.checked){
			vmAvail = "true";
		}
		if(chk.checked && override.disabled == true){
			//alert(i +" "+ mem);
			memMemTotal += mem;
		}
		if(chk.checked && override.disabled == false){
			//alert(i +" "+ override[0].value);
			memOverTotal += overRideint;
		}
	}
	totalMemory = memOverTotal + memMemTotal;
	memUsed.innerHTML = totalMemory;

	if(totalMemory > availMemory && totalMemory > 0){
		startVM.disabled=true;
		testVM.disabled=true;
		document.getElementById('totalMem').style.background="red";
		document.getElementById('memToohigh').style.display="";
	}else{
		startVM.disabled=false;
		testVM.disabled=false;
		document.getElementById('totalMem').style.background="";
		document.getElementById('memToohigh').style.display="none";
	}
}
function updateMem(){
	var memUsed = document.getElementById('totalMem');
	var memAvail = document.getElementById('availMem');
}
function validateVM(testMode){
	var password = prompt("Aurora Password", "");
	basePass = Base64.encode(password);

	vmTestMode = testMode; // set global variable for use in startVM()

	var myurl = "includes/networkhandler.php?action=validateVM&password="+basePass+ "&junk=" + Math.random();
	
	http = getHTTPObject();
	http.open("GET", myurl, true);
	http.onreadystatechange = writeValid;
	http.send(null);
}
function writeValid() {
	if (http.readyState == 4){
		if (http.responseText == 'good'){
			//alert("access");
			startVM();
		}
		else{
			alert("Password is wrong");
		}
	}
}
function startVM(){
	var inputs = document.getElementsByName('totalInputs')[0].value;
	var hosts = '';
	for(i = 1; i < inputs; i++){
	var chk = document.getElementsByName('selected-'+i)[0];
	var hostname = document.getElementById('hostname-'+i);
	var override = document.getElementsByName('overRidemem-'+i)[0];
	var mem = document.getElementsByName('mem-'+i)[0].value;
	
		if(chk.checked){
			if(override.disabled == true){
			hosts += hostname.innerHTML+","+mem+":"
			}
			if(override.disabled == false){
			hosts += hostname.innerHTML+","+override.value+":"
			}
		}
	}
	//alert(hosts);
	var myurl = "includes/networkhandler.php?action=startVM&hosts=" + hosts + "&testMode=" + vmTestMode + "&junk=" + Math.random();
	http = getHTTPObject();
	http.open("GET", myurl, true);
	http.onreadystatechange = writeStartVM;
	http.send(null);
}
function writeStartVM(){
	if (http.readyState == 4){
		alert();
	}
}

