DBM.module.Comments = {
	
	authUrl: "http://www.dagbladet.no/konto/",
	
	commentsTarget: "comments_container",
	
	commentsFormTarget: "comments_form_container",
	
	currentCommentId: "",
	
	modulePath: "",
	
	discussionId: "",
	
	responseObject: "",
	
	switchedContent: "",
	
	defaultOrderType: "",
	
	addCommentVoteCallback: {
		 success: function(o) {
		 	DBM.util.createDiv(DBM.module.Common.requests[o.tId].target, o.responseText);
		  	DBM.module.Common.defaultCallback.success(o);
		  	var div = new DBM.util.getObj("pointsclicker_"+ DBM.module.Comments.currentCommentId);
			var a = div.obj.childNodes[0];
			a.className = 'pointclicker-faded';
			a.onclick = function() {return false;}
		  },  	
		  failure: function(o) {
		  	DBM.module.Common.defaultCallback.failure(o);
		  },  	
		  timeout: DBM.module.Common.timeout
	},
	
	addCommentVote: function (commentId, voteCount) {
		
		this.currentCommentId = commentId;
				
		DBM.util.createDiv(DBM.module.Common.currentLoadingTarget, DBM.module.Common.defaultLoadingHTML);
		
		var target = "points_" + commentId;
		var loadingTarget = "points_" + commentId;
		var callback = this.addCommentVoteCallback;
		var url = DBM.module.Common.rootUrl+  DBM.module.Comments.modulePath + "/?op=AddCommentVote&commentId=" + commentId + "&vote=1&voteCount=" + voteCount;
		var tId = YAHOO.util.Connect.asyncRequest('GET', url, callback);
		
		DBM.module.Common.addRequest(tId, url, callback, target, loadingTarget, "GET");
		
	},
	
	setDefaultOrderType: function (orderType) {
		this.defaultOrderType = orderType;
		return true;
	},
	
	navigateCallback: {
		success: function(o) {
			if (o.responseText.length > 0) {
				DBM.util.createDiv(DBM.module.Common.requests[o.tId].target, o.responseText);
			}
			else {
		  		DBM.module.Common.defaultCallback.failure(o);
		  	}
			DBM.module.Common.defaultCallback.success(o);
			//ss.scrollNow("comments");	
		},
	
		failure: function(o) {
			DBM.module.Common.defaultCallback.failure(o);
		  	if (DBM.module.Common.requests[o.tId].isStopped) {
			  	errorElement = document.getElementById("navigationError");
			  	
			  	if (errorElement) {
				  	errorElement.className = "errormessage";
				  	errorElement.innerHTML = "Kommentarsystemet svarer ikke. Vennligst prøv igjen.";
			  	}
			  	else {
			  		//alert("Kommentarsystemet svarer ikke. Vennligst prøv igjen " + o.status +  " " + o.statusText + " tekst: " + o.responseText);
			  	}
		  	}
		},  	
		timeout: DBM.module.Common.timeout
		
	},
	
	
	// The callback object for listing comments
	commentsListCallback: {  	
		  success: function(o) {
		  	if (o.responseText.length > 0) {
				DBM.util.createDiv(DBM.module.Common.requests[o.tId].target, o.responseText);
				
				if (o.argument.commentId != undefined && o.argument.commentId != "" ) {
					window.location = "#comment_" + o.argument.commentId;
				}
				
				var source = document.getElementById("comments_total");
				var el1 = document.getElementById("ncomments_top");
				var el2 = document.getElementById("ncomments_bottom");
				
				if (source && el1) {
					if (source == "") {
						el1.innerHTML = "0";
					}
					else {
						el1.innerHTML = source.innerHTML;	
					}
				}
				
				if (source && el2) {
					if (source == "") {	
						el2.innerHTML = "0";
					}
					else {	
						el2.innerHTML = source.innerHTML;	
					}
				}
				
				
		  	}
		  	else {
		  		DBM.module.Common.defaultCallback.failure(o);
		  	}
		  	DBM.module.Common.defaultCallback.success(o);
		  },  	
		  failure: function(o) {
		   	//alert("kunne ikke laste");
		  	DBM.module.Common.defaultCallback.failure(o);
		  	if (DBM.module.Common.requests[o.tId].isStopped) {
			  	errorElement = document.getElementById("navigationError");
			  	
			  	if (errorElement) {
				  	errorElement.className = "errormessage";
				  	errorElement.innerHTML = "Kommentarsystemet svarer ikke. Vennligst prøv igjen.";
			  	}
			  	/*else {
			  		DBM.util.createDiv(DBM.module.Common.requests[o.tId].target, "");
			  	}*/
		  	}
		  },  	
		  timeout: DBM.module.Common.timeout,
		argument: {commentId: ""} 	
	},
	
	// window.location = "#comment_345345";
	
	// Inserts comments as a part of the page
	insertComments: function (discussionId, target, loadingTarget, page, orderType, loadingHTML, callback, tag, commentId) {

		if (loadingTarget == undefined) {
			loadingTarget = this.commentsTarget;	
		}
		
		if (target != undefined) {
			this.commentsTarget = target;	
		}
		
		
		if (commentId != undefined) {
			directString = '&commentId=' + commentId;	
			this.commentsListCallback.argument.commentId = commentId;	
		}
		else {
			directString = '';	
		}
		
		target = this.commentsTarget;
		
		if (loadingHTML == undefined) {
			loadingHTML = DBM.module.Common.defaultLoadingHTML;	
		}
		
		if (page == undefined) {
			page = 1;
		}
		
		if (page == this.commentsListCallback) {
			callback = 1;
		}
		
		if (callback == undefined || callback == '') {
			callback = this.commentsListCallback
		}
		
		if (parseInt(orderType)) {
			
			var orderTypeString = "&orderType=" + orderType;	

		}
		else {
			orderType = "";
			var orderTypeString = "";	
		}

		DBM.util.createDiv(loadingTarget, loadingHTML);
		
		if (tag == undefined || tag == "") {
			
			url = DBM.module.Common.rootUrl +  DBM.module.Comments.modulePath + "/?op=ViewComments&discussionId=" + discussionId + orderTypeString + "&page=" + page + directString;
		}
		else {
			url = DBM.module.Common.rootUrl +  DBM.module.Comments.modulePath + "/?op=ViewCommentsByTag&tag=" + tag + orderTypeString + "&page=" + page;
		}
		
		tId = YAHOO.util.Connect.asyncRequest('GET', url, callback); 
		DBM.module.Common.addRequest(tId, url, callback, target, loadingTarget, "GET");
	
	},
	
	// A wrapper function for insertComments, to include scrolling if necessary
	navigateComments: function (discussionId, divId, loadingDivId, page, doScroll, tag) {
		loadingHTML = '<a class="button loading">' + page + '</a>';
		
		var orderType="";
		if (doScroll) {
			location.hash = divId;
	    	this.insertComments(discussionId, divId, loadingDivId, page, orderType, loadingHTML, this.navigateCallback, tag);
		}
		else {
			this.insertComments(discussionId, divId, loadingDivId, page, orderType, loadingHTML, this.commentsListCallback, tag);
		}
	},
	
	// The callback object for comment forms
	commentsFormCallback: {   
		success: function(o) {

			DBM.util.createDiv(DBM.module.Common.requests[o.tId].target, o.responseText);
		  	DBM.module.Common.defaultCallback.success(o);
		  	
		  	var element = document.getElementById("discussionSourceUrl");
		  	if (element) {
		  		if (element.value == "") {
		  			element.value = top.location;	
		  		}	
		  	}
		  	
		  
		  	//var multi_selector = new MultiSelector( document.getElementById( 'files_list' ), 5 );	
			//multi_selector.addElement( document.getElementById( 'my_file_element' ) );
		  	
		  },  	
		  failure: function(o) { 
		  	DBM.module.Common.defaultCallback.failure(o);
		  	if (DBM.module.Common.requests[o.tId].isStopped) {
			  	errorElement = document.getElementById("navigationError");
			  	if (errorElement) {
				  	errorElement.className = "errormessage";
				  	//errorElement.innerHTML = "Kommentarsystemet svarer ikke. Vennligst forsøk på nytt"; // Vennligst prøv igjen " + o.status +  " " + o.statusText + " " + o.responseText;
			  	}
			  	else {
			  		
			  		DBM.util.createDiv(DBM.module.Common.requests[o.tId].target, "");
			  		//alert("KOMMENTARSKJEMA: Kommentarsystemet svarer ikke. Vennligst prøv igjen " + o.status +  " " + o.statusText + " " + o.responseText);
			  	}
		  	}
		  },  	
		  timeout: DBM.module.Common.timeout
	},
	
	// Inserts a comment form where necessary
	insertCommentsForm: function (discussionId, target, parentId, loadingTarget, loadingHTML) {
		
		if (parentId != undefined) {
			parentIdString = "&parentId=" + parentId;
			
			parentTitleElement = document.getElementById("commenttitle_link_"  + parentId);
			if (parentTitleElement && parentTitleElement.innerHTML != "" && parentTitleElement.innerHTML != undefined) {
				titleString = "&title=" + escape("RE: " + 	parentTitleElement.innerHTML);
			}
			else {
				titleString = "";	
			}
				
		}
		else {
			parentIdString = "";
			titleString = "";
		}
		
		if (discussionId == undefined) {
			discussionId = this.discussionId;	
		}
		
		if (target != undefined) {
			this.commentsFormTarget = target;	
		}
		else {
			target = this.commentsFormTarget;	
		}
		
		if (loadingTarget == undefined) {
			loadingTarget = this.commentsFormTarget;	
		}
		
		if (loadingHTML == undefined) {
			loadingHTML = DBM.module.Common.defaultLoadingHTML;	
		}
		
		DBM.util.createDiv(loadingTarget, loadingHTML);

		var callback = this.commentsFormCallback;
		
		var url = DBM.module.Common.rootUrl +  DBM.module.Comments.modulePath + "/?op=NewComment&discussionId=" + discussionId + parentIdString + titleString;
		var tId = YAHOO.util.Connect.asyncRequest('GET', url, callback); 
		
		DBM.module.Common.addRequest(tId, url, callback, target, loadingTarget, "GET");
	
		
		return false;
	},
	
	// Submits a comment form
	submitCommentForm: function (formId, target, loadingTarget, commentId, loadingHTML) {

		if (target != undefined) {
			this.commentsFormTarget = target;	
		}
		
		if (loadingTarget == undefined) {
			loadingTarget = this.commentsFormTarget;	
		}
		
		if (loadingHTML == undefined) {
			loadingHTML = DBM.module.Common.defaultLoadingHTML;	
		}
		
		if (commentId != undefined && commentId != "") {
		    this.submitCommentFormUploadCallback.argument.commentId = commentId;	
		    this.submitCommentFormUploadCallback.argument.target = "feedback_" + commentId;
		}
		else {
			this.submitCommentFormUploadCallback.argument.commentId = "";
			this.submitCommentFormUploadCallback.argument.target = "comments_form_container";
		}
		

		//DBM.util.createDiv(loadingTarget, loadingHTML);

		var formObject = document.getElementById(formId);	
		YAHOO.util.Connect.setForm(formObject, true, true);  	
	
	
	
		var tId = YAHOO.util.Connect.asyncRequest('POST', DBM.module.Common.rootUrl +  DBM.module.Comments.modulePath + "/", this.submitCommentFormUploadCallback);

	},
	
	// The callback object for submitting a comment form
	submitCommentFormCallback: { 
		success: function(o) {
	
			DBM.util.createDiv(o.argument.target, o.responseText);
	
			var element = document.getElementById('updateData');
			if (element) {
				for (i=0; i<element.childNodes.length; i++) {
					node = element.childNodes[i];
					//alert(node.value + " " + node.id);
					if (node.id=="discussionId") {
						var discussionId = node.value;
					}
				}
				DBM.module.Comments.insertComments(discussionId, "comments_container", "commentsfooter")
			}
			
			var element = document.getElementById("discussionSourceUrl");
		  	if (element) {
		  		if (element.value == "") {
		  			element.value = top.location;	
		  		}	
		  	}
		}, 
		
		failure: function(o) {
			alert ("Kommentarsystemet kunne ikke lagre din kommentar. Vennligst prøv igjen");
		},
		timeout: DBM.module.Common.timeout,
		argument: {target: this.commentsFormTarget, commentId: ""} 
	},
	
	submitCommentFormUploadCallback: { 
		upload: function(o) {
			
			//alert(DBM.module.Comments.commentsFormTarget + o.argument.commentId + o.tId);
				//alert("ferdig" + o.responseText);

			
			/*try {
				response = eval ( "(" + o.responseText + ")" );
				
				//DBM.module.Comments.responseObject = response;
				
				
				//var response = DBM.module.Comments.responseObject;
				DBM.module.Comments.publishUnverifiedComment(response.commentId, response.emailAddress, response.commentTitle, response.commentBody);
			}
			catch(e) {*/
			    DBM.util.createDiv(o.argument.target, o.responseText);
				var element = document.getElementById('updateData');
				if (element) {
					
					
					
					for (i=0; i<element.childNodes.length; i++) {
						node = element.childNodes[i];
						//alert(node.value + " " + node.id);
						if (node.id=="discussionId") {
							var discussionId = node.value;
						}
						
						if (node.id=="currentCommentId") {
							var currentCommentId = node.value;
						}
					}
					
					//if (discussionId == 171958)  {
						
						//alert('!' + currentCommentId);
						
						//DBM.module.Comments.insertComments(discussionId, "comments_container", "commentsfooter")
						DBM.module.Comments.insertComments(discussionId, "comments_container", "commentsfooter", 1, DBM.module.Comments.defaultOrderType, DBM.module.Common.defaultLoadingHTML, DBM.module.Comments.commentsListCallback, '', currentCommentId);
					/*}
 					else {
 						DBM.module.Comments.insertComments(discussionId, "comments_container", "commentsfooter")
 					}*/
					//DBM.module.Comments.insertComments(discussionId, "comments_container", "commentsfooter")
				}

				
				var element = document.getElementById("discussionSourceUrl");
			  	if (element) {
			  		if (element.value == "") {
			  			element.value = top.location;	
			  		}	
			  	}
			  	
			  	var commentId = document.getElementById("outputCommentId");
			  	
			  	
			  	if (commentId) {

			  		commentId = commentId.innerHTML;
			  		
			  		var emailAddress = document.getElementById("outputMailbackAddress");
				  	if (emailAddress) {
				  		emailAddress = emailAddress.innerHTML;
				  	}
				  	var commentTitle = document.getElementById("commentTitle").value;
				  	var commentBody = document.getElementById("commentBody").value;
				  	
				  	var parentId = document.getElementById("outputParentId");
				  	if (parentId) {
				  		parentId = parentId.innerHTML;
				  	}
				  	
				  	
				  	
				  	DBM.module.Comments.publishUnverifiedComment(commentId, emailAddress, commentTitle, commentBody, parentId);
			  	}
			  	
			//}
	

			
			
		},
		argument: {target: this.commentsFormTarget, commentId: ""} 
		
	},
	
	// Submits a comment form
	submitFeedbackForm: function (formObject) {
		
		var loadingTarget = "feedback_buttons";
		var loadingHTML = DBM.module.Common.defaultLoadingHTML;

		YAHOO.util.Connect.setForm(formObject); 
		var target = "feedback_container";

		DBM.util.createDiv(loadingTarget, loadingHTML);
		
		var callback = this.feedbackFormCallback;
		var url = DBM.module.Common.rootUrl + DBM.module.Comments.modulePath + "/"; 	 	
		var tId = YAHOO.util.Connect.asyncRequest('POST', url, callback);
		
		DBM.module.Common.addRequest(tId, url, callback, target, loadingTarget, "POST", formObject);
		
	},
	
	// The callback object for submitting a comment form
	feedbackFormCallback: { 
		success: function(o) {
			//alert(o.responseText);
			
			var response = eval ( "(" + o.responseText + ")" );
			
			var element = document.getElementById("feedback_container_" + response.commentId);
			var z = new YAHOO.widget.Effect(element);
			//YAHOO.util.Dom.removeClass(element,'expanded');
			//YAHOO.util.Dom.addClass(element,'collapsed');
			
			if (response.addClass) {
				YAHOO.util.Dom.addClass('comment_'  + response.commentId, response.addClass);
			}
			
			if (response.removeClass) {
				YAHOO.util.Dom.removeClass('comment_'  + response.commentId, response.removeClass);
			}
			
			var messageText = "";
			if (response.successText) {
				//var messageElement = document.getElementById("message_" + response.commentId);
				//YAHOO.util.Dom.addClass(messageElement,'success_message');
				//messageElement.innerHTML = response.successText;
				messageText = '<span class="success_message">' + response.successText + '</span>';
			}
			else if (response.errorText) {
				//var messageElement = document.getElementById("message_" + response.commentId);
				//YAHOO.util.Dom.addClass(messageElement,'error_message');
				//messageElement.innerHTML = response.errorText;
				messageText = '<span class="error_message">' + response.errorText + '</span>';
			}
			else if (response.errors) {
				//var messageElement = document.getElementById("message_" + response.commentId);
				//YAHOO.util.Dom.addClass(messageElement,'error_message');
				messageText = '<span class="error_message">';
				for(var i = 0; i < response.errors.length; i++) {
					if (i >0) {
						//messageElement.innerHTML += ", ";
						messageText += ", ";
					}
					//messageElement.innerHTML += response.errors[i].errorText;
					messageText += response.errors[i].errorText;
				}
				messageText += '</span>';
			}
			
			if (messageText != "") {
				var fn = function() {
					var z = new YAHOO.widget.Effect(element);
					element.innerHTML = '';
					
					z.BlindDown(50);
					element.innerHTML = '<div class="feedback">' + messageText + '</div>';
				}
				z.BlindUp(0.2, fn);
			}
			else {
				z.BlindUp(0.2);
			}
			
			
			//z.yoyo('<div class="feedback">' + messageText + '</div>');
			
			// Close other buttons
			DBM.module.Comments.closeButton("button_delete_" + response.commentId);
			DBM.module.Comments.closeButton("button_answer_" + response.commentId);
			DBM.module.Comments.closeButton("button_complain_" + response.commentId);
			
		}, 
		
		failure: function(o) {
			//alert ("Kommentaren ble ikke lagret. Vennligst prøv igjen");
		},
		timeout: DBM.module.Common.timeout
	},
	
	showHideComplainFeedback: function (commentId) {
		var element = document.getElementById("feedback_container_" + commentId);
		var button = document.getElementById("button_complain_" + commentId);
		
		if ( !YAHOO.util.Dom.hasClass(button,'button_feedback') ) {

			//var messageElement = document.getElementById("message_" + commentId);
			//messageElement.innerHTML = "";
			
			// Close other buttons
			this.closeButton("button_delete_" + commentId);
			this.closeButton("button_answer_" + commentId);
			this.openButton("button_complain_" + commentId);
			this.openButton("button_complain_" + commentId);
			var z = new YAHOO.widget.Effect(element);
			z.BlindDown(100);
			// Open feedback
			//YAHOO.util.Dom.removeClass(element,'collapsed');
			//YAHOO.util.Dom.addClass(element,'expanded');
			element.innerHTML = 
				'<div class="feedback">' +
					'<form onsubmit="javascript:DBM.module.Comments.submitFeedbackForm(this);return false;">' +
						'<input type="hidden" name="op" value="AddCommentComplaint" />' + 
						'<input type="hidden" name="commentId" value="' + commentId + '" />' + 
						'<input type="hidden" name="templateSet" value="json" />' + 
						'<fieldset class="radio">' +
						'<legend>' +
							'På hvilket grunnlag vil du klage inn denne kommentaren?' +
						'</legend>' +
						'<label for="complaintTypeSpam">' +
							'<input id="complaintTypeSpam" name="complaintType" type="radio" checked="checked" value="1"/>' +
							'Spam' +
						'</label>' +
						'<label for="complaintTypePersonal">' +
							'<input id="complaintTypePersonal" name="complaintType" type="radio" value="2"/>' +
							'Personangrep' +
						'</label>' +
						'<label for="complaintTypeRacial">' +
							'<input id="complaintTypeRacial" name="complaintType" type="radio" value="3"/>' +
							'Rasistisk' +
						'</label>' +
	
						'<label for="complaintTypePornography">' +
							'<input id="complaintTypePornography" name="complaintType" type="radio" value="4"/>' +
							'Pornografisk' +
						'</label>' +
						
						'<label for="complaintTypeOther">' +
							'<input id="complaintTypeOther" name="complaintType" type="radio" value="5"/>' +
							'Annet' +
						'</label>' +
					'</fieldset>' +
					'<div id="feedback_buttons">' +
					'<input type="submit" name="sendComplaint" value="Send klage" class="submit"/> eller <input type="submit" class="submit" name="cancelComplaint" value="Avbryt" onclick="javascript:DBM.module.Comments.showHideComplainFeedback(\'' + commentId + '\');return false;" />' +
					'</div>' +
					'</form>';
				'</div>';
			
		}
		else {
			// Close feeback
			//YAHOO.util.Dom.removeClass(element,'expanded');
			//YAHOO.util.Dom.addClass(element,'collapsed');
			this.closeButton("button_complain_" + commentId);
			var z = new YAHOO.widget.Effect(element);
			z.BlindUp();
			element.innerHTML = "";
			
		}
	},
	
	showHideDeleteFeedback: function (commentId) {
		var element = document.getElementById("feedback_container_" + commentId);
		var button = document.getElementById("button_delete_" + commentId);
		
		if ( !YAHOO.util.Dom.hasClass(button,'button_feedback') ) {
			
			//var messageElement = document.getElementById("message_" + commentId);
			//messageElement.innerHTML = "";
			
			// Close other buttons
			this.closeButton("button_answer_" + commentId);
			this.closeButton("button_complain_" + commentId);
			this.openButton("button_delete_" + commentId);
			var z = new YAHOO.widget.Effect(element);
			z.BlindDown(65);
			// Open feedback
			//YAHOO.util.Dom.removeClass(element,'collapsed');
			//YAHOO.util.Dom.addClass(element,'expanded');
			element.innerHTML =
				'<div class="feedback">' +
					'<b>Ønsker du å fjerne kommentaren helt?</b>' +
					'<form onsubmit="javascript:DBM.module.Comments.submitFeedbackForm(this);return false;">' +
					'<input type="hidden" name="op" value="AdminDeleteComment" />' + 
					'<input type="hidden" name="commentId" value="' + commentId + '" />' + 
					'<input type="hidden" name="templateSet" value="json" />' + 
					'<div id="feedback_buttons">' +
					'<input type="submit" name="sendComplaint" value="Slett kommentar" class="submit"/> eller <input type="submit" class="submit" name="cancelComplaint" value="Avbryt" onclick="javascript:DBM.module.Comments.showHideDeleteFeedback(\'' + commentId + '\');return false;" />' +
					'</div>' +
					'</form>' +
				'</div>';
			
			
		}
		else {
			// Close feeback
			//YAHOO.util.Dom.removeClass(element,'expanded');
			//YAHOO.util.Dom.addClass(element,'collapsed');
			var z = new YAHOO.widget.Effect(element);
			z.BlindUp();
			this.closeButton("button_delete_" + commentId);
			element.innerHTML = "";
		}
	},
	
	showHideStarFeedback: function (commentId, mode) {
		var element = document.getElementById("feedback_container_" + commentId);
		var button = document.getElementById("button_star_" + commentId);
		
		if ( !YAHOO.util.Dom.hasClass(button,'button_feedback') ) {
			
			//var messageElement = document.getElementById("message_" + commentId);
			//messageElement.innerHTML = "";
			
			// Close other buttons
			this.closeButton("button_answer_" + commentId);
			this.closeButton("button_complain_" + commentId);
			this.openButton("button_star_" + commentId);
			this.closeButton("button_destar_" + commentId);
			this.closeButton("button_delete_" + commentId);
			var z = new YAHOO.widget.Effect(element);
			z.BlindDown(65);
			// Open feedback
			//YAHOO.util.Dom.removeClass(element,'collapsed');
			//YAHOO.util.Dom.addClass(element,'expanded');
			
			if (mode == 1) {
				element.innerHTML =
					'<div class="feedback">' +
						'<b>Du kan gi stjerne til innlegg du ønsker skal være mer synlige</b>' +
						'<form onsubmit="javascript:DBM.module.Comments.submitFeedbackForm(this);return false;">' +
						'<input type="hidden" name="op" value="AdminStarComment" />' + 
						'<input type="hidden" name="commentId" value="' + commentId + '" />' + 
						'<input type="hidden" name="templateSet" value="json" />' + 
						'<div id="feedback_buttons">' +
						'<input type="submit" name="sendStar" value="Gi stjerne" class="submit"/> eller <input type="submit" class="submit" name="cancelComplaint" value="Avbryt" onclick="javascript:DBM.module.Comments.showHideStarFeedback(\'' + commentId + '\');return false;" />' +
						'</div>' +
						'</form>' +
					'</div>';
			}
			else {
				element.innerHTML =
					'<div class="feedback">' +
						'<b>Du kan fjerne stjernen til innlegg du ikke synes fortjener den</b>' +
						'<form onsubmit="javascript:DBM.module.Comments.submitFeedbackForm(this);return false;">' +
						'<input type="hidden" name="op" value="AdminRemoveStarComment" />' + 
						'<input type="hidden" name="commentId" value="' + commentId + '" />' + 
						'<input type="hidden" name="templateSet" value="json" />' + 
						'<div id="feedback_buttons">' +
						'<input type="submit" name="sendStar" value="Fjern stjerne" class="submit"/> eller <input type="submit" class="submit" name="cancelComplaint" value="Avbryt" onclick="javascript:DBM.module.Comments.showHideStarFeedback(\'' + commentId + '\');return false;" />' +
						'</div>' +
						'</form>' +
					'</div>';
			}
			
			
		}
		else {
			// Close feeback
			//YAHOO.util.Dom.removeClass(element,'expanded');
			//YAHOO.util.Dom.addClass(element,'collapsed');
			var z = new YAHOO.widget.Effect(element);
			z.BlindUp();
			this.closeButton("button_star_" + commentId);
			element.innerHTML = "";
		}
	},
	
	showHideDestarFeedback: function (commentId, mode) {
		var element = document.getElementById("feedback_container_" + commentId);
		var button = document.getElementById("button_destar_" + commentId);
		
		if ( !YAHOO.util.Dom.hasClass(button,'button_feedback') ) {
			
			//var messageElement = document.getElementById("message_" + commentId);
			//messageElement.innerHTML = "";
			
			// Close other buttons
			this.closeButton("button_answer_" + commentId);
			this.closeButton("button_complain_" + commentId);
			this.closeButton("button_delete_" + commentId);
			this.openButton("button_destar_" + commentId);
			this.closeButton("button_star_" + commentId);
			var z = new YAHOO.widget.Effect(element);
			z.BlindDown(65);
			// Open feedback
			//YAHOO.util.Dom.removeClass(element,'collapsed');
			//YAHOO.util.Dom.addClass(element,'expanded');
			if (mode == 1) {
				element.innerHTML =
				'<div class="feedback">' +
					'<b>Du kan gi antistjerne til innlegg du ønsker skal skjules men ikke slettes</b>' +
					'<form onsubmit="javascript:DBM.module.Comments.submitFeedbackForm(this);return false;">' +
					'<input type="hidden" name="op" value="AdminDestarComment" />' + 
					'<input type="hidden" name="commentId" value="' + commentId + '" />' + 
					'<input type="hidden" name="templateSet" value="json" />' + 
					'<div id="feedback_buttons">' +
					'<input type="submit" name="sendStar" value="Gi antistjerne" class="submit"/> eller <input type="submit" class="submit" name="cancelComplaint" value="Avbryt" onclick="javascript:DBM.module.Comments.showHideDestarFeedback(\'' + commentId + '\');return false;" />' +
					'</div>' +
					'</form>' +
				'</div>';
			}
			else {
				element.innerHTML =
				'<div class="feedback">' +
					'<b>Du kan fjerne antistjernen til innlegg du ikke synes fortjener det</b>' +
					'<form onsubmit="javascript:DBM.module.Comments.submitFeedbackForm(this);return false;">' +
					'<input type="hidden" name="op" value="AdminRemoveDestarComment" />' + 
					'<input type="hidden" name="commentId" value="' + commentId + '" />' + 
					'<input type="hidden" name="templateSet" value="json" />' + 
					'<div id="feedback_buttons">' +
					'<input type="submit" name="sendStar" value="Fjern antistjerne" class="submit"/> eller <input type="submit" class="submit" name="cancelComplaint" value="Avbryt" onclick="javascript:DBM.module.Comments.showHideDestarFeedback(\'' + commentId + '\');return false;" />' +
					'</div>' +
					'</form>' +
				'</div>';	
			}
			
			
		}
		else {
			// Close feeback
			//YAHOO.util.Dom.removeClass(element,'expanded');
			//YAHOO.util.Dom.addClass(element,'collapsed');
			var z = new YAHOO.widget.Effect(element);
			z.BlindUp();
			this.closeButton("button_destar_" + commentId);
			element.innerHTML = "";
		}
	},
	
	showHideAnswerFeedback: function (commentId, discussionId) {
		var element = document.getElementById("feedback_container_" + commentId);
		var button = document.getElementById("button_answer_" + commentId);
		
		if ( !YAHOO.util.Dom.hasClass(button,'button_feedback') ) {
			
			//var messageElement = document.getElementById("message_" + commentId);
			//messageElement.innerHTML = "";
			
			// Close other buttons
			this.openButton("button_answer_" + commentId);
			this.closeButton("button_complain_" + commentId);
			this.closeButton("button_delete_" + commentId);
			
			// Open feedback
			//YAHOO.util.Dom.removeClass(element,'collapsed');
			//YAHOO.util.Dom.addClass(element,'expanded');
			var z = new YAHOO.widget.Effect(element);
			z.BlindDown(400);
			element.innerHTML =
				'<div id="feedback_' + commentId + '" class="feedback">' +
				'</div>';
			this.insertCommentsForm(discussionId, "feedback_" + commentId, commentId);
			
			
		}
		else {
			// Close feeback
			//YAHOO.util.Dom.removeClass(element,'expanded');
			//YAHOO.util.Dom.addClass(element,'collapsed');
			var z = new YAHOO.widget.Effect(element);
			z.BlindUp();
			this.closeButton("button_answer_" + commentId);
			element.innerHTML = "";
		}
	},
	
	openButton: function (buttonId) {
		var button = document.getElementById(buttonId);
		YAHOO.util.Dom.addClass(buttonId,'button_feedback');
		YAHOO.util.Dom.removeClass(buttonId,'button');
	},
	
	closeButton: function (buttonId) {
		var button = document.getElementById(buttonId);
		YAHOO.util.Dom.removeClass(buttonId,'button_feedback');
		YAHOO.util.Dom.addClass(buttonId,'button');
	},
	
	init: function (in_discussionId, in_rootUrl, in_modulePath, in_listContainer, in_formContainer, in_commentId, in_authUrl) {
		
		
		if (in_discussionId != undefined) {
			DBM.module.Comments.discussionId = in_discussionId;	
		}
		
		if (in_rootUrl != undefined) {
			DBM.module.Common.rootUrl = in_rootUrl;	
		}
		
		if (in_authUrl != undefined) {
			DBM.module.Comments.authUrl = in_authUrl;	
		}
		//alert(DBM.module.Comments.authUrl);
			
		if (in_modulePath != undefined) {
			DBM.module.Comments.modulePath = in_modulePath;	
		}
				
		if (in_listContainer == undefined || in_listContainer == "") {
			in_listContainer = 	this.commentsTarget;
		}
		
		if (in_commentId == undefined) {
			var getCommentId = this.getVar("commentId");
			if (getCommentId > 0) {
				in_commentId = getCommentId;	
			}	
		}
		
		
		
		this.insertComments(in_discussionId, in_listContainer, this.commentsTarget, 1, this.defaultOrderType, DBM.module.Common.defaultLoadingHTML, this.commentsListCallback, '', in_commentId);

		
		if (in_formContainer == undefined || in_formContainer == "") {
			in_formContainer = this.commentsFormTarget;
		}
		
		this.insertCommentsForm(in_discussionId, in_formContainer);
	
		
	},
	
	showHideCommentForm: function () {
		
	},

	expandCollapseComment: function(in_commentId) {
		
		// Expand/collapse button
		var button = "collapse_" + in_commentId;
		
		// Elements which should collapse/expand
		var elements = new Array();
		elements[0] = "commentbody_" + in_commentId; 
		elements[1] = "commenttools_" + in_commentId; 
		elements[2] = "pointsclicker_" + in_commentId; 
		elements[3] = "commentpoints_" + in_commentId; 
		elements[4] = "commentbyline_" + in_commentId;
		//elements[5] = "profile_image_" + in_commentId;
		//elements[4] = "commentdata_" + in_commentId;
		
		var comment = "comment_" + in_commentId;
		if (YAHOO.util.Dom.hasClass(elements[0], "collapsed")) {
			YAHOO.util.Dom.removeClass(elements, "collapsed");
			YAHOO.util.Dom.addClass(button, "collapse");
			YAHOO.util.Dom.removeClass(button, "expand");
			YAHOO.util.Dom.addClass(comment, "comment");
			YAHOO.util.Dom.removeClass(comment, "morecomments");
			YAHOO.util.Dom.removeClass("profile_image_" + in_commentId, "collapsed");
		}
		else {
			YAHOO.util.Dom.addClass(elements, "collapsed");
			YAHOO.util.Dom.addClass(button, "expand");
			YAHOO.util.Dom.removeClass(button, "collapse");
			YAHOO.util.Dom.removeClass(comment, "comment");
			YAHOO.util.Dom.addClass(comment, "morecomments");
			YAHOO.util.Dom.addClass("profile_image_" + in_commentId, "collapsed");
		}
	},
	
	expandAll: function() {
		var elements = YAHOO.util.Dom.getElementsByClassName('setasexpanded', 'div', 'comments_container');
		
		if (YAHOO.util.Dom.hasClass(elements[0], "collapsed")) {
			
			YAHOO.util.Dom.removeClass(elements, "collapsed");
		
			var elements = YAHOO.util.Dom.getElementsByClassName('setasexpanded', 'a', 'comments_container');
			YAHOO.util.Dom.removeClass(elements, "collapsed");
			
			var elements = YAHOO.util.Dom.getElementsByClassName('setasexpanded', 'p', 'comments_container');
			YAHOO.util.Dom.removeClass(elements, "collapsed");
			
			var elements = YAHOO.util.Dom.getElementsByClassName('setasexpand', 'a', 'comments_container');
			YAHOO.util.Dom.addClass(elements, "collapse");
			YAHOO.util.Dom.removeClass(elements, "expand");
	
			var elements = YAHOO.util.Dom.getElementsByClassName('setascomment', 'div', 'comments_container');
			YAHOO.util.Dom.removeClass(elements, "morecomments");
			YAHOO.util.Dom.addClass(elements, "comment");
			
		}
		else {
			YAHOO.util.Dom.addClass(elements, "collapsed");
		
			var elements = YAHOO.util.Dom.getElementsByClassName('setasexpanded', 'a', 'comments_container');
			YAHOO.util.Dom.addClass(elements, "collapsed");
			
			var elements = YAHOO.util.Dom.getElementsByClassName('setasexpanded', 'p', 'comments_container');
			YAHOO.util.Dom.addClass(elements, "collapsed");
			
			var elements = YAHOO.util.Dom.getElementsByClassName('setasexpand', 'a', 'comments_container');
			YAHOO.util.Dom.addClass(elements, "expand");
			YAHOO.util.Dom.removeClass(elements, "collapse");
	
			var elements = YAHOO.util.Dom.getElementsByClassName('setascomment', 'div', 'comments_container');
			YAHOO.util.Dom.addClass(elements, "morecomments");
			YAHOO.util.Dom.removeClass(elements, "comment");
		}
		
		
	},
	
	
	getVar: function(name) {
		
		get_string = document.location.search;         
		return_value = '';
		
		do { //This loop is made to catch all instances of any get variable.
		name_index = get_string.indexOf(name + '=');
		
		if(name_index != -1)
		  {
		  get_string = get_string.substr(name_index + name.length + 1, get_string.length - name_index);
		  
		  end_of_value = get_string.indexOf('&');
		  if(end_of_value != -1)                
		    value = get_string.substr(0, end_of_value);                
		  else                
		    value = get_string;                
		    
		  if(return_value == '' || value == '')
		     return_value += value;
		  else
		     return_value += ', ' + value;
		  }
		} while(name_index != -1)
		
		//Restores all the blank spaces.
		space = return_value.indexOf('+');
		while(space != -1)
		  { 
		  return_value = return_value.substr(0, space) + ' ' + 
		  return_value.substr(space + 1, return_value.length);
						 
		  space = return_value.indexOf('+');
		  }
		
		return(return_value);        
     },
     
     
     /* DEMO FUNCTIONS - MUST BE REPLACED */
     /* --------------------------------- */
     /* --------------------------------- */
     /* --------------------------------- */
     
     
     focusOn: function(fieldName) {
		
		if (fieldName == 'new') {
			
			YAHOO.util.Dom.addClass('registered-user', 'faded');
			YAHOO.util.Dom.removeClass('new-user', 'faded');
			
		}
		else {
			YAHOO.util.Dom.addClass('new-user', 'faded');
			YAHOO.util.Dom.removeClass('registered-user', 'faded');
		}
		
	},
	
	activateField: function(fieldName) {

		if (fieldName == 'password') {
			var el = YAHOO.util.Dom.get('password');

			if (el.value > '') {
				YAHOO.util.Dom.addClass('new-user', 'faded');
				YAHOO.util.Dom.removeClass('registered-user', 'faded');
			}
			else {
				var el2 = YAHOO.util.Dom.get('signature');
				YAHOO.util.Dom.removeClass('new-user', 'faded');
				if (el2.value > '') {
					YAHOO.util.Dom.addClass('registered-user', 'faded');
				}
				
			}
		}
		else {
			var el = YAHOO.util.Dom.get('signature');
			
			if (el.value > '') {
				YAHOO.util.Dom.addClass('registered-user', 'faded');
				YAHOO.util.Dom.removeClass('new-user', 'faded');
			}
			else {
				var el2 = YAHOO.util.Dom.get('password');
				YAHOO.util.Dom.removeClass('registered-user', 'faded');
				if (el2.value > '') {
					YAHOO.util.Dom.addClass('new-user', 'faded');
				}
			}
			
		}
		
	},
	
	hideAds: function() {
		var adElements = YAHOO.util.Dom.getElementsByClassName('ad','div');
		YAHOO.util.Dom.addClass(adElements, 'hidden');
		
		YAHOO.util.Dom.addClass('ad-top', 'hidden');
	},
	
	showAds: function() {
		var adElements = YAHOO.util.Dom.getElementsByClassName('ad','div');
		
		YAHOO.util.Dom.removeClass(adElements, 'hidden');
	},
	
	showVerificationCode: function(emailAddress, userId, cellNo) {
				
		
		//YAHOO.util.Dom.removeClass("verifyCellFormContainer", "absolute-hidden");	
		
		YAHOO.util.Dom.addClass("user-terms", "absolute-hidden");
		YAHOO.util.Dom.addClass("privacy-terms", "absolute-hidden");
		
		document.getElementById("verifiedEmail").value = emailAddress;
		document.getElementById("verifiedCellNo").value = cellNo;
		document.getElementById("userId").value = userId;
		var anim = new YAHOO.util.Motion(
										"mobile-verifiation-scroller", 
										{ points: { by: [-420, 0] } },
										0.2,
										YAHOO.util.Easing.easeOut
										);

		anim.onComplete.subscribe(function() { 
			//YAHOO.util.Dom.addClass("registerUserFormContainer", "invisible");	
			YAHOO.util.Dom.removeClass("verifyCellFormContainer", "invisible");	
		});

		
			
		anim.animate();
		
		var focusElement = YAHOO.util.Dom.get("verificationCode");
		
		focusElement.focus();
	},

	previewComment: function() {

		var commentTitle = document.getElementById('comment-title').value;
		var commentBody = document.getElementById('comment-body').value;
		
		var button = YAHOO.util.Dom.get("button-container");
		button.innerHTML = "<img src='http://gfx.dagbladet.no/kommentarer/ajax-loader-bar.gif' />";
		
		YAHOO.util.Dom.removeClass('loader-container', 'hidden');
		
		var anim = new YAHOO.util.Anim(  
					'current-step' ,   
					{ opacity: {from: 1, to: 0 } },   
					0.5,   
					YAHOO.util.Easing.easeOut 
					);  
		anim.animate();
		
		anim.onComplete.subscribe(function() { 
	        var currentStep = YAHOO.util.Dom.get("current-step");
			var nextStep = YAHOO.util.Dom.get("step-2");
			var prevStep = YAHOO.util.Dom.get("step-1");
			prevStep.innerHTML = currentStep.innerHTML;
			currentStep.innerHTML = nextStep.innerHTML;
			nextStep.innerHTML = '';
			
			var targetTitle = YAHOO.util.Dom.get('preview-title');
			targetTitle.innerHTML = commentTitle;
			
			var targetBody = YAHOO.util.Dom.get('preview-body');
			targetBody.innerHTML = commentBody;

			
			var preview = YAHOO.util.Dom.get('preview-entry');
			var height = preview.offsetHeight;
			var padding = YAHOO.util.Dom.get('step-2-padding');
			padding.style.paddingTop = (280 - height) + "px";
			
			//alert(preview + " " + height + " " + " - " + preview.style.paddingTop);
			
			//YAHOO.util.Dom.addClass('current-step', 'comment-form-notice');
			
			var prevStepAnim = new YAHOO.util.ColorAnim(  
						'comment-step-1' ,   
						{ color: {from: '#000000', to: '#aaaaaa' } },   
						0.25
						);
			prevStepAnim.animate();
			
			var nextStepAnim = new YAHOO.util.ColorAnim(  
						'comment-step-2' ,   
						{ color: {from: '#aaaaaa', to: '#000000' } },   
						0.25
						);
			nextStepAnim.animate();
			
			
			var anim2 = new YAHOO.util.Anim(  
					'current-step' ,   
					{ opacity: {from: 0, to: 1 } },   
					0.5,   
					YAHOO.util.Easing.easeOut 
					);  
					
			anim2.onComplete.subscribe(function() { 
				YAHOO.util.Dom.addClass('loader-container', 'hidden');
				
				var buttons = YAHOO.util.Dom.get("button-container");
				var nextButtons = YAHOO.util.Dom.get("step-2-buttons");
				buttons.innerHTML = nextButtons.innerHTML;
			});
					
			anim2.animate();
	    });
		
		
		
		
		
		//var height = document.getElementById("preview-entry").offsetHeight;
	
		
		
		
		/*var attributes = { 
	        height: { to: height } 
	    }; 
	    var anim = new YAHOO.util.Anim('comments_form_container', attributes, 0.5, YAHOO.util.Easing.easeOut); 
    	
	     */
	    
    	anim.animate();
		
	},
	
	verifyCellNo: function() {

		// http://www.dagbladet.no/konto/?op=VerifyUser&response=json&serviceid=100&usr=12345678&vid=451&vcode=230245435&vstring=32350990809
		
		
		

		var emailAddress = document.getElementById("verifiedEmail").value;

		var userId = document.getElementById("userId").value;

		var verificationCode = document.getElementById("verificationCode").value;

		var cellNo = document.getElementById("verifiedCellNo").value;

		
		//var url = "http://www.dagbladet.no/konto/?op=VerifyUser&response=json&serviceid=101&userid=" + userId + "&verificationcode=" + verificationCode + "&verificationstring=" + cellNo + "&verificationid=102"; 
		var url = DBM.module.Comments.authUrl + "?op=VerifyUser&response=json&serviceid=101&userid=" + userId + "&verificationcode=" + verificationCode + "&verificationstring=" + cellNo + "&verificationid=102"; 
		
		//alert(url);
		var tId = YAHOO.util.Connect.asyncRequest('GET', url, this.verifyCellNoCallback);
		DBM.module.Common.addRequest(tId, url, DBM.module.Comments.verifyCellNoCallback, '',  '', "GET");
		 
	},
	
	verifyCellNoCallback: {
		success: function(o) {
			
			DBM.module.Common.defaultCallback.success(o);
			
			response = eval ( "(" + o.responseText + ")" );


			document.getElementById("verification-err").innerHTML = "";
						
			if (response.verified == true || response.verified == 1) {
				var token = document.getElementById("outputConfirmationToken").innerHTML;
				var emailAddress = document.getElementById("outputMailbackAddress").innerHTML;
				DBM.module.Comments.activateComment(token, emailAddress, true);
			}
			else if (response.errors) {
				
				//for ( var i=0, len=response.errors.length; i<len; ++i ){

					document.getElementById("verification-err").innerHTML = "Koden er feil. Prøv igjen, eller <a href='#'>send meg en ny kode</a>.";

				//}

			}
			else {
				alert("Noe gikk galt med mobilverifiseringen.");
			}
			
		},  	
		failure: function(o) {
			
			DBM.module.Common.defaultCallback.failure(o);
			
			alert("Feil ved registrering/innlogging. Vennligst prøv igjen, eller ta kontakt med support@dagbladet.no.");
		},  	
		timeout: DBM.module.Common.timeout,
		argument: {emailAddress: "", signature: "", cellNo: ""} 	
	},
	
	activateComment: function(token, emailAddress, displayMessage) {
		
		var url = DBM.module.Common.rootUrl +  DBM.module.Comments.modulePath + "/?op=ActivateComment&token=" + token + "&email=" + emailAddress;
		if (!displayMessage) {
			url = url + '&abortMessage=true';	
		}
		var tId = YAHOO.util.Connect.asyncRequest('GET', url, this.activateCommentCallback);
		this.activateCommentCallback.argument.displayMessage = displayMessage;
		DBM.module.Common.addRequest(tId, url, DBM.module.Comments.activateCommentCallback, '',  '', "GET");

	},
	
	activateCommentCallback: {
		success: function(o) {
			
			//alert(o.responseText);
			DBM.module.Common.defaultCallback.success(o);
			
			response = eval ( "(" + o.responseText + ")" );


			if (response.commentActivated == 1) {
				YAHOO.util.Dom.addClass('loader-container', 'hidden');
				
				var commentId = document.getElementById("outputCommentId").innerHTML;
				
				DBM.module.Comments.setFocusToComment(commentId, this.argument.displayMessage);
				
				
			}
			else {
				DBM.module.Common.defaultCallback.failure(o);
				
				//alert("Noe gikk galt med mobilverifiseringen.");
			}
			
		},  	
		failure: function(o) {
			
			DBM.module.Common.defaultCallback.failure(o);
			
			//alert("Feil ved registrering/innlogging. Vennligst prøv igjen, eller ta kontakt med support@dagbladet.no.");
		},  	
		timeout: DBM.module.Common.timeout,
		argument: {emailAddress: "", signature: "", cellNo: "", displayMessage: false} 	
	},
	
	setFocusToComment: function(commentId, displayMessage) {
		
		
		
		var newComment = YAHOO.util.Dom.get("preview-entry");
	
		
		var commentString = newComment.innerHTML;
		
		var activeCommentString = commentString.replace(/---COMMENTID---/g, commentId);

		
	
		
		newComment.innerHTML = activeCommentString;
		

		
		DBM.module.Comments.myPanel.hide();

		
		
		/*if (displayMessage) {
			YAHOO.util.Dom.removeClass("yellow_box", "absolute-hidden");
			var anim2 = new YAHOO.util.Anim(  
						'yellow_box' ,   
						{ opacity: {from: 0, to: 1 } },   
						2,   
						YAHOO.util.Easing.easeOut 
						); 
			anim2.animate();
		}*/
		//DBM.module.Comments.discussionId
		
		
		var discussionId = document.getElementById("outputDiscussionId");

		if (discussionId) {
			
			discussionId = discussionId.innerHTML;
			this.insertComments(DBM.module.Comments.discussionId, "comments_container", 'preview-entry', 1, '3', 'Vent...');
			this.insertCommentsForm(discussionId, "comments_form_container");
		}
		
	},

	publishComment: function() {
		
		YAHOO.util.Dom.removeClass('loader-container', 'hidden');
		
		
		var commentTitle = document.getElementById('comment-title').value;
		var commentBody = document.getElementById('comment-body').value;
		
		if (commentTitle != undefined && commentTitle > "" && commentBody != undefined && commentBody > "") {
			var targetTitle = YAHOO.util.Dom.get('preview-title');
			targetTitle.innerHTML = commentTitle;
				
			var targetBody = YAHOO.util.Dom.get('preview-body');
			targetBody.innerHTML = this.nl2br(commentBody);
			
			
			
			/*var button = YAHOO.util.Dom.get("button-container");
			button.innerHTML = "<img src='http://gfx.dagbladet.no/kommentarer/ajax-loader-bar.gif' />";*/
			
			
			
			var anim = new YAHOO.util.Anim(  
						'current-step' ,   
						{ opacity: {from: 1, to: 0 } },   
						0.5,   
						YAHOO.util.Easing.easeOut 
						);  
			anim.animate();
			
			document.location.href = '#comments';
			
			var preview = YAHOO.util.Dom.get('preview-entry');
			var height = preview.offsetHeight;
	
			preview.style.height = '0px';
			preview.style.minHeight = '0px';
			
			YAHOO.util.Dom.removeClass('preview-entry', 'absolute-hidden');
			
			var anim2 = new YAHOO.util.Anim(  
						'preview-entry' ,   
						{ height: {from: 0, to: height } },   
						0.3,   
						YAHOO.util.Easing.easeOut 
						); 
			anim2.animate();
			
			var anim2 = new YAHOO.util.Anim(  
						'preview-entry' ,   
						{ opacity: {from: 0, to: 1 } },   
						0.5,   
						YAHOO.util.Easing.easeOut 
						);
						
	
						
			anim2.onComplete.subscribe(function() { 
					preview.style.overflow = 'visible';
					//YAHOO.util.Dom.removeClass('mobile-verification', 'absolute-hidden');
					DBM.module.Comments.showBox();
					
					var elements = YAHOO.util.Dom.getElementsByClassName('discussion-entry', 'li');
					YAHOO.util.Dom.addClass(elements, 'fadeout');
					//var y=document.createElement("div");
					//y.id = 'mask';
					//document.getElementById("doc").appendChild(y);
	
					document.verifycellform.signature.focus()
					
				});
				
			anim2.animate();
		}
		else {
			
			alert("feil");
			
		}
		
		
		
		
		
	},
	

	publishUnverifiedComment: function(commentId, emailAddress, commentTitle, commentBody, parentId) {
		
		

		
		if (parentId == undefined) {
		
			var targetTitle = YAHOO.util.Dom.get('preview-title');
			targetTitle.innerHTML = commentTitle;
				
			var targetBody = YAHOO.util.Dom.get('preview-body');
			targetBody.innerHTML = this.nl2br(commentBody);
			
			var anim = new YAHOO.util.Anim(  
						'current-step' ,   
						{ opacity: {from: 1, to: 0 } },   
						0.5,   
						YAHOO.util.Easing.easeOut 
						); 
						
			anim.onComplete.subscribe(function() { 
					var currentStep = document.getElementById("current-step");
					YAHOO.util.Dom.addClass(currentStep, 'invisible');
					
				}); 
			anim.animate();
			
			
			YAHOO.util.Dom.addClass("yellow_box", "absolute-hidden");
			
			document.location.href = '#comments';
			
			YAHOO.util.Dom.removeClass('preview-entry', 'invisible');
			
			var preview = YAHOO.util.Dom.get('preview-entry');
			var height = preview.offsetHeight;
	
			preview.style.height = '0px';
			preview.style.minHeight = '0px';
			
			
			YAHOO.util.Dom.removeClass('preview-entry', 'absolute-hidden');
			
			var anim2 = new YAHOO.util.Anim(  
						'preview-entry' ,   
						{ height: {from: 0, to: height } },   
						0.3,   
						YAHOO.util.Easing.easeOut 
						); 
			anim2.animate();
			
			var anim2 = new YAHOO.util.Anim(  
						'preview-entry' ,   
						{ opacity: {from: 0, to: 1 } },   
						0.5,   
						YAHOO.util.Easing.easeOut 
						);
						
	
						
			anim2.onComplete.subscribe(function() { 
				
					DBM.module.Comments.checkUser(emailAddress);
				
					
					
				});
				
			anim2.animate();
		}
		else {
			
			var anim = new YAHOO.util.Anim(  
						'current-step' ,   
						{ opacity: {from: 1, to: 0 } },   
						0.5,   
						YAHOO.util.Easing.easeOut 
						); 
						
			anim.onComplete.subscribe(function() { 
					var currentStep = document.getElementById("current-step");
					YAHOO.util.Dom.addClass(currentStep, 'invisible');
					
				}); 
			anim.animate();
			
			DBM.module.Comments.checkUser(emailAddress);
		}

		
		
		
		
		
	},
	
	// The callback object for listing comments
	checkUserCallback: {  	
		  success: function(o) {
		  	
		  	
		  	
		  	DBM.module.Common.defaultCallback.success(o);
		  	
		  	response = eval ( "(" + o.responseText + ")" );
		  	
		  	// REMOVE

		  	if (response.exists == 404) {
		  		DBM.module.Comments.showRegistrationForm(this.argument.emailAddress);
		  	}
		  	else if (response.exists == 402) {
		  		DBM.module.Comments.showLoginForm(this.argument.emailAddress);
		  	}
		  	else {
		  		alert("Det oppstod en feil med din e-postadresse. Vennligst prøv på nytt.");
		  	}
		  	
		  },  	
		  failure: function(o) {
		  	DBM.module.Common.defaultCallback.failure(o);
		   	//alert("Feil ved registrering/innlogging. Vennligst prøv igjen, eller ta kontakt med support@dagbladet.no.");
		  },  	
		  timeout: DBM.module.Common.timeout,
		argument: {emailAddress: ""} 	
	},
	
	checkUser: function(emailAddress) {
		
		this.checkUserCallback.argument.emailAddress = emailAddress;
		var callback = this.checkUserCallback;
		
		
		//var url = "http://www.dagbladet.no/konto/?op=UserAvailable&response=json&serviceid=101&email=" + emailAddress; 	 	
		var url = DBM.module.Comments.authUrl + "?op=UserAvailable&response=json&serviceid=101&email=" + emailAddress; 	 	
		
		
		var tId = YAHOO.util.Connect.asyncRequest('POST', url, callback);
		DBM.module.Common.addRequest(tId, url, DBM.module.Comments.checkUserCallback, '',  '', "GET");
		/**/
	},
	
	showRegistrationForm: function(emailAddress) {
		var preview = YAHOO.util.Dom.get('preview-entry');
		preview.style.overflow = 'visible';
		/*YAHOO.util.Dom.removeClass('mobile-verification', 'absolute-hidden');
		var elements = YAHOO.util.Dom.getElementsByClassName('discussion-entry', 'li');
		YAHOO.util.Dom.addClass(elements, 'fadeout');
		var y=document.createElement("div");
		y.id = 'mask';
		document.getElementById("doc").appendChild(y);

		document.register-user-form.signature.focus();*/
		

		YAHOO.util.Dom.addClass("yellow_box", "absolute-hidden");
		

		location.hash = 'comments_container';
					
		
		DBM.module.Comments.hideAds();
		
	
		DBM.module.Comments.myPanel = new YAHOO.widget.Panel("myPanel", { 
			width:"400px",
			fixedcenter:true, 
			visible:false,
			close:false, 
			constraintoviewport:true, 
			draggable:true,
			zindex:999,
			modal:true
		});
		//DBM.module.Comments.myPanel.setHeader("Hei, du er ikke registrert hos oss ennå!");
		
		var html = YAHOO.util.Dom.get("mobile-verification").innerHTML;
		
		DBM.module.Comments.mobileVerificationHTML = html;
		
		
		YAHOO.util.Dom.get("mobile-verification").innerHTML = '';
		YAHOO.util.Dom.addClass("mobile-verification", "absolute-hidden");
		
		
		
		//DBM.module.Comments.myPanel.setBody("<p>Av sikkerhetshensyn vil vi gjerne vite hvem du er. Derfor ber vi deg om å oppgi mobiltelefonnummeret ditt.</p><p>Neste gang er det bare å logge på.</p>");
		DBM.module.Comments.myPanel.setBody(html);
		DBM.module.Comments.myPanel.render(document.body);
		DBM.module.Comments.myPanel.show();
		
		var focusElement = YAHOO.util.Dom.get("signature");
		focusElement.focus();
		
		// Initialize the temporary Panel to display while waiting for external content to load
		/*var panel2 = 
				new YAHOO.widget.Panel("wait",  
					{ width:"240px", 
					  fixedcenter:true, 
					  close:false, 
					  draggable:false, 
					  zindex:400,
					  modal:true,
					  visible:true
					} 
				);
		
		panel2.setHeader("Loading, please wait...");
		panel2.setBody('<img src="http://us.i1.yimg.com/us.yimg.com/i/us/per/gr/gp/rel_interstitial_loading.gif" />');
		panel2.render(document.body);*/
	},
	
	postComment: function(parentId, target) {
		
		DBM.module.Comments.submitCommentForm('newCommentForm_' + parentId, target, 'buttonrow_' + parentId, parentId);
	},
	
	showBox: function() {
		/*var panel2 = 
				new YAHOO.widget.Panel("wait",  
					{ width:"240px", 
					  fixedcenter:true, 
					  close:false, 
					  draggable:false, 
					  zindex:999,
					  modal:true,
					  visible:false
					} 
				);
		
		panel2.setHeader("Loading, please wait...");
		panel2.setBody('<img src="http://us.i1.yimg.com/us.yimg.com/i/us/per/gr/gp/rel_interstitial_loading.gif" />');
		panel2.render(document.body);
		panel2.show();
		return false;*/
		
		DBM.module.Comments.hideAds();
		
		
		DBM.module.Comments.myPanel = new YAHOO.widget.Panel("myPanel", { 
			width:"400px",
			fixedcenter:true, 
			visible:false,
			close:false, 
			constraintoviewport:true, 
			draggable:true,
			zindex:999,
			modal:true
		});
		//DBM.module.Comments.myPanel.setHeader("Hei, du er ikke registrert hos oss ennå!");
		
		var html = YAHOO.util.Dom.get("mobile-verification").innerHTML;
		YAHOO.util.Dom.get("mobile-verification").innerHTML = '';
		//DBM.module.Comments.myPanel.setBody("<p>Av sikkerhetshensyn vil vi gjerne vite hvem du er. Derfor ber vi deg om å oppgi mobiltelefonnummeret ditt.</p><p>Neste gang er det bare å logge på.</p>");
		DBM.module.Comments.myPanel.setBody(html);
		DBM.module.Comments.myPanel.render(document.body);
		DBM.module.Comments.myPanel.show();
		
		return false;

	},
	
	showConfirmSubscriptionForm: function() {


		//DBM.module.Comments.hideAds();
		
		
		/*DBM.module.Comments.confirmSubscriptionForm = new YAHOO.widget.Panel("confirmSubscriptionForm", { 
			width:"400px",
			fixedcenter:true, 
			visible:false,
			close:false, 
			constraintoviewport:true, 
			draggable:true,
			zindex:999,
			modal:true
		});*/
		//DBM.module.Comments.myPanel.setHeader("Hei, du er ikke registrert hos oss ennå!");
		var el = YAHOO.util.Dom.get("confirm-subscription-container");
		if (el) {
			var html = el.innerHTML;
			el.innerHTML = "";
		}
		
		

		DBM.module.Comments.confirmSubscriptionHTML = html;
		YAHOO.util.Dom.get("login-container").innerHTML = DBM.module.Comments.loginHTML;
		

		//YAHOO.util.Dom.get("confirm-subscription-container").innerHTML = '';
		DBM.module.Comments.myPanel.setBody(html);
		DBM.module.Comments.myPanel.render(document.body);
				
		DBM.module.Comments.myPanel.show();
		
		/*var focusElement = YAHOO.util.Dom.get("loginPassword");
		focusElement.focus();*/

	},
	
	confirmSubscription: function() {
		//this.loginUserCallback.argument.emailAddress = emailAddress;
	
		this.switchContent('confirm-subscription-feedback', DBM.module.Common.defaultLoadingHTML);
	
		
		//var url = "http://www.dagbladet.no/konto/"; 
		//var url = DBM.module.Comments.authUrl; 
		//var postVars = "op=LoginUser&response=json&serviceid=101&username=" + emailAddress + "&password=" + pwd;
		// PAYMENT
		var postVars = "op=HandleSubscribe&response=json&payment=1&username=" + DBM.module.Comments.varEmail + "&password=" + DBM.module.Comments.varPassword;
		var tId = YAHOO.util.Connect.asyncRequest('POST', DBM.module.Comments.authUrl, this.confirmSubscriptionCallback, postVars);
		DBM.module.Common.addRequest(tId, DBM.module.Comments.authUrl, DBM.module.Comments.confirmSubscriptionCallback, '',  '', "POST");
		
		
	
	},
		
	confirmSubscriptionCallback: {
		success: function(o) {
			
			// REMOVE
			//DBM.module.Comments.showVerificationCode(this.argument.emailAddress, "123abc0000003", this.argument.cellNo);
			//return true;
			DBM.module.Common.defaultCallback.success(o);
			response = eval ( "(" + o.responseText + ")" );

			DBM.module.Comments.switchContent('confirm-subscription-feedback', DBM.module.Common.defaultLoadingHTML);
			
			
			
			if (response.cell != null) {

				// Bekreft telefonnummer
				var confirmCell = YAHOO.util.Dom.get('confirmCellNo');
				
				
				var html = YAHOO.util.Dom.get("confirm-subscription-cell-container").innerHTML;
		
				DBM.module.Comments.confirmSubscriptionCellHTML = html;
				YAHOO.util.Dom.get("confirm-subscription-container").innerHTML = DBM.module.Comments.confirmSubscriptionHTML;

		
				
				//YAHOO.util.Dom.get("confirm-subscription-container").innerHTML = '';
				DBM.module.Comments.myPanel.setBody(html);
				DBM.module.Comments.myPanel.render(document.body);
						
				DBM.module.Comments.myPanel.show();
				
				
				var el = YAHOO.util.Dom.get("confirm-subscription-cell-container");
				if (el) el.innerHTML = '';
				
				var confirmCell = YAHOO.util.Dom.get('confirmCellNo');
				
				if (confirmCell) {
					confirmCell.value = response.cell;
					confirmCell.focus();
				}
				
				var confirmCellPrefix = YAHOO.util.Dom.get('confirmCellPrefix');
				
				if (confirmCellPrefix && response.prefix) {
					confirmCellPrefix.value = response.prefix;
				}

				
				
				/*var token = document.getElementById("outputConfirmationToken").innerHTML;
				var userId = document.getElementById("loginEmail").value;
				var emailAddress = document.getElementById("outputMailbackAddress").innerHTML;
				DBM.module.Comments.activateComment(token, emailAddress, false);*/
				
			}
			else if (response.errors) {
				/*for ( var i=0, len=response.errors.length; i<len; ++i ){

					if (response.errors[i] == 403) {
						document.getElementById("password-login-err").innerHTML = "Feil e-post/passord";
					}
					else if (response.errors[i] == 407) {
						DBM.module.Comments.showConfirmSubscriptionForm();
					}
					
				}*/
			}
			
			
			
		},  	
		failure: function(o) {
			DBM.module.Common.defaultCallback.failure(o);
			//alert("Feil ved registrering/innlogging. Vennligst prøv igjen, eller ta kontakt med support@dagbladet.no.");
		},  	
		timeout: DBM.module.Common.timeout,
		argument: {emailAddress: "", signature: "", cellNo: ""} 	
	},
	
	sendForSubscriptionConfirmation: function(resendCode) {

		this.switchContent('confirm-subscription-cell-feedback', DBM.module.Common.defaultLoadingHTML);
		
		if (resendCode) {
			var cellNo = DBM.module.Comments.varCellNo;
			var cellPrefix = DBM.module.Comments.varCellPrefix;		
		}
		else {
			var cellNo = YAHOO.util.Dom.get('confirmCellNo').value;
			var cellPrefix = YAHOO.util.Dom.get('confirmCellPrefix').value;
			
			DBM.module.Comments.varCellNo = cellNo;
			DBM.module.Comments.varCellPrefix = cellPrefix;
		}

		

		cellPrefix = cellPrefix.replace('+', '%2B');
		//var url = "http://www.dagbladet.no/konto/"; 
		//var url = DBM.module.Comments.authUrl; 
		//var postVars = "op=LoginUser&response=json&serviceid=101&username=" + emailAddress + "&password=" + pwd;
		// PAYMENT
		var postVars = "op=HandleSubscribe&response=json&sendverification=1&username=" + DBM.module.Comments.varEmail + "&password=" + DBM.module.Comments.varPassword + "&prefix=" + cellPrefix + "&t=1&cell=" + cellNo;

		
		if (!resendCode) {
			var tId = YAHOO.util.Connect.asyncRequest('POST', DBM.module.Comments.authUrl, this.sendForSubscriptionConfirmationCallback, postVars);
			DBM.module.Common.addRequest(tId, DBM.module.Comments.authUrl, DBM.module.Comments.sendForSubscriptionConfirmationCallback, '',  '', "POST");
		}
		else {
			var tId = YAHOO.util.Connect.asyncRequest('POST', url, this.resendSubscriptionConfirmationCallback, postVars);
			DBM.module.Common.addRequest(tId, url, DBM.module.Comments.resendSubscriptionConfirmationCallback, '',  '', "POST");
		}
	
	},
	
	sendForSubscriptionConfirmationCallback: {
		success: function(o) {
			
			// REMOVE
			//DBM.module.Comments.showVerificationCode(this.argument.emailAddress, "123abc0000003", this.argument.cellNo);
			//return true;
			DBM.module.Common.defaultCallback.success(o);
			response = eval ( "(" + o.responseText + ")" );

			DBM.module.Comments.switchContent('confirm-subscription-cell-feedback', DBM.module.Common.defaultLoadingHTML);
			if (response.codesendt != null) {
				
				//confirm-subscription-code-container
				var html = YAHOO.util.Dom.get("confirm-subscription-code-container").innerHTML;
		
				DBM.module.Comments.confirmSubscriptionCodeHTML = html;
				YAHOO.util.Dom.get("confirm-subscription-cell-container").innerHTML = DBM.module.Comments.confirmSubscriptionCellHTML;

		
				
				YAHOO.util.Dom.get("confirm-subscription-code-container").innerHTML = '';
				DBM.module.Comments.myPanel.setBody(html);
				DBM.module.Comments.myPanel.render(document.body);
						
				DBM.module.Comments.myPanel.show();
				
				
				var focusElement = YAHOO.util.Dom.get('confirmCellCode');
				if (focusElement) {
					focusElement.focus();
				}	
				
			}
			else if (response.errors) {
				for ( var i=0, len=response.errors.length; i<len; ++i ){

					if (response.errors[i] == 504) {
						document.getElementById("confirm-subscription-cell-err").innerHTML = "Ugyldig telefonnummer. Prøv igjen.";
					}else if (response.errors[i] == 516) {
						document.getElementById("confirm-subscription-cell-err").innerHTML = "Ugyldig landskode. Prøv igjen.";
					}
					else {
						document.getElementById("confirm-subscription-cell-err").innerHTML = "Ukjent feil. Ta kontakt med support@dagbladet.no";
					}
					
				}
			}
			
			
			
		},  	
		failure: function(o) {
			DBM.module.Common.defaultCallback.failure(o);
			//alert("Feil ved registrering/innlogging. Vennligst prøv igjen, eller ta kontakt med support@dagbladet.no.");
		},  	
		timeout: DBM.module.Common.timeout,
		argument: {emailAddress: "", signature: "", cellNo: ""} 	
	},
	
	resendSubscriptionConfirmationCallback: {
		success: function(o) {
			
			// REMOVE
			//DBM.module.Comments.showVerificationCode(this.argument.emailAddress, "123abc0000003", this.argument.cellNo);
			//return true;
			DBM.module.Common.defaultCallback.success(o);
			response = eval ( "(" + o.responseText + ")" );

			if (response.codesendt != null) {
				
				//confirm-subscription-code-container
				YAHOO.util.Dom.get("resend-code-feedback").innerHTML = 'Kode sendt på nytt.';
				
			}
			else if (response.errors) {
				for ( var i=0, len=response.errors.length; i<len; ++i ){

					if (response.errors[i] == 504) {
						document.getElementById("confirm-subscription-cell-err").innerHTML = "Ugyldig telefonnummer. Prøv igjen.";
					}else if (response.errors[i] == 516) {
						document.getElementById("confirm-subscription-cell-err").innerHTML = "Ugyldig landskode. Prøv igjen.";
					}
					else {
						document.getElementById("confirm-subscription-cell-err").innerHTML = "Ukjent feil. Ta kontakt med support@dagbladet.no";
					}
					
				}
			}
			
			
			
		},  	
		failure: function(o) {
			DBM.module.Common.defaultCallback.failure(o);
			//alert("Feil ved registrering/innlogging. Vennligst prøv igjen, eller ta kontakt med support@dagbladet.no.");
		},  	
		timeout: DBM.module.Common.timeout,
		argument: {emailAddress: "", signature: "", cellNo: ""} 	
	},
	
	sendSubscriptionConfirmationCode: function() {

		this.switchContent('confirm-subscription-code-feedback', DBM.module.Common.defaultLoadingHTML);
		
		var cellCode = YAHOO.util.Dom.get('confirmCellCode').value;
		
		var cellNo = DBM.module.Comments.varCellNo;
		var cellPrefix = DBM.module.Comments.varCellPrefix;
		cellPrefix = cellPrefix.replace('+', '%2B');
		
		//var url = "http://www.dagbladet.no/konto/"; 
		//var url = DBM.module.Comments.authUrl; 
		
		// PAYMENT
		var postVars = "op=HandleSubscribe&response=json&doverify=1&username=" + DBM.module.Comments.varEmail + "&password=" + DBM.module.Comments.varPassword + "&prefix=" + cellPrefix + "&cell=" + cellNo + "&code=" + cellCode;

		var tId = YAHOO.util.Connect.asyncRequest('POST', DBM.module.Comments.authUrl, this.sendSubscriptionConfirmationCodeCallback, postVars);
		DBM.module.Common.addRequest(tId, DBM.module.Comments.authUrl, DBM.module.Comments.sendSubscriptionConfirmationCodeCallback, '',  '', "POST");
	
	},
	
	sendSubscriptionConfirmationCodeCallback: {
		success: function(o) {
			
			// REMOVE
			//DBM.module.Comments.showVerificationCode(this.argument.emailAddress, "123abc0000003", this.argument.cellNo);
			//return true;
			DBM.module.Common.defaultCallback.success(o);
			response = eval ( "(" + o.responseText + ")" );

			DBM.module.Comments.switchContent('confirm-subscription-code-feedback', DBM.module.Common.defaultLoadingHTML);
			

			if (response.userid != null && response.verified != null) {
				
				//confirm-subscription-code-container
				YAHOO.util.Dom.get("confirm-subscription-code-container").innerHTML = DBM.module.Comments.confirmSubscriptionCodeHTML;
		
				var token = document.getElementById("outputConfirmationToken").innerHTML;
				var emailAddress = DBM.module.Comments.varEmail;
								
				DBM.module.Comments.activateComment(token, emailAddress, false);
				
				
			}
			else if (response.errors) {
				for ( var i=0, len=response.errors.length; i<len; ++i ){

					if (response.errors[i] == 508) {
						document.getElementById("confirm-subscription-code-err").innerHTML = "Ugyldig kode. Prøv igjen.";
					}
					else {
						document.getElementById("confirm-subscription-code-err").innerHTML = "Ukjent feil. Ta kontakt med support@dagbladet.no";
					}
					
				}
			}
			
			
			
		},  	
		failure: function(o) {
			DBM.module.Common.defaultCallback.failure(o);
			//alert("Feil ved registrering/innlogging. Vennligst prøv igjen, eller ta kontakt med support@dagbladet.no.");
		},  	
		timeout: 200000,
		argument: {emailAddress: "", signature: "", cellNo: ""} 	
	},
	
	endSubscription: function() {
		
		
		this.switchContent('confirm-subscription-feedback', DBM.module.Common.defaultLoadingHTML);
		
		var emailAddress = document.getElementById("loginEmail").value;
		var pwd = document.getElementById("loginPassword").value;

		//this.loginUserCallback.argument.emailAddress = emailAddress;
		
		//var url = "http://www.dagbladet.no/konto/"; 
		//var url = DBM.module.Comments.authUrl; 
		//var postVars = "op=LoginUser&response=json&serviceid=101&username=" + emailAddress + "&password=" + pwd;
		// PAYMENT
		var postVars = "op=HandleSubscribe&response=json&delete=1&username=" + DBM.module.Comments.varEmail + "&password=" + DBM.module.Comments.varPassword;
		var tId = YAHOO.util.Connect.asyncRequest('POST', DBM.module.Comments.authUrl, this.endSubscriptionCallback, postVars);
		DBM.module.Common.addRequest(tId, DBM.module.Comments.authUrl, DBM.module.Comments.endSubscriptionCallback, '',  '', "POST");

	},
	
	endSubscriptionCallback: {
		success: function(o) {
			
			DBM.module.Comments.switchContent('confirm-subscription-feedback', DBM.module.Common.defaultLoadingHTML);
			
			// REMOVE
			//DBM.module.Comments.showVerificationCode(this.argument.emailAddress, "123abc0000003", this.argument.cellNo);
			//return true;
			DBM.module.Common.defaultCallback.success(o);
			response = eval ( "(" + o.responseText + ")" );


			if (response.deleted != null) {
				
				DBM.module.Comments.abortMissionCallback.argument.abortType = "endSubscription";
				DBM.module.Comments.abortMission();
				
				
			}
			else if (response.errors) {
				/*for ( var i=0, len=response.errors.length; i<len; ++i ){

					if (response.errors[i] == 403) {
						document.getElementById("password-login-err").innerHTML = "Feil e-post/passord";
					}
					else if (response.errors[i] == 407) {
						DBM.module.Comments.showConfirmSubscriptionForm();
					}
					
				}*/
			}
			
			
			
		},  	
		failure: function(o) {
			DBM.module.Common.defaultCallback.failure(o);
			//alert("Feil ved registrering/innlogging. Vennligst prøv igjen, eller ta kontakt med support@dagbladet.no.");
		},  	
		timeout: DBM.module.Common.timeout,
		argument: {emailAddress: "", signature: "", cellNo: ""} 	
	},
	
	fbShareComment: function(commentId) {
		
		var u= YAHOO.util.Dom.get("fb-comment-url-" + commentId).innerHTML;
		var t = "Les debattinnlegget mitt i saken «" + YAHOO.util.Dom.get("fb-comment-title-" + commentId).innerHTML + "»";
		//window.open('http://www.facebook.com/sharer.php?u='+encodeURIComponent(u)+'&t='+encodeURIComponent(t),'sharer','toolbar=0,status=0,width=626,height=436');
		//window.open('http://www.facebook.com/sharer.php?u='+encodeURIComponent(url)+'&t='+encodeURIComponent(title),'sharer','toolbar=0,status=0,width=626,height=436');
		window.open('http://www.facebook.com/sharer.php?u='+encodeURIComponent(u)+'&t='+encodeURIComponent(t),'sharer','toolbar=0,status=0,width=626,height=436');
		
		return false;


	},
	
	addCommentAnswerAlert: function(commentId) {
		
		
		var url = DBM.module.Common.rootUrl +  DBM.module.Comments.modulePath + "/?op=AddCommentAnswerAlert&commentId=" + commentId;

		var tId = YAHOO.util.Connect.asyncRequest('GET', url, this.addCommentAnswerAlertCallback);
		DBM.module.Common.addRequest(tId, DBM.module.Comments.authUrl, DBM.module.Comments.addCommentAnswerAlertCallback, '',  '', "GET");
		
		
		//var replacementHTML = '<a href="#" onclick="DBM.module.Comments.removeCommentA'
		var replacementHTML = ' Du får nå gratis varsling når noen svarer deg.';
		
		YAHOO.util.Dom.get("add-comment-answer-alert-trigger-" + commentId).innerHTML = replacementHTML;
		
		//var postVars = "op=AddCommentAnswerAlert&commentId=" + commentId +  "&response=json";
		//var tId = YAHOO.util.Connect.asyncRequest('POST', DBM.module.Common.rootUrl +  DBM.module.Comments.modulePath, this.addCommentAnswerAlertCallback, postVars);
		

	},
	
	addCommentAnswerAlertCallback: {
		success: function(o) {
			
			//alert(o.responseText);
			
			/*DBM.module.Comments.switchContent('confirm-subscription-feedback', DBM.module.Common.defaultLoadingHTML);
			
			// REMOVE
			//DBM.module.Comments.showVerificationCode(this.argument.emailAddress, "123abc0000003", this.argument.cellNo);
			//return true;
			DBM.module.Common.defaultCallback.success(o);
			response = eval ( "(" + o.responseText + ")" );


			if (response.deleted != null) {
				
				DBM.module.Comments.abortMissionCallback.argument.abortType = "endSubscription";
				DBM.module.Comments.abortMission();
				
				
			}
			*/
			
			
			
		},  	
		failure: function(o) {
			DBM.module.Common.defaultCallback.failure(o);
			//alert("Feil ved registrering/innlogging. Vennligst prøv igjen, eller ta kontakt med support@dagbladet.no.");
		},  	
		timeout: DBM.module.Common.timeout,
		argument: {emailAddress: "", signature: "", cellNo: ""} 	
	},
	
	showLoginForm: function(emailAddress) {
		
		
		
		
		var preview = YAHOO.util.Dom.get('preview-entry');
		preview.style.overflow = 'visible';
		/*YAHOO.util.Dom.removeClass('login-container', 'absolute-hidden');
		var elements = YAHOO.util.Dom.getElementsByClassName('discussion-entry', 'li');
		YAHOO.util.Dom.addClass(elements, 'fadeout');
		var y=document.createElement("div");
		y.id = 'mask';
		document.getElementById("doc").appendChild(y);*/

		
		DBM.module.Comments.hideAds();
		
		
		DBM.module.Comments.myPanel = new YAHOO.widget.Panel("myPanel", { 
			width:"400px",
			fixedcenter:true, 
			visible:false,
			close:false, 
			constraintoviewport:true, 
			draggable:true,
			zindex:999,
			modal:true
		});
		//DBM.module.Comments.myPanel.setHeader("Hei, du er ikke registrert hos oss ennå!");
		
		var html = YAHOO.util.Dom.get("login-container").innerHTML;
		DBM.module.Comments.loginHTML = html;
		YAHOO.util.Dom.get("login-container").innerHTML = '';
		DBM.module.Comments.myPanel.setBody(html);
		DBM.module.Comments.myPanel.render(document.body);
		
		var loginEmail = YAHOO.util.Dom.get('loginEmail');
		if (loginEmail) {
			loginEmail.value = emailAddress;
		}
		
		DBM.module.Comments.myPanel.show();
		
		var focusElement = YAHOO.util.Dom.get("loginPassword");
		focusElement.focus();
		
		//document.register-user-form.signature.focus();
	},
	
	showAnswerAlertsActivationForm: function(emailAddress) {
		
		
		
		
		
		DBM.module.Comments.hideAds();
		
		
		DBM.module.Comments.myPanel = new YAHOO.widget.Panel("myPanel", { 
			width:"400px",
			fixedcenter:true, 
			visible:false,
			close:false, 
			constraintoviewport:true, 
			draggable:true,
			zindex:999,
			modal:true
		});

		var html = YAHOO.util.Dom.get("activate-answer-alerts-container").innerHTML;
		DBM.module.Comments.answerAlertsHTML = html;
		YAHOO.util.Dom.get("activate-answer-alerts-container").innerHTML = '';
		DBM.module.Comments.myPanel.setBody(html);
		DBM.module.Comments.myPanel.render(document.body);
		
		/*var loginEmail = YAHOO.util.Dom.get('loginEmail');
		if (loginEmail) {
			loginEmail.value = emailAddress;
		}*/
		
		DBM.module.Comments.myPanel.show();

		//document.register-user-form.signature.focus();
	},
	
	registerUserCallback: {
		success: function(o) {
			

			// REMOVE
			//DBM.module.Comments.showVerificationCode(this.argument.emailAddress, "123abc0000003", this.argument.cellNo);
			//return true;
			DBM.module.Common.defaultCallback.success(o);

			response = eval ( "(" + o.responseText + ")" );

			document.getElementById("signature-err").innerHTML = "";
			document.getElementById("password-err").innerHTML = "";
			document.getElementById("cell-no-err").innerHTML = "";
			document.getElementById("terms-err").innerHTML = "";
			//alert(o.responseText);
			if (response.userid != null) {
				userId = response.userid;
				
				DBM.module.Comments.showVerificationCode(this.argument.emailAddress, userId, this.argument.cellNo);
			}
			else if (response.errors) {

				for ( var i=0, len=response.errors.length; i<len; ++i ){

					if (response.errors[i] == 504 || response.errors[i] == 516) {
						document.getElementById("cell-no-err").innerHTML = "Skriv inn et gyldig mobilnummer";
					}
					else if (response.errors[i] == 506 || response.errors[i] == 515 || response.errors[i] == 514  ) {

						document.getElementById("signature-err").innerHTML = "Skriv inn navnet ditt";
					}
					else if (response.errors[i] == 503) {
						document.getElementById("password-err").innerHTML = "Skriv inn et passord";
					}
					else if (response.errors[i] == 505) {
						document.getElementById("terms-err").innerHTML = "Les og godkjenn";
					}
					else if (response.errors[i] == 405) {
						document.getElementById("cell-no-err").innerHTML = "Mobilnummeret er sperret for bruk på Dagbladet.no";
					}
					
				}

			}
			else {
				alert("Noe gikk galt");
			}
			
		},  	
		failure: function(o) {
			DBM.module.Common.defaultCallback.failure(o);
			//alert("Feil ved registrering/innlogging. Vennligst prøv igjen, eller ta kontakt med support@dagbladet.no.");
		},  	
		timeout: DBM.module.Common.timeout,
		argument: {emailAddress: "", signature: "", cellNo: ""} 	
	},
	
	registerUser: function() {

		// OLD
		var signature = document.getElementById("signature").value;
		
		// NEW
		var firstname = document.getElementById("signature").value;
		var lastname = document.getElementById("signature-lastname").value;
		var emailAddress = document.getElementById("email").value;
		var cellNo = document.getElementById("cell-no").value;
		var cellNoPrefix = encodeURIComponent(document.getElementById("cell-no-prefix").value);
		var pwd = document.getElementById("password").value;
		
		var terms = document.getElementById("terms").checked;
	
		
		this.registerUserCallback.argument.emailAddress = emailAddress;
		this.registerUserCallback.argument.cellNo = cellNo;
		this.registerUserCallback.argument.signature = signature;
		
		//var url = "http://www.dagbladet.no/konto/"; 
		//var postVars = "op=RegisterUser&response=json&serviceid=101&register_email=" + emailAddress + "&name=" + signature + "&cell=" + cellNo + "&register_password=" + pwd;
		var postVars = "op=RegisterUser&response=json&serviceid=101&register_email=" + emailAddress + "&firstname=" + firstname + "&lastname=" + lastname + "&cell=" + cellNo + "&prefix=" + cellNoPrefix + "&register_password=" + pwd;
		if (terms) {
			postVars = postVars + "&terms=1";
		}
		
		//YAHOO.util.Connect.setDefaultPostHeader(false);
		//YAHOO.util.Connect.initHeader("Content-Type","application/x-www-form-urlencoded; charset=ISO-8859-1");
		var tId = YAHOO.util.Connect.asyncRequest('POST', DBM.module.Comments.authUrl, this.registerUserCallback, postVars);
		DBM.module.Common.addRequest(tId, DBM.module.Comments.authUrl, DBM.module.Comments.registerUserCallback, '',  '', "POST");
	},
	
	
	loginUserCallback: {
		success: function(o) {
			
			// REMOVE
			//DBM.module.Comments.showVerificationCode(this.argument.emailAddress, "123abc0000003", this.argument.cellNo);
			//return true;
			DBM.module.Common.defaultCallback.success(o);
			response = eval ( "(" + o.responseText + ")" );


			if (response.userid != null) {
				
				var token = document.getElementById("outputConfirmationToken").innerHTML;
				var userId = document.getElementById("loginEmail").value;
				var emailAddress = document.getElementById("outputMailbackAddress").innerHTML;
				DBM.module.Comments.activateComment(token, emailAddress, false);
				
			}
			else if (response.errors) {
				for ( var i=0, len=response.errors.length; i<len; ++i ){

					if (response.errors[i] == 403) {
						document.getElementById("password-login-err").innerHTML = "Feil e-post/passord";
					}
					else if (response.errors[i] == 407) {
						DBM.module.Comments.showConfirmSubscriptionForm();
					}
					
				}
			}
			
			/*if (response.registered == 700 && response.uid != null) {
				userId = response.uid;
				
				DBM.module.Comments.showVerificationCode(this.argument.emailAddress, userId, this.argument.cellNo);
			}
			else if (response.errors) {
				
				for ( var i=0, len=response.errors.length; i<len; ++i ){

					if (response.errors[i] == 505) {
						document.getElementById("cell-no-err").innerHTML = "Skriv inn et gyldig mobilnummer";
					}
					else if (response.errors[i] == 506) {
						document.getElementById("signature-err").innerHTML = "Skriv inn navnet ditt";
					}
					else if (response.errors[i] == 503) {
						document.getElementById("password-err").innerHTML = "Skriv inn et passord";
					}
					else if (response.errors[i] == 510) {
						document.getElementById("terms-err").innerHTML = "Du må lese og godkjenne brukeravtalen og personvernavtalen";
					}
					
				}

			}
			else {
				alert("Noe gikk galt");
			}*/
			
		},  	
		failure: function(o) {
			DBM.module.Common.defaultCallback.failure(o);
			//alert("Feil ved registrering/innlogging. Vennligst prøv igjen, eller ta kontakt med support@dagbladet.no.");
		},  	
		timeout: DBM.module.Common.timeout,
		argument: {emailAddress: "", signature: "", cellNo: ""} 	
	},
	
	loginUser: function() {

		var emailAddress = document.getElementById("loginEmail").value;
		var pwd = document.getElementById("loginPassword").value;

		DBM.module.Comments.varEmail = emailAddress;
		DBM.module.Comments.varPassword = pwd;
		
		
		this.loginUserCallback.argument.emailAddress = emailAddress;
		
		//var url = "http://www.dagbladet.no/konto/"; 
		//var postVars = "op=LoginUser&response=json&serviceid=101&username=" + emailAddress + "&password=" + pwd;
		// PAYMENT
		var postVars = "op=LoginSubscribe&response=json&serviceid=101&username=" + emailAddress + "&password=" + pwd;
		var tId = YAHOO.util.Connect.asyncRequest('POST', DBM.module.Comments.authUrl, this.loginUserCallback, postVars);
		DBM.module.Common.addRequest(tId, DBM.module.Comments.authUrl, DBM.module.Comments.loginUserCallback, '',  '', "POST");
	},
	
	showHideTerms: function(type) {
		
		

		DBM.module.Comments.termsPanel = new YAHOO.widget.Panel("termsPanel", { 
			width:"350px", 
			height:"350px", 
			visible:false,
			close:true, 
			fixedcenter:true, 
			constraintoviewport:true, 
			zindex:999
		});
		//DBM.module.Comments.myPanel.setHeader("Hei, du er ikke registrert hos oss ennå!");
		
	
		if (type == 'user'){
			var html = YAHOO.util.Dom.get("user-terms").innerHTML;	
		}
		else {
			var html = YAHOO.util.Dom.get("privacy-terms").innerHTML;
		}
		
		
		DBM.module.Comments.termsPanel.setBody(html);
		DBM.module.Comments.termsPanel.render(document.body);
		DBM.module.Comments.termsPanel.show();
		
		
		/*if (type == 'user') {
			if (YAHOO.util.Dom.hasClass("user-terms", "absolute-hidden")) {
				YAHOO.util.Dom.removeClass("user-terms", "absolute-hidden");
				YAHOO.util.Dom.addClass("privacy-terms", "absolute-hidden");
			}
			else {
				YAHOO.util.Dom.addClass("user-terms", "absolute-hidden");
				YAHOO.util.Dom.addClass("privacy-terms", "absolute-hidden");
			}
		}
		else if (type == 'privacy') {
			if (YAHOO.util.Dom.hasClass("privacy-terms", "absolute-hidden")) {
				YAHOO.util.Dom.removeClass("privacy-terms", "absolute-hidden");
				YAHOO.util.Dom.addClass("user-terms", "absolute-hidden");
			}
			else {
				YAHOO.util.Dom.addClass("privacy-terms", "absolute-hidden");
				YAHOO.util.Dom.addClass("user-terms", "absolute-hidden");
			}
		}*/
		
		return false;
	},
	
	abortMission: function() {
		
		var commentId = document.getElementById("outputCommentId");
		var discussionId = document.getElementById("outputDiscussionId");
			  	
	  	if (commentId && discussionId) {
			
	  		commentId = commentId.innerHTML;
	  		discussionId = discussionId.innerHTML;
			var url = DBM.module.Common.rootUrl +  DBM.module.Comments.modulePath + "/?op=DeleteUnverifiedComment&id=" + commentId + "&discussionId=" + discussionId;
			var tId = YAHOO.util.Connect.asyncRequest('GET', url, this.abortMissionCallback);
			DBM.module.Common.addRequest(tId, url, DBM.module.Comments.abortMissionCallback, '',  '', "GET");
	  	}
	},
	
	abortMissionCallback: {
		success: function(o) {
			
			// REMOVE
			//DBM.module.Comments.showVerificationCode(this.argument.emailAddress, "123abc0000003", this.argument.cellNo);
			//return true;
			DBM.module.Common.defaultCallback.success(o);
			response = eval ( "(" + o.responseText + ")" );

			//alert(o.responseText);
			
			if (response.commentDeleted) {

				DBM.module.Comments.myPanel.hide();
				
				if (DBM.module.Comments.mobileVerificationHTML != undefined) {
					YAHOO.util.Dom.get("mobile-verification").innerHTML = DBM.module.Comments.mobileVerificationHTML;
				}
				
				if (DBM.module.Comments.loginHTML != undefined) {
					YAHOO.util.Dom.get("login-container").innerHTML = DBM.module.Comments.loginHTML;
				}
				
				/*YAHOO.util.Dom.addClass("mobile-verification", "absolute-hidden");
				YAHOO.util.Dom.addClass("privacy-terms", "absolute-hidden");
				YAHOO.util.Dom.addClass("user-terms", "absolute-hidden");*/
				YAHOO.util.Dom.addClass('preview-entry', 'invisible');
				//YAHOO.util.Dom.addClass('login-container', 'absolute-hidden');
				
				/*var y = document.getElementById("mask");
				document.getElementById("doc").removeChild(y);*/
				
				
		
				var preview = YAHOO.util.Dom.get('preview-entry');
				preview.style.height = '0px';
				preview.style.minHeight = '0px';
				
				
				YAHOO.util.Dom.addClass('preview-entry', 'absolute-hidden');
				

				var alertBox = YAHOO.util.Dom.get("yellow_box");
				if (alertBox) {
					//alert(this.argument.abortType);
					if (this.argument.abortType == 'endSubscription') {
						alertBox.innerHTML = '<h2>Brukeren din er nå stoppet.</h2>' + 
     										'<p>Vi håper du kommer tilbake og bidrar på Dagbladet.no senere. Har du spørsmål om betalingen eller andre ting, er du hjertelig velkommen til å ta kontakt med oss via support@dagbladet.no</p>';
					}
					else {
						alertBox.innerHTML = '<h2>Var du ikke helt fornøyd med innlegget ditt?</h2>' + 
     										'<p>Innlegget ditt er slettet, men vi håper du tar deg tid til å <a href="#comments_form_container">skrive et nytt</a>. Vi vil veldig gjerne høre fra deg, hvis du har noe å bidra med.</p>';
					}
				}
				
				YAHOO.util.Dom.removeClass("yellow_box", "absolute-hidden");
				var anim2 = new YAHOO.util.Anim(  
							'yellow_box' ,   
							{ opacity: {from: 0, to: 1 } },   
							2,   
							YAHOO.util.Easing.easeOut 
							); 
				anim2.animate();

				DBM.module.Comments.insertCommentsForm(response.discussionId, "comments_form_container");
				
			}
			
		},  	
		failure: function(o) {
			DBM.module.Common.defaultCallback.failure(o);
		},  	
		timeout: DBM.module.Common.timeout,
		argument: {commentId: "", abortType: ""} 	
	},
	
	
	abortUserAndMission: function() {
		
		var userId = document.getElementById("userId");
		if (userId) {
			userId = userId.value;	
		}

	  	if (userId) {
			//var url = "http://www.dagbladet.no/konto/?op=AbortUser&userid=" + userId + "&response=json";
			var url = DBM.module.Comments.authUrl + "?op=AbortUser&userid=" + userId + "&response=json";
			var tId = YAHOO.util.Connect.asyncRequest('GET', url, this.abortUserAndMissionCallback);
			DBM.module.Common.addRequest(tId, url, DBM.module.Comments.abortUserAndMissionCallback, '',  '', "GET");
	  	}
	},
	
	abortUserAndMissionCallback: {
		success: function(o) {
			
			// REMOVE
			//DBM.module.Comments.showVerificationCode(this.argument.emailAddress, "123abc0000003", this.argument.cellNo);
			//return true;

			DBM.module.Common.defaultCallback.success(o);
			response = eval ( "(" + o.responseText + ")" );

			
			
			if (response.aborted) {
				DBM.module.Comments.abortMission();
			}
			
		},  	
		failure: function(o) {
			DBM.module.Common.defaultCallback.failure(o);
		},  	
		timeout: DBM.module.Common.timeout,
		argument: {commentId: ""} 	
	},

	
	nl2br: function(text){
		text=escape(text);
		return unescape(text.replace(/(%5Cr%5Cn)|(%5Cn%5Cr)|%5Cr|%5Cn/g,'<br />'));
	},

	
	updateSignature: function() {
		var source = YAHOO.util.Dom.get("signature");
		var source2 = YAHOO.util.Dom.get("signature-lastname");

		var target = YAHOO.util.Dom.get("preview-user-name");
		//var target2 = YAHOO.util.Dom.get("preview-user-name-suffix");
		target.innerHTML = source.value + ' ' + source2.value;
		//target2.innerHTML = ", " + source.value.substr(0,6);
	}, 
	
	
	cell_url: "http://www.dagbladet.no/konto/",
	//cell_url: DBM.module.Comments.authUrl,


	showNewCell: function(){
		//var cell = document.getElementById('newcell');
		//cell.style.display = 'block';	

		DBM.module.Comments.newCellPanel = new YAHOO.widget.Panel("termsPanel", { 
			width:"350px", 
			height:"150px", 
			visible:false,
			close:true, 
			fixedcenter:true, 
			constraintoviewport:true, 
			zindex:999
		});
		//DBM.module.Comments.myPanel.setHeader("Hei, du er ikke registrert hos oss ennå!");
		
		var html = YAHOO.util.Dom.get("newcell").innerHTML;
		
		
		DBM.module.Comments.newCellHtml = html;
		YAHOO.util.Dom.get("newcell").innerHTML = '';
		DBM.module.Comments.newCellPanel.setBody(html);
		DBM.module.Comments.newCellPanel.render(document.body);
		DBM.module.Comments.newCellPanel.show();
			
	},
	
	
	hideNewCell: function(){
		if (DBM.module.Comments.newCellHtml) {
			YAHOO.util.Dom.get("newcell").innerHTML = DBM.module.Comments.newCellHtml;
		}
		//var cell = document.getElementById('newcell');
		//cell.style.display = 'none';
		DBM.module.Comments.newCellPanel.hide();
	},

		
	sendCode: function(serviceid, verificationid, newcell){
		
		var loadingDiv = 'loader';
		var target = 'op=SendCommentVerification';
		
		DBM.util.createDiv(loadingDiv,  DBM.module.Common.defaultLoadingHTML);
				
		if (newcell) {
			var cell_input = document.getElementById('newcellno');
			var newcell = cell_input.value;	
			//var urlparams = this.cell_url+'?'+target+'&serviceid='+serviceid+'&verificationid='+verificationid+'&cell='+newcell;
			var urlparams = DBM.module.Comments.authUrl+'?'+target+'&serviceid='+serviceid+'&verificationid='+verificationid+'&cell='+newcell;
		} else {
			//var urlparams = this.cell_url+'?'+target+'&serviceid='+serviceid+'&verificationid='+verificationid;	
			var urlparams = DBM.module.Comments.authUrl+'?'+target+'&serviceid='+serviceid+'&verificationid='+verificationid;	
		}
		var res = YAHOO.util.Connect.asyncRequest('GET', urlparams, this.sendCodeCallback);	
		this.hideNewCell();

		return false;
	},
	
	
	sendCodeCallback: { 
		
		success: function(o) {
			var message = document.getElementById('verification-err');
			var loader = document.getElementById('loader');
			var infolabel = document.getElementById('verificationLabel');
			
			if (o.responseText.length  > 0) {
				var obj = eval('('+o.responseText+')');
	
//				if (message) {
//					message.style.display = 'block';	
//					message.className ='';		
//					message.innerHTML = '';	
//				}
	
	
				infolabel.innerHTML = '';
				
				if (obj.success) {
					message.className = 'ok';
					
					if (obj.newcell) {
						message.innerHTML = '<div id="oktext">Nå har vi skifet telefon til <strong>'+obj.newcell+'</strong> og send deg en ny kode</div>';
					} else if (obj.cell)  {
						message.innerHTML = '<div id="oktext">Nå har vi sendt deg en ny kode til <strong>'+obj.cell+'</strong></div>';
					}  else {
						message.innerHTML = '<div id="oktext">Nå har vi sendt deg en ny kode!</div>';
					}		
					
				} else {
					
					message.className = 'error';
 					if (obj.errors){
 						
// 						if (obj.newcell) {
//							vstring.value = obj.newcell;
//							refcell.innerHTML = '<strong>'+obj.newcell+'</strong>';
//						}
 						
 						if (obj.errors == 504) {
 							message.innerHTML = '<div id="errortext">Det mobilnummeret hadde ikke 8 siffer.</div>';
 						} else if (obj.errors == 405) {
 							message.innerHTML = '<div id="errortext">Mobilnummeret du prøver å registere er sperret for bruk på Dagbladet.no.</div>';
 						} else if (obj.errors == 200) {
 							message.innerHTML = '<div id="errortext">Nå har du prøvd litt for mange ganger. Vent litt før du prøver igjen.</div>';
 						} else {
 							message.innerHTML = '<div id="errortext">Det oppsto en feil under sending av ny kode. Prøv en gang til.</div>';
 						}
 										
 					} else{
						message.innerHTML = '<div id="errortext">Det oppsto en feil under sending av ny kode. Prøv en gang til.</div>';	
 					}
				}	
			}
			
			loader.innerHTML = '';	
		
			return false;
		}, 
		
		failure: function(o) {
		 	
		 	if (o.status == 404){
		 		alert('Ajax call target not found! (404)');
		 	} 
			
			return false;
		},
		timeout: DBM.module.Common.timeout
	},
	
	showForgottenPass: function(){
		
		//var cell = document.getElementById('newcell');
		//cell.style.display = 'block';	

		DBM.module.Comments.forgottenPassPanel = new YAHOO.widget.Panel("termsPanel", { 
			width:"350px", 
			height:"150px", 
			visible:false,
			close:true, 
			fixedcenter:true, 
			constraintoviewport:true, 
			zindex:999
		});
		//DBM.module.Comments.myPanel.setHeader("Hei, du er ikke registrert hos oss ennå!");
		
		var html = YAHOO.util.Dom.get("forgottenPass").innerHTML;
		
		
		DBM.module.Comments.forgottenPassHtml = html;
		YAHOO.util.Dom.get("forgottenPass").innerHTML = '';
		DBM.module.Comments.forgottenPassPanel.setBody(html);
		DBM.module.Comments.forgottenPassPanel.render(document.body);
		DBM.module.Comments.forgottenPassPanel.show();
			
	},
	
	
	hideForgottenPass: function(){
		if (DBM.module.Comments.forgottenPassHtml) {
			YAHOO.util.Dom.get("forgottenPass").innerHTML = DBM.module.Comments.forgottenPassHtml;
		}
		//var cell = document.getElementById('newcell');
		//cell.style.display = 'none';
		DBM.module.Comments.forgottenPassPanel.hide();
	},
	
	
	switchContent: function(elementId, contentHTML){

		if (DBM.module.Comments.switchedContent.length <= 0) {
			DBM.module.Comments.switchedContent = new Array();	
		}
		
		
		
		if (DBM.module.Comments.switchedContent[0]) {

			var content = DBM.module.Comments.switchedContent[0];

		}
		else {
			
			var content = new DBM.util.switchedContent(elementId, contentHTML);
			DBM.module.Comments.switchedContent[0] = content;
		}
		

		var el = YAHOO.util.Dom.get(elementId);
		
		if (el) {
			if (content.switched) {

				el.innerHTML = content.originalContent;
				content.switched = false;
				DBM.module.Comments.switchedContent[0].switched = false;
				DBM.module.Comments.switchedContent = new Array();	
			}
			else {

				el.innerHTML = content.replacementHTML;
				content.switched = true;
				DBM.module.Comments.switchedContent[0] = content;
				
				
			}
			
		}
		else {
			
		}
		
		return true;
		
	},

		
	resetPassword: function(serviceid, email){
		
		var loadingDiv = 'loader';
		var target = 'op=LostPassword&response=json';
		
		DBM.util.createDiv(loadingDiv,  DBM.module.Common.defaultLoadingHTML);
				
		if (email) {
			var emailInput = document.getElementById('loginEmail');
			var emailAddress = emailInput.value;
			if (emailAddress) {	
				//var urlparams = this.cell_url+'?'+target+'&sid='+serviceid+'&lost_email='+emailAddress;
				var urlparams = DBM.module.Comments.authUrl+'?'+target+'&sid='+serviceid+'&lost_email='+emailAddress;
				
				var res = YAHOO.util.Connect.asyncRequest('GET', urlparams, this.resetPasswordCallback);	
				alert("Vent noen sekunder, og du skal ha fått tilsendt et nytt passord på mobilen din. Bruk det for å logge inn.");
			}
			else {
				alert("Feil: Du har ikke skrevet inn e-postadressen din.");	
			}
			this.hideForgottenPass();
		} 
		else {
			
		}

		return false;
	},
	
	
	resetPasswordCallback: { 
		
		success: function(o) {
			var message = document.getElementById('verification-err');
			var loader = document.getElementById('loader');
			var infolabel = document.getElementById('verificationLabel');
			
			if (o.responseText.length  > 0) {
				var obj = eval('('+o.responseText+')');
	
//				if (message) {
//					message.style.display = 'block';	
//					message.className ='';		
//					message.innerHTML = '';	
//				}
	
	
				infolabel.innerHTML = '';
				
				if (obj.code) {
					message.className = 'ok';
					
					//alert("Du får et nytt passord tilsendt på mobilen din i løpet av noen sekunder. Bruk det for å logge inn.");
					
				} else {
					
					alert("Det oppstod en feil. Vennligst sjekk at e-postadressen din er skrevet riktig, og prøv igjen. Har du fortsatt problemer, kan du ta kontakt på support@dagbladet.no.");
				}	
			}
			
			loader.innerHTML = '';	
		
			return false;
		}, 
		
		failure: function(o) {
		 	
		 	if (o.status == 404){
		 		alert('Ajax call target not found! (404)');
		 	} 
			
			return false;
		},
		timeout: DBM.module.Common.timeout
	}

}	

DBM.util.switchedContent = function(elementId, replacementHTML) {

	this.elementId = elementId;
	this.replacementHTML = replacementHTML;
	
	var el = YAHOO.util.Dom.get(elementId);
	if (el) {
		this.originalContent = el.innerHTML;
	}
	else {
		this.originalContent = "";	
	}
	this.switched = false;
}

