﻿function FP() {
    var FPObj = {};
    
    var headID = 0;
    var forumID = 0;
    //var AuthInfoArray = [];
    var ReplaceElArray = [];
    
    var authObj = {}; //hold author info object
    var msgObj = {}; //hold message info object 
    var imgObj = {}; //hold image info object
    var moState = {}; //holds info about mousover state of box lists 
    var msgListArray = []; //holds list of messages in thread
    var msgListPointer = 0; //holds a pointer so we know which messages we have retieved already
    var threadStarter = ""; //holds the username of whoever strted the current thread
    var isPC = false; //is photo contest;
    var msgPP = 25; //no of messages per page of a thread;
    var msgPg = 1; //current page;
    var msgOI = -1; //message of interest in thread;
    var av = "false"; //Avatars Hidden - true/false
    var sig = "false"; //Signatures Hidden - true/false
    var peerRv = "false"; //Peer Reviews Enabled - true/false
    var peerRvT = 0; //Peer Review Threshold
    var postEn = "false"; //Posting Enabled - true/false
    var tzDiff = 0; //Time Zone Offset - hours
    var tDiff = 0; //Time Offset between browser and server time
    var pgTime;// = new Date(); //UTC Page Load Time
    var uName = "";//username
    var mbrType = "Guest";//membership Type
    var cacheBuster = (new Date()).getTime(); 
    var root = "";   
    
    //HELPER FUNCTIONS=======================================
    
    function indent(depth, name, children) {
        if (depth > 0) {
            if (children > 0) {
                name = new Array(2 * depth - 1).join("&nbsp;") + "+&nbsp;" + name;
            }
            else {
                name = new Array(2 * depth - 1).join("&nbsp;") + "-&nbsp;" + name;
            }
        }
        return name;
     }
     
    
    function returnObjById( id ) {
        var returnVar;
        if (document.getElementById) {
            returnVar = document.getElementById(id); }
        else if (document.all) {
            returnVar = document.all[id]; }
        else if (document.layers) {
            returnVar = document.layers[id]; }
        return returnVar;
    }
    
    function arrayContainsObject(arr,obj) {
        for (var i = 0; i < arr.length; i++) {        
            if (arr[i] === obj) {
                return true;
            }
        }
        return false;
    }
    function arrayContains(arr, match) {
        for (var i = 0;i < arr.length;i++) {
         if (arr[i] === match) { return true; }        
        }
        return false;
    }
    function arrayRemove(arr, match){
        for (var i = 0;i < arr.length;i++){
            if (match === arr[i]) { arr.splice(i, 1); }
        }
        return arr;
    }   
    function flagCode(c,cn) {
        var flg = "";
        if (c.length > 1) {            
            if (c.substr(0,2) === "UK") {
                flg = c;
            } else {
                flg = c.substr(0,2); 
            } 
            flg = "<span title=\"" + cn + "\" class=\"inline\"><div class=\"countryIcon country" + flg + "Icon\">&nbsp;</div></span>";
        }
        else {
            flg = "";
        }
        return flg;
    } //returns a url parameter value when passed the parameter name. Will return "" if the param does not exist.
    FPObj.getURLparam = function(name)
    {
      name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
      var regexS = "[\\?&]"+name+"=([^&#]*)";
      var regex = new RegExp( regexS );
      var results = regex.exec( window.location.href );
      if( results === null ) {
        return "";
      }
      else {
        return results[1];
      }
    };
    function shortenString(stringToShorten, maxLength) {
      if (stringToShorten !== undefined && stringToShorten.length > maxLength) {
          stringToShorten = stringToShorten.substring(0, maxLength-3) + "...";
        }
      return stringToShorten;
    }
    
    function timeDiff(t1,t2)
    {
        currTimeTicks = new Date().getTime() + tDiff;  
        var postAge = Math.round(((new Date().setTime(currTimeTicks))-t2.getTime())/(1000*60*60));  
        var age;

        if (postAge < 48) {
            age = postAge + "hr";
        }
        else if (postAge < 168) {
            age = Math.ceil(postAge / 24) + "d";
        }
        else {
            age = Math.ceil(postAge / 24 / 7) + "w";
        }

        return "~" + age;
    }
    function readCookie(name) {
       var nameEQ = name + "=";
       var ca = document.cookie.split(';');
       for(var i = 0;i < ca.length;i++) {
           var c = ca[i];
           while (c.charAt(0) === ' ') { c = c.substring(1,c.length); }
           if (c.indexOf(nameEQ) === 0) { return c.substring(nameEQ.length,c.length); }
       }
       return null;
   }
   function findPos(obj){
        var curleft = 0;
        var curtop = 0;
        if(obj.offsetParent){
            curleft = obj.offsetLeft;
            curtop = obj.offsetTop;
            while(obj=obj.offsetParent){
                curleft+=obj.offsetLeft;
                curtop+=obj.offsetTop;
            }
        }
        return[curleft,curtop];
    }
    function d2h(d) {return d.toString(16);}    //decimal to hex
    function h2d(h) {return parseInt(h,16);}    //hex to decimal
    // from http://javascript.crockford.com/remedial.html
    String.prototype.supplant = function (o) {
        return this.replace(/{([^{}]*)}/g,
            function (a, b) {
                var r = o[b];
                return typeof r === 'string' || typeof r === 'number' ? r : a;
            }
        );
    };
    String.prototype.repeat = function(num) {
        return new Array( num + 1 ).join( this );
    }

    
    function AddJSONScriptTag(codeRequest) {

        var fullUrl = root + "/" + codeRequest;
        try {
             // Create a new script object
             aObj = new JSONscriptRequest(fullUrl);
             // Build the script tag
             aObj.buildScriptTag();
             // Execute (add) the script tag
             aObj.addScriptTag();               
        }
        catch (err) {
            alert(err);
        }
    }
    function JSONscriptRequest(fullUrl) {
        // REST request path
        this.fullUrl = fullUrl; 
        // Get the DOM location to put the script tag
        this.headLoc = document.getElementsByTagName("head").item(0);
        // Generate a unique script tag id
        this.scriptId = 'fpHead_Id' + headID;
        
        var scriptTag = returnObjById('fpHead_Id' + headID);
        if(scriptTag){
          this.headLoc.removeChild(scriptTag);
        }
        headID++;
    }
    // buildScriptTag method
    JSONscriptRequest.prototype.buildScriptTag = function () {
        // Create the script tag
        this.scriptObj = document.createElement("script");

        // Add script object attributes
        this.scriptObj.setAttribute("type", "text/javascript");
        this.scriptObj.setAttribute("src", this.fullUrl);
        this.scriptObj.setAttribute("id", this.scriptId);
    };
    // removeScriptTag method
    JSONscriptRequest.prototype.removeScriptTag = function () {
        // Destroy the script tag
        this.headLoc.removeChild(this.scriptObj);  
    };
    // addScriptTag method
    JSONscriptRequest.prototype.addScriptTag = function () {
           
        //alert("this.scriptObj");
        // Create the script tag
        this.headLoc.appendChild(this.scriptObj);
    };
    
    FPObj.displayForums = function(jsonData) {
        var t = eval(jsonData); 
        var html = "<select id=\"selForum\" onchange=\"FP.GotoForum();\" >";    
    
        for (var i = 0; i < t.forums.length; i++) {        
            html += displayOption(t.forums[i].n,t.forums[i].id,t.forums[i].c,t.forums[i].d,t.forums[i].ch,t.forums[i].t);        
        }
        
        html += "</select>"; 
        html += "<button id=\"butGF\" type=\"button\" value=\"Go\" onclick=\"FP.GotoForum()\">Go</button>"; 
        var divForum = returnObjById("divForum");
        divForum.className = "";
        divForum.innerHTML = html;
        
        var butGotoForum = document.getElementById("butGF")
        var clickFunction = butGotoForum.onclick;
        var oB = new YAHOO.widget.Button(butGotoForum);
        oB.on("click", clickFunction); 
                
    };
    FPObj.displayForumThreads = function(jsonData) {
        var t = eval(jsonData); 
        var html = t.n + " -> " + t.c + "posts<br/>";    
        var arrThreads = t.forumList;
        
        var param = {};
       
        for (var i = 0; i < arrThreads.length; i++) {   
            arrThreads[i][0] = h2d(arrThreads[i][0]);     
            param.mid = arrThreads[i][0];
            param.au = arrThreads[i][1];
            param.su = arrThreads[i][2];
            html += thumbCodeBlock().supplant(param);       
        }
        
        html += "<hr/>"; 
        var bxThrd = returnObjById("boxThreads");
        bxThrd.className = "";
        bxThrd.innerHTML = html;
    };
    FPObj.displayVoteInfo = function(jsonData) {
        var t = eval(jsonData); 
        var r = t.voteInfo;    
        
        var el = returnObjById("pcinfo|" + r.mid);
        el.className = "";
        
        var html = "";
        if (r.status < 2 && r.voted !== 1) {
            html += "Vote total hidden";
        } else {
            html += "Current votes: " + r.count;
        }
        html += "<br />";
        
        switch (r.status) {
            case 0:
                html += "Voting has not yet commenced.";
            break;
            case 2:
                html += "Voting is now closed.";
            break;
            
            default:
                if (r.voted === 1) {
                    html += "Your vote has been recorded";
                } else {
                    if (mbrType.toLowerCase() === "full member" || mbrType.toLowerCase() === "superuser") {
                        html += "<button type=\"button\" class=\"voteButton\" title=\"Click here to vote for this photo.\" onclick=\"this.style.display='none';FP.VoteFor(" + r.mid + "); return false;\" >Vote for this photo!</button>";
                    } else {
                        html += "Full membership is required to vote";
                    }
                }
            break;
        }  
        
        el.innerHTML = html;      
    };
    FPObj.VoteFor = function(mid) {
        var codeRequest = "JSON/photocontest.aspx?mid=" + mid + "&v=y&cb=" + cacheBuster;
        AddJSONScriptTag(codeRequest);
    };
    FPObj.displayVoteResult = function(jsonData) {
        var t = eval(jsonData); 
        var r = t.voteResult;    
        
        var el = returnObjById("pcinfo|" + r.mid);
        el.className = "";
        
        var html = "";
        html += "Current votes: " + r.count;
        html += "<br />";
        
        switch (r.result) {
            case 0:
                html += "Oops. Something was screwy with your vote..";
                break;
           case 1:
                html += "Your vote was successful!";
                break;
        }  
        
        el.innerHTML = html;  
        
        if (r.result === 1) {
            
            var butArray = getElementsByTagNameAndClass(returnObjById("divMsgList"),"BUTTON","voteButton");
            for (var i = 0;i < butArray.length;i++) {
                butArray[i].style.display = "none";
            }
        }    
    };
    
    
    FPObj.displaySubscriptionStatus = function(jsonData) {
        var t = eval(jsonData); 
        var ss = t.subStatus[0];
        
        var el = returnObjById("divSubscribe");
        var html = "";
       
        if (ss.s === true) {        
            html += "<button type=\"button\" id=\"butSub\" title=\"Click here to stop receiving emails when this thread changes\" value=\"Unsubscribe\" onclick=\"FP.ThreadSubscribe(false); return false;\">Unsubscribe</button>";
        }
        else {
            html += "<button type=\"button\" id=\"butSub\" title=\"Click here to receive an email when this thread changes\" value=\"Subscribe\" onclick=\"FP.ThreadSubscribe(true); return false;\">Subscribe</button>";
        } 
        
        el.innerHTML = html;
        
        
        var butSub = document.getElementById("butSub")
        var clickFunction = butSub.onclick;
        var oB = new YAHOO.widget.Button(butSub);
        oB.on("click", clickFunction); 
        
    };
    FPObj.ThreadSubscribe = function(status) {
        var codeRequest = "JSON/threadsubscription.aspx?sub=" + status + "&tid=" + msgListArray[0].tid + "&cb=" + cacheBuster;
        AddJSONScriptTag(codeRequest);
    };
    FPObj.displayAuthInfo = function(jsonData) {
        var t = eval(jsonData); 
        var ai = t.authInfo[0];
        
        if (authObj[ai.un] === undefined) { authObj[ai.un] = ai;  }      
        
        setAuthInfo(ai);
    };    
    function setAuthInfo(ai) {
        var html = writeAuthInfo(ai);
        var idn = "authinfo|" + ai.un;
        var idsig = "siginfo|" + ai.un;
        var cntry = "country|" + ai.un;
        
        
        var el = document.getElementsByTagName('DIV');
        var i;
        for (i = 0; i < el.length; i++) {
            if (el[i].id === idn) {
                if (el[i].className !== "") {
                    el[i].className = "";
                    el[i].innerHTML = html;
                }
            }
            else if (el[i].id === idsig) {
                if (ai.s.length > 0) {
                    if (sig === "false") { el[i].innerHTML = "<hr />" + FP.InsertSmileys(ai.s); }
                }
            }
            else if (el[i].id === cntry) {
                el[i].innerHTML = flagCode(ai.c,ai.cn);
            }
        }   
          
    }
    function GetPhotoContestDetails() {
        
        var el = document.getElementsByTagName('DIV');
        for (var i = 0; i < el.length; i++) {
            if (el[i].id.indexOf("pcinfo|") === 0) {
                var mid = el[i].id.split("|")[1];
                var codeRequest = "JSON/photocontest.aspx?mid=" + mid + "&cb=" + cacheBuster;
                AddJSONScriptTag(codeRequest);
            }
        }
    }
    function showBoxList(listArray, listName, fid) {
        var divList = returnObjById("div" + listName + "List");
        divList.innerHTML = "";
        var divListItem;
        if (listArray.length > 0) {
            for (var i = 0; i < listArray.length; i++) {
                divListItem = document.createElement("DIV");
                divListItem.setAttribute("id", listName + listArray[i].mid);
                divListItem.innerHTML = boxListMsgCodeBlock(listArray[i]);
                divList.appendChild(divListItem);
            }
        } else {
            divList.innerHTML = "No records found";
        }
        
        var divRfrsh = returnObjById("div" + listName + "ref");
        var nod = -1;
        if (listName === "MAT") { 
            nod = 15; 
        }
        divRfrsh.innerHTML = "<a href=\"#\" onclick=\"FP.RefreshBoxList('" + listName + "',''," + fid + ",10," + nod + "); return false;\">refresh</a>";
        divRfrsh.className = "";        
        divList.className = "";    
    }
    FPObj.displayBoxList = function(jsonData) {
        var t = eval(jsonData);
        showBoxList(t.msgList,t.ln, t.fid);
    }; 
    function GetBoxList(listName,auth,fid,nol,nod,cacheBust) {
        var el = returnObjById("div" + listName + "List");
        if (el.innerHTML === "") {
            el.innerHTML = "Retrieving messages";
        }
        AddJSONScriptTag("JSON/boxlist.aspx?list=" + listName + "&auth=" + auth + "&fid=" + fid + "&nol=" + nol + "&nod=" + nod + "&cb=" + cacheBust);
        //AddJSONScriptTag("json_cache/" + listName + "Info/auth=" + auth + "!$!fid=" + fid + "!$!nol=" + nol + "!$!nod=" + nod + "!$!cb=" + cacheBust + ".js");
    }
    // returns a forum fingerprint
    FPObj.displayRefresh = function(jsonData) {
        var t = eval(jsonData);
        //alert(t.ffp + " -- " + t.ln);
        
        GetBoxList(t.ln,t.un,t.fid,t.nol,t.nod,t.ffp);
        
    };
    function showTileList(listArray, listName, fid) {
        var divList = returnObjById("div" + listName + "List");
        divList.innerHTML = "";
        var divListItem;
        if (listArray.length > 0) {
            for (var i = 0; i < listArray.length; i++) {
                divListItem = document.createElement("DIV");
                //divListItem.setAttribute("id", listName + listArray[i].mid);
                divListItem.className = "divTile";
                divListItem.innerHTML = boxTileMsgCodeBlock(listArray[i]);
                divList.appendChild(divListItem);
            }
        } else {
            divList.innerHTML = "No records found";
        }
        
        var divRfrsh = returnObjById("div" + listName + "ref");
        var nod = -1;
        divRfrsh.innerHTML = "<a href=\"#\" onclick=\"FP.RefreshBoxList('" + listName + "',''," + fid + ",20," + nod + "); return false;\">refresh</a>";
        divRfrsh.className = "";        
        divList.className = "";    
    }
    FPObj.displayTileList = function(jsonData) {
        var t = eval(jsonData);
        showTileList(t.msgList,t.ln, t.fid);
    }; 
    FPObj.RefreshBoxList = function(listName,un,fid,nol,nod) {
        var divRfrsh = returnObjById("div" + listName + "ref");
        divRfrsh.innerHTML = "Refreshing data... please wait.";
        divRfrsh.className = "busy";
        var codeRequest = "JSON/forumfingerprint.aspx?ln=" + listName + "&un=";
        if (listName === "MT") {
        codeRequest += uName;
        }
        codeRequest += "&fid=" + fid + "&nol=" + nol + "&nod=" + nod + "&cb=" + cacheBuster;
        AddJSONScriptTag(codeRequest);
    };
    
    // returns a JSON array with all the messages in the current thread
    FPObj.displayThrdMsgList = function(jsonData) {
        var t;
        try {
            t = eval(jsonData);
        } catch (e) {
            alert(e);
        }
        msgListArray = t.thrdMsgList;
        ProcessThrdMsgList();  
    };
    function ProcessThrdMsgList() {        
        
        var startPg = 1;
        //threadStarter = msgListArray[0].u.toLowerCase();
        threadStarter = returnObjById("divThreadAuthor").innerHTML.toLowerCase();
//        //check to see if a certain page of the thread has been requested
//        var pg = getURLparam("pg");
//        if (pg.length > 0) {
//            startPg = parseInt(pg,10);
//        }
//        else {        
//            //if a page hasn't specifically been requested then go to page of interest 
//            //(the page the requested message is on)
//            if (msgOI > 0) {
//                for (var i = 0; i < msgListArray.length; i++) {
//                    if (msgListArray[i].mid === msgOI) {
//                        startPg = parseInt((i/msgPP),10) + 1;
//                        break;
//                    }
//                }
//            }
//        }
        FP.GotoPg(startPg);
        
        //show the number of messages and allow for thread bookmarking
//        el = returnObjById("numMsgs");
//        el.innerHTML = msgListArray.length;
        var el = returnObjById("favThrd");
        var threadId = returnObjById("divThreadId").innerHTML;
        el.innerHTML = bookmarkThread(threadId);
        
        //show the thread view count
        //AddJSONScriptTag("JSON/threadviewcount.aspx?tid=" + threadId + "&noCache=" + (new Date()).getTime());
    }
        
    // returns a JSON array with all the message_id info of the messages in the current thread
    FPObj.displayThread = function(jsonData) {
        var t = eval(jsonData);
        var startPg = 1;
        msgListArray = t.threadList;        
        threadStarter = t.u.toLowerCase();
        
//        //check to see if a certain page of the thread has been requested
//        var pg = getURLparam("pg");
//        if (pg.length > 0) {
//            startPg = parseInt(pg,10);
//        }
//        else {        
//            //if a page hasn't specifically been requested then go to page of interest 
//            //(the page the requested message is on)
//            if (msgOI > 0) {
//                for (var i = 0; i < msgListArray.length; i++) {
//                    if (msgListArray[i][0] === msgOI) {
//                        startPg = parseInt((i/msgPP),10) + 1;
//                        break;
//                    }
//                }
//            }
//        }
        
        FP.GotoPg(startPg);
        
        //show the number of messages and allow for thread bookmarking
//        el = returnObjById("numMsgs");
//        el.innerHTML = msgListArray.length;
        var el = returnObjById("favThrd");
        el.innerHTML = bookmarkThread(msgListArray[0].tid);
        
        //show the thread view count
        //AddJSONScriptTag("JSON/threadviewcount.aspx?tid=" + msgListArray[0].tid + "&noCache=" + (new Date()).getTime());
    };
    FPObj.displayThreadViewCount = function(jsonData) {
        var t = eval(jsonData);
        var tvc = t.threadViewCount[0];
        if (tvc !== undefined) {
            var spanTVC = returnObjById("thrdVCnt"); 
            spanTVC.innerHTML = tvc.tvc;
        }
        //cloneMessageHeader();
    };
    
    FPObj.GotoPgA = function(pg) {
        setTimeout(function(){FP.GotoPg(pg);},10); //a quick 'doevents' so that the page doesn't lock up 
    };
    function GetMsgInfo(mi) {  
        
        //allocate the colors for the message
        var hdCls = "divMsgHeaderOrig yuimenubar";
        var bdyCls = "divMsgBodyOrig background3";        
        if (mi.u.toLowerCase() !== threadStarter) {
            hdCls = "divMsgHeaderReply yuimenubar";
            bdyCls = "divMsgBodyReply background1";
        }
        
        var param = {};
        param.mid = mi.mid;
        param.u = mi.u;
        param.neg = mi.pr[0];
        param.neu = mi.pr[1];
        param.pos = mi.pr[2];
            
        var html = "";
        
        if ((mi.pr[2] - mi.pr[0]) >= peerRvT) {
            var img = mi.img;
            
            html += "<div class=\"" + hdCls + "\" onclick=\"FP.ToggleVis('msgBdy" + mi.mid.toString() + "');\">";
            html += "<table style=\"width: 100%;\">";
            html += "<tr>";
            html += "<td style=\"width: 5%;\">";
            html += "<a name=\"" + mi.mid.toString()+ "\">#" + mi.mid.toString() + "</a>";
            html += "</td>";
            html += "<td style=\"width: 5%;\">";
            html += "<div id=\"divImgType_" + mi.mid + "\">";
            if (img.a !== undefined && img.a !== "") {
                html += "<b>[IMG]</b>";
            }
            else {
                html += "[txt]";
            }
            html += "</div>";
            html += "</td>";
            html += "<td> " + mi.ms + " </td>";
            html += "<td style=\"width: 20%\">" + mi.n + "</td>";
            
            //flag code
            html += "<td style=\"width: 5%;\">";
            if (authObj[mi.u] !== undefined) {
                html += flagCode(authObj[mi.u].c,authObj[mi.u].cn);
            } else {            
                html += "<div id=\"country|" + mi.u + "\"> </div>";
            }
            html += "</td>";
            
            var msgDate = new Date(mi.d);
            msgDate.setHours(msgDate.getHours() + tzDiff);
            
            html += "<td style=\"width: 20%; text-align: right;\">" + msgDate.getFullYear() + "/" + (msgDate.getMonth() + 1) + "/" + msgDate.getDate() + " " + msgDate.getHours() + ":" + msgDate.getMinutes() + "</td>";
            html += "</tr>";
            html += "</table>";
            html += "</div>";
            
            html += "<div id=\"msgBdy" + mi.mid.toString() + "\" class=\"" + bdyCls + "\">";
            
            //
            html += "<div id=\"divImg_" + mi.mid.toString()+ "\" class=\"divImg\">";            
            if (img.a !== undefined && img.a !== "") {    //if image exists then put it in                    
                html += "<div style=\"text-align: right;\">";
                if (uName.toLowerCase() === mi.u.toLowerCase() || mbrType.toLowerCase() === "superuser") {
                    html += "<a class=\"butLink\" href=\"" + root + "/messageGeocode.aspx?mid="+ mi.mid.toString() +"\">Geocode</a>";
                }
                if (mi.loc.length > 0) {
                    html += "<a class=\"butLink\" href=\"" + root + "/messageMap.aspx?mid="+ mi.mid.toString() +"\">Show on Map</a>";
                }
                html += "</div>";
                if (img.a === "blocked") {
                    html += "<div style=\"text-align: center;background-color:yellow;font-weight:bold;font-size:120%;margin:auto auto;\">";
                    html += "Please help! If your company can sponsor this section so these photos are permanently visible please email farmphoto@farmphoto.com<br/>";
                }
                html += imageCode(img.h,img.w,img.s,img.a);
                if (img.a === "blocked") {
                    html += "</div>";   
                }
                html += "<div style=\"text-align: center;\"><a href=\"" + root + "/ShowImage.aspx?mid=" + mi.mid + "\" class=\"newpage\">Original Image: " + Math.round(img.s/1000) + "kb, " + img.w + " x " + img.h + "</a><div onclick=\"FP.ShowEmbedCode('" + img.a + "',this,'" + mi.mid + "')\" style=\"text-align: center; cursor: pointer;\" class=\"clt$EmbedCode\">Toggle Embed Code</div></div>";
                html += "<div style=\"text-align: center;\">";
                html += ownershipStatement(img.o);
                html += bookmarkImage(mi.mid,img.a); 
                if (isPC) {
                    html += "<div id=\"pcinfo|" + mi.mid.toString() + "\" style=\"margin: auto; text-align: center; background-color: yellow; max-width: 300px;\"  class=\"busy\">Loading vote info</div>"; 
                }
                html += "</div>";               
            }
            html += "</div>";
            
            html += "<div style=\"overflow: auto; height: 100%;\">";
            
            html += "<div id=\"divAuthInfo|" + mi.mid + "\" class=\"divAuthInfo\">";
            if (authObj[mi.u] !== undefined) {
                html += writeAuthInfo(authObj[mi.u]);
            } else {            
                html += "<div id=\"authinfo|" + mi.u + "\" class=\"busy\">Loading details for " + mi.n + "</div>";
            }
            
            html += "</div>";

            html += "<div class=\"divMsgTxt\">";
            html += "<span id=\"msgBody|" + mi.mid.toString() + "\"class=\"msgBody\">" + FP.InsertSmileys(mi.mb) + "</span>";
            html += "<div id=\"siginfo|" + mi.u + "\"></div>";
            html += "<div id=\"msgfunc_" + mi.mid.toString()+ "\" class=\"divMsgFunc\">" + msgFuncCodeBlock(mi).supplant(param);
            html += msgPRCodeBlock().supplant(param);
            if (param.neg !== 0 || param.neu !== 0 || param.pos !== 0) {
                html += msgPRResultsCodeBlock().supplant(param);
            }
            html += "</div>";             
            html += "</div>";            
            html += "</div>";           
            html += "</div>";
            
        }
        else {
            html += "<div class=\"divPR\">";
            html += "<table style=\"width: 100%;\">";
            html += "<tr>";
            html += "<td style=\"width: 5%;\">";
            html += "<a name=\"" + mi.mid.toString()+ "\">#" + mi.mid.toString() + "</a>";
            html += "</td>";
            html += "<td style=\"text-align: left;\">";
            html += "Message hidden due to negative peer reviews";
            html += "</td>";
            html += "<td style=\"text-align: right;\">";
            html += msgPRCodeBlock().supplant(param);
            html += msgPRResultsCodeBlock().supplant(param);
            html += "</td>";
            html += "</tr>";
            html += "</table>";
            html += "</div>";
            
            html += "<div id=\"msgBdy" + mi.mid.toString()+ "\" class=\"" + bdyCls + "\">";
            
        }        
        
        return html;
    }
    FPObj.GotoPg = function(pg) {
        //headID = 0; //reset the script id (will overwrite older stuff)
        msgPg = pg;
        var divMsgList = returnObjById("divMsgList");
        divMsgList.innerHTML = "";
        msgListPointer = (msgPg - 1) * msgPP;
        
        //loop through all messages on page and put in the matching message
        var html = "";
        var maxMsg = (msgPg - 1) * msgPP + msgPP;
        if (maxMsg > msgListArray.length) { maxMsg = msgListArray.length; }
        for (var i=msgListPointer; i < maxMsg; i++) {
            html += "<div id=\"msg" + msgListArray[i].mid + "\" class=\"boxList\">" + GetMsgInfo(msgListArray[i]) + "</div>";
        }
        divMsgList.innerHTML = html;
        
        //clear "Loading Message List" notice
        var divMsgListMsg = returnObjById("divMsgListMsg");
        divMsgListMsg.className = "";
        divMsgListMsg.innerHTML = "";

        //after putting in the messages, put in the author details
        var tempAuthObj = {};
        
        for (i=msgListPointer; i < maxMsg; i++) {
            if (authObj[msgListArray[i].u] === undefined && tempAuthObj[msgListArray[i].u] === undefined){
                AddJSONScriptTag("JSON/authinfo.aspx?auth=" + msgListArray[i].uid + "&cb=" + msgListArray[i].uc );
                //AddJSONScriptTag("json_cache/AuthInfo/auth=" + msgListArray[i].uid + "!$!cb=" + msgListArray[i].uc + ".js");
                tempAuthObj[msgListArray[i].u] = "fetching";
            }
            else {
                if (authObj[msgListArray[i].u] !== undefined) {
                    setAuthInfo(authObj[msgListArray[i].u]);
                }
            }
        }
        
        if (isPC) { GetPhotoContestDetails() ;}
        
//        var thrdNav = showThreadNav(); //top and bottom page select code 
//        
//        var elHead = returnObjById("topNav");
//        var elFoot = returnObjById("botNav");
//        elHead.innerHTML = thrdNav;
//        elFoot.innerHTML = thrdNav;
        
//        if (msgListArray.length > 0) {
//            setTimeout(function(){retrieveNextMsg();},10); //a quick 'doevents' so that the page doesn't lock up 
//        }
        
    };
//    function cloneMessageHeader() {
//        var elHead = returnObjById("topNav");
//        var elFoot = returnObjById("botNav");
//        elFoot.innerHTML = elHead.innerHTML;
//    }
//    function showThreadNav() {
//        var html = "";
//        if (msgListArray.length > msgPP) {
//            var lastPg = Math.floor(msgListArray.length / msgPP) + 1;
//            if (msgPg > 3) html += "[<a href=\"#\" onclick=\"this.parentNode.innerHTML='Changing page';FP.GotoPgA(1);scrollTo(0,0); return false;\">1</a>]" ;
//            if (msgPg > 4) html += "&nbsp;<a href=\"#\" onclick=\"this.parentNode.innerHTML='Changing page';FP.GotoPgA(" + (msgPg-3) + ");scrollTo(0,0); return false;\">...</a>&nbsp;";
//            for (var i=1; i <= lastPg; i++) { 
//                if (i === msgPg) {
//                    html += "[" + i + "]";
//                }
//                else {
//                    if(Math.abs(i-msgPg) < 3) {
//                        html += "[<a href=\"#\" onclick=\"this.parentNode.innerHTML='Changing page';FP.GotoPgA(" + i + ");scrollTo(0,0); return false;\">" + i + "</a>]";
//                    }
//                }                
//            }
//            if (msgPg < (lastPg - 2)) html += "&nbsp;<a href=\"#\" onclick=\"this.parentNode.innerHTML='Changing page';FP.GotoPgA(" + (msgPg+3) + ");scrollTo(0,0); return false;\">...</a>&nbsp;";
//            if (msgPg < (lastPg - 3)) html += "[<a href=\"#\" onclick=\"this.parentNode.innerHTML='Changing page';FP.GotoPgA(" + lastPg + ");scrollTo(0,0); return false;\">" + lastPg + "</a>]";
//            if (lastPg > 5) html += "&nbsp;(" + msgPg + " of " + lastPg + ")";
//           
//        }
//        return html;
//    }
            
    function retrieveNextMsg() {        
        msgListPointer++;
        var maxMsg = (msgPg - 1) * msgPP + msgPP;
        if (maxMsg > msgListArray.length) { maxMsg = msgListArray.length; }
        if (msgListPointer <= maxMsg) { 
            retrieveMsg(msgListArray[(msgListPointer-1)].mid, msgListArray[(msgListPointer-1)][1]);     
        }
    }
    function retrieveMsg(mid, cb) {
        //if we already have the message info then use it, otherwise get the message info
        if (msgObj[mid] === undefined) {
            AddJSONScriptTag("json_cache/MsgImgInfo/mid=" + mid + "!$!cb=" + cb + ".js");
        }
        else {
            setMsgInfo(msgObj[mid]);
        }
    }
    
    FPObj.displayMsgImgInfo = function(jsonData) {
        var t = eval(jsonData); 
        var mi = t.msgInfo[0];
        msgObj[mi.mid] = mi;
        setMsgInfo(mi);
    };
    function setMsgInfo(mi) {
        
        var divMsgList = returnObjById("divMsgList");
        if (divMsgList !== null) {
            setMsgInfoToMsgList(mi);
        }
        var divMATList = returnObjById("divMATList");
        if (divMATList !== null) {
            setMsgInfoToMATList(mi);
        }
        addMsgToBoxList(mi,"divMRAT");
        addMsgToBoxList(mi,"divMRR");
        addMsgToBoxList(mi,"divMT");
    }
    function addMsgToBoxList(mi, listName) {
        if (returnObjById(listName + "List") !== null) {
        
            var divMsg = returnObjById(listName + mi.mid.toString());
        
            if (divMsg !== null) {                
                divMsg.innerHTML = boxListMsgCodeBlock(mi);
                divMsg.className = "";
            }        
        }        
    }
    function boxListMsgCodeBlock(mi) {
        var html = "";                
        if ((mi.pr[2] - mi.pr[0]) >= peerRvT) {
            html += "<div class=\"divLstImg\">";
            var attachment = "";
            if (mi.img.a !== undefined && mi.img.a !== "") {attachment = "IMG";}            
            html += attachment;
            html += "</div>";
            html += "<div class=\"divLstSub\">";
            html += "<a href=\"" + root + "/thread.aspx?mid=" + mi.mid + "\" title=\"" + mi.ms + "\">" + shortenString(mi.ms,20) + "</a>";
            html += "</div>";
            html += "<div class=\"divLstAuth\">";
            html += "<span title=\"" + mi.n + "\">" + shortenString(mi.n,12) + "</span>";
            html += "</div>";
            var msgDate = new Date(mi.d);
            html += "<div class=\"divLstAge\">";
            html += timeDiff(pgTime,msgDate);
            html += "</div>";
            html += "<div class=\"divLstFID\">";
            html += "[" + shortenString(mi.f,10) + "]";
            html += "</div>";
            html += "<div class=\"divLstBody\">";
            //html += FP.InsertSmileys(shortenString(mi.mb.replace(/\r|\n|\r\n/g, ""),30)) ;
            html += FP.InsertSmileys(shortenString(mi.mb.replace(/<br\/>/g, " "),90)) ;
            html += "</div>";
        } else {
            html += "<div class=\"\">";
            html += "Message hidden by peer review process";
            html += "</div>";        
        }
        return html;
    }
    function boxTileMsgCodeBlock(mi) {
        var html = "";                
        html += "<div class=\"divTileImgWnd\">";
        if ((mi.pr[2] - mi.pr[0]) >= peerRvT) {            
            html += "<table height=\"98\" cellspacing=\"0\" cellpadding=\"0\" width=\"98\"><tr><td align=\"center\" valign=\"middle\">";
            html += "<a href=\"" + root + "/thread.aspx?mid=" + mi.mid + "#" + mi.mid + "\">";
            var sz = thumbnailImageSize(mi.img.w,mi.img.h);
            if (sz.h > 90) {
              sz.w = sz.w * 90 / sz.h;           
              sz.h = 90;
            }
            if (sz.w > 90) {
              sz.h = sz.h * 90 / sz.w;  
              sz.w = 90;              
            }
            html += "<img height=\"" + sz.h + "\" width=\"" + sz.w + "\" title=\"" + mi.ms + "\" src=\"" + root + "/ImageURL.aspx?n=" + mi.img.a + "&s=thumbnail&log=1\" style=\"border: 2px solid rgb(221, 221, 221); margin: 0pt; padding: 2px;\"/>";
            html += "</a></td></tr></table></div>";
            html += "<div style=\"text-align: center; font-family: arial; font-size: 12px; white-space: nowrap;\">";
            html += "<a title=\"" + mi.ms + "\" href=\"" + root + "/thread.aspx?mid=" + mi.mid + "#" + mi.mid + "\">" + shortenString(mi.ms,20) + "</a>";
            html += "<div style=\"font-style: italic;\" title=\"" + mi.n + "\">" + shortenString(mi.n,12) + "</div>";
            var msgDate = new Date(mi.d);
            html += "<div style=\"font-size: 10px;\">" + msgDate.getFullYear() + "-" + (msgDate.getMonth() + 1) + "-" + msgDate.getDate()+ "</div>";            
        } else {
            html += "Message hidden by peer review process";
        }
        html += "</div>";            
        return html;
    }
    
    function setMsgInfoToMATList(mi) {
        var divMsg = returnObjById("divMAT" + mi.mid.toString());
        
        if (divMsg !== null) {
            var html = "";
            
            if ((mi.pr[2] - mi.pr[0]) >= peerRvT) {
                html += "<div class=\"divLstImg\">";
//                var attachment = "";
//                if (mi.img.a !== undefined && mi.img.a !== "") {attachment = "IMG";}            
                html += divMsg.innerHTML;
                html += "</div>";
                html += "<div class=\"divLstSub\">";
                html += "<a href=\"" + root + "/thread.aspx?mid=" + mi.mid + "\" title=\"" + mi.ms + "\">" + shortenString(mi.ms,20) + "</a>";
                html += "</div>";
                html += "<div class=\"divLstAuth\">";
                html += "<span title=\"" + mi.n + "\">" + shortenString(mi.n,12) + "</span>";
                html += "</div>";
                var msgDate = new Date(mi.d);
                html += "<div class=\"divLstAge\">";
                //alert("pgTime=[" + pgTime + "],msgDate=[" + msgDate + "],timeDiff(pgTime,msgDate)=[" + timeDiff(pgTime,msgDate) + "]");
                html += timeDiff(pgTime,msgDate);
                html += "</div>";
                html += "<div class=\"divLstFID\">";
                html += "[" + shortenString(mi.f,10) + "]";
                html += "</div>";
                html += "<div class=\"divLstBody\">";
                html += shortenString(mi.mb.replace(/\r|\n|\r\n/g, ""),30) ;
                html += "</div>";
            } else {
                html += "<div class=\"\">";
                html += "Message hidden by peer review process";
                html += "</div>";
            
            }
                
            divMsg.innerHTML = html;
            divMsg.className = "";
        }
    }
//    FPObj.displayImgInfo = function(jsonData) {
//        var t = eval(jsonData); 
//        var ii = t.imgInfo[0];
//        
//        imgObj[ii.mid] = ii;
//        setImgInfo(ii);
//    };
//    function setImgInfo(ii) {
//            
//        //otherwise continue
//        var divImgType = returnObjById("divImgType_" + ii.mid.toString()); 
//        
//        if (ii.a.length > 0) {
//            divImgType.innerHTML = "<b>[IMG]</b>";
//            var divImg = returnObjById("divImg_" + ii.mid.toString());
//            var html = "";
//            
//            html += "<div style=\"text-align: right;\">";
//            if (uName.toLowerCase() === mi.u.toLowerCase()) {
//                html += "<a class=\"clt$Geocode lnkBut\" href=\"messageGeocode.aspx?mid="+ ii.mid.toString() +"\">Geocode</a>";
//            }
//            html += "<a class=\"clt$MapIt lnkBut\" href=\"messageMap.aspx?mid="+ ii.mid.toString() +"\">Show on Map</a>";
//            html += "</div>";
//            html += imageCode(ii.h,ii.w,ii.s,ii.a);
//            html += "<div style=\"text-align: center;\"><a href=\"ShowImage.aspx?mid=" + ii.mid + "\" class=\"newpage\">Original Image: " + Math.round(ii.s/1000) + "kb, " + ii.w + " x " + ii.h + "</a><div onclick=\"FP.ShowEmbedCode('" + ii.a + "',this,'" + ii.mid + "')\" style=\"text-align: center; cursor: pointer;\" class=\"clt$EmbedCode\">Toggle Embed Code</div></div>";
//            html += "<div style=\"text-align: center;\">";
//            html += ownershipStatement(ii.o);
//            html += bookmarkImage(ii.mid,ii.a);
//            divImg.innerHTML = html;
//        }
//        else {            
//            divImgType.innerHTML = "[txt]";
//        }
//    }
    function imageCode(h, w, s, a) {
        if (w > 400) {
            //show medium image and make clickable
            var imgSize = mediumImageSize(w, h);
            return "<img class=\"medium zoomable\" src=\"" + imageUrl(a,"medium") + "\" style=\"width: " + imgSize.w.toString() + "px; height: " + imgSize.h.toString() + "px\" onclick=\"FP.ToggleImg(this," + imgSize.h.toString() + "," + imgSize.w.toString() + "," + h.toString() + "," + w.toString() + ")\">";
        }
        else
        {
            //show full image and make not clickable
            return "<img class=\"medium\" src=\"" + imageUrl(a,"original") + "\">";
        }
    }
    function imageUrl(n,s) {
        if (n === "blocked") {
            return root + "/images/imageblocked.gif";
        } else {
            return root + "/image.aspx?n=" + n + "&s=" + s;
        }
    }
    function mediumImageSize(w, h)
    {
        var imgSz = {};
        imgSz.w = 300;
        imgSz.h = h * imgSz.w / w;
        return imgSz;
    }
    function thumbnailImageSize(w, h)
    {
        var imgSz = {};
        imgSz.w = 90;
        imgSz.h = Math.floor(h * imgSz.w / w);
        return imgSz;
    }
    function ownershipStatement(o)
    {
        var ret = "";

        if (o.length > 0)
        {
            if (o === "perm") {
                ret = "[<span class=\"PstPerm\"><span class=\"clt$PstPerm\">posted with permission</span></span>] ";
                }
            else if (o === "orig") {
                ret = "[<span class=\"PstPerm\"><span class=\"clt$PstOwn\">posted by owner</span></span>] ";
                }
        }
        return ret;
    }
    function bookmarkImage(mid, a)
    {
        var s = "";

        if (a.length > 0)
        {            
            s += "[";
            s += "<a class=\"clt$AddPh2FavLnk\" href=\"" + root + "/favoritePhotos.aspx?addimg=" + mid + "\" title=\"Add photo to favorites\">+</a>";
            s += "] <span class=\"clt$AddPh2Fav\">Add photo to favorites</span>";
            
        }
        return s;
    }
    function bookmarkThread(tid)
    {
        var s = "";
        //s += "<span class=\"clt$AddThr2Fav\">Add thread to favorites</span>";
        s += "[<a class=\"clt$AddThr2FavLnk\" title=\"Add thread to favorites\" href=\"" + root + "/favoriteThreads.aspx?addthread=" + tid + "\">+</a>]";
        return s;
    }
    
    function displayOption(name,id,count,depth,children,translate) {
        var html = "<option value=\"" + id + "_" + children + "\" ";
        var color;
        
        if (children === 0) {
            color = "green";            
        }
        else {
            color = "blue";
        }        
        html += "style='color:" + color + ";'";  
        
        if (forumID === id) { html += " SELECTED"; }
             
        html += ">";
            
        //if (translate == 1) {
        //    name = "<span class=\"clt$" + name + "\">" + name + "</span>";
        //}
        html += indent(depth,name,children);
        if (count > 0) { html += " (" + count + ")"; }
        
        html += "</option>";
        return html;
    }
    
    FPObj.GotoForum = function() {
        var el = returnObjById("selForum");
            
        var val = el.options[el.selectedIndex].value;
        var kids = val.slice(val.indexOf("_") + 1);
        var fid = val.slice(0,val.indexOf("_"));
        if (kids === "0" || fid === "0") {
            var divForum = returnObjById("divForum");
            var au = FP.getURLparam("auth");
            var d = FP.getURLparam("n");
            var targetURL = "forum.aspx?fid=" +  fid.toString();
            if (au) {
                targetURL += "&auth=" + au;
            }
            if (d) {
                targetURL += "&n=" + d;
            }
            divForum.className = "busy";
            divForum.innerHTML = "Navigating to: " + el.options[el.selectedIndex].innerHTML;
            window.location.href = targetURL;  
        }
        else {
            alert("please choose a sub forum!");
        }
    };
    FPObj.GetForums = function(id,auth,nod,cacheBust) {
        var codeRequest = "JSON/forumlist.aspx?auth=" + auth + "&n=" + nod + "&cb=" + cacheBust;
        //var codeRequest = "json_cache/ForumListInfo/auth=" + auth + "!$!n=" + nod + "!$!cb=" + cacheBust + ".js";
        forumID = id;
        AddJSONScriptTag(codeRequest);
        
    };
    FPObj.GetThreads = function(id,auth,nod,cacheBust) {
        //var codeRequest = "JSON/JSON_Forums.aspx?auth=" + auth + "&n=" + nod + "&cb=" + cacheBust;
        var codeRequest = "json_cache/ForumThreads/fid=" + id + "!$!auth=" + auth + "!$!n=" + nod + "!$!cb=" + cacheBust + ".js";
        forumID = id;
        AddJSONScriptTag(codeRequest);
        
    };
    function readPageSettings() {
        try {
            if (returnObjById("pageSettings") !== null) {
                var psMsgPP = returnObjById("psMsgPP"); //messages per page
                var psAv = returnObjById("psAv"); //Avatars Hidden - true/false
                var psSig = returnObjById("psSig"); //Signatures Hidden - true/false
                var psUTC = returnObjById("psUTC"); // UTC Page Load TIme
                var psTO = returnObjById("psTO"); // Time Zone Offset - hours
                var psPRA = returnObjById("psPRA"); //Peer Reviews Enabled - true/false
                var psPRT = returnObjById("psPRT"); //Peer Reviews Threshold
                var psPE = returnObjById("psPE"); //Posting Enabled - true/false
                var psUName = returnObjById("psUName"); //username
                var psMbrType = returnObjById("psMbrType"); //membership type
                root = returnObjById("psRoot").innerHTML.toLowerCase();//root folder
                msgPP = parseInt(psMsgPP.innerHTML,10);
                av = psAv.innerHTML.toLowerCase();
                sig = psSig.innerHTML.toLowerCase();
                peerRv = psPRA.innerHTML.toLowerCase();
                peerRvT =  parseInt(psPRT.innerHTML,10);
                postEn = psPE.innerHTML.toLowerCase();
                tzDiff = parseInt(psTO.innerHTML,10);
                pgTime = new Date(psUTC.innerHTML);
                tDiff = pgTime.getTime() - (new Date().getTime());
                uName = psUName.innerHTML;
                mbrType = psMbrType.innerHTML;
                
                if (returnObjById("isPC") !== null) {
                    isPC = true; //isPhotoContest
                }
            }
        } catch(err) {
            alert("Page settings error - " + err.description);
        }
    }
    FPObj.ReadPageSettings = function() {
        readPageSettings();        
    };
    FPObj.GetMessageList = function(tid,mid,cacheBust) {
        msgOI = mid; //message of interest in thread;
        readPageSettings();
        
        //get the list
        var divMsgList = returnObjById("divMsgList");
        var msgArray = getElementsByTagNameAndClass(divMsgList,"DIV","mI");
        
        var thrdMsgList = [];
        for (var i = 0;i < msgArray.length;i++) {
            var msg = {};
            var msgDeets = getElementsByTagNameAndClass(msgArray[i],"DIV","ms")[0];
            msg.ms = msgDeets.innerHTML;
            msg.mb = getElementsByTagNameAndClass(msgArray[i],"DIV","mb")[0].innerHTML;
            msg.u = msgDeets.attributes["xU"].nodeValue;
            msg.uid = parseInt(msgDeets.attributes["xUid"].nodeValue,10);
            msg.uc = parseInt(msgDeets.attributes["xUc"].nodeValue,10);
            msg.n = msgDeets.attributes["xN"].nodeValue;
            msg.mid = parseInt(msgDeets.attributes["xMid"].nodeValue,10);
            msg.fid = parseInt(msgDeets.attributes["xFid"].nodeValue,10);
            msg.f = msgDeets.attributes["xF"].nodeValue;
            msg.tid = parseInt(msgDeets.attributes["xTid"].nodeValue,10);
            msg.tp = parseInt(msgDeets.attributes["xTp"].nodeValue,10);
            msg.d = msgDeets.attributes["xD"].nodeValue;
            msg.img = {};
            var divImg = getElementsByTagNameAndClass(msgArray[i],"DIV","img")[0];
            if (divImg) {
                msg.img.a = divImg.attributes["xA"].nodeValue;
                msg.img.w = parseInt(divImg.attributes["xW"].nodeValue,10);
                msg.img.h = parseInt(divImg.attributes["xH"].nodeValue,10);
                msg.img.s = parseInt(divImg.attributes["xS"].nodeValue,10);
                msg.img.o = divImg.attributes["xO"].nodeValue;
            }
            
//            if ((getElementsByTagNameAndClass(msgArray[i],"DIV","img")[0]).getElementsByTagName("DIV").length > 0) {
//                msg.img.a = getElementsByTagNameAndClass(msgArray[i],"DIV","a")[0].innerHTML;
//                msg.img.w = parseInt(getElementsByTagNameAndClass(msgArray[i],"DIV","w")[0].innerHTML,10);
//                msg.img.h = parseInt(getElementsByTagNameAndClass(msgArray[i],"DIV","h")[0].innerHTML,10);
//                msg.img.s = parseInt(getElementsByTagNameAndClass(msgArray[i],"DIV","s")[0].innerHTML,10);
//                msg.img.o = getElementsByTagNameAndClass(msgArray[i],"DIV","o")[0].innerHTML;
//            }
            msg.pr = [];
            if (getElementsByTagNameAndClass(msgArray[i],"DIV","pr")[0].innerHTML.length > 0) {
                 var pr = getElementsByTagNameAndClass(msgArray[i],"DIV","pr")[0].innerHTML.split(",");
                 msg.pr = [parseInt(pr[0],10),parseInt(pr[1],10),parseInt(pr[2],10)];
            }
            msg.loc = [];
            if (getElementsByTagNameAndClass(msgArray[i],"DIV","loc")[0].innerHTML.length > 0) {
                msg.loc = getElementsByTagNameAndClass(msgArray[i],"DIV","loc")[0].innerHTML.split(",");
            }
            
            thrdMsgList.push(cloneObject(msg));
        }
        msgListArray = thrdMsgList;
        ProcessThrdMsgList();
    };
    function cloneObject(obj) {
        if (typeof obj !== 'object' || obj == null) {
            return obj;
        }
        var c = obj instanceof Array ? [] : {};
        for (var i in obj) {
            var prop = obj[i];
            if (typeof prop == 'object') {
               if (prop instanceof Array) {
                   c[i] = [];
                   for (var j = 0; j < prop.length; j++) {
                       if (typeof prop[j] != 'object') {
                           c[i].push(prop[j]);
                       } else {
                           c[i].push(cloneObject(prop[j]));
                       }
                   }
               } else {
                   c[i] = cloneObject(prop);
               }
            } else {
               c[i] = prop;
            }
        }
        return c;
    }
    FPObj.MouseOverBoxList = function(listName,auth,fid,nol,nod,cacheBust) {
        var el = returnObjById("head_box" + listName);
        if (moState[listName] === undefined) {
            moState[listName] = 1;
            GetBoxList(listName,auth,fid,nol,nod,cacheBust);
        }
    };
    FPObj.GetSubscription = function(tid) {
        var codeRequest = "JSON/threadsubscription.aspx?tid=" + tid + "&cb=" + cacheBuster;
        AddJSONScriptTag(codeRequest);
        
    };
    function dateDiff(date1,date2) {
        var arrDate1 = date1.split("/");
        var arrDate2 = date2.split("/");
        var d1 = new Date(arrDate1[2],arrDate1[0] - 1,arrDate1[1]);
        var d2 = new Date(arrDate2[2],arrDate2[0] - 1,arrDate2[1]);
        return parseInt((d2.getTime()-d1.getTime())/86450000/365);
    }
    function writeAuthInfo(ai) {
        
        var html = "";
        if (av === "false") {
            if (ai.a.length > 0) { html += "<img src=\"" + root + "/ShowAvatar.aspx?a=" + ai.a + "\"/>"; }
        }
        var name;
        if (ai.n.length > 0) {
            name = ai.n;
        }
        else {
            name = ai.un;
        }
        html += "<br /><nobr><span class=\"authName\">" + name + "</span>[<a class=\"clt$AddU2FavLnk\" title=\"Add user to favorites\" href=\"" + root + "/favoriteauthors.aspx?addauth=" + ai.un + "\">+</a>]</nobr><br/>";
        html += "[<a class=\"clt$AuthHistLnk\" title=\"History\" href=\"" + root + "/authorhistory.aspx?auth=" + ai.un + "\">h</a>]";
        html += "[<a class=\"clt$AuthPostLnk\" title=\"Posts\" href=\"" + root + "/forum.aspx?auth=" + ai.un + "\">p</a>]";
        html += "[<a class=\"clt$AuthFavLnk\" title=\"Favorites\" href=\"" + root + "/favoritephotos.aspx?auth=" + ai.un + "\">f</a>]";
        if (ai.ws > 0 && ai.w.length > 7) {
            html += "[<a target=\"_blank\" href=\"" + ai.w + "\" title=\"" + ai.w + "\">w</a>]";
        }
        html += "[<a class=\"clt$AuthMapLnk\" title=\"Map\" href=\"" + root + "/membersMap.aspx?auth=" + ai.un + "\">m</a>]";
        html += "[<a class=\"clt$AuthPMapLnk\" title=\"Map Photos\" href=\"" + root + "/messageMap.aspx?auth=" + ai.un + "\">mp</a>]";
        html += "[<a title=\"email\" href=\"" + root + "/email_author.aspx?to=" + ai.un + "&n=" + name + "\">@</a>]";
        
        if (ai.msn.length > 0) { html += "<a href=\"msnim:chat?contact=" + ai.msn + "\"><img border=\"0\" src=\"" + root + "/Images/im_msn.gif\"></a>"; }
        if (ai.aim.length > 0) { html += "<a href=\"aim:goIM?screenname=" + ai.aim + "\"><img border=\"0\" src=\"" + root + "/Images/im_aim.gif\"></a>"; }
        if (ai.yah.length > 0) { html += "<a href=\"http://edit.yahoo.com/config/send_webmesg?.target=" + ai.yah + "&.src=pg\"><img border=0 src=\"http://opi.yahoo.com/online?u=" + ai.yah + "&m=g&t=0&l=us\"></a>"; }
        if (ai.icq.length > 0) { html += "<a href=\"http://wwp.mirabilis.com/" + ai.icq + "\" target=\"_blank\"><img border=\"0\" hspace=\"2\" src=\"http://wwp.icq.com/scripts/online.dll?icq=" + ai.icq + "&amp;img=5\" align=\"absmiddle\" height=\"18\" width=\"18\" alt=\"Online Status For " + ai.icq + "\" title=\"Online Status For " + ai.icq + "\"></a>"; }
        html += "<br />";
        
        if (av === "false") {
            var postlen = dateDiff(ai.f,ai.l);
//            var col = "Black";
//            if (postlen >= 6) {
//                col = "Gold";
//            } else if (postlen >= 4) {
//                col = "Silver";
//            } else if (postlen >= 2) {
//                col = "Green";
//            }
            html += "<span class=\"BriefStats\">";
            html += "<span class=\"clt$FstPost\">1st Post</span>: " + ai.f + "<br />";
            html += "<span class=\"clt$LstPost\">Last Post</span>: " + ai.l + "<br />";
            if (postlen > 0) {
                html += ("<img src=\"" + root + "/images/gstar.gif\"/>").repeat(postlen) + "<br />";
            }
            html += "<span class=\"clt$NumPost\"># Posts</span>: ";
            html += "<span style=\"font-size: larger; font-weight: bold;\">" + ai.t + "</span><br />";
            if (ai.t > 1000) {
                html += ("<img src=\"" + root + "/images/gball.gif\"/>").repeat(parseInt(ai.t/1000)) + "";     
            }       
            html += "</span>";
        }
        return html;
    }
    function msgFuncCodeBlock(mi) {
        var html = ""; 
        if (postEn === "true") {  
            html += "<button class=\"butBut\" type=\"button\" value=\"Quote\" onclick=\"MU.Quote(" + mi.mid + ")\" >Quote</button>";
            //html += "<a class=\"butLink\" href=\"" + root + "/post.aspx?qid={mid}\">Quote</a>";
            if (uName.toLowerCase() === mi.u.toLowerCase() || mbrType.toLowerCase() === "superuser") {
                html += "<button class=\"butBut\" type=\"button\" value=\"Edit\" onclick=\"MU.Edit(" + mi.mid + ")\" >Edit</button>";
            }
            if (mbrType.toLowerCase() === "superuser") {
                html += "<button class=\"butBut\" type=\"button\" value=\"Delete Message\" onclick=\"window.location.href='" + root + "/messageDelete.aspx?mid={mid}';\">Delete Message</button>";
                //html += "<a class=\"butLink\" href=\"" + root + "/messageDelete.aspx?mid={mid}\">Delete Message</a>";
            }
        }
        return html;
    }
    function msgPRCodeBlock() {
        //peer reviews
        var html = ""; 
        if (postEn === "true" && peerRv === "true") {
                html += "<button class=\"butBut\" type=\"button\" value=\"Peer Review\" onclick=\"window.location.href='" + root + "/PeerReview.aspx?r=msg&mid={mid}';\">Peer Review</button>";
                //html += "<a class=\"butLink\" href=\"" + root + "/PeerReview.aspx?r=msg&mid={mid}\">Peer Review</a> ";
        }
        return html;      
    }
    function msgPRResultsCodeBlock() {
        //peer review results
        var html = ""; 
        html += "<span class=\"prNeg\">{neg}</span> / <span class=\"prNeut\">{neu}</span> / <span class=\"prPos\">{pos}</span>";
        return html;      
    }
    function thumbCodeBlock() {
    
        var html = "";      
            html += "<div style=\"border: 1px solid #FFFFF0; overflow: hidden; background-color: White; text-align: center; width: 98px; float: left;\">";
            html += "<div style=\"margin: 0pt auto; overflow: hidden; background-color: White; width: 98px; height: 98px; text-align: center; display: table-cell; vertical-align: middle;\">";
            html += "<table width=\"98\" height=\"98\" cellspacing=\"0\" cellpadding=\"0\"><tr><td valign=\"middle\" align=\"center\">";
            html += "<a id=\"thumb_{mid}\" target=\"_top\" href=\"" + root + "/message.aspx?mid={mid}#{mid}\"></a>";
            html += "</td></tr></table>";
            html += "</div>";
            html += "<div style=\"text-align: center; font-family: arial; font-size: 12px; white-space: nowrap;\">";
            html += "<a title=\"{su}\" target=\"_top\" href=\"" + root + "/message.aspx?mid={mid}#{mid}\">{su}</a>";
            html += "<div style=\"font-style: italic;\">{au}</div>";
            html += "<div style=\"font-size: 10px;\">{d}</div>";
            html += "</div>";
            html += "</div>";
            
        return html;
    }
    
    //adds the message view icons where required
    FPObj.AddViews = function(threadID,replies) {
        var html = "";
        var cb = replies + 1;
        html += "<a class=\"clt$vImgTileVw\" href=\"" + root + "/threadTiles.aspx?tid=" + threadID + "&cb=" + cb + "\" title=\"View thread images in tile view\">";
        html += "<img src=\"" + root + "/images/tiles.gif\" border=\"0\" hspace=\"2px\">";
        html += "</a>";

        html += "<a class=\"clt$vSldShw\" href=\"" + root + "/threadViewer.aspx?tid=" + threadID + "&cb=" + cb + "\" title=\"View thread slideshow\">";
        html += "<img src=\"" + root + "/images/slides.gif\" border=\"0\" hspace=\"2px\">";
        html += "</a>";

        html += "<a class=\"clt$vTimeLn\" href=\"" + root + "/timelineThread.aspx?tid=" + threadID + "\" title=\"View thread timeline\">";
        html += "<img src=\"" + root + "/images/timeline.gif\" border=\"0\" hspace=\"2px\">";
        html += "</a>";
    	
        document.write(html);                    
    };
    //hides and shows thread message bodies
    FPObj.HideAllMsgs = function(state) {
      var items = document.getElementsByTagName('div');
      var i = 0;
      var item;
      
      do
      {
        i = i + 1;
        item = items[i-1];
        if (item !== undefined) {
         if (item.id) {
          if (item.id.indexOf("msgBdy") === 0) {
             if (state) {
                  if (item.style.display !== "none")
                  {
                    item.style.display = "none";
                  }
             }
             else
             {                
                 if (item.style.display !== "")
                 {
                    item.style.display = "";
                 }
             }
          }
         }
        }
      } while (i <= items.length);      
    };
    FPObj.ToggleVis = function(id) {
        var item = document.getElementById(id);
        if (item !== null) {
            if (item.style.display !== "none") {
                item.style.display = "none";
            }
            else
            {
                item.style.display = "";
            }
        }
    };
    FPObj.GetBoxState = function(id,init) {
        // current position from cookies, 'init' is a 0 or 1 and refers to default state
        var boxState = parseInt(readCookie('FPBoxState_box' + id),10);
        if (isNaN(boxState)) { boxState=init; }
        
        if (boxState === 1) {
            getList(id);
            FP.ShowHideBox(id);
        }
    };
    FPObj.ShowHideBox = function(id) {
        var box = document.getElementById("body_box" + id);
        if (box !== null) {            
            var boxBut = document.getElementById("but_box" + id);
            if (box.style.display !== "none") {
                box.style.display = "none";
                boxBut.innerHTML = "Click to expand";
                //boxBut.innerHTML = "v";
                document.cookie = 'FPBoxState_box' + id + '=0';
            }
            else
            {
                box.style.display = "";
                //boxBut.innerHTML = "Click to close";
                boxBut.innerHTML = "^";
                document.cookie = 'FPBoxState_box' + id + '=1';
            }
        }
    };
    FPObj.ToggleImg = function(obj,mh,mw,h,w) {            
        //obj.style.cursor = 'wait';
         
        if (obj.src.indexOf("s=medium") >= 0)
        {
            obj.src = obj.src.replace("s=medium", "s=original") ;
            obj.style.height = h + "px";
            obj.style.width = w + "px";                    
            
            var body=document.getElementsByTagName("BODY")[0];
            var bus=document.createElement("IMG");
            var pos = findPos(obj);
            bus.id = "busyIcon_" + obj.parentNode.id;
            bus.src= root + "/Images/icon_busy.gif";
            bus.style.position="absolute";
            bus.style.left=(pos[0]+obj.width/2)+"px";
            bus.style.top=(pos[1]+obj.height/2)+"px";
            bus.style.zIndex="999";
            body.appendChild(bus);
            
            obj.onload=function(){bus.parentNode.removeChild(bus);};
        }
        else
        {
            var busyIcon = document.getElementById("busyIcon_" + obj.parentNode.id);
            if (busyIcon !== undefined && busyIcon !== null) {
                busyIcon.parentNode.removeChild(busyIcon);
            }
            obj.src = obj.src.replace("s=original","s=medium") ;
            obj.style.height = mh + "px";
            obj.style.width = mw + "px";
            obj.onload = null;
        }
        //obj.style.cursor = 'url(magnify.cur)';
    };
    FPObj.ShowEmbedCode = function(name,obj,mid)
    {
        if (obj.id === "open") {
            target = returnObjById("embedCode_" + name);
            target.parentNode.removeChild(target);
            obj.id = "";
        }
        else {
            obj.id = "open";
            var div = document.createElement("div");
            div.style.backgroundColor = "#FFFFF0";
            div.style.border = "solid 1px Red";
            div.style.overflow = "auto";
            div.style.height = "100%";
            div.style.textAlign = "left";
            div.id = "embedCode_" + name;
            var html = "";
            html += "<table border='0'>";
            html += "<tr><td><b>HTML</b>:</td><td>" + imageUrl(name,'original') + "</td></tr>";
            html += "</div><div>";
            html += "<tr><td><b>BBCode</b>:</td><td>[url=" + root + "/thread.aspx?mid=" + mid + "#" + mid + "][img]" + imageUrl(name,'original') + "[/img][/url]</td></tr>";
            html += "<tr><td><b>Google Gadget</b>:</td><td>&lt;script src=\"http://gmodules.com/ig/ifr?url=" + root + "/gadgets/images/MsgImg.xml&amp;up_mid=" + mid + "&amp;up_size=Maximum&amp;up_bCol=Ivory&amp;up_fCol=Green&amp;up_link=1&amp;up_title=1&amp;up_author=1&amp;up_subject=1&amp;up_date=1&amp;synd=open&amp;w=auto&amp;h=540&amp;title=&amp;border=%23ffffff%7C3px%2C1px+solid+%23999999&amp;output=js\"&gt;&lt;/script&gt;</td></tr>";
            html += "</table>";
            div.innerHTML = html;
            obj.parentNode.appendChild(div);
        }
    };
    FPObj.MenuBar = function () { 
        var html = "";
        html += menuSection(true, "Navigation", [["/forum.aspx","Home",""],["/allforums.aspx","View all forums",""]]) 
        html += menuSection(true, "Member Info", [["/Members.aspx","Member listing",""],["/NewPosters.aspx","Posts of new members",""],["/MembersMap.aspx","Map of members",""],["/usersonline.aspx","Members online",""]]) 
        html += menuSection(true, "Recent Posts", [["/recentthreadhist.aspx","24 hour heat map",""],["/recentpostlisting.aspx","Last 48 hours",""],["/forum.aspx?n=7","Last 7 days",""],["/timelineRecentThreads.aspx","Timeline",""]]) 
        html += menuSection(true, "Popular", [["/mostViewedThreads.aspx","Most viewed threads",""],["/mostFollowedThreads.aspx","Most followed threads",""],["/favorites.aspx","Favorites",""],["/avatars.aspx","Avatars",""],["/PeerReviewSynopsis.aspx","Peer Reviews",""]]) 
        html += menuSection(true, "Help", [["/codeofconduct.aspx","Code of conduct",""],["/FAQ.aspx","FAQ",""],["/FormatCodes.aspx","Text Formatting Code",""],["/about.aspx","About",""]])
        if (mbrType === "Guest") {
            html += menuSection(true, "Sign up or Sign in!", [["/login.aspx?v=new","Become a member",""],["/login.aspx?ReturnUrl=" + escape(window.location.href),"Sign in","menuLogin"]]) 
        } else {
            html += "<li class=\"yuimenubaritem\"><a class=\"yuimenubaritemlabel\" href=\"#myPages\">My Pages</a>";
            html += "<div id=\"myPages\" class=\"yuimenu\">";
            html += "<div class=\"bd\">";
            html += "<ul>";
            html += "<li class=\"yuimenuitem\"><a class=\"yuimenuitemlabel\" href=\"#myFavorites\">My Favorites</a>";
            html += "<div id=\"myFavorites\" class=\"yuimenu\">";
            html += "<div class=\"bd\">";
            html += "<ul class=\"first-of-type\">";
            html += menuItem("/favoriteAuthors.aspx","Members","");
            html += menuItem("/favoritePhotos.aspx","Photos","");
            html += menuItem("/favoriteThreads.aspx","Threads","");
            html += "</ul></div></div></li>";
            html += menuItem("/forum.aspx?auth=" + escape(uName) + "\"","My Posts","");
            html += menuItem("/memberThreads.aspx","My Threads","");
            html += menuItem("/authorhistory.aspx?s=true","My History (Threads only)","");
            html += menuItem("/authorhistory.aspx","My History (All posts)","");
            html += menuItem("/profile.aspx","My Profile","");
            html += menuItem("/userspace.aspx","My User Space","");
            html += "</ul></div></div></li>";
            html += "<li class=\"yuimenubaritem\"><a id=\"menuLogout\" class=\"yuimenubaritemlabel\" href=\"" + root + "/logout.aspx\">Logout " + uName + "</a></li>";
        }        
        returnObjById("ulTopMenu").innerHTML = html;
        
        var oMenuBar = new YAHOO.widget.MenuBar("topMenu", { 
                                                        autosubmenudisplay: true, 
                                                        hidedelay: 750, 
                                                        lazyload: true });


            oMenuBar.render();
    }
    function menuSection(first,title,arr) {
        var html = "";
        var titleLower = title.replace(/ /ig,"").toLowerCase();
        html += "<li class=\"yuimenubaritem ";
        if (first) { html += "first-of-type"; }
        html += "\"><a class=\"yuimenubaritemlabel\" href=\"#" + titleLower + "\">" + title + "</a>";
        html += "<div id=\"" + titleLower + "\" class=\"yuimenu\"><div class=\"bd\"><ul>";
        
        for (var i = 0; i < arr.length; i++) {
            html += menuItem(arr[i][0],arr[i][1],arr[i][2])
        }
        
        html += "</ul></div></div></li>";
        return html;
    }
    function menuItem(url,title,id) {
        return "<li class=\"yuimenuitem\"><a id=\"" + id + "\" class=\"yuimenuitemlabel\" href=\"" + root + url + "\">" + title + "</a></li>";
    }
    
//    FPObj.LoginView = function()
//    {
//        var divSettings = returnObjById("divSettings");
//        if (divSettings !== null) {
//            var html = "";
//            if (mbrType !== "Guest") {
//                html += "My Favorites: <a class=\"butLink\" href=\"" + root + "/favoriteAuthors.aspx\">Members</a><a class=\"butLink\" href=\"" + root + "/favoritePhotos.aspx\">Photos</a><a class=\"butLink\" href=\"" + root + "/favoriteThreads.aspx\">Threads</a>";
//                html += " | <a class=\"butLink\" href=\"" + root + "/forum.aspx?auth=" + escape(uName) + "\">My Posts</a>";
//                html += "<a class=\"butLink\" href=\"" + root + "/memberThreads.aspx\">My Threads</a>";
//                html += "<a class=\"butLink\" href=\"" + root + "/authorhistory.aspx\">My History</a>";
//                html += "<a class=\"butLink\" href=\"" + root + "/profile.aspx\">My Profile</a>";
//                html += " | " + uName;
//                html +=  " (" + mbrType;
//                html += ") <a class=\"butLink\" href=\"" + root + "/logout.aspx\"><img src=\"" + root + "/Images/icon_logged_on.gif\" alt=\"Logged On\" />Logout</a>";
//            } else {
//                html += "<a class=\"butLink\" href=\"" + root + "/login.aspx?v=new\">Join!</a>&nbsp;<a class=\"butLink\" href=\"" + root + "/login.aspx?ReturnUrl=" + escape(window.location.href) + "\"><img src=\"" + root + "/Images/icon_logged_off.gif\" alt=\"Logged Out\" />Login</a>";
//            }
//            
//            divSettings.innerHTML = html;
//            divSettings.className="divSettings";
//        }
//    };
//    FPObj.SiteTitle = function() {    
//        var html = "";
//        //html += "<a name=\"pgTop\"><span class=\"SiteTitle\">farmphoto - " + titleQuote() + "</span></a><br />";
//        html += "<span class=\"TopMenu\">";
//        html += "<a class=\"butLink\" href=\"" + root + "/forum.aspx\">Home</a>";
//        html += "<a class=\"butLink\" href=\"" + root + "/allforums.aspx\">All Forums</a>";
//        html += "<a class=\"butLink\" href=\"" + root + "/Members.aspx\">Members</a>";
//        html += "<a class=\"butLink\"  href=\"" + root + "/NewPosters.aspx\">New Members</a>";
//        html += "<a class=\"butLink\" href=\"" + root + "/MembersMap.aspx\">Map</a>";
//        html += "<a class=\"butLink\" href=\"" + root + "/usersonline.aspx\">Members Online</a>";
//        html += "<a class=\"butLink\" href=\"" + root + "/favorites.aspx\">Favorites</a>";
//        html += "<a class=\"butLink\" href=\"" + root + "/avatars.aspx\">Avatars</a>";
//        html += "<a class=\"butLink\" href=\"" + root + "/PeerReviewSynopsis.aspx\">Peer Reviews</a>";
//        html += "<a class=\"butLink\" href=\"" + root + "/codeofconduct.aspx\">Code of Conduct</a>";
//        html += "</span><br /><span class=\"TopMenu\">";
//        html += "<a class=\"butLink\" href=\"" + root + "/recentthreadhist.aspx\">24 hours</a>";
//        html += "<a class=\"butLink\" href=\"" + root + "/recentpostlisting.aspx\">48 hours</a>";
//        html += "<a class=\"butLink\" href=\"" + root + "/forum.aspx?n=7\">7 days</a>";
//        html += "<a class=\"butLink\" href=\"" + root + "/timelineRecentThreads.aspx\">Timeline</a>";
//        html += "<a class=\"butLink\" href=\"" + root + "/mostViewedThreads.aspx\">Most Viewed</a></span>";
//        returnObjById("SiteTitle").innerHTML = html;
//        
//    };
//    function titleQuote() {
//        var quoteArray = [
//        "<span class=\"clt$tqIdeal\">The ideal place to share farming photos.</span>",
//        "<span class=\"clt$tqFFBF\">Photos. For farmers. By farmers.</span>",
//        "<span class=\"clt$tqDigPhot\">Digital photography for farmers.</span>",
//        "<span class=\"clt$tqPfF\">Photography for farmers.</span>",
//        "<span class=\"clt$tqWorld\">The world of farming in photos.</span>",
//        "<span class=\"clt$tqPYF\">Picture yourself farming.</span>",
//        "<span class=\"clt$tqGFC\">The global farmer community.</span>",
//        "<span class=\"clt$tqInterLan\">Photos. The international farming language.</span>",
//        "<span class=\"clt$tqGloFrm\">The global farming community.</span>",
//        "<span class=\"clt$tqFrmNvr\">Farming like you've never seen it before.</span>"
//        ];
//        return quoteArray[Math.ceil(Math.random()*quoteArray.length-1)];         
//    }
    FPObj.jump2 = function() {
        var el = returnObjById("jumpTo");
        window.location.href = root + "/thread.aspx?mid=" + el.value + "#" + el.value;
    };  
    FPObj.search4 = function() {
        var el = returnObjById("search4");
        window.location.href = root + "/searchAPIRaw.aspx?q=" + escape(el.value);
    };  
    FPObj.ExpImg = function(w,el,clickable) {
        var body=document.getElementsByTagName("BODY")[0];
        var divFrame=document.createElement("DIV"); 
        var aLink=document.createElement("A");
        divFrame.appendChild(aLink);
        if (clickable !== undefined && clickable === true) {
            aLink.href = el.parentNode.href;
        }
        body.appendChild(divFrame);
        var pos = findPos(el);
        divFrame.onmouseout=function(){ divFrame.parentNode.removeChild(divFrame); };
//        if (clickable !== undefined && clickable === true) {
//            divFrame.onclick=function(){ window.location.href = el.parentNode.href; };
//            divFrame.style.cursor="pointer";
//        }
        divFrame.style.width=3*el.width+"px";
        divFrame.style.height=3*el.height+"px";
        divFrame.style.position="absolute";
        divFrame.style.left=(pos[0]-el.width)+"px";
        divFrame.style.top=(pos[1]-el.height)+"px";
        divFrame.style.zIndex="999";
        
        var thm=document.createElement("IMG");        
        thm.src=el.src;
        thm.style.width=divFrame.style.width;
        thm.style.height=divFrame.style.height;
        thm.style.border="solid 2px gray";
        aLink.appendChild(thm); 
        //divFrame.appendChild(thm);
        
        var bus=document.createElement("IMG");        
        bus.src= root + "/Images/icon_busy.gif";
        bus.style.position="absolute";
        bus.style.left=(1.5*el.width)+"px";
        bus.style.top=(1.5*el.height)+"px"; 
        aLink.appendChild(bus);
        
        var exp=document.createElement("IMG");  
        exp.style.position="absolute";
        exp.style.left="0px";
        exp.style.top="0px";
        exp.style.width=divFrame.style.width;
        exp.style.height=divFrame.style.height;
        exp.style.border="solid 2px gray";
        if (w > 400) {       
            exp.src=el.src.replace("s=thumbnail","s=medium");
        } else {
            exp.src=el.src.replace("s=thumbnail","s=original");
        }
        aLink.appendChild(exp);
    };
    
       
    FPObj.SmileyArray = function() {
        var smileyArray = [
            ["(:|","yawn"],
            ["\\:D/","dancing"],
            [":)>-","peace sign"],
            ["3:-O","cow"],
            [":(|)","monkey"],
            ["~:>","chicken"],
            [">:P","phbbbbt"],
            ["<):)","cowboy"],
            [">:)","devil"],
            ["O:-)","angel"],
            [":))","laughing"],
            ["/:)","raised eyebrow"],
            [":)]","on the phone"],
            ["*-:)","idea"],
            ["=:)","bug"],
            ["^:)^","not worthy"],
            [":)","happy"],
            [":-)","happy"],
            [":((","crying"],
            [":(","sad"],
            [":-(","sad"],
            [";;)","batting eyelashes"],
            [";))","hee hee"],
            [">;-)","alien"],
            [";)","winking"],
            [";-)","winking"],
            [">:D<","big hug"],
            [":D","big grin"],
            [":-D","big grin"],
            [":-/","confused"],
            [":x","love struck"],
            [":\">","blushing"],
            [":-[","blushing"],
            ["<:-P","party"],
            [":P","tongue"],
            [":-P","tongue"],
            [":-*","kiss"],
            ["=((","broken heart"],
            [":-O","surprise"],
            ["~X(","at wits end"],
            ["X(","angry"],
            [":>","smug"],
            ["B-)","cool"],
            ["#:-S","whew"],
            [":-SS","nailbiting"],
            [":-S","worried"],
            [":|","straight face"],
            [":-\\","straight face"],
            ["=))","rolling on the floor"],
            [":-B","nerd"],
            ["=;","talk to the hand"],
            [":-c","call me"],
            [":-h","wave"],
            [":-t","time out"],
            ["8->","daydreaming"],
            ["I-)","sleepy"],
            ["8-|","rolling eyes"],
            ["L-)","loser"],
            [":-<","sigh"],
            [":-&","sick"],
            [":-$","sealed lips"],
            ["[-(","not talking"],
            [":O)","clown"],
            ["8-}","silly"],
            ["=P~","drooling"],
            [":-??","unsure"],
            [":-?","thinking"],
            ["#-o","doh"],
            ["=D>","applause"],
            ["@-)","hypnotized"],
            [":^o","liar"],
            [":-w","waiting"],
            [":o3","puppy dog eyes"],
            ["%-(","not listening"],
            [":@)","pig"],
            ["@};-","rose"],
            ["%%-","good luck"],
            ["**==","flag"],
            ["(~~)","pumpkin"],
            ["~O)","coffee"],
            ["8-X","skull"],
            [":-L","frustrated"],
            ["[-O<","praying"],
            ["$-)","money eyes"],
            [":-\"","whistling"],
            ["b-(","feeling beat up"],
            ["[-X","shame on you"],
            [">:/","bring it on"],
            [":-@","chatterbox"],
            [":-j","oh go on"],
            ["(*)","star"]
        ];
        return smileyArray;
    };
    FPObj.InsertSmileys = function(input) {
        
        var smileyArray = FP.SmileyArray();
        
        var replacerText = "";
        var replaceeText = "";
        for (var i = 0; i < smileyArray.length; i++) { 
            replaceeText = smileyArray[i][0];
            replaceeText = replaceeText.replace("&","&amp;").replace("\"","&quot;").replace("<","&lt;").replace(">","&gt;");
            replacerText = "<img height=\"18\" border=\"0\" alt=\"" + smileyArray[i][1] + "\" title=\"" + smileyArray[i][1] + "\" src=\"" + root + "/images/yhoo_smileys/" + smileyArray[i][1].replace(/ /ig,"_") + ".gif\" />";
            while (input.indexOf(replaceeText) >= 0) {
                input = input.replace(replaceeText, replacerText);
            }        
        }
        
        return input;
    };
    FPObj.InsertText = function(myID, myValue) 
    {
        var myField = returnObjById(myID);
        if (document.selection) 
        {
            myField.focus();
            sel = document.selection.createRange();
            sel.text = myValue;
        }
        else if (myField.selectionStart || myField.selectionStart === '0') 
        {
            var startPos = myField.selectionStart;
            var endPos = myField.selectionEnd;
            myField.value = myField.value.substring(0, startPos)+ myValue + myField.value.substring(endPos, myField.value.length);
        } 
        else 
        {
            myField.value += myValue;
        }
    };
    function str_to_num(str_in) {
        num_out = "";        
        for(i = 0; i < str_in.length; i++) {
            num_out += "&#" + (str_in.charCodeAt(i)) + ";";
        }
        return num_out;       
    }
    FPObj.ClickableSmileyCode = function(destID, targetID) {
        var html = "";
        
        var smileyArray = FP.SmileyArray();
        
        for (var i = 0; i < smileyArray.length; i++) { 
            replaceeText = smileyArray[i][0];
            replaceeText = replaceeText.replace("&","&amp;").replace("\"","&quot;").replace("<","&lt;").replace(">","&gt;");
            replaceeTextEncodedDoubleSlash = str_to_num(smileyArray[i][0].replace("\\","\\\\"));
            replaceeTextEncoded = str_to_num(smileyArray[i][0]);
            html += "<span class=\"SmileyList\" onclick=\"FP.InsertText('" + targetID + "',' " + replaceeTextEncodedDoubleSlash + " ');\"><nobr>" + replaceeTextEncoded + " " + replaceeText + "</nobr></span>";
        }
        html = FP.InsertSmileys(html);
        var smileyDest = returnObjById(destID);
        smileyDest.innerHTML = html;
    };
    
    function getElementsByTagNameAndClass(el,tn,n) {
        var arr = [];
        var allEl = el.getElementsByTagName(tn);
        if (allEl && allEl.length > 0) {
            for (var i = 0;i < allEl.length;i++) {
                if (allEl[i].className === n) {
                    arr.push(allEl[i]);
                }
            }
        
        }
        return arr;
    }
    return FPObj;
    
}
FP = new FP();