// Popup Windows
function strOpenWindowFeatures(iWindowWidth, iWindowHeight) {
	var iMouseX = 10;
	var iMouseY = 10;
	if ( window.event != null ) {
		iMouseX = window.event.screenX;
		iMouseY = window.event.screenY; }
	var iScreenX = window.screen.availWidth;
	var iScreenY = window.screen.availHeight;
	var iWindowLeft = iMouseX;
	if ( iWindowLeft + iWindowWidth > iScreenX ) { iWindowLeft = iMouseX - iWindowWidth - 10; }
	if ( iWindowLeft < 10 ) { iWindowLeft = 10; }
	var iWindowTop = iMouseY;
	if ( iWindowTop + iWindowHeight > iScreenY - 50 ) { iWindowTop = iMouseY - iWindowHeight - 60; }
	if ( iWindowTop < 10 ) { iWindowTop = 10; }
	return "width=" + iWindowWidth + ", height=" + iWindowHeight + ", left=" + iWindowLeft + ", top=" + iWindowTop + ", resizable=yes, scrollbars=yes";
}
function fnOpenWindow(strWindowURL, strWindowName, iWindowWidth, iWindowHeight) {
	var objNewWindow = window.open(strWindowURL, strWindowName, strOpenWindowFeatures(iWindowWidth, iWindowHeight), false);
	if ( objNewWindow != null ) { objNewWindow.focus(); }
}

// Simplified Popup
// Usage: <a onclick="return popUp(this.href,250,250);" href="popup.aspx">Link</a>
function popUp(theLink, popUpWidth, popUpHeight) {
	var popUpWindow = window.open(theLink, "popUp",
	"width=" + popUpWidth + ", height=" + popUpHeight +
	", left=50, top=50, resizable=yes, scrollbars=yes", false);
	if ( popUpWindow != null ) { popUpWindow.focus(); }
	return false;
}
function closePopUp() {
	window.close();
}

// ** fnSimulateRepeaterCommand **
//
// This function is commonly used to simulate an "ItemCommand" event for
//  a DataBound WebControls.Repeater object with EnableViewState = False.
//
// "fnSimulateRepeaterCommand" works around what is essentially a chicken-and-egg problem...
// The "ItemCommand" event cannot fire until the Repeater is bound,
//  but DataBinding does not take place unless the event fires.
//
// (In Avera, this situation arises when an "Approve" button
//   is displayed on the list of CmsPages or CmsPanels.)
//
// To use this function, write server-side codebehind to handle
//  a "Click" event on a WebControls.LinkButton control outside
//  the Repeater or other templated DataBound control, and look
//  for the value in an HtmlControls.HtmlInputHidden control.
// Generally, the LinkButton will have a "Text" property
//  of empty string, but it MUST be visible on the Page
//  to be a valid postback target.
//
// The JavaScript places the strHiddenFieldValue parameter
//  into the HtmlInputHidden control, then causes a postback
//  to fire on the LinkButton control.
//
// Use the strLinkButtonUniqueID and strHiddenFieldUniqueID
//  parameters to identify the LinkButton and HtmlInputHidden
//  controls with the "UniqueID" property.
//
// Note how join and split are used to create the appropriate strings
//  understood by the .NET aspnet_client system_web v1.1.4322.
//
// -- KRopa, April 15 2004
function fnSimulateRepeaterCommand(strLinkButtonUniqueID, strHiddenFieldUniqueID, strHiddenFieldValue) {
	//alert("fnSimulateRepeaterCommand('" + strLinkButtonUniqueID + "', '" + strHiddenFieldUniqueID + "', '" + strHiddenFieldValue + "');");
	// Split and Join the UniqueID property of the LinkButton to get
	//  the DHTML ID and .NET __doPostBack ID for the server control.
	var aryLinkButtonID = strLinkButtonUniqueID.toString().split("$");
	var strLinkButtonClientID = aryLinkButtonID.join("_");
	var strLinkButtonPostBackID = aryLinkButtonID.join("$");
	// Split and Join the UniqueID property of the HtmlInputHidden
	//  to get the DHTML ID for the server control.
	var aryHiddenFieldID = strHiddenFieldUniqueID.toString().split("$");
	var strHiddenFieldClientID = aryHiddenFieldID.join("_");
	// Look for DHTML objects for the LinkButton and HtmlInputHidden.
	var objLinkButton = document.getElementById(strLinkButtonClientID);
	var objHiddenField = document.getElementById(strHiddenFieldClientID);
	// A variable to verify that everything will work...
	var blnOK = false;
	//alert("typeof __doPostback = '" + typeof __doPostBack + "'");
	if ( typeof __doPostBack == 'function' ) {
		if ( objLinkButton != null ) {
			if ( typeof objLinkButton == 'object' ) {
				if ( objHiddenField != null ) {
					if ( typeof objHiddenField == 'object' ) {
						if ( objHiddenField.value != null ) {
							if ( strHiddenFieldValue.toString().length > 0 ) {
								blnOK = true;
							} else { alert("ERROR! strHiddenFieldValue parameter is an empty string!"); }
						} else { alert("ERROR! DHTML element with id='" + strHiddenFieldClientID + "' has no 'value' attribute!"); }
					} else { alert("ERROR! DHTML element with id='" + strHiddenFieldClientID + "' is not an object!"); }
				} else { alert("ERROR! Could not find a DHTML element with id='" + strHiddenFieldClientID + "'"); }
			} else { alert("ERROR! DHTML element with id='" + strLinkButtonClientID + "' is not an object!"); }
		} else { alert("ERROR! Could not find a DHTML element with id='" + strLinkButtonClientID + "'"); }
	} else { alert("ERROR! Could not find a '__doPostBack' function!"); }
	if ( blnOK == true ) {
		objHiddenField.value = strHiddenFieldValue.toString();
		try {
			__doPostBack(strLinkButtonPostBackID,'');
		} catch (err) {
			alert("JavaScript error:\n" + err.description);
		}
	}
}

// ** fnConfirmCheckboxes **
//
// This function returns true or false, and is commonly used to
//  verify that at least one checkbox is checked in a list of
//  DHTML checkboxes with the same "name" attribute.
// <input type="submit" onclick="return fnConfirmCheckboxes('[value of "name" attribute]');" />
function fnConfirmCheckboxes(strCheckboxesName, strErrorMessage, strConfirmMessage) {
	var blnOK = false;
	var strAlertMessage = "Please check at least one item.";
	if ( strErrorMessage != null ) {
		if ( strErrorMessage.toString().length > 0 ) {
			strAlertMessage = strErrorMessage.toString();
		}
	}
	var strConfirmQuestion = "Are you sure?";
	if ( strConfirmMessage != null ) {
		if ( strConfirmMessage.toString().length > 0 ) {
			strConfirmQuestion = strConfirmMessage.toString();
		}
	}
	var i = 0;
	var objCheckbox;
	var objCheckboxes = document.getElementsByName(strCheckboxesName.toString());
	if ( objCheckboxes != null ) {
		if ( typeof objCheckboxes == 'object' ) {
			if ( objCheckboxes.length > 0 ) {
				for (i = 0; i < objCheckboxes.length; i++) {
					objCheckbox = objCheckboxes.item(i);
					if ( objCheckbox.checked != null ) {
						if ( objCheckbox.checked == true ) { blnOK = true; }
					} else { alert("ERROR! Element at index " + i.toString() + " of '" + strCheckboxesName.toString() + "' collection has no 'checked' attribute!"); }
				}
				if ( blnOK ) {
					blnOK = confirm(strConfirmQuestion);
				} else { alert(strAlertMessage); }
			}
			else {
				objCheckbox = objCheckboxes.item(0);
				if ( objCheckbox.checked != null ) {
					if ( objCheckbox.checked == true ) {
						blnOK = confirm(strConfirmQuestion);
					} else { alert(strAlertMessage); }
				} else { alert("ERROR! The one '" + strCheckboxesName.toString() + "' element has no 'checked' attribute!"); }
			}
		} else { alert("ERROR! DHTML element named '" + strCheckboxesName.toString() + "' is not an object!"); }
	} else { alert("ERROR! Could not find a DHTML element named '" + strCheckboxesName.toString() + "'"); }
	return blnOK;
}

// Cross-Browser Block Element Display Toggler
function toggleElement(elId) {
	var visibleStyle = "block";
	if (!document.all) {
		var el = document.getElementById(elId);
		if ((el != null) && (typeof(el) == 'object')) {
			var elName = el.tagName.toLowerCase();
			if (elName == "tr") {
				visibleStyle = "table-row";
			}
			else if (elName == "tbody") {
				visibleStyle = "table-row-group";
			}
		} else {
			alert("ElementId '" + elId + "' is null or not an object.");
		}
	}
	var v = ((document.getElementById(elId).style.display == visibleStyle) || (document.getElementById(elId).style.display == ""));
	document.getElementById(elId).style.display = v ? "none" : visibleStyle;
	return false;
}

// Adding Event Handlers
function addLoadEvent(fn) {
	return addEvent(window, "load", fn, false);
}
function addEvent(elm, evType, fn, useCapture) {
	if (elm == null) {
		alert("The element to which to attach the event is null.");
		return false;
	}
	if (evType == null) {
		alert("The type of event to attach is null.");
		return false;
	}
	if (evType == "") {
		alert("The type of event to attach is empty.");
		return false;
	}
	if (fn == null) {
		alert("Cannot add null value to an event handler.");
		alert(elm);
		alert(evType);
		return false;
	}
	if (typeof(fn) != "function") {
		alert("Cannot add any JavaScript types except functions to an event handler.");
		return false;
	}
	if (elm.addEventListener) {
		elm.addEventListener(evType, fn, useCapture);
		return true;
	} else if (elm.attachEvent) {
		var r = elm.attachEvent("on" + evType, fn);
		return r;
	} else {
		elm["on" + evType] = fn;
		return true;
	}
}

//Surf and Edit CMS info show/hide/positioning functions
function handleCmsInfoAndPanelButtonClick(obj)
{
	var $objParent = $(obj).parent();
	var $cmsInfoObj = $objParent.next();
	$cmsInfoObj.toggleClass('cmsinfoshow');
	var left = $objParent.position().left;
	var width = $cmsInfoObj.width();
	var top = $objParent.position().top - $cmsInfoObj.height() + 57;

	left = left - width - 3;
	$cmsInfoObj.css({position: "absolute",left: left, top: top});
}
function closeCmsInfoObj(obj)
{
	$(obj).parent().removeClass('cmsinfoshow');
}

// PHOTO SLIDER
addLoadEvent(initializePhotoSliders);

function initializePhotoSliders()
{
	//Set the width of the slider to the largest image for each slider on the page
	var theSliders = $('.PhotoSlider').each(function(index){
		var maxWidth = 0;
		var firstWidth = 0;
		var imgCount = 0;

		var thisPhotoSlider = new PhotoSliderObj(index + 1);
		thisPhotoSlider.DomElement = this;
		$(this).find('img').each(function(index2){
			imgCount++;

			thisPhotoSlider.images[index2] = this;

			if(firstWidth == 0)
			{
				firstWidth = $(this).width();
			}

			if( (maxWidth == 0) || ($(this).width() > maxWidth) )
			{
				maxWidth = $(this).width();
			}
		});

		//Set properties of slider
		thisPhotoSlider.sliderLength = imgCount;
		thisPhotoSlider.slideWidth = maxWidth;
		thisPhotoSlider.init(firstWidth);
	});
}

function PhotoSliderObj(id)
{
	this.id = id;
	this.sliderLength = 0;
	this.slideWidth = 0;
	this.scrollNum = 0; // number of items scrolled left
	this.DomElement;
	this.slideSpeed = "slow";
	this.init = function(firstWidth)
	{
		this.addMarkup(firstWidth);

		$(".Next",this.DomElement).bind("click",{SliderObj:this,cssClass:".Next",alternateClass:".Prev"}, Slider_ButtonClick);
		$(".Prev",this.DomElement).bind("click",{SliderObj:this,cssClass:".Prev",alternateClass:".Next"}, Slider_ButtonClick);
	};
	this.addMarkup = function(firstWidth)
	{
		$(this.DomElement).wrapInner('<div class="Border"></div>');
		$('ul',this.DomElement).wrap('<div class="Overflow"></div>');

		//Set the photo slider to the largest width
		$(this.DomElement).css("width",this.slideWidth + 10 + "px");

		$('<p class="PhotoCaption" />').insertAfter($('.Overflow',this.DomElement));

		$('.Overflow ul',this.DomElement).addClass('Container');

		//Set the overflow to the first image width
		$('.Overflow',this.DomElement).css("width",firstWidth + "px");

		$('.Container li',this.DomElement).addClass('Slide');
		$('<div class="Buttons"></div>').insertAfter($('p.PhotoCaption',this.DomElement));
		$('<a href="#" class="Prev"></a>').appendTo($('.Buttons',this.DomElement));
		$('<a href="#" class="Next"></a>').appendTo($('.Buttons',this.DomElement));
		$('<em class="Count"></em>').insertBefore($('.Next',this.DomElement));

		$(".Count",this.DomElement).prepend("<span></span>&nbsp;of " + this.sliderLength );
		var ContainerWidth = this.sliderLength * (this.slideWidth + 10);
		$(".Container",this.DomElement).css("width",ContainerWidth + "px");
		$(".Container .Slide",this.DomElement).eq(0).css("width",firstWidth + "px");
		$(".Prev",this.DomElement).addClass("Inactive");
		$(".Count span",this.DomElement).html(1);

		var $currentSlide = $(".Slide",this.DomElement).eq(0);
		$(".PhotoCaption",this.DomElement).html($("img", $currentSlide).attr("alt"));
	};
	this.images = new Array();
}

//Firefox binds two click events when user double clicks the previous or next buttons so only allow one click
//event in a half second by using this flag and the setTimeout function : timerToAllowClick to flip the flag back
//after a half second.
var allowClick = true;

/// This function handles the click event for all buttons (Previous and Next inside the PhotoSlider)
function Slider_ButtonClick(event)
{
	if(allowClick)
	{
		//Assign Parameters from data oblject passed by jQuery, to local variables.
		var SliderObj = event.data.SliderObj;

		var OverflowWidth = 0;
		var cssClass = event.data.cssClass;
		var alternateClass = event.data.alternateClass;
		var isNext = cssClass == ".Next";
		var animateLeft = 0;

		animateLeft = parseInt($(".Container",SliderObj.DomElement).css("left"))

		//Determine if we have reached the ends
		if( ( (SliderObj.scrollNum == 0) && (!isNext) ) ||
			( (SliderObj.scrollNum == (SliderObj.sliderLength - 1) ) && (isNext) ) )
		{
			return false;
		}

		//Determine the current scroll number based on whether we are navigating forward or backward
		if(isNext)
		{
			//Get width of next image to determine how far to extend the overflow area
			OverflowWidth = SliderObj.images[SliderObj.scrollNum + 1].width + 10;
			animateLeft -= SliderObj.images[SliderObj.scrollNum].width + 10;
			SliderObj.scrollNum++;
		}
		else
		{
			SliderObj.scrollNum--;
			OverflowWidth = SliderObj.images[SliderObj.scrollNum].width + 10;
			animateLeft += SliderObj.images[SliderObj.scrollNum].width + 10;
		}

		$('.Overflow',SliderObj.DomElement).css("width",OverflowWidth + "px");

		var shouldContinue = isNext
			? animateLeft + parseInt($(".Container",SliderObj.DomElement).css("width")) > 0
			: (animateLeft + parseInt($(".Container",SliderObj.DomElement).css("width"))) <= parseInt($(".Container",SliderObj.DomElement).css("width"));

		if (shouldContinue)
		{
			$(alternateClass,SliderObj.DomElement).removeClass("Inactive");

			$(".Container",SliderObj.DomElement).animate({left: animateLeft}, SliderObj.slideSpeed, function()
			{
				$(this).css("left",animateLeft);

				//****** SETS THE Text Of the Caption on the box to reflect current Image Index ******//
				var current = parseInt($(".Count span", SliderObj.DomElement).html());

				//The next two lines Copies the text from the alt of the new Img being scrolled to and then puts it in the title of the correct Image Container.

				//if its next you do not subtract anything because the div ids are 1 based and you will get a node in the correct slot.
				// however if the user clicked the back button, then you subtract 2, one for the one based index offset and 1 more for the back click.
				var currentSlide = $(".Slide", SliderObj.DomElement).eq((isNext ? current : (current - 2)));

				if($("img", currentSlide).attr("alt") != null)
				{
					$(".PhotoCaption", SliderObj.DomElement).html($("img", currentSlide).attr("alt"));
				}
				else
				{
					$(".PhotoCaption", SliderObj.DomElement).html("&nbsp;");
				}

				var newCurrent = isNext ? current + 1: current -1;

				$(".Count span",SliderObj.DomElement).html(newCurrent);
				//****** END SETS THE Text ... ******//

				var hitLimit = isNext
							? parseInt($(".Container",SliderObj.DomElement).css("left")) + parseInt($(".Container",SliderObj.DomElement).css("width")) <= SliderObj.slideWidth * SliderObj.scrollNum
							: parseInt($(".Container",SliderObj.DomElement).css("left")) == 0;
				if (hitLimit)
				{
					$(cssClass,SliderObj.DomElement).addClass("Inactive");
					$(cssClass,SliderObj.DomElement).click(function(){return false;});
				}
				else
				{
					$(cssClass,SliderObj.DomElement).bind("click",{SliderObj:SliderObj,alternateClass:alternateClass,cssClass:cssClass}, Slider_ButtonClick);
				}

				$(alternateClass,SliderObj.DomElement).bind("click",{SliderObj:SliderObj,cssClass:alternateClass,alternateClass:cssClass}, Slider_ButtonClick);
			});

			allowClick = false;
			setTimeout(timerToAllowClick,500);
		}
	}

	return false;
};

function timerToAllowClick()
{
	allowClick = true;
}

// TABS
// Copyright (c) 2006 Patrick Fitzgerald
// http://www.barelyfitz.com/projects/tabber/
/* Optional: set an ID for each tab navigation link */
var tabberOptions = { 'addLinkId': true };
/* start minified tabs script*/
function tabberObj(argsObj)
{var arg;this.div=null;this.classMain="TabContainer";this.classMainLive="TabContainerlive";this.classTab="Tab";this.classTabDefault="Tabdefault";this.classNav="Tabnav ClearFix";this.classTabHide="Tabhide";this.classNavActive="Tabactive";this.summaryElements=['h2'];this.summaryElementsStripHTML=true;this.removeSummary=true;this.addLinkId=false;this.linkIdFormat='<tabberid>nav<tabnumberone>';for(arg in argsObj){this[arg]=argsObj[arg];}
this.REclassMain=new RegExp('\\b'+this.classMain+'\\b','gi');this.REclassMainLive=new RegExp('\\b'+this.classMainLive+'\\b','gi');this.REclassTab=new RegExp('\\b'+this.classTab+'\\b','gi');this.REclassTabDefault=new RegExp('\\b'+this.classTabDefault+'\\b','gi');this.REclassTabHide=new RegExp('\\b'+this.classTabHide+'\\b','gi');this.tabs=new Array();if(this.div){this.init(this.div);this.div=null;}}
tabberObj.prototype.init=function(e)
{var
childNodes,i,i2,t,defaultTab=0,DOM_ul,DOM_li,DOM_a,aId,headingElement;if(!document.getElementsByTagName){return false;}
if(e.id){this.id=e.id;}
this.tabs.length=0;childNodes=e.childNodes;for(i=0;i<childNodes.length;i++){if(childNodes[i].className&&childNodes[i].className.match(this.REclassTab)){t=new Object();t.div=childNodes[i];this.tabs[this.tabs.length]=t;if(childNodes[i].className.match(this.REclassTabDefault)){defaultTab=this.tabs.length-1;}}}
DOM_ul=document.createElement("ul");DOM_ul.className=this.classNav;for(i=0;i<this.tabs.length;i++){t=this.tabs[i];t.headingText=t.div.summary;if(this.removeSummary){t.div.summary='';}
if(!t.headingText){for(i2=0;i2<this.summaryElements.length;i2++){headingElement=t.div.getElementsByTagName(this.summaryElements[i2])[0];if(headingElement){t.headingText=headingElement.innerHTML;if(this.summaryElementsStripHTML){t.headingText.toString().replace(/<br>/gi," ");t.headingText=t.headingText.toString().replace(/<[^>]+>/g,"");}
break;}}}
if(!t.headingText){t.headingText=i+1;}
DOM_li=document.createElement("li");t.li=DOM_li;DOM_a=document.createElement("a");DOM_a.innerHTML = t.headingText;DOM_a.href="javascript:void(null);";DOM_a.summary=t.headingText;DOM_a.onclick=this.navClick;DOM_a.tabber=this;DOM_a.tabberIndex=i;if(this.addLinkId&&this.linkIdFormat){aId=this.linkIdFormat;aId=aId.toString().replace(/<tabberid>/gi,this.id);aId=aId.toString().replace(/<tabnumberzero>/gi,i);aId=aId.toString().replace(/<tabnumberone>/gi,i+1);aId=aId.toString().replace(/<tabsummary>/gi,t.headingText.toString().replace(/[^a-zA-Z0-9\-]/gi,''));DOM_a.id=aId;}
DOM_li.appendChild(DOM_a);DOM_ul.appendChild(DOM_li);}
e.insertBefore(DOM_ul,e.firstChild);e.className=e.className.toString().replace(this.REclassMain,this.classMainLive);this.tabShow(defaultTab);if(typeof this.onLoad=='function'){this.onLoad({tabber:this});}
return this;};tabberObj.prototype.navClick=function(event)
{var
rVal,a,self,tabberIndex,onClickArgs;a=this;if(!a.tabber){return false;}
self=a.tabber;tabberIndex=a.tabberIndex;a.blur();if(typeof self.onClick=='function'){onClickArgs={'tabber':self,'index':tabberIndex,'event':event};if(!event){onClickArgs.event=window.event;}
rVal=self.onClick(onClickArgs);if(rVal===false){return false;}}
self.tabShow(tabberIndex);return false;};tabberObj.prototype.tabHideAll=function()
{var i;for(i=0;i<this.tabs.length;i++){this.tabHide(i);}};tabberObj.prototype.tabHide=function(tabberIndex)
{var div;if(!this.tabs[tabberIndex]){return false;}
div=this.tabs[tabberIndex].div;if(!div.className.match(this.REclassTabHide)){div.className+=' '+this.classTabHide;}
this.navClearActive(tabberIndex);return this;};tabberObj.prototype.tabShow=function(tabberIndex)
{var div;if(!this.tabs[tabberIndex]){return false;}
this.tabHideAll();div=this.tabs[tabberIndex].div;div.className=div.className.toString().replace(this.REclassTabHide,'');this.navSetActive(tabberIndex);if(typeof this.onTabDisplay=='function'){this.onTabDisplay({'tabber':this,'index':tabberIndex});}
return this;};tabberObj.prototype.navSetActive=function(tabberIndex)
{this.tabs[tabberIndex].li.className=this.classNavActive;return this;};tabberObj.prototype.navClearActive=function(tabberIndex)
{this.tabs[tabberIndex].li.className='';return this;};function tabberAutomatic(tabberArgs)
{var
tempObj,divs,i;if(!tabberArgs){tabberArgs={};}
tempObj=new tabberObj(tabberArgs);divs=document.getElementsByTagName("div");for(i=0;i<divs.length;i++){if(divs[i].className&&divs[i].className.match(tempObj.REclassMain)){tabberArgs.div=divs[i];divs[i].tabber=new tabberObj(tabberArgs);}}
return this;}


/*function tabberAutomaticOnLoad(tabberArgs)
{var oldOnLoad;if(!tabberArgs){tabberArgs={};}
oldOnLoad=window.onload;if(typeof window.onload!='function'){window.onload=function(){tabberAutomatic(tabberArgs);};}else{window.onload=function(){oldOnLoad();tabberAutomatic(tabberArgs);};}}
*/

var TabLoadedArray = new Array();

//if(typeof tabberOptions=='undefined')
//{
$(function(){
	tabberAutomatic(tabberOptions);
	var TabLoadedCounter = 0;
	for (TabLoadedCounter = 0;TabLoadedCounter <TabLoadedArray.length;TabLoadedCounter++)
	{
		TabLoadedArray[TabLoadedCounter]();
	}

});

//TabLoadedArray

//}//else{if(!tabberOptions['manualStartup']){tabberAutomaticOnLoad(tabberOptions);}}
