// Prog: Shawn Welch <shrimpwagon@yahoo.com>
// File: jquery.chat.js
// Vers: 2.0
// Purp: Operate Velaro live chat and popup element
$(document).ready(function(){
    chat_box = new Object();
    
    chat_box.timeoutID = setTimeout(function(){
        var saw_chat = $.readCookie('saw_chat');
        if (saw_chat == null) {
            popupChat();
        }
    }, 45000);
});

function doLiveHelp(form){
    popupChatHide();
    
    var lhWin = window.open('', 'LiveHelp', 'toolbar=no,location=no,directories=no,menubar=no,status=no,scrollbars=no,resizable=yes,replace=no,width=100,height=200');
    
    if (lhWin != null) {
        lhWin.focus();
        form.submit();
        
    }
    else {
        // in reality, this is never called. Almost all popup blockers work with this code.
        alert('Unable to launch Live Help Window, please disable all popup blockers and retry');
    }
}

function popupChat(){
    $('#chat-box').fadeIn('fast');
}

function popupChatNow() {
	popupChatMessage('<strong>TheSignChef</strong>: Hey there! How can I help you today?');
}

function popupChatMessage(message){
    $('#chat-message').html(message);
    popupChat();
}

function popupChatClick(){
    popupChat();
    clearTimeout(chat_box.timeoutID);
    $.createCookie('saw_chat', '1');
}

function popupChatHide(){
    $('#chat-box').fadeOut('fast');
    $.createCookie('saw_chat', '1');
}

function engageChat(question){
    $('#chat-question').text(question);
    doLiveHelp(document.getElementById('chat-form'));
}
