// JavaScript Document for Chat
function loadInstantChat(sessionType)
	{
	// Show Instant Chat
	document.getElementById("InstantChatDiv").style.display = "";
	
	// Hide Channel form
	document.getElementById("ChannelForm").style.display = "none";

	// Hide PIN Code form
	document.getElementById("PinForm").style.display = "none";
		
	// Hide Language dropdown
	document.getElementById("LanguageForm").style.display = "none";

	var ICLoader = new RescueInstantChatLoader();
	ICLoader.ICContainer = "InstantChatDiv";
	ICLoader.HostedCSS = "http://YourSite/yourstylesheet.css";
	
	// sessionType == 0, we are after REBOOT
	// Channel session
	if (sessionType == 1)
		ICLoader.EntryID = "123456789";
	// Private Session
	if (sessionType == 2)
	{
		var pin = document.getElementById("inputPinCode").value;
		if ((pin.length != 6) || isNaN(pin))
		{
			handleError("Private code should be a 6-digit number!");
			return;
		}
		else
			ICLoader.PrivateCode = document.getElementById("inputPinCode").value;
	}
	ICLoader.Name = document.getElementById("inputYourName").value;
	ICLoader.Comment1 = document.getElementById("inputEmailAddress").value;
	ICLoader.Comment2 = document.getElementById("inputPhoneNumber").value;
	ICLoader.Comment3 = document.getElementById("inputCompanyName").value; 
	ICLoader.Comment4 = document.getElementById("inputLocation").value; 
	ICLoader.Comment5 = document.getElementById("inputComment").value; ICLoader.Tracking0 = "TestForm01";
	ICLoader.Language = document.getElementById("inputLanguageSelect").value; 
		
	// Error + No Technician available notification handling 
	ICLoader.HostedErrorHandler = function(ErrorName) 
	{
		switch(ErrorName) 
		{
			case "NOTECHAVAILABLE":	handleError("Currently no technicians are available. Please check back later."); break;
			case "NOTECHWORKING":	handleError("Sorry, we're closed. No Technicians are available at this time. Please check back later during our hours of operation."); break;
			case "INVALID_PARAMETERS":	handleError("Invalid parameters supplied. Please contact your support provider."); break;
			case "SESSIONALREADYSTARTED": handleError("A session using this PIN Code has already been started. Please ask your support provider for a new PIN Code."); break;
			case "UCONNECTIONERROR":	handleError("Unknown connection error occured."); break;
			case "ERRNOSUCHSSESSION":	handleError("The support session cannot be started."); break;
			case "ERRNOSUCHENTRY":	handleError("The online support session cannot be started. Please contact your support provider directly."); break;
			case "ERRCODEDOESNOTEXIST":	handleError("PIN Code does not exist. Please contact your support provider."); break;
			case "ERRCODEEXPIRED":	handleError("PIN Code has expired. Please contact your support provider."); break;
			case "ERRNOTEXPIRED":	handleError("Technician or company does not exist. Please contact your support provider."); break;
			case "ERRMISSINGTECHLICENSE": handleError("The support session cannot be started. The technician is not configured to support this type of device."); break;
		} 
		ICLoader.Start();
	}
} 
	
// Start automatically Instant Chat after REBOOT 
function handleRebootOrRefresh() 
{
	if ((window.location + "").indexOf("rescuewebsessionid") != -1) 
		loadInstantChat(0);
	if (window.location.hash.length == webSessionIdLength + 1) 
		loadInstantChat(0);
} 

// Show error messages 
function handleError(ErrorDescription) 
{
	// Hide Instant Chat 
	document.getElementById("InstantChatDiv").style.display = "none"; 
	// Show ErrorForm 
	var ef = document.getElementById("ErrorForm"); 
	ErrorForm.style.display = ""; 
	ErrorForm.innerHTML = ErrorDescription;
} 