var aSort = new Array(), aList = new Array(), aBlocks = new Array(), htmBars = '', hviews = '<span name=3 title="shows blocks" class=view>Block</span><span name=2 title="shows list" class=view>List</span>';
var NO = '<span style="width:WIDTH" class=NO>S</span>', aM = new Array('Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'), aMd = new Array(), aMd2 = new Array(), ITs = new Array();
aMd["Jan"] = "00"; aMd["Feb"] = "01"; aMd["Mar"] = "02"; aMd["Apr"] = "03";
aMd["May"] = "04"; aMd["Jun"] = "05"; aMd["Jul"] = "06"; aMd["Aug"] = "07";
aMd["Sep"] = "08"; aMd["Oct"] = "09"; aMd["Nov"] = "10"; aMd["Dec"] = "11";
aMd2["Jan"] = "01"; aMd2["Feb"] = "02"; aMd2["Mar"] = "03"; aMd2["Apr"] = "04";
aMd2["May"] = "05"; aMd2["Jun"] = "06"; aMd2["Jul"] = "07"; aMd2["Aug"] = "08";
aMd2["Sep"] = "09"; aMd2["Oct"] = "10"; aMd2["Nov"] = "11"; aMd2["Dec"] = "12";
var todayDMY = ckDate.getDate() + ' ' + aM[ckDate.getMonth()] + ' ' + ckDate.getFullYear(), StatusDMY = new Date(), MatchesDMY = new Date();
StatusDMY.setDate(StatusDMY.getDate() - 52);
MatchesDMY.setDate(MatchesDMY.getDate() - 14);
aList["p"] = '<div class=list name="xIt|xTp|xId" name2=0 name3=0><span class=dsc></span><table class="tbList" name="xIt|xTp|xId" style="background:COLOR" cellspacing=0><tr><td style="width:20px;padding-top:0px" class=check><input class=sl type=checkbox /></td><td class=pc style="width:40px;display:inline-block">xPC</td><td class=img>PDF</td><td class=img>IMG</td><td class=tw style="width:110px">xTW</td><td style="width:155px" class=st>STREET</td><td style="width:110px" class=sz>SIZE</td><td class=rn><input class=rn style="background:COLOR" title="click to\nupdate\nrent/price" value="RENT" /></td></tr></table><div class=block2 name=0></div></div>';
aList["r"] = '<div class=list name="xIt|xTp|xId" name2=0 name3=0><span class=dsc></span><table class="tbList" name="xIt|xTp|xId" style="background:COLOR" cellspacing=0><tr><td style="width:20px;padding-top:0px" class=check><input class=sl type=checkbox /></td><td class=img>PDF</td><td class=tps style="width:125px">SUBTYPEs</td><td style="width:132px;text-align:left" class=sz>SIZE</td><td style="width:165px" class=st>LOCATION</td><td style="width:88px" class=cn>CLIENT</td></tr></table><div class=block2></div></div>'; //;id=rentxI onclick="showRent(xI)"
var img = 'http://www.each.co.uk/images/thumb/Property/PID_xthumb.jpg', imgGoogle = '/images/thumb/Property/Google/PID_mp.jpg', latitude = "http://maps.google.com/staticmap?center=LAT,LON&zoom=13&size=130x100&format=jpg&markers=LAT,LON,blues&key=ABQIAAAATKhsz5Jij0Gp-7ep3UnychSuaNt0esGP_Ql2zlvB-XY1jXOB8hTOkFx-qzc5m4TvfAyra0_oDeng8w";
var htmComments = '<div class="dvComments"><img class=com title="add a comment" src="http://www.each.co.uk/images/toolbar/Comment.jpg"/>&nbsp;<img class=fav title="add to favourites" src="http://www.each.co.uk/images/toolbar/Plus.jpg"/>&nbsp;<img class=rej title="move to rejected list" src="http://www.each.co.uk/images/toolbar/Minus.jpg"/></div><div class="comments"></div>';
var htmSpeech = '<div class="speech"><span class="img">&nbsp;</span><span class="comment"></span><span title="will delete this comment" class=uncomment>-</span><span style="clear:both;height:3px"></span></div>';
var DateChecked = "<span class=status style='color:#f00;font-size:0.8em;margin-top:3px'>DateChecked</span>";
var Status = new Array(), flMax = new Array(), arSelected = new Array(), cSTATUS = new Array(), cSTATUSo = new Array(), cSTATUSt = new Array();
var htmBar = '<div class="bar" title="click to open" name="xIt|xTp"><table name="0" class="bar" cellspacing=0 border=0><tr><td class=check><input title="select\nall" type=checkbox /></td><td class=count>0</td><td class=type>TYPE</td><td class=sort><span class=sort name4=8 title="sort by date created">Created&#8661</span></td><td class=sort><span class=sort name4=9 title="sort by date checked">Status&#8661</span></td><td class=views>VIEWS</td></tr></table><div class=load></div><div class=sort name=0></div><div class=block name=0></div><div class=map id="mapxItxTp" name=0></div></div>';
aBlocks['p'] = '<div class=block>IMG<div class=StSTATUS name="tp" style="float:right;width:422px"><div class=tp1 style="width:281px">TYPES</div><div class=tp3>xST</div><div class=tp2>xI</div></div>'
        + '<div class=dtext><span style="width:135px" class=Location>LOC</span><span class=Size style="width:152px">SIZE</span><span class=Owner style="float:right;width:135px">OWNER</span></div>'
        + '<div class=Desc style="clear:both">DESC</div>' + htmSpeech + DateChecked + htmComments
        + '<div class="Control" ><table style="width:100%" cellspacing=0 cellpadding=0><tr><td><span style="padding-left:5px;width:130px"><a title="click to see Street View" class=map>Map</a>xAtt</span><span class=cp><a title="several similar instructions?&#13;this makes an exact copy, then change address, size, locations, etc. Record only saved when you click \'save & match\' at the end"  class=copy>Copy</a></span>&nbsp;<a title="something wrong?&#13;click to change it.&#13;&#13;NB: you can easily change rent/price, picture, pdf on the modern view (you can also update the Office floors available via Status)" class=edit>Edit</a>&nbsp;&nbsp;&nbsp;<a class=mail title="click this if you want&#13;to email this Instruction&#13;to all interested Agents">Email</a>&nbsp;&nbsp;&nbsp;<a title="other agents dealing with this Instruction?&#13;click their name to add them (click added one to delete)" class=agent>Agent</a>&nbsp;<a title="click to change Available, Under&nbsp;offer, Completed, Withdrawn. You can split individual floor sizes of an office (part under offer or part completed) and rematch the new size" class=status>Status</a></td><td><a title="will delete the above Property" class=del>Delete</a></td><td style="text-align:right">xClicks&nbsp;xMatches</td></tr></table></div>'
        + '<div class="Enq" name="0"></div><div class="Edit" name="0"></div><div class="Pdf" name="0"></div><div class="Mail" name="0"></div><div class="Status" name="0"></div><div class="Map" name="0"></div><div class="Agent" name="0"></div><div class="Clicks" name="0"></div><div class="MatchesBar"></div><div class="Matches"></div><div class="Floors"></div><div class="Rents"></div>';
aBlocks['r'] = '<div><div class=StSTATUS name="tp"><div class=tp1>TYPES</div><div class=tp3>xST</div><div class=tp2>xI</div></div><div class=Location>LOCATION</div><div class=Size>SIZE</div><div class=Desc>DESC</div><div class=Owner>OWNER</div>'
        + htmSpeech + DateChecked + htmComments + '</div><div class="Control"><table style="width:100%" cellspacing=0 cellpadding=0><tr><td><span style="padding-left:33px;width:130px">xAtt</span><span class=cp><a title="several similar instructions?&#13;this makes an exact copy, then change address, size, locations, etc. Record only saved when you click \'save & match\' at the end" class=copy>Copy</a></span>&nbsp;<a title="something wrong?&#13;click to change it.&#13;&#13;NB: you can easily change rent/price, picture, pdf on the modern view (you can also update the Office floors available via Status)" class=edit>Edit</a>&nbsp;&nbsp;&nbsp;<a class=mail title="click this if you want&#13;to email this Instruction&#13;to all interested Agents">Email</a>&nbsp;&nbsp;&nbsp;<a title="other agents dealing with this Instruction?&#13;click their name to add them (click added one to delete)" class=agent>Agent</a>&nbsp;<a title="click to change Available, Under&nbsp;offer, Completed, Withdrawn. You can split individual floor sizes of an office (part under offer or part completed) and rematch the new size" class=status>Status</a></td><td><a title="will delete the above Requirement" class=del>Delete</a></td><td style="text-align:right">xClicks&nbsp;xMatches</td></tr></table></div>'
        + '<div class="Enq" name="0"></div><div class="Pdf" name="0"></div><div class="Mail" name="0"></div><div class="Status" name="0"></div><div class="Map" name="0"></div><div class="Agent" name="0"></div><div class="Clicks" name="0"></div><div class="MatchesBar"></div><div class="Matches"></div><div class="Floors"></div><div class="Rents"></div>';
Status['N'] = 'yellow'; Status['A'] = '#d6eac2'; Status['U'] = '#F8F1B4'; Status['V'] = '#F8F1B4'; Status['W'] = '#EBC9C8'; Status['C'] = '#EBC9C8'; Status['M'] = '#EBC9C8';
Status['0'] = '#d6eac2'; Status['1'] = '#F8F1B4'; Status['2'] = '#EBC9C8'; Status['4'] = Status['2']; Status['7'] = '#B8CFE1'; Status['3'] = '#DFDFFF';
Status['M0'] = '#EAF4E0'; Status['M1'] = '#FBF8D9'; Status['M2'] = '#F5E4E3'; Status['M4'] = Status['M2']; Status['M7'] = '#D6EDFF';

cSTATUS[0] = "url('http://www.4prop.com/JSON/images/common/Rolls/A1.gif') repeat-x left top", cSTATUSt[0] = "#370";
cSTATUS[1] = "url('http://www.4prop.com/JSON/images/common/Rolls/U1.gif') repeat-x left top", cSTATUSt[1] = "#550";
cSTATUS[2] = "url('http://www.4prop.com/JSON/images/common/Rolls/C1.gif') repeat-x left top", cSTATUS[4] = cSTATUS[2], cSTATUSt[2] = "#611", cSTATUSt[4] = cSTATUSt[2];
cSTATUS[7] = "url('http://www.4prop.com/JSON/images/common/Rolls/NoAdvertise0.gif') repeat-x left top", cSTATUSt[7] = "#2259af";

cSTATUS[5] = "#eee"; cSTATUSt[5] = "#555"; cSTATUSo[5] = "#fff"; //undchnaged
cSTATUS[10] = '#E5F3DF', cSTATUS[11] = '#fffadf', cSTATUS[12] = '#F9E3E3', cSTATUS[14] = '#F9E3E3';
cSTATUSo[0] = '#c6dab2', cSTATUSo[1] = '#F3E67B', cSTATUSo[2] = '#e1aead', cSTATUSo[4] = '#e1aead';
cSTATUSo[10] = '#dfefcf', cSTATUSo[11] = '#efeacf', cSTATUSo[12] = '#ecc', cSTATUSo[14] = '#ecc';
cSTATUSo[7] = "#C2D9FF"; cSTATUS[17] = '#EBF2FF', cSTATUSo[17] = '#eeeeff';
//listing q=prop,l=req
aList[18] = '<div class=list name="xIt|xTp|xId" name2=0 name3=0><span class=dsc></span><table class="tbList" name="xIt|xTp|xId" style="background:COLOR" cellspacing=0><tr><td style="width:20px;padding-top:0px" class=check><input class=sl type=checkbox /></td><td class=tps style="width:75px">SUBTYPEs</td><td style="width:132px;text-align:left" class=sz>SIZE</td><td style="width:215px" class=st>LOCATION</td><td style="width:88px" class=cn>CLIENT</td></tr></table><div class=block2></div></div>';
aList[19] = aList[18]; aList[20] = aList[19]; aList[21] = aList[20];
//q=req,l=prop
XY.StatText[18] = "Prop Current"; XY.StatText[19] = "Prop Archive"; XY.StatText[20] = "Req Current"; XY.StatText[21] = "Req Archive";
Status['20'] = '#4CF8D6'; Status['21'] = '#FF6666'
Status['18'] = Status['20']; Status['19'] = Status['21'];
cSTATUSo[30] = '#4CF8D6'; 
cSTATUSo[21] = "#FF6666"; cSTATUSo[31] = '#FF6666';
cSTATUSo[20] = cSTATUSo[30];cSTATUSo[18] = cSTATUSo[20];cSTATUSo[28] = cSTATUSo[30];
cSTATUSo[19] = cSTATUSo[21];cSTATUSo[29] = cSTATUSo[31];
cSTATUS[20] = "url('http://www.4prop.com/JSON/images/common/Rolls/20.gif') repeat-x left top";cSTATUS[30] = '#aCF8D6'; 
cSTATUS[21] = "url('http://www.4prop.com/JSON/images/common/Rolls/21.gif') repeat-x left top";cSTATUS[31] = "#FFB6B6";
cSTATUS[18] = "url('http://www.4prop.com/JSON/images/common/Rolls/20.gif') repeat-x left top"; cSTATUS[28] = cSTATUS[30]; 
cSTATUS[19] = "url('http://www.4prop.com/JSON/images/common/Rolls/21.gif') repeat-x left top";cSTATUS[29] = cSTATUS[31]; 
Status['M20'] = '#ADFFEF'; Status['M21'] = '#FFAAAA';
Status['M18'] = Status['M20']; Status['M19'] = Status['M21'];
var tCompany = new Array(); tCompany['A'] = 'Agency'; tCompany['C'] = 'Council'; tCompany['D'] = 'Developer'; tCompany['I'] = 'Investor'; tCompany['O'] = 'Occupier'; ;
function Select(J) {
    if (arSelected[J.It] == undefined) arSelected[J.It] = new Array();
    if (arSelected[J.It][J.Crit] == undefined) arSelected[J.It][J.Crit] = '';
    var S = arSelected[J.It][J.Crit];
    try {
        if (J.ck == 0) S = (',' + S + ',').replace(new RegExp(',' + J.I + ',', "g"), ',');
        else if (S.indexOf(J.I) == -1) S += ',' + J.I;
        if (S.substring(0, 1) == ',') S = S.substring(1, S.length);
        if (S.substring(S.length - 1, S.length) == ',') S = S.substring(0, S.length - 1);
        arSelected[J.It][J.Crit] = S;
        if (RepO != null) { RepN += (J.ck == 0 ? -1 : 1); ReporTit(); }
    } catch (e) { }
}
function REPORT(b, d, it) {
    $('#rp').css('display', 'inline-block');
    $(b).find('span.prn').css('display', 'inline-block').attr('name2', it).mouseover(function() { if ($(this).attr('name') == '1') return; $(this).css('background', "url('http://www.4prop.com/JSON/images/common/Print2O.png') no-repeat"); }
        ).mouseout(function() { if ($(this).attr('name') == '1') return; $(this).css('background', "url('http://www.4prop.com/JSON/images/common/PrintBlue.png') no-repeat"); }
    ).click(function() { Report(this, d); });
}
var RepO = null, RepN = 0;
function ReporTit() { $(RepO).find('.tit').html(RepN + ' item(s) selected for the Report'); if (RepN == 0) $(RepO).parent().find('span.prn').trigger('click'); }
function retSel(it) {
    var ids = '';
    try {
        for (var t = 1; t < 18; t++) if (arSelected[it][t] != undefined && arSelected[it][t].length > 0) ids += arSelected[it][t] + ',';
        return ids;
    } catch (e) { return ""; }
}
function Report(o0, o) {
    var it = $(o0).attr('name2'), RpTit = propreq[retA(it)]; //11=com,12=fav
    if (IsMenu == "11") { it = it + 'c'; RpTit = 'Commented'; }
    if (IsMenu == "12") { it = it + 'f'; RpTit = 'Favourite'; }
    RepO = null;
    if ($(o0).attr('name') == '1') {
        $(o).css('display', 'none');
        $(o0).attr('name', '0');
    }
    else {
        $(o0).attr('name', '1');
        var Ids = retSel(it); //$(o0).attr('name2')
        if (IsMenu == "11" || IsMenu == "12") Ids = (arSelected[it]['p'] == undefined ? '' : arSelected[it]['p']) + (arSelected[it]['r'] == undefined ? '' : ',' + arSelected[it]['r']);

        if (Ids.length < 3) {
            $(o0).attr('name', '0');
            alert('You must check ' + propreqs[it] + ', which\nyou want to print out');
            return;
        }
        RepO = o; RepN = Ids.split(',').length - 1;
        $(o).html('<table width="100%" cellpadding=0 cellspacing=0><tr><td style="height:16px"><div class=pin></div></td></tr></table><table width=100% cellpadding=0 cellspacing=0><tr><td><div class=body>'
                + '<table width="100%" class=body cellpadding=0 cellspacing=5><tr><td><span class=tit></span></td></tr><tr><td>Title:<font size="3px"> <b>' + RpTit + ' Report</b></font><div style="float:right"><input style="width:320px;background:#afa" class="rpTitle" onfocus="this.select()" value="'
                + RpTit + ' List' + '" /></div></td></tr>'
                + '<tr><td><div style="float:left" class=excl>Exclude&nbsp;<div class=check title="Exclude&nbsp;Agency&nbsp;details">Agency&nbsp;details</div><div class=check style="margin-left:11px" title="Exclude&nbsp;Street&nbsp;number">Street&nbsp;Number</div><div  style="margin-left:11px;display:none;" class=check  title="Exclude&nbsp;Geography&nbsp;Map">Map</div></div></td></tr>'
                + '<tr><td align=left><div class=check style="display:none" title="New Format" name=noimg>New Format </div><div class=check name=img title="New Format with image ">with image</div></td></tr>'
                + '<tr><td align=right><div class="rpEmail"><div class=check title="Email report to me">Email report to me</div>, and/or <input name2=0 onfocus="this.select()"  class=rpEmails value="other email; email; email to send report" style="float:right;width:315px" /></div></td></tr>'
                + '<tr><td align=right><span><div class=check name="rpopen" style="margin-top:10px">open report after it is generated</div><span name=pdf class=bReport title="press to generate PDF report">click here to print <img src="http://www.each.co.uk/JSON/images/attachments/pdf.png"/></span><span name=doc class=bReport title="press to generate Word document report">click here to print <img src="http://www.each.co.uk/JSON/images/attachments/doc.png"/></span></td></tr></table></td></tr></table>'
        ).css('display', 'block').find('span.bReport').mouseover(function() { $(this).css('background-color', '#afa'); }).mouseout(function() { $(this).css('background-color', ''); }
        ).click(function() {// $(this).css('background-color', '#aef');
            Criteria = { print: 1, NID: _gNid, NID: _gNid, ids: Ids, OPEN: 0, Emails: '', type: $(this).attr('name') };
            Criteria.header = $(o).find('input.rpTitle').val();
            if (retA(it) == 'r') Criteria.Requirement = 1;
            if ($(o).find('div[name=rpopen]').attr('name2') == '1') Criteria.OPEN = 1;
            set_cookie('rpopen', Criteria.OPEN);
            set_cookie('rpEmail', '');
            if ($(o).find('div.rpEmail').find('input').attr('name2') == '1') {
                Criteria.Emails = $(o).find('div.rpEmail').find('input').val();
                set_cookie('rpEmail', Criteria.Emails);
            }
            set_cookie('excl1', ''); set_cookie('excl2', ''); set_cookie('excl3', ''); set_cookie('rpEmail0', ''); //rpEmail0
            if ($(o).find('div.excl').find('.check').slice(0, 1).attr('name2') == '1') {
                set_cookie('excl1', '1');
                Criteria.ExcludeAgency = 1;
            }
            if ($(o).find('div.excl').find('.check').slice(1, 2).attr('name2') == '1') {
                set_cookie('excl2', '1');
                Criteria.ExcludeStreetNo = 1;
            }
            if ($(o).find('div.excl').find('.check').slice(2, 3).attr('name2') == '1') {
                set_cookie('excl3', '1');
                Criteria.ExcludeMap = 1;
            }
            if ($(o).find('div.rpEmail').find('.check').attr('name2') == '1') {
                set_cookie('rpEmail0', '1');
                if (Owners.split('|').length > 1) Criteria.Emails += Owners.split('|')[2];
            }

            /*if ($(o).find('div[name=noimg]').attr('name2') == '1') {
            set_cookie('rpnoimg', '1');
            Criteria.New = 'noimg';
            }*/
            Criteria.New = 'noimg';
            if ($(o).find('div[name=img]').attr('name2') == '1') {
                set_cookie('rpimg', '1');
                Criteria.New = 'img';
            }
            //email report
            if (Criteria.Emails.length > 0) {
                Criteria.SendFrom = "EACH " + propreq[retA(it)] + " list";
                if (it.length == 2) Criteria.SendBody = "EACH Matches " + propreq[retA(it)] + " list";
                Criteria.SendSubject = "EACH Report";
                Criteria.SendBody = Criteria.SendFrom
            }
            $(o).find('div.body').html(waitSometime('Generating report...'));
            $.post(urlLoad, Criteria, function(file) {
                if (file.replace(/ /g, '').length > 5) {
                    $(o).find('div.body').html('The report was generated<br>  <a target=_blank href="http://www.each.co.uk/Alert/A.aspx?fn=' + file + '">click here to view your report</a>');
                    if (Criteria.OPEN > 0) window.open('http://www.each.co.uk/Alert/A.aspx?fn=' + file);
                    $(o).attr('name', '0');
                }
                else $(o).find('div.body').html('Ooops some error...');
            });
        });
        ReporTit();
        $(o).find('.check').mouseover(function() { $(this).css('opacity', 0.5); }).mouseout(function() { $(this).css('opacity', ''); }
        ).click(function() {
            if ($(this).attr('name2') != '1') {
                $(this).attr('name2', '1').css('background', XY.check).css('background-color', $(this).parent().attr('class') == 'excl' ? '#faa' : '#afa'); //#71A4F6
                if ($(this).attr('name') == 'img')
                    $(this).parent().find('div[name=noimg]').attr('name2', '1').css('background', XY.check).css('background-color', $(this).parent().attr('class') == 'excl' ? '#faa' : '#afa'); //#71A4F6
            }
            else {
                $(this).attr('name2', '0').css('background', XY.uncheck).css('background-color', '#ECF8FF');
                if ($(this).attr('name') == 'noimg')
                    $(this).parent().find('div[name=img]').attr('name2', '0').css('background', XY.uncheck).css('background-color', '#ECF8FF');
            }

        }
        );
        $(o).find('div.rpEmail').find('input').change(function() {
            $(this).css('background-color', '').attr('name2', '0'); if ($(this).val().indexOf('@') > 1 && $(this).val().indexOf('.') > 2
            ) $(this).css('background-color', '#afa').attr('name2', '1');
        })
        //alert(get_cookie('rpopen'));
        if (get_cookie('rpopen') != '0') $(o).find('div[name=rpopen]').trigger('click');
        //if (get_cookie('rpnoimg') != '0') $(o).find('div[name=noimg]').trigger('click');
        if (get_cookie('rpimg') != '0') $(o).find('div[name=img]').trigger('click');

        if (get_cookie('excl1') == '1') $(o).find('div.excl').find('.check').slice(0, 1).trigger('click');
        if (get_cookie('excl2') == '1') $(o).find('div.excl').find('.check').slice(1, 2).trigger('click');
        if (get_cookie('excl3') == '1') $(o).find('div.excl').find('.check').slice(2, 3).trigger('click');

        if (get_cookie('rpEmail0') == '1') $(o).find('div.rpEmail').find('.check').trigger('click');
        if (get_cookie('rpEmail').length > 0) $(o).find('div.rpEmail').find('input').val(get_cookie('rpEmail')).trigger('change');
    }
}
var mailMessage = "Enter your message here (max 200 chs)";
function addCommas(nStr) {
    if (nStr == undefined || nStr.length == 0) return 0;
    nStr = parseFloat(nStr); nStr += '';
    x = nStr.split('.');
    x1 = x[0]; x2 = x.length > 1 ? '.' + x[1] : '';
    var rgx = /(\d+)(\d{3})/;
    while (rgx.test(x1)) x1 = x1.replace(rgx, '$1' + ',' + '$2');
    return x1 + x2;
}
function MapDesc(J) {//hiden identity
    try {
        var l = J.Lc.split('|'), sz = htmlSizeP(J, 1); if (sz.length > 0) sz += '\n';
        if (!NoStreet(J.H)) {
            if (l[3].length > 0) sz += l[3] + '\n';
            if (!NoStreetNum(J.H)) {
                if (l[6].length > 0 && l[7].length > 0) sz += l[6] + ', ' + l[7] + '\n';
                else if (l[6].length > 0 || l[7].length > 0) sz += l[6] + l[7] + '\n';

                if (l[0].length > 0 && l[2].length > 0) sz += l[0] + ', ' + l[2] + '\n';
                else if (l[0].length > 0 || l[2].length > 0) sz += l[0] + l[2] + '\n';
            }
            else if (l[2].length > 0) sz += l[2] + '\n';
        }
        if (l[5].length > 0 && l[4].length > 0) sz += l[5] + ', ' + l[4] + '\n';
        else if (l[5].length > 0 || l[4].length > 0) sz += l[5] + l[4] + '\n';
        sz += l[1].split(' ')[0];
        // alert(sz);
        return sz;
    } catch (e) { }
}
var hstno = '<span class>NO&nbsp;</span>', hst = '<span title="click for Street Profile\noccupiers and deals" class="streetprofile">STREET</span><br>';
var hest = '<span title="click for Street Profile\noccupiers and deals" class="estateprofile" >ESTATE</span><br>';
var hvoa = '<span title="Click to see VOA records\nthen at \'postcode\' field\nclick to \'paste\' and \'Start search\'" class=voa>VOA</span>';
var htown = '<span title= "Town Profile" class=TownProfilelink>xTW</span><span>xPC</span>';
//StreetNumber|postcode|street|CentreEstate|townCity|suburbLocality|buildingNumber|building|CTIDs
function htmlLoc(j) { return htmLoc2(j.Lc.split('|'), j.H, j.M); }
function htmlLocSearched(j) { return htmLoc2(FindS(j.Lc).split('|'), j.H, j.M); }
function htmLoc2(l, h, M) {
    var r = '', pc = l[1].split(' ')[0], RETsNO = 'S ', RET = 'S', NoNum;
    if (l[1].indexOf('found') > -1) pc = l[1];
    if (!NoStreet(h) || !XY.view) {
        if (NoStreet(h)) r += '<span class=NO>';
        if (l[3].length > 0) r += hest.replace(/ESTATE/g, l[3]);

        if (!NoStreetNum(h) || (!XY.view && M == 0)) {
            NoNum = !NoStreet(h) && NoStreetNum(h);
            if (NoNum) r += '<div class=NO>';
            if (l[7].length > 0 && l[6].length > 0) r += l[6] + ", " + l[7] + '<br>'; //buld no + building
            else if (l[6].length > 0) r += l[6] + '<br>';
            else if (l[7].length > 0) r += l[7] + '<br>';
            if (NoNum) r += '</div>';
            if (l[0].length > 0) r += hstno.replace('NO', l[0]).replace('class', NoNum ? 'class=NO' : '');
        }
        if (l[2].length > 0) r += hst.replace(/STREET/g, l[2]);
        if (NoStreet(h)) r += '</span>';
    }
    r += htown.replace(/xTW/g, (l[4].length > 0 && l[5].length > 0 ? l[5] + '<br>' + l[4] + '<br>' : (l[5].length > 0 ? l[5] : l[4]))); //town suburb...
    return (r + hvoa.replace(/FULLPC/g, l[1])).replace(/xPC/g, pc);
}
function retOwnersPhMb(ph, mb) { if (ph.length > 2 && mb.length > 2) return ph + ', ' + mb; else if (ph.length > 2) return ph; return mb; }
function isReq(j) { return retA(j.It) == "r" || j.S > 17; }
function isProp(t) { return retA(t) == "p"; }
function htmlOwners(j, mail) {
    var ar, iar, ar2, iar2, s = '', deli = '<br>', deli2 = '<br>', comp = '<a title="click to email" href="mailto:MAIL">NAME SURNAME</a><br>PHONE', RET = 'S';
    if (NoCompanyPDF(j.H)) {//.M=matches
        if (mail == 0) {// || XY.hash>0
            if (j.IS < 2 || j.M == 1) return "<a class=enq>make enquiry</a>"; //j.My == 0  .IS < 2
            else RET = NO.replace('WIDTH', '150px').replace(/span/g, 'div');
        }
        else return '<br><br><div style="margin-top:7px;margin-left:10px">' + MailEditLink(j, 102, 'make enquiry', 0) + '</div>';
    }
    if (isReq(j)) {
        comp = '<br><a style="color:#03F;font-weight:bold" title="click to email" href="mailto:MAIL">NAME SURNAME</a>, PHONE';
        deli = ', '; deli2 = ''; //<br>';
    }
    ar = j.O.split('*');
    for (iar = 0; iar < ar.length && ar[iar].length > 5; iar++) {
        ar2 = ar[iar].split('|'); //XY.It == "r" || (j.it == 'n' && XY.It == "r")
        if (isReq(j)) s += '<b>' + ar2[0] + '</b>';
        else s += '<b>' + (mail == 1 ? ar2[0] : Fading(ar2[0], 11, 8, '')) + '</b>'; //else s += '<b>' + Fading(ar2[0], 11, 8, '') + '</b>';
        s += deli + ar2[1] + deli2;
        for (iar2 = 2; iar2 < ar2.length - 5; iar2 += 5) {
            if (iar2 > 2 && (iar2 - 2) % 5 == 0) s += deli;
            s += comp.replace('MAIL', ar2[iar2]).replace('NAME', ar2[iar2 + 1]).replace('SURNAME', ar2[iar2 + 2]
                        ).replace('PHONE', retOwnersPhMb(ar2[iar2 + 3], ar2[iar2 + 4]));
        }
        s += '<br>';
    }
    return RET.replace('S', s);
}
function htmlOwnersSearch(O) {
    var ar, iar, ar2, iar2, s = '', deli = '<br>', comp = '<a title="click to email" href="mailto:MAIL">NAME SURNAME</a><br>PHONE';
    if (XY.It == "r") {
        comp = '<a style="color:#03F;font-weight:bold" title="click to email" href="mailto:MAIL">NAME SURNAME</a>, PHONE';
        deli = ', ';
    }
    ar = O.split('*');
    for (iar = 0; iar < ar.length && ar[iar].length > 5; iar++) {
        ar2 = ar[iar].split('|'); //'<b>' +</b>
        if (XY.It == "r") s += '<b>' + FindS(ar2[0]) + '</b>'; //
        else s += '<b>' + FindS(ar2[0].substring(0, 19)) + '</b>';  //<span class=abs></span>
        s += deli + ar2[1] + deli;
        for (iar2 = 2; iar2 < ar2.length - 5; iar2 += 5) {
            if (iar2 > 2 && (iar2 - 2) % 5 == 0) s += deli;
            s += comp.replace('MAIL', ar2[iar2]).replace('NAME', FindS(ar2[iar2 + 1])).replace('SURNAME', FindS(ar2[iar2 + 2])
                        ).replace('PHONE', FindS(retOwnersPhMb(ar2[iar2 + 3], ar2[iar2 + 4])));
        }
        s += '<br>';
    }
    return s;
}

function CommaPrec(r) { return (r.length > 0 ? ', ' : ''); }
//StreetNumber|postcode|street|CentreEstate|townCity|suburbLocality|buildingNumber|building|CTIDs
//Upload property -if centre not exists - show red color
function LsPLc(J, fade1, fade2) {
    try {
        var r = '', l = J.Lc.split('|'), rNum = '', NoNum;
        if (NoStreet(J.H)) {
            if (XY.view) return "";
        } else NoNum = NoStreetNum(J.H);
        if (NoStreetNum(J.H) && XY.view) {
            r = l[2];

            if (l[3].length > 0) r += CommaPrec(r) + l[3];
            if (fade1 > 0) return Fading(r, fade1, fade2, '');
            if (fade2 > 0) return r.substring(0, fade2);
        }

        if (l[6].length > 0) rNum += l[6];
        if (l[7].length > 0) rNum += CommaPrec(rNum) + l[7];
        if (l[0].length > 0) rNum += CommaPrec(rNum) + l[0];
        if (!NoNum) r = rNum;
        if (l[2].length > 0) r += CommaPrec(r) + l[2];

        if (l[3].length > 0) r += CommaPrec(r) + l[3];
        if (!NoNum) {
            if (fade1 > 0) r = Fading(r, fade1, fade2, '');
            else if (fade2 > 0) r = r.substring(0, fade2);
        } else {
            if (J.M == 1) rNum = '';
            if (fade1 + fade2 == 0) r = NO.replace('S', rNum) + CommaPrec(rNum) + r;
            else if (rNum.length + r.length + 2 > fade1 + fade2) {
                if (rNum.length + 2 < fade1 + fade2)
                    r = NO.replace('S', rNum) + CommaPrec(rNum) + r.substring(0, fade1 + fade2 - rNum.length - 2);
                else r = NO.replace('S', rNum.substring(0, fade1 + fade2));
            }
            else r = NO.replace('S', rNum) + CommaPrec(rNum) + r;
        }
        if (NoStreet(J.H)) r = NO.replace('S', r);  //'</span>';     
        return r;
    } catch (e) { return ""; }
}
function dscLocR(J) {
    try {////AreaTitle|LondonCentral|TownsWithPC|PCs|Streets|CTIDs|area|Regions
        var aL = J.Lc.split('|'), Streets = (aL[4].length > 1 ? aL[4] + '<br>' : '');
        if (aL[0].length > 1) return Streets + aL[0];
        if (aL[1].length > 1) return Streets + aL[1];
        if (aL[2].length > 1) return Streets + aL[2];
        if (aL[3].length > 1) return Streets + CommaStripAZ(aL[3]);
        return Streets + htmReqCtids(aL[5], aL[7], 0, 1);
    } catch (e) { return ""; }
}

function DDMMYYhhmm(v, i, f) {
    try {
        if (f == 0) {
            if (i == 0) return v.substring(0, 2) + '/' + v.substring(2, 4) + '/' + v.substring(6, 8);
            return v.substring(0, 2) + ' ' + aM[parseFloat(v.substring(2, 4)) - 1] + ' ' + v.substring(4, 8) + ' ' + v.substring(8, 10) + ':' + v.substring(10, 12);
        }
        if (i == 0) return v.substring(0, 2) + '/' + v.substring(2, 4) + '/' + v.substring(4, 6);
        return v.substring(0, 2) + ' ' + aM[parseFloat(v.substring(2, 4)) - 1] + ' 20' + v.substring(4, 6) + ' ' + v.substring(6, 8) + ':' + v.substring(8, 10);
    } catch (e) { return ""; }

}
var arReportedTitle = new Array(), ClicksTitle = new Array(); // EACH
var hClicks = '<tr style="STYLE"><td title="DateTitle" style="width:57px">Date</td><td style="width:92px"><span title="TitleSrc" style="position:absolute">Source</span></td><td style="width:147px;position:relative" title="No email yet" class="eNID"><span style="position:absolute">Email</span></td><td style="width:155px" class="cNID"><span style="position:absolute">Company</span></td><td style="width:92px;position:relative;z-index:10;text-align:right" class="pNID">Phone</td></tr>';
var hClicks4Prop = '<tr style="STYLE"><td title="DateTitle" style="width:57px">Date</td><td style="width:92px"><span title="TitleSrc" style="position:absolute">Source</span></td><td style="width:147px;position:relative" title="No email yet" class="eNID"><span style="position:absolute">Email</span></td><td colspan=2 style="width:247px;cursor:pointer" class="cNID">Company</td></tr>';
arReportedTitle['0'] = 'Matches'; arReportedTitle['1'] = 'MySearch'; arReportedTitle['2'] = '4PROP';
arReportedTitle['3'] = 'Alert List'; arReportedTitle['4'] = 'Inst Search'; arReportedTitle['44'] = '4PROP email';
ClicksTitle['4'] = '4PROP'; ClicksTitle['40'] = '4PROP Email'; ClicksTitle['44'] = '4PROP Google';
ClicksTitle['2'] = 'Email Agents'; ClicksTitle['20'] = 'ACE Email'; ClicksTitle['5'] = 'Alert List'; ClicksTitle['6'] = 'Matches email';
ClicksTitle['8'] = 'Alert email'; ClicksTitle['9'] = 'Matches'; ClicksTitle['91'] = 'Request Info';
ClicksTitle['21'] = 'Street profile'; ClicksTitle['23'] = 'Town profile'; ClicksTitle['27'] = 'My Searches';

var htmClicks = '<a title="shows who has &#13opened your PDF" class=clicks NONE>Clicks[xClicks]</a>';
var htmPDF = '<a title="click to update pdf and picture" class=pdf style="margin-left:5px" NONE>PDF</a>WORD';
var htmWord = '<a title="click to update attachments and picture" class=word style="margin-left:5px" NONE>Word</a><a disabled=true name3=1 title="show html format" class=h style="margin-left:5px;width:15px;text-align:center;display:inline-block">H</a>';
var hMatches = '<a title="click to see the Requirements that match this Property" class=matches NONE>Matches [xN]</a>';
function retClicks(c, r) {
    if (c == 0) return htmClicks.replace('NONE', 'name3=1 disabled=true').replace('xClicks', '0');
    return htmClicks.replace('NONE', '').replace('xClicks', retLength(r[7], '*', -1) + retLength(r[8], '$', -1) + retLength(r[14], '*', 0) + retLength(r[16], '*', 0)
    );
}
function retLength(a, split, add) {
    if (a == undefined || a.length == 0) return 0; return a.split(split).length + add;
}
function htmlBlock(i) { var N = i.split('|'), j = JSON[N[0]][N[2]]; return htmlBlockJS(j); }
function hMatchesButton(j) {
    return hMatches.replace('xN', j.R.split('|')[2]).replace('NONE'
        , (j.R.split('|')[2] == '0'
            && j.It != 'rl' && j.It != 'rq'
            ? 'name3=1 disabled=true' : '')
        );
}
function htmlBlockJS(j) {
    if (!isReq(j))
        return aBlocks['p'].replace('DateChecked', j.R.split('|')[0].length == 0 ? '' : 'last status ' + j.R.split('|')[0]
                 ).replace('STATUS', j.S).replace('xST', XY.StatText[j.S]).replace('xClicks', retClicks(j.Cl, j.R.split('|'))
                 ).replace('xAtt', htmPDF.replace('NONE', (j.Pf < 0 ? 'name3=1' : ''))
                 ).replace('WORD', htmWord.replace('NONE', (j.Wd < 0 ? 'name3=1' : ''))
                 ).replace('LOC', htmlLoc(j)
                 ).replace('xMatches', hMatchesButton(j)
                 ).replace('xTp', j.Crit
                 ).replace('OWNER', htmlOwners(j, 0)).replace(/xI/g, (j.I == 0 ? '' : j.I)).replace(/II/g, j.II).replace('IMG', htmPic(1, j, 0)
                 ).replace('DESC', (j.Cn.length == 0 ? '' : 'Client: <b>' + j.Cn.toUpperCase() + '</b><br>') + j.D).replace('TYPES', htmPSTIDs(j)
                 ).replace('SIZE', htmlSizeP(j, 0) + htmlTenure(j) + j.A.replace('^', '<br>').replace(/,/g, '<br>')
                 );
    else return aBlocks['r'].replace('DateChecked', j.R.split('|')[0].length == 0 ? '' : 'last status ' + j.R.split('|')[0]
                 ).replace('STATUS', j.S).replace('xST', XY.StatText[j.S]).replace('xClicks', retClicks(j.Cl, j.R.split('|'))
                 ).replace('xAtt', htmPDF.replace('NONE', (j.Pf < 0 ? 'name3=1' : ''))
                 ).replace('WORD', htmWord.replace('NONE', (j.Wd < 0 ? 'name3=1' : ''))
                 ).replace('LOCATION', htmlReqLocFull(j.Lc.split('|'))
                 ).replace('xMatches', hMatchesButton(j)
                 ).replace('OWNER', htmlOwners(j, 0)).replace(/xI/g, (j.I == 0 ? '' : j.I)).replace(/II/g, j.II
                 ).replace('DESC', (j.Cn.length == 0 ? '' : 'Client: <b>' + j.Cn.toUpperCase() + '</b><br>') + j.D
                 ).replace('TYPES', htmPSTIDs(j)
                 ).replace('SIZE', htmlSizeP(j, 0) + htmlTenure(j) + j.A.replace('^', '<br>').replace(/,/g, '<br>')
                 );
}
var uSz = new Array(); uSz['2'] = 'sqft'; uSz['1'] = 'sqM'; uSz['4'] = 'acres'; uSz['8'] = 'hect';
function htmlSizeIf(mn, mx) { return (mn.length == 0 && mx.length == 0) || (parseFloat(mn) == 0 && parseFloat(mx) == 0); }
function htmlSizeIf0(m) { return m.length == 0 || parseFloat(m) == 0; } //var NoFloors = false; || NoFloors NoFloors = false; 
function htmSizeAddFloors(J, v, lst, ve) {
    if (J.It == 'r' || lst == 1) { var vv = v; if (lst == 1) vv = vv.replace(/sqft/g, 'sf').replace(/sqM/g, 'sm'); return (vv.length > 17 ? vv.replace(' - ', '-') : vv); }
    if (J.F.length < 2) return v + (ve.length > 0 ? '<br>' + ve : '');
    return htmlFloors(v, J, ve);
}
function htmlSizeP(J, lst) {
    if (J.Sz.length == 0) return "";
    var aS = J.Sz.split('|'), Unit = '', Unite = '', bA = '<b>', bZ = '</b>';
    if (lst == 1) { bA = "", bZ = ""; }
    var mn = Math.round(aS[1] * 100) / 100, mx = Math.round(aS[2] * 100) / 100, u = aS[0], mne = Math.round(aS[4] * 100) / 100, mxe = Math.round(aS[5] * 100) / 100, ue = aS[3];
    try {
        if (htmlSizeIf(mn, mx)) Unit = "";
        else {
            if (htmlSizeIf0(mn)) Unit = " max " + bA + addCommas(mx) + " " + uSz[u] + bZ;
            else if (htmlSizeIf0(mx)) Unit = " min " + bA + addCommas(mn) + " " + uSz[u] + bZ;
            else if (mn == mx) Unit = bA + addCommas(mx) + " " + uSz[u] + bZ;
            else Unit = bA + addCommas(mn) + " - " + addCommas(mx) + " " + uSz[u] + bZ;
        }
        if (XY.It == 'r' && aS[6] == "1" && (mne > 0 || mxe > 0)) Unit = ''; //IsExternal...
        if (lst == 1 && Unit.length > 0) return htmSizeAddFloors(J, Unit, lst, '');
        if (htmlSizeIf(mne, mxe)) Unite = "";
        else {
            var Ext = (lst == 1 ? '' : 'Ext: ');
            if (htmlSizeIf0(mne)) Unite = Ext + bA + addCommas(mxe) + " " + uSz[ue] + bZ;
            else if (htmlSizeIf0(mxe)) Unite = Ext + bA + addCommas(mne) + " " + uSz[ue] + bZ;
            else if (mne == mxe) Unite = Ext + bA + addCommas(mxe) + " " + uSz[ue] + bZ;
            else Unite = Ext + bA + addCommas(mne) + " - " + addCommas(mxe) + " " + uSz[ue] + bZ;
        }
        if (Unit.length > 0 && Unite.length > 0) return htmSizeAddFloors(J, Unit, lst, Unite);
        if (Unit.length > 0) return htmSizeAddFloors(J, Unit, lst, '');
        if (Unite.length > 0) return lst == 1 ? Unite.replace(/acres/g, 'ac').replace(/hectares/g, 'ha') : Unite;
        return XY.It == 'r' ? '<b>Any size</b>' : '';
    } catch (e) {
        return '';
    }
}
var aTen = new Array(); aTen['-1'] = 'sf'; aTen['-2'] = 'sm'; aTen['1'] = 'pa'; aTen['2'] = 'pm'; aTen['4'] = 'pw';
function htmlTenure(J) {
    var aT = J.Rn.split('|'), ret = '', ret0 = '';
    aT[0] = parseInt(aT[0]);
    if (!isReq(J)) {
        if ((aT[0] & 4) > 0) ret0 = 'FHold';
        if ((aT[0] & 8) > 0) ret0 += (ret0.length == 0 ? '' : ', ') + 'LongLs';
        if (ret0.length > 0 && aT[3].length > 0) ret0 = ret0 + (parseFloat(aT[3]) == 0 ? ' &pound;POA' : ' <b>&pound;' + addCommas(aT[3])) + '</b>';        //if (aT[2].length > 0 && aT[2] != "0"
        if ((aT[0] & 1) > 0) ret += (ret0.length == 0 ? '' : '<br>') + 'Lease';
        if ((aT[0] & 2) > 0) ret += (ret.length == 0 ? (ret0.length == 0 ? '' : '<br>') : ', ') + 'Short Lease';
        if (ret.length > 0 && aT[2].length > 0) ret0 += ret + (parseFloat(aT[2]) == 0 ? ' &pound;POA' : ' <b>&pound;' + addCommas(aT[2]) + ' ' + aTen[aT[1]]) + '</b>';
        if (ret.length > 0 && aT[2].length == 0) ret0 += ret;
        return '<div>' + ret0 + '</div><div class=cln></div>';
    }
    else {
        if ((aT[0] & 4) > 0) ret0 = 'FHold'; //
        if ((aT[0] & 8) > 0) ret0 += (ret0.length == 0 ? '' : ', ') + 'LongLs';
        if (ret0.length > 0 && (aT[4].length > 0 || aT[5].length > 0)) {
            if (aT[4].length > 0 && aT[5].length > 0) ret0 = ret0 + (parseFloat(aT[4]) == 0 ? '' : ' <b>&pound;' + addCommas(aT[4]) + '-' + addCommas(aT[5])) + '</b>'; //  &pound;POA    
            else if (aT[4].length > 0) ret0 = ret0 + (parseFloat(aT[4]) == 0 ? '' : '<b>&pound;' + addCommas(aT[4])) + '</b>';   //   mn &pound;POA' : 
            else ret0 = ret0 + (parseFloat(aT[5]) == 0 ? '' : ' <b>&pound;' + addCommas(aT[5])) + '</b>'; // mx &pound;POA    
        }
        if ((aT[0] & 1) > 0) ret += (ret0.length == 0 ? '' : '<br>') + 'Lease';
        if ((aT[0] & 2) > 0) ret += (ret.length == 0 ? (ret0.length == 0 ? '' : '<br>') : ', ') + 'Short Lease';
        if (ret.length > 0 && (aT[2].length > 0 || aT[3].length > 0)) {// &pound;POA
            if (aT[2].length > 0 && aT[3].length > 0) ret0 += ret + (parseFloat(aT[2]) == 0 ? '' : ' <b>&pound;' + addCommas(aT[2]) + '-' + addCommas(aT[3]) + ' ' + aTen[aT[1]]) + '</b>';
            else if (aT[2].length > 0) ret0 += ret + (parseFloat(aT[2]) == 0 ? '' : ' mn <b>&pound;' + addCommas(aT[2]) + ' ' + aTen[aT[1]]) + '</b>'; // mn &pound;POA
            else ret0 += ret + (parseFloat(aT[3]) == 0 ? '' : ' mx <b>&pound;' + addCommas(aT[3]) + ' ' + aTen[aT[1]]) + '</b>'; // mx &pound;POA
        }
        if (ret.length > 0 && aT[2].length == 0 && aT[3].length == 0) ret0 += ret;
        return '<div>' + ret0 + '</div><div class=cln></div>';
    }
}
function URLshow(it, c, b, f, e, PRid, source, nidclicked, add) {
    var itt = retA(it);
    if (add.length == 0)
        window.open('http://www.each.co.uk/f/' + c + '/' + itt + '/' + b + '/' + f + '.' + e);
    else
        window.open('http://www.each.co.uk/' + itt + '/' + c + '/' + b + '/' + f + '.' + e);
    if (PRid.length > 0 && source.length > 0)
        $.post(urlLoad, { list: 3, Type: 152, Nid: _gNid, DID: itt, BID: source, CID: PRid }, function(e) { });
}

function URL(it, c, b, f, e, PRid, source, nidclicked, add) { return 'http://www.each.co.uk/t.htm?' + PRid + '*' + source + '*' + it + '*' + nidclicked + '*' + f + "*" + e + "*" + c + "*" + b + add; }
function htmPSTIDs(J) {
    try {
        var req = "req ", ar; if (!isReq(J) || J.S > 17) req = ""; ar = J.T.split('|')[1].split(','); //T        
        ar[ar.length] = '';
        for (iar = 0; iar < ar.length - 1; iar++) {
            if (ar[iar].length > 0) {
                if (ar[ar.length - 1].length > 0) ar[ar.length - 1] += ", ";
                ar[ar.length - 1] += eval('jsPts3.v' + ar[iar]);
            }
        }
        if (ar[ar.length - 1].length == 0) return req + eval('jsPts.v' + +J.T.split('|')[0]).replace('undefined', 'Type'); //J.tp
        return req + ar[ar.length - 1].replace(/, undefined/g, '');
    }
    catch (e) { return "No Subtypes"; }
}
function oldPic(im, i) {
    try { return im.split('^')[0].split('.')[0]; }
    catch (e) { return i; }
}
function htmPic(t, J, src) {
    var u; //J.My == 0
    if (NoStreet(J.H) && (J.IS < 2 || XY.view)) return src == 1 ? "http://www.each.co.uk/JSON/images/common/None.gif" : XY.picNo.replace('attachment', 'image');
    if (J.Im.length < 15 || (NoStreetNum(J.H) && (J.IS < 2 || XY.view || J.M == 1))) {
        if (t == 0) return src == 1 ? "http://www.each.co.uk/JSON/images/common/None.gif" : XY.picNo.replace('attachment', 'image');
        if (J.R.split('|')[9] == 1) u = imgGoogle.replace('PID', (retZ(J.It) == "n" ? J.III : J.I)); //
        else u = latitude.replace(/LAT/g, J.Lt).replace(/LON/g, J.Ln);
    }
    else {
        var ar = J.Im.split('*'); //J.Im.indexOf('^') > -1
        //J.Im
        if (ar[ar.length - 2].indexOf('^') > -1)
            u = img.replace('PID', oldPic(ar[ar.length - 2], J.I)).replace('xthumb', (t == 0 ? 'tiny' : 'thumb')); //(retZ(J.It) == "n" ? J.III : J.I)
        else {            //223|hok-1b.jpg||1/6/2011 23:00:51|33252|59368*
            var ar2 = ar[ar.length - 2].split('|')
            u = "http://www.4prop.com/JSON/NIDs/" + ar2[5] + "/" + ar2[0] + "/thumb" + ar2[1]; //.replace('bmp','jpg');
            if (t == 0) u = "http://www.4prop.com/JSON/NIDs/" + ar2[5] + "/" + ar2[0] + "/tiny" + ar2[1]; //.replace('bmp', 'jpg');      //tiny for new...
        }
    }
    if (t == 0) return src == 1 ? u : '<img title="click to upload/delete image" src="' + u + '" />';
    return src == 1 ? u : '<img class=imgblock src="' + u + '" />';
}
//IsMenu = 5=My Department,6=Add Req,7=Req,9=Add Prop,10=Props
var Was = new Array(); Was['r'] = ''; Was['p'] = '';
function Process(ar) {
    try {
        JSON[XY.New] = new Array();
        JSON[XY.It] = ar;
        Was[XY.It] = JSON[XY.It];
        if (JSON[XY.It].length == 0)
            WhatsUp(XY.hash > 0 ? 'No ' + propreq[XY.It] + ' found...' : 'You have no ' + propreqs[XY.It] + ' uploaded, <span style="cursor:pointer" onclick="Add(\'New\',0)"><u>click here</u></span> to add one...'); //        
        else {
            jsPts.v17 = "Unadvertised";
            XY.Crit = 12;
            htmBars = JustAdded();
            Bars('#RESULT');
        }
        EachListHeaders();
    } catch (e) {
        WhatsUp('Some data format problem.<br>The error was sent to EACH<br>We are resolving it');
        Error('Processing Data', e.message);
    }
}
function WhatsUp(htm) { $('#RESULT').html('<div class=ErrorMsg>' + htm + '</div>'); }
function StatusChangeOne(ItTpI, s) {
    var N = ItTpI.split('|'), L = ListId(ItTpI), J = JSON[N[0]][N[2]];
    J.S = s;
    cssStatus(J.ck, L, J);
    var R = J.R.split('|');
    J.R = todayDMY + J.R.substring(11, J.R.length);
    if (J.rc == 1) {
        J.rc = 2;
        aIS[4]--;
    }
}
function cssStatus(ck, L, J) {
    if (ck == 1) $(L).css('background', cSTATUSo[J.S]);
    $(L).find('div.block2').find('div[name=tp]').attr('class', 'St' + J.S).find('div.tp3').html(XY.StatText[J.S]);
    $(L).find('div.block2').find('span.status').slice(0, 1).html('last status ' + todayDMY);
    $(L).find('div.block2').find('span.status').slice(1, 2).html('last status ' + todayDMY + ', created ' + J.R.split('|')[3] + ', updated ' + J.R.split('|')[12] + ', previous updated ' + J.R.split('|')[13]);
    $(L).find('table.tbList').css('background', cSTATUSo[J.S]).find('td.sz,td.rn,td.cn').find('input').css('background', cSTATUSo[parseInt(J.S) + 10]);
    $(L).find('div.block2').find('div.Control').css('background', cSTATUSo[J.S]).find('a[class!=status]').slice(0, 11).css('background', cSTATUS[parseInt(J.S) + 10]);
}
function AdminButton() {
    $('#fsAdmin').attr('style', 'padding:4px;background:#eef;margin-bottom:3px'
        ).html('<span style="float:right"><a style="float:left" disabled="disabled" alt="Show the NEW matches since I last logged in"> New matches</a><a style="float:left" alt="Select at tickbox those properties to transfer to another agent">Transfer agent</a></span>'
        ).slideDown('fast');
}
function BarId(ItIp) { return 'div.bar[name="' + ItIp + '"]'; }
function ListId(ItIpId) { return 'div.list[name="' + ItIpId + '"]'; }
function Filter(is) {
    atmpO = new Array();
    Secretary = (is < 5 ? 'N' : 'S');
    $('#RESULT').find('div.bar').css('display', 'none').find('div.block').attr('name', '0');
    if (XY.aMatchPages[is][0] != undefined) {
        var ar = XY.aMatchPages[is][0].split('|');
        for (var ff = 1; ff < ar.length; ff++) {
            if (ar[ff].length > 0) {
                var B = BarId(XY.It + '|' + ar[ff]);
                try {
                    $(B).css('display', 'block').find('table.bar').find('td.count').html(XY.Counts[ar[ff]].split('|')[is]);
                } catch (e) {
                    //alert(e.message);
                }
                if (XY.hash > 0 || is == 4 || parseFloat(get_cookie(XY.It + ar[ff])) > 0) {
                    if (get_cookie(XY.It + ar[ff]) == '3') set_cookie(XY.It + ar[ff], 2);
                    atmpO[atmpO.length] = XY.It + '|' + ar[ff];
                    $(B).find('div.block').html(waitSometime("Loading " + eval('jsPts.v' + ar[ff]) + "..."));
                }
            }
        }
    }
    IS = is;
    itmpO = 0; //atmpO.length - 1; //-1
    if (itmpO < atmpO.length) View(atmpO[itmpO], get_cookie(atmpO[itmpO].replace('|', '')));
    else $('#explain').html('* Please click on the bar(s) above to open them').slideDown('fast');
    //if(XY.searched.length>0) setTimeout("Find()", 1500);
}
function BarsCrit(v, found) { return v.indexOf(',' + found + ',') > -1; }
function offsetY(y) {
    try {
        if (XY.hash > 0 || XY.EditStart > 0) return;
        if (XY.NoMove > 0) { XY.NoMove = 0; return; }
        $('html,body').animate({ scrollTop: $(y).offset().top - 47 }, 1000); //35
    } catch (e) { }
}

function fBars(id, htm) {
    $(id).html(htm).find('div.bar').each(function() {
        var N = $(this).attr('name').split('|'), ItTp = N[0] + '|' + N[1];
        $(this).find('table.bar').mouseover(function() { if ($(this).attr('name') == '1') return; $(this).css('background', '#0F2A86'); }
            ).mouseout(function() { if ($(this).attr('name') == '1') return; $(this).css('background', 'url("http://www.4prop.com/JSON/images/common/Rolls/Bar1.gif") repeat-x left top').css('color', '#eef'); }
            ).find('td.count,td.type').click(function() {
                if (STAY == 1) { STAY = 0; return; }
                if (XY.Views[ItTp] == undefined || XY.Views[ItTp] == '0')
                    View(ItTp, '2'); //list by default
                else {
                    var B = BarId(ItTp);
                    if ($(B).find('table.bar').attr('name') == '1') {
                        $(B).attr('title', 'clik to open').find('div.sort,div.block,div.map').slideUp('fast'); //css('display','none'); //s
                        $(B).find('table.bar').attr('name', '0').find('span.sort').css('display', 'none');
                        set_cookie(ItTp.replace('|', ''), "0");
                    }
                    else {
                        if (XY.Views[ItTp] == '1')
                            $(B).attr('title', '').find('div.map').css('display', 'block');
                        else {
                            $(B).attr('title', '').find('div.block').css('display', 'block');
                            if ($(B).find('div.list').length > 1) $(B).find('div.sort,span.sort').css('display', 'block');
                            if (IsMenu == 14) $(B).find('span.sort[name4=9]').css('display', 'none'); //Listing / Find                            
                        }
                        $(B).find('table.bar').attr('name', '1');
                    }
                }
            });
        $(this).find('span.view').mouseover(function() { $(this).css('opacity', 0.5); }).mouseout(function() { $(this).css('opacity', ''); }
            ).click(function() {
                if (XY.Views[ItTp] == $(this).attr('name')) {
                    if (XY.Views[ItTp] == "2") {
                        $(id).find('div.list').each(function() {
                            var N = $(this).attr('name').split('|'), J = JSON[N[0]][N[2]];
                            if (J.block == 1) {
                                J.block = 2;
                                $(this).css('border', '').find('div.block2').css('display', 'none');
                                $(this).find('table.tbList').css('background', (J.ck == 1 ? cSTATUSo[J.S] : cSTATUS[J.S]));
                            }
                        });
                    }
                    else if (XY.Views[ItTp] == "3") {
                        $(id).find('div.list').each(function() {
                            var N = $(this).attr('name').split('|'), J = JSON[N[0]][N[2]];
                            if (J.block == 2) {
                                J.block = 1;
                                $(this).css('border', '1px solid ' + (J.M == 0 ? '#003' : '#eef')).css('border-bottom', '4px solid ' + (J.M == 0 ? '#003' : '#eef')).css('border-top', '3px solid ' + (J.M == 0 ? '#003' : '#eef')
                                  ).find('div.block2').css('display', 'block');
                                $(this).find('table.tbList').css('background', cSTATUSo[J.S]).css('border-bottom', '0px');
                            }
                        });
                    }
                }
                else View(ItTp, $(this).attr('name'));
            }
            );
        $(this).find('td.check').mouseover(function() { $(this).css('opacity', 0.5); }).mouseout(function() { $(this).css('opacity', ''); }
            ).click(function() {
                var ck = 0, id;
                if ($(this).attr('name') != '1') ck = 1;
                $(this).attr('name', ck);
                $(this).find('input').attr('checked', (ck == 1));
                var B = BarId(ItTp);
                $(B).find('div.list').each(function() {
                    var N = $(this).attr('name').split('|'), J = JSON[N[0]][N[2]];
                    if (!isReje(J)) {
                        J.ck = ck;
                        CHECK($(this), J);
                        Select(J);
                    }
                });
            }
            );
        })
        if (XY.SimiEdit > 0) {
            XY.SimiEdit = 0;
            setTimeout(function() { SimiEdit(XY.iti); }, 720);
        }    
}
var aViewTit = new Array("", "map", "list", "block");
function View(ItTp, view) {
    XY.Views[ItTp] = (view == undefined || view == '0' ? "2" : view); // || XY.view
    if (XY.hash == 1) XY.Views[ItTp] = '3';
    var B = BarId(ItTp);
    $(B).find('table.bar').attr('name', '1').css('background', '#0F2A86').find('span.sort,span.view').css('display', 'none');
    $(B).find('div.block,div.sort,div.map').css('display', 'none');
    $(B).find('div.load').html(waitSometime('Switching to the ' + aViewTit[XY.Views[ItTp]] + ' view...'));
    setTimeout(function() { View2(ItTp); }, 150);
}
function View2(ItTp) {
    var B = BarId(ItTp);
    if (XY.Views[ItTp] == '') XY.Views[ItTp] = '2';
    XY.viewtype = XY.Views[ItTp];
    switch (XY.Views[ItTp] + '') {
        case "1":
            iMap = ItTp;
            if ($(B).find('div.map').attr('name') == '0')
                setTimeout('scLoad("http://maps.google.com/maps/api/js?sensor=false&callback=iGMap")', 400);
            else
                $(B).find('div.map').attr('name', '1').css('display', 'block');
            break;
        case "2":
            if ($(B).find('div.block').attr('name') == '0') {
                ListLoad(ItTp, $(B).find('table.bar').find('input[type=checkbox]').attr('checked'), 0);
                $(B).find('div.block').attr('name', '1');
            }
            else if ($(B).find('div.block').attr('name') == '1') {
                ListAll(ItTp);
            }
            else {
                $(B).find('div.list').each(function() {
                    var N = $(this).attr('name').split('|'), J = JSON[N[0]][N[2]];
                    if (J.block == 1) {
                        J.block = 2;
                        $(this).find('div.block2').css('display', 'none');
                    }
                    $(this).find('table.tbList').css('background', (J.ck == 1 ? cSTATUSo[J.S] : cSTATUS[J.S]));
                });
                setTimeout(function() { ViewEnd(ItTp); }, 50);
            }
            $(B).find('div.list').css('border', '').find('table.tbList').css('border-bottom', '1px solid ' + (ItTp.split('|')[0].length == 1 ? '#989898' : '#eef'));
            break;
        case "3":
            if ($(B).find('div.block').attr('name') == '0') {
                ListLoad(ItTp, $(B).find('table.bar').find('input[type=checkbox]').attr('checked'), 1);
            }
            else if ($(B).find('div.block').attr('name') == '1') {
                setTimeout(function() { BlockAll(ItTp); }, 150);
            }
            else {
                $(B).find('div.list').css('border', '').each(function() {
                    var N = $(this).attr('name').split('|'), J = JSON[N[0]][N[2]];
                    J.block = 1;
                    $(this).find('div.block2').css('display', 'block');
                    $(this).find('table.tbList').css('background', cSTATUSo[J.S]); //.css('border-bottom', '0px'); //(J.ck == 1 ?  : '')
                    $(this).find('div.block2').find('div.Control').css('background', cSTATUSo[J.S]);
                });
                setTimeout(function() { ViewEnd(ItTp); }, 50);
            }
            //alert(ItTp);
            var col = (ItTp.split('|')[0].length == 1 ? '#003' : '#eef');
            $(B).find('div.list').css('border', '1px solid ' + col).css('border-bottom', '4px solid ' + col).css('border-top', '3px solid ' + col).find('table.tbList').css('border-bottom', '0px');
            $(B).find('div.block').attr('name', '2');
            break;
    }
}
function htmSortbar(it) {
    //<td name4=14 class=srt title="sort by client" style="width:88px">CLIENT/REF&#8661</td>
    if (it == 'rl') return '<div class=sort name=0><table cellspacing=0 cellpadding=0 width=100%><tr><td class=srt title="sort by un/selected items" style="width:20px;text-align:center" name4=100>&#8661</td><td class=srt title="sort by subtypes" style="width:75px;text-align:right;padding-right:45px" name4=12>TYPE&#8661</td><td class=srt name4=10 title="sort by min size" style="width:40px">min&#8661</td><td class=srt name4=11 title="sort by max size" style="width:47px;text-align:center">max&#8661</td><td style="width:35px">SIZE</td><td class=srt title="sort by location" style="width:235px" name4=13>LOCATION&#8661</td><td name4=14 class=srt title="sort by client" style="width:88px">REFERENCE&#8661</td></tr></table></div>'; //Listing / Find
    if (it == 'rq') return '<div class=sort name=0><table cellspacing=0 cellpadding=0 width=100%><tr><td class=srt title="sort by un/selected items" style="width:20px;text-align:center" name4=100>&#8661</td><td class=srt title="sort by subtypes" style="width:75px;text-align:right;padding-right:45px" name4=12>TYPE&#8661</td><td class=srt name4=10 title="sort by min size" style="width:40px">min&#8661</td><td class=srt name4=11 title="sort by max size" style="width:47px;text-align:center">max&#8661</td><td style="width:35px">SIZE</td><td class=srt title="sort by location" style="width:235px" name4=13>LOCATION&#8661</td><td name4=14 class=srt title="sort by client" style="width:88px">REFERENCE&#8661</td></tr></table></div>';
    return retA(it) == 'p' ?
              '<div class=sort name=0><table cellspacing=0 cellpadding=0 width=100%><tr><td class=srt title="sort by un/selected items" style="width:20px;text-align:center" name4=100>&#8661</td><td class=srt title="sort by postcode" style="width:40px" name4=1>PC &#8659;</td><td class=srt title="sort by pdfs" style="width:20px;text-align:center" name4=2>&#8661</td><td class=srt title="sort by images" style="width:20px;text-align:center" name4=3>&#8661</td><td class=srt title="sort by town" style="width:110px" name4=4>TOWN&#8661</td><td class=srt title="sort by street" style="width:155px" name4=5>STREET&#8661</td><td  class=srt name4=10 title="sort by min size" style="width:40px">min&#8661</td><td class=srt name4=11 title="sort by max size" style="width:42px;text-align:center">max&#8661</td><td style="width:23px;text-align:right">SIZE</td><td name4=7 class=srt title="sort by rent" style="text-align:right;width:70px">RENT&#8661</td></tr></table></div>'
              : '<div class=sort name=0><table cellspacing=0 cellpadding=0 width=100%><tr><td class=srt title="sort by un/selected items" style="width:20px;text-align:center" name4=100>&#8661</td><td class=srt title="sort by no/attachments" style="width:20px;text-align:center" name4=2>&#8661</td><td class=srt title="sort by subtypes" style="width:125px" name4=12>SUBTYPEs&#8661</td><td class=srt name4=10 title="sort by min size" style="width:40px">min&#8661</td><td class=srt name4=11 title="sort by max size" style="width:47px;text-align:center">max&#8661</td><td style="width:35px">SIZE</td><td class=srt title="sort by location" style="width:165px" name4=13>LOCATION&#8661</td><td name4=14 class=srt title="sort by client"  style="width:88px">CLIENT/REF&#8661</td></tr></table></div>'

}
function ViewEnd(ItTp) {
    var B = BarId(ItTp);
    $(B).find('div.load').html(''); //td.loading,
    if ($.browser.msie) $(B).find('td.views').css('float', 'right');
    $(B).find('span.view').css('display', 'block').css('color', '').css('background-color', '');
    $(B).find('span.view[name=' + XY.Views[ItTp] + ']').css('color', '#0F2A86').css('background-color', '#eef');
    $('#explain').css('display', 'none');
    set_cookie(ItTp.replace('|', ''), XY.Views[ItTp]);
    if (XY.Views[ItTp] + '' == '1') {
    }
    else {
        $(B).find('div.block').css('display', 'block');
        if ($(B).find('div.list').length > 1) {
            $(B).find('div.sort,span.sort').css('display', 'block'); //td.sort,
            if (IsMenu == 14) $(B).find('span.sort[name4=9]').css('display', 'none'); //Listing / Find
            if ($(B).find('div.sort').html().length == 0) {
                $(B).find('div.sort').attr('name', '1').html(htmSortbar(ItTp.split('|')[0]));
                fSort(ItTp);
            }
        }
    } //>0 --
    if (itmpO < atmpO.length - 1) { itmpO++; View(atmpO[itmpO], get_cookie(atmpO[itmpO].replace('|', ''))); }
    else if (XY.offset.length > 0) offsetY(XY.offset);
    //if (IS != 2 && urlp.indexOf('comp') > -1) fisMenu(5, 0);
    setTimeout("$('" + ListId(XY.iti) + "').find('div.Action').attr('name',1).find('span.b[name2=" + (XY.MatchButton % 10) + "]').trigger('click')", 500);
    if (XY.searched.length > 0) setTimeout("Find()", 1500);
}
function CHECK(o, J) {
    try {
        $(o).find('div.block2').css('background', (J.ck == 1 ? cSTATUSo[J.S] : (J.M > 0 ? Status['M' + J.S] : ''))
            ).parent().find('table.tbList').css('background', (J.ck == 1 || J.block == 1 ? cSTATUSo[J.S] : cSTATUS[J.S])).find('input.sl').attr('checked', J.ck == 1);
    } catch (e) { }
}
function BlockAll(ItTp) {
    var B = BarId(ItTp), last = $(B).find('div.list').length, Last; //parseInt()
    Last = last;
    $(B).find('div.list').each(function() {
        try {
            var N = $(this).attr('name').split('|'), J = JSON[N[0]][N[2]];
            CHECK(this, J);
            J.block = (J.block == 1 ? 2 : 0);
            J.NoMove = 1;
            setTimeout("showBlock(\'" + $(this).attr('name') + "\')", 50);
            last--;
            if (last == 0) setTimeout("ViewEnd(\'" + ItTp + "\')", 50 * Last);
        } catch (ee) { }
    });
}
function ListAll(ItTp) {
    var last = parseInt($('div.bar[name="' + ItTp + '"]').find('div.list').length), Last = last, B = 'div.bar[name="' + ItTp + '"]';
    $(B).find('div.list').each(function() {
        var N = $(this).attr('name').split('|'), J = JSON[N[0]][N[2]];
        CHECK(this, J);
        try {
            if (J.block == 1) J.block = 2;
        } catch (e) {
            //J.block = 0;
        }
        last--;
        if (last == 0) setTimeout("ViewEnd(\'" + ItTp + "\')", 150);
    });
}
function BarTitles(J, it) {
    try {
        return htmBar.replace('VIEWS', retA(it) == 'p' ? hviews + '<span title="shows map view" name=1 class=view>Map</span>' : hviews
                                  ).replace(/xIt/g, it).replace(/xTp/g, J.Crit).replace('TYPE', CritName(J.Crit));
    } catch (e) {
        Error('BarTitles', 'it=' + it + ', ' + e.message); //J.I'+ J.I +', 
        return "";
    }

}
function JustAdded() { return htmBar.replace('VIEWS', "<a class=NewReload onclick=\"EachList('" + XY.It + "');\">reload</a>").replace(/xIt/g, XY.New).replace(/xTp/g, "0").replace('TYPE', "Just added").replace('MAPVIEW', ''); }
function NoStreetNum(h) { return (h & 2) > 0 || (h & 4); }
function NoCompanyPDF(h) { return (h & 1) > 0; }
function NoStreet(h) { return (h & 2) > 0; }
function NoAll(h) { return (h & 7) > 0; }

function Bars(htmID) {
    var J, rd;
    try {
        for (var i = 0; i < JSON[XY.It].length; i++) {
            try {
                J = JSON[XY.It][i]; J.ck = 0; J.rc = 0; J.block = 0; J.II = i; J.found = 1; J.It = 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.R.split('|')[16].length;  //- 4;
                J.Crit = (J.S == 7 ? 17 : J.tp);
                J.MyAg = 0; J.M = 0; J.My = 0;
                J.Tx = ''; //J.R.split('|')[17];                
                if (XY.Crit2 != J.Crit) {
                    XY.Counts[XY.Crit2] = aCount[0] + '|' + aCount[1] + '|' + aCount[2] + '|' + aCount[3] + '|' + aCount[4] + '|' + aCount[5];
                    htmBars += BarTitles(J, XY.It);
                    aCount[0] = 0; aCount[1] = 0; aCount[2] = 0; aCount[3] = 0; aCount[4] = 0; aCount[5] = 0;
                }
                XY.Crit2 = J.Crit;
                aCount[0]++; aIS[0]++; J.IS = 0;
                if (aCount[0] == 1) { XY.aMatchPages[0][J.Crit] = J.Crit + "|"; XY.aMatchPages[0][0] += "|" + J.Crit; }
                XY.aMatchPages[0][J.Crit] += htmMatchPage(i, aCount[0]);
                if (BarsCrit(J.N.split('|')[2], _gBid)) {
                    aCount[1]++; J.IS = 1; aIS[1]++;
                    if (aCount[1] == 1) { XY.aMatchPages[1][J.Crit] = J.Crit + "|"; XY.aMatchPages[1][0] += "|" + J.Crit; }
                    XY.aMatchPages[1][J.Crit] += htmMatchPage(i, aCount[1]);
                };

                if (BarsCrit(J.N.split('|')[1], _gDid)) {
                    aCount[2]++; J.IS = 2; aIS[2]++;
                    if (aCount[2] == 1) { XY.aMatchPages[2][J.Crit] = J.Crit + "|"; XY.aMatchPages[2][0] += "|" + J.Crit; }
                    XY.aMatchPages[2][J.Crit] += htmMatchPage(i, aCount[2]);
                }
                if (BarsCrit(J.N.split('|')[0], _gNid)) {//
                    if (XY.firstMatchITI.length == 0 && J.R.split('|')[2] != '0') XY.firstMatchITI = XY.It + '|' + J.Crit + '|' + i;
                    aCount[3]++; J.IS = 3; aIS[3]++; J.My = 1;
                    if (aCount[3] == 1) { XY.aMatchPages[3][J.Crit] = J.Crit + "|"; XY.aMatchPages[3][0] += "|" + J.Crit; }
                    XY.aMatchPages[3][J.Crit] += htmMatchPage(i, aCount[3]);
                    JSON.Status = new Date();
                    XY.sddmmyy = J.R.split('|')[0].split(' ');
                    reDate(JSON.Status, XY.sddmmyy[0], parseFloat(aMd[XY.sddmmyy[1]]), XY.sddmmyy[2]);

                    if (JSON.Status < StatusDMY && J.S < 7) {
                        aIS[4]++; J.rc = 1; aCount[4]++;
                        if (aCount[4] == 1) { XY.aMatchPages[4][J.Crit] = J.Crit + "|"; XY.aMatchPages[4][0] += "|" + J.Crit; }
                        XY.aMatchPages[4][J.Crit] += htmMatchPage(i, aCount[4]);
                    }                  //register check, must be within My department...                    
                }
                if (J.R.split('|')[11].length > 0 && (',' + J.R.split('|')[11]).indexOf(',' + _gNid + ',') > -1) {
                    J.MyAg = 1; aCount[5]++; aIS[5]++;
                    if (aCount[5] == 1) { XY.aMatchPages[5][J.Crit] = J.Crit + "|"; XY.aMatchPages[5][0] += "|" + J.Crit; }
                    XY.aMatchPages[5][J.Crit] += htmMatchPage(i, aCount[5]);
                    JSON.Status = new Date();
                    XY.sddmmyy = J.R.split('|')[0].split(' ');
                    reDate(JSON.Status, XY.sddmmyy[0], parseFloat(aMd[XY.sddmmyy[1]]), XY.sddmmyy[2]);

                    if (JSON.Status < StatusDMY && J.rc == 0 && J.S < 7) {
                        aIS[4]++; J.rc = 1; aCount[4]++;
                        if (aCount[4] == 1) { XY.aMatchPages[4][J.Crit] = J.Crit + "|"; XY.aMatchPages[4][0] += "|" + J.Crit; }
                        XY.aMatchPages[4][J.Crit] += htmMatchPage(i, aCount[4]);
                    }
                }                //status must inclde my agent's ones...
            } catch (e) { }
        }
    } catch (e) { }
    //StatusDMY.setDate(StatusDMY.getDate() + 38); //before 2 weeks, for matches...
    XY.Counts[XY.Crit2] = aCount[0] + '|' + aCount[1] + '|' + aCount[2] + '|' + aCount[3] + '|' + aCount[4] + '|' + aCount[5];
    fBars(htmID, htmBars);
}
function EachListHeaders() {
    $('#fsScope').html('<div style="text-align:left;padding:0px;margin:0px"><a class="ct" title="shows only \nmy Properties" name="3">My&nbsp;Properties&nbsp;<span></span></a><a class="ct" title="shows my \ndepartment\'s Properties" name="2">Department&nbsp;<span></span></a><a class="ct" title="shows Properties \nwithin my branch" name="1">Branch&nbsp;<span></span></a><a class="ct" title="shows my \ncompany\'s Properties" name="0">Company&nbsp;<span></span></a><a class="ct" title="shows Properties needed to register check" style="float:right;width:87px;display:none"  name="4">Status<span></span></a><a class="ct" style="width:75px;float:right" title="shows only \nmy Agents" name="5">My&nbsp;Agents&nbsp;<span></span></a></div>'
        ).find('a.ct').each(function() {
            var c = parseInt($(this).attr('name'));
            $(this).find('span').html('[' + aIS[c] + ']');
            if (aIS[c] == 0) { $(this).attr('class', 'ct0'); if (c == 5) $(this).css('display', 'none'); }
            if (XY.CoProps > 300 && c == 0) $(this).css('display', 'none');
            if (XY.It == 'r') {
                c = $(this).attr('title');
                $(this).attr('title', c.replace('Properties', 'Requirements'));
                c = $(this).html();
                $(this).html(c.replace('Properties', 'Requirements'));
            }
        });
    $('#fsScope').find('a.ct').mouseover(function() { $(this).css('opacity', 0.5) }).mouseout(function() { $(this).css('opacity', '') }
                             ).click(function() {
                                 $('#fsScope').find('a.ct').css('background', "url('http://www.4prop.com/JSON/images/common/Rolls/MyProp0.gif') no-repeat").css('color', '#0F2A86');
                                 $(this).css('background', "url('http://www.4prop.com/JSON/images/common/Rolls/MyProp.gif') no-repeat").css('color', '#eef');
                                 Filter($(this).attr('name'));
                                 var rc;
                                 if ($(this).attr('name') == '4') { //register check
                                     $('#fsStatus').html('<span class="reglist"><a>' + aIS[4] + '</a><span name="1">need to check</span></span><span class="reglist">,&nbsp;<a>0</a> <span name="2">checked</span></span><span style="color:red;float:right;margin-top:2px"><a name=0 class=a title="set selected items as available">available</a>&nbsp;<a  title="set selected items as under offer" name=1 class=u>under offer</a>&nbsp;<a title="set selected items as withdrawn" name=2 class=w>withdrawn</a>&nbsp;<a  title="set selected items as completed" name=4 class=c>completed</a></span><span style="clear:both"></span>'
                                            ).slideDown('fast'
                                            ).find('span').find('a').css('padding', 3).each(function() { $(this).css('background', cSTATUS[$(this).attr('name')]); $(this).css('color', cSTATUSt[$(this).attr('name')]); });
                                     $('#fsStatus').find('span.reglist').find('span').mouseover(function() { $(this).css('opacity', 0.5); }).mouseout(function() { $(this).css('opacity', ''); }
                                                  ).click(function() {
                                                      $('#fsStatus').find('span.reglist').find('span').css('text-decoration', 'underline').css('font-weight', '');
                                                      rc = parseInt($(this).attr('name'));
                                                      $(this).parent().find('span[name=' + rc + ']').css('text-decoration', '').css('font-weight', 'bold');
                                                      try { for (var i = 0; i < JSON[XY.It].length; i++) $(ListId(XY.It + '|' + JSON[XY.It][i].tp + '|' + i)).css('display', (JSON[XY.It][i].rc != rc ? 'none' : 'block')); } catch (e) {
                                                          //alert(e.message); 
                                                      }
                                                  }
                                        );
                                     $('#fsStatus').find('span.reglist:first').find('span').trigger('click');
                                     $('#fsStatus').find('span').find('a.a,a.u,a.w,a.c'
                                            ).mouseover(function() { $(this).css('background', cSTATUSo[$(this).attr('name')]); }
                                            ).mouseout(function() { $(this).css('background', cSTATUS[$(this).attr('name')]); }
                                            ).click(function() {
                                                try {  //alert(rc);
                                                    for (var i = 0; i < JSON[XY.It].length; i++) {
                                                        if (JSON[XY.It][i].ck == 1 && JSON[XY.It][i].rc == 1) {//1
                                                            StatusChangeOne(XY.It + '|' + JSON[XY.It][i].tp + '|' + i, $(this).attr('name'));
                                                            $(ListId(XY.It + '|' + JSON[XY.It][i].tp + '|' + i)).css('display', (JSON[XY.It][i].rc != rc ? 'none' : 'block'));
                                                            jsCriteria = { Update: 1, status: $(this).attr('name') };
                                                            DatabaseUpdate(JSON[XY.It][i]);
                                                        }
                                                    }
                                                } catch (e) { }
                                                $('#fsScope').find('a[name=4]').html('Status [' + aIS[4] + ']').attr('disabled', aIS[4] == 0);
                                                $('#head').find('span.itm[name2=4]').html('Status [' + aIS[4] + ']').attr('disabled', aIS[4] == 0);
                                                var checked = 0;
                                                $('#fsStatus').find('span.reglist').find('a').each(function() { checked += parseInt($(this).html()); });
                                                $('#fsStatus').find('span.reglist:first').find('a').html(aIS[4]);
                                                $('#fsStatus').find('span.reglist:last').find('a').html((checked - aIS[4]) + '');
                                            }
                                            );
                                 }
                                 else $('#fsStatus').slideUp('fast');
                             });
    $('#head').attr('style', 'height:23px;padding-top:1px;padding-right:3px;margin-top:27px;position:fixed;width:560px').html('<span class=itm name2=0 title="open a new ' + Capital1(propreq[XY.It]) + ' form">&nbsp;ADD ' + propreq[XY.It].toUpperCase() + '</span><span class=itm title="see matching ' + Capital1(propreqs[XY.It]) + ', all\nor from your selected date" name2=1>MATCHES</span><span title="search on any words\nin record, address, comments" class=itm name2=2>Find</span><span disabled=true class=itm title="move batch of ' + Capital1(propreqs[XY.It]) + '\nto another Agent" name2=3>Admin</span><span class=itm title="batch update the Status\n of your ' + Capital1(propreqs[XY.It]) + '" style="color:#f00;display:' + (aIS[4] == 0 ? 'none' : '') + '" name2=4>STATUS[' + aIS[4] + ']</span><span class=Tit></span><div id=BillDate></div><a class=Cancel title="Cancel your changes" onclick="EditCancel()"></a><a style="display:none" class=aGO onclick="AddSave(2)"></a><fieldset id="fsAdmin"></fieldset><span style="clear:both"></span>'
             ).find('span.itm').mouseover(function() { if ($(this).attr('name') == '1') return; $(this).css('opacity', 0.5); }
             ).mouseout(function() { if ($(this).attr('name') == '1') return; $(this).css('opacity', ''); }
             ).click(function() {//disabled
                 if ($(this).attr('name') != '1') {
                     $(this).attr('name', '1');
                     switch ($(this).attr('name2')) {
                         case '0': AddPrRq(XY.It); break;
                         case '1': XY.iti = XY.firstMatchITI; MatchPageClick(); break;
                         case '2':                             //XY.NoMove = 1;
                             $('#fsFind').slideDown('fast').attr('name', '1');
                             if ($('#RESULT').find('table.bar[name=0]').length > 0) {
                                 $('#FindCnt').html('Opening bars...');
                                 $('#RESULT').find('table.bar[name=0]').each(function() { setTimeout("Bar2Open('" + $(this).parent().attr('name') + "')", 500); });
                                 setTimeout("$('#FindCnt').html('')", 3000);
                             }
                             if ($('#txFind').val().length > 0) Find0();
                             ControlCloseAll(XY.iti, null);
                             break;
                         case '3': AdminButton(); break;
                         case '4': $('#fsScope').find('a.ct[name=4]').trigger('click'); break;
                     }
                 }
                 else {
                     $(this).attr('name', '0'); //.css('color', '');//.css('background-color', '')
                     switch ($(this).attr('name2')) {
                         case '1': break;
                         case '2': $('#fsFind').slideUp('fast').attr('name', '0'); XY.searched = ''; Filter(IS); break;
                         case '3': $('#fsAdmin').slideUp('fast'); break;
                         case '4': $('#fsScope').find('a.ct').slice(0, 1).trigger('click'); break;
                     }
                 }
             }
    );
    if (XY.firstMatchITI.length == 0) $('#head').find('span.itm[name2=1]').css('display', 'none');
    if (XY.hash > 0) {
        if (aIS[3] == 0 && aIS[5] == 0 && !XY.view)
            WhatsUp('You are not authorized to edit this ' + propreq[XY.It]);
        else {
            $('#fsScope').find('a.ct').slice(0, 1).trigger('click');
            $('#head').html("<img src='http://www.4prop.com/JSON/images/common/LogoSmallAd.png'><span class=edit></span><span style='clear:both'>&nbsp;</span>"
                ).attr('style', 'height:30px;color:#eef;padding-right:11px;background:#0F2A86;padding-top:10px;position:relative'
                ).slideDown('fast');
            $('#RESULT').find('table.bar').css('display', 'none');
        }
    }
    else {
        if (aIS[3] == 0) {
            $('#RESULT').find('div.bar').css('display', 'none');
            MineIsEmpty();
        }
        if (aIS[0] > 0) {
            ShowHeaders(); //.ct,a.ct0
            var ii = (urlp.indexOf('comp') > -1 ? 1 : 0);
            urlp = urlp.replace('comp', '');
            $('#fsScope').find('a').slice(ii, (ii + 1)).trigger('click');
        }
        HeaderAlwaysSHown();
    }
}
function ShowHeaders() {
    $('#fsScope,#head').slideDown('fast');
    $('#txFind').bind("keydown", function(l) { if (l.keyCode == 13) Find0(); });
    REPORT('#statusbar', '#rp', XY.It);
}
function HeaderAlwaysSHown() {
    $('#head').css('display', 'block');
    fSaveEdit($('#head').find('a'));
}

//|id2.text,ddmmyyhhmm|id3.text,ddmmyyhhmm
function isFavo(j) { try { return XY.Favo[retA(j.It)].indexOf('|' + j.I + ',') > -1; } catch (e) { return false; } }
function isReje(j) { try { return XY.Reje[retA(j.It)].indexOf('|' + j.I + ',') > -1; } catch (e) { return false; } }
//|id1,ddmmyyhhmm|id2,ddmmyyhhmm
function isFavoAdd(j, dl) {
    if (dl == 0) XY.Favo[retA(j.It)] += '|' + j.I + ',' + retDDMMYYHHMM(); //id1,ddmmyyhhmm
    else {
        var p = XY.Favo[retA(j.It)].indexOf('|' + j.I), s = XY.Favo[retA(j.It)].substring(p, p + (j.I + '').length + 12);
        XY.Favo[retA(j.It)] = XY.Favo[retA(j.It)].replace(s, '');
    }
    DataSet((retA(j.It) == 'p' ? '21' : '22'), XY.Favo[retA(j.It)]);
    Favourites();
}
function isRejeAdd(j, dl) {
    if (dl == 0) XY.Reje[retA(j.It)] += '|' + j.I + ',' + retDDMMYYHHMM();
    else {
        var p = XY.Reje[retA(j.It)].indexOf('|' + j.I), s = XY.Reje[retA(j.It)].substring(p, p + (j.I + '').length + 12);
        XY.Reje[retA(j.It)] = XY.Reje[retA(j.It)].replace(s, '');
    }
    DataSet((retA(j.It) == 'p' ? '25' : '26'), XY.Reje[retA(j.It)]);
}
//XY.Comm[XY.It] = '|10,this is it~546546|30,semria~545|10,like it~45959|';
function isCommPrivAdd(j, tx, dl) {//
    if (dl == 0) {
        XY.Comm[retA(j.It)] += '|' + j.I + ',' + tx + '~' + retDDMMYYHHMM(); //id1,ddmmyyhhmm
        //Comments();
    }
    else {
        var p = XY.Comm[retA(j.It)].indexOf('|' + j.I + ',' + tx), s = XY.Comm[retA(j.It)].substring(p, p + (j.I + '').length + 13 + tx.length);
        XY.Comm[retA(j.It)] = XY.Comm[retA(j.It)].replace(s, '');
        //if (XY.Comm[retA(j.It)].indexOf(j.I) == -1) Comments();
    }
    DataSet(retA(j.It) == 'p' ? '23' : '24', XY.Comm[retA(j.It)]);
    Comments();
}

function isCommPriv(j) {
    try {
        var s0 = XY.Comm[retA(j.It)];
        if (s0.indexOf('|' + j.I + ',') == -1) return "";
        var p = 0, s = '';
        while (s0.indexOf('|' + j.I + ',', p) > -1) {
            p = s0.indexOf('|' + j.I + ',', p) + (j.I + '').length + 2; //alert(p);        
            if (s.length > 0) s += '|';
            s += s0.substring(p, (s0.indexOf('|', p + 1) == -1 ? s0.length : s0.indexOf('|', p + 1)));
        }
        return s;
    } catch (e) { return ""; }
}
function DataSet(t, v) { $.post(urlLoad, { list: 3, Nid: _gNid, Type: t, CID: v }, function() { }); CookieSet(); }
function retDDMMYYHHMM2(ddmmyyhhmm) {
    try {
        return parseInt(ddmmyyhhmm.substring(0, 2)) + ' ' + aM[parseInt(ddmmyyhhmm.substring(2, 4))] + ' 20' + ddmmyyhhmm.substring(4, 6);
    } catch (e) { return ""; }
}
function retDDMMYYHHMM() {
    var d = new Date();
    return ret2(d.getDate()) + ret2('' + d.getMonth()) + (d.getFullYear() + '').substring(2, 4) + ret2(d.getHours()) + ret2(d.getMinutes());
}
function fSaveEdit(id) {//$(this).css('opacity', 0.5);$(this).css('opacity', '');
    $(id).mouseover(function() {//Save
        $('#Advertise,#EDIT,#explain').css('background', headColors[$(this).attr('class')]);
    }).mouseout(function() { $('#Advertise,#EDIT,#explain').css('background', '#fff'); });

}
function Bar2Open(it) { $('#RESULT').find('div.bar[name=' + it + ']').find('table.bar').find('td.count').trigger('click'); }
function MineIsEmpty() {
    if (JSON[XY.New].length > 0) return;
    var tx = '<div class=MineIsEmpty><div>You are not marketing any ' + propreq[XY.It] + ' on www.each.co.uk</div><div class=Add>Click here to Add a ' +
                     propreq[XY.It] + '</div>' + (aIS[0] > 0 ? '<div>or click above to see any Instructions in your Department, Branch, Company</div>' : '') + '</div>';

    if (XY.AddedOnly == 1) tx = 'Click above button to add ' + propreq[XY.It] + '...';
    $('#explain').html(tx).slideDown('fast').find('div.Add').mouseover(function() { $(this).css('opacity', 0.5); }).mouseout(function() { $(this).css('opacity', ''); }
                 ).click(function() { Add('New', 0); });
}
function ButtonColor(i, d) { if (d != '1') return cSTATUS[parseInt(JSON[XY.It][i].S) + 10]; else return "#fff"; }
function ControlCloseAll(iti, o) {
    try {
        var N = iti.split('|'), J = JSON[N[0]][N[2]], L = ListId(iti), State = $(o).attr('name');
        $(L).find('div.Matches,div.MatchesBar,div.Status,div.Pdf,div.Agent,div.Map,div.Clicks,div.Mail,div.Floors,div.Rents,div.Edit,div.Enq').css('display', 'none');
        $(L).find('a.del,a.matches,a.status,a.pdf,a.agent,a.map,a.clicks,a.mail,a.rent,a.edit,a.copy,a.floors,input.sz,input.rn,a.enq').attr('name', '0').css('color', '#111');
        $(L).find('table.tbList').find('td.img').css('background-color', '').find('img').attr('name', '0').css('opacity', '');
        $(L).find('a.del,a.matches,a.status,a.pdf,a.agent,a.map,a.clicks,a.mail,a.rent,a.edit,a.copy,a.floors,input.sz,input.rn,a.enq').each(function() { $(this).css('background-color', cSTATUS[parseInt(J.S) + 10]); });

        if (State != '1') $(o).attr('name', '1').css('background-color', '#0F2A86').css('color', '#eef');
        $('#RESULT').find('div.bar').css('opacity', '');
        $(L).find('div.Matches').html('');
        try { arSelected[XY.Match][J.Crit] = ""; } catch (e0) { }
        $(L).find('a.enq').css('background', '#f96'); //#f96
        return State;
    } catch (e) { }
}
var EmailList = new Array(), EmailListIDs = '';
function htmlComments(J) {
    if (J.It == XY.It) return ""; else return ' EACH emailed this agent my instruction';
    if (J.It == "p") return '<b>10 Mar 2007</b>, Normally public comment(s) will appear only if there is one, now this appears only because of testing<br><b>11 Jun 2011</b>, this is my private comment, only my department will see this...'
    else return '<b>11 Jun 2011</b>, this is my private comment, only me will see this...<br>No Public comment appear on requirement'
}
function htmlCommentsEdit(J) {//For My props / reqs or My Companies\'s ones, only private comments possible...
    return '<div style="float:left">PRIVATE Comments</div><div style="float:right"><textarea>Write your comment here...</textarea></div><a>Save & Close</a>'
}
var AddedSince = 0; //, ckRejected;
function AddedYes(db) { if (db > MatchesDMY) { AddedSince++; return 1; } return 0; }
function fAddedSince(v) {
    var rd = v.split(' ');
    MatchesDMY.setFullYear(rd[2]); MatchesDMY.setMonth(parseFloat(aMd[rd[1]])); MatchesDMY.setDate(rd[0]);
    calcAdded();
    setTimeout('AddedClick()', 500);
}
function calcAdded() {
    AddedSince = 0;
    var J2;
    try {
        for (var i = 0; i < JSON[XY.Match].length; i++) {
            J2 = JSON[XY.Match][i];
            J2.Ad = AddedYes(J2.dt)
            $(ListId(XY.Match + '|' + J2.tp + '|' + i)).attr('name3', J2.Ad);
        }
    } catch (e) { }
}
function AddedClick() { $(XY.L).find('div.MatchesBar').find('span.b').slice(1, 2).html(AddedSince + ' added since').trigger('click'); }
function clickBlock() {
    $(ListId(XY.iti)).find('table.tbList').slice(0, 1).trigger('click');
    setTimeout("MatchClickDelay()", 700);
}
function htmMatchPage(i, ord) {
    if (JSON[XY.It][i].R.split('|')[2] == '0') return '<span class=MatchPage0 title="0 pages" name=' + i + '>' + ord + '</span>';
    return '<span title="' + JSON[XY.It][i].R.split('|')[2] + ' matches" class=MatchPage name=' + i + '>' + ord + '</span>';
}
function MatchPageClick() {
    var n = XY.iti.split('|'), J = JSON[n[0]][n[2]], B = BarId(n[0] + '|' + n[1]);    //arSelected[ItR][J.tp] = "";
    $(B).find('div.sort').html('');
    if (XY.Views[n[0] + '|' + n[1]] == undefined) {
        $(B).find('table.bar').find('td.count').trigger('click');
        setTimeout("clickBlock()", 500);
        return;
    }    //alert(XY.Views[n[0] + '|' + n[1]]);   //MapBlock(id, B, JSON[N[0]][id]);
    if (XY.Views[n[0] + '|' + n[1]] == "1") {
        MapBlock(n[2], B, J, 1);
        return;
    }
    if ($(B).find('table.bar').attr('name') == '0') {
        $(B).attr('title', '').find('div.block').css('display', 'block');
        if ($(B).find('div.list').length > 1) $(B).find('div.sort,span.sort').css('display', 'block'); //
        $(B).find('table.bar').attr('name', '1');
    }
    if (J.block == 0) clickBlock();
    else {
        if (J.block == 2) showBlockNow(XY.iti);
        MatchClickDelay();
    }
}
function MatchClickDelay() { try { var n = XY.iti.split('|'), L = ListId(XY.iti); $(L).find('a.matches').trigger('click').trigger('mouseover'); offsetY(L); } catch (e) { } }
function matchPagesFill(L, J, tp) {//179+367
    try {
        var n = XY.iti.split('|'), M = $(L).find('div.matchPages');
        if (XY.aMatchPages[IS][tp].split('|')[1].split('MatchPage').length < 3) { $(M).html(''); return; }
        $(M).html('<div style="float:left;display:inline-block;width:168px">Select another ' + propreq[retA(J.It)] + ':</div><div style="float:right;margin-right:10px;display:inline-block;width:376px">'
                + (tp == J.Crit && XY.aMatchPages[IS][tp].split('|')[1].split('MatchPage').length > 2 ? '<span class=A>&#8656;</span>' : '')
                + XY.aMatchPages[IS][tp].split('|')[1]
                + (tp == J.Crit && XY.aMatchPages[IS][tp].split('|')[1].split('MatchPage').length > 2 ? '<span class=Z>&#8658;</span>' : '')
                + '</div><span style="clear:both"></span>'
                );
        $(M).find('span.A').click(function() { $(M).find('span[name=' + n[2] + ']').prev().trigger('click'); })
        $(M).find('span.Z').click(function() { $(M).find('span[name=' + n[2] + ']').next().trigger('click'); })
        $(M).find('span.MatchPage,span.A,span.Z').mouseover(function() { $(this).css('opacity', 0.5); }).mouseout(function() { $(this).css('opacity', ''); });
        $(M).find('span.MatchPage').click(function() {
            if (n[2] == $(this).attr('name')) return;
            $(BarId(XY.Match + '|' + tp)).find('div.block').attr('name', '0');
            JSON[n[0]][n[2]].block = 2;
            $(L).css('border', '').find('div.block2').slideUp('fast');
            ControlCloseAll(XY.iti, null);
            XY.iti = XY.It + '|' + tp + '|' + $(this).attr('name'); //J.
            MatchPageClick();
        });
        $(M).find('span[name=' + n[2] + ']').attr('style', 'background:#0F2A86;color:#eef;font-weight:bold');
    }
    catch (e) {    }
}
function OtherPages(L, J) {
    try {
        var ar = XY.aMatchPages[IS][0].split('|'), r = '';
        for (var i = 1; i < ar.length; i++) r += '<span name=' + ar[i] + ' title="show pages of ' + CritName(ar[i]) + ' type" class="PagesType">' + (XY.aMatchPages[IS][ar[i]].split('|')[1].split('<span').length - 1) + ' ' + CritName(ar[i]) + '</span>';
        if (ar.length < 3) return;
        $(L).find('div.otherPages').html('<div class=tit1>or Another ' + (XY.It == 'r' ? 'req' : 'prop') + ' type:</div><div class=tit2>' + r + '</div>'
        ).find('span.PagesType').mouseover(function() { $(this).css('opacity', 0.5); }).mouseout(function() { $(this).css('opacity', ''); }
        ).click(function() {
            $(this).css('background', '#0F2A86').css('color', '#0F2A86'
                       ).parent().find('span').css('background', '#ECF8FF').css('color', '');
            matchPagesFill(L, J, $(this).attr('name'));
        }).parent().find('[name=' + J.Crit + ']').css('background', '#0F2A86').css('color', '#0F2A86');
    } catch (e) { }
}
function AddComment(J, o, tx, dt, save) {
    $(o).find('.comment:last').html('<div class=dt>' + dt + '</div><span class=tx>' + tx + '</span>');
    if (XY.searched.length > 0) $(o).find('.comment:last').html('<div class=dt>' + FindS(dt) + '</div><span class=tx>' + FindS(tx) + '</span>');
    $(o).find('div.speech:last').css('display', 'block').after(htmSpeech);
    if (save == 1) isCommPrivAdd(J, tx, 0);

    $(o).find('.uncomment[name!=1]').mouseover(function() { $(this).parent().find('span.comment').css('background-color', '#faa'); }
    ).mouseout(function() { $(this).parent().find('span.comment').css('background-color', ''); }
    ).click(function() {
        $(this).parent().slideUp('fast');
        if (tx.indexOf('EACH email') == 0) {
            set_cookie('me' + J.I, '1'); return;
        }
        else if (J.Sent > 0) {
            set_cookie('ace' + J.Sent + J.I, '1'); return;
        }
        isCommPrivAdd(J, $(this).parent().find('span.tx').html(), 1);
    })
    $(o).find('.uncomment').attr('name', '1');
}
function MatchBarUpButtons() {
    $(XY.M).find('div.list').css('display', 'none');
    $(XY.M).find('div.dvComments').find('img.rej').attr('title', 'move to rejected list');
    if (XY.viewtype == '1') {
        var J2;
        for (var i = 0; i < JSON[XY.Match].length; i++) {
            J2 = JSON[XY.Match][i];
            J2.marker.setVisible(true);
            switch (XY.MatchButton) {
                case 1: if (J2.Ad == 0) J2.marker.setVisible(false);
                    break;
                case 2:
                    if (J2.Rej == 0) J2.marker.setVisible(false);
                    break;
            }
        }
    }
    else
        switch (XY.MatchButton) {
        case 0: $(XY.M).find('div.list[name2=0]').css('display', 'block'); break;
        case 1:
            try {
                if (AddedSince > 0 && $(XY.M).find('div.list[name2=1]').length == 0) { //first was map...
                    $(XY.M).find('div.list').each(function() {
                        if (JSON[XY.Match][$(this).attr('name').split('|')[2]].Ad == 1) $(this).attr('name3', '1');
                    })
                }
            } catch (e1) { }
            $(XY.M).find('div.list[name3=1]').css('display', 'block');
            break;
        case 2: $(XY.M).find('div.list[name2=1]').css('display', 'block');
            $(XY.M).find('div.dvComments').find('img.rej').attr('title', 'move to ACTIVE list');
            break;
    }
}
function MailFromTitle(J) {
    try {
        if (NoCompanyPDF(J.H)) return "MAKE ENQUIRY";
        if (J.IS < 2) return MailCompanies(J.O);
        return XY.Company;
    } catch (e) { return ""; }
}
function MailCompanies(O) {
    var ar, iar, ret = '';
    ar = O.split('*');
    for (iar = 0; iar < ar.length && ar[iar].length > 5; iar++) ret += ar[iar].split('|')[0] + ', ';
    return ret.substring(0, ret.length - 2);
}
function MailSubject(tx, J, l) { //StreetNumber|postcode|street|CentreEstate|townCity|suburbLocality|buildingNumber|building|CTIDs
    if (XY.It == 'r') return tx + dscLocR(J);
    if (NoStreet(J.H)) return tx + l[1].split(' ')[0];
    if (NoStreetNum(J.H)) return tx + (l[1].length > 0 ? l[1] + ',' : '') + l[1].split(' ')[0];
    return tx + LsPLc(J, 0, 0) + ', ' + l[1].split(' ')[0];
    //<br>
}
function MailAceReplyLink(J, O, subject, append) { //&nbsp;&nbsp;&nbsp;the company has hidden identity, click here to make enquiry&nbsp;&nbsp;&nbsp;
    if (NoCompanyPDF(J.H)) return MailEditLink(J, 102, "TO REPLY to this email, please click here - DO NOT USE 'REPLY' ABOVE", 1) + '<br>';
    var link = '<a style="color:#a00" href=\'mailto:xMail?subject=RE:' + subject + '\'><b>TO REPLY</b> to xNameSurn, xCompany, please click here - DO NOT USE \'REPLY\' ABOVE </a>';
    var add = '<div style="font-size:12px;color:black" class=click>xNameSurn&nbsp;&nbsp;&nbsp;&nbsp;xMail<br>xCompany<br>DDI:xDDI </div></div>'; //<br>xPC
    var ar, iar, ar2, iar2, ret = '';
    ar = O.split('*');
    for (iar = 0; iar < ar.length && ar[iar].length > 5; iar++) {
        ar2 = ar[iar].split('|');
        for (iar2 = 2; iar2 < ar2.length - 5; iar2 += 5) {//there can be more agents withing the same company
            ret += link.replace('xCompany', ar2[0]).replace('xNameSurn', ar2[iar2 + 1] + ' ' + ar2[iar2 + 2]).replace('xMail', ar2[iar2]);
            if (append > 0) ret += add.replace('xCompany', ar2[0]).replace('xNameSurn', ar2[iar2 + 1] + ' ' + ar2[iar2 + 2]).replace('xMail', ar2[iar2]
                                     ).replace('xDDI', retOwnersPhMb(ar2[iar2 + 3], ar2[iar2 + 4]));
            ret += '<br>';

        }
    }
    return ret;

}
//http://www.each.co.uk/alert/f.aspx?**p**52083*pdf*0000002266*0000002318*
function MailBut2() {
    var Rq = (XY.It == 'r' ? 'XPIPEXReq' : '');
    return '<table cellpadding="0" cellspacing="2" style="width:565px;font-family:Arial;font-size:0.9em"><tr><td style="width:360px">no longer yours?</td><td><a href="http://www.each.co.uk/JSON/EACH/edit.htm?XPIPEXhashXPIPEX99!XPIPEXxNID' + Rq + '"><b>click&nbsp;here</b></a>&nbsp;to&nbsp<b>reallocate&nbsp;to&nbsp;a&nbsp;colleague</b></td></tr>'
            + '<tr><td colspan="2">&nbsp;</td></tr><tr><td style="width:360px">details incorrect?</td><td><a href="http://www.each.co.uk/JSON/EACH/edit.htm?XPIPEXhashXPIPEX99!XPIPEXxNID' + Rq + '">click here to edit</a></td></tr>'
            + '<tr><td colspan="2">&nbsp;</td></tr><tr><td style="width:360px">password to login to my account&nbsp;</td><td><a href="http://www.each.co.uk/psw">email&nbsp;me&nbsp;a&nbsp;password</a></td></tr></table>';
}

function MailButStatus(J) {
    var Rq = (XY.It == 'r' ? 'XPIPEXReq' : '');
    var ret = '<table cellpadding="0" cellspacing="2" style="width:565px"><tr><td style="width:300px;display:block"><u>Please CLICK ONCE to update status to:</u>&nbsp;&nbsp;</td>'
            + '<td style="font-size:0.9em;background:#d6eac2;width:205px;border:1px solid #060;text-align:left"><a style="text-decoration:none;color:#060" title="change the status to Active" href="http://www.each.co.uk/JSON/EACH/edit.htm?XPIPEXhashXPIPEX0!XPIPEXxNID' + Rq + '">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;AVAILABLE</a></td></tr>';
    if (isProp(J.It) && J.T.split('|')[0] == "8" && J.F.length > 10) ret += '<tr><td style="width:300px">&nbsp;</td><td style="font-size:0.9em;background:#F3E67B;width:205px;border:1px solid #440" ><a style="text-decoration:none;color:#440;" href="http://www.each.co.uk/JSON/EACH/edit.htm?XPIPEXhashXPIPEX50!XPIPEXxNID' + Rq + '">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;PART&nbsp;Under&nbsp;offer</a></td></tr>';
    ret += '<tr><td style="width:300px;display:block">&nbsp;</td><td style="font-size:0.9em;background:#F3E67B;width:205px;border:1px solid #440" ><a style="text-decoration:none;color:#440" href="http://www.each.co.uk/JSON/EACH/edit.htm?XPIPEXhashXPIPEX1!XPIPEXxNID' + Rq + '">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;UNDER OFFER</a></td></tr>';
    ret += '<tr><td style="width:300px">&nbsp;</td><td style="font-size:0.9em;background:#E1AEAD;width:205px;border:1px solid #600"><a style="text-decoration:none;color:#600" href="http://www.each.co.uk/JSON/EACH/edit.htm?XPIPEXhashXPIPEX2!XPIPEXxNID' + Rq + '">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;WITHDRAWN</a></td></tr>';
    if (isProp(J.It) && J.T.split('|')[0] == "8" && J.F.length > 10) ret += '<tr><td  style="width:350px">&nbsp;</td><td style="font-size:0.9em;background:#E1AEAD;width:205px;border:1px solid #600"><a style="text-decoration:none;color:#600" href="http://www.each.co.uk/JSON/EACH/edit.htm?XPIPEXhashXPIPEX50!XPIPEXxNID' + Rq + '">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;PART&nbsp;Completed</a></td></tr>';
    ret += '<tr><td style="width:300px">&nbsp;</td><td style="font-size:0.9em;background:#E1AEAD;width:205px;border:1px solid #600"><a style="text-decoration:none;color:#600" href="http://www.each.co.uk/JSON/EACH/edit.htm?XPIPEXhashXPIPEX4!XPIPEXxNID' + Rq + '">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;COMPLETED</a></td></tr></table>';

    return ret;
}
var MailsBd = new Array(); //MailsBd[32] = MailsBd[0];
MailsBd[0] = '060'; MailsBd[1] = '440'; MailsBd[2] = '600'; MailsBd[4] = MailsBd[2]; MailsBd[7] = '006';
function MailMap(J) {
    if (retA(J.It) == 'r' || NoStreet(J.H)) return '&nbsp;';
    return map = '<a style="background:#fff;padding:3px;text-decoration:none;color:#' + MailsBd[J.S] + ';border:1px solid #' + MailsBd[J.S]
                + '" href="http://www.4prop.com/map1.htm?g=' + J.Lt + '*' + J.Ln + '">Map</a>&nbsp;';
}
function MailImg(J) {
    if (NoStreet(J.H)) return 'images\\Google\\NoPicture.jpg';
    if (J.Im.length < 2 || NoStreetNum(J.H)) {
        if (J.R.split('|')[9] == 1) return 'images\\Google\\' + J.I + '_mp.jpg';
        return 'images\\Google\\NoPicture.jpg';
    }
    var ar = J.Im.split('*');
    if (ar[ar.length - 2].indexOf('^') > -1) return "images\\Property\\" + oldPic(ar[ar.length - 2], J.I) + "_thumb.jpg";
    else {
        var ar2 = ar[ar.length - 2].split('|'); //ar = J.Im.split('*'), 
        return "JSON\\NIDs\\" + ar2[5] + "\\" + ar2[0] + "\\thumb" + ar2[1];
    }
}
function MailEditLink(J, action, name, type) {
    var q = '*q';
    if (type == 0)
        return '<a style="padding:3px;text-decoration:none;color:#' + MailsBd[J.S] + ';border:1px solid #' + MailsBd[J.S]
                    + '" href="http://www.each.co.uk/JSON/EACH/edit.htm?*' + J.R.split('|')[10] + '*' + action + '!*xNID' + (retA(J.It) == 'r' ? '*req' : '') + q + '">' + name + '</a>';
    if (type == 1)
        return '<a style="color:#a00" href="http://www.each.co.uk/JSON/EACH/edit.htm?*' + J.R.split('|')[10] + '*' + action + '!*xNID' + (retA(J.It) == 'r' ? '*req' : '') + q + '">' + name + '</a>';
}
function MailAttach(J, source) {
    if (NoCompanyPDF(J.H)) return '';
    if (J.At.length < 2) return MailEditLink(J, 100, 'Pdf', 0);
    var ar = J.At.split('*'), iar, h, ret, url = '';
    if (J.File == undefined) {
        J.File = new Array();
        for (iar = 0; iar < ar.length && ar[iar].length > 1; iar++) {
            if (ar[iar].split('|').length > 5)
                J.File[J.File.length] = { "f": ar[iar].split('|')[0] + '|' + ar[iar].split('|')[1], "d": 0, "dsc": ar[iar].split('|')[2], "date": ar[iar].split('|')[3], "size": ar[iar].split('|')[4], "nid": ar[iar].split('|')[5] };
            else if (ar[iar].split('|').length > 3)
                J.File[J.File.length] = { "f": ar[iar].split('|')[0], "d": 0, "dsc": ar[iar].split('|')[1], "date": ar[iar].split('|')[2], "size": ar[iar].split('|')[3], "nid": ar[iar].split('|')[4] };
            else
                J.File[J.File.length] = { "f": ar[iar].split('^')[0] + '^' + ar[iar].split('^')[1] + '^' + ar[iar].split('^')[2], "d": 0, "dsc": ar[iar].split('^')[3], "date": ar[iar].split('^')[4], "size": ar[iar].split('^')[5], "nid": "" };
        }
    }
    iar = J.File.length - 1;
    if (J.File[iar].nid.length == 0) {
        ar = J.File[iar].f.split('^');
        url = URL(retA(J.It), ret10(ar[0]), ret10(ar[1]), ar[2].split('.')[0], ar[2].split('.')[1], J.I, source, 'xNID', '*');
    }
    else if (J.File[iar].size == 0 && J.File[iar].f.split('|').length < 2) { //URL attachment
        ar = J.File[iar].f.split('|');
        url = 'http://www.each.co.uk/t.htm?' + J.I + '*' + source + '*' + retA(J.It) + '*xNID*' + ar[0].replace('http://', '');
    }
    else {
        ar = J.File[iar].f.split('|');
        var end = ar[1].split('.')[ar[1].split('.').length - 1], fn = ar[1].substring(0, ar[1].length - end.length - 1);
        url = URL(retA(J.It), J.File[iar].nid, ar[0], fn, end, J.I, source, 'xNID', '');
    }
    return '<a style="padding:3px;text-decoration:none;color:#' + MailsBd[J.S] + ';border:1px solid #' + MailsBd[J.S] + '" href="' + url + '">Pdf</a>';  //+ (pure == 0 ? '||' : '');
}
function MailData(J, L, source, json) {
    if (!isReq(J)) {
        J.mail = 1;
        json.images = MailImg(J);
        json.attachments += Status[J.S] + '|' + MailsBd[J.S] + '|' + htmPSTIDs(J).substring(0, 45) + '|' + J.I + '|' + XY.StatText[J.S] + '|'
                            + MailLoc(J.Lc.split('|'), J.H) + '|' + htmlSizeP(J, 0).replace(/£/g, '&pound;') + htmlTenure(J) + '|' + htmlOwners(J, 1) + '|'
                            + J.D.replace(/£/g, '&pound;') + "<div style='color:#f00;font-size:0.8em'>last status DateChecked</div><br>".replace('DateChecked', J.R.split('|')[0].length == 0 ? todayDMY : J.R.split('|')[0]) + '|'
                            + MailMap(J) + MailAttach(J, source);
        J.mail = 0;
    }
    else
        json.attachments += Status[J.S] + '|' + MailsBd[J.S] + '|' + $(L).find('div.block2').find('div[name=tp]').find('div.tp1').html() + '|' + J.I + '|' + XY.StatText[J.S] + '|'
                          + $(L).find('div.block2').find('.Location').html().replace(/£/g, '&pound;') + '|'
                          + $(L).find('div.block2').find('.Size').html().replace(/£/g, '&pound;') + '|'
                          + J.D.replace(/£/g, '&pound;') + '|'
                          + htmlOwners(J, 1) 
                          + "<div style='color:#f00;font-size:0.8em'>last status DateChecked</div>".replace('DateChecked', J.R.split('|')[0].length == 0 ? todayDMY : J.R.split('|')[0]) + '|' //htmlOwners(J, 1)
                          + MailAttach(J, source);  
}
function MailLoc(l, h) {
    var r = '', pc = l[1].split(' ')[0]; 
    if (!NoStreet(h)) {
        if (l[3].length > 0) r += l[3] + '<br>';
        if (!NoStreetNum(h)) {
            if (l[7].length > 0 && l[6].length > 0) r += l[6] + ", " + l[7] + '<br>'; //buld no + building
            else if (l[6].length > 0) r += l[6] + '<br>';
            else if (l[7].length > 0) r += l[7] + '<br>';
            if (l[0].length > 0) r += l[0] + '&nbsp;';
        }
        if (l[2].length > 0) r += l[2] + '<br>';
    }
    r += ('xTW<br>').replace(/xTW/g, (l[4].length > 0 && l[5].length > 0 ? l[5] + '<br>' + l[4] : (l[5].length > 0 ? l[5] : l[4]))); //town suburb...
    r += pc;
    return r;
}

function NoMatches(L, status) {
    $(L).find('div.MatchesBar').html('No matches...').animate({ opacity: 0.5 }, 1000,
                            function() {
                                $(L).find('div.MatchesBar').css('opacity', '');
                                $(L).find('a.matches').trigger('click');
                            }
                        );
    if (status > 17) $(L).find('a.matches').html('0 matched on ' + todayDMY + ', click to rematch');
}
function BlockFill(ItTpI, htms) {
    var N = ItTpI.split('|'), L = ListId(ItTpI), J = JSON[N[0]][N[2]], B = BarId(N[0] + '|' + N[1]);
    $(L).find('div.block2').html(htms).find('span,img').css('float', 'left').css('display', 'inline-block');
    if (J.M > 0) $(L).find('div.block2').css('background', Status['M' + J.S]).find('img.imgblock').css('width', '127px'); //matches    

    if (XY.searched.length > 0) htmlBlockSearch($(L).find('div.block2'), J);
    $(L).find('div.block2').find('div.dvComments').find('img').mouseover(function() { $(this).css('opacity', 0.5); }).mouseout(function() { $(this).css('opacity', ''); }
        ).click(function() {
            switch ($(this).attr('class')) {
                case 'com':
                    $(L).find('div.block2').find('div.comments').html(htmlCommentsEdit(J)).css('display', 'block').find('textarea').focus(function() { $(this).select(); });
                    $(L).find('div.block2').find('div.comments').find('a').mouseover(function() { $(this).css('opacity', 0.5); }).mouseout(function() { $(this).css('opacity', ''); }).click(
                                    function() {
                                        $(this).parent().slideUp('fast'); //.css('display', 'none');//.find('div.comments')slideDown('slow')
                                        var tx = $(this).parent().find('textarea').val();
                                        if (tx.length > 0 && tx != 'Write your comment here...') AddComment(J, $(this).parent().parent(), tx, todayDMY, 1);
                                    });
                    break;
                case 'fav':
                    if (isFavo(J)) return;
                    isFavoAdd(J, 0);
                    $(this).attr('src', "http://www.4prop.com/JSON/images/common/Rolls/Favourite0.png").attr('title', 'in your Favourites').css('float', 'left'); //
                    break;
                case 'rej':
                    var n = XY.iti.split('|'), l = ListId(XY.iti), j = JSON[n[0]][n[2]];
                    j.Active += ($(L).attr('name2') == '0' ? -1 : 1);
                    J.Rej = ($(L).attr('name2') == '0' ? 1 : 0);
                    $(L).css('display', 'none').attr('name2', ($(L).attr('name2') == '0' ? '1' : '0'));
                    $(l).find('div.MatchesBar').find('span.b').slice(0, 1).html(j.Active + ' ACTIVE');
                    $(l).find('div.MatchesBar').find('span.b').slice(2, 3).html((j.All - j.Active) + ' rejected');
                    isRejeAdd(J, ($(L).attr('name2') == '1' ? 0 : 1));
                    break;
            }
        }
        );
    Weakening(L); //

    var cms = isCommPriv(J).split('|');
    for (var icms = 0; icms < cms.length; icms++) {
        if (cms[icms].length > 3)
            AddComment(J, $(L).find('div.block2').find('.speech:last').parent(), cms[icms].split('~')[0], retDDMMYYHHMM2(cms[icms].split('~')[1]), 0);
    }
    if (isFavo(J)) $(L).find('div.block2').find('div.dvComments').find('img.fav').attr('src', "http://www.4prop.com/JSON/images/common/Rolls/Favourite0.png").attr('title', 'in your Favourites').css('float', 'left');

    //match or notmatched//!= 'n' J.It.length == 1 &&
    $(L).find('a.edit,a.status,a.agent').attr('disabled', J.IS < 2); //disable if it is not mine...
    if (J.S > 17) {// It == 'rl' || J.It == 'rq'  find listing...
        $(L).find('a.status,a.clicks,a.mail,a.pdf,a.word,a.h,img.rej,img.fav,a.copy').css('display', 'none'); //a.agent
        var srematch = J.R.split('|')[2] + ' matched on ' + J.R.split('|')[12];
        if (J.R.split('|')[2] == '0') srematch += ' click to rematch';
        else srematch = 'list ' + srematch;
        $(L).find('div.block2').find('a.matches').html(J.R.split('|')[12].length == 0 ? 'GO' : srematch);
        if (J.R.split('|')[12].length == 0) $(L).find('a.copy,a.edit,a.del').attr('disabled', true);
    }
    else {
        if (J.M == 0 || retZ(J.It) == 'n') {//.length >  1XY.It == J.It   list + new... comments list
            $(L).find('div.block2').find('div.dvComments').find('img.rej,img.fav').css('display', 'none');
            XY.iti = ItTpI;
            if (J.It.length > 1 && retZ(J.It) != 'u') $(L).find('a.copy,a.edit,a.status,a.clicks,a.matches,a.mail').css('display', 'none'); //a.agent,
        }
        if ((J.M > 0 || XY.view))// XY.It != J.It  == 1
            $(L).find('div.block2').find('div.Control').find('a').slice((XY.It == 'r' ? 4 : 3), 12).css('display', 'none');
        if (J.S == 7) {
            $(L).find('a.status,a.clicks,a.mail').css('display', 'none');
        }
        else $(L).find('a.del').css('display', 'none');
    }
    var btns = 'a.del,a.matches,a.status,a.pdf,a.word,a.agent,a.map,a.clicks,a.mail,a.edit,a.copy,a.enq';
    if (J.S > 17) btns = 'a.del,a.agent,a.matches,a.edit,a.copy';
    $(L).find(btns).mouseover(function() {
        if ($(this).attr('name') == '1') return;
        if ($(this).attr('class') == "enq") $(this).css('opacity', 0.5);
        else $(this).css('background-color', '#0F2A86').css('color', '#eef');
    }).mouseout(function() {
        if ($(this).attr('name') == '1') return;
        if ($(this).attr('class') == "enq") $(this).css('opacity', '');
        else $(this).css('background-color', $(this).attr('name3') == '1' ? '#fff' : cSTATUS[parseInt(J.S) + 10]).css('color', '');
    }).click(function() {
        var cls = $(this).attr('class');
        if (ControlCloseAll(ItTpI, this) != '1') {
            if (J.S < 17 || (cls != "edit" && cls != 'copy')) offsetY(L);

            if (cls == "del") {
                $(L).find('div.block2').css('background-color', 'red');
                if (confirm("Do you really want to delete the above " + propreq[XY.It])) {
                    //J.S = 9; //deleted
                    $(L).slideUp('fast');
                    $.post(urlLoad, { list: 3, Nid: J.I, Type: 113, BID: (J.S < 18 ? XY.It : 'r') }, function(d) {
                        if (J.S < 18) {
                            if (XY.It == 'r') XY.Reqs--; else XY.Props--;
                            PropReq();
                        }
                        else {
                            XY.ListFind--;
                            ListFind();
                        }
                        $(B).find('table.bar').find('td.count').each(function() { var c = parseInt($(this).html()) - 1; $(this).html(c); if (c == 0) $(B).html('All items deleted from the list').attr('class', 'NoListing'); });
                        J.S = 9;
                    });
                }
                else {
                    $(L).find('div.block2').css('background-color', '');
                    ControlCloseAll(ItTpI, this);
                }
            }
            else if (cls == "matches") {
                if (J.S > 17) {
                    //XY.Crit = 12;
                    XY.NoMove = 1; //alert('Listing Find...');
                    if (J.I == 0) {
                        $(this).attr('name', '');
                        FindGoNew();
                        return;
                    }
                }
                $('#RESULT').find('div.bar').css('opacity', 0.3);
                //if (retZ(ItTpI.split('|')[0]) != 'n') XY.Match = (XY.It == 'r' ? 'pr' : 'rp');
                //else XY.Match = (XY.It == 'r' ? 'pn' : 'rn');
                XY.iti = ItTpI;
                $(B).css('opacity', '').find('div.list').css('opacity', 0.3);
                $(L).attr('matches', '1').css('opacity', 1).find('div.MatchesBar').html(waitSometime("Loading " + (J.S < 18 ? "matches" : "list") + "...")).css('display', 'block');
                jsCriteria = { CID: "", list: 1 };
                arSelected[XY.Match] = new Array();
                if (J.S > 17) {
                    jsCriteria.ListFind = J.I; // ListFind = 1;
                    XY.Match = 'pr';
                    if (J.S > 19) {
                        jsCriteria.Requirement = 1;
                        XY.Match = 'rp';
                    }
                    XY.M = '';
                    //XY.Match = (XY.It == 'p' ? 'pr' : 'rp');
                    if (J.S == 19 || J.S == 21) jsCriteria.archive = 1;
                    //$(L).find('a.matches:first').html('Rematch');                    
                }
                else {
                    if (J.It == 'ru') XY.It = 'r';
                    if (J.It == 'pu') XY.It = 'p';
                    if (retZ(ItTpI.split('|')[0]) != 'n') XY.Match = (XY.It == 'r' ? 'pr' : 'rp');
                    else XY.Match = (XY.It == 'r' ? 'pn' : 'rn');
                    if (XY.It == 'p') jsCriteria.propertyMatch = J.I;
                    else jsCriteria.requirementMatch = J.I;
                    if (J.S == 7) jsCriteria.status = 7;
                }
                $.post(urlLoad, jsCriteria, function(output) {
                    if (trim(output).length == 0) {
                        NoMatches(L, J.S);
                        return;
                    }
                    JSON[XY.Match] = eval(output);
                    if (JSON[XY.Match].length == 0)
                        NoMatches(L, J.S);
                    else {
                        AddedSince = 0;
                        var im = N[0] + N[1] + N[2], J2, rd;
                        J.Active = 0;
                        try {
                            for (var i = 0; i < JSON[XY.Match].length; i++) {
                                J2 = JSON[XY.Match][i]; J2.dt = new Date(); rd = J2.R.split('|')[12].split(' ');
                                J2.dt.setFullYear(rd[2]); J2.dt.setMonth(parseFloat(aMd[rd[1]])); J2.dt.setDate(rd[0]);
                                J2.Ad = AddedYes(J2.dt); J2.ck = 0; J2.rc = 0; J2.II = i; J2.found = 1; J2.It = XY.Match;
                                J2.tp = J2.T.split('|')[0]; J2.Crit = J2.tp; J2.Wd = J2.At.indexOf('.doc') + J2.At.indexOf('.rtf'); J2.Pf = J2.At.indexOf('.pdf');
                                J2.block = 0; J2.IS = IS; J2.NoMove = 1; J2.View = 1; J2.My = 0;
                                J2.M = 1; J2.S0 = J.S; //(J.S > 17 ? J.S : 0);
                                J.Active++; J2.Rej = 0;
                                if (BarsCrit(J2.N.split('|')[0], _gNid)) J2.My = 1;
                                if (isReje(J2)) {
                                    J2.Rej = 1;
                                    J.Active--;
                                }
                            }
                        } catch (e) { }
                        J.All = i;
                        var rej = (J.All - J.Active);
                        if (rej == 0 && XY.MatchButton == 0) XY.MatchButton = 10;
                        $(L).find('div.MatchesBar').html(
                                            ('<div class=Action name=0 style="clear:both;color:#eef;margin-top:2px"><span style="width:170px;display:inline-block;font-weight:bold">for&nbsp;this&nbsp;'
                                              + (J.S < 18 ? propreq[retA(XY.It)] : XY.StatText[J.S])
                                              + '&nbsp;there&nbsp;are</span><span name2=0 class=b>' + J.Active + ' ACTIVE</span><br><span name2=1 style="margin-left:170px;margin-top:2px" class=b>' +
                                              +AddedSince + ' added since</span>&nbsp;<input title="click to change date" style="border:0px;border-bottom:1px solid #fff" onclick="showCalendarControl(this)" class="Added" value="'
                                              + (MatchesDMY.getDate() + ' ' + aM[MatchesDMY.getMonth()] + ' ' + MatchesDMY.getFullYear()) + '" /><br><span style="margin-left:170px;margin-top:2px" name2=2 class=b>'
                                              + rej + ' rejected</span><span style="margin-left:99px;font-size:1em;font-weight:bold">matched ' + propreqs[retA(XY.Match)] + ' below</span></div>'
                                              + '<div class=matchPages></div><div class=otherPages></div><div class=Action2 style="margin-top:8px;width:100%"><span class="hlp" name2=1 title="help for matches" style="float:right;margin-top:-2px;margin-right:4px"></span><span class="prn" title="select Report\nto print/email" style="margin-top:-4px"></span><span title="click to set up\nemail to Agents" class=Em2Ag></span><span style="font-size:0.9em;display:inline-block">&nbsp;eg&nbsp;request&nbsp;PDF,&nbsp;viewing</span><div class=MATCHmail></div><div name4=1 class=help></div><div id=rp2 class=drp></div></div>'
                                        ).replace(/IM/g, im)).find('div.Action').find('span.b'
                                        ).mouseover(function() { $(this).css('opacity', 0.5); }).mouseout(function() { $(this).css('opacity', ''); }
                                        ).click(function() {
                                            $(L).find('div.MatchesBar').find('span.b').css('font-weight', 'normal').css('color', '').css('background', "url('http://www.4prop.com/JSON/images/common/Rolls/Match.png') no-repeat"); //-color
                                            $(this).css('background', '#0F2A86').css('color', '#eef').css('font-weight', 'bold');
                                            if (XY.MatchButton == 10) { XY.MatchButton = 0; return; }
                                            XY.MatchButton = parseInt($(this).attr('name2')); //.css('padding-left', '0px')
                                            XY.M = $(L).find('div.Matches[name="' + ItTpI + '"]');
                                            MatchBarUpButtons();
                                        });
                        $(L).find('div.MatchesBar').find('input.Added').mouseover(function() { $(this).css('opacity', 0.5); }).mouseout(function() { $(this).css('opacity', ''); });
                        $(L).find('div.MatchesBar').find('div.Action2').find('span.Em2Ag').mouseover(function() { $(this).css('opacity', 0.5); }).mouseout(function() { $(this).css('opacity', ''); }
                                                ).click(function() {
                                                    var Ids = retSel(XY.Match); //must be nulled...
                                                    if (Ids.length == 0) {
                                                        alert('No ' + propreq[XY.Match] + ' selected!');
                                                        return;
                                                    }
                                                    var dM = $(L).find('div.MatchesBar').find('.MATCHmail:first');
                                                    $(dM).css('display', 'none');
                                                    if ($(this).css('background', "url('http://www.4prop.com/JSON/images/common/Em2Ag.png') no-repeat").css('color', '').attr('name') == '1') { $(this).attr('name', '0'); return; }
                                                    $(this).attr('name', '1').css('background', "url('http://www.4prop.com/JSON/images/common/Em2AgO.png') no-repeat"); //.css('color', '#eef');
                                                    $(dM).html('<div class=tit><table width=100% cellspacing=0 cellpadding=0><tr><td>Subject&nbsp;Title&nbsp;of&nbsp;email:</td><td align=right><input onfocus="this.select()" value="information request for '
                                                                + MailSubject(eval('jsPts.v' + J.tp) + (isProp(J.It) ? ' at ' : ' in '), J, J.Lc.split('|')) + '" /></td></tr></table></div><textarea onclick="this.select()">'
                                                                + mailMessage + '</textarea><span class=b title="Email above message to agents\nwith selected matches below">Email above message to agents with selected matches below</span>'
                                                         ).css('display', 'block').find('span.b').mouseover(function() { $(this).css('background-color', '#003').css('color', '#aaf').parent().find('textarea').css('background-color', '#003').css('color', '#aaf'); }).mouseout(function() { $(this).css('background-color', '').css('color', '').parent().find('textarea').css('background-color', '').css('color', ''); }
			                                             ).click(function() {
			                                                 mailMessage = replSplChr($(dM).find('textarea').val());
			                                                 if (mailMessage == "Enter your message here (max 200 chs)" || mailMessage == '') {
			                                                     alert('You did not write any message');
			                                                     $(dM).find('textarea').select();
			                                                     return;
			                                                 }
			                                                 jsCriteria = { HtmlTemplate: 'MatchPropertyEmail', From: "info@each.co.uk", PIDS: Ids, RIDS: Ids, Mails: 1, Message: escape(mailMessage), Subject: escape($(dM).find('input:first').val()), NIDs: _gNid };
			                                                 jsCriteria.To = "miroslav@each.co.uk,miro.brada@yahoo.co.uk";
			                                                 jsCriteria.attachments = '';
			                                                 MailData(J, L, 91, jsCriteria);
			                                                 jsCriteria.FromTitle = MailFromTitle(J);
			                                                 //if (XY.It == "r") jsCriteria.HtmlTemplate = "MatchRequirementEmail";
			                                                 if (XY.It == "r") {
			                                                     jsCriteria.HtmlTemplate = "MatchRequirementEmail";
			                                                     jsCriteria.RIDS = J.I;
			                                                 } else jsCriteria.PIDS = J.I;
			                                                 $(dM).html('<table style="width:540px"><tr><td>' + waitSometime('Sending your information requests...') + '</td></tr></table>'); //.css('display', 'block');
			                                                 jsCriteria.attachments = escape(jsCriteria.attachments.replace(new RegExp("\\*q", "g"), ""));
			                                                 $.post(urlLoad, jsCriteria, function(output) {
			                                                     $(dM).html('<table style="width:540px"><tr><td style="text-align:center"><br><br><b>Your email(s) are sent...</b></td></tr></table>').animate({ opacity: 0.5 }, 1500, function() {
			                                                         $(this).css('opacity', '');
			                                                         $(L).find('div.MatchesBar').find('div.Action2').find('span.Em2Ag').trigger('click');
			                                                     });
			                                                 });
			                                             }
			                                        );
                                                }
                                            );

                        $(L).find('div.Matches').attr('name', ItTpI);
                        XY.L = L; XY.J = J;
                        XY.offset = L; //Error...ItTpI.split('|')[0]
                        if (J.S > 17 || IsMenu == "100") XY.Crit = 12;
                        fBars($(L).find('div.Matches[name="' + ItTpI + '"]'), BarTitles(JSON[XY.Match][0], XY.Match));
                        if (J.S > 17) {
                            var R = J.R.split('|');
                            R[2] = JSON[XY.Match].length;
                            R[12] = todayDMY;
                            J.R = retPipedString(R);
                            $(L).find('a.matches').html('list ' + J.R.split('|')[2] + ' matched on ' + J.R.split('|')[12]);
                            //28 Dec 2011||0|28 Dec 2011|||||||72d787c7||28 Dec 2011|||||
                        }
                        $(L).find('div.Matches[name="' + ItTpI + '"]').find('table.bar').find('td.count').html(CountLastArrayEmpty(JSON[XY.Match].length));
                        var viewtype = 2;
                        if (XY.It == 'r' && J.Lc.split('|')[0].length > 0) viewtype = 1; //map view
                        else if (J.R.split('|')[2] < 12) viewtype = 3; //block view                            
                        setTimeout(function() { View(XY.Match + '|' + JSON[XY.Match][0].Crit, viewtype); }, 1500);
                        REPORT($(L).find('div.MatchesBar'), "#rp2", XY.Match); //retA(XY.Match));
                        $($(L).find('div.MatchesBar')).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 ($(this).attr('name') != '1') {
                                        $(this).attr('name', '1').css('background-color', '#393').css('color', '#efe');
                                        $('.help[name4=1]').html('<table border=0 cellspacing=0 cellpadding=0><tr><td style="height:16px"><div class=pin></div></td></tr><tr><td><div class=body>'
                                            + "These Instructions have been emailed to all interested agents on EACH Alert <br>It has been emailed to all Agents with matching properties <br>you can make extra notes<br><br><span style='padding:1px;background:#d6eac2;color:#3B519C'>green=Available</span> <span style='padding:1px;background:#F8F1B4;color:#3B519C'>yellow=Under Offer</span> <span style='padding:1px;background:#EBC9C8;color:#3B519C'>red=Completed or Withdrawn</span>(falling off after 3 days)<br><br><br>The Instructions below match your Instruction above, and have<br>a) been emailed to Agents where entered on EACH before your Instruction,<br>b) been emailed to you where entered on EACH after your Instruction.<br><br><br>Click <span style=\"background:url('http://www.each.co.uk/images/toolbar/Minus.jpg') no-repeat left top;width:13px;height:13px;display:inline-block\"></span>&nbsp; to move that matching Instruction to the rejected list<br>Click <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>&nbsp; to record a privately viewable comment for all instances of that match<br>Click <span style=\"background:url('http://www.4prop.com/JSON/images/common/Rolls/Favourite.png') no-repeat left top;width:13px;height:13px;display:inline-block\"></span>&nbsp; to move that Instruction to your Favourites list on www.each.co.uk<br><br><br>Click <span style=\"background:url('http://www.4prop.com/JSON/images/common/PrintBlue.png') no-repeat left top;width:17px;height:17px;display:inline-block\"></span>&nbsp; to create a Report from the selected matches below<br>Click <span style=\"background:url('http://www.4prop.com/JSON/images/common/Em2Ag.png') no-repeat left top;width:225px;height:17px;display:inline-block\">&nbsp;</span> to individually email your note for selected matches <br><br><br>email for help (and build Q&A) for this page<br><br><span style='padding:1px;background:#d6eac2;color:#3B519C'>green=Available</span> <span style='padding:1px;background:#F8F1B4;color:#3B519C'>yellow=Under Offer</span> <span style='padding:1px;background:#EBC9C8;color:#3B519C'>red=Completed or Withdrawn</span>(falling off after 3 days)"
                                            + '</div></td></tr></table>'
                                            ).css('display', 'block');
                                    }
                                    else {
                                        $(this).attr('name', '0').css('background-color', '').css('color', '');
                                        $('.help[name4=1]').css('display', 'none');
                                    }
                                }
                            );

                        if (AddedSince > 0) setTimeout("calcAdded()", 2000);
                        if (XY.hash == 0) {
                            matchPagesFill(L, J, J.Crit);
                            OtherPages(L, J);
                        }
                    }
                });
                $(L).find('div.Matches').slideDown('slow');
            } else if (cls == "clicks") {
                var hC = '', nids = '', r, ld = 'Loading..', r0 = 0, Msg4propIs = '';
                if ($(L).find('div.Clicks').html().length < 10) {
                    var ar = J.R.split('|')[14].split('*');
                    r0 = ar.length; //4prop enquiry
                    for (r = 0; r < ar.length && ar[r].length > 4; r++) {
                        Msg4propIs += ',' + ar[r].split('%')[2];
                        hC += hClicks4Prop.replace('DateTitle', DDMMYYhhmm(ar[r].split('%')[1], 1, 1)
                                     ).replace('Date', DDMMYYhhmm(ar[r].split('%')[1], 0, 1)
                                     ).replace('Email', '<a title="click to email" href="mailto:' + ar[r].split('%')[0] + '">' + Fading(ar[r].split('%')[0], 15, 6, 'style="text-decoration:underline"') + '</a>'
                                     ).replace('Company', 'Loading message...' //Fading(ar[r].split('%')[2], 44, 6, '')
                                     ).replace('Phone', '').replace(/NID/g, 'p' + ar[r].split('%')[2]
                                     ).replace('Source', Fading('4PROP Enquiry', 8, 5, '')
                                     ).replace('TitleSrc', '4prop email enquiry'
                                     ).replace(/STYLE/g, (r % 2 == 0 ? 'background:#1D3C92' : ''));
                    } //'Print '
                    ar = J.R.split('|')[7].split('*');
                    r0 = ar.length;
                    for (r = 0; r < ar.length && ar[r].length > 4; r++) {
                        nids += ',' + ar[r].split('%')[0];
                        hC += hClicks.replace('DateTitle', DDMMYYhhmm(ar[r].split('%')[2], 1, 0)
                                     ).replace('Date', DDMMYYhhmm(ar[r].split('%')[2], 0, 0)
                                     ).replace('Email', '').replace('Company', '').replace('Phone', ''
                                     ).replace(/NID/g, ar[r].split('%')[0]
                                     ).replace('Source', '&#8471; ' + Fading(arReportedTitle[ar[r].split('%')[1]], 8, 5, '')
                                     ).replace('TitleSrc', 'Printed to report'
                                     ).replace(/STYLE/g, (r % 2 == 0 ? 'background:#1D3C92' : ''));
                    } //'Print '
                    ar = J.R.split('|')[8].split('$');
                    for (r = 0; r < ar.length && ar[r].length > 4; r++) {
                        ld = '';
                        if (ar[r].split('%')[0].indexOf('.') == -1)
                            nids += ',' + ar[r].split('%')[0];
                        else ld = ar[r].split('%')[0];
                        hC += hClicks.replace('DateTitle', DDMMYYhhmm(ar[r].split('%')[2], 1, 1)
                                 ).replace('Date', DDMMYYhhmm(ar[r].split('%')[2], 0, 1)
                                 ).replace('Email', ld).replace('Company', '').replace('Phone', ''
                                 ).replace(/NID/g, ar[r].split('%')[0]
                                 ).replace('Source', Fading(ClicksTitle[ar[r].split('%')[1]], 7, 6, '')
                                 ).replace('TitleSrc', 'Opened as attachment'
                                 ).replace(/STYLE/g, ((r0 + 1 + r) % 2 == 0 ? 'background:#1D3C92' : '')); //ffa
                    }
                    ar = J.R.split('|')[16].split('*'); //requests
                    for (r = 0; r < ar.length && ar[r].length > 4; r++) {
                        ld = '';
                        if (ar[r].split('%')[0].indexOf('.') == -1)
                            nids += ',' + ar[r].split('%')[0];
                        else ld = ar[r].split('%')[0];
                        hC += hClicks.replace('DateTitle', DDMMYYhhmm(ar[r].split('%')[1], 1, 1)
                                 ).replace('Date', DDMMYYhhmm(ar[r].split('%')[1], 0, 1)
                                 ).replace('Email', ld).replace('Company', '').replace('Phone', ''
                                 ).replace(/NID/g, ar[r].split('%')[0]
                                 ).replace('Source', Fading('Request attachment', 7, 6, '')
                                 ).replace('TitleSrc', 'Request attachment'
                                 ).replace(/STYLE/g, ((r0 + 1 + r) % 2 == 0 ? 'background:#1D3C92' : '')); //ffa
                    }
                    $(L).find('div.Clicks').html('<b>Those below were interested and opened your attachment</b><table cellspacing=0 style="border-top:1px solid #aaf" cellpadding=0 width=100%>' + hC + '</table><div style="clear:both"></div>');
                    Criteria = { list: 3, Nid: nids, Cid: Msg4propIs };
                    $.post(urlLoad, Criteria, function(output) {
                        ar = output.split('*');
                        try {
                            for (r = 0; r < ar.length && ar[r].length > 4 && ar[r].split('|')[0].length > 0; r++) {
                                nids = ar[r].split('|')[0];
                                if (nids.substring(0, 1) != 'p') {
                                    $(L).find('div.Clicks').find('td.e' + nids).attr('title', ar[r].split('|')[4] + ' ' + ar[r].split('|')[5]
                                            + '\n' + ar[r].split('|')[1]).html('<a title="click to email" href="mailto:' + ar[r].split('|')[1] + '">' + Fading(ar[r].split('|')[1], 15, 6, '') + '</a>').find('font').css('text-decoration', 'underline');
                                    $(L).find('div.Clicks').find('td.c' + nids).attr('title', ar[r].split('|')[2]).html(Fading(ar[r].split('|')[2], 15, 6, ''));
                                    $(L).find('div.Clicks').find('td.p' + nids).html(ar[r].split('|')[3]);
                                }
                                else $(L).find('div.Clicks').find('td.c' + nids).attr('title', ar[r].split('|')[2]).html(Fading(ar[r].split('|')[2], 47, 6, '')
                                        ).click(function() { $(this).html($(this).attr('title')); });
                            }
                        } catch (e) { }
                        Weakening($(L).find('div.Clicks'));
                    });
                }
                $(L).find('div.Clicks').css('display', 'block');
            }
            else if (cls == "status") {//DateChecked
                $(L).find('div.Status').html("<span class=title>Click on bar to update to the correct status</span><div style='margin-bottom:5px' class=s name=7>Unadvertised</div><div name=0 class=s>Available</div><div name=1 class=s>Under Offer</div><div name=2 class=s>Withdrawn</div><div name=4 class=s>Completed</div>&nbsp;"
                            + (J.R.split('|')[0].length == 0 ? '' : '<span class=status style="float:left;color:#fff">last status ' + J.R.split('|')[0]
                            + ', created ' + J.R.split('|')[3] + ', updated ' + J.R.split('|')[12] + ', previous updated ' + J.R.split('|')[13] + '</span>'
                           + (retA(J.It) == 'p' ? '<div class="Advert" title="updated Properties can update your website if linked with EACH"><span class=tit>Advertised on your website (if linked)</span><span class=s name2=4prop name=1 name4=0 title="markets your Properties direct to Occupiers, Investors and Developers">4prop.com/search engines</span><span class=s name2=other name4=1 title="other Property websites can be updated direct from PROP.COM " name=1>other public property websites</span><span class=s name2=ab name=1 name4=2 title="other Agents market your Properties, but you control the information">other agents websites</span></div>' : '')
                            )
                        ).css('display', 'block').find('div').slice(0, 5).each(function() { $(this).css('background', cSTATUS[$(this).attr('name')]).css('color', cSTATUSt[$(this).attr('name')]); }
                        ).mouseover(function() { $(this).css('background', cSTATUSo[$(this).attr('name')]); }).mouseout(function() { $(this).css('background', cSTATUS[$(this).attr('name')]); }
                        ).click(function() {
                            $(L).find('div.Status').find('span.title').html('Status was just updated to ' + XY.StatText[$(this).attr('name')]);
                            StatusChangeOne(ItTpI, $(this).attr('name'));
                            jsCriteria = { Update: 1, status: $(this).attr('name') };
                            DatabaseUpdate(J);
                        });
                if (retA(J.It) == 'p') {
                    J.write = 0;
                    $(L).find('div.Status').find('div.Advert').find('span.s'
                                ).mouseover(function() { $(this).css('background-color', $(this).css('color')).css('color', '#eef'); }
                                ).mouseout(function() { $(this).css('background-color', '').css('color', ''); }
                                ).click(function() {
                                    if (J.write) {
                                        if ($(this).attr('name2') == '4prop' && $(this).attr('name') == '1') {
                                            alert('you must go to Edit to change this'); return;
                                        }
                                        a4prop[$(this).attr('name4')] = ($(this).attr('name') == '0' ? '' : '01.01.2020');
                                        J.R = retPipesRpl(J.R, J.R.split('|').length - 2, a4prop.join('*'));

                                        $.post(urlLoad, { list: 3, Nid: J.I, Type: 236, UNI: $(this).attr('name'), UNI2: $(this).attr('name2') }, function(d) { });
                                        $.post(urlLoad, { IsPublic: 1, list: 3, Nid: J.I, Type: 236, UNI: $(this).attr('name'), UNI2: $(this).attr('name2') }, function(d) { });
                                    }
                                    var t = $(this).html();
                                    if ($(this).attr('name') == '1') {
                                        $(this).attr('name', '0').html('NOT ' + t).css('background', XY.uncheck);
                                    }
                                    else {
                                        $(this).attr('name', '1').html(t.replace('NOT ', '')).css('background', XY.check);
                                    }
                                });
                    var a4prop = J.R.split('|')[J.R.split('|').length - 2].split('*'), y = (new Date()).getFullYear() + 1;
                    if (a4prop[0].length > 5 && a4prop[0].split('.')[2] > y) $(L).find('div.Status').find('div.Advert').find('span.s[name2=4prop]').trigger('click');
                    if (a4prop[1].length > 5 && a4prop[1].split('.')[2] > y) $(L).find('div.Status').find('div.Advert').find('span.s[name2=other]').trigger('click');
                    if (a4prop[2].length > 5 && a4prop[2].split('.')[2] > y) $(L).find('div.Status').find('div.Advert').find('span.s[name2=ab]').trigger('click');
                    J.write = 1;
                }
            } else if (cls == "agent") {
                $(L).find('div.Agent').html(waitSometime("Loading Agent's tree...")).css('display', 'block');
                Agents(ItTpI, 1);
            }
            else if (cls == "pdf" || cls == "word") {
                $(L).find('table.tbList').find('td.img').css('background-color', '#0F2A86').find('img').attr('name', '1').css('opacity', 0.7);
                if ((XY.view || XY.action == 102) && J.At.length < 3) {//    (&& J.At.length < 3)==attachment was uploaed later...
                    if (XY.hash > 0 && get_cookie('RqPdf' + J.I) == '1')// && 1 == 2  
                        $(L).find('div.Pdf').html('<div style="color:#eef;font-size:1.5em;padding:10px">You have already requested Details / PDF for this ' + propreq[XY.It] + '</div>');
                    else {
                        $(L).find('div.Pdf').html('<div class=ReqPDF>Click here to request Details / PDF</div>'
                        ).find('div.ReqPDF').mouseover(function() { $(this).css('opacity', 0.5); }).mouseout(function() { $(this).css('opacity', ''); }
                        ).click(function() {
                            if (get_cookie('RqPdf' + J.I) == '1') {
                                $(L).find('div.Pdf').html('<div style="color:#eef;font-size:1.5em;padding:10px">You have already requested Details / PDF for this ' + propreq[XY.It] + '</div>');
                                return;
                            }
                            $(L).find('div.Pdf').html(waitSometime('Requesting Details / PDF'));
                            set_cookie('RqPdf' + J.I, '1');
                            jsCriteria = { HtmlTemplate: 'Enquiry', NIDS: _gNid, RIDS: J.I, PIDS: J.I, Mails: 1, Message: "Please email me a copy of the Details / PDF. Thank you", Subject: "PDF Request" };
                            jsCriteria.To = "miroslav@each.co.uk"; //jsCriteria.CC = "miro.brada@yahoo.co.uk,miro.brada@seznam.cz"; //,af@each.co.uk,a@f.eclipse.co.uk,"; //af@each.co.uk,a@f.eclipse.co.uk,miro.brada@seznam.cz,gopi@each.co.uk ,af@each.co.uk,a@f.eclipse.co.uk"; //,af@each.co.uk,a@f.eclipse.co.uk,
                            jsCriteria.FromTitle = MailFromTitle(J); // Company + ": Pdf Request";af@each.co.uk,a@f.eclipse.co.uk,
                            if (XY.It == 'r') jsCriteria.HtmlTemplate = 'EnquiryReq';
                            jsCriteria.attachments = '|' + MailButStatus(J).replace(/hash/g, J.R.split('|')[10]) + MailBut2().replace(/hash/g, J.R.split('|')[10]) + '|';
                            MailData(J, L, 0, jsCriteria);
                            jsCriteria.attachments = escape(jsCriteria.attachments.replace(new RegExp("\\*q", "g"), ""));

                            $.post(urlLoad, jsCriteria, function(output) {
                                setTimeout(function() {
                                    $(L).find('div.Pdf').html('<center><b>Your request was sent...</b></center>');
                                    setTimeout(function() { ControlCloseAll(XY.iti, ""); }, 500);
                                }, 500);
                            });
                        });
                        if (XY.action == 100 && XY.hash > 0) $(L).find('div.ReqPDF').trigger('click');
                    }
                }
                else {
                    $(L).find('div.Pdf').html(XY.hFiles.replace('&pid=', (XY.It == 'r' ? "" : '&pid=')).replace('PIC', (XY.It == 'r' ? "" : XY.hPic)).replace(/NID/g, _gNid).replace(/ID/g, N[0] + '*' + N[1] + '*' + N[2]));
                    J.Picture = new Array(); J.PictureAll = new Array(); J.File = new Array();
                    $(L).find('div.Pdf').find('.urlatt').find('a'
                            ).mouseover(function() { $(this).parent().find('input').css('background', '#bbf'); }
                            ).mouseout(function() { $(this).parent().find('input').css('background', ''); }
                            ).click(function() {
                                var aurl = trim($(this).parent().find('input').val());
                                if (aurl.replace('ONLY enter/paste a URL for a specific HTML or PDF file for this ' + propreq[XY.It], ''
                                       ).replace('you must add url attachment link here...', '').length == 0)
                                    $(this).parent().find('input').val('you must add url attachment link here...').css('color', '#f00');
                                else {
                                    if (aurl.substring(0, 7) != 'http://') aurl = 'http://' + aurl;
                                    if ($(this).attr('name') == 'v') window.open(aurl);
                                    else {
                                        FileAttached(aurl.replace(/\|/g, 'XPIPEX'), 0, 1, ItTpI.replace(/\|/g, '*')); //FileAttached(s, size, p, ItTpI);
                                    }
                                }
                            }
                    ).parent().find('input').val('ONLY enter/paste a URL for a specific HTML or PDF file for this ' + propreq[XY.It]
                    ).focus(function() { $(this).attr('color', ''); });

                    if (XY.It == 'p') $(L).find('div.Pdf').find('table.tbPics').html(XY.tbPics);
                    if (J.Im.length > 1) PicPop(J, ItTpI);
                    if (J.At.length > 1) {// (J.H & 1)                     
                        if (NoCompanyPDF(J.H)) {
                            if (J.IS < 3) {
                                $(L).find('div.Pdf').css('opacity', 0.7).find('tr.files').find('td').slice(0, 1).html('hidden company details'); //css('display', 'none');
                                return;
                            }
                            else {
                                $(L).find('div.Pdf').css('opacity', 0.7).find('tr.files').find('td').slice(0, 1).html('<div class=NoSee>other Agents won\'t see your attachments</div>');
                            }
                        }
                        else $(L).find('div.Pdf').css('opacity', '').find('tr.files').find('td').slice(0, 1).css('display', 'none');

                        ar = J.At.split('*');
                        for (iar = 0; iar < ar.length && ar[iar].length > 1; iar++) {
                            if (ar[iar].split('|').length > 5)
                                J.File[J.File.length] = { "f": ar[iar].split('|')[0] + '|' + ar[iar].split('|')[1], "d": 0, "dsc": ar[iar].split('|')[2], "date": ar[iar].split('|')[3], "size": ar[iar].split('|')[4], "nid": ar[iar].split('|')[5] };
                            else if (ar[iar].split('|').length > 3)
                                J.File[J.File.length] = { "f": ar[iar].split('|')[0], "d": 0, "dsc": ar[iar].split('|')[1], "date": ar[iar].split('|')[2], "size": ar[iar].split('|')[3], "nid": ar[iar].split('|')[4] };
                            else
                                J.File[J.File.length] = { "f": ar[iar].split('^')[0] + '^' + ar[iar].split('^')[1] + '^' + ar[iar].split('^')[2], "d": 0, "dsc": ar[iar].split('^')[3], "date": ar[iar].split('^')[4], "size": ar[iar].split('^')[5], "nid": "" };
                            CurrentFiles(ItTpI);
                        }

                    }
                    if (XY.view || J.View == 1) {
                        $(L).find('div.Pdf').find('tr').slice(0, 3).css('display', 'none');
                        $(L).find('div.Pdf').find('span.Delete,span.D').css('display', 'none');
                        $(L).find('div.Pdf').find('input.details').each(function() { var v = $(this).val(); $(this).parent().html(v); });
                        if (XY.action == 100 && XY.hash > 0)
                            setTimeout(function() { $(L).find('div.Pdf').find('table.files').find('tr.files:first').find('td').slice(0, 1).trigger('click'); }, 100);

                    }
                }
                $(L).find('div.Pdf').css('display', 'block');
            }
            else if (cls == "map") {
                $(L).find('div.Map').html('<div class=NoSee>other Agents won\'t see pin\'s position</div><span><b>Please MOVE PIN to correct property location (click & drag)</b></span><div class=MAP id=MAP' + J.II + '></div><span class=SAVE>SAVE new position</span>'
                                          ).css('display', 'block').find('span.SAVE').mouseover(function() { $(this).css('opacity', 0.5); }).mouseout(function() { $(this).css('opacity', ''); }
                                          ).click(function() {
                                              J.Lt = J.marker.position.lat(); J.Ln = J.marker.position.lng();
                                              $(this).parent().find('span').slice(0, 1).html('Saved...'
                                              ).animate({ opacity: 0.5 }, 900, function() {
                                                  $(this).html('Please MOVE PIN to correct property location (click & drag)').css('opacity', '');
                                              });
                                              if (J.Im.length < 10) {  //no image, image map must be therefore reloaded!...
                                                  $(L).find('div.block2').find('img.imgblock'
                                                                ).attr('src', latitude.replace(/LAT/g, J.Lt).replace(/LON/g, J.Ln));

                                              }
                                              jsCriteria = { Update: 1, latitude: J.Lt, longitude: J.Ln };
                                              if (J.I > 0) DatabaseUpdate(J);
                                              var R = J.R.split('|');
                                              R[9] = '';
                                              J.R = retPipedString(R);
                                              if (J.Im.length < 3) ImgCh(J, L);

                                          });
                $(L).find('div.Map').find('div.NoSee').css('display', 'none');
                if (J.IS < 2 || XY.view || J.View == 1) $(L).find('div.Map').find('span').css('display', 'none');
                XY.J = JSON[J.It][J.II];
                scLoad("http://maps.google.com/maps/api/js?sensor=false&callback=iGMap0");
                $(L).find('div.Map').css('display', 'block');
            }
            else if (cls == "mail") {
                if (J.S == 7) {
                    alert('Change status to Available\nin order to email to Agents!');
                    $(L).find('a.status').trigger('click');
                    return;
                }
                $(L).find('div.Mail').html(waitSometime("Loading emails's list(s)...")).css('display', 'block');                    //64
                Criteria = { list: 3, Nid: J.T.split('|')[1], Type: 2 };
                if (Criteria.Nid.length == 0) Criteria.Nid = eval('jsPts2.v' + J.tp).replace(new RegExp("\\.", "g"), ","); //replaceAll(".",","); //
                var ctids = ''; //, SubjectTitle; // J.Lc.split('|')[8];
                aL = J.Lc.split('|');
                XY.view = true;
                if (XY.It == 'r') {
                    if (J.Lc.split('|')[1].length == 0) ctids = J.Lc.split('|')[5];
                }
                else ctids = aL[8];
                ////AreaTitle|LondonCentral|TownsWithPC|PCs|Streets|CTIDs|area|Regions
                if (ctids.length > 0) {
                    Criteria.Cid = ctids; //XY.CTIDsEmail;
                }
                else if (aL[7].length > 0) {//requirement, regids
                    Criteria.Type = 8;
                    Criteria.Cid = aL[7];
                }
                else if (aL[0].length > 1) {//requirement, area
                    Criteria.Type = 7;
                    Criteria.Cid = aL[6];
                }
                else if (aL[1].length > 1) {//requirement, london
                    Criteria.Type = 6;
                    Criteria.Cid = aL[5];
                }
                else if (aL[2].length > 1) {//requirement, towns with pcs
                    Criteria.Type = 5;
                    Criteria.Cid = aL[2];
                }
                else if (aL[3].length > 1) {//requirement, pcs
                    Criteria.Type = 4;
                    Criteria.Cid = aL[3];
                }
                if (XY.L != '' && XY.L != L) $(XY.L).find('a.mail[name=1]').trigger('click');
                $.post(urlLoad, Criteria, function(output) {
                    if (trim(output).length < 10) {
                        $(L).find('div.Mail').html('No agent\'s list for given subtypes and location...');
                        return;
                    }
                    XY.L = L; XY.J = J;
                    var tmp = 'XYproperty';
                    if (XY.It == 'r') tmp = 'XYrequirement';
                    $(L).find('div.Mail').html(
                            (J.Ace == 0 ? '' : '<div class=NoListing style="text-align:center">You have already sent an email today to all relevant Agents</div>')
                            + '<span style="padding-left:51px;color:#58c"><b>Preselected email lists</b></span><div ondragstart="return false" onselectstart="return false" class="iPersonal"></div>'
                            + '<div class="AutoTitle"><span class=mail><span>&nbsp;Subject Title of email:</span><input style="width:410px;float:right" onfocus="this.select()" value="'
                            + (get_cookie(J.It + J.I).length > 0 ? '' : 'ACE: ')
                            + MailSubject(eval('jsPts.v' + J.tp) + (isProp(J.It) ? ' at ' : ' in '), J, J.Lc.split('|')) + '" /></span>'
                            + '<br><span>&nbsp;Body&nbsp;text&nbsp;salutation:</span>&nbsp;&nbsp;<input class="dear" style="width:70px" onfocus="this.select()" value="Dear" />&nbsp;<i>firstname</i><br/></div>'
                            + '<div class="MailWrap" onclick="MailFocus(this)"><textarea id=tMail' + J.I + '>write or paste your message here</textarea></div>'
                            + (J.Ace == 0 ? '' : '<div class=NoListing style="clear:both;text-align:center">You have already sent an email today to all relevant Agents</div>')
                            + '<div style="clear:both"><a title="will send test email immediately to me" name=1 onclick="email2(1,1,223,\'' +
                                tmp + '\')" class=Send>send immediate test email to me</a><a name=0  onclick="email2(0,1,224,\'' +
                                tmp + '\');" title="will send emails to interested agents" style="margin-left:3px" class=Send>send emails to all agents (5 min)</a></div>'
                            );
                    MailLists(output, '#102984', '#102984', '#eef', 'ACE', '');
                    LoadTextEditor();
                    setTimeout(function() {
                        ShowMailBox('tMail' + J.I);
                    }, 225);


                });
                XY.view = false;
                $(L).find('div.Mail').css('display', 'block');
            }
            else if (cls == "copy") {
                ControlCloseAll(ItTpI, null);
                Stringify(J);
                if (J.S > 17) {
                    XY.J = J; XY.J.I = 0; //XY.L = L; 
                    XY.J.Edit = 2;
                    SUMMARYopen();
                    $('#ListList').css('display', 'block');
                    setTimeout(function() { FindCopy(); }, 1500);
                }
                else {
                    //ControlCloseAll(ItTpI, null);
                    Add('Copy', 3);
                }
            }
            else if (cls == "edit") {
                XY.iti = ItTpI;
                if (J.S > 17) {
                    XY.J = J; XY.L = L; XY.J.Edit = 1;
                    $('#ListList').css('display', 'none');
                    FindCopy();
                }
                else Edit('Edit');
            }
            else if (cls == "enq") {
                $(L).find('div.Enq').html('<textarea onfocus="this.select()">write or paste your message here (style will be enabled soon)</textarea><span title="will your enquiry to agents" class=Send><b>send your enquiry</b></span>'
                    ).css('display', 'block');
                $(L).find('div.Enq').find('span.Send').mouseover(function() { $(this).css('opacity', 0.5); }).mouseout(function() { $(this).css('opacity', ''); }
                        ).click(function() {
                            var msg = escape($(L).find('div.Enq').find('textarea').val());
                            $(L).find('div.Enq').html(waitSometime('Sending your enquiry'));
                            jsCriteria = { HtmlTemplate: 'Enquiry', NIDS: _gNid, RIDS: J.I, PIDS: J.I, From: "undelivered@each.co.uk", Mails: 1, Message: msg, Subject: "Enquiry" };
                            jsCriteria.To = "miroslav@each.co.uk";
                            //jsCriteria.CC = "miro.brada@yahoo.co.uk,af@each.co.uk,a@f.eclipse.co.uk,miro.brada@seznam.cz,gopi@each.co.uk"; //,af@each.co.uk,a@f.eclipse.co.uk"; //,af@each.co.uk,a@f.eclipse.co.uk,
                            jsCriteria.FromTitle = MailFromTitle(J); // +": Enquiry";
                            if (XY.It == 'r') jsCriteria.HtmlTemplate = 'EnquiryReq';
                            jsCriteria.attachments = '|' + MailMyPropReqButtons(J).replace(/hash/g, J.R.split('|')[10]) + '|';
                            MailData(J, L, 0, jsCriteria);
                            jsCriteria.attachments = escape(jsCriteria.attachments.replace(new RegExp("\\*q", "g"), ""));
                            $.post(urlLoad, jsCriteria, function(output) {
                                setTimeout(function() {
                                    $(L).find('div.Enq').html('<center><b>Your enquiry was sent...</b></center>');
                                    setTimeout(function() { ControlCloseAll(XY.iti, ""); }, 500);
                                }, 500);
                            });
                        })
            }
        }
        else {
            $(this).attr('name', '');
            if (cls == "matches") $(B).find('div.list').css('opacity', 1);

        }
    }
    );
    if (isProp(J.It)) ExternalLinks(J, L);
    if (XY.action > 0 || XY.hash > 0) {
        var a = new Array(), ax = new Array(); a[0] = 'a.status', a[1] = a[0], a[2] = a[0], a[4] = a[0], a[10] = a[0], a[50] = 'input.sz', a[55] = 'input.rn', a[99] = 'a.agent', a[100] = 'a.pdf', a[101] = 'a.map', a[102] = 'a.enq', a[200] = '';
        ax[99] = 'Add / remove agent(s)', ax[100] = 'Upload attachment', ax[101] = 'Change map position', ax[102] = 'Make enquiry', ax[50] = 'Edit floors', ax[200] = 'Edit using buttons below the box';
        if (XY.view) {
            $('#head').find('span.edit').html('You are in a view mode, you can\'t edit anything!');
            ax[100] = 'Request Details / PDF';
        }
        if (XY.hash > 0) {
            $(L).find('a.edit,span.cp').css('display', 'none');
            if (J.IS < 3) {//J.My ==  0<3 aIS[3] == 0  not me
                if (NoCompanyPDF(J.H)) {
                    if (XY.action == 99) return;
                    ax[100] = 'Request Details / PDF';
                }
                else if (XY.action == 102) XY.action = 100;
                if (NoStreet(J.H)) ax[101] = 'View the map';

            }
            else $(L).find('a.clicks,a.matches').css('display', 'inline-block');
            $(L).find(a[XY.action]).trigger('click'); //.attr('name', '0').trigger('mouseover')
            if (XY.action < 5) {
                $(L).find('div.Status').find('div[name=' + XY.action + ']').trigger('click');
                ax[XY.action] = 'Status was just updated to ' + XY.StatText[XY.action];
            }
            $('#head').find('span.edit').html(ax[XY.action]);
        }
        else {
            XY.NoMove = 1;
            $(L).find(a[XY.action]).trigger('click');
        }
        setTimeout(function() { $(L).find(a[XY.action]).css('background-color', '#0F2A86'); }, 250);
    }
    if (XY.view) $(L).find('div.block2').find('div.dvComments').css('display', 'none');
    if (J.IS > 1 && J.M == 0) NoSee(L, J); // J.My == 1   if (J.IS == 3) NoSee(L, J);
    if (J.S > 17) {
        $(L).find('div.block2').find('.Size').html(htmlSizeP(J, 0) + htmlTenure(J) + J.A.replace('^', '<br>') + (J.Tx == '' ? '' : 'Searched keywords: <b><i>' + J.Tx + '</i></b>').replace(/,/g, '<br>'));
        $(L).find('div.block2').find('a.copy').attr('title', 'enables to copy your search\nto create the new one');
        $(L).find('div.block2').find('a.edit').attr('title', 'enables to amend your search');
        $(L).find('div.block2').find('a.del').attr('title', 'will delete the above ' + XY.StatText[J.S]);
        $(L).find('div.block2').find('a.matches').attr('title', 'will list below found ' + (J.S < 20 ? 'Properties' : 'Requirements'));
    }
    $(L).find('div.block2').find('a.matches').trigger('mouseout');
    J.Ace = 0; J.Sent = 0;
    if (J.M > 0 && J.S < 7 && get_cookie('me' + J.I) != '1') {
        //Jsent(J);
        if (XY.J.S == 7) return;
        if (XY.J.My == 0 && XY.J.IS < 2 && XY.J.MyAg == 0) return;
        var mp = J.R.split('|')[J.R.split('|').length - 1].split('%');
        if (mp[0].length == 0) return;
        var et = 'EACH emailed my ' + (XY.J.IS == 3 ? '' : 'Department ') + propreq[retA(XY.J.It)] + ' to this Agent';
        if ((XY.It == 'p' && mp[0] == '0') || (XY.It == 'r' && mp[0] == '1'))
            et = 'EACH emailed this ' + propreq[retA(J.It)] + (XY.J.IS == 3 ? ' to me' : ' to my Department');
        AddComment(J, $(L).find('div.block2').find('.speech:last').parent(), et, mp[1], 0);
        //0=req was added
        //1=prop was added
    }

    Jsent(J, L, '');
}

var JSent = new Array();
JSent['2'] = ' emailed this message "MESSAGE" to COUNT Agents';
JSent['3'] = ' emailed this message "MESSAGE" to COUNT Agents';
JSent['4'] = ' emailed PDF request to for this Property';
JSent['6'] = ' emailed PDF request to for this Requirement';
JSent['7'] = ' emailed this Property to COUNT Agents';
JSent['8'] = ' emailed this Requirement to COUNT Agents';
function Jsent(J, L, n) {
    try {
        if (XY.StatSent[J.I + n] != undefined) {
            var adt = XY.StatSent[J.I + n].split(',');
            J.Sent = adt[0];
            if (adt[2] == ret2(ckDate.getUTCDate()) + '.' + ret2((ckDate.getUTCMonth() + 1)) + '.' + ckDate.getFullYear())
                J.Ace = 1; //adt[4]
            if (get_cookie('ace1' + J.Sent + J.I) != '1')
                AddComment(J, $(L).find('div.block2').find('.speech:last').parent()
                        , XY.Fsn + ' ' + XY.Srn + JSent[J.Sent].replace('COUNT', adt[3]).replace('MESSAGE', adt.slice(4).join(', '))
                        , adt[2], 0);
            Jsent(J, L, n + 'a');
        }
    } catch (e) { }
}

function MailFunctions(id) {
    $(id).find('span').attr('style', "background:url('http://www.4prop.com/JSON/images/common/Rolls/check1.png') no-repeat;padding-left:11px;cursor:pointer"
                     ).attr('name', '1').mouseover(function() {
                         $(this).css('opacity', 0.5);
                     }).mouseout(function() {
                         $(this).css('opacity', '');
                     }).click(function() {
                         $(this).parent().find('input').css('display', 'none');
                         if ($(this).attr('name') != '0')
                             $(this).attr('name', '0').css('background', "url('http://www.4prop.com/JSON/images/common/Rolls/checkNo1.png') no-repeat left top").css('color', '#777');
                         else {
                             $(this).attr('name', '1').css('background', "url('http://www.4prop.com/JSON/images/common/Rolls/check1.png') no-repeat left top").css('color', '#000');
                             $(this).parent().find('input').css('display', 'inline-block');
                         }
                     });
    LoadTextEditor();
}
function MailBody(J, L, source) {
    if (!isReq(J)) {
        J.mail = 1;
        return Status[J.S] + '|' + MailsBd[J.S] + '|' + htmPSTIDs(J).substring(0, 45) + '|' + J.I + '|' + XY.StatText[J.S] + '|'
                            + MailLoc(J.Lc.split('|'), J.H) + '|' + htmlSizeP(J, 0).replace(/£/g, '&pound;') + htmlTenure(J) + '|'
                            + htmlOwners(J, 1) + '|'
                            + J.D.replace(/£/g, '&pound;') + "<div style='color:#f00;font-size:0.8em'>last status DateChecked</div><br>".replace('DateChecked', J.R.split('|')[0].length == 0 ? todayDMY : J.R.split('|')[0]) + '|'
                            + MailMap(J) + MailAttach(J, source);
    }
    else
        return Status[J.S] + '|' + MailsBd[J.S] + '|' + $(L).find('div.block2').find('div[name=tp]').find('div.tp1').html() + '|' + J.I + '|' + XY.StatText[J.S] + '|'
                          + $(L).find('div.block2').find('.Location').html().replace(/£/g, '&pound;') + '|'
                          + $(L).find('div.block2').find('.Size').html().replace(/£/g, '&pound;') + '|'
                          + J.D.replace(/£/g, '&pound;') + '|'
                          + htmlOwners(J, 1)
                          + "<div style='color:#f00;font-size:0.8em'>last status DateChecked</div>".replace('DateChecked', J.R.split('|')[0].length == 0 ? todayDMY : J.R.split('|')[0]) + '|'
                          + MailAttach(J, source);
}

var ePublic = '', ePrivate = '', eCriteria = {}, etLoading = '', eLists = new Array(), eStay = 0;
function emailBodyFormat(oldA, oldZ, newA, newZ) {
    var apx, ipx;
    if (eCriteria.UNI.indexOf(oldA) > -1) {
        apx = eCriteria.UNI.split(oldA);
        eCriteria.UNI = apx[0];
        for (ipx = 1; ipx < apx.length; ipx += 1)
            eCriteria.UNI += newA + apx[ipx].replace(oldZ, newZ);
    }
}
function email2(onlyme, ace, type, tmpl) {
    if ($(XY.L).find('span.mail').find('input').val().length == 0) {
        $(XY.L).find('span.mail').find('input').css('background-color', '#faa');
        alert('fill in subject');
        return;
    }

    eCriteria = { list: 3, Decode: 1, BID: escape($(XY.L).find('span.mail').find('input').val()), CID: '', UNI: '', NID: _gNid, Type: type }; //223
    etLoading = 'you';
    MailAgentsLists(6, 0); //1
    MailAgentsListsFilters();
    eCriteria.DID = MailTitleFont((onlyme == 1 ? XY.Fsn : 'TITLE'), '<br><br>') + '|' + ePrivate + '|' + ePublic + '|' + eCriteria.UNI + '|' + eCriteria.CID + '|' + tmpl;
    //if (onlyme == 1) eCriteria.Type = 242;
    eCriteria.DID += '|' + (ace == 1 ? 'mailings@each.co.uk' : XY.Em); // 'mailings@each.co.uk';        
    eCriteria.CID = escape(XY.Company);
    //in case texter was not loaded...
    try {
        eCriteria.UNI = XY.Texter.nicInstances[0].saveContent();
        emailBodyFormat('<p align="center">', '</p>', '<div style="width:50%;padding-left:50%;text-align:center">', '</div>');
        emailBodyFormat('<p align="right">', '</p>', '<div style="width:100%;text-align:right;color:pink">', '</div>');
        eCriteria.UNI = eCriteria.UNI.replace(/<p>/g, '').replace(/<p align="left">/g, '').replace(/<\/p>/g, '<br>');
    } catch (e) {
        eCriteria.UNI = $(XY.L).find('textarea').val(); 
    }
    eCriteria.UNI = escape(replSplChr(eCriteria.UNI.replace('write or paste your message here', '')));
    if (ace == 1) {
        XY.view = true;
        eCriteria.UNI2 = escape(MailAceReplyLink(XY.J, XY.J.O, eCriteria.BID, 0)
             + '|' + MailAceReplyLink(XY.J, XY.J.O, eCriteria.BID, 1)
             + '|' + MailBody(XY.J, XY.L, 20)) + '|' + eCriteria.UNI;
        XY.J.mail = 0;
        if (isProp(XY.J.It)) eCriteria.UNI3 = MailImg(XY.J);
        XY.view = false;
        eCriteria.UNI = XY.J.I;
    }
    else if (ace == 0) {
        eCriteria.UNI2 = escape(eAttachmentsHtml(XY.Emails, 1)) + '|' + eCriteria.UNI
        eCriteria.UNI = XY.Emails + '|' + XY.EmailsAtt;
    }
    //Mail MailWrap,.eMail
    var msg = $(XY.L).find('div.Mail,.eMail').find('a.Send[name=' + onlyme + ']').html();
    $(XY.L).find('div.Mail,.eMail').find('a.Send[name=' + onlyme + ']').html('sending your email').attr('class', 'Sent');
    $.post(urlLoad, eCriteria, function(list) {
        $(XY.L).find('div.Mail,.eMail').find('a.Sent[name=' + onlyme + ']').html('Your message was sent...');
        if (ace == 1) {
            if (onlyme == 0) {
                $(XY.L).find('div.Mail,.eMail').html('<div style="width:100%;text-align:center;font-size:1.2em;padding:10px">Your message was sent...</div>');
                setTimeout(function() { $(XY.L).find('a.mail').trigger('click'); XY.L = ''; XY.J = ''; }, 1750);
                set_cookie(XY.J.It + XY.J.I, '1');
                XY.J.Ace = 1;
                AddComment(XY.J, $(XY.L).find('div.block2').find('.speech:last').parent()
                    , XY.OrigMenu[5] + ' ' + XY.OrigMenu[6] + ' emailed this ' + propreq[XY.J.It] + ' to all relevant Agents'
                    , ret2(ckDate.getUTCDate()) + '.' + ret2((ckDate.getUTCMonth() + 1)) + '.' + ckDate.getFullYear()
                    , 0);
            }
        }
        else {
            ckDate = new Date()
            eSent[eSent.length] = { R: ret2(ckDate.getUTCDate()) + '/' + ret2((ckDate.getUTCMonth() + 1)) + '/' + ckDate.getFullYear()
                                  + '|' + $(XY.L).find('span.mail').find('input').val()
                                  + '|' + XY.Emails
                                  + '|' + eCriteria.UNI2
                                  + '|'
                                  + '|' + onlyme * 5
                                  + '||'
            };
            $(XY.L).find('div.OnceSent').find('div[class!=tit]:first').before(
                    eListHtml(eSent.length - 1, eSent[eSent.length - 1].R.split('|'))
            );
            $(XY.L).find('div.OnceSent').find('div.tit:first').html(CountLastArrayEmpty(eSent.length) + ' sent emails, so far...');
            $(XY.L).find('div.OnceSent').find('.NoListing').slideUp('slow');
        }
        //if (onlyme == 1) RunBlinkNow();
    });
}

function MailAgentsLists(pv, pb) {
    ePublic = '', ePrivate = '';
    $(XY.L).find('div.eList[name2=1][public=0]').each(function() {
        if (ePrivate.length > 0) ePrivate += '*';
        ePrivate += eLists[$(this).attr('name')].R.split('|')[6] + eLists[$(this).attr('name')].R.split('|')[11].split('^')[0];
    });
    $(XY.L).find('div.eList[name2=1][public!=0]').each(function() { ePublic += ',' + eLists[$(this).attr('name')].R.split('|')[pb]; });
}
function MailFocus(o) {
    if ($(o).attr('name') == '1') return;
    $(o).attr('name', '1');
    XY.Texter.nicInstances[0].setContent('');
}

function MailLists(list, bgpv, bgpb, color, type, spec) {
    try {
        var eHtm = '<div class=eList style="display:none" name=100 public=0></div><div class=eList name=100 style="display:none" public=0></div>', bts = '<a is=D class=eBtL title="delete list" style="background:url(\'http://www.each.co.uk/JSON/images/common/Delete.png\')  no-repeat" name=eID>&nbsp;</a>'
        //+ '<a is=E class=eBtL title="edit list" style="background:url(\'http://www.each.co.uk/JSON/images/common/Edit.png\')  no-repeat"  name=eID>&nbsp;</a>'
                            + '<a is=A class=eBtL title="view agents" style="background:url(\'http://www.each.co.uk/JSON/images/common/Agents.png\')  no-repeat" name=eID>&nbsp;</a>';
        if (XY.L != '#Email2') bts = '<a is=A class=eBtL  name=eID style="width:60px;text-align:right">List Agents</a>';
        eLists = eval(list);
        for (var e = 0; e < eLists.length; e++) {
            aL = eLists[e].R.split('|');
            var et = aL[10], title = '';
            if (aL.length > 10 && aL[11].split('^').length > 1) {
                et = '<span class=et>' + aL[11].split('^')[0] + '</span>' + aL[10];
                var at = ['', aL[6].split(',')];
                for (var n = 0; n < at[1].length; n++) at[0] += '\n' + eval('jsRgs3.v' + at[1][n]);
                title = 'branch locations:' + at[0];
            }

            eHtm += ('<div class="eList" title="' + title + '" name2="0" public=Public name=eID><span style="width:35px;display:inline-block" class=cnt>COUNT</span><span class=tit>TITLE</span>'
                + bts + '<div class=list style="border:0px" name="e|0|eID"><div class=Agent></div></div></div>'
                        ).replace('Public', (aL[10] == undefined ? '1' : aL[0])
                        ).replace('TITLE', et
                        ).replace('COUNT', aL[1]
                        ).replace(/eID/g, e);
        }
    } catch (e) { }
    if (eLists.length > 1 && XY.L != '#Email2') eHtm += '<div class=SendAll style="clear:both;display:block;margin-top:2px;margin-bottom:4px"><a style="float:right;text-decoration:none" name=SendAll href="javascript:MailAgentsAll(0)">All Agents</a><div style="float:left;clear:both" class="list" name="Em|0|0"><div class="Agent"></div></div></div>';
    $(XY.L).find('div.iPersonal').html(eHtm);
    MailLists2(bgpv, bgpb, color, type, spec);
}
function MailLists2(bgpv, bgpb, color, type, spec) {
    $(XY.L).find('div.iPersonal').find('div.eList' + spec).css('background', bgpv).css('color', color
                    ).mouseover(function() { $(this).css('opacity', 0.5); }
                    ).mouseout(function() { $(this).css('opacity', ''); }
                    ).click(
                        function() {
                            if (eStay > 0) { eStay = 0; return; }
                            if ($(this).attr('name2') != '1') {
                                $(this).attr('name2', '1').css('opacity', '').css('background', ($(this).attr('public') != '0' ? bgpv : bgpb)
                                 ).find('.cnt').css('background', "url('http://www.4prop.com/JSON/images/common/Rolls/check" + type + "1.png') no-repeat left top");
                                if (type != 'ACE') {
                                    $('#dMail').css('display', 'block');
                                    ShowMailBox('tMail');
                                }
                            }
                            else
                                $(this).attr('name2', '0').css('opacity', 0.5).css('background', COLORS.Add3($(this).css('background'), 45, 45, 45)
                                    ).find('.cnt').css('background', "url('http://www.4prop.com/JSON/images/common/Rolls/checkNo" + type + "1.png') no-repeat left top");
                        }
                    );

    $(XY.L).find('div.iPersonal').find('div.eList[public=0]').css('background', bgpb); //.css('display', 'none');
    $(XY.L).find('div.iPersonal').find('div.eList' + spec).find('.eBtL'
                  ).mouseover(function() {
                      if ($(this).attr('name2') == "1") return;
                      $(this).css('font-weight', 'bold');
                      var is = $(this).attr('is');
                      $(this).parent().css('background-color', '#faa');
                      if (is == 'E') $(this).parent().css('background-color', '#afa');
                      else if (is == 'A') $(this).parent().css('background-color', '#aaf');
                  }).mouseout(function() {
                      if ($(this).attr('name2') == "1") return;
                      $(this).css('font-weight', '');
                      if ($(this).parent().attr('public') != '0')
                          $(this).parent().css('background-color', bgpv);
                      else $(this).parent().css('background-color', bgpb);
                  }).click(
                    function() {
                        eStay = 1;
                        var nm = $(this).attr('name'), is = $(this).attr('is');
                        if ($(this).attr('name2') != "1") {
                            $(this).attr('name2', '1');
                            if (is == 'A') {
                                MailAgents('e', nm);
                                if (type == 'ACE') $(this).css('background', '#eef').css('color', '#0F2A86');
                            }
                            else if (is == 'D') {
                                if (confirm("Do you really want to delete this email list?")) {
                                    $(XY.L).find('div.iPersonal').find('div.eList[name=' + nm + ']').slideUp('slow');
                                    $.post(urlLoad, { type: 221, NID: eLists[nm].R.split('|')[2], list: 3 }, function(list) { });
                                }
                                $(this).attr('name2', '0');
                            }
                        }
                        else {
                            $(this).attr('name2', '0');
                            if (is == 'A') {
                                $(XY.L).find('div.list[name=e|0|' + nm + ']').find('.Agent').css('display', 'none')
                                if (type == 'ACE') $(this).css('background', '#0F2A86').css('color', '#eef');
                                //else if (type == '') $(this).css('background', '').css('color', '');
                            }
                        }
                        //}else if (is == 'E') {  alert('edit...');                        }
                        //$(XY.L).find('div.iPersonal').find('div.eList[name=' + nm + ']').css('border', '');
                    }
                  );
    if (spec != '') return;
    $(XY.L).find('span.mail').find('input').focus(function() { $(this).css('background-color', ''); })
    if (type == 'ACE') {
        $(XY.L).find('div.iPersonal').find('div.eList[name!=100]').css('background', "#3c57b3").trigger('click').each(function() {
            aL = eLists[$(this).attr('name')].R.split('|');
            $(this).find('.tit').html(htmPSTIDs({ It: 'p', T: '|' + aL[2] }) + ' located in ' + eval('jsRgs3.v' + aL[3]));
        }).find('.eBtL').css('color', '#fff');
    }
}

function MailAgentsListsFilters() {
    etLoading = 'Loading Agents and Administrators';
    if ($('#Admins').find('span[name=1]').length == 1) {//1 is unchecked
        eCriteria.UNI = 'N';
        etLoading = 'Loading only Agents';
        if ($('#Admins').find('span').slice(1, 2).attr('name') == '1') {
            eCriteria.UNI = 'S';
            etLoading = 'Loading only Administrators';
        }
    }
    if ($('#Payers').find('span[name=1]').length == 1) {//1 is unchecke
        eCriteria.CID = 1;
        if ($('#Payers').find('span').slice(1, 2).attr('name') == '1') {
            eCriteria.CID = 0;
            etLoading += ', who did not pay';
        }
        else etLoading += ', who paid';
    }
    etLoading += '...';
}

function MailAgentsAll(t) {
    if ($(XY.L).find('a[name=SendAll]').attr('name2') != '1') {
        if ($(XY.L).find('div.iPersonal').find('div.eList[name2=1]').length == 0) {
            alert('No list selected');
        }
        else {
            MailAgents('Em', 0);
            $(XY.L).find('a[name=SendAll]').css('background-color', '#0F2A86').css('color', '#eef').attr('name2', '1');
        }
    }
    else $(XY.L).find('a[name=SendAll]').css('background-color', '').css('color', '').attr('name2', '0').parent().find('div.Agent').css('display', 'none');
}

function MailAgents(id, no) {
    eCriteria = { type: 222, list: 3 };
    ePublic = '', ePrivate = '';
    if (id == 'Em') {//All[name=' + no + ']
        $(XY.L).find('div.iPersonal').find('div.eList[public=0]').each(function() {
            if ($(this).attr('name2') == '1') {
                if (ePrivate.length > 0) ePrivate += '*';
                ePrivate += eLists[$(this).attr('name')].R.split('|')[6] + eLists[$(this).attr('name')].R.split('|')[11].split('^')[0];
            }
        });
        $(XY.L).find('div.iPersonal').find('div.eList[public!=0]').each(function() {
            if ($(this).attr('name2') == '1')
                ePublic += ',' + eLists[$(this).attr('name')].R.split('|')[0];
        });
    }
    else {
        if ($(XY.L).find('div.iPersonal').find('div.eList[name=' + no + '][public=0]').length > 0)
            ePrivate = eLists[no].R.split('|')[6] + eLists[no].R.split('|')[11].split('^')[0];
        else ePublic = eLists[no].R.split('|')[0];
    }
    MailAgentsListsFilters();
    Tree = ''; treeHash = 0;
    JSON[id] = new Array();
    JSON[id][no] = { N: ',0,|,,|,,|,0,' };
    $(XY.L).find('div.list').find('.Agent').css('display', 'none');
    $(XY.L).find('div.list[name=' + id + '|0|' + no + ']').find('.Agent').css('display', 'block').html(waitSometime(etLoading));
    eCriteria.NID = ePrivate; eCriteria.BID = ePublic;
    setTimeout(function() {
        $.post(urlLoad, eCriteria, function(list) {
            if (trim(list).length < 10) {
                $('div.list[name=' + id + '|0|' + no + ']').find('.Agent').css('display', 'block').html('zero agents found...');
                setTimeout(function() { $('div.list[name=' + id + '|0|' + no + ']').find('.Agent').slideUp('slow'); }, 1000);
                return;
            }
            TreeC[treeHash] = eval(list);
            fAgents(id + '|0|' + no, 106);
        });
    }, 1000);
}

function MailTitleFont(title, aftertml) {
    if ($(XY.L).find('div.AutoTitle').find('input.dear').val().replace(/ /g, '') == '') return "";
    try {
        var t = XY.Texter.nicInstances[0].saveContent().split('<font '), font = '<font STYLE>', fontclose = '';
        if (t.length > 1) {
            font = font.replace('STYLE', t[1].substring(0, t[1].indexOf('>')));
            if ((t[0] + t[1]).split('</font')[0].indexOf('<em>') > -1) { font += '<em>'; fontclose += '</em>'; };
            if ((t[0] + t[1]).split('</font')[0].indexOf('<strong>') > -1) { font += '<strong>'; fontclose = '</strong>' + fontclose; }
            if ((t[0] + t[1]).split('</font')[0].indexOf('<u>') > -1) { font += '<u>'; fontclose = '</u>' + fontclose; }
            if ((t[0] + t[1]).split('</font')[0].indexOf('<strike>') > -1) { font += '<strike>'; fontclose = '</strike>' + fontclose; }
        }
    }
    catch (e) {
        return escape($(XY.L).find('div.AutoTitle').find('input.dear').val() + ' ' + title + aftertml);
    }
    return escape(font.replace(' STYLE', '') + $(XY.L).find('div.AutoTitle').find('input.dear').val() + ' ' + title
                                             + fontclose + '</font>' + aftertml);
}

function NoSee(L, J) {
    var msg = '';
    if (NoCompanyPDF(J.H)) msg = '<br>other Agent won\'t see Company and Company\'s details';
    if (NoStreet(J.H)) msg += '<br>other Agent won\'t see street, image, map';
    else if (NoStreetNum(J.H)) msg += '<br>other Agent won\'t see street number, image';
    $(L).find('.Desc').html(J.D + (msg.length == 0 ? '' : '<div style="display:block" class=NoSee>According to your setting: ' + msg + '</div>'));
    if (J.Cn.length > 0) $(L).find('.Size').find('.cln').html('Client: <b>' + J.Cn + '</b>');
}
function ExternalLinks(J, L) {
    var l = J.Lc.split('|');
    $(L).find('.Location').find('span.voa').click(function() {
        if ($.browser.msie) window.clipboardData.setData("text", l[1]);
        window.open("http://www.2010.voa.gov.uk/rli/en/advanced", "winVOAsite");
    });
    $(L).find('.Location').find('span.TownProfilelink').click(function() {
        window.open('http://www.each.co.uk/abu/popup/TownProfile.aspx?pc=' + l[1].split(' ')[0] + '&tn=' + (l[5].length > 0 ? l[5] : l[4]).replace(/ /g, '05550') + '&NID=' + _gNid, '', 'width=600,height=700,scrollbars=1,resizable=1');
    });
    $(L).find('.Location').find('span.streetprofile').click(function() {
        window.open('http://www.each.co.uk/abu/popup/LocationProfile.aspx?pc=' + l[1].split(' ')[0] + '&st=' + l[2].replace(/ /g, '05550') + '&type=streetinfo&NID=' + _gNid, '', 'width=900,height=700,scrollbars=1,resizable=1');
    });
    $(L).find('.Location').find('span.estateprofile').click(function() {
        window.open('http://www.each.co.uk/abu/popup/LocationProfile.aspx?pc=' + l[1].split(' ')[0] + '&st=' + l[3].replace(/ /g, '05550') + '&type=CentreEstateInfo&NID=' + _gNid, '', 'width=900,height=700,scrollbars=1,resizable=1');
    });
}

function getStreetProfile(_pc, _st, _type) {
    if (_type == 0) return;
    var win;
    if (_type == 2)
        window.open('http://www.each.co.uk/abu/popup/LocationProfile.aspx?pc=' + _pc + '&st=' + _st + '&type=CentreEstateInfo&NID=' + _gNid, '', 'width=900,height=700,scrollbars=1,resizable=1');
    else
        window.open('http://www.each.co.uk/abu/popup/LocationProfile.aspx?pc=' + _pc + '&st=' + _st + '&type=streetinfo&NID=' + _gNid, '', 'width=900,height=700,scrollbars=1,resizable=1');
    win.focus();
}



function PicPop(J, iti) {
    J.Picture = new Array(); J.PictureAll = new Array();
    ar = J.Im.split('*');
    for (iar = 0; iar < ar.length && ar[iar].length > 1; iar++) {
        if (ar[iar].split('|').length > 3)
            J.Picture[J.Picture.length] = { "f": ar[iar].split('|')[0] + '|' + ar[iar].split('|')[1], "d": 0, "dsc": ar[iar].split('|')[2], "date": ar[iar].split('|')[3], "size": ar[iar].split('|')[4], "nid": ar[iar].split('|')[5] };
        else
            J.Picture[J.Picture.length] = { "f": ar[iar].split('^')[0], "d": 0, "dsc": ar[iar], "date": ar[iar].split('^')[5], "size": ar[iar].split('^')[4], "nid": '' };
        CurrentPictures(iti);
    }
}
function FileAttached(s, size, p, ItTpI) {//picture:p==2,attachment:p==1
    var dt = ckDate.getUTCDate() + '/' + (ckDate.getUTCMonth() + 1) + '/' + ckDate.getYear() + ' ' + ckDate.toTimeString().split(' ')[0];
    var js = { "f": s, "d": 0, "dsc": "Detail", "date": dt, "size": Math.round(parseInt(size) / 1024), "nid": _gNid };
    var N = ItTpI.split('*'), J = JSON[N[0]][N[2]], B = BarId(N[0] + '|' + N[1]);
    var iti = N[0] + '|' + N[1] + '|' + N[2];
    L = ListId(iti);
    $(L).find('div.loadfileatt').css('display', 'none');
    if (p == 1) {//attachment
        if (J.File.length > 0) js.dsc = "Details";
        if (size == 0) js.dsc = "URL Attachment";
        J.File[J.File.length] = js;
        $(L).find('div.Pdf').find('tr.files').find('td').slice(0, 1).css('display', 'none');
        CurrentFiles(iti);
        rewriteFiles(iti, 1);
    }
    else {
        var end = s.split('.')[s.split('.').length - 1].toLowerCase();
        if (end == 'gif' || end == 'jpg' || end == 'jpeg' || end == 'bmp' || end == 'png') {
            J.Picture[J.Picture.length] = js;
            rewriteFiles(iti, 0);
            $(L).find('div.Pdf').find('table.tbPics').html(XY.tbPics);
            PicPop(J, iti);
            reImage(L, J, iti);
        }
        else alert('The file you are trying to upload is not an image\nPlease ensure the file is a gif, jpg, bmp or png');
    }
}
function ImgCh(J, L) {
    $(L).find('table.tbList').find('td.img').find('img').slice(1, 2).attr('src', htmPic(0, J, 1)); //.attr('class','nothing');
    $(L).find('div.block2').find('img').slice(0, 1).attr('src', htmPic(1, J, 1));
}

function reImage(L, J, iti) {//n, s) {
    var u = CurrentPicSrc(iti, J.Picture.length - 1, 1);
    $(L).find('div.block2').find('img').slice(0, 1).attr('src', u);
    $(L).find('table.tbList').find('td.img').find('img').slice(1, 2).parent().html(htmPic(0, J, 0));
}
var aPicCol = new Array(); aPicCol["D"] = "900"; aPicCol["V"] = "009";
function CurrentPicSrc(ItTpI, f, thumb) {
    var N = ItTpI.split('|'), J = JSON[N[0]][N[2]];
    if (J.Picture[f].nid.length == 0) return 'http://www.each.co.uk/images/thumb/Property/' + J.Picture[f].f.split('.')[0] + (thumb == 0 ? '' : '_thumb') + '.jpg';
    return 'http://www.each.co.uk/JSON/NIDs/' + J.Picture[f].nid + '/' + J.Picture[f].f.replace('|', '/' + (thumb == 0 ? '' : 'thumb'));
}
function CurentRemove(ItTpI, t) {
    var Pics = new Array(), p = 0, N = ItTpI.split('|'), J = JSON[N[0]][N[2]], L = ListId(ItTpI);
    if (t == 0) {
        for (p; p < J.Picture.length; p++)
            if (J.Picture[p].d != 1) {
            Pics[Pics.length] = J.Picture[p];
        }
        J.Picture = Pics;
        rewriteFiles(ItTpI, 0);
    }
    else {
        for (p; p < J.File.length; p++) {
            if (J.File[p].d != 1)
                Pics[Pics.length] = J.File[p];
        }
        //J.File = Pics;
        rewriteFiles(ItTpI, 1);
    }
}
function rewriteFiles(ItTpI, t) {
    var rewrite = '', A, f, N = ItTpI.split('|'), J = JSON[N[0]][N[2]];
    jsCriteria = { Update: 1 };
    if (t == 0) {
        for (f = 0; f < J.Picture.length; f++) {
            A = J.Picture[f];
            if (A.d == 0) {
                if (A.nid.length != "") rewrite += A.f + '|' + A.dsc + '|' + A.date + '|' + A.size + '|' + A.nid + '*';
                else rewrite += A.dsc + '*';
            }
        }
        J.Im = rewrite;
        jsCriteria.images = J.Im;
    }
    else {
        for (f = 0; f < J.File.length; f++) {
            A = J.File[f];
            if (A.d == 0) {
                if (A.nid.length == 0) rewrite += A.f + '^' + A.dsc + '^' + A.date + '^' + A.size + '*';
                else rewrite += A.f + '|' + A.dsc + '|' + A.date + '|' + A.size + '|' + A.nid + '*';
            }
        }
        J.At = rewrite;
        $(ListId(ItTpI)).find('table.tbList').find('td.img').find('img').slice(0, 1).parent().html(LastAttached(J));
        jsCriteria.attachments = J.At;
    }
    if (J.I > 0) DatabaseUpdate(J);
}
function CurrentPictures(ItTpI) {
    var N = ItTpI.split('|'), L = ListId(ItTpI), J = JSON[N[0]][N[2]], B = BarId(N[0] + '|' + N[1]);
    if (J.Picture.length == 1)
        $(L).find('div.Pdf').find('tr.pictures').css('height', '9px').find('td').slice(0, 1).html('<b>Current pictures</b>').css('color', '#77f').css('margin-top', '7px');
    var f = J.Picture.length - 1;
    h = XY.Pic.replace('xS', J.Picture[f].f.replace('|', '/')).replace('Size', addCommas(J.Picture[f].size) + ' KB').replace(/PIC/g, f).replace('xNAME', J.Picture[f].f);    //imgblock
    $(L).find('div.Pdf').find('div.Pics').find('img').css('width', '125px');
    $(L).find('div.Pdf').find('div.Pics:first').before(h).parent().find('img[name=' + f + ']').attr('src', CurrentPicSrc(ItTpI, f, 0)).css('width', '250px'); //latitude;/....find('div.Pics:first').find()
    $(L).find('div.Pdf').find('div.Pics:first').css('margin-right', '1px').find('span.D,span.V'
			).mouseover(function() { $(this).parent().parent().parent().css('background-color', '#' + aPicCol[$(this).attr('class')]).find('img').css('opacity', 0.7); }
			).mouseout(function() {
			    if ($(this).attr('name2') == "1") return;
			    $(this).parent().parent().parent().css('background-color', '').find('img').css('opacity', '');
			}).click(function() {
			    var n = $(this).attr('name'); //, '1');
			    if ($(this).attr('class') == "V") {
			        if ($(this).html() == "View") {
			            $(L).find('div.Pdf').find('img[name=' + n + ']').css('width', '');
			            $(this).html('Back').attr('title', 'back to previous size');
			        }
			        else {
			            $(L).find('div.Pdf').find('img[name=' + n + ']').css('width', (n == 0 ? 250 : 125));
			            $(this).html('View').attr('title', 'click to view the original image\'s size');
			        }
			    }
			    else {
			        $(this).attr('name2', '1');
			        if (confirm("Do you really want to delete this picture?")) {
			            J.Picture[n].d = 1;
			            CurentRemove(ItTpI, 0);
			            if (J.Picture.length == 0) {
			                $(L).find('div.Pdf').find('table.tbPics').html('<tr><td style="color:#eef">No picture uploaded...</td></tr>');
			                $(L).find('div.block2').find('img').slice(0, 1).attr('src', latitude.replace(/LAT/g, J.Lt).replace(/LON/g, J.Ln));
			                $(L).find('table.tbList').find('td.img').find('img').slice(1, 2).attr('class', 'nothing').attr('src', "http://www.each.co.uk/JSON/images/common/None.gif");
			                J.Im = '';
			            }
			            else {
			                reImage(L, J, ItTpI);
			                $(L).find('div.Pdf').find('table.tbPics').html(XY.tbPics);
			                PicPop(J, ItTpI);
			            }
			        }
			        $(this).attr('name2', '0');
			    }
			}
		);
    if (f > 0)
        $(L).find('div.Pdf').find('td.Is[name=' + (f - 1) + ']').html('make front').css('cursor', 'pointer'
		    ).mouseover(function() { $(this).parent().parent().parent().css('background-color', '#9d9'); }
		    ).mouseout(function() { $(this).parent().parent().parent().css('background-color', ''); }
		    ).click(function() {
		        var n = $(this).attr('name');
		        $(L).find('div.block2').find('img').slice(0, 1).attr('src', CurrentPicSrc(ItTpI, n, 1));
		        var n0 = $(L).find('div.Pdf').find('div.Pics').find('img').slice(0, 1).attr('src', CurrentPicSrc(ItTpI, n, 0)).attr('name');
		        $(L).find('div.Pdf').find('div.Pics').find('img[name=' + n + ']').attr('src', CurrentPicSrc(ItTpI, n0, 0));
		        var js0 = J.Picture[n0];
		        J.Picture[n0] = J.Picture[n];
		        J.Picture[n] = js0; 	        //DatabaseUpdate(J);
		        rewriteFiles(ItTpI, 0)
		    }
	    );
}
function CurrentFiles(ItTpI) {
    var N = ItTpI.split('|'), L = ListId(ItTpI), J = JSON[N[0]][N[2]], B = BarId(N[0] + '|' + N[1]);
    var f = J.File.length - 1, ar = J.File[f].f.split('|'), h = '';
    if (f == 0) $(L).find('div.Pdf').find('table.files').html(XY.FileHeader + '<tr class=files></tr>').css('display', 'block');
    //old...
    if (J.File[f].nid.length == 0) {
        ar = J.File[f].f.split('^');
        h = XY.File.replace('X1', ar[2].split('.')[1]).replace('x1', Fading(ar[2].split('.')[1], 10, 5, '')); //Old
    }
    else if (J.File[f].size == 0 && J.File[f].f.split('|').length < 2) { //URL attachment
        h = XY.File.replace(/x0/g, ar[0]).replace('x1', Fading(ar[0].replace('http://', '').replace('www.', ''), 10, 5, '')).replace('X1', 'pdf');
    }
    else h = XY.File.replace(/x0/g, ar[0]).replace('x1', Fading(ar[1], 10, 5, '')).replace('X1', ar[1].toLowerCase().split('.')[ar[1].toLowerCase().split('.').length - 1]);
    h = h.replace('Details', J.File[f].dsc).replace('xSize', addCommas(J.File[f].size) + ' KB').replace('xDate', J.File[f].date).replace(/xF/g, f);
    $(L).find('div.Pdf').find('table.files').find('tr.files:first').before(h).parent().find('span.Delete').slice(0, 1
        ).mouseover(function() { $(this).parent().parent().css('background-color', '#900'); }
        ).mouseout(function() { if ($(this).attr('name2') == '1') return; $(this).parent().parent().css('background-color', ''); }
        ).click(function() {
            var n = $(this).attr('name');
            $(this).attr('name2', '1');
            if (confirm("Do you really want to delete this file?")) {
                $(this).parent().parent().attr('class', 'n');
                try {
                    J.File[n].d = 1;
                    CurentRemove(ItTpI, 1);
                } catch (er) { }
                if ($(L).find('div.Pdf').find('tr.files[class!=n]').length < 3) {
                    $(L).find('div.Pdf').find('table.files').css('display', 'none');
                    $(L).find('div.Pdf').find('tr.files').find('td').slice(0, 1).css('display', 'block');
                }
            }
            $(this).attr('name2', '0');
        });
    Weakening($(L).find('div.Pdf').find('table.files').find('tr.files:first'));
    $(L).find('div.Pdf').find('table.files').css('display', 'block').find('tr.files:first').find('td').slice(0, 4).css('cursor', 'pointer').attr('title', 'click to open the attachment'
        ).mouseover(function() { $(this).parent().css('background-color', '#09f'); } //ee
				  ).mouseout(function() { $(this).parent().css('background-color', ''); }
				  ).click(function() {
				      var f = $(this).parent().attr('name'), source = '', NidClicked = '', PRid = '';
				      if (J.M != 0) {
				          source = '9';
				          NidClicked = _gNid;
				          PRid = J.I;
				      }
				      else if (XY.hash > 0 && XY.action == 100) {
				          source = '20';
				          NidClicked = _gNid;
				          PRid = J.I;
				      }
				      if (J.File[f].nid.length == 0) {
				          ar = J.File[f].f.split('^');
				          URLshow(N[0], ret10(ar[0]), ret10(ar[1]), ar[2].split('.')[0], ar[2].split('.')[1], PRid, source, NidClicked, '*');
				      }
				      else if (J.File[f].size == 0 && J.File[f].f.split('|').length < 2) {//URL attachment
				          window.open(J.File[f].f.replace(/XPIPEX/g, '|'), '_blank');
				          $.post(urlLoad, { list: 3, Type: 152, Nid: _gNid, DID: retA(N[0]), BID: source, CID: PRid }, function(e) { });
				      }
				      else {
				          ar = J.File[f].f.split('|');
				          var end = ar[1].split('.')[ar[1].split('.').length - 1], fn = ar[1].substring(0, ar[1].length - end.length - 1);
				          URLshow(N[0], J.File[f].nid, ar[0], fn, end, PRid, source, NidClicked, '');
				      }
				  });
    $(L).find('div.Pdf').find('table.files').find('tr.files:first').find('input.details').change(
				  function() { J.File[f].dsc = $(this).val(); rewriteFiles(ItTpI, 1); });
}

function mapOptions(latlng, Zoom) {//google.maps.MapTypeId.ROADMAP
    return { center: latlng, zoom: Zoom,
        mapTypeId: google.maps.MapTypeId.HYBRID,
        mapTypeControlOptions: { style: google.maps.MapTypeControlStyle.DROPDOWN_MENU, position: google.maps.ControlPosition.TOP_LEFT },
        navigationControlOptions: { style: google.maps.NavigationControlStyle.SMALL, position: google.maps.ControlPosition.TOP_LEFT },
        scaleControl: true, streetViewControl: true, positionControl: true, labels: true
    }
}
var lTen = new Array(); lTen['0'] = '/sf'; lTen['-1'] = '/sf'; lTen['-2'] = '/sm'; lTen['1'] = 'pa'; lTen['2'] = 'pm'; lTen['4'] = 'pw';
function listRent(j, t) {
    if (t == 'p') {
        aT = j.split('|');
        var un = lTen[parseFloat(aT[1])];
        if ((Number(aT[0]) & 4) > 0) un = '';
        if (aT[2].length > 0 && parseFloat(aT[2]) != 0) return "£" + addCommas(aT[2]) + ' ' + un;
        else if (aT[3].length > 0 && parseFloat(aT[3]) != 0) return "£" + addCommas(aT[3]) + ' ' + un;
    }
    return "";
}
function htmlReqLocFull(aL) {
    var Streets = (aL[4].length > 1 ? '<br>ONLY in specific Street(s) named: ' + aL[4] : ''), tit = 'searching: ';
    if (aL[0].length > 1) return tit + '<b>' + aL[0] + '</b>' + Streets
    if (aL[1].length > 1) return tit + '<b>' + aL[1] + '</b>' + Streets;
    if (aL[2].length > 1) return tit + '<b>' + aL[2] + '</b>' + Streets;
    if (aL[3].length > 1) return tit + '<b>' + CommaStripAZ(aL[3]) + '</b>' + Streets;
    return tit + '<b>' + htmReqCtids(aL[5], aL[7], 0, 1) + '</b>' + Streets;
}
function htmReqCtids(ctids, regids, lst, all) {
    var ar, iar, All = '';
    if (regids.replace(',', '').length > 0) {
        ar = regids.split(','), Ls = '', iar;
        for (iar = 0; iar < ar.length; iar++) {
            if (ar[iar].length > 0) {
                if (Ls.length > 0) Ls += ', ';
                Ls += eval('jsRgs.v' + ar[iar].replace(',', ''));
            }
        }
        if (all == 0) return Ls; //(lst == 1 ? '' : 'Region(s): ') + 
        else All = Ls; //(lst == 1 ? '' : 'Region(s): ') +
    }
    if (ctids.replace(',', '').length > 0) {
        ar = ctids.split(','), iar;
        ar[ar.length] = '';
        for (iar = 0; iar < ar.length - 1; iar++)
            if (ar[iar].length > 0) {
            if (ar[ar.length - 1].length > 0) ar[ar.length - 1] += ', ';
            ar[ar.length - 1] += eval('jsRgs3.v' + ar[iar]);
        }
        if (all == 0) return ar[ar.length - 1]; //(lst == 1 ? '' : 'Counties: ') +
        else All += (All.length == 0 ? '' : '<br>') + ar[ar.length - 1]; //(lst == 1 ? '' : 'Counties: ') +
    }
    return All;
}
function htmlReqLoc(aL, lst) {    //if (ItR != 'r' && It) return "";
    if (aL[0].length > 1) return aL[0];
    if (aL[1].length > 1) return aL[1];
    if (aL[2].length > 1) return (aL[4].length > 1 ? aL[4] + ', ' : '') + aL[2]; //+ (lst==0 ? 'Street:' : '' )
    if (aL[3].length > 1) return (aL[4].length > 1 ? aL[4] + ', ' : '') + CommaStripAZ(aL[3]);  //+ (aL[4].length > 1 ? ', '  + aL[4] : '');//
    return htmReqCtids(aL[5], aL[7], 1, 0);
}

function LastAttached(J) {
    try {
        if (NoCompanyPDF(J.H) && (J.IS < 2 || XY.view)) return XY.picNo; //J.My == 0 
        var v = J.At;
        if (v.length > 0) {
            var ar = v.split('*'), ar2, end;
            end = ar[ar.length - 2].toLowerCase();
            if (end.indexOf('^') > -1) {
                ar2 = end.split('^');
                ar2 = ar2[4].split('/');
            }
            else {        //223|hok-1b.jpg||1/6/2011 23:00:51|33252|59368*
                ar2 = end.split('|');
                ar2 = ar2[3].split(' ')[0].split('/');
            }
            return '<img title="last uploaded ' + ar2[0] + ' ' + aM[parseFloat(ar2[1]) - 1] + ' ' + ar2[2]
                    + '\nclick to manage" src="http://www.each.co.uk/JSON/images/attachments/' + (end.indexOf('.doc') > -1 || end.indexOf('.rtf') > 0 ? 'doc' : 'pdf') + '.png" />';
        }
        return XY.picNo;
    } catch (e) { return XY.picNo; ; }
}
function SuburbTown(l) { return l[5].length == 0 ? l[4] : l[5]; }
function ListSizeP(J) {
    return (J.tp == "8" || J.tp == "2" || J.tp == "4" ? '<input class=sz title="click to see\nfloors table" style="background:' + cSTATUS[parseInt(J.S) + 10] + '" value="' + htmlSizeP(J, 1) + '" /><div class=inFloors></div>' : htmlSizeP(J, 1));
}

function ListHtml(J, i, add) {
    if (isProp(J.It)) return aList['p'].replace(/xIt/g, J.It).replace(/xTp/g, J.Crit).replace(/xId/g, J.II
              ).replace('xTW', Fading(SuburbTown(J.Lc.split('|')), 9, 6, '')
              ).replace('SIZE', ListSizeP(J)
              ).replace(/COLOR/g, cSTATUS[parseInt(J.S) + 10]
              ).replace('RENT', listRent(J.Rn, J.It)).replace('PDF', LastAttached(J)).replace('xPC', J.Lc.split('|')[1].split(' ')[0].toUpperCase()
              ).replace('STREET', LsPLc(J, 14, 8)
              ).replace('COLOR', cSTATUS[J.S]
              ).replace('IMG', htmPic(0, J, 0));
    else return aList[J.S < 18 ? 'r' : J.S].replace(/xIt/g, J.It).replace(/xTp/g, J.Crit).replace(/xId/g, J.II
              ).replace('COLOR', cSTATUS[J.S]).replace(/COLOR/g, cSTATUS[parseInt(J.S) + 10]
              ).replace('SIZE', htmlSizeP(J, 1)
              ).replace('PDF', LastAttached(J)
              ).replace('LOCATION', Fading(htmlReqLoc(J.Lc.split('|'), 1), 15, 7, '')
              ).replace('SUBTYPEs', (J.S < 18 ? Fading(htmPSTIDs(J), 13, 5, '') : XY.StatText[J.S])
              ).replace('CLIENT', Fading(J.Cn, 7, 6, ''));

}

var sortBy = 1, aSorTit = new Array();
aSorTit["p"] = new Array("&#8661", "PC&#8661", "&#8661", "&#8661", "TOWN&#8661", "STREET&#8661", "SIZE&#8661", "RENT&#8661", "Created&#8661", "Status&#8661", "min&#8661", "max&#8661", "SUBTYPEs&#8661", "LOCATIION&#8661", "CLIENT/REF&#8661");
aSorTit["r"] = new Array("&#8661", "PC&#8661", "&#8661", "&#8661", "TOWN&#8661", "LOCATION&#8661", "SIZE&#8661", "CLIENT/REF&#8661", "Created&#8661", "Status&#8661", "min&#8661", "max&#8661", "SUBTYPEs&#8661", "LOCATION&#8661", "CLIENT/REF&#8661");
aSorTit["p"][100] = "&#8661"; aSorTit["r"][100] = "&#8661";
var aSorTitLoading = new Array("Selected items", "postcodes", "attachments", "images", "towns", "streets", "", "rent", "created date", "register Status date", "minimum size", "maximum size", "subtypes", "locations", "client/ref");
function Included(J, crit) { return J.S != 9 && J.Crit == crit && ((IS <= J.IS) || (IS == 4 && J.rc == 1)); }
function Sort(ItTp) {
    //if (JSON[ItTp.split('|')[0]][0].S0 > 17) { alert('This is Beta version of Listing / Find\nSorting will start working soon...'); return; }
    var B = 'div.bar[name="' + ItTp + '"]';
    $(B).find('div.block').html(waitSometime("Sorting by " + aSorTitLoading[Math.abs(sortBy) % 100]));
    setTimeout("Sort2('" + ItTp + "')", 500);
}
function Sort2(ItTp) {
    var is, J, N = ItTp.split('|');
    htm = '';
    aSort = new Array();
    try { for (is = 0; is < JSON[N[0]].length; is++) if (Included(JSON[N[0]][is], N[1])) aSort[aSort.length] = { "i": is, "number": sortBy }; } catch (e) { }
    for (is = 0; is < aSort.length; is++) {
        J = JSON[N[0]][aSort[is].i];
        switch (Math.abs(sortBy)) {
            case 1: aSort[is].number *= aSort[is].i; break;
            case 100: aSort[is].number *= -J.ck; break;
            case 2: aSort[is].number *= J.At.length; break;
            case 3: aSort[is].number *= J.Im.length; break;
            case 4: aSort[is].number *= TextNumber(SuburbTown(J.Lc.split('|'))); break;
            case 5: aSort[is].number *= TextNumber(!isReq(J) ? J.Lc.split('|')[2] : dscLocR(J)); break;
            case 6: aSort[is].number *= AnnualSize(J.Sz.split('|')); break;
            case 7: aSort[is].number *= AnnualRent(J.Rn.split('|'), J.Sz.split('|')); break;
            case 8: aSort[is].number *= DateToNumber(J.R.split('|')[3].split(' ')); break;
            case 9: aSort[is].number *= DateToNumber(J.R.split('|')[0].split(' ')); break;
            case 10: aSort[is].number *= AnnualMinSize(J.Sz.split('|')); break;
            case 11: aSort[is].number *= AnnualMaxSize(J.Sz.split('|')); break;
            case 12: aSort[is].number *= TextNumber(htmPSTIDs(J).substring(4, 10)); break;
            case 13: aSort[is].number *= TextNumber(htmlReqLoc(J.Lc.split('|'), 1)); break;
            case 14: aSort[is].number *= TextNumber(J.Cn); break;
        }
    }
    if (aSort.length > 0) {
        quick_sort(aSort);
        try {
            if (arSelected[N[0]][N[1]] != undefined && arSelected[N[0]][N[1]].length > 3) {
                var s = arSelected[N[0]][N[1]];
                arSelected[N[0]][N[1]] = '';
                for (is = 0; is < aSort.length; is++) {
                    J = JSON[N[0]][aSort[is].i];
                    if (s.indexOf(J.I) > -1) Select(J);
                }
            }
        } catch (e) { }
        for (is = 0; is < aSort.length; is++) {
            if (JSON[N[0]][aSort[is].i].found > 0)
                htm += ListHtml(JSON[N[0]][aSort[is].i], aSort[is].i, '');
        }
    }
    //return;
    fList(BarId(ItTp), htm, 0);
    offsetY(BarId(ItTp));
    $(BarId(ItTp)).find('div.list').css('border', '').find('table.tbList').css('border-bottom', '1px solid #989898');
    if (N[0] != XY.It && XY.M != '') setTimeout("MatchBarUpButtons()", 500);
    //if (XY.searched.length > 0) setTimeout("Find0()", 250);
}
function TextNumber(t) { if (t == '') return 0; return parseFloat(t.charCodeAt(0)) * 10000 + parseFloat(t.charCodeAt(1)) * 100 + parseFloat(t.charCodeAt(2)); }
var sf2sm = 10.76391041670972;
function AnnualSizeUni(c, v) {
    if (c == "2") return parseFloat(v);
    if (c == "1") return sf2sm * parseFloat(v); //metres
    if (c == "4") return 43560 * parseFloat(v); //acres
    if (c == "8") return 107639.104 * parseFloat(v); //hectares
    return 0;
}
function AnnualMinSize(aS) {
    if (aS[1].length > 0) { if (aS[0] == "2") return parseFloat(aS[1]); if (aS[0] == "1") return sf2sm * parseFloat(aS[1]); }
    return AnnualSizeUni(aS[3], aS[4]);
}
function AnnualMaxSize(aS) {
    if (aS[2].length > 0) { if (aS[0] == "2") return parseFloat(aS[2]); if (aS[0] == "1") return sf2sm * parseFloat(aS[2]); }
    return AnnualSizeUni(aS[3], aS[5]);
}
function AnnualSize(aS) {
    if (aS[1].length + aS[2].length > 0) { if (aS[0] == "2") return parseFloat((aS[1].length > 0 ? aS[1] : aS[2])); if (aS[0] == "1") return sf2sm * parseFloat((aS[1].length > 0 ? aS[1] : aS[2])); }
    return AnnualSizeUni(aS[3], (aS[4].length > 0 ? aS[4] : aS[5]));
}
function AnnualRent(aR, aS) {
    if (aR[1] == "1") return parseFloat((aR[2].length > 0 ? aR[2] : aR[3])); //anually
    if (aR[1] == "2") return 12 * parseFloat((aR[2].length > 0 ? aR[2] : aR[3])); //monthly
    if (aR[1] == "4") return 52 * parseFloat((aR[2].length > 0 ? aR[2] : aR[3])); //weekly
    if (aR[1] == "-1") return parseFloat((aR[2].length > 0 ? aR[2] : aR[3])) * parseFloat((aS[1].length > 0 ? aS[1] : aS[2])); //psf
    if (aR[1] == "-2") return sf2sm * parseFloat((aR[2].length > 0 ? aR[2] : aR[3])) * parseFloat((aS[1].length > 0 ? aS[1] : aS[2])); //psm
    return 0;
}
function DateToNumber(aD) { return parseFloat(aD[2]) * 1000 + parseFloat(aMd[aD[1]]) * 100 + parseFloat(aD[0]); }
function SortTitSpace(t, a) {
    if (t == '&#9826;') return a;
    if (t.substring(0, 3) == 'max' || t.substring(0, 3) == 'min') return t + a;
    return t + ' ' + a;
}
function fSort(ItTp) {
    var B = 'div.bar[name="' + ItTp + '"]', N = ItTp.split('|');
    N[0] = retA(N[0]);
    $(B).find('td.srt,span.sort').mouseover(function() { if ($(this).attr('name2') == '1') return; $(this).css('background-color', '#9FAACF').css('color', '#558'); }
        ).mouseout(function() { if ($(this).attr('name2') == '1') return; $(this).css('background-color', '').css('color', ''); }
    ).click(function() {
        $(B).find('td.srt,span.sort').css('background-color', '').css('color', '').attr('name2', ''
        ).each(function() { $(this).html(aSorTit[N[0]][Math.abs(parseInt($(this).attr('name4')))]); });
        $(this).css('background-color', '#fff').css('color', '#0F2A86').attr('name2', '1');
        sortBy = parseInt($(this).attr('name4'));
        var img = SortTitSpace(aSorTit[N[0]][sortBy], '&#8659;');
        if ($(this).attr('name') == '2') {
            img = SortTitSpace(aSorTit[N[0]][sortBy], '&#8657;');
            $(this).attr('name', '1');
            sortBy *= -1;
        }
        else $(this).attr('name', '2');
        $(this).html(img.replace('&#8661', '').replace('⇕', ''));
        Sort(ItTp);
    });
    $(B).find('td[name4=1]').attr('name2', '1').attr('name', '2').css('background-color', '#fff').css('color', '#0F2A86');    //postcode as default...
}

function fList(B, htms, block) {
    $(B).find('div.block').html(htms).find('table.tbList').mouseover(function() {
        try {
            var N = $(this).attr('name').split('|'), J = JSON[N[0]][N[2]];
            if (J.block == 1) return;
            var dsc = ''; //;J.It == 'p' || (J.It == 'n' && XY.It == 'p')
            if (!isReq(J)) dsc = LsPLc(J, 0, 0);
            else dsc = dscLocR(J);
            $(this).parent().find('span.dsc').css('background', cSTATUSo[J.S]).html("<b>click to open block</b><br>" + dsc + "<br>" + 'created: ' + J.R.split('|')[3] + ', status: ' + J.R.split('|')[0]).css('display', 'block');
            if (J.ck == 1) return;
            $(this).css('background', cSTATUSo[J.S]).find('td.sz,td.rn,td.cn').find('input').css('background', cSTATUSo[parseInt(J.S) + 10]);
        } catch (e) { }
    }).mouseout(function() {
        try {
            var N = $(this).attr('name').split('|'), J = JSON[N[0]][N[2]];
            $(this).parent().find('span.dsc').css('display', 'none');
            if (J.block == 1 || J.ck == 1) return;
            $(this).css('background', cSTATUS[J.S]).find('td.sz,td.rn,td.cn').find('input').css('background', cSTATUS[parseInt(J.S) + 10]);
        } catch (e) { }
    }).click(function() {
        if (XY.L != '' && XY.J.It == $(this).attr('name').split('|')[0] && $(XY.L).attr('matches') == '1'
             && XY.L != ListId($(this).attr('name'))
            ) {//XY.L != '' && 
            $(XY.L).attr('matches', '').find('a.matches:first').trigger('click'); // .css('border', '').find('div.block2').slideUp('fast');
            $(XY.L).attr('matches', '').css('border', '').find('div.block2').slideUp('fast');
            XY.J.block = 2;
        }
        showBlock($(this).attr('name'));
    }).find('font').each(function() { $(this).css('opacity', $(this).attr('name')); });
    $(B).find('div.list').each(function() {
        var iti = $(this).attr('name'), N = iti.split('|'), J = JSON[N[0]][N[2]], L = ListId($(this).attr('name'));
        CHECK($(this), J);
        if (J.Rej > 0) $(this).attr('name2', '1');
        if (J.block == 1) {
            J.block = 0;
            J.NoMove = 1; //JSON[N[0]][N[2]]
            setTimeout("showBlock(\'" + N[0] + '|' + N[1] + '|' + N[2] + "\')", 25);
        } else if (J.block == 2) J.block = 0;
        $(this).find('table.tbList').find('td.check').mouseover(function() { $(this).css('opacity', 0.5); }).mouseout(function() { $(this).css('opacity', ''); }
                        ).click(function() {
                            STAY = 1;
                            J.ck = (J.ck + 1) % 2;
                            CHECK($(ListId(N[0] + '|' + N[1] + '|' + N[2])), J);
                            Select(J);
                        }
                    );
        $(this).find('td.rn,td.sz,td.cn').find('input').mouseover(function() { $(this).css('font-weight', 'bold'); }).mouseout(function() { $(this).css('font-weight', ''); });
        $(this).find('input.rn').click(function() {
            STAY = 1;
            if ($(this).attr('name') == "1") {
                ControlCloseAll(iti, null);
                $(this).trigger('blur');
            }
            else {
                ControlCloseAll(iti, this);
                if (J.block != 1) {
                    showBlock(iti);
                    setTimeout("Rents2('" + iti + "')", 250);
                }
                else Rents2(iti); //N[0] + '|' + N[1] + '|' + N[2]
            }
        });
        fListSize(this, iti, J);
        $(this).find('td.img').mouseover(function() { if ($(this).attr('name') == '1') return; $(this).css('opacity', 0.5); }
                ).mouseout(function() { if ($(this).attr('name') == '1') return; $(this).css('opacity', ''); }
                ).click(function() {
                    if (J.block == 1) STAY = 1;                    //else if (J.block == 0) XY.action = 100;
                    setTimeout("$('" + L + "').find('a.pdf').slice(0, 1).trigger('click')", 300);
                }
            );
    });
    if (block == 0) $(B).find('div.block').attr('name', '1').css('display', 'block');
}
function fListSize(o, iti, J) {
    $(o).find('input.sz').click(function() {
        STAY = 1;
        if ($(this).attr('name') == "1") {
            ControlCloseAll(iti, null);
            $(this).trigger('blur');
        }
        else {
            ControlCloseAll(iti, this);
            if (J.block != 1) {
                showBlock(iti);
                setTimeout("ShowFloor('" + iti + "')", 250);
            }
            else ShowFloor(iti)
        }
    }).mouseover(function() {
        $(this).parent().find('.inFloors:first').html(
               htmlFloors('', J, '')
            ).css('display', 'block').find('.dvFloors2').css('display', 'block').find('span.u').css('width', '14px');
    }).mouseout(function() {
        var o2 = $(this).parent();
        setTimeout(function() { $(o).find('.inFloors:first').css('display', 'none'); }, 200); // alert(2);
    }
    );
}

function Rents2(iti) {
    var N = iti.split('|'), J = JSON[N[0]][N[2]], L = ListId(iti);
    if (XY.view || J.View == 1) return;
    aT = J.Rn.split('|');
    var ins = $(L).find('div.Rents').html('<table cellspacing=0 cellpadding=0><tr><td style="padding-left:5px">Enter values then click update</td><td>price &pound;<input /></td><td>rent &pound;<input /></td><td><select><option value="-1">per sft</option><option value="-2">per sqm</option><option value="1">pa</option><option value="2">monthly</option><option value="4">weekly</option></select></td><td><a title="will update valus if changed\nand close the price/ rent box">update</a></td></tr></table>').slideDown('fast');
    ins.find('input').focus(function() { $(this).select(); }).slice(0, 1).val(addCommas(aT[3].length == 0 ? '0' : aT[3]));
    ins.find('input').slice(1, 2).val(addCommas(aT[2].length == 0 ? '0' : aT[2]));
    ins.find('select').val(aT[1]);
    ins.find('input').change(function() { if (!IsNumeric($(this).val().replace(/,/g, ''))) { $(this).focus(); alert('must be numeric!'); }; });
    ins.find('a').mouseover(function() { $(this).css('opacity', 0.5); }).mouseout(function() { $(this).css('opacity', ''); }).click(function() {
        aT = J.Rn.split('|');
        aT[1] = ins.find('select').val();
        var oldRent = aT[2];
        aT[2] = CommaStrip(ins.find('input').slice(1, 2).val());
        var ExistPrice = parseFloat(aT[3]);
        aT[3] = parseFloat(CommaStrip(ins.find('input').slice(0, 1).val()));
        aT[0] = parseFloat(aT[0]);
        if (aT[3] > 0) {//alert('tenure must be changed - add Freehold=4 / Long Leasehold...' 8);
            if (ExistPrice.length == 0 || ExistPrice == '0') aT[0] += 12;
        }
        else {//alert('tenure must be changed - remove Freehold / Long Leasehold...');
            if (ExistPrice.length > 0 && ExistPrice != '0') aT[0] -= 12;
        }
        J.Rn = aT[0] + "|" + aT[1] + "|" + aT[2] + "|" + aT[3] + "|" + aT[4] + "|" + aT[5] + "|" + aT[6] + "|" + aT[7] + "|" + aT[8] + "|" + aT[9] + "|" + aT[10] + "|" + aT[11] + "|" + aT[12];
        $(L).find('div.Rents').slideUp('fast');
        ControlCloseAll(iti, null);
        $(L).find('td.rn,td.cn').find('input').val(listRent(J.Rn, J.It)); //SON[N[0]][N[2]]
        htmlResize(iti);
        jsCriteria = { Update: 1, tenure: aT[0], rentPeriod: aT[1], rentMin: aT[2], priceMin: aT[3] };
        if (J.F.length > 5 && (aT[1] == '-1' || aT[1] == '-2')) {
            //XY.floorSizeRent = aT[2];
            //7|7 Suite1|100|1170.00|A|0.00|0.00|0.00|01/03/2011|2||Dron  Wright|^||||||*3|3 SuiteD|100|3107.00|A|0.00|0.00|0.00|01/03/2011|3||Dron  Wright|^||||||*3|3 SuiteA2|100|620.00|A|0.00|0.00|0.00|01/03/2011|3||Dron  Wright|^||||||*7|7 Suite3|100|2913.00|A|0.00|0.00|0.00|01/11/2009|2||Dron  Wright|^||||||*0|0 GF|100|5759.00|U|0.00|0.00|0.00|01/08/2009|1||Dron  Wright|^||||||*1|1|100|16760.00|U|0.00|0.00|0.00|01/08/2009|1||Dron  Wright|^||||||*100            
            var A, B, aFs = J.F.split('*'), F = '';
            for (var f = 0; f < aFs.length && aFs[f].length > 3; f++) {
                B = aFs[f].split('^'); A = B[0].split('|');
                if (A[4] == 'A' && A[7] == oldRent && ((aT[1] == '-1' && A[2] == "100") || (aT[1] == '-2' && A[2] == "101"))) A[7] = aT[2];
                F += A[0] + '|' + A[1] + '|' + A[2] + '|' + A[3] + '|' + A[4] + '|' + A[5] + '|' + A[6] + '|' + A[7] + '|' + A[8] + '|' + A[9] + '|' + A[10] + '|' + A[11]
                    + '|' + A[12] + '^' + B[1] + '*'; //+'|' + A[13] + '|' + A[14];
                //A[7], A[2], A[4];//7=rent,2=unit,4=status
            }
            J.F = F;
            jsCriteria.floors = J.F;
        }
        DatabaseUpdate(J);
    })
}
function ListLoad(ItTp, ck, block) {
    try {
        htms = '';
        var B = BarId(ItTp), N = ItTp.split('|'), J;
        for (var i = 0; i < JSON[N[0]].length; i++) {
            J = JSON[N[0]][i];
            if (N[1] == J.Crit && (IS <= J.IS || (IS == 4 && J.rc == 1) || (IS == 5 && J.MyAg == 1))) {
                J.ck = ck; if (J.block == 1) J.block = 2;
                htms += ListHtml(J, i, '');
            }
        }
    } catch (e) {
        //alert(e.message);
    }    //It = XY.It;
    fList(B, htms, block);
    if (block) setTimeout(function() { BlockAll(ItTp); }, 150);
    else setTimeout(function() { ViewEnd(ItTp); }, 150);
}

function showBlockNow(ItTpI) {
    var N = ItTpI.split('|'), B = BarId(N[0] + '|' + N[1]), J = JSON[N[0]][N[2]], L = ListId(ItTpI);
    $('#RESULT').find('div.bar').css('opacity', '');
    $(L).css('border', '1px solid ' + (J.M == 0 ? '#003' : '#eef')).css('border-bottom', '4px solid ' + (J.M == 0 ? '#003' : '#eef')).css('border-top', '3px solid ' + (J.M == 0 ? '#003' : '#eef')
        ).find('div.block2').css('display', 'block').find('div.Control').css('background', cSTATUSo[J.S]
        ).find('a').slice(0, 11).each(function() { if ($(this).attr('name3') == '1') $(this).css('background', '#fff'); else $(this).css('background', cSTATUS[parseInt(J.S) + 10]); });
    if (J.ck == 1) $(L).css('background', cSTATUSo[J.S]);
    $(L).find('table.tbList').css('background', cSTATUSo[J.S]).css('border-bottom', '0px'); // solid #fff
    if (J.block == 0 && isProp(J.It)) showFloorsButton($(L).find('.Size'));
    J.block = 1;
    if (J.NoMove == 1) { J.NoMove = 0; return; }
    offsetY(L);
}
function showBlock(iti) {    //if (XY.EditStart == 1) return;
    if (STAY == 1) { STAY = 0; return; };
    var N = iti.split('|'), B = BarId(N[0] + '|' + N[1]), L = ListId(iti), J = JSON[N[0]][N[2]];
    $(B).find('div.list').css('opacity', '');
    if (J.block != 1) {
        if (J.block != 2) BlockFill(iti, htmlBlock(iti));
        showBlockNow(iti);
    }
    else {
        J.block = 2;
        $(L).css('border', '').find('div.block2').css('display', 'none');
        $(L).find('table.tbList').css('border-bottom', '1px solid ' + (J.M == 0 ? '#989898' : '#eef'));
        ControlCloseAll(iti, null);
    }
}

function showFloorsButton(o) {
    $(o).find('div.dvFloors').find('a').mouseover(function() {
        $(this).parent().find('.dvFloors2').slideDown('fast');
    }).mouseout(function() {
        var o2 = $(this).parent();
        setTimeout(function() { $(o2).find('.dvFloors2').slideUp('slow'); }, 250);
    }).click(function() {
        $(o).parent().parent().parent().parent().find('input.sz').trigger('click');
    }
    ).parent().find('.dvFloors2').css('display', 'none');
}
//floors...
var jFloors = '<span><span class=Title>Shop&nbsp;Specification</span><span title="click to close the floors\n and annul your changes" class=close>x</span><br><br></span>'
+ '<span class="Title2">&nbsp;Please enter what you can<span class="FtM">metre / feet</span></span>'
+ '<table cellpadding="0" cellspacing="0" style="width:415px" border=0><tr><td class=f1>&nbsp;</td><td><span class="Number">&nbsp;Sales&nbsp;Area</span></td><td>&nbsp;</td><td colspan="2"><span class="Number" >Ancillary&nbsp;Area</span></td></tr>'
+ '<tr><td class=f1>&nbsp;Other areas / floors</td><td><input class="txt3Sales" name="d6eac2" /></td><td><span class="FloorUnit">sqft</span></td><td><input class="txt3Ancillary" name="d6eac2" /></td><td><span class="FloorUnit">sqft</span></td></tr>'
+ '<tr><td class=f1>&nbsp;Floor<font class="Number"> 2</font></td><td><input class="txt2Sales" name="d6eac2" /></td><td><span class="FloorUnit">sqft</span></td><td><input class="txt2Ancillary" name="d6eac2" /></td><td><span class="FloorUnit">sqft</span></td></tr>'
+ '<tr><td class=f1>&nbsp;Floor <font class="Number"> 1</font></td><td><input class="txt1Sales" name="d6eac2"  /></td><td><span class="FloorUnit">sqft</span></td><td><input class="txt1Ancillary" name="d6eac2" /></td><td><span class="FloorUnit">sqft</span></td></tr>'
+ '<tr><td class=f1>&nbsp;Ground floor<font class="Number"> 0</font></td><td><input class="txtGSales"  name="ccf98a"  /></td><td><span class="FloorUnit">sqft</span></td><td><input class="txtGAncillary" name="d6eac2" /></td><td><span class="FloorUnit">sqft</span></td></tr>'
+ '<tr><td class=f1>&nbsp;Basement floor<font class="Number"> -1</font></td><td><input class="txtBSales" name="d6eac2" /></td><td><span class="FloorUnit">sqft</span></td><td><input class="txtBAncillary" name="d6eac2" /></td><td><span class="FloorUnit">sqft</span></td></tr>'
+ 'TYPE<tr><td colspan=3></td><td colspan=2><span title="click to confirm your changes" class="Save">Save&nbsp;&amp;&nbsp;Close</span></td></tr></table>'
var floor2 = '<tr><td colspan=5>&nbsp;</td></tr>'
+ '<tr><td class=f1>&nbsp;TOTAL</td><td><input class="txtTotalSales"  name="C0DFA2"  /></td><td><span class="FloorUnit">sqft</span></td><td><input class="txtTotalAncillary" name="C0DFA2" /></td><td><span class="FloorUnit">sqft</span></td></tr>'
+ '<tr><td colspan=5>&nbsp;</td></tr>'
+ '<tr><td class=f1><b>&nbsp;Min and Max TOTAL</b></td><td><input class="txtTotMin" name="CAE4FF" /></td><td><span class="FloorUnit">sqft</span></td><td><input class="txtTotMax" name="CAE4FF" /></td><td><span class="FloorUnit">sqft</span></td></tr>'
+ '<tr><td></td><td style="text-align:right">min</td><td></td><td style="text-align:right">max</td><td></td></tr>'
+ '<tr><td class=f1>&nbsp;Gross Frontage</td><td><input class="txtGrossFrontage" name="d6eac2" /></td><td><span class="FloorUnit2">ft</span></td><td colspan="2" ></td></tr>'
+ '<tr><td class=f1>&nbsp;Net Frontage</td><td><input class="txtNetFrontage" name="d6eac2" /></td><td><span class="FloorUnit2">ft</span></td><td colspan="2"></td></tr>'
+ '<tr><td class=f1>&nbsp;Internal Width</td><td><input class="txtInternalWidth" name="ccf98a"  /></td><td><span class="FloorUnit2">ft</span></td><td colspan="2" ></td></tr>'
+ '<tr><td class=f1>&nbsp;Widening to Width</td><td><input class="txtWideningWidth" name="d6eac2" /></td><td><span class="FloorUnit2">ft</span></td><td colspan="2" ></td></tr>'
+ '<tr><td class=f1>&nbsp;After&nbsp;(what&nbsp;distance)</td><td><input class="txtAfter" name="d6eac2"  /></td><td><span class="FloorUnit2">ft</span></td><td colspan="2" ></td></tr>'
+ '<tr><td class=f1>&nbsp;Shop Depth</td><td><input class="txtShopDepth" name="ccf98a" /></td><td><span class="FloorUnit2">ft</span></td><td colspan="2" ></td></tr>'
+ '<tr><td colspan="5"></td></tr>'
+ '<tr><td class=f1>&nbsp;Return&nbsp;/&nbsp;Rear&nbsp;frontage</td><td><input class="txtReturnFrontage"  name="d6eac2" /></td><td><span class="FloorUnit2">ft</span></td><td colspan="2"></td></tr>'
var floor4 = '<tr><td class=f1>&nbsp;Trade&nbsp;Counter</td><td><input class="txtTradeCounter" name="d6eac2" /></td><td><span class="FloorUnit">sqft</span></td><td colspan="2" ></td></tr>'
+ '<tr><td class=f1>&nbsp;Covered&nbsp;Loading</td><td><input class="txtCoveredLoading"  name="d6eac2" /></td><td><span class="FloorUnit">sqft</span></td><td colspan="3"></td></tr>'
+ '<tr><td class=f1>&nbsp;Garage&nbsp;/&nbsp;Repair</td><td><input class="txtGarageRepair"  name="d6eac2" /></td><td><span class="FloorUnit">sqft</span></td><td colspan="3" ></td></tr>'
+ '<tr><td class=f1>&nbsp;Ancillary&nbsp;Stores</td><td><input class="txtAncillaryStore" name="d6eac2" /></td><td><span class="FloorUnit">sqft</span></td><td colspan="2"></td></tr>'
+ '<tr><td colspan=6>&nbsp;</td></tr>'
+ '<tr><td class=f1>&nbsp;Total</td><td><input class="txtTotalProduction" name="c0dfa2" /></td><td><span class="FloorUnit">sqft</span></td><td><input class="txtTotalOfficeArea" name="c0dfa2" /></td><td><span class="FloorUnit">sqft</span></td></tr>'
+ '<tr><td colspan=5>&nbsp;</td></tr>'
+ '<tr><td class=f1>&nbsp;TOTAL&nbsp;SIZE</td><td><input class="txtTotMin" name="CAE4FF" /></td><td><span class="FloorUnit">sqft</span></td><td><input class="txtTotMax" name="CAE4FF" /></td><td><span class="FloorUnit">sqft</span></td></tr>'
+ '<tr><td>&nbsp;</td><td style="text-align:right">min</td><td>&nbsp;</td><td style="text-align:right">max</td><td>&nbsp;</td></tr>'
var jFloorsOfficeTit = { New: "Enter floor sizes for any of the 4 default floors first.<br>"
+ "Overwrite a floor ‘Name’ starting with a number then a space (0=Ground, 0.5=Mezzanine, etc.)<br>‘Save’ will delete any unused floors.<br>‘add new floor’ will add sequential numbered floors.<br>"
+ "click ‘Save’ to check final display. Check/Overwrite ‘min’ Size before clicking ‘Save & Close’."
, Exist: "update Status for each relevant floor. 'Part UO' / 'Part Completed' splits the floor.<br><span style='padding:1px;background:#d6eac2;color:#3B519C'>green=Available</span> <span style='padding:1px;background:#F8F1B4;color:#3B519C'>yellow=Under Offer</span> <span style='padding:1px;background:#EBC9C8;color:#3B519C'>red=Completed or Withdrawn</span><br>"
+ "If completed please give some information, eg. Occupier.<br>'add new floor' will add sequential numbered floors.<br>Check/Overwrite Min Size before clicking ‘Save & Close’."
}; ////if (XY.flPeriod == -1) return 100;if (XY.flPeriod == -2) return 101;if (XY.flPeriod == 2) return 12;if (XY.flPeriod == 4) return 52;
var jFloorsOffice = '<span><span class=Title>Office&nbsp;floors</span><span class=close>x</span></span><div style="font-size:10px;padding:2px">TITLE</div>'
+ "<div class=FloorsOffice style='height:100%' name=0><table cellpadding=0 cellspacing=0 class=tbFloors></table>"
+ "<div class=FloorsControl><select><option value=0>add new FLOOR</option><option value=1>add 1 new FLOOR</option><option value=2>add 2 new FLOORs</option><option value=3>add 3 new FLOORs</option><option value=4>add 4 new FLOORs</option><option value=5>add 5 new FLOORs</option></select>"
+ "<span class=floorUnits>Rent / RP / SC&nbsp;<select name='-1'><option value='-1'>per sqft</option><option value='-2'>per sqm</option><option value=1>yearly</option><option value=2>monthly</option><option value=4>weekly</option></select></span></div></div>"
+ "<div style='display:block;padding-top:7px'><span style='float:left;top:0px;margin-right:35px' title='click to save your changes' class=Save>Save</span><div class=mnmx><select style='height:16px;font-size:0.8em'><option value=2>sqf</option><option value=1>sqm</option></select><span class=mxOffice><input class=mxoffice /><br>max</span><span class=mnOffice><input class=mnoffice /><br>min</span></div>"
+ '<span style="float:right;top:0px;left:-7px" title="click to close and save your changes" class=Save>Save &amp; Close</span></div><div style="clear:both;padding-bottom:1px"></div>';
var trFloor = '<tr name=floorxF class=CLASS><td><input class=f1 name=xF tabindex=1 value="NAME" /></td><td><span style="width:102px;display:inline-block"><input tabindex=2 style="float:left" class=f2 name2=xF value="SIZE" /><select style="float:right" name2=xF tabindex=3 class=units><option selected style="border:1px solid #eee" value="100">sq ft</option><option value="101">sq m</option></select></span></td>'
    + '<td><span style="width:70px;display:inline-block"><input tabindex=4 class=f3 value="RENT" /><span class=unit>psf</span></span></td>'
    + '<td><span style="width:70px;display:inline-block"><input tabindex=5 class=f4 value="RATE" /><span class=unit>psf</span></span></td>'
    + '<td><span style="width:70px;display:inline-block"><input tabindex=6 class=f5 value="CHARGE" /><span class=unit>psf</span></span></td><td><span></span><input tabindex=7 onfocus="Calendar(this,1,21)" name="mmyy" class="fdate" value="DATE" /></td>'
    + '<td><span class=tenant></span><select tabindex=8 name=xF class=status><option selected value="A">Available</option><option style="background:#F8F1B4" value="U">Under Offer</option><option style="background:#F8F1B4" value="V">Part Under Offer</option><option style="background:#EBC9C8" value="W">Withdrawn</option><option style="background:#EBC9C8" value="C">Complete</option><option style="background:#EBC9C8" value="M">Part Complete </option></select></td><td><input tabindex=9 class=occ value="OCC" /></td><td><input tabindex=10 class=agn value="AGN" /></td></tr>';
var aFloor = new Array(), jFloor = "Floor={number:NO,name:'NAME',unit:'UNIT',size:'SIZE',status:'STATUS',charge:'CHARGE',rate:'RATE',rent:'RENT',occupier:'OCC',agency:'AGN',available:'DATE',one:'',tenant:''}";
var hTenant = '<span><span style="float:left"><b>Floors&nbsp;tenants</b></span><span class=close>x</span></span>'
+ '<table cellpadding=0 cellspacing=0><tr><td><span class=ti>Tenant</span></td><td colspan="3"><input onfocus="this.select()" class=cmp value="Company name" tabindex="31" style="width:130px;text-align:left" /></td></tr>'
+ '<tr><td><span class=ti>Rent&nbsp;marketed</span></td><td><input disabled class=trent1 style="width:50pt;background:#fec;border:0px" value="RENT" /></td>'
+ '<td><span class=ti>Lease&nbsp;Start</span></td><td><input tabindex="32" class=tlease1 onfocus="showCalendarControl(this)" name="mmyy" style="width:40px" /></td></tr>'
+ '<tr><td><span class=ti>Unit&nbsp;charge</span></td><td><select tabindex="33" class=tunit style="width:54pt"><option value="100">per sqft</option><option value="101">per sqm</option><option value="1">yearly</option><option value="12">monthly</option><option value="52">weekly</option></select></td>'
+ '<td><span class=ti>1st&nbsp;Break&nbsp;Option</span></td><td><span></span><input onfocus="Calendar(this,0,21)" name="mmyy" class="tbreak" tabindex="34" style="width:40px" /></td></tr>'
+ '<tr><td><span class=ti>Rent&nbsp;achieved</span></td><td><span></span><input value="0" class=trent2 onfocus="this.select()" tabindex="35" style="width:50pt" /></td>'
+ '<td><span class=ti>Lease&nbsp;End</span></td><td><span></span><input tabindex="36" onfocus="Calendar(this,0,21)" name="mmyy" class="tlease2" style="width:40px" /></td>'
+ '</tr><tr><td colspan="4">Please enter any information you can remember, otherwise just click</td></tr></table>'
+ '<span class="Save" style="clear:both;float:right;margin-right:25px">Update</span><div style="clear:both">&nbsp;</div>';
function Substr(s, st, end) { if (s == undefined || s.length < end) return ""; return s.substring(st, end); }
function floorNumber(v) { try { return (IsNumeric(v.split(' ')[0]) ? parseFloat(v.split(' ')[0]) : 0); } catch (e) { return 0; } }
function floorDate(v) { try { return v.length == 0 ? '' : aM[v.split('/')[1] - 1] + '.' + Substr(v.split('/')[2], 2, 4); } catch (e) { return ""; } }
function floorsOfficePop(iti) {
    var f = 0, aFs, A, N = iti.split('|'), J = JSON[N[0]][N[2]];
    J.aFloor = new Array();
    try {
        aFs = J.F.split('*');
        for (f = 0; f < aFs.length && aFs[f].length > 3; f++) {
            A = aFs[f].split('|');
            popJsFloor(iti, floorNumber(A[1]), A[1], floorDate(A[8]), A[3], A[7], A[6], A[5], A[10], A[11], A[2], A[4]); //7=rent,2=unit,4=status
        }
        quick_sort(J.aFloor);
    } catch (e) {
        //alert(e.message);
    }
}
function Undefined(s) { if (s == undefined) return ""; return s; }
function popJsFloor(iti, no, name, date, size, rent, rate, charge, occ, agn, unit, status) {
    var N = iti.split('|'), J = JSON[N[0]][N[2]], L = ListId(iti);
    J.aFloor[J.aFloor.length] = eval(jFloor.replace('NO', no).replace('NAME', name).replace('DATE', Undefined(date)
                                                 ).replace('SIZE', size).replace('RENT', rent).replace('RATE', rate).replace('CHARGE', charge
                                                 ).replace('OCC', occ).replace('AGN', agn).replace('UNIT', unit).replace('STATUS', status));
}
function htmlFloor0(a, b, c, mail, first) {
    if (mail == 1)
        return '<div style="clear:both;font-size:0.8em">' + (first == 0 ? 'floors:<br>' : '') + '<span style="width:MAXpx"><b>'
                + a + '</b>:</span><span style="width:35px">&nbsp;'
                + addCommas(b) + '&nbsp;' + c + "</span></div>";
    ;
    return '<div style="clear:both"><span style="width:MAXpx"><b>'
                + a + '</b>:</span><span style="width:35px">'
                + addCommas(b) + "</span><span style='width:4px;display:inline-block' class=u>&nbsp;"
                + c + "</span></div>";
    ;
}
function htmlFloors(title, J, ve) {
    var ret = '', f = 0, aFs, aFs2 = new Array("", "Base", "", "Ground", "", "1st", "", "2nd", "", "Other");
    try {
        jsCriteria.floors = J.F;
        var floors = J.F;
        if (floors.length < 2) return '';
        aFs = floors.split('|');
        if (J.tp == "2" || J.tp == "4") {
            if (floors.indexOf('^') > -1) return "";
            var MAX = 0;
            for (f = 10; f > 1; f -= 2) {
                if (aFs[f - 1].length > 0 && aFs[f - 1] != "0" || (aFs[f].length > 0 && aFs[f] != "0")) {
                    if (aFs2[f - 1].length > MAX - 3) MAX = aFs2[f - 1].length + 3;
                    if (aFs[f - 1].length > 0 && aFs[f - 1] != "0")
                        ret += htmlFloor0(aFs2[f - 1], aFs[f - 1], (aFs[0] == "2" ? "sf" : "sm"), J.mail, ret.length);
                    if (aFs[f].length > 0 && aFs[f] != "0") {
                        if (9 > MAX - 3) MAX = aFs2[f - 1].length + 3;
                        ret += htmlFloor0('ancillary', aFs[f], (aFs[0] == "2" ? "sf" : "sm"), J.mail, ret.length);
                    }
                }
            }
            if (ret.length == 0) return title + (ve.length > 0 ? '<br>' + ve : ''); //"";
        }
        else {
            var iti = J.It + '|' + J.tp + '|' + J.II;
            if (floors.indexOf('^') == -1) return "";
            if (J.aFloor == undefined) floorsOfficePop(iti);
            var MAX = 0, j = JSON[J.It][J.II];
            for (f = j.aFloor.length - 1; f >= 0; f--) {
                if (j.aFloor[f].status == "A" && j.aFloor[f].name.length > 0) {
                    if (j.aFloor[f].name.length > MAX - 3) MAX = j.aFloor[f].name.length + 3;
                    ret += htmlFloor0(j.aFloor[f].name, j.aFloor[f].size, (j.aFloor[f].unit == "100" ? "sf" : "sm"), J.mail, ret.length);
                }
            }
        }
    } catch (e) { return ""; } 
    return "<div class=dvFloors><a>" + title + "</a><span class=dvFloors2 style='width:" + parseFloat((MAX * 8) + 50) + "px'>" + ret.replace(/MAX/g, (MAX * 8)) + "</span></div>" + ve + "<br>";
}
var oFloor;
function ShowFloor(iti) {
    var N = iti.split('|'), J = JSON[N[0]][N[2]], L = ListId(iti);
    if (XY.view || J.View == 1) return;
    oFloor = $(L).find('div.Floors').slice(0, 1);
    J.aFloor = new Array();
    J.Forig = J.F; J.Szorig = J.Sz; J.Sorig = J.S; J.Rnorig = J.Rn;
    if (J.tp == "8") {
        J.aFloor = new Array();
        var cDate = new Date(), f = 0, aF = new Array('1', '0 GF', '-1 Lwr Grd', '-1 Base Storage', '5'), aFs, aFs2;
        MMYYDD = aM[cDate.getMonth()] + '.' + cDate.getFullYear().toString().substring(2, 4);
        $(oFloor).css('width', '550px').html(jFloorsOffice.replace('TITLE', J.F.length < 5 ? jFloorsOfficeTit.New : jFloorsOfficeTit.Exist));
        $(oFloor).find('div.FloorsOffice').find('table').html(FloorOfficeTable.replace('Asc', 'Desc'));
        $(oFloor).find('div.FloorsControl').find('select').slice(0, 1).change(function() {
            for (f = J.aFloor.length - 1; f >= 0; f--)
                if (J.aFloor[f].status == 'N' && J.aFloor[f].name != undefined && J.aFloor[f].name.length > 0 && J.aFloor[f].size != '0') J.aFloor[f].status = 'A';

            J.F = retFloors(iti, 1);
            for (var f = 0; f < J.aFloor.length; f++) {
                $(oFloor).find('tr[name=floor' + f + ']').find('input,select').css('background', Status[J.aFloor[f].status]);
                //to be deleted...
                if (J.aFloor[f].name == undefined || J.aFloor[f].name.length == 0 || J.aFloor[f].status == 'N')
                    $(oFloor).find('tr[name=floor' + f + ']').css('display', 'none');
            }
            if (flMax.length == 0) flMax[0] = 0;
            var name;
            for (f = 0; f < $(this).val(); f++) {
                name = parseInt(rMax(flMax)) + 1 + f + '';
                if (name == undefined) name = '';
                popJsFloor(iti, name.split(' ')[0], name, MMYYDD, '0', XY.flRent, XY.flRatesPayable, XY.flServiceCharge, '', XY.Company, '100', 'N');
                $(oFloor).find('div.FloorsOffice').find('table').find('tr:first').after(popFloorRet(iti, J.aFloor.length - 1));
                popFloor2(iti, J.aFloor.length - 1);
            }
            $(this).val(0);
            fOfficeFloors(iti);
        });
        if (J.F.length == 0) {//^=tenants...? || J.F.indexOf('^') == -1
            if (XY.flRent == 0 && parseFloat(J.Rn.split('|')[2]) > 0) XY.flRent = J.Rn.split('|')[2];
            if (XY.flRatesPayable == 0 && parseFloat(J.Rn.split('|')[5]) > 0) XY.flRatesPayable = J.Rn.split('|')[5];
            if (XY.flServiceCharge == 0 && parseFloat(J.Rn.split('|')[6]) > 0) XY.flServiceCharge = J.Rn.split('|')[6];
            for (f = 3; f >= 0; f--) {
                popJsFloor(iti, aF[f].split(' ')[0], aF[f], MMYYDD, '0', XY.flRent, XY.flRatesPayable, XY.flServiceCharge, '', XY.Company, '100', 'N');
                $(oFloor).find('div.FloorsOffice').find('table').find('tr:first').after(popFloorRet(iti, J.aFloor.length - 1));
                popFloor2(iti, J.aFloor.length - 1);
            }
        }
        else {
            if (J.aFloor.length == 0) floorsOfficePop(iti);
            for (f = J.aFloor.length - 1; f >= 0; f--) {
                if (J.aFloor[f].name.length > 0 && J.aFloor[f].status != 'N') {
                    popFloor(iti, f);
                    flMax[flMax.length] = J.aFloor[f].number; //.split(' ')[0];
                }
            }
        }
        $(oFloor).find('input.f2,input.f3,input.f4,input.f5').each(function() { $(this).val(addCommas($(this).val())); });
        if ($(oFloor).find('input.f2').length > 2) $(oFloor).find('input.f2').slice(1, 2).attr('name', 'txtGSales');
        else $(oFloor).find('input.f2').slice(0, 1).attr('name', 'txtGSales');
        $(oFloor).attr('name', '1').css('display', 'block'); //.slideDown('fast')
        fOfficeFloors(iti);
    }
    else {
        if (J.tp == "2")
            $(oFloor).html(jFloors.replace('TYPE', floor2)).slideDown('fast').attr('name', '1');
        else {
            $(oFloor).html(jFloors.replace('TYPE', floor4)).slideDown('fast').attr('name', '1').find('span.Title').html("Industrial");
            $(oFloor).find('span.Number').slice(0, 1).html("Industrial&nbsp;Areas").css('margin-left', '9px').css('position', 'absolute');
        }
        if (J.F.length > 6) {
            var floor = J.F.split("|"), Sz = J.Sz.split("|");
            oFloor = $(oFloor);
            $(oFloor).find('.txtBSales').val(floor[1]); $(oFloor).find('.txtBAncillary').val(floor[2]);
            $(oFloor).find('.txtGSales').val(floor[3]); $(oFloor).find('.txtGAncillary').val(floor[4]);
            $(oFloor).find('.txt1Sales').val(floor[5]); $(oFloor).find('.txt1Ancillary').val(floor[6]);
            $(oFloor).find('.txt2Sales').val(floor[7]); $(oFloor).find('.txt2Ancillary').val(floor[8]);
            $(oFloor).find('.txt3Sales').val(floor[9]); $(oFloor).find('.txt3Ancillary').val(floor[10]);
            $(oFloor).find('.txtTotMin').val(Sz[1]); $(oFloor).find('.txtTotMax').val(Sz[2]);
            if (J.tp == "2") {
                $(oFloor).find('.txtTotalSales').val(floor[11]); $(oFloor).find('.txtTotalAncillary').val(floor[12]);
                $(oFloor).find('.txtGrossFrontage').val(floor[13]); $(oFloor).find('.txtNetFrontage').val(floor[14]);
                $(oFloor).find('.txtInternalWidth').val(floor[15]); $(oFloor).find('.txtWideningWidth').val(floor[16]);
                $(oFloor).find('.txtAfter').val(floor[17]); $(oFloor).find('.txtShopDepth').val(floor[18]); $(oFloor).find('.txtReturnFrontage').val(floor[19]);
            }
            else if (J.tp == "4") {
                $(oFloor).find('.txtTotalProduction').val(floor[11]); $(oFloor).find('.txtTotalOfficeArea').val(floor[12]);
                $(oFloor).find('.txtTradeCounter').val(floor[13]); $(oFloor).find('.txtCoveredLoading').val(floor[14]);
                $(oFloor).find('.txtGarageRepair').val(floor[15]); $(oFloor).find('.txtAncillaryStore').val(floor[16]);
            }
            $(oFloor).find('input[type=text]').each(function() { $(this).val(addCommas($(this).val())); });
            if (floor[0] == "1") fFloorsClick(iti); //1=sm,2=sf            
        }
    }
    fFloors(iti);
    setTimeout("FloorFocus()", 300);
}
var FloorOfficeTable = "<tr style='background:#aae;color:#339'><td class=FloorsName><img src='http://www.4prop.com/JSON/images/Asc.png' />Name</td><td>Size</td><td>Rent</td><td>Rates Payable</td><td>Serv. Charge</td><td>Available</td><td>Status</td><td>Occupier</td><td>Agency</td></tr>";
function fOfficeRow(iti, F) {
    var N = iti.split('|'), J = JSON[N[0]][N[2]], L = ListId(iti), ret = '';
    $(F).find('.FloorsName').mouseover(function() { $(this).css('opacity', 0.5); }).mouseout(function() { $(this).css('opacity', ''); }).click(function() {
        var F = $(oFloor).find('div.FloorsOffice');
        $(F).find('table').html(FloorOfficeTable);
        if ($(F).attr('name') == "1") {
            for (f = J.aFloor.length - 1; f >= 0; f--) popFloor(iti, f);
            $(F).find('.FloorsName').find('img').attr('src', 'http://www.4prop.com/JSON/images/Desc.png');
        }
        else for (f = 0; f < J.aFloor.length; f++) popFloor(iti, f);
        $(F).attr('name', $(F).attr('name') == '0' ? '1' : '0');
        FloorsCellStyle($(oFloor).find('div.FloorsOffice').find('tr'));
        fOfficeRow(iti, $(oFloor).find('div.FloorsOffice'));
    });
    $(F).find('select.status').change(function() {
        var f = $(this).attr('name'), f2 = J.aFloor.length;
        var F = $(oFloor).find('div.FloorsOffice').find('tr[name=floor' + f + ']'), v = $(this).val();
        J.aFloor[f].status = v;
        $(F).find('input,select').css('background-color', Status[$(this).val()]);
        if (v == 'M' || v == 'V') {//extra floor...
            popJsFloor(iti, J.aFloor[f].no, J.aFloor[f].name, J.aFloor[f].available, J.aFloor[f].size, J.aFloor[f].rent, J.aFloor[f].rate, J.aFloor[f].charge, J.aFloor[f].occupier, J.aFloor[f].agency, J.aFloor[f].unit, 'N');
            $(F).before(popFloorRet(iti, f2));
            popFloor2(iti, f2);
            $(this).val(v == 'M' ? 'C' : 'U');
            J.aFloor[f].size = 0;
            $(F).find('input.f2').val('0');
            FloorsCellStyle($(oFloor).find('div.FloorsOffice').find('tr[name=floor' + f2 + ']'));
            fOfficeRow(iti, $(oFloor).find('div.FloorsOffice').find('tr[name=floor' + f2 + ']'));
            $(F).find('input,select').css('background-color', Status['N']);
        }
        if (v == 'C' || v == 'M') {//tennant
            var rn = $(F).find('input.f3').val(), Fo = F;
            F = $(F).find('span.tenant');
            $(F).html(hTenant.replace('RENT', rn)).css('display', 'block').find('span.close'
                    ).mouseover(function() { $(this).css('color', '#900').css('background-color', '#fff'); $(F).css('background-color', '#900'); }
	                ).mouseout(function() { $(this).css('color', '#fff').css('background-color', ''); $(F).css('background-color', ''); }
	                ).click(function() { $(F).slideUp('fast'); hideCalendarControl(); })
            $(F).find('span.Save').mouseover(function() { $(this).css('background-color', '#cfc').css('color', '#393'); $(F).css('background-color', '#090'); }
               ).mouseout(function() { $(this).css('background-color', '').css('color', ''); $(F).css('background-color', ''); }
               ).click(function() {
                   var v = $(this).parent().find('input.cmp').val(), v1 = $(Fo).find('input.occ').val();
                   if (v != 'Company name') {
                       J.aFloor[f].tenant = $(this).parent().find('input.tlease1').val() + '|'
                                        + $(this).parent().find('input.tlease2').val()
                                        + '|' + $(this).parent().find('select.tunit').val()
                                        + '|' + $(this).parent().find('input.trent2').val()
                                        + '|' + v + '|' + $(this).parent().find('input.tbreak').val() + '|';
                       if (v1.length > 0) v += ',' + v1;
                       $(Fo).find('input.occ').val(v);
                   }
                   $(F).css('display', 'none');
                   hideCalendarControl();                   //startLease|endLease|Unit|Rent|Company|firstBreak|
               })
        }
        FloorsRecalc(iti);
        if (v == 'M' || v == 'V') { $(F).find('input,select').css('background-color', Status['N']); }
    });
    $(F).find('input.f1').change(function() {
        var f = parseInt($(this).attr('name'));
        J.aFloor[f].name = $(this).val();
        J.aFloor[f].number = J.aFloor[f].name.split(' ')[0];
        flMax[f] = 0;
        if (IsNumeric(J.aFloor[f].number)) flMax[f] = J.aFloor[f].number;
        if (J.aFloor[f].status == 'N') {
            J.aFloor[f].status = 'A';
            $(F).find('tr[name=floor' + f + ']').find('input,select').css('background', Status['A']);
        }
        FloorsRecalc(iti);
    });
    $(F).find('input.f2').change(function() {
        var f = parseInt($(this).attr('name2'));
        if (J.aFloor[f].status == 'N') {
            J.aFloor[f].status = 'A';
            $(F).find('tr[name=floor' + f + ']').find('input,select').css('background', Status['A']);
        }
        J.aFloor[f].size = CommaStrip($(this).val());
        FloorsRecalc(iti);
    });
    $(F).find('select.units').change(function() {
        J.aFloor[$(this).attr('name2')].unit = CommaStrip($(this).val());
        FloorsRecalc(iti);
    });
}
function fOfficeFloors(iti) { fOfficeStart(iti); fOfficeRow(iti, $(oFloor).find('div.FloorsOffice')); }
function retFloors(iti, stay) {
    var N = iti.split('|'), J = JSON[N[0]][N[2]], L = ListId(iti), ret = '';
    switch (J.tp) {
        case "2":
            ret = J.Sz.split('|')[0] + Split + CommaStrip($(oFloor).find('input.txtBSales').val()) + Split + CommaStrip($(oFloor).find('input.txtBAncillary').val()) + Split + CommaStrip($(oFloor).find('input.txtGSales').val()) + Split + CommaStrip($(oFloor).find('input.txtGAncillary').val());
            ret += Split + CommaStrip($(oFloor).find('input.txt1Sales').val()) + Split + CommaStrip($(oFloor).find('input.txt1Ancillary').val()) + Split + CommaStrip($(oFloor).find('input.txt2Sales').val()) + Split + CommaStrip($(oFloor).find('input.txt2Ancillary').val()) + Split + CommaStrip($(oFloor).find('input.txt3Sales').val()) + Split + CommaStrip($(oFloor).find('input.txt3Ancillary').val());
            ret += Split + CommaStrip($(oFloor).find('input.txtTotalSales').val()) + Split + CommaStrip($(oFloor).find('input.txtTotalAncillary').val()) + Split + CommaStrip($(oFloor).find('input.txtGrossFrontage').val()) + Split + CommaStrip($(oFloor).find('input.txtNetFrontage').val());
            ret += Split + CommaStrip($(oFloor).find('input.txtInternalWidth').val()) + Split + CommaStrip($(oFloor).find('input.txtWideningWidth').val()) + Split + CommaStrip($(oFloor).find('input.txtAfter').val()) + Split + CommaStrip($(oFloor).find('input.txtShopDepth').val()) + Split + CommaStrip($(oFloor).find('input.txtReturnFrontage').val());
            break;
        case "4":
            ret = J.Sz.split('|')[0] + Split + CommaStrip($(oFloor).find('input.txtBSales').val()) + Split + CommaStrip($(oFloor).find('input.txtBAncillary').val()) + Split + CommaStrip($(oFloor).find('input.txtGSales').val()) + Split + CommaStrip($(oFloor).find('input.txtGAncillary').val());
            ret += Split + CommaStrip($(oFloor).find('input.txt1Sales').val()) + Split + CommaStrip($(oFloor).find('input.txt1Ancillary').val()) + Split + CommaStrip($(oFloor).find('input.txt2Sales').val()) + Split + CommaStrip($(oFloor).find('input.txt2Ancillary').val()) + Split + CommaStrip($(oFloor).find('input.txt3Sales').val()) + Split + CommaStrip($(oFloor).find('input.txt3Ancillary').val());
            ret += Split + CommaStrip($(oFloor).find('input.txtTotalProduction').val()) + Split + CommaStrip($(oFloor).find('input.txtTotalOfficeArea').val()) + Split + CommaStrip($(oFloor).find('input.txtTradeCounter').val()) + Split + CommaStrip($(oFloor).find('input.txtCoveredLoading').val()) + Split + CommaStrip($(oFloor).find('input.txtGarageRepair').val()) + Split + CommaStrip($(oFloor).find('input.txtAncillaryStore').val());
            break;
        case "8":
            flMax = new Array();          //if (J.aFloor.length == 0) fOfficeStart(XY.iti);  //oFloor = $(oFloor).find('div.FloorsOffice');            else
            try {//determine status...
                XY.floorSizeRent = 0; ////J.S = 4; //0 1 2 4
                var T = J.Rn.split('|');
                for (var f = 0; f < J.aFloor.length; f++) {
                    if (J.aFloor[f].name != undefined) {
                        var tr = $(oFloor).find('tr[name=floor' + f + ']');
                        J.aFloor[f].name = tr.find('td').slice(0, 1).find('input').val(); //J.aFloor[f].name == undefined ||
                        if (stay == 0 && J.aFloor[f].status == 'N' && tr.find('input.f2').val() == '0') {
                            $(tr).css('display', 'none');
                        }
                        if (J.aFloor[f].name != undefined) {
                            if (J.aFloor[f].name.length == 0) $(tr).css('display', 'none');
                            //if (J.aFloor[f].status != 'N') J.aFloor[f].status = tr.find('select.status').val();
                            J.aFloor[f].name = tr.find('input.f1').val();
                            J.aFloor[f].size = CommaStrip(tr.find('input.f2').val());
                            J.aFloor[f].unit = tr.find('select.units').val();
                            J.aFloor[f].rent = CommaStrip(tr.find('input.f3').val());
                            J.aFloor[f].rate = CommaStrip(tr.find('input.f4').val());
                            J.aFloor[f].charge = CommaStrip(tr.find('input.f5').val());
                            J.aFloor[f].available = tr.find('td').find('input.fdate').val();
                            J.aFloor[f].occupier = tr.find('td').find('input.occ').val();
                            J.aFloor[f].agency = tr.find('td').find('input.agn').val();
                            var j = J.aFloor[f]; //j.name != undefined ||
                            if (j.name.length > 0 && J.aFloor[f].status != 'N') {
                                if (ret.length == 0) J.S = 4;
                                if (J.S > 0 && J.aFloor[f].status == 'A') J.S = 0;
                                if (J.S > 1 && (J.aFloor[f].status == 'U' || J.aFloor[f].status == 'V')) J.S = 1;
                                if (J.S > 2 && J.aFloor[f].status == 'W') J.S = 2; flMax[flMax.length] = j.number;
                                if (j.status == 'A') FloorCompareSmSf(T[1], j.unit, j.rent);
                                ret += j.number + '|' + j.name + '|' + j.unit + '|' + j.size + '|' + j.status + '|' + j.charge + '|' + j.rate + '|' + j.rent
                                + (j.available.length == 0 ? '|' : '|01/' + ret2(parseInt(aMd[j.available.split('.')[0]]) + 1) + '/20' + j.available.split('.')[1])
                                + '|' + j.one + '|' + j.occupier + '|' + j.agency + '|^' + j.tenant + '*';
                            }
                        }
                    }
                }
                EditSizeRw(J.Sz.split('|'));
                cssStatus(J.ck, L, J);
                if (T[1] == '-1' || T[1] == '-2') {//psf psm, 
                    J.Rn = T[0] + "|" + T[1] + "|" + XY.floorSizeRent + "|" + T[3] + "|" + T[4] + "|" + T[5] + "|" + T[6] + "|" + T[7] + "|" + T[8] + "|" + T[9] + "|" + T[10] + "|" + T[11] + "|" + T[12];
                    $(L).find('td.rn,td.cn').find('input').val(listRent(J.Rn, J.It));
                    htmlResize(iti);
                }
            } catch (e) { }
            break;
    }
    return ret;
}
function FloorCompareSmSf(unit, funit, frent) {
    if ((unit == '-1' && funit == '100') || (unit == '-2' && funit == '101')) {
        if (XY.floorSizeRent < frent) XY.floorSizeRent = frent;
    }
    else if (unit == '-1') { //psf
        if (XY.floorSizeRent < frent / 10.764) XY.floorSizeRent = Math.round(frent * 10.764 * 100) / 100;
    }
    else if (XY.floorSizeRent < frent * 10.764) XY.floorSizeRent = Math.round(frent / 10.764 * 100) / 100;

}
function popFloorRet(iti, f) {
    var N = iti.split('|'), J = JSON[N[0]][N[2]], L = ListId(iti);
    return trFloor.replace(/xF/g, f).replace('NAME', J.aFloor[f].name).replace('DATE', J.aFloor[f].available).replace('SIZE', J.aFloor[f].size
                                   ).replace('RENT', J.aFloor[f].rent).replace('RATE', J.aFloor[f].rate
                                   ).replace('CHARGE', J.aFloor[f].charge).replace('CLASS', J.aFloor[f].status
                                   ).replace('OCC', J.aFloor[f].occupier).replace('AGN', J.aFloor[f].agency);
}
function popFloor(iti, f) {
    $(oFloor).find('div.FloorsOffice').find('table').find('tr:last').after(popFloorRet(iti, f));
    popFloor2(iti, f);
}
function popFloor2(iti, f) {
    var N = iti.split('|'), J = JSON[N[0]][N[2]], L = ListId(iti);
    try {
        if (J.F.length > 5) {            //var ff = J.aFloor.length - 1;
            var F = $(oFloor).find('div.FloorsOffice').find('tr[name=floor' + f + ']');
            $(F).find('input,select').css('background', Status[J.aFloor[f].status]);
            $(F).find('select.units').val(J.aFloor[f].unit);
            $(F).find('select.status').val(J.aFloor[f].status);
        }
    }
    catch (e) { }
}
function FloorFocus() { $(oFloor).find('input.txtGSales,input[name=txtGSales]').focus().select(); }
function CommaStrip(c) { if (c == undefined || c.length == 0) return ""; return parseFloat((c + '').replace(/,/g, '')); }
function CommaStripAZ(c) { if (c.substring(0, 1) == ',') c = c.substring(1, c.length); if (c.substring(c.length - 1, c.length) == ',') c = c.substring(0, c.length - 1); return c; }
function fFloors(iti) {
    var N = iti.split('|'), J = JSON[N[0]][N[2]], L = ListId(iti);
    oFloor = $(L).find('div.Floors');
    $(oFloor).find('span.close').mouseover(function() { $(this).css('color', '#900').css('background-color', '#fff'); $(oFloor).css('background-color', '#933').css('opacity', 0.8); }).mouseout(function() {
        $(this).css('color', '#fff').css('background-color', ''); $(oFloor).css('background-color', '').css('opacity', '');
    }).click(function() {
        ControlCloseAll(iti, null);
        $(oFloor).slideUp('slow').attr('name', '0');
        J.F = J.Forig; J.Sz = J.Szorig; J.S = J.Sorig; //J.Rn = J.Rnorig;
        cssStatus(J.ck, L, J);
        $(L).find('input.sz').val(htmlSizeP(J, 1));
        $(L).find('.Size').html(htmlSizeP(J, 0) + htmlTenure(J) + J.A.replace('^', '<br>').replace(/,/g, '<br>'));
        showFloorsButton($(L).find('.Size')); //if (J.block == 0)
        EditSizeRw(J.Sz.split('|'));
        if (J.Rn != J.Rnorig) {//psf psm
            J.Rn = J.Rnorig;
            $(L).find('td.rn,td.cn').find('input').val(listRent(J.Rn, J.It));
            htmlResize(iti);
        }

    });
    $(oFloor).find('span.Save').mouseover(function() {
        $(this).css('background-color', '#cfc').css('color', '#393'); $(oFloor).css('background-color', '#393').css('opacity', 0.9);
    }).mouseout(function() {
        $(this).css('background-color', '').css('color', ''); $(oFloor).css('background-color', '').css('opacity', '');
    }).click(function() {
        J.F = retFloors(iti, 0);
        J.Forig = J.F; J.Szorig = J.Sz; J.Sorig = J.S; J.Rnorig = J.Rn;
        htmlResize(iti);
        if ($(this).html().length > 5) ControlCloseAll(iti, null);
        else {
            for (var f = 0; f < J.aFloor.length; f++)
                $(oFloor).find('tr[name=floor' + f + ']').find('input,select').css('background', Status[J.aFloor[f].status]);
        }
        jsCriteria = { Update: 1, floors: J.F, status: J.S, SizeUnit: J.Sz.split('|')[0], SizeMin: J.Sz.split('|')[1], SizeMax: J.Sz.split('|')[2] };
        StatusChangeOne(iti, J.S);
        EditSizeRw(J.Sz.split('|'));
        var T = J.Rn.split('|');
        jsCriteria.tenure = T[0]; jsCriteria.rentPeriod = T[1]; jsCriteria.rentMin = T[2];
        if (J.I > 0) DatabaseUpdate(J);
    });
    $(oFloor).find('span.FtM').mouseover(function() { $(this).css('background-color', '#cfc').css('color', '#393'); }).mouseout(function() { $(this).css('background-color', '').css('color', ''); }
			  ).click(function() { fFloorsClick(iti); try { EditSizeRw(XY.J.Sz.split('|')); } catch (e) { } });
    if (J.tp == "8") return;

    $(oFloor).find('input').attr('style', 'text-align:right;width:65pt;border:1px solid #999;margin-top:1px'
				).focus(function() { $(this).css('background-color', 'yellow').select(); }
				).blur(function() { $(this).css('background-color', '#' + $(this).attr('name')); }
				).each(function() { if ($(this).attr('name').length > 2) $(this).css('background', '#' + $(this).attr('name')); }
				).change(function() { if (!IsNumeric($(this).val())) { alert('value must be numeric!!'); $(this).val('0').focus(); } });

    $(oFloor).find('input').slice(0, 10).change(function() {
        if (IsNumeric($(this).val())) {
            var u = " sf", t = 0, ta = 0;
            if (J.Sz.substring(0, 1) == "1") u = " sm";
            if (J.tp == 2) {
                t = 0, ta = 0;
                $(oFloor).find('input').slice(0, 10).each(function() {
                    if (IsNumeric(CommaStrip($(this).val())))
                        if ($(this).attr('class').indexOf('Sales') > -1)
                        t += parseFloat(CommaStrip($(this).val()));
                    else ta += parseFloat(CommaStrip($(this).val()));
                });
                $(oFloor).find('input.txtTotalSales').val(addCommas(t));
                $(oFloor).find('input.txtTotalAncillary').val(addCommas(ta));
                $(oFloor).find('input.txtTotMin,input.txtTotMax').val(addCommas(t + ta)); // + ta
            }
            else {
                t = 0, ta = 0;
                $(oFloor).find('input').slice(0, 10).each(function() {
                    if (IsNumeric(CommaStrip($(this).val())))
                        if ($(this).attr('class').indexOf('Ancillary') == -1)
                        t += parseFloat(CommaStrip($(this).val()));
                    else ta += parseFloat(CommaStrip($(this).val()));
                });
                $(oFloor).find('input.txtTotalProduction').val(addCommas(t));
                $(oFloor).find('input.txtTotalOfficeArea').val(addCommas(ta));
                $(oFloor).find('input.txtTotMin,input.txtTotMax').val(addCommas(t + ta)); // + ta
            }
            $(L).find('td.sz').find('input').val(addCommas(t + ta) + u);
            fFloorsRebox(iti, t + ta, t + ta);
        }
    })
    $(oFloor).find('input.txtTotMin,input.txtTotMax').change(function() {
        var mn = CommaStrip($(this).parent().parent().find('input.txtTotMin').val());
        var mx = CommaStrip($(this).parent().parent().find('input.txtTotMax').val());
        $(this).val(addCommas(CommaStrip($(this).val())));
        fFloorsRebox(iti, Math.round(mn * 100) / 100, Math.round(mx * 100) / 100);
    });
}
function EditSizeRw(l) {
    $('#SizeMin').val(addCommas(l[1])); $('#SizeMax').val(addCommas(l[2]));
    $('#Size').find('input[name=unit][name2=' + l[0] + ']').attr('checked', true);
    if (l[1] != '0' || l[2] != '0') $('#Size').find('div.Error').css('display', 'none');
}
function EditSizeBox() {
    $(XY.L).find('div.block2').find('.Size').html(htmlSizeP(XY.J, 0) + htmlTenure(XY.J) + XY.J.A.replace('^', '<br>').replace(/,/g, '<br>'));
    if (XY.It == 'p' && (XY.J.tp == '8' || XY.J.tp == '2' || XY.J.tp == '4')) {
        if ($(XY.L).find('input.sz').length > 0)
            $(XY.L).find('input.sz').val(htmlSizeP(XY.J, 1)).css('color', '#111');
        else {
            $(XY.L).find('td.sz').html(ListSizeP(XY.J));
            fListSize($(XY.L), XY.It + '|' + XY.J.tp + '|' + XY.J.I, XY.J)
        }
        showFloorsButton($(XY.L).find('.Size'));
    } else $(XY.L).find('td.sz').html(htmlSizeP(XY.J, 1));
    if (XY.J.Cn.length > 0) $(XY.L).find('div.block2').find('div.cln').html('Client: <b>' + XY.J.Cn + '</b>');
}
function htmlResize(iti) {
    var N = iti.split('|'); XY.J = JSON[N[0]][N[2]], XY.L = ListId(iti);
    EditSizeBox();
}
function fFloorsClick(iti) {
    var N = iti.split('|'), J = JSON[N[0]][N[2]], L = ListId(iti);
    if ($(oFloor).find('span.FloorUnit').slice(0, 1).html() == 'sqft') {
        $(oFloor).find('span.FloorUnit').html('sqm');
        $(oFloor).find('span.FloorUnit2').html('m');
        J.Sz = '1' + J.Sz.substring(1, J.Sz.length);
    }
    else {
        $(oFloor).find('span.FloorUnit').html('sqft');
        $(oFloor).find('span.FloorUnit2').html('ft');
        J.Sz = '2' + J.Sz.substring(1, J.Sz.length);
    }
    fFloorsRebox(iti, J.Sz.split('|')[1], J.Sz.split('|')[2]);
    $(L).find('td.sz').find('input').val(htmlSizeP(J, 1)); //sm
}
function fFloorsRebox(iti, mn, mx) {
    var N = iti.split('|'), J = JSON[N[0]][N[2]], L = ListId(iti);
    var aSz = J.Sz.split('|');
    J.Sz = aSz[0] + "|" + mn + "|" + mx + "|" + aSz[3] + "|" + aSz[4] + "|" + aSz[5];
    J.F = retFloors(iti, 1);
    $(L).find('input.sz').val(htmlSizeP(J, 1));
    $(L).find('.Size').html(htmlSizeP(J, 0) + htmlTenure(J) + J.A.replace('^', '<br>').replace(/,/g, '<br>'));
    if (J.block == 0) showFloorsButton($(L).find('.Size'));
    $('#SizeMin').val(addCommas(mn)); $('#SizeMax').val(addCommas(mx));
}
function FloorsRecalc(iti) {
    var N = iti.split('|'), J = JSON[N[0]][N[2]], L = ListId(iti), cSum = 0, cMin = 0, inside = false, sf2sm = 1, F = $(oFloor), v;
    for (var f = 0; f < J.aFloor.length; f++) {
        if (J.aFloor[f].name != undefined && J.aFloor[f].name.length > 0)
            if (J.aFloor[f].status == 'A') {//|| J.aFloor[f].status == 'N'
            sf2sm = 1;
            if (J.aFloor[f].unit == "101") sf2sm = 1 / 0.09290304;
            if (IsNumeric(J.aFloor[f].size)) {
                v = CommaStrip(J.aFloor[f].size) * sf2sm
                cSum += v;
                if (!inside || cMin > v) cMin = v;
                inside = true;
            }
        }
    }
    var Sz = J.Sz.split('|');
    sf2sm = 1;
    if (Sz[0] == "1") sf2sm = 0.09290304;
    cMin *= sf2sm; cSum *= sf2sm;
    J.Sz = F.find('div.mnmx').find('select').val() + "|" + cMin + "|" + cSum + "|" + Sz[3] + "|" + Sz[4] + "|" + Sz[5];
    F.find('.mnoffice').val(addCommas(cMin));
    F.find('.mxoffice').val(addCommas(cSum));
    J.F = retFloors(iti, 1);
    htmlResize(iti);
}
function fOfficeStart(iti) {
    var N = iti.split('|'), L = ListId(iti), J = JSON[N[0]][N[2]], B = BarId(N[0] + '|' + N[1]);
    var F = $(oFloor), aFs = J.F.split('|');
    F.find('input').focus(function() { $(this).select(); });
    F.find('.mnoffice').val(addCommas(J.Sz.split('|')[1])
        ).change(function() {
            var Sz = J.Sz.split('|');
            J.Sz = Sz[0] + "|" + parseFloat($(this).val().replace(',', '')) + "|" + Sz[2] + "|" + Sz[3] + "|" + Sz[4] + "|" + Sz[5];
            htmlResize(iti);
        });
    F.find('.mxoffice').val(addCommas(J.Sz.split('|')[2])
        ).change(function() {
            var Sz = J.Sz.split('|');
            J.Sz = Sz[0] + "|" + Sz[1] + "|" + parseFloat($(this).val().replace(',', '')) + "|" + Sz[3] + "|" + Sz[4] + "|" + Sz[5];
            htmlResize(iti);
        });
    F.find('div.mnmx').find('select').val(J.Sz.split('|')[0]).change(function() {
        J.Sz = $(this).val() + J.Sz.substring(1, J.Sz.length);
        htmlResize(iti);
        EditSizeRw(J.Sz.split('|'));
    });
    XY.flPeriod = J.Rn.split('|')[1];
    $(F).find('span.floorUnits').find('select').change(function() {
        var units = 'psf', sf = 1, csf = 1, was = $(this).attr('name'), v = $(this).val(), newRent;
        var T = J.Rn.split('|');
        newRent = CommaStrip(T[2]);
        switch (v) {
            case "-2": units = 'psm';
                if (was == "-1") sf = 1 / 0.09290304; break;
            case "1": units = 'pa';
                if (was == "2") sf = 12; else if (was == "4") sf = 52; break;
            case "2": units = 'pm';
                if (was == "1") sf = 1 / 12; else if (was == "4") sf = 52 / 12; break;
            case "4": units = 'pw';
                if (was == "1") sf = 1 / 52; else if (was == "2") sf = 12 / 52; break;
            default: if (was == "-2") sf = 0.09290304; //101
        }
        if (was != v) {
            if (IsNumeric(newRent)) newRent = Math.round(parseFloat(newRent) * sf * 100) / 100;
            J.Rn = T[0] + "|" + v + "|" + newRent + "|" + T[3] + "|" + T[4] + "|" + T[5] + "|" + T[6] + "|" + T[7] + "|" + T[8] + "|" + T[9] + "|" + T[10] + "|" + T[11] + "|" + T[12];
            $(L).find('td.rn,td.cn').find('input').val(listRent(J.Rn, J.It));
            htmlResize(iti);
        }
        $(this).attr('name', v);
        var f = $(oFloor).find('div.FloorsOffice');
        $(f).find('tr').find('span.unit').html(units);
        try {
            for (var j = 0; j < J.aFloor.length; j++) {
                J.aFloor[j].rent = Math.round(parseFloat(J.aFloor[j].rent) * sf * 100) / 100;
                $(f).find('tr[name=floor' + j + ']').find('input.f3').val(addCommas(J.aFloor[j].rent));
                J.aFloor[j].rate = Math.round(parseFloat(J.aFloor[j].rate) * sf * 100) / 100;
                $(f).find('tr[name=floor' + j + ']').find('input.f4').val(addCommas(J.aFloor[j].rate));
                J.aFloor[j].charge = Math.round(parseFloat(J.aFloor[j].charge) * sf * 100) / 100;
                $(f).find('tr[name=floor' + j + ']').find('input.f5').val(addCommas(J.aFloor[j].charge));
            }
        } catch (e) { }
        try { $('#rentperiod').val(v).trigger('change'); } catch (e0) { }
    }).val(XY.flPeriod).attr('name', XY.flPeriod).trigger('change');      //
    F = $(F).find('div.FloorsOffice').find('tr');
    FloorsCellStyle(F);
}
function FloorsCellStyle(F) {
    $(F).find('td').css('text-align', 'center').css('border-right', '1px dotted #339');
    $(F).find('input.f1').css('width', '70px').focus(function() { $(this).select(); });
    $(F).find('input.f3,input.f4,input.f5').css('float', 'left');
    $(F).find('input.f2').css('width', '45px');
    $(F).find('select.units').css('width', '50px');
    $(F).find('select.status').css('width', '95px').css('display', 'inline-block');
    $(F).find('input.f2,input.f3,input.f4,input.f5'
        ).focus(function() { $(this).select(); }
        ).blur(function() {
            if (!IsNumeric($(this).val())) { alert('Must be numeric value!'); $(this).val('0').select(); };
        });
}
var endTree, AgentsSurname2 = new Array(), letters, letters2, AgentOtherClicked = { N: 0, C: 0, D: 0 }, treeHash;
function AgentsSurnames(ItTpI) {
    var N = ItTpI.split('|'), L = ListId(ItTpI), J = JSON[N[0]][N[2]], B = BarId(N[0] + '|' + N[1]);
    //$(L).find('div.Agent').find('div.List').slideUp('fast');
    var a, h = '', hA = "<div title='click to add agent' name=NIDxCID class=SurnameII><span style='width:130px'>&nbsp;xXX</span><span style='width:130px'>xYY</span><span>xCC</span></div>", ii = 0;
    try {
        for (var ai = 0; ai < AgentsSurname2[letters2].length; ai++) {
            a = AgentsSurname2[letters2][ai].R.split(',');
            if (a[0].substring(0, letters.length).toLowerCase() == letters) {
                ii++;
                h += hA.replace('II', (ii % 2)).replace('NID', a[3]).replace('CID', a[4]
                      ).replace('xXX', Fading(a[0], 15, 7, '')).replace('xYY', Fading(a[1], 15, 7, '')).replace('xCC', Fading(a[2], 22, 7, ''));
            }
        }
    } catch (e) { }
    if (h.length == 0) h = '<div class=Surname1 title="click to close" style="padding:5px;background:#700;color:#fee;text-align:center;font-size:1em">No agents with prefix \'' + letters + '\', try other letter(s)</div>';
    $(L).find('div.Agent').find('div.List').html('<span title="click to close" class=close>x</span>' + h + '<div style="clear:both">&nbsp;</div>').slideDown('fast').find('div'
        ).mouseover(function() { $(this).css('background-color', '#0F2A86'); }
        ).mouseout(function() { $(this).css('background-color', ''); }
        ).click(function() {
            $(L).find('div.Agent').find('div.List').slideUp('fast');
            try {
                AgentOtherClicked.N = $(this).attr('name').split('x')[0];
                AgentOtherClicked.D = $(this).attr('name').split('x')[1];
                J.N.split('|')[1] += AgentOtherClicked.D + ',';
                var NDBC = J.N.split('|');
                J.N = NDBC[0] + AgentOtherClicked.N + ",|" + NDBC[1] + AgentOtherClicked.D + ",|" + NDBC[2] + "|" + NDBC[3];
                $(L).find('div.Agent').html(waitSometime('Adding a new Agent...'));
                setTimeout("Agents('" + ItTpI + "',1)", 500);
            } catch (e) { }
        }).find('font').each(function() { $(this).css('opacity', $(this).attr('name')) }); ;
    $(L).find('div.Agent').find('div.List').find('span.close'
        ).mouseover(function() { $(L).find('div.Agent').find('div.List').css('background-color', '#900').find('div').css('opacity', 0.5); }
        ).mouseout(function() { $(L).find('div.Agent').find('div.List').css('background-color', '').find('div').css('opacity', ''); }
        ).click(function() { $(L).find('div.Agent').find('div.List').slideUp('fast'); })
}
function Agents(iti, typ) {
    var N = iti.split('|'), L = ListId(iti), J = JSON[N[0]][N[2]], B = BarId(N[0] + '|' + N[1]);
    Tree = '';
    treeHash = J.N.split('|')[1];
    if (TreeC[treeHash] != undefined) fAgents(iti, typ);
    else {
        Criteria = { list: 3, Nid: treeHash, Type: typ };
        $.post(urlLoad, Criteria, function(output) {
            TreeC[treeHash] = eval(output);
            fAgents(iti, typ);
            if (AgentOtherClicked.N > 0) {
                OwnersRewrite(iti);
                AgentOtherClicked = { N: 0, C: 0 };
            }
        });
    }
}

function fAgents(ItTpI, typ) {
    try {
        var N = ItTpI.split('|'), L = ListId(ItTpI), J = JSON[N[0]][N[2]], B = BarId(N[0] + '|' + N[1]);
    }
    catch (e) { }
    endTree = 1;
    if (TreeC[treeHash].length > 2) endTree = TreeC[treeHash].length - 1;  //2 +1;//if (!$.browser.msie) endTree++;
    makeTree(0, endTree, 0, typ);
    var intro = '<span class=tit>Click name to add/delete their association</span><span class=Add title="click to add other Agency\'s Agent">Add Agent at another Agency</span>'
                    + '<div class=Add>Type in the lastname/surname (3 letters at least)&nbsp;&nbsp;'
                    + '<input onfocus="this.select()" title="enter first 2 letters\nof Agent\'s Agency \nyou want to add" value="of the Agent" />'
                    + '</div><div class=List></div><div style="clear:both"></div>';
    if (typ == 101) intro = "My Admins (in bold)";
    else if (typ == 102) {
        intro = "My Agents (in bold)";
        $('#homedep').find('a[name3=change]').css('margin-top', '-1px').css('margin-right', '3px').html('close');
    }
    else if (typ == 103 || typ == 104 || typ == 107) intro = "Company\'s Branches, Department, and Agents...";
    else if (typ == 105) intro = "Select public / branch email list";
    else if (typ == 106) intro = "";
    var tre;
    $(L).find('div.Agent').html(intro + Tree + '<div style="clear:both"></div>').slideDown('fast').find('span.ng'
                 ).mouseover(function() { if (TreeC[treeHash][$(this).attr('name')].IS == 1) return; $(this).css('font-weight', 'bold').css('color', '#005'); }
                 ).mouseout(function() { if (TreeC[treeHash][$(this).attr('name')].IS == 1) return; $(this).css('font-weight', '').css('color', ''); }
                ).click(function() {
                    tre = TreeC[treeHash][$(this).attr('name')]; //var id = $(this).attr('name');
                    tre.IS = (tre.IS + 1) % 2;
                    $(this).css('font-weight', '').css('color', '');
                    if (tre.IS == 1)
                        $(this).css('font-weight', 'bold').css('color', '#005');
                    if (typ == 101 || typ == 102) {//My Department
                        var pNid = TreeC[treeHash][$(this).attr('name')].R.split('|')[5], pNid2 = pNid; //XY.Agents.split('|')[$(this).attr('name')].split('~')[0];
                        DepartmentReCount(N[2], tre.IS == 1 ? 1 : -1, typ, pNid);
                        DepartmentReCount(pNid, tre.IS == 1 ? 1 : -1, (typ == 101 ? 102 : 101), N[2]);
                        if (XY.AgAd == 1) pNid2 = N[2];
                        else pNid = N[2];
                        $.post(urlLoad, { list: 3, Nid: pNid, Did: pNid2, Type: (tre.IS == 1 ? 32 : 33) }, function(d) {
                            if (XY.DepId == '#homedep') {
                                $('#homedep').html('');
                                XY.Dep['#homedep'] = '';
                                Department('#homedep');
                            }
                        });
                    }
                    else if (typ == 103 || typ == 104) {
                        SwitchUser2(TreeC[treeHash][$(this).attr('name')].R.split('|')[5]);
                    }
                    else if (typ == 105) {
                    }
                    else if (typ == 106 || typ == 107) {
                    }
                    else OwnersRewrite(ItTpI);
                }).each(function() {
                    var id = $(this).attr('name');
                    tre = TreeC[treeHash][id];
                    try {
                        TreeC[treeHash][id].IS = 0; TreeC[treeHash][id].OPEN = 0;
                        $(this).attr('title', tre.R.split('|')[6]).html(tre.R.split('|')[3] + ', ' + tre.R.split('|')[4]);
                        if (typ == 101 || typ == 102 || typ == 107) {//My Department
                            if (tre.R.split('|')[7] == _gDid) {
                                tre.OPEN = 2;
                                TreeOpenD(this);
                            }
                        }
                        else if (typ == 103) {
                            $(this).css('width', '250px').html(tre.R.split('|')[3] + ', ' + tre.R.split('|')[4]
                                + '<span class=ng2 style="color:#aaf">' + tre.R.split('|')[5] + '</span>'
                            );
                            if (id == 0) {
                                tre.OPEN = 2;
                                TreeOpenD(this);
                            }
                        }
                        if (J.N.split('|')[0].indexOf(tre.R.split('|')[5]) > -1) {
                            tre.IS = 1; tre.OPEN = 2;
                            $(this).css('font-weight', 'bold').css('color', '#005');
                            TreeOpenD(this);
                        }
                    } catch (e) { }
                });
                $(L).find('div.Agent').find('span.ch').click(function() {
                    if ($(this).attr('name') != '1') {
                        $(this).parent().find('span.ch').attr('name', '1').css('background', XY.check);
                    }
                    else {
                        $(this).parent().find('span.ch').attr('name', '0').css('background', XY.uncheck);
                    }
                });
                $(L).find('div.Agent').find('div.Add').find('input').keyup(function(evt) {
                    letters = $(this).val().toLowerCase();
                    letters2 = letters.substring(0, 3);
                    if (letters.length > 2 && letters != 'of the Agent') {
                        $(L).find('div.Agent').find('div.List').html(waitSometime("Loading agents whose surnames starts with '" + letters + "'")).slideDown('fast');
                        if (AgentsSurname2[letters2] == undefined) {
                            Criteria = { list: 3, Cid: letters2, Type: 3 };
                            $.post(urlLoad, Criteria, function(output) {
                                AgentsSurname2[letters2] = eval(output);
                                AgentsSurnames(ItTpI);
                            });
                        }
                        else AgentsSurnames(ItTpI);
                    }
                });
                $(L).find('div.Agent').find('span.Add'
                ).mouseover(function() { $(this).css('opacity', 0.5); }
                ).mouseout(function() { $(this).css('opacity', ''); }
                ).click(function() {
                    if ($(this).attr('name') != '1') {
                        $(this).attr('name', '1').css('background-color', '#0F2A86').css('color', '#eef');
                        $(L).find('div.Add').css('display','block');
                        setTimeout(function() {
                        $(L).find('div.Add').parent().find('input').val('of the Agent').trigger('focus');//.focus();
                        }, 200);
                    }
                    else {
                        $(this).attr('name', '0').css('background-color', '').css('color', '');
                        $(L).find('div.Add').slideUp('fast');
                    }
                }); 

    $(L).find('div.Agent').find('ul').find('span.ng:last').css('background', "url('http://www.each.co.uk/images/ct/joinbottom.gif') no-repeat");
    $(L).find('div.Agent').find('span.sp0,span.sp1,span.sp2'
        ).mouseover(function() { $(this).css('opacity', 0.5).css('backgrond-color', '#fff'); }
        ).mouseout(function() { $(this).css('opacity', '').css('backgrond-color', ''); }
        ).click(function() {
            if ($(this).attr('name') != '1')
                $(this).css('background', "url('http://www.each.co.uk/images/ct/minus.gif') no-repeat").attr('name', '1').parent().find('ul').slice(0, 1).slideDown('fast'); //[name=1]
            else
                $(this).css('background', "url('http://www.each.co.uk/images/ct/plus.gif') no-repeat").attr('name', '0').parent().find('ul').slice(0, 1).slideUp('fast'); //[name=0]        
        }
        );
    $(L).find('div.Agent').find('span.sp0').trigger('click');
    offsetY(L);
}
function TreeOpenD(o) {
    $(o).parent().parent().parent().parent().slideDown('fast').parent(
                                        ).find('span[class!=ch]').slice(0, 1).attr('name', '1').css('background', "url('http://www.each.co.uk/images/ct/minus.gif') no-repeat");
    $(o).parent().parent().slideDown('fast').parent(
                                        ).find('span[class!=ch]').slice(0, 1).attr('name', '1').css('background', "url('http://www.each.co.uk/images/ct/minus.gif') no-repeat");

}
function CommaFirst(s) { return s.length == 0 ? ',' : ''; }
function OwnersRewrite(ItTpI) {
    var N = ItTpI.split('|'), L = ListId(ItTpI), J = JSON[N[0]][N[2]], B = BarId(N[0] + '|' + N[1]);
    var NDBC = new Array("", "", "", ""), ndbc;
    try {
        J.O = '';
        for (var y = 0; y < TreeC[treeHash].length; y++) {
            if (TreeC[treeHash][y].IS == 1) {
                ndbc = TreeC[treeHash][y].R.split('|');
                if (NDBC[0].indexOf(',' + ndbc[5] + ',') == -1) NDBC[0] += CommaFirst(NDBC[0]) + ndbc[5] + ',';
                if (NDBC[1].indexOf(',' + ndbc[7] + ',') == -1) NDBC[1] += CommaFirst(NDBC[1]) + ndbc[7] + ',';
                if (NDBC[2].indexOf(',' + ndbc[8] + ',') == -1
                    || NDBC[3].indexOf(',' + ndbc[9] + ',') == -1) {//new branch... or new company...
                    NDBC[2] += CommaFirst(NDBC[2]) + ndbc[8] + ',';
                    J.O += ndbc[0] + '|' + ndbc[10] + '|' + ndbc[6] + '|' + ndbc[4] + '|' + ndbc[3] + '|' + ndbc[11] + '|' + ndbc[12] + '|*';
                }
                else {
                    J.O = J.O.substring(0, J.O.length - 1);                    //ndbc[9] + '|' + ndbc[10] + '|' +
                    J.O += ndbc[6] + '|' + ndbc[4] + '|' + ndbc[3] + '|' + ndbc[11] + '|' + ndbc[12] + '|*';
                    //same branch, negotiator must be included...
                }
                if (NDBC[3].indexOf(',' + ndbc[9] + ',') == -1) NDBC[3] += CommaFirst(NDBC[3]) + ndbc[9] + ',';
            }
        }
    } catch (e) { }
    J.N = NDBC[0] + '|' + NDBC[1] + '|' + NDBC[2] + '|' + NDBC[3];
    $(L).find('div.block2').find('.Owner').html(htmlOwners(J, 0)).find('font').each(function() { $(this).css('opacity', $(this).attr('name')) });
    jsCriteria = { Update: 1 };
    jsCriteria.owners = J.O;
    jsCriteria.Dealswith = NDBC[0];
    jsCriteria.DIDs = NDBC[1]; jsCriteria.BIDs = NDBC[2]; jsCriteria.CIDs = NDBC[3];
    if (J.I > 0) DatabaseUpdate(J);
}
function retEmptyHtml(s, r, n) {
    if (s == undefined) return '';
    if (s.length > 0) return s;
    return 'xxxxxxxxxx'.replace(/x/g, r).substring(0, n * (r.length));
}

var Tree = '', DEPTH = 3;
function makeTree(start, end, depth, typ) {
    var v;
    Tree += "<ul name=0 class=ulp" + depth + ">";
    var interval = 0, items = '';
    if (depth <= DEPTH)
        while (start < end) {
        interval++;
        var dar = TreeC[treeHash][start].R.split('|');
        v = dar[depth];
        if (depth == DEPTH) items += '<li><span class=ch0></span><span name=' + start + ' class=ng></span></li>';
        else if (start == end - 1 || v != TreeC[treeHash][start + 1].R.split('|')[depth]) {
            if (typ == 105) {
                if (depth > 1)
                    Tree += '<li class=li' + depth + '><span depth=' + depth + ' name2=' + v + ' class=ch>&nbsp;</span><span class=sp' + depth + '>' + v + '</span>';
                else Tree += '<li class=li' + depth + '><span depth=' + depth + ' name2=' + v + ' class=ch>&nbsp;</span><span class=sp' + depth + '>'
                + eval('jsRgs' + (depth == 0 ? '' : '3') + '.v' + v)
                + '</span>';
            }
            else if (typ == 103 && depth == 1) {//switch user...
                Tree += '<li class=li' + depth + ' style="width1:400px"><span class=ch></span><span class=sp' + depth + '>'
                    + v + ' - ' + dar[8] + '</span>'
                    + '<span class=ng2>' + retEmptyHtml(dar[17], '&nbsp;', 2) + '</span>'
                    + '<span class=ng2>' + retEmptyHtml(dar[15], '&nbsp;', 2) + '</span>'
                    + '<span class=ng2>' + retEmptyHtml(dar[14], '&nbsp;', 2) + '</span>'
                    + '<a class=nb>' + retEmptyHtml(dar[13], '&nbsp;', 2) + '</a>'
                    ;
            }
            else if (typ == 103 && depth == 0) {//switch user...
                Tree += '<li class=li' + depth + '><span class=ch></span><span class=sp' + depth + '>' + v + '</span>'
                     + '<a class=ab>AB ' + dar[18] + '</a>'
                ;
            }
            else Tree += '<li class=li' + depth + '><span class=ch></span><span class=sp' + depth + '>' + v + '</span>';
            makeTree(start - interval + 1, start + 1, depth + 1, typ);
            Tree += '</li>';
            interval = 0;
            items = '';
        }
        start++;
    }
    if (depth == DEPTH && end == endTree) {
        if (typ == 105) items += '<li><span class=ch0></span><span name=' + start + ' class=ng></span></li>';
        else items += '<li><span class=ch></span><span name=' + start + ' class=ng></span></li>';
    }
    Tree += items + "</ul>";
}

function Calendar(o, all, M) {
    offsetY($(o));    //if (XY.inCalendar[$(o).attr('id')])return;
    var p = $(o).parent().find('span').slice(0, 1), alldate = '';
    if ($(p).html().length > 0) return;
    var YearsTit = '<span class=Jan>Jan</span><span class=Feb>Feb</span><span class=Mar>Mar</span><span class=Apr>Apr</span><span class=May>May</span><span class=Jun>Jun</span><span class=Jul>Jul</span><span class=Aug>Aug</span><span class=Sep>Sep</span><span class=Oct>Oct</span><span class=Nov>Nov</span><span class=Dec>Dec</span>';
    $(p).attr('style', 'position:absolute;border:1px solid #F90;margin-left:-385px;margin-top:15px;width:425px;background:#FFC;z-index:10002');
    if (all == 1) alldate = '<span style="float:right;margin-right:20px"><input id="allDates" style="width:14px;border:0px;cursor:pointer;background:#dda;margin-left:5px" type="checkbox" />update all dates</span>';
    XY.hCalendar = '<div class="CalMonths" style="width:420px"><b>&nbsp;Select year and month available</b><span class=close>x</span>' + alldate;
    XY.hCalendar += '<span class=tit style="display:block;width:420px;border-bottom:1px dotted #F90;font-weight:bold"><span class=mm style="width:35px;color:#d60"></span><div class="CalMonthsTit">' + YearsTit + '</div></span>';
    for (var m = 0; m < M; m++)
        XY.hCalendar += '<span class=' + (11 + m) + '><span class=mm style="width:35px;color:#d60">' + (2011 + m) + '</span><div class="CalMonths2" >' + YearsTit + '</div></span>';
    XY.hCalendar += '</div>';
    XY.hCalendarName = $(o).attr('name');
    $(p).html(XY.hCalendar).find('div.CalMonths2').find('span'
				).css('color', '#eed').mouseover(function() {
				    if ($(this).attr('name') == '1') return; $(this).css('background-color', '#330');
				    $(p).find('div.CalMonthsTit').find('span.' + $(this).html()).css('background-color', '#cfc');
				    $(p).find('div.CalMonths2').find('span.' + $(this).html()).css('border-left', '1px solid #696').css('border-right', '1px solid #696');
				    $(this).parent().parent().find('span').slice(0, 1).css('background-color', '#cfc');
				    $(this).parent().parent().find('span').slice(1, 100).css('border-bottom', '1px solid #696').css('border-top', '1px solid #696');
				}
				).mouseout(function() {
				    if ($(this).attr('name') == '1') return; $(this).css('background-color', '');
				    $(p).find('div.CalMonthsTit').find('span.' + $(this).html()).css('background-color', '');
				    $(p).find('div.CalMonths2').find('span.' + $(this).html()).css('border', '0px');
				    $(this).parent().parent().find('span').slice(0, 1).css('background-color', '');
				    $(this).parent().parent().find('span').slice(1, 100).css('border', '0px');
				}
				).click(function() {
				    $(p).find('div.CalMonths2').find('span').attr('name', '0').css('background-color', '');
				    var v = $(this).html() + '.', yy = $(this).parent().parent().find('span.mm').html();

				    if (XY.hCalendarName == "mmyyyy") {
				        v += yy;
				    }
				    else {
				        v += yy.substring(2, 4);
				        if ($('#allDates').attr('checked')) {
				            $('.FloorsOffice').find('input.fdate').val(v);
				            $(p).css('display', 'none').html('');
				            return;
				        }				        
				    }
				    if ($(o).val() == v) {//XY.inCalendar[$(o).attr('id')] == v) {
				        if (XY.hCalendarName == "mmyyyy")
				            $(o).val("mm.yyyy");
				        else $(o).val("");
				        XY.inCalendar[$(o).attr('id')] = "mm.yyyy";
				    }
				    else {
				        $(o).val(v);
				        XY.inCalendar[$(o).attr('id')] = v;
				    }
				    $(p).css('display', 'none').html('');
				});
    if ($(o).val().length > 0) {
        var yy = $(o).val().split('.')[1];
        if (XY.hCalendarName == "mmyyyy") yy = yy.substring(2, 4);
        $(p).find('span.' + yy).find('div.CalMonths2').find('span.' + $(o).val().split('.')[0]).css('background-color', '#330').attr('name', '1');

    }
    $(p).find('span.close').mouseover(function() { $(this).css('color', '#900').css('background-color', '#fff'); $(this).parent().parent().css('opacity', 0.8); }
									 ).mouseout(function() { $(this).css('color', '#fff').css('background-color', ''); $(this).parent().parent().css('opacity', ''); }
									 ).click(function() {
									     $(p).css('display', 'none').html('');
									     XY.inCalendar[$(o).attr('id')] = false;
									 });
    if (XY.hCalendarName == "mmyyyy") $('#allDates').attr('disabled', true);
    XY.inCalendar[$(o).attr('id')] = $(o).val().split('.')[0] + "." + $(o).val().split('.')[1]; //.substring(2, 4); //true;
}
function trim(s) { if (s == undefined) return ""; return s.replace(/^\s*/, "").replace(/\s*$/, ""); }
function rMin(ar) { var min = 0, inside = false; for (var i = 1; i < ar.length; i++) if (IsNumeric(ar[i])) { if (!inside || parseFloat(ar[i]) < min) { min = parseFloat(ar[i]); inside = true; } } return min; }
function rMax(ar) { var max = 0, inside = false; for (var i = 1; i < ar.length; i++) if (IsNumeric(ar[i])) { if (!inside || parseFloat(ar[i]) > max) { max = parseFloat(ar[i]); inside = true; } } return max; }
Array.prototype.swap = function(a, b) { var tmp = this[a]; this[a] = this[b]; this[b] = tmp; }
function partition(array, begin, end, pivot) {
    var piv = array[pivot].number;
    array.swap(pivot, end - 1);
    var store = begin, ix;
    for (ix = begin; ix < end - 1; ++ix) {
        if (array[ix].number <= piv) {
            array.swap(store, ix);
            ++store;
        }
    }
    array.swap(end - 1, store);
    return store;
}
function qsort(array, begin, end) {
    if (end - 1 > begin) {
        var pivot = begin + Math.floor(Math.random() * (end - begin));
        pivot = partition(array, begin, end, pivot);
        qsort(array, begin, pivot);
        qsort(array, pivot + 1, end);
    }
}
function quick_sort(array) { qsort(array, 0, array.length); }
var f = '', foundcnt = 0;
function FindS(f) { return f.replace(new RegExp(XY.searched, "gi"), '<font class=found>' + XY.searched.toUpperCase() + '</font>'); }
//StreetNumber|postcode|street|CentreEstate|townCity|suburbLocality|buildingNumber|building|CTIDs
function FindNone(J) {
    var s = J.Lc + J.D + J.A + J.O + J.F + J.Rn + J.Sz + J.I + XY.StatText[J.S] + htmPSTIDs(J) + isCommPriv(J); //.Cm;
    if (J.H > 0 && XY.view) {
        var l = J.Lc.split('|');
        if (NoAll(J.H)) s = l[1] + l[4] + l[5] + J.D + J.O + J.F + J.Rn + J.Sz + J.I + XY.StatText[J.S] + htmPSTIDs(J) + isCommPriv(J); //J.Cm;
        else {//
            if (NoCompanyPDF(J.H)) s = J.D + J.O + J.F + J.Rn + J.Sz + J.I + XY.StatText[J.S] + htmPSTIDs(J) + isCommPriv(J); //J.Cm;
            if (retA(XY.It) == 'p') {
                if (NoStreet(J.H)) s = l[1] + l[4] + l[5] + J.D + J.A + J.O + J.F + J.Rn + J.Sz + J.I + XY.StatText[J.S] + htmPSTIDs(J) + isCommPriv(J); //J.Cm;
                else if (NoStreetNo(J.H)) s = l[1] + l[2] + l[3] + l[4] + l[5] + J.D + J.A + J.O + J.F + J.Rn + J.Sz + J.I + XY.StatText[J.S] + htmPSTIDs(J) + isCommPriv(J); //J.Cm;
                else s += J.lc;
            }
            else s += J.lc;
        }
    }
    return (s).toLowerCase().indexOf(XY.searched);
}
$('#aFound').mouseover(function() { $(this).css('background', '#ff0'); }).mouseout(function() { $(this).css('background', ''); }).click(function() { Find0(); })
function Find0() {
    $('#FindCnt').html('Searching...');
    XY.searched = trim($('#txFind').val()).toLowerCase();
    if (XY.searched.length == 0) {
        $('#head').find('span.itm[name2=2]').trigger('click').trigger('mouseout');
        for (var i = 0; i < JSON[XY.It].length; i++) {
            JSON[XY.It][i].found = 1;
            if (JSON[XY.It][i].marker != undefined) JSON[XY.It][i].marker.setMap(XY.Maps[It + JSON[XY.It][i].tp]);
        }
        setTimeout("Filter(" + IS + ")", 150);
    }
    else {
        $('#explain').html(waitSometime("Searching for keyword: " + $('#txFind').val())).slideDown('fast');
        $('#RESULT').css('display', 'none');
        setTimeout("Find()", 150);
    }
}
function Find() {
    foundcnt = 0;
    var L, J, Tps = '';
    try {
        for (var i = 0; i < JSON[XY.It].length; i++) {
            J = JSON[XY.It][i];
            J.found = (FindNone(J) == -1 ? 0 : 1);
            L = ListId(XY.It + '|' + J.tp + '|' + i);
            if (XY.Views[XY.It + '|' + J.tp] == "1") {
                try { if (J.marker != undefined) J.marker.setMap(null); } catch (e0) { }
            }
            else $(L).css('display', 'none');
            if (J.found > 0 && J.IS >= IS) {
                foundcnt++;
                if (XY.Views[XY.It + '|' + J.tp] == "1") {
                    try { if (J.marker != undefined) J.marker.setMap(XY.Maps[XY.It + J.tp]); } catch (e1) { }
                } else {
                    if (XY.It == 'p') {
                        $(L).css('display', 'block').find('td.pc').html(FindS(J.Lc.split('|')[1].split(' ')[0]));
                        $(L).find('td.tw').html(FindS(J.Lc.split('|')[4].substring(0, 15))); //
                        $(L).find('td.st').html(FindS(LsPLc(J, 0, 22))); //.substring(0, 22)
                    }
                    else {
                        $(L).css('display', 'block').find('td.st').html(FindS(htmlReqLoc(J.Lc.split('|')).substring(0, 25)));
                        $(L).find('td.tps').html(FindS(htmPSTIDs(J).substring(0, 18)));
                        $(L).find('td.cn').html(FindS(J.Cn.substring(0, 13)));
                    }
                    if (J.block == 1) htmlBlockSearch($(L).find('div.block2'), J);
                    if (J.block == 2) J.block = 0; //once opened to closed
                }
                if ((',' + Tps).indexOf(',' + XY.It + '|' + J.Crit + ',') == -1) Tps += XY.It + '|' + J.Crit + ',';
            }
        }
    } catch (e) { }
    $('#FindCnt').html(foundcnt + ' instructions found');
    $('#explain').html('').css('display', 'none');
    $('#RESULT').css('display', 'block').find('div.bar,div.sort').css('display', 'none');
    if (IsNumeric(XY.searched)) XY.searched = addCommas(XY.searched);
    var tps = Tps.split(',');
    for (i = 0; i < tps.length - 1; i++) {
        $('#RESULT').find('div.bar[name=' + tps[i] + ']').css('display', 'block');
        if (XY.Views[tps[i]] == "1") $('#map' + tps[i]).css('display', 'block'); //map
    }
}
function htmlBlockSearch(Bl, J) {//.css('display', 'none')
    $(Bl).find('div[name=tp]').find('div.tp1').html(FindS(htmPSTIDs(J)));
    $(Bl).find('div[name=tp]').find('div.tp2').html(FindS(J.I));
    $(Bl).find('div[name=tp]').find('div.tp3').html(FindS(XY.StatText[J.S]));
    $(Bl).find('.Size').html(FindS(htmlSizeP(J, 0) + htmlTenure(J) + J.A.replace('^', '<br>').replace(/,/g, '<br>')));
    if (!isReq(J)) {
        $(Bl).find('.Location').html(htmlLocSearched(J));
        $(Bl).find('.Desc').html((J.Cn.length == 0 ? '' : '<i>' + FindS(J.Cn) + '</i><br>') + FindS(J.D));
        if (J.block == 1) showFloorsButton($(Bl).find('.Size'));
    }
    else {
        $(Bl).find('.Location').html(FindS(htmlReqLocFull(J.Lc.split('|'))));
        $(Bl).find('.Desc').html((J.Cn.length == 0 ? '' : '<i>' + FindS(J.Cn) + '</i><br>') + FindS(J.D));
    }
    $(Bl).find('.Owner').html(htmlOwnersSearch(J.O));
    $(Bl).find('span.comment').each(function() { var c = $(this).html(); $(this).html(FindS(c)); });
}
function Capital1(s) { return s.charAt(0).toUpperCase() + s.slice(1); }
//alert(11);
function DatabaseUpdate(J) {
    jsCriteria.NID = _gNid; jsCriteria.ID = (J.I < 20 ? 0 : J.I);
    if (XY.It == 'r' || J.S > 17) jsCriteria.req = 1;
    if (jsCriteria.Rematch == 1) {
        $(XY.L).find('a.matches').html(jsCriteria.ID == 0 ? 'Matching...' : 'Rematching...');
        $(XY.L).find('.Matches').html(waitSometime(jsCriteria.ID == 0 ? 'Generating matches' : 'Rematching...')).css('display', 'block');
    }
    //return;
    $.post(urlLoad, jsCriteria, function(output) {
        if (jsCriteria.Rematch > 0) {
            $('#explain').html('');
            XY.J.I = output.split('*')[1];
            aL = XY.J.Lc.split('|');
            XY.L = ListId(XY.iti);
            if (XY.It == 'p')
                XY.J.Lc = aL[0] + '|' + aL[1] + '|' + aL[2] + '|' + aL[3] + '|' + aL[4] + '|' + aL[5] + '|' + aL[6] + '|' + aL[7] + '|' + trim(output.split('*')[3]); //CTIDs
            else {
                if (aL[3].length == 0)
                    XY.J.Lc = aL[0] + '|' + aL[1] + '|' + aL[2] + '|' + trim(output.split('*')[3]) + '|' + aL[4] + '|' + aL[5] + '|' + aL[6] + '|' + aL[7]; //CTIDs

            }
            var R = J.R.split('|');
            if (XY.It == 'p' && XY.J.S < 7)
                R[18] = (XY.PublicListing == '255' ? '01.01.2020' : '') + '*' + (XY.PublicListingOther == '255' ? '01.01.2020' : '') + '*' + (XY.PublicListingOtherAgents == '255' ? '01.01.2020' : '');

            R[10] = output.split('*')[2];
            J.R = retPipedString(R);
            $(XY.L).find('div.tp2').html(XY.J.I);
            $(XY.L).find('a.matches').html('Matches [' + output.split('*')[0] + ']');
            if (jsCriteria.Rematch == 1) {
                if (output.split('*')[0] != '0') {
                    $(ListId(XY.iti)).find('a.matches').attr('disabled', false).trigger('mouseout');
                    if (XY.Advertise == 0) $(XY.L).find('a.matches').attr('disabled', false).trigger('click');
                }
                else {
                    $(XY.L).find('a.matches').css('background', '#fff').attr('disabled', true);
                    $(XY.L).find('.Matches').html('<div style="text-align:center;font-size:1.5em;padding:20px">No match...</div>');
                }
                if (XY.Advertise > 0) $(XY.L).find('a.mail').trigger('click');
            }
        }
    });
}
var arPropSearchHelp = new Array('<div style="color:#5300A6"><p><b>Is this Property IN a Shopping Centre, Retail Park, Industrial Estate, etc.?</b></p><p>NB. A \'Business Centre\' is a Building not a \'Centre/Estate/Business Park/..\'</p><br /><p><b>Type the name into the Centre/Estate box</b></p><br /><p>If the Property is NOT IN a Centre/Estate</p><p>enter, either:</p><p>1) Full \'Postcode\'</p><p>or</p><p>2) Part Postcode then Street, then \'Street No\'</p><p>or</p><p>3) \'Town\', then \'Street\', then \'Street No\'</p></div>'
	, '<div style="color:#f92"><p>If you <b>enter the unusual word</b> into the \'Centre/..\' box, you will <b>find it quicker</b></p><br /><p>The choices are listed below. <b>Click</b> the line <b>for the correct \'Centre/..\'</b> and the address will be entered for you.</p><br /><p><b>Wrong Estate?</b></p><p>delete the address and start again.</p><br /><p><b>If the \'Centre/..\' is not listed,</b></p><p>at the bottom of the list click</p><p>\'Add a new Centre/Estate\'</p><p>Put in the \'Centre/..\' name in full, the town,</p><p>and a full postcode of a building there, and </p><p>click \'Save\'. The address is entered for you.</p></div>'
	, '<div style="color:#070"><p>Either:</p><p>enter the <b>full Postcode</b></p><p><b>or</b></p><p>enter <b>first half of the postcode</b></p><p>then <b>Street</b></p><p>then <b>Street No</b></p><p><b>or</b></p><p>enter <b>Town/City</b></p><p>enter <b>Street</b></p><p>enter <b>Street No</b></p><br /><p>A list of addresses should appear below.</p><p><b>Click</b> on the line of the closest address.</p><p>The address will be entered for you.</p><p>(Correct the Street No, Building, etc.)</p></div>'
	, '<div style="color:#00B;background-color:#EAF4FF"><p>With the full address entered, you will see a list of nearby Properties.</p><p><b><font color=green >GREEN:</font></b> these are other Available Properties </p><p><b><font color=red >RED:</font></b> these are EACH Archived Properties.</p><br /><p>Your Properties show first. If this Property is  already listed and GREEN (so \'available\'), you must select it and then choose an option.</p><br /><p>If this Property is listed and <b><font color=red >RED</font></b>, you can select it and recover the details from the archive to save time keying in the details.</p><br /><p>A similar nearby Property may also save you time if you select it. <b>If it does not work out,</b><b>click \'Add property\' in the menu and start</b><b>again – nothing is saved yet.</b></p></div>'
	, '<div class="PropBlock" style="padding:3px;background:#ef9;color:green;cursor:pointer;text-align:center"><span style="display:block">If the Estate is not listed above<a href="javascript:fisMenu(105);" style="background:#ef9;color:#c00;padding:0px;font-weight:bold">&nbsp;Please Add&nbsp;new&nbsp;Centre&nbsp;/&nbsp;Estate</a><span class=close>x</span></span><span>Enter Estate name, town and postcode only. It saves time for all future entries. <b>*</b></span></div>'
	, '<p><b>Is this Property IN a Shopping Centre, Retail Park, Industrial Estate, etc.?</b></p><p>NB. A \'Business Centre\' is a Building not a \'Centre/Estate/Business Park/..\'</p><br /><p><b>Type the name into the Centre/Estate box</b></p><br /><p>If the Property is NOT IN a Centre/Estate</p> <p>enter, either:</p><p>1) Full \'Postcode\'</p><p>or</p><p>2) Part Postcode then Street, then \'Street No\'</p><p>or</p><p>3) \'Town\', then \'Street\', then \'Street No\'</p>'
);
var aPropFieldset = new Array('<legend>Property <b>location</b><font>1</font></legend><div class=Error></div><div class="PropLocLeft">'
+ '<span onclick="getGoogle(0)" class=M title="Google map &#58 full postcode required"><u>M</u></span>'
+ '<div class=inl><span class=s1><b>Centre/Estate</b></span><span class=s2><input maxlength="30" id="centreestate" tabindex="3" s=1 /></span></div>'
+ '<div class=inl><span class=s1><b>Postcode</b></span><span class=s2><input name="postcode" maxlength="30" id="postcode" tabindex="7" s=1 /></span></div>'
+ '<div class=M><span style="width:107px">No&nbsp;postcode?</span><span onclick="getGoogle(1)" style="cursor:pointer"><u>from&nbsp;address&nbsp;entered,&nbsp;find&nbsp;on&nbsp;Google</u></span></div>'
+ '<div class=inl><span class=s1>Unit&nbsp;number</span><span class=s2><input maxlength="45" id="buildingnumber" tabindex="10" /></span></div>'
+ '<div class=inl><span class=s1>Building name</span><span class=s2><input maxlength="45" id="building" tabindex="13" /></span></div>'
+ '<div class=inl><span class=s1>Street No</span><span class=s2><input maxlength="30" id="streetnumber" tabindex="15"  s=1 /></span></div>'
+ '<div class=inl><span class=s1>Street</span><span class=s2><input maxlength="30" id="street" value="street" tabindex="18"  s=1 /></span></div>'
+ '<div class=inl><span class=s1>Suburb</span><span class=s2><input maxlength="30" id="suburblocality" value="only suburbs" tabindex="20" /></span></div>'
+ '<div class=inl><span class=s1>City / Town</span><span class=s2><input maxlength="30" id="towncity" value="city / town" tabindex="23"  s=1 /></span></div></div>'
+ '<div class="propSearchHelp"><b>READ THIS - SAVE TIME</b><div id="propSearchHelp"></div></div><div id="semiResult"><div class=Cest name=0></div><div class=Prop name=0></div></div>'
, '<legend><b>SIZE<font>4</font></b></legend><div class=Error></div><div style="float:left;width:100%;display:inline-block;padding-bottom:3px;padding-top:2px"><span style="width:70px;display:inline-block;padding-top:3px;float:left;text-indent:7px"><b>Internal</b></span><span style="float:right;display:inline-block">min&nbsp;<input type="text" id="SizeMin" size="9" />&nbsp;max&nbsp;<input type="text" id="SizeMax" size="9" /></span><span style="float:left;margin-right:0px;display:inline-block" id="SizeUnit"><span><input type="radio" name="unit" name2="2" value="2" checked="checked" />sqft&nbsp;</span><span><input name="unit"  name2="1" type="radio" value="1" />sqm</span></span><span style="color:green;font-size:10px;display:inline-block;float:left;padding-top:5px">&nbsp;&nbsp;land <b>only</b>? make Int=0&nbsp;</span></div>'
+ '<div id="Land" style="float:left;width:100%"><span style="width:70px;display:inline-block;float:left;padding-top:3px;text-indent:7px"><b>Land</b></span><span style="float:right;padding-top:3px">min&nbsp;<input type="text" id="SizeMine" size="9" value="0" />&nbsp;max&nbsp;<input type="text" id="SizeMaxe" size="9" value="0" /></span><span style="float:left" id="SizeUnite"><span><input type="radio" name="unite" name2="2" value="2" />sqft&nbsp;</span><span><input name="unite"  name2="1" type="radio" value="1" />sqm</span><span><input name="unite"  name2="1" type="radio" checked value="4" />acres</span><span><input name="unite" name2="1" type="radio" value="8" />hectares</span></span></div>'
+ '<span style="clear:both;float:left;margin-top:7px;width:490px" class="small green" >Internal is for Building size, Land is for external size/Terraces/etc.</span><div class=list><div class=Floors></div></div>'
, '', '<legend style="margin-bottom:7px"><b>TENURE</b><font>3</font></legend><div class=Error></div><div class="dvclick" style="width:85px;padding-left:7px" name2="0"><input type="checkbox" name="0" value="4" />&nbsp;<span>Freehold</span></div><div class="dvclick" name2="0" style="width:152px"><input type="checkbox" name="0" value="8" />&nbsp;<span>LongLeasehold</span></div>'
	+ '<span class="fr hide" style="float:left"><span style="width:80px;display:inline-block">Guide&nbsp;price</span>&pound&nbsp;<input id="priceMin" style="width:85px" />&nbsp;&nbsp;</span>'
	+ '<span class="fr"></span><br/><br/><div class="dvclick" style="clear:both;width:85px;padding-left:7px" name2="2"><input name="0" type="checkbox" value="1" />&nbsp;<span>Lease</span></div>'
	+ '<div class="dvclick" style="float:left;width:152px" name2="2"><input type="checkbox" value="2" />&nbsp;<span>Short&nbsp;Lease</span></div>'
	+ '<span class="fr hide" style="float:left"><span style="width:80px;display:inline-block">Guide&nbsp;rent</span>&pound&nbsp;<input id="rentMin" style="width:85px" />&nbsp;&nbsp;<select id=rentperiod><option value="-1">per sqft</option><option value="-2">per sqm</option><option value="1">pa</option><option value="2">monthly</option><option value="4">weekly</option></select></span>'
	+ '<span class="fr"><br><br></span><div class="TenureADD"><span style="width:135px">For Auction/Tender</span><span style="width:140px"><input type=radio checked name=Auction />No<input id=AuctionYes type=radio name=Auction />Yes</span><span style="padding-left:19px">Date: <input onfocus="showCalendarControl(this)" id="AuctionDate" style="width:70px" value="dd.mm.yy" name="ddmmyy" /></span></div>'
    + '<div class="TenureADD"><span style="width:110px;float:left">Rates: </span><div style="float:left">'
	+ '<div><span class="tensp0" >Rateable value </span><span>&pound;&nbsp;<input id="Rateable" style="width:85px" /></span></div>'
	+ '<div style="color:#787"><span class="tensp0">year  2011/2012 rate in </span><span>&pound;&nbsp;43.6</span></div>'
	+ '<div><span class="tensp0">Rates Payable </span><span>&pound;&nbsp;<input id="Payable" style="width:85px" /><span class=units></span></span></div>'
	+ '</div><br/><br/><br/><br/></div><div class="TenureADD"><span style="width:110px;float:left">Lease Terms: </span><div style="float:left">'
	+ '<div><span class="tensp0">Service Charge</span><span>&pound;&nbsp;<input id="serviceCharge" style="width:85px" /><span  class=units></span></span></div>'
	+ '<div style="height:22px;padding-top:3px"><span class="tensp0">Estate Charge</span><span>&pound;&nbsp;<input id="estateCharge" style="width:85px" /><span  class=units></span></span></div>'
	+ '<div><span class="tensp0">New Lease Available</span><span>&nbsp;&nbsp;<input id="NewLeaseAvail" type="checkbox" checked="checked" /></span></div>'// relevant information gives better replies from other Agents (max 300chs)
	+ '<div><span class="tensp0">Lease end date</span><span><span class="calendar"></span>&nbsp;&nbsp;<input onfocus="Calendar(this,0,31)" id="dateLeaseEnd" name="mmyyyy" value="mm.yyyy" style="width:55px" /></span></div><div><span class="tensp0">&nbsp;</span><span></span></div><div><span class="tensp0">1st Tenant Break</span><span><span class="calendar"></span>&nbsp;&nbsp;<input onfocus="Calendar(this,0,21)" id="TenantLeaseBreakDate" name="mmyyyy" value="mm.yyyy" style="width:55px" /></span></div><div style="height:22px;padding-top:3px"><span class="tensp0">1st Landlord Break</span><span><span class="calendar"></span>&nbsp;&nbsp;<input name="mmyyyy" id="LandlordLeaseBreakDate" value="mm.yyyy" onfocus="Calendar(this,0,21)" style="width:55px" /></span></div><div id="CalMonths"></div></div><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/></div>'
, '<legend>Public information (shown on listing)<font>5</font></legend><div class=Error></div><br/><span style="float:left">Client Company or Reference</span><input id="ClientName" style="width:324px;float:right" value="" type="text" /><br/><br/><span style="float:left;clear:both">Amenities</span><textarea id="Amenities" style="width:324px;float:right" multiline="2" type="text"></textarea><span class="green small">&nbsp;(300 chs)</span><div id="Amenities2"></div><span style="clear:both;float:left;width:100%;margin-top:7px"><div style="width:220px;float:left">Brief Description<span class="green small">&nbsp;(300 chs)</span></div><textarea style="float:right" multiline="2" id="description">e.g. For solicitors. Min 3 meeting rooms. Max 2 floors.</textarea></span>'
);
var aReqFieldset = new Array('', '<legend style="margin-bottom:5px"><b>SIZE</b><font>2</font></legend><div class=Error></div><table cellpadding="0" cellspacing="0" name="0" style="border:1px solid #aac;float:left;cursor:pointer;width:85px"><tr><td class=IntExt style="vertical-align:middle">&nbsp;&nbsp;Internal&nbsp;&nbsp;</td><td style="vertical-align:middle;text-align:right">&nbsp;<img src="http://www.osidil.com/JSON/4prop/Drop.jpg" /></td></tr></table>'
+ '<span style="float:right;margin-top:3px">min&nbsp;<input type="text" id="SizeMin" size="9" />&nbsp;max&nbsp;<input type="text" id="SizeMax" size="9" /></span>'
+ '<span id="SizeUnit"></span><div style="clear:both;float:left;margin-top:4px;display:BLOCK" class="small green" >Internal is for Building size. <br/>If Land size is more important, click to External</div>'
, '', '<legend><b>TENURE</b><font>4</font></legend><div class=Error></div><div class="dvclick" style="width:85px" name2="0"><input type="checkbox" name="0" value="4" />&nbsp;Freehold</div>'
	+ '<div class="dvclick" name2="0"><input type="checkbox" name="0" value="8" />&nbsp;LongLeasehold</div>'
	+ '<span class="fr hide">&nbsp;min&nbsp;&nbsp;&pound&nbsp;<input type="text" id="priceMin" size="10" />&nbsp;&nbsp;max&nbsp;&nbsp;&pound&nbsp;<input id=priceMax type="text" size="10" /></span>'
	+ '<span class="fr hide" style="clear:both;color:green;font-size:9px;width:200px;float:right;text-align:right"><b>NB</b>: An empty field means <b>any</b> value.</span>'
	+ '<br/><div class="dvclick" style="clear:both;width:85px" name2="2"><input name="0" type="checkbox" value="1" />&nbsp;Lease</div>'
	+ '<div class="dvclick" style="float:left" name2="2"><input type="checkbox" value="2" />&nbsp;Short&nbsp;Lease</div>'
	+ '<span class="fr hide">min&nbsp;&pound&nbsp;<input type="text" id="rentMin" size="10" />&nbsp;&nbsp;max&nbsp;&pound&nbsp;<input id=rentMax type="text" size="10" />&nbsp;<select id=rentperiod><option value="-1">per sqft</option><option value="-2">per sqm</option></select></span>'
    + '<span class="fr hide" style="clear:both;color:green;font-size:9px;width:200px;float:right;text-align:right"><b>NB</b>: An empty field means <b>any</b> value.</span>'
	, '<legend>DISPLAY DESCRIPTION & CLIENT<font>5</font></legend><div class=Error></div><br/><span style="float:left">Client Company or Reference</span><input id="ClientName" style="width:324px;float:right" value="" type="text" /><br/><br/><span style="float:left;clear:both">Amenities Required</span><textarea id="Amenities" style="width:324px;float:right" multiline="2" type="text" ></textarea><span class="green small">&nbsp;(300 chs)</span><span id="Amenities2"></span><span style="clear:both;float:left;width:100%;margin-top:7px"><div style="width:220px;float:left">Brief Description<span class="green small">&nbsp;(300 chs)</span></div><textarea style="float:right" multiline="2" id="description">e.g. For solicitors. Min 3 meeting rooms. Max 2 floors.</textarea></span>'
, '<legend><b>SEARCH&nbsp;-</b><font>3</font>&nbsp;<span style="font-weight:normal">SELECT ONE AREA TYPE ONLY (and Streets if search is Street specific)</span></legend><div class=Error></div>'
+ '<div id="Street"><span style="float:left">specific STREET(S)</span><textarea name="Street" class=street></textarea></div>'
+ '<div id="London"><span style="float:left">CENTRAL London AREAS</span><span id="LondonCentralClick"></span><div name="London" id="LondonCentral"></div><div id="LondonBlock"></div></div>'
+ '<div id="Region"><span style="float:left">REGIONS&nbsp;&&nbsp;COUNTIES&nbsp;</span><span id="RegionButton">Click here to select REGIONS/COUNTIES</span><div id=RgsMulti></div><div id=RgsMulti2><div class=cnts></div></div></div>'
+ '<div id="Town"><span style="float:left">TOWNS</span><textarea name="Town" class=loc></textarea><span id="TownList"></span></div>'
+ '<div id="Postcode"><span style="float:left">POSTCODES</span><textarea name="Postcode" class=loc rows="2" cols="65"></textarea></div>'
+ '<div id="Map"><span style="float:left;display:block">MAP</span><textarea name="Map" class=loc></textarea><a id=aMap href="javascript:AreaMap()">open map</a>'
+ '<span class=barea style="float:left;color:#933" name=i></span><span style="clear:both;margin-right:10px;background:#dfd;float:left" class=barea name=s>Start&nbsp;New&nbsp;Area</span>'
+ '<div id=MapWrap><span style="color:red;font-size:1.25em">to complete the search box, you MUST CLICK your STARTING POINT</span><div id=MapInput></div></div></div><div id=semiResult><div class=Cest name=0></div><div class=Prop name=0></div></div><div id=semiResult2></div>');
var Split = "|", ACE = 1, Preset = false, selAll;
var ADDbutton = '<div class="button" name="xID" style="STYLE" name2="xValue" name3="ORDER" ><input type="checkbox" />xValue</div>', cssClose = 'class=bClose style="background:#900;color:#fff;border:0px;text-align:center;font-size:10px;width:32%"', cssClickeCol = "#7c7";
var cssClicked = 'background:' + cssClickeCol, aPts, aPtsClicks, aPstCntIds;
var orderTypes = [0, 8, 2, 4, 6, 5, 7, 9, 3, 1], V = '', option = '<option value=xValue>yValue</option>';
function MissedLoc(t) { $('#PropLoc,#Location').find('div.Error').html(t).slideDown('fast'); offsetY(XY.It == 'p' ? '#PropLoc' : '#Location'); }
function MissedDsc(t) { $('#DescriptionClient').find('div.Error').html(t).slideDown('fast'); offsetY('#DescriptionClient'); }
function MissedTps(t) { $('#Type').find('div.Error').html(t).slideDown('fast'); offsetY('#Type'); }
function MissedTnr(t) { $('#Tenure').find('div.Error').html(t).slideDown('fast'); offsetY('#Tenure'); }
function MissedSz(t) { $('#Size').find('div.Error').html(t).slideDown('fast'); offsetY('#Size'); }
function TownsNoPc(t) { if (t.length == 0) return ""; var ar = t.split(','), ts = ''; for (var i = 0; i < ar.length && ar[i].indexOf('[') > -1; i++) { ts += ar[i].split(' [')[0] + ','; } return ts.substring(0, ts.length - 1); }
function TownsOnlyPc(t) { if (t.length == 0) return ""; var ar = t.split(','), ts = ''; for (var i = 0; i < ar.length && ar[i].indexOf('[') > -1; i++) { ts += ar[i].split(' [')[1].replace(']', '') + ','; } return ts.substring(0, ts.length - 1); }
function AddSave(matches) {
    try {
        if (XY.J.T.split('|')[1].length == 0) {
            if (XY.J.T.split('|')[0].length == 0) {
                MissedTps('Please check some subtypes');
                return;
            }
            else XY.J.T += eval('jsPts2.v' + XY.J.T.split('|')[0].replace(/,/g, '')).replace(/\./g, ',');
        }
        if (XY.J.N.length < 8) {
            $('#EDIT').find('div.ErrorSum').attr('name', '1').html('You have not selected any agent / Company'
                    + '<br>You must select at least one agent'
                ).css('font-size', '1.1em').slideDown('fast');
            if ($(XY.L).find('a.agent').attr('name') != '1') $(XY.L).find('a.agent').trigger('click');
            offsetY($(XY.L).find('a.agent'));
            return;
        }

        if (Secretary == 'S' && retZ(XY.J.It) == 'n') { //some agent's prop / req are under me...
            if (XY.J.O == Owners && $('#EDIT').find('div.ErrorSum').css('display', 'none').attr('name') != '1') {
                $('#EDIT').find('div.ErrorSum').attr('name', '1').html('Warning:<br>As an administrator, you are creating ' + propreq[retA(XY.J.It)] + ' under your name'
                    + '<br>If you want to create it on behalf of your agents, please use the Agent\'s tree below'
                    + '<br>If you want to create ' + propreq[retA(XY.J.It)] + ' on your behalf, click SAVE again'
                ).css('font-size', '1.1em').slideDown('fast');
                if ($(XY.L).find('a.agent').attr('name') != '1') $(XY.L).find('a.agent').trigger('click');
                offsetY($(XY.L).find('a.agent'));
                return;
            }

        }
        else if (XY.J.N.split('|')[0].indexOf(',' + _gNid + ',') == -1 && $('#EDIT').find('div.ErrorSum').css('display', 'none').attr('name') != '1') {
            $('#EDIT').find('div.ErrorSum').attr('name', '1').html('Warning:<br>You are creating ' + propreq[retA(XY.J.It)] + ' NOT under your name'
                    + '<br>If is is your intention, click SAVE again'
                ).css('font-size', '1.1em').slideDown('fast');
            if ($(XY.L).find('a.agent').attr('name') != '1') $(XY.L).find('a.agent').trigger('click');
            offsetY($(XY.L).find('a.agent'));
            return;
        }
        $('#EDIT').find('div.ErrorSum').attr('name', '0');
        aS = XY.J.Sz.split('|');
        //Only Prop & Investment Type
        if (XY.It == 'p' && XY.J.tp != '5' && aS[1] == '0' && aS[2] == '0' && aS[4] == '0' && aS[5] == '0') {
            MissedSz('Please fill in values for Size'); return;
        }
        if (!IsNumeric(XY.J.Sz.replace(/\|/g, ''))) {  // aS.join('')[1]  || !IsNumeric(aS[2]) || !IsNumeric(aS[4]) || !IsNumeric(aS[5])   
            MissedSz('Non numeric values for Size!'); return;
        }
        //if (XY.J.Rn.split('|')[0] == '0') { MissedTnr('Please check some tenure'); return; }
        if (XY.J.Rn.split('|')[0] == '0') {
            if (XY.It == 'r') {
                XY.J.Rn = '15' + XY.J.Rn.substring(1, XY.J.Rn.length);
            }
            else {
                MissedTnr('Please check some tenure');
                return;
            }
        }
        if (XY.J.D.length > 300) { MissedDsc('Description has ' + XY.J.D.length + ' characters, maximum is 300'); return; }
        if (XY.J.A.length > 300) { MissedDsc('Amenities has ' + XY.J.A.length + ' characters, maximum is 300'); return; }

        aL = XY.J.Lc.split('|');
        if (XY.It == 'r') {
            if (XY.ReqLoc == 'None') { MissedLoc('Please specify postcode or town for your requirement'); return; }
            else if (XY.ReqLoc == 'London') {
                if (aL[1] == '') { MissedLoc('Please specify central london areas, or other type location'); return; }
            }
            else if (XY.ReqLoc == 'Region') {
                if (aL[5] == '' && aL[7] == '') { MissedLoc('Please specify Region(s) or Counties, or other type location'); return; }
            }
            else if (XY.ReqLoc == 'Postcode') {
                if (aL[3] == '') { MissedLoc('Please specify Postcode(s), or other type location'); return; }
            }
            else if (XY.ReqLoc == 'Town') {
                try {
                    if (aL[2] == '') { MissedLoc('Please specify Town(s), or other type location'); return; }
                    if (aL[2] != $('#Town').find('textarea').val()) {
                        aL[2] = $('#Town').find('textarea').val();
                        var ln = aL[2].length;
                        if (aL[2].substring(ln - 2, ln) == ', ') aL[2] = aL[2].substring(0, ln - 2);
                        if (aL[2].substring(ln - 1, ln) == ',') aL[2] = aL[2].substring(0, ln - 1);
                        XY.J.Lc = aL[0] + '|' + aL[1] + '|' + aL[2] + '|' + aL[3] + '|' + aL[4] + '|' + aL[5] + '|' + aL[6] + '|' + aL[7];
                    }
                    var ar = aL[2].split(','), ts = ''; for (var i = 0; i < ar.length; i++) { if (ar[i].indexOf('[') == -1) throw 'a'; ts = ar[i].split(' [')[0]; }
                }
                catch (e) {
                    MissedLoc('Please make sure the towns are selected from the town\'s list<br>As you type first 3 letters the town list appears<br>You click the town you want to select<br>Selected town must have [postcode], e.g. Bristol [BS]');
                    return;
                }
            }
            else if (XY.ReqLoc == 'Map') {
                if (XY.J.polygon.length < 1) {//aL[6].length<30
                    MissedLoc('Please draw Area(s), or specify other type location');
                    return;
                }
                else if (aL[0].length < 2) {
                    var areadesc = $('#Map').find('textarea').val();
                    if (areadesc != 'eg. Birmingham-Nottingham-Sheffield, M1 corridor, etc' && areadesc.indexOf('Describe') == -1) {
                        //$('#Map').find('textarea').val(
                        aL[0] = areadesc;
                    }
                    else {
                        MissedLoc('Please describe the Area');
                        $('#Map').find('textarea').select();
                        return;
                    }
                }            //XY.J.map.getCenter().lat()
                aL[6] = XY.J.map.getCenter().lat() + ',' + XY.J.map.getCenter().lng() + '!' + XY.J.map.getZoom() + '!';  //+ '0*';
                var poly = 'PolygonsX', polys = '', p = 0, p2 = 0, aP, ps = ''; //0
                for (p; p < XY.J.polygon.length; p++) {
                    if ($('#Map').find('span.barea[name=' + XY.J.polygon[p].name + ']').find('td').slice(0, 1).html() == 'delete') {
                        aP = XY.J.polygon[p].C[0].j;
                        ps = '';
                        for (p2 = 0; p2 < aP.length; p2++) ps += '*' + aP[p2].x + ',' + aP[p2].y;

                        polys += poly.replace('Polygons', ps);
                    }
                }
                aL[6] += polys;
                if (polys.length == 0) {
                    MissedLoc('You deleted all areas... Draw or renew at least one');
                    return;
                }
                XY.J.Lc = aL[0] + '|' + aL[1] + '|' + aL[2] + '|' + aL[3] + '|' + aL[4] + '|' + aL[5] + '|' + aL[6] + '|' + aL[7]; ;
            }
        }
        else {//property check values...
            var pcc = $('#postcode').val().toUpperCase(); //.replace('postcode', '')
            if (pcc.length < 1) { MissedLoc('Please fill in Postcode'); return; }
            if (pcc.replace(/^(((([A-PR-UWYZ][0-9][0-9A-HJKS-UW]?)|([A-PR-UWYZ][A-HK-Y][0-9][0-9ABEHMNPRV-Y]?))\s{0,2}[0-9]([ABD-HJLNP-UW-Z]{2}))|(GIR\s{0,2}0AA))$/, '').length > 0) {
                MissedLoc('Postcode is not in valid UK format'); return;
            }
            //            .replace(/^((([A-PR-UWYZ][0-9])|([A-PR-UWYZ][0-9][0-9])|([A-PR-UWYZ][A-HK-Y][0-9][0-9])|([A-PR-UWYZ][A-HK-Y][0-9][0-9])|([A-PR-UWYZ][0-9][A-HJKSTUW])|([A-PR-UWYZ][A-HK-Y][0-9][ABEHMNPRVWXY]))\s?([0-9][ABD-HJLNP-UW-Z]{2})|(GIR)\s?(0AA))$/, '').length
            ///^([A-PR-UWYZ0-9][A-HK-Y0-9][AEHMNPRTVXY0-9]?[ABEHMNPRVWXY0-9]? {1,2}[0-9][ABD-HJLN-UW-Z]{2}|GIR 0AA)$/i
            if ($('#towncity').val().length < 1) { MissedLoc('Please fill in Town / City'); return; }
        }
        jsCriteria = { Update: 1, ChargeNid: IsAdmin }; //_gNid
        jsCriteria.Rematch = matches;
        aL = XY.J.Lc.split('|'); aT = XY.J.Rn.split('|');
        jsCriteria.clientName = XY.J.Cn; jsCriteria.attachments = XY.J.At; jsCriteria.description = XY.J.D;
        jsCriteria.Amenities = XY.J.A; jsCriteria.hideidentity = XY.J.H;
        jsCriteria.tenure = aT[0]; jsCriteria.rentPeriod = aT[1];
        jsCriteria.rentMin = (aT[2].length == 0 || aT[2] == 'rent' ? "0" : aT[2]); //aT[2];
        jsCriteria.SizeUnit = aS[0]; jsCriteria.SizeMin = aS[1] != "undefined" && aS[1] != '' ? parseFloat(aS[1]) : '0'; jsCriteria.SizeMax = aS[2] != "undefined" && aS[2] != '' ? parseFloat(aS[2]) : '0';
        if (aS[3].length > 0 && aS[3] != '0' && aS[3] != "undefined") {
            jsCriteria.sizeUnitExternal = aS[3];
            jsCriteria.minExternal = aS[4];
            jsCriteria.maxExternal = aS[5];
        }
        if (XY.It == 'r' && aS[3].length > 0 && aS[3] != '0') {// && aS[3] != "undefined"
            if (aS[1] != '0' && aS[2] != '0') {
                jsCriteria.SizeUnit = aS[3];
                jsCriteria.SizeMin = aS[4];
                jsCriteria.SizeMax = aS[5];
            }
        }
        jsCriteria.owners = XY.J.O; jsCriteria.types = XY.J.T.split('|')[0]; jsCriteria.PSTids = XY.J.T.split('|')[1];
        jsCriteria.status = XY.J.S;
        jsCriteria.Dealswith = XY.J.N.split('|')[0]; jsCriteria.DIDs = XY.J.N.split('|')[1];
        jsCriteria.BIDs = XY.J.N.split('|')[2]; jsCriteria.CIDs = XY.J.N.split('|')[3];
        jsCriteria.AlertListing = XY.AlertListing;
        if (XY.It == 'r') {//AreaTitle|LondonCentral|TownsWithPC|PCs|Streets|CTIDs|area|Regions
            jsCriteria.Area = aL[6]; jsCriteria.AreaTitle = aL[0]; jsCriteria.LondonCentral = aL[1];
            jsCriteria.PCs = aL[3]; jsCriteria.Regions = aL[7]; jsCriteria.CTIDs = aL[5];
            if (aL[2].length > 0) {
                jsCriteria.TownsWithPC = aL[2]; jsCriteria.Towns = TownsNoPc(aL[2]); jsCriteria.PCs = TownsOnlyPc(aL[2]);
            }
            jsCriteria.Streets = aL[4]; jsCriteria.rentMax = aT[3]; jsCriteria.priceMin = aT[4]; jsCriteria.priceMax = aT[5];
            //Rent:tenure|rentperiod|rentMin|RentMax|priceMin|priceMax|					
            //Size:sizeUnit|sizemin|sizemax|sizeUnitExt|SizeMinExt|SizeMaxExt|IsExternal
        }
        else {//StreetNumber|postcode|street|CentreEstate|townCity|suburbLocality|buildingNumber|building|CTIDs
            jsCriteria.PublicListing = XY.PublicListing;
            if (XY.PublicListingOther > 0) jsCriteria.PublicListingOther = XY.PublicListingOther;
            if (XY.PublicListingOtherAgents > 0) jsCriteria.PublicListingOtherAgents = XY.PublicListingOtherAgents;
            jsCriteria.latitude = XY.J.Lt; jsCriteria.longitude = XY.J.Ln;
            jsCriteria.images = XY.J.Im; jsCriteria.floors = XY.J.F;
            jsCriteria.buildingNumber = aL[6]; jsCriteria.building = aL[7]; jsCriteria.streetNumber = aL[0];
            jsCriteria.street = aL[2]; jsCriteria.suburbLocality = aL[5]; jsCriteria.townCity = aL[4];
            jsCriteria.postcode = aL[1]; jsCriteria.CentreEstate = aL[3]; //.replace();
            jsCriteria.priceMin = aT[3]; jsCriteria.RateableValue = (aT[4].length == 0 ? "0" : aT[4]);
            jsCriteria.ratesPayable = (aT[5].length == 0 || aT[5] == 'Rates Payable' ? "0" : aT[5]);
            jsCriteria.serviceCharge = (aT[6].length == 0 || aT[6] == 'Service Charge' ? "0" : aT[6]);
            jsCriteria.estateCharge = (aT[7].length == 0 ? "0" : aT[7]);
            jsCriteria.NewLeaseAvail = aT[9];
            var mmyyyy, mplus; //dd.mm.yyyy,mm.yy.dd
            if (dtValidate($('#AuctionDate').val()).length > 0 && $('#AuctionDate').val() != 'dd.mm.yy') {
                mmyyyy = $('#AuctionDate').val().split('.');
                aT[8] = $('#AuctionDate').val();
                jsCriteria.dateAuction = mmyyyy[1] + "." + mmyyyy[2].substring(2, 4) + "." + ret2(mmyyyy[0]);
            }
            if (dtValidate($('#dateLeaseEnd').val()).length > 0 && $('#dateLeaseEnd').val() != 'mm.yyyy') {
                mmyyyy = $('#dateLeaseEnd').val().split('.');
                mplus = ret2(parseFloat(aMd[mmyyyy[0]]) + 1);
                aT[10] = "01." + mplus + "." + mmyyyy[1];
                jsCriteria.dateLeaseEnd = mplus + "." + mmyyyy[1].substring(2, 4) + ".01";
            }
            if (dtValidate($('#TenantLeaseBreakDate').val()).length > 0 && $('#TenantLeaseBreakDate').val() != 'mm.yyyy') {
                mmyyyy = $('#TenantLeaseBreakDate').val().split('.');
                mplus = ret2(parseFloat(aMd[mmyyyy[0]]) + 1);
                aT[11] = "01." + mplus + "." + mmyyyy[1];
                jsCriteria.TenantLeaseBreakDate = mplus + "." + mmyyyy[1].substring(2, 4) + ".01";
            }
            if (dtValidate($('#LandlordLeaseBreakDate').val()).length > 0 && $('#LandlordLeaseBreakDate').val() != 'mm.yyyy') {
                mmyyyy = $('#LandlordLeaseBreakDate').val().split('.');
                mplus = ret2(parseFloat(aMd[mmyyyy[0]]) + 1);
                aT[12] = "01." + mplus + "." + mmyyyy[1];
                jsCriteria.LandlordLeaseBreakDate = mplus + "." + mmyyyy[1].substring(2, 4) + ".01";
            }
            XY.J.Rn = aT[0] + '|' + aT[1] + '|' + aT[2] + '|' + aT[3] + '|' + aT[4] + '|' + aT[5] + '|' + aT[6] + '|' + aT[7] + '|' + aT[8] + '|' + aT[9] + '|' + aT[10] + '|' + aT[11] + '|' + aT[12];
            //Rent: tenure | rentperiod | rent | price | RateableValue | ratesPayable | serviceCharge | estateCharge | dateAuction | NewLeaseAvail | dateLeaseEnd | TenantLeaseBreakDate | LandlordLeaseBreakDate
            //Size: sizeUnit | sizemin | sizemax | sizeUnitExternal | minExternal | maxExternal
        }
        if (IsAdmin > 0) {
            mmyyyy = $('#billdate').val().split(' '); //mmyydd
            jsCriteria.BillDate = ret2(parseFloat(aMd[mmyyyy[1]]) + 1) + "." + mmyyyy[2].substring(2, 4) + "." + ret2(mmyyyy[0]); //$('#billdate').split(' ');// ret2($('#Bmonth').val()) + '.' + $('#Byear').val().substring(2, 4) + '.' + ret2($('#Bday').val());
        }

        XY.J.Crit = XY.J.tp;
        if (matches == 2 && XY.J.I < 100 && XY.Advertise == 1) {
            $('#badvertise').trigger('click');
            XY.J.S = 7;
        }
        //if (XY.J.I > 100) {
        //a.matches,a.map,a.pdf,,a.floors,input.sz,input.rn,a.enq,a.mail,a.rent,a.edit,a.copy,a.agent
        /*
        $(XY.L).find('a.del,a.status,a.clicks,a.mail').css('display', 'none');
        if (XY.J.S == 7) $(XY.L).find('a.del').css('display', 'block');
        else $(XY.L).find('a.status,a.clicks,a.mail').css('display', 'block');
        */
        //}        
        DatabaseUpdate(XY.J);
        if (XY.J.It == XY.New) {//'n'
            set_cookie("addT", XY.J.T.split('|')[0] + '|'); set_cookie("addRn", XY.J.Rn); set_cookie("addSz", XY.J.Sz);
            JSON[XY.New][0].NewSaved++; JSON[XY.New][JSON[XY.New].length - 1].NewSaved = 1;
            $(XY.B).find('.bar').css('display', 'block'); //.css('display', 'block')table
        } else {
            StatusChangeOne(XY.iti, XY.J.S);
        }
        EditStart(0);
        //if (matches > 0)$(ListId(XY.iti)).find('.Matches').html(waitSometime(XY.J.I == '0' ? 'Generating matches' : 'Rematching...')).css('display','block');
        if (matches == 0) offsetY(ListId(XY.iti));
        if (XY.It == 'p') XY.Props++; else XY.Reqs++;
        PropReq();
        XY.action = 0;
        XY.JustAdded = 1;
        $(XY.L).find('a.del,a.status,a.clicks,a.mail,a.copy,a.edit').css('display', 'none');
        //if (XY.J.S == 7) $(XY.L).find('a.del').css('display', 'inline-block');       else
        if (XY.J.S != 7) $(XY.L).find('a.status,a.clicks,a.mail').css('display', 'inline-block');
    }
    catch (e) {
        MissedLoc('Some data problem<br>The error was sent to EACH<br>We are resolving it');
        Error('List Save', e.message);
    }
}
function ret2(v) { if ((v + '').length == 1) return '0' + v; return v; }
function retA(v) { return v != undefined ? v.substring(0, 1) : ''; }
function retZ(v) { return v.substring(v.length - 1, v.length); }
function EditStart(v) {
    $('#Advertise,#EDIT').css('background', '#fff');
    $('#RESULT').find('div.bar').css('display', 'none');

    if (v == 0) {//back to My Prop / req, or Add Req / Prop
        $('#EDIT,#explain,#BillDate,.aGO,.Cancel').html('').css('display', 'none');
        $('#head').find('span.Tit').html('');
        $('#fsScope,#fsFind').css('display', 'block');
        //,span.prn
        $('#head').find('span.itm').css('display', 'inline-block').slice(0, 1).attr('name', '0').css('background-color', '').css('color', '').trigger('mouseout'); //ADD button...
        ControlCloseAll(XY.iti, null);
        document.title = "EACH: My / Our " + propreqs[XY.It];
        //Find Instruction
        if ($('#fsFind').attr('name') != '1') $('#fsFind').css('display', 'none');
        //only Mine will be shown...
        if (XY.aMatchPages[IS][0] == undefined) MineIsEmpty(); //mine is zero...                
        else {
            var a = XY.aMatchPages[IS][0].split('|'), b;
            for (var t = 1; t < a.length; t++) {
                b = XY.It + '|' + a[t];
                if (XY.Views[b] == '1') $(BarId(b)).find('div.map').css('display', 'block');
                b = BarId(b);
                $(b).css('display', 'block').find('div.list,table.bar').css('display', 'block');
                if ($(b).find('div.sort').attr('name') == '1') $(b).find('div.sort').css('display', 'block');
            }
        }
        if (aIS[4] == 0) $('#head').find('span.itm[name2=4]').css('display', 'none');

        if (XY.AddedOnly == 1) {
            $('#head').find('span.itm').slice(1, 6).css('display', 'none');
            $('#fsScope').css('display', 'none');
            $('#RESULT').css('margin-top', '50px').find('div.bar').css('display', 'block').find('div.block2').css('display', 'block');
            $('#RESULT').find('div[name=pn|0],div[name=rn|0]').css('display', 'none');
        }
        else {
            $('#lhs').find('div.dMn').find('a[name=6],a[name=9]').attr('name2', '0').trigger('mouseout');
            fisMenu((XY.It == 'r' ? 7 : 10), 0);
        }
        //alert(isCommPriv(XY.J));//.split('|')
        //$(XY.L).find('div.speech').css('display', 'block');
        //}
    }
    else {//to Edit
        $('#EDIT').css('display', 'block');
        $('#head').find('span.itm').css('display', 'none'); //,span.prn
        $('#fsScope,#fsFind').css('display', 'none');
        $('#head').css('display', 'inline-block').find('a').css('display', 'inline-block');
        $('#RESULT').find('div.bar[name=' + XY.id + ']').css('display', 'block').find('div.list,table.bar,div.sort,div.map').css('display', 'none');
        $(XY.L).css('display', 'block').find('div.speech').css('display', 'none');
        $(XY.L).find('div.block2').find('div.dvComments').find('img').css('display', 'none');
        //:last

    }
    if (JSON[XY.New].length > 0 && JSON[XY.New][0].NewSaved > 0) {
        $(XY.B).css('display', 'block').find('table.bar').css('display', 'block').attr('name', '1').css('background', '#0F2A86').find('td.count').html(JSON[XY.New][0].NewSaved);
        $(XY.B).find('div.list,a.copy,a.edit,a.status,a.clicks,a.matches,a.mail').css('display', 'inline-block');
    }
}
function EditCancel() {
    XY.action = 0;
    EditStart(0);
    if (XY.J.It == XY.New) {
        var a = new Array();
        for (var j = 0; j < JSON[XY.New].length - 1; j++) a[j] = JSON[XY.New][j];

        JSON[XY.New] = a;
        $(XY.B).find('div.list:last').html('').attr('name', '');
        XY.J.block = 0;
    }
    else {//Edit..
        var N = XY.iti.split('|'); //, cIt = XY.J.It;
        XY.J = XY.parse(XY.Js);
        JSON[N[0]][N[2]] = XY.J;
        XY.J.block = 0;
        if (XY.J.marker != undefined) XY.J.marker = XY.marker; //JSON[N[0]][N[2]]
        if (XY.It == 'r') {
            ReqListClient(XY.L);
            $(XY.L).find('td.sz').html(htmlSizeP(XY.J, 1));
            $(XY.L).find('td.st').html(Fading(htmlReqLoc(XY.J.Lc.split('|'), 1), 16, 7, '')).find('font').each(function() { $(this).css('opacity', $(this).attr('name')) });
        } else {
            if (XY.J.tp == '2' || XY.J.tp == '4' || XY.J.tp == '8') $(XY.L).find('input.sz').val(htmlSizeP(XY.J, 1));
            else $(XY.L).find('td.sz').html(htmlSizeP(XY.J, 1));
            $(XY.L).find('input.rn').val(listRent(XY.J.Rn, 'p')); //Fading()
            $(XY.L).find('td.st').html(LsPLc(XY.J, 14, 8)).find('font').each(function() { $(this).css('opacity', $(this).attr('name')) });
            //showFloorsButton($(XY.L).find('.Size'));
        }
        showBlock(XY.iti);
    }
}
var headColors = new Array(); headColors['Cancel'] = '#fdd'; headColors['aGO'] = '#dfd';
function Add(typ, copy) { //',59368,|,430,|,75,|,95,'   
    XY.action = 100;
    if (typ == 'New') JSON[XY.New][JSON[XY.New].length] = { T: '8|', tp: 8, Crit: '', I: 0, N: ',' + _gNid + ',|,' + _gDid + ',|,' + _gBid + ',|,' + _gCid + ',', S: 0, H: 0, D: "", Cn: "", A: "", At: "", Im: "0", Ln: '', Lt: '', Sz: '2|0|0|0|0|0', Rn: '0|1|0|0|0|0|0|0||1|||', Lc: "||||||||", O: Owners, F: "", R: "|||||||||||||||||||" };
    else JSON[XY.New][JSON[XY.New].length] = XY.parse(XY.Js);

    XY.J = JSON[XY.New][JSON[XY.New].length - 1];
    XY.J.S = 0; XY.J.NewSaved = 0;
    XY.J.III = XY.J.I; XY.J.I = JSON[XY.New].length - 1;
    XY.ItTp = XY.New + "|0"; XY.iti = XY.ItTp + "|" + XY.J.I;
    XY.J.found = 1; //XY.J.Cm = "";
    if (typ == 'New') {
        XY.J.Lt = LatLong.split(',')[0];
        XY.J.Ln = LatLong.split(',')[1];
        if (JSON[XY.It].length > 0) {        //at least one record exists
            XY.J.T = JSON[XY.It][0].T;
            XY.J.tp = JSON[XY.It][0].tp;
        }
        else if ($('#RESULT').find('div.bar').length == 0) fBars('#RESULT', JustAdded()); //$('#RESULT').html()

        XY.J.Wd = 0; XY.J.Pf = 0; XY.J.Rej = 0; XY.J.Cl = 0; //memory
        try {
            if (get_cookie("addT").length > 0) { XY.J.T = get_cookie("addT"); XY.J.tp = XY.J.T.split('|')[0].replace(/,/g, ''); }
        } catch (et) { }
    }
    else {
        XY.J.F = "";
        if (copy == 0) XY.J = { T: '8|', tp: 8, Crit: '', I: 0, N: ',' + _gNid + ',|,' + _gDid + ',|,' + _gBid + ',|,' + _gCid + ',', S: 0, H: 0, D: "", Cn: "", A: "", At: "", Im: "0", Ln: '', Lt: '', Sz: '2|0|0|0|0|0', Rn: '1|1|0|0|0|0|0|0||1|||', Lc: XY.J.Lc, O: Owners, F: "", R: "||||||||||" };
        else if (copy == 1) XY.J.At = "";
        else if (copy == 2) XY.J.Im = "";
        XY.J.N = ',' + _gNid + ',|,' + _gDid + ',|,' + _gBid + ',|,' + _gCid + ',';
        XY.J.O = Owners;
    }
    XY.J.View = 0; XY.J.ck = 0; XY.J.rc = 0; XY.J.block = 0; XY.J.II = XY.J.I; XY.J.It = XY.New; XY.B = BarId(XY.ItTp); XY.J.Crit = 0;
    XY.view = false;
    Edit(typ);
    if ($(XY.B).find('div.list').length == 0) {
        $(XY.B).find('div.block').html(ListHtml(XY.J, XY.J.I, '')
            ).find('div.list[name!=' + XY.iti + ']').css('display', 'none');
        $(XY.B).find('a.NewReload').mouseover(function() { $(this).css('background-color', '#eef').css('color', '#336'); }).mouseout(function() { $(this).css('background-color', '').css('color', ''); });
    }
    else $(XY.B).find('div.list:last').after(ListHtml(XY.J, XY.J.I, '')).find('div.list[name!=' + XY.iti + ']').css('display', 'none');
    $(XY.B).css('display', 'block').find('table.bar').css('display', 'none');
    $(XY.B).find('div.list[name!=' + XY.iti + ']').css('display', 'none');
    NEW();
}

function HideTick(n) { $('#EDIT').find('div.LocHide').find('span[name2=' + n + ']').css('background', XY.check).css('background-color', '#f77').attr('name', '1'); }
function Edit(T) {
    prolong();
    $(RepO).parent().find('span.prn').trigger('click');
    var N = XY.iti.split('|'), J = JSON[N[0]][N[2]], aL; Stringify(J);
    XY.id = N[0] + '|' + N[1];
    XY.J = J; XY.L = ListId(XY.iti);
    XY.LblAction = T.toUpperCase();
    $('#head').find('span.Tit').html(T + ' ' + propreq[XY.It]);
    aPts = new Array(), aPts[0] = new Array(), aPts[1] = new Array(), aPtsClicks = new Array(), aPstCntIds = new Array('', '');
    aPtsClicks[0] = new Array(); aPtsClicks[1] = new Array(); aPtsClicks[11] = new Array(); aPstCntIds[11] = '';
    XY.inCalendar = new Array();
    EditStart(1);
    document.title = "EACH:" + T + " " + Capital1(propreq[XY.It]);
    XY.EditStart = 1;
    if (XY.It == 'p') {//street number/picture      | street name/map       | our Company/pdf
        var LocOptionsP = '<div class=ErrorSum name=0></div><div class=LocHide><b>Don’t show&nbsp;</b><span name2=1>our Company/pdf</span><span name2=2>street name/map</span><span name2=4>street number/picture</span></div>'; //<div style="clear:both"></div>
        $('#EDIT').html('<fieldset id="PropLoc"></fieldset><fieldset id="Type"></fieldset><fieldset id="Tenure"></fieldset><fieldset id="Size" ></fieldset><fieldset id="DescriptionClient"></fieldset><div style="display:block;clear:both;height:20px;font-weight:bold;margin-left:5px;padding-left:15px" class=summary><div style="padding-top:3px;height:20px"><font>6</font>Summary</div></div>' + LocOptionsP).find('fieldset').css('display', 'block').css('float', 'left');
        $('#PropLoc').html(aPropFieldset[0]).find('input').change(function() { PropLocRewrite(); });
        $('#PropLoc').find('input[s=1]').keyup(function() { Address0(); }).bind('paste', function() { Address0(); }); 
        $('#propSearchHelp').html(arPropSearchHelp[5]);
        $('#Size').html(aPropFieldset[1]).find('input').focus(function() { $(this).select(); });
        $('#Tenure').html(aPropFieldset[3]);
        $('#Rateable').keyup(function() { if (!IsNumeric($(this).val())) { alert('must be numeric!'); $(this).val('0').focus(); return; }; if ($('#rentperiod').val() != '0') return; $('#Payable').val(parseFloat(parseFloat($(this).val()) * 0.436)); });
        $('#serviceCharge').change(function() { if (!IsNumeric($(this).val())) { alert('must be numeric!'); $(this).val('0').focus(); return; }; XY.flServiceCharge = $(this).val(); });
        $('#Payable').keyup(function() { if (!IsNumeric($(this).val())) { alert('must be numeric!'); $(this).val('0').focus(); return; }; XY.flRatesPayable = $(this).val(); if ($('#rentperiod').val() != '0') return; $('#Rateable').val(parseFloat(parseFloat($(this).val()) / 0.436)); });
        $('#DescriptionClient').html(aPropFieldset[4]);
        aL = J.Lc.split('|'); //StreetNumber|postcode|street|CentreEstate|townCity|suburbLocality|buildingNumber|building|CTIDs        
        $('#centreestate').val(aL[3]); $('#postcode').val(aL[1]); $('#buildingnumber').val(aL[6]); $('#building').val(aL[7]);
        $('#streetnumber').val(aL[0] == aL[2] ? "" : aL[0]); $('#street').val(aL[2]); $('#suburblocality').val(aL[5]); $('#towncity').val(aL[4]);
        aL = J.Rn.split('|');
        XY.flPeriod = aL[1]; XY.flServiceCharge = 0; XY.flRatesPayable = 0; XY.flRent = 0;
        if (parseFloat(aL[3]) > 0) $('#priceMin').val(addCommas(aL[3]));
        if (parseFloat(aL[2]) > 0) { $('#rentMin').val(addCommas(aL[2])); XY.flRent = addCommas(aL[2]); }
        $('#rentperiod').val(aL[1]); //.trigger('change');
        if (parseFloat(aL[4]) > 0) $('#Rateable').val(addCommas(aL[4]));
        if (parseFloat(aL[5]) > 0) { $('#Payable').val(addCommas(aL[5])); XY.flRatesPayable = addCommas(aL[5]); }
        if (parseFloat(aL[6]) > 0) { $('#serviceCharge').val(addCommas(aL[6])); XY.flServiceCharge = addCommas(aL[6]); }
        if (parseFloat(aL[7]) > 0) $('#estateCharge').val(addCommas(aL[7]));
        if (aL[8].length > 0) { $('#AuctionDate').val(aL[8]); $('#AuctionYes').attr('checked', true); }
        $('#NewLeaseAvail').attr('checked', aL[9] != '0');
        if (aL[10].length > 0) $('#dateLeaseEnd').val(aM[parseInt(aL[10].substring(3, 5)) - 1] + '.' + aL[10].substring(6, 10));
        if (aL[11].length > 0) $('#TenantLeaseBreakDate').val(aM[parseInt(aL[11].substring(3, 5)) - 1] + '.' + aL[11].substring(6, 10));
        if (aL[12].length > 0) $('#LandlordLeaseBreakDate').val(aM[parseInt(aL[12].substring(3, 5)) - 1] + '.' + aL[12].substring(6, 10));
        if (XY.propfind == 0) { XY.propfind++; scLoad('http://www.each.co.uk/JSON/EACH/files/propsearch.js' + XY.Reload); }
    }
    else {
        var LocOptionsR = '<div class=ErrorSum  name=0></div><div class=LocHide><b>Don’t show&nbsp;</b><span name2=1>our Company/pdf</span></div>';
        $('#EDIT').html('<fieldset id="Type"></fieldset><fieldset id="Size"></fieldset><fieldset id="Location"></fieldset><fieldset id="Tenure" ></fieldset><fieldset id="DescriptionClient"></fieldset><div style="display:block;clear:both;height:20px;font-weight:bold;margin-left:3px;padding-left:15px" class=summary><div style="padding-top:3px;height:20px"><font>6</font>Summary</div></div>' + LocOptionsR).find('fieldset').css('display', 'block');
        $('#Size').html(aReqFieldset[1]); $('#Location').html(aReqFieldset[5]); $('#Tenure').html(aReqFieldset[3]);
        $('#DescriptionClient').html(aReqFieldset[4]);
        $('#LondonCentralClick').html('Click here to select Central London Areas').css('color', '').click(function() {
            if ($('#LondonCentralClick').html() == 'Click here to select Central London Areas') {
                ReqLocOff('London'); RegMulti();
                $('#LondonCentral').css('display', 'block');
                $('#LondonCentralClick').html('deselect Central London Areas').css('color', '#f00').attr('disabled', false);  //.css('height', '10px');
                if (XY.EditStart == 1) return;
                aL = XY.J.Lc.split('|');
                XY.J.Lc = aL[0] + '|' + londonCentral + '|' + aL[2] + '|' + aL[3] + '|' + aL[4] + '|' + aPstCntIds[11] + '|' + aL[6] + '|' + aL[7];
                ReqLocRewrite();
            }
            else {
                $('#LondonCentralClick').html('Click here to select Central London Areas').css('color', ''); //.css('height', '25px');
                ReqLoc('');
            }
        });
        $('#LondonBlock,#LondonCentral').css('display', 'none');
        $('#Street').find('textarea').val(XY.ExpStreet).css('font-size', '9px').css('color', 'green');
        $('#Location').find('a').mouseover(function() { $(this).css('opacity', 0.5); }).mouseout(function() { $(this).css('opacity', ''); });
        $('#RegionButton').mouseover(function() { $(this).css('opacity', 0.5); }).mouseout(function() { $(this).css('opacity', ''); }
			               ).click(function() {
			                   if ($('#RegionButton').html() == 'Click here to select REGIONS/COUNTIES') {
			                       RegMulti(); RegidsCnts(); $('#RegionButton').html('deselect REGIONS/COUNTIES').css('color', '#f00').attr('disabled', false);
			                   }
			                   else {
			                       $('#RegionButton').html('Click here to select REGIONS/COUNTIES').css('color', ''); ReqLoc('');
			                   }
			               });
        $('#SizeUnit').html('<span><input type="radio" name2="2" value="2" checked="checked" />sqft</span><span><input name2="1" type="radio" value="1" />sqm</span><span><input name2="4" type="radio" value="4" />acres&nbsp;</span><span><input type="radio" name2="8" value="8" />hectares</span>'
		             ).find('span').slice(2, 4).css('display', 'none');
        $('#SizeUnit').find('input').attr("name", "unit");
        $('#Size').find('table').mouseover(function() { $(this).css('opacity', 0.5); }).mouseout(function() { $(this).css('opacity', ''); }).click(function() {
            if ($(this).find('td.IntExt').html().indexOf('Internal') > -1) {
                $(this).find('td.IntExt').html('&nbsp;External');

                $('#SizeUnit').find('span').css('display', 'inline-block');
                XY.J.Sz = '|||' + $('#Size').find('input[name=unit][checked=1]').val() + '|' + CommaStrip($('#SizeMin').val()) + '|' + CommaStrip($('#SizeMax').val());
            }
            else {
                $(this).find('td.IntExt').html('&nbsp;Internal');
                $('#SizeUnit').find('span').slice(2, 4).css('display', 'none');
                XY.J.Sz = $('#Size').find('input[name=unit][checked=1]').val() + '|' + CommaStrip($('#SizeMin').val()) + '|' + CommaStrip($('#SizeMax').val()) + '|||';
            }
            EditSizeBox();
            $('#SizeUnit').find('input').mouseover(function() { $(this).parent().css('color', '#777'); }).mouseout(function() { $(this).parent().css('color', '#000'); });
        });
        $('#Location').find('textarea[name=Town]').keyup(function(evt) {
            sCR = $(this).val();
            evt = evt || window.event;
            if (evt.which == 13 || evt.keyCode == 13) {
                sCR = sCR.replace(/[\r\n]/i, ",");
                $(this).html(sCR).val(sCR);
            }
            if ($(this).parent().attr('id') == 'Town') {
                aLetter = $(this).val().split(',');
                Letter = trim(aLetter[aLetter.length - 1]);
                if (Letter.length > 1) {
                    if (LetterFull != Letter) {
                        LetterFull = Letter;
                        Letter = Letter.substr(0, 1).toUpperCase();
                        $('#Town').find('span:last').html('');
                        if (aTs[Letter.charCodeAt(0)] == undefined) scLoad('http://www.4prop.com/JSON/Utilities/lists/towns/c' + Letter + '.js');
                        else jsPTw(aTs[Letter.charCodeAt(0)]);
                    }
                }
            }
        });
        $('#Location').find('textarea').change(function() {
            aL = XY.J.Lc.split('|');
            if ($(this).val().length > 0) {                //ReqLocOff($(this).attr('name'));                
                if ($(this).attr('name') == 'Postcode') {
                    ReqLocOff($(this).attr('name'));
                    XY.J.Lc = aL[0] + '|' + aL[1] + '|' + aL[2] + '|' + $(this).val() + '|' + aL[4] + '|' + aL[5] + '|' + aL[6] + '|' + aL[7];
                    ReqLocRewrite();
                }
                else if ($(this).attr('name') == 'Street') {
                    ReqLocOff($(this).attr('name'));
                    XY.J.Lc = aL[0] + '|' + aL[1] + '|' + aL[2] + '|' + aL[3] + '|' + $(this).val() + '|' + aL[5] + '|' + aL[6] + '|' + aL[7];
                    ReqLocRewrite();
                }
                else if ($(this).attr('name') == 'Map') {
                    XY.AreaDesc = $(this).val();
                    if (XY.ReqLoc != 'Map') AreaMap();
                    $(this).val(XY.AreaDesc);
                    XY.J.Lc = XY.AreaDesc + '|' + aL[1] + '|' + aL[2] + '|' + aL[3] + '|' + aL[4] + '|' + aL[5] + '|' + aL[6] + '|' + aL[7];
                    ReqLocRewrite();
                }
            }
            else {
                if ($(this).attr('name') == 'Street') XY.J.Lc = aL[0] + '|' + aL[1] + '|' + aL[2] + '|' + aL[3] + '||' + aL[5] + '|' + aL[6] + '|' + aL[7];
                ReqLoc($(this).attr('name'));
            }
        });
        aL = J.Lc.split('|');
        if (aL[4].length > 0) {
            $('#Street').find('textarea').val(aL[4]);
            ReqLocOff('Street');
        }
        if (aL[0].length > 0) {
            $('#Map').find('textarea').val(aL[0]);
            AreaMap();
        }
        else {
            if (aL[1].length > 0) $('#LondonCentralClick').trigger('click');
            else if (aL[2].length > 0) {
                $('#Town').find('textarea').val(aL[2] + ',');
                ReqLocOff('Town');
            }
            else if (aL[3].length > 0) {
                $('#Postcode').find('textarea').val(aL[3]);
                ReqLocOff('Postcode');
            }
            else if (aL[5].length + aL[7].length > 0) {
                RegMulti();
                $('#RegionButton').html('deselect REGIONS/COUNTIES').css('color', '#f00').attr('disabled', false);
            }
        }
        $('#Street,#Map,#Postcode').find('textarea').keyup(function() { Multiline($(this)); });
        aL = J.Rn.split('|');
        if (parseFloat(aL[3]) > 0) $('#rentMax').val(addCommas(aL[3]));
        if (parseFloat(aL[2]) > 0) $('#rentMin').val(addCommas(aL[2]));
        $('#rentperiod').val(aL[1]);
        if (parseFloat(aL[5]) > 0) $('#priceMax').val(addCommas(aL[5]));
        if (parseFloat(aL[4]) > 0) $('#priceMin').val(addCommas(aL[4]));
        $('#Town').find('textarea').focus(function() { if ($(this).val() == XY.ExpTowns) $(this).val('').focus(); });
        $('#Postcode').find('textarea').focus(function() { if ($(this).val() == XY.ExpPcs) $(this).val('').focus(); });
        $('#Street').find('textarea').focus(function() { if ($(this).val() == XY.ExpStreet) $(this).val('').focus(); });
        $('#Map').find('textarea').focus(function() { if (XY.ReqLoc != 'Map') AreaMap(); });
    }
    $('#ClientName').change(function() {
        XY.J.Cn = $(this).val();
        if (XY.It == 'r') ReqListClient(ListId(XY.iti));
        if (XY.J.Cn.length > 0) $(XY.L).find('div.block2').find('div.cln').html('Client: <b>' + XY.J.Cn + '</b>');
    });

    $('#EDIT').find('div.LocHide').find('span').attr('name', '0').mouseover(function() { $(this).css('opacity', 0.5); }).mouseout(function() { $(this).css('opacity', ''); }
            ).click(function() {
                var n = parseInt($(this).attr('name2'));
                if ($(this).attr('name') == '0') {
                    HideTick(n);
                    J.H += n;
                    if (n == 2 && (J.H & 4) == 0) { J.H += 4; HideTick(4); }
                    if (n == 1) $(XY.L).find('div.Pdf').css('opacity', 0.7).find('tr.files').find('td').slice(0, 1).html('<div class=NoSee>other Agents won\'t see your attachments</div>');
                }
                else {
                    $(this).css('background', "url('http://www.4prop.com/JSON/images/common/Rolls/checkNo1.png') no-repeat left top").css('background-color', '').attr('name', '0');
                    J.H -= n;
                    if (n == 1) $(XY.L).find('div.Pdf').css('opacity', '').find('tr.files').find('td').slice(0, 1).html(''); ;
                }
                $(XY.L).find('div.block2').find('.Owner').html(htmlOwners(J, 0)).find('font').each(function() { $(this).css('opacity', $(this).attr('name')) });
                if (retA(XY.It) == 'p') {
                    $(XY.L).find('.Location').html(htmlLoc(XY.J)); //Fading()
                    $(XY.L).find('td.st').html(LsPLc(XY.J, 14, 8)).find('font').each(function() { $(this).css('opacity', $(this).attr('name')); });
                    ImgCh(XY.J, XY.L);
                    if (XY.J.gmap != undefined && XY.J.gmap != "") {
                        $(XY.L).find('div.Map').find('div.NoSee').css('display', 'none');
                        scLoad("http://maps.google.com/maps/api/js?sensor=false&callback=iGMap0");
                    }
                }
                NoSee(XY.L, XY.J);
            });
    J.H = parseInt(J.H);
    if (NoCompanyPDF(J.H)) HideTick(1); if (NoStreetNum(J.H)) HideTick(4); if (NoStreet(J.H)) { HideTick(2); if (!NoStreetNum(J.H)) { J.H += 4; HideTick(4); } }

    $('#ClientName').val(J.Cn);
    $('#Amenities').val(J.A.replace('^', (J.A.indexOf('^') == 0 ? '' : '\n')).replace(new RegExp(", ", "g"), "\n").replace(new RegExp(",", "g"), "\n")
        ).change(function() {
            XY.J.A = $(this).val().replace(new RegExp("\n", "g"), ",");
            $(ListId(XY.iti)).find('div.block2').find('.Size').html(htmlSizeP(XY.J, 0) + htmlTenure(XY.J) + XY.J.A.replace('^', '<br>').replace(/,/g, '<br>'));
        });
    Multiline('#Amenities');
    $('#Amenities').bind('paste', function(e) { J.A = $(this).val(); Multiline(this); });
    $('#description').bind('paste', function(e) { J.D = $(this).val(); $(XY.L).find('.Desc').html(J.D); Multiline(this); }).keyup(function() { J.D = $(this).val(); $(XY.L).find('.Desc').html(J.D); Multiline(this); });
    $('#description').html(J.D).change(function() { J.D = $(this).val(); $(XY.L).find('.Desc').html(J.D); });
    $('#Amenities,#description').trigger('keyup');
    aL = J.Sz.split('|');
    $('#SizeMin').val(addCommas(aL[1])); $('#SizeMax').val(addCommas(aL[2]));
    $('#Size').find('input[name=unit][name2=' + aL[0] + ']').attr('checked', true);
    //try {if(XY.J.tp==undefined)XY.J.tp = XY.J.T.split('|')[0]; } catch (aa) { }
    $('#SizeMin,#SizeMax').focus(function() {
        if (XY.It == 'p' && (XY.J.tp == '8' || XY.J.tp == '2' || XY.J.tp == '4')) {
            $('#Size').find('div.Floors').parent().attr('name', XY.iti);
            setTimeout("ShowFloor('" + XY.iti + "')", 50);
            setTimeout("$(XY.L).find('div.Floors').find('span.close').trigger('mouseout')", 200);
        }
    });
    if (parseFloat(aL[4]) + parseFloat(aL[5]) > 0 || aL[6] == "1") {
        if (J.It == 'r') { $('#SizeMin').val(addCommas(aL[4])); $('#SizeMax').val(addCommas(aL[5])); $('#Size').find('table').trigger('click'); }
        else $('#SizeMine').val(addCommas(aL[4])); $('#SizeMaxe').val(addCommas(aL[5]));
        $('#Size').find('input[name=unite][name2=' + aL[3] + ']').attr('checked', true);
    }
    $('#Size').find('input[type=radio]').mouseover(function() { $(this).parent().css('color', '#777'); }).mouseout(function() { $(this).parent().css('color', '#000'); });
    $('#Size').find('input').change(function() {       // alert(111);
        if (XY.It == 'p') {
            var ue = $('#Size').find('input[name=unite][checked=1]').val();
            XY.J.Sz = $('#Size').find('input[name=unit][checked=1]').val() + '|' + CommaStrip($('#SizeMin').val()) + '|' + CommaStrip($('#SizeMax').val())
                + '|' + (ue == undefined ? '2' : ue) + '|' + CommaStrip($('#SizeMine').val()) + '|' + CommaStrip($('#SizeMaxe').val());
            $(XY.L).find('div.mnmx').find('select').val(XY.J.Sz.split('|')[0]);
            if (XY.J.tp == '2' || XY.J.tp == '4') fFloorsClick(XY.iti);
        }
        else {
            if ($('#Size').find('td.IntExt').html().indexOf('Internal') > -1)
                XY.J.Sz = $('#Size').find('input[name=unit][checked=1]').val() + '|' + CommaStrip($('#SizeMin').val()) + '|' + CommaStrip($('#SizeMax').val()) + '|||';
            else XY.J.Sz = '|||' + $('#Size').find('input[name=unit][checked=1]').val() + '|' + CommaStrip($('#SizeMin').val()) + '|' + CommaStrip($('#SizeMax').val());
        }
        EditSizeBox();
        if ($(this).val() != "0") $('#Size').find('div.Error').css('display', 'none');
    });
    $('#EDIT').find('input[type=text]').css('border', '1px solid #aae').css('background', '#fafffa').css('color', '#030').focus(function() { $(this).select(); });
    $('#Type').html(XY.hTypes.replace('xOrd', XY.It == 'p' ? '2' : '1'));
    V = '';
    for (var t = 1; t < orderTypes.length; t++) V += option.replace(/xValue/g, orderTypes[t]).replace('yValue', eval('jsPts.v' + orderTypes[t]));
    $('#Pts').html(V); //!= 'n'
    aL = J.Rn.split('|');

    $('#Tenure').attr('name', '0').find('div.dvclick').attr('name', '0').mouseover(function() { $(this).css('opacity', 0.5); }).mouseout(function() { $(this).css('opacity', ''); }
		  ).click(function() {
		      var cf = parseFloat($(this).attr('name2')), tenure = Number($('#Tenure').attr('name'));
		      if (parseFloat($(this).attr('name')) == 0) {
		          tenure = tenure + Number($(this).find('input').attr('checked', true).val());
		          $(this).css('font-weight', 'bold').attr('name', 1);
		      }
		      else {
		          tenure = tenure - Number($(this).find('input').attr('checked', false).val());
		          $(this).css('font-weight', '').attr('name', 0);
		          $('#Tenure').find('span.fr').slice(cf, cf + 2).css('display', 'none');
		          if (cf == 0) $('#Tenure').find('div.TenureADD').slice(0, 1).css('display', 'none');
		          else if (cf == 2) $('#Tenure').find('div.TenureADD').slice(1, 3).css('display', 'none');
		      }
		      $('#Tenure').attr('name', tenure);
		      if ((tenure & 12) > 0) {
		          $('#Tenure').find('span.fr').slice(0, 2).css('display', 'block');
		          $('#Tenure').find('div.TenureADD').slice(0, 1).css('display', 'block');
		      }
		      if ((tenure & 3) > 0) {
		          $('#Tenure').find('span.fr').slice(2, 4).css('display', 'block');
		          $('#Tenure').find('div.TenureADD').slice(1, 3).css('display', 'block');
		      }
		      if (XY.EditStart == 1) return;
		      if (tenure > 0) $('#Tenure').find('div.Error').css('display', 'none'); else MissedTnr('Please check some tenure');
		      EditTenure(tenure);
		  }
    ).each(function() { if (parseFloat($(this).find('input').val()) & parseFloat(aL[0])) $(this).trigger('click'); })
    $('#Tenure').find('input,select').focus(function() { $(this).select(); }).change(function() {
        EditTenure(J.Rn.split('|')[0]);
        $('#Tenure').find('span.units').html('&nbsp;' + $('#rentperiod').find('option:selected').html());

        $('#EDIT').find('span.floorUnits').find('select').val($('#rentperiod').val()); //.trigger('change');
    });
    $('#rentperiod').trigger('change');
    $('#Amenities').keyup(function(evt) {
        $(this).css('background', '#fff').attr('name', 1); evt = evt || window.event; LetterAm = $(this).val(); gPsTs2(evt.which || evt.keyCode);
        J.A = $(this).val(); // alert(J.A);
        $(XY.L).find('div.block2').find('.Size').html(htmlSizeP(XY.J, 0) + htmlTenure(XY.J) + XY.J.A.replace('^', '<br>').replace(/,/g, '<br>')); Multiline(this);

    });
    XY.Advertise = 1;
    if (T == 'Edit') {
        if (J.S == 7) XY.Advertise = 0;
        SaveButton();
    }
    if (IsAdmin > 0) {
        $('#BillDate').css('display', 'inline-block').html('Bill&nbsp;date&nbsp;<input id=billdate title="click to change date" onfocus="showCalendarControl(this)" value="' + todayDMY + '" name="ddmmyy" />'
        ).find('input').mouseover(function() { $(this).css('opacity', 0.5); }).mouseout(function() { $(this).css('opacity', ''); });
    }
    $('#Pts').val(J.tp).trigger('change');
    if (J.T.split('|')[1].length > 0) {
        J.tps = J.T.split('|')[1].split(',');
        if (J.tps.length == 0 || (J.tps.length == 1 && J.tps[0].length == 0)) $('#PtsShow').find('div.button').slice(0, 1).trigger('click');
        else for (var t = 0; t < J.tps.length; t++) $('#PtsShow').find('div.button[name=' + J.tps[t] + ']').trigger('click');
    }
    else if (T == 'Edit' || T == 'Copy') $('#PtsShow').find('div.button').slice(0, 1).trigger('click');
    setTimeout(function() { window.scroll(0, 0); }, 1000);
}
function NewProp() {
    if ($('#centreestate').val().length == 0) $('#centreestate').val('Shopping Centre, Retail Pk, Ind Est').attr('class', 'Here').css('color', '#7FBF9D').focus(function() { if ($(this).val() == 'Shopping Centre, Retail Pk, Ind Est') $(this).val('').focus().attr('class', '').css('color', ''); });
    if ($('#postcode').val().length == 0) $('#postcode').val('postcode').attr('class', 'Here').css('color', '#7FBF9D').focus(function() { if ($(this).val() == 'postcode') $(this).val('').focus().attr('class', '').css('color', ''); });
    if ($('#street').val().length == 0) $('#street').val('street').attr('class', 'Here').css('color', '#7FBF9D').focus(function() { if ($(this).val() == 'street') $(this).val('').focus().attr('class', '').css('color', ''); });
    if ($('#suburblocality').val().length == 0) $('#suburblocality').val('only suburbs').attr('class', 'Here').css('color', '#7FBF9D').focus(function() { if ($(this).val() == 'only suburbs') $(this).val('').focus().attr('class', '').css('color', ''); });
    if ($('#towncity').val().length == 0) $('#towncity').val('city / town').attr('class', 'Here').css('color', '#7FBF9D').focus(function() { if ($(this).val() == 'city / town') $(this).val('').focus().attr('class', '').css('color', ''); });
    if ($('#serviceCharge').val().length == 0) $('#serviceCharge').val('Service Charge').attr('class', 'Here').css('color', '#7FBF9D').focus(function() { if ($(this).val() == 'Service Charge') $(this).val('').focus().attr('class', '').css('color', ''); });
    if ($('#Payable').val().length == 0) $('#Payable').val('Rates Payable').attr('class', 'Here').css('color', '#7FBF9D').focus(function() { if ($(this).val() == 'Rates Payable') $(this).val('').focus().attr('class', '').css('color', ''); });
    if ($('#rentMin').val().length == 0) $('#rentMin').val('rent').attr('class', 'Here').css('color', '#7FBF9D').focus(function() { if ($(this).val() == 'rent') $(this).val('').focus().attr('class', '').css('color', ''); });
    XY.LtLnSet = 0;
}
function NEW() {//street only suburbs city / town
    if ($('#EDIT').html() == '') return;
    if (XY.It == 'r') ReqLoc(''); else NewProp();
    XY.J.NoMove = 1; XY.flPeriod = $('#rentperiod').val();
    XY.flServiceCharge = 0; XY.flRatesPayable = 0; XY.flRent = 0;    //XY.J.tp = XY.tp;
    SaveButton();
    if (XY.LblAction == 'NEW') $('#Amenities').val(XY.ExpAm);
    showBlock(XY.iti);
    $('#RESULT').css('display', 'block');
}
function SaveGoBottom() {
    //'SAVE ' + XY.LblAction + ' ' + propreq[XY.It]
    $('#explain').find('.aGO').html('SAVE ' + (XY.Advertise == 1 ? ', ADVERTISE, open window to email,' : '') + ' and see matches');
    $('#head').find('.aGO').html((XY.LblAction == 'EDIT' ? 'SAVE and see matches' : 'SAVE, NO ADVERTISE, see matches')); //XY.LblAction    
}
function SaveButton() {
    $('#explain').css('display', 'block').html('<fieldset id="Save"></fieldset><a style="margin-top:10px;margin-bottom:10px;display:block" class="aGO"></a>'
                ).find('fieldset').css('display', 'block').css('color', '#113');
    //+ hManage
    fSaveEdit($('#explain').find('.aGO'));
    $('#explain').find('legend').css('cursor', 'pointer').mouseover(function() { $(this).css('opacity', 0.5); }).mouseout(function() { $(this).css('opacity', ''); }
        ).click(function() {
            if ($('#explain').find('.Mng').attr('name') != '0')
                $('#explain').find('.Mng').attr('name', '0').slideUp('fast');
            else {
                $('#explain').find('.Mng').attr('name', '1').slideDown('fast');
                //alert('exp');
                setTimeout(function() { offsetY($('#explain')); }, 300);
            }
        });
    //$('#head').find('.aGO').html('Save ' + XY.LblAction + ' ' + ' ' + propreq[XY.It]); //#explain,
    SaveGoBottom();
    $('#explain').find('.aGO').click(function() { AddSave(1); })
    $('#Save').html(hSummary).css('display', 'block').find('div.L').find('a').mouseover(function() { $(this).css('opacity', 0.5); }).mouseout(function() { $(this).css('opacity', ''); });
    $('#badvertise').click(function() {
        if (XY.Advertise == 1) {
            $('#badvertise2').html('This will NOT be advertised');
            $(this).parent().css('background', XY.uncheck);
            XY.Advertise = 0;
            XY.J.S = 7;
            $('#balert2,.b4prop2,#bace2').css('display', 'none');
            $('#balert,.b4prop,#bace').parent().css('display', 'none');
        }
        else {
            $('#badvertise2').html('Advertising');
            $(this).parent().css('background', XY.check);
            XY.Advertise = 1;
            XY.J.S = 0;
            $('#balert2,.b4prop2,#bace2').css('display', 'inline-block');
            $('#balert,.b4prop,#bace').parent().css('display', 'inline-block');
            if (XY.It == 'r') { $('#b4prop').parent().css('display', 'none'); $('#b4prop2').css('display', 'none'); }
        }
        //$('#explain').find('.aGO').html('Save ' + XY.LblAction + ' ' + propreq[XY.It] + (XY.Advertise == 1 ? ', open window to EMAIL,' : '') + ' and view matches');
        SaveGoBottom();
        cssStatus(0, XY.L, XY.J);
    })
    $('#bace').click(function() {
        if (XY.ACE == 1) {
            $('#bace2').html('NO email to Agents');
            $(this).parent().css('background', XY.uncheck);
            balertChange($('#balert').trigger('click').find('select').val('0'));
            XY.AlertListing = 0;
            XY.ACE = 0;
        }
        else {
            $('#bace2').html('send ACE email NOW');
            $(this).parent().css('background', XY.check);
            XY.ACE = 1;
        }
        set_cookie(_gNid + 'bac', '' + XY.ACE);
    })
    $('.b4prop').click(function() {
        if ($(this).find('select').length == 0) {
            $(this).html('<select style="margin-top:3px" onchange="b4propChange(this)"><option value="1">tomorrow</option><option value="2">in 2 days</option><option value="4">in 4 days</option><option value="7" selected>in 1 week</option><option value="14">in 2 weeks</option><option value="255">never</option></select>');
            $('#' + $(this).attr('id') + '2').css('padding-top', '4px');
        }
    })
    $('#balert').click(function() {
        if ($(this).find('select').length == 0) {
            $(this).html('<select style="margin-top:3px" onchange="balertChange(this)"><option value="0">NOW</option><option value="1">in 1 day</option><option selected value="2">in 2 days</option><option value="7">in 1 week</option><option value="14">in 2 weeks</option><option value="255">never</option></select>');
            $('#balert2').css('padding-top', '4px');
        }
    })
    if (XY.It == 'r') { $('.b4prop').parent().css('display', 'none'); $('.b4prop2').css('display', 'none'); }
    if (XY.Advertise == 0) {
        $('#badvertise2').html('This will NOT be advertised');
        $('#badvertise').parent().css('background', XY.uncheck);
        $('#balert2,.b4prop2,#bace2').css('display', 'none');
        $('#balert,.b4prop,#bace').parent().css('display', 'none');
    }
    else if (XY.LblAction == 'EDIT') {
        $('#Save').find('.b4prop').trigger('click').find('select').val(0);
        XY.PublicListing = '1'; XY.PublicListingOther = '1'; XY.PublicListingOtherAgents = '1';
        try {
            var a4prop = XY.J.R.split('|')[XY.J.R.split('|').length - 2].split('*'), y = (new Date()).getFullYear() + 1;
            if (a4prop[0].length > 5 && a4prop[0].split('.')[2] > y) PublicProp(0);
            if (a4prop[1].length > 5 && a4prop[1].split('.')[2] > y) PublicProp(1);
            if (a4prop[2].length > 5 && a4prop[2].split('.')[2] > y) PublicProp(2);
        } catch (es) { }
    }
    else if (XY.It == 'p') {
        if ((XY.PublicProp & 4) > 0) PublicProp(0);
        if ((XY.PublicProp & 2) > 0) PublicProp(1);
        if ((XY.PublicProp & 1) > 0) PublicProp(2);
    }
    /*if (XY.J.S == 7) 
    $('#badvertise').trigger('click');    
    else if (XY.LblAction == 'EDIT') {
    $('#balert2,.b4prop2,#bace2').css('display', 'none');
    $('#balert,.b4prop,#bace').parent().css('display', 'none');
    }
    */
    $('#Amenities').focus(function() { if (XY.EditStart == 0 && $(this).val() == XY.ExpAm) $(this).val(''); });
    setTimeout(function() { XY.EditStart = 0; }, 300);
    if (get_cookie(_gNid + 'bac') == '0') $('#bace').trigger('click');
}
function PublicProp(i) {
    $('.b4prop').slice(i, i + 1).trigger('click').find('select').val(255).trigger('change');
    if (i == 0) XY.PublicListing = '255';
    else if (i == 0) XY.PublicListingOther = '255';
    else XY.PublicListingOtherAgents = '255';
}
function Multiline(o) {
    setTimeout(function() {
        try {
            multiline = parseInt($(o).val().length / 55); multiline += $(o).val().split('\n').length;
            if (multiline < 2) multiline = 2;
            if ($(o).attr('multiline') != (multiline + 1)) $(o).attr('multiline', multiline + 1).css('height', (15 * multiline)).focus(); //setCursorPosition(multiline + 1)            
        } catch (e) { }
    }, 100);
}
function ReqLoc(s) {
    if (s == 'Street')
        $('#Street').css('background', '').css('font-weight', '').find('textarea').css('font-size', '9px').css('background', '').val(XY.ExpStreet).attr('multiline', 2); //.css('height', 30);
    else {
        XY.ReqLoc = 'None';
        $('#London,#Town,#Postcode,#Region,#Map').css('background', '').css('font-weight', '').find('textarea').css('font-size', '').css('background', '').attr('multiline', 2); //.css('height', 30);
        $('#Town').find('textarea').attr('disabled', false).val(XY.ExpTowns).css('font-size', '9px').css('color', 'green');
        $('#Postcode').find('textarea').attr('disabled', false).val(XY.ExpPcs).css('font-size', '9px').css('color', 'green');
        $('#Map').find('textarea').attr('disabled', false).val(XY.ExpMap).css('font-size', '10px').css('color', 'green').attr('multiline', 3);
        $('#LondonCentralClick').html('Click here to select Central London Areas').css('background', '').attr('class', '');
        $('#RegionButton').html('Click here to select REGIONS/COUNTIES').attr('class', '');
        $('#aMap').html('open map').attr('class', '');
        $('#TownList,#RgsMulti,#RgsMulti2,#MapWrap,#LondonBlock,#LondonCentral,span.barea').css('display', 'none');
        $('#RegionButton').css('display', 'block');
        $('#LondonCentralClick,#aMap,#RegionButton').attr('disabled', false);
        XY.J.Lc = '||||' + $('#Street').find('textarea').val().replace(XY.ExpStreet, '') + '|||';
    }
    ReqLocRewrite();
}
function ReqLocOff(n) {
    if (n != 'Street') $('#London,#Town,#Postcode,#Region,#Map').css('background', '').css('font-weight', '').find('textarea').css('font-size', '').css('background', '').css('border', '');
    $('#' + n).css('background', cssClickeCol).css('font-weight', 'bold').find('textarea').css('font-size', '1em').css('background', '#dfd').css('border', '1px solid #9e9');
    Multiline($('#' + n).find('textarea'));
    if (n == 'Street') return;
    XY.ReqLoc = n;
    $('#LondonCentralClick,#aMap,#RegionButton').attr('disabled', true);
    $('#Location').find('textarea.loc[name!=' + n + ']').val('You cannot make an entry here, unless you delete ' + n).attr('disabled', true);
    $('#RgsMulti,#RgsMulti2').css('display', (n == 'Region' ? 'block' : 'none'));
    $('#MapWrap,span.barea').css('display', n == 'Map' ? 'block' : 'none');
}
function ReqListClient(L) { $(L).find('td.cn').html(Fading(XY.J.Cn, 10, 5, '')).find('font').each(function() { $(this).css('opacity', $(this).attr('name')) }); }
var multiline;
function retDateMMyyyy(mmYYYY) { if (mmYYYY == 'mm.yyyy') return ''; return '01.' + aMd2[mmYYYY.split('.')[0]] + '.' + mmYYYY.split('.')[1]; }
function EditTenure(tenure) {
    if (XY.It == 'p') {
        XY.J.Rn = tenure + '|' + $('#rentperiod').val() + '|' + CommaStrip($('#rentMin').val().replace('rent', '')) + '|' + CommaStrip($('#priceMin').val()) + '|'
		                + CommaStrip($('#Rateable').val()) + '|' + CommaStrip($('#Payable').val().replace('Rates Payable', '')) + '|' + CommaStrip($('#serviceCharge').val().replace('Service Charge', '')) + '|'
		                + CommaStrip($('#estateCharge').val()) + '|' + $('#AuctionDate').val().replace('dd.mm.yy', '') + '|' + ($('#NewLeaseAvail').attr('checked') ? '1' : '0')
		                + '|' + retDateMMyyyy($('#dateLeaseEnd').val()) + '|' + retDateMMyyyy($('#TenantLeaseBreakDate').val())
		                + '|' + retDateMMyyyy($('#LandlordLeaseBreakDate').val());
        if (XY.LtLnSet == 0 && XY.EditStart == 0) {
            if ($('#postcode').val().replace('postcode', '') == '') {
                MissedLoc('Please populate Address - postcode');
            }
            else GoogleLatLng($('#postcode').val().replace('postcode', ''));
        }
    }
    else XY.J.Rn = tenure + '|' + $('#rentperiod').val() + '|' + CommaStrip($('#rentMin').val().replace('rent', '')) + '|' + CommaStrip($('#rentMax').val()) + '|' + CommaStrip($('#priceMin').val()) + '|' + CommaStrip($('#priceMax').val());
    XY.flPeriod = $('#rentperiod').val();
    if (IsNumeric($('#rentMin').val())) XY.flRent = CommaStrip($('#rentMin').val());
    htmlResize(XY.iti);
    $(XY.L).find('td.rn,td.cn').find('input').val(listRent(XY.J.Rn, XY.J.It));
}
function fPts(v) {
    try {
        aPstCntIds[0] = '';
        var V = $('#Pts').val();    //$('#Type').attr('name', V).attr('name2', '');   
        UNI = ADDbutton.replace(/xValue/g, '&nbsp;Select All').replace(/STYLE/, 'font-weight:bold;color:#000;text-align:left;padding-left:40px;padding-bottom:3px').replace(/xID/, '0');
        V = eval('jsPts2.v' + V).split('.');
        for (var c = 0; c < V.length; c++) UNI += ADDbutton.replace('xID', V[c]).replace(/xValue/g, eval('jsPts3.v' + V[c])).replace('ORDER', c % 2);
        $('#PtsShow').html(UNI).find('div.button').attr('style', 'width:45%;height:24px;padding-top:5px;text-align:left;padding-left:20px;background:#eee;color:#444;margin:2px;border:1px solid #ddd').slice(0, 1).css('width', '95%').css('height', '18px').css('padding-top', '1px');
        fButtons('#PtsShow', v, V, 0);
        if (XY.EditStart == 1) return;
        XY.J.tp = $('#Pts').val(); XY.J.T = XY.J.tp + '|'; XY.J.tps = '';
        $(XY.L).find('div[name=tp]').find('div.tp1').html(htmPSTIDs(XY.J));
        if (XY.It == 'r') $(XY.L).find('td.tps').html(Fading(htmPSTIDs(XY.J), 13, 5, '')).find('font').each(function() { $(this).css('opacity', $(this).attr('name')) });
        else {
            $('#Size').find(".Floors").css('display', 'none');
            XY.J.F = "";
            XY.flPeriod = 1; XY.flServiceCharge = 0; XY.flRatesPayable = 0;
        }
    } catch (e) { }    /*var dd = '', dd2; //memory    if (V == 0) {dd2 = aPstCntIds[11].split(',');for (var c = 0; c < dd2.length; c++)$('#' + aControlIds[v] + 'Show').find('div.button[name=' + dd2[c] + ']').css('background', cssClickeCol); }*/
}
function fButtons(id, v, V, add) {//
    $(id).slideDown('slow').find('div.button').mouseover(function() {
        if (aPtsClicks[v + add][$(this).attr('name')] % 2 == 1) return; $(this).css('background', '#ccc');
    }).mouseout(function() {
        if (aPtsClicks[v + add][$(this).attr('name')] % 2 == 1) return; $(this).css('background', '#eee');
    }).click(function() {
        if (aPtsClicks[v + add][$(this).attr('name')] == undefined) aPtsClicks[v + add][$(this).attr('name')] = 0;
        aPtsClicks[v + add][$(this).attr('name')] += 1;
        if (aPtsClicks[v + add][$(this).attr('name')] % 2 == 1) {
            $(this).find('input').attr('checked', true);
            $(this).css('background', cssClickeCol);
            if ($(this).attr('name') == 0) {
                $(id).find("div.button").css('background', cssClickeCol).each(function() { aPtsClicks[v + add][$(this).attr('name')] = 1; }
            ).find('input').attr('checked', true);
                if (add == 0) $(id).find("div.button:first").html('<input type=checkbox checked />&nbsp;Deselect All');
            }
            else {
                var selAll = true;
                $(id).find("div.button").slice(1, 22).each(
                function() {
                    try {
                        if (aPtsClicks[v + add][$(this).attr('name')] == undefined || parseFloat(aPtsClicks[v + add][$(this).attr('name')]) % 2 == 0) {
                            selAll = false;
                        }
                    }
                    catch (e) { selAll = false; }
                }
             )
                if (add == 0 && selAll) {
                    $(id).find("div.button:first").css('background', cssClickeCol).html('<input type=checkbox checked />&nbsp;Deselect All');
                    aPtsClicks[v + add][0] = 1;
                }
            }
            $('#Type').find('div.Error').css('display', 'none');
        }
        else {
            $(this).css('background', '#efe').find('input').attr('checked', false);
            if (add == 0) $(id).find("div.button:first").html('<input type=checkbox />&nbsp;Select All');
            if ($(this).attr('name') == 0) {
                $(id).find("div.button").css('background', '#eee').each(function() { aPtsClicks[v + add][$(this).attr('name')] = 0; }
                ).find('input').attr('checked', false);
                MissedTps('Please select some subtypes');
            }
            else {
                $(id).find("div.button:first").css('background', '#eee');
                aPtsClicks[v + add][0] = 0;
            }
        }
        var Val = '';
        aPstCntIds[v + add] = '';
        if (v == 1) { londonCentral = ''; LondonCentralDiv = ''; }
        if ($(this).attr('name') != 0) {//Central London
            $(id).find("div.button").each(
                function() {
                    if ($(id).find("div.button:first").attr('name2') != $(this).attr('name2')) {
                        if (aPtsClicks[v + add][$(this).attr('name')] % 2 == 1) {
                            aPstCntIds[v + add] += "," + $(this).attr('name');
                            if (v == 1) {
                                londonCentral += $(this).attr('name2') + ', ';
                                LondonCentralDiv += '<span name=' + $(this).attr('name') + ' class="spCentral"><a title="delete" class="del">-</a><span>' + $(this).attr('name2') + '</span></span>';
                            }
                        }
                    }
                }
             )
            if (add == 10) fCentralLondon();
        }
        if (v == 0) {
            XY.J.T = XY.J.T.split('|')[0] + '|' + aPstCntIds[0];
            $(XY.L).find('div.block2').find('div[name=tp]').find('div.tp1').html(htmPSTIDs(XY.J));
            if (XY.It == 'r') $(XY.L).find('td.tps').html(Fading(htmPSTIDs(XY.J), 13, 5, '')).find('font').each(function() { $(this).css('opacity', $(this).attr('name')) }); ;
        }
        else {
            aL = XY.J.Lc.split('|');
            XY.J.Lc = aL[0] + '|' + londonCentral + '|' + aL[2] + '|' + aL[3] + '|' + aL[4] + '|' + aPstCntIds[11] + '|' + aL[6] + '|' + aL[7];
            ReqLocRewrite();
        }
    });
    //alert(V);    return;
    if (V != 0) {
        if ($.browser.msie) {
            if ($.browser.version == 6)
                $(id).find('div.button').slice(1, 100).css('width', '45%').each(function() {
                    if (parseInt($(this).attr('name3')) % 2 == 0) $(this).css('float', 'right');
                })
            if ($.browser.version == 7) {
                $(id).find('div.button').slice(1, 100).css('width', '235px');
                $(id).find('div.button').slice(0, 1).css('width', '500px');
            }
        }
        else $(id).css('width', '');
    }
}
function fCentralLondon() {
    londonCentral = londonCentral.substring(0, londonCentral.length - 2);
    $('#LondonCentral').html(LondonCentralDiv).find('a.del').mouseover(function() { $(this).parent().css('opacity', 0.5); }).mouseout(function() { $(this).parent().css('opacity', 1); }
								  ).click(function() {
								      aPstCntIds[11] = (aPstCntIds[11] + ',').replace(',' + $(this).parent().css('display', 'none').attr('name') + ',', ',');
								      $('#LondonBlock').find('div.button[name=' + $(this).parent().attr('name') + ']').trigger('click').trigger('mouseout'); //html()
								  });
}
function RegPop(n) {
    //if (n == '5') return; //Wales
    if ($('#RgsMulti2').find('div.[name=' + n + ']').length == 0) {
        UNI = '<div name=' + n + ' style="padding-top:5px" name2=1 class=cnts>';
        V = eval('jsRgs2.v' + n).split('.');
        UNI += ADDbutton.replace(/xValue/g, '&nbsp;All ' + eval('jsRgs.v' + n)).replace(/STYLE/, 'font-weight:bold;text-align:left;padding-left:40px;padding-bottom:3px').replace(/xID/, 'r' + n);
        for (var c = 0; c < V.length; c++) UNI += ADDbutton.replace('xID', V[c]).replace(/xValue/g, eval('jsRgs3.v' + V[c])).replace('ORDER', c % 2);
        $('#RgsMulti2').find('div.cnts:first').before(UNI + '</div>');
        $('#RgsMulti2').find('div[name=' + n + ']').find('div.button').mouseover(function() { $(this).css('opacity', 0.7); }).mouseout(function() { $(this).css('opacity', ''); }
            ).click(function() {
                var s = $(this).attr('name'), all;
                if (aPtsClicks[1][s] == undefined) aPtsClicks[1][s] = 0;
                aPtsClicks[1][s] += 1;
                if (aPtsClicks[1][s] % 2 == 1) {
                    $(this).css('background', "#36a").css('color', '#ddd').find('input').attr('checked', true);
                    if (s.substring(0, 1) == 'r')
                        $(this).parent().find('div.button').css('background', "#36a").css('color', '#ddd').each(function() { aPtsClicks[1][$(this).attr('name')] = 1; $(this).find('input').attr('checked', true); });
                    else {
                        all = true;
                        $(this).parent().find('div.button').slice(1, 50).each(function() { if (aPtsClicks[1][$(this).attr('name')] == undefined || aPtsClicks[1][$(this).attr('name')] % 2 == 0) all = false; });
                        if (all == true) {
                            var r = $('#RgsMulti2').find('div[name=' + n + ']').find('div.button').slice(0, 1).attr('name'); //.substring(1,3);
                            if (aPtsClicks[1][r] == undefined || aPtsClicks[1][r] % 2 == 0) { aPtsClicks[1][r] = 1; $('#RgsMulti2').find('div[name=' + n + ']').find('div.button').slice(0, 1).css('background', "#36a").css('color', '#ddd').find('input').attr('checked', true); }
                        }; //
                    }
                    $('#RgsMulti').find('table').find('td[name=' + n + ']').attr('name2', '1').css('background', '#36a').css('color', '#ddd');
                }
                else {
                    $(this).css('background', '#B2CEFF').css('color', '#3C465E').find('input').attr('checked', false);
                    $('#RgsMulti2').find('div[name=' + n + ']').find('div.button').slice(0, 1).css('background', '#bdf').css('color', '#3C465E').find('input').attr('checked', false);
                    aPtsClicks[1]['r' + n] = 0;
                    if (s.substring(0, 1) == 'r') {
                        $(this).parent().find('div.button').css('background', '#B2CEFF').css('color', '#3C465E').each(function() { aPtsClicks[1][$(this).attr('name')] = 0; $(this).find('input').attr('checked', false); });
                        $('#RgsMulti').find('table').find('td[name=' + s.substring(1, s.length) + ']').attr('name2', '0').css('background', '#bdf').css('color', ''); ;
                    }
                    else {
                        all = false;
                        $(this).parent().find('div.button').each(function() { if (aPtsClicks[1][$(this).attr('name')] % 2 == 1) all = true; });
                        if (all == false) $('#RgsMulti').find('table').find('td[name=' + n + ']').attr('name2', '0').css('background', '#bdf').css('color', ''); ;
                    }
                }
                RegidsCnts();
            });
        $('#RgsMulti2').find('div[name=' + n + ']').find('div.button').attr('style', 'width:250px;height:24px;padding-top:4px;text-align:left;padding-left:20px;background:#B2CEFF;color:#3C465E;margin:1px').slice(0, 1).css('width', '521px').css('height', '18px').css('padding-top', '1px');
    }
    $('#RgsMulti2').find('div.[name=' + n + ']').slideDown();
}
function RegidsCnts() {
    if (XY.EditStart == 1) return;
    aL = XY.J.Lc.split('|'); //
    var rids = '', cnts = '';
    $('#RgsMulti2').find('div.cnts[name2=1]').each(function() {//regions
        if ($(this).attr('name') != undefined && $(this).find('input').slice(0, 1).attr('checked')) {
            rids += ',' + $(this).attr('name');
        }
        else {
            $(this).find('div.button').slice(1, 50).each(function() {
                if ($(this).find('input').attr('checked')) cnts += ',' + $(this).attr('name');
            });
        }
    });
    if ($('#RgsMulti').find('table').find('td[name=5]').attr('name2') == '1') rids += ',5'; //Wales
    XY.J.Lc = aL[0] + '|' + aL[1] + '|' + aL[2] + '|' + aL[3] + '|' + aL[4] + '|' + cnts.substring(1, cnts.length) + '|' + aL[6] + '|' + rids.substring(1, rids.length);
    ReqLocRewrite();
}
var aLondon = new Array(["OTHER", "29.30.16.17.45.20.42.19.28.47"], ["WEST END", "4.3.1.6.7.5.8.39.10.35.12.11"], ["MID TOWN", "22.27.2.13"], ["CITY", "26.15.14.46.43.41.40.38.24.37.36.31.21"]), aHex = new Array('A', 'B', 'C', 'D', 'E', 'F');
function RegMulti() {
    if (XY.ReqLoc == 'London') {
        if ($('#LondonBlock').find('div.button').length > 0) { $('#LondonBlock').css('display', 'block'); fCentralLondon(); return; }
        UNI = '<div name=0 class=cnts style="padding-left:0px;width:545px">';
        var c2, c3;
        for (var c = 0; c < aLondon.length; c++) {
            UNI += '<div style="font-weight:bold;color:#00' + (6 - c * 2) + 'f00;background:#99' + aHex[c] + 'f99;width:25%;display:inline-block;text-align:center">' + aLondon[c][0] + '<br/>';
            for (c2 = 0; c2 < aLondon[c][1].split('.').length; c2++) {
                c3 = aLondon[c][1].split('.')[c2];
                UNI += ADDbutton.replace('xID', c3).replace(/xValue/g, eval('jsLondon.v' + c3)).replace('ORDER', c2);
            }
            UNI += '</div>';
        }
        UNI += '</div>';
        $('#LondonBlock').html(UNI).find('div.button').attr('style', 'width:99%;height:17px;text-align:left;padding-left:2px;padding-top:4px;background:#eee;color:#444;border-bottom:1px solid #999;border-left:1px solid #77CC77;font-size:0.92em'
                              ).find('input').css('display', 'none');
        fButtons('#LondonBlock', 1, 0, 10);
        aL = XY.J.Lc.split('|');
        $('#LondonCentral').html(aL[1]);
        XY.J.rgs = aL[5].split(',');
        for (var t = 0; t < XY.J.rgs.length; t++) $('#LondonBlock').find('div.button[name=' + XY.J.rgs[t] + ']').trigger('click'); //setTimeout("$('#LondonBlock').find('div.button[name=" + XY.J.rgs[t] + "]').trigger('click')", 150);                        
    }
    else {
        ReqLocOff('Region');
        if ($('#RgsMulti2').find('div.button').length > 0) { $('#RgsMulti,#RgsMulti2').css('display', 'block'); return; }
        $('#RgsMulti').html('<table style="float:right;background:#eef"><tr><td></td><td name=8 class=b_r>Scotland</td><td></td></tr><tr><td name=10 class=b_r>N. Ireland</td><td name=6 class=b_r>North West</td><td name=7 class=b_r>North East</td></tr><tr><td name=5 class=b_r>Wales</td><td name=4 class=b_r>Midlands</td><td></td></tr><tr><td name=3 class=b_r>South West</td><td name=1 class=b_r>London</td><td name=2 class=b_r>South East</td></tr></table>'
                     ).find('.b_r').mouseover(function() { $(this).css('opacity', 0.7); }).mouseout(function() { $(this).css('opacity', 1); }
                     ).click(function() {
                         var n = $(this).attr('name');
                         if ($(this).attr('name2') != '1') {
                             $(this).attr('name2', '1').css('background', '#36a').css('color', '#ddd');
                             if ($('#RgsMulti2').find('div[name=' + n + ']').find('div.button').length > 0) {
                                 $('#RgsMulti2').find('div[name=' + n + ']').css('display', 'block'); return;
                             }
                             RegPop(n);
                             $('#RgsMulti2').find('div[name=' + n + ']').attr('name2', '1').find('div.button').slice(0, 1).trigger('click');
                             //if (n == '5') RegidsCnts();
                         }
                         else {
                             $(this).attr('name2', '0').css('background', '#bdf').css('color', '');
                             $('#RgsMulti2').find('div[name=' + n + ']').attr('name2', '0').css('display', 'none');
                             RegidsCnts();
                         }
                     });
        aL = XY.J.Lc.split('|');
        XY.J.rgs = aL[7].split(','); //was 7
        for (var t = 0; t < XY.J.rgs.length; t++)
            if (XY.J.rgs[t].length > 0) $('#RgsMulti').find('td[name=' + XY.J.rgs[t] + ']').trigger('click');

        XY.J.cnts = aL[5].split(',');
        for (t = 0; t < XY.J.cnts.length; t++)
            if (XY.J.cnts[t].length > 0) {
            var r = retRegid(XY.J.cnts[t]);
            if ($('#RgsMulti').find('td[name=' + r + ']').attr('name2') != '1') { $('#RgsMulti').find('td[name=' + r + ']').attr('name2', '1').css('background', '#36a').css('color', '#ddd'); RegPop(r); }
            $('#RgsMulti2').find('div[name=' + XY.J.cnts[t] + ']').trigger('click');
        }
    }
}
var LondonCentralDiv = '', londonCentral = '';
function Stringify(j) { try { j.marker = ""; j.map = ""; j.polygon = ""; XY.Js = XY.stringify(j); } catch (e) { }; }
function PropLocRewrite() {
    XY.J.Lc = $('#streetnumber').val() + '|' + $('#postcode').val().replace('postcode', '') + '|' + $('#street').val().replace('street', '') + '|' + $('#centreestate').val().replace('Shopping Centre, Retail Pk, Ind Est', '')
                + '|' + $('#towncity').val().replace('city / town', '') + '|' + $('#suburblocality').val().replace('only suburbs', '') + '|' + $('#buildingnumber').val() + '|' + $('#building').val() + '|' + XY.J.Lc.split('|')[7];
    $(XY.L).find('div.block2').find('.Location').html(htmlLoc(XY.J));
    $(XY.L).find('td.tw').html(Fading(XY.J.Lc.split('|')[4], 9, 6, '')).find('font').each(function() { $(this).css('opacity', $(this).attr('name')); }); ;
    $(XY.L).find('td.st').html(Fading(LsPLc(XY.J), 14, 8, '')).find('font').each(function() { $(this).css('opacity', $(this).attr('name')); }); ;
}
var aLetter, LetterAm, LetterFullAm = '', LetterFull, aTs = new Array(), aAmenities = new Array("24 Hour Access", "24 Hour Security", "3 Compartment Trunking", "Air Conditioning", "Atrium", "Car Parking", "Car Spaces", "Carpeting", "Category 2 Lighting", "Category 5 Cabling", "CCTV", "Central Heating", "Cloakrooms", "Closed Circuit TV", "Comfort Cooling", "Courtyard", "Demountable Partitioning", "Disabled Facilities", "Double Glazing", "Energy Performance Rating - A-E", "Entire Building", "Excellent Natural Light", "Garden", "Gas Central Heating", "Good Natural Light", "Goods Lift", "Grade A", "Heating", "Kitchen Facilities", "LG7 Lighting", "Loading Bay", "Loading Yard", "Meeting Room(s)", "Open Plan Layout", "Passenger Lift(s)", "Passenger Lift(s)", "Perimeter Trunking", "Period Building", "Private Offices", "Raised Floors", "Reception", "Recessed Lighting", "Redecorated", "Refurbished", "Restaurant", "Roof Terrace", "Security Entry System", "Security System", "Shell And Core Condition", "Shower(s)", "Storage Space", "Suspended Ceilings", "Under Floor Trunking", "WC's", "Wooden Floors");
function gPsTs2(code) {
    aLetter = LetterAm.split('\n');
    LetterAm = aLetter[aLetter.length - 1];
    if (code == 13 || code == 44 || code == 188) {
        if (code != 13) Multiline($('#Amenities'));
    }
    else {
        if (LetterFullAm != LetterAm && LetterAm.length > 1 && LetterAm.length < 10) {
            LetterFullAm = LetterAm;
            LetterAm = LetterAm.substr(0, 1).toUpperCase();
            jsAmenities(0);
        }
        else $('#Amenities2').css('display', 'none');
    }
}
function jsAmenities(ix) {
    $('#Amenities2').css('display', 'none'); //if ($('#Amenities2').css('display') != 'none') 
    var UNI = '';
    for (i = 1; i < aAmenities.length; i++)
        if (LetterFullAm.toLowerCase() == aAmenities[i].substr(0, LetterFullAm.length).toLowerCase())
        UNI += '<div name3=l' + aAmenities[i] + ' class="items" style="padding-left:2px;background:#afa;display:block">' + aAmenities[i] + '</div>';
    if (UNI.length == 0) return;
    $('#Amenities2').html('<div style="position:absolute"><div name=1 class=head>Click an Amenity to add, click red line to Close</div>'
        + UNI + '</div>').css('display', 'block').find('div.items'
	).mouseover(function() { $(this).css('opacity', 0.7); }).mouseout(function() { $(this).css('opacity', 1); }).click(function() {
	    var am = $('#Amenities').val();
	    am = am.replace(LetterFullAm, '');
	    $('#Amenities').val(am + $(this).html() + '\n');
	    Multiline($('#Amenities'));
	    XY.J.A = $('#Amenities').val().replace(new RegExp("\n", "g"), ",");
	    $(XY.L).find('div.block2').find('.Size').html(htmlSizeP(XY.J, 0) + htmlTenure(XY.J) + XY.J.A.replace('^', '<br>').replace(/,/g, '<br>'));
	});
    $('#Amenities2').find('div.head').mouseover(function() { $(this).css('opacity', 0.8); }).mouseout(function() { $(this).css('opacity', ''); }
	    ).click(function() { $('#Amenities2').css('display', 'none'); });
}
function jsTw(a) { aTs[Letter.charCodeAt(0)] = a; jsPTw(a); }
function jsTwPc(a) {
    if (IsMenu == 14) jsT(a.replace(new RegExp("'", "g"), "&rsquo;"));
    else {
        aTs[Letter.charCodeAt(0)] = a;
        jsPTw(a);
    }
}
function jsPTw(a) {
    $('#TownList').css('display', 'block').css('opacity', '').css('width', "325px").html(waitSometime('Loading towns...'));
    setTimeout("jsPTw2('" + a.replace(new RegExp("'", "g"), "&rsquo;") + "')", 850);
}
function jsPTw2(a) {
    var UNI = '', UNI2 = a.split(',');
    for (i = 1; i < UNI2.length; i++) {
        if (LetterFull.toLowerCase() == UNI2[i].substr(0, LetterFull.length).toLowerCase()) {
            UNI += '<table name3=' + (UNI2[i].split('@')[0] + '@' + UNI2[i].split('@')[1]).replace(/ /g, '_') + ' style="background:#afa;width:100%" cellpadding=0 cellspacing=0><tr><td style="width:25px">'
				+ UNI2[i].split('@')[1] + '</td><td style="width:185px;background:yellow1">'
				+ UNI2[i].split('@')[0] + '</td><td align=left>' + eval("jsRgs3.v" + UNI2[i].split('@')[2]) + '</td></tr></table>';
        }
    }
    if (UNI == '') {
        $('#TownList').html('<span style="color:#933;background:#eee;display:block;text-align:center;font-weight:bold">No&nbsp;Town&nbsp;change&nbsp;entered&nbsp;value</span>'
							).animate({ opacity: 0 }, 1000, function() { $('#TownList').css('opacity', '').html('<br/>'); });
        return;
    }
    $('#TownList').html('<div name=1 name3=0 style="background:#900;color:#fff;text-align:center">You must select town from the list below</div>'
                        + UNI).find('table').mouseover(function() { $(this).css('opacity', 0.7); }).mouseout(function() {
                            $(this).css('opacity', '');
                        }).click(function() {
                            if ($(this).attr('name3') != '0') {
                                var val = $(this).attr('name3').replace(/_/g, ' ').replace('@', ' [') + ']';
                                aL = XY.J.Lc.split('|');
                                aL[2] = $('#Town').find('textarea').val(); aL[2] = aL[2].substring(0, aL[2].lastIndexOf(','));
                                if (aL[2].length > 0) val = aL[2] + ', ' + val;
                                aL[2] = val;
                                XY.J.Lc = aL[0] + '|' + aL[1] + '|' + aL[2] + '|' + aL[3] + '|' + aL[4] + '|' + aL[5] + '|' + aL[6] + '|' + aL[7];
                                $('#Town').find('textarea').val(aL[2] + ', '); //.focus();
                                Multiline($('#Town').find('textarea'));
                                $('#Town').find('textarea').focus();
                                if (XY.ReqLoc != 'Town') ReqLocOff('Town');
                                ReqLocRewrite();
                            }
                            $('#TownList').css('display', 'none'); //.html('<br>')
                        });
}
function ReqLocRewrite() {
    $(XY.L).find('div.block2').find('.Location').html(htmlReqLocFull(XY.J.Lc.split('|')));
    $(XY.L).find('td.st').html(Fading(htmlReqLoc(XY.J.Lc.split('|'), 1), 16, 7, '')).find('font').each(function() { $(this).css('opacity', $(this).attr('name')) }); ;
}
function AreaDel() {    //XY.J.map.removeOverlay(XY.J.polygon[0]);        
    aL = XY.J.Lc.split('|'); //
    XY.J.Lc = aL[0] + "|" + aL[1] + "|" + aL[2] + "|" + aL[3] + "|" + aL[4] + "|" + aL[5] + "||" + aL[7];
    XY.J.map.clearOverlays();
    XY.AreaColor = 0;
    startShape();
}
function AreaMap() {
    if ($('#aMap').html() == 'deselect map search') {
        ReqLoc('');
        $('#aMap').html('open map');
    }
    else {
        if ($('#MapInput').html().length == 0) {
            XY.AreaColor = 0;
            $('#Map').find('textarea').val('eg. Birmingham-Nottingham-Sheffield, M1 corridor, etc');
            GUnload(); setTimeout("GMapArea()", 250);
        }
        ReqLocOff('Map');
        $('#aMap').html('deselect map search').attr('disabled', false);
        $('#Map').find('textarea').val(XY.J.Lc.split('|')[0].length > 0 ? XY.J.Lc.split('|')[0] : (XY.AreaDesc == '' ? XY.ExpMap2 : XY.AreaDesc));
        setTimeout(function() { offsetY($('#Map')); }, 500); //if (XY.EditStart == 0) 
    }
}
function startShape() {
    var col = XY.AreaColors(), polygon = new GPolygon([], col, 2, 0.7, col, 0.3);
    $('#Map').find('span.barea[name=s]').css('display', 'none');
    $('#Map').find('span.barea[name=i]').html('Click map to start. Scroll. Drag.').css('display', 'inline-block');
    startDrawing(XY.J.map, polygon, col);
    polygon.enableDrawing({});
    fPoly(polygon, col);
}
function startDrawing(map, poly, color) {
    map.addOverlay(poly); // XY.J.map.addOverlay(poly);    
    poly.name = (XY.AreaColor - 1);
    poly.enableEditing({ onEvent: "mouseover" });
    poly.disableEditing({ onEvent: "mouseout" });
}
function fPoly(poly, color) {
    GEvent.addListener(poly, "endline", function() {
        GEvent.bind(poly, "lineupdated", XY.AreaColor,
                function() {
                    $('#Map').find('span.barea[name=s]').css('display', 'inline-block'); //Don\'t forget to describe the area<br>
                    $('#Map').find('span.barea[name=i]').html('click on the vertex to delete it');
                    XY.J.polygon[poly.name] = poly;
                    if ($('#Map').find('span.barea[name=' + poly.name + ']').length == 0) htmArea(poly.name, color, (Math.round(poly.getArea() / 10000) / 100));
                    else $('#Map').find('span.barea[name=' + poly.name + ']').find('td').slice(1, 2).html((Math.round(poly.getArea() / 10000) / 100) + "km<sup>2</sup>");
                }
        );
        GEvent.addListener(poly, "click", function(latlng, index) {
            if (typeof index == "number") poly.deleteVertex(index);
        });
    });
    GEvent.addListener(poly, "click", function(latlng, index) {
        alert(11); // if (typeof index == "number") poly.deleteVertex(index);
    });
    /*GDraggableObject.addListener(poly, "dragend", function() {
    alert(55);
    })*/
}
function GMapArea() {
    if (GBrowserIsCompatible()) {
        var latlng = new GLatLng(LatLong.split(',')[0], LatLong.split(',')[1]);
        XY.J.map = new GMap2(document.getElementById("MapInput"));
        XY.J.map.clearOverlays();
        XY.J.map.addControl(new GSmallMapControl());
        XY.J.map.addControl(new GMapTypeControl());
        XY.J.map.setMapType(G_HYBRID_MAP);
        XY.J.map.setCenter(latlng, 13);       // XY.J.map.enableScrollWheelZoom();
        $('#Map').find('span.barea[name=s]').mouseover(function() { $(this).css('opacity', 0.5); }).mouseout(function() { $(this).css('opacity', ''); }).click(function() { startShape(); })
        XY.AreaColor = 0;
        XY.J.polygon = new Array();
        if (XY.J.Lc.split('|')[6].length < 10) {//no area...            
            startShape();
            return;
        }
        var aArea = XY.J.Lc.split('|')[6].split('X'), LL, coords, coord, ii;
        var latlng = new GLatLng(aArea[0].split(',')[0], aArea[0].split(',')[1].split('!')[0]);
        XY.J.map.setCenter(latlng, parseInt(aArea[0].split('*')[0].split('!')[1]));   //   .split(',')[1]  
        try {
            for (var i = 0; i < aArea.length - 1; i++) {
                coords = aArea[i].split('*');
                ii = 1;                //if (coords[0].length < 5) ii = 1;//this is dues to the previous version of the area map (flash)...
                LL = new Array();
                for (ii; ii < coords.length; ii++) {
                    coord = coords[ii].split(",");
                    LL[LL.length] = new GLatLng(coord[1], coord[0]); //latlng;//.toString();
                }
                if (LL[LL.length - 1] != LL[0]) LL[LL.length] = LL[0]; //this is dues to the previous version of the area map (flash)... area must be closed...            
                var col = XY.AreaColors();
                XY.J.polygon[i] = new GPolygon(LL, col, 2, 0.7, col, 0.3);
                var p = XY.J.polygon[i];
                p.name = (XY.AreaColor - 1);
                htmArea(p.name, col, (Math.round(p.getArea() / 10000) / 100));
                startDrawing(XY.J.map, p, col);
                fPoly(p, col);
                p.enableEditing();
                GEvent.trigger(p, "endline");
            }
        } catch (r) { }
    }
}
var iMap, markerPic = "http://www.4prop.com/JSON/images/common/pin.png?ID";
function iGMap0() {
    try {
        var latlng = new google.maps.LatLng(parseFloat(XY.J.Lt), parseFloat(XY.J.Ln));
        XY.J.gmap = new google.maps.Map(document.getElementById("MAP" + XY.J.II), mapOptions(latlng, 17));
        XY.J.marker = new google.maps.Marker({ draggable: true, position: latlng, map: XY.J.gmap, title: 'your location based on\n postcode ' + XY.J.Lc.split('|')[1]
                    , icon: markerPic.replace('pin', 't1' + XY.J.tp)
        });
        if (NoStreet(XY.J.H)) {
            if (J.IS < 2 || XY.view) XY.J.marker.setMap(null); //XY.J.My == 0
            else {
                $(XY.L).find('div.Map').css('opacity', 0.7).find('div.NoSee').css('display', 'block');
            }

        }
        else $(XY.L).find('div.Map').css('opacity', '');
    } catch (e) { }
}
function MapBlock(id, B, J, match) {
    try { XY.J.block = 0; XY.J.marker.setAnimation(null); } catch (e) { };
    J.marker.setAnimation(google.maps.Animation.BOUNCE);
    J.marker.setIcon(markerPic.replace('pin', 't0' + J.tp).replace('ID', id));
    XY.iti = J.It + '|' + J.Crit + '|' + id; //J.tp
    fList(B, ListHtml(J, 0, 0), 0);
    XY.J = J;
    setTimeout(function() { showBlock(XY.iti); }, 75);  //
    setTimeout(function() { $(B).find('div.block').attr('name', '0').css('display', 'block'); }, 120);  //0
    if (match > 0) setTimeout("MatchClickDelay()", 250);
    if (XY.searched.length > 0) setTimeout("htmlBlockSearch(" + $(B).find('div.block2') + "," + J + ")", 350); //searched...         
}
function iGMap() {
    try {
        var N = iMap.split('|'), J, B = BarId(iMap); N[2] = N[0] + N[1];
        var latlng = new google.maps.LatLng(51, 0.5), Lts = 0, Lns = 0, MnMxLt = new Array(), MnMxLn = new Array();
        var ck = $(B).find('table.bar').find('input[type=checkbox]').attr('checked');
        $('#map' + N[2]).css('display', 'block');
        XY.Maps[N[2]] = new google.maps.Map(document.getElementById("map" + N[2]), mapOptions(latlng, 10)); //lhs
        try {
            htm = '';
            for (var i = 0; i < JSON[N[0]].length; i++) {
                J = JSON[N[0]][i];
                if (N[1] == J.Crit && (IS <= J.IS || (IS == 4 && J.rc == 1))) {//tp
                    if (ck) J.ck = 1; //wed
                    J.block = 0;
                    latlng = new google.maps.LatLng(J.Lt, J.Ln);
                    if (J.Lt.length > 0 && J.Ln.length > 0) {
                        Lts += parseFloat(J.Lt); Lns += parseFloat(J.Ln); MnMxLn[MnMxLt.length] = J.Ln; MnMxLt[MnMxLt.length] = J.Lt;
                    }
                    J.marker = new google.maps.Marker({ draggable: true, position: latlng, map: XY.Maps[N[2]]
                        , title: MapDesc(J), icon: markerPic.replace('pin', 't1' + J.tp).replace('ID', i)
                    });
                    google.maps.event.addListener(J.marker, 'click', function() {
                        try {
                            var id = $(this).attr('icon').split('?')[1];
                            MapBlock(id, B, JSON[N[0]][id], 0);
                        } catch (e) { }
                    });
                }
            }
        } catch (e) { }
        XY.Maps[N[2]].setCenter(new google.maps.LatLng(Lts / MnMxLt.length, Lns / MnMxLt.length));
        var MnMx = new Array(); MnMx[0] = Math.abs(rMax(MnMxLt) - rMin(MnMxLt)); MnMx[1] = Math.abs(rMax(MnMxLn) - rMin(MnMxLn));
        MnMxLt[0] = parseInt(rMax(MnMx) * 40);
        //XY.Maps[N[2]].setZoom(MnMxLt[0] > 15 ? 10 : 15 - MnMxLt[0]);
        if (XY.It == 'r') {
            try {
                var jmap = JSON["r"][XY.iti.split('|')[2]];
                if (jmap.Lc.split('|')[6].length > 10) {
                    var aArea = jmap.Lc.split('|')[6].split('X'), LL, coords, coord, ii;
                    jmap.polygon = new Array();
                    for (var i = 0; i < aArea.length - 1; i++) {
                        coords = aArea[i].split('*');
                        ii = 1;
                        LL = new Array();
                        for (ii; ii < coords.length; ii++) {
                            coord = coords[ii].split(",");
                            LL[LL.length] = new google.maps.LatLng(coord[1], coord[0]);
                        }
                        if (LL[LL.length - 1] != LL[0]) LL[LL.length] = LL[0]; //this is dues to the previous version of the area map (flash)... area must be closed...
                        var col = XY.AreaColors();
                        var overlay = new google.maps.Polygon({
                            paths: LL, strokeColor: col, strokeOpacity: 0.5, strokeWeight: 1, fillColor: col, fillOpacity: 0.20, map: XY.Maps[N[2]]
                        });
                    }
                }
            } catch (r) { }
        }
        setTimeout("ViewEnd(\'" + iMap + "\')", 50);
    } catch (e) { }
}
function htmArea(acol, col, area) {
    $('#Map').find('.barea:last').after('<span class=barea style="display:inline-block;width:50px;color:#000;background:#dfd;margin-left:1px;margin-right:1px;font-weight:normal" name='
                            + acol + '><table cellspacing=0 cellpadding=0 style="color:'
                            + col + '"><tr><td style="font-weight:bold">delete</td></tr><tr><td style="color:#030">'
                            + area + "km<sup>2</sup></td></tr></table></span>");
    $('#Map').find('.barea[name=' + acol + ']').mouseover(function() { $(this).css('opacity', 0.5); }).mouseout(function() { $(this).css('opacity', ''); }
            ).click(function() {
                if ($(this).find('td').slice(0, 1).html() == 'delete') {
                    $(this).find('td').slice(0, 1).html('renew');
                    XY.J.map.removeOverlay(XY.J.polygon[acol]);
                }
                else {
                    $(this).find('td').slice(0, 1).html('delete');
                    XY.J.map.addOverlay(XY.J.polygon[acol]);
                }
            });
}
function retRegid(ctid) { for (var r = 1; r <= 10; r++) if (('.' + eval('jsRgs2.v' + r) + '.').indexOf('.' + ctid + '.') > -1) return r; }
function balertChange(o) {
    XY.AlertListing = $('#balert').find('option:selected').attr('value');
    $('#balert2').html('list on EACH Alert <b>' + $('#balert').find('option:selected').html() + '</b>');
    $(o).parent().parent().css('background', $(o).val() == '255' ? XY.uncheck : XY.check);
}
function b4propChange(o) {
    var id = $(o).parent().attr('id');
    if (id == 'b4prop0') {
        XY.PublicListing = $(o).find('option:selected').attr('value');
    }
    else if (id == 'b4prop') {
        XY.PublicListingOther = $(o).find('option:selected').attr('value');
    }
    else if (id == 'b4prop1') {
        XY.PublicListingOtherAgents = $(o).find('option:selected').attr('value');
    }
    $('#' + id + '2').html('on ' + $(o).parent().attr('name') + '  <b>' + $(o).find('option:selected').html() + '</b>');
    $(o).parent().parent().css('background', $(o).val() == '255' ? XY.uncheck : XY.check);
}

var hManage = '<fieldset class="MngCnt"><legend>MANAGE CONTACT – <span>click here to close if not using</span></legend><div class="Mng"><span class="Tit"><span class="tit">Title</span><input /><span class="tit">&nbsp;&nbsp;Company&nbsp;Name</span><input /></span><span class="Tit"><span class="tit">First&nbsp;Name</span><input /><span class="tit">&nbsp;&nbsp;Company&nbsp;Phone</span><input /></span>'
    + '<span class="Tit"><span class="tit">Last&nbsp;Name</span><input /><span class="tit">&nbsp;&nbsp;Company&nbsp;Website</span><input /></span><span class="Tit"><span class="tit">DDI</span><input /></span><span class="Tit"><span class="tit">Mobile</span><input /></span>'
    + '<span class="Tit"><span class="tit">Email</span><input /></span><span class="Tit"><span class="tit" style="float:left">Date&nbsp;&amp;&nbsp;Conversation</span><textarea rows="2" cols="20" style="height:85px;width:380px;overflow:auto;float:left"></textarea></span>'
    + '<span class="Tit"><span class="tit" style="float:left">Date for next Contact</span><span style="width:200px;float:left"><input id="txtDD" onfocus="showCalendarControl(this)" style="width:75px;float:left;margin-left:0px" /></span></span>'
    + '<div style="clear:both;display:block"><br/></div><a style="clear:both;float:left" >Show previous conversations</a><a style="float:right" >Save this conversation</a>'
    + '<div style="clear:both;display:block"><br/></div><a style="float:left" >View all Contacts</a><a style="float:left;margin-left:50px">View my Contacts</a><a style="float:right" >Email me my contacts</a></div></fieldset>';
var hSummary = '<legend>MARKETING CONFIRMATION<font>7</font></legend><div class="L"><div style="margin-top:7px;margin-bottom:9px"><b>Select your Marketing</b></div>'
+ '<div class="check"><a id="badvertise">Advertise&nbsp;to&nbsp;Agents:&nbsp;yes/no</a></div><div class="check"><a id="bace">Email to <u>interested</u> Agents now yes/no</a></div>'
+ '<div class="check"><a id="balert">Change days</a> for EACH Alert</div><div class="check"><a id="b4prop0" name="www.4prop.com" class=b4prop>Change days</a> to advertise on www.4prop.com</div><div class="check"><a id="b4prop" name="other websites" class=b4prop>Change days</a> to advertise on other websites</div><div class="check"><a id="b4prop1" name="Agents\' sites" class=b4prop>Change days</a> to advertise on Agents\' websites</div></div>'
+ '<div class="R"><div style="margin-top:7px;margin-bottom:9px"><b>Marketing selected</b></div><div id="badvertise2">Advertising</div><div id="bace2">send ACE email NOW</div>'
+ '<div id="balert2">list on EACH Alert <b>in 2 days</b></div><div id="b4prop02" class=b4prop2>on www.4prop.com <b>in 1 week</b></div><div id="b4prop2" class=b4prop2>on other websites <b>in 1 week</b></div><div id="b4prop12" class=b4prop2>on other Agents\' sites <b>in 1 week</b></div></div>';
XY.stringify = function(obj) {// implement JSON.stringify serializationjsHTML.stringify ||
    var t = typeof (obj);
    if (t != "object" || obj === null) {        // simple data type
        if (t == "string") obj = '"' + obj + '"';
        return String(obj);
    }
    else {        // recurse array or object
        var n, v, json = [], arr = (obj && obj.constructor == Array);
        for (n in obj) {
            v = obj[n]; t = typeof (v);
            if (t == "string") v = '"' + v + '"';
            else if (t == "object" && v !== null) v = XY.stringify(v);
            json.push((arr ? "" : '"' + n + '":') + String(v));
        }
        return (arr ? "[" : "{") + String(json) + (arr ? "]" : "}");
    }
}; // implement JSON.parse de-serialization
XY.parse = XY.parse || function(str) { if (str === "") str = '""'; eval("var p=" + str + ";"); return p; };
function replSplChr(txt) { return txt.replace(/£/g, '&pound;').replace(/& /g, '&amp;').replace(/"/g, '&quot;'); }
function dtValidate(dt) { return dt == "undefined" || dt == undefined ? '' : dt; }
//Calendar
var NonAll = true, arValidMonth = Array("", "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
function positionInfo(object) {

    var p_elm = object;

    this.getElementLeft = getElementLeft;
    function getElementLeft() {
        var x = 0;
        var elm;
        if (typeof (p_elm) == "object") {
            elm = p_elm;
        } else {
            elm = document.getElementById(p_elm);
        }
        while (elm != null) {
            if (elm.style.position == 'relative') {
                break;
            }
            else {
                x += elm.offsetLeft;
                elm = elm.offsetParent;
            }
        }
        return parseInt(x);
    }

    this.getElementWidth = getElementWidth;
    function getElementWidth() {
        var elm;
        if (typeof (p_elm) == "object") {
            elm = p_elm;
        } else {
            elm = document.getElementById(p_elm);
        }
        return parseInt(elm.offsetWidth);
    }

    this.getElementRight = getElementRight;
    function getElementRight() {
        return getElementLeft(p_elm) + getElementWidth(p_elm);
    }

    this.getElementTop = getElementTop;
    function getElementTop() {
        var y = 0;
        var elm;
        if (typeof (p_elm) == "object") {
            elm = p_elm;
        } else {
            elm = document.getElementById(p_elm);
        }
        while (elm != null) {
            if (elm.style.position == 'relative') {
                break;
            }
            else {
                y += elm.offsetTop;
                elm = elm.offsetParent;
            }
        }
        return parseInt(y);
    }

    this.getElementHeight = getElementHeight;
    function getElementHeight() {
        var elm;
        if (typeof (p_elm) == "object") {
            elm = p_elm;
        } else {
            elm = document.getElementById(p_elm);
        }
        return parseInt(elm.offsetHeight);
    }

    this.getElementBottom = getElementBottom;
    function getElementBottom() {
        return getElementTop(p_elm) + getElementHeight(p_elm);
    }
}

function CalendarControl() {

    var calendarId = 'CalendarControl';
    var currentYear = 0;
    var currentMonth = 0;
    var currentDay = 0;

    var selectedYear = 0;
    var selectedMonth = 0;
    var selectedDay = 0;

    var months = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'];
    var dateField = null;

    function getProperty(p_property) {
        var p_elm = calendarId;
        var elm = null;

        if (typeof (p_elm) == "object") {
            elm = p_elm;
        } else {
            elm = document.getElementById(p_elm);
        }
        if (elm != null) {
            if (elm.style) {
                elm = elm.style;
                if (elm[p_property]) {
                    return elm[p_property];
                } else {
                    return null;
                }
            } else {
                return null;
            }
        }
    }

    function setElementProperty(p_property, p_value, p_elmId) {
        var p_elm = p_elmId;
        var elm = null;

        if (typeof (p_elm) == "object") {
            elm = p_elm;
        } else {
            elm = document.getElementById(p_elm);
        }
        if ((elm != null) && (elm.style != null)) {
            elm = elm.style;
            elm[p_property] = p_value;
        }
    }

    function setProperty(p_property, p_value) {
        setElementProperty(p_property, p_value, calendarId);
    }

    function getDaysInMonth(year, month) {
        return [31, ((!(year % 4) && ((year % 100) || !(year % 400))) ? 29 : 28), 31, 30, 31, 30, 31, 31, 30, 31, 30, 31][month - 1];
    }

    function getDayOfWeek(year, month, day) {
        var date = new Date(year, month - 1, day)
        return date.getDay();
    }

    this.clearDate = clearDate;
    function clearDate() { dateField.value = ''; hide(); }
    this.setDate = setDate;
    function setDate(year, month, day) {    //  alert(CalendarPurpose);
        if (day < 10) { day = "0" + day; }
        if (month < 10) { month = "0" + month; }
        var dateString = day + " " + arValidMonth[parseFloat(month)] + " " + year; //.toString().substring(2, 4);
        if ($(dateField).attr('id') == 'AuctionDate') dateField.value = day + '.' + month + '.' + year;
        else dateField.value = dateString;
        if ($(dateField).attr('class').indexOf('Added') > -1) fAddedSince(dateField.value);
        if ($(dateField).attr('class').indexOf('uploadedp') > -1) UploadedP(dateField.value);
        if ($(dateField).attr('class').indexOf('uploadedr') > -1) UploadedR(dateField.value);
        hide();
        try { $('#AuctionYes').attr('checked', true); } catch (e) { }

        return;
    }

    this.changeMonth = changeMonth;
    function changeMonth(change) {
        currentMonth += change;
        currentDay = 0;
        if (currentMonth > 12) {
            currentMonth = 1;
            currentYear++;
        } else if (currentMonth < 1) {
            currentMonth = 12;
            currentYear--;
        }

        calendar = document.getElementById(calendarId);

        calendar.innerHTML = calendarDrawTable();
    }

    this.changeYear = changeYear;
    function changeYear(change) {
        currentYear += change;
        currentDay = 0;
        calendar = document.getElementById(calendarId);
        calendar.innerHTML = calendarDrawTable();
    }

    function getCurrentYear() {
        var year = new Date().getYear();
        if (year < 1900) year += 1900;
        return year;
    }

    function getCurrentMonth() {
        return new Date().getMonth() + 1;
    }

    function getCurrentDay() {
        return new Date().getDate();
    }

    function calendarDrawTable() {

        var dayOfMonth = 1;
        var validDay = 0;
        var startDayOfWeek = getDayOfWeek(currentYear, currentMonth, dayOfMonth);
        var daysInMonth = getDaysInMonth(currentYear, currentMonth);
        var css_class = null; //CSS class for each day

        var table = "<table cellspacing='0' cellpadding='0' border='0'>";
        table = table + "<tr class='header'>";
        table = table + "  <td colspan='2' class='previous'><a href='javascript:changeCalendarControlMonth(-1);'>&lt;</a> <a href='javascript:changeCalendarControlYear(-1);'>&laquo;</a></td>";
        table = table + "  <td colspan='3' class='title'>" + months[currentMonth - 1] + "<br>" + currentYear + "</td>";
        table = table + "  <td colspan='2' class='next'><a href='javascript:changeCalendarControlYear(1);'>&raquo;</a> <a href='javascript:changeCalendarControlMonth(1);'>&gt;</a></td>";
        table = table + "</tr>";
        table = table + "<tr><th>S</th><th>M</th><th>T</th><th>W</th><th>T</th><th>F</th><th>S</th></tr>";

        for (var week = 0; week < 6; week++) {
            table = table + "<tr>";
            for (var dayOfWeek = 0; dayOfWeek < 7; dayOfWeek++) {
                if (week == 0 && startDayOfWeek == dayOfWeek) {
                    validDay = 1;
                } else if (validDay == 1 && dayOfMonth > daysInMonth) {
                    validDay = 0;
                }

                if (validDay) {
                    if (dayOfMonth == selectedDay && currentYear == selectedYear && currentMonth == selectedMonth) {
                        css_class = 'current';
                    } else if (dayOfWeek == 0 || dayOfWeek == 6) {
                        css_class = 'weekend';
                    } else {
                        css_class = 'weekday';
                    }

                    table = table + "<td><a class='" + css_class + "' href=\"javascript:setCalendarControlDate(" + currentYear + "," + currentMonth + "," + dayOfMonth + ")\">" + dayOfMonth + "</a></td>";
                    dayOfMonth++;
                } else {
                    table = table + "<td class='empty'>&nbsp;</td>";
                }
            }
            table = table + "</tr>";
        }

        table = table + "<tr class='header'><th colspan='7' style='padding: 3px;'><a href='javascript:clearCalendarControl();'>Clear</a> | <a href='javascript:hideCalendarControl();'>Close</a></td></tr>";
        table = table + "</table>";

        return table;
    }

    this.show = show;
    function show(field) {
        can_hide = 0;

        // If the calendar is visible and associated with
        // this field do not do anything.
        if (dateField == field) {
            return;
        } else {
            dateField = field;
        }

        if (dateField) {
            try {
                var dateString = new String(dateField.value);
                var dateParts = dateString.split(" ");

                selectedMonth = parseInt(aMd[dateParts[1]]) + 1; // parseInt(dateParts[0],10);
                selectedDay = parseInt(dateParts[0], 10);
                selectedYear = parseInt(dateParts[2], 10);
            } catch (e) { }
        }

        if (!(selectedYear && selectedMonth && selectedDay)) {
            selectedMonth = getCurrentMonth();
            selectedDay = getCurrentDay();
            selectedYear = getCurrentYear();
        }

        currentMonth = selectedMonth;
        currentDay = selectedDay;
        currentYear = selectedYear;

        if (document.getElementById) {

            calendar = document.getElementById(calendarId);
            calendar.innerHTML = calendarDrawTable(currentYear, currentMonth);

            setProperty('display', 'block');

            var fieldPos = new positionInfo(dateField);
            var calendarPos = new positionInfo(calendarId);

            var x = fieldPos.getElementLeft();
            var y = fieldPos.getElementBottom();
            setProperty('left', (x - calendarPos.getElementWidth()) + "px");
            setProperty('top', y + "px");
        }
    }
    this.hide = hide;
    function hide() {
        if (dateField) {
            setProperty('display', 'none');
            dateField = null;
        }
    }
    this.visible = visible;
    function visible() {
        return dateField
    }

    this.can_hide = can_hide;
    var can_hide = 0;
}
var calendarControl = new CalendarControl();
function showCalendarControl(textField) { calendarControl.show(textField); }
function showCalendarLeft(textField) { calendarControl.show(textField); }
function clearCalendarControl() { calendarControl.clearDate(); }
function hideCalendarControl() { if (calendarControl.visible()) calendarControl.hide(); }
function setCalendarControlDate(year, month, day) { calendarControl.setDate(year, month, day); }
function changeCalendarControlYear(change) { calendarControl.changeYear(change); }
function changeCalendarControlMonth(change) { calendarControl.changeMonth(change); }
try {
    //$('#spLog').html('<div style="color:#fee;background:#a44;font-size:2em;padding:10px;padding-left:25px;font-family:Arial">We have a database problem.<br>We are fixing it now.<br>Please wait<br>Thank You!</div>').css('display', 'block');
    $('#email').val(get_cookie('email'));
    $('#email,#password').css('textIndent', '12px');
} catch (e) { }
