function removeScript(){
	var script;
	while (script = document.getElementById('JscriptId')) {
		script.parentNode.removeChild(script);
		for (var prop in script) {
			delete script[prop];
		}
	}
}
function commentDataResponse(jData){
	if (jData == 'true') {
		alert('Saved!');
	} else {
		alert('Error!');
	}
	removeScript();
}

function requestCommentData(server,el,id,elid,eltype){
	var req  = server+"/comments/comments_data_remote.cfm?el="+el+"&id="+id+"&elid="+elid+"&eltype="+eltype;
	bObj = new JSONscriptRequest(req);
	bObj.buildScriptTag();
	bObj.addScriptTag();
}

function replyTo(commentForm,commentID) {
	document.forms[commentForm].elements["replyto_id"].value = commentID;
 };

function reportAbuse(id,elid,eltype,dynserver) {
	if (id != '') {
		requestCommentData(dynserver,'abuse',id,elid,eltype);
		$("#abuse"+id).html("Reported");
	};
};

function recordVote(id,elid,eltype,dynserver) {
	if (id != '') {
		requestCommentData(dynserver,'vote',id,elid,eltype);
			var currentRating = $("#vote"+id).find('.count').html();
			var newRating = parseInt(currentRating)+1;
			$("#vote"+id).find('.count').html(newRating);
			$("#vote"+id).removeClass('recommend').addClass('recommended');
			$("#vote"+id).children().children().unwrap();				
	};
};

function checkComments(obj) {
	var text = null; 
	var cleanText="";
	var oForm=obj.form;
	<!---FCKEditor generates a textarea only on Node, Builder shows the FCKEditor so we create two ways of validating the text entered--->
	if (typeof FCKeditorAPI == 'undefined') {
		text = oForm["comment"].value;
	}
	else {
		var oEditor = FCKeditorAPI.GetInstance('comment');
		if (oEditor) {
			text = oEditor.GetXHTML(true);
		}
	}    
	text = text.replace(/^\s+|\s+$/g, '');//trim the string

	optionalName = oForm["optionalName"].value;
	if(text.length == 0)
			{
			alert('Comments box can not be left empty, please provide some comments before submitting.');
			return false;
			}
	else if(text.length >= 2000)
			{
			alert('Please enter a maximum of 2000 characters for the comment.');
			return false;
			}
	else if(optionalName.length < 2)
			{
			alert('Please enter a minimum of 2 characters for the name.');
			return false;
			}
	else
		{
		//	if (getCookie("LOGGEDIN") == 'true') {
				oForm.submit();
		/*	}else{
				logMeIn(obj);
				return false;
			}*/
		}

	return false;

};

/*
function logMeIn(obj){
	//Start timer to check for login window close
	startLoginTimerComments(obj.form.id);

	//Open login/registration lightbox
	$("#commentSignInButton").click();
	return false;
}	
*/
	
/* FUNCTIONS FOR TRACKING LOGIN DIALOGUE BOX CHANGES */	

/*
var tc;
var timer_period_comments=20;	
var timer_comments_is_on=0;
var timer_comments_formId="";

function loginTimerCommentsCheck()
{
	if (window.location.hash == "#loginComplete") {
    		window.location.hash = "";

		//alert('loginTimerCommentsCheck() - found loginComplete');
		if (getCookie("LOGGEDIN") == 'true') {
			$('#'+timer_comments_formId).submit();
		}else{
			//alert('loginTimerCommentsCheck() - Back in parent - user was not logged in yet. stopping.');
		}
	}else if(window.location.hash == "##userRegistrationStep3"
		|| window.location.hash == "#showConfirmationFacebook"){
		//USER COMPLETED REGISTRATION. NEED TO CLOSE PRETTY PHOTO.
		//USER WILL NEED TO CLICK ACTIVATION EMAIL LINK BEFORE LOG IN
		//alert('loginTimerCheck() - USER COMPLETED REGISTRATION. CLOSE PRETTY PHOTO.');
	    	window.location.hash = "";
		jQuery.prettyPhoto.close();
		stopLoginTimerComments();
	}else {
		//alert('loginTimerCommentsCheck() - reseting timeout');
		tc=setTimeout("loginTimerCommentsCheck()",timer_period_comments);
    }
}

function startLoginTimerComments(formId)
{
	if (!timer_comments_is_on)
	  {
	  timer_comments_is_on=1;
		timer_comments_formId=formId;
	  loginTimerCommentsCheck();
	  }
}

function stopLoginTimerComments()
{
	clearTimeout(tc);
	timer_comments_is_on=0;
}		
*/
