// JavaScript Document
var chat;
var chatDiv = document.getElementById("chatnow");
var that1 = document.getElementById("Start");

// JS for the Chat function
            
testStatus = function() {
	if (chat.status === 'ready') {
		// show online chat button
		chatDiv.style.backgroundImage = 'url(/crforms/styleimages/chat/ChatOnline.png)';
		if( chatDiv.attachEvent ){
			chatDiv.attachEvent('onclick', cmdChat_onClick);
		} else {
			chatDiv.setAttribute('onclick', 'cmdChat_onClick()');
		}		
	} 
	else 	{
		chatDiv.style.backgroundImage = 'url(/crforms/styleimages/chat/ChatOffline.png)';

		if( chatDiv.attachEvent ){
			chatDiv.attachEvent('onmouseover', toggleover);
			chatDiv.attachEvent('onmouseout', toggleout);
		} else {
			chatDiv.setAttribute('onmouseover', 'toggleover()');
			chatDiv.setAttribute('onmouseout', 'toggleout()');
		}		
	}

};

toggleover = function () {
	if (that1) {
			that1.className = "DROPcontreqcontrolHighlight"; 
	}

	return false;
}

toggleout = function () {
	if (that1) {
			that1.className = "DROPcontreqcontrol";
	}

	return false;
}


cmdChat_onClick = function() {   
	chat.start({
		options: {
			window: {
			}
		}
	});
};

onReady = function(theSystem,theSite,theLogo,theCSS) {
	var logolocation = ''
	var csslocation = ''
	Wt.chat.PublicChat.crsChatSystem = theSystem;
	chat = Wt.chat.PublicChat;
	if (typeof(theLogo) !== 'undefined' && theLogo != '') { logolocation = 'https://pils0815.pepsico.com/crforms/styleimages/chat/'+theLogo; }
	if (typeof(theCSS) !== 'undefined' && theCSS != '') { csslocation = 'https://pils0815.pepsico.com/crforms/stylesheets/chat/'+theCSS; }
	
	chat.init ({
		msgUnavailable: "Sorry, chat is temporarily unavailable",
		site: theSite, 
		statusCallback: testStatus,
		startOptions: {
			window: {
				top: 100,
				left: 100,
				width: 400,
				height: 500,
				logoUrl: logolocation,
				cssUrl: csslocation,
				headerHtml: 'How may I help you?',
				title: 'Chat with a Live Representative! '
			}
			
		}
	});  
};


