//================================================================
//  BEGIN: ElementVisibility object and associated functions
/*
    Purpose:    The ElementVisibility object allows binding 
                an "event" element (ex: <a id="link-elt" href="">Link</a>)
                to a "visibility" element (normally a div). 
                Instantiating the object creates an onclick handler
                on the "event" element which will toggle the 
                display of the "visibility" element.
                
     Date:      2008-04-10
*/
//================================================================
function ElementVisibility(obj_config) {
    this.eventElement   = document.getElementById(obj_config.evt_element_id);
    this.visElement     = document.getElementById(obj_config.vis_element_id);
    this.liElement      = document.getElementById(obj_config.li_element_id);
    this.visible        = false;
    this.DISPLAY_NONE   = "none";
    this.DISPLAY_BLOCK  = "block";
    
    this.bind();
}
//================================================================
ElementVisibility.prototype.toggleDisplay=function() {
    // Show/hide vis element.
    this.visElement.style.display = ( this.visible ? this.DISPLAY_NONE : this.DISPLAY_BLOCK);
    
    // Toggle li arrow.
    this.liElement.style.backgroundImage = ( this.visible ? "url(http://images.homegain.com/i/c/bullet_arrow.gif)" : "url(http://images.homegain.com/i/arrows/down_orange_01.gif)" );
    
    // Toggle visibility.
    this.visible = !this.visible;
}
//================================================================
ElementVisibility.prototype.bind = function() {
    this.eventElement.modelObj  = this;
    this.eventElement.onclick   = ElementVisibilityEventHandler;
}
//================================================================
function ElementVisibilityEventHandler(event){
    var oModel = this.modelObj;
    var oEvent = ( event ? event : window.event );
    
    if ( oModel ) {
        oModel.toggleDisplay();
    }
    return true;
}
//================================================================
//  END: ElementVisibility object and associated functions
//================================================================
function addWindowEventCallback(event_name, function_reference) {
   if (window.addEventListener) {
      window.addEventListener(event_name, function_reference, false);
   } else if (window.attachEvent) {
      //ie browser
      window.attachEvent("on" + event_name, function_reference);
   }
}
//================================================================
// RFC4958 - blog.js
// 04/07/2008 - cp

// This is a set of JavaScript functions for the Agent's Blog Management pages

// Function for the pages that contain more than one checkbox that will toggle on and off using Select: All None prompt for the user.
// coded by jc and cr
var strCBFieldName		= "blogCheckbox";
var strDelButtonName		= "btnDelete";

function check(method) {
	var checkboxes = document.getElementsByTagName("input");
	for ( var i = 0; i < checkboxes.length; i++) {
		checkboxes[i].checked = method;
	}
	checkBoxes();
}

function checkBoxes() {
	var bAnyChecked = false;
	var checkboxes = document.getElementsByTagName("input");

	for ( var i = 0; i < checkboxes.length; i++) {
		if ( checkboxes[i].checked ) {
			bAnyChecked = true;
				break;
			}
		}
	toggleButtonEnable(bAnyChecked);
	
}

function toggleButtonEnable(status) {
	var strClass = "";
	var oButton = document.getElementById(strDelButtonName);

	if ( status ) {
		strClass = "btn_active";
	}
	else {
		strClass = "btn_inactive";
	}
	oButton.className		= strClass;
	oButton.disabled		= !status;

}


//================================================================

// Character counter. Used in blog to determine if user has exceeded the limit of allowable characters for a field.
// When the limit has been reached, no more characters will be allowed to be entered.
function characterCount(fieldName,myCounter,maxChars) {
  var len = fieldName.value.length;
  if (len > maxChars) {
    fieldName.value = fieldName.value.substring(0,maxChars);
    len = maxChars;
  }
  document.getElementById(myCounter).value = maxChars - len;
}
//================================================================
// Note: this validation test is prior to exMethod being created which will test for validation. However, this logic will persist.
// Validation and set display of error messages for entries under the minimum characters entered.
// Function used in the new_post and the edit_post pages.
function postCheck() {
	var postTitleLen = document.newPostForm.post_title.value.length;
	var postBodyLen = document.newPostForm.post_text.value.length;
	var windowURL = window.location.toString();
	
	if (postTitleLen < 4) {
		document.getElementById('postTitleCheck').style.display = 'block';
		var postTitleFlag = 0;
	} else {
		document.getElementById('postTitleCheck').style.display = 'none';
		var postTitleFlag = 1;
	}
	
	if (postBodyLen < 10) {
		document.getElementById('postBodyCheck').style.display = 'block';
		var postBodyFlag = 0;
		postFlagCalc();
	} else {
		document.getElementById('postBodyCheck').style.display = 'none';
		var postBodyFlag = 1;
		postFlagCalc();
	}

// Condition checked to see if this is coming from the new_post or edit_post page. Will display one of two messages on the BMP based on what page is this function run from.
	function postFlagCalc() {
		var postFlag = postTitleFlag + postBodyFlag;
		if (postFlag < 2) {
		} else {
			if (windowURL.indexOf('new') != -1) {
				window.location = '/agent/blog/new_post?posted=1';
			} else if (windowURL.indexOf('edit') != -1) {
				window.location = '/agent/blog/edit_post?posted=1';
			}
		}
	}
}

//================================================================
// Note: this validation test is prior to exMethod being created which will test for validation. However, this logic will persist.
// Set display of either Publish or Reject Comments of comments.
// Function used in the review_new_comments page
function commentCheck() {
	
}
	

// Condition checked to see if this is coming from the new_post or edit_post page. Will display one of two messages on the BMP based on what page is this function run from.
function postCommentFlag() {

}




