var previewComment = function()
{
	comment_body = $('comment_preview_inner');
	comment_author = $('preview_name');

	body_text = $('root_comment_text').value;
	re= /<\S[^>]*>/g; 
	body_text = body_text.replace(re,"");

	comment_body.innerHTML = body_text.replace( /\r|\n/g, '<br \/>' );
	//comment_author.innerHTML = $('comment_author').value;

	HuffPoUtil.show( 'comment_preview' );
	HuffPoUtil.hide( 'comment_meta' );
};

var previewCommentForReply = function(cmt_id)
{
	comment_body = $('comment_preview_inner_' + cmt_id);
	comment_author = $('preview_name_' + cmt_id);

	body_text = $('comment_text_' + cmt_id).value;
	re= /<\S[^>]*>/g; 
	body_text = body_text.replace(re,"");

	comment_body.innerHTML = body_text.replace( /\r|\n/g, '<br \/>' );
	//comment_author.innerHTML = $('comment_author').value;

	HuffPoUtil.show( 'comment_preview_' + cmt_id );
	HuffPoUtil.hide( 'comment_meta_' + cmt_id );
};

var current_comment_parent 		= null;
var current_reply_parent 		= null;
var last_response 				= null;
var replies_loading 			= false;

var update_comments_obj 		= null;
var update_comments_entry_id 	= null;
var update_comments_all_parents	= null;
var update_comments_end_parent	= null;
var update_comments_target		= null;
var update_comments_loaded		= new Array();
var update_comments_loading		= new Array();
var update_comments_last_loading= null;

var childrensRequestHandler = {
	success: function(o) {
		$('comment_children_' + current_comment_parent).style.paddingLeft = '0px';
		$("comment_children_" + current_comment_parent).innerHTML = o.responseText;
		
		if (replies_loading && current_reply_parent) {
			Comments.addCommentAsReply(current_reply_parent);
			replies_loading = false;
			current_reply_parent = null;
		}
	},
	failure: function(o) {
		$("comment_children_" + current_comment_parent).innerHTML = "Sorry, we couldn't load comments for some reason. Try reloading the page.";
	}
};

var allChildrensRequestHandler = {
	success: function(o) {
		$('comment_children_' + update_comments_target).style.paddingLeft = '0px';
		$("comment_children_" + update_comments_target).innerHTML = o.responseText;
		
		if (update_comments_obj != null) {
			setTimeout("update_comments_loaded.push(update_comments_last_loading); Comments.success(update_comments_obj);", 500);
		}
	},
	failure: function(o) {
		$("comment_children_" + update_comments_obj).innerHTML = "Sorry, we couldn't load comments for some reason. Try reloading the page.";
	}
};

var toggleChildrens = function(parent_id, entry_id, level)
{
	current_comment_parent = parent_id;
	childs = $('comment_children_' + parent_id);
	if ( typeof childs=='undefined' ) return false;
	
	if ( childs.style.display == 'none' )
	{
		spinnerHtml = $('comment_spinner_replies').innerHTML;
		$('comment_children_' + parent_id).innerHTML = spinnerHtml;
		$('comment_children_' + parent_id).style.paddingLeft = level * 22 + 'px';
		HuffPoUtil.show( 'comment_children_' + parent_id );
		HuffPoUtil.hide( 'show_view_reply_link_' + parent_id );
		D.setStyle('hide_view_reply_link_' + parent_id, 'display', 'inline');
		var coch = YAHOO.util.Connect.asyncRequest('GET', '/include/just_threaded_comments_html.php?entry_id=' + entry_id + '&level=' + level + '&comment_parent=' + parent_id, childrensRequestHandler);
	}
	else if ( childs.style.display == 'block' )
	{
		$('comment_children_' + parent_id).innerHTML = '';
		HuffPoUtil.hide( 'comment_children_' + parent_id );
		HuffPoUtil.hide( 'hide_view_reply_link_' + parent_id );
		$('show_view_reply_link_' + parent_id).style.display = 'inline';
	}
	return true;
};

var loadAllParents = {
	success: function(o) {
		if (o.responseText=='' || o.responseText==0) return;
		
		update_comments_all_parents = o.responseText;
		pids = o.responseText.split(';');
		pln=pids.length;
		if (pln==0) {
			return;
		}
		end_level = pids[pln-1].split(":")[1];
		
		for (i=0; i < pln; i++) {
			curp = pids[i].split(":");
			cur_pid = curp[0];
			cur_level = curp[1];
			div_ch = $('comment_children_' + cur_pid);
			if (div_ch != null && typeof  div_ch != 'undefined' && div_ch.innerHTML == '') {
				update_comments_target = cur_pid;
				toggleAllChildrens(cur_pid, cur_level, end_level);
				return true;
			}
		}
		return false;
	},
	failure: function(o) {
		
	}
};

var toggleAllChildrens = function(parent_id, level, end_level)
{
	spinnerHtml = $('comment_spinner_replies').innerHTML;
	$('comment_children_' + parent_id).innerHTML = spinnerHtml;
	$('comment_children_' + parent_id).style.paddingLeft = level * 22 + 'px';
	HuffPoUtil.show( 'comment_children_' + parent_id );
	HuffPoUtil.hide( 'show_view_reply_link_' + parent_id );
	D.setStyle('hide_view_reply_link_' + parent_id, 'display', 'inline');
	var coch = YAHOO.util.Connect.asyncRequest('GET', '/include/just_threaded_comments_html.php?update=1&entry_id=' + update_comments_entry_id + '&level=' + level + '&comment_parent=' + parent_id + '&end_level=' + end_level + '&new_comment_id=' + update_comments_last_loading + '&all_parents=' + update_comments_all_parents, allChildrensRequestHandler);
};

var Comments = {
	maxWords: 350,
	
	collapseComment: function(id) {
		if ( $('cmt_txt_wrap_'+id) ) { 
			if ( $('cmt_txt_wrap_'+id).style.display != 'none' )
				$('cmt_txt_wrap_'+id).style.display = 'none';
			else this.expandComment(id);
		}
	},
	
	expandComment: function(id) {
		if ( $('cmt_txt_wrap_'+id) ) { 
			if ( $('cmt_txt_wrap_'+id).style.display != 'block' )
				$('cmt_txt_wrap_'+id).style.display = 'block';
			else this.collapseComment(id);
		}
	},
	
	// returns 0 for okay length or n, where n is the number of words too long
	lengthOkay: function(el) {
		over = 0;
		this.trimmed = $(el).value;

		if ( this.trimmed.match(/\S/) )
		{
			this.trimmed = this.trimmed.replace(/^[\s._\-*+&?\/\\]+/, '');
			this.trimmed = this.trimmed.replace(/[\s._\-*+&?\/\\]$/, '');
		}

		this.chunkedText = this.trimmed.split(/[\s._\-*+&?\/\\]+/);

		if (this.chunkedText.length > this.maxWords)
			return (this.chunkedText.length - this.maxWords);
		else if (this.trimmed == '' || !$(el).value || $(el).value == '')
			// no text
			return -1;
		else
			// okay
			return 0;
	},
	
	alertEmpty: function() {
		alert("Your comment is empty. Please type a comment, then click POST again.");
	},
	
	alertTooLong: function(over) {
		alert("Your comment is too long by " + over + " " + (over == 1 ? 'word' : 'words') + ". The maximum length is " + this.maxWords + " words. Please edit your comment and click POST again.");
	},
	
	replyClick: function(cmt_id, entry_id, level) {
		reply_form_div = $('reply_form_' + cmt_id);
		if (!reply_form_div || typeof reply_form_div=='undefined') return false;
		if (reply_form_div.style.display=='block') {
			reply_form_div.style.display = 'none';
			return true;
		}
		
		if ( $('comment_spinner_replies') ) {
			reply_form_div.innerHTML = $('comment_spinner_replies').innerHTML;
			reply_form_div.style.display = 'block';
		}
			
		var cof = YAHOO.util.Connect.asyncRequest('GET', '/extensions/comments/comment/commentForm.php?comment_id=' + cmt_id + '&entry_id=' + entry_id + '&level=' + level , this.replyClickCallback);
		return true;
	},
	
	replyClickCallback: {
		success: function(o) {
			if (o.responseText=='') return;
			
			splits = o.responseText.split(':::');
			cmt_id = splits[1];
			reply_html = splits[0];
			
			reply_form_div = $('reply_form_' + cmt_id);
			if (!reply_form_div || typeof reply_form_div=='undefined') return;
			
			reply_form_div.innerHTML = reply_html;
			reply_form_div.style.display = 'block';
			
			if (getCookie('_dick_cookie_username')) {
				$('q_reply_form_'+cmt_id+'').style.display = 'block';
				$('q_login_form_'+cmt_id+'').style.display = 'none';
			}
			
			$('comment_author_'+cmt_id+'').innerHTML = getCookie('_dick_cookie_username');
			$('loggin_as_'+cmt_id+'').innerHTML = getCookie('_dick_cookie_username');

		},
		failure: function() {
			
		}
	},
	
	// posts a new root-level comment
	addComment: function() {
		update_comments_entry_id = null;
		var over = this.lengthOkay('root_comment_text');
		if (over == 0) {
			$('post_button_new').disabled = true;
			HuffPoUtil.hide('post_button_new');
	        if ( $('post_spinner_new') ) $('post_spinner_new').style.display = 'inline';
			YAHOO.util.Connect.setForm('comments_form_new');
			var co = YAHOO.util.Connect.asyncRequest('POST','/extensions/comments/comment/postComment.php', this.addCommentCallback);
												
		} else if (over > 0) {
			this.alertTooLong(over);
		} else if (over < 0)
			this.alertEmpty();
												
	},
	
	addCommentCallback: {
		success: function(o) {
			if (o.responseText == '' || o.responseText == 0) return;
			if (o.responseText == '___failure___') {
				this.failure();
				return;
			}
			splits   = o.responseText.split(':::');
			new_html = splits[0];
			is_new	 = splits[1] == 'new' ? true : false;
			
			cmt_id   = splits[2];
			cmt_entry_id = splits[3];
			var cmt_count_update='';
			if (splits[4]) cmt_count_update = splits[4];
			
			if (is_new) {
				var el = $('comments_inner');
				if($('root_comment_text')) $('root_comment_text').value  = '';
				Fat.fade_element('comment_' + cmt_id);
				
				if (cmt_count_update && cmt_count_update==1) document.getElementById('lastComment').innerHTML=cmt_id;
				el.innerHTML = new_html+el.innerHTML;
				
				if (update_comments_entry_id == null || update_comments_entry_id == '' || !update_comments_entry_id) Comments.scrollToComment(cmt_id);
				document.getElementById('replyFlag').innerHTML='1';
				HuffPoUtil.hide('comment_preview');
				
				if($('post_button_new')) $('post_button_new').style.display = 'inline';
				if($('post_button_new')) $('post_button_new').disabled = false;
	        	if ( $('post_spinner_new') ) $('post_spinner_new').style.display = 'none';
			}
			
		},
		failure: function() {
			alert('Sorry, problems... Please try later');
		}
	},

	addCommentMy: function(entry_id, last) {
		//var h = Math.random();
		var h =''; //let's get rid of cache-busting for now
		update_comments_entry_id = entry_id;
		document.getElementById('replyFlag').innerHTML='1';
		var co = YAHOO.util.Connect.asyncRequest('GET', '/extensions/comments/comment/checkNewComments.php?entry_id='+entry_id+'&last='+last+'&hash='+h, this);
	},

	addCommentAsReply: function(parent_id, entry_id, level) {
		var over = this.lengthOkay('comment_text_' + parent_id);
		if (over == 0) {
			$('post_button_' + parent_id).disabled = true;
			HuffPoUtil.hide('post_button_' + parent_id);
	        D.setStyle('post_spinner_' + parent_id, 'display', 'inline');
			YAHOO.util.Connect.setForm('comments_form_' + parent_id);
			var co = YAHOO.util.Connect.asyncRequest('POST', '/extensions/comments/comment/postComment.php', this.addCommentAsReplyCallback);
												
		} else if (over > 0) {
			this.alertTooLong(over);
		} else if (over < 0)
			this.alertEmpty();
	},
	
	addCommentAsReplyCallback: {
		success: function(o) {
			if (o.responseText=='') return;
			splits = o.responseText.split(':::');
			if (splits[0]!='reply') return;
			parent_id = splits[1];
			if ( $('reply_form_' + parent_id) ) $('reply_form_' + parent_id).style.display = 'none';
			RepliesPager.load('last', parent_id);
		},
		failure: function() {
			
		}
	},
	
	scrollToComment: function(id) {
		scrollToAnchor('comment_' + id);
	},
	
	scrollToParent: function(id) {
		this.scrollToComment(id);
		Fat.fade_element('comment_' + id, 30, 1000);
	},
	
	// callbacks
	success: function(o) {
		if (o.responseText=='' || o.responseText==0) return;

		splits   = o.responseText.split(':::');
		new_html = splits[0];
		
		is_new	 = splits[1] == 'new' ? true : false;
		
		if (!is_new)
			var cmt_parent_id = Math.floor(splits[1]) + 0; // force to int
			
		cmt_id   = splits[2];
		cmt_entry_id = splits[3];
		var cmt_count_update='';
		if (splits[4]) cmt_count_update = splits[4];
		
		if (!is_new) {
			// comment is in reply to a parent comment
			var el = $('comment_children_' + cmt_parent_id);
			//alert(el);
			if ( (el==null || typeof el=="undefined" || el.innerHTML=='') && !update_comments_loading.inArray(cmt_id) ) {
				update_comments_obj = o;
				update_comments_end_parent = cmt_parent_id;
				update_comments_loading.push(cmt_id);
				update_comments_last_loading = cmt_id;

				var cupd = YAHOO.util.Connect.asyncRequest('GET','/extensions/comments/comment/getAllParents.php?entry_id=' + update_comments_entry_id + '&last_parent=' + cmt_parent_id, loadAllParents);
				return;
			} else if ( (el==null || typeof el=="undefined") && !update_comments_loaded.inArray(cmt_id) ) {
				return;
			}else if ( (el==null || typeof el=="undefined") )
				return;
				
			if (update_comments_obj != null && typeof update_comments_obj != 'undefined') {
				if (update_comments_obj.responseText == o.responseText) {
					update_comments_obj = null;
				}
			}
			
			if($('post_button_' + cmt_parent_id)) $('post_button_' + cmt_parent_id).disabled  = false;
			if($('comment_text_' + cmt_parent_id)) $('comment_text_' + cmt_parent_id).value      = '';  
			
			if($('post_button_' + cmt_parent_id)) D.setStyle('post_button_' + cmt_parent_id, 'display', 'inline');
			
	        D.setStyle('post_spinner_' + cmt_parent_id, 'display', 'none');
			
			HuffPoUtil.hide('reply_' + cmt_parent_id);
			HuffPoUtil.hide('comment_preview_' + cmt_parent_id);
			if ($('reply_ajax_for_' + cmt_parent_id)) $('reply_ajax_for_' + cmt_parent_id).innerHTML = '';
			Fat.fade_element('comment_children_' + cmt_parent_id);
		} else {
			// comment is a new root-level comment
			var el = $('comments_inner');
			
			if($('post_button_new')) $('post_button_new').disabled = false;
			if($('root_comment_text')) $('root_comment_text').value  = '';
			
			if($('post_button_new')) D.setStyle('post_button_new', 'display', 'inline');
	        
			if($('post_spinner_new')) D.setStyle('post_spinner_new', 'display', 'none');
			
			Fat.fade_element('comment_' + cmt_id);
		}
		if (is_new) {
			if (cmt_count_update && cmt_count_update==1) document.getElementById('lastComment').innerHTML=cmt_id;
			el.innerHTML = new_html+el.innerHTML;
		}
		else {
			if (cmt_count_update && cmt_count_update==1) document.getElementById('lastComment').innerHTML=cmt_id;
			if (update_comments_last_loading != cmt_id)
				el.innerHTML = el.innerHTML + new_html;
		}
		HuffPoUtil.show('new_comment_alert');
		$('new_comment_alert').innerHTML= "<a href='#' onclick='Comments.scrollToComment("+cmt_id+"); return false;'>New comments on this entry</a>";
		setTimeout("HuffPoUtil.hide('new_comment_alert');", 10000);
		
		if (update_comments_entry_id == null || update_comments_entry_id == '' || !update_comments_entry_id) this.scrollToComment(cmt_id);
		document.getElementById('replyFlag').innerHTML='0';
		
		// close preview
		HuffPoUtil.hide('comment_preview');
	},
	
	displayReplyBox: function(comment_id, entry_id, cur_level)
	{
		el = $('reply_ajax_for_'+comment_id);
		if (el.innerHTML != '') {
			el.innerHTML = '';
			return false;
		}
		el.innerHTML = '<br /><p><img src="/extensions/comments/images/v/spinner.gif" alt="loading" /> Loading...</p>';
		var co = YAHOO.util.Connect.asyncRequest('GET',
											 '/extensions/comments/comment/commentForm.php?entry_id='+entry_id+'&comment_id='+comment_id+'&level='+cur_level,
											 ReplyBoxCallbacks);
		return false;
	},
	
	displayPostBox: function(entry_id)
	{
		el = $('ajax_post_form_for_root');
		el.innerHTML = '<br /><p><img src="/extensions/comments/images/v/spinner.gif" alt="loading" /> Loading...</p>';
		var co = YAHOO.util.Connect.asyncRequest('GET',
											 '/extensions/comments/comment/rootCommentForm.php?entry_id='+entry_id,
											 RootBoxCallbacks);
		return false;
	}
};

var CommentsFlagging = {
	asGood: function(comment_id, entry_id, blog_id) {
		this.process(comment_id, entry_id, blog_id, 'best');
		if ( $('flag1-Lightbox-' + comment_id) ) $('flag1-Lightbox-' + comment_id).style.display = 'block';
		return false;
	},
	
	asAbusive: function(comment_id, entry_id, blog_id) {
		this.process(comment_id, entry_id, blog_id, 'abuse');
		
		if ( $('flag2-Lightbox-' + comment_id) ) {
			var inp_name = 'flag2-Lightbox-' + comment_id;
			$(inp_name).style.display = 'block';
			xy = YAHOO.util.Dom.getXY('cmt_flag_abusive_btn_' + comment_id);
			xy[1] = xy[1] - 117;
			xy[0] = xy[0] - 173; 
			YAHOO.util.Dom.setXY(inp_name, xy);  
			
		}
		return false;
	},
	
	process: function(comment_id, entry_id, blog_id, type) {
		var callbackFlagging = null;
		if (type=='best')
			callbackFlagging = this.callbackGood;
		else
			callbackFlagging = this.callbackAbusive;
			
		var cfr = YAHOO.util.Connect.asyncRequest('GET',
						"/extensions/comments/include/flagComment.php?type=" + type + "&blog_id=" + blog_id + "&cmt_id=" + comment_id + "&entry_id=" + entry_id,
						callbackFlagging);
	},
	
	callback: {
		success: function(o, type) {
			if (o.responseText=='') return;
			splits = o.responseText.split(':::');
			cmt_id = splits[1] ? splits[1] : '0';
			flag_link = $('cmt_flag_' + type + '_btn_' + cmt_id);
			if (flag_link) {
				flag_link.style.cursor = 'default';
				flag_link.onclick = function(){return false;};
			}
		}
	},
	
	callbackGood: { 
		success: function(o) {
			CommentsFlagging.callback.success(o, 'good');
		},
		failure: function() {
			
		}
	},
	
	callbackAbusive: { 
		success: function(o) {
			CommentsFlagging.callback.success(o, 'abusive');
		},
		failure: function() {
			
		}
	}
};

var CommentsOrder = {
	spinnerHTML: '<div id="comment_spinner"><p><img src="/extensions/comments/images/spinner.gif" alt="spinner" />Loading comments&hellip;</p></div>',
	
	change: function() {
		YAHOO.util.Connect.setForm('cmt_order_form');
		var co = YAHOO.util.Connect.asyncRequest('POST', '/extensions/comments/include/just_comments_html.php', this);
		if ( $("comments") ) {
			$("comments").innerHTML = this.spinnerHTML;
		}
		return true;
	},
	
	success: function(o) {
		if ( $("comments") ) $("comments").innerHTML = o.responseText;
		setTimeout("runClient();", 500);
	},
	
	failure: function() {
		if ( $("comments") ) $("comments").innerHTML = "Sorry, we couldn't load comments for some reason. Try reloading the page.";
	}
};

var RepliesPager = {
	load: function(page, parent_id) {
		if ( !$('comment_children_' + parent_id) ) return false;
		
		if ( $('comment_spinner_replies') &&  $('comment_children_body_' + parent_id)) {
			$('comment_children_body_' + parent_id).innerHTML = $('comment_spinner_replies').innerHTML;
		}
		h = '';
		var co = YAHOO.util.Connect.asyncRequest('GET', '/extensions/comments/include/comment_childrens_html.php?page=' + page + '&parent_id=' + parent_id + '&hash=' + h, this);
	},
	success: function(o) {
		if (o.responseText=='') return;
		splits = o.responseText.split(':::');
		html = splits[0];
		parent_id = splits[1];
		el = $('comment_children_' + parent_id);
		if ( !el || typeof el=='undefined' ) return false;
		
		el.style.display = 'block';
		if (splits[2] && splits[2]=='new')
			Fat.fade_element('comment_children_' + parent_id);
		el.innerHTML = html;
		//FanSystem.checkAlready();
	},
	failure: function() {
		
	}
};

var CommentFinder = function(objName, interval) {
	this.timeout = interval;
	this.intervalID = null;
	this.objName = objName;
	
	this.runUpdate = function() {
		if ( !$('comment_finder_content') ) return false;
		this.intervalID = setInterval(this.objName + '.update();', this.timeout);
		return true;
	};
	
	this.update = function() {
		var cfr = YAHOO.util.Connect.asyncRequest('GET', '/include/comment_finder_updater.php?update_comment_finder=1', this);
	};
	
	this.success = function(o) {
		if (o.responseText=='') return;
		if ( $('comment_finder_content') )
			$('comment_finder_content').innerHTML = o.responseText;
	};
	
	this.failure = function() {
		//if (this.intervalID!=null) clearInterval(this.intervalID);
	};
};

var ApprovedPoller = function(objName, entry_id) {
	this.objName 			= objName;
	this.interval		 	= 60000;
	this.timeout		 	= 60000;
	this.first				= true;
	this.intervalID 		= null;
	this.entry_id			= entry_id;
	this.user				= getCookie('_dick_cookie_username') ? true : false;
	
	this.runUpdate = function() {
		if (!this.entry_id || !this.user) return false;
		if (this.first) {
			setTimeout(this.objName + ".runUpdate();", this.timeout);
			this.first = false;
		} else {
			this.intervalID = setInterval(this.objName + ".update();", this.interval);
			this.update();
		}
		return true;
	};
	
	this.update = function() {
		h = '';
		var conn = YAHOO.util.Connect.asyncRequest('GET', '/extensions/comments/comment/checkNewApprovedComments.php?entry_id='+this.entry_id+'&hash='+h, this, null);
	};
	
	this.success = function(o) {
		if (o.responseText=='0') return;
		cmt_ids = o.responseText.split(':::');
		for (i = 0, len = cmt_ids.length-1; i < len; i++) {
			this.approve(cmt_ids[i]);
		}
		if (cmt_ids[cmt_ids.length-1].indexOf('p_')!=-1) {
			pending_cnt = cmt_ids[cmt_ids.length-1].substring(2);
			if ( $('pending_comments_cnt') ) $('pending_comments_cnt').innerHTML = pending_cnt;
			if ( $('pending_comments') ) Fat.fade_element('pending_comments');
		}
	};
	
	this.failure = function() {
		if (this.intervalID!=null) clearInterval(this.intervalID);
	};
	
	this.approve = function(cmt_id) {
		comment_el = $('comment_' + cmt_id);
		if (!comment_el || typeof comment_el=='undefined') return false;
		
		approve_el = $('not_approved_comment_' + cmt_id);
		if (!approve_el || typeof approve_el=='undefined' || approve_el.style.display=='none') return false;
		approve_el.style.display = 'none';
		Fat.fade_element(comment_el.id);
	};
};

var CommentsPager = {
	load: function(entry_id, params) {
		var co = YAHOO.util.Connect.asyncRequest('GET', '/extensions/comments/include/just_comments_html.php?entry_id=' + entry_id + '&' + params, this);
		if ( $("comments") )
			$("comments").innerHTML = CommentsOrder.spinnerHTML;
	},
	success: function(o) {
		$("comments").innerHTML = o.responseText;
		setTimeout("runClient();", 500);
	},
	failure: function(o) {
		$("comments").innerHTML = "Sorry, we couldn't load comments for some reason. Try reloading the page.";
	}
};

var CommentPoller = {
	check: function(entry_id)
	{
		if (document.getElementById('lastComment')) {
			var last=document.getElementById('lastComment').innerHTML;
			if ($('replyFlag').innerHTML=='0') Comments.addCommentMy(entry_id, last);
		}
		setTimeout("CommentPoller.check('" + entry_id + "');", 10000);
	}
};

var ReplyBoxCallbacks = {
	success: function(o)
	{
		var splits   = o.responseText.split(':::');
		var new_html = splits[0];
		var cmt_id   = Math.floor(splits[1]) + 0;
		var el = $('reply_ajax_for_'+cmt_id);
		el.innerHTML = new_html;
	}
};

var RootBoxCallbacks = {
	success: function(o)
	{
		var splits   = o.responseText.split(':::');
		var new_html = splits[0];
		var cmt_id   = Math.floor(splits[1]) + 0;
		var el = $('ajax_post_form_for_root');
		el.innerHTML = new_html;
	}
};

/*----------------------------------------------------------------------*/

// @name      The Fade Anything Technique
// @namespace http://www.axentric.com/aside/fat/
// @version   1.0-RC1
// @author    Adam Michela
// @name      The Fade Anything Technique
// @namespace http://www.axentric.com/aside/fat/
// @version   1.0-RC1
// @author    Adam Michela

var Fat = {
	make_hex : function (r,g,b) 
	{
		r = r.toString(16); if (r.length == 1) r = '0' + r;
		g = g.toString(16); if (g.length == 1) g = '0' + g;
		b = b.toString(16); if (b.length == 1) b = '0' + b;
		return "#" + r + g + b;
	},
	fade_all : function ()
	{
		var a = document.getElementsByTagName("*");
		for (var i = 0; i < a.length; i++) 
		{
			var o = a[i];
			var r = /fade-?(\w{3,6})?/.exec(o.className);
			if (r)
			{
				if (!r[1]) r[1] = "";
				if (o.id) Fat.fade_element(o.id,null,null,"#"+r[1]);
			}
		}
	},
	fade_element : function (id, fps, duration, from, to) 
	{
		if (!fps) fps = 30;
		if (!duration) duration = 3000;
		if (!from || from=="#") from = "#FFFF33";
		if (!to) to = this.get_bgcolor(id);
		
		var frames = Math.round(fps * (duration / 1000));
		var interval = duration / frames;
		var delay = interval;
		var frame = 0;
		
		if (from.length < 7) from += from.substr(1,3);
		if (to.length < 7) to += to.substr(1,3);
		
		var rf = parseInt(from.substr(1,2),16);
		var gf = parseInt(from.substr(3,2),16);
		var bf = parseInt(from.substr(5,2),16);
		var rt = parseInt(to.substr(1,2),16);
		var gt = parseInt(to.substr(3,2),16);
		var bt = parseInt(to.substr(5,2),16);
		
		var r,g,b,h;
		while (frame < frames)
		{
			r = Math.floor(rf * ((frames-frame)/frames) + rt * (frame/frames));
			g = Math.floor(gf * ((frames-frame)/frames) + gt * (frame/frames));
			b = Math.floor(bf * ((frames-frame)/frames) + bt * (frame/frames));
			h = this.make_hex(r,g,b);
		
			setTimeout("Fat.set_bgcolor('"+id+"','"+h+"')", delay);

			frame++;
			delay = interval * frame; 
		}
		setTimeout("Fat.set_bgcolor('"+id+"','"+to+"')", delay);
	},
	set_bgcolor : function (id, c)
	{
		var o = document.getElementById(id);
		o.style.backgroundColor = c;
	},
	get_bgcolor : function (id)
	{
		var o = document.getElementById(id);
		while(o)
		{
			var c;
			if (window.getComputedStyle) c = window.getComputedStyle(o,null).getPropertyValue("background-color");
			if (o.currentStyle) c = o.currentStyle.backgroundColor;
			if ((c != "" && c != "transparent") || o.tagName == "BODY") { break; }
			o = o.parentNode;
		}
		if (c == undefined || c == "" || c == "transparent") c = "#FFFFFF";
		var rgb = c.match(/rgb\s*\(\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1,3})\s*\)/);
		if (rgb) c = this.make_hex(parseInt(rgb[1]),parseInt(rgb[2]),parseInt(rgb[3]));
		return c;
	}
};



/*----------------------------------------------------------------------*/
/* scroll functions from and (c) brandspankingnew
http://www.brandspankingnew.net/archive/2005/09/animated_anchor.html */
/*----------------------------------------------------------------------*/

	/*
	SCROLL FUNCTIONS
	*/
	
	var scrollInt;
	var scrTime, scrSt, scrDist, scrDur, scrInt;
	
	
	function scrollPage()
	{
		scrTime += scrInt;
		if (scrTime < scrDur) {
			window.scrollTo( 0, easeInOut(scrTime,scrSt,scrDist,scrDur) );
		}else{
			window.scrollTo( 0, scrSt+scrDist );
			clearInterval(scrollInt);
		}
	}
	
	// modified from original; now looks for div#some_id
	function scrollToAnchor(aname)
	{
		var anchors, i, ele;
	
		if (!document.getElementById)
			return;
		
		// get anchor
		anchors = document.getElementsByTagName("div");
		for (i=0;i<anchors.length;i++) {
			if (anchors[i].id == aname) {
				ele = anchors[i];
				i = anchors.length;
			}
		}
		
		// set scroll target
		if (window.scrollY)
			scrSt = window.scrollY;
		else if (document.documentElement.scrollTop)
			scrSt = document.documentElement.scrollTop;
		else
			scrSt = document.body.scrollTop;

		
		
		scrDist = ele.offsetTop - scrSt;
		scrDur = 100;
		scrTime = 0;
		scrInt = 10;
		
		// set interval
		clearInterval(scrollInt);
		scrollInt = setInterval( scrollPage, scrInt );
	}
	
	

	
	/*
	EASING FUNCTIONS
	*/
	
	function easeInOut(t,b,c,d)
	{
		return c/2 * (1 - Math.cos(Math.PI*t/d)) + b;
	}
	
	
function hidedivFlagGreen(id){
	document.getElementById('flag1-Lightbox-' + id).style.display="none";
}
function hidedivFlagRed(id){
	document.getElementById('flag2-Lightbox-' + id).style.display="none";
}

function showdivLogin(){
	var ev = YAHOO.util.Event;
	xy = ev.getXY(ev.getEvent());
	xy[1] = xy[1] - 303;
	xy[0] = xy[0] - 47; 
	YAHOO.util.Dom.setXY('comment-login-Lightbox', xy);  
	//document.getElementById('comment-login-Lightbox').style.top = xy[1] + 'px';
	
	setTimeout("$('comment-login-username').focus();", 500);
}
function hidedivLogin(){
	document.getElementById('comment-login-Lightbox').style.top="-1000px";
	document.getElementById('comment-login-Lightbox').style.left="-1000px";
}

function showtoplogindiv(obj){
	if ( $('advertisement300_hidden') && $('advertisement300_hidden')) {
    	$('advertisement300').style.display='none';
    	$('advertisement300_hidden').style.display='block';
    }
	var xy = YAHOO.util.Dom.getXY('top-login-link');
	//console.debug(xy);
	$('login-Lightbox').style.left = xy[0]-348 + 'px';
	//document.getElementById('login-Lightbox').style.display="block";
	setTimeout("document.getElementById('top-login-username').focus();", 500);
	scrollToAnchor('login-Lightbox');
}

function bottomPostClick()
{
	scrollToAnchor('ajax_post_form_for_root');
	if ( $('root_comment_text') )
		setTimeout("$('root_comment_text').focus();", 500);
}

/**
followong code is for getting html abt the user  or login/register links*/
var CommentsLogged = function () {
var resp = {
	success: function(o) {
		$("comment-user-info").innerHTML = o.responseText;
	},
	failure: function(o) {
		$("comment-user-info").innerHTML = "";
	}
}
var req = YAHOO.util.Connect.asyncRequest('GET', '/extensions/comments/auth/load_user_info.php?', resp);
}

YAHOO.util.Event.onDOMReady(CommentsLogged);  


  
  function showdiv(){
			var xy = YAHOO.util.Dom.getXY('top-login-link');
			document.getElementById('login-Lightbox').style.left = xy[0]-348 + 'px';
			
        	//document.getElementById('login-Lightbox').style.display="block";
            //setTimeout("document.getElementById('top-login-username').focus();", 500);
            setTimeout("document.getElementById('login-Lightbox').focus();", 500);
        }
		
        function hidediv() {
        	document.getElementById('login-Lightbox').style.left="-1000px";
        }

		//
		
/*********** registration form load starts here*/
function  load_registration_form(){
	$('bodyContent').innerHTML = '<img alt="spinner" src="/extensions/comments/images/spinner.gif"/>Please wait ...';
	var loader = YAHOO.util.Connect.asyncRequest('GET', '/extensions/comments/auth/regiatrtion_form.php', {
	success: function(o) {
		arr = YAHOO.util.Dom.getElementsByClassName("firstHeading");
		arr[0].innerHTML = "Registration";
		$('bodyContent').innerHTML = o.responseText;
		},
	failure: function(o) {
		alert('Can not establish connection to server');
		}
	});
	
}

/*********** registration form load ends here*/
