function restore_default(iter) {
    var def = document.getElementById('defmsg_' + iter)
    var area = document.getElementById('sysmsg_' + iter)

    area.value = def.innerHTML
}

function clear_default(iter) {
    var area = document.getElementById('sysmsg_' + iter)
    area.value = ''
}

function clear_all() {
    var count = document.getElementById('sysmsg_count').value
    var i = 1

    for (; i <= count; i++) {
        clear_default(i)
    }
}

function restore_all() {
    var count = document.getElementById('sysmsg_count').value
    var i = 1

    for (; i <= count; i++) {
        restore_default(i)
    }
}

function toggle_display(id) {
    var q = document.getElementById(id)

    q.style.display =
        (q.style.display == 'none' ? '' : 'none')
}


/*
    DOM INSPECTOR
*/
function bible(object, firstLetter) {
    if ( firstLetter == undefined ) firstLetter = '';
    var out = '';
    for ( var i in object ) {
        if ( firstLetter == '' || i.substr(0, 1) == firstLetter )
            out += i + ' = ' + object[i] + '\n';
    }
    if ( ( ta = document.getElementById('bible') ) == null ) {
        ta = document.createElement('textarea');
        ta.setAttribute('cols', 80);
        ta.setAttribute('rows', 25);
        ta.setAttribute('id', 'bible');
        document.body.appendChild(ta);
    }
    ta.value = out;
    //alert(out);
}


function toggle_all (my_list) {
    for (var c=0; c < my_list.elements.length; c++) {
        if (my_list.elements[c].type == 'checkbox') {
            if (my_list.elements[c].checked == true) {
                my_list.elements[c].checked = false;
            } else {
                my_list.elements[c].checked = true;
            }
        }
    }
    return false;
}
function checkmark_all (my_list,checkmarked) {
    for (var c=0; c < my_list.elements.length; c++) {
        if (my_list.elements[c].type == 'checkbox') {
            if (checkmarked.checked == true) {
                my_list.elements[c].checked = true;
            } else {
                my_list.elements[c].checked = false;
            }
        }
    }
    return false;
}
//-->
function NewWindow(mypage, myname, w, h, scroll, pos) {
    if ( pos == "random" ) {
        LeftPosition = ( screen.availWidth ) ? Math.floor(Math.random() * ( screen.availWidth - w ) ) : 50;
        TopPosition = ( screen.availHeight ) ? Math.floor(Math.random() * ( ( screen.availHeight - h ) - 75 ) ) : 50;
    }
    if ( pos == "center" ) {
        LeftPosition = ( screen.availWidth ) ? ( screen.availWidth - w ) / 2 : 50;
        TopPosition = ( screen.availHeight ) ? ( screen.availHeight - h ) / 2 : 50;
    }
    if ( pos == "default" ) {
        LeftPosition = 50;
        TopPosition = 50;
    }
    else if ( ( pos != "center" && pos != "random" && pos != "default" ) || pos == null ) {
        LeftPosition = 0;
        TopPosition = 20;
    }
    settings = 'width=' + w + ',height=' + h + ',top=' + TopPosition + ',left=' + LeftPosition + ',scrollbars=' + scroll + ',location=no,directories=no,status=yes,menubar=no,toolbar=no,resizable=no';
    win = window.open(mypage, myname, settings);
    if ( win.focus ) win.focus();
}

function CloseNewWin() {
    if ( win != null && win.open ) win.close();
}

function xml_to_array(node) {
    var ary = new Array();
    var i   = 0;

    while (node != null) {
        if (node.firstChild) {
            if (node.firstChild.data) {
                if (node.textContent)
                    ary[node.nodeName] = node.textContent;
                else
                    ary[node.nodeName] = node.firstChild.data;
            }
            else
                ary[i] = xml_to_array(node.firstChild);
        }
            
        node = node.nextSibling;
        i++;
    }

    return ary;
}
function xml_to_array_nest(node) {
    var ary = new Array();

    while (node != null) {
        if (node.firstChild) {
            // its either data or a list
            if (node.firstChild.data) {
                if (node.textContent)
                    ary[node.nodeName] = node.textContent;
                else
                    ary[node.nodeName] = node.firstChild.data;
            } else {
                if (!(node.nodeName in ary)) {
                    ary[node.nodeName] = new Array();
                    ary[node.nodeName].push(xml_to_array_nest(node.firstChild));
                } else {
                    ary[node.nodeName].push(xml_to_array_nest(node.firstChild));
                }
            }
        }
            
        node = node.nextSibling;
    }

    return ary;
}
/*
 * Return the named class for a line of conversation in a session
 * based on its integer message_class field.
 */

function message_class(id) {
    switch (id) {
        case 0:
            return "client";
        case 1:
            return "operator";
        case 2:
            return "system_message";
        default:
            return "";
    }
}

function real_unicode(message) {
    var mat;

    while ((mat = message.match(/&#([0-9]+);/))) {
        message = message.replace(new RegExp(mat[0]), String.fromCharCode(parseInt(mat[1], 10)));
    }

    return message;
}

function escape_unicode(message) {
    var out = "";
    var i;

    for (i = 0; i < message.length; i++) {
        if (message.charCodeAt(i) > 255)
            out += "&#" + message.charCodeAt(i) + ";";
        else
            out += message.charAt(i);
    }

    return out;
}

function split_unicode(message) {
    var out = "";
    var i;

    for (i = 0; i < message.length; i++) {
        out += String.fromCharCode((message.charCodeAt(i) >> 8) & 255);
        out += String.fromCharCode((message.charCodeAt(i) >> 0) & 255);
    }

    return out;
}

function join_into_unicode(message) {
    var out = "";
    var i;

    // If this isn't a multiple of two, there's no way it's a string
    // that we split up before.

    if ((message.length % 2) != 0)
        return message;

    for (i = 0; i < message.length; i += 2) {
        out += String.fromCharCode((message.charCodeAt(i) << 8) | (message.charCodeAt(i+1) & 255));
    }

    return out;
}

// From RFC 2045 (http://tools.ietf.org/html/2045), page 24

var base64_dec = {
    'A':  0, 'B':  1, 'C':  2, 'D':  3, 'E':  4, 'F':  5, 'G':  6, 'H':  7,
    'I':  8, 'J':  9, 'K': 10, 'L': 11, 'M': 12, 'N': 13, 'O': 14, 'P': 15,
    'Q': 16, 'R': 17, 'S': 18, 'T': 19, 'U': 20, 'V': 21, 'W': 22, 'X': 23,
    'Y': 24, 'Z': 25, 'a': 26, 'b': 27, 'c': 28, 'd': 29, 'e': 30, 'f': 31,
    'g': 32, 'h': 33, 'i': 34, 'j': 35, 'k': 36, 'l': 37, 'm': 38, 'n': 39,
    'o': 40, 'p': 41, 'q': 42, 'r': 43, 's': 44, 't': 45, 'u': 46, 'v': 47,
    'w': 48, 'x': 49, 'y': 50, 'z': 51, '0': 52, '1': 53, '2': 54, '3': 55,
    '4': 56, '5': 57, '6': 58, '7': 59, '8': 60, '9': 61, '-': 62, '!': 63,
    '=': 0
};

var base64_enc = {
     0: 'A',  1: 'B',  2: 'C',  3: 'D',  4: 'E',  5: 'F',  6: 'G',  7: 'H',
     8: 'I',  9: 'J', 10: 'K', 11: 'L', 12: 'M', 13: 'N', 14: 'O', 15: 'P',
    16: 'Q', 17: 'R', 18: 'S', 19: 'T', 20: 'U', 21: 'V', 22: 'W', 23: 'X',
    24: 'Y', 25: 'Z', 26: 'a', 27: 'b', 28: 'c', 29: 'd', 30: 'e', 31: 'f',
    32: 'g', 33: 'h', 34: 'i', 35: 'j', 36: 'k', 37: 'l', 38: 'm', 39: 'n',
    40: 'o', 41: 'p', 42: 'q', 43: 'r', 44: 's', 45: 't', 46: 'u', 47: 'v',
    48: 'w', 49: 'x', 50: 'y', 51: 'z', 52: '0', 53: '1', 54: '2', 55: '3',
    56: '4', 57: '5', 58: '6', 59: '7', 60: '8', 61: '9', 62: '-', 63: '!'
};

function base64_elshift(m, i, sh) {
    return (m.charCodeAt(i) << sh) & 63;
}

function base64_ershift(m, i, sh) {
    return (m.charCodeAt(i) >> sh) & 63;
}

// Base-64 encode a string, essentially by taking a 3-character block
// and turning it into a 4-character block using the base-64 alphabet.
// If less than 3 characters exist in the last block, the equal sign is
// used as padding (2 equal signs if only 1 character, 1 equal sign if 2
// characters).



function base64_encode(message) {
    var out = "";
    var buf0;
    var buf1;
    var buf2;
    var buf3;
    var i;

    message = escape_unicode(message);

    for (i = 0; i < message.length; i += 3) {
        buf0 = base64_enc[base64_ershift(message, i+0, 2)];
        buf2 = "_";
        buf3 = "_";

        if ((i+1) < message.length)
            buf1 = base64_enc[base64_elshift(message, i+0, 4) | base64_ershift(message, i+1, 4)];
        else
            buf1 = base64_enc[base64_elshift(message, i+0, 4)];

        if ((i+2) < message.length) {
            buf2 = base64_enc[base64_elshift(message, i+1, 2) | base64_ershift(message, i+2, 6)];
            buf3 = base64_enc[base64_elshift(message, i+2, 0)];
        } else if ((i+1) < message.length)
            buf2 = base64_enc[base64_elshift(message, i+1, 2)];

        out += buf0 + buf1 + buf2 + buf3;
    }

    return out;
}

function base64_dlshift(c, sh) {
    return (base64_dec[c] << sh) & 255;
}

function base64_drshift(c, sh) {
    return (base64_dec[c] >> sh) & 255;
}

function base64_decode(message) {
    var out = "";
    var i;

    // All base-64 blocks are multiples of four characters.  Try it:
    // encode a one-letter string.  You'll get four characters
    // in return.  If that's not the case with this message, then it's
    // not really base-64 encoded (or not encoded correctly).

    if ((message.length % 4) != 0)
        return message;

    // Each block of four encoded characters can be decoded to, at most,
    // three unencoded ones.  (Which makes sense: 4 * 6bits = 24bits,
    // and 3 * 8bits = 24bits.)  The bits in base-64 are encoded
    // left-to-right, that is, starting with the high-order bit and
    // moving to the low-order bit.  Each number we consider has a bit
    // mask of 255 applied, so only (low-order) 8 bits are considered at
    // any given moment.

    // The equal sign is considered "padding" in an encoded string, but
    // they also represent the end marker.  A block of four bytes with
    // two equal signs on the end is a signal that only one character is
    // encoded; with one equal sign, two characters encoded.  No equal
    // sign is necessary if the initial string's length was a multiple
    // of 3.

    for (i = 0; i < message.length; i += 4) {
        out += String.fromCharCode(base64_dlshift(message.charAt(i+0), 2) | base64_drshift(message.charAt(i+1), 4)); if (message.charAt(i+2) == '_') break;
        out += String.fromCharCode(base64_dlshift(message.charAt(i+1), 4) | base64_drshift(message.charAt(i+2), 2)); if (message.charAt(i+3) == '_') break;
        out += String.fromCharCode(base64_dlshift(message.charAt(i+2), 6) | base64_drshift(message.charAt(i+3), 0));
    }
    
    return out;
}

/* cpaint escapes ampersands, angle brackets, and all non-printables... */

function remove_unicode(message) {
    if (message == "" || message == null || message == undefined || message == 0)
        return "";

    message = base64_decode(message);
    
    message = message.replace(/\\u0026/g, '&');
    message = message.replace(/\\u003c\?/g, '&lt;?');   /* <? */
    message = message.replace(/\?\\u003e/g, '?&gt;');   /* ?> */
    message = message.replace(/\\u003c[ \t\r\n]*script/gi, '&lt;script');
    message = message.replace(/\\u003c[ \t\r\n]*\/[ \t\r\n]*script/gi, '&lt;/script');
    message = message.replace(/\\u003c/g, '<');
    message = message.replace(/\\u003e/g, '>');
    message = message.replace(/\\u000a/g, ' ');

    message = message.replace(/<!--c(#[0-9A-Fa-f]+)-->(.*)/, '<span style="color: $1">$2</span>');

    return message;
}

/*
 * This returns the actual data contained in the given named tag.
 * If there are several tags with that name, only the first one will
 * have its data returned.
 */

function cpaint_node(res, name) {
    var col;

    col = res.getElementsByTagName(name);

    if (col.length < 1 || col[0].firstChild == null)
        return "";
    else {
        if (col[0].textContent)
            return col[0].textContent;
        else
            return col[0].firstChild.data;
    }
}
/*
 * Cross-browser attempt at supporting the regular function,
 * document.getElementById().  That function is a DOM-2 level function,
 * which is something that IE -- even at version 6 -- does not yet fully
 * support.
 */

function get_id(id) {
    if (document.getElementById)
        return document.getElementById(id);
    else
        return document.all[id];        /* probably IE */
}

/*
 * Apparently, IE does not support the (somewhat useful) indexOf method,
 * which returns the index of a given value in an array.  So we've got
 * to reinvent the wheel here.
 *
 * NOTE: this function won't work for an array where the index could be
 * a string (or for an object with properties, which is essentially the
 * same thing).  In fact, it's probably not a good idea even for an
 * array where string and numeric indices are mixed.
 */

function index_of(ary, val) {
    var i;

    for (i = 0; i < ary.length; i++) {
        if (ary[i] == val)
            return i;
    }

    return -1;
}

function run_command(type, param) {
    switch (type) {
        case 'push_url':
            window.open(param, "_blank");
            break;
        default:
            break;
    }
}
// b64.js

var ac_b64_dec = {
    'A':  0, 'B':  1, 'C':  2, 'D':  3, 'E':  4, 'F':  5, 'G':  6, 'H':  7,
    'I':  8, 'J':  9, 'K': 10, 'L': 11, 'M': 12, 'N': 13, 'O': 14, 'P': 15,
    'Q': 16, 'R': 17, 'S': 18, 'T': 19, 'U': 20, 'V': 21, 'W': 22, 'X': 23,
    'Y': 24, 'Z': 25, 'a': 26, 'b': 27, 'c': 28, 'd': 29, 'e': 30, 'f': 31,
    'g': 32, 'h': 33, 'i': 34, 'j': 35, 'k': 36, 'l': 37, 'm': 38, 'n': 39,
    'o': 40, 'p': 41, 'q': 42, 'r': 43, 's': 44, 't': 45, 'u': 46, 'v': 47,
    'w': 48, 'x': 49, 'y': 50, 'z': 51, '0': 52, '1': 53, '2': 54, '3': 55,
    '4': 56, '5': 57, '6': 58, '7': 59, '8': 60, '9': 61, '-': 62, '!': 63,
    '=': 0
};

var ac_b64_enc = {
     0: 'A',  1: 'B',  2: 'C',  3: 'D',  4: 'E',  5: 'F',  6: 'G',  7: 'H',
     8: 'I',  9: 'J', 10: 'K', 11: 'L', 12: 'M', 13: 'N', 14: 'O', 15: 'P',
    16: 'Q', 17: 'R', 18: 'S', 19: 'T', 20: 'U', 21: 'V', 22: 'W', 23: 'X',
    24: 'Y', 25: 'Z', 26: 'a', 27: 'b', 28: 'c', 29: 'd', 30: 'e', 31: 'f',
    32: 'g', 33: 'h', 34: 'i', 35: 'j', 36: 'k', 37: 'l', 38: 'm', 39: 'n',
    40: 'o', 41: 'p', 42: 'q', 43: 'r', 44: 's', 45: 't', 46: 'u', 47: 'v',
    48: 'w', 49: 'x', 50: 'y', 51: 'z', 52: '0', 53: '1', 54: '2', 55: '3',
    56: '4', 57: '5', 58: '6', 59: '7', 60: '8', 61: '9', 62: '-', 63: '!'
};

function ac_b64_elshift(m, i, sh) {
    return (m.charCodeAt(i) << sh) & 63;
}

function ac_b64_ershift(m, i, sh) {
    return (m.charCodeAt(i) >> sh) & 63;
}

// Base-64 encode a string, essentially by taking a 3-character block
// and turning it into a 4-character block using the base-64 alphabet.
// If less than 3 characters exist in the last block, the equal sign is
// used as padding (2 equal signs if only 1 character, 1 equal sign if 2
// characters).

function ac_b64_encode(message) {
    var out = "";
    var buf0;
    var buf1;
    var buf2;
    var buf3;
    var i;

    for (i = 0; i < message.length; i += 3) {
        buf0 = ac_b64_enc[ac_b64_ershift(message, i+0, 2)];
        buf2 = "_";
        buf3 = "_";

        if ((i+1) < message.length)
            buf1 = ac_b64_enc[ac_b64_elshift(message, i+0, 4) | ac_b64_ershift(message, i+1, 4)];
        else
            buf1 = ac_b64_enc[ac_b64_elshift(message, i+0, 4)];

        if ((i+2) < message.length) {
            buf2 = ac_b64_enc[ac_b64_elshift(message, i+1, 2) | ac_b64_ershift(message, i+2, 6)];
            buf3 = ac_b64_enc[ac_b64_elshift(message, i+2, 0)];
        } else if ((i+1) < message.length)
            buf2 = ac_b64_enc[ac_b64_elshift(message, i+1, 2)];

        out += buf0 + buf1 + buf2 + buf3;
    }

    return out;
}

function ac_b64_dlshift(c, sh) {
    return (ac_b64_dec[c] << sh) & 255;
}

function ac_b64_drshift(c, sh) {
    return (ac_b64_dec[c] >> sh) & 255;
}

function ac_b64_decode(message) {
    var out = "";
    var i;

    // All base-64 blocks are multiples of four characters.  Try it:
    // encode a one-letter string.  You'll get four characters
    // in return.  If that's not the case with this message, then it's
    // not really base-64 encoded (or not encoded correctly).

    if ((message.length % 4) != 0)
        return message;

    // Each block of four encoded characters can be decoded to, at most,
    // three unencoded ones.  (Which makes sense: 4 * 6bits = 24bits,
    // and 3 * 8bits = 24bits.)  The bits in base-64 are encoded
    // left-to-right, that is, starting with the high-order bit and
    // moving to the low-order bit.  Each number we consider has a bit
    // mask of 255 applied, so only (low-order) 8 bits are considered at
    // any given moment.

    // The equal sign is considered "padding" in an encoded string, but
    // they also represent the end marker.  A block of four bytes with
    // two equal signs on the end is a signal that only one character is
    // encoded; with one equal sign, two characters encoded.  No equal
    // sign is necessary if the initial string's length was a multiple
    // of 3.

    for (i = 0; i < message.length; i += 4) {
        out += String.fromCharCode(ac_b64_dlshift(message.charAt(i+0), 2) | ac_b64_drshift(message.charAt(i+1), 4)); if (message.charAt(i+2) == '_') break;
        out += String.fromCharCode(ac_b64_dlshift(message.charAt(i+1), 4) | ac_b64_drshift(message.charAt(i+2), 2)); if (message.charAt(i+3) == '_') break;
        out += String.fromCharCode(ac_b64_dlshift(message.charAt(i+2), 6) | ac_b64_drshift(message.charAt(i+3), 0));
    }
    
    return out;
}

// variables loaded from integration:
//var type = 'text'; // 'image','text' or 'tracking'
var online_text = '<div id=\"frameContainer\"><h2><img title=\"Information\" alt=\"Information\" src=\"/vgnmedia/images/Personal_Finance/question.gif\" border=\"0\" mediaid=\"71682\" />Need Help?</h2><p id=\"textCopy\">A NAB Home Loan Specialist is online now to assist you with your application.</p><a title=\"Click to chat\" href=\"javascript:globalWindowOpen(\'https://www.clicktolivechat.com/index.php?action=chat_select&code=952f0f&dept=2&nopost=1\',\'chat\',530,580,1,0,0,1,1,0,0,0,0)\" onclick=\"javascript:dcsMultiTrack(\'DCS.dcsuri\',\'User initiated click to chat - chat online\',\'DCS.dcssip\',\'nab.com.au\',\'WT.ti\',\'User initiated click to chat - chat online\');\">   <img title=\"Chat Online\" alt=\"Chat online\" src=\"/vgnmedia/images/Personal_Finance/chat.gif\" border=\"0\" /></a></div>'; 
var offline_text = ''; 
//var invite_id = '1'; 
//var invite_initiate = '5'; 
//var invite_hide = '10'; 

var href = "";
var traffic_id = 0;

var do_not_disturb = 0;
var operators_are_online = 0;
var browser_info_img = new Image();


var do_auto_invite = '0';
var dept  = '2';
var code  = '952f0f';
var type = 'text';
var plink = 'https://www.clicktolivechat.com';
var details = '19';
var initial_dept = '2';
var traffic_id = '3';
var invite_href = plink + "/index.php?action=chat_select&code=952f0f&dept=2&nopost=1";
var default_name = '';
var default_question = '';
var online_offline_interval = '30';
var invite_interval = '10000';
var opt_nopost = '1';

//http://clicktolivechat.com/index.php?action=chat_select&code=952f0f&dept=2&nopost=1

var styles = new Array();

styles[1] = new Array();
styles[1]['accept_isimage'] = 1;
styles[1]['reject_isimage'] = 1;
styles[1]['hpixels'] = '150';
styles[1]['vpixels'] = '150';
styles[1]['hposition'] = 'left';
styles[1]['vposition'] = 'top';

var online_offline_img = new Image();
online_offline_img.onload = function() { 
    if (online_offline_img.width == '1') { // 1 = online, 2 = offline
        operators_are_online = 1;
		dcsMultiTrack('DCS.dcsuri','User initiated click to chat - displayed','DCS.dcssip','nab.com.au','WT.ti','User initiated click to chat - displayed');
        get_id('online_offline').innerHTML = online_text;        
    } else {
        operators_are_online = 0;
        get_id('online_offline').innerHTML = offline_text;
    }
};


var invitation_img = new Image();
invitation_img.onload = function() { 
    if (invitation_img.width == '1') { // 1 = yes, 2 = no, 3 = do not disturb (visitor is in chat)
        do_not_disturb = 0; 
        do_invitation();
    } else if (invitation_img.width == '2') {
        do_not_disturb = 0; 
    } else if (invitation_img.width == '3') {
        do_not_disturb = 1;
    }
};

browser_info_img.src = plink + '/image_utility.php?mode=browser_info&details_id=' + details + '&width='+screen.width
    +'&height='+screen.height+'&page='+escape(document.location.href)+'&referer='+escape(document.referrer)+'&title='+escape(document.title)+'&dept='+dept;


	    document.write('<span id="online_offline"></span>');
	


// This portion below is not our code...

/***********************************************
* Floating Top Bar script- © Dynamic Drive (www.dynamicdrive.com)
* Sliding routine by Roy Whittle (http://www.javascript-fx.com/)
* This notice must stay intact for legal use.
* Visit http://www.dynamicdrive.com/ for full source code
***********************************************/

var persistclose=0 //set to 0 or 1. 1 means once the bar is manually closed, it will remain closed for browser session
var startX = 30 //set x offset of bar in pixels
var startY = 5 //set y offset of bar in pixels
var verticalpos="fromtop" //enter "fromtop" or "frombottom"

function iecompattest(){
    return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}

function get_cookie(Name) {
    var search = Name + "=";
    var returnvalue = "";
    if (document.cookie.length > 0) {
        offset = document.cookie.indexOf(search);
        if (offset != -1) {
            offset += search.length;
            end = document.cookie.indexOf(";", offset);
            if (end == -1)
                end = document.cookie.length;
            returnvalue = unescape(document.cookie.substring(offset, end));
        }
    }
    return returnvalue;
}

function closebar(){
    if (persistclose)
        document.cookie="remainclosed=1";
    document.getElementById("invite_popup").style.visibility="hidden";
}

function staticbar(){
    barheight=document.getElementById("invite_popup").offsetHeight;
    var ns = (navigator.appName.indexOf("Netscape") != -1) || window.opera;
    var d = document;
    function ml(id){
        var el=d.getElementById(id);
        if (!persistclose || persistclose && get_cookie("remainclosed")=="")
            el.style.visibility="visible";
        if(d.layers)el.style=el;
        el.sP=function(x,y){this.style.left=x+"px";this.style.top=y+"px";};
        el.x = startX;
        if (verticalpos=="fromtop")
            el.y = startY;
        else{
            el.y = ns ? pageYOffset + innerHeight : iecompattest().scrollTop + iecompattest().clientHeight;
            el.y -= startY;
        }
        return el;
    }
    window.stayTopLeft=function(){
        if (verticalpos=="fromtop"){
            var pY = ns ? pageYOffset : iecompattest().scrollTop;
            ftlObj.y += (pY + startY - ftlObj.y)/8;
        }
        else{
            var pY = ns ? pageYOffset + innerHeight - barheight: iecompattest().scrollTop + iecompattest().clientHeight - barheight;
            ftlObj.y += (pY - startY - ftlObj.y)/8;
        }
        ftlObj.sP(ftlObj.x, ftlObj.y);
        setTimeout("stayTopLeft()", 10);
    }
    ftlObj = ml("invite_popup");
    stayTopLeft();
}

function get_defaults(use_message, invited) {
    var extra = "";

    if (default_name != '')
        extra = extra + "&name=" + default_name;
    else if (invited)
        extra = extra + "&name=" + ac_b64_encode("Auto-Invite");

    if (default_question != '') {
        if (use_message)
            extra = extra + "&message=" + default_question;
        else
            extra = extra + "&question_box=" + default_question;
    }

    return extra;
}

// The rest of our code continues from here.

function open_chat_window () {
    window.open(plink + '/index.php?action=chat_select&code=' + code + '&dept=' + initial_dept + get_defaults(false, false),'acp_livechat','height=550,width=500, toolbar=no,directories=no,status=no,menubar=no, scrollbars=yes,resizable=yes');
   return false;   
}
function do_invitation() {
    var invite_src = plink + '/image_utility.php?mode=invitation_style_id&anti_cache='+no_cache_integer();
    img_1.src = invite_src + '&digit=1';
    img_2.src = invite_src + '&digit=2';
    img_3.src = invite_src + '&digit=3';
    img_4.src = invite_src + '&digit=4';
    img_5.src = invite_src + '&digit=5';
    img_6.src = invite_src + '&digit=6';
    img_7.src = invite_src + '&digit=7';
    img_8.src = invite_src + '&digit=8';
    img_9.src = invite_src + '&digit=9';
    img_10.src = invite_src + '&digit=10';
    //document.body.innerHTML += img_1.src+'*'+invitation_img.width+'<br>';
    // what actually happens when these images are loaded takes place in the image.onload handler
}
function get_online_offline() {
    online_offline_img.src = plink + '/image_utility.php?mode=online_offline&code=' + code + '&dept=' + dept + '&anti_cache='+no_cache_integer();
    //document.body.innerHTML += online_offline_img.src+'*'+online_offline_img.width+'<br>';

    try {
        if (check_back == 1)
            window.setTimeout('get_online_offline()', online_offline_interval * 1000);
    } catch (e) {
        window.setTimeout('get_online_offline()', online_offline_interval * 1000);
    }
}
function check_for_invitation() {
    invitation_img.src = plink + '/image_utility.php?mode=invitation_check&traffic_id=' + traffic_id + '&anti_cache='+no_cache_integer();
    //document.body.innerHTML += invitation_img.src+'*'+invitation_img.width+'<br>';
    window.setTimeout('check_for_invitation()', invite_interval * 1000);
}

function no_cache_integer () {
    var d = new Date();
    return d.getTime();
}
function popup_info(style_id) {
    var acp = get_id('accept_div');
    var rjt = get_id('reject_div');
    var box = get_id('invite_popup');
    
    if (!style_id) {
        try {
            style_id = invite_id;
        } catch (e) {
            style_id = 1;
        }
    } 
    if (styles[style_id] && !do_not_disturb) {
        acp.innerHTML = '';
        if (styles[style_id].accept_isimage == 1) {
            acp.innerHTML = "<img src='" + plink + "/image.php?mood=accept&image=" + style_id + "' alt='Accept' style='cursor:pointer;'>";
        } else {
            acp.innerHTML = styles[style_id].accept_html;
        }
        rjt.innerHTML = '';
        if (styles[style_id].reject_isimage == 1) {
            rjt.innerHTML = "<img src='" + plink + "/image.php?mood=reject&image=" + style_id + "' alt='Reject' style='cursor:pointer;'>";
        } else {
            rjt.innerHTML = styles[style_id].reject_html;
        }
    
        box.style.position = 'absolute';
        
        switch (styles[style_id].hposition) {
            default:        // FALLTHRU
            case 'left':
                startX = parseInt(styles[style_id].hpixels, 10);
                //box.style.left = styles[style_id].hpixels + "px";
                break;
            case 'right':
                startX = parseInt(styles[style_id].hpixels, 10);
                //box.style.right = styles[style_id].hpixels + "px";
                break;
        }
    
        switch (styles[style_id].vposition) {
            default:        // FALLTHRU
            case 'top':
                startY = parseInt(styles[style_id].vpixels, 10);
                //box.style.top = styles[style_id].vpixels;
                break;
            case 'bottom':
                startY = parseInt(styles[style_id].vpixels, 10);
                //box.style.bottom = styles[style_id].vpixels;
                break;
        }
    
        staticbar();
        box.style.display = 'block';
    
        try {
            if (invite_hide > 0)
                window.setTimeout('hide_invite_popup()', invite_hide * 1000);
        } catch (e) {}
    }
}
function hide_invite_popup () {
    get_id("invite_popup").style.display = "none"; 
    get_id("accept_div").innerHTML = ' '; 
    get_id("reject_div").innerHTML = ' ';
}
function auto_invite() {
    if (do_auto_invite == 1) {
        try {
            popup_info(invite_id);
        } catch (e) {
            popup_info(1);
        }
    }
}

// We have to create our (potential) popup-invite div.

var div = document.createElement("div");

div.style.display = 'none';
div.style.margin = '5px';
div.id = 'invite_popup';

var accept_div = document.createElement("div");
var reject_div = document.createElement("div");
var accept_div_img = new Image();

accept_div.id = "accept_div";
reject_div.id = "reject_div";

accept_div.onclick = function() {
    if (invite_href != "")
        window.open(invite_href + get_defaults(true, true), "Chat", "height=625,width=500,toolbar=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no");

    div.style.display = 'none';
    accept_div_img.src = plink + '/image_utility.php?mode=accept_reject_div&traffic_id=' + traffic_id + '&result=1';
    //document.body.innerHTML += accept_div_img.src+'*'+accept_div_img.width+'<br>';
}

reject_div.onclick = function() {
    div.style.display = 'none';
    accept_div_img.src = plink + '/image_utility.php?mode=accept_reject_div&traffic_id=' + traffic_id + '&result=0';
    closebar();
    //document.body.innerHTML += accept_div_img.src+'*'+accept_div_img.width+'<br>';
}

div.appendChild(accept_div);
div.appendChild(reject_div);

//document.write(div.innerHTML);
document.write('<div id="acp_int_div"></div>');
get_id("acp_int_div").appendChild(div);

//////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////
var is_loaded_1 = 0;
var is_loaded_2 = 0;
var is_loaded_3 = 0;
var is_loaded_4 = 0;
var is_loaded_5 = 0;
var is_loaded_6 = 0;
var is_loaded_7 = 0;
var is_loaded_8 = 0;
var is_loaded_9 = 0;
var is_loaded_10 = 0;

var value_1 = 0;
var value_2 = 0;
var value_3 = 0;
var value_4 = 0;
var value_5 = 0;
var value_6 = 0;
var value_7 = 0;
var value_8 = 0;
var value_9 = 0;
var value_10 = 0;

var img_1 = new Image();
var img_2 = new Image();
var img_3 = new Image();
var img_4 = new Image();
var img_5 = new Image();
var img_6 = new Image();
var img_7 = new Image();
var img_8 = new Image();
var img_9 = new Image();
var img_10 = new Image();

img_1.onload = function() { 
    is_loaded_1 = 1;
    if (img_1.width == 10) { value_1 = 0; } else { value_1 = img_1.width; }
    do_event ();
};  
img_2.onload = function() { 
    is_loaded_2 = 1;
    if (img_2.width == 10) { value_2 = 0; } else { value_2 = img_2.width; }
    do_event ();
};  
img_3.onload = function() { 
    is_loaded_3 = 1;
    if (img_3.width == 10) { value_3 = 0; } else { value_3 = img_3.width; }
    do_event ();
};  
img_4.onload = function() { 
    is_loaded_4 = 1;
    if (img_4.width == 10) { value_4 = 0; } else { value_4 = img_4.width; }
    do_event ();
};  
img_5.onload = function() { 
    is_loaded_5 = 1;
    if (img_5.width == 10) { value_5 = 0; } else { value_5 = img_5.width; }
    do_event ();
};  
img_6.onload = function() { 
    is_loaded_6 = 1;
    if (img_6.width == 10) { value_6 = 0; } else { value_6 = img_6.width; }
    do_event ();
};  
img_7.onload = function() { 
    is_loaded_7 = 1;
    if (img_7.width == 10) { value_7 = 0; } else { value_7 = img_7.width; }
    do_event ();
};  
img_8.onload = function() { 
    is_loaded_8 = 1;
    if (img_8.width == 10) { value_8 = 0; } else { value_8 = img_8.width; }
    do_event ();
};  
img_9.onload = function() { 
    is_loaded_9 = 1;
    if (img_9.width == 10) { value_9 = 0; } else { value_9 = img_9.width; }
    do_event ();
};  
img_10.onload = function() { 
    is_loaded_10 = 1;
    if (img_10.width == 10) { value_10 = 0; } else { value_10 = img_10.width; }
    do_event ();
};  
function do_event() {
    if (is_loaded_1 && is_loaded_2 && is_loaded_3 && is_loaded_4 && is_loaded_5 && is_loaded_6 && is_loaded_7 && is_loaded_8 && is_loaded_9 && is_loaded_10) {
        var this_style_id = parseInt(''+value_1+value_2+value_3+value_4+value_5+value_6+value_7+value_8+value_9+value_10, 10);
        //document.body.innerHTML += 'style_id='+this_style_id+'<br>';
        popup_info(this_style_id);  
    } 
}   
function reset_loaded () {
    is_loaded_1 = 0;
    is_loaded_2 = 0;
    is_loaded_3 = 0;
    is_loaded_4 = 0;
    is_loaded_5 = 0;
    is_loaded_6 = 0;
    is_loaded_7 = 0;
    is_loaded_8 = 0;
    is_loaded_9 = 0;
    is_loaded_10 = 0;
}

//////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////
try {
    if (invite_initiate > 0) {
        window.setTimeout('auto_invite()', invite_initiate * 1000);
    }
} catch (e) {       // do nothing
}

get_online_offline();
check_for_invitation();

