<!--
//---- Javascript for Web Call (include keypad) ----

var xid;

if (top.xid)
	xid = top.xid;
else
	xid = 0;

//---- 登入 ----
function cmdLogin() {
	top.MsgTag.innerHTML = "系統載入中...";
	try {
		var CamangiX = objectFrame.CamangiX;
		CamangiX.init(GetLocationStr());
		CamangiX.setServiceServ(xid);
	}
	catch(e) {
		top.document.all.showarea1.innerHTML = "第一次使用者<br>請同意安裝ActiveX<br>如果你電腦無法使用ActiveX<br>請自行下載執行通話元件";
		top.document.all.download_area.style.display = 'inline';
		window.status = "";
	}
}

function cmdLogout() {
	var CamangiX = objectFrame.CamangiX;
	CamangiX.unInit();
}

function chk_install() {
	setTimeout("chk_install();", 2000);
	try {
		var obj = new ActiveXObject("CAMANGIX.CamangiXCtrl.1");
		if (obj) {
			window.close();
		}
	}
	catch(e) {}
}

function IsControlInstalled() {
	try {
		var obj = new ActiveXObject("CAMANGIX.CamangiXCtrl.1");
		if (obj) {
			objectFrame.show();
			return true;
		}
	}
	catch(e) {}
	return false;
}

//---- 撥號鍵送出 ----
function cmdCallExt(num) {
	try {
		var CamangiX = objectFrame.CamangiX;
		CamangiX.sendDtmf(num);
	}
	catch(e) {
		alert('語音通話元件尚未啟用');
	}
}

//---- 撥電話(固定電話號碼) ----
function cmdCall() {
	var CamangiX = objectFrame.CamangiX;

	CamangiX.setAudioCodec(1);  // Choose Codec
	//GSM:        1;
	//G.711 μLAW: 2;
	//G.711 aLAW: 3;
	//SPEEX:      4;
	//iLBC:       5;

	top.CloseLayer();  // Close network checking table
	CamangiX.call("");
	stopSound();
}

//---- 掛斷電話 ----
function cmdDel() {
	var CamangiX = objectFrame.CamangiX;
	top.CloseLayer();  // Close network checking table
	ClearInput();
	CamangiX.hangUp();
	stopSound();
}

function cmdSetAudio() {
	var CamangiX = objectFrame.CamangiX;
	CamangiX.setAudioWiz();
}

function cmdCheck() {
	var CamangiX = objectFrame.CamangiX;
	top.CloseLayer();  // Close network checking table
	CamangiX.check();
}

function playSound() {
	wavFrame.location = "../share/playSound.html";
}

function stopSound() {
	wavFrame.location = "../share/stopSound.html";
}

//---- 呼叫鍵盤面板部份 ----
function show_button() {
	document.all.DisplayPanel.style.display = 'inline';
}

//---- 關閉鍵盤面板 ----
function CloseKey() {
	document.all.DisplayPanel.style.display = 'none';
	IsActiveKey = false;
}

//---- 清除鍵盤面板輸入 ----
function ClearInput() {
	document.all.ReadOut.value = "";
	for(var i = 0; i < k_count; i++) {
		keydata[i] = null;
	}
	k_count = 0;
	first_press = true;
}

//---- 鍵盤面板 ----

//48 49 50 51 52 53 54 55 56 57 42 35 (0 1 2 3 4 5 6 7 8 9 * # enter)
var keyinfo = new Array(48,49,50,51,52,53,54,55,56,57,42,35,13);
var temp = 0;
var IsActiveKey = false;  //啟動鍵盤初始值
var keydata = new Array();
var first_press = true;
var k_count = 0;

function keyboard_input(n) {
	if (IsActiveKey == false)
		return;

	if (n == '') {
		temp = event.keyCode;
		for(var i = 0; i < 13; i++) {
			if (temp == keyinfo[i]) {
				num = i;
				break;
			}
		}
		if (num == '10') { num = '*'; }
		if (num == '11') { num = '#'; }
		if (num == '12') { ClearInput(); return; }
	}
	else {
		num = n;
	}

	if (first_press) {
		document.all.ReadOut.value = num;
		k_count = 1;
		keydata[k_count-1] = num;
		first_press = false;
	}
	else {
		if (k_count < 11) {
			document.all.ReadOut.value += num;
			k_count++;
			keydata[k_count-1] = num;
		}
		else {
			document.all.ReadOut.value = "";
			for(var i = 1; i < 11; i++) {
				document.all.ReadOut.value += keydata[i];
			}
			document.all.ReadOut.value += num;
			for(var i = 1; i < 11; i++) {
				keydata[i] = keydata[i+1];
			}
			keydata[k_count-1] = num;
		}
	}

	cmdCallExt(num);
	num = "";
}

//---- 取得位址後面的參數 ----
function GetLocationStr() {
	var str = window.location.search.replace("?", "");
	return str;
}

//---- 鎖定Backspace鍵 ----
document.onkeydown = checkbacksapce;

function checkbacksapce(e) {
	var code;
	if (!e)
		var e = window.event;
	if (e.keyCode)
		code = e.keyCode;
	else if (e.which)
		code = e.which;

	if (code == 8) {
		code = 0;
		if (document.all.ReadOut.value != "") {
			document.all.ReadOut.value = "";
			for(var i = 0; i < (k_count-1); i++) {
				document.all.ReadOut.value += keydata[i];
			}
			keydata[k_count-1] = null;
			k_count--;
		}
		return false;
	}
	return true;
}

//-->
