<!DOCTYPE html>
<html>
   <head>
      <?php
         define('USER', 'jesse.turner@gatewaybaltic.com');
         define('TOKEN', 'reNaj8P1B4r3y9=fD8RaM0a4Lf30sdBda1d210we'); 
         //define('USER', 'inese.andersone@gatewaybaltic.com');
         //define('TOKEN', 'r7Vc51cdBcsbOej4t1BbwdabU6p9M0Beafl8c142'); 
         require 'Solve360Service.php';
         $solve360Service = new Solve360Service(USER, TOKEN);
         $blogs = $solve360Service->searchProjectblogs(array(  'layout' => '1','searchmode' => '','searchvalue' => '',
                                                               'special' => 'OR','limit'=>'9999'));
         $data=array();
	      foreach ($blogs->children() as $blog) {
	         $title=$blog->title;
            $status=$blog->custom9401709;
	         $blogId=$blog->id;
    	      $coordinator=$blog->custom9401708;
    	      $assigned=$blog->assignedto;
    	      $created=$blog->created;
    	      $email=$blog->custom9484073;
    	      $contactName=$blog->custom9557786;
    	      $data[]=array("$blogId","$title","Unassigned","$coordinator","$created","$status","$assigned","$email","$contactName",0);
    	   } 
      ?>
      <script type="text/javascript">
         // **************************************** script taken from helper utility *****************************************
         // -------------------------- constants -------------------------------
         var WAITING=0;
         var SENT=-1;			// solve loading statuses
         var RECEIVED=-2;
         var ALLLOADING=-1;		// return value for _continueLoading function
         var ALLLOADED=-2;       // return value for _continueLoading function
         //
         var STATUS=0;
         var COMPANYID=1;		// solveCompanies indices
         var COMPANYNAME=2;
         var ACTIVITIES=3;		// (contains call logs and simple notes only - from under company + under relevant related contacts)
         var RELATED=4;			// (this will contain project blog relations only; for parsing [<project name>] tags)
         var WEBSITE=5;
         var PHONE=6;
         var ADDRESS=7;
         var TURNOVER=8;
         var EMPLOYEES=9;
         var PROFILE=10;			// for now use existing Solve profile field!
         var INDUSTRY=11;
         var BACKGROUND=12;
         var CREATED=13;
         var DATE1=14;
         var COMMENT1=15;
         var DATE2=16;
         var COMMENT2=17;
         var DECISION=18;
         var HIDEON=19;    // true or false
         var oDATE1=20;
         var oCOMMENT1=21;
         var oDATE2=22;
         var oCOMMENT2=23;
         var oDECISION=24;
         //
         var DATE=0;
         var COMMENT=1;
         var COMTYPE=2;
         var ISCALL=0;     // for COMTYPE (notes/other = 1)
         
         var TOTALCALLS=0;
         var NO1CALLS=1;
         var NO2CALLS=2;
         var oTOTALCALLS=3;
         var oNO1CALLS=4;
         var oNO2CALLS=5;
         //
         var NOTFOUND=-1;
         var FIRSTCONTACT=0;
         var RED=1;
         var YELLOW=2;
         var GREEN=3;
         var START=4;
         var END=5;
         var PRIVATE=6;		
         var NODECISION=0;
         var ONFIRSTCALL=-2;
         
         // -------------------------- globals ------------------------------- 
         var solveCompanies=new Array();
         var solveStats=new Array();         // =[ #activities(excl.notes,private) , #no1 , #no2 ]
         var dateCmp=120401;            // date for OLD stats, status, etc.
         
         // -------------------------- activity processing functions -------------------------------                  
         function _processActivities(project,comp) {
            var i,dec;
            var data;
            // don't use - consultants don't need expanded forms!
            //_expandShortForms(project,comp); 
            if (solveCompanies[project][comp].length<DATE2) {
               for (i=0;i<4;i++) solveCompanies[project][comp].push("");
               solveCompanies[project][comp].push(ONFIRSTCALL);
               solveCompanies[project][comp].push(false);
               for (i=0;i<4;i++) solveCompanies[project][comp].push("");
               solveCompanies[project][comp].push(ONFIRSTCALL); 
               _processOldActivities(project,comp);
            } else {
               solveCompanies[project][comp][DATE1]="";
               solveCompanies[project][comp][COMMENT1]="";
               solveCompanies[project][comp][DATE2]="";
               solveCompanies[project][comp][COMMENT2]="";
               solveCompanies[project][comp][DECISION]=ONFIRSTCALL;
               solveCompanies[project][comp][HIDEON]=false;
            }
            
            if (solveCompanies[project][comp][ACTIVITIES].length>0) {
               // first order activities by date!
               if (solveCompanies[project][comp][ACTIVITIES].length>1) _orderByDate(project,comp);                              

               // check for start and end; modify variables accordingly
               var start=_getActivityBoundary("start",project,comp);
               if (start==NOTFOUND) start=solveCompanies[project][comp][ACTIVITIES].length-1;
               var end=_getActivityBoundary("end",project,comp);
               if (end==NOTFOUND) end=0;
               //
               var stop=false;
               for (i=end;i<=start && stop==false;i++) {
                  data=_getTags(solveCompanies[project][comp][ACTIVITIES][i][COMMENT],false,project);
                  if (data[1]==FIRSTCONTACT) {
                     solveCompanies[project][comp][DATE1]=_processDate(solveCompanies[project][comp][ACTIVITIES][i][DATE]);
                     solveCompanies[project][comp][COMMENT1]=data[0];
                     solveCompanies[project][comp][DECISION]=NODECISION;
                     var start=i;
                     for (i=end;i<=start && stop==false;i++) {
                        data=_getTags(solveCompanies[project][comp][ACTIVITIES][i][COMMENT],false,project);
                        if (data[2]==RED || data[2]==GREEN || data[2]==YELLOW) {
                           if (i<start) solveCompanies[project][comp][DATE2]=_processDate(solveCompanies[project][comp][ACTIVITIES][i][DATE]);
                           if (i<start) solveCompanies[project][comp][COMMENT2]=data[0];
                           solveCompanies[project][comp][DECISION]=data[2];
                           solveCompanies[project][comp][HIDEON]=true;
                           stop=true;
                        }
                     }
                     if (stop==false) {
                        for (i=end;i<start && stop==false;i++) {
                           data=_getTags(solveCompanies[project][comp][ACTIVITIES][i][COMMENT],false,project);
                           if (data[1]!=PRIVATE) {
                              solveCompanies[project][comp][DATE2]=_processDate(solveCompanies[project][comp][ACTIVITIES][i][DATE]);
                              solveCompanies[project][comp][COMMENT2]=data[0];
                              stop=true;
                           }
                        }
                     }
                     stop=true;
                  }
               }
               if (stop==false) {
                  for (i=end;i<=start && stop==false;i++) {
                     data=_getTags(solveCompanies[project][comp][ACTIVITIES][i][COMMENT],false,project);
                     if (data[1]!=PRIVATE) {
                        solveCompanies[project][comp][DATE1]=_processDate(solveCompanies[project][comp][ACTIVITIES][i][DATE]);
                        solveCompanies[project][comp][COMMENT1]=data[0];
                        stop=true;
                     }
                  }
               }
            }
         }
         
         function _getFullActivityList(project,comp) {
            var text="";
            if (solveCompanies[project][comp][ACTIVITIES].length>0) {
               // check for start and end; modify variables accordingly
               var start=_getActivityBoundary("start",project,comp);
               if (start==NOTFOUND) start=solveCompanies[project][comp][ACTIVITIES].length-1;
               var end=_getActivityBoundary("end",project,comp);
               if (end==NOTFOUND) end=0;
               //
               for (i=end;i<=start;i++) {
                  data=_getTags(solveCompanies[project][comp][ACTIVITIES][i][COMMENT],true,project);
                  if (data[0]!="" && data[1]!=PRIVATE) {
                     if (text!="") text+="\n";
                     text+=_processShortDate(solveCompanies[project][comp][ACTIVITIES][i][DATE])+" "+data[0];
                  }
               }
            }
            return text;
         }
         
         function _processOldActivities(project,comp) {
            var i,dec;
            var data;
            if (solveCompanies[project][comp][ACTIVITIES].length>0) {
               // first order activities by date!
               if (solveCompanies[project][comp][ACTIVITIES].length>1) _orderByDate(project,comp);                              

               // check for start and end; modify variables accordingly
               var start=_getActivityBoundary("start",project,comp);
               if (start==NOTFOUND) start=solveCompanies[project][comp][ACTIVITIES].length-1;
               var end=_getActivityBoundary("end",project,comp);
               if (end==NOTFOUND) end=0;
               //
               var newend=end;
               for (i=start;i>=end;i--) {
                  if (_getDateNum(solveCompanies[project][comp][ACTIVITIES][i][DATE])<=dateCmp) newend=i;
               }
               end=newend;
               var stop=false;
               for (i=end;i<=start && stop==false;i++) {
                  data=_getTags(solveCompanies[project][comp][ACTIVITIES][i][COMMENT],false,project);
                  if (data[1]==FIRSTCONTACT) {
                     solveCompanies[project][comp][oDATE1]=_processDate(solveCompanies[project][comp][ACTIVITIES][i][DATE]);
                     solveCompanies[project][comp][oCOMMENT1]=data[0];
                     solveCompanies[project][comp][oDECISION]=NODECISION;
                     var start=i;
                     for (i=end;i<=start && stop==false;i++) {
                        data=_getTags(solveCompanies[project][comp][ACTIVITIES][i][COMMENT],false,project);
                        if (data[2]==RED || data[2]==GREEN || data[2]==YELLOW) {
                           if (i<start) solveCompanies[project][comp][oDATE2]=_processDate(solveCompanies[project][comp][ACTIVITIES][i][DATE]);
                           if (i<start) solveCompanies[project][comp][oCOMMENT2]=data[0];
                           solveCompanies[project][comp][oDECISION]=data[2];
                           stop=true;
                        }
                     }
                     if (stop==false) {
                        for (i=end;i<start && stop==false;i++) {
                           data=_getTags(solveCompanies[project][comp][ACTIVITIES][i][COMMENT],false,project);
                           if (data[1]!=PRIVATE) {
                              solveCompanies[project][comp][oDATE2]=_processDate(solveCompanies[project][comp][ACTIVITIES][i][DATE]);
                              solveCompanies[project][comp][oCOMMENT2]=data[0];
                              stop=true;
                           }
                        }
                     }
                     stop=true;
                  }
               }
               if (stop==false) {
                  for (i=end;i<=start && stop==false;i++) {
                     data=_getTags(solveCompanies[project][comp][ACTIVITIES][i][COMMENT],false,project);
                     if (data[1]!=PRIVATE) {
                        solveCompanies[project][comp][oDATE1]=_processDate(solveCompanies[project][comp][ACTIVITIES][i][DATE]);
                        solveCompanies[project][comp][oCOMMENT1]=data[0];
                        stop=true;
                     }
                  }
               }
            }
         }
                  
         function _getTags(text,showPrivate,proj) {
            var returnData=["",NOTFOUND,NODECISION]
            var start,end,tagText;
            do {
               start=_findString(text,"[",true);
               if (start!=NOTFOUND) {
                  end=_findString(text,"]",true);
                  tagText=text.slice(start+1,end);
                  switch (tagText) {
                     case "1":
                     case "c":
                     case "e":
                        if (returnData[1]!=PRIVATE) returnData[1]=FIRSTCONTACT;
                        break;
                     case "red":
                     case "r":
                        if (returnData[1]!=PRIVATE) returnData[2]=RED;
                        break;
                     case "yellow":
                     case "y":
                        if (returnData[1]!=PRIVATE) returnData[2]=YELLOW;
                        break;
                     case "green":
                     case "g":
                        if (returnData[1]!=PRIVATE) returnData[2]=GREEN;
                        break;
                     case "!":
                        if (!showPrivate) returnData[1]=PRIVATE;
                        break;
                     default:
                        if (!_checkTagProject(tagText,solveBlogs[proj][1])) returnData[1]=PRIVATE;
                  }
                  text=text.slice(0,start)+text.slice(end+1);
               }
            } while (start!=NOTFOUND);
            returnData[0]=text;
            return returnData;
         }
         
         function _getActivityBoundary(searchStr,proj,comp) {
            var end=0;
            var start=solveCompanies[proj][comp][ACTIVITIES].length-1;
            var found=NOTFOUND;
            for (i=end;i<=start && found==NOTFOUND;i++) {
               var startTag=_findString(solveCompanies[proj][comp][ACTIVITIES][i][COMMENT],"["+searchStr+"=",true);
               if (startTag!=NOTFOUND) {
                  var endTag=solveCompanies[proj][comp][ACTIVITIES][i][COMMENT].indexOf("]",startTag);
                  if (endTag==NOTFOUND) alert("Unexpected error - no closing tag");
                  var tagProj=solveCompanies[proj][comp][ACTIVITIES][i][COMMENT].slice(startTag+searchStr.length+2,endTag);
                  if (_checkTagProject(tagProj,solveBlogs[proj][1])) found=i;
               }
            }
            if (found==NOTFOUND) {
               for (i=end;i<=start && found==NOTFOUND;i++) {
                  var endTag=_findString(solveCompanies[proj][comp][ACTIVITIES][i][COMMENT],"="+searchStr+"]",true);
                  if (endTag!=NOTFOUND) {
                     var startTag;
                     var startSearch=0;
                     var rightTag=false;
                     do {
                        startTag=solveCompanies[proj][comp][ACTIVITIES][i][COMMENT].indexOf("[",startSearch);
                        if (startTag==NOTFOUND) alert("Unexpected error - no opening tag");
                        if (solveCompanies[proj][comp][ACTIVITIES][i][COMMENT].indexOf("]",startTag)==endTag+1+searchStr.length) rightTag=true;
                        else startSearch=solveCompanies[proj][comp][ACTIVITIES][i][COMMENT].indexOf("]",startTag)+1;
                     } while (!rightTag);
                     var tagProj=solveCompanies[proj][comp][ACTIVITIES][i][COMMENT].slice(startTag+1,endTag);
                     if (_checkTagProject(tagProj,solveBlogs[proj][BLOGNAME])) found=i;
                  }
               }
            }
            return found;   
         }
         
         function _checkTagProject(tagProj,thisProj) {
            if (tagProj.indexOf("=")>=0) {
               var equals=tagProj.indexOf("=");
               if (tagProj.slice(0,equals)=="start" || tagProj.slice(0,equals)=="end") tagProj=tagProj.slice(equals+1);
               else tagProj=tagProj.slice(0,equals);
            }
            tagProj=tagProj.toLowerCase();
            thisProj=thisProj.toLowerCase();
            if (thisProj.indexOf(tagProj)>=0) return true;
            else return false;
         }
         
         function _processShortDate(dateStr) {
            var day=parseInt(dateStr.slice(8,10),10);
            var month=parseInt(dateStr.slice(5,7),10);
            return day+"."+month+".";
         }
         
         function _orderByDate(project,comp) {
            var swapped;
            var swapTemp;
            do {
               swapped=false;
               for (i=0;i<solveCompanies[project][comp][ACTIVITIES].length-1;i++) {
                  var date1=_getDateNum(solveCompanies[project][comp][ACTIVITIES][i][DATE]);
                  var date2=_getDateNum(solveCompanies[project][comp][ACTIVITIES][i+1][DATE]);
                  if (date2>date1) {
                     swapTemp=solveCompanies[project][comp][ACTIVITIES][i];
                     solveCompanies[project][comp][ACTIVITIES][i]=solveCompanies[project][comp][ACTIVITIES][i+1];
                     solveCompanies[project][comp][ACTIVITIES][i+1]=swapTemp;
                     swapped=true;
                  }
               }
            } while (swapped);
         }
            
         // ------------------------------------------- text correction functions -----------------------------------------------
         function _expandShortForms(project,comp) {
            if (solveCompanies[project][comp][ACTIVITIES].length>0) { 
               var expText=["","No answer/line busy","The contact person was unavailable"];
               for (var i=0;i<solveCompanies[project][comp][ACTIVITIES].length;i++) {
                  var st=solveCompanies[project][comp][ACTIVITIES][i][COMMENT].slice(0,2);
                  if (st.toLowerCase()=="no") {
                     st=solveCompanies[project][comp][ACTIVITIES][i][COMMENT].slice(2,4);
                     var found=0;
                     if (st.charAt(0)=="1" || st.charAt(1)=="1") found=1;
                     if (st.charAt(0)=="2" || st.charAt(1)=="2") found=2;
                     if (found>0) {
                        if (st.charAt(0)=="1" || st.charAt(0)=="2") st=solveCompanies[project][comp][ACTIVITIES][i][COMMENT].slice(3);
                        else st=solveCompanies[project][comp][ACTIVITIES][i][COMMENT].slice(4);
                        if (st.length==0) solveCompanies[project][comp][ACTIVITIES][i][COMMENT]=expText[found]+".";
                        else solveCompanies[project][comp][ACTIVITIES][i][COMMENT]=expText[found]+st;
                     }  
                  }
               }
            }
         }
         
         function _correctText(text) {
            var start,end;
            // remove formatting
            do {
               start=_findString(text,"<",false);
               if (start!=NOTFOUND) {
                  end=_findString(text,">",false);
                  text=text.slice(0,start)+text.slice(end+1);
               }
            } while (start!=NOTFOUND);
            //
            // change nbsp to normal space
            do {
               start=_findString(text,"&nbsp;",true);
               if (start!=NOTFOUND) text=text.slice(0,start)+" "+text.slice(start+6);
            } while (start!=NOTFOUND);
            //
            // correct &amp;
            do {
               start=_findString(text,"&amp;",true);
               if (start!=NOTFOUND) text=text.slice(0,start)+"&"+text.slice(start+5);
            } while (start!=NOTFOUND);
            //
            // remove \n
            do {
               start=_findString(text,"\n",true);
               if (start!=NOTFOUND) text=text.slice(0,start)+text.slice(start+1);
            } while (start!=NOTFOUND);
            //
            // correct << and >> ------------ do later!
            //
            // remove double space
            do {
               start=_findString(text,"  ",true);
               if (start!=NOTFOUND) text=text.slice(0,start)+text.slice(start+1);
            } while (start!=NOTFOUND);
            return text;
         }
         
         function _findString(text,searchString,canRepeat) {
            var endSearch=false;
            var pos=0;
            while (endSearch==false) {
               pos=text.indexOf(searchString,pos);
               if (pos==NOTFOUND) endSearch=true;
               else if (canRepeat==true || text.slice(pos+1,pos+2)!=searchString) endSearch=true;
            }
            return pos;
            //return NOTFOUND;
         }
         
         function _shortened(name) {
            if (name.length>19) name=name.slice(0,18)+"...";
            return name;
         }
         // -------------------------- Statistic functions ---------------------------------
         function _calculateCallStats(proj) {
            //alert(solveStats.length);
            //alert(solveStats[proj].length);
            //alert(solveStats[proj][TOTALCALLS]);
            solveStats[proj][TOTALCALLS]=0;
            //alert("assigned");
            solveStats[proj][NO1CALLS]=0;
            solveStats[proj][NO2CALLS]=0;
            solveStats[proj][oTOTALCALLS]=0;
            solveStats[proj][oNO1CALLS]=0;
            solveStats[proj][oNO2CALLS]=0;
            if (solveCompanies[proj].length>0) {
               //alert("are companies!");
               for (var comp=0;comp<solveCompanies[proj].length;comp++) {
                  if (solveCompanies[proj][comp][ACTIVITIES].length>0) {
                     //alert("looking at comp="+comp);
                     for (var ac=0;ac<solveCompanies[proj][comp][ACTIVITIES].length;ac++) {
                        if (solveCompanies[proj][comp][ACTIVITIES][ac][COMTYPE]==ISCALL) {
                           var st=solveCompanies[proj][comp][ACTIVITIES][ac][COMMENT];
                           if (st.indexOf("[!]")==NOTFOUND) {
                              solveStats[proj][TOTALCALLS]++;
                              if (_getDateNum(solveCompanies[proj][comp][ACTIVITIES][ac][DATE])<=dateCmp) solveStats[proj][oTOTALCALLS]++;
                              st=st.toLowerCase();
                              if (st.slice(0,2)=="no") {
                                 if (st.charAt(2)=="1" || st.charAt(3)=="1") {
                                    solveStats[proj][NO1CALLS]++;
                                    if (_getDateNum(solveCompanies[proj][comp][ACTIVITIES][ac][DATE])<=dateCmp) solveStats[proj][oNO1CALLS]++;
                                 }
                                 if (st.charAt(2)=="2" || st.charAt(3)=="2") {
                                    solveStats[proj][NO2CALLS]++;
                                    if (_getDateNum(solveCompanies[proj][comp][ACTIVITIES][ac][DATE])<=dateCmp) solveStats[proj][oNO2CALLS]++;
                                 }
                              }
                           }
                        }
                     }
                  }
               }
            }
         }
         
         function _countOLDcompanies(proj) {
            var count=0;
            for (var comp=0;comp<solveCompanies[proj].length;comp++) {
               if (solveCompanies[proj][comp][CREATED]<=dateCmp) count++;
            }
            return count;
         }
         
         function _countDecisions(proj,dec) {
            var count=0;
            for (var i=0;i<solveCompanies[proj].length;i++) {
               if (solveCompanies[proj][i][DECISION]==dec) count++;
            }
            return count;
         }
         
         function _countOldDecisions(proj,dec) {
            var count=0;
            for (var i=0;i<solveCompanies[proj].length;i++) {
               if (solveCompanies[proj][i][oDECISION]==dec && solveCompanies[proj][i][CREATED]<=dateCmp) count++;
            }
            return count;
         }
         
         // -------------------------- Solve loading functions -------------------------------
         function _loadSolveData(proj) {
            var xmlhttp;
	         if (window.XMLHttpRequest) xmlhttp=new XMLHttpRequest();
	         else xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	      
	         xmlhttp.onreadystatechange=function() {
	            if (xmlhttp.readyState==4 && xmlhttp.status==200) {
		            var companyList=JSON.parse(xmlhttp.responseText);
                  // [projectId,[profile,meeting,final],"NOTE","email","contactName","<blank>",id0,id1,...]
                  var proj=_getProjectNumber(companyList[BLOGID]);
                  solveStats[proj]=[0,0,0,0,0,0];
                  solveBlogs[proj].push(companyList[1]);
                  solveBlogs[proj].push(companyList[2]);
                  if (solveBlogs[proj][BLOGSTATUS]=="Preparation") {
                     for (var i=6;i<companyList.length;i++) {
                        solveCompanies[proj].push(new Array(WAITING,companyList[i]));
                     }
                  }
                  if (companyList.length>6 && solveBlogs[proj][BLOGSTATUS]!="" && solveBlogs[proj][BLOGSTATUS]!="Preparation") {
                     for (var i=3;i<companyList.length;i++) {
                        solveCompanies[proj].push(new Array(WAITING,companyList[i]));
                     } 
                     var found=false;
                     for (var i=0;i<solveBlogs.length && !found;i++) {
                        if (solveBlogs[i][BLOGLOADINGNOW]==isWAITING) found=true;
                        if (solveBlogs[i][BLOGLOADINGNOW]==isLOADING && solveBlogs[i][BLOGLOADSTATUS]==BLOGLOAD1) found=true;
                     }
                     solveBlogs[proj][BLOGLOADSTATUS]=BLOGLOAD1;
                     if (!found) {
                        solveBlogs[proj][BLOGLOADINGNOW]=isLOADING;
                        for (var i=0;i<7 && i<solveCompanies[proj].length;i++) _loadCompany(proj,i);
                     } else {
                        solveBlogs[proj][BLOGLOADINGNOW]=isWAITING;
                     }
                  } else {
                     solveBlogs[proj][BLOGLOADINGNOW]=isNOTLOADING;
                     solveBlogs[proj][BLOGLOADSTATUS]=BLOGLOADED;
                     _checkErrors(proj);
                     var found=false;
                     for (var i=0;i<solveBlogs.length && !found;i++) {
                        if (solveBlogs[i][BLOGLOADINGNOW]==isWAITING || solveBlogs[i][BLOGLOADINGNOW]==isLOADING) found=true;
                     }
                     if (found) _display();
                     else _finishedLoading();
                  }
               }
            }
            document.getElementById("loadbutton").disabled=true;
            solveBlogs[proj][BLOGLOADINGNOW]=isLOADING;
            //document.getElementById("loadmessage"+proj).innerHTML="Loading... ";
            xmlhttp.open("GET","getcompanylist.php?p="+solveBlogs[proj][BLOGID],true);
            xmlhttp.send();
            //alert("sent "+solveBlogs[proj][BLOGNAME]);
         }
         
         function _getProjectNumber(projectId) {
            var proj=0;
            while (projectId!=solveBlogs[proj][BLOGID]) proj++;
            return proj;
         }
         
         function _loadPercentage(project) {
            var count=0;
            for (var i=0;i<solveCompanies[project].length;i++) {
               if (solveCompanies[project][i][STATUS]==RECEIVED) count++;
            }
            var progr=Math.round(count*100/solveCompanies[project].length);
            if (progr==100 && count<solveCompanies[project].length) progr=99;
            return progr;
         }
         
         function _loadCompany(proj,comp) {
            var xmlhttp;
            if (window.XMLHttpRequest) xmlhttp=new XMLHttpRequest();
            else xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
            xmlhttp.onreadystatechange=function() {
               if (xmlhttp.readyState==4 && xmlhttp.status==200) {
                  var companyData=JSON.parse(xmlhttp.responseText);
                  // =[projectNumber,companyID,name,[activities],background]
                  var proj=companyData[0];
                  var comp=_getCompanyNumber(proj,companyData[1]);
                  solveCompanies[proj][comp][STATUS]=RECEIVED;
                  // solveCompanies[project][comp][STATUS,id,name,[activities],...]
                  for (var i=COMPANYNAME;i<BACKGROUND;i++) solveCompanies[proj][comp].push(companyData[i]);
                  solveCompanies[proj][comp].push(_correctText(companyData[BACKGROUND]));
                  solveCompanies[proj][comp].push(_getDateNum(companyData[CREATED]));
                  _processActivities(proj,comp);
                  _display();
                  _continueLoading(proj);
               }
            }
            solveBlogs[proj][BLOGLOADINGNOW]=isLOADING;
            solveCompanies[proj][comp][STATUS]=SENT;
            xmlhttp.open("GET","loadcompany.php?p="+proj+"&c="+solveCompanies[proj][comp][COMPANYID]+"&n="+_getPHPBlogName(proj),true);
            xmlhttp.send();
         }
         
         function _getPHPBlogName(proj) {
            var name=solveBlogs[proj][1];
            for (var i=0;i<name.length;i++) {
               if (name.charCodeAt(i)==32) name=name.slice(0,i)+"+"+name.slice(i+1);
            }
            return name;
         }
         
         function _getCompanyNumber(proj,companyId) {
            var comp=0;
            while (companyId!=solveCompanies[proj][comp][COMPANYID]) comp++;
            return comp;
         }
         
         function _continueLoading(proj) {
            var project=proj;
            var comp=_getNextCompanyToLoad(proj);
            if (comp!=ALLLOADED && comp!=ALLLOADING) _loadCompany(proj,comp);
            else {
               if (comp==ALLLOADED) {
                  solveBlogs[proj][BLOGLOADINGNOW]=isNOTLOADING;
                  solveBlogs[proj][BLOGLOADSTATUS]=BLOGLOADED;
                  if (solveBlogs[proj][BLOGSTATUS]==isATTRACTION) _calculateCallStats(proj);
                  _checkErrors(proj);
               }
               compp=ALLLOADING;
               var looped=false;
               for (var i=0;i<solveBlogs.length && (compp==ALLLOADING || compp==ALLLOADED);i++) {
                  if (i!=project && solveBlogs[i][BLOGLOADINGNOW]==isWAITING) {
                     looped=true;
                     proj=i;
                     compp=_getNextCompanyToLoad(proj);
                  }
               }
               if ((compp==ALLLOADED) || (!looped && comp==ALLLOADED)) _finishedLoading();
               else if (comp!=ALLLOADING) _loadCompany(proj,compp);
            }
         }
         
         function _getNextCompanyToLoad(proj) {
            var comp=ALLLOADED;
            for (var i=0;i<solveCompanies[proj].length && (comp==ALLLOADING || comp==ALLLOADED);i++) {
               if (solveCompanies[proj][i][STATUS]==WAITING) comp=i;
               else if (solveCompanies[proj][i][STATUS]==SENT) comp=ALLLOADING;
            } 
            return comp;
         }
         
         function _finishedLoading() {
            document.getElementById("loadbutton").disabled=false;
            _display();
         }
         // -------------------------------------------- end of helper utility code -----------------------------------------------------------
         // ****************************************
         // **************************************** script for page *****************************************
         // ****************************************
         // ------------------------------------------------------------------------------------------------------------------------------------------
         // -------------------------- constants -------------------------------
         var BLOGID=0;
         var BLOGNAME=1;
         var ASSIGNEDTO=2;
         var COORDINATOR=3;
         var BLOGCREATED=4;
         var BLOGSTATUS=5;
         var ASSIGNEDTO_CODE=6;     // used only to generate ASSIGNEDTO from look-up array
         var BLOGEMAIL=7;
         var BLOGCONTACTNAME=8;
         var BLOGERROR=9;           
         var BLOGLOADSTATUS=10;
         var BLOGLOADINGNOW=11;      // isLOADING,isWAITING,isNOTLOADING
         var BLOGHIDEINDEX=12;   // 0=visible,1+ = hidden, in the order given
         var BLOGFILES=13;      // e.g. = ["YES,"NO","NO"]
         var BLOGNOTE=14;     
         //
         var isLOADING=1;
         var isWAITING=0;
         var isNOTLOADING=-1;
         //
         var BLOGNOTLOADED=0;
         var BLOGLOAD1=1;
         var BLOGLOADED=2;
         //
         var LISTVIEW=0;
         var DETAILVIEW=1;
         var ORGANISERVIEW=2;
         //
         var isNOTSTARTED="";               // for getBlogByType
         var isSELECTION="Preparation";
         var isATTRACTION="Attraction";
         var isREPORTS="Finalisation";
         var isCOMPLETED="Completed";
         var isALL="ALL";
         //
         var fNOTSTARTED=0;               // for getBlogByType
         var fSELECTION=1;
         var fATTRACTION=2;
         var fREPORTS=3;
         var fCOMPLETED=4;
         var fALL=5;
         //
         var NO_ERROR=0;
         var ERROR_NOTCOMPLETED=1;
         var ERROR_COMPLETED=2;
         var ERROR_REPORTS=3;
         var ERROR_ATTRACTION=4;
         var ERROR_NOTSELECTION=5;
         var ERROR_SELECTION=6;
         var ERROR_NOACTIVITY=7;
         //
         var NOFILTER=-1;
         //
         var BYLOAD="LOAD";      // currently not using; for organiser view only, and for staff not projects
         var BYNAME="NAME";
         var BYDATE="DATE";
         var BYSTATUS="STATUS";
         //
         var CONSCODE=0;
         var CONSNAME=1;
         var CONSNAMESHORT=2;
         var CONSTYPE=3;
         var STAFFHIDEINDEX=4;
         var STAFFEXECTYPE=5;       // =0/1/2
         //
         var ISNONE=-1;
         var ISCONS=0;
         var ISCOORD=1;
         var ISBOTH=2;
         //
         var SHOWCONS=1;
         var SHOWCOORDS=0;
         var SHOWOLD=2;
         var SHOWSTATS=3;

         // -------------------------- globals -------------------------------
         var displayView=LISTVIEW;
         var sortBy=[BYNAME,BYNAME,BYNAME];
         var displayOptions=[[false,false],[true,true,false,false],[true]];
         var statusFilter=[[true,true,true,true,true,false],[true,true,true,true,false,false],[true,true,true,true,false,false]];
         var coordFilter=[NOFILTER,NOFILTER,NOFILTER];
         var consFilter=[NOFILTER,NOFILTER,NOFILTER];
         var dateFilter=[120101,120101,120101];
         var lockSettings=[false,false,false];
         var blogHideIndex=1;
         var hideUnassigned=false;

         //
         var solveBlogs;
         var GBstaff = [   ["24213626","Armands Liseks","Armands",ISCONS,0,0],["42368419","Baiba Auzane","Baiba",ISCONS,0,0],["23392110","Dace Kirha","Dace",ISCONS,0,0],
                           ["24202362","Didzis Melbiksis","Didzis",ISCONS,0,0],["24202367","Dovile Buskeviciute","Dovile",ISCONS,0,0],["34988876","Evija Sprodzena","Evija",ISCONS,0,0],
                           ["16728048","Inese Andersone","Inese A",ISNONE,0,0],["23392014","Inese Manguse","Inese M",ISBOTH,0,0],["43416448","Inga Plesauniece","Inga P",ISBOTH,0,0],
                           ["35555309","Inga Ulmane","Inga U",ISBOTH,0,0],["34988889","Jesse Turner","Jesse",ISCONS,0,1],["17387710","Jekaterina Bobola","Kate",ISCONS,0,2],
                           ["25687818","Liga Vanaga","Liga",ISBOTH,0,0],["47351311","Mara Labunska","Mara",ISCONS,0,0],["23116851","Martins Tiknuss","Martins",ISCOORD,0,0],
                           ["35555333","Zanda Vipule","Zanda",ISBOTH,0,0] ];
         
         // ---------------------------- Solve data error checking functions ---------------------------------
         
         function _checkErrors(proj) {
            /*var stat=solveBlogs[proj][BLOGSTATUS];
            if (stat==isCOMPLETED && (solveBlogs[proj][BLOGFILES][1]=="NO" || solveBlogs[proj][BLOGFILES][2]=="NO")) solveBlogs[proj][BLOGERROR]=ERROR_NOTCOMPLETED;
            if (stat==isATTRACTION && (solveBlogs[proj][BLOGFILES][1]=="YES" || solveBlogs[proj][BLOGFILES][2]=="YES")) solveBlogs[proj][BLOGERROR]=ERROR_REPORTS;
            if (stat!=isCOMPLETED && solveBlogs[proj][BLOGFILES][1]=="YES" && solveBlogs[proj][BLOGFILES][2]=="YES") solveBlogs[proj][BLOGERROR]=ERROR_COMPLETED;
            if (stat==isSELECTION && solveBlogs[proj][BLOGCREATED]<) solveBlogs[proj][BLOGERROR]=ERROR_NOTSELECTION;
            if (stat==isNOTSTARTED && solveBlogs[proj][BLOGCREATED]<) solveBlogs[proj][BLOGERROR]=ERROR_NOACTIVITY;
            if (stat==isNOTSTARTED && (solveBlogs[proj][BLOGFILES][1]=="YES" || solveCompanies[proj].length>1) solveBlogs[proj][BLOGERROR]=ERROR_SELECTION;*/
                        
            
            
            /*if MP and FR uploaded & not completed OR BLOGDATE<4 months ago - ERROR_COMPLETED
                  else if MP or FR uploaded & not reports - ERROR_REPORTS
                  else if company count>0 or profile uploaded & = unstarted - ERROR_SELECTION
                  if =SELECTION/ERROR_SELECTION & BLOGDATE<1 month ago - ERROR_ATTRACTION*/
         }
         
         // ---------------------------- date functions ---------------------------------
         function _processDate(dateStr) {
            var months=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"];
            var day=parseInt(dateStr.slice(8,10),10);
            var month=parseInt(dateStr.slice(5,7),10);
            var year=dateStr.slice(0,4);
            return day+" "+months[month-1]+" "+year;
         }
         
         function _getDateNum(dateStr) {
            var year=parseInt(dateStr.slice(2,4),10);
            var day=parseInt(dateStr.slice(8,10),10);
            var month=parseInt(dateStr.slice(5,7),10);
            return 10000*year+100*month+day;
         }
         
         function _setDates() {
            var d=new Date();
            var dy=d.getDay();
            if (dy<2) document.getElementById("yesterday").innerHTML="Show status on Friday";
            else document.getElementById("yesterday").innerHTML="Show status yesterday";
            if (dy==1) document.getElementById("weekstart").style.display="none";
            else document.getElementById("weekstart").style.display="";
            var sel=document.getElementById("olddateselector");
            switch (parseInt(sel[sel.selectedIndex].value)) {
               case 0:
               case 7:
               case 14:
               case 28:
                  d.setDate(d.getDate()-parseInt(sel[sel.selectedIndex].value));
                  break;
               case 1:
                  if (dy>1) d.setDate(d.getDate()-1);
                  else d.setDate(d.getDate()-2-dy);
                  break;
               case 2:
                  if (dy==0) dy=7;
                  d.setDate(d.getDate()-dy+1);
                  break;
            }
            var yr=d.getFullYear();
            var mn="0"+(d.getMonth()+1);
            var dy="0"+d.getDate();
            var dateCmpStr=yr+mn.slice(-2)+dy.slice(-2);
            dateCmp=parseInt(dateCmpStr.slice(2),10);
         }
         
         function _changeDate() {
            _setDates();
            for (proj=0;proj<solveBlogs.length;proj++) {
               for (var i=0;i<solveCompanies[proj].length;i++) _processOldActivities(proj,i);
               _calculateCallStats(proj);
            }
            //alert("pause");
            _display();
         }
         
         // ---------------------------- display functions ---------------------------------
         function _display() {
            var hideBoxes;
            switch (displayView) {
               case LISTVIEW:
                  _showListTable();
                  hideBoxes=["detailcontainer","organisercontainer"];
                  break;
               case DETAILVIEW:
                  _showDetailedView();
                  hideBoxes=["listcontainer","organisercontainer"];
                  break;
               case ORGANISERVIEW:
                  _showOrganiserView();
                  hideBoxes=["listcontainer","detailcontainer"];
                  break;
            }
            for (var i=0;i<hideBoxes.length;i++) document.getElementById(hideBoxes[i]).style.display="none";
            _setMenuToView();
         }
         
         function _setMenuToView() {
            // status filter
            document.getElementById("unstartedfilter").checked=statusFilter[displayView][fNOTSTARTED];
            document.getElementById("selectionfilter").checked=statusFilter[displayView][fSELECTION];
            document.getElementById("attractionfilter").checked=statusFilter[displayView][fATTRACTION];
            document.getElementById("reportsfilter").checked=statusFilter[displayView][fREPORTS];
            document.getElementById("completedfilter").checked=statusFilter[displayView][fCOMPLETED];
            document.getElementById("allstatusesfilter").checked=statusFilter[displayView][fALL];
            document.getElementById("unstartedfilter").disabled=statusFilter[displayView][fALL];
            document.getElementById("selectionfilter").disabled=statusFilter[displayView][fALL];
            document.getElementById("attractionfilter").disabled=statusFilter[displayView][fALL];
            document.getElementById("reportsfilter").disabled=statusFilter[displayView][fALL];
            document.getElementById("completedfilter").disabled=statusFilter[displayView][fALL];
            // set load button options
            if (statusFilter[displayView][fNOTSTARTED] || statusFilter[displayView][fALL]) document.getElementById("loadOptionUnstarted").style.display="";
            else document.getElementById("loadOptionUnstarted").style.display="none";
            if (statusFilter[displayView][fSELECTION] || statusFilter[displayView][fALL]) document.getElementById("loadOptionSelection").style.display="";
            else document.getElementById("loadOptionSelection").style.display="none";
            if (statusFilter[displayView][fATTRACTION] || statusFilter[displayView][fALL]) document.getElementById("loadOptionAttraction").style.display="";
            else document.getElementById("loadOptionAttraction").style.display="none";
            if (statusFilter[displayView][fREPORTS] || statusFilter[displayView][fALL]) document.getElementById("loadOptionReports").style.display="";
            else document.getElementById("loadOptionReports").style.display="none";
            if (statusFilter[displayView][fCOMPLETED] || statusFilter[displayView][fALL]) document.getElementById("loadOptionCompleted").style.display="";
            else document.getElementById("loadOptionCompleted").style.display="none";
            // other filters
            document.getElementById("coordfilter").selectedIndex=_getIndex("coordfilter",coordFilter[displayView]);
            document.getElementById("consfilter").selectedIndex=_getIndex("consfilter",consFilter[displayView]);
            document.getElementById("datefilter").selectedIndex=_getIndex("datefilter",dateFilter[displayView]);
            // sort
            switch (sortBy[displayView]) {
               case BYNAME:
                  document.getElementById("sortbox").selectedIndex=0;
                  break;
               case BYDATE:
                  document.getElementById("sortbox").selectedIndex=1;
                  break;
               case BYSTATUS:
                  document.getElementById("sortbox").selectedIndex=2;
                  break;
            }
            // lock button
            if (lockSettings[displayView]) document.getElementById("lockButton").className="lockOn";
            else document.getElementById("lockButton").className="lockOff";
            
            // display options
            switch (displayView) {
               case LISTVIEW:
                  document.getElementById("displaycons").checked=displayOptions[LISTVIEW][SHOWCONS];
                  document.getElementById("displaycoord").checked=displayOptions[LISTVIEW][SHOWCOORDS];
                  document.getElementById("displayolddiv").style.visibility="hidden";
                  document.getElementById("displaystatsdiv").style.visibility="hidden";
                  document.getElementById("displaycons").disabled=false;
                  document.getElementById("sortstatus").disabled=true; 
                  document.getElementById("loaddiv").style.display="none";
                  document.getElementById("olddateselector").style.visibility="hidden";
                  document.getElementById("olddateselector").style.display="inline";
                  document.getElementById("staffsortbox").style.display="none";
                  document.getElementById("logo").style.display="block";
                  document.getElementById("sortboxlabel").innerHTML="Sort by:"
                  document.getElementById("constypefilter").style.display="none";
                  document.getElementById("consfilter").style.display="";
                  document.getElementById("hideunknownscontainer").style.display="none";
                  document.getElementById("hidezeroscontainer").style.display="none";
                  break;
               case DETAILVIEW:
                  document.getElementById("displaycons").checked=displayOptions[DETAILVIEW][SHOWCONS];
                  document.getElementById("displaycoord").checked=displayOptions[DETAILVIEW][SHOWCOORDS];
                  document.getElementById("displayold").checked=displayOptions[DETAILVIEW][SHOWOLD];
                  document.getElementById("displaystats").checked=displayOptions[DETAILVIEW][SHOWSTATS];
                  document.getElementById("displayolddiv").style.visibility="";
                  document.getElementById("displaystatsdiv").style.visibility="";
                  document.getElementById("displaycons").disabled=false;
                  document.getElementById("sortstatus").disabled=false;
                  document.getElementById("loaddiv").style.display="block";
                  document.getElementById("olddateselector").style.visibility="";
                  document.getElementById("olddateselector").style.display="inline";
                  document.getElementById("staffsortbox").style.display="none";
                  document.getElementById("logo").style.display="none";
                  document.getElementById("sortboxlabel").innerHTML="Sort by:"
                  document.getElementById("constypefilter").style.display="none";
                  document.getElementById("consfilter").style.display="";
                  document.getElementById("hideunknownscontainer").style.display="none";
                  document.getElementById("hidezeroscontainer").style.display="none";
                  break;
               case ORGANISERVIEW:
                  document.getElementById("displaycoord").checked=displayOptions[ORGANISERVIEW][SHOWCOORDS];
                  document.getElementById("displaycons").disabled=true;
                  document.getElementById("displayolddiv").style.visibility="hidden";
                  document.getElementById("displaystatsdiv").style.visibility="hidden";
                  document.getElementById("sortstatus").disabled=false;
                  document.getElementById("loaddiv").style.display="block";
                  document.getElementById("olddateselector").style.display="none";
                  document.getElementById("staffsortbox").style.display="inline";
                  document.getElementById("logo").style.display="none";
                  document.getElementById("sortboxlabel").innerHTML="Sort projects by:"
                  document.getElementById("constypefilter").style.display="";
                  document.getElementById("consfilter").style.display="none";
                  document.getElementById("hideunknownscontainer").style.display="block";
                  document.getElementById("hidezeroscontainer").style.display="block";
                  break;
            }
         }
         
         function _getIndex(id,value) {
            var indx=0;
            var sel=document.getElementById(id);
            while (sel[indx].value!=value) indx++;
            return indx;
         }
         
         function _showListTable() {
            var div=document.getElementById("listcontainer");
            var existing=document.getElementById("listtable");
            if (existing!=null) div.removeChild(existing);
            var tmpBlogs=[_getBlogsByType(isNOTSTARTED),_getBlogsByType(isSELECTION),_getBlogsByType(isATTRACTION),_getBlogsByType(isREPORTS),_getBlogsByType(isCOMPLETED)];
            var i;
            var numRows=0;
            for (i=0;i<tmpBlogs.length;i++) {
               for (var j=0;j<tmpBlogs[i].length;j++) {
                  var filterOut=false;
                  if (coordFilter[LISTVIEW]!=NOFILTER) {
                     if (solveBlogs[tmpBlogs[i][j]][COORDINATOR]!=GBstaff[coordFilter[LISTVIEW]][CONSNAME]) filterOut=true;
                  }
                  if (consFilter[LISTVIEW]!=NOFILTER && filterOut==false) {
                     if (solveBlogs[tmpBlogs[i][j]][ASSIGNEDTO]!=GBstaff[consFilter[LISTVIEW]][CONSNAME]) filterOut=true;
                  }
                  if (dateFilter[LISTVIEW]!=NOFILTER && filterOut==false) {
                     if (_getDateNum(solveBlogs[tmpBlogs[i][j]][BLOGCREATED])<dateFilter[LISTVIEW]) filterOut=true;
                  }
                  if (filterOut==true) tmpBlogs[i].splice(j--,1);
               }
               if (statusFilter[LISTVIEW][i]==false && statusFilter[LISTVIEW][fALL]==false) tmpBlogs[i]=[];
               if (tmpBlogs[i].length>numRows) numRows=tmpBlogs[i].length;
            }
            if (numRows>0) {
               if (sortBy[LISTVIEW]==BYDATE) tmpBlogs=_sortByDate(tmpBlogs);
               var table=document.createElement("table");
               table.setAttribute("id","listtable");
               var row=document.createElement("tr");
               if (tmpBlogs[0].length>0) _makeHeader(row,{text:"Unstarted ("+tmpBlogs[0].length+")",bcol:"grey"});
               if (tmpBlogs[1].length>0) _makeHeader(row,{text:"Preparation ("+tmpBlogs[1].length+")",bcol:"grey"});
               if (tmpBlogs[2].length>0) _makeHeader(row,{text:"Attraction ("+tmpBlogs[2].length+")",bcol:"grey"});
               if (tmpBlogs[3].length>0) _makeHeader(row,{text:"Finalisation ("+tmpBlogs[3].length+")",bcol:"grey"});
               if (tmpBlogs[4].length>0) _makeHeader(row,{text:"Completed ("+tmpBlogs[4].length+")",bcol:"grey"});
               table.appendChild(row);
               var text,cell;
               var Bborder="none";
               for (var j=0;j<numRows;j++) {
                  var row=document.createElement("tr");
                  if (j==numRows-1) Bborder="1px solid black";
                  for (i=0;i<tmpBlogs.length;i++) {
                     if (tmpBlogs[i].length>0) {
                        cell=_makeCell(row,{Bborder:Bborder});
                        if (j<tmpBlogs[i].length) {
                           if (solveBlogs[tmpBlogs[i][j]][BLOGNAME].length>0) text="<p class='tablep'>"+solveBlogs[tmpBlogs[i][j]][BLOGNAME]+"</p>";
                           else text="<p class='tablep'>&lt;Untitled project&gt;</p>";
                           if (solveBlogs[tmpBlogs[i][j]][ASSIGNEDTO]!="" && displayOptions[LISTVIEW][SHOWCONS]) text+="<p class='tablepi'>"+solveBlogs[tmpBlogs[i][j]][ASSIGNEDTO]+"</p>";
                           //if (solveBlogs[tmpBlogs[i][j]][COORDINATOR]!="" && displayOptions[LISTVIEW][SHOWCOORDS]) text+="<p class='tablepiBl'>("+solveBlogs[tmpBlogs[i][j]][COORDINATOR]+")</p>";
                           if (solveBlogs[tmpBlogs[i][j]][COORDINATOR]!="" && displayOptions[LISTVIEW][SHOWCOORDS]) {
                              var cName=solveBlogs[tmpBlogs[i][j]][COORDINATOR];
                              for (var kk=0;kk<GBstaff.length;kk++) {
                                 if (cName==GBstaff[kk][CONSNAME]) cName=GBstaff[kk][CONSNAMESHORT];
                              }
                              text+="<p class='tablepi'>("+cName+")</p>";
                           }
                           cell.innerHTML=text;
                        }
                     }
                  }
                  table.appendChild(row);
               }
               div.appendChild(table);
            }
            div.style.display="block";
         }
         
         function _sortByDate(data) {
            // insertion sort
            for (var k=0;k<data.length;k++) {
               var len = data[k].length, i = -1, j, tmp; 
                while (len--) {     
                  tmp = data[k][++i];
                  j = i;
                  while (j-- && solveBlogs[data[k][j]][BLOGCREATED] < solveBlogs[tmp][BLOGCREATED]) {
                     data[k][j + 1] = data[k][j];
                  }
                  data[k][j + 1] = tmp;
               }
            }
            return data;
         }
         
         function _sortByStatus(data) {
            // insertion sort
            for (var k=0;k<data.length;k++) {
               var len = data[k].length, i = -1, j, tmp; 
                while (len--) {     
                  tmp = data[k][++i];
                  j = i;
                  while (j-- && _getStatusFromString(solveBlogs[data[k][j]][BLOGSTATUS]) > _getStatusFromString(solveBlogs[tmp][BLOGSTATUS])) {
                     data[k][j + 1] = data[k][j];
                  }
                  data[k][j + 1] = tmp;
               }
            }
            return data;
         }
         
         function _getBlogsByType(blStatus) {
            var data=new Array();
            for (var i=0;i<solveBlogs.length;i++) {
               if (solveBlogs[i][BLOGSTATUS]==blStatus) data.push(i);
            }
            return data;
         }
         
         function _makeHeader(row,data) {
            var cell=document.createElement("th");
            _makeTableCell(cell,row,data);
            return cell;
         }
         
         function _makeCell(row,data) {
            var cell=document.createElement("td");
            _makeTableCell(cell,row,data);
            return cell;
         }
         
         function _makeTableCell(cell,row,data) {
            var prop;
            for (prop in data) {
               switch (prop) {
                  case "text":
                     cell.appendChild(document.createTextNode(data[prop]));
                     break;
                  case "bcol":
                     cell.style.backgroundColor=data[prop];
                     break;
                  case "Bborder":
                     cell.style.borderBottom=data[prop];
                     break;
                  default:
                     cell.setAttribute(prop,data[prop]);
               }
            }
            row.appendChild(cell);
         }
         
         function _showDetailedView() {
            var tmpBlogs=[new Array()];
            var i;
            var okay;
            for (i=0;i<solveBlogs.length;i++) {
               if (_getDateNum(solveBlogs[i][BLOGCREATED])<dateFilter[DETAILVIEW]) okay=false;
               else okay=true;
               if (coordFilter[DETAILVIEW]!=NOFILTER && okay) {
                  if (solveBlogs[i][COORDINATOR]!=GBstaff[coordFilter[DETAILVIEW]][CONSNAME]) okay=false;
               }
               if (consFilter[DETAILVIEW]!=NOFILTER && okay) {
                  if (solveBlogs[i][ASSIGNEDTO]!=GBstaff[consFilter[DETAILVIEW]][CONSNAME]) okay=false;
               }
               if (!statusFilter[DETAILVIEW][fALL] && !statusFilter[DETAILVIEW][_getStatusFromString(solveBlogs[i][BLOGSTATUS])]) okay=false;
               if (okay) tmpBlogs[0].push(i);
            }
            if (sortBy[DETAILVIEW]==BYDATE) tmpBlogs=_sortByDate(tmpBlogs);
            else {
               if (sortBy[DETAILVIEW]==BYSTATUS) tmpBlogs=_sortByStatus(tmpBlogs);
            }
            //
            var div=document.getElementById("detailcontainer");
            while (div.hasChildNodes()) div.removeChild(div.lastChild);
            //
            var canGrow=false;
            var box;
            for (i=0;i<tmpBlogs[0].length;i++) {
               if (solveBlogs[tmpBlogs[0][i]][BLOGHIDEINDEX]==0) {
                  switch (solveBlogs[tmpBlogs[0][i]][BLOGSTATUS]) {
                     case isNOTSTARTED:
                     case isSELECTION:
                        box=_createSummaryBox(tmpBlogs[0][i],true,false,false,false);
                        break;
                     case isATTRACTION:
                        canGrow=true;
                        box=_createSummaryBox(tmpBlogs[0][i],false,false,true,true);
                        break;
                     case isREPORTS:
                     case isCOMPLETED:
                        box=_createSummaryBox(tmpBlogs[0][i],false,true,true,false);
                        break;
                  }
                  div.appendChild(box);
               }
            }
            for (i=0;i<tmpBlogs[0].length;i++) {
               if (solveBlogs[tmpBlogs[0][i]][BLOGHIDEINDEX]>0) div.appendChild(_createMinimisedBlogBox(tmpBlogs[0][i]));
            }
            //
            var boxHeight=160;
            if (canGrow) {
               if (displayOptions[DETAILVIEW][SHOWSTATS]) boxHeight+=20;
               if (displayOptions[DETAILVIEW][SHOWOLD]) boxHeight+=65;
               if (displayOptions[DETAILVIEW][SHOWSTATS] && displayOptions[DETAILVIEW][SHOWOLD]) boxHeight+=50;
            } 
            document.getElementById("displayold").disabled=!canGrow;
            document.getElementById("displaystats").disabled=!canGrow;
            document.getElementById("olddateselector").disabled=!canGrow;
            
            var boxes=document.getElementsByClassName("detailDivClass");
            for (var kk=0;kk<boxes.length;kk++) {
               boxes[kk].style.height=boxHeight+"px";
            }
            div.style.display="block";
         }
         
         function _createMinimisedBlogBox(blog) {
            var mainDiv=_buildDiv("detailDivClassMINI","detailDivMINI"+blog);
            mainDiv.setAttribute("title","Click to restore.\nCtrl-Shift-Click to restore all.");
            mainDiv.onmousedown=function(e) { var evt = e ? e:window.event; var id=this.id; if (evt.ctrlKey && evt.shiftKey) _restoreAllBlogs(); else solveBlogs[parseInt(id.slice(13))][BLOGHIDEINDEX]=0; _display(); };
            
            var titleText=solveBlogs[blog][BLOGNAME];
            if (titleText=="") titleText="<Untitled project>";
            _makePtext(mainDiv,"projectTitleClassMINI",titleText);
            
            var statustext=solveBlogs[blog][BLOGSTATUS].toUpperCase();
            if (statustext=="") statustext="UNSTARTED";
            _makePtext(mainDiv,"projectStatusClassMINI",statustext);
            
            return mainDiv;   
         }
         
         function _createSummaryBox(blog,seltext,finaltext,boxes1,boxes2) {
            // NB seltext includes right-side info
            // NB boxes2 is 1st+f-up count + old-boxes + stats!
            
            var mainDiv=_buildDiv("detailDivClass","detailDiv"+blog);
            if (solveBlogs[blog][BLOGLOADSTATUS]==BLOGNOTLOADED && solveBlogs[blog][BLOGNAME]!="") {
               mainDiv.setAttribute("title","Left-click to load.\nMiddle-click or Ctrl-click to minimise.");
               mainDiv.onmousedown=function(e) { var evt = e ? e:window.event; var id=this.id; if (evt.ctrlKey || evt.which==2) solveBlogs[parseInt(id.slice(9))][BLOGHIDEINDEX]=blogHideIndex++; else _loadSolveData(parseInt(id.slice(9))); _display(); };
            } else {
               if (solveBlogs[blog][BLOGNAME]=="") {
                  mainDiv.setAttribute("title","Left-click to delete from Solve.\nMiddle-click or Ctrl-click to minimise.");
                  mainDiv.onmousedown=function(e) { var evt = e ? e:window.event; var id=this.id; if (evt.ctrlKey || evt.which==2) solveBlogs[parseInt(id.slice(9))][BLOGHIDEINDEX]=blogHideIndex++; else _deleteUntitled(id.slice(9)); _display(); };               
               } else {
                  if (solveBlogs[blog][BLOGSTATUS]==isATTRACTION || solveBlogs[blog][BLOGSTATUS]==isREPORTS) {
                     mainDiv.setAttribute("title","Left-click to generate report.\nMiddle-click or Ctrl-click to minimise.");
                     mainDiv.onmousedown=function(e) { var evt = e ? e:window.event; var id=this.id; if (evt.ctrlKey || evt.which==2) solveBlogs[parseInt(id.slice(9))][BLOGHIDEINDEX]=blogHideIndex++; else _generateReport(id.slice(9)); _display(); };
                  } else {
                     mainDiv.setAttribute("title","Middle-click or Ctrl-click to minimise.");
                     mainDiv.onmousedown=function(e) { var evt = e ? e:window.event; var id=this.id; if (evt.ctrlKey || evt.which==2) solveBlogs[parseInt(id.slice(9))][BLOGHIDEINDEX]=blogHideIndex++; _display(); };
                  }
               }
            }
            
            var titleText=solveBlogs[blog][BLOGNAME];
            if (titleText=="") titleText="<Untitled project>";
            _makePtext(mainDiv,"projectTitleClass",titleText);
                        
            var statustext=solveBlogs[blog][BLOGSTATUS].toUpperCase();
            if (statustext=="") statustext="UNSTARTED";
            _makePtext(mainDiv,"projectStatusClass",statustext);
            
            var loader=_buildDiv("loadmessageClass","loadmessage"+blog);
            var loadMessage="Loading...";
            if (solveBlogs[blog][BLOGLOADINGNOW]==isLOADING && solveBlogs[blog][BLOGLOADSTATUS]==BLOGLOAD1) loadMessage+=_loadPercentage(blog)+"%";
            loader.appendChild(document.createTextNode(loadMessage));
            
            if (solveBlogs[blog][BLOGLOADINGNOW]!=isNOTLOADING) loader.style.display="block";
            else loader.style.display="none";
            mainDiv.appendChild(loader);
            
            var itext=[["Info profile:","??"],["Selection:","??"],["Execution:",""],["Coordinator:",""]];
            if (solveBlogs[blog][ASSIGNEDTO]!="") {
               itext[2][1]=solveBlogs[blog][ASSIGNEDTO];
               for (var i=0;i<GBstaff.length;i++) {
                  if (itext[2][1]==GBstaff[i][CONSNAME]) itext[2][1]=GBstaff[i][CONSNAMESHORT];
               }
            }
            if (solveBlogs[blog][COORDINATOR]!="") {
               itext[3][1]=solveBlogs[blog][COORDINATOR];
               for (var i=0;i<GBstaff.length;i++) {
                  if (itext[3][1]==GBstaff[i][CONSNAME]) itext[3][1]=GBstaff[i][CONSNAMESHORT];
               }
            }
            
            if (seltext) {
               if (solveBlogs[blog][BLOGLOADSTATUS]==BLOGNOTLOADED) {
                  var textI="??";
                  var textS="??";
               } else {
                  // change profile & selection status
                  var textI=solveBlogs[blog][BLOGFILES][0];
                  var textS=solveCompanies[blog].length;
                  // get profile & selection workers from NOTE
                  itext[0][1]=_getFromNote(blog,1);
                  itext[1][1]=_getFromNote(blog,2);
                  if (itext[1][1]=="") itext.splice(1,1);
                  if (itext[0][1]=="") itext.shift();
               }
               _makePspan(mainDiv,"profileClass","Info profile: ",textI);
               _makePspan(mainDiv,"selectionClass","Selection: ",textS);
            } else {
               itext.shift();
               itext.shift();
            }
            
            if (!displayOptions[DETAILVIEW][SHOWCONS]) {
               while(itext.length>1) itext.shift();
            }
            if (!displayOptions[DETAILVIEW][SHOWCOORDS]) itext.pop();
            
            for (var i=0;i<itext.length;i++) {
               if (itext[i][1]!="") {
                  _makePtext(mainDiv,"infoClassLabel"+i,itext[i][0]);
                  if (itext[i][1]=="??") _makePspan(mainDiv,"infoClass"+i,"",itext[i][1]);
                  else _makePtext(mainDiv,"infoClass"+i,itext[i][1]);
               }
            }
            
            if (finaltext) {
               if (solveBlogs[blog][BLOGLOADSTATUS]==BLOGNOTLOADED) {
                  var textMP="??";
                  var textFR="??";
               } else {
                  var textMP=solveBlogs[blog][BLOGFILES][1];
                  var textFR=solveBlogs[blog][BLOGFILES][2];
               }
               _makePspan(mainDiv,"meetingClass","Meeting plan: ",textMP);
               _makePspan(mainDiv,"finalClass","Final report: ",textFR);
            }
            
            if (boxes1) {
               var summaryDiv=_buildDiv("summaryClass","");
               if (solveBlogs[blog][BLOGLOADSTATUS]!=BLOGLOADED) {
                  var textG="?";
                  var textY="?";
                  var textR="?";
                  var text1="?";
                  var textF="?";
                  if (solveBlogs[blog][BLOGLOADSTATUS]==BLOGLOAD1) {
                     var textT=solveCompanies[blog].length+" =";
                  } else {
                     var textT="? =";
                  }
               } else {
                  var textT=solveCompanies[blog].length+" =";
                  var textG=_countDecisions(blog,GREEN);
                  var textY=_countDecisions(blog,YELLOW);
                  var textR=_countDecisions(blog,RED);
                  var text1=_countDecisions(blog,ONFIRSTCALL);
                  var textF=_countDecisions(blog,NODECISION);      
               }
               _makePtext(summaryDiv,"totalNumClass",textT);
               _makeDiv(summaryDiv,"greenNumClass",textG);
               _makeDiv(summaryDiv,"yellowNumClass",textY);
               _makeDiv(summaryDiv,"redNumClass",textR);
               if (boxes2) {
                  var div=_buildDiv("whiteNumClass","");
                  _makeDiv(div,"firstNumClass",text1);
                  _makeDiv(div,"followNumClass",textF);
                  _makePtext(div,"firstNumLabelClass","1st calls");
                  _makePtext(div,"followNumLabelClass","follow-ups");
                  summaryDiv.appendChild(div);
               }
               if (!boxes2 || !displayOptions[DETAILVIEW][SHOWSTATS]) mainDiv.appendChild(summaryDiv);
            }
            if (boxes2) {
               if (displayOptions[DETAILVIEW][SHOWSTATS]) {
                  var div=_buildDiv("statsClass","");
                  if (solveBlogs[blog][BLOGLOADSTATUS]==BLOGLOADED) {
                     var statsData=[solveStats[blog][TOTALCALLS],solveStats[blog][NO1CALLS],solveStats[blog][NO2CALLS],(solveStats[blog][TOTALCALLS]-solveStats[blog][NO1CALLS]-solveStats[blog][NO2CALLS]) ];
                  } else {
                     var statsData=["?","?","?","?"];
                  }
                  _makePtext(div,"callsTClass",statsData[0]);
                  _makePtext(div,"calls1Class",statsData[1]);
                  _makePtext(div,"calls2Class",statsData[2]);
                  _makePtext(div,"callsCClass",statsData[3]);
                  summaryDiv.appendChild(div);     
                  mainDiv.appendChild(summaryDiv);
               }
               if (displayOptions[DETAILVIEW][SHOWOLD]) {
                  if (displayOptions[DETAILVIEW][SHOWSTATS]) _makeDiv(mainDiv,"separatorClass","");
                  var summaryDiv=_buildDiv("OLDsummaryClass","");
                  if (solveBlogs[blog][BLOGLOADSTATUS]!=BLOGLOADED) {
                     var textG="?";
                     var textY="?";
                     var textR="?";
                     var text1="?";
                     var textF="?";
                     if (solveBlogs[blog][BLOGLOADSTATUS]==BLOGLOAD1) {
                        var textT=_countOLDcompanies(blog)+" =";
                     } else {
                        var textT="? =";
                     }
                  } else {
                     var textT=_countOLDcompanies(blog)+" =";
                     var textG=_countOldDecisions(blog,GREEN);
                     var textY=_countOldDecisions(blog,YELLOW);
                     var textR=_countOldDecisions(blog,RED);
                     var text1=_countOldDecisions(blog,ONFIRSTCALL);
                     var textF=_countOldDecisions(blog,NODECISION);      
                  }
                  _makePtext(summaryDiv,"OLDtotalNumClass",textT);
                  _makeDiv(summaryDiv,"OLDgreenNumClass",textG);
                  _makeDiv(summaryDiv,"OLDyellowNumClass",textY);
                  _makeDiv(summaryDiv,"OLDredNumClass",textR);
                  
                  var div=_buildDiv("OLDwhiteNumClass","");
                  _makeDiv(div,"OLDfirstNumClass",text1);
                  _makeDiv(div,"OLDfollowNumClass",textF);
                  _makePtext(div,"OLDfirstNumLabelClass","1st calls");
                  _makePtext(div,"OLDfollowNumLabelClass","follow-ups");
                  summaryDiv.appendChild(div);

                  if (!displayOptions[DETAILVIEW][SHOWSTATS]) {
                     mainDiv.appendChild(summaryDiv);
                  } else {
                     var div=_buildDiv("OLDstatsClass","");
                     if (solveBlogs[blog][BLOGLOADSTATUS]==BLOGLOADED) {
                        var statsData=[solveStats[blog][oTOTALCALLS],solveStats[blog][oNO1CALLS],solveStats[blog][oNO2CALLS],(solveStats[blog][oTOTALCALLS]-solveStats[blog][oNO1CALLS]-solveStats[blog][oNO2CALLS]) ];
                     } else {
                        var statsData=["?","?","?","?"];
                     }
                     _makePtext(div,"OLDcallsTClass",statsData[0]);
                     _makePtext(div,"OLDcalls1Class",statsData[1]);
                     _makePtext(div,"OLDcalls2Class",statsData[2]);
                     _makePtext(div,"OLDcallsCClass",statsData[3]);
                     summaryDiv.appendChild(div);     
                     mainDiv.appendChild(summaryDiv);
                  }
               }
            }
            return mainDiv;       
         }
          
         function _getFromNote(blog,indx) {
            // [##] info profile:NAME / selection:? / HELP WITH additional selection:NAME / calling:NAME, NAME
            var pos=1;
            for (i=0;i<indx && pos>0;i++) pos=1+solveBlogs[blog][BLOGNOTE].indexOf(":",pos);
            if (pos>0) {
               var stop=solveBlogs[blog][BLOGNOTE].indexOf("/",pos);
               var retStr=solveBlogs[blog][BLOGNOTE].slice(pos,stop);
               while (retStr.charCodeAt(retStr.length-1)==32) retStr=retStr.slice(0,retStr.length-1);
               if (retStr=="?") retStr="";
            } else var retStr="";
            return retStr;
         }
         
         function _buildDiv(divclass,id) {
            var div=document.createElement("div");
            div.setAttribute("class",divclass);
            if (id!="") div.setAttribute("id",id);
            return div;
         }
         
         function _makeDiv(cont,divclass,text) {
            var div=document.createElement("div");
            div.setAttribute("class",divclass);
            div.appendChild(document.createTextNode(text));
            cont.appendChild(div);
         }
         
         function _makeP(cont,pclass) {
            var para=document.createElement("p");
            para.setAttribute("class",pclass);
            cont.appendChild(para);
         }
         
         function _makePtext(cont,pclass,text) {
            var para=document.createElement("p");
            para.setAttribute("class",pclass);
            para.appendChild(document.createTextNode(text));
            cont.appendChild(para);
         }
         
         function _makePspan(cont,pclass,text,spantext) {
            var para=document.createElement("p");
            para.setAttribute("class",pclass);
            para.appendChild(document.createTextNode(text));
            var spn=document.createElement("span");
            spn.setAttribute("class","stateSpan");
            spn.appendChild(document.createTextNode(spantext));
            para.appendChild(spn);
            cont.appendChild(para);
         }
         
         function _getStatusFromString(stat) {
            var ret;
            switch (stat) {
               case isNOTSTARTED:
                  ret=fNOTSTARTED;
                  break;
               case isSELECTION:
                  ret=fSELECTION;
                  break;
               case isATTRACTION:
                  ret=fATTRACTION;
                  break;
               case isREPORTS:
                  ret=fREPORTS;
                  break;
               case isCOMPLETED:
                  ret=fCOMPLETED;
                  break;
               case isALL:
                  ret=fALL;
                  break;
            }
            return ret;
         }
         
         function _showOrganiserView() {
            var tmpStaff=[];
            var hiddenStaff=[];
            var consTypes=document.getElementById("constypefilter").selectedIndex;
            
            for (var i=0;i<GBstaff.length;i++) {
               if (GBstaff[i][CONSTYPE]==ISCONS || GBstaff[i][CONSTYPE]==ISBOTH) {
                  if ((consTypes==1 && GBstaff[i][STAFFEXECTYPE]==2) || (consTypes==2 && GBstaff[i][STAFFEXECTYPE]==1)) {
                     // filtered out
                     // exec types can be 0 (both), 1 (exec only), 2 (non-exec only)
                  } else {
                     if (GBstaff[i][STAFFHIDEINDEX]==0) tmpStaff.push(i);
                     else hiddenStaff.push(i);
                  }
               }
            }
            if (document.getElementById("staffsortbox").selectedIndex==1) {
               // sort tmpStaff by workload
               var tmpStaffLoad=[];
               for (var i=0;i<tmpStaff.length;i++) tmpStaffLoad.push(0);
               var okay;
               for (var i=0;i<solveBlogs.length;i++) {               
                  if (_getDateNum(solveBlogs[i][BLOGCREATED])<dateFilter[ORGANISERVIEW]) okay=false;
                  else okay=true;
                  if (coordFilter[ORGANISERVIEW]!=NOFILTER && okay) {
                     if (solveBlogs[i][COORDINATOR]!=GBstaff[coordFilter[ORGANISERVIEW]][CONSNAME]) okay=false;
                  }
                  if (!statusFilter[ORGANISERVIEW][fALL] && !statusFilter[ORGANISERVIEW][_getStatusFromString(solveBlogs[i][BLOGSTATUS])]) okay=false;
                  if (okay) {
                     for (var j=0;j<tmpStaff.length;j++) {
                        if (solveBlogs[i][ASSIGNEDTO]==GBstaff[tmpStaff[j]][CONSNAME]) tmpStaffLoad[j]++; 
                     }
                  }
               }
               // insertion sort
               var len=tmpStaff.length, i=-1, j, tmp, tmpLoad; 
               while (len--) {     
                  tmp = tmpStaff[++i];
                  tmpLoad=tmpStaffLoad[i];
                  j = i;
                  while (j-- && tmpStaffLoad[j] < tmpLoad) {
                     tmpStaff[j + 1] = tmpStaff[j];
                     tmpStaffLoad[j+1]= tmpStaffLoad[j];
                  }
                  tmpStaff[j + 1] = tmp;
                  tmpStaffLoad[j + 1] = tmpLoad;
               }
            }
            
            var div=document.getElementById("organisercontainer");
            while (div.hasChildNodes()) div.removeChild(div.lastChild);
            
            var box;            
            for (var i=0;i<tmpStaff.length;i++) {
               box=_makeStaffBox(tmpStaff[i]);
               div.appendChild(box);
            }
            if (hideUnassigned) box=_createMinimisedStaffBox(-1);
            else box=_makeStaffBox(-1);
            div.appendChild(box);
            
            for (var i=0;i<hiddenStaff.length;i++) {
               box=_createMinimisedStaffBox(hiddenStaff[i]);
               div.appendChild(box);
            }
            
            div.style.display="block";
         }
         
         function _createMinimisedStaffBox(empl) {
            if (empl==-1) {
               var id="staffDivUNASSIGNED";
               var titleText="<Unassigned>";
            } else {
               var id="staffDiv"+empl;
               var titleText=GBstaff[empl][CONSNAMESHORT];
            }
            
            var mainDiv=_buildDiv("staffDivClassMINI",id);  
            mainDiv.setAttribute("title","Click to restore.\nCtrl-Shift-Click to restore all.");
            if (empl==-1) {
               mainDiv.onmousedown=function(e) { var evt = e ? e:window.event; var id=this.id; if (evt.ctrlKey && evt.shiftKey) _restoreAllStaff(); else hideUnassigned=false; _display(); };
            } else {
               mainDiv.onmousedown=function(e) { var evt = e ? e:window.event; var id=this.id; if (evt.ctrlKey && evt.shiftKey) _restoreAllStaff(); else GBstaff[parseInt(id.slice(8))][STAFFHIDEINDEX]=0; _display(); };
            }
            
            _makePtext(mainDiv,"staffTitleClassMINI",titleText);
            
            var tmpBlogs=[new Array()];
            var okay;
            for (i=0;i<solveBlogs.length;i++) {
               if (_getDateNum(solveBlogs[i][BLOGCREATED])<dateFilter[ORGANISERVIEW]) okay=false;
               else okay=true;
               if (coordFilter[ORGANISERVIEW]!=NOFILTER && okay) {
                  if (solveBlogs[i][COORDINATOR]!=GBstaff[coordFilter[ORGANISERVIEW]][CONSNAME]) okay=false;
               }
               if (!statusFilter[ORGANISERVIEW][fALL] && !statusFilter[ORGANISERVIEW][_getStatusFromString(solveBlogs[i][BLOGSTATUS])]) okay=false;
               if (okay) {
                  if (empl==-1) {
                     if (solveBlogs[i][ASSIGNEDTO]=="" || solveBlogs[i][ASSIGNEDTO]=="Unassigned") tmpBlogs[0].push(i);
                  } else {
                     if (solveBlogs[i][ASSIGNEDTO]==GBstaff[empl][CONSNAME]) tmpBlogs[0].push(i);
                  }
               }
            }         
            
            _makePtext(mainDiv,"staffLoadClassMINI",tmpBlogs[0].length);
            if (document.getElementById("hidezeros").checked==true && tmpBlogs[0].length==0) mainDiv.style.display="none";
            return mainDiv;   
         }
         
         function _makeStaffBox(empl) {
            if (empl==-1) {
               var id="staffDivUNASSIGNED";
               var titleText="<Unassigned>";
            } else {
               var id="staffDiv"+empl;
               var titleText=GBstaff[empl][CONSNAMESHORT];
            }
            
            var mainDiv=_buildDiv("staffDivClass",id);

            var titleP=document.createElement("p");
            titleP.setAttribute("class","staffTitleClass");
            titleP.appendChild(document.createTextNode(titleText));
            titleP.setAttribute("id","staffTitleId"+empl);
                        
            titleP.setAttribute("title","Left-click to load all unloaded projects.\nMiddle-click or Ctrl-click to minimise.");
            if (empl==-1) {
               titleP.onmousedown=function(e) { var evt = e ? e:window.event; if (evt.ctrlKey || evt.which==2) hideUnassigned=true; else _loadStaffMember(-1); _display(); };
            } else {
               titleP.onmousedown=function(e) { var evt = e ? e:window.event; var id=this.id; if (evt.ctrlKey || evt.which==2) GBstaff[parseInt(id.slice(12))][STAFFHIDEINDEX]=blogHideIndex++; else _loadStaffMember(parseInt(id.slice(12))); _display(); };
            }
            mainDiv.appendChild(titleP);
                         
            var tmpBlogs=[new Array()];
            var okay;
            for (i=0;i<solveBlogs.length;i++) {
               if (_getDateNum(solveBlogs[i][BLOGCREATED])<dateFilter[ORGANISERVIEW]) okay=false;
               else okay=true;
               if (coordFilter[ORGANISERVIEW]!=NOFILTER && okay) {
                  if (solveBlogs[i][COORDINATOR]!=GBstaff[coordFilter[ORGANISERVIEW]][CONSNAME]) okay=false;
               }
               if (!statusFilter[ORGANISERVIEW][fALL] && !statusFilter[ORGANISERVIEW][_getStatusFromString(solveBlogs[i][BLOGSTATUS])]) okay=false;
               if (okay) {
                  if (empl==-1) {
                     if (solveBlogs[i][ASSIGNEDTO]=="" || solveBlogs[i][ASSIGNEDTO]=="Unassigned") tmpBlogs[0].push(i);
                  } else {
                     if (solveBlogs[i][ASSIGNEDTO]==GBstaff[empl][CONSNAME]) tmpBlogs[0].push(i);
                  }
               }
            }         
            if (sortBy[ORGANISERVIEW]==BYDATE) tmpBlogs=_sortByDate(tmpBlogs);
            else {
               if (sortBy[ORGANISERVIEW]==BYSTATUS) tmpBlogs=_sortByStatus(tmpBlogs);
            }

            if (document.getElementById("hidezeros").checked==true && tmpBlogs[0].length==0) {
               mainDiv.style.display="none";
            } else {
               _makePtext(mainDiv,"staffLoadClass",tmpBlogs[0].length);
               var contDiv=_buildDiv("staffDivContainerClass","");
               
               for (var i=0;i<tmpBlogs[0].length;i++) {
                  _makeProjectListBox(tmpBlogs[0][i],contDiv,i%2,empl);
               }
               if (tmpBlogs[0].length<4) {
                  _makeProjectListBoxDummy(contDiv,empl);
                  contDiv.setAttribute("class","staffDivContainerClassNoOv");
               }
            
               mainDiv.appendChild(contDiv);
            }
            return mainDiv;
         }
         
         function _makeProjectListBoxDummy(div,empl) {
            var box=_buildDiv("projectListDummyClass","projectListDummyId"+empl);
            box.setAttribute("title","Middle-click or Ctrl-click to minimise.");
            if (empl==-1) {
               box.onmousedown=function(e) { var evt = e ? e:window.event; if (evt.ctrlKey || evt.which==2) { hideUnassigned=true; _display(); } };
            } else {
               box.onmousedown=function(e) { var evt = e ? e:window.event; var id=this.id; if (evt.ctrlKey || evt.which==2) { GBstaff[parseInt(id.slice(18))][STAFFHIDEINDEX]=blogHideIndex++; _display(); } };
            }
            div.appendChild(box);
         }
         
         function _makeProjectListBox(blog,div,type,empl) {
            if (empl==-1) var emplStr="UNN";
            else var emplStr="00"+empl;
            var box=_buildDiv("projectListBoxClass"+type,"projectListBoxId"+emplStr.slice(-3)+blog);
            box.setAttribute("title","Left-click to edit project details.\nMiddle-click or Ctrl-click to minimise.");
            if (empl==-1) {
               box.onmousedown=function(e) { var evt = e ? e:window.event; var id=this.id; if (!evt.ctrlKey && evt.which!=2) _editBlog(parseInt(id.slice(19))); else { hideUnassigned=true; _display(); } };
            } else {
               box.onmousedown=function(e) { var evt = e ? e:window.event; var id=this.id; if (!evt.ctrlKey && evt.which!=2) _editBlog(parseInt(id.slice(19))); else { GBstaff[parseInt(id.slice(16,19),10)][STAFFHIDEINDEX]=blogHideIndex++; _display(); } };
            }
            
            var titleText=solveBlogs[blog][BLOGNAME];
            if (titleText=="") titleText="<Untitled project>";
            _makePtext(box,"projectListTitleClass",titleText);     

            if (solveBlogs[blog][BLOGLOADINGNOW]!=isNOTLOADING) {
               var statusText="Loading...";
               if (solveBlogs[blog][BLOGLOADINGNOW]==isLOADING && solveBlogs[blog][BLOGLOADSTATUS]==BLOGLOAD1) statusText+=_loadPercentage(blog)+"%";
               _makePtext(box,"projectListLoadingClass",statusText);
            } else {
               var statusText=solveBlogs[blog][BLOGSTATUS].toUpperCase();
               if (statusText=="") statusText="UNSTARTED";
               _makePtext(box,"projectListStatusClass",statusText);
            }   
            
	         if (displayOptions[ORGANISERVIEW][SHOWCOORDS] && solveBlogs[blog][COORDINATOR]!="") {
	            _makePtext(box,"projectListCoordClass",solveBlogs[blog][COORDINATOR]);
	         }

   	      switch (solveBlogs[blog][BLOGSTATUS]) {
   	         case isNOTSTARTED:
   	         case isSELECTION:
   		         if (solveBlogs[blog][BLOGLOADSTATUS]==BLOGNOTLOADED) {
                     var textI="??";
                     var textS="??";
                  } else {
                     // change profile & selection status
                     var textI=solveBlogs[blog][BLOGFILES][0];
                     var textS=solveCompanies[blog].length;
		            }
		            if (document.getElementById("hideunknowns").checked==false || textI!="??") _makePspan(box,"listprofileClass","Info profile: ",textI);
                  if (document.getElementById("hideunknowns").checked==false || textS!="??") _makePspan(box,"listselectionClass","Selection: ",textS);
		            break;
	            case isREPORTS:
	            case isCOMPLETED:
		            // intentional run-through!
		         case isATTRACTION:
		            if (solveBlogs[blog][BLOGLOADSTATUS]!=BLOGLOADED) {
                     var textG="?";
                     var textY="?";
                     var textR="?";
                     if (solveBlogs[blog][BLOGLOADSTATUS]==BLOGLOAD1) {
                        var textT=solveCompanies[blog].length+" =";
                     } else {
                        var textT="? =";
                     }
                  } else {
                     var textT=solveCompanies[blog].length+" =";
                     var textG=_countDecisions(blog,GREEN);
                     var textY=_countDecisions(blog,YELLOW);
                     var textR=_countDecisions(blog,RED);               
                  }
                  _makePtext(box,"totalNumClassLIST",textT);
                  _makeDiv(box,"greenNumClassLIST",textG);
                  _makeDiv(box,"yellowNumClassLIST",textY);
                  _makeDiv(box,"redNumClassLIST",textR);
		            break;
	         }
            
            div.appendChild(box);
         }
         
         function _restoreAllBlogs() {
            for (var i=0;i<solveBlogs.length;i++) solveBlogs[i][BLOGHIDEINDEX]=0;
         }
         
         function _restoreAllStaff() {
            hideUnassigned=false;
            for (var i=0;i<GBstaff.length;i++) GBstaff[i][STAFFHIDEINDEX]=0;
         }
         
         
         // ****************************************************************************************************************************
         // ****************************************************************************************************************************
         //
         // ---------------------------- menubar functions ---------------------------------
         function _defaultSettings() {
            document.getElementById("loadselect").selectedIndex=5;
            document.getElementById("loadbutton").disabled=false;
            document.getElementById("olddateselector").selectedIndex=0;
            document.getElementById("olddateselector").disabled=true;
            document.getElementById("staffsortbox").selectedIndex=0;
            document.getElementById("constypefilter").selectedIndex=0;
            document.getElementById("hideunknowns").checked=false;
            document.getElementById("hidezeros").checked=true;
            _setDates();
         }
         
         function _addOption(sel,text,value) {
            var opt=document.createElement("option");
            opt.text=text;
            opt.value=value;
            sel.appendChild(opt);
         }
         
         function _getView(num) {
            var rotView=[0,1,2,0,1,2];
            return rotView[displayView+num+1];
         }
         
         function _statusFilterClick(fil) {
            for (var i=LISTVIEW;i<=ORGANISERVIEW;i++) {
               var vw=_getView(i);
               if (displayView==vw || (!lockSettings[vw] && !lockSettings[displayView])) {
                  switch (fil) {
                     case isNOTSTARTED:
                        statusFilter[vw][fNOTSTARTED]=!statusFilter[displayView][fNOTSTARTED];
                        break;
                     case isSELECTION:
                        statusFilter[vw][fSELECTION]=!statusFilter[displayView][fSELECTION];
                        break;
                     case isATTRACTION:
                        statusFilter[vw][fATTRACTION]=!statusFilter[displayView][fATTRACTION];
                        break;
                     case isREPORTS:
                        statusFilter[vw][fREPORTS]=!statusFilter[displayView][fREPORTS];
                        break;
                     case isCOMPLETED:
                        statusFilter[vw][fCOMPLETED]=!statusFilter[displayView][fCOMPLETED];
                        break;
                     case isALL:
                        statusFilter[vw][fALL]=!statusFilter[displayView][fALL];
                        document.getElementById("unstartedfilter").disabled=statusFilter[vw][fALL];
                        document.getElementById("selectionfilter").disabled=statusFilter[vw][fALL];
                        document.getElementById("attractionfilter").disabled=statusFilter[vw][fALL];
                        document.getElementById("reportsfilter").disabled=statusFilter[vw][fALL];
                        document.getElementById("completedfilter").disabled=statusFilter[vw][fALL];
                        break;
                  }
               }
            }
            _display();   
         }
         
         function _displayOptionsClick(optStr) {
            var opt=parseInt(optStr);
            for (var i=LISTVIEW;i<=ORGANISERVIEW;i++) {
               var vw=_getView(i);
               if (displayView==vw || (!lockSettings[vw] && !lockSettings[displayView])) {
                  if (opt<displayOptions[vw].length) displayOptions[vw][opt]=!displayOptions[displayView][opt];
               }
            }
            if (displayView==DETAILVIEW && opt==SHOWOLD) document.getElementById("olddateselector").disabled=!displayOptions[DETAILVIEW][SHOWOLD];
            _display();
         }
         
         function _sortChange(sortopt) {
            for (var vw=LISTVIEW;vw<=ORGANISERVIEW;vw++) {
               if (displayView==vw || (!lockSettings[vw] && !lockSettings[displayView])) {
                  if (sortopt!=BYSTATUS || vw!=LISTVIEW) sortBy[vw]=sortopt;
               }
            }
            _display();
         }
         
         function _mainMenuClick(opt) {
            if (opt!=displayView) {
               var tmpId=["listview","detailview","organiserview"];
               document.getElementById(tmpId[displayView]).setAttribute("class","menu");
               displayView=opt;
               document.getElementById(tmpId[displayView]).setAttribute("class","menuSelected");
               _display();
            }
         }
         
         function _filterCoord(indx) {
            for (var vw=LISTVIEW;vw<=ORGANISERVIEW;vw++) {
               if (displayView==vw || (!lockSettings[vw] && !lockSettings[displayView])) coordFilter[vw]=indx;
            }
            _display();
         }
                  
         function _filterCons(indx) {
            for (var vw=LISTVIEW;vw<=ORGANISERVIEW;vw++) {
               if (displayView==vw || (!lockSettings[vw] && !lockSettings[displayView])) consFilter[vw]=indx;
            }
            _display();
         }
         
         function _filterDate(indx) {
            for (var vw=LISTVIEW;vw<=ORGANISERVIEW;vw++) {
               if (displayView==vw || (!lockSettings[vw] && !lockSettings[displayView])) dateFilter[vw]=indx;
            }
            _display();
         }
         
         function _staffSortChange() {
            _display();
         }
         
         function _filterConsType() {
            _display();
         }
         
         function _loadStaffMember(empl) {
            var okay;
            for (var i=0;i<solveBlogs.length;i++) {
               if (solveBlogs[i][BLOGLOADSTATUS]==BLOGNOTLOADED) {
                  if (_getDateNum(solveBlogs[i][BLOGCREATED])<dateFilter[ORGANISERVIEW]) okay=false;
                  else okay=true;
                  if (coordFilter[ORGANISERVIEW]!=NOFILTER && okay) {
                     if (solveBlogs[i][COORDINATOR]!=GBstaff[coordFilter[ORGANISERVIEW]][CONSNAME]) okay=false;
                  }
                  if (!statusFilter[ORGANISERVIEW][fALL] && !statusFilter[ORGANISERVIEW][_getStatusFromString(solveBlogs[i][BLOGSTATUS])]) okay=false;
                  if (okay) {
                     if (empl==-1) {
                        if (solveBlogs[i][ASSIGNEDTO]=="" || solveBlogs[i][ASSIGNEDTO]=="Unassigned") _loadSolveData(i);
                     } else {
                        if (solveBlogs[i][ASSIGNEDTO]==GBstaff[empl][CONSNAME]) _loadSolveData(i);
                     }
                  }
               }
            }
            _display();
         }
         
         function _loadClick() {
            if (displayView==ORGANISERVIEW) {
               var tmpStaff=[];
               var consTypes=document.getElementById("constypefilter").selectedIndex;            
               for (var i=0;i<GBstaff.length;i++) {
                  if (GBstaff[i][CONSTYPE]==ISCONS || GBstaff[i][CONSTYPE]==ISBOTH) {
                     if ((consTypes==1 && GBstaff[i][STAFFEXECTYPE]==2) || (consTypes==2 && GBstaff[i][STAFFEXECTYPE]==1)) {
                        // filtered out
                        // exec types can be 0 (both), 1 (exec only), 2 (non-exec only)
                     } else {
                        if (GBstaff[i][STAFFHIDEINDEX]==0) tmpStaff.push(i);
                     }
                  }
               }
            }
            var sel=document.getElementById("loadselect");
            for (i=0;i<solveBlogs.length;i++) {
               if (_getDateNum(solveBlogs[i][BLOGCREATED])<dateFilter[displayView]) okay=false;
               else okay=true;
               if (coordFilter[displayView]!=NOFILTER && okay) {
                  if (solveBlogs[i][COORDINATOR]!=GBstaff[coordFilter[displayView]][CONSNAME]) okay=false;
               }
               // need to change this to work for organiser view - if assigned to a displayed consultant
               if (displayView==DETAILVIEW && consFilter[displayView]!=NOFILTER && okay) {
                  if (solveBlogs[i][ASSIGNEDTO]!=GBstaff[consFilter[displayView]][CONSNAME]) okay=false;
               }
               
               if (solveBlogs[i][BLOGLOADSTATUS]!=BLOGNOTLOADED) okay=false;
               
               if (sel[sel.selectedIndex].value==isALL) {
                  if (!statusFilter[displayView][fALL] && !statusFilter[displayView][_getStatusFromString(solveBlogs[i][BLOGSTATUS])]) okay=false;
               } else {
                  if (solveBlogs[i][BLOGSTATUS]!=sel[sel.selectedIndex].value) okay=false;
               }
               if (okay && solveBlogs[i][BLOGNAME]!="") {
                  if (displayView==DETAILVIEW) _loadSolveData(i);
                  else {
                     for (var k=0;k<tmpStaff.length;k++) {
                        if (solveBlogs[i][ASSIGNEDTO]==GBstaff[k][CONSNAME]) _loadSolveData(i);
                     }
                  }
               }
            }
            _display();
         }
         
         function _toggleLock(el) {
            if (el.className=="lockOff") {
               el.className="lockOn";
               lockSettings[displayView]=true;
            } else {
               el.className="lockOff";
               lockSettings[displayView]=false;
            }
         }
         
         function _clearSettings() {
            alert("clear settings");
         }
         
         function _editBlog(blog) {
            alert(solveBlogs[blog][BLOGNAME]);
         }
         
         // -------------------------------------- action functions ----------------------------------------
         
         function _deleteUntitled(blog) {
            var cont=confirm("Are you sure you want to delete this project blog from Solve?");
            if (cont) {
               alert("deleting");
            }
         }
         
         function _generateReport(blog) {
            alert("generate");
         }
         
         // -------------------------------------- end of javascript ----------------------------------------
         // **************************************************************************************************
      </script>
      <style type="text/css">
         body { margin:0; padding:10px; font-family:arial,sans-serif; font-size:100%; position:relative; }
         h1 { font-size:2.5em; }
         h2 { font-size:1.25em; }
         h3 { font-size:1.0em; }
         p { font-size:0.75em; }
         span { font-size:0.75em; }
         label { font-size:0.75em; }
         input { font-size:0.75em; }
         select { font-size:0.75em; }
         
         .bold { font-weight:bold; }
         .italic { font-style:italic; }
         .close { margin:0 0 5px 0; padding:0; }
         
         #dummybox { position:fixed; top:0; left:0; background:white; z-index:998; width:100%; height:20px; }
         #menubar { position:fixed; margin:0; padding:0; width:100%; height:85px; border-bottom:1px solid black; background:white; z-index:999; overflow-x:auto; overflow-y:hidden; }
         span.menu { font-size:0.75em; }
         span.menuSelected { font-size:0.75em; color:blue; cursor:default; }
         span.menu:hover { cursor:pointer; text-decoration:underline; }
         #organiserview { margin:0 55px 0 0; }
         
         #sortbox { margin:0 0 0 1px; }
         
         #loaddiv { position:absolute; top:33px; left:5px; width:150px; }
         
         #displayoptions { position:absolute; top:26px; left:210px; width:415px; }
         .check { position:relative; top:2px; margin:0; }
         .checkcontainer1 { width:145px; float:left; margin:0 30px; }
         
         #hideunknownscontainer { position:absolute; top:26px; left:240px; }
         #hidezeroscontainer { position:absolute; top:46px; left:240px; }
         
         #statusfilter { position:absolute; top:0; left:650px; width:195px; }
         .checkcontainer2 { width:95px; float:left; }
         
         #otherfilters { position:absolute; top:0; left:850px; width:200px; height:68px; }
         .ofilterlabel { position:absolute; top:2px; right:120px; text-align:right; }
         .ofilterbox { position:absolute; left:86px; width:100px; }
         .ofilterdiv { position:relative; height:22px; }
         
         table { border-collapse:collapse; font-size:0.75em; padding:0; margin:0; width:100%; }
         td { text-align:center; vertical-align:top; border-left:1px solid black; border-right:1px solid black;padding:5px; cursor:default; }
         th { text-align:center; vertical-align:top; border-left:1px solid black; border-right:1px solid black;padding:5px; cursor:default; }
         p.tablep { font-size:1.0em; margin:0; padding:0; }
         p.tablepi { font-style:italic; font-size:0.875em; margin:0; padding:0; }
         p.tablepiBl { color:blue; font-style:italic; font-size:0.875em; margin:0; padding:0; }
         
         #listcontainer { margin:75px 0 0 0; padding:20px 10px 10px 10px; }
         #detailcontainer { margin:75px 0 0 0; padding:20px 10px 10px 10px; }
         #organisercontainer { margin:75px 0 0 0; padding:20px 10px 10px 10px; }
         
         #olddateselector { margin:0 25px 0 0; }
         #staffsortbox { margin:0 25px 0 0; }
         
         .lockOff { border-top:solid 2px #eaeaea; border-left:solid 2px #eaeaea; border-bottom:solid 2px #777; border-right:solid 2px #777; }
         .lockOn { background:#bbb; border-top:solid 2px #777; border-left:solid 2px #777; border-bottom:solid 2px #eaeaea; border-right:solid 2px #eaeaea; }
         #lockButton { position:absolute; top:0px; left:1050px; font-size:0.55em; margin:0; padding:0; width:62px; }
         #clearButton { position:absolute; top:37px; left:1059px; font-size:0.75em; margin:0; padding:0; }
         #bufferdiv { position:absolute; top:37px; left:1120px; width:20px; height:20px; margin:0; padding:0; }
         
         #logo { background:white url('GatewayBaltic_Logo.png') no-repeat left top; width:200px; height:35px; top:35px; left:0; position:absolute; margin:0; padding:0; background-size:contain; cursor:pointer; }
         
         /* ------------------------------------------- organiser box CSS ----------------------------------------------- */
         
         .staffDivClass { float:left; margin:10px; padding:10px; width:350px; height:200px; border:1px solid black; position:relative; overflow:hidden; }
         .staffDivClass:hover { border:1px solid blue; }
         .staffTitleClass { position:relative; font-size:1.25em; margin:0; padding:0; font-weight:bold; text-align:left; cursor:pointer; }
         .staffLoadClass { position:absolute; font-size:1em; top:12px; right:15px; margin:0; padding:0; font-weight:bold; text-align:right;}
	 
	      .staffDivClassMINI { float:left; margin:10px; padding:10px; width:154px; height:39px; border:1px solid black; position:relative; overflow:hidden; cursor:pointer; }
	      .staffDivClassMINI:hover { border:1px solid blue; }
	      .staffTitleClassMINI { position:relative; font-size:1em; margin:0; padding:0; font-weight:bold; text-align:left; }
	      .staffLoadClassMINI { position:absolute; font-size:0.875em; top:12px; right:15px; margin:0; padding:0; font-weight:bold; text-align:right;}
	 
	      .staffDivContainerClass { position:relative; overflow-y:auto; overflow-x:hidden; width:100%; height:160px; margin:10px 0 0 0; padding:0; }
	      .staffDivContainerClassNoOv { position:relative; overflow-y:hidden; overflow-x:hidden; width:100%; height:160px; margin:10px 0 0 0; padding:0; }
	      .projectListDummyClass { cursor:pointer; margin:0; padding:5px 0; height:160px; width:100%; }
	
	      .projectListBoxClass0 { position:relative; margin:0; padding:5px 0; background:#dddddd; cursor:pointer; }
	      .projectListBoxClass1 { position:relative; margin:0; padding:5px 0; background:white; cursor:pointer; }
	      .projectListTitleClass { margin:0; font-size:0.8125em; width:210px; overflow:hidden; white-space:nowrap; overflow:hidden; }
   	   .projectListStatusClass { margin:0; font-size:0.6875em; }
   	   .projectListLoadingClass { margin:0; font-size:0.6875em; color:blue; }
   	   .projectListCoordClass { margin:0; font-size:0.6875em; font-style:italic; }
   	   
   	   .listprofileClass { position:absolute; margin:0; padding:0; text-align:right; top:5px; left:230px; width:90px; }
   	   .listselectionClass { position:absolute; margin:0; padding:0; text-align:right; top:19px; left:230px; width:90px; }
   	   
   	   .totalNumClassLIST { top:12px; left:221px; position:absolute; width:30px; height:16px; font-size:0.75em; font-weight:bold; text-align:right; margin:0; padding:0; }
   	   .greenNumClassLIST { background:#6b9f17; top:9px; left:256px; position:absolute; width:20px; height:19px; font-size:0.875em; font-weight:bold; text-align:center; margin:0; padding:0; border:1px solid black; }
   	   .yellowNumClassLIST { background:yellow; top:9px; left:281px; position:absolute; width:20px; height:19px; font-size:0.875em; font-weight:bold; text-align:center; margin:0; padding:0; border:1px solid black; }
   	   .redNumClassLIST { background:red; top:9px; left:306px; position:absolute; width:20px; height:19px; font-size:0.875em; font-weight:bold; text-align:center; margin:0; padding:0; border:1px solid black; }
                 
         /* ------------------------------------------- detail box CSS ----------------------------------------------- */
         .detailDivClass { float:left; margin:10px; padding:10px; width:565px; height:160px; border:1px solid black; position:relative; overflow:hidden; cursor:pointer; }
         .detailDivClass:hover { border:1px solid blue; }
         .projectTitleClass { position:relative; font-size:1.5em; margin:0; padding:0; font-weight:bold; text-align:left; white-space:nowrap; overflow:hidden; }
         .projectStatusClass { position:absolute; font-size:0.875em; top:16px; right:10px; margin:0; padding:0; font-weight:bold; text-align:right;}
         .loadmessageClass { color:blue; position:absolute; top:50px; left:0; width:600px; height:300px; font-size:1.5em; margin:0; padding:50px 0 0 0; text-align:center; background:white; z-index:997; }
         
         .detailDivClassMINI { float:left; margin:10px; padding:10px; width:200px; height:59px; border:1px solid black; position:relative; overflow:hidden; cursor:pointer; }
         .detailDivClassMINI:hover { border:1px solid blue; }
         .projectTitleClassMINI { position:relative; font-size:1em; margin:0; padding:0; font-weight:bold; text-align:left; white-space:nowrap; overflow:hidden; }
         .projectStatusClassMINI { position:relative; font-size:0.75em; margin:10px 0 0 0; padding:0; font-weight:bold; text-align:left;}
         
         .profileClass { position:absolute; font-size:1em; top:60px; left:16px; margin:0; padding:0; text-align:left;}
         .selectionClass { position:absolute; font-size:1em; top:90px; left:16px; margin:0; padding:0; text-align:left;}
         .meetingClass { position:absolute; font-size:1em; top:120px; left:16px; margin:0; padding:0; text-align:left;}
         .finalClass { position:absolute; font-size:1em; top:150px; left:16px; margin:0; padding:0; text-align:left;}
         .stateSpan { font-size:0.875em; font-weight:bold; }

         .infoClassLabel0 { position:absolute; font-size:0.875em; top:60px; left:410px; width:90px; margin:0; padding:0; text-align:right; }
         .infoClassLabel1 { position:absolute; font-size:0.875em; top:90px; left:410px; width:90px; margin:0; padding:0; text-align:right; }
         .infoClassLabel2 { position:absolute; font-size:0.875em; top:120px; left:410px; width:90px; margin:0; padding:0; text-align:right; }
         .infoClassLabel3 { position:absolute; font-size:0.875em; top:150px; left:410px; width:90px; margin:0; padding:0; text-align:right; }
         .infoClass0 { position:absolute; font-size:0.875em; top:60px; left:505px; margin:0; padding:0; text-align:left; }
         .infoClass1 { position:absolute; font-size:0.875em; top:90px; left:505px; margin:0; padding:0; text-align:left; }
         .infoClass2 { position:absolute; font-size:0.875em; top:120px; left:505px; margin:0; padding:0; text-align:left; }
         .infoClass3 { position:absolute; font-size:0.875em; top:150px; left:505px; margin:0; padding:0; text-align:left; }
         
         .summaryClass { position:relative; top:10px; width:355px; height:115px; margin:0; padding:0; }
         .greenNumClass { background:#6b9f17; top:10px; left:75px; position:absolute; width:36px; height:34px; font-size:1.75em; font-weight:bold; text-align:center; margin:0; padding:0; border:1px solid black; }
         .yellowNumClass { background:yellow; top:10px; left:120px; position:absolute; width:36px; height:34px; font-size:1.75em; font-weight:bold; text-align:center; margin:0; padding:0; border:1px solid black; }
         .redNumClass { background:red; top:10px; left:165px; position:absolute; width:36px; height:34px; font-size:1.75em; font-weight:bold; text-align:center; margin:0; padding:0; border:1px solid black; }
         .whiteNumClass { top:10px; left:225px; width:200px; height:76px; border:none; position:absolute; font-size:1.75em; font-weight:bold; text-align:center; margin:0; padding:0; }
         .firstNumClass { margin:0; padding:0; font-size:1em; position:absolute; font-size:1em; width:36px; height:34px; text-align:center; border:1px solid black; }
         .followNumClass { margin:0; padding:0; position:relative; top:42px; font-size:1em; width:36px; height:34px; text-align:center; border:1px solid black; }
         .firstNumLabelClass { margin:0; padding:0; position:absolute; top:12px; left:44px; width:100px; font-size:0.5em; text-align:left; }
         .followNumLabelClass { margin:0; padding:0; position:absolute; top:54px; left:44px; width:100px; font-size:0.5em; text-align:left; }
         .totalNumClass { position:absolute; top:10px; left:0px; width:65px; height:34px; font-size:1.5em; font-weight:bold; text-align:right; margin:0; padding:4px 0 0 0; }
         
         .separatorClass { position:relative; width:300; height:44px; }
         
         .OLDsummaryClass { position:relative; top:10px; width:240px; height:100px; margin:0; padding:0; }
         .OLDgreenNumClass { background:#6b9f17; top:10px; left:54px; position:absolute; width:22px; height:21px; font-size:1em; font-weight:bold; text-align:center; margin:0; padding:0; border:1px solid black; }
         .OLDyellowNumClass { background:yellow; top:10px; left:83px; position:absolute; width:22px; height:21px; font-size:1em; font-weight:bold; text-align:center; margin:0; padding:0; border:1px solid black; }
         .OLDredNumClass { background:red; top:10px; left:112px; position:absolute; width:22px; height:21px; font-size:1em; font-weight:bold; text-align:center; margin:0; padding:0; border:1px solid black; }
         .OLDwhiteNumClass { top:10px; left:146px; width:200px; height:76px; border:none; position:absolute; font-size:1em; font-weight:bold; text-align:center; margin:0; padding:0; }
         .OLDfirstNumClass { margin:0; padding:0; font-size:1em; position:absolute; font-size:1em; width:22px; height:21px; text-align:center; border:1px solid black; }
         .OLDfollowNumClass { margin:0; padding:0; position:relative; top:28px; font-size:1em; width:22px; height:21px; text-align:center; border:1px solid black; }
         .OLDfirstNumLabelClass { margin:0; padding:0; position:absolute; top:7px; left:28px; width:100px; font-size:0.65em; text-align:left; }
         .OLDfollowNumLabelClass { margin:0; padding:0; position:absolute; top:34px; left:28px; width:100px; font-size:0.65em; text-align:left; }
         .OLDtotalNumClass { position:absolute; top:10px; left:0px; width:47px; height:21px; font-size:0.8em; font-weight:bold; text-align:right; margin:0; padding:4px 0 0 0; }
         
         .statsClass { position:absolute; top:96px; left:16px; background:url("statsicons.jpg") no-repeat; background-size:contain; width:400px; height:34px; margin:0; padding:0; }
         .callsTClass { position:absolute; top:16px; left:18px; font-size:0.8em; margin:0; padding:0; }
         .calls1Class { position:absolute; top:16px; left:89px; font-size:0.8em; margin:0; padding:0; }
         .calls2Class { position:absolute; top:16px; left:166px; font-size:0.8em; margin:0; padding:0; }
         .callsCClass { position:absolute; top:16px; left:239px; font-size:0.8em; margin:0; padding:0; }
         
         .OLDstatsClass { position:absolute; top:70px; left:20px; background:url("statsicons.jpg") no-repeat; background-size:contain; width:250px; height:23px; margin:0; padding:0; }
         .OLDcallsTClass { position:absolute; top:10px; left:11px; font-size:0.6em; margin:0; padding:0; }
         .OLDcalls1Class { position:absolute; top:10px; left:59px; font-size:0.6em; margin:0; padding:0; }
         .OLDcalls2Class { position:absolute; top:10px; left:111px; font-size:0.6em; margin:0; padding:0; }
         .OLDcallsCClass { position:absolute; top:10px; left:162px; font-size:0.6em; margin:0; padding:0; }
      </style>
   </head>
   <body onresize="document.getElementById('menubar').offsetWidth=document.body.clientWidth;">
      <div id="dummybox"></div>
      <div id="menubar">
         <span class="bold">View:&nbsp;</span>
         <span id="listview" class="menuSelected" onclick="_mainMenuClick(LISTVIEW)">List</span>
         <span> | </span>
         <span id="detailview" class="menu" onclick="_mainMenuClick(DETAILVIEW)">Detail</span>
         <span> | </span>
         <span id="organiserview" class="menu" onclick="_mainMenuClick(ORGANISERVIEW)">Organiser</span>
         
         <select id="olddateselector" onchange="_changeDate()">
            <option value="0">Show current status only</option>
            <option value="1" id="yesterday">Show status yesterday</option>
            <option value="2" id="weekstart">Show status at start of week</option>
            <option value="7">Show status 1 week ago</option>
            <option value="14">Show status 2 weeks ago</option>
            <option value="28">Show status 4 weeks ago</option>
         </select>
          
         <select id="staffsortbox" onchange="_staffSortChange()">
            <option value="STAFFNAME">Arrange alphabetically</option>
            <option value="STAFFLOAD">Order by workload</option>
         </select> 
          
         <label for="sortbox" id="sortboxlabel">Sort by:</label>
         <select id="sortbox" onchange="_sortChange(this[this.selectedIndex].value)">
            <option value="NAME">Project name</option>
            <option value="DATE">Project date</option>
            <option value="STATUS" id="sortstatus">Project status</option>
         </select>
                  
         <div id="loaddiv">
            <button id="loadbutton" onclick="_loadClick()">Load</button>
            <select id="loadselect">
               <option value="" id="loadOptionUnstarted">Unstarted</option>
               <option value="Preparation" id="loadOptionSelection">Preparation</option>
               <option value="Attraction" id="loadOptionAttraction">Attraction</option>
               <option value="Finalisation" id="loadOptionReports">Finalisation</option>
               <option value="Completed" id="loadOptionCompleted">Completed</option>
               <option value="ALL">ALL</option>
            </select>
         </div>
         
         <button id="lockButton" class="lockOff" onclick="_toggleLock(this)">UNIQUE SETTINGS</button>
         <button id="clearButton" onclick="_clearSettings()">Reset</button>
         
         <div id="displayoptions">
            <div class="checkcontainer1" id="displayolddiv">
               <input type="checkbox" name="displaycheckboxes" value="2" id="displayold" class="check" onclick="_displayOptionsClick(this.value)"/>
               <label for="displayold">Show previous state</label>
            </div>
            <div class="checkcontainer1">
               <input type="checkbox" name="displaycheckboxes" value="1" id="displaycons" class="check" onclick="_displayOptionsClick(this.value)"/>
               <label for="displaycons">Show consultants</label>
            </div>
            <div class="checkcontainer1" id="displaystatsdiv">
               <input type="checkbox" name="displaycheckboxes" value="3" id="displaystats" class="check" onclick="_displayOptionsClick(this.value)"/>
               <label for="displaystats">Show call stats</label>
            </div>
            <div class="checkcontainer1">
               <input type="checkbox" name="displaycheckboxes" value="0" id="displaycoord" class="check" onclick="_displayOptionsClick(this.value)"/>
               <label for="displaycoord">Show coordinators</label>
            </div>
         </div>
         <div id="hideunknownscontainer">
            <input type="checkbox" name="displaycheckboxes2" value="1" id="hideunknowns" class="check" onclick="_display();"/>
            <label for="hideunknowns">Hide ??s</label>
         </div>
         <div id="hidezeroscontainer">
            <input type="checkbox" name="displaycheckboxes2" value="1" id="hidezeros" class="check" onclick="_display();"/>
            <label for="hidezeros">Hide 0 boxes</label>
         </div>
         
         <div id="statusfilter">
            <div class="checkcontainer2">
               <input type="checkbox" name="statuscheckboxes" value="" id="unstartedfilter" class="check" onclick="_statusFilterClick(this.value)"/>
               <label for="unstartedfilter">Unstarted</label>
            </div>
            <div class="checkcontainer2">
               <input type="checkbox" name="statuscheckboxes" value="Preparation" id="selectionfilter" class="check" onclick="_statusFilterClick(this.value)"/>
               <label for="selectionfilter">Preparation</label>
            </div>
            <div class="checkcontainer2">
               <input type="checkbox" name="statuscheckboxes" value="Attraction" id="attractionfilter" class="check" onclick="_statusFilterClick(this.value)"/>
               <label for="attractionfilter">Attraction</label>
            </div>
            <div class="checkcontainer2">
               <input type="checkbox" name="statuscheckboxes" value="Finalisation" id="reportsfilter" class="check" onclick="_statusFilterClick(this.value)"/>
               <label for="reportsfilter">Finalisation</label>
            </div>
            <div class="checkcontainer2">
               <input type="checkbox" name="statuscheckboxes" value="Completed" id="completedfilter" class="check" onclick="_statusFilterClick(this.value)"/>
               <label for="completedfilter">Completed</label>
            </div>
            <div class="checkcontainer2">
               <input type="checkbox" name="statuscheckboxes" value="ALL" id="allstatusesfilter" class="check" onclick="_statusFilterClick(this.value)"/>
               <label for="allstatusesfilter" class="bold">All</label>
            </div>
         </div>
         <div id="otherfilters">
            <div class="ofilterdiv">
               <select id="constypefilter" class="ofilterbox" onclick="_filterConsType()">
                  <option value="ALL">ALL</option>
                  <option value="EXEC">EXECUTIVE</option>
                  <option value="NONEXEC">NON-EXEC</option>
               </select>
               <label for="consfilter" class="ofilterlabel">Consultant:</label>
               <select id="consfilter" class="ofilterbox" onclick="_filterCons(parseInt(this[this.selectedIndex].value))">
                  <option value="-1">ALL</option></select>
            </div>
            <div class="ofilterdiv">
               <label for="coordfilter" class="ofilterlabel">Coordinator:</label>
               <select id="coordfilter" class="ofilterbox" onclick="_filterCoord(parseInt(this[this.selectedIndex].value))">
                  <option value="-1">ALL</option></select>
            </div>
            <div class="ofilterdiv">
               <label for="datefilter" class="ofilterlabel">From date:</label>
               <select id="datefilter" class="ofilterbox" onclick="_filterDate(parseInt(this[this.selectedIndex].value))">
                  <option value="120101">Jan 12</option><option value="120601">Jun 12</option></select>
            </div>
         </div>
         <div id="logo"></div>
         <div id="bufferdiv"></div>
      </div>
      <div id="listcontainer"></div>
      <div id="detailcontainer"></div>
      <div id="organisercontainer"></div>
      <script type="text/javascript">
         solveBlogs = <?php echo json_encode($data); ?>;
         //alert(solveBlogs.toSource());
         for (var i=0;i<solveBlogs.length;i++) {
            var code=solveBlogs[i][ASSIGNEDTO_CODE];
            var found=-1;
            for (var j=0;j<GBstaff.length && found==-1;j++) {
               if (code==GBstaff[j][CONSCODE]) found=j;
            }
            if (found!=-1) solveBlogs[i][ASSIGNEDTO]=GBstaff[found][CONSNAME];
            solveCompanies.push(new Array());
            solveStats.push(new Array());
            solveBlogs[i].push(BLOGNOTLOADED);
            solveBlogs[i].push(isNOTLOADING);
            solveBlogs[i].push(0);
         }
         var coordSel=document.getElementById("coordfilter");
         var consSel=document.getElementById("consfilter");
         for (var i=0;i<GBstaff.length;i++) {
            if (GBstaff[i][CONSTYPE]==ISBOTH || GBstaff[i][CONSTYPE]==ISCOORD) _addOption(coordSel,GBstaff[i][CONSNAMESHORT],i);
            if (GBstaff[i][CONSTYPE]==ISBOTH || GBstaff[i][CONSTYPE]==ISCONS) _addOption(consSel,GBstaff[i][CONSNAMESHORT],i);
         }
         _defaultSettings();
         _display();  
         // ----------------------------------------------- notes -----------------------------------------------------------
         /*
               enable CLEAR button, GENERATE action, EDIT action, DELETE action
               rename selection->preparation, attraction->calling
               add DEADLINES for profile,selection,calling{1st calls,2nd call},meeting plan,final report + MEETING WEEK
               in detail view - all deadlines shown for this stage and future stages; meeting week still shown for completed?
               in organiser view - just for current stage
               NEED to be able to set these in EDIT mode, but auto-set for new blogs (e.g. 1 week for profile,selection)
               HELPERs are required - add. select + calling
               FILTER for blog type - EXPORT or MARKETING (or ALL)   -----> need to add field to Solve
               add "expand full" option in organiser view (height:100% for projectlistdivs - define different class?)
               ERROR CHECKING for blog statuses - make ERRORS as separate blog files, so can see original status
                  if MP and FR uploaded & not completed OR BLOGDATE<4 months ago - ERROR_COMPLETED
                  else if MP or FR uploaded & not reports - ERROR_REPORTS
                  else if company count>0 or profile uploaded & = unstarted - ERROR_SELECTION
                  if =SELECTION/ERROR_SELECTION & BLOGDATE<1 month ago - ERROR_ATTRACTION
               => create a new Error? option for status filter (new tickbox, enabled only if errors exist)
                  can be corrected in edit mode - if status changed from unstarted/selection to attraction/report/completed, reload!
                  SHIFT-click in DETAIL MODE to go to EDIT MODE
                  auto generate DATE filter (this month, last month, 2 months ago, ... 6 months ago, start of year, previous year, ...
                     ------ if THISMONTH<=7, start of year is omitted
                  
                  light yello #ffff99
[15:02:28] Swede: green light #a2d800
                  
                  
         */       
      </script>
   </body>
</html> 