function confirmDeletePage(msg, url){
	if(confirm(msg)){
		top.location.href=url;
	}
}

function generateIdentityPin() {// This function Generates a new ID pin and sends the result to the screen in a javascript window.
	sendFrameCommand("generateIdPin");
}

function openQueueWindow(){
	childwin = window.open("opQueueWait.php?", "opQueueWaitWin", "height=300,width=500,toolbar=0");
//		childwin.focus();
}

function openQandAQueueWindow(){
	childwin = window.open("qanda_queue.php", "q_and_a_queue_win", "fullscreen=no,toolbar=no,status=no,menubar=yes,scrollbars=yes,resizable=yes,directories=no,location=no,width=640,height=400,left=0,top=0");
	childwin.focus();	
}

function doDial(dialnum){
	var lookingAtSubId = top.document.getElementById("liveConfSubId");
	lookingAtSubId = (lookingAtSubId != null && lookingAtSubId.value > 0)?lookingAtSubId.value:0;
	if(dialnum == null){
		dialing = window.open("dialoutWait.php", "dialOutWin", "height=500,width=500,toolbar=0");
	} else {
		dialing = window.open("dialoutWait.php?dialAssisted=" + dialnum, "dialOutWin", "height=500,width=500,toolbar=0");
	}
	dialing.subId = lookingAtSubId;
	dialing.focus();
}

function addFrameCommand(command, args){
	var controlFrame = top.document.getElementById("controlFrame");
	var topcommandtag = controlFrame.contentWindow.document.getElementById("topcommandtag");
	if(topcommandtag.value != ""){
		topcommandtag.value = topcommandtag.value + ";\n";
	}
	topcommandtag.value = topcommandtag.value + command + ":" + args;
}

function sendFrameCommand(command, args){
	if(command != "")
		addFrameCommand(command, args);
	var controlFrame = top.document.getElementById("controlFrame");
	mainform = controlFrame.contentWindow.document.getElementById("mainform");
	mainform.submit();
}

function manageCaller(action, DNIS, vru, channel, confId){
	subId = 0;
	operjointoo = 0;
	if(action > 10){
		action = action - 10;
		operjointoo = 1;
	}
//	alert("Action:" + action + " dnis:" + DNIS + " vru:" + vru + " channel:" + channel + " confId:" + confId);
	switch(action){
		case 0: // hangup voice path
			addFrameCommand("hangupVoicePath", action + ":" + vru + ":" + channel);
			break;
		case 1: // into conf as part
		case 4: // into conf silent
		case 5: // into conf as host
		case 6:// back into conf as participant
		case 7: // back into conf as host
			if( (confId == null) || (confId == 0)) {
				confId = top.document.getElementById("liveConfId");
				if(confId != null) {
					confId = confId.value;
				} else {
					subId = top.document.getElementById("liveConfSubId");
					if((subId == null)  || (subId.value <= 0)){
						alert("You must be viewing a conference to put this caller into.");
						return;
					} else {
						subId = subId.value;
					}
				}
			}
			if((confId != null) && (confId > 0) && (action < 6) && (DNIS == null)){
				if(!confirm("Put Caller into Conference " + confId + " ?"))
					return;
			} else if (subId > 0) {				
				if(!confirm("This will begin this conference.\nPlace caller in new conference?"))
					return;					
			}
			// fallthrough
		case 2:
			if(action == 2){
				if(DNIS.length <= 0){
					DNIS = "<use original DNIS>";
				}
				DNIS = prompt("Enter DNIS", DNIS);				
				if(DNIS == null){
					return;
				}
				DNIS = (DNIS == "<use original DNIS>")?"":DNIS;
			}		
			// fallthrough
		case 3: // hangup
			addFrameCommand("sendCaller", action + ":" + DNIS + ":" + vru + ":" + channel + ":" + confId + ":" + subId + ":" + operjointoo);
			break;
		case 8: // disco operator from conf
			addFrameCommand("leaveConf", action + ":" + confId + ":" + vru + ":" + channel + ":" + confId);
			break;
		case 9: // mute Operator
		case 10: // unmute operator (fallthrough)
			addFrameCommand("muteOper", (10-action) + ":" + vru + ":" + channel);
			break;
		default: 
			alert("Error: Unknown command " + action);
	}
	if(operjointoo > 0){
		if(confId > 0)
			addFrameCommand("operJoinConf", confId + ":force");
		else
			alert("Can only Escort into a conference that already exists.");
	}
	sendFrameCommand("", "");
}

function modTakingCalls(taking){
	sendFrameCommand("takingCalls", taking);
}
