/** * @author Peter Alexandersson */function ForumList(settings){		this.instanceId = ForumList.instances.length;	this.strRef = 'ForumList.instances[' + this.instanceId + ']';	ForumList.instances[this.instanceId] = this;}//Class static membersForumList.instances = new Array();ForumList.eventStack = new Array();function WebForum(settings){	//call super class	ForumList.call(this, settings);	this.init(settings);	}WebForum.prototype={	//PROPERTIES =========================================================================================	className:'WebForum',					//Used by debug alert	dbUrl:'',								//Url used by ajax request	contentDiv:'',							//Target div/span id where the forum will appear	popupDiv:'forumpopup',					//default div/span id where the forum popups will appear	category:'',							//Filter on category,'' means all categories	listMode:'T',							//How responses should be displayed T=Threaded, D=strickly after date created	listStyle:'table',						//Table or list	currentStart:0,							//which row in servers resultset that we currently display	totalCount:0,							//total number of matching records in servers resultset	sortOrder:'D',							//Sort order in view. Valid values are (D)esc, (A)sc	showSubject:1,							//Should attribute be displayed. 0=Not displayed, 1=Displayed	showContent:1,							//Should attribute be displayed. 0=Not displayed, 1=Displayed	showBody:1,								//Should content+image be displayed. 0=Not displayed, 1=Displayed	showNavigator:1,						//Should attribute be displayed. 0=Not displayed, 1=Displayed	showSearchBox:0,						//Should attribute be displayed. 0=Not displayed, 1=Displayed	maxSearchResult:100,					//max records returned from a search	showReplyLink:1,						//Should attribute be displayed. 0=Not displayed, 1=Displayed	showNotifyLink:1,						//Should attribute be displayed. 0=Not displayed, 1=Displayed	notifymessage:'Ett anm\u00E4lan har nu l\u00E4mnats hos ansvarig personal!', //Response message when a notify been sent	showDate:1,								//Should attribute be displayed. 0=Not displayed, 1=Displayed	showTime:1,								//Should attribute be displayed. 0=Not displayed, 1=Displayed	showAuthor:0,							//Should attribute be displayed. 0=Not displayed, 1=Displayed	showAlias:1,							//Should attribute be displayed. 0=Not displayed, 1=Displayed	showImage:1,							//Should attribute be displayed. 0=Not displayed, 1=Displayed	numberOfGenericFields:0,				//Number of generic data fields to display	generic1Label:'',							//Generic data field label	generic2Label:'',			  				//Generic data field label	generic3Label:'',							//Generic data field label	generic4Label:'',							//Generic data field label	generic5Label:'',							//Generic data field label	sendMailOnNewPostFlag:1,				//Should a flag be set on new posts, that can be picked up by a scheduled 'mail-list-of-new-docs' procedure. 0=No, 1=Yes	imgMaxWidth:100,						//Max image width, if set to zero, the original image size is used.	imgAttribute:'',						//Additional attribute for embedded topic images, e.i: 'align="left"'	imgClassName:'forumimage',				//Default forum image class name	linesToDisplay:10,						//Max number of main topics that we will try to fetch	postRenderCall:null,					//Custom function to call after a render operation has occurred	debugLevel:0,							//WSelects debug mode. 0=Off, 1=On, but no alerts, 2=On, with alerts	debugDiv:'debuginfo',					//Debug div/span id where the debug info will appear	labelAlias:'<span class="forumresponselabel">Namn</span>',						//Label used in response form	labelComment:'<span class="forumresponselabel">Kommentar</span>',				//Label used in response form 	labelMandentory:'<span class="forumasterix">*</span>',							//Label used in response form 	labelFormTitle:'<div class="forumformtitle">Din kommentar:</div>',			//Label used in response form 	labelNotifyFormTitle:'<div class="forumformtitle">Anm\u00E4lan av inl\u00E4gg</div>',			//Label used in notify form 	labelNotifyComment:'<span class="forumresponselabel">Anledning till anm\u00E4lan</span>',			//Label used in notify form 	lastAction:null,						//Last WebEvent issued	lastRequestString:'',					//Last AJAX request	lastResponseString:'',					//Last AJAX response	searchVal:'ange s\u00F6kord',				//default search value	drawOptions: {atall:true,searchfield:true,first:true,previous:false,next:false,last:false}, //styr visning av navigator	//METHODS =============================================================================================	//===== used to initialize the forum	init:function(settings){						if (settings){			if (settings.postRenderCall) this.postRenderCall=settings.postRenderCall;			if (settings.dbUrl) this.dbUrl=settings.dbUrl;			if (settings.sortOrder) this.sortOrder=settings.sortOrder; 			if (settings.contentDiv) this.contentDiv=settings.contentDiv;			if (settings.category) this.category=settings.category;			if (settings.listMode) this.listMode=settings.listMode;			if (settings.numberOfDataFields) this.numberOfDataFields=settings.numberOfDataFields;			if (settings.data1Label) this.data1Label=settings.data1Label;			if (settings.data2Label) this.data2Label=settings.data2Label;			if (settings.data3Label) this.data3Label=settings.data3Label;			if (settings.data4Label) this.data4Label=settings.data4Label;			if (settings.data5Label) this.data5Label=settings.data5Label;			if (settings.sendMailOnNewPostFlag!=null) this.sendMailOnNewPostFlag=settings.sendMailOnNewPostFlag; 			if (settings.showSubject!=null) this.showSubject=settings.showSubject; 			if (settings.showContent!=null) this.showContent=settings.showContent; 			if (settings.showBody!=null) this.showBody=settings.showBody; 			if (settings.showNavigator!=null) this.showNavigator=settings.showNavigator; 			if (settings.showSearchBox!=null) this.showSearchBox=settings.showSearchBox; 			if (settings.showReplyLink!=null) this.showReplyLink=settings.showReplyLink; 			if (settings.showNotifyLink!=null) this.showNotifyLink=settings.showNotifyLink; 			if (settings.showDate!=null) this.showDate=settings.showDate; 			if (settings.showTime!=null) this.showTime =settings.showTime;			if (settings.showAuthor!=null) this.showAuthor =settings.showAuthor; 			if (settings.showAlias!=null) this.showAlias =settings.showAlias; 			if (settings.showImage!=null) this.showImage =settings.showImage; 			if (settings.linesToDisplay) this.linesToDisplay=settings.linesToDisplay;			if (settings.debugLevel!=null) this.debugLevel=settings.debugLevel; 			if (settings.debugDiv) this.debugDiv=settings.debugDiv; 		}		},	//===== Used to send an Ajax request to server to get data	sendRequest:function(webEvent){					if (this.debugLevel==2) alert(this.className+'.sendRequest()');		var pars;		var ajaxreq;		var agentused;		var fetchObject;		var targetDiv = this.contentDiv;		//verify that we have an event		if (webEvent){			switch(webEvent.type){				case WebEvent.EVT_DO_POST_RESPONSE:		//post response event					targetDiv = webEvent.targetString;				case WebEvent.EVT_DO_POST:		//post main topic event					//agentused = 'forumController';					pars = "task=post&mailflag="+ this.sendMailOnNewPostFlag + webEvent.dataString;					//alert('pars: '+ pars);					//ajaxreq = {method:'get', onSuccess:new Function('data', 'ForumList.instances['+this.instanceId+'].recieveData(data)'), parameters: pars, onFailure:this.handleError };					break;				case WebEvent.EVT_DO_POST_NOTIFY:		//post notify event					//agentused = 'forumController';					pars = "task=notify"+ webEvent.dataString;					//alert('pars: '+ pars);					//ajaxreq = {method:'get', onSuccess:new Function('data', 'ForumList.instances['+this.instanceId+'].recieveData(data)'), parameters: pars, onFailure:this.handleError };					break;				case WebEvent.EVT_DO_SEARCH:	//fulltext search event 					fetchObject = webEvent.fetchObject;					//agentused = 'forumController';					//pars = "&task=search&cat="+this.category+"&list="+this.listMode +"&start="+fetchObject.start+"&count="+fetchObject.count + "&key="+webEvent.dataString;					pars = "task=search&cat="+this.category+"&list="+this.listMode +"&start="+fetchObject.start+"&count="+ this.maxSearchResult+ "&key="+webEvent.dataString;					//ajaxreq = {method:'get', onSuccess:new Function('data', 'ForumList.instances['+this.instanceId+'].recieveData(data)'), parameters: pars, onFailure:this.handleError };					break;				case WebEvent.EVT_GET_RESPONSES:	//get responses					fetchObject = webEvent.fetchObject;					//agentused = 'forumController';					targetDiv = webEvent.dataString;					pars = "&task=response&cat="+webEvent.dataString +"&reqid="+webEvent.dataString+"&list="+this.listMode +"&start="+fetchObject.start+"&count="+fetchObject.count;					//pars = "task=response&reqid="+webEvent.dataString+"&list="+this.listMode +"&start="+fetchObject.start+"&count="+fetchObject.count;					//ajaxreq = {method:'get', onSuccess:new Function('data', 'ForumList.instances['+this.instanceId+'].recieveData(data)'), parameters: pars, onFailure:this.handleError };					break;				default:						//assumes its a navigation event					fetchObject = webEvent.fetchObject;					//agentused = 'forumController'					//pars = "&task=main&cat="+this.category+"&order="+this.sortOrder+"&list="+this.listMode +"&start="+fetchObject.start+"&count="+fetchObject.count;					pars = "task=main&cat="+this.category+"&order="+this.sortOrder+"&list="+this.listMode +"&start="+fetchObject.start+"&count="+fetchObject.count;					//ajaxreq = {method:'get', onSuccess:new Function('data', 'ForumList.instances['+this.instanceId+'].recieveData(data)'), parameters: pars, onFailure:this.handleError };			}		} else {			alert(this.className+'.sendRequest: Missing a valid event object.' );			return;		}		//send request to server		try{			this.lastRequestString = pars;			agentused = 'forumController';			var url = this.dbUrl+'/' + agentused +'?OpenAgent';			//alert(url);			if (typeof jQuery != 'undefined') {        		// use jQuery style call				//jQuery.noConflict();				ajaxreq = {type: "GET",url: url, data: pars, success: new Function('data', 'ForumList.instances['+this.instanceId+'].recieveData(data)')	 }				//ajaxreq = {method:'get', onSuccess:new Function('data', 'ForumList.instances['+this.instanceId+'].recieveData(data)'), parameters: pars, onFailure:this.handleError };				//this.lastRequest = jQuery.ajax(ajaxreq);				this.lastRequest = $.ajax(ajaxreq);							} else {				//assume prototype.js style call				ajaxreq = {method:'get', onSuccess:new Function('data', 'ForumList.instances['+this.instanceId+'].recieveData(data)'), parameters: pars, onFailure:this.handleError };				this.lastRequest = new Ajax.Request(url, ajaxreq);			}		}catch (e){			alert('Kommunikationsproblem med server: ' + e.message + '\nParams: ' + pars);			location.reload();		}		//show progress icon unless it is a notify posting		if (webEvent.type!=WebEvent.EVT_DO_POST_NOTIFY){			document.getElementById(targetDiv).innerHTML = '<img src="'+this.dbUrl+'/img/indicator.gif">';		}	},	//===== Callback method for Ajax communication errors	handleError:function(){							if (this.debugLevel==2) alert(this.className+'.handleError()');		alert('Kommunikationsfel - F\u00E5r ej svar fr\u00E5n AJAX server.')	},	//===== Callback method for successfull Ajax response	recieveData:function(originalRequest){		var responseText;		if (this.debugLevel==2) alert(this.className+'.recieveData()');		//document.getElementById(this.contentDiv).innerHTML = 'Data recieved!';		//		if (typeof originalRequest == 'object'){			responseText = originalRequest.responseText;		}else{			responseText = originalRequest;		}		//alert('recieveData:' + responseText);		this.lastResponseString = responseText;		if (this.debugLevel>0){			this.printDebug();		}		var jsondata;		try{			jsondata = eval('(' + responseText + ')')		}catch(e){			//alert('catch:' + originalRequest.Status + e.message);			if (responseText.substring(0,1)=="<"){				//no JSON object, assumes an html page, probably logged out				location.reload(true);			} else {				//something wrong in the viewdata				alert('Problem with view data:' + e.message);			}		}			if (jsondata){			switch(jsondata.task){				case 'post':					if (jsondata.parentunid==''){						//main topic - refresh						this.handleMainSubmit(jsondata);					} else {						//response topic - only refresh the reponse list						this.handleResponseSubmit(jsondata);					}					break;				case 'notify':					alert(this.notifymessage);					break;				default:					//a normal view/list response/search result					if (jsondata.task=='search'&& jsondata.countdelivered==0){						alert('Inget i databasen motsvarade din s\u00F6kning!');						this.firstClicked();					}					//alert('going to render:' + originalRequest.responseText);					var dh = new WebDataHolder( {data:jsondata} );					dh.setStart(jsondata.start);					dh.setTotalCount(jsondata.total);					dh.setResultCount(jsondata.countdelivered);					this.calcRedraw(dh,true);					this.render(jsondata);;			}		}			},	//===== Render the forum view data to HTML code	render:function(view){							if (this.debugLevel==2) alert(this.className+'.render()');		var html='';		var isResponseList = false;		var targetDiv = this.contentDiv;		if (!view){			html = 'Invalid data:'+ this.toString(view);			document.getElementById(this.contentDiv).innerHTML = html;			return false;		} 		if (view.error) {			alert(' view_error');			this.show_error(view.error);		}		//check if other than default target is to be used, e.i response list update		if (view.reqid!='' && view.reqid!='null') isResponseList = true;		//build the table		//var tablewidth = document.getElementById(this.contentDiv).clientWidth - 10;		var tablewidth = "100%";		var html_header;		var html_footer;		var html_mainrecstart;		var html_mainrecend;		if (this.listStyle=='list'){			html_header='<ul class="forumlist">';			html_footer='</ul>';			html_mainrecstart='<li>';			html_mainrecend='</li>';		} else {			html_header='<table width="' + tablewidth + '" border="0" class="forumtable">';			html_footer='</table>';			html_mainrecstart='<tr><td valign="top">';			html_mainrecend='</td></tr>';		}		//alert('debug:' + view.total);		if (view.total > 0){			//print entries			//process all entries in view			try{				var processedResponses = false;				for (var entryidx=0; entryidx<view.entries.length; entryidx++){					//alert('Inside renderData: '+entryidx + '-'+view.entries.length);					var entry =view.entries[entryidx];					if (!entry._unid){return}; //no document=must be end of the view					var strUnid =entry._unid;					var strUrl = this.dbUrl+'/vunid/'+ strUnid +'?OpenDocument' ;					var strTopicId = entry.columns[0];					var strSubject = entry.columns[1];					var strSubjectLink = '<a href="#" class="forumtopiclink" title="Klicka f\u00F6r att \u00F6ppna i eget f\u00F6nster..." onclick="WebForum.openWindow(\''+ strUrl+'\',\'wnd'+strUnid+'\',640,480)">' + strSubject +'</a>'					var strContent = entry.columns[2];					var strAuthor = entry.columns[3];					var strAlias = entry.columns[4];					var strDate = entry.columns[5];					var strTime = entry.columns[6];					var strIsResponse = entry.columns[7];					var strParentUnid = entry.columns[8];					if (strIsResponse !='true') strParentUnid = strUnid;					var strFile = entry.columns[9];					var strData1 = entry.columns[11];					var strData2 = entry.columns[12];					var strData3 = entry.columns[13];					var strData4 = entry.columns[14];					var strData5 = entry.columns[15];					var strImageUrl = (strFile==''||strFile==undefined)?'':this.dbUrl+'/vunid/'+ strUnid +'/$File/'+strFile+'?OpenElement' ;					//var strResponseDiv = strUnid.substr(-8,8);					var strToggle = '<a href="#" class="forumtoggle" title="Visa eller d\u00F6lj ev. svar p\u00E5 inl\u00E4gget." onclick="ForumList.instances['+this.instanceId+'].toggleDisplay(\''+ strUnid + '\',false);return false;" ><img src="'+this.dbUrl+'/img/plus.gif" id="img'+strUnid +'" align="top" border="0"></a>';					if (this.listMode!='T') strToggle='';					//check if other than default target is to be used, e.i response list update					if (isResponseList){						//response list rendering. Updates a div with the same id as the parent UNID.						html+= '  <div class="forumresponse">' ;						html+= '     <div class="forumsubject">'+ strSubjectLink + '<div class="forumtopictoolbar">';						html+= this.getReplyLinkHtml(strParentUnid,strSubject,view);						html+= this.getNotifyLinkHtml(strParentUnid,strTopicId,strSubject);						html+= ' </div></div>';						html+= this.getTopicBodyHtml(strContent,strAuthor,strAlias,strDate,strTime,strIsResponse,strImageUrl);						html+= this.getTopicGenericDataHtml(strData1,strData2,strData3,strData4,strData5);						html+= '  </div>  <!-- close response -->' ;					} else {						//normal rendering						html+= html_mainrecstart;						html+= '  <div class="forumtopic">' ;						html+= '     <div class="forumsubject">'+ strToggle +' '+ strSubjectLink + '<div class="forumtopictoolbar">';						//html+= this.getReplyLinkHtml(strUnid,strSubject);						html+= this.getReplyLinkHtml(strParentUnid,strSubject,view);						html+= this.getNotifyLinkHtml(strParentUnid,strTopicId,strSubject);						html+= '</div></div>';						html+= this.getTopicBodyHtml(strContent,strAuthor,strAlias,strDate,strTime,strIsResponse,strImageUrl);						html+= this.getTopicGenericDataHtml(strData1,strData2,strData3,strData4,strData5);						html+= '  <div class="forumresponslist" id="'+ strUnid + '" style="display:none;"></div>';						html+= '  </div> <!-- close topic -->';						html+= html_mainrecend					}																	} //end for-loop			} catch(e){ alert(e.message)}		} //end view.total		else {			if (isResponseList)	html = '<div class="forumresponse"><p class="forum_nodata">Det finns inga kommentarer till detta inl\u00E4gg.</p></div>';			else	html = '<div class="forumtopic"><p class="forum_nodata">Ingen data finns att visa.</p></div>'					}		//alert('html:' + html);		//update contentDiv		if (isResponseList){			targetDiv = view.reqid;			document.getElementById(targetDiv).innerHTML = html;		} else {			var navDiv = '<div class="forumnavigator">' + this.getNavHtml(this.drawOptions, view) + '</div>';			var popupDiv = '<div id="'+ this.popupDiv +'" class="hiddenResponseForm" ></div>';			document.getElementById(targetDiv).innerHTML = html_header + '<tbody id="table-view-body">' + html+ '</tbody>' + html_footer + navDiv+popupDiv;		}						//perform any post render call		try{			//alert('postRenderCall: '+ this.postRenderCall)			if (this.postRenderCall) this.postRenderCall();		} catch(e){}		//return status		return true;					},	//===== Resends the last request to server	refresh:function(){								if (this.debugLevel==2) alert(this.className+'.refresh()');		//check if first time its called		if (this.lastAction==null){			this.firstClicked();		} else {			this.sendRequest(this.lastAction);		}			},	//===== Generates a reply link html code	getReplyLinkHtml:function(strParentUnid, strSubject, jsondata){		if (this.listMode!='T' || jsondata.task=='search') return ''; //only display replylink if Threaded view		var url='';		var rethtml='';		if (this.showReplyLink){			url = this.dbUrl+'/ForumResponseTopic?openform&parentunid='+strParentUnid + '&subject='+escape( strSubject );			rethtml+= '&nbsp;<a href="#" onclick="ForumList.instances['+this.instanceId+'].showResponseForm(\''+strParentUnid + '\',event);return false;" class="forumreplylink">'			rethtml+= '<img src="'+this.dbUrl+'/newtopic1.gif" border="0" title="Svara p\u00E5 inl\u00E4gg">'			rethtml+= '</a>'		}		return rethtml;	},	//===== Generates a notify link html code	getNotifyLinkHtml:function(strParentUnid,strTopicId, strSubject){		var rethtml='';		if (this.showNotifyLink){			//rethtml+= '&nbsp;<a href="#" onclick="alert(\'Ej implementerat \u00E4n!\')" class="forumnotifylink">'			rethtml+= '&nbsp;<a href="#" onclick="ForumList.instances['+this.instanceId+'].showNotifyForm(\''+strParentUnid + '\',\''+strTopicId + '\',\''+escape(strSubject) + '\',event);return false;" class="forumreplylink">'			rethtml+= '<img src="'+this.dbUrl+'/exclamation.gif" border="0" title="Anm\u00E4l inl\u00E4gget!">'			rethtml+= '</a>'		}		return rethtml;	},	//===== Navigation - Get first page	firstClicked:function(htmlElem){				if (this.debugLevel==2) alert(this.className+'.firstClicked()');		var fetchObj = this.calcRange(WebEvent.EVT_GET_FIRST);		var navEvent= new WebEvent({type:WebEvent.EVT_GET_FIRST,fetchObject:fetchObj,srcObject:this});		this.lastAction = navEvent;		this.sendRequest(navEvent);	},	//===== Navigation - Get next page	nextClicked:function(){							if (this.debugLevel==2) alert(this.className+'.nextClicked()');		var fetchObj = this.calcRange(WebEvent.EVT_GET_NEXT);		var navEvent=new WebEvent({type:WebEvent.EVT_GET_NEXT,fetchObject:fetchObj,srcObject:this});		this.lastAction = navEvent;		this.sendRequest(navEvent);	},	//===== Navigation - Get previous page	previousClicked:function(){						if (this.debugLevel==2) alert(this.className+'.previousClicked()');		var fetchObj = this.calcRange(WebEvent.EVT_GET_PREVIOUS);		var navEvent=new WebEvent({type:WebEvent.EVT_GET_PREVIOUS,fetchObject:fetchObj,srcObject:this});		this.lastAction = navEvent;		this.sendRequest(navEvent);	},	//===== Navigation - Get last page	lastClicked:function(){							if (this.debugLevel==2) alert(this.className+'.lastClicked()');		var fetchObj = this.calcRange(WebEvent.EVT_GET_LAST);		var navEvent=new WebEvent({type:WebEvent.EVT_GET_LAST,fetchObject:fetchObj,srcObject:this});		this.lastAction = navEvent;		this.sendRequest(navEvent);	},	//===== Fetch responses - Get all responses ============================================	getResponsesClicked:function(unidToParent){							if (this.debugLevel==2) alert(this.className+'.getResponsesClicked("'+ unidToParent +'"');		var fetchObj = new WebFetchObject({start:1,end:999,count:999});		var navEvent=new WebEvent({type:WebEvent.EVT_GET_RESPONSES,dataString:unidToParent,fetchObject:fetchObj,srcObject:this});		this.lastAction = navEvent;		this.sendRequest(navEvent);	},	//===== Submit a topic	submitTopic:function(strPostData, unidToParent){							if (this.debugLevel==2) alert(this.className+'.post("'+ strPostData +'","'+ unidToParent +'"');		var navEvent;		if (unidToParent!=''){			strPostData += '&parentunid='+ unidToParent;			navEvent=new WebEvent({type:WebEvent.EVT_DO_POST_RESPONSE,targetString:unidToParent,dataString:strPostData,fetchObject:null,srcObject:this});		} else {			navEvent=new WebEvent({type:WebEvent.EVT_DO_POST,dataString:strPostData,fetchObject:null,srcObject:this});		}		//this.lastAction = navEvent; //we don't want do resend a posting...		this.sendRequest(navEvent);	},	//===== Submit a notify	submitNotify:function(strPostData, unidToParent){							if (this.debugLevel==2) alert(this.className+'.post("'+ strPostData +'","'+ unidToParent +'"');		var navEvent;		if (unidToParent!=''){			strPostData += '&parentunid='+ unidToParent;		}		navEvent=new WebEvent({type:WebEvent.EVT_DO_POST_NOTIFY,targetString:unidToParent,dataString:strPostData,fetchObject:null,srcObject:this});		//this.lastAction = navEvent; //we don't want do resend a posting...		this.sendRequest(navEvent);	},	//===== Do a search view	searchTriggered:function(e,srcElem){		    var keynum;			try{			if(window.event) keynum = e.keyCode; // IE			else if(e.which) keynum = e.which; // Netscape/Firefox/Opera  			if(keynum==13){				this.searchVal = (srcElem.value !=null) ? (srcElem.value):'' ;					if (this.debugLevel==2)alert(this.className+'.searchTriggered:' + this.searchVal);					var fo = new WebFetchObject({start:1,end:this.linesToDisplay,count:this.linesToDisplay});					var navEvent=new WebEvent({type:WebEvent.EVT_DO_SEARCH,dataString:this.searchVal,srcObject:this,fetchObject:fo});					this.lastAction = navEvent;					this.sendRequest(navEvent);					srcElem.value = '';			}			} catch (e){			alert('Error: '+ e.message);		}	},	calcRedraw:function(resObj, success){		//alert('in calc redraw');				var type = 	(this.lastAction) ? this.lastAction.type : WebEvent.EVT_GET_FIRST; 					switch(type){				case WebEvent.EVT_GET_FIRST:				case WebEvent.EVT_GET_PREVIOUS:				case WebEvent.EVT_GET_NEXT:				case WebEvent.EVT_GET_LAST:				case WebEvent.EVT_DO_SEARCH:					//alert('in calcRedraw get first ');					//alert('totalCount before = ' + this.totalCount + ', currentStart before = ' + this.currentStart + ', currentEnd before = ' + this.currentEnd);					if(this.lastAction){						//alert('lastAction fetchobject.start = ' + this.lastAction.fetchObject.start);					}					//set max					this.totalCount = (resObj) ? resObj.totalCount : this.totalCount;					//set cStart					//this.currentStart = (this.lastAction) ? this.lastAction.fetchObject.start :1;					this.currentStart = (resObj.start) ? resObj.start : 1;					//set cEnd					//this.currentEnd = (this.lastAction) ? this.lastAction.fetchObject.end : ((resObj) ? resObj.count :this.linesToDisplay); 					this.currentEnd = (resObj.start) ? (resObj.start + resObj.count)-1 :this.linesToDisplay; 					//draw navigator					//alert('totalCount after = ' + this.totalCount + ', currentStart after = ' + this.currentStart + ', currentEnd after = ' + this.currentEnd);										this.drawOptions.previous = this.drawOptions.first = (!(this.currentStart <= 1));					this.drawOptions.next = this.drawOptions.last = (!(this.currentEnd >= this.totalCount));										//this.draw();					break;				default:					break;			}				},		calcRange:function(action){		var retObj = new WebFetchObject({});				//alert('1. PRIOR CALC: fetchObject in Navaigator currentStart = ' + this.currentStart + ',linesToDisplay = ' + this.linesToDisplay+ ',totalCount = ' + this.totalCount);		switch(action){			case WebEvent.EVT_GET_FIRST:				retObj.start = 1;				//retObj.end = Math.min(retObj.start + this.linesToDisplay -1, this.totalCount);				retObj.end = this.linesToDisplay;				retObj.count = this.linesToDisplay; 				break;			case WebEvent.EVT_GET_PREVIOUS:				retObj.start = Math.max(1,this.currentStart - this.linesToDisplay);				retObj.end = Math.min(retObj.start + this.linesToDisplay - 1, this.totalCount)				retObj.count = this.linesToDisplay; 				break;			case WebEvent.EVT_GET_NEXT:				retObj.start = Math.min(this.currentStart + this.linesToDisplay, this.totalCount);				retObj.end = Math.min(retObj.start + this.linesToDisplay - 1, this.totalCount);				retObj.count = Math.min((this.totalCount-retObj.start)+1, this.linesToDisplay); 				break;			case WebEvent.EVT_GET_LAST:				retObj.start = Math.max(1, this.totalCount - this.linesToDisplay + 1);				retObj.end = this.totalCount;				retObj.count = Math.min((this.totalCount-retObj.start)+1, this.linesToDisplay); 				break;			default:				break;		}				return retObj;		  	},	//===== Generates the html code for a topic entry	getTopicBodyHtml:function(strContent,strAuthor,strAlias,strDate,strTime,strIsResponse,strImageUrl){		var imgtag='';		var mozMinHeight=''; //fix for handling images flowing over to topic below		var retHtml='     <p>';		if (this.showImage){			if (strImageUrl!=''){				var x=new Image;				var scalefactor;				var ih;				var imgstyle;				x.src=strImageUrl;				if (this.imgMaxWidth!=0){					//adjust image size					scalefactor=x.width/this.imgMaxWidth;					ih=x.height/scalefactor;					imgstyle ='style="height:'+ ih +'px;width:'+ this.imgMaxWidth +'px;"';				}else{					//use actual size					ih=x.height;				}				mozMinHeight='min-height:'+ih+ 'px';				imgtag ='<img src="'+ strImageUrl+ '" class="'+ this.imgClassName+ '" '+ imgstyle+ ' '+ this.imgAttribute +' />';			}		} 		if (this.showDate) retHtml+= '     <span class="forumdate">'+ strDate + ' ' + strTime + '</span>';		if (this.showAuthor) retHtml+= '     <span class="forumauthor">'+ strAuthor+ '</span>';		if (this.showAlias) retHtml+= '     <span class="forumalias">av \''+ strAlias+ '\'</span>';		retHtml+= '     </p>';		if (!this.showContent) strContent=''; //clear content string if not to be displayed		if (this.showBody) retHtml+= '     <p class="forumcontent" style="'+mozMinHeight+'">'+imgtag+  strContent + '</p>';		return retHtml;	},	//===== Generates the html code for a topic entry	getTopicGenericDataHtml:function(strData1,strData2,strData3,strData4,strData5){		var retHtml='';		if (this.numberOfGenericFields>0){			retHtml+= '<table width="100%" class="forumgenericdatatable">';			retHtml+= '<tr><td class="forumgenericlabel">' + this.generic1Label + '</td><td class="forumgenericdata">' + strData1 + '</td></tr>';			if (this.numberOfGenericFields>1){				retHtml+= '<tr><td class="forumgenericlabel">' + this.generic2Label + '</td><td class="forumgenericdata">' + strData2 + '</td></tr>';			}			if (this.numberOfGenericFields>2){				retHtml+= '<tr><td class="forumgenericlabel">' + this.generic3Label + '</td><td class="forumgenericdata">' + strData3 + '</td></tr>';			}			if (this.numberOfGenericFields>3){				retHtml+= '<tr><td class="forumgenericlabel">' + this.generic4Label + '</td><td class="forumgenericdata">' + strData4 + '</td></tr>';			}			if (this.numberOfGenericFields>4){				retHtml+= '<tr><td class="forumgenericlabel">' + this.generic5Label + '</td><td class="forumgenericdata">' + strData5 + '</td></tr>';			}			retHtml+= '</table>';		}		return retHtml;	},	//===== Prints dubug information	printDebug:function() {		try{			var divDebug = document.getElementById(this.debugDiv);			var html = '<div id="debugrequest">LAST REQUEST:<br />' + this.lastRequestString + '</div><br />';			html +='<div id="debugresponse">LAST RESPONSE:<br />' + this.getNiceOutput(this.lastResponseString) + '</div>';			divDebug.innerHTML = html;		} catch(e){}	},	//===== converts cr's to html <br>	getNiceOutput:function(str) {		var newstr=''; 		var re = /\r/gi;		newstr = str.replace(re,'<br />');		return newstr;			},	//==== toggle to show responses, if they havent been loaded already the method will do so	toggleDisplay:function(nr, forceReload){		if (this.debugLevel==2) alert(this.className+'.toggleDisplay("'+ nr +'"');		var container;		var linkimg;		try{			//toggle display			if (document.layers)			{				linkimg =document.layers['img'+nr];				container = document.layers[nr];				var current = (document.layers[nr].display == 'none'||forceReload) ? 'block' : 'none';				document.layers[nr].display = current;			}			else if (document.all)			{				linkimg =document.all['img'+nr];				container = document.all[nr];				var current = (document.all[nr].style.display == 'none'||forceReload) ? 'block' : 'none';				document.all[nr].style.display = current;			}			else if (document.getElementById)			{				linkimg =document.getElementById('img'+nr);				container = document.getElementById(nr);				var vista = (document.getElementById(nr).style.display == 'none'||forceReload) ? 'block' : 'none';				document.getElementById(nr).style.display = vista;			}			//toggle image in link						if (linkimg){				//alert(linkimg.src.slice(-8));				if (linkimg.src.slice(-8)=='plus.gif'||forceReload){					linkimg.src=this.dbUrl+'/img/minus.gif';				} 				else linkimg.src=this.dbUrl+'/img/plus.gif';			}			//check if the container contains any data otherwise load response data			if (container.innerHTML==''||forceReload) this.getResponsesClicked(nr);		}		catch(e){}	},	//==== returns html for the navigator	getNavHtml:function(obj, jsondata){		var html='';		if (jsondata.task=='search'){			//we don't show any navigation on search			if (jsondata.countdelivered==this.maxSearchResult) html+='S\u00F6kresultatet har en begr\u00E4nsning p\u00E5 max. ' + this.maxSearchResult + ' poster.<br/>' ;			html+='<a href="#" onclick="location.reload();">Klicka h\u00E4r f\u00F6r att \u00E5terg\u00E5.</a>'			return html;		}		if (this.totalCount>0){			if (this.showNavigator){				//First link				html+= (obj.first) ? '<a href="#" onclick="ForumList.instances['+this.instanceId+'].firstClicked(this);"><img src="'+this.dbUrl+'/first.gif" border="0" title="F\u00F6rsta sidan"></a>&nbsp;' : '<img src="'+this.dbUrl+'/first_disabled.gif" border="0">&nbsp;';				//Previous link				html+= (obj.previous) ? '<a href="#" onclick="ForumList.instances['+this.instanceId+'].previousClicked(this);"><img src="'+this.dbUrl+'/prev.gif" border="0" title="F\u00F6reg\u00E5ende sida"></a>' : '<img src="'+this.dbUrl+'/prev_disabled.gif" border="0">';				//Navigator text getTranslation 				try{					html+= '&nbsp;'  +WebForum.STRING_SHOWING_ENTRIES + '&nbsp;'  + this.currentStart + '&nbsp;' + WebForum.STRING_VIEW_TO+'&nbsp;' + this.currentEnd + '&nbsp;'+WebForum.STRING_VIEW_OF+'&nbsp;' + this.totalCount+'&nbsp;';					//html+= '<span id=\"viewnav_ShowingEntries\"></span>&nbsp;'  + this.currentStart + '&nbsp;<span id="viewnav_To"></span>&nbsp;' + this.currentEnd + '&nbsp;<span id="viewnav_Of"></span>&nbsp;' + this.totalCount;				}catch(e){}				//Next link				html+= (obj.next) ? '<a href="#" onclick="ForumList.instances['+this.instanceId+'].nextClicked(this);"><img src="'+this.dbUrl+'/next.gif" border="0" title="N\u00E4sta sida"></a>' : '<img src="'+this.dbUrl+'/next_disabled.gif" border="0">';				//Last link				html+= (obj.last) ? '&nbsp;<a href="#" onclick="ForumList.instances['+this.instanceId+'].lastClicked(this);"><img src="'+this.dbUrl+'/last.gif" border="0" title="Sista sidan"></a>' : '<img src="'+this.dbUrl+'/last_disabled.gif" border="0">';			}			//Search field			if (this.showSearchBox==1){				var srchbuttons ='';				html+= (obj.searchfield) ? '<div class="forumsearchbox">'+ WebForum.STRING_NAV_SEARCH +'&nbsp;'  +  '<input type="text" class="forum_search_input" id="ForumSearchVal" value="" onkeypress="ForumList.instances['+this.instanceId+'].searchTriggered(event,this)" /></div>' : '<div class="st_nav_no_search"></div>';			}		} else {			html+= '<span id="viewnav_NothingToShow"></span>'		}					return html;	},	//==== returns html for the notify form	showNotifyForm:function(strParentUnid,strTopicId, strSubject, evt){		var html='';		var posX;		var posY;		if(evt.x)posX=evt.x+document.documentElement.scrollLeft;		if (posX==0){			if(evt.pageX)posX=evt.pageX;		}		if(evt.y)posY=evt.y+document.documentElement.scrollTop;		if (posY==0){			if(evt.pageY)posY=evt.pageY;		}		html+='<form method="get" id="notifyform" name="notifyform" action="javascript:ForumList.instances['+this.instanceId+'].validateResponse(\'notifyform\');return false;">';		html+= this.labelNotifyFormTitle;		html+='<table>';		html+='<tr><td>Avser anm\u00E4lan av ['+unescape(strSubject)+']</td></tr>';		html+='<tr><td>'+this.labelAlias+'&nbsp;'+this.labelMandentory+'</td></tr>';		html+='<tr><td><input type="text" id="alias" name="alias" size="40" /></td></tr>';		html+='<tr><td valign="top">'+this.labelNotifyComment+'&nbsp;'+this.labelMandentory+'</td></tr>';		html+='<tr><td valign="top"><textarea id="content" rows="5" cols="30"  name="content" ></textarea></td></tr>';		html+='<tr style="display:none;"><td><input type="text" id="unid" name="unid" value="'+strParentUnid+'" />';		html+='<input type="text" id="topicid" name="topicid" value="'+strTopicId+'" />';		html+='<input type="text" id="subject" name="subject" value="'+strSubject+'" /></td></tr>';		html+='<tr><td>&nbsp;<input type="button" id="saveresponsebutton" value="Spara" onclick="ForumList.instances['+this.instanceId+'].validateResponse(\'notifyform\')" />&nbsp;';		html+='<input type="button" id="cancelresponsebutton" value="Avbryt" onclick="document.getElementById(\''+this.popupDiv+'\').className=\'hiddenResponseForm\';"/></td></tr>';		html+='</table>';		html+='</form>';		try {			var popupDiv = document.getElementById(this.popupDiv);			popupDiv.innerHTML = html;			popupDiv.className = 'visibleResponseForm';			var popupStyle = WebForum.getStyleObject(this.popupDiv);			var w=popupStyle.width;	   		var h=popupStyle.height;			var l;			var t	   		if (!w) w=400;			if (!h) h=280;			if(posX!=0)	l=posX-w;			if(posY!=0)	t=posY-h;			if (l<0 || t<0){				l=200;				t=200;			}			WebForum.moveDiv(this.popupDiv,l,t);		} catch (e){			alert('Ett fel har uppst\u00E5tt i popupDiv: ' + e.message);		}		return true;	},	//==== returns html for the response form	showResponseForm:function(strParentUnid,evt){		var html='';		var posX;		var posY;		if(evt.x)posX=evt.x+document.documentElement.scrollLeft;		if (posX==0){			if(evt.pageX)posX=evt.pageX;		}		if(evt.y)posY=evt.y+document.documentElement.scrollTop;		if (posY==0){			if(evt.pageY)posY=evt.pageY;		}		html+='<form method="get" id="responsform" name="responsform" action="javascript:ForumList.instances['+this.instanceId+'].validateResponse(\'responsform\');return false;">';		html+= this.labelFormTitle;		html+='<table>';		html+='<tr><td>'+this.labelAlias+'&nbsp;'+this.labelMandentory+'</td></tr>';		html+='<tr><td><input type="text" id="alias" name="alias" size="40" /></td></tr>';		html+='<tr><td valign="top">'+this.labelComment+'&nbsp;'+this.labelMandentory+'</td></tr>';		html+='<tr><td valign="top"><textarea id="content" rows="5" cols="30"  name="content" ></textarea></td></tr>';		html+='<tr style="display:none;"><td><input type="text" id="unid" name="unid" value="'+strParentUnid+'" /></td></tr>';		html+='<tr><td><br/>&nbsp;<input type="button" id="saveresponsebutton" value="Spara" onclick="ForumList.instances['+this.instanceId+'].validateResponse(\'responsform\')" />&nbsp;';		html+='<input type="button" id="cancelresponsebutton" value="Avbryt" onclick="document.getElementById(\''+this.popupDiv+'\').className=\'hiddenResponseForm\';"/></td></tr>';		html+='</table>';		html+='</form>';		try {			var popupDiv = document.getElementById(this.popupDiv);			popupDiv.innerHTML = html;			popupDiv.className = 'visibleResponseForm';			var popupStyle = WebForum.getStyleObject(this.popupDiv);			var w=popupStyle.width;	   		var h=popupStyle.height;			var l;			var t	   		if (!w) w=400;			if (!h) h=280;			if(posX!=0)	l=posX-w;			if(posY!=0)	t=posY-h;			if (l<0 || t<0){				l=200;				t=200;			}			WebForum.moveDiv(this.popupDiv,l,t);		} catch (e){			alert('Ett fel har uppst\u00E5tt i popupDiv: ' + e.message);		}		return true;	},	validateResponse:function(frmType){		try{			var f = document.forms[frmType];			if (frmType=='notifyform'){			}			var strAlias = f.alias.value;			var strContent = f.content.value;			var strParentUnid = f.unid.value;			if (strAlias==''||strContent==''){				alert('Obligatoriska uppgifter saknas!\nFyll i dessa uppgifter och f\u00F6rs\u00F6k igen.');				return false;			}			var frmdata = WebForum.getFormData(f);			//alert('this.popupDiv:' + this.popupDiv);			document.getElementById(this.popupDiv).className='hiddenResponseForm';			if (frmType=='notifyform'){				this.submitNotify(frmdata,strParentUnid);			} else{				this.submitTopic(frmdata,strParentUnid);			}			return true;		} catch(e){			alert('Ett fel uppstod vid validering. Felmeddelande:' + e.message);				document.getElementById(this.popupDiv).className='hiddenResponseForm';			return false;		}		return result;	},	//==== returns html for the notify form	getNotifyFormHtml:function(obj){		var html='';					return html;	}		} //end of class WebForum//class constants & static methodsWebForum.STRING_NAV_SEARCH = 'S&ouml;k i forumet';WebForum.STRING_SHOWING_ENTRIES = 'Visar inl\u00E4gg';WebForum.STRING_VIEW_TO = 'till';WebForum.STRING_VIEW_OF = 'av totalt';WebForum.openWindow = function(url,wndname,width,height){		var hwnd=null;		hwnd = window.open(url,wndname,'toolbar=0,menubar=0,resizable=1,width='+ width + ',height=' +height);		hwnd.moveTo(screen.width/2-(width/2),screen.height/2-(height/2));		return hwnd;	}WebForum.getFormData = function(frm){	var formdata='';	try{		for(i=0;i < frm.length;i++){			var strType = frm.elements[i].type.toLowerCase();			var strName = frm.elements[i].name.toLowerCase();			if (strType=='text'||strType=='textarea'||strType=='hidden'){				formdata += '&'+ strName + '=' + encodeURIComponent(frm.elements[i].value);			}			//alert('tag:'+frm.elements[i].tagName +'type:'+frm.elements[i].type + ', name:'+ frm.elements[i].name+ ', value:'+ frm.elements[i].value);		}					return formdata;	} catch(e){		return '';	}}WebForum.getStyleObject = function(objectId) {    // cross-browser function to get an object's style object given its    if(document.getElementById && document.getElementById(objectId)) {	// W3C DOM	return document.getElementById(objectId).style;    } else if (document.all && document.all(objectId)) {	// MSIE 4 DOM	return document.all(objectId).style;    } else if (document.layers && document.layers[objectId]) {	// NN 4 DOM.. note: this won't find nested layers	return document.layers[objectId];    } else {	return false;    }}WebForum.moveDiv = function(objectId, left, top){  var the_style = WebForum.getStyleObject(objectId);  if (document.layers)  {    the_style.left = left;    the_style.top = top;  }  else   {    the_style.left = left + "px";    the_style.top = top + "px";    }}function WebFetchObject(settings){	this.start = (settings.start) ? settings.start : 0;	this.end = (settings.end) ? settings.end : 0;	this.count = (settings.count) ? settings.count : 0;} //==== used to signal eventsfunction WebEvent(settings){	this.type = (settings.type) ? settings.type :0; // type of event one of WebEvent constants	this.dataString = (settings.dataString) ? settings.dataString :null; // the search/post string	this.targetString = (settings.targetString) ? settings.targetString :null; // optional target for event	this.srcObject = (settings.srcObject) ? settings.srcObject :null; // the object that generated the event	this.fetchObject = (settings.fetchObject) ? settings.fetchObject :null; //Data range to request (WebFetchObject)}//Class ConstantsWebEvent.EVT_GET_FIRST = 1;WebEvent.EVT_GET_NEXT = 2;WebEvent.EVT_GET_PREVIOUS = 3;WebEvent.EVT_GET_LAST = 4;WebEvent.EVT_DO_SEARCH = 5;WebEvent.EVT_GET_RESPONSES = 6;WebEvent.EVT_DO_POST = 7;WebEvent.EVT_DO_POST_RESPONSE = 8;WebEvent.EVT_DO_POST_NOTIFY = 9;//=== used to carry data between objectsfunction WebDataHolder(settings){	this.data = (settings.data) ? settings.data : null; 	}WebDataHolder.prototype ={	start:1,	totalCount:0,	count:0,	data:null,	setStart:function(s){		this.start=s;	},	getStart:function(){		return this.start;	},	setTotalCount:function(count){			//this.totalCount = funcToCalcCount(arglist);		this.totalCount = count;	},		getTotalCount:function(){		return this.totalCount;	},			setResultCount:function(count){		//this.count = funcGetResultCount(argList);		this.count =(count) ? count:0; 	},	getResultCount:function(){		return this.resultCount;	},		setData:function(dataObj){		this.data = dataObj;	}}//==== File upload controlfunction WebImageUpload(settings){	//call super class	ForumList.call(this, settings);	if (settings){		if (settings.dbUrl) this.dbUrl=settings.dbUrl;		if (settings.contentDiv) this.contentDiv=settings.contentDiv;		if (settings.linkButtonCode) this.linkButtonCode=settings.linkButtonCode;	}	}WebImageUpload.prototype ={	dbUrl:null,	contentDiv:null,	noFileSelectedHtml:'H&auml;mta bildfil',	linkButtonCode:'',	refresh:function(){		var uploadContainer = document.getElementById(this.contentDiv);		var iHtml = '<span valign="top" id="' + this.contentDiv+ '_filename">'+ this.noFileSelectedHtml+'</span><span class="uploadspacer"></span>';		iHtml += '<input type="hidden" id="' + this.contentDiv+ '_fileid" value="" />';		if (this.linkButtonCode=='') this.linkButtonCode='<img src="'+this.dbUrl+'/img/folder.gif" valign="top" border="0">';		iHtml +='<a href="#" onclick="ForumList.instances['+this.instanceId+'].selectFileDialogbox()" title="V\u00E4lj bild">'+ this.linkButtonCode+'</a>'		uploadContainer.innerHTML = iHtml;	},	selectFileDialogbox:function(){		var w=410;		var h=120;		hWnd=window.open(dbUrl +'/fileupload?openform&target='+ this.contentDiv,'selectFileDialogbox','toolbar=0,status=0,menubar=0,resizable=1,width='+w+',height='+h);		hWnd.moveTo(screen.width/2-(w/2),screen.height/2-(h/2))	},	getFileId:function(){		try{			var uploadId = document.getElementById(this.contentDiv+'_fileid');			if (uploadId) return uploadId.value;			else return '';		} catch(e){			return '';		}	}, 	clear:function(){		try{			document.getElementById(this.contentDiv+'_fileid').value='';			document.getElementById(this.contentDiv+'_filename').value='';		}catch(e){}	}}