if (!acsJsIncluded) {
	var acsJsIncluded = true;
	function showHide(linkId, elementId, newStyle, showText, hideText) {
		if (showText == null) {showText = "(Show)";}
		if (hideText == null) {hideText = "(Hide)";}
		if (linkId.innerHTML) {link = linkId;}
		else {link = document.getElementById(linkId);}
		if (newStyle === true) {newStyle = 'inline-block';}
		else if (!newStyle) {newStyle = 'block';}

		if (link.innerHTML == showText) {
			link.innerHTML = hideText;
			try {document.getElementById(elementId).style.display = newStyle;}
			catch (e) {document.getElementById(elementId).style.display = 'inline-block';}//IE if given table-cell or similar
		}
		else {
			link.innerHTML = showText;
			document.getElementById(elementId).style.display = 'none';
		}
	}

	function simpleShowHide(elementId, newStyle) {
		if (!newStyle) {newStyle = 'block';}
		if (document.getElementById(elementId).style.display == 'none') {
			try {document.getElementById(elementId).style.display = newStyle;}
			catch (e) {document.getElementById(elementId).style.display = 'inline-block';}//IE if given table-cell or similar
		}
		else {document.getElementById(elementId).style.display = 'none';}
	}

	//Intended for toggling FCK when showing/hiding or similar needs
	function extendedShowHide(elementId, newStyle, showCommand, hideCommand) {
		if (newStyle == '') {newStyle = 'block';}
		if (document.getElementById(elementId).style.display == 'none') {
			try {document.getElementById(elementId).style.display = newStyle;}
			catch (e) {document.getElementById(elementId).style.display = 'inline-block';}//IE if given table-cell or similar
			if (showCommand) {eval(showCommand);}
		} else {
			if (hideCommand) {eval(hideCommand);}
			document.getElementById(elementId).style.display = 'none';
		}
	}

	//case insensetive on class names
	function changeClassStyle(className, properties, changes) {//(string, new Array(), new Array())
		if (!document.styleSheets) {return;}
		var rule = null;
		for (sheetCtr=0; sheetCtr<document.styleSheets.length; sheetCtr++){
			var sheet = document.styleSheets[sheetCtr];
			var rules = (sheet.cssRules? sheet.cssRules : sheet.rules);
			for (rulesCtr = 0; rulesCtr < rules.length; rulesCtr++){
				if(rules[rulesCtr] && rules[rulesCtr].selectorText && rules[rulesCtr].selectorText.toLowerCase() == className.toLowerCase()){
					rule = rules[rulesCtr];
					break;
				}//end if
			}//end foreach rule
			if (rule != null) {break;}
		}//end foreach sheet
		if (rule == null) {return false;}
		for (var index in properties) {eval("rule."+properties[index]+" = '"+changes[index]+"';");}
		return true;
	}//end function


/************************************************************************************************************************************************************************

Positioning/dragging functions

************************************************************************************************************************************************************************/

	function acsGetMousePosition(e) {
		var x,y;
		if(e.pageX || e.pageY) {
			x = e.pageX;
			if (window.pageXOffset) {x = x - window.pageXOffset;}
			y = e.pageY;
			if (window.pageYOffset) {y = y - window.pageYOffset;}
		} else {
			x = e.clientX;
			y = e.clientY;

			var browser = navigator.appName;
			if (browser == 'Microsoft Internet Explorer') {
				var b_version = navigator.appVersion;
				var version = parseFloat(b_version);
				if (version < 8) {
		 	x += (document.body.scrollLeft - document.body.clientLeft);
		 	y += (document.body.scrollTop - document.body.clientTop);
				}//end if version < 8
			}//end if MSIE
		}
		return {x:x,y:y};
	}//end function

	function acsGetElementPosition(e){
		var left = 0;
		var top = 0;
		while (e.offsetParent){
			if (e.offsetLeft) {left += e.offsetLeft;}
			if (e.offsetTop) {top += e.offsetTop;}
			e = e.offsetParent;
		}
		if (e.offsetLeft) {left += e.offsetLeft;}
		if (e.offsetTop) {top += e.offsetTop;}
		return {x:left, y:top};
	}//end function

//Begin Move Functions
	var acsMoveElementEle = null;
	var offsetX, offsetY, startX, startY = null;

	function acsMoveElement (e) {
		var x,y;
		e = e ? e : window.event;

		var pos = acsGetMousePosition(e);

		if (offsetX == null) {offsetX = pos.x;}
		if (offsetY == null) {offsetY = pos.y;}

		x = startX - (offsetX - pos.x);
		y = startY - (offsetY - pos.y);
		x = x < 0 ? 0 : x;
		y = y < 10 ? 10 : y;//using 10 to account for admin menu

		acsMoveElementEle.style.left = parseInt(x)+'px';
		acsMoveElementEle.style.top = parseInt(y)+'px';
	}//end function

	function acsMoveElementDown (ele) {
		acsMoveElementEle = ele;

		var pos = acsGetElementPosition(acsMoveElementEle);
		startX = pos.x;
		startY = pos.y;

		document.onmousemove = acsMoveElement;
		document.onmouseup = acsMoveElementUp;
	}//end function

	function acsMoveElementUp () {
		document.onmousemove = null;
		document.onmouseup = null;

		acsMoveElementEle.style.display = 'none';
		setTimeout(function() {acsMoveElementFinish();}, 10);
		offsetX = offsetY = startX = startY = null;
	}//end function

	//FF had issue with succesive attempts to move if item was not 'reset' by hiding and then reshowing
	function acsMoveElementFinish() {
		acsMoveElementEle.style.display = 'block';
		acsMoveElementEle = null;
	}
//Get Size Functions
	function getViewportSize () {
		var viewportWidth;
		var viewportHeight;
		if (typeof window.innerWidth != 'undefined') {
			viewportWidth = window.innerWidth;
			viewportHeight = window.innerHeight;
		} else if (typeof document.documentElement != 'undefined' && typeof document.documentElement.clientWidth != 'undefined' && document.documentElement.clientWidth != 0) {
			viewportWidth = document.documentElement.clientWidth;
			viewportHeight = document.documentElement.clientHeight;
		} else {
			viewportWidth = document.getElementsByTagName('body')[0].clientWidth;
			viewportHeight = document.getElementsByTagName('body')[0].clientHeight;
		}
		return {width:viewportWidth, height:viewportHeight};
	}//end function


	/************************************************************************************************************************************************************************

	Functions for adding RTF editor

	************************************************************************************************************************************************************************/
//CKEditor
	function addCk(fieldId, toolbar, cssPath, height, configOptions) {
		if (!CKEDITOR) {return;}
		if (CKEDITOR.instances[fieldId]) {CKEDITOR.instances[fieldId].setData(document.getElementById(fieldId).value);}
		else {CreateEditorCk(fieldId, toolbar, cssPath, height, configOptions);}
	}//end function

	function CreateEditorCk(fieldId, toolbar, cssPath, height, configOptions) {
		var defaultPath = '/sites/all/themes/asa/style.css';
		var sBasePath = '/sites/all/modules/ckeditor/ckeditor/';

		if (typeof(toolbar) == 'undefined') {toolbar = 'ACS_Default';}
		else if (toolbar.indexOf(' ') > 0) {toolbar = toolbar.replace(' ', '_');}
		if (typeof(height) == 'undefined') {height = 350;}

		config = {};
		config.baseHref = sBasePath;
		config.width = '100%' ;
		config.height = height ;
		config.toolbar = toolbar;
		if (typeof(cssPath) == 'string') {config.contentsCss = new Array(defaultPath, cssPath);}
		else if (cssPath && typeof(cssPath) == 'object') {
			cssPath[cssPath.length] = defaultPath;
			config.contentsCss = cssPath;
		} else {config.contentsCss = defaultPath;}

		if (configOptions && typeof(configOptions) == 'object') {
			for (var i in configOptions) {eval("config."+i+" = '"+configOptions[i]+"';");}
		}//end if sent config options

		CKEDITOR.replace(fieldId, config) ;
	}//end function

//formId deprecated. removeFck(formId, fieldId)
	function removeCk(fieldId) {
		if (!CKEDITOR) {return;}
		if (CKEDITOR.instances[fieldId]) {
			try{CKEDITOR.instances[fieldId].destroy();}
			catch (e) {/*Not working, need to fix removal*/}
		}
	}//end function

	function saveCk(fieldId) {
		if (!CKEDITOR) {return;}
		if (CKEDITOR.instances[fieldId]) {CKEDITOR.instances[fieldId].updateElement();}
	}//end function


//FCK
	function addFck(fieldId, toolbar, cssPath, height) {
		// Try to get the FCKeditor instance, if available.
		var oEditor ;
		if ( typeof( FCKeditorAPI ) != 'undefined' ) {oEditor = FCKeditorAPI.GetInstance(fieldId) ;}

		// Get the _Textarea and _FCKeditor DIVs.
		var eTextareaDiv = document.getElementById(fieldId);

		// If it is the first time, create the editor.
		if ( !oEditor ) {oEditor = CreateEditor(fieldId, toolbar, cssPath, height);}
		else {oEditor.SetData( document.getElementById(fieldId).value );}

		// Switch the DIVs display.
		eTextareaDiv.style.display = 'none' ;
	}//end function

	//formId deprecated. left for backward compat
	function removeFck(formId, fieldId) {
		var oEditor ;
		if (typeof( FCKeditorAPI ) != 'undefined') {oEditor = FCKeditorAPI.GetInstance(fieldId) ;}
		if (oEditor) {
			document.getElementById(fieldId).value = oEditor.GetXHTML();
			DestroyEditor(formId, fieldId);
		}
	}//end function

	function saveFck(fieldId) {
		var oEditor;
		if (typeof( FCKeditorAPI ) != 'undefined') {oEditor = FCKeditorAPI.GetInstance(fieldId);}
		if (oEditor) {document.getElementById(fieldId).value = oEditor.GetXHTML();}
	}//end function

	function CreateEditor(fieldId, toolbar, cssPath, height) {
		var defaultPath = '/sites/all/themes/asa/style.css';
		var sBasePath = '/sites/all/modules/fckeditor/fckeditor/';

		if (typeof(toolbar) == 'undefined') {toolbar = 'Basic';}
		if (typeof(height) == 'undefined') {height = 350;}

		// Create an instance of FCKeditor (using the target textarea as the name).
		var oFCKeditor = new FCKeditor(fieldId) ;
		oFCKeditor.BasePath = sBasePath ;
		oFCKeditor.Width = '100%' ;
		oFCKeditor.Height = height ;
		oFCKeditor.ToolbarSet = toolbar;

		if (typeof(cssPath) == 'string') {oFCKeditor.Config['EditorAreaCSS'] = new Array(defaultPath, cssPath);}
		else if (typeof(cssPath) == 'object') {
			cssPath[cssPath.length] = defaultPath;
			oFCKeditor.Config['EditorAreaCSS'] = cssPath;
		} else {oFCKeditor.Config['EditorAreaCSS'] = defaultPath;}

		oFCKeditor.ReplaceTextarea() ;
		return oFCKeditor;
	}//end function

	//formId deprecated. left for backward compat
	function DestroyEditor(formId, fieldId) {
		var configElement = document.getElementById(fieldId+'___Config');
		var frameElement = document.getElementById(fieldId+'___Frame');
		var textarea = document.getElementById(fieldId);//document.forms[formId].elements[fieldId];
		var editor = FCKeditorAPI.GetInstance(fieldId);

	 	if (editor!=null && configElement && frameElement && configElement.parentNode==textarea.parentNode && frameElement.parentNode==textarea.parentNode && document.removeChild)
	 	{
	 		editor.UpdateLinkedField();
	 		configElement.parentNode.removeChild(configElement);
	 		frameElement.parentNode.removeChild(frameElement);
	 		textarea.style.display = '';
	 		delete FCKeditorAPI.__Instances[fieldId];
	 		delete editor;
	 	}
	}
}

/************************************************************************************************************************************************************************



************************************************************************************************************************************************************************/
//list attributes of an object
function listObjectAttributes(obj) {
	var out = '';
	for (var i in obj) {
		out = out + "\n" + i;
	}
	alert(':'+out+':');
}//end function

function acsAddJs(file, type) {
	if(!this.added) {this.added = Array();}
	for (var i in this.added) {if (this.added[i] == file) {return true;}}
	this.added[this.added.length] = file;

	if (type == 'css') {
		var jsLoad = document.createElement("link")
		jsLoad.setAttribute("rel", "stylesheet")
		jsLoad.setAttribute("type", "text/css")
		jsLoad.setAttribute("href", file)
	} else {
		var jsLoad = document.createElement('script');
		jsLoad.setAttribute("type", "text/javascript");
		jsLoad.setAttribute("src", file);
	}
	document.getElementsByTagName("head")[0].appendChild(jsLoad);

	return true;
}//end function

//get a parent node of specific type from an element
function getAncestor(el, ancestorType) {
	if (!el.parentNode) {return false;}
	do {el = el.parentNode;}
	while (el && el.type != ancestorType && el.parentNode)
	if (el.type != ancestorType) {return false;}
	return el;
}//end function

function getSellectedText() {
 var txt = '';
	if (window.getSelection)
		{txt = window.getSelection();}
	else if (document.getSelection)
		{txt = document.getSelection();}
	else if (document.selection)
		{txt = document.selection.createRange().text;}
	else return;
	return txt;
}

function getTopLeft(ele) {
	var x, y = 0;
	x = ele.offsetLeft;
	y = ele.offsetTop;
	ele = ele.offsetParent;
	while(ele != null) {
		x = parseInt(x) + parseInt(ele.offsetLeft);
		y = parseInt(y) + parseInt(ele.offsetTop);
		ele = ele.offsetParent;
	}
	return {top:y, left: x};
}//end function


/************************************************************************************************************************************************************************
Selects
************************************************************************************************************************************************************************/

function selectAddOption(selectEl, val, txt, index) {
	var opt = null;
	var newEl = document.createElement('option');
	newEl.text = txt;
	newEl.value = val;
	var selectElId = (selectEl.id ? selectEl.id : 'selectId');
	newEl.id = selectElId + 'Option' + [index];
	if (index && index < selectEl.length && selectEl.options[index]) {var opt = selectEl.options[index];}
	else {index = selectEl.length;}

	try {selectEl.add(newEl, opt);}
	catch(ex) {selectEl.add(newEl, index);}
}//end function

function getSelectedOption(selectEl) {
	var options = selectEl.getElementsByTagName('option');
	for (var ctr = 0; ctr < options.length; ctr++) {
		var opt = options[ctr];
		if (opt.selected) {return options[ctr];}
	}//end for
	return null;
}//end function


function selectMoveOptionUp(selectEl) {
	var options = selectEl.getElementsByTagName('option');
	for (var ctr = 1; ctr < options.length; ctr++) {
		var opt = options[ctr];
		if (opt.selected) {
			selectEl.removeChild(opt);
			selectEl.insertBefore(opt, options[ctr - 1]);
		}//end if
	}//end for
}//end function

function selectMoveOptionDown(selectEl) {
	var options = selectEl.getElementsByTagName('option');
	for (var ctr = options.length - 2; ctr >= 0; ctr--) {
		var opt = options[ctr];
		if (opt.selected) {
			var nextOpt = options[ctr + 1];
			opt = selectEl.removeChild(opt);
			nextOpt = selectEl.replaceChild(opt, nextOpt);
			selectEl.insertBefore(nextOpt, opt);
		}//end if
	}//end for
}//end function
