//=== DEMO TELEPHONY ================================================================================
function IsTelephonyDivVisible(){
	var tel_div = FgetElementById("TelephonyDiv");
	return !(tel_div.style.left == "3000" || tel_div.style.left == "3000px" || tel_div.style.left == "");
}
function IsDivVisible(div_id){
	var div = document.getElementById(div_id);
	return !(div.style.visibility == "hidden" || div.style.visibility == "");
}
function SetDivVisibility(div_id, visibility){
	document.getElementById(div_id).style.visibility = visibility;
}
function SetTelephonyDivLabels(label_1, label_2, label_3, label_12, label_13, label_14){
	FgetElementById("SK74").innerHTML = label_1;	//1
	FgetElementById("SK75").innerHTML = label_12;		//12
	FgetElementById("SK76").innerHTML = label_2;	//2
	FgetElementById("SK77").innerHTML = label_13;		//13
	FgetElementById("SK78").innerHTML = label_3;	//3
	FgetElementById("SK79").innerHTML = label_14;		//14
}
function TelephonyDivShow(){
	// shows telephony "pop-up" window
	FgetElementById("TelephonyDiv").style.left = "0px";
	SetTelephonyDivLabels("Phonebook","","Music On", "","Redial","Messaging");
}
function TelephonyDivHide(){
	// hide telephony "pop-up" window
	FgetElementById("TelephonyDiv").style.left = "3000px";
	FgetElementById("TextDisplay").innerHTML = "";
}
function TelephonyDivToggle(){
	SetDivVisibility("Lamp","hidden");
	
	if(IsTelephonyDivVisible()){ 
		TelephonyDivHide(); // hide telephony "pop-up" window
	}else{
		TelephonyDivShow(); // show telephony "pop-up" window
	}
}
function SetHandsetOffHook(set_off_hook){
	if(set_off_hook==-1) 
		set_off_hook = (document.getElementById("P").src.indexOf("5340-phone.gif")!=-1 && !IsTelephonyDivVisible());
	document.getElementById("P").src = (set_off_hook) ? "Demo_Images/5340-phone-off.gif" : "Demo_Images/5340-phone.gif";
	document.getElementById("AreaHookswitch").title = (set_off_hook) ? "Hang up" : "Answer";
}
var simulate_answer = false;
function TelephonyDivOffHookToggle(handset_click){
	if(simulate_answer){
		SetHandsetOffHook(true);
		
		SetTelephonyDivLabels("","","", "","Trans/Conf","Hang-up");
		SetDivVisibility("Lamp","hidden");
		simulate_answer = false;
		return;
	}else{
		SetHandsetOffHook( (handset_click ? -1 : false) ); // -1 means toggle, if necessary
	}
	SetDivVisibility("Lamp", "hidden");
	SetDivVisibility("Sound", (IsDivVisible("Sound"))? "hidden" : "visible" );
	
	// Synchronize with "sound"
	if(!IsDivVisible("Sound")){ 
		TelephonyDivHide(); // hide telephony "pop-up" window
	}else{
		TelephonyDivShow(); // show telephony "pop-up" window
	}
	
	SetTelephonyDivLabels("","","", "","Redial","Hang-up");
}
function TelephonyDivOnHook(){
	SetDivVisibility("Lamp","hidden");
	SetDivVisibility("Sound","hidden");
	SetHandsetOffHook(false);
	
	TelephonyDivHide(); // hide telephony "pop-up" window
}
function TelephonyDivIncoming(sim_answ){
	// simulate incomming call
	if(document.getElementById("P").src.indexOf("Demo_Images/5340-phone.gif") != -1){
		simulate_answer = sim_answ;
		
		TelephonyDivShow();
		FgetElementById("TextDisplay").innerHTML = "1907 NICHOLAS COHEN";
		SetTelephonyDivLabels("","","", "","","");
		
		SetDivVisibility("Sound","visible");
		SetDivVisibility("Lamp","visible");
	}else{
		alert("You have to hang up first :)");
	}
}
//=== Dial mock up function =========================================================================
function DialMockUp(number) // DO NOT REMOVE! THIS IS USED ON THE MAIN PAGE
{
	// This function mocks up the dialing.
	TelephonyDivShow();
	SetDivVisibility("Sound","visible");
	SetDivVisibility("Lamp","visible");
	FgetElementById("TextDisplay").innerHTML = number;
	SetTelephonyDivLabels("Call Me Back","","Leave A Msg", "","","Hang-up");
}
//=== Date and Time script ==========================================================================
//=== Displays current date in DateDisplay div, if such a div exists on the page ====================
function displayTime()
{
	var TimerDIV = document.getElementById( "TimeDisplay" );
	var CurrentTime = new Date();
	if( TimerDIV ){
		var Minutes = new String( CurrentTime.getMinutes() );

		if( Minutes.length < 2 )
			Minutes = "0" + Minutes;

		TimerDIV.innerHTML = CurrentTime.getHours() + ":" + Minutes;
	}
}
//=== Displays current time in TimeDisplay div, if such a div exists on the page ====================
function displayDate()
{
	var DateDIV = document.getElementById( "DateDisplay" );
	var CurrentTime = new Date();
	var num_month = ( CurrentTime.getMonth() + 1 );
	var abbrev_month = "";
	switch(num_month){
		case 1:  abbrev_month="JAN"; break;
		case 2:  abbrev_month="FEB"; break;
		case 3:  abbrev_month="MAR"; break;
		case 4:  abbrev_month="APR"; break;
		case 5:  abbrev_month="MAY"; break;
		case 6:  abbrev_month="JUN"; break;
		case 7:  abbrev_month="JUL"; break;
		case 8:  abbrev_month="AUG"; break;
		case 9:  abbrev_month="SEP"; break;
		case 10: abbrev_month="OCT"; break;
		case 11: abbrev_month="NOV"; break;
		case 12: abbrev_month="DEC"; break;
	}
	if( DateDIV ){
		DateDIV.innerHTML = CurrentTime.getDate() + "-" + abbrev_month + "-" + CurrentTime.getFullYear();
	}
}