function CheckVersion() {
	verString = RTSSoftUpdate.GetVersionString()
	if(verString == "0.8.3.192") {
		return(1)
	}
	return(0)
}

function OnContentsExpandDevices() {
	var contentForm;
	var page_main;
	var page_content;
	page_main = parent.frames[2]
	page_content = parent.frames[1]
	turl = "http://" + page_main.document.domain + "/webupdate/modernize.aspx"
	if(page_main.location != turl) {
		page_main.location = "/webupdate/modernize.aspx?command=RescanDevices"
		return
	}
	if (window.navigator.appName.toLowerCase().indexOf("netscape") > -1) {
		contentForm = page_content.document.forms["Contents"];
	} else {
		contentForm = page_content.document.Contents;
	}
	contentForm.expandDevices.value = 1
	contentForm.submit()
}

function OnContentsCollapseDevices() {
	var contentForm;
	var page_main;
	var page_content;
	page_main = parent.frames[2]
	page_content = parent.frames[1]
	turl = "http://" + page_main.document.domain + "/webupdate/modernize.aspx"
	if(page_main.location != turl) {
		page_main.location = "/webupdate/modernize.aspx?command=RescanDevices"
		return
	}
	if (window.navigator.appName.toLowerCase().indexOf("netscape") > -1) {
		contentForm = page_content.document.forms["Contents"];
	} else {
		contentForm = page_content.document.Contents;
	}
	contentForm.expandDevices.value = 0
	contentForm.submit()
}

function OnContentsWelcome() {
	var contentForm;
	var page_main;
	var page_content;
	page_main = parent.frames[2]
	page_content = parent.frames[1]
	if (window.navigator.appName.toLowerCase().indexOf("netscape") > -1) {
		contentForm = page_content.document.forms["Contents"];
		MForm = page_main.document.forms["ModernizeForm"];
	} else {
		contentForm = page_content.document.Contents;
		MForm = page_main.document.ModernizeForm;
	}
	turl = "http://" + page_main.document.domain + "/webupdate/modernize.aspx"
	if(page_main.location != turl) {
		page_main.location = "/webupdate/modernize.aspx?command_Welcome"
		return
	}

	MForm.command.value = "command_Welcome"
	MForm.submit()
}

function OnContentsScanDevices() {
	var contentForm;
	var page_main;
	var page_content;
	page_main = parent.frames[2]
	page_content = parent.frames[1]
	turl = "http://" + page_main.document.domain + "/webupdate/modernize.aspx"
	if(page_main.location != turl) {
		page_main.location = "/webupdate/modernize.aspx?command=RescanDevices"
		return
	}
	if (window.navigator.appName.toLowerCase().indexOf("netscape") > -1) {
		contentForm = page_content.document.forms["Contents"];
		MForm = page_main.document.forms["ModernizeForm"];
	} else {
		contentForm = page_content.document.Contents;
		MForm = page_main.document.ModernizeForm;
	}
	MForm.command.value = "command_Devices"
	MForm.highlightedDevice.value = ""
	MForm.submit()
}

function OnContentsSelectDevice(deviceHash) {
	var page_main;
	
	page_main = parent.frames[2]
	page_main.location = "/manage/devices.aspx?command=details&deviceHash=" + deviceHash.value
}

function OnContentsPerformScanAndUpdate() {
	var contentForm;
	var page_main;
	var page_content;
	page_main = parent.frames[2]
	page_content = parent.frames[1]
	if (window.navigator.appName.toLowerCase().indexOf("netscape") > -1) {
		contentForm = page_content.document.forms["Contents"];
		MForm = page_main.document.forms["ModernizeForm"];
	} else {
		contentForm = page_content.document.Contents;
		MForm = page_main.document.ModernizeForm;
	}
	MForm.command.value = "command_Updates"	
	RTSSoftUpdate.FindDevices()
	MForm.device_Hash.value = RTSSoftUpdate.GetDevicesHash()
	MForm.updateResults.value = RTSSoftUpdate.PerformUpdates(RTSSoftUpdate.PerformVersionScan(MForm.device_Hash.value))
	MForm.submit()
}

function OnContentsPerformUpdate() {
	var contentForm;
	var page_main;
	var page_content;
	page_main = parent.frames[2]
	page_content = parent.frames[1]
	if (window.navigator.appName.toLowerCase().indexOf("netscape") > -1) {
		contentForm = page_content.document.forms["Contents"];
		MForm = page_main.document.forms["ModernizeForm"];
	} else {
		contentForm = page_content.document.Contents;
		MForm = page_main.document.ModernizeForm;
	}
	MForm.command.value = "command_Updates"	
	RTSSoftUpdate.FindDevices()
	MForm.device_Hash.value = RTSSoftUpdate.GetDevicesHash()
	MForm.updateResults.value = RTSSoftUpdate.PerformUpdates(MForm.updateInfo.value)
	MForm.submit()
}

function OnContentsSoftwareUpdateScan() {
	var contentForm;
	var page_main;
	var page_content;
	page_main = parent.frames[2]
	page_content = parent.frames[1]
	if (window.navigator.appName.toLowerCase().indexOf("netscape") > -1) {
		contentForm = page_content.document.forms["Contents"];
		MForm = page_main.document.forms["ModernizeForm"];
	} else {
		contentForm = page_content.document.Contents;
		MForm = page_main.document.ModernizeForm;
	}
	MForm.command.value = "command_Updates"	
	RTSSoftUpdate.FindDevices()
	MForm.device_Hash.value = RTSSoftUpdate.GetDevicesHash()
	MForm.updateInfo.value = RTSSoftUpdate.PerformVersionScan(MForm.device_Hash.value)
	MForm.submit()
}

function OnSoftwareUpdateScan() {
	var contentForm;
	var page_main;
	var page_content;
	page_main = parent.frames[2]
	page_content = parent.frames[1]
	if (window.navigator.appName.toLowerCase().indexOf("netscape") > -1) {
		contentForm = page_content.document.forms["Contents"];
		MForm = page_main.document.forms["ModernizeForm"];
	} else {
		contentForm = page_content.document.Contents;
		MForm = page_main.document.ModernizeForm;
	}
	MForm.command.value = "command_Updates"	
	RTSSoftUpdate.FindDevices()
	MForm.device_Hash.value = RTSSoftUpdate.GetDevicesHash()
	MForm.updateInfo.value = RTSSoftUpdate.PerformVersionScan(MForm.device_Hash.value)
	MForm.submit()
}

function OnPerformUpdate() {
	var contentForm;
	var page_main;
	var page_content;
	page_main = parent.frames[2]
	page_content = parent.frames[1]
	if (window.navigator.appName.toLowerCase().indexOf("netscape") > -1) {
		contentForm = page_content.document.forms["Contents"];
		MForm = page_main.document.forms["ModernizeForm"];
	} else {
		contentForm = page_content.document.Contents;
		MForm = page_main.document.ModernizeForm;
	}
	MForm.command.value = "command_Updates"	
	RTSSoftUpdate.FindDevices()
	MForm.device_Hash.value = RTSSoftUpdate.GetDevicesHash()
	MForm.updateResults.value = RTSSoftUpdate.PerformUpdates(MForm.updateInfo.value)
	MForm.submit()
}

function OnPerformExpressUpdate() {
	var contentForm;
	var page_main;
	var page_content;
	page_main = parent.frames[2]
	page_content = parent.frames[1]
	if (window.navigator.appName.toLowerCase().indexOf("netscape") > -1) {
		contentForm = page_content.document.forms["Contents"];
		MForm = page_main.document.forms["ModernizeForm"];
	} else {
		contentForm = page_content.document.Contents;
		MForm = page_main.document.ModernizeForm;
	}
	MForm.command.value = "command_Updates"	
	RTSSoftUpdate.FindDevices()
	MForm.device_Hash.value = RTSSoftUpdate.GetDevicesHash()
	if (MForm.device_Hash.value == "0") {
		MForm.command.value = "command_Devices"	
		MForm.highlightedDevice.value = MForm.device_Hash.value
		MForm.submit()
	} else {
		var updateInformation = RTSSoftUpdate.PerformVersionScan(MForm.device_Hash.value)
		MForm.updateResults.value = RTSSoftUpdate.PerformUpdates(updateInformation)
		MForm.submit()
	}
}

function OnScanDevices() {
	var MForm;
	if (window.navigator.appName.toLowerCase().indexOf("netscape") > -1) {
		MForm = document.forms["ModernizeForm"];
	} else {
		MForm = document.ModernizeForm;
	}
	//RTSSoftUpdate = document.getElementById("RTSSoftUpdate")
	MForm.command.value = "command_Devices"	
	RTSSoftUpdate.FindDevices()
	MForm.device_Hash.value = RTSSoftUpdate.GetDevicesHash()
	MForm.highlightedDevice.value = ""							// clear this value out so that new scans don't try to display a non-existant device
	MForm.submit()
}

function OnSelectDevice(deviceHash) {
	var MForm;
	if (window.navigator.appName.toLowerCase().indexOf("netscape") > -1) {
		MForm = document.forms["ModernizeForm"];
	} else {
		MForm = document.ModernizeForm;
	}
	MForm.command.value = "command_Devices"	
	RTSSoftUpdate.FindDevices()
	MForm.device_Hash.value = RTSSoftUpdate.GetDevicesHash()
	MForm.highlightedDevice.value = MForm.device_Hash.value
	MForm.submit()
}

function OnRegisterDevice(deviceHash) {
	page_main = parent.frames[2]
	page_main.location = "/manage/devices.aspx?command=register&deviceHash=" + deviceHash
}

function OnCheckDevice(deviceHash) {
	var MForm;
	if (window.navigator.appName.toLowerCase().indexOf("netscape") > -1) {
		MForm = document.forms["ModernizeForm"];
	} else {
		MForm = document.ModernizeForm;
	}
	MForm.command.value = "command_Devices"	
	RTSSoftUpdate.FindDevices()
	MForm.device_Hash.value = RTSSoftUpdate.GetDevicesHash()
	MForm.selectedDevices.value += deviceHash + ";"
	MForm.submit()
}

function OnContentsPageLoaded() {
	page_main = parent.frames[2]
	if(page_main.location == "about:blank") {
		page_main.location = "modernize.aspx"
	}
	return;
}

function SyncContents() {
	var MForm;
	var contentForm;
	var page_main;
	var page_content;
	page_main = parent.frames[2]
	page_content = parent.frames[1]
	if (window.navigator.appName.toLowerCase().indexOf("netscape") > -1) {
		contentForm = page_content.document.forms["Contents"];
		MForm = page_main.document.forms["ModernizeForm"];
	} else {
		contentForm = page_content.document.Contents;
		MForm = page_main.document.ModernizeForm;
	}
		
	var submit_contents
	submit_contents = 0
	
	if(contentForm.device_Hash.value != MForm.device_Hash.value) {
		contentForm.device_Hash.value = MForm.device_Hash.value
		submit_contents = 1
	}
	if(contentForm.command.value != MForm.command.value) {
		contentForm.command.value = MForm.command.value
		submit_contents = 1
	}
	if(contentForm.highlightedDevice.value != MForm.highlightedDevice.value) {
		contentForm.highlightedDevice.value = MForm.highlightedDevice.value
		submit_contents = 1
	}
	if(contentForm.selectedDevices.value != MForm.selectedDevices.value) {
		contentForm.selectedDevices.value = MForm.selectedDevices.value
		submit_contents = 1
	}
	if(contentForm.hidden_updateResults.value != MForm.updateResults.value) {
		contentForm.hidden_updateResults.value = MForm.updateResults.value
		submit_contents = 1
	}
	if(submit_contents == 1) {
		contentForm.submit()
	}
	return 1;
}

function OnContentsReadyState() {
	if(page_content.readystate=="complete") {
		SyncContents()
	} 
}

function OnMainPageLoaded() {
	var MForm;
	var contentForm;
	var page_main;
	var page_content;
	page_main = parent.frames[2]
	page_content = parent.frames[1]
	if (window.navigator.appName.toLowerCase().indexOf("netscape") > -1) {
		contentForm = page_content.document.forms["Contents"];
		MForm = page_main.document.forms["ModernizeForm"];
	} else {
		contentForm = page_content.document.Contents;
		MForm = page_main.document.ModernizeForm;
	}
	MForm.action = "modernize.aspx"
	
	if(MForm.command.value == "") {
		MForm.command.value = "command_Welcome"
		MForm.submit()
		return;
	}
	
	if(!RTSSoftUpdate||RTSSoftUpdate == null||RTSSoftUpdate.GetVersionString == null) {
		window.top.alert("RTS Software Update System could not be loaded.  If you see a yellow bar at the top of this page, please follow the directions on the bar to allow the update plugin to install and function.  If you do not see a yellow bar you may need to configure your anti-virus protection to allow this website to use and install ActiveX controls.");
		//window.top.location = "error.aspx?errCode=noLibrary"
		return;
	}
	if(CheckVersion() == 0) {
		window.alert("RTS Software Update System could not be updated.\nThis system must be updated to continue properly.  A reboot may resolve this issue.")
		//window.top.location = "error.aspx?errCode=bad_version&error_info=" + RTSSoftUpdate.GetVersionString()
		return;
	}
	
	if(MForm.command.value == "RescanDevices") {
		RTSSoftUpdate.FindDevices()
		MForm.device_Hash.value = RTSSoftUpdate.GetDevicesHash()
		MForm.command.value = "command_Devices"
		MForm.submit()
	}
	
	if(MForm.command.value == "command_Devices" && MForm.device_Hash.value == "") {
		RTSSoftUpdate.FindDevices()
		MForm.device_Hash.value = RTSSoftUpdate.GetDevicesHash()
		MForm.submit()
	}
	
	if(MForm.device_Hash.value != "") {
		if(MForm.device_Hash.value != RTSSoftUpdate.GetDevicesHash()) {
			MForm.device_Hash.value = RTSSoftUpdate.GetDevicesHash()
			MForm.submit()
		}
	}
	// if the contents page hasn't loaded, wait till its loaded before trying to update it
//	if(page_content.readystate!="complete") {
//		page_content.onreadystatechange = OnContentsReadyState
//	} else {	
		SyncContents()
//	}
}
