function ShowStatus(StatusCode) {
	switch (StatusCode) {
		case 1:
			hello.txtStatus.value =  "Connecting....";
			hello.txtStatus2.value =  "";
			break;
		case 4:
			hello.txtStatus.value =  "Ringing...";
			hello.txtStatus2.value =  "";
			break;
		case 6:
			hello.txtStatus.value =  "Connected.";
			hello.txtStatus2.value =  "";
			break;
		case 2:
			hello.txtStatus.value =  "Disconnected.";
			hello.txtStatus2.value =  "";
			setTimeout('hello.txtStatus.value = "Ready...."',4000);
			bCallInitialized = false;
			break;
		case 3:
			break;
		case 11:
			hello.txtStatus.value =  "Call Rejected.";
			hello.txtStatus2.value =  "";
			setTimeout('hello.txtStatus.value = "Ready...."',4000);
			bCallInitialized = false;
			break;
		case 13:
			hello.txtStatus.value =  "Destination Busy.";
			hello.txtStatus2.value =  "";
			setTimeout('hello.txtStatus.value = "Ready...."',4000);
			bCallInitialized = false;
			break;
		case 14:
			hello.txtStatus.value =  "Destination Not Online.";
			hello.txtStatus2.value =  "";
			setTimeout('hello.txtStatus.value = "Ready...."',4000);
			bCallInitialized = false;
			break;
		case 15: // Display the RTC error text
			calltable.style.visibility = "hidden";
			fwtable.style.visibility = "hidden";
			rtctable.style.visibility = "visible";
			break;
		case 16: // Display the firewall/port error text
			calltable.style.visibility = "hidden";
			rtctable.style.visibility = "hidden";
			fwtable.style.visibility = "visible";
			break;
	}
}

var bCallInitialized = false;
var bClicked=false;
var bWinClosed=false;
	 	
function StartCall() {
		CCallerCtrl1.Call(hello.Target.value);
		bCallInitialized = true;
}

function EndCall() {
	CCallerCtrl1.EndCall(0);
	bCallInitialized = false;	
}

function Configure() {
	CCallerCtrl1.InvokeTuningWizard();
}


function ConfirmClose() {  //called for OnbeforeUnload()
	//Browser is closed using the 'X' button
	if (window.screenTop&&(window.screenTop>screen.height)) bWinClosed=true;
		
	//While on call, page is refreshed or close IE
	if ((!bClicked) && (!bWinClosed) && bCallInitialized == true) {
		var message = 'You are currently on a call...'; 
		if (typeof evt == 'undefined') {
			evt = window.event; 
		} 
		if (evt) { 
			evt.returnValue = message; 
		} 
		return message;					
	}
}


function userClick() {
	bClicked = true;
	setTimeout("bClicked=false;", 100);
}


function HandleOnClose() {//Called for onUnload
	CCallerCtrl1.EndCall(1);
}


function PageLoaded() {
//alert("Javascript working - will now change status to initializing");
	hello.txtStatus.value =  "Initializing Please wait.. ..";
	hello.txtStatus2.value =  "";
	calltable.style.visibility = "visible";
	rtctable.style.visibility = "hidden";
	fwtable.style.visibility = "hidden";
//alert("checking browser, If 98 or ME, change 98/ME error layer if not found");
	checkBrowser();
//alert("OS OK, continuing to initialize the button");

        //      Needed to display the "Initializing..." layer
        //      Browser needs a pause  (500ms) to refresh before init'ing CCallerCtrl1.
        setTimeout("PageInit()",500);
}


function checkBrowser() {
	if(
		(
			(navigator.userAgent.indexOf('Win') != -1) &&
			(navigator.userAgent.indexOf('98') != -1)
		) || (
			(navigator.userAgent.indexOf('Win') != -1) &&
			(navigator.userAgent.indexOf('ME') != -1)
		)
	){
		//alert("Using 98.. ");
		hello.txtStatus.value =  "Initializing Please wait.. ..";
		hello.txtStatus2.value =  "";
		calltable.style.visibility = "hidden";
		rtctable.style.visibility = "hidden";
		fwtable.style.visibility = "hidden";
		win98.style.visibility = "visible";
	}
}


function PageInit() {
        CCallerCtrl1.Initialize();
        hello.txtStatus.value =  "Ready.. ..";
//alert("Now ready to call");
        Call.onclick = StartCall;
        End.onclick = EndCall;
}


window.onload = PageLoaded;
window.onbeforeunload = ConfirmClose;
window.onunload = HandleOnClose;
