﻿var urlp = window.location + '', urlLoad = 'http://www.each.co.uk/alert/async.aspx', _gNid = 0; _gDid = 0; _gBid = 0; _gCid = 0;
var jsCriteria, JSON, IS = 3, STAY = 0, htm = '', Criteria, atmpO = new Array(), itmpO = 0, ckDate = new Date(), expires = new Date(ckDate.getFullYear() + 1, ckDate.getMonth(), ckDate.getDate());
var aCount, aIS, propreq = new Array(), propreqs = new Array(), TreeC = new Array();
propreq['p'] = 'Property'; propreq['r'] = 'Requirement'; propreqs['p'] = 'Properties'; propreqs['r'] = 'Requirements';
propreqs['pf'] = 'Favourite Properties'; propreqs['rf'] = 'Favourite Requirements';
propreqs['pc'] = 'Commented Properties'; propreqs['rc'] = 'Commented Requirements';
var XY = { "option": "<option value='I'>N</option>", "PicCol": new Array("900", "009", "090")
, Pic: "<div class=Pics name=PIC><table cellspacing=0 cellpadding=0><tr><td><span name=PIC title='click to view original image\'s size' class=V>View</span><span class=S>Size</span><span class=E>Replace</span><span name=PIC  title='click to delete the image' class=D>Delete</span></td><tr><td><img name=PIC /></td></tr><tr><td class=Is name=PIC name2=xNAME>front image</td></tr></table></div>"
, File: '<tr name="xF" class="files" style="height:9px"><td style="padding-left:2px"><img src="http://www.each.co.uk/JSON/images/attachments/X1.png" /></td><td style="width:150px">x1</td><td align=right style="width:90px">xSize</td><td align=center>xDate</td><td style="width:75px"><input  class=details onclick="this.select()" name="xF" value="Details" />&nbsp;</td><td align=right><span title="click to delete attachment" name="xF" class="Delete">Delete</span></td></tr>'
, Close: 1, hCalendar: "", firstMatchITI: "", FileHeader: '<tr style="color:#77f;height:9px;font-weight:bold"><td colspan=2 style="width:150px">Current files</td><td>Size</td><td align=center>Date</td><td align=center>Display&nbsp;Title</td><td align=right></td></tr>'
, Title: "Properties", StatText: new Array("AVAILABLE", "UNDER OFFER", "WITHDRAWN", "", "COMPLETED", "", "", "UNADVERTISED")
, MatchButton: 0, hash: 0, view: false, action: 0, It: "p", picNo: '<img class=nothing title="no attachment\nclick to upload" src="http://www.each.co.uk/JSON/images/common/None.gif" />'
, hPic: '<tr><td style="padding-top:5px;font-weight:bold">click to UPLOAD&nbsp;<iframe style="position:absolute" src="http://www.each.co.uk/alert/upload.aspx?bg=0F2A86&Tit=2&I=ID&nd=NID&pic=&pid=" frameborder="0" scrolling="no" ></iframe></td></tr>'
, hFiles: '<table width=100% cellspacing=0 cellpadding=0 border=0>PIC<tr><td style="padding-top:3px;padding-bottom:5px;font-weight:bold">click to UPLOAD AN&nbsp;<iframe style="position:absolute" src="http://www.each.co.uk/alert/upload.aspx?bg=0F2A86&Tit=3&I=ID&nd=NID&pid=" scrolling="no" frameborder="0" ></iframe></td></tr><tr><td colspan=2 class=urlatt>URL attachment: <input onclick="this.select()" /><a target=_blank title="click to view the url" name=v>view</a><a title="click to save the url attachment" name=s>save</a></td></tr><tr><td colspan=2 style="color:red;font-size:0.9em">I confirm that the files, maps and pictures I upload infringe no copyright, and contain no viruses. </td></tr><tr class="files"><td>No attachment uploaded...</td></tr><tr><td></td></tr></table><div class=loadfileatt>Loading file...</div><table class="files" cellpadding=0 cellspacing=0 border=0></table><table style="color:#0F2A86" class=tbPics></table><br>'
, tbPics: '<tr><td style="height:5px">&nbsp;</td></tr><tr class="pictures"><td>No picture uploaded...</td></tr><tr><td class=Pics><div class=Pics></div></td></tr>'
, AreaColors: function() { var C = new Array("ff0000", "00ff00", "0000ff", "ffff00", "ff00ff", "00ffff"); return '#' + C[this.AreaColor++ % C.length]; }
, Advertise: 1, ACE: 1, PublicListing: 7, AlertListing: 2, PublicListingOther: 7, PublicListingOtherAgents: 7
, searched: '', offset: "", iti: "", EditStart: 0, ReqLoc: 0, AreaDesc: '', AreaColor: 0, NoMove: 0, LblAction: 'NEW', Fav: ''
, ExpTowns: 'type first 3+ letters of the town and then select from the list\n(London is not a town)'
, ExpStreet: 'type here comma separated Street names\neg Grosvenor Square, Sun Street, Bond Street, High'
, ExpPcs: 'type here comma separated Postcodes\neg G1, BT1, BT2, CF, SW1A, W, W1, W1T'
, ExpMap: 'Describe your search area here\notherwise Agents don\'t know where you are looking', ExpMap2: 'eg. Birmingham-Nottingham-Sheffield, M1 corridor, etc'
, ExpAm: 'e.g Air Conditioning', hTypes: '<legend><span><b>TYPE<font>xOrd</font></b>&nbsp;</span>&nbsp;<select onchange="fPts(0)" id="Pts"></select></legend><div class=Error></div><div id="PtsShow"></div><div id="PtsStatic"></div>'
, inCalendar: "", flPeriod: 1, flServiceCharge: 0, flRatesPayable: 0, flRent: 0, propfind: 0, New: 'pn', Match: 'rp', floorSizeRent: '', isAdmin: 0
, hHelpTx: '', hHelpTxOrig: '', hHelp: '<table border=0 cellspacing=0 cellpadding=0><tr><td style="height:16px"><div class=pin></div></td></tr><tr><td><div class=body>HELP</div></td></tr></table>'
, DepBra: '', g: 0, LtLnSet: 0, Expiry: '', WasIsMenu: '', Loaded: 0, EmailsAtt: '', StatSent: '', PublicProp: ''
, check: "url('http://www.4prop.com/JSON/images/common/Rolls/check1.png') no-repeat left top", uncheck: "url('http://www.4prop.com/JSON/images/common/Rolls/checkNo1.png') no-repeat left top"
, Favo: new Array(), Comm: new Array(), Reje: new Array(), Crit: 12, Crit2: '', AddedOnly: 0, Dep: new Array(), STAYdep: 0
, Alert: "http://www.each.co.uk/Alert/CODE/CID/BID/DID/NID/Settings.aspx?each", Invoice: 'http://www.each.co.uk/invoice/CODE/CID/BID/DID/NID/invform.aspx'
, PropHelp: "These are all The Properties for this Account (red name at top), (or this Department, Branch or Company).<br>The properties can be displayed on a map (click on pin), as a list (single line), or a block (summary detail). <br><br>You only have permissions for the Instructions in your Department.<br><br>In LINE or BLOCK view you can sort the list by column title, or by Created Date, or Last Status Checked date.<br><br>In LINE view you can review and update: Pdfs, pictures, size (including letting floors), and updating rent/price<br>Click on the town or street to open that record in BLOCK view.<br><br>In BLOCK view you can also:<br>MAP – set the exact positon of the Property<br>PDF – update PDFs and Pictures<br>COPY – make an exact copy record and adjust (if you have another similar Property)<br>EDIT – update and correct the information on the Property (floors table identifies all the floors)<br>EMAIL – email to all Agents who are interested in that Property Type in that Location<br>AGENT – update any Agents dealing with this Property<br>STATUS – update status<br>CLICKS – shows every person that has opened your PDF (or tried to open it if not uploaded)<br>MATCHES – shows all the advertised Requirements that match your Property<br><br><span style=\"background:url('http://www.each.co.uk/images/toolbar/Comment.jpg') no-repeat left top;width:13px;height:13px;display:inline-block\"></span> - red button just above MATCHES<br>this enables you to store PRIVATE comments about this Property, visible to YOU ONLY.<br><br>Any queries on how to use this page click here</a> or call 020 7602 5947<br><br>All Properties listed are colour coded<br><span style='display:inline-block;margin-top:2px;padding:1px;background:#D4E4FF;color:#3B519C;width:333px'>blue = unadvertised Query</span><br><span style='display:inline-block;margin-top:2px;padding:1px;background:#d6eac2;color:#3B519C;width:333px'>green = Available advertised Instruction</span><br><span style='display:inline-block;margin-top:2px;padding:1px;background:#F8F1B4;color:#3B519C;width:333px'>yellow = Under Offer</span><br><span style='display:inline-block;margin-top:2px;padding:1px;background:#EBC9C8;color:#3B519C;width:333px'>red = Completed or Withdrawn (falling off after 3 days)</span>"
, Validate: 0, OrigMenu: '', OrigUser: '', Views: new Array(), Counts: new Array(), States: new Array(), Maps: new Array(), Markers: new Array()
, jsonLists: 'http://www.each.co.uk/JSON/Utilities/lists/hash/', Em: '', L: '', M: '', Reload: '', txEditor: 0, JustAdded: 0, Texter: '', MailIntro: 'write or paste your message here'
, SimiEdit: 0
}; 
function get_cookie(key) {
    results = document.cookie.match('(^|;) ?' + key + '=([^;]*)(;|$)');
    if (results) return (unescape(results[2]));
    return '';
}
function set_cookie(key, value) {
    var ckDate = new Date(), expires = new Date(ckDate.getFullYear() + 1, ckDate.getMonth(), ckDate.getDate());
    cookie_string = key + "=" + escape(value);
    cookie_string += "; expires=" + expires.toGMTString();
    document.cookie = cookie_string;
}

var LatLong = '51.5136,-0.1528', Owners = '', Secretary = '', MyEmail = '', oMn, MnItm = {
    htm: '<span><a name=NAME class=img>MENU</a><span name2=NAME name=0 class=MnDsc><span class=MnDsc2>DSC</span></span></span>'
    , htm0: '<span><a class=amenNAMEID class=img style="background:#3B519C;color:#eef;border:2px solid #3B519C" target href="/HREF.aspx">MENU</a><span class=dsc></span></span>'
	, htm1: '<span><a class=amenNAMEID class=img href="/HREF.aspx" style="background:#30509b;border:0px black solid;border-left:1px #3B519C solid;border-right:1px #30509b solid;color:#dde;padding:5px 2px 5px 6px">MENU</a><span class=dsc></span></span>'
	, none: 'display:none'
}
function O(i) { return document.getElementById(i); }
function Oi(i, v) { try { O(i).innerHTML = v; } catch (e) { return null; } }
function Os(i) { return O(i).style; }
function Rnd(n) { return Math.floor(10 * Math.random(n)); }
function CountLastArrayEmpty(cnt) {
    var s = cnt;
    if ($.browser.msie && $.browser.version < 9) s--;
    return s + '';
}
function SubscCheck() {
    if (XY.Validate > 0) return;
    if ($("#email").val().length < 3) return;
    XY.Validate++;
    $.post("http://www.each.co.uk/abu/Login_AJAX.aspx", { sid: 1, email: $("#email").val() }, function(output) {
        XY.res = getValue(output).split('*');
        if (XY.res[0] == '2') return;
        _gNid = XY.res[1];
        scLoad('http://www.each.co.uk/JSON/EACH/files/subscValidate.js');
    });
}
function getValue(pName) {
    var pos = pName.indexOf("Res=");
    pos = pName.substr(pos + 4);
    return pos.substr(0, pos.indexOf("<"));
}

function FrPs() {
    $('#spLog').html('<div style="text-align:center;color:#500;background:#eef;padding:5px;font-family:Arial;margin:2px;margin-left:35px;width:440px;margin-top:5px;display:block"><div class=close title=close>x</div><div title="send a new password to the email above" style="display:inline-block;background:#afa;color:#050;cursor:pointer;padding:7px">I wish to be sent a generated password to the email above</div></div>'
                    ).slideDown('slow'
                    ).find('div.close'
                    ).mouseover(function() { $('#spLog').find('div').slice(0, 1).css('background-color', '#f00'); }
                    ).mouseout(function() { $('#spLog').find('div').slice(0, 1).css('background-color', '#eef'); }
                    ).click(function() {
                        $('#spLog').slideUp('fast');
                    });

    $('#spLog').find('div').slice(2, 3).mouseover(function() { $('#spLog').find('div').slice(0, 1).css('background-color', '#afa'); }
                    ).mouseout(function() { $('#spLog').find('div').slice(0, 1).css('background-color', '#eef'); }
                    ).click(function() {
                        var ob = this;
                        MyEmail = $('#email').val();
                        $(ob).html(waitSometime('generating new password'));
                        $.post(urlLoad, { list: 3, type: 155, nid: MyEmail, psw: "" }, function(o) {
                            if (eval(o)[0].R == '1')
                                LogInAlert("User with email address does not exist.", 200, 'email');
                            else {
                                $(ob).html('Newly generated password sent (1 min) to the email above...');

                                $.post(urlLoad, { Forgotten: MyEmail, Type: 227, PswNew: "", NID: MyEmail }, function(d) {
                                    setTimeout(function() { $('#spLog').slideUp('slow'); }, 1000);
                                    RunBlinkNow();
                                });
                            }
                        });
                    });
}
function LogInAlert(tx, delay, ider) {
    if (delay > 0) $('#spLog').slideUp('slow');
    $('#' + ider).css('background-color', '#f33');
    $('#email,#password').focus(function() { $(this).css('background-color', ''); });
    $('#login').find('img[name=lg]').css('opacity', '');
    set_cookie('email', '');
    setTimeout(function() {
        $('#spLog').html('<div style="color:#fee;background:#f33;padding:5px;font-family:Arial;margin:2px;margin-left:35px;width:440px;margin-top:5px">'
            + tx + '</div>'
        ).slideDown('slow');
    }, delay);
}
function LogIn() {
    try {
        MyEmail = $('#email').val();
        if (!validateEmail(MyEmail)) {
            LogInAlert('Invalid email format', 0, 'email');
            return;
        }
        if ($('#password').val().length < 5) {
            LogInAlert('Password must have at least 5 characters', 0, 'password');
            return;
        }
        set_cookie('email', MyEmail);
        $('#spLog').html("<div class=Load style='margin-left:33px;width:440px;padding:5px'>EACH Logging in...</div>");
        $('#login').find('img[name=lg]').css('opacity', 0.5);
        $.post(urlLoad, { list: 3, type: 155, nid: MyEmail, psw: $('#password').val() }, function(o) {
            var a = eval(o)[0].R.split('|');
            if (a[0] < 10) {
                var aErr = Array("Invalid password.", "User with email address does not exist in EACH database.", "The email address entered is not valid.");
                LogInAlert('<b>Access denied</b>.<br />' + aErr[a[0]], 500, (a[0] == '1' ? 'email' : 'password'));
            }
            else LOAD(a);
        });
    } catch (e) { }
}


function trim(s) { return s.replace(/^\s+|\s+$/g, ""); }
function ltrim(s) { return s.replace(/^\s+/, ""); }
function rtrim(s) { return s.replace(/\s+$/, ""); }
//function IsNumeric(input) { return (input - 0) == input && input.length > 0; }
function IsNumeric(sText) {
    try {
        if (sText.length == 0) return false;
        var ValidChars = "0123456789.-,", IsNumber = true, Char;
        for (i = 0; i < sText.length && IsNumber == true; i++) {
            Char = sText.charAt(i);
            if (ValidChars.indexOf(Char) == -1)
                return IsNumber = false;

        }
        return IsNumber;
    } catch (e) { return false; }
}
function RemoveLetters(input) { return input.replace(/[^\d]/g, ""); }
function RemoveNumeric(input) { return input.replace(/[^\^[a-zA-Z]/g, ""); }
function CookieLoad() {
    XY.Favo['p'] = get_cookie("Favop"); XY.Comm['p'] = get_cookie("Commp"); XY.Reje['p'] = get_cookie("Rejep");
    XY.Favo['r'] = get_cookie("Favor"); XY.Comm['r'] = get_cookie("Commr"); XY.Reje['r'] = get_cookie("Rejer");
    set_cookie("RecognizeEACH", '1');
}
function CookieSet() {
    set_cookie("Favop", XY.Favo['p']); set_cookie("Favor", XY.Favo['r']);
    set_cookie("Commp", XY.Comm['p']); set_cookie("Rejep", XY.Reje['p']);
    set_cookie("Commr", XY.Comm['r']); set_cookie("Rejer", XY.Reje['r']);
}
function Fading2(s, a, c, style) { return '<font ' + style + ' class=FF name=' + (c / 10) + '>' + s.substring(a, a + 1).replace(' ', '&nbsp;') + '</font>'; }
function Fading(s, limit, sp, style) {
    try {
        if (s.length < limit) return s;
        else {
            var r = s.substr(0, limit - 1);
            for (var f = limit; f < limit + sp && f <= s.length; f++)
                r += Fading2(s, f - 1, 9 - (f - limit + 1) * 1, style);
            return r;
        }
    } catch (e) { return "" }
}

function CritName(v) {
    switch (XY.Crit) {
        case 12: if (v == 17) return "Unadvertised"; return eval('jsPts.v' + v).replace(/ /g, '&nbsp;'); break;
        case "f": return "Your favourite " + propreqs[v]; break;
        case "c": return "Your comments on " + propreqs[v]; break;
        case "l": return "Your listings for PROPERTY SEARCHES"; break;
        case "q": return "Your listings for REQUIREMENT SEARCHES"; break;
        case "u": return "Uploaded " + propreqs[v] + ' for <input title="click to change date" onfocus="STAY=1;showCalendarControl(this)" name=ddmmyy class=uploaded' + v + ' />'; break;
    }
}
function Weakening(i) { $(i).find('font').each(function() { $(this).css('opacity', $(this).attr('name')) }); }
function xStatus(a) {
    fStatus(a);
    if (IsMenu != 4 && $('#department').html().length > 0) {
        $('#department').find('table').each(function() { $(this).css('border', '').css('border-top', '1px solid #fff').css('background', $(this).attr('name2')); });
        var ob = $('#department').find('table[name=' + _gNid + ']');
        $(ob).css('background', COLORS.Add($(ob).css('background'), -50));
    }
    $('#comr,#comp,#favr,#favp').html('');
    LoadComments();
}

function fStatus(a) {
    try {
        _gNid = a[0]; _gDid = a[1]; _gBid = a[2]; _gCid = a[3];
        var line1 = a[16];
        if (a[20].length > 0) line1 = '<a style="color:blue" target=_blank href="http://' + a[20] + '">' + a[16] + '</a>';
        $('#statusbar').html('<span style="float:left;font-family:Arial"><a style="color:red;font-weight:bold;text-decoration:none" href="mailto:' + a[33] + '">' + a[5] + ' ' + a[6] + '</a>, ' + line1 + ' <a title="click to call with Skype" style="color:red;text-decoration:none" href="callto://+' + a[32] + '">' + a[32] + '</a><br>'
            + Fading(a[18] + ', ' + a[17] + (a[17].length == 0 ? '' : ', ') + a[34] + (a[34].length == 0 ? '' : ', ') + a[35] + (a[35].length == 0 ? '' : ', ') + a[36], 93, 10, '') + '</span></span><span style="float:right"><span title="explain how it works" class=hlp name2=0></span><span title="select and choose a report to print" class=prn></span><span name=countdown id=Countdown></span></span><div class="help"></div><div id="rp" style="background:#fff" class="drp"></div>'
            + '<span id=statusback></span><div id=statusmsg></div>'
        ).slideDown('slow'); //
        $('#statusbar').find('a').mouseover(function() { $(this).css('opacity', 0.5); }).mouseout(function() { $(this).css('opacity', ''); })
        if (XY.OrigUser.length > 0)
            $('#statusback').css('display', 'block').html(XY.OrigUser).mouseover(function() {
                $(this).css('opacity', 0.7);
            }).mouseout(function() {
                $(this).css('opacity', '');
            }).click(function() {
                if (IsMenu == 4) {
                    $(XY.DepId).find('table[name=' + XY.OrigMenu[0] + ']').trigger('click');
                }
                else {
                    XY.OrigUser = '';
                    XY.Em = MyEmail;
                    var a = XY.OrigMenu;
                    _gNid = a[0]; //XY.Em = a[33];
                    loadMenu(a[1], a[2], a[3], a[4], a[5], a[6], a[7], a[8], a[9], a[10], a[11], a[12], a[13], a[14], a[15], a[16], a[17], a[18], a[19], a[20], a[21], a[22], a[23], a[24], a[25], a[26], a[27], a[28], a[29], a[30], a[31], a[32], a[38], a[37], a[40], a[41]);
                    xStatus(a);
                    if (IsMenu == 3) {
                        $(XY.DepId).html('')
                        Department(XY.DepId);
                        AgAd();
                    }
                    else if (IsMenu == 7 || IsMenu == 10) {
                        EachList(XY.It);
                    }
                    else if (IsMenu == 11 || IsMenu == 12) {//Comments Favourites
                        $('#lhs').find('div.dMn').find('a[name=' + IsMenu + ']').attr('name2', '0').trigger('mouseout');
                        setTimeout(function() { fisMenu(IsMenu, 1); }, 155);

                    }
                }
            });
        Weakening('#statusbar');
        $('#statusbar').find('span.hlp').mouseover(function() { if ($(this).attr('name') == '1') return; $(this).css('background', "url('http://www.4prop.com/JSON/images/common/hlpO.png') no-repeat"); }).mouseout(function() { if ($(this).attr('name') == '1') return; $(this).css('background', "url('http://www.4prop.com/JSON/images/common/hlp.png') no-repeat"); }
        ).click(function() {
            if (XY.hHelpTx == '') return;
            $('#statusbar').find('.help').css('display', 'none');
            if ($(this).attr('name') != '1') {
                $(this).attr('name', '1').css('background-color', '#393').css('color', '#efe');
                $('#statusbar').find('.help').css('background', '#fff').html(XY.hHelp.replace('HELP', XY.hHelpTx)).css('display', 'block');
            }
            else $(this).attr('name', '0').css('background-color', '').css('color', '');
        });

    }
    catch (e) {    }
}
function refreshNow() { XY.Reload = '?cd' + Rnd(10) + Rnd(10); }
function LOAD(a) {
    try {
        document.onkeyup = null;
        refreshNow();
        XY.OrigMenu = a; XY.Em = a[33];
        XY.jsonLists = XY.jsonLists.replace('hash', a[39]);
        if (MyEmail.length == 0) MyEmail = XY.Em;
        $('#spLog').html('<div style="margin-left:33px;width:440px;color:#dfd;font-weight:bold;padding-top:5px">You have been logged in' + (IsAdmin == 0 ? ' as an Adminsitrator' : '') + '</div>');
        $('#login').slideUp('fast');
        $('#image').slideDown('slow');
        $('#bars').html('<div id="home"></div><div id="Email2"></div><div id="switchuser"></div><div id="tickets"></div><div id=divInvoiceGen ></div><div id=divCash ></div><div id="divcentreestate"></div><div id="department" class=department></div><div class=profarch id="profile"></div><div class=profarch id="archive"></div><div id="uploaded"><div id=uploadedp></div><div id=uploadedr></div></div><div id="favp"></div><div id="favr"></div><div id="comp"></div><div id="comr"></div><div id=Find></div><div id=AgentAB></div>');
        XY.Dep['#department'] = ''; XY.Dep['#homedep'] = '';
        _gNid = a[0]; _gDid = a[1]; _gBid = a[2]; _gCid = a[3];
        MenuHtml();
        loadMenu(a[1], a[2], a[3], a[4], a[5], a[6], a[7], a[8], a[9], a[10], a[11], a[12], a[13], a[14], a[15], a[16], a[17], a[18], a[19], a[20], a[21], a[22], a[23], a[24], a[25], a[26], a[27], a[28], a[29], a[30], a[31], a[32], a[38], a[37], a[40], a[41]);
        fStatus(a);
        setTimeout(countDown, 1000);
        if (urlp.indexOf('.aspx') > -1) return;
        var gm = get_cookie("eachmenu");
        if (gm == "19" || gm == '') gm = "3";
        if (gm.length == 0) set_cookie("eachmenu", 3);
        if (gm == "11" || gm == "12") gm = "3"; // return;
        if (IsAdmin == 0) gm = "3"; //always on Home page        
        if (IsAdmin > 0) gm = "101"; //"101";//admin, always switch user...
        //if (IsAdmin == 0) 
        fisMenu(gm, 1);
    } catch (e) {
        fisMenu(3, 1);
    }
}
var IsAdmin = 0;
function SwitchUser(n) {
    _gNid = n;
    window.location = "http://www.each.co.uk/?i=" + n;
}
function SwitchUser2(n) {
    _gNid = n;
    if (IsAdmin == 0) return;
    XY.Dep['#department'] = '';
    XY.Dep['#homedep'] = '';
    $.post(urlLoad, { list: 3, Nid: _gNid, Type: 158 }, function(d) {
        var a = eval(d)[0].R.split('|');
        if (a.length > 1) {
            if (XY.Em == '') LOAD(eval(d)[0].R.split('|'));
            else {
                XY.Em = a[33];
                if (XY.Em == '') XY.Em = '@';
                XY.OrigUser = 'back to ' + XY.OrigMenu[5] + ' ' + XY.OrigMenu[6];
                loadMenu(a[1], a[2], a[3], a[4], a[5], a[6], a[7], a[8], a[9], a[10], a[11], a[12], a[13], a[14], a[15], a[16], a[17], a[18], a[19], a[20], a[21], a[22], a[23], a[24], a[25], a[26], a[27], a[28], a[29], a[30], a[31], a[32], a[38], a[37], a[40], a[41]);
                xStatus(a);
                Was = new Array(); Was['r'] = ''; Was['p'] = '';
                $("#NegDD").val(n); 
                $('#tProformEmail').val(XY.Em);                
            }

        }
    });
}

function AdminLoad() {
    IsAdmin = 1;
    set_cookie('EachAdmin', '1');
    if (urlp.indexOf('?') > -1 && urlp.length > 70) setTimeout(function() { LOAD(unescape(urlp.split('?')[1]).split('|')); }, 100);
    else if (urlp.indexOf('?i=') > -1) SwitchUser2(parseFloat(urlp.split('?i=')[1]));
}
function BrowserVersion() {
    urlp = urlp.toLowerCase();
    if ($.browser.msie) {
        if ($.browser.version < 7) {
            alert('You use IE version 6.0 or lower, which is now very old\nIt will be better for all your web use, if you upgrade to a higher version\nor use Chrome or Mozilla browser\n\nSome functionality and display on EACH will not work using IE6\n\nAfter you close this window you will see a page on how to upgrade from IE6\n\nOr eventually use Chrome or Mozilla');
            window.open('http://www.browserupgrade.info/ie6/');
        }
        else if ($.browser.version == 7) {
            if (get_cookie('eachie7') == '') {
                alert('You are using Internet Explorer 7<br>Some versions work OK with www.each.co.uk<br>others do not!<br><br>Please click Suggestions in the menu and email us if you have a problem<br><br>It will be better for...\n\nOr eventually use Chrome or Mozilla');
                window.open('http://internet-explorer.uk.msn.com/');
                set_cookie('eachie7', '1');
            }
        }
    }
}
if (get_cookie('EachAdmin') == "1") AdminLoad();//&& 1 == 2
else $.post(urlLoad, { ip: 1 }, function(ip) {
    if ("86.2.36.103;94.194.207.79;81.137.147.15;94.194.207.97;217.205.225.130;91.84.36.241;91.84.36.242;91.84.36.243;91.84.36.244;91.84.36.245;91.84.36.246;192.168.11.40;192.168.11.62;192.168.11.63;87.194.76.180;192.168.2.4;81.100.167.13".indexOf(trim(ip)) > -1)
        AdminLoad();
})
BrowserVersion();

function KeyCheck(e) {
    var KeyID = (window.event) ? event.keyCode : e.keyCode;
    if (KeyID == 13) LogIn();
}
document.onkeyup = KeyCheck;
function CreateBookmarkLink() {//doesn't work on Chrome / Opera 
    if ($.browser.msie)
        window.external.AddFavorite('http://www.each.co.uk', 'EACH');
    else window.sidebar.addPanel('EACH', 'http://www.each.co.uk', "");
}

function AgentABcode() {
    var sCode = _gCid + '', s = '';
    sCode = sCode.split('');
    for (var c = 0; c < sCode.length; c++) s += 'MIROBRADAX'.substr(sCode[c], 1);
    return _gCid * 2 + s;
}
//utils...
function retMax(s, n) { return s.substring(0, n); }
function scLoad(url) {
    script = document.createElement("script");
    script.setAttribute("src", url);
    script.setAttribute("type", "text/javascript");
    document.body.appendChild(script);
}
function cssLoad(cssurl) {
    var cssNode = document.createElement('link');
    cssNode.type = 'text/css'; cssNode.media = 'screen'; cssNode.rel = 'stylesheet';
    cssNode.href = cssurl; //'css/url2.css';
    var headID = document.getElementsByTagName("head")[0];
    headID.appendChild(cssNode);
}
if (top.frames.length != 0) top.location = self.document.location;

function EachListMail() {
    EachListLoad();
    if (urlp.indexOf('req') > -1) EachReq();
    XY.view = urlp.substring(urlp.length - 2, urlp.length) == '|q' || urlp.substring(urlp.length - 2, urlp.length) == '*q';
    var ndbc = urlp.split('*');
    if (ndbc.length < 2) ndbc = urlp.split('|');
    if (ndbc.length < 2) ndbc = urlp.split('%7c');
    _gNid = ndbc[3]; //parseFloat returns number only
    XY.action = parseFloat(ndbc[2]); //0-32 = status, 99= Deals With, 100 = Upload Details / image
    XY.hash = 1;
    jsCriteria.hash = ndbc[1];
    LoadComments();
    EachListData();
}
function EachListLoad() {
    Nullify();
    document.title = "EACH: My / Our " + propreqs[XY.It];
    $('#RESULT').css("display", "block").html(waitSometime("Loading&nbsp;your&nbsp;" + propreqs[XY.It].toLowerCase() + "..."));
}
function EachListData() {
    $.post(urlLoad, jsCriteria, function(output) {
        if (output.length == 0) WhatsUp('It seems there is timeout database problem. <br><br> Please wait a while, and then try again.');
        else Process(eval(output));
    });
}
function EachReq() {
    jsCriteria.Requirement = 1;
    XY.It = 'r'; XY.Match = 'pr'; XY.New = 'rn';
}
function EachList(req) {
    HideAll2();
    $('#fsScope,#RESULT,#head').css('display', 'block');
    EachListLoad();
    if (XY.CoProps <= 300) jsCriteria.CID = _gCid;
    else jsCriteria.BID = _gBid;
    XY.It = 'p'; XY.Match = 'rp'; //assume it is property
    if (req == 'r') EachReq();
    //if (Was[XY.It].length == 0) EachListData(); else Process(Was[XY.It]);
    if (Was[XY.It].length == 0 || XY.JustAdded > 0) EachListData(); else Process(Was[XY.It]);
    XY.JustAdded = 0;
    if ($.browser.msie && $.browser.version == 7) {
        $('#bars').find('div').css('display', 'none');
        $('#fsScope').css('top', '52px');
        $('#explain,#RESULT').css('position', 'relative').css('top', '52px');
    }
}
function retPipesRpl(R, ix, val) {
    var a = R.split('|')
    a[ix] = val;
    return retPipedString(a);
}
function retPipedString(R) {
    var sr = '';
    for (var r = 0; r < R.length; r++) {
        if (r > 0) sr += '|'; //sr.length > 0
        sr += R[r];
    }
    return sr;
}

function MnAdmin() {
    IsAdmin = _gNid;  //45493=Marcin	K, 60582=Internet	Input
    $('#rhs').html('<div class=dMn><span name=0 class=t>Data Entry</span><div class=gMen0><span><a name=101 class=img>Switch User</a><span class=dsc></span></span><span><a name=100 class=img>Uploaded</a><span name2=100 name=0 class=MnDsc><span class=MnDsc2>Uploaded properties and requirements</span></span></span><span><a class=amen03 class=img style="background:#3B519C;color:#eef;border:2px solid #3B519C" target href="/admin/Tally.aspx?i=57042&edr=57042">Tally</a><span class=dsc></span></span></div><span name=1 class=t>Admin</span><div class=gMen1><span><a name=103 class=img>Email 2 Agents</a></span><span><a name=105 class=img>Centres</a></span><span><a name=108 class=img>Tickets</a></span><span><a name=109 class=img>Invoice&nbsp;Generation</a></span><span><a name=110 class=img>Cash</a></span></div><span name=2 class=t>Testing / Release</span><div class=gMen2><span><a class=amen21 class=img style="background:#3B519C;color:#eef;border:2px solid #3B519C" target=_blank href="http://www.osidil.com/JSON/4prop/test/index.html">4prop</a><span class=dsc></span></span><span><a class=amen22 class=img style="background:#3B519C;color:#eef;border:2px solid #3B519C" target=_blank href="http://www.osidil.com/JSON/AgentAB/test/AgentAB.html">Agent&nbsp;AB/Councils</a><span class=dsc></span></span>').find('span.t').slice(1, 5).css('margin-top', '5px');

    var locUni;
    $('#rhs').find('span.t').mouseover(function() { $(this).css('background', '#aaa').css('color', '#900'); }
    ).mouseout(function() { $(this).css('background', '#eee').css('color', 'red'); }
    ).click(function() {
        try {
            if ($('#lhs').find('div.gMen' + $(this).attr('name')).attr('style') == undefined || $('#lhs').find('div.gMen' + $(this).attr('name')).attr('style').toLowerCase().indexOf('none') == -1) {
                $('#lhs').find('div.gMen' + $(this).attr('name')).slideUp('slow');
                locUni = '+&nbsp;' + $(this).html();
            }
            else {
                $('#lhs').find('div.gMen' + $(this).attr('name')).slideDown('fast');
                locUni = $(this).html().replace('+&nbsp;', '');
            }
            $(this).html(locUni);
        } catch (e) { }
    });
    $('#rhs').find('div.dMn:first').find('a').css('border-bottom', '1px dotted #ddf'
    ).mouseover(function() {
        try {
            if ($(this).attr('name2') == '1') return;
            var bgc = COLORS.Add($(this).css('background-color').toLowerCase().replace('#', ''), -30);
            $(this).css('background-color', bgc);
        } catch (e) { }
    }).mouseout(function() {
        try {
            if ($(this).attr('name2') == '1') return;
            var bgc = COLORS.Add($(this).css('background-color').toLowerCase().replace('#', ''), +30);
            $(this).css('background-color', bgc); //
        } catch (e) { }
    });
}

function AddPrRq(it) {
    if (!Subscription(it)) AddPrRq2(it);
}
function AddPrRq2(it) {
    XY.It = it;
    fisMenu((XY.It == 'r' ? 6 : 9), 0);
    $('#lhs').find('div.dMn').find('a[name=7],a[name=10]').attr('name2', '0').trigger('mouseout');
    if ((XY.It == 'r' && XY.WasIsMenu != '7') || (XY.It == 'p' && XY.WasIsMenu != '10')) {
        $('#RESULT').html('');
        AddOnly();
    }
    Add('New', 0); //,div[name=rn|0]
    $('#RESULT').css('display', 'block').find('div[name=' + XY.It + 'n|0]').css('display', 'block');
}
function AddOnly() {
    Nullify();
    XY.AddedOnly = 1;
    XY.hHelpTx = (XY.It == 'r' ? '<div style="font-weight:bold"><font size=5>Add Requirement Help</font><span style="padding-left:40px">ONLY 2 compulsory<font color=red>*</font> fields to complete</span></div>'
                + '<br><font color=red>1</font> <b>Type of Requirement</b><font color=red>*</font>'
                + '<div style="padding-left:50px">from the dropdown select the Requirement Type you want</div>'
                + '<div style="padding-left:50px">then select all subtypes that might apply (click anywhere in the box)</div>'
                + '<br><font color=red>2</font> <b>Size</b>'
                + '<div style="padding-left:50px">no entry = any size</div>'
                + '<br><font color=red>3</font> <b>Search area</b><font color=red>*</font>'
                + '<div><b>only use ONE of these:</b> (unless Street where you need to say in which Town or Postcode)</div>'
                + '<div style="padding-left:50px"><b>STREET</b> to search the exact street names that you enter</div>'
                + '<div style="padding-left:50px">a) <b>CENTRAL LONDON AREAS</b> for typical central London towns</div>'
                + '<div style="padding-left:50px">b) <b>REGIONS &amp; COUNTIES</b> for broad search areas around the UK</div>'
                + '<div style="padding-left:50px">c) <b>TOWNS</b> where you are searching those towns (or shopping centres, industrial estates, etc.)</div>'
                + '<div style="padding-left:50px">d) <b>POSTCODES</b> (specific or broad) to cover the areas you want</div>'
                + '<div style="padding-left:50px">d) <b>MAP</b> where the other area selection options are more difficult (eg. motorways, coastal section, etc)</div>'
                + '<br><font color=red>4</font> <b>Tenure</b>'
                + '<div style="padding-left:50px">no entry = all tenures</div>'
                + '<br><font color=red>5</font> <b>Description</b>'
                + '<div style="padding-left:50px">It helps to give a brief description to the other Agents of what you are looking for.</div>'
                + '<div style="padding-left:50px">(Amenities will sort results at a later time)</div>'
                + '<br><font color=red>6</font> <b>Summary</b>'
                + '<div style="padding-left:50px">This is your advertisement that other Agents will see.</div>'
                + '<div style="padding-left:50px">(if the search is sensitive, you can click to hide your Company Name)</div>'
                + '<br><font color=red>7</font> <b>Marketing Confirmation</b>'
                + '<div style="padding-left:50px">usually you need to do nothing because you want to advertise your Requirement</div>'
                + '<div style="padding-left:50px">but you can keep it as an ENQUIRY SEARCH by NOT advertising your Search</div>'
                + '<br><b>SAVE Requirement</b>'
                + '<br>If you are advertising, you then click to email it to all interested Agents (auto selected by EACH)'
                + '<br>It will also automatically email all Agents with matching Properties'
                + '<br>You can print a listing, by clicking ‘MATCHES’ and then click the printer icon'
                + '<br>You will be emailed when new Properties are added that match your Requirement.'
                + '<br><br><br>All your Requirements are SAVED under <b>REQUIREMENTS</b>'
                + '<br><br><a href=\'mailto:help@each.co.uk\'>Any queries on how to use this page click here</a> or call 020 7602 5947 '
                : '<div style="font-weight:bold"><font size=5>Add Property Help</font><span style="padding-left:50px">ONLY 4 compulsory<font color=red>*</font> fields to complete</span></div>'
            + '<br><font color=red>1</font> <b>Property Location</b><font color=red>*</font>'
            + '<div style="padding-left:50px">Please follow the instruction to the right of the address as this will save you time</div>'
            + '<br><font color=red>2</font> <b>Type of Property</b><font color=red>*</font>'
            + '<div style="padding-left:50px">from the dropdown select the Property Type you want</div>'
            + '<div style="padding-left:50px">then select all subtypes that might apply (click anywhere in the box)</div>'
            + '<div style="padding-left:50px">(when saved you can make a COPY of the record and save it under another Property Type that suits)</div>'
            + '<br><font color=red>3</font> <b>Tenure</b><font color=red>*</font>'
            + '<div style="padding-left:50px">select tenures</div>'
            + '<div style="padding-left:50px">no need to enter Price or Rent or Rates, etc.</div>'
            + '<br><font color=red>4</font> <b>Size</b><font color=red>*</font>'
            + '<div style="padding-left:50px">this will open a floors table if an Office, Retail or Industrial property</div>'
            + '<div style="padding-left:50px">you can just enter Totals</div>'
            + '<br><font color=red>5</font> <b>Description</b>'
            + '<div style="padding-left:50px">entries are not compulsory</div>'
            + '<div style="padding-left:50px">List Amenities to clearly show the best attributes (it will be used to sort results at a later time)</div>'
            + '<div style="padding-left:50px">It helps to give a brief description to the other Agents of what you are looking for.</div>'
            + '<br><font color=red>6</font> <b>Summary</b>'
            + '<div style="padding-left:50px">This is your advertisement that other Agents will see.</div>'
            + '<div style="padding-left:50px">(if the search is sensitive, you can click to hide your Company Name, and/or street number, or street)</div>'
            + '<br><font color=red>7</font> <b>Marketing Confirmation</b>'
            + '<div style="padding-left:50px">usually you need to do nothing because you want to advertise your Requirement</div>'
            + '<div style="padding-left:50px">but you can keep it as an ENQUIRY SEARCH by NOT advertising your Search</div>'
            + '<br><b>SAVE Property</b>'
            + '<br>If you are advertising, you then click to email it to all interested Agents (auto selected by EACH)'
            + '<br>It will also automatically email all Agents with matching Requirements'
            + '<br>You can print a listing of Requirements, by clicking ‘MATCHES’ and then click the printer icon'
            + '<br>You will be emailed when new Properties are added that match your Requirement.'
            + '<br><br><br>All your Properties are SAVED under Properties'
            + '<br><br><a href=\'mailto:help@each.co.uk\'>Any queries on how to use this page click here</a> or call 020 7602 5947'
        )
    JSON[XY.New] = new Array(); JSON[XY.It] = new Array();
    EachListHeaders();
}
function MenuHtml() {
    var EachMenu = new Array('20|INSTANT HELP|call Anthony, Jeremy, or Jamie if you need any help 020 7602 5947<br>There are <span class=menuhlpicon>&nbsp;</span> to help on each page'
        , '3|ADMIN &#47; HOME|Update your Contact Information, Password, web address, etc'
        , '4|My Department|Department Staff overview and SWITCH to use other Agents\' accounts'
        , '5|Co Properties|Lists your Properties marketed via EACH with EASY REVIEW & UPDATE of your pdf/picture/rent/price/size'
    //, '8|Potential Clients|Enquiries for your Properties from Occupiers, Investors, and Developers'
        , '6|ADD Requirement|to Find Properties that match your Requirement/Search with or without ADVERTISING'
        , '7|Requirements|Review your Requirements and the Properties that match. Update, transfer to another Agent, update status'
        , '9|ADD Property|to Find Requirements that match your Property, with or without ADVERTISING'
        , '10|Properties|Review your Properties and the Requirements that match. Update, transfer to another Agent, update status'
        , '11|Comments|See the comments you have made on the Properties and Requirements you have seen'
        , '12|Favourites|See the Properties and Requirements you have saved as Favourites'
        , '13|PROFILES|Occupiers, Ownership, Availability, and Archive of Towns, Streets, Shopping Centres, Industrial Estates, etc'
        , '14|Listings / Find|Set up relevant listings that you want to view or print time and again, including YOUR DEPARTMENT\'s'
        , '15|Alert Settings|link to the daily list of new Properties and Requirements, according to your Settings of areas of interest'
        , '16|Property Archive|ArchiveSearch archived Properties in \'The Property Archive\''
        , '17|Agent AB|demonstration of a Property Search button we can support on your website, that we almost guarantee will win you new clients.'
        , '18|Invoices &amp; Forms|links to a page to see your invoices and other EACH information sheets'
        , '2|Suggestions|We appreciate your suggestions to improve our service'
        , '19|LOG OUT|logs you out'), IsMenu = '';

    UNI = '<div class=dMn>';
    for (var g = 0; g < EachMenu.length; g++) {
        aUni = EachMenu[g].split('|');
        //if (aUni[1].indexOf('Listing') == -1 || IsAdmin > 0)
        UNI += MnItm.htm.replace(/NAME/g, aUni[0]).replace('MENU', aUni[1]).replace('DSC', aUni[2]);
    }
    $('#lhs').html(UNI + '</div><div id=rhs></div>');
    oMn = $('#lhs').find('div.dMn');
    $(oMn).find('a').attr('name4', '#aaaaca');
    $(oMn).find('a[name=2]').attr('href', 'mailto:help@each.co.uk');
    $(oMn).find('a[name=15]').css('background-image', "url('http://www.4prop.com/JSON/images/common/EachButtonLY.gif')").attr('name4', '#551').css('color', '#551'
        ).attr('target', '_blank').parent().find('span.MnDsc2').css('background', '#F3E67B').css('color', '#550');
    $(oMn).find('a[name=18]').css('background-image', "url('http://www.4prop.com/JSON/images/common/EachButtonLY.gif')"
        ).attr('name4', '#551').css('color', '#551').attr('target', '_blank').parent().find('span.MnDsc2').css('background', '#F3E67B').css('color', '#550');
    $(oMn).find('a:last').css('background-image', "url('http://www.4prop.com/JSON/images/common/EachButtonLP.png')"
        ).attr('name4', '#daaaaa').css('color', '#daaaaa').parent().find('span.MnDsc2').css('background', '#C15952').css('color', '#fdd');
    $(oMn).find('a[name=2],a[name=3],a[name=6],a[name=11],a[name=15]').css('margin-top', '12px');
    $(oMn).find('a[name=0],a[name=3],a[name=6],a[name=7],a[name=9],a[name=10],a[name=15],a[name=19]').css('font-weight', 'bold');
    $(oMn).find('a[name=6],a[name=7],a[name=9],a[name=10]').css('color', '#fff').attr('name4', '#fff');
    $(oMn).find('a[name=20]').attr('name4', '#7f3').attr('style', 'color:#7f3;display:block;text-align:center;font-size:0.9em;padding-top:6px;height:19px;padding-left:0px;font-weight:bold;letter-spacing:1px');
    if (IsAdmin > 0) MnAdmin();
    $('#lhs,#rhs').find('div.dMn').find('a.img').mouseover(function() {//:first
        try {
            MenuDsc($(this).attr('name'), 1);
            if ($(this).attr('name2') == '1') return;
            var cshift = 36;
            if (COLORS.Mx($(this).css('color')) > 255 - cshift) cshift *= -1;
            $(this).css('background-image', $(this).css('background-image').replace('.png', 'O.png').replace('.gif', 'O.gif')).css('color', COLORS.Add($(this).css('color').toLowerCase().replace('#', ''), cshift));
        } catch (e) { }
    }).mouseout(function() {
        try {
            MenuDsc($(this).attr('name'), 0);
            if ($(this).attr('name2') == '1') return;
            $(this).css('background-image', $(this).css('background-image').replace('O.png', '.png').replace('O.gif', '.gif')).css('color', $(this).attr('name4'));
        } catch (e) { }
    });
    $('#lhs,#rhs').find('div.dMn').find('a').click(function() {
        if ($(this).attr('name') == "15" || $(this).attr('name') == "18" || $(this).attr('name') == "") return; //external (alert) links
        try {
            $('html,body').animate({ scrollTop: 0 }, 1000);
            XY.action = 0; XY.view = false; XY.L = '';
            if ($(this).attr('name2') != '1') {
                if ($('#statusbar').find('span.hlp').attr('name') == '1') $('#statusbar').find('span.hlp').trigger('click');
                $(this).attr('name2', '1');
                IsMenu = $(this).attr('name');
                if (IsMenu == '2' || IsMenu == '3' || IsMenu == '4' || IsMenu == '6' || IsMenu == '9' || IsMenu == '14')
                    $('#statusbar').find('span.prn').css('display', 'none');
                XY.hHelpTxOrig = XY.hHelpTx;
                HideAll();
                switch ($(this).attr('name')) {
                    case "0": LogOut(); break;
                    case "2": $(this).attr('name2', '0'); break; //Suggestion
                    case "3": Home(); break; //ADMIN / HOME
                    case "4":
                        XY.Dep['#department'] = '';
                        Department('#department'); break;
                    case "5": XY.hHelpTx = "Hover over each button to see what it does<br><br>You can update Instructions within your Department (name recorded)<br>My Instructions shows the Instructions you are associated with,<br>Department shows the Instructions for your Department.<br>You can see, but not edit, Instructions for your Branch and Company<br><br>You can sort Instructions by column title, created or last status date.<br>Click on the line to open/close the block view<br>'Admin' allows you to move Instructions to Agents from your Department<br><a href=\'mailto:help@each.co.uk'\>Any queries on how to use this page click here</a> or call 020 7602 5947<br><br><span style='display:inline-block;margin-top:2px;padding:1px;background:#D4E4FF;color:#3B519C;width:333px'>blue = unadvertised Query</span><br><span style='display:inline-block;margin-top:2px;padding:1px;background:#d6eac2;color:#3B519C;width:333px'>green = Available advertised Instruction</span><br><span style='display:inline-block;margin-top:2px;padding:1px;background:#F8F1B4;color:#3B519C;width:333px'>yellow = Under Offer</span><br><span style='display:inline-block;margin-top:2px;padding:1px;background:#EBC9C8;color:#3B519C;width:333px'>red = Completed or Withdrawn (falling off after 3 days)</span>";
                        urlp = 'comp';
                        if (XY.WasIsMenu == "10") {
                            $('#fsScope,#RESULT,#head').css('display', 'block');
                            $('#fsScope').find('a.ct').slice(1, 2).trigger('click');
                        }
                        else EachList('p');
                        break;
                    case "6": AddPrRq('r'); break;
                    case "7":
                        XY.hHelpTx = XY.PropHelp.replace(/Properties/g, 'Requirements').replace(/Property/g, 'Requirement'
                            ).replace(/properties/g, 'requirements').replace(/property/g, 'requirement'
                            ).replace('on a map (click on pin), ', ''
                            ).replace('MAP – set the exact positon of the Requirement', '');
                        //All Properties listed are colour coded
                        EachList('r');
                        break;
                    case "8": break; //Potential Clients
                    case "9": AddPrRq('p'); break;
                    case "10":
                        XY.hHelpTx = XY.PropHelp;
                        if (XY.WasIsMenu == "5" && aIS[3] > 0) {
                            $('#fsScope,#RESULT,#head').css('display', 'block');
                            $('#fsScope').find('a.ct').slice(0, 1).trigger('click');
                        }
                        else EachList('p');
                        break;
                    case "11":
                        XY.action = 0;
                        XY.hHelpTx = "List of properties and requirements you commented";
                        if (CommentsN() == 0) {
                            // $('#lhs').find('div.dMn').find('a[name=3]').trigger('click');
                            return;
                        }
                        XY.Crit = "c";
                        htmBars = BarTitles({ Crit: 'p' }, 'pc') + BarTitles({ Crit: 'r' }, 'rc');
                        var J;
                        if ($('#comr').html().length == 0 && XY.Comm['r'].length > 2) {
                            $('#comr').html(waitSometime('Loading Your Commented Requirements'));
                            $.post(urlLoad, { List: 1, archive: 1, Requirement: 1, IDs: XY.Comm['r'].replace(/[a-z]/g, '').replace(/~[0-9]*/g, '').replace(/,[0-9]*/g, '').replace(/\|/g, ',').replace(/\./g, '') }, function(d) {
                                JSON['rc'] = eval(d), J;
                                if (JSON['rc'].length == 0) { $('#comr').html('Your commented requirements are in archive').css('background', '#993A37').css('color', '#fee'); return; }
                                for (var i = 0; i < JSON['rc'].length; i++) {
                                    try {
                                        J = JSON['rc'][i]; J.ck = 0; J.rc = 0; J.block = 0; J.II = i; J.found = 1;
                                        J.It = 'rc'; //XY.It
                                        J.View = 0; J.tp = J.T.split('|')[0]; ITs[J.I] = i;
                                        J.Wd = J.At.indexOf('doc') + J.At.indexOf('rtf'); J.Pf = J.At.indexOf('pdf'); J.Rej = 0; J.Cl = J.R.split('|')[7].length + J.R.split('|')[8].length + J.R.split('|')[14].length;
                                        J.Crit = 'r'; //(J.S == 7 ? 17 : J.tp);
                                        J.IS = 3;
                                        J.MyAg = 0; J.M = 1; J.My = 0;
                                    } catch (e) { }
                                }
                                fBars('#comr', BarTitles({ Crit: 'r' }, 'rc'));
                                $('#comr').find('table.bar').find('td.count').html(CommentsNpr('r'));
                                setTimeout(function() { View('rc|r', 3); }, 500);
                            });
                        }
                        if ($('#comp').html().length == 0 && XY.Comm['p'].length > 2) {
                            $('#comp').html(waitSometime('Loading Your Commented Properties'));
                            $.post(urlLoad, { List: 1, archive: 1, IDs: XY.Comm['p'].replace(/[a-z]/g, '').replace(/~[0-9]*/g, '').replace(/,[0-9]*/g, '').replace(/\|/g, ',').replace(/\./g, '') }, function(d) {
                                JSON['pc'] = eval(d), J;
                                if (JSON['pc'].length == 0) { $('#comp').html('Your commented properties are in archive').css('background', '#993A37').css('color', '#fee'); return; }
                                for (var i = 0; i < JSON['pc'].length; i++) {
                                    try {
                                        J = JSON['pc'][i]; J.ck = 0; J.rc = 0; J.block = 0; J.II = i; J.found = 1;
                                        J.It = 'pc'; J.View = 0; J.tp = J.T.split('|')[0]; ITs[J.I] = i;
                                        J.Wd = J.At.indexOf('doc') + J.At.indexOf('rtf'); J.Pf = J.At.indexOf('pdf'); J.Rej = 0; J.Cl = J.R.split('|')[7].length + J.R.split('|')[8].length + J.R.split('|')[14].length;
                                        J.Crit = 'p'; J.IS = 3; J.MyAg = 0; J.M = 1; J.My = 0;
                                    } catch (e) { }
                                }
                                fBars('#comp', BarTitles({ Crit: 'p' }, 'pc'));
                                $('#comp').find('table.bar').find('td.count').html(CommentsNpr('p'));
                                setTimeout(function() { View('pc|p', 3); }, 1200);
                            });
                        }
                        $('#comr,#comp').slideDown('fast');
                        break;
                    case "12": //"Favourites":
                        XY.action = 0;
                        XY.hHelpTx = "List of properties and requirements you marked as favourite";
                        if (FavouritesN() == 0) { alert('You have no favourites'); return; }
                        XY.Crit = "f";
                        if ($('#favr').html() == 0 && XY.Favo['r'].length > 2) {
                            $('#favr').html(waitSometime('Loading Your Favourites Requirements'));
                            $.post(urlLoad, { List: 1, archive: 1, Requirement: 1, IDs: XY.Favo['r'].replace(/,[0-9]*/g, '').replace(/\|/g, ',') }, function(d) {
                                JSON['rf'] = eval(d), J;
                                if (JSON['rf'].length == 0) { $('#favr').html('Your favourite requirements are in archive').css('background', '#993A37').css('color', '#fee'); return; }
                                for (var i = 0; i < JSON['rf'].length; i++) {
                                    try {
                                        J = JSON['rf'][i]; J.ck = 0; J.rc = 0; J.block = 0; J.II = i; J.found = 1; J.It = 'rf';
                                        J.View = 0; J.tp = J.T.split('|')[0]; ITs[J.I] = i;
                                        J.Wd = J.At.indexOf('doc') + J.At.indexOf('rtf'); J.Pf = J.At.indexOf('pdf'); J.Rej = 0; J.Cl = J.R.split('|')[7].length + J.R.split('|')[8].length + J.R.split('|')[14].length;
                                        J.Crit = 'r'; J.IS = 3; J.MyAg = 0; J.M = 1; J.My = 0;
                                    } catch (e) { }
                                }
                                fBars('#favr', BarTitles({ Crit: 'r' }, 'rf'));
                                setTimeout(function() { $('#favr').find('table.bar').find('td.count').html(FavouritesNpr('r')); View('rf|r', 3); }, 1500);
                            });
                        }
                        if ($('#favp').html() == 0 && XY.Favo['p'].length > 2) {
                            $('#favp').html(waitSometime('Loading Your Favourites Properties'));
                            $.post(urlLoad, { List: 1, archive: 1, IDs: XY.Favo['p'].replace(/,[0-9]*/g, '').replace(/\|/g, ',') }, function(d) {
                                JSON['pf'] = eval(d), J;
                                if (JSON['pf'].length == 0) { $('#favp').html('Your favourite properties are in archive').css('background', '#993A37').css('color', '#fee'); return; }
                                for (var i = 0; i < JSON['pf'].length; i++) {
                                    try {
                                        J = JSON['pf'][i]; J.ck = 0; J.rc = 0; J.block = 0; J.II = i; J.found = 1;
                                        J.It = 'pf'; //XY.It
                                        J.View = 0; J.tp = J.T.split('|')[0]; ITs[J.I] = i;
                                        J.Wd = J.At.indexOf('doc') + J.At.indexOf('rtf'); J.Pf = J.At.indexOf('pdf');
                                        J.Rej = 0; J.Cl = J.R.split('|')[7].length + J.R.split('|')[8].length + J.R.split('|')[14].length;
                                        J.Crit = 'p'; //(J.S == 7 ? 17 : J.tp);
                                        J.IS = 3;
                                        J.MyAg = 0; J.M = 1; J.My = 0;
                                    } catch (e) { }
                                }
                                fBars('#favp', BarTitles({ Crit: 'p' }, 'pf'));
                                setTimeout(function() { $('#favp').find('table.bar').find('td.count').html(FavouritesNpr('p')); View('pf|p', 3); }, 1500);
                            });
                        }
                        $('#favp,#favr').slideDown('fast');
                        break;
                    case "13":
                        XY.hHelpTx = "Location Profile help";
                        if ($('#profile').html().length > 10) $('#profile').slideDown('fast');
                        else {
                            $('#profile').html(waitSometime('Loading Your Profile')).slideDown('fast');
                            scLoad('http://www.each.co.uk/JSON/EACH/files/LocationProfile.js' + XY.Reload);
                        }
                        break;
                    case "14":
                        $('#Find').html(waitSometime('Loading Listings / Find...')).css('display', 'block');
                        scLoad('http://www.each.co.uk/JSON/EACH/files/Find.js' + XY.Reload);
                        cssLoad('files/find.css?' + Rnd(1000));
                        break;
                    case "16":
                        XY.hHelpTx = "Property Archive help";
                        if ($('#archive').html().length > 10) $('#archive').slideDown('fast');
                        else {
                            $('#archive').html(waitSometime('Loading Your Profile')).slideDown('fast');
                            scLoad('http://www.each.co.uk/JSON/EACH/files/Archive.js' + XY.Reload);
                        }
                        break; // Archive
                    case "17":
                        scLoad('http://www.each.co.uk/JSON/EACH/files/AgentAB.js' + XY.Reload);
                        break; //Agent AB
                    case "19": LogOut(); break;
                    case "100":
                        UploadedP(todayDMY);UploadedR(todayDMY);
                        $('#uploaded').slideDown('fast');
                        break;
                    case "101":
                        $('#switchuser').html(waitSometime('Loading switch user...')).css('display', 'block').css('width', '550px');
                        cssLoad('files/switch.css' + XY.Reload); //old/
                        scLoad('http://www.each.co.uk/JSON/EACH/files/SwitchUser.js' + XY.Reload);
                        break;
                    case "103":
                        $('#Email2').html(waitSometime('Loading email lists...')).css('display', 'block').css('width', '550px');
                        //cssLoad('files/Email2.css' + XY.Reload);
                        scLoad('http://www.each.co.uk/JSON/EACH/files/Email2.js' + XY.Reload);
                        break;
                    case "105":
                        $('#divcentreestate').html(waitSometime('Loading Centers...')).css('display', 'block').css('width', '550px');
                        cssLoad('files/CentreEstate.css');
                        scLoad('http://www.each.co.uk/JSON/EACH/files/CentreEstate.js' + XY.Reload);
                        break;
                    case "108":
                        $('#tickets').html(waitSometime('Loading tickets..')).css('display', 'block').css('width', '550px');
                        //cssLoad('files/CentreEstate.css');
                        scLoad('http://www.each.co.uk/JSON/EACH/files/tickets.js' + XY.Reload);
                        break;
                    case "109":
                        $('#divInvoiceGen').html(waitSometime('Loading Invoice Generation..')).css('display', 'block').css('width', '550px');
                        cssLoad('files/InvoiceGeneration.css')
                        scLoad('http://www.each.co.uk/JSON/EACH/files/InvoiceGeneration.js' + XY.Reload);
                        break;
                    case "110":
                        $('#divCash').html(waitSometime('Loading Cash..')).css('display', 'block').css('width', '550px');
                        cssLoad('files/cash.css')
                        scLoad('http://www.each.co.uk/JSON/EACH/files/cash.js' + XY.Reload);
                        break;

                } //IsMenu = 5=My Department,6=Add Req,7=Req,9=Add Prop,10=Props
                if (IsMenu != "19") set_cookie("eachmenu", IsMenu);
                $('#lhs').find('div.dMn').find('a[name=' + XY.WasIsMenu + ']').attr('name2', '0').trigger('mouseout');
                XY.WasIsMenu = IsMenu;
                fisMenu(IsMenu, 0);
            }
            else {
                if (XY.WasIsMenu == '7') EachList('r');
                else if (XY.WasIsMenu == '10' || XY.WasIsMenu == '5') EachList('p');
                else if (XY.WasIsMenu == '4') {
                    XY.Dep['#department'] = '';
                    Department('#department');
                }
                else if (XY.WasIsMenu == '6') {
                    AddPrRq('r'); //req
                }
                else if (XY.WasIsMenu == '9') {
                    AddPrRq('p'); //prop
                }
                //alert(XY.WasIsMenu);
            }
        }
        catch (e) {
            //alert(e.message);
        }

    });
    set_cookie("RecognizeEACH", '');
}

function cssLeft() {
    XY.Skins = '1';
    $('#lhs,#image').css('left', '570px');
    $('#middle').css('left', '0px');
}
function cssZero() {
    XY.Skins = '';
    $('#lhs,#image').css('left', '');
    $('#middle').css('left', '');
}
function loadMenu(did, bid, cid, Tit, Fsn, Srn, Pos, Rol, Phn, Mbl, Skp, Msn, Pcs, Llg, Plg, Cmp, Brn, Dep, Exp, Url, CmpT, DelT, Access, AnnS
        , LL, Reqs, Props, Mydepart, CoProps, CompLogo, BranchLogo, BrnPhone, listFind, owners, PublicProp, Skins) {
    try {
        XY.Skins = Skins;
        if (XY.Skins.length > 0) cssLeft();      
        _gDid = did; _gBid = bid; _gCid = cid;
        Owners = owners.replace(/~/g, '|');
        XY.Props = Props; XY.Reqs = Reqs;  
        XY.ListFind = listFind;
        XY.CompPic = ''; XY.Pos = Pos;
        XY.MyPic = Pcs; XY.CompLogo = CompLogo; XY.BranchLogo = BranchLogo;
        XY.Expiry = Exp; XY.LastLogin = Llg; XY.PrevLogin = Plg;
        XY.AgAd = (Rol == 'N' ? 0 : 1);
        XY.Url = Url;
        XY.Company = Cmp;
        XY.Phn = Phn; XY.Mbl = Mbl; XY.Skp = Skp; XY.Msn = Msn; XY.DelT = DelT; XY.Access = Access;
        if (LL.length > 0) LatLong = LL;
        var code = AgentABcode();
        XY.Alert = XY.Alert.replace('CODE', code);
        XY.Invoice = XY.Invoice.replace('CODE', code);
        XY.DepBra = Dep + ', ' + Brn;
        XY.Tit = Tit; XY.Fsn = Fsn; XY.Srn = Srn; XY.CoProps = CoProps;
        XY.StatusData = Tit + '|' + Fsn + '|' + Srn + '|' + Url + '|' + Cmp + '|' + Dep + '|' + Brn + '|' + BrnPhone;
        XY.Favo['p'] = ''; XY.Favo['r'] = ''; XY.Comm['p'] = ''; XY.Comm['r'] = ''; XY.Reje['p'] = ''; XY.Reje['r'] = '';
        LoadComments();
        XY.Dep['#homedep'] = '';
        PropReq();
        ListFind();
        oMn = $('#lhs').find('div.dMn');
        $(oMn).find('a[name=15]').attr('href', XY.Alert.replace('CID', _gCid).replace('BID', _gBid).replace('DID', _gDid).replace('NID', _gNid));
        $(oMn).find('a[name=18]').attr('href', XY.Invoice.replace('CID', _gCid).replace('BID', _gBid).replace('DID', _gDid).replace('NID', _gNid));
        $(oMn).find('a[name=5]').html('Co Properties ' + (CoProps == 0 ? '' : ' <font style="font-size:0.8em;font-weight:normal">[' + CoProps + ']</font>')).css('opacity', (CoProps == 0 ? 0.4 : ''));
        //if (CoProps>300)
        $(oMn).find('a[name=4]').html('My Department <font style="font-size:0.8em">[' + Mydepart + ']</font>');
        XY.PublicProp = parseInt(PublicProp);
        $.post(urlLoad, { list: 3, Nid: _gNid, Type: 244 }, function(d) {
            XY.StatSent = '';
            try {
                if (trim(d).length > 12) {
                    XY.StatSent = eval(d);
                    var si, sn = '';
                    for (var e = 0; e < XY.StatSent.length; e++) {
                        si = XY.StatSent[e].R.split(',')[1];
                        while (XY.StatSent[si] != undefined) si += 'a';
                        XY.StatSent[si] = XY.StatSent[e].R;
                    }
                }
            } catch (s) { }
        })
    }
    catch (e) {  }
}

var sec = 0, min = 40, LIMIT = 5;   // set the minutes
function LogOut() { window.location = "http://www.each.co.uk"; }
function prolong() {
    sec = 0; min = 40;
    $('#message').attr('name', '0').css('display', 'none'); //#homedep
    $('#lhs,#RESULT,#fsScope,#statusbar,#middle,#bars,#department,#head').css('opacity', ''); //,img
}
function countDown() {
    sec--;
    if (sec == -01) {
        sec = 59;
        min = min - 1;
    } else min = min;
    if (sec <= 9) { sec = "0" + sec; }
    time = (min <= 9 ? "0" + min : min) + ":" + sec;
    try {
        if (min < LIMIT && $('#message').attr('name') != '1') {
            $('#lhs,#RESULT,#fsScope,#statusbar,#middle,#bars,#department,#head').css('opacity', 0.3); //  ,img
            $('#message').attr('name', '1').html("You will be logged out in 5 minues<br><br><a href='javascript:prolong()'>Click here to extend session</a>"
                        ).css('display', 'block');
        }
        $('#Countdown').html(time);
    } catch (e) { }
    if (min == 0 && sec == 0) LogOut();
    else setTimeout(countDown, 1000);
}

var COLORS = { r: 50 + Rnd(6) * 30, g: 50 + Rnd(6) * 30, b: 50 + Rnd(6) * 30, uni: ''
	, aHex: new Array("0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F")
	, X: function() { this.r = 255 - this.r; this.g = 255 - this.g; this.b = 255 - this.b; }
	, Ad: function(v) { this.AdR(v); this.AdG(v); this.AdB(v); }
	, Mn: function(col) {
	    var bscol = col.replace('#', '');
	    if (bscol.toLowerCase().indexOf('rgb') == -1)
	        this.uni = new Array(this.h2d(bscol.substring(0, 2)), this.h2d(bscol.substring(2, 4)), this.h2d(bscol.substring(4, 6)));
	    else
	        this.uni = bscol.split('rgb(')[1].replace(')', '').replace(/, /g, ',').split(',');

	    var r = this.uni[0]; if (r > this.uni[1]) r = this.uni[1]; if (r > this.uni[2]) r = this.uni[2]; return r;
	}
	, Mx: function(col) {
	    var bscol = col.replace('#', '');
	    if (bscol.toLowerCase().indexOf('rgb') == -1)
	        this.uni = new Array(this.h2d(bscol.substring(0, 2)), this.h2d(bscol.substring(2, 4)), this.h2d(bscol.substring(4, 6)));
	    else
	        this.uni = bscol.split('rgb(')[1].replace(')', '').replace(/, /g, ',').split(',');

	    var r = this.uni[0]; if (r < this.uni[1]) r = this.uni[1]; if (r < this.uni[2]) r = this.uni[2]; return r;
	}
	, AdR: function(v) { this.r = (this.r + v) % 255; if (this.r < 0) this.r = 255 + this.r; }
	, AdG: function(v) { this.g = (this.g + v) % 255; if (this.g < 0) this.g = 255 + this.g; }
	, AdB: function(v) { this.b = (this.b + v) % 255; if (this.b < 0) this.b = 255 + this.b; }
	, RGB: function(r, g, b) { return '#' + this.HEX2((r < 0 ? 0 : r) % 256) + this.HEX2((g < 0 ? 0 : g) % 256) + this.HEX2((b < 0 ? 0 : b) % 256); }
	, RGB0: function() { return this.RGB(this.r, this.g, this.b); }
	, RGB0x: function() { return this.RGB(255 - this.r, 255 - this.g, 255 - this.b); }
	, HEX2: function(v) { return this.aHex[parseInt(v / 16)] + this.aHex[v % 16]; }
	, Add: function(col, add) {//$.browser.msie)
	    if (col == undefined) return '#fff';
	    var bscol = col.replace('#', '');
	    if (bscol.toLowerCase().indexOf('rgb') == -1)
	        this.uni = new Array(this.h2d(bscol.substring(0, 2)), this.h2d(bscol.substring(2, 4)), this.h2d(bscol.substring(4, 6)));
	    else
	        this.uni = bscol.split('rgb(')[1].replace(')', '').replace(/, /g, ',').split(',');

	    var rn = parseFloat(this.uni[0]) + parseFloat(add);
	    if (rn > 255) rn -= add; if (rn < 0) rn -= add;
	    var gn = parseFloat(this.uni[1]) + parseFloat(add);
	    if (gn > 255) gn -= add; if (gn < 0) gn -= add;
	    var bn = parseFloat(this.uni[2]) + parseFloat(add);
	    if (bn > 255) bn -= add; if (bn < 0) bn -= add;
	    return '#' + this.d2h(rn) + this.d2h(gn) + this.d2h(bn);
	}
	, Add3: function(col, add1, add2, add3) {//$.browser.msie)
	    var bscol = col.replace('#', '');
	    if (bscol.toLowerCase().indexOf('rgb') == -1) {
	        if (bscol.length > 5)
	            this.uni = new Array(this.h2d(bscol.substring(0, 2)), this.h2d(bscol.substring(2, 4)), this.h2d(bscol.substring(4, 6)));
	        else this.uni = new Array(this.h2d(bscol.substring(0, 1) + 'a'), this.h2d(bscol.substring(1, 2) + 'a'), this.h2d(bscol.substring(2, 3) + 'a'));
	    } else
	        this.uni = bscol.split('rgb(')[1].replace(')', '').replace(/, /g, ',').split(',');

	    var rn = parseFloat(this.uni[0]) + add1;
	    if (rn > 255) rn -= add1; if (rn < 0) rn -= add1;
	    var gn = parseFloat(this.uni[1]) + add2;
	    if (gn > 255) gn -= add2; if (gn < 0) gn -= add2;
	    var bn = parseFloat(this.uni[2]) + add3;
	    if (bn > 255) bn -= add3; if (bn < 0) bn -= add3;

	    return '#' + this.d2h(rn) + this.d2h(gn) + this.d2h(bn);
	}
	, d2h: function(d) { if (d.toString(16).length == 1) return "0" + d.toString(16); return d.toString(16); }
	, h2d: function(h) { return parseInt(h, 16); }
	, max: function(v, mx) { return v <= mx ? v : mx; }
}
function waitSometime(t) { return "<div class=Loading><img class=load src='http://www.each.co.uk/JSON/images/common/loadingcircles6.gif' />&nbsp;<span>" + t + "</span></div>"; }
function Error(subject, message) {
    $.post(urlLoad, { list: 3, Decode:1, Type: 29, Nid: subject, CID: message + ', NID=' + _gNid
        + ', url=' + escape(urlp) + ', browser version=' + $.browser.version
    , BID: 'miro.brada@yahoo.co.uk' }, function(d) { });
}
function Mail(from, to, fromtitle, message) {
    $.post(urlLoad, { list: 3, Type: 31, BID: fromtitle, DID: to, Nid: from, CID: message }, function(d) { });
}

function DepXY(i, ar, ad) {
    return '<span class=ad' + ad + ' title="' + (ad == 0 ? 'click to show/update\nmy administrators' : 'click to show/update\nmy agents') + '" name=' + i + '>'
            + (ar.length == 1 && ar[0] == '' ? '0' : ar.length)
            + '</span>';
}
function DepartmentName(hasalert, a) {
    var tmp = '<b>X</b>';
    if (hasalert == 0) tmp = 'X';
    if (a[2].length == 0) return tmp.replace('X', a[0] + ' ' + a[1]);
    return tmp.replace('X', a[0] + ' ' + a[1]) + '<br><span class=position>' + a[2] + '</span>';
}
function Department(depid) {
    XY.DepId = depid;
    if (XY.DepId != '#homedep') {
        XY.hHelpTx = "<div style='font-weight:bold'><font size=5>Help for My Department</font></div><br>This page shows a <b>Department overview</b>, and enables <b>switching to a colleague's account</b><br><br>"
                    + "<b>Department overview</b> shows Staff, number of Instructions, Direct Dial, Mobile, and Email.<br>Add by clicking on 'Add new Agent' or 'Add new Administrator'<br>Delete by clicking on 'del' for that person<br>EACH will confirm the addition or deletion by phone and then complete the update.<br><br><span style='display:inline-block;margin-top:2px;padding:1px;background:#d6eac2;color:#3B519C;width:370px'>Green Accounts – Agents with Status Checks up to date</span><br><span style='display:inline-block;margin-top:2px;padding:1px;background:#F8F1B4;color:#3B519C;width:370px'>Yellow Accounts - Agents with Status Checks over 8 weeks old</span><br><span style='display:inline-block;margin-top:2px;padding:1px;background:#EBC9C8;color:#3B519C;width:370px'>Red Accounts - Agents with Status Checks over 18 weeks old</span><br><span style='display:inline-block;margin-top:2px;padding:1px;background:#D4E4FF;color:#3B519C;width:370px'>Blue Accounts – Administrators	(switch Agent / Administrator at Home Page).</span><br><br>"
                    + "<b>Switch to a colleague's account</b> by clicking on the line for a person below.<br>You are logged in as the person shown in red on the top line.<br>The menu buttons apply to this person, eg 'My Properties', 'My Requirements'.<br><br>"
                    + "<b>AD column</b> enables you to add an Administrator or an Agent to your account<br>Click the numbered box to add an Agent or Administrator to your account<br>Select your Agents(s) or Administrator(s) from the branch tree<br>If the person is not listed, you need to add them first on 'add new admin' or 'add new agent'.";
    }
    if (XY.Dep[XY.DepId] == '') {// $(XY.DepId).html() == '') {
        $(XY.DepId).html(waitSometime('Loading your department'));

        var js = { list: 3, Type: 30, NID: _gDid };
        if (XY.DepId == '#homedep') {
            js.Type = 36;
            js.BID = XY.AgAd;
            js.NID = _gNid;
        }
        $.post(urlLoad, js, function(d) {
            XY.Dep[XY.DepId] = eval(d);
            DepartmentPop();
        });
    }
    $(XY.DepId).slideDown('fast');
}
function DepartmentReCount(nid, c, typ, nid2) {
    try {
        var n = parseInt($(XY.DepId).find('table[name=' + nid + ']').find('span.ad0,span.ad1').html());
        $(XY.DepId).find('table[name=' + nid + ']').find('span.ad0,span.ad1').html((n + c) + '');
        n = $(XY.DepId).find('table[name=' + nid + ']').attr('name3');
        var ar = XY.Dep[XY.DepId][n].R.split('|');
        if (typ == 101) {//agents
            if (c == 1) ar[9] += '~' + nid2;
            else ar[9] = ('~' + ar[9] + '~').replace('~' + nid2 + '~', '~');
        }
        else {
            if (c == 1) ar[10] += '~' + nid2;
            else ar[10] = ('~' + ar[10] + '~').replace('~' + nid2 + '~', '~');
        }
        XY.Dep[XY.DepId][n].R = ar[0] + '|' + ar[1] + '|' + ar[2] + '|' + ar[3] + '|' + ar[4] + '|' + ar[5] + '|' + ar[6] + '|' + ar[7] + '|' + ar[8] + '|' + ar[9].replace('~~', '~') + '|' + ar[10].replace('~~', '~') + '|' + ar[11];
    } catch (e) { }
}
function DepTree(ths, typ, ClickedNid, adagNIDS) {//nm, 
    XY.STAYdep = 1;    //var ar = XY.Dep[XY.DepId][nm].R.split('|');
    //$(o).find('div.Agent').slideUp('fast');
    var o = $(XY.DepId).find('div.list[name=Dp|0|' + ClickedNid + ']');
    if ($(ths).attr('name2') != '1') {
        $(XY.DepId).find('span.ad0,span.ad1').attr('name2', '0');
        $(ths).attr('name2', '1');
        Tree = '';
        treeHash = _gCid + typ;
        JSON['Dp'] = new Array();
        JSON['Dp'][ClickedNid] = { N: ',' + adagNIDS + ',|,' + _gDid + ',|,' + _gBid + ',|,' + _gCid + ',' };
        if (TreeC[treeHash] != undefined) {
            if (TreeC[treeHash].length == 0)
                $('div.list[name=Dp|0|' + ClickedNid + ']').find('div.Agent').html('There are no ' + (typ == 101 ? 'admins' : 'agents') + ' within your company<br>Create one, if you need').css('display', 'block');
            else fAgents('Dp|0|' + ClickedNid, typ);
        }
        else {
            Criteria = { list: 3, Nid: _gCid, Type: typ };
            $.post(urlLoad, Criteria, function(output) {
                TreeC[treeHash] = eval(output);
                if (TreeC[treeHash].length == 0) {
                    $('div.list[name=Dp|0|' + ClickedNid + ']').find('div.Agent').html('There are no ' + (typ == 101 ? 'admins' : 'agents') + ' within your company<br>Create one, if you need').css('display', 'block');
                    return;
                }
                if (adagNIDS.length < 4) {
                    TreeC[treeHash][0].IS = 1; TreeC[treeHash][0].OPEN = 2;
                }
                fAgents('Dp|0|' + ClickedNid, typ);
            });
        }
    }
    else {
        $(ths).attr('name2', '0');
        $(o).find('div.Agent').slideUp('fast');
    }
}
function remZero1(s) {
    if (s.substring(0, 1) == '0') return s.substring(1, s.length).replace(/ /g, '');
    return s.replace(/ /g, '');
}
function DepartmentPop() {//'+_gNid+'    
    var ar, hD = '', hDepList = '<table title="click to switch to this user" border=0 name=NID name2=COLOR name3=xID name4=AgAd cellspacing=0 cellpadding=0 style="width:560px;background:COLOR;border-top:1px solid #fff;cursor:pointer"><tr><td style="width:200px">NAME</td><td style="width:25px;text-align:right">PROP</td><td style="width:25px;text-align:right">REQ</td><td style="width:25px;text-align:right">&nbsp;DDI</td><td style="width:25px;text-align:center">&nbsp;MOBILE&nbsp;</td><td style="width:180px"><a href="mailto:EMAIL">EMAIL</a></td><td  name3=0 style="width:40px;vertical-align:middle">xAD</td><td style="width:40px" name3=0><span name=NID name4=xID  title="click to request\ndeletion by EACH" class=del>del</span></td></tr></table><div name="Dp|0|NID" class=list><div class=Agent></div></div>';
    XY.DepAdmins = ''; XY.Agents = ''; XY.HomeDepAgAd = '';
    $("#homedep,#department").html('');
    try {//depadd '<a border=0 href="callto://' + ar[4] + '"
        hD = '';
        for (var i = 0; i < XY.Dep[XY.DepId].length; i++) {
            ar = XY.Dep[XY.DepId][i].R.split('|');
            if (ar[11] == 'S' && XY.DepAdmins.indexOf(ar[0]) == -1) XY.DepAdmins += ar[0] + '~' + ar[2].split('~')[0] + '~' + ar[2].split('~')[1] + '~' + ar[3] + '|';
            else XY.Agents += ar[0] + '~' + ar[2].split('~')[0] + '~' + ar[2].split('~')[1] + '~' + ar[3] + '|';
            if (XY.DepId == '#homedep') XY.HomeDepAgAd += '~' + ar[0]; //if(ar[0] == _gNid)            
            if (XY.Dep[XY.DepId][i].D != 1)
                hD += hDepList.replace('AgAd', ar[11]).replace(/COLOR/g, Status[ar[8]]).replace(/NID/g, ar[0]
                            ).replace('NAME', DepartmentName(ar[1], ar[2].split('~'))
                            ).replace(/xID/g, i
                            ).replace('PROP', ar[6]).replace('REQ', ar[7]
                            ).replace('DDI', (ar[4].length < 4 ? '' : '<a border=0 href="skype:+44' + remZero1(ar[4]) + '?call"><img border=0 title="will launch Skype with number ' + ar[4] + '" src="http://www.each.co.uk/images/common/phone.gif" /></a>')
                            ).replace('MOBILE', (ar[5].length < 4 ? '' : '<a border=0 href="skype:+44' + remZero1(ar[5]) + '?call"><img border=0 title="will launch Skype with number ' + ar[5] + '" src="http://www.each.co.uk/images/common/mobile.gif" /></a>')
                            ).replace('EMAIL', ar[3]
                            ).replace('EMAIL', ar[3].split('@')[0] + '<br><span style="float:right">@' + ar[3].split('@')[1] + '</span>'
                            ).replace('xAD', (ar[11] == 'S' ? DepXY(i, ar[10].split('~'), 1)
                                            : DepXY(i, ar[9].split('~'), 0)
                                        )
                            ); //(ar[9].length == 0 ? '<span name=' + i + ' class=ad0>0</span>' :)
        }
    } catch (e) { }
    var addb = '<a class=ct>add new agent</a><a class=ct>add new admin</a>'; // style='width:150px'
    if (XY.DepId == '#homedep') addb = "<a name3='change' class=ct>change my " + (XY.AgAd == 0 ? 'Admins' : 'Agents') + "</a><br><div name='Dp|0|" + _gNid + "' class=list><div class=Agent></div></div>";
    if (hD == '') {
        hD = addb + 'There is nobody in your department yet...';
        if (XY.DepId == '#homedep') hD = addb.replace('change', 'add') + (XY.AgAd == 0 ? 'You have no Admin/PA/Sec assigned yet' : 'You have no Negotiator assigned yet');
    }
    else
        hD = addb + '<div id=addagent2></div><div id=depmessage></div><table border=0 cellspacing=0 cellpadding=0 style="width:560px;margin-top:2px;background:#0F2A86;border-bottom:1px solid #000;color:#eef;font-weight:bold;padding-top:2px;padding-bottom:2px"><tr><td style="width:200px">Agent</td><td style="width:25px;text-align:right" title="number of\nProperties">Prop</td><td style="width:25px;text-align:right" title="number of\nRequirements">Req</td><td style="width:25px;text-align:center" title="Direct Dial">&nbsp;</td><td style="width:25px;text-align:center" title="direct mobile">&nbsp;</td><td style="width:180px">email</td><td style="width:40px"></td><td style="width:40px">&nbsp;</td></tr></table>'
                + hD;

    $(XY.DepId).html(hD).find('table'
                ).slice(1, 100).mouseover(function() { $(this).css('opacity', 0.6); }
                ).mouseout(function() { $(this).css('opacity', ''); }
                ).click(function() {
                    if (XY.STAYdep > 0) { XY.STAYdep = 0; return; }
                    $(XY.DepId).find('table[name=' + _gNid + ']').each(function() { $(this).css('border', '').css('border-top', '1px solid #fff').css('background', $(this).attr('name2')); });
                    _gNid = $(this).css('border-top', '1px solid #777').css('background', COLORS.Add($(this).css('background'), -50)).attr('name');
                    $.post(urlLoad, { list: 3, Nid: _gNid, Type: 158 }, function(d) {
                        var a = eval(d)[0].R.split('|');
                        _gNid = a[0]; XY.Em = a[33];
                        loadMenu(a[1], a[2], a[3], a[4], a[5], a[6], a[7], a[8], a[9], a[10], a[11], a[12], a[13], a[14], a[15], a[16], a[17], a[18], a[19], a[20], a[21], a[22], a[23], a[24], a[25], a[26], a[27], a[28], a[29], a[30], a[31], a[32], a[38], a[37], a[40], a[41]);
                        XY.OrigUser = '';
                        if (XY.Em != MyEmail) XY.OrigUser = 'back to ' + XY.OrigMenu[5] + ' ' + XY.OrigMenu[6]; // +' account';
                        if (IsMenu == 3) {
                            $(XY.DepId).html('');
                            Department(XY.DepId);
                            AgAd();
                        }
                        xStatus(a);
                    })
                }
             ).find('span.ad0,span.ad1').click(function() {
                 try {
                     var ar = XY.Dep[XY.DepId][$(this).attr('name')].R.split('|'), typ = $(this).attr('class') == 'ad0' ? 101 : 102;
                     DepTree(this, typ, ar[0], (typ == 101 ? ar[9] : ar[10]));
                 } catch (ed) {
                     //alert(ed.message); 
                 }
             });
    $(XY.DepId).find('span.del').mouseover(function() {
        $(XY.DepId).find('table[name=' + $(this).attr('name') + ']').each(function() { $(this).css('background', '#fbb'); }); //red
    }).mouseout(function() {
        if (XY.DepClick == 1) return;
        $(XY.DepId).find('table[name=' + $(this).attr('name') + ']').each(function() { $(this).css('background', $(XY.DepId).find('table[name=' + $(this).attr('name') + ']').attr('name2')); }); //.css('background', '');
        if (_gNid == $(this).attr('name')) {
            $(XY.DepId).find('table[name=' + _gNid + ']').each(function() { $(this).css('border-top', '1px solid #777').css('background', COLORS.Add($(this).css('background'), -50)); });
        }
    }).click(function() {
        XY.STAYdep = 1; XY.DepClick = 1;
        if (IsAdmin > 0) {
            if (confirm("Do you really want to remove this agent from Department?")) {
                $(XY.DepId).find('[name=' + $(this).attr('name') + ']').css('display', 'none');
                $.post(urlLoad, { list: 3, Nid: $(this).attr('name'), Type: 35 }, function(d) { });
                XY.Dep[XY.DepId][$(this).attr('name4')].D = 1;
            }
            XY.DepClick = 0;
        }
        else {
            $(o).find('div.Agent').slideUp('fast');
            var agad = XY.Dep[XY.DepId][$(this).attr('name4')].R.split('|');
            agad[11] = (agad[11] == 'S' ? 'ADMIN' : 'Agent');
            var name = agad[2].split('~');
            if (name[2].length > 1) name[2] = ' (' + name[2] + ')';
            var o = $(XY.DepId).find('div.list[name=Dp|0|' + agad[0] + ']');
            $(XY.DepId).find('span.ad0[name2=1],span.ad1[name2=1]').trigger('click');
            if ($(o).find('div.Agent').find('div.del').length == 0 || $(o).find('div.Agent').css('display') == 'none')
                $(o).find('div.Agent').html('<div class=del>Do you want to delete ' + agad[11] + ' <b>' + name[0] + ' ' + name[1] + name[2] + '</b> from your Department?<br><br>Please say where they have moved to (Department, Branch, Agency/Property Co/Council/Retired)'
                            + '<br><br><input /><span class=del>confirm</span><div style="clear:both"></div></div>'
                            ).slideDown('fast').find('span.del').mouseover(function() { $(this).css('opacity', 0.6); }).mouseout(function() { $(this).css('opacity', ''); }
                            ).click(function() {
                                if ($(o).find('input').val().length < 2) {
                                    alert('You must write where the ' + agad[11] + ' moved!');
                                    return;
                                }
                                $('#depmessage').css('background-color', '').html('request to delete ' + agad[11] + '<br>' + name[0] + ' ' + name[1] + name[2] + ' was sent to EACH...').css('display', 'block');
                                XY.DepClick = 0;
                                $(o).find('div.Agent').slideUp('fast');
                                Mail(MyEmail, 'feedback@each.co.uk', XY.Company, 'Please delete XBRX ' + agad[3] + 'XBRX' + agad[11] + 'XBRXXB1X' + name[0] + 'XB2X ' + name[1] + 'XBRX' + name[2] + 'XBRXfrom ' + XY.DepBra + 'XBRXleft / moved to: XB1X' + $(o).find('input').val() + 'XB2X'); // + ' should be deleted from my department');
                            });
            else $(o).find('div.Agent').html('');
            XY.DepClick = 0;
        }
    });
    $(XY.DepId).find('table[name=' + _gNid + ']').each(function() { $(this).css('border-top', '1px solid #777').css('background', COLORS.Add($(this).css('background'), -50)); });
    $(XY.DepId).find('.ct').mouseover(function() { $(this).css('opacity', 0.5); }).mouseout(function() { $(this).css('opacity', ''); }
                        ).click(function() {
                            var o = this, role = ($(this).html().indexOf('dmin') > -1 ? 'S' : 'N');
                            if (XY.DepId == '#homedep') {
                                if ($(this).html() == 'close') $(this).html('change my ' + (XY.AgAd == 0 ? 'Admins' : 'Agents'));
                                DepTree(this, (role == 'S' ? 101 : 102), _gNid, XY.HomeDepAgAd);
                            }
                            else {
                                if ($(this).attr('name') != '1') {
                                    $(o).find('div.Agent').slideUp('fast');
                                    $('#department').find('.ct').attr('name', '0').css('background', 'url("http://www.4prop.com/JSON/images/common/Rolls/MyProp0.gif")').css('color', '')
                                    $(this).attr('name', '1').css('background', 'url("http://www.4prop.com/JSON/images/common/Rolls/MyProp.gif")').css('color', '#eef');
                                    $('#addagent2').html('<table cellspacing=0 cellpading=0><td colspan=2>Please fill in as much information as possible</td></tr><tr><td><b>Email</b></td><td><input value="@'
                                                    + XY.Em.split('@')[1] + '" /></td></tr><tr><td>Department</td><td><select id=slDep></select>&nbsp;*</td></tr><tr><td>Position</td><td><select onchange="sPositions(this)" class=slPos></select></td></tr><tr><td>Title</td><td><input id=tit /></td></tr><tr><td><b>Firstname</b></td><td><input id=fsn />&nbsp;*</td></tr><tr><td><b>Surname</b></td><td><input id=srn />&nbsp;*</td></tr><tr><td>Phone/DDI</td><td><input id=ddi /></td></tr><tr><td>Mobile</td><td><input id=mbl /></td></tr><tr><td></td><td align=right><input type=button class=Save value="'
                                                    + (IsAdmin == 0 ? 'Send request to EACH' : 'SAVE') + '"/></td></tr></table>'
                                                   ).slideDown('slow'
                                                   ).find('input.Save').mouseover(function() { $(this).css('background-color', '#eef').css('color', '#0F2A86'); }).mouseout(function() {
                                                       $(this).css('background-color', '').css('color', '#eef');
                                                   }).click(function() {
                                                       var ins = $('#addagent2').find('input[type=text]');
                                                       var em = $(ins).slice(0, 1).val().toLowerCase();
                                                       if (em.length < 0 || em.indexOf('@') < 1) {
                                                           $(ins).slice(0, 1).focus().css('background', '#faa');
                                                           alert('Please enter valid email');
                                                           return;
                                                       }
                                                       if ((XY.DepAdmins + XY.Agents).toLowerCase().indexOf(em) > -1) {
                                                           $(ins).slice(0, 1).focus().css('background', '#faa');
                                                           alert('The email is already in use\nPlease enter unique email!');
                                                           return;
                                                       }
                                                       var fs = $('#fsn').val();
                                                       if (fs.length == 0) {
                                                           $('#fsn').focus().css('background', '#faa');
                                                           alert('Please enter firstname');
                                                           return;
                                                       }
                                                       var sn = $('#srn').val();
                                                       if (sn.length == 0) {
                                                           $('#srn').focus().css('background', '#faa');
                                                           alert('Please enter surname');
                                                           return;
                                                       }
                                                       var dep = $('#slDep').find('option:selected').html(), tit = $('#tit').val();
                                                       var ph = $('#ddi').val(), mb = $('#mbl').val();
                                                       var ps = $(XY.DepId).find('.slPos').val().replace('Enter new position here', '');
                                                       if (IsAdmin == 0) {// || 1==1 
                                                           $('#depmessage').css('background-color', '#050').html('request to add new ' + (role == 'S' ? 'ADMIN ' : 'Agent <br>') + tit + ' ' + fs + ' ' + sn + '<br>' + ps + ' ' + ph + ',' + mb + ', to ' + dep + ' was sent to EACH...').css('display', 'block');
                                                           Mail(MyEmail, 'feedback@each.co.uk', XY.Company, 'Please add XBRX new ' + (role == 'S' ? 'ADMIN ' : 'Agent') + 'XBRX' + em + 'XBRX' + tit + 'XBRX' + fs + 'XBRX' + sn + 'XBRX' + ps + 'XBRX' + dep + 'XBRX' + ph + 'XBRX' + mb);
                                                           $('#addagent2').slideUp('slow');
                                                       }
                                                       else {
                                                           var msg = 'new agent was created...';
                                                           if ($('#slDep').val() != _gDid) msg = 'The new ' + (role == 'S' ? 'Admin' : 'Agent') + ' created, but not in the department below';
                                                           $.post(urlLoad, { list: 3, Did: $('#slDep').val(), Cid: _gCid, Bid: _gBid
                                                , NID: em + '~' + tit + '~' + fs + '~' + sn + '~' + ph + '~' + mb + '~' + ps + '~' + role
                                                , Type: 34
                                                           }, function(d) {
                                                               if (eval(d)[0].R == 0) {
                                                                   $('#depmessage').css('background-color', '#500').html('the entered email ' + em + ' already exists in EACH database').css('display', 'block');
                                                               }
                                                               else {
                                                                   $(o).attr('name', '0').css('background-color', '');
                                                                   $('#addagent2').slideUp('slow');
                                                                   $('#depmessage').css('background-color', '#050').html(msg).css('display', 'block');
                                                                   if (msg != 'new agent was created...') return;
                                                                   for (var i = XY.Dep[XY.DepId].length + 1; i > 0; i--) XY.Dep[XY.DepId][i] = XY.Dep[XY.DepId][i - 1];
                                                                   XY.Dep[XY.DepId][0] = { R: eval(d)[0].R + '|0|' + fs + '~' + sn + '~' + ps + '|' + em + '|' + ph + '|' + mb + '|0|0|' + (role == 'S' ? 3 : 0) + '|||' + role };
                                                                   DepartmentPop();
                                                               }
                                                           });
                                                       }
                                                   })
                                    $.post(urlLoad, { list: 3, Bid: _gBid, Type: 40
                                    }, function(d) {
                                        var dep = '', dp = eval(d);
                                        try {
                                            for (var p = 0; p < dp.length; p++)
                                                dep += '<option value=' + dp[p].R.split('|')[0] + (dp[p].R.split('|')[0] == _gDid ? ' selected' : '') + ' >' + dp[p].R.split('|')[1] + '</option>';

                                        } catch (e) { }
                                        $('#slDep').html(dep).val(_gDid);
                                        $(XY.DepId).find('.slPos').html(PositionPop());
                                    });

                                }
                                else {
                                    $(this).attr('name', '0').css('background', 'url("http://www.4prop.com/JSON/images/common/Rolls/MyProp0.gif")').css('color', '');
                                    $('#addagent2').slideUp('slow');
                                }
                            }
                        });
                        if (XY.DepId == '#homedep') $(XY.DepId).find('.del').css('display', 'none');
                        else {
                            $(XY.DepId).find('table:last').after('<div id="CompanyTree" class=list style="margin-top:27px" name="Cm|0|0"><div style="display:block" class=Agent>'
                                        + waitSometime('Loading Company tree...') + '</div></div>');
                            JSON['Cm'] = new Array();
                            JSON['Cm'][0] = { N: ',' + _gCid + ',|,,|,,|,' + _gCid + ',' };
                            Tree = ''; treeHash = _gCid;
                            XY.NoMove = 1;
                            if (TreeC[treeHash] == undefined)
                                $.post(urlLoad, { list: 3, Nid: _gCid, Type: 101, UNI: 'A' }, function(output) {
                                    TreeC[treeHash] = eval(output);
                                    fAgents('Cm|0|0', 107);
                                });
                            else fAgents('Cm|0|0', 107);                                                  
                        }
}

function sPositions(o) {
    if ($(o).find('option:selected').html() == 'Other Position')
        $(o).parent().html('<input onclick="this.select()" style ="color:red;font-weight:bold" value="Enter new position here" class=slPos />');
}
function reLtLn(lt, ln) {
    try {
        XY.J.Lt = lt; XY.J.Ln = ln; XY.LtLnSet = 1;
        var ll = new google.maps.LatLng(XY.J.Lt, XY.J.Ln);
        $(XY.L).find('img.imgblock').attr('src', latitude.replace(/LAT/g, XY.J.Lt).replace(/LON/g, XY.J.Ln));
        XY.J.marker.setPosition(ll);
        XY.J.gmap.setCenter(ll);
    } catch (r) { }
}


function StatusMsg(msg) {
    $('#statusmsg').html(msg).css('display', 'block').css('opacity', '').animate({ opacity: 0.3 }, 1700, function() { $('#statusmsg').css('display', 'none') });
}
function PropReq() {
    $('#lhs').find('div.dMn').find('a[name=10]').html('Properties' + (XY.Props == 0 ? '' : ' <font style="font-size:0.8em;font-weight:normal">[' + XY.Props + ']</font>')).css('opacity', (XY.Props == 0 ? 0.4 : ''));
    $('#lhs').find('div.dMn').find('a[name=7]').html('Requirements' + (XY.Reqs == 0 ? '' : ' <font style="font-size:0.8em;font-weight:normal">[' + XY.Reqs + ']</font>')).css('opacity', (XY.Reqs == 0 ? 0.4 : ''));
}
function ListFind() {//(XY.ListFind == 0 ? '' : )
    $('#lhs').find('div.dMn').find('a[name=14]').html('Listings / Find' + ' <font style="font-size:0.8em;font-weight:normal">[' + XY.ListFind + ']</font>'); //.css('opacity', (XY.ListFind == 0 ? 0.4 : ''));
}
function Nullify() {
    jsCriteria = { list: 1 }; aCount = new Array(0, 0, 0, 0, 0, 0), aIS = new Array(0, 0, 0, 0, 0, 0, 0);
    JSON = new Array(), IS = 3, STAY = 0, atmpO = new Array(), itmpO = 0;
    XY.Crit = '', XY.Crit2 = '', XY.Views = new Array(); XY.Counts = new Array(); XY.States = new Array(); XY.Maps = new Array(); XY.Markers = new Array();
    XY.aMatchPages = new Array({}, {}, {}, {}, {}, {});
    XY.AlertListing = 2;XY.PublicListing = 7;XY.PublicListingOther = 7;XY.PublicListingOtherAgents = 7;
    XY.New = XY.It + 'n';
    $('#RESULT').css('margin-top', '0px');
    XY.AddedOnly = 0;
}
function HideAll() {//
    $('#lhs').find('div.dMn').find('a[name2=1]').attr('name2', '0').trigger('mouseout');    //#Summary,
    HideAll2();
}
function HideAll2() {
    $('#explain,#fsScope,#head,#home,#homedep,#switchuser,#department,#RESULT,#EDIT,#fsFind,#comr,#comp,#favr,#favp,#uploaded,#profile,#archive,#Find,#AgentAB,#Email2,#divcentreestate,#tickets,#divInvoiceGen,#divCash').css('display', 'none');
    $('#Find,#Email2').html('');
}
function LoadTextEditor() {
    if (XY.txEditor > 0) return;
    XY.txEditor++;
    scLoad('http://www.each.co.uk/JSON/Utilities/textbox/nicEdit.js');
}

function ShowMailBox(id) {
    if (XY.Texter == '')
        XY.Texter = new nicEditor({ fullPanel: true }).panelInstance(id);
}

function LoadComments() {
    // alert(get_cookie("RecognizeEACH").length+', _gNid='+_gNid);
    try {
        if (get_cookie("RecognizeEACH").length == 0) {
            $.post(urlLoad, { list: 3, Nid: _gNid, Type: 20 }, function(d) {
                //alert(d);
                if (eval(d).length > 0) {
                    var a = eval(d)[0].R.split('*');
                    XY.Favo['p'] = a[0]; XY.Favo['r'] = a[1];
                    XY.Comm['p'] = a[2]; XY.Comm['r'] = a[3];
                    XY.Reje['p'] = a[4]; XY.Reje['r'] = a[5];
                    CookieSet();
                    Favourites();
                    Comments();
                }
                var gm = get_cookie("eachmenu");
                if (gm != "11" && gm != "12") return;
                fisMenu(gm, 1);
            });
        }
        else {
            CookieLoad();
            Favourites();
        }
    }
    catch (e) {
        alert(e.message);
    }
}
function FavouritesN() { return (XY.Favo['p'] + XY.Favo['r']).split('|').length - 1; }
function FavouritesNpr(pr) { return (XY.Favo[pr]).split('|').length - 1; }
function CommentsN() { return ((XY.Comm['p'] + XY.Comm['r']).split('|').length - 1); }
function CommentsNpr(pr) { return ((XY.Comm[pr]).split('|').length - 1); }
function Favourites() {
    if (FavouritesN() > 0) $('#lhs').find('div.dMn').find('a[name=12]').css('opacity', '').html('Favourites [' + FavouritesN() + ']');
    else $('#lhs').find('div.dMn').find('a[name=12]').css('opacity', 0.4).html('Favourites');
}
function Comments() {
    if (CommentsN() > 0) $('#lhs').find('div.dMn').find('a[name=11]').css('opacity', '').html('Comments [' + CommentsN() + ']');
    else $('#lhs').find('div.dMn').find('a[name=11]').css('opacity', 0.4).html('Comments');
}
function MenuDsc(nm, on) {    //.css('margin-top', -25 * (1 + parseInt(tx.length / 75) / 2)	     )
    $('#lhs').find('div.dMn:first').find('span.MnDsc[name2!=' + nm + ']').css('display', 'none'); //.find('MnDsc[]')
    if (on > 0) {
        $('#lhs').find('div.dMn:first').find('span.MnDsc[name2=' + nm + '][name=0]').css('opacity', 0).attr('name', 0).css('display', 'none').animate({ opacity: 1 }, 1000, function() {
            if ($(this).attr('name') == 0) $(this).css('display', 'block').attr('name', 2);
        });
        $('#lhs').find('div.dMn:first').find('span.MnDsc[name2=' + nm + '][name=2]').css('display', 'block');
    }
    else {
        $('#lhs').find('div.dMn:first').find('span.MnDsc[name2=' + nm + ']').attr('name', 2); //.animate({ opacity: 0 }, 500, function() { $(this).css('display', 'none').attr('name', 0); })
        if (nm != 20 || IsMenu == 101
        ) $('#lhs').find('div.dMn:first').find('span.MnDsc[name2=' + nm + ']').animate({ opacity: 0 }, 500, function() { $(this).css('display', 'none').attr('name', 0); });
        else {
        }
        //alert(IsMenu);
    }
}
function fisMenu(n, go) {
    IsMenu = n;
    oMn = $('#lhs').find('div.dMn').find('a[name=' + IsMenu + ']');
    if (go == 0) $(oMn).trigger('mouseover').attr('name2', '1').trigger('mouseout');
    else $(oMn).trigger('click');
}

function UploadedR(dt) {
    $('#uploadedr').html(waitSometime('Loading Uploaded Requirements'));
    XY.Crit = "u"; //
    var J, ar = dt.split(' '), mmyydd = ret2(parseFloat(aMd[ar[1]]) + 1) + '.' + ar[2].substring(2, 4) + '.' + ret2(ar[0]);
    $.post(urlLoad, { List: 1, Requirement: 1, date: mmyydd }, function(d) {
        JSON['ru'] = eval(d);
        for (var i = 0; i < JSON['ru'].length; i++) {
            try {
                J = JSON['ru'][i]; J.ck = 0; J.rc = 0; J.block = 0; J.II = i; J.found = 1;
                J.It = 'ru';
                J.View = 0; J.tp = J.T.split('|')[0]; ITs[J.I] = i;
                J.Wd = J.At.indexOf('.doc') + J.At.indexOf('.rtf'); J.Pf = J.At.indexOf('.pdf'); J.Rej = 0; J.Cl = J.R.split('|')[7].length + J.R.split('|')[8].length + J.R.split('|')[14].length;
                J.Crit = 'r'; J.IS = 3; J.My = 1; J.MyAg = 1; J.M = 0;
            } catch (e) { }
        }
        fBars('#uploadedr', BarTitles({ Crit: 'r' }, 'ru'));
        if (JSON['ru'].length > 0) $('#uploadedr').find('table.bar').find('td.count').html(CountLastArrayEmpty(JSON['ru'].length));
        $('#uploadedr').find('table.bar').find('input.uploadedr').val(dt);
        setTimeout(function() { View('ru|r', 2); }, 1500);
    });
}
function UploadedP(dt) {
    $('#uploadedp').html(waitSometime('Loading Uploaded Properties'));
    XY.Crit = "u";
    var J, ar = dt.split(' '), mmyydd = ret2(parseFloat(aMd[ar[1]]) + 1) + '.' + ar[2].substring(2, 4) + '.' + ret2(ar[0]);
    $.post(urlLoad, { List: 1, date: mmyydd }, function(d) {
        JSON['pu'] = eval(d);
        for (var i = 0; i < JSON['pu'].length; i++) {
            try {
                J = JSON['pu'][i]; J.ck = 0; J.rc = 0; J.block = 0; J.II = i; J.found = 1;
                J.It = 'pu'; J.View = 0; J.tp = J.T.split('|')[0]; ITs[J.I] = i;
                J.Wd = J.At.indexOf('.doc') + J.At.indexOf('.rtf'); J.Pf = J.At.indexOf('.pdf'); J.Rej = 0; J.Cl = J.R.split('|')[7].length + J.R.split('|')[8].length + J.R.split('|')[14].length;
                J.Crit = 'p'; J.IS = 3; J.My = 1; J.MyAg = 1; J.M = 0;
            } catch (e) { }
        }
        fBars('#uploadedp', BarTitles({ Crit: 'p' }, 'pu')); //
        if (JSON['pu'].length > 0) $('#uploadedp').find('table.bar').find('td.count').html(CountLastArrayEmpty(JSON['pu'].length));
        $('#uploadedp').find('table.bar').find('input.uploadedp').val(dt);
        setTimeout(function() { View('pu|p', 2); }, 1500);
    });
}

function loadingAttPic() {
    $(ListId(XY.iti)).find('div.loadfileatt').css('display', 'inline-block');
}

function loadingFile(tit, fn) {
    if (IsMenu == "103") {
        var afn = fn.split('\\');
        XY.AttFiles[XY.EmailsAtt] = afn[afn.length - 1];
        $(XY.L).find('div.loadfile').css('display', 'inline-block').html('Loading file');
    }
    else {
        if (tit == '2')
            $('#iMyPic').css('display', 'none').parent().find('div.loadfile').css('display', 'inline-block');
        else
            $('#iLogo').css('display', 'none').parent().find('div.loadfile').css('display', 'inline-block');
    }
}
function logo(filend, sz, cnid, cbid) {    //cnid=2, negotiator, cnid=1, company
    if (IsMenu == "103") {
        $(XY.L).find('div.loadfile').css('display', 'none');
        if (XY.Emails.length > 0) XY.Emails += '^';
        XY.Emails += XY.EmailsAtt + '.' + filend;
        var files = $(XY.L).find('span.files').html();
        $(XY.L).find('span.files').html(files + AttHtml(0, XY.EmailsAtt, filend));
        AttDeleteFn();
        AttViewFn('span.files');
        XY.EmailsAtt += 'a';
        $(XY.L).find('iframe.att').attr('src', 'http://www.each.co.uk/alert/uploadlogo.aspx?Tit=4&path=a' + _gNid + '&NID=' + XY.EmailsAtt);
    }
    else {
        var rnd = '?lastmod=' + Rnd(9) + Rnd(9) + sz + Rnd(9);
        $('#iMyPic,#iLogo').css('display', 'block').parent().find('div.loadfile').css('display', 'none');
        if (cnid == 2) {
            $('#iMyPic').css('display', 'none').attr('src', 'http://www.each.co.uk/images/thumb/CompanyLogos/' + ret10(_gCid) + '/' + _gNid + '.' + filend + rnd);
            setTimeout(function() { $('#iMyPic').slideDown('slow'); }, 700);
        }
        else if (cnid == 1) {
            $('#iLogo').css('display', 'none').attr('src', 'http://www.each.co.uk/images/thumb/CompanyLogos/' + ret10(_gCid) + '/' + (sz > 0 ? _gBid : cbid) + '.' + filend + rnd);
            setTimeout(function() { $('#iLogo').slideDown('slow'); }, 700);
        }
        if (sz > 0) $.post(urlLoad, { list: 3, NID: _gNid, Type: 111, Did: (cnid == 2 ? 'picture' : 'logo'), Bid: filend }, function(e) { });
    }
}

function Home() {
    XY.hHelpTx = '<div style="font-weight:bold"><font size=5>Help for My Admin/Home</font></div><br><div>You are logged in as the person shown in red above.</div>'
                + '<div>The menu buttons apply to this person, eg ‘My Properties’ are for this person</div>'
                + '<div>Switch between Agents’ accounts via menu ‘My Department’ and click on the bar with their name</div>'
                + '<br><div>AGENTS</div><div>Administrator(s) listed help maintain your Properties, Status Checks, and the members of your Department</div>'
                + '<div>Administrators are sent Property Status Checks first, and we only send them to you as a last resort</div>'
                + '<div>Select your Administrator(s) from the branch tree</div>'
                + '<div>If your Administrator is not listed, you need to add them first on menu ‘My Department’</div>'
                + '<br><div>ADMINISTRATORS</div>'
                + '<div>Agents listed are for those that you maintain their Properties, and Status Checks</div>'
                + '<div>‘Add a new Agent’ enables you to add Agents from the branch tree</div>'
                + '<div>If one of your Agents is not listed, you need to add them first on menu ‘My Department’</div>'
                + '<br><div>ADMINISTRATORS and STATUS CHECKS</div>'
                + '<div>At 8 weeks since last updated, we email you a Status Check. If missed then we email you at 18 weeks.</div>'
                + '<div>At 20 weeks we email both you and your Agent.</div>'
                + '<div>Agents producing Reports can see the last status date and will not need to contact you if recently done</div>'
                + '<div>Status Checks can be done under menu ‘Co Properties’, tab at the top ‘My Agents’ , STATUS button</div>'
                + '<div style="padding-left:15px">if no STATUS button, then all Properties are up to date.</div>'
                + '<br><div>You can do everything that we can do at EACH, except:</div>'
                + '<div>1)  add and delete staff – enter the details and EACH will check and complete the action,</div>'
                + '<div style="padding-left:15px">(if deleting please re-allocate Properties and Requirements to other Agents first)</div>'
                + '<div>2) change email addresses,</div>'
                + '<div>3) change Company name, Branch name, or Department name,</div>'
                + '<div>4) change Branch address.</div>';
    $('#home').html('<div class=homebar>ADMIN / HOME <span style="float:right">last login: ' + XY.LastLogin + ', previous: ' + XY.PrevLogin + '</span></div>'
            + '<fieldset class=homtit><legend>Account Summary<div class="agad"><span class=ag>change to an Agent</span>&nbsp;<span class=ad>change to an Admin/PA/Sec</span></div></legend>'
            + '<div style="float:left;clear:both">You have ' + XY.Props + ' current properties</div><div style="float:right"><a title="Add a new Property to the database" href="javascript:fisMenu(9, 1)">Add new &#187;</a> <a title="View List" href="javascript:fisMenu(10, 1)">View List &#187;</a></div>'
            + '<div style="float:left;clear:both">You have ' + XY.Reqs + ' current requirements</div><div style="float:right"><a title="Add a new Requirement to the database" href="javascript:fisMenu(6, 1)">Add new &#187;</a> <a title="View List" href="javascript:fisMenu(7, 1)">View List &#187;</a></div>'
            + '</fieldset>'
            + '<fieldset name=0 class=homtit><legend>Agents I look after are:</legend><div id=homedep class=department></div></fieldset>'
            + '<fieldset class=homtit><legend>Branch & Company Admin</legend>'
            + '<div class=personal>'
            + '<div><span>Company website</span><span style="width:235px" ><input style="width:225px" value="' + XY.Url + '" /></span><span name=companyweb class=update>update</span></div>'
            + '<div><span style="vertical-align:top">Branch logo <br>for Advertising<br>&nbsp;and Listings</span><span><img src="http://www.each.co.uk/images/nologo.jpg" id="iLogo" /><div class=loadfile>Loading file</div></span>'
            + '<span style="vertical-align:top"><iframe style="height:18px;width:105px;margin-left:65px" src="http://www.each.co.uk/alert/uploadlogo.aspx?Tit=3&path=' + ret10(_gCid) + '&BID=' + _gBid + '" frameborder="0" scrolling="no" ></iframe></span></div>'
            + (IsAdmin > 0 ? '<div class=branch4prop>master control - appearing on other Agents websites (EACH only can see this)</div>' : '')
            + '</div></fieldset>'
            + '<fieldset class=homtit style="width:550px"><legend>Personal Details</legend>'
            + '<div style="float:right;width:110px"><img id=iMyPic style="float:right;margin-right:23px" width=88 src="http://www.each.co.uk/images/Negotiator.gif"/>'
            + '<div class=loadfile>Loading file</div><iframe style="height:18px;float:right;width:105px" src="http://www.each.co.uk/alert/uploadlogo.aspx?Tit=2&path=' + ret10(_gCid) + '&CID=' + _gCid + '&NID=' + _gNid + '" frameborder="0" scrolling="no" ></iframe>'
            + '</div><div class=personal><div><span>Email Address</span><span><input value="' + XY.Em + '" /></span><span name=email class=update>update</span></div>'
            + '<div><span>Department</span><span><select id=homDep /></span><span name=department class=update>update</span></div>'
            + '<div><span>Title</span><span><input value="' + XY.Tit + '" /></span><span name=title class=update>update</span></div>'
            + '<div><span>First name</span><span><input value="' + XY.Fsn + '" /></span><span name=firstname class=update>update</span></div>'
            + '<div><span>Surname</span><span><input value="' + XY.Srn + '" /></span><span name=surname class=update>update</span></div>'
            + '<div><span>Position in Company</span><span><select onchange="sPositions(this)" class=slPos /></span><span name=position class=update>update</span></div>'
            + '<div><span>Direct Dial</span><span><input value="' + XY.Phn + '" /></span><span name=phone class=update>update</span></div>'
            + '<div><span>Mobile</span><span><input value="' + XY.Mbl + '" /></span><span name=mobile class=update>update</span></div>'
            + '<div><span>MSN email</span><span><input value="' + XY.Msn + '" /></span><span name=msn class=update>update</span></div>'
            + '<div><span>Skype name</span><span><input value="' + XY.Skp + '" /></span><span name=skype class=update>update</span></div>'
            + '</div></fieldset><fieldset class=homtit><legend>Change Password</legend>'
            + '<div class=personal><div><span>Old password</span><span><input id=PswOld type=password /></span></div>'
            + '<div><span>New password</span><span><input id=PswNew type=password /></span></div>'
            + '<div><span></span><span style="color:green">5 or more characters</span></div>'
            + '<div><span>...and again</span><span><input type=password /></span><span name=psw class=update>update</span></div>'
            + '</div></fieldset>'
            + (IsAdmin > 0 ? '<fieldset class=homtit style="width:550px"><legend>Change Style (only EACH sees that...)</legend>'
                        + '<div class=cssmenu>menu on the left</div>'
                : '')            
        ).css('display', 'block').find('div.agad').find('span').mouseover(function() { $(this).css('opacity', 0.6); }).mouseout(function() { $(this).css('opacity', ''); }
            ).click(function() {
                XY.NoMove = 1;
                XY.AgAd = (XY.AgAd == 0 ? 1 : 0);
                $.post(urlLoad, { list: 3, NID: _gNid, Type: 111, Did: 'role', Bid: (XY.AgAd == 0 ? 'N' : 'S') }, function(e) { });
                AgAd();
                $('#homedep').html('');
                Department('#homedep');   //DepartmentPop();
            });
    $('#home').find('fieldset').css('display', 'block').find('legend').slice(2, 10).mouseover(function() { $(this).css('opacity', 0.6); }).mouseout(function() { $(this).css('opacity', ''); }
            ).click(function() {
                if (XY.NoMove == 1) { XY.NoMove = 0; return; }
                if ($(this).attr('name2') != '1') $(this).attr('name2', '1').parent().find('div').slideUp('fast');
                else $(this).attr('name2', '0').parent().find('div').slideDown('fast');
            });
    AgAd();
    $('#home').find('.slPos').html(PositionPop()).val(XY.Pos);
    if (XY.MyPic.length > 0) logo(XY.MyPic, 0, 2, 0);
    if (XY.BranchLogo.length > 0) logo(XY.BranchLogo, 0, 1, _gBid);
    else if (XY.CompLogo.length > 0) logo(XY.CompLogo.split('.')[XY.CompLogo.split('.').length - 1], 0, 1, _gCid);

    $.post(urlLoad, { list: 3, NID: _gNid, Type: 157 }, function(d) {
        XY.DpsBrs = eval(d)[0].R; //.split('|');
        var deps = XY.DpsBrs.split('@')[0].split('~');
        for (var id = 1; id < deps.length; id++) $('#homDep').append('<option value=' + deps[id].split(',')[0] + '>' + deps[id].split(',')[1] + '</option>');
        var branches = '';
        try {
            deps = XY.DpsBrs.split('@')[1].split('~');
            if (deps.length > 2) {
                branches = '<option value=null></option><option style="background:#ffa" value=bids>Other Branches</option>';
                for (var id = 1; id < deps.length; id++)
                    branches += '<option style="color:#33f" value=b' + deps[id].split(',')[0] + '>' + deps[id].split(',')[1] + '</option>';
            }
        } catch (e0) { }
        var newBid = _gBid, newDid = _gDid;
        $('#homDep').append(branches).val(_gDid).change(
            function() {
                if ($(this).val().substring(0, 1) == 'b') {//branch
                    newBid = $(this).val().substring(1, $(this).val().length);
                    $.post(urlLoad, { list: 3, Type: 112, Bid: newBid }, function(d) {
                        $('#homDep').html('');
                        deps = eval(d)[0].R.split('~');
                        newDid = deps[1].split(',')[0];
                        for (id = 1; id < deps.length; id++) $('#homDep').append('<option value=' + deps[id].split(',')[0] + '>' + deps[id].split(',')[1] + '</option>');
                        $('#homDep').append(branches)
                    });
                }
                else { //department
                    newDid = $(this).val();
                }

            }
        );
        $('#home').find('span.update').mouseover(function() { $(this).css('background', '#aea'); $(this).parent().find('input,select').css('background', '#aea'); }
            ).mouseout(function() {
                if ($(this).html() == 'updated') return;
                $(this).css('background', '#efe').parent().find('input,select').css('background', '');
            }).click(function() {
                $(this).html('updated');
                setTimeout(function() { $(o).html('update').trigger('mouseout'); }, 1000);
                var o = this, nm = $(this).attr('name'), v;
                if ($(this).parent().find('input').length > 0)
                    v = $(this).parent().find('input').val();
                else v = $(this).parent().find('select').val();
                if (nm == "department" && _gDid == newDid) return;
                else {
                    _gDid = newDid;
                    _gBid = newBid;
                }
                var jsNeg = { list: 3, NID: _gNid, Type: 111, Did: nm, Bid: v };
                if (nm == 'psw') {
                    if (IsAdmin == 0 && v != $('#PswNew').val()) {
                        alert('new Password does not match with ...and again');
                        return;
                    }
                    if (v.length < 5) {
                        $(this).parent().find('input').css('background-color', 'red');
                        alert('password must have at least 5 characters!');
                        return;
                    }

                    jsNeg.Psw = $('#PswOld').val();
                    jsNeg.PswNew = v;
                }
                $.post(urlLoad, jsNeg, function(d) { });
            })
        XY.Dep['#homedep'] = '';
        Department('#homedep');
        $('#homedep').css('height', '').css('position', 'relative');
    });

    if (IsAdmin > 0) {
        $('#home').find('div.branch4prop,.cssmenu'
             ).mouseover(function() {
                 $(this).css('opacity', 0.5);
             }).mouseout(function() {
                 $(this).css('opacity', '');
             })
        $('#home').find('div.branch4prop').click(
             function() {
                 if ($(this).attr('name') != '0') {
                     if (confirm("This will stop all this \nAgents Properties from \nshowing on other Agents\'s websites.\nAre you sure?")) {
                         XY.PublicProp++;
                         $(this).attr('name', '0').css('background', XY.uncheck).css('background-color', '#fee').html('NOT master control - appearing on other Agents websites (EACH only can see this)');
                     }
                     else return;
                 }
                 else {
                     $(this).attr('name', '1').css('background', XY.check).css('background-color', '#efe').html('master control - appearing on other Agents websites (EACH only can see this)');
                     XY.PublicProp--;
                 }
                 $.post(urlLoad, { list: 3, Nid: XY.PublicProp, BID: _gBid, CID: _gCid, Type: 237 }, function(d) { Was['p'] = ''; });
                 $.post(urlLoad, { IsPublic: 1, list: 3, Nid: XY.PublicProp, BID: _gBid, CID: _gCid, Type: 237 }, function(d) { });
             }
             );
        if ((XY.PublicProp & 1) > 0) $('#home').find('div.branch4prop').attr('name', '0').css('background', XY.uncheck).css('background-color', '#fee').html('NOT master control - appearing on other Agents websites (EACH only can see this)');

        $('#home').find('div.cssmenu').click(function() {
            $(this).css('background', XY.check).css('background-color', '#efe');
            if (XY.Skins == '') {
                cssLeft();
                $(this).css('background', XY.uncheck).css('background-color', '#fee');
            }
            else cssZero();
            $.post(urlLoad, { list: 3, NID: _gNid, Type: 111, Did: 'skins', Bid: XY.Skins }, function(d) { });
        });
        if (XY.Skins.length > 0) $('#home').find('div.cssmenu').css('background', XY.uncheck).css('background-color', '#fee');    
    }   
}
function AgAd() {
    $('#home').find('div.agad').find('span').css('background-image', "url('http://www.4prop.com/JSON/images/common/Rolls/checkNo1.png')").css('font-weight', 'normal'
        ).each(function() { var v = $(this).html(); $(this).html(v.replace('I am', 'change to')); });
    $('#home').find('div.agad').find('span').slice(XY.AgAd, XY.AgAd + 1).css('background-image', "url('http://www.4prop.com/JSON/images/common/Rolls/check1.png')").css('font-weight', 'bold'
        ).each(function() {
            var v = $(this).html(); $(this).html(v.replace('change to', 'I am'));
        });
    $('#home').find('fieldset[name=0]').find('legend').html(XY.AgAd == 0 ? 'Administrator/PA/Secretary' : 'Agents I look after are:');
    //XY.AgAd = (XY.AgAd == 0 ? 1 : 0);
}
function ret10(p) { return "0000000000000".substr(0, 10 - ('' + p).length) + '' + p; }
function PositionPop() { return '<option value="???">???</option><option value="Graduate Trainee">Graduate Trainee</option><option value="Surveyor">Surveyor</option><option value="Associate">Associate</option><option value="Partner">Partner</option><option value="Director">Director</option><option value="Senior Partner">Senior Partner</option><option value="Managing Director">Managing Director</option><option value="Head of Department">Head of Department</option><option value="Head of Branch">Head of Branch</option><option value="Head of Region">Head of Region</option><option value="Negotiator">Negotiator</option><option value="PA">PA</option><option value="Secretary">Secretary</option><option value="Administrator">Administrator</option><option value=""></option><option value="Other Position">Other Position</option>'; }

function Subscription(it) {//deltp, accs
    if ((XY.DelT != 'N' && XY.DelT != 'H') || IsAdmin > 0) return false;
    var haccs = '<div style="margin-top:20px;font-weight:bold;color:red" >FOR A &pound;FREE 2 WEEK TRIAL USE OF THE WEBSITE, <span class=trial>CLICK HERE TO START TRIAL</span></div>';
    var untilpay = '<div style="font-weight:bold;margin-top:12px">Until you pay the Annual Subscription of &pound;300 for your Branch'
      + '<br />you will be charged &pound;10+vat each time to Add a Property or Add a Requirement <br /> </div>';
    var proforma = '<div style="color:red;margin-top:15px"><span class=proforma> click here to receive a proforma invoice </span>&nbsp;for the Annual Subscription'
      + '<br />do call us with any queries on 020 7602 5947 <br /><br /> </div>';
    var charge = '<div class=proformaclick style="margin-top:5px"><b>I AGREE EACH will charge me &pound;10+vat</b>, <span style="background:green;color:#efe;"  >CLICK HERE TO ADD AN INSTRUCTION</span></a>'
                + '<br /> <span class="green"> (you will be charged when you <strong>complete</strong> the entry)</span></div>';
    var bcontinue = 'Click here to continue, and pay &pound;10 + VAT';

    if (XY.Access == 0) {
        haccs = haccs + untilpay + proforma + '<span style="color:green"> or</span>' + charge;

        bcontinue = 'Click menu to choose another option';
        untilpay = '';
    }
    if (XY.Access == 1) {
        haccs = '<div class=proformaclick style="margin-top:20px"><b>YOUR BRANCH IS NOW ON A TWO WEEK TRIAL OF THIS SERVICE TILL ' + XY.Expiry + '</b>'
      + '<br /><span class=green style="font-size:9px">all instructions you enter are advertised on EACH until Register Checked as Completed or Withdrawn.</span></div>'
      + proforma + untilpay + charge;
    }
    if (XY.Access == 2) {
        haccs = '<div style="color:red;margin-top:20px"><b>YOU HAVE HAD A TRIAL PERIOD, ending ' + XY.Expiry + '</b><br><span class=proforma> click here to receive a proforma invoice </span>&nbsp;for the Annual Subscription'
    + '<br />or do call us with any queries on 020 7602 5947 <br /> </div>'
    + untilpay + charge;
        untilpay = ''; proforma = ''; bcontinue = 'Click menu to choose another option';
    }

    $('#uploaded').html('<fieldset style="display:block"><legend> EACH Database Access Control</legend>'
      + haccs + '<div class=continue>or Click menu to choose another option</div>'.replace('Click menu to choose another option', bcontinue)
      + '</fieldset>'
      ).slideDown('slow').css('width', '560px').css('height', '1000px').css('background', '#fff'
      ).find('span.proforma,div.proformaclick,div.continue,span.trial'
      ).mouseover(function() { $(this).css('background-color', '#aaa'); }
      ).mouseout(function() { $(this).css('background-color', ''); }
      ).click(function() {
          if ($(this).attr('class') == 'continue') {
              $('#uploaded').slideUp('fast');
              if (IsAdmin == 0) Home();
          }
          else if ($(this).attr('class') == 'trial') {
              $.post(urlLoad, { list: 3, Type: 107, Nid: _gNid }, function(d) {
                  $('#uploaded').slideUp('fast');
                  AddPrRq2(it);
              });
          }
          else if ($(this).attr('class') == 'proformaclick') {
              $('#uploaded').slideUp('fast');
              AddPrRq2(it);
          }
          else {
              $.post("abu/Login_AJAX.aspx", { sid: 2, email: MyEmail }, function(output) {
                  $('#uploaded').slideUp('fast');
                  AddPrRq2(it);

              });
          }
      });
    return true;
}
function reDate(date, dd, mm, yy) {
    date.setFullYear(yy);
    date.setMonth(mm);
    date.setDate(dd);
}
function sDDMMYY(date) {
    return ret2(date.getDate()) + '.' + ret2(date.getMonth()+1) + '.' + (date.getFullYear() + '').substring(2, 4);
}

function RunBlinkNow() {
    $.post(urlLoad, { MailsImmediate: 1 }, function(output) { });
}
function validateEmail(email) {
    var re = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
    return re.test(email);
} 
