function showResponse(response)
{
	// for AJAX testing purposes
    alert(response.responseText);
}

// BLOG COMMENTING FUNCTIONS ====================================================================
function closeCommentBox (boxToClose, divID){
	var truncatedDivID = divID.substr(15);
	boxToClose.innerHTML = '<div id="' + divID + '" class="floatRight"><a onclick="populateCommentBox(' + truncatedDivID + ');" class="hand"><img src="images/interface/button-comment.gif" alt="Post Comment" border="0"></a></div><div class="clearer"><img src="images/interface/clear.gif" alt=""></div>';
} 
// end closeCommentBox ------------------------------------------------------------

function populateCommentBox (blogPostID){
	var blogPostID = blogPostID;
	var activeStatus = '';
	var commentButtonDivID = $('commentButton_' + blogPostID);
	var postCommentBoxDivID = $('postCommentBox_' + blogPostID);	
	
	// Gather all existing comment boxes and close them
	var allCommentIDs = $$('div.commentBox');	
	var numberOfCommentDivs = allCommentIDs.length;
		// Iterate through each box with class commentBox
		
		for (i = 0; i < numberOfCommentDivs; i++) {
		// Evaluate name of and close each DIV
			var divname = eval('allCommentIDs[' + i + ']');
			var commentBoxID = divname.id;
			closeCommentBox(divname, commentBoxID);
		}
	
	// Hide the comment button DIV
	commentButtonDivID.hide();
	postCommentBoxDivID.show();
	// Create global variable for referencing the blogPostID after updateCommentBox is returned.
	globalBlogID = blogPostID;
	
		var url = 'ajax/ajax-comments.php';
		var pars = '&ajaxSQLaction=populateCommentsBox' + '&blogPostID=' + blogPostID;
		var myAjax = new Ajax.Request(url,
				{ method: 'get',
				  parameters: pars,
				  //onFailure:  report_error,
				  onComplete: updateCommentBox
				  });  
} // end populateProductsBox ------------------------------------------------------------


function updateCommentBox(response)
{
  // Create ID of the comment box from global variable	
  var o = 'postCommentBox_' + globalBlogID;
  
  // Change text to HTML form.
  	  var newText = response.responseText;
 		changetext(o, newText);  
 		
  // Focus on Name Field
  	var nameFieldID = $('commentName');
  	nameFieldID.focus();
 		
} // end updateCommentBox ------------------------------------------------------------

function submitComment (blogPostID){
	var blogPostID = blogPostID;
	var activeStatus = '';
	var commentButtonDivID = $('commentButton_' + blogPostID);
	var postCommentBoxDivID = $('postCommentBox_' + blogPostID);	
	
	// Hide the comment button DIV
	//commentButtonDivID.show();
	//postCommentBoxDivID.show();
	// Create global variable for referencing the blogPostID after updateCommentBox is returned.
	globalBlogID = blogPostID;

	// Comment Validation ------------------------------------------------------------
	
	// First, clear the error DIV of information
	var errorDIVLocation = $('errorDiv');
	errorDiv.innerHTML = '';
	
	var commentName = $F('commentName');
	var commentEmail = $F('commentEmail');
	var commentURL = $F('commentURL');
	var commentText = $F('commentText');
	
	isValidName = validate('isNotEmpty', commentName, 'Please make sure the name field of your comment is not left blank.', errorDIVLocation);
	isValidEmail = validate('isValidEmailAddress', commentEmail, '<p>Please enter a valid email address.<p>motum b2b will never divulge or distribute your email information, but we do ask for a valid address in order to prevent automated blog spam.', errorDIVLocation);
	//isValidURL = validate('isValidURL', commentURL, 'Please make sure your URL is valid', errorDIVLocation);
	isValidText = validate('isNotEmpty', commentText, 'Please make sure your comment field is not left blank', errorDIVLocation);
	
	if ((isValidName == true) && (isValidEmail == true) && (isValidText == true)) {
	// Pass Parameters ----------------------------------------------------------------
		var url = 'ajax/ajax-comments.php';
		var pars = '&ajaxSQLaction=submitComment' 
		+ '&blogPostID=' + globalBlogID
		+ '&commentName=' + $F('commentName')
		+ '&commentEmail=' + $F('commentEmail')
		+ '&commentURL=' + $F('commentURL')
		+ '&commentText=' + $F('commentText');
		
	// Do the AJAX request --------------------------------------------------------------------		
		var myAjax = new Ajax.Request(url,
				{ method: 'get',
				  parameters: pars,
				  //onFailure:  report_error,
				  onComplete: refreshCommentBox
				  });
	} else {
		return false;
	}
} // end submitComment ----------------------------------------------------------------

function refreshCommentBox(response)
{
  // Create ID of the comment box from global variable	
  var o = 'postCommentBox_' + globalBlogID;
  
  // Change text to HTML form.
  	  var newText = response.responseText;
 		changetext(o, newText);  
} // end refreshCommentBox ------------------------------------------------------------


function hideOrShowDate(theDateDiv, theCheckbox)
{
	var theDateDivValue = theCheckbox.checked;
	
	if (theDateDivValue == true) {
		document.getElementById(theDateDiv).style.visibility = 'visible';		
	} else { 
		document.getElementById(theDateDiv).style.visibility = 'hidden';		
	}
}

function activateCommentBox(element, state)
{
	el = document.getElementById(element);
	
	if (state == 'show') {
		el.style.display = "block";
	} else {
		el.style.display = "none";		
		el.innerHTML = "";	
	}
}

function repositionProductsBox(element, theEvent) {
 	var repositionX;
	var repositionY;
 	repositionX = getMouseXY(theEvent, 'x');
  	repositionY = getMouseXY(theEvent, 'y');

	//correction for BASF template offset
	repositionX = repositionX - 165 ;
	repositionY = repositionY - 68 + 2000 ;
  	
  	//reposition the element
  	document.getElementById(element).style.left = repositionX;
  	document.getElementById(element).style.top = repositionY;
}

// TIMEOUT funciton set : destroyPopoutTimer, setPopupFadeTimer and hideThePopup
// Set the timerID to initally be blank (but defined)
var timeoutID = '';

function destroyPopoutTimer(){
	window.clearTimeout(timeoutID);
}

function setPopupFadeTimer(boxToHide, seconds){
	milliseconds = seconds*1000;
  	timeoutID = window.setTimeout("hideThePopup('" + boxToHide + "')", milliseconds);
}

function hideThePopup(divID){
 	activateProductsBox(divID, 'hide');
}
// Timeout functions end


function expandComment(){
	var d = $('comment_1_1');
	alert(d.innerHTML);
	d.hide();
	d.show();
	d.addClassName('active');
}