/**
 * This file contains all HTML elements used by WisaForce
 * All rights reserved, copyright 2011
 */

function WisaInsertChatBox() {
	var div = document.createElement("DIV");
	div.id = "wisa_chat_window";
	div.className = "wisa_no_sync wisa_chat_window wisa_html_client_only";
	document.body.appendChild( div );
	
	var html = "";
	html += "<div id=\"wisa_chatheader\" class=\"wisa_chatheader\"></div>";
	html += "<div id=\"wisa_chatbody\" class=\"wisa_chatbody\">";
	html += "<div id=\"wisa_chatbox\" class=\"wisa_chatbox\"></div>";
	html += "Message :<br/><textarea id=\"wisa_chattext\" class=\"wisa_chattext\" onkeypress=\"WisaValid(event)\"></textarea>";
	html += "<div class=\"wisa_chatsend\"><input type=\"button\" id=\"send\" value=\"Valider\" onclick=\"WisaChatSend()\"/></div>";
	html += "</div>";
	html += "<div class=\"wisa_chatclose\"><a title=\"Close\" onclick=\"WisaChatStop()\">X</a></div>";

	div = Wisa$("wisa_chat_window");
	div.innerHTML = html;
	
	WisaChatInit("wisa_chat_window", "wisa_chatbox", "wisa_chattext");
}

function WisaValid(e) {
    var charCode;
    
    if(e && e.which){
        charCode = e.which;
    }else if(window.event){
        e = window.event;
        charCode = e.keyCode;
    }

    if (charCode == 13) {
    	WisaChatSend();
    	e.cancelBubble = true;
    	e.returnValue = false;
    	if (e.stopPropagation) {
    		e.stopPropagation();
    		e.preventDefault();
    	}
    	return false;
    }
}

function WisaInsertHelpWindow() {
	var div = document.createElement("DIV");
	div.id = "wisa_help_window";
	div.className = "wisa_no_sync wisa_help_window wisa_html_client_only";

	document.body.appendChild( div );
	
	var html = "";
//	html += "<h2>Besoin d'aide ?</h2>";
//	html += "Si vous avez des probl&egrave;mes pour poursuivre, des conseillers sont &agrave; votre disposition pour vous aider dans vos d&eacute;marches. Pour cela, veuillez entrer votre num&eacute;ro de t&eacute;l&eacute;phone ci-dessous.<br/>";
//	html += "<br/>num&eacute;ro de t&eacute;l&eacute;phone : ";
	html += "<input type=\"text\" id=\"phone_help_window\" />";
//	html += "<br/>";
//	html += "<br/>";
	html += "<div id=\"wisa_client_action_only\">";
	html += "<input type=\"button\" id=\"wisa_ok_button\" value=\"\" onclick=\"WisaHelpClose(true)\"/>";
	html += "<input type=\"button\" id=\"wisa_cancel_button\" value=\"\" onclick=\"WisaHelpClose(false)\" />";
	html += "</div>";

	div = Wisa$("wisa_help_window");
	div.innerHTML = html;
	
	WisaHide(div);
}

function WisaInsertOPChatBox() {
	var div = document.createElement("DIV");
	div.id = "wisa_opdock_window";
	div.className = "wisa_no_sync wisa_opdock_window wisa_html_client_only";
	document.body.appendChild( div );
	
	var html = "";
	html += "<div class=\"wisa_opdockheader\"></div>";
	
	// Op Status
	html += "<b><u>Etat de collaboration</u></b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
	html += "<span id=\"wisa_opstateobs\" class=\"wisa_opstateoff\" title=\"Observation simple\" onclick=\"WisaObsToggle()\">O</span>&nbsp;&nbsp;&nbsp;";
	html += "<span id=\"wisa_opstatectrl\" class=\"wisa_opstateoff\" title=\"Controle de la session\" onclick=\"WisaCtrlToggle()\">C</span>&nbsp;&nbsp;&nbsp;";
	html += "<span id=\"wisa_opstatechat\" class=\"wisa_opstateoff\" title=\"Clavardage en cours\" onclick=\"WisaChatToggle()\">D</span>&nbsp;&nbsp;&nbsp;";
	html += "<br/>";
	
	// Op Tools
	html += "<br/><b><u>Options de collaboration</u></b><br/><br/>";
	html += "<input id=\"wisa_modeflash\" type='checkbox' onclick='WisaSetXHRMode(this.checked?\"Flash\":null)'> Force Flash<br/>";
	html += "<input id=\"wisa_sendmouse\" type='checkbox' onclick='WisaSetMouseFlag(this.checked)'> Envoyer la position de ma souris<br/>";
	html += "<br/><b><u>Actions disponibles</u></b><br/><br/>";
	html += "<div id=\"wisa_ctrlstart\" class=\"wisa_opaction\"><a href=\"#\" onclick=\"WisaCtrlStart()\">Démarrer le contrôle</a></div>";
	html += "<div id=\"wisa_ctrlstop\" class=\"wisa_opaction\"><a href=\"#\" onclick=\"WisaCtrlStop()\">Arrêter le contrôle</a></div>";

	html += "<div id=\"wisa_collabstop\" class=\"wisa_opaction\"><a href=\"#\" onclick=\"WisaCollabStop()\">Arrêter la collaboration</a></div>";
	
	html += "<div id=\"wisa_chatstart\" class=\"wisa_opaction\"><a href=\"#\" onclick=\"WisaChatStart()\">Démarrer le clavardage</a></div>";
	html += "<div id=\"wisa_chatstop\" class=\"wisa_opaction\"><a href=\"#\" onclick=\"WisaChatStop()\">Arrêter le clavardage</a></div>";
	
	// Chat
	html += "<div id=\"wisa_chat_window\" class=\"wisa_opchat_window\">";
	html += "<br><b><u>Clavardage</u></b><br>";
	html += "<div id=\"wisa_chatbox\" class=\"wisa_opchatbox\"></div>";
	html += "<textarea id=\"wisa_chattext\" class=\"wisa_opchattext\" onkeypress=\"WisaValid(event)\"></textarea>";
	html += "<div class=\"wisa_opchatclose\"><a title=\"Close\" onclick=\"WisaChatStop()\">X</a></div>";
	html += "<div class=\"wisa_opchatsend\"><input type=\"button\" id=\"send\" value=\"Valider\" onclick=\"WisaChatSend()\"/></div>";
	html += "</div>";
	html += "</div>";
	html += "<div class=\"wisa_opdockreduce\"><a title=\"Reduce\" onclick=\"WisaOpDockReduce(0)\"><|</a></div>";

	div = Wisa$("wisa_opdock_window");
	div.innerHTML = html;

	var div2 = document.createElement("DIV");
	div2.id = "wisa_opdock_window_reduced";
	div2.className = "wisa_no_sync wisa_opdock_window_hidden wisa_html_client_only";
	document.body.appendChild( div2 );

	var html = "";
	
	html += "<div class=\"wisa_opdockheader2\"></div>";
	// Op Status
	html += "&nbsp;<span id=\"wisa_opstateobs2\" class=\"wisa_opstateoff\" title=\"Observation simple\" onclick=\"WisaObsToggle()\">O</span><br/><br/>";
	html += "&nbsp;<span id=\"wisa_opstatectrl2\" class=\"wisa_opstateoff\" title=\"Controle de la session\" onclick=\"WisaCtrlToggle()\">C</span><br/><br/>";
	html += "&nbsp;<span id=\"wisa_opstatechat2\" class=\"wisa_opstateoff\" title=\"Clavardage en cours\" onclick=\"WisaChatToggle()\">D</span><br/><br/>";
	html += "<br/>";
	
	html += "<div class=\"wisa_opdockreduce\"><a title=\"Open\" onclick=\"WisaOpDockReduce(1)\">|></a></div>";
	
	div2 = Wisa$("wisa_opdock_window_reduced");
	div2.innerHTML = html;
	
	var dockpos = WisaReadCookie("wisadock"+WisaGetSessionId());
	if( dockpos !=null && dockpos == "0" ) WisaOpDockReduce( dockpos );
	else WisaOpDockReduce( 1 );
	
	WisaChatInit("wisa_chat_window", "wisa_chatbox", "wisa_chattext");
}

function WisaOpDockReduce( state ) {
	WisaDisplay( Wisa$("wisa_opdock_window"), (state==1) );
	WisaDisplay( Wisa$("wisa_opdock_window_reduced"), (state==0) );
	WisaCreateCookie("wisadock"+WisaGetSessionId(),state,"1");
}

function WisaHelpClose(accepted)
{
	var phoneNumber = document.getElementById('phone_help_window');
	var helpWindow = document.getElementById('wisa_help_window');
	helpWindow.style.visibility = "hidden";
	WisaHelpUserToServer(accepted ? "1" : "0", phoneNumber.value);
}

function WisaInsertCollaborationBox() {
/* deactivation en attente de la mise au point du css */
return;
	var div = document.createElement("DIV");
	div.id = "wisa_collaboration_window";
	div.className = "wisa_collaboration_window";
	document.body.appendChild( div );

	var html = "";
	html += "<div id='ask_collaboration'>";
	html += "<div id='wisa_monitoring_callback'><input type='text' maxlength='10' id='callback' class='centrerVertical' name='callback'></div>";
	html += "<button onclick='asking_op();' class='centrerVertical' id='bouton_appel' type='button'>OK</button>";
	html += "</div>";
	html += "<div style='display:none' id='cancel_collaboration'>";
	html += "<div id='textecollaboattente'>Recherche d'un conseiller en cours</div>";
	html += "<img src='/fr/../images//attente-conseiller.gif' id='attente-conseiller' alt=''>";
	html += "<button onclick='WisaSetCollaborativeStateUserToServer(WISA_CS_OFF);' class='centrerVertical' id='bouton_cancel_appel' type='button'>Annuler</button>";
	html += "</div>";
	html += "<div style='display:none' id='terminate_collaboration'>";
	html += "<div id='textecollabo'>En collaboration</div>";
	html += "<div id='wisa_no_sync'>";
	html += "<button onclick='WisaSetCollaborativeStateUserToServer(WISA_CS_OFF);' id='bouton_terminate_collaboration' type='button'>Terminer</button>";
	html += "</div>";
	html += "</div>";

	div = Wisa$("wisa_collaboration_window");
	div.innerHTML = html;
}
	
function asking_op()
{
	var	phone = document.getElementById('callback');
	WisaSetCollaborativeStateUserToServer(WISA_CS_ASKING, phone.value );
}

function WisaCollaborativeStateCallback(state)
{
/* deactivation en attente de la mise au point du css */
return;
	state = parseInt(state);
	var div1 = document.getElementById('ask_collaboration');
	if (!div1) {return;}
	var div2 = document.getElementById('cancel_collaboration');
	if (!div2) {return;}
	var div3 = document.getElementById('terminate_collaboration');
	if (!div3) {return;}
	switch(state)
	{
		case WISA_CS_OFF:
		case WISA_CS_OBS:		div1.style.display = "";     div2.style.display = "none"; div3.style.display = "none"; break;
		case WISA_CS_ASKING:   	div1.style.display = "none"; div2.style.display = "";     div3.style.display = "none"; break;
		case WISA_CS_COL:		div1.style.display = "none"; div2.style.display = "none"; div3.style.display = "";     break;
	}
};

