function openManualTestPopup(message)
{
	var windowW = 475;
	var windowH = 370;
	var LeftPosition = (screen.width) ? (screen.width-windowW)/2 : 0;
	var TopPosition = (screen.height) ? (screen.height-windowH)/2 : 0;
	var url = "/schedule/device_selector.html?mode=test";
	var options = "left="+LeftPosition+",top="+TopPosition+",width="+windowW+",height="+windowH;
	options = options+",toolbar=no,location=no,status=no,menubar=no";
	options = options+",scrollbars=auto,resizable,alwaysRaised,dependent,titlebar=no";
	if(message != null && message != "") url = url+"&msg="+message;
	var deviceSelector = window.open(url, "Popup", options);
	if(deviceSelector != null){
		deviceSelector.focus();
	}else{
		alert("ERROR: Popup Window Blocked. Popups are required for editing schedule");
	}
}
function openManualOverridePopup(message)
{
	var windowW = 500;
	var windowH = 370;
	var LeftPosition = (screen.width) ? (screen.width-windowW)/2 : 0;
	var TopPosition = (screen.height) ? (screen.height-windowH)/2 : 0;
	var url = "/schedule/device_selector.html?mode=override";
	var options = "left="+LeftPosition+",top="+TopPosition+",width="+windowW+",height="+windowH;
	options = options+",toolbar=no,location=no,status=no,menubar=no";
	options = options+",scrollbars=auto,resizable,alwaysRaised,dependent,titlebar=no";
	if(message != null && message != "") url = url+"&msg="+message;
	var deviceSelector = window.open(url, "Popup", options);
	if(deviceSelector != null){
		deviceSelector.focus();
	}else{
		alert("ERROR: Popup Window Blocked. Popups are required for editing schedule");
	}
}
function openDeviceSelector(message,field,actionStr)
{
	document.ev1.action = '/schedule/device_selector.html';
	document.ev1.submit();
}
function openDeviceSelectorPopup(message,field,actionStr)
{
	var windowW = 475;
	var windowH = 370;
	var LeftPosition = (screen.width) ? (screen.width-windowW)/2 : 0;
	var TopPosition = (screen.height) ? (screen.height-windowH)/2 : 0;
	var url = "/schedule/device_selector.html?mode=device&actionUrl="+escape(field.value)+"&frame=1";
	var options = "left="+LeftPosition+",top="+TopPosition+",width="+windowW+",height="+windowH;
	options = options+",toolbar=no,location=no,status=no,menubar=no";
	options = options+",scrollbars=auto,resizable,alwaysRaised,dependent";
	if(message != null && message != "") url = url+"&msg="+message;
	var deviceSelector = window.open(url, "Popup", options);
	if(deviceSelector != null){
		deviceSelector.deviceSelectorParent = window;
		deviceSelector.deviceSelectorResult = field;
		if(actionStr != null)deviceSelector.deviceSelectorEngrish = actionStr;
		deviceSelector.focus();
	}else{
		alert("ERROR: Popup Window Blocked. Popups are required for editing schedule");
	}
}

function openActionSelectorPopup(message,field,actionStr)
{
	var windowW = 475;
	var windowH = 370;
	var LeftPosition = (screen.width) ? (screen.width-windowW)/2 : 0;
	var TopPosition = (screen.height) ? (screen.height-windowH)/2 : 0;
	var url = "/schedule/device_selector.html?actionUrl="+escape(field.value)+"&frame=1";
	var options = "left="+LeftPosition+",top="+TopPosition+",width="+windowW+",height="+windowH;
	options = options+",toolbar=no,location=no,status=no,menubar=no";
	options = options+",scrollbars=auto,resizable,alwaysRaised,dependent";
	if(message != null && message != "") url = url+"&msg="+message;
	var deviceSelector = window.open(url, "Popup", options);
	if(deviceSelector != null){
		deviceSelector.deviceSelectorParent = window;
		deviceSelector.deviceSelectorResult = field;
		if(actionStr != null)deviceSelector.deviceSelectorEngrish = actionStr;
		deviceSelector.focus();
	}else{
		alert("ERROR: Popup Window Blocked. Popups are required for editing schedule");
	}
}

function setDirty(type){
/*	var curtype = document.picker1.chtype.value;
	switch(curtype){
	case 'R':
		break;
	default:
		document.picker1.chtype.value = type;
	}
*/
}

function changeType(type){
	setDirty("D");
	document.picker1.sel_type.value = type;
	//document.picker1.action.value = document.picker1.systemMoniker.value;
 	document.picker1.submit();
}
function changePanel(){
	setDirty("D");
 	var num = document.picker1.a_panel.value;
	document.picker1.sel_type.value = "RelayPanel";
	document.picker1.actionUrl.value = num;
	document.picker1.submit();
}
function setAction(auto){
	var actionUrl;
	var actionStr;
	if(auto) setDirty("D");
	if(document.picker1.dev_type[3].checked == true){ // groupdevice
		actionUrl = document.picker1.a_groupdevice.value;
		actionStr = document.picker1.a_groupdevice[document.picker1.a_groupdevice.selectedIndex].text;
	}else if(document.picker1.dev_type[2].checked == true){ // relay
		actionUrl = document.picker1.a_relay.value;
		actionStr = document.picker1.a_relay[document.picker1.a_relay.selectedIndex].text;
	}else if(document.picker1.dev_type[1].checked == true){ // phonecode
		actionUrl = document.picker1.a_phonecode.value;
		actionStr = document.picker1.a_phonecode[document.picker1.a_phonecode.selectedIndex].text;
	}else if(document.picker1.dev_type[0].checked == true){ //switchcode
		actionUrl = document.picker1.a_switchcode.value;
		actionStr = document.picker1.a_switchcode[document.picker1.a_switchcode.selectedIndex].text;
	}
	if(document.picker1.device_action){
		if(document.picker1.device_action[0].checked == true) {
			actionUrl+="?Level=on";
			actionStr += ' - ';
			if(document.picker1.relayfunction){
				actionStr+=document.picker1.relayfunction[document.picker1.relayfunction.selectedIndex].text;
			}
			actionStr+=" On";
			if(document.picker1.duration_minutes){
				var duration = document.picker1.duration_minutes.value;
				if(duration > 0){
					actionUrl += '&Duration='+duration;
					actionStr += ' for '+duration+' minutes';
				}
			}
		}else{ 
			actionUrl+="?Level=off";
			actionStr += ' - ';
			if(document.picker1.relayfunction){
				actionStr+=document.picker1.relayfunction[document.picker1.relayfunction.selectedIndex].text;
			}
			actionStr+=" Off";
		}
		if(document.picker1.relayfunction){
			actionUrl += '&Function='+document.picker1.relayfunction.value;
		}
	}
	document.picker1.actionUrl.value = actionUrl;
	document.picker1.actionStr.value = actionStr;
	return true;
}
function updateAction(){
	setAction();
	document.picker1.action="/schedule/edit_action.html";
	document.picker1.submit();
}
function actionTest(){
	setAction();
	document.picker1.pgcommand.value="FireEvent";
	document.picker1.submit();
}
function doActionNow(level){
	var actionUrl;
	var actionStr;
	if(document.picker1.dev_type[3].checked == true){ // groupdevice
		actionUrl = document.picker1.a_groupdevice.value;
		actionStr = document.picker1.a_groupdevice[document.picker1.a_groupdevice.selectedIndex].text;
	}else if(document.picker1.dev_type[2].checked == true){ // relay
		actionUrl = document.picker1.a_relay.value;
		actionStr = document.picker1.a_relay[document.picker1.a_relay.selectedIndex].text;
	}else if(document.picker1.dev_type[1].checked == true){ // phonecode
		actionUrl = document.picker1.a_phonecode.value;
		actionStr = document.picker1.a_phonecode[document.picker1.a_phonecode.selectedIndex].text;
	}else if(document.picker1.dev_type[0].checked == true){ //switchcode
		actionUrl = document.picker1.a_switchcode.value;
		actionStr = document.picker1.a_switchcode[document.picker1.a_switchcode.selectedIndex].text;
	}
	if(level == "on"){
		actionUrl+="?Level=on";
		actionStr += ' - ';
		if(document.picker1.relayfunction){
			actionStr+=document.picker1.relayfunction[document.picker1.relayfunction.selectedIndex].text;
		}
		actionStr+=" On";
		if(document.picker1.duration_minutes){
			var duration = document.picker1.duration_minutes.value;
			if(duration > 0){
				actionUrl += '&Duration='+duration;
				actionStr += ' for '+duration+' minutes';
			}
		}
	}else{ 
		actionUrl+="?Level=off";
		actionStr += ' - ';
		if(document.picker1.relayfunction){
			actionStr+=document.picker1.relayfunction[document.picker1.relayfunction.selectedIndex].text;
		}
		actionStr+=" Off";
	}
	if(document.picker1.relayfunction){
		actionUrl += '&Function='+document.picker1.relayfunction.value;
	}
	document.picker1.actionUrl.value = actionUrl;
	document.picker1.actionStr.value = actionStr;
	sendAction(actionUrl);
}
function doAction(){
	setAction();
	document.picker1.pgcommand.value="Override";
	document.picker1.submit();
}
function saveEdit(){
	setAction();
	document.picker1.action="/schedule/edit_action.html";
	document.picker1.submit();
}
function cancelEdit(){
	document.picker1.action="/schedule/edit_action.html";
	document.picker1.submit();
}
function saveActionUrl(){
	var devsel = null;
	var actionStr = null;
	setAction();
	if(window.deviceSelectorEngrish){
		actionStr = window.deviceSelectorEngrish;
	}else{
		if(window.parent && window.parent.deviceSelectorEngrish){
			actionStr = window.parent.deviceSelectorEngrish;
		}
	}
	if(actionStr){
		actionStr.value = document.picker1.actionStr.value;
	}
	if(window.deviceSelectorResult){
		devsel = window.deviceSelectorResult;
	}else{
		if(window.parent && window.parent.deviceSelectorResult){
			devsel = window.parent.deviceSelectorResult;
		}
	}
	if(devsel){
		devsel.value = document.picker1.actionUrl.value;
	}
	if(window.parent) window.parent.close();
	else window.close();
}
function closeSelector(){
	if(window.parent) window.parent.close();
	else window.close();
}
