﻿
function validateText(e)
{
    var arr = [16, 13, 8, 39, 37, 38, 40, 36, 35, 186, 188, 222, 190, 191, 46];
    for (var i = 0; i < arr.length; i++)
    {
        if (arr[i] == e.keyCode)
            return true;
    }
    var re = /[a-z]|\d|\s|\r|\n|\f/i;
    return re.test(String.fromCharCode(e.keyCode));
}

function tar_keyup(e)
{
    if (e.keyCode == 13)
        SendMessage();
}



function SendMessage()
{
    var msg = (arguments.length == 0 ? document.getElementById("tar").value : arguments[0]);
    //AppendMessage(msg, yourName, 0, true);
    //AdjustLastMessage();
	var adminid = "chris";
	//var cid = '<?php echo $cusID;?>';
	server_location = "http://www.usboxprinting.com/sendindiv.php";

    if (msg != "")
    {

        $.getJSON(server_location, { "RT": 1, "adminid": adminid, "cid": cid, "MSG": msg }, function (json) { AppendROFromServer(json); });
        document.getElementById("tar").value = "";
    }
}



function ClientShowChatWindow()
{
    ChangeWindowState(6);
    $("#dv_chat_win").show();
}


function ChangeWindowState(pState)
{
    if (pState == 1)
    {
        $("#tr_csr_list").hide();
        $("#tr_chat_messages").show();
        $("#tbl_blue_min, #tbl_yellow_min").hide();
        $("#tbl_chat_win").show();
        $("#div_chat_messages").css("height", "130px");
        $("#tr_ri_form").hide();
        $("#tr_send_bar").show();
    }
    else if (pState == 2)
    {
        $("#tr_csr_list").hide();
        $("#tr_chat_messages").show();
        $("#tbl_blue_min, #tbl_yellow_min").hide();
        $("#tbl_chat_win").show();
        $("#div_chat_messages").css("height", ($.browser.msie ? 132 : 145) + "px");
        $("#tr_ri_form").show();
        $("#tr_send_bar").show();
    }
    else if (pState == 3)
    {
        $("#tr_csr_list").show();
        $("#tr_chat_messages").hide();
        $("#tr_ri_form").hide();
        $("#tr_send_bar").hide();
    }
    else if (pState == 4)
    {
        $("#tbl_blue_min").show();
        $("#tbl_yellow_min").hide();
        $("#tbl_chat_win").hide();
    }
    else if (pState == 5)
    {
        $("#tbl_blue_min").hide();
        $("#tbl_yellow_min").show();
        $("#tbl_chat_win").hide();
    }
    else if (pState == 6)
    {
        $("#tbl_blue_min").hide();
        $("#tbl_yellow_min").hide();
        $("#tbl_chat_win").show();

        SetCookie("WinMin", "0");
        UpdateChatWindowMinimizeState(0);
    }

    if (pState == 4 || pState == 5)
    {
        SetCookie("WinMin", "1");
        UpdateChatWindowMinimizeState(1);
    }
    
    PositionChatWin();
}

function PositionChatWin()
{
    var win = $(window);

    var chat_win_height = $("#dv_chat_win").height();
    var chat_win_width = $("#dv_chat_win").width();

    var top = (win.height() + win.scrollTop()) - chat_win_height - 4;
    var left = (win.width() + win.scrollLeft()) - chat_win_width - 4;

    //top -= 170;

    setTimeout(function() { $("#dv_chat_win").css({ "top": top + "px", "left": left + "px" }); }, (arguments.length == 0 ? 100 : arguments[0]));
    //$("#dv_chat_win").animate({ "top": top + "px", "left": left + "px" }, "fast", "swing" );
}

function SetCookie(sName, sValue)
{
    document.cookie = sName + "=" + escape(sValue);
    var date = new Date();
    date.setMonth(date.getMonth() + 1);
    document.cookie += ("; expires=" + date.toUTCString());
}

function GetCookie(sName)
{
    var aCookie = document.cookie.split("; ");
    for (var i = 0; i < aCookie.length; i++)
    {
        var aCrumb = aCookie[i].split("=");
        if (sName == aCrumb[0])
            return unescape(aCrumb[1]);
    }
    return null;
}


function isBrowserClosed()

{

    var browserWindowWidth = 0;

    var browserWindowHeight = 0;

     

    // gets the width and height of the browser window

    if (parseInt(navigator.appVersion) > 3)

    {

        if (navigator.appName == "Netscape")

        {

            browserWindowWidth = window.innerWidth;

            browserWindowHeight = window.innerHeight;

        }

        if (navigator.appName.indexOf("Microsoft") !=- 1)

        {

            browserWindowWidth = top.window.document.body.offsetWidth;

            browserWindowHeight = top.window.document.body.offsetHeight;

        }

    }

     

    // checks if the X button was closed

    // if event.clientY < 0, then click was on the browser menu area

    // if event.screenX > (browserWindowWidth - 25), the X button was clicked

    // use screenX if working with multiple frames

    return (event.clientY < 0 && event.screenX > (browserWindowWidth - 25)) ? true : false;

}
