// JavaScript Document
var lastPCTopic;
var ageok = false;
var lastFilmId;
var lastFilmSrc;
var lastIsRestricted;
var skipReloadFilm = false;
var chToTopic;
var loginPing = null;
var userStatus = false;

var loadedDirectURL = false;

var skipFormatThumbs = false;
var newTopic = false;
var onCritique = false;

var curPath = "";

var loadedDispAwrap = false;
var loadedDispA = false;
var loadedDispB = false;
var loadedDispC = false;
var loadedDispC1 = false;
var loadedDispC2 = false;
var loadedDipsC3 = false;

var currentDisplay = "default";


function centerPopDiv( divN, divH, divW ){
					
	var winSize = document.viewport.getDimensions();
	//alert( " width: "+winSize.width+" height: "+winSize.height );
	var offsets = document.viewport.getScrollOffsets();
	var divSize = $(divN).getDimensions();
		
	if (divH == -1){
		divH = divSize.height/2;
	}
	if (divW == -1){
		divW = divSize.width/2;
	}
	
	var topPos = offsets.top + divH;
	var leftPos = winSize.width/2 - divW;
	if (topPos < 0 )
		topPos = 0;
	if (leftPos < 0 )
		leftPos = 0;
	$(divN).setStyle({top: topPos, left: leftPos});
}

function dpSelectTab( tabid, groupName ){
	var selectedOpts = $$("."+groupName+"_sel");
	var defaultOpts = $$("."+groupName);
	
	// hide previously selected items
	selectedOpts.each(function(item) {
		if ( item == $(""+tabid+"_sel") )
			item.show();
		else
			item.hide();
		});
	// show other items and hide base selectable button
	defaultOpts.each( function(item){
		if ( item == $(tabid))
			item.hide();
		else
			item.show();
		});
}

function checkAgeOk(){
	new Ajax.Updater('blankDiv',curPath+'handler.php',{
	 parameters: {'event':'checkloginage'},
	 evalScripts: true
	 });
}


function TopicToColor( sTopic ){
	switch (sTopic){
		case 'love': 	return 'red';
		case 'greed': 	return 'green';
		case 'hope':	return 'blue';
		case 'pain':	return 'grey';
		case 'forgiveness': 	return 'yellow';
		case 'freedom':		return 'teal';
		case 'redemption':	return 'purple';
		case 'energy':		return 'orange';
		case 'doorpostinfo':	return 'bluegrey';
		default:	return 'orange';
	}
}

function TopicToHex( sTopic ){
	switch (sTopic){
		case 'love': 	return 'A10101';
		case 'greed': 	return '609113';
		case 'hope': 	return '1E606A';
		case 'pain':	return '777777';
		case 'forgiveness': 	return 'FFFE30';
		case 'freedom':		return '04F9FA';
		case 'redemption':	return 'FACE39';
		case 'energy':		return 'FACE39';
		case 'doorpostinfo':	return '0796E5';
		default:	return 'FACE39';
	}
}

function aj_Update( pg, divId, params, onComp ){
		new Ajax.Updater( divId, pg, { parameters: params, onComplete: onComp } );
}

function hist_ChangePgRedirect( newPg ){
	window.location = '/?'+newPg;
}

function hist_ChangePg( newPg ){
	hist_CheckAdd( 'hist_ChangePg', newPg, 'hist_ChangePg' );
	aj_ChangePg( newPg );
}

function aj_ChangePg( newPg ){
	
	switch ( newPg ){
		case 'doorpostinfo':
			break;
		case 'hope':
			break;
		case 'doneregistration':
			onCritique = false;
			// we should be in doorpostinfo
			if (sCurTopic != 'doorpostinfo'){
				alert('Not in doorpost info!');
			}
			aj_MarkLoading('mainquestion', 'Loading...');
			aj_MarkLoading('oldquestions', 'Loading...');
			formatLoadPg('doneregistration');
			new Ajax.Updater( 'mainquestion', curPath+'handler.php', {
					 parameters: {'event':'buildmainquestion'}, onComplete: aj_RedrawTopicComments
					 });	
			new Ajax.Updater( 'oldquestions', curPath+'handler.php', {
					 parameters: {'event':'buildoldquestions'}
					 });			
			
			break;
		case 'registration':
			onCritique = false;
			displayingUserInfo = true;			
			formatLoadPg('registration');
			if (sCurTopic != 'doorpostinfo'){
				sCurTopic = 'doorpostinfo';
				var sColor = TopicToColor('doorpostinfo');
				$('body').style.backgroundImage = "url('http://c0625612.cdn.cloudfiles.rackspacecloud.com/webimages/"+sColor+"background.jpg')";
				new Ajax.Request( curPath+'handler.php', {parameters: {'event':'changeTopic', 'topic':'doorpostinfo'}});
				aj_RedrawTopic(-1, 'doorpostinfo');
			}
			break;
		case 'top15':
			/*
			
		  var complexObject = new Object();
          complexObject.value1 = 
                        "This is the first value";
          complexObject.value2 = 
                        "This is the second data";
          complexObject.value3 = new Array();
          complexObject.value3[0] = "array 1";
          complexObject.value3[1] = "array 2";
            
          dhtmlHistory.add("complexObject", 
                           complexObject);
		  
		  */
			checkHideUserInfo();
			onCritique = false;	
			if (sCurTopic != 'hope'){
				sCurTopic = 'hope';
				var sColor = TopicToColor('hope');
				$('body').style.backgroundImage = "url('http://c0625612.cdn.cloudfiles.rackspacecloud.com/webimages/"+sColor+"background.jpg')";
				new Ajax.Request( curPath+'handler.php', {parameters: {'event':'changeTopic', 'topic':'hope'}});
				aj_RedrawTopic(-1, 'hope');
			} 
			new Ajax.Updater('fullBody', curPath+'handler.php', { parameters: {'event':'displaytopfifteen'} });
			new Ajax.Updater('videocontent', curPath+'handler.php', { parameters: {'event':'buildvideocontent', 'subcontent':'displaytopfifteen'}});
			
			formatLoadPg('top15');
			break;
		default:
			hist_CheckAdd('', newPg, '' );
			// all other topics
			break;
	}
}

function checkHideUserInfo(){
	if (modUserManage == true && displayingUserInfo == true){
		dpu_HideUserInfo();
		displayingUserInfo = false;
		dispC3.togTo('thumbnailwrapper');
	}	
	if (loadedDirectURL == true ){
		//dispAwrap.togTo('bodyHeaderTableDiv');
		loadedDirectURL = false;
	}
}

function aj_HideAllContent(){
	dispB.togTo('videocontent');
	dispC2.togTo('');
}


// wrapper used by the actual click links since the function below is called by many things.
function hist_ChangeTopic( anewtopic ){
	hist_CheckAdd('hist_ChangeTopic', anewtopic, 'hist_ChangeTopic' );
	if (loadedDirectURL == true ){
		//dispAwrap.togTo('bodyHeaderTableDiv');
		dispA.togTo('maintopic');
		loadedDirectURL = false;
		
	}
	aj_ChangeTopic( anewtopic );
}

function aj_ChangeTopic( anewtopic ){
	newTopic = true;
	
	if (anewtopic == ""){
		// no topic sent....
		anewtopic = sCurTopic;
	}
	
	sCurTopic = anewtopic;

	var sColor = TopicToColor(anewtopic);
	$('body').style.backgroundImage = "url('http://c0625612.cdn.cloudfiles.rackspacecloud.com/webimages/"+sColor+"background.jpg')";

	switch ( anewtopic ){
		case 'doorpostinfo':
			onCritique = false;
			new Ajax.Request( curPath+'handler.php', { parameters: {'event':'changeTopic', 'topic':anewtopic}, onComplete: aj_RedrawTheRest } );
			break;
		case 'hope':
			onCritique = false;
			new Ajax.Request( curPath+'handler.php', { parameters: {'event':'changeTopic', 'topic':anewtopic}, onComplete: aj_TopicConversation } );
			break;
		default:
			new Ajax.Request( curPath+'handler.php', { parameters: {'event':'changeTopic', 'topic':anewtopic}, onComplete: aj_WriteAReview } );
			break;
	}
	aj_RedrawTopic( -1, anewtopic);
	formatLoadPg( 'changetopic' );
	return false;
}

// THis is used by the direct film link, so keep the film details in this one.
function aj_ChangeTopicTwo( newtopic ){
	newTopic = true;
	formatLoadPg( 'changetopic2' );
	if (newtopic == ""){
		//sCurTopic = newtopic;
		newtopic = sCurTopic;
	} 
	sCurTopic = newtopic;
	new Ajax.Request( curPath+'handler.php', {
					 parameters: {'event':'changeTopic', 'topic':newtopic},
					 onComplete: aj_RedrawTopicTwo
					 } );
	
	var sColor = TopicToColor(newtopic);
	$('body').style.backgroundImage = "url('http://c0625612.cdn.cloudfiles.rackspacecloud.com/webimages/"+sColor+"background.jpg')";
	return false;
}

// this is used by history functions
function aj_BackToTopic( newtopic ){
	// don't do anything but the basics!!!
	// keep this clean.
	newTopic = true;
	sCurTopic = newtopic;
	new Ajax.Request( curPath+'handler.php', {parameters: {'event':'changeTopic', 'topic':newtopic}} );
	var sColor = TopicToColor(newtopic);
	$('body').style.backgroundImage = "url('http://c0625612.cdn.cloudfiles.rackspacecloud.com/webimages/"+sColor+"background.jpg')";
	dispA.changeTopic( newtopic );
	return false;
}

function aj_RedrawTopic( cmp, topicStr ){	
	if (!topicStr){
		topicStr = sCurTopic;
	}
	if (!cmp || cmp != "-1"){
		dispA.changeTopic( topicStr );
		aj_RedrawTheRest();
	} else {
		dispA.changeTopic( topicStr );
	}
	//aj_LoadFilmThumbs();
}

function aj_RedrawTopicTwo(){
	dispA.changeTopic( sCurTopic );
	aj_RedrawNoVideo();
}

// Redraw the topic comments section. If  we're on the doorpost info section, we do not need to redraw this.
function aj_RedrawTopicComments(){
	// if we're in the doorpostinfo section, we don't need to get any info, it's just blank at this stage.
	if (sCurTopic == "doorpostinfo"){
		$('questioncomments').innerHTML = "";
		return;
	}
	aj_MarkLoading('questioncomments', 'Reading comments... ');
	new Ajax.Updater('questioncomments', curPath+'handler.php', {parameters: {'event':'buildquestioncomments'}});
}

function aj_RedrawNoVideo(){
	//dispC2.togTo('contentWrapper');
//	$('contentWrapper').show();
	new Ajax.Updater( 'mainquestion', curPath+'handler.php', {
					 parameters: {'event':'buildmainquestion'},
					 onComplete: aj_RedrawTopicComments
					 });	
	new Ajax.Updater( 'oldquestions', curPath+'handler.php', {
					 parameters: {'event':'buildoldquestions'}
					 });
	aj_LoadFilmThumbs();
}

function aj_RedrawTheRest(){
	/**
	 * Add in crit reviews
	 */
	new Ajax.Updater( 'critFilmCommentDiv', curPath+'handler.php', {
					 parameters: {'event':'drawcritique'}
					 });
	
	new Ajax.Updater( 'mainquestion', curPath+'handler.php', {
					 parameters: {'event':'buildmainquestion'},
					 onComplete: aj_RedrawTopicComments
					 });	
	new Ajax.Updater( 'oldquestions', curPath+'handler.php', {
					 parameters: {'event':'buildoldquestions'}
					 });
	
	new Ajax.Updater( 'videocontent', curPath+'handler.php', {
						 parameters: {'event':'buildvideocontent'},
						 evalScripts: true
						 });	
	aj_LoadFilmThumbs();
	
}


// this should be obsolete
function aj_RedrawTopicCommentsPg(limit, pg, qId){
	aj_MarkLoading('questioncomments', 'Reading comments... ');
	new Ajax.Updater('questioncomments', curPath+'handler.php', {
					 parameters: {'event':'buildquestioncomments', 't_p':pg, 'qid':qId}
					 });
}

/** 
 * Actual processing functions here
 */

function aj_PostEmail(){
	var email = $('email').value;
	if (email == '' || email == 'EMAIL ADDRESS'){
		alert('Please provide your email address.');
		return;
	} 
	$('newslettersignup').innerHTML = "Registering for the newsletter...<img src=\"images/working.gif\" alt=\"loading\">";
	new Ajax.Updater( 'newslettersignup', curPath+'handler.php', 
					 	{
					 	parameters: {'email': email, 'event':'newslettersignup' }
					 });
}

// called by login from iframe
function aj_ReviewerIsLoggedin(){
	aj_MarkLoadingBlack('loginlink', 'Logging in...');

	new Ajax.Updater('loginlink', curPath+'handler.php',{
					 parameters:{'event':'checkloginstatus','drawRes':'true'},
					 evalScripts:true
					 });	
}

function aj_ReviewerLogin( nonPopup ){

	if (nonPopup){
		var email = $F('revieweremail_main');
		var pwd = $F('reviewerpassword_main');
		var divN = 'loginBlue';
		myLogin.clickFrom = "main";
	} else {
		var email = $('revieweremail').value;
		var pwd = $('reviewerpassword').value;
		var divN = 'login';
	}
	

	if (email == '' || pwd == '' || email == 'USER NAME' || pwd == 'PASSWORD'){
			alert("Please provide your username and password to log in.");
			return;
	}
	if (nonPopup){
		aj_MarkLoadingBlack( divN, 'Logging in...');
	}
	new Ajax.Updater(divN, curPath+'handler.php', 
					 {
						 parameters: { 'email':email, 'password': pwd, 'event':'reviewerlogin'},
						 evalScripts: true,
						 onComplete: function(){
							 myLogin.compelteClick();
						 }
					 });
}

function aj_closeLoginDetails(){
	dispC2.togTo('contentWrapper');
}

function aj_ReviewerLogout( redir ){
	curUser.logout();
	
	ageok = false;
	loadedMyInfo = false;
	userStatus = false;
	var fd = $('filmDetails');

	if (loginPing){
		loginPing.stop();
	}

	if ( redir ){
		aj_MarkLoadingBlack('login');
		new Ajax.Updater('login',curPath+'handler.php', {parameters: {'event':'reviewerlogout'}, 
						 onComplete: function(){
							 window.location = ''+curPath;
						 }});
	} else {
	
		if (loadedDispA == true && dispA.current == 'profileHead'){
			dpu_DoneManage();
		}
	
		if (loadedDispC1 == true && dispC1.current != 'filmDetails'){
			$('filmDetails').innerHTML = "";
			dispC1.togTo('fullBody');
			dispC.togTo('tableBodyDiv');
			aj_WriteAReview();
		}
		new Ajax.Updater('login', curPath+'handler.php', { parameters: {'event':'reviewerlogout'} });
	}
	

	hist_CheckAdd('aj_ReviewerLogout','logout', 'logout');
}

function aj_FormatPostcardDetailsView(){
		$('showPostcardDetailsLink').hide();
}

var convalue = 0;
var genvalue = 0;
var enjvalue = 0;
	
function StarRating(userid, cat, filmid, count, id, units){
	var percent = count * 20;

	if (cat == 'conceptrank')
	   convalue = count;
   else if (cat == 'generalrank')
	   genvalue = count;
   else enjvalue = count;

	var str = "unit_long"+id;
	var UnitLong = $(str);
	UnitLong.innerHTML = '<ul id="unit_ul'+id+'" class="unit-rating" style="width:100px;">     <li class="current-rating" style="width:'+percent+'px;">Currently 2.00/5</li> <li> <a href=javascript:StarRating("'+userid+'","'+cat+'","'+filmid+'","0.5","'+id+'","5"); title="0.5 out of 2.5" class="r1-unit rater" rel="nofollow">0.5</a></li><li> <a href=javascript:StarRating("'+userid+'","'+cat+'","'+filmid+'","1.0","'+id+'","5"); title="1 out of 2.5" class="r2-unit rater" rel="nofollow">1</a></li><li> <a href=javascript:StarRating("'+userid+'","'+cat+'","'+filmid+'","1.5","'+id+'","5"); title="1.5 out of 2.5" class="r3-unit rater" rel="nofollow">1.5</a></li><li> <a href=javascript:StarRating("'+userid+'","'+cat+'","'+filmid+'","2.0","'+id+'","5"); title="2 out of 2.5" class="r4-unit rater" rel="nofollow">2</a></li><li> <a href=javascript:StarRating("'+userid+'","'+cat+'","'+filmid+'","2.5","'+id+'","5"); title="2.5 out of 2.5" class="r5-unit rater" rel="nofollow">2.5</a></li>    <li> <a href=javascript:StarRating("'+userid+'","'+cat+'","'+filmid+'","3.0","'+id+'","5"); title="0.5 out of 2.5" class="r6-unit rater" rel="nofollow">0.5</a></li><li> <a href=javascript:StarRating("'+userid+'","'+cat+'","'+filmid+'","3.5","'+id+'","5"); title="1 out of 2.5" class="r7-unit rater" rel="nofollow">1</a></li><li> <a href=javascript:StarRating("'+userid+'","'+cat+'","'+filmid+'","4.0","'+id+'","5"); title="1.5 out of 2.5" class="r8-unit rater" rel="nofollow">1.5</a></li><li> <a href=javascript:StarRating("'+userid+'","'+cat+'","'+filmid+'","4.5","'+id+'","5"); title="2 out of 2.5" class="r9-unit rater" rel="nofollow">2</a></li><li> <a href=javascript:StarRating("'+userid+'","'+cat+'","'+filmid+'","5","'+id+'","5"); title="2.5 out of 2.5" class="r10-unit rater" rel="nofollow">2.5</a></li> </ul>';

}

function aj_SubmitVotes(filmid){
	if (convalue==0 || genvalue ==0 ||enjvalue==0)
		alert("Please vote for all the categories.");
	else {
		var answer= confirm("You may only vote once. Are you sure you want to vote?");

		if (answer== true){
			$('filmDetailVotingBlock').innerHTML = "Saving your votes... <img src=\"images/working.gif\" alt=\"loading\">";			
			new Ajax.Updater('filmDetailVotingBlock',curPath+'handler.php',{
							 	parameters: {'event':'submitfilmvotes','f':filmid,'c':convalue,'g':genvalue,'e':enjvalue},
								onComplete: function(){
									$('filmDetailRatingBlock').innerHTML = "Calculating...<img src=\"images/working.gif\" alt=\"loading\">";
									new Ajax.Updater('filmDetailRatingBlock',curPath+'handler.php', {parameters:{'event':'redrawrating'}});
/*									convalue=0;
									genvalue=0;
									enjvalue=0;  */
								}
							 	});
		}
	}
}

function aj_MarkLoading( div, msg ){
	$(div).innerHTML = "<span style=\"color: black;\">&nbsp;"+msg+"</span><img src=\"http://c0625612.cdn.cloudfiles.rackspacecloud.com/webimages/working.gif\" alt=\"loading\">";
}

function aj_MarkLoadingBlack( div, msg ){
	$(div).innerHTML = "<span style=\"color: white;\">&nbsp;"+msg+"</span><img src=\"http://c0625612.cdn.cloudfiles.rackspacecloud.com/webimages/working2.gif\" alt=\"loading\">";
}
function aj_MarkLoadingGrey( div, msg ){
	var str = dpv_loadswf( 'http://c0625612.cdn.cloudfiles.rackspacecloud.com/webimages/loading_slide', '126', '12', '#c0c0c0' );
	$(div).innerHTML = (""+msg+" "+str);
}


function hist_LoadOldQuestion( qid ){
	var conv_object = new Object();
	conv_object.qid = qid;
	conv_object.topic = sCurTopic;
	conv_object.link_clicked = 'load_question';
	
	hist_CheckAdd('hist_LoadOldQuestion','tq'+qid, conv_object );
	aj_LoadOldQuestion( qid );
}

function aj_LoadOldQuestion( qid ){
	new Ajax.Updater( 'mainquestion', curPath+'handler.php', {
					 parameters: {'event':'buildmainquestion', 'qid':qid},
					 onComplete: aj_RedrawTopicComments
					 });
}

function aj_PostFilmReview( fno ){
	var textareaname = 'filmReviewInputForm';
	var textareawrapper = 'filmReviewInputDiv';
	
	textVal = $(textareaname).value;
	if (textVal == ""){
		alert("You cannot add an empty review.");
		return;
	}
	aj_MarkLoadingBlack(textareawrapper, 'Saving your review... ');
	new Ajax.Updater(textareawrapper, curPath+'handler.php', {
					 	parameters: {'event':'submitfilmreview', 'comment':textVal, 'fno':fno},
						evalScripts: true					
							
					 });
	
}

function aj_PostFilmComment( fno ){
	var textareaname = 'filmDetailCommentInputForm';
	var textareawrapper = 'filmDetailCommentInputDiv';
	
	textVal = $(textareaname).value;
	if (textVal == ""){
		alert("You cannot add an empty comment.");
		return;
	}
	aj_MarkLoadingBlack(textareawrapper, 'Saving your comment... ');
	new Ajax.Request(curPath+'handler.php', {
					 	parameters: {'event':'submitfilmcomment', 'comment':textVal, 'fno':fno},
						onComplete: aj_LoadFilmCommentsPg
					 });
	
}

// This function is used to submit the topic comment
function aj_PostTopicComment( qid, inputName, pid ){
	//alert("pid: "+pid);
	var textareaname = ''+inputName+'Form';
	var textareawrapper = ''+inputName+'Div';
	textVal = $(textareaname).value;
	if (textVal == ""){
		alert("You cannot add an empty comment.");
		return;
	}
	//aj_MarkLoading(textareawrapper, 'Saving your comment... ');
	new Ajax.Updater(textareawrapper, curPath+'handler.php', {
					 	parameters: {'event':'submitquestioncomment', 'qid':qid,'pid':pid,'comment':textVal,'divN':inputName},
						onComplete: aj_RedrawTopicComments
					 });
	
	// don't redraw the input area, redraw the entire comments thread section, then add the form back
}



function aj_PostcardSubmit(){
	var pc_topic = $('PC_topic');
	var pc_story = $('PC_story');
	
	
	var pct = pc_topic.value;
	var pcs = pc_story.value;
	
	if( pct == 't'){
		alert('Please select a topic.');
		return;
	}	
	
	if( pcs == ''){
		alert('You did not enter any story text.');
		return;
	}
	
	lastPCTopic = pct;
	
	aj_MarkLoading('postCardFormDiv', 'Saving your story...');
	new Ajax.Updater('postCardFormDiv', curPath+'handler.php', {
						parameters:{'event':'submitpostcardcomment', 'pct':pct, 'pcs':pcs},
						onComplete: aj_drawPostcardComments
					});

}

function aj_drawPostcardComments( topic ){
	if (!topic)
		topic = lastPCTopic;
		
	$('postCardComments').innerHTML = "<tr><td>Loading comments...<img src=\"images/working.gif\" alt=\"loading\"></td></tr>";
	new Ajax.Updater('postCardComments', curPath+'handler.php', {parameters:{'event':'drawpostcardcomments', 'pct':topic}});
}

function dp_text(elem, divid, amt){
	theElem = $(elem);
	var story =  theElem.value;
	var length = theElem.value.length;
	if (length <= amt){
	   var left = amt - length;
	   left += " characters left";
	   $(divid).innerHTML = left;
	 } else {
		 story = story.slice(0,amt); 
		 theElem.value= story;
	 }
}


function hist_showcontent( pgName ){
	hist_CheckAdd('hist_showcontent', pgName, 'hist_showcontent' );
	aj_showcontent( pgName );
}

function aj_showcontent( pgName ){
	aj_MarkLoading('mainquestion', 'Loading... ');
	new Ajax.Updater('mainquestion', curPath+'handler.php', {
					 parameters: {'event':'displaycontent', 'pg':pgName}
					 });
	
}

function hist_TopicConversation(){
	hist_CheckAdd('hist_TopicConversation','topic_conversation', sCurTopic);
	aj_TopicConversation();
}

function aj_TopicConversation(){
	onCritique = false;
	aj_MarkLoadingBlack('videocontent', 'Loading...');
	aj_MarkLoading('mainquestion', 'Loading...');
	aj_MarkLoading('oldquestions', 'Loading...');
	$('questioncomments').innerHTML = "";
	
	formatLoadPg('topicconversation');
	
	MM_swapImage( 'topicconversation' ,'','http://c0625612.cdn.cloudfiles.rackspacecloud.com/webimages/topicconversation2.jpg',1);
	if ($('writeareview')){
		MM_swapImage( 'writeareview' ,'','http://c0625612.cdn.cloudfiles.rackspacecloud.com/webimages/writeareview.jpg',1)
	}
	new Ajax.Updater('videocontent', curPath+'handler.php', { parameters: {'event':'buildvideocontent', 'subcontent':'displayScrollingInfo'}} );
	
	new Ajax.Updater( 'mainquestion', curPath+'handler.php', {
			 parameters: {'event':'buildmainquestion', 'fortopic':sCurTopic},
			 onComplete: aj_RedrawTopicComments
			 });	
	new Ajax.Updater( 'oldquestions', curPath+'handler.php', {
			 parameters: {'event':'buildoldquestions', 'fortopic':sCurTopic}
			 });
	aj_LoadFilmThumbs( true );
}


function hist_TakeSurvey(){
	hist_CheckAdd('hist_TakeSurvey','survey', sCurTopic );
	aj_TakeSurvey();
}
function aj_TakeSurvey(){
	aj_MarkLoadingBlack('surveyform', 'Loading survey...');
	new Ajax.Updater( 'surveyform', curPath+'handler.php',{ parameters: {'event':'GenerateSurvey', 'grouping':sCurTopic }});	
	formatLoadPg('survey');
}

function hist_showCritReview( id, topic ){
	var cObj = new Object();
	cObj.critid = id;
	if (topic){
		cObj.topic = topic;
	} else {
		cObj.topic = sCurTopic;
	}
	cObj.link_clicked = 'show_crit_review';
	hist_CheckAdd('hist_showCritReview','critique'+id, cObj);
	dpv_showCritReview( id, topic );
}

function hist_WriteAReview(){
	hist_CheckAdd('hist_WriteAReview','critique', sCurTopic );
	aj_WriteAReview();
}



function aj_WriteAReview(){
	if (skipFormatThumbs == true ){
		skipFormatThumbs = false;
		return;
	}
	
	if (sCurTopic == 'doorpostinfo'){
		formatLoadPg('doorpostinfo');
		return;
	}

	if (sCurTopic == 'hope'){
		aj_TopicConversation();
		return;
	}
	MM_swapImage( 'writeareview' ,'','http://c0625612.cdn.cloudfiles.rackspacecloud.com/webimages/writeareview2.jpg',1);
	if ($('topicconversation')){
		MM_swapImage( 'topicconversation' ,'','http://c0625612.cdn.cloudfiles.rackspacecloud.com/webimages/topicconversation.jpg',1);
	}

	if ( onCritique == false ){
		onCritique = true;
		aj_MarkLoadingBlack('videocontent', 'Loading...');
		new Ajax.Updater('videocontent', curPath+'handler.php', { parameters: {'event':'buildvideocontent', 'subcontent':'displayCritInfo'}} );
	}

	aj_MarkLoading('critFilmCommentDiv', 'Loading...');
	new Ajax.Updater( 'critFilmCommentDiv', curPath+'handler.php', { parameters: {'event':'drawcritique'}, onComplete: function(){
			Element.hide('critique_terms');
																														}});
	formatLoadPg('writeareview');
	
	aj_LoadFilmThumbs( true );
}

/*
 * NEWS FEED RELATED FUNCTIONS COMMON THROUGHOUT THE SITE
 */
 function nf_commentForm( itemNo ){
		var cf = $("commentInputDiv_"+itemNo);
		$('nf_comment').value="Write a comment...";
		$('nf_id').value = itemNo;
		
		cf.show();
		var tmp = $('nf_comment_template').remove();
		cf.insert(tmp);
	}
function nf_replaceForm( ){
		var tmp = $('nf_comment_template').remove();
		$('nf_holder').insert(tmp);
		$('nf_comment').value="Write a comment...";
		
	}
function nf_remComment( cid ){
		if (!confirm('You are about to permanently delete this comment, are you sure you wish to continue?')){
			return;
		}
		aj_MarkLoadingBlack("NFC_"+cid, "Removing this comment...");
		new Ajax.Updater( "NFC_"+cid, curPath+'handler.php', {parameters:{'event':'remfeedcomment', 'citem':cid},evalScripts:true, insertion: 'bottom'});
	}
function nf_postComment( ){
		var itemNo = $('nf_id').value;
		var cfd = $('commentsForItem_'+itemNo);
		if (itemNo == 0){
			return;
		}
		var cmt =  $('nf_comment').value;
		if (cmt == ""){
			return;
		}
		new Ajax.Updater( cfd, curPath+'handler.php', {parameters:{'event':'addfeedcomment', 'item':itemNo, 'txt': cmt }, insertion: 'bottom'});
		nf_replaceForm();
		//cfd.insert( $('nf_comment').value );
	}	