/*--------------------------------------------------
	Project:	The November Group - CMS Administration
	Script:		cms_main.js
	Includes:
		CMS_Main
		CMS_Cookie (not used)
--------------------------------------------------*/

var CMS_Main={

	objRequest:null,
	strRootDirectory:"",
	strSessionName:"",
	strPage:"",
	strLoadingMessage:"Loading...",
	
	getRootDirectory:function()
	{
		return this.strRootDirectory;
	},
	setRootDirectory:function(strRootDirectory)
	{
		this.strRootDirectory=strRootDirectory;
	},
	getSessionName:function()
	{
		return this.strSessionName;
	},
	setSessionName:function(strSessionName)
	{
		this.strSessionName=strSessionName;
	},
	getPage:function()
	{
		return this.strPage;
	},
	setPage:function(strPage)
	{
		this.strPage=strPage;
	},
	getLoadingMessage:function()
	{
		return this.strLoadingMessage;
	},
	
	initialize:function()
	{
		this.objRequest.open("GET","get_page_xml.php"+window.location.search,true); //include search string, to allow linking to a specific page in the admin system
		this.objRequest.onreadystatechange=CMS_Main.updatePage;
		this.objRequest.send(null);
		
		return false;
	},
	
	initializeAdmin:function()
	{
		window.onbeforeunload=function()
		{
			return "";
		};
		
		return false;
	},
	
	adminHome:function()
	{
		this.setPage("");
		
		this.objRequest.open("GET","get_page_xml.php",true);
		this.objRequest.onreadystatechange=CMS_Main.updatePage;
		this.objRequest.send(null);
		
		return false;
	},
	
	adminForms:function()
	{
		CMS_Main.setPage("adminForms");
		
		CMS_Main.objRequest.open("GET","get_page_xml.php?page="+CMS_Main.getPage(),true);
		CMS_Main.objRequest.onreadystatechange=CMS_Main.updatePage;
		CMS_Main.objRequest.send(null);
		
		return false;
	},
	
	//add overlay
	addOverlay:function(eleContent,intZIndex,blnFixed)
	{
		if(!document.getElementById("overlay"))
		{
			var eleOverlay=document.createElement("div");
			eleOverlay.id="overlay";
			if(intZIndex)
				eleOverlay.style.zIndex=Number(intZIndex);
			
			eleOverlay.appendChild(document.createElement("div"));
			eleOverlay.lastChild.id="overlayColour";
			
			eleOverlay.appendChild(document.createElement("div"));
			eleOverlay.lastChild.id="overlayContent";
			eleOverlay.lastChild.style.width="100%";
			if(blnFixed)
			{
				eleOverlay.lastChild.style.position="fixed";
			}
			else
			{
				eleOverlay.lastChild.style.position="relative";

				var intScrollX=0;
				var intScrollY=0;
				
				//get the current horizontal scroll offset of the window
				if(window.pageXOffset)
					intScrollX=window.pageXOffset; //Firefox
				else if(document.body && document.body.parentElement && document.body.parentElement.scrollLeft)
					intScrollX=document.body.parentElement.scrollLeft; //IE
				else if(document.body && document.body.scrollLeft)
					intScrollX=document.body.scrollLeft;
				
				//get the current vertical scroll offset of the window
				if(window.pageYOffset)
					intScrollY=window.pageYOffset; //Firefox
				else if(document.body && document.body.parentElement && document.body.parentElement.scrollTop)
					intScrollY=document.body.parentElement.scrollTop; //IE
				else if(document.body && document.body.scrollTop)
					intScrollY=document.body.scrollTop;
				
				eleOverlay.lastChild.style.left=intScrollX.toString()+"px";
				eleOverlay.lastChild.style.top=intScrollY.toString()+"px";
			}
			eleOverlay.lastChild.appendChild(eleContent);
			
			//add overlay to document
			document.getElementsByTagName("body")[0].insertBefore(eleOverlay,document.getElementsByTagName("body")[0].firstChild);
		}
	},
	
	//remove overlay and return contents
	removeOverlay:function()
	{
		eleContent=null;
		
		if(document.getElementById("overlayContent") && document.getElementById("overlayContent").lastChild)
			eleContent=document.getElementById("overlayContent").removeChild(document.getElementById("overlayContent").lastChild);
		if(document.getElementById("overlay"))
			document.getElementsByTagName("body")[0].removeChild(document.getElementById("overlay"));
		
		return eleContent;
	},
	
	//return a style class as an object
	getStyleClass:function(strClassName)
	{
		//declare variables
		var returnValue=null;
		
		try
		{
			if(document.styleSheets)
			{
				for(var s=0;s<document.styleSheets.length;s++)
				{
					if(document.styleSheets[s].rules)
					{
						//IE
						for(var r=0;r<document.styleSheets[s].rules.length;r++)
						{
							if (document.styleSheets[s].rules[r].selectorText == '.' + strClassName)
							{
								returnValue=document.styleSheets[s].rules[r];
							}
						}
					}
					else if(document.styleSheets[s].cssRules)
					{
						//regular browsers
						for(var r=0;r<document.styleSheets[s].cssRules.length;r++)
						{
							if (document.styleSheets[s].cssRules[r].selectorText == '.' + strClassName)
								returnValue=document.styleSheets[s].cssRules[r];
						}
					}
				}
			}
		}
		catch(err)
		{
			//do nothing
		}
		
		return returnValue;
	},

	//checks for a valid email address format
	isValidEmailAddress:function(email)
	{
		//declare variables
		var atPos=email.indexOf("@");
		var dotPos=email.lastIndexOf(".");
		var returnValue=true;
		
		if(email.length==0) //check if email is blank
		{
			returnValue=false;
		}
		else if(atPos<1) //check if there are any characters before the "@" sign
		{
			returnValue=false;
		}
		else if(email.length-dotPos<2) //check if there are any characters after the "."
		{
			returnValue=false;
		}
		else if(dotPos-atPos<2) //check if there are any characters between the "@" and the "." and make sure they're in the right order
		{
			returnValue=false;
		}
		
		return returnValue;
	},
	
	//checks for a valid postal/zip code format
	isValidPostalZip:function(strPostalZip,strCountry)
	{
		var blnReturnValue=true;
		
		//validate specific content
		if(strPostalZip.length>0)
		{
			//verify postal code
			if(strCountry=="Canada")
			{
				//ensure it is long enough
				if(strPostalZip.length<6)
				{
					blnReturnValue=false;
				}
				//check for valid format
				else
				{
					var j=0;
					
					// Check for legal characters in string - note index starts at zero
					if('ABCEGHJKLMNPRSTVXY'.indexOf(strPostalZip.charAt(j)) < 0)
					{
						blnReturnValue=false;
					}
					j++;
					if('0123456789'.indexOf(strPostalZip.charAt(j)) < 0)
					{
						blnReturnValue=false;
					}
					j++;
					if('ABCEGHJKLMNPRSTVWXYZ'.indexOf(strPostalZip.charAt(j)) < 0)
					{
						blnReturnValue=false;
					}
					j++;
					
					if(strPostalZip.charAt(j)==' ')
					{
						j++;
					}
					
					if('0123456789'.indexOf(strPostalZip.charAt(j)) < 0)
					{
						blnReturnValue=false;
					}
					j++;
					if('ABCEGHJKLMNPRSTVWXYZ'.indexOf(strPostalZip.charAt(j)) < 0)
					{
						blnReturnValue=false;
					}
					j++;
					if('0123456789'.indexOf(strPostalZip.charAt(j)) < 0)
					{
						blnReturnValue=false;
					}
				}
			}
			//verify zip code
			else if(strCountry=="United States")
			{
				//ensure it is long enough
				if(strPostalZip.length<5)
				{
					blnReturnValue=false;
				}
				else
				{
					//check to make sure each character is numeric (or a space or hyphen)
					for(var i=0;i<strPostalZip.length;i++)
					{
						if('0123456789 -'.indexOf(strPostalZip.charAt(i)) < 0)
						{
							blnReturnValue=false;
						}
					}
				}
			}
		}
		else
		{
			blnReturnValue=false;
		}
		
		return blnReturnValue;
	},
	
	//create XMLHttpRequest object
	createRequest:function()
	{
		//declare variables
		var returnValue=null;
		
		try
		{
			returnValue = new XMLHttpRequest();
		}
		catch(microsoftOption1)
		{
			try
			{
				returnValue = new ActiveXObject("Msxml2.XMLHTTP");
			}
			catch(microsoftOption2)
			{
				try
				{
					returnValue = new ActiveXObject("Microsoft.XMLHTTP");
				}
				catch(failed)
				{
					returnValue=null;
				}
			}
		}
		
		return returnValue;
	},
	
	updatePage:function()
	{
		if(CMS_Main.objRequest.readyState==4)
		{
			if(CMS_Main.objRequest.status==200)
			{
				var eleDoc=CMS_Main.objRequest.responseXML.documentElement;
				
				//check for login
				if(eleDoc.getElementsByTagName("login") && eleDoc.getElementsByTagName("login").length>0 && eleDoc.getElementsByTagName("login")[0].firstChild.nodeValue=="logged in")
				{
					//update content
					if(eleDoc.getElementsByTagName("content").length>0)
					{
						document.getElementById("content_main").innerHTML="";
						
						for(var i=0;i<eleDoc.getElementsByTagName("content").length;i++)
							if(eleDoc.getElementsByTagName("content")[i].firstChild)
								document.getElementById("content_main").innerHTML+=eleDoc.getElementsByTagName("content")[i].firstChild.nodeValue;
					}
					//update user details
					if(eleDoc.getElementsByTagName("userDetails")[0])
					{
						if(eleDoc.getElementsByTagName("userDetails")[0].firstChild && eleDoc.getElementsByTagName("userDetails")[0].firstChild.nodeValue.length>0)
							document.getElementById("user_details").innerHTML=eleDoc.getElementsByTagName("userDetails")[0].firstChild.nodeValue;
						else
							document.getElementById("user_details").innerHTML="";
					}
					//update main menu
					if(eleDoc.getElementsByTagName("menuMain")[0])
					{
						if(eleDoc.getElementsByTagName("menuMain")[0].firstChild && eleDoc.getElementsByTagName("menuMain")[0].firstChild.nodeValue.length>0)
							document.getElementById("main_menu").innerHTML=eleDoc.getElementsByTagName("menuMain")[0].firstChild.nodeValue;
						else
							document.getElementById("main_menu").innerHTML="";
					}
					//update secondary menu
					if(eleDoc.getElementsByTagName("menuSec")[0])
					{
						if(eleDoc.getElementsByTagName("menuSec")[0].firstChild && eleDoc.getElementsByTagName("menuSec")[0].firstChild.nodeValue.length>0)
							document.getElementById("sec_menu").innerHTML=eleDoc.getElementsByTagName("menuSec")[0].firstChild.nodeValue;
						else
							document.getElementById("sec_menu").innerHTML="";
					}
					//update sidebar menu
					if(eleDoc.getElementsByTagName("menuSidebar")[0])
					{
						if(eleDoc.getElementsByTagName("menuSidebar")[0].firstChild && eleDoc.getElementsByTagName("menuSidebar")[0].firstChild.nodeValue.length>0)
							document.getElementById("sidebar_menu").innerHTML=eleDoc.getElementsByTagName("menuSidebar")[0].firstChild.nodeValue;
						else
							document.getElementById("sidebar_menu").innerHTML="";
					}
					//update sidebar help
					if(eleDoc.getElementsByTagName("sidebarHelp")[0])
					{
						if(eleDoc.getElementsByTagName("sidebarHelp")[0].firstChild)
							document.getElementById("sidebar_help").innerHTML=eleDoc.getElementsByTagName("sidebarHelp")[0].firstChild.nodeValue;
					}
					//run javascript
					if(eleDoc.getElementsByTagName("javascript").length>0)
					{
						for(var i=0;i<eleDoc.getElementsByTagName("javascript").length;i++)
							if(eleDoc.getElementsByTagName("javascript")[i].firstChild)
								eval(eleDoc.getElementsByTagName("javascript")[i].firstChild.nodeValue);
					}
					
					//update message
					if(eleDoc.getElementsByTagName("message")[0])
					{
						if(eleDoc.getElementsByTagName("message")[0].firstChild && eleDoc.getElementsByTagName("message")[0].firstChild.nodeValue.length>0)
						{
							document.getElementById("message").innerHTML=eleDoc.getElementsByTagName("message")[0].firstChild.nodeValue;
							document.getElementById("message").className="system_messages";
						}
						else
						{
							document.getElementById("message").innerHTML="";
							document.getElementById("message").className="";
						}
					}
				}
				else if(eleDoc.getElementsByTagName("login") && eleDoc.getElementsByTagName("login").length>0 && eleDoc.getElementsByTagName("login")[0].firstChild.nodeValue=="logged out")
				{
					//allow windows to close
					window.onbeforeunload=function()
					{
						return;
					};

					window.location.assign(CMS_Main.getRootDirectory()+"/");
				}
			}
		}
	},
	
	//return form values encoded as a POST string
	formEncode:function(frm)
	{
		var strPost="";
		var blnArray=false;
		
		for(var i=0;i<frm.length;i++)
		{
			//check if there are multiple elements with the same name (for "hidden", "text", "password", "textarea", "checkbox", and "select-one" elements; "radio", and "select-multiple" elements are always arrays and need to be handled differently)
			blnArray=false;
			if(frm.elements[frm.elements[i].name] && frm.elements[frm.elements[i].name].length)
				blnArray=true;
			
			switch(frm.elements[i].type)
			{
				case("hidden"):
					strPost+=frm.elements[i].name+(blnArray ? "[]" : "")+"="+encodeURIComponent(frm.elements[i].value)+"&";
					break;
				case("text"):
					strPost+=frm.elements[i].name+(blnArray ? "[]" : "")+"="+encodeURIComponent(frm.elements[i].value)+"&";
					break;
				case("password"):
					strPost+=frm.elements[i].name+(blnArray ? "[]" : "")+"="+encodeURIComponent(frm.elements[i].value)+"&";
					break;
				case("textarea"):
					strPost+=frm.elements[i].name+(blnArray ? "[]" : "")+"="+encodeURIComponent(frm.elements[i].value)+"&";
					break;
				case("checkbox"):
					if(frm.elements[i].checked)
						strPost+=frm.elements[i].name+(blnArray ? "[]" : "")+"="+encodeURIComponent(frm.elements[i].value)+"&";
					else
						strPost+=frm.elements[i].name+(blnArray ? "[]" : "")+"=0&";
					break;
				case("radio"):
					if(frm.elements[i].checked)
						strPost+=frm.elements[i].name+"="+encodeURIComponent(frm.elements[i].value)+"&";
					break;
				case("select-multiple"):
					for(var j=0;j<frm.elements[i].length;j++)
					{
						if(frm.elements[i].options[j].selected)
						{
							strPost+=frm.elements[i].name+"[]="+encodeURIComponent(frm.elements[i].options[j].value)+"&";
						}
					}
					break;
				case("select-one"):
					for(var j=0;j<frm.elements[i].length;j++)
					{
						if(frm.elements[i].options[j].selected)
						{
							strPost+=frm.elements[i].name+(blnArray ? "[]" : "")+"="+encodeURIComponent(frm.elements[i].options[j].value)+"&";
						}
					}
					break;
				case("submit"):
					strPost+=frm.elements[i].name+"="+encodeURIComponent(frm.elements[i].value)+"&";
					break;
				case("reset"):
					strPost+=frm.elements[i].name+"="+encodeURIComponent(frm.elements[i].value)+"&";
					break;
			}
		}
		
		//remove final "&"
		if(strPost.substr(strPost.length-1,1)=="&")
		{
			strPost=strPost.substr(0,strPost.length-1);
		}
		
		return strPost;
	},
	
	createNamedElement:function(strType, strName)
	{
		var eleNew = null;

		try
		{
			//IE
			eleNew=document.createElement('<'+strType+' name="'+strName+'">');
		}
		catch(e)
		{}
		
		if(!eleNew || eleNew.nodeName.toLowerCase()!=strType)
		{
			//Not IE
			eleNew=document.createElement(strType);
			eleNew.name=strName;
		}
		return eleNew;
	},
	
	addListener:function(objObject,strEventName,fnHandler)
	{
		//add event listener
		if(objObject.addEventListener)
			objObject.addEventListener(strEventName, fnHandler, false); //DOM-compliant
		else if(objObject.attachEvent) //IE
			objObject.attachEvent("on"+strEventName, fnHandler);
	},
	
	getEventSrc:function(e)
	{
		if(!e)
			e=window.event; //IE
		
		//return event source element
		if(e.target)
			return e.target; //DOM-compliant
		else if(e.srcElement)
			return e.srcElement; //IE
	},
		
	inArray:function(arrArray,strValue)
	{
		var blnReturnValue=false;
		
		for(i in arrArray)
		{
			if(arrArray[i].toString()==strValue.toString())
			{
				blnReturnValue=true;
				break;
			}
		}
		
		return blnReturnValue;
	},

	parseXml:function(strXml)
	{
		var xmlDoc=null;
		
		try //Internet Explorer
		{
			parser=new DOMParser();
			xmlDoc=parser.parseFromString(strXml,"text/xml");
		}
		catch(e)
		{
			try //Firefox, Mozilla, Opera, etc.
			{
				xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
				xmlDoc.async="false";
				xmlDoc.loadXML(strXml);
			}
			catch(e)
			{
				alert(e.message);
			}
		}
		return xmlDoc;
	},
	
	clipboardCopy:function(strText)
	{
		if(window.clipboardData && clipboardData.setData)
		{
			clipboardData.setData("Text", strText);
		}
		else
		{
			var flashcopier = 'flashcopier';
			if(!document.getElementById(flashcopier))
			{
				var divholder = document.createElement('div');
				divholder.id = flashcopier;
				document.body.appendChild(divholder);
			}
			document.getElementById(flashcopier).innerHTML = '';
			var divinfo = '<embed src='+CMS_Main.getRootDirectory()+'"/scripts/main/javascript/_clipboard.swf" FlashVars="clipboard='+encodeURIComponent(strText)+'" width="0" height="0" type="application/x-shockwave-flash"></embed>';
			document.getElementById(flashcopier).innerHTML = divinfo;			
		}
		return false; //cancel link
	},
	
	textEditorInit:function(strId)
	{
		if(document.getElementById(strId))
		{
			tinyMCE.init({
				
				//general options
				mode:"exact"
				,elements:strId
				,theme:"advanced"
				,width:"510"
				,plugins : "safari,style,table,advimage,inlinepopups,contextmenu,paste,fullscreen,nonbreaking,xhtmlxtras"
				,convert_urls:false
				,relative_urls:false
				,verify_html:false //don't cleanup any html
				
				//theme options
				,theme_advanced_buttons1:"bold,italic,|,sub,sup,|,forecolor,backcolor,|,formatselect,fontsizeselect,|,bullist,numlist,|,outdent,indent,blockquote,|,justifyleft,justifycenter,justifyright,justifyfull"
				,theme_advanced_buttons2:"cut,copy,paste,pastetext,pasteword,|,link,unlink,image,|,undo,redo,|,charmap,hr,nonbreaking,|,removeformat,styleprops,attribs,|,fullscreen,code,help"
				,theme_advanced_buttons3:"tablecontrols"
				,theme_advanced_buttons4:""
				,theme_advanced_toolbar_location:"top"
				,theme_advanced_toolbar_align:"left"
				,theme_advanced_statusbar_location:"bottom"
				,theme_advanced_resizing:true
				
				//content css
				,content_css:"/get_element_xml.php?function=getEditorStyleSheet"
			});
		}
	},
	
	textEditorUpdate:function(strId)
	{
		if(document.getElementById(strId))
			tinyMCE.get(strId).save();
	},
	
	//allows the tab key to insert a tab into a textarea (or other input element), rather than changing focus to the next element
	allowTabs:function(eleInput)
	{
		function insertTab(event)
		{
			if(event.keyCode==9 || event.which==9) //tab key
			{
				var eleTextArea=CMS_Main.getEventSrc(event);
				//IE
				if(document.selection)
				{
					//get focus
					eleTextArea.focus();
					
					//get selection
					var sel = document.selection.createRange();
					
					//insert tab
					sel.text = "\t";
				}
				//Mozilla + Netscape
				else if(this.selectionStart || this.selectionStart == "0")
				{
					//save scrollbar positions
					var scrollY = eleTextArea.scrollTop;
					var scrollX = eleTextArea.scrollLeft;
					
					//get current selection
					var start = eleTextArea.selectionStart;
					var end = eleTextArea.selectionEnd;
					
					//insert tab
					eleTextArea.value = eleTextArea.value.substring(0,start) + "\t" + eleTextArea.value.substring(end,eleTextArea.value.length);
					
					//move cursor back to insert point
					eleTextArea.focus();
					eleTextArea.selectionStart = start+1;
					eleTextArea.selectionEnd = start+1;
					
					//reset scrollbar position
					eleTextArea.scrollTop = scrollY;
					eleTextArea.scrollLeft = scrollX;
				}
				
				//prevent default behaviour
				if(event.preventDefault)
					event.preventDefault();
				return false;
			}
		}
		
		//CMS_Main.addListener(eleInput,"keypress",insertTab);
		CMS_Main.addListener(eleInput,"keydown",insertTab);
	}
}

//create main request object
CMS_Main.objRequest=CMS_Main.createRequest();

//cookie handling functions
var CMS_Cookie={

	//set a cookie value
	set:function(strName, strValue, dtmExpires, strPath, strDomain, blnSecure)
	{
		document.cookie= strName + "=" + encodeURIComponent(strValue) +
			((dtmExpires) ? "; expires=" + dtmExpires.toGMTString() : "") +
			((strPath) ? "; path=" + strPath : "") +
			((strDomain) ? "; domain=" + strDomain : "") +
			((blnSecure) ? "; secure" : "");
	},
	
	//get a cookie value
	get:function(strName)
	{
		//declare variables
		var strSearch = strName + "=";
		var strCookie="";
		var intOffset=0;
		var intEnd=0;
		
		if (document.cookie.length > 0)
		{ // if there are any cookies
			intOffset = document.cookie.indexOf(strSearch);
			if (intOffset != -1) // if cookie name exists
			{
				intOffset += strSearch.length // set index of beginning of value
				intEnd = document.cookie.indexOf(";", intOffset); // set index of end of cookie value
				if (intEnd == -1)
				{
					intEnd = document.cookie.length;
				}
				strCookie=decodeURIComponent(document.cookie.substring(intOffset, intEnd));
			}           
		}
		
		//for browsers that return "undefined" when a cookie is not found, return an empty string instead, for consistent return values across browsers
		if(strCookie=="undefined")
		{
			strCookie="";
		}
		return strCookie;
	},
	
	//delete a cookie
	del:function(strName)
	{
		this.set(strName,"",-1);
	}
}

//correct IE's getElementById function so it doesn't select elements using the name attribute
if (/msie/i.test (navigator.userAgent)) //only override IE
{
	document.nativeGetElementById = document.getElementById;
	document.getElementById = function(id)
	{
		var elem = document.nativeGetElementById(id);
		if(elem)
		{
			//make sure that it is a valid match on id
			if(elem.attributes['id'].value == id)
			{
				return elem;
			}
			else
			{
				//otherwise find the correct element
				for(var i=1;i<document.all[id].length;i++)
				{
					if(document.all[id][i].attributes['id'].value == id)
					{
						return document.all[id][i];
					}
				}
			}
		}
		return null;
	};
}/*--------------------------------------------------
	Project:	The November Group - Date Time Select
	Script:		dts.js
	Includes:	DTS
	Description:
		insert() takes an id an id for an input element and inserts drop-down boxes to select the date and time, updating the input element when they are changed.
--------------------------------------------------*/

var DTS={
	
	intTypeFull:0,
	intTypeDateOnly:1,
	intTypeDateOptional:2,
	
	insert:function(strId,intType,objSettings)
	{
		if(document.getElementById(strId))
		{
			var input=document.getElementById(strId);
			var dtmDate=DTS.getDateObject(strId);
			
			//create select elements
			var eleSelectYear=document.createElement("select");
			eleSelectYear.name="DTS_year";
			eleSelectYear.id="DTS_year_"+strId;
			eleSelectYear.className="input9";
			eleSelectYear.onchange=this.change;
			
			var eleSelectMonth=document.createElement("select");
			eleSelectMonth.name="DTS_month";
			eleSelectMonth.id="DTS_month_"+strId;
			eleSelectMonth.className="input9";
			eleSelectMonth.onchange=this.change;
			
			var eleSelectDate=document.createElement("select");
			eleSelectDate.name="DTS_date";
			eleSelectDate.id="DTS_date_"+strId;
			eleSelectDate.className="input7";
			eleSelectDate.onchange=this.change;
			
			var eleSelectHours=document.createElement("select");
			eleSelectHours.name="DTS_hours";
			eleSelectHours.id="DTS_hours_"+strId;
			eleSelectHours.className="input6";
			eleSelectHours.onchange=this.change;
			
			var eleSelectMinutes=document.createElement("select");
			eleSelectMinutes.name="DTS_minutes";
			eleSelectMinutes.id="DTS_minutes_"+strId;
			eleSelectMinutes.className="input7";
			eleSelectMinutes.onchange=this.change;
			
			var eleSelectAm=document.createElement("select");
			eleSelectAm.name="DTS_am";
			eleSelectAm.id="DTS_am_"+strId;
			eleSelectAm.className="input7";
			eleSelectAm.onchange=this.change;
			
			//create container
			var eleContainer=document.createElement("span");
			//append elements to container
			eleContainer.appendChild(eleSelectYear);
			eleContainer.appendChild(eleSelectMonth);
			eleContainer.appendChild(eleSelectDate);
			//check type before including hours and minutes
			if(intType!=this.intTypeDateOnly)
			{
				eleContainer.appendChild(document.createTextNode(" "));
				eleContainer.appendChild(eleSelectHours);
				eleContainer.appendChild(eleSelectMinutes);
				eleContainer.appendChild(eleSelectAm);
			}
			
			//insert container before input element
			input.parentNode.insertBefore(eleContainer,input);

			//populate select elements
			DTS.clearOptions(eleSelectYear);
			var intYear=dtmDate.getFullYear();
			if(objSettings && objSettings.intYearStart && objSettings.intYearEnd)
			{
				if(objSettings.intYearStart<objSettings.intYearEnd)
				{
					for(var i=objSettings.intYearStart;i<=objSettings.intYearEnd;i++)
					{
						var eleOpt=document.createElement("option");
						eleOpt.text=i;
						eleOpt.value=i;
						eleSelectYear.options[eleSelectYear.length]=eleOpt;
						if(eleOpt.value==dtmDate.getFullYear())
						{
							eleOpt.selected=true;
						}
					}
				}
				else
				{
					for(var i=objSettings.intYearStart;i>=objSettings.intYearEnd;i--)
					{
						var eleOpt=document.createElement("option");
						eleOpt.text=i;
						eleOpt.value=i;
						eleSelectYear.options[eleSelectYear.length]=eleOpt;
						if(eleOpt.value==dtmDate.getFullYear())
						{
							eleOpt.selected=true;
						}
					}
				}
			}
			else
			{
				for(var i=-7;i<9;i++)
				{
					var eleOpt=document.createElement("option");
					eleOpt.text=dtmDate.getFullYear()+i;
					eleOpt.value=dtmDate.getFullYear()+i;
					eleSelectYear.options[eleSelectYear.length]=eleOpt;
					if(eleOpt.value==dtmDate.getFullYear())
					{
						eleOpt.selected=true;
					}
				}
			}
			
			DTS.clearOptions(eleSelectMonth);
			for(var i=0;i<12;i++)
			{
				var eleOpt=document.createElement("option");
				//eleOpt.text=(1+i < 10 ? "0" : "")+(1+i).toString();
				eleOpt.text=DTS.monthAbbrev[i];
				eleOpt.value=i;
				eleSelectMonth.options[eleSelectMonth.length]=eleOpt;
				if(eleOpt.value==dtmDate.getMonth())
				{
					eleOpt.selected=true;
				}
			}
			
			DTS.monthChange(strId);
	
			DTS.clearOptions(eleSelectHours);
			if(intType==this.intTypeDateOptional)
			{
				var eleOpt=document.createElement("option");
				eleOpt.text="--";
				eleOpt.value=-1;
				eleSelectHours.options[eleSelectHours.length]=eleOpt;
			}
			for(var i=0;i<12;i++)
			{
				var eleOpt=document.createElement("option");
				eleOpt.text=(i==0 ? i+12 : i);
				eleOpt.value=i;
				eleSelectHours.options[eleSelectHours.length]=eleOpt;
				if(eleOpt.value==dtmDate.getHours() || eleOpt.value==(dtmDate.getHours()-12))
				{
					eleOpt.selected=true;
				}
			}
			
			DTS.clearOptions(eleSelectMinutes);
			if(intType==this.intTypeDateOptional)
			{
				var eleOpt=document.createElement("option");
				eleOpt.text="--";
				eleOpt.value=-1;
				eleSelectMinutes.options[eleSelectMinutes.length]=eleOpt;
			}
			for(var i=0;i<4;i++)
			{
				var eleOpt=document.createElement("option");
				eleOpt.text=(i*15 < 10 ? "0" : "")+(i*15).toString();
				eleOpt.value=i*15;
				eleSelectMinutes.options[eleSelectMinutes.length]=eleOpt;
				if(eleOpt.value <= dtmDate.getMinutes() && eleOpt.value > dtmDate.getMinutes()-15)
				{
					eleOpt.selected=true;
					dtmDate.setMinutes(eleOpt.value); //update date object to currently selected value
				}
			}
			
			DTS.clearOptions(eleSelectAm);
			if(intType==this.intTypeDateOptional)
			{
				var eleOpt=document.createElement("option");
				eleOpt.text="--";
				eleOpt.value=-1;
				eleSelectAm.options[eleSelectAm.length]=eleOpt;
				eleOpt.selected=true;
			}
			var eleOptA=document.createElement("option");
			eleOptA.text="AM";
			eleOptA.value=0;
			eleSelectAm.options[eleSelectAm.length]=eleOptA;
			var eleOptP=document.createElement("option");
			eleOptP.text="PM";
			eleOptP.value=12;
			eleSelectAm.options[eleSelectAm.length]=eleOptP;
			if(dtmDate.getHours()<12)
			{
				eleOptA.selected=true;
			}
			else
			{
				eleOptP.selected=true;
			}
			
			//change time selection based on type
			if(intType==this.intTypeDateOptional)
			{
				//check for default time
				if(eleSelectHours.value==0 && eleSelectMinutes.value==0 && eleSelectAm.value==0)
				{
					//select default options
					eleSelectHours.options[0].selected=true;
					eleSelectMinutes.options[0].selected=true;
					eleSelectAm.options[0].selected=true;
				}
			}
			
			dtmDate.setSeconds(0);
			
			//update input value
			document.getElementById(strId).value=Math.floor(dtmDate.getTime()/1000);
		}
	},
	
	monthChange:function(strId)
	{
		var eleDateSelect=null;
		var dtmDate=DTS.getDateObject(strId);
		var dtmDay=new Date();
		
		dtmDay.setTime(dtmDate.getTime());
		eleSelectDate=document.getElementById("DTS_date_"+strId);
		
		DTS.clearOptions(eleSelectDate);
		
		//add first day of month
		var eleOpt=document.createElement("option");
		dtmDay.setDate(1);
		eleOpt.text=dtmDay.getDate();
		eleOpt.value=dtmDay.getDate();
		eleSelectDate.options[eleSelectDate.length]=eleOpt;
		//add remaining days of month
		var dtmPrevDay=new Date();
		dtmPrevDay.setTime(dtmDay.getTime());
		dtmDay.setDate(2);
		for(var i=3;dtmDay.getDate() > dtmPrevDay.getDate();i++)
		{
			var eleOpt=document.createElement("option");
			eleOpt.text=dtmDay.getDate();
			eleOpt.value=dtmDay.getDate();
			eleSelectDate.options[eleSelectDate.length]=eleOpt;
			if(eleOpt.value==dtmDate.getDate())
			{
				eleOpt.selected=true;
			}
			
			dtmDay.setDate(i);
			dtmPrevDay.setDate(i-1);
		}
	},
	
	change:function(event)
	{
		var eleSelect=null;
		var strId="";
		var intType=0;
		
		try
		{
			eleSelect=event.target;
		}
		catch(e)
		{
			eleSelect=window.event.srcElement; //IE
		}
		strId=DTS.getId(eleSelect.id);
		
		//determine type
		if(document.getElementById("DTS_hours_"+strId) && document.getElementById("DTS_hours_"+strId).options[0].value==-1)
			intType=this.intTypeDateOptional;
		
		if(intType==this.intTypeDateOptional) //check for date optional type
		{
			if(eleSelect.id.indexOf("DTS_hours_")==0 || eleSelect.id.indexOf("DTS_minutes_")==0 || eleSelect.id.indexOf("DTS_am_")==0) //check if changed element was a time select box
			{
				if(Number(eleSelect.value)==-1) //check if default value was selected
				{
					//change other time values to default values
					document.getElementById("DTS_hours_"+strId).options[0].selected=true;
					document.getElementById("DTS_minutes_"+strId).options[0].selected=true;
					document.getElementById("DTS_am_"+strId).options[0].selected=true;
				}
				else
				{
					//change other time values to non-default values
					if(Number(document.getElementById("DTS_hours_"+strId).value)==-1)
						document.getElementById("DTS_hours_"+strId).options[1].selected=true;
					if(Number(document.getElementById("DTS_minutes_"+strId).value)==-1)
						document.getElementById("DTS_minutes_"+strId).options[1].selected=true;
					if(Number(document.getElementById("DTS_am_"+strId).value)==-1)
						document.getElementById("DTS_am_"+strId).options[1].selected=true;
				}
			}
		}
	
		var dtmDateLastDayOfMonth=DTS.getDateObject(strId);
		dtmDateLastDayOfMonth.setDate(1); //set to first day of month
		dtmDateLastDayOfMonth.setYear(document.getElementById("DTS_year_"+strId).value);
		dtmDateLastDayOfMonth.setMonth(Number(document.getElementById("DTS_month_"+strId).value)+1); //set to next month
		dtmDateLastDayOfMonth.setDate(0); //set back to last day of current month
		if(document.getElementById("DTS_hours_"+strId))
			dtmDateLastDayOfMonth.setHours((Number(document.getElementById("DTS_hours_"+strId).value)==-1 ? 0 : Number(document.getElementById("DTS_hours_"+strId).value)) + (Number(document.getElementById("DTS_am_"+strId).value)==-1 ? 0 : Number(document.getElementById("DTS_am_"+strId).value)));
		else
			dtmDateLastDayOfMonth.setHours(0);
		if(document.getElementById("DTS_minutes_"+strId))
			dtmDateLastDayOfMonth.setMinutes((Number(document.getElementById("DTS_minutes_"+strId).value)==-1 ? 0 : Number(document.getElementById("DTS_minutes_"+strId).value)));
		else
			dtmDateLastDayOfMonth.setMinutes(0);
		dtmDateLastDayOfMonth.setSeconds(0);
		
		var dtmDate=DTS.getDateObject(strId);
		dtmDate.setDate(1);
		dtmDate.setYear(document.getElementById("DTS_year_"+strId).value);
		dtmDate.setMonth(document.getElementById("DTS_month_"+strId).value);
		//check if date is past last day of month (and always set date before setting month)
		dtmDate.setDate((document.getElementById("DTS_date_"+strId).value <= dtmDateLastDayOfMonth.getDate() ? document.getElementById("DTS_date_"+strId).value : dtmDateLastDayOfMonth.getDate()));
		if(document.getElementById("DTS_hours_"+strId))
			dtmDate.setHours((Number(document.getElementById("DTS_hours_"+strId).value)==-1 ? 0 : Number(document.getElementById("DTS_hours_"+strId).value)) + (Number(document.getElementById("DTS_am_"+strId).value)==-1 ? 0 : Number(document.getElementById("DTS_am_"+strId).value)));
		else
			dtmDate.setHours(0);
		if(document.getElementById("DTS_minutes_"+strId))
			dtmDate.setMinutes((Number(document.getElementById("DTS_minutes_"+strId).value)==-1 ? 0 : Number(document.getElementById("DTS_minutes_"+strId).value)));
		else
			dtmDate.setMinutes(0);
		dtmDate.setSeconds(0);
		
		document.getElementById(strId).value=Math.floor(dtmDate.getTime()/1000);
		
		//update date select when month or year changes (when year changes, in case february is selected and it switches between a leap year and a non-leap year)
		if(eleSelect.id.indexOf("DTS_month_")==0 || eleSelect.id.indexOf("DTS_year_")==0)
		{
			DTS.monthChange(strId);
			DTS.update(strId);
		}
	},
	
	//update select elements from input value
	update:function(strId)
	{
		var dtmDate=DTS.getDateObject(strId);
		var intType=0;
		
		var eleSelectYear=document.getElementById("DTS_year_"+strId);
		for(var i=0;i<eleSelectYear.options.length;i++)
		{
			if(eleSelectYear.options[i].value==dtmDate.getFullYear())
			{
				eleSelectYear.options[i].selected=true;
				break;
			}
		}
		
		var eleSelectMonth=document.getElementById("DTS_month_"+strId);
		for(var i=0;i<eleSelectMonth.options.length;i++)
		{
			if(eleSelectMonth.options[i].value==dtmDate.getMonth())
			{
				eleSelectMonth.options[i].selected=true;
				break;
			}
		}
		
		var eleSelectDate=document.getElementById("DTS_date_"+strId);
		for(var i=0;i<eleSelectDate.options.length;i++)
		{
			if(eleSelectDate.options[i].value==dtmDate.getDate())
			{
				eleSelectDate.options[i].selected=true;
				break;
			}
		}
		
		if(document.getElementById("DTS_hours_"+strId))
		{
			var eleSelectHours=document.getElementById("DTS_hours_"+strId);
			for(var i=0;i<eleSelectHours.options.length;i++)
			{
				if(eleSelectHours.options[i].value>=0)
				{
					if(eleSelectHours.options[i].value==dtmDate.getHours() || eleSelectHours.options[i].value==(dtmDate.getHours()-12))
					{
						eleSelectHours.options[i].selected=true;
						break;
					}
				}
			}
		}
		
		if(document.getElementById("DTS_minutes_"+strId))
		{
			var eleSelectMinutes=document.getElementById("DTS_minutes_"+strId);
			for(var i=0;i<eleSelectMinutes.options.length;i++)
			{
				if(eleSelectMinutes.options[i].value>=0)
				{
					if(eleSelectMinutes.options[i].value <= dtmDate.getMinutes() && eleSelectMinutes.options[i].value > dtmDate.getMinutes()-15)
					{
						eleSelectMinutes.options[i].selected=true;
						break;
					}
				}
			}
		}
		
		if(document.getElementById("DTS_am_"+strId))
		{
			var eleSelectAm=document.getElementById("DTS_am_"+strId);
			for(var i=0;i<eleSelectAm.options.length;i++)
			{
				if(eleSelectAm.options[i].value>=0)
				{
					if(eleSelectAm.options[i].value <= dtmDate.getHours() && eleSelectAm.options[i].value > dtmDate.getHours()-12)
					{
						eleSelectAm.options[i].selected=true;
						break;
					}
				}
			}
		}
		
		//determine type
		if(eleSelectHours && eleSelectHours.options[0].value==-1)
			intType=this.intTypeDateOptional;
		
		//check type
		if(intType==this.intTypeDateOptional)
		{
			//check for default time
			if(eleSelectHours.value==0 && eleSelectMinutes.value==0 && eleSelectAm.value==0)
			{
				//select default options
				eleSelectHours.options[0].selected=true;
				eleSelectMinutes.options[0].selected=true;
				eleSelectAm.options[0].selected=true;
			}
		}
	},
	
	getDateObject:function(strId)
	{
		var input=document.getElementById(strId);
		var dtmDate=new Date();
		
		dtmDate.setTime(input.value.valueOf()*1000);
		
		return dtmDate;
	},
	
	getId:function(strId)
	{
		//remove all possible prefixes
		strId=strId.replace("DTS_year_","");
		strId=strId.replace("DTS_month_","");
		strId=strId.replace("DTS_date_","");
		strId=strId.replace("DTS_hours_","");
		strId=strId.replace("DTS_minutes_","");
		strId=strId.replace("DTS_am_","");
		
		return strId;
	},
	
	clearOptions:function(eleSelect)
	{
		while(eleSelect.options.length>0)
		{
			eleSelect.remove(0);
		}
	},
	
	disabled:function(strId,blnDisabled)
	{
		if(document.getElementById("DTS_year_"+strId))
			document.getElementById("DTS_year_"+strId).disabled=blnDisabled;
		if(document.getElementById("DTS_month_"+strId))
			document.getElementById("DTS_month_"+strId).disabled=blnDisabled;
		if(document.getElementById("DTS_date_"+strId))
			document.getElementById("DTS_date_"+strId).disabled=blnDisabled;
		if(document.getElementById("DTS_hours_"+strId))
			document.getElementById("DTS_hours_"+strId).disabled=blnDisabled;
		if(document.getElementById("DTS_minutes_"+strId))
			document.getElementById("DTS_minutes_"+strId).disabled=blnDisabled;
		if(document.getElementById("DTS_am_"+strId))
			document.getElementById("DTS_am_"+strId).disabled=blnDisabled;
	},
	
	month:["January","February","March","April","May","June","July","August","September","October","November","December"],
	monthAbbrev:["Jan.","Feb.","Mar.","Apr.","May","June","July","Aug.","Sept.","Oct.","Nov.","Dec."]
}/*
 * A JavaScript implementation of the RSA Data Security, Inc. MD5 Message
 * Digest Algorithm, as defined in RFC 1321.
 * Version 2.1 Copyright (C) Paul Johnston 1999 - 2002.
 * Other contributors: Greg Holt, Andrew Kepert, Ydnar, Lostinet
 * Distributed under the BSD License
 * See http://pajhome.org.uk/crypt/md5 for more info.
 */

/*
 * Configurable variables. You may need to tweak these to be compatible with
 * the server-side, but the defaults work in most cases.
 */
var hexcase = 0;  /* hex output format. 0 - lowercase; 1 - uppercase        */
var b64pad  = ""; /* base-64 pad character. "=" for strict RFC compliance   */
var chrsz   = 8;  /* bits per input character. 8 - ASCII; 16 - Unicode      */

/*
 * These are the functions you'll usually want to call
 * They take string arguments and return either hex or base-64 encoded strings
 */
function hex_md5(s){ return binl2hex(core_md5(str2binl(s), s.length * chrsz));}
function b64_md5(s){ return binl2b64(core_md5(str2binl(s), s.length * chrsz));}
function str_md5(s){ return binl2str(core_md5(str2binl(s), s.length * chrsz));}
function hex_hmac_md5(key, data) { return binl2hex(core_hmac_md5(key, data)); }
function b64_hmac_md5(key, data) { return binl2b64(core_hmac_md5(key, data)); }
function str_hmac_md5(key, data) { return binl2str(core_hmac_md5(key, data)); }

/*
 * Perform a simple self-test to see if the VM is working
 */
function md5_vm_test()
{
  return hex_md5("abc") == "900150983cd24fb0d6963f7d28e17f72";
}

/*
 * Calculate the MD5 of an array of little-endian words, and a bit length
 */
function core_md5(x, len)
{
  /* append padding */
  x[len >> 5] |= 0x80 << ((len) % 32);
  x[(((len + 64) >>> 9) << 4) + 14] = len;

  var a =  1732584193;
  var b = -271733879;
  var c = -1732584194;
  var d =  271733878;

  for(var i = 0; i < x.length; i += 16)
  {
    var olda = a;
    var oldb = b;
    var oldc = c;
    var oldd = d;

    a = md5_ff(a, b, c, d, x[i+ 0], 7 , -680876936);
    d = md5_ff(d, a, b, c, x[i+ 1], 12, -389564586);
    c = md5_ff(c, d, a, b, x[i+ 2], 17,  606105819);
    b = md5_ff(b, c, d, a, x[i+ 3], 22, -1044525330);
    a = md5_ff(a, b, c, d, x[i+ 4], 7 , -176418897);
    d = md5_ff(d, a, b, c, x[i+ 5], 12,  1200080426);
    c = md5_ff(c, d, a, b, x[i+ 6], 17, -1473231341);
    b = md5_ff(b, c, d, a, x[i+ 7], 22, -45705983);
    a = md5_ff(a, b, c, d, x[i+ 8], 7 ,  1770035416);
    d = md5_ff(d, a, b, c, x[i+ 9], 12, -1958414417);
    c = md5_ff(c, d, a, b, x[i+10], 17, -42063);
    b = md5_ff(b, c, d, a, x[i+11], 22, -1990404162);
    a = md5_ff(a, b, c, d, x[i+12], 7 ,  1804603682);
    d = md5_ff(d, a, b, c, x[i+13], 12, -40341101);
    c = md5_ff(c, d, a, b, x[i+14], 17, -1502002290);
    b = md5_ff(b, c, d, a, x[i+15], 22,  1236535329);

    a = md5_gg(a, b, c, d, x[i+ 1], 5 , -165796510);
    d = md5_gg(d, a, b, c, x[i+ 6], 9 , -1069501632);
    c = md5_gg(c, d, a, b, x[i+11], 14,  643717713);
    b = md5_gg(b, c, d, a, x[i+ 0], 20, -373897302);
    a = md5_gg(a, b, c, d, x[i+ 5], 5 , -701558691);
    d = md5_gg(d, a, b, c, x[i+10], 9 ,  38016083);
    c = md5_gg(c, d, a, b, x[i+15], 14, -660478335);
    b = md5_gg(b, c, d, a, x[i+ 4], 20, -405537848);
    a = md5_gg(a, b, c, d, x[i+ 9], 5 ,  568446438);
    d = md5_gg(d, a, b, c, x[i+14], 9 , -1019803690);
    c = md5_gg(c, d, a, b, x[i+ 3], 14, -187363961);
    b = md5_gg(b, c, d, a, x[i+ 8], 20,  1163531501);
    a = md5_gg(a, b, c, d, x[i+13], 5 , -1444681467);
    d = md5_gg(d, a, b, c, x[i+ 2], 9 , -51403784);
    c = md5_gg(c, d, a, b, x[i+ 7], 14,  1735328473);
    b = md5_gg(b, c, d, a, x[i+12], 20, -1926607734);

    a = md5_hh(a, b, c, d, x[i+ 5], 4 , -378558);
    d = md5_hh(d, a, b, c, x[i+ 8], 11, -2022574463);
    c = md5_hh(c, d, a, b, x[i+11], 16,  1839030562);
    b = md5_hh(b, c, d, a, x[i+14], 23, -35309556);
    a = md5_hh(a, b, c, d, x[i+ 1], 4 , -1530992060);
    d = md5_hh(d, a, b, c, x[i+ 4], 11,  1272893353);
    c = md5_hh(c, d, a, b, x[i+ 7], 16, -155497632);
    b = md5_hh(b, c, d, a, x[i+10], 23, -1094730640);
    a = md5_hh(a, b, c, d, x[i+13], 4 ,  681279174);
    d = md5_hh(d, a, b, c, x[i+ 0], 11, -358537222);
    c = md5_hh(c, d, a, b, x[i+ 3], 16, -722521979);
    b = md5_hh(b, c, d, a, x[i+ 6], 23,  76029189);
    a = md5_hh(a, b, c, d, x[i+ 9], 4 , -640364487);
    d = md5_hh(d, a, b, c, x[i+12], 11, -421815835);
    c = md5_hh(c, d, a, b, x[i+15], 16,  530742520);
    b = md5_hh(b, c, d, a, x[i+ 2], 23, -995338651);

    a = md5_ii(a, b, c, d, x[i+ 0], 6 , -198630844);
    d = md5_ii(d, a, b, c, x[i+ 7], 10,  1126891415);
    c = md5_ii(c, d, a, b, x[i+14], 15, -1416354905);
    b = md5_ii(b, c, d, a, x[i+ 5], 21, -57434055);
    a = md5_ii(a, b, c, d, x[i+12], 6 ,  1700485571);
    d = md5_ii(d, a, b, c, x[i+ 3], 10, -1894986606);
    c = md5_ii(c, d, a, b, x[i+10], 15, -1051523);
    b = md5_ii(b, c, d, a, x[i+ 1], 21, -2054922799);
    a = md5_ii(a, b, c, d, x[i+ 8], 6 ,  1873313359);
    d = md5_ii(d, a, b, c, x[i+15], 10, -30611744);
    c = md5_ii(c, d, a, b, x[i+ 6], 15, -1560198380);
    b = md5_ii(b, c, d, a, x[i+13], 21,  1309151649);
    a = md5_ii(a, b, c, d, x[i+ 4], 6 , -145523070);
    d = md5_ii(d, a, b, c, x[i+11], 10, -1120210379);
    c = md5_ii(c, d, a, b, x[i+ 2], 15,  718787259);
    b = md5_ii(b, c, d, a, x[i+ 9], 21, -343485551);

    a = safe_add(a, olda);
    b = safe_add(b, oldb);
    c = safe_add(c, oldc);
    d = safe_add(d, oldd);
  }
  return Array(a, b, c, d);

}

/*
 * These functions implement the four basic operations the algorithm uses.
 */
function md5_cmn(q, a, b, x, s, t)
{
  return safe_add(bit_rol(safe_add(safe_add(a, q), safe_add(x, t)), s),b);
}
function md5_ff(a, b, c, d, x, s, t)
{
  return md5_cmn((b & c) | ((~b) & d), a, b, x, s, t);
}
function md5_gg(a, b, c, d, x, s, t)
{
  return md5_cmn((b & d) | (c & (~d)), a, b, x, s, t);
}
function md5_hh(a, b, c, d, x, s, t)
{
  return md5_cmn(b ^ c ^ d, a, b, x, s, t);
}
function md5_ii(a, b, c, d, x, s, t)
{
  return md5_cmn(c ^ (b | (~d)), a, b, x, s, t);
}

/*
 * Calculate the HMAC-MD5, of a key and some data
 */
function core_hmac_md5(key, data)
{
  var bkey = str2binl(key);
  if(bkey.length > 16) bkey = core_md5(bkey, key.length * chrsz);

  var ipad = Array(16), opad = Array(16);
  for(var i = 0; i < 16; i++)
  {
    ipad[i] = bkey[i] ^ 0x36363636;
    opad[i] = bkey[i] ^ 0x5C5C5C5C;
  }

  var hash = core_md5(ipad.concat(str2binl(data)), 512 + data.length * chrsz);
  return core_md5(opad.concat(hash), 512 + 128);
}

/*
 * Add integers, wrapping at 2^32. This uses 16-bit operations internally
 * to work around bugs in some JS interpreters.
 */
function safe_add(x, y)
{
  var lsw = (x & 0xFFFF) + (y & 0xFFFF);
  var msw = (x >> 16) + (y >> 16) + (lsw >> 16);
  return (msw << 16) | (lsw & 0xFFFF);
}

/*
 * Bitwise rotate a 32-bit number to the left.
 */
function bit_rol(num, cnt)
{
  return (num << cnt) | (num >>> (32 - cnt));
}

/*
 * Convert a string to an array of little-endian words
 * If chrsz is ASCII, characters >255 have their hi-byte silently ignored.
 */
function str2binl(str)
{
  var bin = Array();
  var mask = (1 << chrsz) - 1;
  for(var i = 0; i < str.length * chrsz; i += chrsz)
    bin[i>>5] |= (str.charCodeAt(i / chrsz) & mask) << (i%32);
  return bin;
}

/*
 * Convert an array of little-endian words to a string
 */
function binl2str(bin)
{
  var str = "";
  var mask = (1 << chrsz) - 1;
  for(var i = 0; i < bin.length * 32; i += chrsz)
    str += String.fromCharCode((bin[i>>5] >>> (i % 32)) & mask);
  return str;
}

/*
 * Convert an array of little-endian words to a hex string.
 */
function binl2hex(binarray)
{
  var hex_tab = hexcase ? "0123456789ABCDEF" : "0123456789abcdef";
  var str = "";
  for(var i = 0; i < binarray.length * 4; i++)
  {
    str += hex_tab.charAt((binarray[i>>2] >> ((i%4)*8+4)) & 0xF) +
           hex_tab.charAt((binarray[i>>2] >> ((i%4)*8  )) & 0xF);
  }
  return str;
}

/*
 * Convert an array of little-endian words to a base-64 string
 */
function binl2b64(binarray)
{
  var tab = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
  var str = "";
  for(var i = 0; i < binarray.length * 4; i += 3)
  {
    var triplet = (((binarray[i   >> 2] >> 8 * ( i   %4)) & 0xFF) << 16)
                | (((binarray[i+1 >> 2] >> 8 * ((i+1)%4)) & 0xFF) << 8 )
                |  ((binarray[i+2 >> 2] >> 8 * ((i+2)%4)) & 0xFF);
    for(var j = 0; j < 4; j++)
    {
      if(i * 8 + j * 6 > binarray.length * 32) str += b64pad;
      else str += tab.charAt((triplet >> 6*(3-j)) & 0x3F);
    }
  }
  return str;
}/*--------------------------------------------------
	Project:	The November Group - Progress bar
	Script:		TNGProgressBar.js
	Includes:	TNGProgressBar
--------------------------------------------------*/

//sample settings object
/*
 * settings object properties:
 * 
 * objSettings={
 * 		intPercent:0
 * };
 */

//constructor
function TNGProgressBar(objSettings)
{
	//constants
	this.IdPrefix="TNGProgressBar";
	this.ImageBoxPath="/css/tng/progressbar/box.gif";
	this.ImageBarPath="/css/tng/progressbar/bar.png";
	this.Width=150;
	
	//set default values
	this.intPercent=0;
	this.intId=TNGProgressBar.objects.length;
	TNGProgressBar.objects[TNGProgressBar.objects.length]=this; //add this to static array
	
	//set to passed values
	if(objSettings.intPercent)
		this.intPercent=objSettings.intPercent;
	
	//methods
	this.getId=function()
	{
		return this.intId;
	};
	this.getHtmlId=function()
	{
		return this.IdPrefix + this.getId().toString();
	};
	this.getProgressBar=function()
	{
		var eleProgressBar=document.createElement("div");
		eleProgressBar.id=this.getHtmlId();
		//set styles
		eleProgressBar.style.cssFloat="left";
		eleProgressBar.style.width=this.Width.toString()+"px";
		eleProgressBar.style.height="12px";
		eleProgressBar.style.margin="5px 7px 0px 0px";
		eleProgressBar.style.backgroundImage="url('"+this.ImageBarPath+"')";
		eleProgressBar.style.backgroundRepeat="no-repeat";
		eleProgressBar.style.backgroundPosition="-"+this.Width.toString()+"px 0px";
		
		var eleImgBox=document.createElement("img");
		eleProgressBar.appendChild(eleImgBox);
		eleImgBox.src=this.ImageBoxPath;
		eleImgBox.width=this.Width.toString();
		eleImgBox.height="12";
		eleImgBox.alt="";
		eleImgBox.title="";
		//set styles
		eleImgBox.style.display="block";
		
		return eleProgressBar;
	};
	this.setPercent=function(intPercent)
	{
		var intPosition=-this.Width + Math.round(intPercent / 100 * this.Width);
		
		if(document.getElementById(this.getHtmlId()))
			document.getElementById(this.getHtmlId()).style.backgroundPosition=intPosition+"px 0px";
	};
};

if(TNGProgressBar.objects==undefined)
	TNGProgressBar.objects=new Array();

/*--------------------------------------------------
	Project:	The November Group - CMS Administration
	Script:		cms_user.js
	Includes:	CMS_User
--------------------------------------------------*/

var CMS_User={
	
	blnUsernameAvailable:null,
	blnSubmit:false,
	
	loginAs:function(intUserId)
	{
		CMS_Main.setPage("");
		
		CMS_Main.objRequest.open("GET","get_page_xml.php?fAction=loginAs&fUser_id="+intUserId.toString(),true);
		CMS_Main.objRequest.onreadystatechange=CMS_Main.updatePage;
		CMS_Main.objRequest.send(null);
		
		return false;
	},

	loginFormInitialize:function(frm)
	{
		if(frm)
		{
			frm.fUsername.focus();
			frm.fUsername.select();
		}
	},
	
	loginFormSubmit:function(frm)
	{
		//declare variables
		var blnReturnValue=true;
		
		if(frm.fUsername.value.length==0)
		{
			alert("Please enter your username");
			frm.fUsername.focus();
			frm.fUsername.select();
			blnReturnValue=false;
		}
		else if(frm.fPassword.value.length==0)
		{
			alert("Please enter your password");
			frm.fPassword.focus();
			frm.fPassword.select();
			blnReturnValue=false;
		}
		
		if(blnReturnValue)
		{
			frm.fPassword_hash.value=hex_md5(frm.fUsername.value+frm.fPassword.value); //md5 encode the password
			frm.fPassword.value=""; //clear the entered password field before submitting form data
			document.getElementById("fSubmit").disabled=true;
			CMS_Main.setPage("");
			
			CMS_Main.objRequest.open("POST","get_element_xml.php?function=login&fUsername="+frm.fUsername.value.toString()+"&fPassword_hash="+frm.fPassword_hash.value.toString(),true);
			CMS_Main.objRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
			CMS_Main.objRequest.onreadystatechange=function()
			{
				if(CMS_Main.objRequest.readyState==4 && CMS_Main.objRequest.status==200)
				{
					var objData=eval("("+CMS_Main.objRequest.responseText+")");
					
					//check for login
					if (objData.blnLoggedIn) 
						window.location.assign(CMS_Main.getRootDirectory()+"/admin.php");
					else
					{
						if(objData.strMessage)
							if(document.getElementById("message"))
								document.getElementById("message").innerHTML="<div class=\"error\"><div class=\"error_inner\"><strong>Access denied</strong> | <span>"+objData.strMessage+"</span></div></div>";
						
						document.getElementById("fSubmit").disabled=false;
					}
				}
			};
			CMS_Main.objRequest.send(null);
		}
		
		return false;
	},
	
	logout:function()
	{
		CMS_Main.objRequest.open("GET","get_page_xml.php?fAction=logout",true);
		CMS_Main.objRequest.onreadystatechange=CMS_Main.updatePage;
		CMS_Main.objRequest.send(null);
		
		return false;
	},
	
	manageAdministrators:function()
	{
		CMS_Main.setPage("manageAdministrators");
		
		CMS_Main.objRequest.open("GET","get_page_xml.php?page="+CMS_Main.getPage(),true);
		CMS_Main.objRequest.onreadystatechange=CMS_Main.updatePage;
		CMS_Main.objRequest.send(null);
		
		return false;
	},
	
	manageUsers:function()
	{
		CMS_Main.setPage("manageUsers");
		
		CMS_Main.objRequest.open("GET","get_page_xml.php?page="+CMS_Main.getPage(),true);
		CMS_Main.objRequest.onreadystatechange=CMS_Main.updatePage;
		CMS_Main.objRequest.send(null);
		
		return false;
	},
	
	addUser:function()
	{
		CMS_Main.objRequest.open("GET","get_page_xml.php?page=addUser",true);
		CMS_Main.objRequest.onreadystatechange=CMS_Main.updatePage;
		CMS_Main.objRequest.send(null);
		
		return false;
	},
	
	addUserFormInitialize:function(frm)
	{
		if(frm && frm.fFirst_name)
		{
			frm.fFirst_name.focus();
			frm.fFirst_name.select();
		}
	},
	
	addUserFormSubmit:function(frm)
	{
		//declare variables
		var blnReturnValue=true;
		
		if (frm.fUsername.value.length > 0 && CMS_User.blnUsernameAvailable == null) 
		{
			this.blnSubmit = true;
			blnReturnValue = false;
			
			//force username blur
			this.onUsernameBlur(frm.fUsername.value);
		}
		else 
		{
			if(frm.fFirst_name.value.length==0)
			{
				alert("Please enter a first name");
				frm.fFirst_name.focus();
				frm.fFirst_name.select();
				blnReturnValue=false;
			}
			else if(frm.fLast_name.value.length==0)
			{
				alert("Please enter a last name");
				frm.fLast_name.focus();
				frm.fLast_name.select();
				blnReturnValue=false;
			}
			else if(frm.fEmail.value.length==0)
			{
				alert("Please enter an email address");
				frm.fEmail.focus();
				frm.fEmail.select();
				blnReturnValue=false;
			}
			else if(!CMS_Main.isValidEmailAddress(frm.fEmail.value))
			{
				alert("Please enter a valid email address");
				frm.fEmail.focus();
				frm.fEmail.select();
				blnReturnValue=false;
			}
			else if(frm.fPhone.value.length==0)
			{
				alert("Please enter a phone number");
				frm.fPhone.focus();
				frm.fPhone.select();
				blnReturnValue=false;
			}
			else if(frm.fUsername.value.length==0)
			{
				alert("Please enter a username");
				frm.fUsername.focus();
				blnReturnValue=false;
			}
			else if(!CMS_User.blnUsernameAvailable)
			{
				alert("The username you entered is already in use. Please enter a different username.");
				frm.fUsername.focus();
				frm.fUsername.select();
				blnReturnValue=false;
			}
			else if(frm.fPassword.value.length==0)
			{
				alert("Please enter a password");
				frm.fPassword.focus();
				frm.fPassword.select();
				blnReturnValue=false;
			}
			else if(frm.fPassword_repeat.value.length==0)
			{
				alert("Please repeat the password");
				frm.fPassword_repeat.focus();
				frm.fPassword_repeat.select();
				blnReturnValue=false;
			}
			else if(frm.fPassword.value!=frm.fPassword_repeat.value)
			{
				alert("The passwords entered do not match. Please re-enter the passwords.");
				frm.fPassword.value="";
				frm.fPassword_repeat.value="";
				frm.fPassword.focus();
				frm.fPassword.select();
				blnReturnValue=false;
			}
		}
		
		if(blnReturnValue)
		{
			frm.fPassword_hash.value=hex_md5(frm.fUsername.value+frm.fPassword.value); //md5 encode the password
			frm.fPassword.value=""; //clear the entered password fields before submitting form data
			frm.fPassword_repeat.value="";

			//select all items in fClient_ids
			if(frm.fClient_ids)
			{
				for(var i=0;i<frm.fClient_ids.length;i++)
				{
					frm.fClient_ids.options[i].selected=true;
				}
			}
			//select all items in fClient_ids_available
			if(frm.fClient_ids_available)
			{
				for(var i=0;i<frm.fClient_ids_available.length;i++)
				{
					frm.fClient_ids_available.options[i].selected=true;
				}
			}
			
			document.getElementById("fSubmit").disabled=true;
			
			CMS_Main.objRequest.open("POST","get_page_xml.php",true);
			CMS_Main.objRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
			CMS_Main.objRequest.onreadystatechange=CMS_Main.updatePage;
			CMS_Main.objRequest.send(CMS_Main.formEncode(frm)+"&page="+CMS_Main.getPage());
		}
		
		return false;
	},
	
	addUserFormCancel:function(frm)
	{
		CMS_Main.objRequest.open("GET","get_page_xml.php?page="+CMS_Main.getPage(),true);
		CMS_Main.objRequest.onreadystatechange=CMS_Main.updatePage;
		CMS_Main.objRequest.send(null);
		
		return false;
	},
	
	onUsernameChange:function(eleInput)
	{
		CMS_User.blnUsernameAvailable=null;
		
		return true;
	},
	
	onUsernameBlur:function(strUsername)
	{
		if (strUsername.length == 0) 
		{
			//remove message
			if (document.getElementById("usernameStatus")) 
				document.getElementById("usernameStatus").innerHTML = "";
			
			CMS_User.blnUsernameAvailable = null;
		}
		else 
		{
			//loading message
			if(document.getElementById("usernameStatus"))
				document.getElementById("usernameStatus").innerHTML="Checking username...";
			
			CMS_User.blnUsernameAvailable=null;
			
			var objUsernameRequest=CMS_Main.createRequest();
			objUsernameRequest.open("GET","get_element_xml.php?function=checkUsernameXml&fUsername="+strUsername.toString(),true);
			objUsernameRequest.onreadystatechange=function(){
				if(objUsernameRequest.readyState==4 && objUsernameRequest.status==200)
				{
					var eleDoc=objUsernameRequest.responseXML.documentElement;
					
					if(eleDoc.getElementsByTagName("usernameAvailable").length>0)
					{
						if(eleDoc.getElementsByTagName("usernameAvailable")[0].firstChild && eleDoc.getElementsByTagName("usernameAvailable")[0].firstChild.nodeValue=="1")
							CMS_User.blnUsernameAvailable=true;
						else
							CMS_User.blnUsernameAvailable=false;
							
						//update status message
						if(document.getElementById("usernameStatus"))
							if(CMS_User.blnUsernameAvailable)
								document.getElementById("usernameStatus").innerHTML="<span class=\"system positive\">Username is available</span>";
							else
								document.getElementById("usernameStatus").innerHTML="<span class=\"system negative\">Username is already in use</span>";
							
						if(CMS_User.blnSubmit)
						{
							CMS_User.blnSubmit=false;
							CMS_User.addUserFormSubmit(document.getElementById("frmAddUser"));
						}
					}
				}
			};
			objUsernameRequest.send(null);
		}
		
		return true;
	},
	
	editUser:function(intUserId)
	{
		CMS_Main.objRequest.open("GET","get_page_xml.php?page=editUser&fUser_id="+intUserId.toString(),true);
		CMS_Main.objRequest.onreadystatechange=CMS_Main.updatePage;
		CMS_Main.objRequest.send(null);
		
		return false;
	},
	
	editUserFormInitialize:function(frm)
	{
		if(frm)
		{
			CMS_Client_User_Settings.initialize(frm);
			this.editUserChangePasswordClick(frm);
			
			if(frm.fFirst_name)
			{
				frm.fFirst_name.focus();
				frm.fFirst_name.select();
			}
		}
	},
	
	editUserFormSubmit:function(frm)
	{
		//declare variables
		var blnReturnValue=true;
		
		if(frm.fChange_password.checked && frm.fPassword.value.length==0)
		{
			alert("Please enter a new password");
			frm.fPassword.focus();
			frm.fPassword.select();
			blnReturnValue=false;
		}
		else if(frm.fChange_password.checked && frm.fPassword_repeat.value.length==0)
		{
			alert("Please repeat the new password");
			frm.fPassword_repeat.focus();
			frm.fPassword_repeat.select();
			blnReturnValue=false;
		}
		else if(frm.fChange_password.checked && frm.fPassword.value!=frm.fPassword_repeat.value)
		{
			alert("The passwords entered do not match. Please re-enter the passwords.");
			frm.fPassword.value="";
			frm.fPassword_repeat.value="";
			frm.fPassword.focus();
			frm.fPassword.select();
			blnReturnValue=false;
		}
		else if(frm.fFirst_name.value.length==0)
		{
			alert("Please enter a first name");
			frm.fFirst_name.focus();
			frm.fFirst_name.select();
			blnReturnValue=false;
		}
		else if(frm.fLast_name.value.length==0)
		{
			alert("Please enter a last name");
			frm.fLast_name.focus();
			frm.fLast_name.select();
			blnReturnValue=false;
		}
		else if(frm.fEmail.value.length==0)
		{
			alert("Please enter an email address");
			frm.fEmail.focus();
			frm.fEmail.select();
			blnReturnValue=false;
		}
		else if(!CMS_Main.isValidEmailAddress(frm.fEmail.value))
		{
			alert("Please enter a valid email address");
			frm.fEmail.focus();
			frm.fEmail.select();
			blnReturnValue=false;
		}
		else if(frm.fPhone.value.length==0)
		{
			alert("Please enter a phone number");
			frm.fPhone.focus();
			frm.fPhone.select();
			blnReturnValue=false;
		}
		
		if(blnReturnValue)
		{
			if(frm.fChange_password.checked)
			{
				frm.fPassword_hash.value=hex_md5(frm.fUsername.value+frm.fPassword.value); //md5 encode the password
			}
			frm.fPassword.value=""; //clear the entered password fields before submitting form data
			frm.fPassword_repeat.value="";
			
			//select all items in fClient_ids
			if(frm.fClient_ids)
			{
				for(var i=0;i<frm.fClient_ids.length;i++)
				{
					frm.fClient_ids.options[i].selected=true;
				}
			}
			//select all items in fClient_ids_available
			if(frm.fClient_ids_available)
			{
				for(var i=0;i<frm.fClient_ids_available.length;i++)
				{
					frm.fClient_ids_available.options[i].selected=true;
				}
			}
			
			document.getElementById("fSubmit").disabled=true;
			
			CMS_Main.objRequest.open("POST","get_page_xml.php",true);
			CMS_Main.objRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
			CMS_Main.objRequest.onreadystatechange=CMS_Main.updatePage;
			CMS_Main.objRequest.send(CMS_Main.formEncode(frm)+"&page="+CMS_Main.getPage());
		}
		
		return false;
	},
	
	editUserFormCancel:function(frm)
	{
		CMS_Main.objRequest.open("GET","get_page_xml.php?page="+CMS_Main.getPage(),true);
		CMS_Main.objRequest.onreadystatechange=CMS_Main.updatePage;
		CMS_Main.objRequest.send(null);
		
		return false;
	},
	
	editUserChangePasswordClick:function(frm)
	{
		if(frm.fChange_password.checked)
		{
			frm.fPassword.disabled=false;
			frm.fPassword_repeat.disabled=false;
			frm.fPassword.focus();
		}
		else
		{
			frm.fPassword.disabled=true;
			frm.fPassword_repeat.disabled=true;
		}
	},
	
	
	addClientAdmin:function(frm)
	{
		for(var i=0;i<frm.fClient_ids_available.length;i++)
		{
			if(frm.fClient_ids_available.options[i].selected)
			{
				frm.fClient_ids_available.options[i].selected=false;
				try
				{
					frm.fClient_ids.add(frm.fClient_ids_available.options[i],null);
				}
				catch(e) //ie
				{
					var eleOpt=document.createElement("option");
					eleOpt.text=frm.fClient_ids_available.options[i].text;
					eleOpt.value=frm.fClient_ids_available.options[i].value;
					
					frm.fClient_ids.options[frm.fClient_ids.length]=eleOpt;
					frm.fClient_ids_available.remove(i);
				}
				i--; //retry at current index after removing current index
			}
		}
	},
	
	removeClientAdmin:function(frm)
	{
		for(var i=0;i<frm.fClient_ids.options.length;i++)
		{
			if(frm.fClient_ids.options[i].selected)
			{
				frm.fClient_ids.options[i].selected=false;
				try
				{
					frm.fClient_ids_available.add(frm.fClient_ids.options[i],null);
				}
				catch(e) //ie
				{
					var eleOpt=document.createElement("option");
					eleOpt.text=frm.fClient_ids.options[i].text;
					eleOpt.value=frm.fClient_ids.options[i].value;
					
					frm.fClient_ids_available.options[frm.fClient_ids_available.length]=eleOpt;
					frm.fClient_ids.remove(i);
				}
				i--; //retry at current index after removing current index
			}
		}
	},
	
	
	deleteUser:function(intUserId)
	{
		var strUserName=document.getElementById("selectUserName"+intUserId).value.toString();
		
		if(confirm("Are you sure you want to delete user "+strUserName.toString()+"?"))
		{
			CMS_Main.objRequest.open("GET","get_page_xml.php?page="+CMS_Main.getPage()+"&fAction=deleteUser&fUser_id="+intUserId.toString(),true);
			CMS_Main.objRequest.onreadystatechange=CMS_Main.updatePage;
			CMS_Main.objRequest.send(null);
		}
		
		return false;
	}
}/*--------------------------------------------------
	Project:	The November Group - CMS Administration
	Script:		cms_client.js
	Includes:	CMS_Client
--------------------------------------------------*/

var CMS_Client={
	
	blnCodeExists:null,
	blnAddSubmit:false,
	blnEditSubmit:false,
	eleEditorStyleOptions:null,
	eleEditorStyleFileOptions:null,
	intNewStyleIndex:0,
	intNewStyleFileIndex:0,
	
	intMaxFileSize:null,
	intSystemMaxFileSize:null,
	intMaxTotalFileSize:null,
	arrAllowedFileTypes:null,
	arrGalleryAllowedFileTypes:null,
	blnFtpEnabled:null,
	
	getMaxFileSize:function()
	{
		return this.intMaxFileSize;
	},
	getSystemMaxFileSize:function()
	{
		return this.intSystemMaxFileSize;
	},
	getMaxTotalFileSpace:function()
	{
		return this.intMaxTotalFileSpace;
	},
	getAllowedFileTypes:function()
	{
		return this.arrAllowedFileTypes;
	},
	getGalleryAllowedFileTypes:function()
	{
		return this.arrGalleryAllowedFileTypes;
	},
	isFtpEnabled:function()
	{
		return this.blnFtpEnabled;
	},
	
	setMaxFileSize:function(intMaxFileSize)
	{
		this.intMaxFileSize=intMaxFileSize;
	},
	setSystemMaxFileSize:function(intSystemMaxFileSize)
	{
		this.intSystemMaxFileSize=intSystemMaxFileSize;
	},
	setTotalSpace:function(intMaxTotalFileSpace)
	{
		this.intMaxTotalFileSpace=intMaxTotalFileSpace;
	},
	setAllowedFileTypes:function(strArray)
	{
		this.arrAllowedFileTypes=eval(strArray);
	},
	setGalleryAllowedFileTypes:function(strArray)
	{
		this.arrGalleryAllowedFileTypes=eval(strArray);
	},
	setFtpEnabled:function(blnFtpEnabled)
	{
		this.blnFtpEnabled=blnFtpEnabled;
	},

	getEditorStyleOptions:function()
	{
		return this.eleEditorStyleOptions.cloneNode(true);
	},
	
	getEditorStyleFileOptions:function()
	{
		return this.eleEditorStyleFileOptions.cloneNode(true);
	},
		
		
	manageClients:function()
	{
		CMS_Main.setPage("manageClients");
		
		CMS_Main.objRequest.open("GET","get_page_xml.php?page="+CMS_Main.getPage(),true);
		CMS_Main.objRequest.onreadystatechange=CMS_Main.updatePage;
		CMS_Main.objRequest.send(null);
		
		return false;
	},
	
	addClient:function()
	{
		CMS_Main.objRequest.open("GET","get_page_xml.php?page=editClient",true);
		CMS_Main.objRequest.onreadystatechange=CMS_Main.updatePage;
		CMS_Main.objRequest.send(null);
		
		return false;
	},
	
	onCodeChange:function(eleInput)
	{
		this.blnCodeExists=null;
		
		return true;
	},
	
	onCodeBlur:function(intClientId, strCode)
	{
		CMS_Client.blnCodeExists = null;

		if (strCode.length == 0) 
		{
			//remove message
			if (document.getElementById("codeStatus")) 
				document.getElementById("codeStatus").innerHTML = "";
		}
		else 
		{
			//loading message
			if (document.getElementById("codeStatus")) 
				document.getElementById("codeStatus").innerHTML = "Checking code...";
			
			var objCodeRequest=CMS_Main.createRequest();
			objCodeRequest.open("GET","get_element_xml.php?function=checkCodeXml&fClient_id="+intClientId.toString()+"&fCode="+strCode.toString(),true);
			objCodeRequest.onreadystatechange=function(){
				if(objCodeRequest.readyState==4 && objCodeRequest.status==200)
				{
					var eleDoc=objCodeRequest.responseXML.documentElement;
					
					if(eleDoc.getElementsByTagName("codeExists").length>0)
					{
						if(eleDoc.getElementsByTagName("codeExists")[0].firstChild && eleDoc.getElementsByTagName("codeExists")[0].firstChild.nodeValue=="1")
							CMS_Client.blnCodeExists=true;
						else
							CMS_Client.blnCodeExists=false;
							
						//update status message
						if(document.getElementById("codeStatus"))
							if(!CMS_Client.blnCodeExists)
								document.getElementById("codeStatus").innerHTML="<span class=\"system positive\">Code is available</span>";
							else
								document.getElementById("codeStatus").innerHTML="<span class=\"system negative\">Code is already in use</span>";
							
						if(CMS_Client.blnAddSubmit)
						{
							CMS_Client.blnAddSubmit=false;
							CMS_Client.addClientFormSubmit(document.getElementById("frmAddClient"));
						}
						if(CMS_Client.blnEditSubmit)
						{
							CMS_Client.blnEditSubmit=false;
							CMS_Client.editClientFormSubmit(document.getElementById("frmEditClient"));
						}
					}
				}
			};
			objCodeRequest.send(null);
		}			
		
		return true;
	},

	editClient:function(intClientId)
	{
		CMS_Main.objRequest.open("GET","get_page_xml.php?page=editClient&fClient_id="+intClientId.toString(),true);
		CMS_Main.objRequest.onreadystatechange=CMS_Main.updatePage;
		CMS_Main.objRequest.send(null);
		
		return false;
	},
	
	editClientFormInitialize:function(frm)
	{
		this.blnCodeExists=null;
		this.blnEditSubmit=false;

		//store text editor options html
		if(document.getElementById("editorStyleFileOptions"))
			this.eleEditorStyleFileOptions=document.getElementById("editorStyleFileOptions").parentNode.removeChild(document.getElementById("editorStyleFileOptions"));
		if(document.getElementById("editorStyleOptions"))
			this.eleEditorStyleOptions=document.getElementById("editorStyleOptions").parentNode.removeChild(document.getElementById("editorStyleOptions"));

		if(frm)
		{
			frm.fName.focus();
			frm.fName.select();
		}
		
		this.onFileActiveClick(frm.fFile_active);
		this.onFtpEnabledClick(frm.fFtp_enabled);
		this.onHttpPathAutoClick(frm);
		this.onCalendarActiveClick(frm.fCalendar_active);
		this.onFormActiveClick(frm.fForm_active);
		this.onDynamicActiveClick(frm.fDynamic_active);
		this.onSiteUserActiveClick(frm.fSite_user_active);
		this.onPageActiveClick(frm.fPage_active);
		this.onGalleryActiveClick(frm.fGallery_active);
		this.onContestActiveClick(frm.fContest_active);
		
		this.initializeMaxFileSize(frm);
		this.initializeTotalSpace(frm);
		this.onCalendarFileCategoryCreateNewClick(frm.fCalendar_file_category_new);
		this.onDynamicFileCategoryCreateNewClick(frm.fDynamic_file_category_new);
		this.onPageFileCategoryCreateNewClick(frm.fPage_file_category_new);
		this.onGalleryFileCategoryCreateNewClick(frm.fGallery_file_category_new);
	},

	addEditorStyle:function()
	{
		if (document.getElementById("styleListContainer")) 
		{
			//increment index
			this.intNewStyleIndex++;
			var strId = "new" + this.intNewStyleIndex.toString();
		
			//add field options to document
			document.getElementById("styleListContainer").appendChild(this.getEditorStyleOptions());
			
			//update element ids
			document.getElementById("editorStyleOptions").id+=strId;
			
			document.getElementById("fEditor_default_style_id").id+=strId;
			document.getElementById("fEditor_default_style_id"+strId).value=strId;
			document.getElementById("fEditor_style_id").id+=strId;
			document.getElementById("fEditor_style_id"+strId).value=strId;
			document.getElementById("fEditor_style_name").name+=strId;
			document.getElementById("fEditor_style_name").id+=strId;
			document.getElementById("fEditor_style_name_label").id+=strId;
			document.getElementById("fEditor_style_name_label"+strId).htmlFor="fEditor_style_name"+strId;
			
			document.getElementById("editorStyleFileListContainer").id+=strId;
			
			document.getElementById("editorStyleFileAdd").id+=strId;
			CMS_Main.addListener(document.getElementById("editorStyleFileAdd"+strId),"click",function(){
				return CMS_Client.addEditorStyleFile(strId);
			});
			
			document.getElementById("editorStyleDelete").id+=strId;
			CMS_Main.addListener(document.getElementById("editorStyleDelete"+strId),"click",function(){
				return CMS_Client.deleleEditorStyle(strId);
			});
		}	
		
		return false;
	},
	
	addEditorStyleFile:function(strStyleId)
	{
		if (document.getElementById("editorStyleFileListContainer"+strStyleId)) 
		{
			//increment index
			this.intNewStyleFileIndex++;
			var strFileId = "file"+this.intNewStyleFileIndex.toString();
		
			//add field options to document
			document.getElementById("editorStyleFileListContainer"+strStyleId).appendChild(this.getEditorStyleFileOptions());
			
			//update element ids
			document.getElementById("editorStyleFileOptions").id+=strStyleId+strFileId;
			
			document.getElementById("fEditor_style_file").name+=strStyleId;
			document.getElementById("fEditor_style_file").id+=strStyleId;
		}	
		
		return false;
	},
	
	deleleEditorStyle:function(strStyleId)
	{
		if (document.getElementById("editorStyleOptions"+strStyleId)) 
			document.getElementById("editorStyleOptions"+strStyleId).parentNode.removeChild(document.getElementById("editorStyleOptions"+strStyleId));
		
		return false;		
	},
		
	editClientFormSubmit:function(frm)
	{
		//declare variables
		var blnReturnValue=true;
		
		if (frm.fCode.value.length > 0 && CMS_Client.blnCodeExists == null) 
		{
			this.blnEditSubmit = true;
			blnReturnValue = false;
			
			//force code blur
			this.onCodeBlur(frm.fClient_id.value, frm.fCode.value);
		}
		else 
		{
			if(frm.fName.value.length==0)
			{
				alert("Please enter a name");
				frm.fName.focus();
				blnReturnValue=false;
			}
			else if(CMS_Client.blnCodeExists)
			{
				alert("The verification code is already in use. Please enter a different verification code.");
				frm.fCode.focus();
				frm.fCode.select();
				blnReturnValue=false;
			}
			else if(frm.fPhone.value.length==0)
			{
				alert("Please enter a phone number");
				frm.fPhone.focus();
				blnReturnValue=false;
			}
			else if(frm.fAddress1.value.length==0)
			{
				alert("Please enter an address");
				frm.fAddress1.focus();
				blnReturnValue=false;
			}
			else if(frm.fCity.value.length==0)
			{
				alert("Please enter a city");
				frm.fCity.focus();
				blnReturnValue=false;
			}
			else if(frm.fProvince.value.length==0)
			{
				alert("Please enter a province");
				frm.fProvince.focus();
				blnReturnValue=false;
			}
			else if(frm.fCountry.value.length==0)
			{
				alert("Please enter a country");
				frm.fCountry.focus();
				blnReturnValue=false;
			}
			else if(frm.fPostal_zip.value.length==0)
			{
				alert("Please enter a postal or zip code");
				frm.fPostal_zip.focus();
				blnReturnValue=false;
			}
			else if(!CMS_Main.isValidPostalZip(frm.fPostal_zip.value,frm.fCountry.value))
			{
				alert("Please enter a valid postal or zip code for "+frm.fCountry.value);
				frm.fPostal_zip.focus();
				blnReturnValue=false;
			}
			else if(frm.fFile_max_file_size.value > this.getSystemMaxFileSize())
			{
				alert("Max file size will be reduced system limit of "+CMS_File.formatFileSize(this.getSystemMaxFileSize())+".");
				frm.fFile_max_file_size.value=this.getSystemMaxFileSize();
				this.initializeMaxFileSize(frm);
			}
			else if(frm.fCalendar_active.checked && frm.fCalendar_file_category_new.checked && frm.fCalendar_file_category_name.value.length==0)
			{
				alert("Please enter a name for the new category");
				frm.fCalendar_file_category_name.focus();
				blnReturnValue=false;
			}
			else if(frm.fDynamic_active.checked && frm.fDynamic_file_category_new.checked && frm.fDynamic_file_category_name.value.length==0)
			{
				alert("Please enter a name for the new category");
				frm.fDynamic_file_category_name.focus();
				blnReturnValue=false;
			}
		}
		
		if(blnReturnValue)
		{
			document.getElementById("fSubmit").disabled=true;
			
			CMS_Main.objRequest.open("POST","get_page_xml.php",true);
			CMS_Main.objRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
			CMS_Main.objRequest.onreadystatechange=CMS_Main.updatePage;
			CMS_Main.objRequest.send(CMS_Main.formEncode(frm)+"&page="+CMS_Main.getPage());
		}
		
		return false;
	},
	
	editClientFormCancel:function(frm)
	{
		CMS_Main.objRequest.open("GET","get_page_xml.php?page="+CMS_Main.getPage(),true);
		CMS_Main.objRequest.onreadystatechange=CMS_Main.updatePage;
		CMS_Main.objRequest.send(null);
		
		return false;
	},
	
	
	deleteClient:function(intClientId)
	{
		var strClientName=document.getElementById("selectClientName"+intClientId).value.toString();
		
		if(confirm("Are you sure you want to delete client "+strClientName.toString()+"?"))
		{
			CMS_Main.objRequest.open("GET","get_page_xml.php?page="+CMS_Main.getPage()+"&fAction=deleteClient&fClient_id="+intClientId.toString(),true);
			CMS_Main.objRequest.onreadystatechange=CMS_Main.updatePage;
			CMS_Main.objRequest.send(null);
		}
		
		return false;
	},
	
	exportClient:function(intClientId)
	{
		window.open("get_element_xml.php?function=CMS_Main::export&arguments[]="+intClientId.toString());
		return false; //cancel link
	},
	
	selectClient:function(intClientId)
	{
		CMS_Main.objRequest.open("GET","get_page_xml.php?page="+CMS_Main.getPage()+"&fAction=selectClient&fClient_id="+intClientId.toString(),true);
		CMS_Main.objRequest.onreadystatechange=CMS_Main.updatePage;
		CMS_Main.objRequest.send(null);
		
		return false;
	},
	
	deselectClient:function(intClientId)
	{
		CMS_Main.objRequest.open("GET","get_page_xml.php?fAction=deselectClient&page=selectClient",true);
		CMS_Main.objRequest.onreadystatechange=CMS_Main.updatePage;
		CMS_Main.objRequest.send(null);
		
		return false;
	},

	
	//file module methods
	
	initializeMaxFileSize:function(frm)
	{
		var intMaxFileSizeAmount=0;
		var intMaxFileSize=Number(frm.fFile_max_file_size.value);
		
		intMaxFileSizeAmount=intMaxFileSize/1048576;
		
		frm.fFile_max_file_size_amount.value=intMaxFileSizeAmount.toFixed(0).toString();
	},
	
	initializeTotalSpace:function(frm)
	{
		var intTotalSpaceAmount=0;
		var intTotalSpace=Number(frm.fFile_total_space.value);
		
		for(var i=0;i<frm.fFile_total_space_unit.options.length;i++)
		{
			if(intTotalSpace >= Number(frm.fFile_total_space_unit.options[i].value))
			{
				intTotalSpaceAmount=intTotalSpace/Number(frm.fFile_total_space_unit.options[i].value);
				frm.fFile_total_space_unit.options[i].selected=true;
			}
		}
		
		frm.fFile_total_space_amount.value=intTotalSpaceAmount.toFixed(0).toString();
	},
	
	onFtpEnabledClick:function(eleInput)
	{
		if(document.getElementById("ftp"))
		{
			if(eleInput.checked)
				document.getElementById("ftp").style.display="block";
			else
				document.getElementById("ftp").style.display="none";
		}
	},

	onFtpPasswordChange:function(frm)
	{
		if(frm.fFtp_password_change)
			frm.fFtp_password_change.checked=true;
	},
		
	onFtpPasswordChangeClick:function(frm)
	{
		if(frm.fFtp_password && frm.fFtp_password_change)
		{
			if(frm.fFtp_password_change.checked)
			{
				frm.fFtp_password.focus();
				frm.fFtp_password.select();
			}
		}
	},
	
	onFtpTestClick:function(frm)
	{
		var blnSuccess=false;
		
		if(frm.fFtp_host && frm.fFtp_path && frm.fFtp_username && frm.fFtp_password)
		{
			if(frm.fFtp_host.value=="")
			{
				alert("Please enter a host or server name for the FTP server");
				frm.fFtp_host.focus();
			}
			else if(frm.fFtp_username.value=="")
			{
				alert("Please enter a username to login to the FTP server");
				frm.fFtp_host.focus();
			}
			else
			{
				var objFtpTestRequest=CMS_Main.createRequest();
				objFtpTestRequest.open("GET","get_element_xml.php?function=ftpTestConnection&fFtp_host="+encodeURIComponent(frm.fFtp_host.value)+"&fFtp_path="+encodeURIComponent(frm.fFtp_path.value)+"&fFtp_username="+encodeURIComponent(frm.fFtp_username.value)+"&fFtp_password="+encodeURIComponent(frm.fFtp_password.value),true);
				objFtpTestRequest.onreadystatechange=function()
				{
					if(objFtpTestRequest.readyState==4 && objFtpTestRequest.status==200)
					{
						var objResponse=eval("("+objFtpTestRequest.responseText+")");
						alert(objResponse.strMessages);
					}
				};
				objFtpTestRequest.send(null);
			}
		}
		
		return false; //cancel link
	},
	
	onHttpPathAutoClick:function(frm)
	{
		if(frm.fHttp_path && frm.fHttp_path_auto)
		{
			frm.fHttp_path.disabled=frm.fHttp_path_auto.checked;
			
			if(frm.fHttp_path_auto.checked)
				this.updateHttpPath(frm);
		}
	},
	
	updateHttpPath:function(frm)
	{
		if(frm.fHttp_path_auto && frm.fHttp_path_auto.checked)
		{
			if(frm.fHttp_path && frm.fFtp_host && frm.fFtp_path)
			{
				//remove duplicate forward slashes
				var strPath=frm.fFtp_host.value+"/"+frm.fFtp_path.value+"/";
				strPath=strPath.replace(/\/\//g,"/");
				
				frm.fHttp_path.value="http://"+strPath;
			}
		}
	},
	
	onFileActiveClick:function(eleInput)
	{
		if(eleInput.checked)
		{
			if(document.getElementById("fileModule"))
				document.getElementById("fileModule").style.display="block";
		}
		else
		{
			if(eleInput.form.fCalendar_active.checked || eleInput.form.fDynamic_active.checked || eleInput.form.fPage_active.checked || eleInput.form.fGallery_active.checked)
			{
				alert("The file module cannot be disabled when either the calendar module, the dynamic content module, the page module, or the gallery module is enabled.");
				eleInput.form.fFile_active.checked=true;
			}
			else
			{
				if(document.getElementById("fileModule"))
					document.getElementById("fileModule").style.display="none";
			}
		}
	},
	
	maxFileSizeChange:function(frm)
	{
		var intMaxFileSizeAmount=Number(frm.fFile_max_file_size_amount.value);
		var intMaxFileSize=0;
		
		intMaxFileSize=intMaxFileSizeAmount*Number(1048576);
		
		frm.fFile_max_file_size.value=intMaxFileSize.toString();
	},
	
	totalSpaceChange:function(frm)
	{
		var intTotalSpaceAmount=Number(frm.fFile_total_space_amount.value);
		var intTotalSpace=0;
		
		for(var i=0;i<frm.fFile_total_space_unit.options.length;i++)
		{
			if(frm.fFile_total_space_unit.options[i].selected)
			{
				intTotalSpace=intTotalSpaceAmount*Number(frm.fFile_total_space_unit.options[i].value);
				break;
			}
		}
		
		frm.fFile_total_space.value=intTotalSpace.toString();
	},
	
	//calendar module methods
	
	onCalendarActiveClick:function(eleInput)
	{
		if(eleInput.checked)
		{
			if(document.getElementById("calendarModule"))
				document.getElementById("calendarModule").style.display="block";
			
			if(!eleInput.form.fFile_active.checked)
			{
				alert("The file module is required by the calendar module and will also be activated.");
				eleInput.form.fFile_active.checked=true;
				this.onFileActiveClick(eleInput.form.fFile_active);
			}
		}
		else
		{
			if(document.getElementById("calendarModule"))
				document.getElementById("calendarModule").style.display="none";
		}
	},
	
	onCalendarFileCategoryCreateNewClick:function(eleInput)
	{
		if(eleInput.checked)
		{
			eleInput.form.fCalendar_file_category_name.disabled=false;
			eleInput.form.fCalendar_file_category_id.disabled=true;
			eleInput.form.fCalendar_file_category_name.focus();
			eleInput.form.fCalendar_file_category_name.select();
		}
		else
		{
			eleInput.form.fCalendar_file_category_name.disabled=true;
			eleInput.form.fCalendar_file_category_id.disabled=false;
		}
	},
	
	//form module methods
	
	onFormActiveClick:function(eleInput)
	{
		if(eleInput.checked)
		{
			if(document.getElementById("formModule"))
				document.getElementById("formModule").style.display="block";
		}
		else
		{
			if(document.getElementById("formModule"))
				document.getElementById("formModule").style.display="none";
		}
	},
	
	//dynamic module methods
	
	onDynamicActiveClick:function(eleInput)
	{
		if(eleInput.checked)
		{
			if(document.getElementById("contentModule"))
				document.getElementById("contentModule").style.display="block";
			
			if(!eleInput.form.fFile_active.checked)
			{
				alert("The file module is required by the dynamic content module and will also be activated.");
				eleInput.form.fFile_active.checked=true;
				this.onFileActiveClick(eleInput.form.fFile_active);
			}
		}
		else
		{
			if(document.getElementById("contentModule"))
				document.getElementById("contentModule").style.display="none";
		}
	},

	onDynamicFileCategoryCreateNewClick:function(eleInput)
	{
		if(eleInput.checked)
		{
			eleInput.form.fDynamic_file_category_name.disabled=false;
			eleInput.form.fDynamic_file_category_id.disabled=true;
			eleInput.form.fDynamic_file_category_name.focus();
			eleInput.form.fDynamic_file_category_name.select();
		}
		else
		{
			eleInput.form.fDynamic_file_category_name.disabled=true;
			eleInput.form.fDynamic_file_category_id.disabled=false;
		}
	},

	//site user module methods
	
	onSiteUserActiveClick:function(eleInput)
	{
		if(eleInput.checked)
		{
			if(document.getElementById("siteUserModule"))
				document.getElementById("siteUserModule").style.display="block";
		}
		else
		{
			if(document.getElementById("siteUserModule"))
				document.getElementById("siteUserModule").style.display="none";
		}
	},
	
	//page module methods
	
	onPageActiveClick:function(eleInput)
	{
		if(eleInput.checked)
		{
			if(document.getElementById("pageModule"))
				document.getElementById("pageModule").style.display="block";
			
			if(!eleInput.form.fFile_active.checked)
			{
				alert("The file module is required by the page module and will also be activated.");
				eleInput.form.fFile_active.checked=true;
				this.onFileActiveClick(eleInput.form.fFile_active);
			}
		}
		else
		{
			if(document.getElementById("pageModule"))
				document.getElementById("pageModule").style.display="none";
		}
	},

	onPageFileCategoryCreateNewClick:function(eleInput)
	{
		if(eleInput.checked)
		{
			eleInput.form.fPage_file_category_name.disabled=false;
			eleInput.form.fPage_file_category_id.disabled=true;
			eleInput.form.fPage_file_category_name.focus();
			eleInput.form.fPage_file_category_name.select();
		}
		else
		{
			eleInput.form.fPage_file_category_name.disabled=true;
			eleInput.form.fPage_file_category_id.disabled=false;
		}
	},
	
	//gallery module methods
	
	onGalleryActiveClick:function(eleInput)
	{
		if(eleInput.checked)
		{
			if(document.getElementById("galleryModule"))
				document.getElementById("galleryModule").style.display="block";
			
			if(!eleInput.form.fFile_active.checked)
			{
				alert("The file module is required by the gallery module and will also be activated.");
				eleInput.form.fFile_active.checked=true;
				this.onFileActiveClick(eleInput.form.fFile_active);
			}
		}
		else
		{
			if(document.getElementById("galleryModule"))
				document.getElementById("galleryModule").style.display="none";
		}
	},

	onGalleryFileCategoryCreateNewClick:function(eleInput)
	{
		if(eleInput.checked)
		{
			eleInput.form.fGallery_file_category_name.disabled=false;
			eleInput.form.fGallery_file_category_id.disabled=true;
			eleInput.form.fGallery_file_category_name.focus();
			eleInput.form.fGallery_file_category_name.select();
		}
		else
		{
			eleInput.form.fGallery_file_category_name.disabled=true;
			eleInput.form.fGallery_file_category_id.disabled=false;
		}
	},
	
	//contest module methods
	
	onContestActiveClick:function(eleInput)
	{
		if(eleInput.checked)
		{
			if(document.getElementById("contestModule"))
				document.getElementById("contestModule").style.display="block";
		}
		else
		{
			if(document.getElementById("contestModule"))
				document.getElementById("contestModule").style.display="none";
		}
	},
	
	//shopping module methods
	
	onShoppingActiveClick:function(eleInput)
	{
		if(eleInput.checked)
		{
			if(document.getElementById("shoppingModule"))
				document.getElementById("shoppingModule").style.display="block";
		}
		else
		{
			if(document.getElementById("shoppingModule"))
				document.getElementById("shoppingModule").style.display="none";
		}
	}
}/*--------------------------------------------------
	Project:	The November Group - CMS Administration
	Script:		cms_client_importer.js
	Includes:	CMS_Client_Importer
--------------------------------------------------*/

var CMS_Client_Importer={
	
	open:function(intClientId)
	{
		function bpInitialized(intClientId)
		{
			//remove and store the import screen
			if(document.getElementById("clientImport"))
			{
				this.eleImportClient=document.getElementById("clientImport").parentNode.removeChild(document.getElementById("clientImport"));
				this.eleImportClient.style.display="block";
			}
			
			CMS_Main.addOverlay(this.eleImportClient);

			if(document.getElementById("importContainer"))
				document.getElementById("importContainer").innerHTML="<a href=\"#\" onclick=\"return CMS_Client_Importer.importCompare("+intClientId+");\">Select file</a>";
		}
		
		BrowserPlus.init(function(res)
		{
			if(!res.success)
			{
				if(res.error == "bp.notInstalled")
				{
					if(document.getElementById("importContainer"))
						document.getElementById("importContainer").innerHTML="<a href=\"http://browserplus.yahoo.com/install\">Install Yahoo! BrowserPlus (required)</a>";
					BrowserPlus.initWhenAvailable({},bpInitialized(intClientId));
				}
				else if(res.error == "bp.unsupportedClient")
					if(document.getElementById("importContainer"))
						document.getElementById("importContainer").innerHTML="Yahoo! BrowserPlus (required) cannot be installed on your system.";
				else
					if(document.getElementById("importContainer"))
						document.getElementById("importContainer").innerHTML="Failed to initialize BrowserPlus: " + res.verboseError;
			}
			else 
			{
				BrowserPlus.require({
					services: [{
						service: 'Uploader',
						version: "3",
						minversion: "3.1.5"
					},{
						service: 'FileBrowse'
					}]
				}, function(res)
				{
					if (res.success) 
						bpInitialized(intClientId);
					else 
						alert("Error Loading BrowserPlus services: " + res.error);
				});
			}
		});
		
		return false; //cancel link
	},
	
	close:function()
	{
		CMS_Main.removeOverlay();
	},
	
	importCompare:function(intClientId)
	{
		BrowserPlus.FileBrowse.OpenBrowseDialog({"limit":1,"mimeTypes":["text/xml"]},function(objFileList){
			
			//get array of selected files from FileBrowse service
			arrFiles=objFileList.value;
			
			if(arrFiles.length>=1)
			{
				i=0;
				objFiles={};
				
				//get the first file only
				objFiles["fFile"]=arrFiles[i];
				
				BrowserPlus.Uploader.upload({
					"url":"get_element_xml.php",
					"files":objFiles,
					"postvars":{"function":"CMS_Main::importCompare","arguments[]":intClientId.toString(),"sessionId":CMS_Cookie.get(CMS_Main.getSessionName())},
					"progressCallback":CMS_Client_Importer.updateProgress
				},function(objResponse){
					if(objResponse.value.statusCode==200)
						document.getElementById("importContainer").innerHTML=objResponse.value.body;
					else
						document.getElementById("importContainer").innerHTML="Error uploading file: "+objResponse.value.statusString;
				});
				
				if(document.getElementById("importContainer"))
				{
					CMS_Client_Importer.progressBar=new TNGProgressBar({});
					document.getElementById("importContainer").innerHTML=""; //clear import container
					document.getElementById("importContainer").appendChild(CMS_Client_Importer.progressBar.getProgressBar());
				}
			}
		});
		
		return false;
	},
	
	updateProgress:function(objResponse)
	{
		CMS_Client_Importer.progressBar.setPercent(objResponse.totalPercent);
	},
	
	importData:function(intClientId,frm)
	{
		var objRequest=CMS_Main.createRequest();
		objRequest.open("POST","get_element_xml.php",true);
		objRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		objRequest.onreadystatechange=function()
		{
			if(objRequest.readyState==4 && objRequest.status==200)
			{
				if(document.getElementById("importContainer"))
					document.getElementById("importContainer").innerHTML=objRequest.responseText;
			}
		};
		objRequest.send(CMS_Main.formEncode(document.getElementById("frmClientImport"))+"&function=CMS_Main::import&arguments[]="+intClientId.toString());
		
		return false; //cancel link
	}
}/*--------------------------------------------------
	Project:	The November Group - CMS Administration
	Script:		cms_file.js
	Includes:	CMS_Client_User_Settings
--------------------------------------------------*/

var CMS_Client_User_Settings={
	
	blnFilePublish:null,
	blnCalendarItemsPublish:null,
	blnDynamicEntriesPublish:null,
	blnPageContentsPublish:null,
	blnGalleriesPublish:null,
	
	intShowCountFiles:100,
	intShowCountFileCategories:100,
	intShowCountCalendarItems:100,
	intShowCountForms:100,
	intShowCountDynamicEntries:100,
	intShowCountDynamicCodes:100,
	intShowCountUsers:100,
	intShowCountPages:100,
	intShowCountGalleries:100,
	intShowCountGalleryImages:100,
	intShowCountContestEntries:100,
	
	canPublishFiles:function()
	{
		return this.blnFilePublish;
	},
	canPublishCalendarItems:function()
	{
		return this.blnCalendarItemsPublish;
	},
	canPublishDynamicEntries:function()
	{
		return this.blnDynamicEntriesPublish;
	},
	canPublishPageContents:function()
	{
		return this.blnPageContentsPublish;
	},
	canPublishGalleries:function()
	{
		return this.blnGalleriesPublish;
	},
	
	setFilePublish:function(blnFilePublish)
	{
		this.blnFilePublish=blnFilePublish;
	},
	setCalendarItemsPublish:function(blnCalendarItemsPublish)
	{
		this.blnCalendarItemsPublish=blnCalendarItemsPublish;
	},
	setDynamicEntriesPublish:function(blnDynamicEntriesPublish)
	{
		this.blnDynamicEntriesPublish=blnDynamicEntriesPublish;
	},
	setPageContentsPublish:function(blnPageContentsPublish)
	{
		this.blnPageContentsPublish=blnPageContentsPublish;
	},
	setGalleriesPublish:function(blnGalleriesPublish)
	{
		this.blnGalleriesPublish=blnGalleriesPublish;
	},
	
	setShowCountFiles:function(intShowCount)
	{
		this.intShowCountFiles=intShowCount;

		var objShowCountRequest=CMS_Main.createRequest();
		objShowCountRequest.open("GET","get_element_xml.php?function=setShowCountFiles&fShow_count="+intShowCount,true);
		objShowCountRequest.onreadystatechange=function(){
			//do nothing
		};
		objShowCountRequest.send(null);
	},
	setShowCountFileCategories:function(intShowCount)
	{
		this.intShowCountFileCategories=intShowCount;

		var objShowCountRequest=CMS_Main.createRequest();
		objShowCountRequest.open("GET","get_element_xml.php?function=setShowCountFileCategories&fShow_count="+intShowCount,true);
		objShowCountRequest.onreadystatechange=function(){
			//do nothing
		};
		objShowCountRequest.send(null);
	},
	setShowCountCalendarItems:function(intShowCount)
	{
		this.intShowCountCalendarItems=intShowCount;

		var objShowCountRequest=CMS_Main.createRequest();
		objShowCountRequest.open("GET","get_element_xml.php?function=setShowCountCalendarItems&fShow_count="+intShowCount,true);
		objShowCountRequest.onreadystatechange=function(){
			//do nothing
		};
		objShowCountRequest.send(null);
	},
	setShowCountForms:function(intShowCount)
	{
		this.intShowCountForms=intShowCount;

		var objShowCountRequest=CMS_Main.createRequest();
		objShowCountRequest.open("GET","get_element_xml.php?function=setShowCountForms&fShow_count="+intShowCount,true);
		objShowCountRequest.onreadystatechange=function(){
			//do nothing
		};
		objShowCountRequest.send(null);
	},
	setShowCountDynamicEntries:function(intShowCount)
	{
		this.intShowCountDynamicEntries=intShowCount;

		var objShowCountRequest=CMS_Main.createRequest();
		objShowCountRequest.open("GET","get_element_xml.php?function=setShowCountDynamicEntries&fShow_count="+intShowCount,true);
		objShowCountRequest.onreadystatechange=function(){
			//do nothing
		};
		objShowCountRequest.send(null);
	},
	setShowCountDynamicCodes:function(intShowCount)
	{
		this.intShowCountDynamicCodes=intShowCount;

		var objShowCountRequest=CMS_Main.createRequest();
		objShowCountRequest.open("GET","get_element_xml.php?function=setShowCountDynamicCodes&fShow_count="+intShowCount,true);
		objShowCountRequest.onreadystatechange=function(){
			//do nothing
		};
		objShowCountRequest.send(null);
	},
	setShowCountUsers:function(intShowCount)
	{
		this.intShowCountUsers=intShowCount;

		var objShowCountRequest=CMS_Main.createRequest();
		objShowCountRequest.open("GET","get_element_xml.php?function=setShowCountUsers&fShow_count="+intShowCount,true);
		objShowCountRequest.onreadystatechange=function(){
			//do nothing
		};
		objShowCountRequest.send(null);
	},
	setShowCountPages:function(intShowCount)
	{
		this.intShowCountPages=intShowCount;

		var objShowCountRequest=CMS_Main.createRequest();
		objShowCountRequest.open("GET","get_element_xml.php?function=setShowCountPages&fShow_count="+intShowCount,true);
		objShowCountRequest.onreadystatechange=function(){
			//do nothing
		};
		objShowCountRequest.send(null);
	},
	setShowCountGalleries:function(intShowCount)
	{
		this.intShowCountGalleries=intShowCount;

		var objShowCountRequest=CMS_Main.createRequest();
		objShowCountRequest.open("GET","get_element_xml.php?function=setShowCountGalleries&fShow_count="+intShowCount,true);
		objShowCountRequest.onreadystatechange=function(){
			//do nothing
		};
		objShowCountRequest.send(null);
	},
	setShowCountGalleryImages:function(intShowCount)
	{
		this.intShowCountGalleryImages=intShowCount;

		var objShowCountRequest=CMS_Main.createRequest();
		objShowCountRequest.open("GET","get_element_xml.php?function=setShowCountGalleryImages&fShow_count="+intShowCount,true);
		objShowCountRequest.onreadystatechange=function(){
			//do nothing
		};
		objShowCountRequest.send(null);
	},
	setShowCountContestEntries:function(intShowCount)
	{
		this.intShowCountContestEntries=intShowCount;

		var objShowCountRequest=CMS_Main.createRequest();
		objShowCountRequest.open("GET","get_element_xml.php?function=setShowCountContestEntries&fShow_count="+intShowCount,true);
		objShowCountRequest.onreadystatechange=function(){
			//do nothing
		};
		objShowCountRequest.send(null);
	},
	
	getShowCountFiles:function()
	{
		return this.intShowCountFiles;
	},
	getShowCountFileCategories:function()
	{
		return this.intShowCountFileCategories;
	},
	getShowCountCalendarItems:function()
	{
		return this.intShowCountCalendarItems;
	},
	getShowCountForms:function()
	{
		return this.intShowCountForms;
	},
	getShowCountDynamicEntries:function()
	{
		return this.intShowCountDynamicEntries;
	},
	getShowCountDynamicCodes:function()
	{
		return this.intShowCountDynamicCodes;
	},
	getShowCountUsers:function()
	{
		return this.intShowCountUsers;
	},
	getShowCountPages:function()
	{
		return this.intShowCountPages;
	},
	getShowCountGalleries:function()
	{
		return this.intShowCountGalleries;
	},
	getShowCountGalleryImages:function()
	{
		return this.intShowCountGalleryImages;
	},
	getShowCountContestEntries:function()
	{
		return this.intShowCountContestEntries;
	},

	initialize:function(frm)
	{
		if(frm.fFile_access)
			this.onFileAccessClick(frm.fFile_access);
		if(frm.fFile_category_access_all)
			this.onFileCategoryAccessAllClick(frm.fFile_category_access_all);
		if(frm.fCalendar_access)
			this.onCalendarAccessClick(frm.fCalendar_access);
		if(frm.fCalendar_category_access_all)
			this.onCalendarCategoryAccessAllClick(frm.fCalendar_category_access_all);
		if(frm.fForm_access)
			this.onFormAccessClick(frm.fForm_access);
		if(frm.fDynamic_access)
			this.onDynamicAccessClick(frm.fDynamic_access);
		if(frm.fDynamic_form_access_all)
			this.onDynamicFormAccessAllClick(frm.fDynamic_form_access_all);
		if(frm.fDynamic_form_id)
		{
			if(frm.fDynamic_form_id.length)
				for(var i=0;i<frm.fDynamic_form_id.length;i++)
				{
					this.onDynamicFormAccessClick(document.getElementById("fDynamic_form_access"+frm.fDynamic_form_id[i].value.toString()));
					if(document.getElementById("fDynamic_entry_access_all"+frm.fDynamic_form_id[i].value.toString()))
						this.onDynamicEntryAccessAllClick(document.getElementById("fDynamic_entry_access_all"+frm.fDynamic_form_id[i].value.toString()));
				}
			else
			{
				this.onDynamicFormAccessClick(document.getElementById("fDynamic_form_access"+frm.fDynamic_form_id.value.toString()));
				if(document.getElementById("fDynamic_entry_access_all"+frm.fDynamic_form_id.value.toString()))
					this.onDynamicEntryAccessAllClick(document.getElementById("fDynamic_entry_access_all"+frm.fDynamic_form_id.value.toString()));
			}
		}		
		if(frm.fSite_user_access)
			this.onSiteUserAccessClick(frm.fSite_user_access);
		if(frm.fSite_user_category_access_all)
			this.onSiteUserCategoryAccessAllClick(frm.fSite_user_category_access_all);
		if(frm.fPage_access)
			this.onPageAccessClick(frm.fPage_access);
		if(frm.fPage_form_access_all)
			this.onPageFormAccessAllClick(frm.fPage_form_access_all);
		if(frm.fGallery_access)
			this.onGalleryAccessClick(frm.fGallery_access);
		if(frm.fGallery_category_access_all)
			this.onGalleryCategoryAccessAllClick(frm.fGallery_category_access_all);
		if(frm.fContest_access)
			this.onContestAccessClick(frm.fContest_access);
	},
	
	onFileAccessClick:function(eleInput)
	{
		if(eleInput.checked)
		{
			document.getElementById("fileModule").style.display="block";
		}
		else
		{
			document.getElementById("fileModule").style.display="none";
		}
	},
	
	//enable or disable file category checkboxes when "All categories" is clicked
	onFileCategoryAccessAllClick:function(eleInput)
	{
		var frm=eleInput.form;
		
		if(frm.fFile_category_id)
		{
			if(frm.fFile_category_id.length)
			{
				for(var i=0;i<frm.fFile_category_id.length;i++)
				{
					document.getElementById("fFile_category_access"+frm.fFile_category_id[i].value.toString()).disabled=eleInput.checked;
				}
			}
			else
			{
				document.getElementById("fFile_category_access"+frm.fFile_category_id.value.toString()).disabled=eleInput.checked;
			}
		}
	},
	
	onCalendarAccessClick:function(eleInput)
	{
		if(eleInput.checked)
		{
			document.getElementById("calendarModule").style.display="block";
		}
		else
		{
			document.getElementById("calendarModule").style.display="none";
		}
	},
	
	//enable or disable calendar category checkboxes when "All categories" is clicked
	onCalendarCategoryAccessAllClick:function(eleInput)
	{
		var frm=eleInput.form;
		
		if(frm.fCalendar_category_id)
		{
			if(frm.fCalendar_category_id.length)
			{
				for(var i=0;i<frm.fCalendar_category_id.length;i++)
				{
					document.getElementById("fCalendar_category_access"+frm.fCalendar_category_id[i].value.toString()).disabled=eleInput.checked;
				}
			}
			else
			{
				document.getElementById("fCalendar_category_access"+frm.fCalendar_category_id.value.toString()).disabled=eleInput.checked;
			}
		}
	},
	
	onFormAccessClick:function(eleInput)
	{
		if(eleInput.checked)
		{
			document.getElementById("formModule").style.display="block";
		}
		else
		{
			document.getElementById("formModule").style.display="none";
		}
	},
	
	onDynamicAccessClick:function(eleInput)
	{
		if(eleInput.checked)
		{
			document.getElementById("dynamicModule").style.display="block";
		}
		else
		{
			document.getElementById("dynamicModule").style.display="none";
		}
	},
	
	//enable or disable dynamic form checkboxes and dynamic entry checkboxes when "All forms" is clicked
	onDynamicFormAccessAllClick:function(eleInput)
	{
		var frm=eleInput.form;
		
		if(frm.fDynamic_form_id)
		{
			if(frm.fDynamic_form_id.length)
			{
				for(var i=0;i<frm.fDynamic_form_id.length;i++)
				{
					document.getElementById("fDynamic_form_access"+frm.fDynamic_form_id[i].value.toString()).disabled=eleInput.checked;
					
					if(document.getElementById("fDynamic_entry_access_all"+frm.fDynamic_form_id[i].value.toString()))
					{
						var eleEntriesAll=document.getElementById("fDynamic_entry_access_all"+frm.fDynamic_form_id[i].value.toString());
						
						eleEntriesAll.disabled=eleInput.checked;
	
						if(frm.elements["fDynamic_entry_access"+frm.fDynamic_form_id[i].value.toString()])
						{
							if(frm.elements["fDynamic_entry_access"+frm.fDynamic_form_id[i].value.toString()].length) //check if there is more than one
							{
								for(var j=0;j<frm.elements["fDynamic_entry_access"+frm.fDynamic_form_id[i].value.toString()].length;j++)
									if(frm.elements["fDynamic_entry_access"+frm.fDynamic_form_id[i].value.toString()][j].name=="fDynamic_entry_access"+frm.fDynamic_form_id[i].value.toString())
										frm.elements["fDynamic_entry_access"+frm.fDynamic_form_id[i].value.toString()][j].disabled=(eleInput.checked || eleEntriesAll.checked);
							}
							else
								if(frm.elements["fDynamic_entry_access"+frm.fDynamic_form_id[i].value.toString()].name=="fDynamic_entry_access"+frm.fDynamic_form_id[i].value.toString())
									frm.elements["fDynamic_entry_access"+frm.fDynamic_form_id[i].value.toString()].disabled=(eleInput.checked || eleEntriesAll.checked);
						}
					}
				}
			}
			else
			{
				document.getElementById("fDynamic_form_access"+frm.fDynamic_form_id.value.toString()).disabled=eleInput.checked;
				this.onDynamicFormAccessClick(document.getElementById("fDynamic_form_access"+frm.fDynamic_form_id.value.toString()));
			}
		}
	},
	
	//show or hide dynamic entry checkboxes when form access is clicked
	onDynamicFormAccessClick:function(eleInput)
	{
		if(eleInput)
		{
			var strFormId=eleInput.id.replace("fDynamic_form_access","");
			if(document.getElementById("entryAccess"+strFormId))
			{
				var eleOptions=document.getElementById("entryAccess"+strFormId);
				
				if(eleInput.checked)
					eleOptions.style.display="block";
				else
					eleOptions.style.display="none";
			}
		}
	},
	
	//enable or disable dynamic entry checkboxes when "All entries" is clicked
	onDynamicEntryAccessAllClick:function(eleInput)
	{
		if(eleInput && document.getElementById("fDynamic_form_access_all"))
		{
			var strFormId=eleInput.id.replace("fDynamic_entry_access_all","");
			var eleFormsAll=document.getElementById("fDynamic_form_access_all");
			
			if(eleInput.form.elements["fDynamic_entry_access"+strFormId])
			{
				if(eleInput.form.elements["fDynamic_entry_access"+strFormId].length) //check if there is more than one
				{
					for(var i=0;i<eleInput.form.elements["fDynamic_entry_access"+strFormId].length;i++)
						if(eleInput.form.elements["fDynamic_entry_access"+strFormId][i].name=="fDynamic_entry_access"+strFormId) //exclude elements referenced by id
							eleInput.form.elements["fDynamic_entry_access"+strFormId][i].disabled=(eleInput.checked || eleFormsAll.checked);
				}
				else
					if(eleInput.form.elements["fDynamic_entry_access"+strFormId].name=="fDynamic_entry_access"+strFormId) //exclude elements referenced by id
						eleInput.form.elements["fDynamic_entry_access"+strFormId].disabled=(eleInput.checked || eleFormsAll.checked);
			}
		}
	},
	
	onSiteUserAccessClick:function(eleInput)
	{
		if(eleInput.checked)
		{
			document.getElementById("siteUserModule").style.display="block";
		}
		else
		{
			document.getElementById("siteUserModule").style.display="none";
		}
	},
	
	//enable or disable site user category checkboxes when "All categories" is clicked
	onSiteUserCategoryAccessAllClick:function(eleInput)
	{
		var frm=eleInput.form;
		
		if(frm.fSite_user_category_id)
		{
			if(frm.fSite_user_category_id.length)
			{
				for(var i=0;i<frm.fSite_user_category_id.length;i++)
				{
					document.getElementById("fSite_user_category_access"+frm.fSite_user_category_id[i].value.toString()).disabled=eleInput.checked;
				}
			}
			else
			{
				document.getElementById("fSite_user_category_access"+frm.fSite_user_category_id.value.toString()).disabled=eleInput.checked;
			}
		}
	},
	
	onPageAccessClick:function(eleInput)
	{
		if(eleInput.checked)
		{
			document.getElementById("pageModule").style.display="block";
		}
		else
		{
			document.getElementById("pageModule").style.display="none";
		}
	},
	
	//enable or disable page form checkboxes when "All forms" is clicked
	onPageFormAccessAllClick:function(eleInput)
	{
		var frm=eleInput.form;
		
		if(frm.fPage_form_id)
		{
			if(frm.fPage_form_id.length)
			{
				for(var i=0;i<frm.fPage_form_id.length;i++)
				{
					document.getElementById("fPage_form_access"+frm.fPage_form_id[i].value.toString()).disabled=eleInput.checked;
				}
			}
			else
			{
				document.getElementById("fPage_form_access"+frm.fPage_form_id.value.toString()).disabled=eleInput.checked;
			}
		}
	},
	
	onGalleryAccessClick:function(eleInput)
	{
		if(eleInput.checked)
		{
			document.getElementById("galleryModule").style.display="block";
		}
		else
		{
			document.getElementById("galleryModule").style.display="none";
		}
	},
	
	//enable or disable gallery checkboxes when "All galleries" is clicked
	onGalleryCategoryAccessAllClick:function(eleInput)
	{
		var frm=eleInput.form;
		
		if(frm.fGallery_category_id)
		{
			if(frm.fGallery_category_id.length)
			{
				for(var i=0;i<frm.fGallery_category_id.length;i++)
				{
					document.getElementById("fGallery_category_access"+frm.fGallery_category_id[i].value.toString()).disabled=eleInput.checked;
				}
			}
			else
			{
				document.getElementById("fGallery_category_access"+frm.fGallery_category_id.value.toString()).disabled=eleInput.checked;
			}
		}
	},
	
	onContestAccessClick:function(eleInput)
	{
		if(eleInput.checked)
		{
			document.getElementById("contestModule").style.display="block";
		}
		else
		{
			document.getElementById("contestModule").style.display="none";
		}
	},
	
	onShoppingAccessClick:function(eleInput)
	{
		if(eleInput.checked)
		{
			document.getElementById("shoppingModule").style.display="block";
		}
		else
		{
			document.getElementById("shoppingModule").style.display="none";
		}
	}
}/*--------------------------------------------------
	Project:	The November Group - CMS Administration
	Script:		cms_reseller.js
	Includes:	CMS_Reseller
--------------------------------------------------*/

var CMS_Reseller={
	
	blnDomainAvailable:null,
	
	manageResellers:function()
	{
		CMS_Main.setPage("manageResellers");
		
		CMS_Main.objRequest.open("GET","get_page_xml.php?page="+CMS_Main.getPage(),true);
		CMS_Main.objRequest.onreadystatechange=CMS_Main.updatePage;
		CMS_Main.objRequest.send(null);
		
		return false;
	},
	
	manageResellersInitialize:function(frm)
	{
		return false;
	},
	
	addReseller:function()
	{
		CMS_Main.objRequest.open("GET","get_page_xml.php?page=editReseller",true);
		CMS_Main.objRequest.onreadystatechange=CMS_Main.updatePage;
		CMS_Main.objRequest.send(null);
	},
	
	editReseller:function(intResellerId)
	{
		CMS_Main.objRequest.open("GET","get_page_xml.php?page=editReseller&fReseller_id="+intResellerId.toString(),true);
		CMS_Main.objRequest.onreadystatechange=CMS_Main.updatePage;
		CMS_Main.objRequest.send(null);
		
		return false;
	},
	
	editResellerFormInitialize:function(frm)
	{
		this.blnDomainAvailable=null;
		this.blnSubmit=false;
		
		if(frm)
		{
			frm.fName.focus();
			frm.fName.select();
			
			if(frm.fReseller_id.value>0)
				this.blnDomainAvailable==true;
		}
	},
	
	onDomainChange:function(intResellerId,strDomain)
	{
		this.blnDomainAvailable=null;

		if(strDomain.length==0)
		{
			//remove message
			if(document.getElementById("domainStatus"))
				document.getElementById("domainStatus").innerHTML="";
			
		}
		else
		{
			//loading message
			if(document.getElementById("domainStatus"))
				document.getElementById("domainStatus").innerHTML="Checking domain...";
			
			var objDomainRequest=CMS_Main.createRequest();
			objDomainRequest.open("GET","get_element_xml.php?function=resellerDomainAvailableXml&fReseller_id="+intResellerId.toString()+"&fDomain="+strDomain.toString(),true);
			objDomainRequest.onreadystatechange=function(){
				if(objDomainRequest.readyState==4 && objDomainRequest.status==200)
				{
					var eleDoc=objDomainRequest.responseXML.documentElement;
					
					if(eleDoc.getElementsByTagName("domainAvailable").length>0)
					{
						if(eleDoc.getElementsByTagName("domainAvailable")[0].firstChild && eleDoc.getElementsByTagName("domainAvailable")[0].firstChild.nodeValue=="1")
							CMS_Reseller.blnDomainAvailable=true;
						else
							CMS_Reseller.blnDomainAvailable=false;
						
						//update status message
						if(document.getElementById("domainStatus"))
							if(CMS_Reseller.blnDomainAvailable)
								document.getElementById("domainStatus").innerHTML="<span class=\"system positive\">Domain is available</span>";
							else
								document.getElementById("domainStatus").innerHTML="<span class=\"system negative\">Domain is already in use</span>";
						
						if(CMS_Reseller.blnSubmit)
						{
							CMS_Reseller.blnSubmit=false;
							CMS_Reseller.editResellerFormSubmit(document.getElementById("frmEditReseller"));
						}
					}
				}
			};
			objDomainRequest.send(null);
		}
		
		return true;
	},

	editResellerFormSubmit:function(frm)
	{
		//declare variables
		var blnReturnValue=true;
		
		if(frm.fDomain.value.length>0 && this.blnDomainAvailable==null) //domain exists but has not been checked
		{
			this.blnSubmit=true;
			blnReturnValue=false;
			
			//check domain
			this.onDomainChange(frm.fReseller_id.value,frm.fDomain.value);
		}
		else
		{
			if(frm.fName.value.length==0)
			{
				alert("Please enter a name");
				frm.fName.focus();
				blnReturnValue=false;
			}
			else if(frm.fDomain.value.length==0)
			{
				alert("Please enter a domain name");
				frm.fDomain.focus();
				blnReturnValue=false;
			}
			else if(!this.blnDomainAvailable)
			{
				alert("The domain you entered is already being used. Please enter a different domain.");
				frm.fDomain.focus();
				frm.fDomain.select();
				blnReturnValue=false;
			}
		}
		
		if(blnReturnValue)
		{
			document.getElementById("fSubmit").disabled=true;
			
			CMS_Main.objRequest.open("POST","get_page_xml.php",true);
			CMS_Main.objRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
			CMS_Main.objRequest.onreadystatechange=CMS_Main.updatePage;
			CMS_Main.objRequest.send(CMS_Main.formEncode(frm)+"&page="+CMS_Main.getPage());
		}
		
		return false;
	},
	
	editResellerFormCancel:function(frm)
	{
		CMS_Main.objRequest.open("GET","get_page_xml.php?page="+CMS_Main.getPage(),true);
		CMS_Main.objRequest.onreadystatechange=CMS_Main.updatePage;
		CMS_Main.objRequest.send(null);
		
		return false;
	},
	
	
	deleteReseller:function(intResellerId)
	{
		var strResellerName=document.getElementById("selectResellerName"+intResellerId.toString()).value.toString();
		
		if(confirm("Are you sure you want to delete "+strResellerName.toString()+"?"))
		{
			CMS_Main.objRequest.open("GET","get_page_xml.php?page="+CMS_Main.getPage()+"&fAction=deleteReseller&fReseller_id="+intResellerId.toString(),true);
			CMS_Main.objRequest.onreadystatechange=CMS_Main.updatePage;
			CMS_Main.objRequest.send(null);
		}
		
		return false;
	}
}/*--------------------------------------------------
	Project:	The November Group - CMS Administration
	Script:		cms_staging_area.js
	Includes:	CMS_Staging_Area
--------------------------------------------------*/

var CMS_Staging_Area={
	
	intFileTypeId:1,
	intCalendarTypeId:2,
	intDynamicTypeId:3,
	intPageTypeId:4,
	intGalleryTypeId:5,
	eleStagingAreaResponse:null,
	
	manageStagingArea:function()
	{
		CMS_Main.setPage("manageStagingArea");
		
		CMS_Main.objRequest.open("GET","get_page_xml.php?page="+CMS_Main.getPage(),true);
		CMS_Main.objRequest.onreadystatechange=CMS_Main.updatePage;
		CMS_Main.objRequest.send(null);
		
		return false;
	},
	
	manageStagingAreaInitialize:function()
	{
		//remove and store the file attachment form
		if(document.getElementById("stagingAreaResponse"))
		{
			this.eleStagingAreaResponse=document.getElementById("stagingAreaResponse").parentNode.removeChild(document.getElementById("stagingAreaResponse"));
			this.eleStagingAreaResponse.style.display="block";
		}
	},
	
	process:function(arrIds,arrNames,intType,intResponse)
	{
		//show dialogue
		CMS_Main.addOverlay(this.eleStagingAreaResponse);
		
		frm=document.getElementById("frmStagingAreaResponse");
		if(frm)
		{
			switch(Number(intResponse))
			{
				case(0):
					document.getElementById("responseTitle").innerHTML="Deny";
					break;
				case(1):
					document.getElementById("responseTitle").innerHTML="Approve";
					break;
				default:
					document.getElementById("responseTitle").innerHTML="Invalid response";
			}
			frm.fItem_type.value=intType;
			frm.fResponse_type.value=intResponse;
			frm.fComments.value="";
			
			//add names to form
			document.getElementById("itemNames").innerHTML=arrNames.join("<br />");
			
			//add hidden fields to form
			document.getElementById("itemIds").innerHTML=""; //remove existing
			for(var i in arrIds)
			{
				var eleInput=CMS_Main.createNamedElement("input","fItem_id");
				eleInput.type="hidden";
				eleInput.value=arrIds[i];
				document.getElementById("itemIds").appendChild(eleInput);
			}
		}
		
		return false;
	},
	
	confirmStagingAreaResponse:function(frm)
	{
		CMS_Main.removeOverlay();
		
		frm.fSubmit.disabled=true;
			
		CMS_Main.objRequest.open("POST","get_page_xml.php",true);
		CMS_Main.objRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		CMS_Main.objRequest.onreadystatechange=CMS_Main.updatePage;
		CMS_Main.objRequest.send(CMS_Main.formEncode(frm)+"&page="+CMS_Main.getPage());
		
		return false;
	},
	
	closeStagingAreaResponse:function(frm)
	{
		CMS_Main.removeOverlay();
		
		return false;
	},
	
	onActionClick:function(frm)
	{
		var arrIds=new Array();
		var arrNames=new Array();
		var strInputName="";

		if(frm)
		{
			switch(Number(frm.fItem_type.value))
			{
				case(this.intFileTypeId):
					strInputName="selectFile";
					break;
				case(this.intCalendarTypeId):
					strInputName="selectItem";
					break;
				case(this.intDynamicTypeId):
					strInputName="selectEntry";
					break;
				case(this.intPageTypeId):
					strInputName="selectContent";
					break;
				case(this.intGalleryTypeId):
					strInputName="selectGallery";
					break;
			}
			
			switch(Number(frm.fAction_index.value))
			{
				case(0): //deny
					for(var i=0;i<frm.length;i++)
					{
						if(frm.elements[i].name && frm.elements[i].name.indexOf(strInputName)==0 && frm.elements[i].type=="checkbox" && frm.elements[i].checked)
						{
							arrIds[arrIds.length]=frm.elements[i].value;
							arrNames[arrNames.length]=frm.elements[i+1].value;
						}
					}
					if(arrIds.length==0)
						alert("You do not have any items selected.");
					else
						this.process(arrIds,arrNames,Number(frm.fItem_type.value),0);
					break;
				case(1): //approve
					for(var i=0;i<frm.length;i++)
					{
						if(frm.elements[i].name && frm.elements[i].name.indexOf(strInputName)==0 && frm.elements[i].type=="checkbox" && frm.elements[i].checked)
						{
							arrIds[arrIds.length]=frm.elements[i].value;
							arrNames[arrNames.length]=frm.elements[i+1].value;
						}
					}
					if(arrIds.length==0)
						alert("You do not have any items selected.");
					else
						this.process(arrIds,arrNames,Number(frm.fItem_type.value),1);
					break;
			}
			
		}
		return false;
	}
}/*--------------------------------------------------
	Project:	The November Group - CMS Administration
	Script:		cms_file.js
	Includes:	CMS_File
--------------------------------------------------*/

var CMS_File={
	
	strUploaderInitialContent:"<p>The YUI File Uploader Control requires Flash Player 9.0.45 or higher.</p><p><a href=\"http://www.adobe.com/go/getflashplayer\">Get Adobe Flash Player</a></p>",
	objUploader:null,
	objFileList:null,
	arrUsedFileIds:new Array(),
	objFileListRequest:null,
	intCurrentCategoryId:-1,
	blnFilterModuleFiles:false,
	blnFilterNotSet:true,
	blnFilterPublished:true,
	blnFilterNotPublished:true,
	blnFilterArchived:true,
	blnFilterStaging:true,
	strFilterAlpha:"all",
	intCurrentOrderType:0,
	arrValidFileRequest:new Array(),
	intSizeUploadingTotal:0,
	intImageTypeId:6,
	
	//pagination attributes
	intPageNumber:1,
	
	getUploaderSWFURL:function()
	{
		return CMS_Main.getRootDirectory()+"/scripts/yui_2.6.0/build/uploader/assets/uploader.swf";
	},
	
	adminFiles:function()
	{
		CMS_Main.setPage("adminFiles"); //store page selection

		CMS_Main.objRequest.open("GET","get_page_xml.php?page="+CMS_Main.getPage(),true);
		CMS_Main.objRequest.onreadystatechange=CMS_Main.updatePage;
		CMS_Main.objRequest.send(null);
		
		return false;
	},
	
	//file uploader methods
	
	initializeUploader:function()
	{
		YAHOO.widget.Uploader.SWFURL=this.getUploaderSWFURL();

		//create uploader element
		if(!document.getElementById("eleUploader"))
		{
			var eleUploader=document.createElement("div");
			eleUploader.id="eleUploader";
			eleUploader.innerHTML=this.strUploaderInitialContent;
			document.getElementById("content_main").insertBefore(eleUploader,document.getElementById("content_main").firstChild);
			
			//hide uploader element
			eleUploader.style.width="0px";
			eleUploader.style.height="0px";
		}
	},
	
	preloadProgressImages:function()
	{
		//preload progress bar images
		img1=document.createElement("img");
		img1.src=CMS_Main.getRootDirectory()+"/css/tng/progressbar/box.gif";
		img2=document.createElement("img");
		img2.src=CMS_Main.getRootDirectory()+"/images/progressbar/bar.png";
	},
	
	onContentReady:function()
	{
		//set file uploader properties
		CMS_File.objUploader.setAllowMultipleFiles(true);
		CMS_File.objUploader.setFileFilters(CMS_Client.getAllowedFileTypes());
		CMS_File.objUploader.setSimUploadLimit(1); //set simultaneous upload limit
	},
	onFileSelect:function(event)
	{
		CMS_File.objFileList=event.fileList;
		
		//add files to table
		for(var i in event.fileList)
		{
			if(!CMS_File.isUsed(event.fileList[i].id))
			{
				CMS_File.setUsed(event.fileList[i].id);
				
				//remove "no records" row
				if(document.getElementById("noRecords"))
					document.getElementById("noRecords").parentNode.removeChild(document.getElementById("noRecords"));
				
				//add row to table
				document.getElementById("fileListContainer").insertBefore(CMS_File.createUploadRow(event.fileList[i]),document.getElementById("fileListContainer").firstChild);
	
				//check for valid file
				var j=CMS_File.arrValidFileRequest.length+1;
				CMS_File.arrValidFileRequest[j]=CMS_Main.createRequest();
				CMS_File.arrValidFileRequest[j].open("GET","get_element_xml.php?function=isValidFileXml&fFile_id=0&fileId="+encodeURIComponent(event.fileList[i].id)+"&fName="+encodeURIComponent(event.fileList[i].name)+"&fSize="+encodeURIComponent(event.fileList[i].size)+"&sizeUploadingTotal="+encodeURIComponent(CMS_File.intSizeUploadingTotal)+"&fTitle=",true);
				CMS_File.arrValidFileRequest[j].onreadystatechange=CMS_File.validFileResponse;
				CMS_File.arrValidFileRequest[j].send(null);
			}
		}
	},
	validFileResponse:function()
	{
		//loop through all open requests
		for(i in CMS_File.arrValidFileRequest)
		{
			if(CMS_File.arrValidFileRequest[i] && CMS_File.arrValidFileRequest[i].readyState==4)
			{
				if(CMS_File.arrValidFileRequest[i].status==200)
				{
					var eleDoc=CMS_File.arrValidFileRequest[i].responseXML.documentElement;
					
					if(eleDoc.getElementsByTagName("validFile"))
					{
						var strId=eleDoc.getElementsByTagName("fileId")[0].firstChild.nodeValue;
						
						//add to size uploading total
						CMS_File.intSizeUploadingTotal+=CMS_File.objFileList[strId].size;
						
						if(eleDoc.getElementsByTagName("validFile")[0].firstChild.nodeValue==1)
						{
							//upload
							CMS_File.objUploader.upload(strId, CMS_Main.getRootDirectory()+'/file_upload.php',"POST",{sessionId:CMS_Cookie.get(CMS_Main.getSessionName()), fCategory_id:CMS_File.intCurrentCategoryId},"fFile");
						}
						else
						{
							//cancel
							if(eleDoc.getElementsByTagName("message"))
								CMS_File.cancel(strId,eleDoc.getElementsByTagName("message")[0].firstChild.nodeValue,(eleDoc.getElementsByTagName("existingFileId") ? Number(eleDoc.getElementsByTagName("existingFileId")[0].firstChild.nodeValue) : 0));
						}
					}
					//remove from array
					CMS_File.arrValidFileRequest.splice(i,1);
				}
			}
		}
	},
	
	//mark file id as used
	setUsed:function(id)
	{
		//mark id as used
		this.arrUsedFileIds.push(id);
	},
	isUsed:function(id)
	{
		blnReturnValue=false;
		
		for(var i=0;i<this.arrUsedFileIds.length;i++)
		{
			if(this.arrUsedFileIds[i]==id)
			{
				blnReturnValue=true;
				break;
			}
		}
		
		return blnReturnValue;
	},
	clearUsed:function()
	{
		this.arrUsedFileIds=new Array();
	},
	
	cancel:function(id,strStatus,intExistingFileId)
	{
		//cancel upload
		this.objUploader.cancel(id);
		this.objUploader.removeFile(id);

		//remove from size uploading total
		CMS_File.intSizeUploadingTotal-=CMS_File.objFileList[id].size;

		if(!strStatus)
			strStatus="Upload cancelled.";
		
		//check if cancellation is due to existing file
		if(intExistingFileId && intExistingFileId>0)
			if(document.getElementById("frmManageFiles") && document.getElementById("frmManageFiles").fCategory_id && document.getElementById("frmManageFiles").fCategory_id.value>0) //check if user has selected a specific category
				strStatus+="<br /><a href=\"#\" onclick=\"return CMS_File.addExistingFileToCategory('"+id+"',"+intExistingFileId.toString()+");\">Add to category</a>"; //add option to status message
		
		document.getElementById("fileStatus"+id).innerHTML=strStatus;
		document.getElementById("fileAction"+id).innerHTML=" \
		<div class=\"actions\"> \
			<ul> \
				<li><a class=\"action4\" href=\"#\" onclick=\"return CMS_File.remove("+id+");\" title=\"Remove\">Remove</a></li> \
			</ul> \
		</div>";
		

		return false;
	},
	clearUploads:function()
	{
		try
		{
			this.objUploader.cancel();
			this.objUploader.clearFileList();
		}
		catch(e)
		{
		}
		
		this.clearUsed();
	},
	remove:function(id)
	{
		if(document.getElementById("fileRow"+id))
			document.getElementById("fileRow"+id).parentNode.removeChild(document.getElementById("fileRow"+id));
		
		return false;
	},
	
	onUploadStart:function(event)
	{
		//CMS_File.updateProgress(event.id,0);
		document.getElementById("fileStatus"+event.id).innerHTML="Waiting...";
	},
	onUploadProgress:function(event)
	{
		//check if progress bar exists
		if(!document.getElementById("progressBar"+event.id))
		{
			//create progress bar
			eleContainer=document.createElement("div");
			eleContainer.className="progressBar";
			eleContainer.id="progressBar"+event.id;
			
			eleImg=document.createElement("img");
			eleImg.src=CMS_Main.getRootDirectory()+"/css/tng/progressbar/box.gif";
			eleImg.id="progressBarImage"+event.id;
			eleImg.width="150";
			eleImg.height="12";
			eleImg.alt="";
			eleImg.title="";
			
			eleSpan=document.createElement("span");
			eleSpan.className="progressBarPercent";
			eleSpan.id="progressBarPercent"+event.id;
			eleSpan.appendChild(document.createTextNode("0%"));
			
			eleContainer.appendChild(eleImg);
			document.getElementById("fileStatus"+event.id).innerHTML="";
			document.getElementById("fileStatus"+event.id).appendChild(eleContainer);
			document.getElementById("fileStatus"+event.id).appendChild(document.createTextNode(" "));
			document.getElementById("fileStatus"+event.id).appendChild(eleSpan);
		}
		
		CMS_File.updateProgress(event.id,(event.bytesLoaded/event.bytesTotal)*100);
	},
	updateProgress:function(strId,dblPercent)
	{
		strHtml="";
		strPercent=Math.round(dblPercent).toString()+"%";
		intPosition=Math.round((100-dblPercent)/100*150) * -1;
		
		if(document.getElementById("progressBar"+strId))
		{
			document.getElementById("progressBar"+strId).style.backgroundPosition=intPosition+"px 0px";
			document.getElementById("progressBarPercent"+strId).replaceChild(document.createTextNode(strPercent),document.getElementById("progressBarPercent"+strId).firstChild);
		}
	},
	onUploadCancel:function(event)
	{
		//this event doesn't seem to fire
	},
	onUploadComplete:function(event)
	{
		CMS_File.updateProgress(event.id,100);

		//remove "cancel" link
		document.getElementById("fileAction"+event.id).innerHTML=" ";
	},
	onUploadCompleteData:function(event)
	{
		var objFileData=eval("("+event.data+")");
		
		if(!objFileData.blnSuccess)
		{
			CMS_File.cancel(event.id,objFileData.strMessages,objFileData.intExistingFileId);
		}
		else
		{
			//remove from size uploading total
			CMS_File.intSizeUploadingTotal-=CMS_File.objFileList[event.id].size;
			
			//replace row
			var eleRow=CMS_File.createRow(objFileData);
			eleRow.style.backgroundColor="#ffffff";
			eleRow.onmouseover=function()
			{
				this.style.backgroundColor="#ffffdd";
				this.style.color="#000000";
			}
			eleRow.onmouseout=function()
			{
				this.style.backgroundColor="#ffffff";
				this.style.color="";
			}
			document.getElementById("fileListContainer").replaceChild(eleRow,document.getElementById("fileRow"+event.id.toString()));
			
			//update pagination numbers
			if(document.getElementById("fFile_count"))
				document.getElementById("fFile_count").value=Number(document.getElementById("fFile_count").value)+1; //incrememt file count
			if(document.getElementById("fileCountEnd"))
				document.getElementById("fileCountEnd").innerHTML=(Number(document.getElementById("fileCountEnd").innerHTML)+1).toString(); //increment file end count
			if(document.getElementById("fileCount"))
				document.getElementById("fileCount").innerHTML=document.getElementById("fFile_count").value.toString(); //update file count
				
			//update pagination links
			CMS_File.updatePaginationLinks(document.getElementById("frmManageFiles"));
			
			CMS_File.initializeOrder(document.getElementById("frmManageFiles"));
		}
		
		return false;
	},
	onUploadError:function(event)
	{
		//CMS_File.cancel(event.id,event.status);
		CMS_File.cancel(event.id,"Error uploading file, please try again.");
	},
	
	onRollOver:function()
	{
	},
	onRollOut:function()
	{
	},
	onClick:function()
	{
	},
	
	//file manager methods
	
	objFileStatisticsRequest:null,
	eleFileStatistics:null,

	manageFiles:function()
	{
		CMS_Main.setPage("manageFiles"); //store page selection

		CMS_Main.objRequest.open("GET","get_page_xml.php?page="+CMS_Main.getPage(),true);
		CMS_Main.objRequest.onreadystatechange=CMS_Main.updatePage;
		CMS_Main.objRequest.send(null);
		
		return false;
	},
	
	initializeFileManager:function(frm)
	{
		var blnSelected=false;
		
		//instantiate uploader
		YAHOO.widget.Uploader.SWFURL=this.getUploaderSWFURL();
		document.getElementById("eleUploader").innerHTML=this.strUploaderInitialContent;
		this.objUploader=new YAHOO.widget.Uploader("eleUploader");
		
		//resize transparent overlay
		document.getElementById("eleUploader").style.width=document.getElementById("addFiles").offsetWidth.toString()+"px";
		document.getElementById("eleUploader").style.height=document.getElementById("addFiles").offsetHeight.toString()+"px";
		document.getElementById("eleUploader").style.zIndex=1;
		
		//set uploader event handlers
		this.objUploader.addListener("contentReady",this.onContentReady);
		this.objUploader.addListener("fileSelect",this.onFileSelect);
		this.objUploader.addListener("uploadStart",this.onUploadStart);
		this.objUploader.addListener("uploadProgress",this.onUploadProgress);
		this.objUploader.addListener("uploadCancel",this.onUploadCancel);
		this.objUploader.addListener("uploadComplete",this.onUploadComplete);
		this.objUploader.addListener("uploadCompleteData",this.onUploadCompleteData);
		this.objUploader.addListener("uploadError",this.onUploadError);
		//set more uploader event handlers
		this.objUploader.addListener("rollOver",this.onRollOver);
		this.objUploader.addListener("rollOut",this.onRollOut);
		this.objUploader.addListener("click",this.onClick);
		//reset file request variables
		this.arrValidFileRequest=new Array();
		this.intSizeUploadingTotal=0;
		
		this.preloadProgressImages();
		
		if(frm)
		{
			//remove and store the file statistics form
			if(document.getElementById("fileStatistics"))
			{
				this.eleFileStatistics=document.getElementById("fileStatistics").parentNode.removeChild(document.getElementById("fileStatistics"));
				this.eleFileStatistics.style.display="block";
			}
			
			//reselect previously selected category
			blnSelected=false;
			if(document.getElementById("fCategory_id") && document.getElementById("fCategory_id").length)
			{
				for(var i=0;i<document.getElementById("fCategory_id").options.length;i++)
				{
					if(document.getElementById("fCategory_id").options[i].value==this.intCurrentCategoryId)
					{
						document.getElementById("fCategory_id").options[i].selected=true;
						blnSelected=true;
						break;
					}
				}
				if(!blnSelected)
				{
					document.getElementById("fCategory_id").options[0].selected=true;
					this.intCurrentCategoryId=document.getElementById("fCategory_id").options[0].value;
				}
			}
			blnSelected=false;
			if(document.getElementById("fCategory_id_top") && document.getElementById("fCategory_id_top").length)
			{
				for(var i=0;i<document.getElementById("fCategory_id_top").options.length;i++)
				{
					if(document.getElementById("fCategory_id_top").options[i].value==this.intCurrentCategoryId)
					{
						document.getElementById("fCategory_id_top").options[i].selected=true;
						blnSelected=true;
						break;
					}
				}
				if(!blnSelected)
				{
					document.getElementById("fCategory_id_top").options[0].selected=true;
					this.intCurrentCategoryId=document.getElementById("fCategory_id_top").options[0].value;
				}
			}
			
			//reselect previously selected filters
			if(document.getElementById("fFilter_module_files")) document.getElementById("fFilter_module_files").checked=this.blnFilterModuleFiles;
			if(document.getElementById("fFilter_module_files_top")) document.getElementById("fFilter_module_files_top").checked=this.blnFilterModuleFiles;
			if(document.getElementById("fFilter_not_set")) document.getElementById("fFilter_not_set").checked=this.blnFilterNotSet;
			if(document.getElementById("fFilter_not_set_top")) document.getElementById("fFilter_not_set_top").checked=this.blnFilterNotSet;
			if(document.getElementById("fFilter_published")) document.getElementById("fFilter_published").checked=this.blnFilterPublished;
			if(document.getElementById("fFilter_published_top")) document.getElementById("fFilter_published_top").checked=this.blnFilterPublished;
			if(document.getElementById("fFilter_not_published")) document.getElementById("fFilter_not_published").checked=this.blnFilterNotPublished;
			if(document.getElementById("fFilter_not_published_top")) document.getElementById("fFilter_not_published_top").checked=this.blnFilterNotPublished;
			if(document.getElementById("fFilter_archived")) document.getElementById("fFilter_archived").checked=this.blnFilterArchived;
			if(document.getElementById("fFilter_archived_top")) document.getElementById("fFilter_archived_top").checked=this.blnFilterArchived;
			if(document.getElementById("fFilter_staging")) document.getElementById("fFilter_staging").checked=this.blnFilterStaging;
			if(document.getElementById("fFilter_staging_top")) document.getElementById("fFilter_staging_top").checked=this.blnFilterStaging;

			frm.fFilter_alpha.value=this.strFilterAlpha;
			
			//alpha
			if(document.getElementById("filterAlpha"))
			{
				var arrLinks=document.getElementById("filterAlpha").getElementsByTagName("a");
				for(var i=0;i<arrLinks.length;i++)
				{
					if(arrLinks[i].firstChild.firstChild.firstChild.nodeValue.toLowerCase()==frm.fFilter_alpha.value.toString())
					{
						arrLinks[i].className+=" current_page";
						break;
					}
				}
			}
			if(document.getElementById("filterAlphaTop"))
			{
				var arrLinks=document.getElementById("filterAlphaTop").getElementsByTagName("a");
				for(var i=0;i<arrLinks.length;i++)
				{
					if(arrLinks[i].firstChild.firstChild.firstChild.nodeValue.toLowerCase()==frm.fFilter_alpha.value.toString())
					{
						arrLinks[i].className+=" current_page";
						break;
					}
				}
			}
			
			//reselect previously selected show count
			blnSelected=false;
			if(document.getElementById("fShow_count"))
			{
				var eleSelect2=document.getElementById("fShow_count");
				for(var i=0;i<eleSelect2.options.length;i++)
				{
					if(Number(eleSelect2.options[i].value)==CMS_Client_User_Settings.getShowCountFiles())
					{
						eleSelect2.options[i].selected=true;
						blnSelected=true;
						break;
					}
				}
				if(!blnSelected)
				{
					eleSelect2.options[0].selected=true;
					CMS_Client_User_Settings.setShowCountFiles(Number(eleSelect2.options[0].value));
				}
			}
			blnSelected=false;
			if(document.getElementById("fShow_count_top"))
			{
				var eleSelect2=document.getElementById("fShow_count_top");
				for(var i=0;i<eleSelect2.options.length;i++)
				{
					if(Number(eleSelect2.options[i].value)==CMS_Client_User_Settings.getShowCountFiles())
					{
						eleSelect2.options[i].selected=true;
						blnSelected=true;
						break;
					}
				}
				if(!blnSelected)
				{
					eleSelect2.options[0].selected=true;
					CMS_Client_User_Settings.setShowCountFiles(Number(eleSelect2.options[0].value));
				}
			}
			
			//retrieve previously selected page number
			if(frm.fPage_number)
				frm.fPage_number.value=this.intPageNumber.toString();
			
			//enable or disable "publish files" option
			if(document.getElementById("fAction_index"))
			{
				var eleSelect2=document.getElementById("fAction_index");
				for(var i=0;i<eleSelect2.length;i++)
				{
					if(eleSelect2.options[i].value==2)
					{
						if(CMS_Client_User_Settings.canPublishFiles())
						{
							eleSelect2.options[i].disabled=false;
						}
						else
						{
							if(eleSelect2.options[i].selected)
								eleSelect2.options[0].selected=true;
								
							//disable option
							eleSelect2.options[i].disabled=true;
						}
						break;
					}
				}
			}
			if(document.getElementById("fAction_index_top"))
			{
				var eleSelect2=document.getElementById("fAction_index_top");
				for(var i=0;i<eleSelect2.length;i++)
				{
					if(eleSelect2.options[i].value==2)
					{
						if(CMS_Client_User_Settings.canPublishFiles())
						{
							eleSelect2.options[i].disabled=false;
						}
						else
						{
							if(eleSelect2.options[i].selected)
								eleSelect2.options[0].selected=true;
								
							//disable option
							eleSelect2.options[i].disabled=true;
						}
						break;
					}
				}
			}

			this.onCategoryChange(frm,document.getElementById("fCategory_id"));
		}
	},
	
	onCategoryOrFilterChange:function(frm)
	{
		this.clearUploads();
		
		CMS_File.getFileList(frm);
	},

	onCategoryChange:function(frm,eleSelect)
	{
		this.intCurrentCategoryId=eleSelect.options[eleSelect.selectedIndex].value;
		
		if(document.getElementById("fCategory_id"))
		{
			var eleSelect2=document.getElementById("fCategory_id");
			for(var i=0;i<eleSelect2.options.length;i++)
			{
				if(eleSelect2.options[i].value==this.intCurrentCategoryId)
					eleSelect2.options[i].selected=true;
				else
					eleSelect2.options[i].selected=false;
			}
		}
		if(document.getElementById("fCategory_id_top"))
		{
			var eleSelect2=document.getElementById("fCategory_id_top");
			for(var i=0;i<eleSelect2.options.length;i++)
			{
				if(eleSelect2.options[i].value==this.intCurrentCategoryId)
					eleSelect2.options[i].selected=true;
				else
					eleSelect2.options[i].selected=false;
			}
		}

		if(document.getElementById("fAction_index"))
		{
			var eleSelect2=document.getElementById("fAction_index");
			for(var i=0;i<eleSelect2.length;i++)
			{
				if(eleSelect2.options[i].value==5)
				{
					if(this.intCurrentCategoryId>0)
					{
						eleSelect2.options[i].disabled=false;
					}
					else
					{
						if(eleSelect2.options[i].selected)
							eleSelect2.options[0].selected=true;
							
						//disable option
						eleSelect2.options[i].disabled=true;
					}
					break;
				}
			}
		}
		if(document.getElementById("fAction_index_top"))
		{
			var eleSelect2=document.getElementById("fAction_index_top");
			for(var i=0;i<eleSelect2.length;i++)
			{
				if(eleSelect2.options[i].value==5)
				{
					if(this.intCurrentCategoryId>0)
					{
						eleSelect2.options[i].disabled=false;
					}
					else
					{
						if(eleSelect2.options[i].selected)
							eleSelect2.options[0].selected=true;
							
						//disable option
						eleSelect2.options[i].disabled=true;
					}
					break;
				}
			}
		}
		
		this.onCategoryOrFilterChange(frm);
	},
	
	onFilterModuleFilesClick:function(frm,eleInput)
	{
		this.blnFilterModuleFiles=eleInput.checked;

		if(document.getElementById("fFilter_module_files"))
			document.getElementById("fFilter_module_files").checked=eleInput.checked;
		if(document.getElementById("fFilter_module_files_top"))
			document.getElementById("fFilter_module_files_top").checked=eleInput.checked;
		
		this.onCategoryOrFilterChange(frm);
	},
	
	onFilterNotSetClick:function(frm,eleInput)
	{
		this.blnFilterNotSet=eleInput.checked;

		if(document.getElementById("fFilter_not_set"))
			document.getElementById("fFilter_not_set").checked=eleInput.checked;
		if(document.getElementById("fFilter_not_set_top"))
			document.getElementById("fFilter_not_set_top").checked=eleInput.checked;
		
		this.onCategoryOrFilterChange(frm);
	},
	
	onFilterPublishedClick:function(frm,eleInput)
	{
		this.blnFilterPublished=eleInput.checked;

		if(document.getElementById("fFilter_published"))
			document.getElementById("fFilter_published").checked=eleInput.checked;
		if(document.getElementById("fFilter_published_top"))
			document.getElementById("fFilter_published_top").checked=eleInput.checked;
		
		this.onCategoryOrFilterChange(frm);
	},
	
	onFilterNotPublishedClick:function(frm,eleInput)
	{
		this.blnFilterNotPublished=eleInput.checked;

		if(document.getElementById("fFilter_not_published"))
			document.getElementById("fFilter_not_published").checked=eleInput.checked;
		if(document.getElementById("fFilter_not_published_top"))
			document.getElementById("fFilter_not_published_top").checked=eleInput.checked;
		
		this.onCategoryOrFilterChange(frm);
	},
	
	onFilterArchivedClick:function(frm,eleInput)
	{
		this.blnFilterArchived=eleInput.checked;

		if(document.getElementById("fFilter_archived"))
			document.getElementById("fFilter_archived").checked=eleInput.checked;
		if(document.getElementById("fFilter_archived_top"))
			document.getElementById("fFilter_archived_top").checked=eleInput.checked;
		
		this.onCategoryOrFilterChange(frm);
	},
	
	onFilterStagingClick:function(frm,eleInput)
	{
		this.blnFilterStaging=eleInput.checked;

		if(document.getElementById("fFilter_staging"))
			document.getElementById("fFilter_staging").checked=eleInput.checked;
		if(document.getElementById("fFilter_staging_top"))
			document.getElementById("fFilter_staging_top").checked=eleInput.checked;
		
		this.onCategoryOrFilterChange(frm);
	},
	
	onAlphaClick:function(frm,eleA)
	{
		if(frm && eleA)
		{
			frm.fFilter_alpha.value=eleA.firstChild.firstChild.firstChild.nodeValue.toLowerCase(); //retrieve selected value
			this.strFilterAlpha=frm.fFilter_alpha.value.toString();
			
			//reset classes
			if(document.getElementById("filterAlpha"))
			{
				var arrLinks=document.getElementById("filterAlpha").getElementsByTagName("a");
				for(var i=0;i<arrLinks.length;i++)
				{
					if(arrLinks[i].className.indexOf("current_page")>-1)
						arrLinks[i].className=arrLinks[i].className.replace("current_page","");
					if(arrLinks[i].firstChild.firstChild.firstChild.nodeValue.toLowerCase()==frm.fFilter_alpha.value)
						arrLinks[i].className+=" current_page";
				}
			}
			if(document.getElementById("filterAlphaTop"))
			{
				var arrLinks=document.getElementById("filterAlphaTop").getElementsByTagName("a");
				for(var i=0;i<arrLinks.length;i++)
				{
					if(arrLinks[i].className.indexOf("current_page")>-1)
						arrLinks[i].className=arrLinks[i].className.replace("current_page","");
					if(arrLinks[i].firstChild.firstChild.firstChild.nodeValue.toLowerCase()==frm.fFilter_alpha.value)
						arrLinks[i].className+=" current_page";
				}
			}
			
			//update filter
			CMS_File.onCategoryOrFilterChange(frm);
		}
		return false; //cancel link
	},
	
	onShowCountChange:function(frm,eleSelect)
	{
		if(frm)
		{
			var intPages=1;
			
			if(document.getElementById("fShow_count"))
			{
				var eleSelect2=document.getElementById("fShow_count");
				for(var i=0;i<eleSelect2.options.length;i++)
				{
					if(Number(eleSelect2.options[i].value)==Number(eleSelect.options[eleSelect.selectedIndex].value))
						eleSelect2.options[i].selected=true;
				}
			}
			if(document.getElementById("fShow_count_top"))
			{
				var eleSelect2=document.getElementById("fShow_count_top");
				for(var i=0;i<eleSelect2.options.length;i++)
				{
					if(Number(eleSelect2.options[i].value)==Number(eleSelect.options[eleSelect.selectedIndex].value))
						eleSelect2.options[i].selected=true;
				}
			}
			
			CMS_Client_User_Settings.setShowCountFiles(Number(eleSelect.value)); //store selected value
			
			//calculate number of pages
			if(Number(eleSelect.value)>0)
				intPages=Math.ceil(Number(frm.fFile_count.value)/Number(eleSelect.value));
			if(intPages==0)
				intPages++;
			
			//check if current page number will exist for new show count
			if(Number(frm.fPage_number.value)>intPages)
				frm.fPage_number.value="1"; //reset page number
			
			this.getFileList(frm);
		}
	},
	
	onPageClick:function(frm,eleNumber)
	{
		if(frm && eleNumber)
		{
			frm.fPage_number.value=eleNumber.firstChild.firstChild.firstChild.nodeValue; //retrieve selected value
			this.getFileList(frm);
		}
		return false;
	},
	
	updatePaginationLinks:function(frm)
	{
		if(frm && frm.fShow_count && frm.fPage_number)
		{
			var intPages=1;
			
			//calculate number of pages
			if(Number(frm.fShow_count.value)>0)
				intPages=Math.ceil(Number(frm.fFile_count.value)/Number(frm.fShow_count.value));
			if(intPages==0)
				intPages++;
			
			//rebuild page links
			if(document.getElementById("filterPage"))
			{
				document.getElementById("filterPage").innerHTML="";
				for(var i=0;i<intPages;i++)
					document.getElementById("filterPage").innerHTML+="<li><a href=\"#\" onclick=\"return CMS_File.onPageClick(document.getElementById('frmManageFiles'),this);\"><span><span>"+(i+1).toString()+"</span></span></a></li>";
			}
			if(document.getElementById("filterPageTop"))
			{
				document.getElementById("filterPageTop").innerHTML="";
				for(var i=0;i<intPages;i++)
					document.getElementById("filterPageTop").innerHTML+="<li><a href=\"#\" onclick=\"return CMS_File.onPageClick(document.getElementById('frmManageFiles'),this);\"><span><span>"+(i+1).toString()+"</span></span></a></li>";
			}
			
			//select page link
			var blnSelected=false;
			if (document.getElementById("filterPage")) 
			{
				var arrLinks=document.getElementById("filterPage").getElementsByTagName("a");
				for(var i=0;i<arrLinks.length;i++)
				{
					if(arrLinks[i].firstChild.firstChild.firstChild.nodeValue==frm.fPage_number.value.toString())
					{
						//change class
						arrLinks[i].className+=" current_page";
						blnSelected=true;
						break;
					}
				}
				if(!blnSelected)
				{
					arrLinks[0].className+=" current_page";
					frm.fPage_number.value=arrLinks[0].firstChild.firstChild.firstChild.nodeValue;
				}
			}
			blnSelected=false;
			if (document.getElementById("filterPageTop")) 
			{
				var arrLinks=document.getElementById("filterPageTop").getElementsByTagName("a");
				for(var i=0;i<arrLinks.length;i++)
				{
					if(arrLinks[i].firstChild.firstChild.firstChild.nodeValue==frm.fPage_number.value.toString())
					{
						//change class
						arrLinks[i].className+=" current_page";
						blnSelected=true;
						break;
					}
				}
				if(!blnSelected)
				{
					arrLinks[0].className+=" current_page";
					frm.fPage_number.value=arrLinks[0].firstChild.firstChild.firstChild.nodeValue;
				}
			}

			//store selected value
			this.intPageNumber=Number(frm.fPage_number.value);
		}
	},
	
	updatePaginationNumbers:function(frm)
	{
		if(frm && frm.fShow_count && frm.fPage_number)
		{
			//calculate numbers
			var intCountStart=(Number(frm.fPage_number.value)-1)*Number(frm.fShow_count.value);
			var intCountEnd=(Number(frm.fShow_count.value)==0 ? Number(frm.fFile_count.value) : Math.min(Number(frm.fShow_count.value)+intCountStart,Number(frm.fFile_count.value)));
			
			//update numbers
			if(document.getElementById("fileCountStart"))
				document.getElementById("fileCountStart").innerHTML=(Math.min(intCountStart+1,Number(frm.fFile_count.value))).toString();
			if(document.getElementById("fileCountEnd"))
				document.getElementById("fileCountEnd").innerHTML=intCountEnd.toString();
			if(document.getElementById("fileCount"))
				document.getElementById("fileCount").innerHTML=frm.fFile_count.value.toString();

			if(document.getElementById("fileCountStartTop"))
				document.getElementById("fileCountStartTop").innerHTML=(Math.min(intCountStart+1,Number(frm.fFile_count.value))).toString();
			if(document.getElementById("fileCountEndTop"))
				document.getElementById("fileCountEndTop").innerHTML=intCountEnd.toString();
			if(document.getElementById("fileCountTop"))
				document.getElementById("fileCountTop").innerHTML=frm.fFile_count.value.toString();
		}
	},
	
	getFileList:function(frm)
	{
		var strHtml="";
		
		//clear select all
		if(document.getElementById("selectAll"))
			document.getElementById("selectAll").checked=false;
		
		//clear file list
		while(document.getElementById("fileListContainer").firstChild)
			document.getElementById("fileListContainer").removeChild(document.getElementById("fileListContainer").firstChild);
		
		//add loading message
		var eleLoading=document.createElement("tr");
		eleLoading.appendChild(document.createElement("td"));
		eleLoading.childNodes[0].colSpan=7;
		eleLoading.childNodes[0].appendChild(document.createTextNode(CMS_Main.getLoadingMessage()));
		document.getElementById("fileListContainer").appendChild(eleLoading);
		
		//get file list
		CMS_File_Category.objFileListRequest=CMS_Main.createRequest();
		CMS_File_Category.objFileListRequest.open("GET","get_element_xml.php?function=getFileListJson&fCategory_id="+CMS_File.intCurrentCategoryId.toString()+"&fFilter_module_files="+(CMS_File.blnFilterModuleFiles ? "1" : "0")+"&fFilter_not_set="+(CMS_File.blnFilterNotSet ? "1" : "0")+"&fFilter_published="+(CMS_File.blnFilterPublished ? "1" : "0")+"&fFilter_not_published="+(CMS_File.blnFilterNotPublished ? "1" : "0")+"&fFilter_archived="+(CMS_File.blnFilterArchived ? "1" : "0")+"&fFilter_staging="+(CMS_File.blnFilterStaging ? "1" : "0")+"&fFilter_alpha="+encodeURIComponent(CMS_File.strFilterAlpha)+"&fShow_count="+frm.fShow_count.value.toString()+"&fPage_number="+frm.fPage_number.value.toString(),true);
		CMS_File_Category.objFileListRequest.onreadystatechange=function(){
			if(CMS_File_Category.objFileListRequest.readyState==4)
			{
				if(CMS_File_Category.objFileListRequest.status==200)
				{
					//clear loading message
					while(document.getElementById("fileListContainer").firstChild)
						document.getElementById("fileListContainer").removeChild(document.getElementById("fileListContainer").firstChild);
					
					var objFileList=eval("("+CMS_File_Category.objFileListRequest.responseText+")");
					document.getElementById("fFile_count").value=objFileList.intFileCount.toString();
					
					//store order type
					CMS_File.intCurrentOrderType=objFileList.intOrderType;
					
					//check if upload date needs to be displayed
					if(CMS_File.intCurrentOrderType==2 || CMS_File.intCurrentOrderType==3)
					{
						try
						{
							document.getElementById("uploadedTitle").style.display="table-cell";
						}
						catch(e)
						{
							document.getElementById("uploadedTitle").style.display="block";
						}
					}
					else
					{
						document.getElementById("uploadedTitle").style.display="none";
					}
						
					//check if modified date needs to be displayed
					if(CMS_File.intCurrentOrderType==4 || CMS_File.intCurrentOrderType==5)
					{
						try
						{
							document.getElementById("modifiedTitle").style.display="table-cell";
						}
						catch(e)
						{
							document.getElementById("modifiedTitle").style.display="block";
						}
					}
					else
					{
						document.getElementById("modifiedTitle").style.display="none";
					}
					
					//add rows
					for(var i in objFileList.arrFiles)
					{
						var eleRow=CMS_File.createRow(objFileList.arrFiles[i]);
						
						if(i%2==0)
							eleRow.className="first";
						else
							eleRow.className="second";

						document.getElementById("fileListContainer").appendChild(eleRow);
					}
					
					if(objFileList.arrFiles.length==0)
						document.getElementById("fileListContainer").appendChild(CMS_File.createEmptyRow());
					
					CMS_File.initializeOrder(document.getElementById("frmManageFiles"));					
					CMS_File.updatePaginationLinks(document.getElementById("frmManageFiles"));
					CMS_File.updatePaginationNumbers(document.getElementById("frmManageFiles"));
				}
			}
		};
		CMS_File_Category.objFileListRequest.send(null);
		
		return false;
	},
	
	initializeOrder:function(frm)
	{
		blnDisabled=true; //default value
		
		if(frm && frm.fCategory_id && frm.fAction_index)
		{
			//check category selection
			if(CMS_File.intCurrentOrderType==6 && frm.fCategory_id.value > 0)
			{
				//check filter selection
				if(frm.fFilter_not_set.checked && frm.fFilter_published.checked && frm.fFilter_not_published.checked && frm.fFilter_archived.checked && frm.fFilter_alpha.value.toLowerCase()=="all")
				{
					//check pagination list
					if(Number(frm.fShow_count.value)==0 || Number(frm.fFile_count.value)<=Number(frm.fShow_count.value) || (Number(document.getElementById("fileCountStart").innerHTML)==1 && Number(frm.fFile_count.value)<=Number(document.getElementById("fileCountEnd").innerHTML))) //show count is "all" or greater than file count
					{
						blnDisabled=false;
						
						//initialize the drag drop
						$("#fileListContainer").tableDnD();
					}
				}
			}
			
			//enable or disable "save current file order" option
			//frm.saveOrder.disabled=blnDisabled;
		}
	},
	
	onActionChange:function(frm,eleSelect,eleContainer)
	{
		if(frm)
		{
			switch(Number(eleSelect.value))
			{
				case(4): //add files to category
					CMS_File.onAddFilesToCategorySelect(frm,eleContainer);
					break;
				default:
					CMS_File.onAddFilesToCategoryDeselect();
			}
		}
	},
	
	onActionClick:function(frm,eleSelect)
	{
		if(frm)
		{
			switch(Number(eleSelect.value))
			{
				case(1): //delete files
					CMS_File.deleteFiles(frm);
					break;
				case(2): //publish files
					CMS_File.publishFiles(frm);
					break;
				case(3): //archive files
					CMS_File.archiveFiles(frm);
					break;
				case(4): //add files to category
					CMS_File.addFilesToCategory(frm);
					break;
				case(5): //remove files from category
					CMS_File.removeFilesFromCategory(frm);
					break;
				case(6): //upload files to FTP location
					CMS_File.uploadFilesToFtpLocation(frm);
					break;
				default:
			}
		}
		return false;
	},
	
	addFiles:function()
	{
		//this.objUploader.browse(true, CMS_Client.getAllowedFileTypes()); //this function no longer exists as of YUI 2.6.0
		
		return false;
	},

	deleteFile:function(intFileId)
	{
		var strFileName=document.getElementById("selectFileName"+intFileId).value.toString();
		
		if(confirm("Are you sure you want to delete "+strFileName+"?"))
		{
			CMS_Main.objRequest.open("GET","get_page_xml.php?page="+CMS_Main.getPage()+"&fAction=deleteFiles&fFile_id[]="+intFileId,true);
			CMS_Main.objRequest.onreadystatechange=CMS_Main.updatePage;
			CMS_Main.objRequest.send(null);
		}
		
		return false;
	},
	
	deleteFiles:function(frm)
	{
		var arrFileIds=new Array();
		var arrFileNames=new Array();
		
		for(var i=0;i<frm.length;i++)
		{
			if(frm.elements[i].name && frm.elements[i].name.indexOf("selectFile")==0 && frm.elements[i].type=="checkbox" && frm.elements[i].checked)
			{
				arrFileIds[arrFileIds.length]=frm.elements[i].value;
				arrFileNames[arrFileNames.length]=frm.elements[i+1].value;
			}
		}
		if(arrFileIds.length==0)
		{
			alert("You do not have any files selected.");
		}
		else if(confirm("Are you sure you want to delete "+(arrFileIds.length==1 ? arrFileNames[0]+"?" : "the following files?\n\n\t"+arrFileNames.join("\n\t")+"\n ")))
		{
			CMS_Main.objRequest.open("GET","get_page_xml.php?page="+CMS_Main.getPage()+"&fAction=deleteFiles&fFile_id[]="+arrFileIds.join("&fFile_id[]="),true);
			CMS_Main.objRequest.onreadystatechange=CMS_Main.updatePage;
			CMS_Main.objRequest.send(null);
		}
		
		return false;
	},
	
	publishFiles:function(frm)
	{
		var arrFileIds=new Array();
		var arrFileNames=new Array();
		
		for(var i=0;i<frm.length;i++)
		{
			if(frm.elements[i].name && frm.elements[i].name.indexOf("selectFile")==0 && frm.elements[i].type=="checkbox" && frm.elements[i].checked)
			{
				arrFileIds[arrFileIds.length]=frm.elements[i].value;
				arrFileNames[arrFileNames.length]=frm.elements[i+1].value;
			}
		}
		if(arrFileIds.length==0)
		{
			alert("You do not have any files selected.");
		}
		else if(confirm("Are you sure you want to publish "+(arrFileIds.length==1 ? arrFileNames[0]+"?" : "the following files?\n\n\t"+arrFileNames.join("\n\t")+"\n ")))
		{
			CMS_Main.objRequest.open("GET","get_page_xml.php?page="+CMS_Main.getPage()+"&fAction=publishFiles&fFile_id[]="+arrFileIds.join("&fFile_id[]="),true);
			CMS_Main.objRequest.onreadystatechange=CMS_Main.updatePage;
			CMS_Main.objRequest.send(null);
		}
		
		return false;
	},
	
	archiveFiles:function(frm)
	{
		var arrFileIds=new Array();
		var arrFileNames=new Array();
		
		for(var i=0;i<frm.length;i++)
		{
			if(frm.elements[i].name && frm.elements[i].name.indexOf("selectFile")==0 && frm.elements[i].type=="checkbox" && frm.elements[i].checked)
			{
				arrFileIds[arrFileIds.length]=frm.elements[i].value;
				arrFileNames[arrFileNames.length]=frm.elements[i+1].value;
			}
		}
		if(arrFileIds.length==0)
		{
			alert("You do not have any files selected.");
		}
		else if(confirm("Are you sure you want to archive "+(arrFileIds.length==1 ? arrFileNames[0]+"?" : "the following files?\n\n\t"+arrFileNames.join("\n\t")+"\n ")))
		{
			CMS_Main.objRequest.open("GET","get_page_xml.php?page="+CMS_Main.getPage()+"&fAction=archiveFiles&fFile_id[]="+arrFileIds.join("&fFile_id[]="),true);
			CMS_Main.objRequest.onreadystatechange=CMS_Main.updatePage;
			CMS_Main.objRequest.send(null);
		}
		
		return false;
	},
	
	onAddFilesToCategorySelect:function(frm,eleContainer)
	{
		var blnReturnValue=false;
		var intIndex=1;
		var strHtml="";
		var objCategoryRequest=CMS_Main.createRequest();
		
		//get or create container
		if(document.getElementById("categorySelect"+intIndex.toString()))
		{
			eleDiv=document.getElementById("categorySelect"+intIndex.toString());
		}
		else
		{
			eleDiv=document.createElement("div");
			eleDiv.className="categorySelect";
			eleDiv.id="categorySelect"+intIndex.toString();
			eleParent=eleContainer.appendChild(eleDiv);
		}
		eleDiv.innerHTML=CMS_Main.getLoadingMessage();

		objCategoryRequest.open("GET","get_element_xml.php?function=getCategorySelectXml&fCategory_select_index="+intIndex.toString(),true);
		objCategoryRequest.onreadystatechange=function(){
			if(objCategoryRequest.readyState==4 && objCategoryRequest.status==200)
			{
				var eleDoc=objCategoryRequest.responseXML.documentElement;
				
				if(eleDoc.getElementsByTagName("categorySelect").length>0)
				{
					if(eleDoc.getElementsByTagName("categorySelect")[0].firstChild)
					{
						//update container contents
						strHtml=eleDoc.getElementsByTagName("categorySelect")[0].firstChild.nodeValue;
						document.getElementById("categorySelect"+intIndex.toString()).innerHTML=strHtml;
						
						//remove "remove" link
						document.getElementById("removeCategory"+intIndex.toString()).parentNode.removeChild(document.getElementById("removeCategory"+intIndex.toString()));
						
						//initialize
						CMS_File.startDateEnabledClick(document.getElementById("fStart_date_enabled"+intIndex.toString()),intIndex);
						DTS.insert("fStart_date"+intIndex.toString());
						
						CMS_File.endDateEnabledClick(document.getElementById("fEnd_date_enabled"+intIndex.toString()),intIndex);
						DTS.insert("fEnd_date"+intIndex.toString());
					}
				}
			}
		};
		objCategoryRequest.send(null);
		
		return false;
	},
	
	onAddFilesToCategoryDeselect:function()
	{
		var intIndex=1;

		//remove category select box
		if(document.getElementById("categorySelect"+intIndex.toString()))
			document.getElementById("categorySelect"+intIndex.toString()).parentNode.removeChild(document.getElementById("categorySelect"+intIndex.toString()));
	},
	
	addFilesToCategory:function(frm)
	{
		var arrFileIds=new Array();
		var arrFileNames=new Array();
		var intCategoryId=0;
		var intStartDateEnabled=0;
		var intStartDate=0;
		var intEndDateEnabled=0;
		var intEndDate=0;
		var intIndex=1;
		var blnReturnValue=true;
		
		for(var i=0;i<frm.length;i++)
		{
			if(frm.elements[i].name && frm.elements[i].name.indexOf("selectFile")==0 && frm.elements[i].type=="checkbox" && frm.elements[i].checked)
			{
				arrFileIds[arrFileIds.length]=frm.elements[i].value;
				arrFileNames[arrFileNames.length]=frm.elements[i+1].value;
			}
		}
		if(arrFileIds.length==0)
		{
			alert("You do not have any files selected.");
			blnReturnValue=false;
		}
		else
		{
			//check if start date is earlier than end date
			if(document.getElementById("fStart_date_enabled"+intIndex.toString()).checked && document.getElementById("fEnd_date_enabled"+intIndex.toString()).checked)
			{
				if(document.getElementById("fStart_date"+intIndex.toString()).value >= document.getElementById("fEnd_date"+intIndex.toString()).value)
				{
					alert("Please make sure the start date is earlier than the end date.");
					document.getElementById("fStart_date_enabled"+intIndex.toString()).focus();
					blnReturnValue=false;
				}
			}
		}
		
		if(blnReturnValue)
		{
			intCategoryId=document.getElementById("fCategory_id"+intIndex.toString()).value;
			intStartDateEnabled=(document.getElementById("fStart_date_enabled"+intIndex.toString()).checked ? document.getElementById("fStart_date_enabled"+intIndex.toString()).value : 0);
			intStartDate=document.getElementById("fStart_date"+intIndex.toString()).value;
			intEndDateEnabled=(document.getElementById("fEnd_date_enabled"+intIndex.toString()).checked ? document.getElementById("fEnd_date_enabled"+intIndex.toString()).value : 0);
			intEndDate=document.getElementById("fEnd_date"+intIndex.toString()).value;
			
			CMS_Main.objRequest.open("GET","get_page_xml.php?page="+CMS_Main.getPage()+"&fAction=addFilesToCategory&fCategory_id="+intCategoryId+"&fStart_date_enabled="+intStartDateEnabled+"&fStart_date="+intStartDate+"&fEnd_date_enabled="+intEndDateEnabled+"&fEnd_date="+intEndDate+"&fFile_id[]="+arrFileIds.join("&fFile_id[]="),true);
			CMS_Main.objRequest.onreadystatechange=CMS_Main.updatePage;
			CMS_Main.objRequest.send(null);
		}
		
		return false;
	},
	
	addExistingFileToCategory:function(id,intExistingFileId)
	{
		var blnReturnValue=true;
		var intCategoryId=0;
		
		//retrieve category id
		if(document.getElementById("frmManageFiles").fCategory_id)
			intCategoryId=Number(document.getElementById("frmManageFiles").fCategory_id.value);
		
		var objRequest=CMS_Main.createRequest();
		objRequest.open("GET","get_element_xml.php?function=addExistingFileToCategoryJson&fCategory_id="+intCategoryId+"&fFile_id="+intExistingFileId,true);
		objRequest.onreadystatechange=function(){
			if(objRequest.readyState==4)
			{
				if(objRequest.status==200)
				{
					var objFileList=eval("("+objRequest.responseText+")");
					
					//replace row
					var eleRow=CMS_File.createRow(objFileList.arrFiles[0]);
					eleRow.style.backgroundColor="#ffffff";
					eleRow.onmouseover=function()
					{
						this.style.backgroundColor="#ffffdd";
						this.style.color="#000000";
					}
					eleRow.onmouseout=function()
					{
						this.style.backgroundColor="#ffffff";
						this.style.color="";
					}
					document.getElementById("fileListContainer").replaceChild(eleRow,document.getElementById("fileRow"+id.toString()));
					
					//update pagination numbers
					if(document.getElementById("fFile_count"))
						document.getElementById("fFile_count").value=Number(document.getElementById("fFile_count").value)+1; //incrememt file count
					if(document.getElementById("fileCountEnd"))
						document.getElementById("fileCountEnd").innerHTML=(Number(document.getElementById("fileCountEnd").innerHTML)+1).toString(); //increment file end count
					if(document.getElementById("fileCount"))
						document.getElementById("fileCount").innerHTML=document.getElementById("fFile_count").value.toString(); //update file count
						
					//update pagination links
					CMS_File.updatePaginationLinks(document.getElementById("frmManageFiles"));
					
					CMS_File.initializeOrder(document.getElementById("frmManageFiles"));
				}
			}
		};
		objRequest.send(null);
		
		return false;
	},
	
	removeFilesFromCategory:function(frm)
	{
		var arrFileIds=new Array();
		var arrFileNames=new Array();
		
		for(var i=0;i<frm.length;i++)
		{
			if(frm.elements[i].name.indexOf("selectFile")==0 && frm.elements[i].type=="checkbox" && frm.elements[i].checked)
			{
				arrFileIds[arrFileIds.length]=frm.elements[i].value;
				arrFileNames[arrFileNames.length]=frm.elements[i+1].value;
			}
		}
		if(arrFileIds.length==0)
		{
			alert("You do not have any files selected.");
		}
		else if(confirm("Are you sure you want to remove "+(arrFileIds.length==1 ? arrFileNames[0]+" from this category?" : "the following files from this category?\n\n\t"+arrFileNames.join("\n\t")+"\n ")))
		{
			CMS_Main.objRequest.open("GET","get_page_xml.php?page="+CMS_Main.getPage()+"&fAction=removeFilesFromCategory&fCategory_id="+this.intCurrentCategoryId+"&fFile_id[]="+arrFileIds.join("&fFile_id[]="),true);
			CMS_Main.objRequest.onreadystatechange=CMS_Main.updatePage;
			CMS_Main.objRequest.send(null);
		}
		
		return false;
	},
	
	uploadFilesToFtpLocation:function(frm)
	{
		var arrFileIds=new Array();
		var arrFileNames=new Array();
		
		for(var i=0;i<frm.length;i++)
		{
			if(frm.elements[i].name && frm.elements[i].name.indexOf("selectFile")==0 && frm.elements[i].type=="checkbox" && frm.elements[i].checked)
			{
				arrFileIds[arrFileIds.length]=frm.elements[i].value;
				arrFileNames[arrFileNames.length]=frm.elements[i+1].value;
			}
		}
		if(arrFileIds.length==0)
		{
			alert("You do not have any files selected.");
		}
		else if(confirm("Are you sure you want to upload "+(arrFileIds.length==1 ? arrFileNames[0]+"?" : "the following files?\n\n\t"+arrFileNames.join("\n\t")+"\n ")))
		{
			CMS_Main.objRequest.open("GET","get_page_xml.php?page="+CMS_Main.getPage()+"&fAction=uploadFilesToFtpLocation&fFile_id[]="+arrFileIds.join("&fFile_id[]="),true);
			CMS_Main.objRequest.onreadystatechange=CMS_Main.updatePage;
			CMS_Main.objRequest.send(null);
		}
		
		return false;
	},
	
	ftpUpload:function(intFileId)
	{
		var objRequest=CMS_Main.createRequest();
		objRequest.open("GET","get_element_xml.php?function=uploadFtp&fFile_id="+intFileId,true);
		objRequest.onreadystatechange=function(){
			if(objRequest.readyState==4 && objRequest.status==200)
			{
				var objResponse=eval("("+objRequest.responseText+")");
				
				if(objResponse.blnSuccess)
				{
					//remove link
					if(document.getElementById("ftpUpload"+objResponse.intFileId.toString()))
						document.getElementById("ftpUpload"+objResponse.intFileId.toString()).parentNode.removeChild(document.getElementById("ftpUpload"+objResponse.intFileId.toString()));
				}
				else
				{
					if(objResponse.strMessages.length>0)
						alert(objResponse.strMessages.toString());
				}
			}
		};
		objRequest.send(null);
		
		return false;
	},
	
	saveOrder:function(frm)
	{
		var arrFileIds=new Array();
		var arrFileNames=new Array();
		
		if(frm && frm.fCategory_id && Number(frm.fCategory_id.value)>0)
		{
			for(var i=0;i<frm.length;i++)
			{
				if(frm.elements[i].name && frm.elements[i].name.indexOf("selectFile")==0 && frm.elements[i].type=="checkbox")
				{
					arrFileIds[arrFileIds.length]=frm.elements[i].value;
					arrFileNames[arrFileNames.length]=frm.elements[i+1].value;
				}
			}
			if(arrFileIds.length==0)
			{
				alert("There are no files in this category.");
			}
			else
			{
				CMS_Main.objRequest.open("GET","get_page_xml.php?page="+CMS_Main.getPage()+"&fAction=saveOrder&fCategory_id="+frm.fCategory_id.value.toString()+"&fFile_id[]="+arrFileIds.join("&fFile_id[]="),true);
				CMS_Main.objRequest.onreadystatechange=CMS_Main.updatePage;
				CMS_Main.objRequest.send(null);
			}
		}
		
		return false;
	},
	
	selectAllClick:function(frm)
	{
		for(var i=0;i<frm.length;i++)
			if(frm.elements[i].name && frm.elements[i].name.indexOf("selectFile")==0)
				frm.elements[i].checked=true;
		return false;
	},
	
	deselectAllClick:function(frm)
	{
		for(var i=0;i<frm.length;i++)
			if(frm.elements[i].name && frm.elements[i].name.indexOf("selectFile")==0)
				frm.elements[i].checked=false;
		return false;
	},
	
	showFileStatistics:function(intFileId)
	{
		//add overlay
		CMS_Main.addOverlay(this.eleFileStatistics.cloneNode(true),null,true);
		
		//clear content
		while(document.getElementById("fileStatisticsContent").firstChild)
		{
			document.getElementById("fileStatisticsContent").removeChild(document.getElementById("fileStatisticsContent").firstChild);
		}
		//add loading message
		document.getElementById("fileStatisticsContent").appendChild(document.createElement("p"));
		document.getElementById("fileStatisticsContent").firstChild.appendChild(document.createTextNode(CMS_Main.getLoadingMessage()));
		
		var objFileStatisticsRequest=CMS_Main.createRequest();
		objFileStatisticsRequest.open("GET","get_element_xml.php?function=getFileStatisticsXml&fFile_id="+intFileId.toString(),true);
		objFileStatisticsRequest.onreadystatechange=function(){
			if(objFileStatisticsRequest.readyState==4)
			{
				if(objFileStatisticsRequest.status==200)
				{
					//clear loading message
					while(document.getElementById("fileStatisticsContent").firstChild)
					{
						document.getElementById("fileStatisticsContent").removeChild(document.getElementById("fileStatisticsContent").firstChild);
					}
					
					var eleDoc=objFileStatisticsRequest.responseXML.documentElement;
					
					//show statistics
					if(eleDoc.getElementsByTagName("fileStatistics")[0] && eleDoc.getElementsByTagName("fileStatistics")[0].firstChild)
					{
						document.getElementById("fileStatisticsContent").innerHTML=eleDoc.getElementsByTagName("fileStatistics")[0].firstChild.nodeValue;
						
					}
					
					//update message
					if(eleDoc.getElementsByTagName("message")[0])
					{
						if(eleDoc.getElementsByTagName("message")[0].firstChild && eleDoc.getElementsByTagName("message")[0].firstChild.nodeValue.length>0)
						{
							document.getElementById("message").innerHTML=eleDoc.getElementsByTagName("message")[0].firstChild.nodeValue;
							document.getElementById("message").className="message";
						}
						else
						{
							document.getElementById("message").innerHTML="";
							document.getElementById("message").className="";
						}
					}
				}
			}
		};
		objFileStatisticsRequest.send(null);
		
		return false; //cancel link
	},
	
	closeFileStatistics:function()
	{
		//remove overlay
		CMS_Main.removeOverlay();
	},
	
	//file editor uploader methods
	
	objEditUploader:null,
	objEditFile:null,
	
	onEditContentReady:function()
	{
		//set file uploader properties
		CMS_File.objEditUploader.setAllowMultipleFiles(false);
		CMS_File.objEditUploader.setFileFilters(CMS_Client.getAllowedFileTypes());
		CMS_File.objEditUploader.setSimUploadLimit(1); //set simultaneous upload limit
	},
	onEditFileSelect:function(event)
	{
		for(var id in event.fileList)
		{
			CMS_File.objEditFile=event.fileList[id];
			
			document.getElementById("fFile_replace").value="1";
			
			document.getElementById("originalFile").style.display="none"; //hide original filename
			document.getElementById("newFile").innerHTML=event.fileList[id].name+" - "+CMS_File.formatFileSize(event.fileList[id].size); //show new filename

			document.getElementById("fileReplaceContainer").style.width="0px"; //hide replace button
			document.getElementById("fileReplaceContainer").style.marginLeft="0px"; //hide replace button
			document.getElementById("fileUndoContainer").style.display="block"; //show undo button
		}
	},
	onEditUploadStart:function(event)
	{
		document.getElementById("fileStatus").innerHTML="Waiting...";
	},
	onEditUploadProgress:function(event)
	{
		//check if progress bar exists
		if(!document.getElementById("progressBar"))
		{
			//create progress bar
			eleContainer=document.createElement("div");
			eleContainer.className="progressBar";
			eleContainer.id="progressBar";
			
			eleImg=document.createElement("img");
			eleImg.src=CMS_Main.getRootDirectory()+"/css/tng/progressbar/box.gif";
			eleImg.id="progressBarImage";
			eleImg.width="150";
			eleImg.height="12";
			eleImg.alt="";
			eleImg.title="";
			
			eleSpan=document.createElement("span");
			eleSpan.className="progressBarPercent";
			eleSpan.id="progressBarPercent";
			eleSpan.appendChild(document.createTextNode("0%"));
			
			eleContainer.appendChild(eleImg);
			document.getElementById("fileStatus").innerHTML="";
			document.getElementById("fileStatus").appendChild(eleContainer);
			document.getElementById("fileStatus").appendChild(document.createTextNode(" "));
			document.getElementById("fileStatus").appendChild(eleSpan);
		}
		
		CMS_File.updateEditProgress(event.id,(event.bytesLoaded/event.bytesTotal)*100);
	},
	updateEditProgress:function(strId,dblPercent)
	{
		strHtml="";
		strPercent=Math.round(dblPercent).toString()+"%";
		intPosition=Math.round((100-dblPercent)/100*150) * -1;
		
		if(document.getElementById("progressBar"))
		{
			document.getElementById("progressBar").style.backgroundPosition=intPosition+"px 0px";
			document.getElementById("progressBarPercent").replaceChild(document.createTextNode(strPercent),document.getElementById("progressBarPercent").firstChild);
		}
	},
	onEditUploadCancel:function(event)
	{
		//this event doesn't seem to fire
	},
	onEditUploadComplete:function(event)
	{
		CMS_File.updateProgress(event.id,100);
	},
	onEditUploadCompleteData:function(event)
	{
		var objFileData=eval("("+event.data+")");
		
		if(!objFileData.blnSuccess)
		{
			alert(objFileData.strMessages);
			document.getElementById("fileStatus").innerHTML="";
			document.getElementById("fSubmit").disabled=false;
		}
		else
		{
			CMS_File.editFileFormSubmitFinal(document.getElementById("frmEditFile"));
		}
		
		return false;
	},
	onEditUploadError:function(event)
	{
		alert(event.status);
		document.getElementById("fileStatus").innerHTML="";
		document.getElementById("fSubmit").disabled=false;
	},
	
	onEditRollOver:function()
	{
	},
	onEditRollOut:function()
	{
	},
	onEditClick:function()
	{
	},

	//file editor methods
	
	editFile:function(intFileId,blnUseStagingAreaCopy)
	{
		//remove any existing element with the "eleUploader" id
		if(document.getElementById("eleUploader"))
			document.getElementById("eleUploader").parentNode.removeChild(document.getElementById("eleUploader"));
		
		CMS_Main.objRequest.open("GET","get_page_xml.php?page=editFile&fFile_id="+intFileId.toString()+(blnUseStagingAreaCopy ? "&fUse_staging_area_copy=1" : ""),true);
		CMS_Main.objRequest.onreadystatechange=CMS_Main.updatePage;
		CMS_Main.objRequest.send(null);
		
		return false;
	},
	
	editFileFormInitialize:function(frm)
	{
		//instantiate uploader
		YAHOO.widget.Uploader.SWFURL=this.getUploaderSWFURL();
		document.getElementById("eleUploader").innerHTML=this.strUploaderInitialContent;
		this.objEditUploader=new YAHOO.widget.Uploader("eleUploader");
		
		//resize transparent overlay
		document.getElementById("eleUploader").style.width=document.getElementById("fileReplace").offsetWidth.toString()+"px";
		document.getElementById("eleUploader").style.height=document.getElementById("fileReplace").offsetHeight.toString()+"px";

		//set uploader event handlers
		this.objEditUploader.addListener("contentReady",this.onEditContentReady);
		this.objEditUploader.addListener('fileSelect',this.onEditFileSelect);
		this.objEditUploader.addListener('uploadStart',this.onEditUploadStart);
		this.objEditUploader.addListener('uploadProgress',this.onEditUploadProgress);
		this.objEditUploader.addListener('uploadCancel',this.onEditUploadCancel);
		this.objEditUploader.addListener('uploadComplete',this.onEditUploadComplete);
		this.objEditUploader.addListener('uploadCompleteData',this.onEditUploadCompleteData);
		this.objEditUploader.addListener('uploadError',this.onEditUploadError);
		//set more uploader event handlers
		this.objEditUploader.addListener("rollOver",this.onEditRollOver);
		this.objEditUploader.addListener("rollOut",this.onEditRollOut);
		this.objEditUploader.addListener("click",this.onEditClick);

		this.preloadProgressImages();

		if(frm)
		{
			//initialize Date/Time select
			if(frm.fCategory_select_count)
			{
				for(var i=1;i<=Number(frm.fCategory_select_count.value);i++)
				{
					this.startDateEnabledClick(document.getElementById("fStart_date_enabled"+i.toString()),i);
					DTS.insert("fStart_date"+i.toString());
					
					this.endDateEnabledClick(document.getElementById("fEnd_date_enabled"+i.toString()),i);
					DTS.insert("fEnd_date"+i.toString());
				}
			}
			if(frm.fDate)
			{
				DTS.insert("fDate",DTS.intTypeDateOptional);
			}
			
			CMS_Main.textEditorInit("fDescription");
			
			CMS_File.onPublishedClick(frm.fPublished);
			
			if(frm.fTitle)
			{
				frm.fTitle.focus();
				frm.fTitle.select();
			}
		}
	},
	
	onReplaceFileClick:function()
	{
		return false;
	},
	
	onUndoReplaceFileClick:function()
	{
		CMS_File.objEditUploader.clearFileList();
		document.getElementById("fFile_replace").value="0";

		document.getElementById("newFile").innerHTML=""; //remove new filename
		document.getElementById("originalFile").style.display="inline"; //show original filename

		document.getElementById("fileUndoContainer").style.display="none"; //hide undo button
		document.getElementById("fileReplaceContainer").style.width="auto"; //show replace button
		document.getElementById("fileReplaceContainer").style.marginLeft="5px"; //show replace button
	},
	
	editFileFormSubmit:function(frm)
	{
		//declare variables
		var intCategoryCount=0;
		var blnReturnValue=true;
		
		CMS_Main.textEditorUpdate("fDescription");
	
		if(frm.fTitle.value.length==0)
		{
			alert("Please enter a title");
			frm.fTitle.focus();
			blnReturnValue=false;
		}
		if(blnReturnValue)
		{
			for(var i=1;i<=frm.fCategory_select_max_index.value;i++)
			{
				if(document.getElementById("fCategory_id"+i.toString()))
				{
					//check for duplicate categories
					intCategoryCount=0;
					
					if(frm.elements["fCategory_id"].length)
					{
						for(var j=0;j<frm.elements["fCategory_id"].length;j++)
						{
							if(frm.elements["fCategory_id"][j].value==document.getElementById("fCategory_id"+i.toString()).value)
							{
								intCategoryCount++;
								
								if(intCategoryCount>=2)
								{
									alert("You cannot assign a file to the same category more than once.");
									blnReturnValue=false;
									break;
								}
							}
						}
					}
				}
				if(!blnReturnValue)
					break;
			}
		}
		if(blnReturnValue)
		{
			for(var i=1;i<=frm.fCategory_select_max_index.value;i++)
			{
				if(document.getElementById("fCategory_id"+i.toString()))
				{
					//check if start date is earlier than end date
					if(document.getElementById("fStart_date_enabled"+i.toString()).checked && document.getElementById("fEnd_date_enabled"+i.toString()).checked)
					{
						if(document.getElementById("fStart_date"+i.toString()).value >= document.getElementById("fEnd_date"+i.toString()).value)
						{
							alert("Please make sure the start date is earlier than the end date.");
							document.getElementById("fStart_date_enabled"+i.toString()).focus();
							blnReturnValue=false;
						}
					}
				}
			}
		}
		
		if(blnReturnValue)
		{
			document.getElementById("fSubmit").disabled=true;

			if(frm.fFile_replace.value.toString()=="1")
			{
				//check for valid file
				var objValidFileRequest=CMS_Main.createRequest();
				objValidFileRequest.open("GET","get_element_xml.php?function=isValidFileXml&fFile_id="+frm.fFile_id.value.toString()+"&fileId=0&fName="+encodeURIComponent(CMS_File.objEditFile.name)+"&fSize="+CMS_File.objEditFile.size+"&sizeUploadingTotal=0&fTitle="+frm.fTitle.value.toString(),true);
				objValidFileRequest.onreadystatechange=function(){
					if(objValidFileRequest.readyState==4)
					{
						if(objValidFileRequest.status==200)
						{
							var eleDoc=objValidFileRequest.responseXML.documentElement;
							
							if(eleDoc.getElementsByTagName("validFile") && eleDoc.getElementsByTagName("validFile")[0].firstChild)
							{
								if(eleDoc.getElementsByTagName("validFile")[0].firstChild.nodeValue==1)
								{
									//upload
									CMS_File.objEditUploader.uploadAll(CMS_Main.getRootDirectory()+'/file_upload.php',"POST",{sessionId:CMS_Cookie.get(CMS_Main.getSessionName()), fFile_id:frm.fFile_id.value.toString(), fTitle:frm.fTitle.value.toString(), fStaging_area_copy:frm.fStaging_area_copy.value.toString()},"fFile");
								}
								else
								{
									//cancel
									if(eleDoc.getElementsByTagName("message"))
										alert(eleDoc.getElementsByTagName("message")[0].firstChild.nodeValue);
									document.getElementById("fileStatus").innerHTML="";
									document.getElementById("fSubmit").disabled=false;
									
									CMS_File.onUndoReplaceFileClick();
								}
							}
							
						}
					}
				}
				objValidFileRequest.send(null);
			}
			else
			{
				var objTitleRequest=CMS_Main.createRequest();
				objTitleRequest.open("GET","get_element_xml.php?function=isValidTitleXml&fFile_id="+frm.fFile_id.value.toString()+"&fTitle="+encodeURIComponent(frm.fTitle.value.toString()),true);
				objTitleRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
				objTitleRequest.onreadystatechange=function()
				{
					if(objTitleRequest.readyState==4)
					{
						if(objTitleRequest.status==200)
						{
							var eleDoc=objTitleRequest.responseXML.documentElement;
							
							if(eleDoc.getElementsByTagName("validTitle")[0])
							{
								if(eleDoc.getElementsByTagName("validTitle")[0].firstChild)
								{
									if(eleDoc.getElementsByTagName("validTitle")[0].firstChild.nodeValue==1)
									{
										CMS_File.editFileFormSubmitFinal(frm);
									}
									else
									{
										alert(eleDoc.getElementsByTagName("message")[0].firstChild.nodeValue);
										frm.fTitle.focus();
										frm.fTitle.select();
										document.getElementById("fSubmit").disabled=false;
									}
								}
							}
						}
					}
				};
				objTitleRequest.send(null);
			}
		}
		
		return false;
	},
	
	editFileFormSubmitFinal:function(frm)
	{
		CMS_Main.objRequest.open("POST","get_page_xml.php",true);
		CMS_Main.objRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		CMS_Main.objRequest.onreadystatechange=CMS_Main.updatePage;
		CMS_Main.objRequest.send(CMS_Main.formEncode(frm)+"&page="+CMS_Main.getPage());
	},
	
	editFileFormCancel:function(frm)
	{
		CMS_Main.objRequest.open("GET","get_page_xml.php?page="+CMS_Main.getPage(),true);
		CMS_Main.objRequest.onreadystatechange=CMS_Main.updatePage;
		CMS_Main.objRequest.send(null);
		
		return false;
	},
	
	editFileFormRevert:function(frm)
	{
		if(confirm("Are you sure you want to revert this file back to the original version?"))
		{
			CMS_Main.objRequest.open("GET","get_page_xml.php?page="+CMS_Main.getPage()+"&fAction=revertFile&fFile_id="+frm.fFile_id.value.toString(),true);
			CMS_Main.objRequest.onreadystatechange=CMS_Main.updatePage;
			CMS_Main.objRequest.send(null);
		}
		
		return false;
	},
	
	startDateEnabledClick:function(eleInput,intIndex)
	{
		if(eleInput && intIndex)
		{
			if(eleInput.checked)
			{
				document.getElementById("startDate"+intIndex.toString()).style.display="block";
			}
			else
			{
				document.getElementById("startDate"+intIndex.toString()).style.display="none";
			}
		}
	},

	endDateEnabledClick:function(eleInput,intIndex)
	{
		if(eleInput && intIndex)
		{
			if(eleInput.checked)
			{
				document.getElementById("endDate"+intIndex.toString()).style.display="block";
			}
			else
			{
				document.getElementById("endDate"+intIndex.toString()).style.display="none";
			}
		}
	},
	
	onPublishedClick:function(input)
	{
		if(document.getElementById("unpublishOptions"))
		{
			if(input.checked)
			{
				document.getElementById("unpublishOptions").style.display="none";
			}
			else
			{
				try
				{
					document.getElementById("unpublishOptions").style.display="table-row";
				}
				catch(e)
				{
					document.getElementById("unpublishOptions").style.display="block";
				}
			}
		}
	},

	//utility methods
	
	createUploadRow:function(objFileData)
	{
		//create row
		var eleRow=document.createElement("tr");
		eleRow.id="fileRow"+objFileData.id;
		
		var eleTd2=document.createElement("td");
		var strTitle=objFileData.name.substr(0,objFileData.name.lastIndexOf("."));
		eleTd2.appendChild(document.createTextNode(strTitle));
		eleRow.appendChild(eleTd2);
		
		if(CMS_File.intCurrentOrderType==2 || CMS_File.intCurrentOrderType==3)
		{
			var eleTd3=document.createElement("td");
			eleTd3.appendChild(document.createTextNode(" "));
			eleRow.appendChild(eleTd3);
		}
		
		if(CMS_File.intCurrentOrderType==4 || CMS_File.intCurrentOrderType==5)
		{
			var eleTd4=document.createElement("td");
			eleTd4.appendChild(document.createTextNode(" "));
			eleRow.appendChild(eleTd4);
		}
		
		var eleTd5=document.createElement("td");
		eleTd5.appendChild(document.createTextNode(CMS_File.formatFileSize(objFileData.size)));
		eleRow.appendChild(eleTd5);
		
		var eleTd6=document.createElement("td");
		eleTd6.id="fileStatus"+objFileData.id;
		eleTd6.innerHTML=" ";
		eleRow.appendChild(eleTd6);
		
		var eleTd7=document.createElement("td");
		eleTd7.appendChild(document.createTextNode("0"));
		eleRow.appendChild(eleTd7);
		
		var eleTd10=document.createElement("td");
		eleTd10.id="fileAction"+objFileData.id;
		eleTd10.style.width="96px";
		eleTd10.innerHTML=" \
		<div class=\"actions\"> \
			<ul> \
				<li><a class=\"action4\" href=\"#\" onclick=\"return CMS_File.cancel("+objFileData.id+");\" title=\"Cancel\">Cancel</a></li> \
			</ul> \
		</div>";
		eleRow.appendChild(eleTd10);
		
		return eleRow;
	},
	
	//create row from passed file data
	createRow:function(objFileData)
	{
		//create row
		var eleRow=document.createElement("tr");
		eleRow.id="fileRow"+objFileData.intFileId;
		
		var eleTd1=document.createElement("td");
		eleTd1.style.padding=".5em";
		eleTd1.style.textAlign="center";
		eleTd1.style.width="20px";
 		var eleInput1=CMS_Main.createNamedElement("input","selectFile"+objFileData.intFileId.toString());
		eleInput1.id="selectFile"+objFileData.intFileId.toString();
		eleInput1.type="checkbox";
		eleInput1.value=objFileData.intFileId.toString();
		eleTd1.appendChild(eleInput1);
		var eleInput2=CMS_Main.createNamedElement("input","selectFileName");
		eleInput2.id="selectFileName"+objFileData.intFileId.toString();
		eleInput2.type="hidden";
		eleInput2.value=objFileData.strName;
		eleTd1.appendChild(eleInput2);
		//eleRow.appendChild(eleTd1);

		var eleTd2=document.createElement("td");
		eleTd2.appendChild(document.createTextNode(objFileData.strTitle));
		eleRow.appendChild(eleTd2);

		//check if upload date needs to be displayed
		if(CMS_File.intCurrentOrderType==2 || CMS_File.intCurrentOrderType==3)
		{
			var eleTd3=document.createElement("td");
			eleTd3.appendChild(document.createTextNode(objFileData.strDateUploaded));
			eleRow.appendChild(eleTd3);
		}

		//check if modified date needs to be displayed
		if(CMS_File.intCurrentOrderType==4 || CMS_File.intCurrentOrderType==5)
		{
			var eleTd4=document.createElement("td");
			eleTd4.appendChild(document.createTextNode(objFileData.strDateModified));
			eleRow.appendChild(eleTd4);
		}

		var eleTd5=document.createElement("td");
		eleTd5.appendChild(document.createTextNode(CMS_File.formatFileSize(objFileData.intSize)));
		eleRow.appendChild(eleTd5);

		var eleTd6=document.createElement("td");
		eleTd6.appendChild(document.createTextNode((objFileData.strStatus.length>0 ? objFileData.strStatus : " ")));
		eleRow.appendChild(eleTd6);

		var eleTd7=document.createElement("td");
		//eleTd7.appendChild(document.createTextNode(objFileData.intHits.toString()));
		eleTd7.innerHTML="<a href=\"\" title=\"Details\" onclick=\"return CMS_File.showFileStatistics("+objFileData.intFileId.toString()+");\">"+objFileData.intHits.toString()+"</a>";
		eleRow.appendChild(eleTd7);

		var eleTd8=document.createElement("td");
		eleTd8.style.width="96px";
		eleTd8.innerHTML=" \
		<div class=\"actions\"> \
			<ul> \
				<li><a class=\"action9\" href=\""+objFileData.strHref+"\" target=\"_blank\" title=\""+objFileData.strName.replace(/\"/g,'&quote;')+"\">"+objFileData.strName.replace(/\"/g,'&quote;')+"</a></li> \
				<li><a "+(objFileData.blnNew ? "class=\"action5\"" : "class=\"action5\"")+" href=\"#\" onclick=\"return CMS_File.editFile("+objFileData.intFileId.toString()+");\" title=\"Edit\">Edit</a></li> \
				"+(objFileData.blnStagingAreaCopyExists ? "<li><a class=\"action6\" href=\"#\" onclick=\"return CMS_File.editFile("+objFileData.intFileId.toString()+",true);\" title=\"Edit copy\">Edit copy</a></li>" : "")+" \
				<li><a class=\"action4\" href=\"#\" onclick=\"return CMS_File.deleteFile("+objFileData.intFileId.toString()+");\" title=\"Delete\">Delete</a></li> \
				"+(CMS_Client.isFtpEnabled() && !objFileData.blnFtpCopyExists ? "<li id=\"ftpUpload"+objFileData.intFileId.toString()+"\"><a class=\"action13\" href=\"#\" title=\"Upload to FTP folder\" onclick=\"return CMS_File.ftpUpload("+objFileData.intFileId.toString()+");\">"+objFileData.strName.replace(/\"/g,'&quote;')+"</a></li>" : "")+" \
			</ul> \
			<div style=\"float:right;\"> \
				<input class=\"radio\" name=\"selectFile\" id=\"selectFile"+objFileData.intFileId.toString()+"\" type=\"checkbox\" value=\""+objFileData.intFileId.toString()+"\" /> \
				<input name=\"selectFileName\" id=\"selectFileName"+objFileData.intFileId.toString()+"\" type=\"hidden\" value=\""+objFileData.strName+"\" /> \
			</div> \
		</div>";
		eleRow.appendChild(eleTd8);
		
		return eleRow;
	},
	
	createEmptyRow:function()
	{
		var eleRow=document.createElement("tr");
		eleRow.id="noRecords";
		var intColumns=5;
		
		if(CMS_File.intCurrentOrderType==2 || CMS_File.intCurrentOrderType==3 || CMS_File.intCurrentOrderType==4 || CMS_File.intCurrentOrderType==5)
			intColumns++;
		
		var eleTd1=document.createElement("td");
		eleTd1.colSpan=intColumns;
		eleTd1.appendChild(document.createTextNode("No files to display"));
		eleRow.appendChild(eleTd1);
		
		return eleRow;
	},
	
	formatFileSize:function(intBytes,intSignificantDigits)
	{
		dblSize=Number(intBytes);
		strNotation="bytes";
		intDegree=0;
		
		if(!intSignificantDigits)
		{
			intSignificantDigits=3;
		}
		
		switch(true)
		{
			case(Math.abs(intBytes)>=1099511627776):
				dblSize=intBytes/1099511627776;
				strNotation="TB";
				break;
			case(Math.abs(intBytes)>=1073741824):
				dblSize=intBytes/1073741824;
				strNotation="GB";
				break;
			case(Math.abs(intBytes)>=1048576):
				dblSize=intBytes/1048576;
				strNotation="MB";
				break;
			case(Math.abs(intBytes)>=1024):
				dblSize=intBytes/1024;
				strNotation="KB";
				break;
		}
		
		//round to correct number of significant digits
		intDegree=(Math.floor(dblSize).toString()).length; //count digits before decimal place
		dblSize=dblSize.toFixed(Math.max((intSignificantDigits - intDegree),0));
		
		return dblSize.toString()+" "+strNotation;
	}
}/*--------------------------------------------------
	Project:	The November Group - CMS Administration
	Script:		cms_file_category.js
	Includes:	CMS_File_Category
--------------------------------------------------*/

var CMS_File_Category={
	
	strFilterAlpha:"all",
	
	//pagination attributes
	intPageNumber:1,

	manageCategories:function()
	{
		CMS_Main.setPage("manageCategories"); //store page selection

		CMS_Main.objRequest.open("GET","get_page_xml.php?page="+CMS_Main.getPage(),true);
		CMS_Main.objRequest.onreadystatechange=CMS_Main.updatePage;
		CMS_Main.objRequest.send(null);
		
		return false;
	},
	
	manageCategoriesInitialize:function(frm)
	{
		if(frm)
		{
			//reselect previously selected filters
			frm.fFilter_alpha.value=this.strFilterAlpha;
			
			//alpha
			if(document.getElementById("filterAlpha"))
			{
				var arrLinks=document.getElementById("filterAlpha").getElementsByTagName("a");
				for(var i=0;i<arrLinks.length;i++)
				{
					if(arrLinks[i].firstChild.firstChild.firstChild.nodeValue.toLowerCase()==frm.fFilter_alpha.value.toString())
					{
						arrLinks[i].className+=" current_page";
						break;
					}
				}
			}
			if(document.getElementById("filterAlphaTop"))
			{
				var arrLinks=document.getElementById("filterAlphaTop").getElementsByTagName("a");
				for(var i=0;i<arrLinks.length;i++)
				{
					if(arrLinks[i].firstChild.firstChild.firstChild.nodeValue.toLowerCase()==frm.fFilter_alpha.value.toString())
					{
						arrLinks[i].className+=" current_page";
						break;
					}
				}
			}
			
			//reselect previously selected show count
			var blnSelected=false;
			if(document.getElementById("fShow_count"))
			{
				var eleSelect2=document.getElementById("fShow_count");
				for(var i=0;i<eleSelect2.options.length;i++)
				{
					if(Number(eleSelect2.options[i].value)==CMS_Client_User_Settings.getShowCountFileCategories())
					{
						eleSelect2.options[i].selected=true;
						blnSelected=true;
						break;
					}
				}
				if(!blnSelected)
				{
					eleSelect2.options[0].selected=true;
					CMS_Client_User_Settings.setShowCountFileCategories(Number(eleSelect2.options[0].value));
				}
			}
			blnSelected=false;
			if(document.getElementById("fShow_count_top"))
			{
				var eleSelect2=document.getElementById("fShow_count_top");
				for(var i=0;i<eleSelect2.options.length;i++)
				{
					if(Number(eleSelect2.options[i].value)==CMS_Client_User_Settings.getShowCountFileCategories())
					{
						eleSelect2.options[i].selected=true;
						blnSelected=true;
						break;
					}
				}
				if(!blnSelected)
				{
					eleSelect2.options[0].selected=true;
					CMS_Client_User_Settings.setShowCountFileCategories(Number(eleSelect2.options[0].value));
				}
			}

			//retrieve previously selected page number
			if(frm.fPage_number)
				frm.fPage_number.value=this.intPageNumber.toString();
			
			this.onCategoryOrFilterChange(frm);
		}
	},
	
	onCategoryOrFilterChange:function(frm)
	{
		CMS_File_Category.getCategoryList(frm);
	},
	
	onAlphaClick:function(frm,eleA)
	{
		if(frm && eleA)
		{
			frm.fFilter_alpha.value=eleA.firstChild.firstChild.firstChild.nodeValue.toLowerCase(); //retrieve selected value
			this.strFilterAlpha=frm.fFilter_alpha.value.toString();
			
			//reset classes
			if(document.getElementById("filterAlpha"))
			{
				var arrLinks=document.getElementById("filterAlpha").getElementsByTagName("a");
				for(var i=0;i<arrLinks.length;i++)
				{
					if(arrLinks[i].className.indexOf("current_page")>-1)
						arrLinks[i].className=arrLinks[i].className.replace("current_page","");
					if(arrLinks[i].firstChild.firstChild.firstChild.nodeValue.toLowerCase()==frm.fFilter_alpha.value)
						arrLinks[i].className+=" current_page";
				}
			}
			if(document.getElementById("filterAlphaTop"))
			{
				var arrLinks=document.getElementById("filterAlphaTop").getElementsByTagName("a");
				for(var i=0;i<arrLinks.length;i++)
				{
					if(arrLinks[i].className.indexOf("current_page")>-1)
						arrLinks[i].className=arrLinks[i].className.replace("current_page","");
					if(arrLinks[i].firstChild.firstChild.firstChild.nodeValue.toLowerCase()==frm.fFilter_alpha.value)
						arrLinks[i].className+=" current_page";
				}
			}
			
			//update filter
			CMS_File_Category.onCategoryOrFilterChange(frm);
		}
		return false; //cancel link
	},
	
	onShowCountChange:function(frm,eleSelect)
	{
		if(frm && eleSelect)
		{
			var intPages=1;

			if(document.getElementById("fShow_count"))
			{
				var eleSelect2=document.getElementById("fShow_count");
				for(var i=0;i<eleSelect2.options.length;i++)
				{
					if(Number(eleSelect2.options[i].value)==Number(eleSelect.options[eleSelect.selectedIndex].value))
						eleSelect2.options[i].selected=true;
				}
			}
			if(document.getElementById("fShow_count_top"))
			{
				var eleSelect2=document.getElementById("fShow_count_top");
				for(var i=0;i<eleSelect2.options.length;i++)
				{
					if(Number(eleSelect2.options[i].value)==Number(eleSelect.options[eleSelect.selectedIndex].value))
						eleSelect2.options[i].selected=true;
				}
			}
			
			CMS_Client_User_Settings.setShowCountFileCategories(Number(eleSelect.value)); //store selected value
			
			//calculate number of pages
			if(Number(frm.fShow_count.value)>0)
				intPages=Math.ceil(Number(frm.fCategory_count.value)/Number(eleSelect.value));
			if(intPages==0)
				intPages++;
			
			//check if current page number will exist for new show count
			if(Number(frm.fPage_number.value)>intPages)
				frm.fPage_number.value="1"; //reset page number
			
			this.getCategoryList(frm);
		}
	},
	
	onPageClick:function(frm,eleNumber)
	{
		if(frm && eleNumber)
		{
			frm.fPage_number.value=eleNumber.firstChild.firstChild.firstChild.nodeValue; //retrieve selected value
			this.getCategoryList(frm);
		}
		return false;
	},
	
	updatePaginationLinks:function(frm)
	{
		if(frm && frm.fShow_count && frm.fPage_number)
		{
			var intPages=1;
			
			//calculate number of pages
			if(Number(frm.fShow_count.value)>0)
				intPages=Math.ceil(Number(frm.fCategory_count.value)/Number(frm.fShow_count.value));
			if(intPages==0)
				intPages++;
			
			//rebuild page links
			if(document.getElementById("filterPage"))
			{
				document.getElementById("filterPage").innerHTML="";
				for(var i=0;i<intPages;i++)
					document.getElementById("filterPage").innerHTML+="<li><a href=\"#\" onclick=\"return CMS_File_Category.onPageClick(document.getElementById('frmManageCategories'),this);\"><span><span>"+(i+1).toString()+"</span></span></a></li>";
			}
			if(document.getElementById("filterPageTop"))
			{
				document.getElementById("filterPageTop").innerHTML="";
				for(var i=0;i<intPages;i++)
					document.getElementById("filterPageTop").innerHTML+="<li><a href=\"#\" onclick=\"return CMS_File_Category.onPageClick(document.getElementById('frmManageCategories'),this);\"><span><span>"+(i+1).toString()+"</span></span></a></li>";
			}
			
			//select page link
			var blnSelected=false;
			if (document.getElementById("filterPage")) 
			{
				var arrLinks=document.getElementById("filterPage").getElementsByTagName("a");
				for(var i=0;i<arrLinks.length;i++)
				{
					if(arrLinks[i].firstChild.firstChild.firstChild.nodeValue==frm.fPage_number.value.toString())
					{
						//change class
						arrLinks[i].className+=" current_page";
						blnSelected=true;
						break;
					}
				}
				if(!blnSelected)
				{
					arrLinks[0].className+=" current_page";
					frm.fPage_number.value=arrLinks[0].firstChild.firstChild.firstChild.nodeValue;
				}
			}
			blnSelected=false;
			if (document.getElementById("filterPageTop")) 
			{
				var arrLinks=document.getElementById("filterPageTop").getElementsByTagName("a");
				for(var i=0;i<arrLinks.length;i++)
				{
					if(arrLinks[i].firstChild.firstChild.firstChild.nodeValue==frm.fPage_number.value.toString())
					{
						//change class
						arrLinks[i].className+=" current_page";
						blnSelected=true;
						break;
					}
				}
				if(!blnSelected)
				{
					arrLinks[0].className+=" current_page";
					frm.fPage_number.value=arrLinks[0].firstChild.firstChild.firstChild.nodeValue;
				}
			}

			//store selected value
			this.intPageNumber=Number(frm.fPage_number.value);
		}
	},
	
	updatePaginationNumbers:function(frm)
	{
		if(frm && frm.fShow_count && frm.fPage_number)
		{
			//calculate numbers
			var intCountStart=(Number(frm.fPage_number.value)-1)*Number(frm.fShow_count.value);
			var intCountEnd=(Number(frm.fShow_count.value)==0 ? Number(frm.fCategory_count.value) : Math.min(Number(frm.fShow_count.value)+intCountStart,Number(frm.fCategory_count.value)));
			
			//update numbers
			if(document.getElementById("categoryCountStart"))
				document.getElementById("categoryCountStart").innerHTML=(Math.min(intCountStart+1,Number(frm.fCategory_count.value))).toString();
			if(document.getElementById("categoryCountEnd"))
				document.getElementById("categoryCountEnd").innerHTML=intCountEnd.toString();
			if(document.getElementById("categoryCount"))
				document.getElementById("categoryCount").innerHTML=frm.fCategory_count.value.toString();

			if(document.getElementById("categoryCountStartTop"))
				document.getElementById("categoryCountStartTop").innerHTML=(Math.min(intCountStart+1,Number(frm.fCategory_count.value))).toString();
			if(document.getElementById("categoryCountEndTop"))
				document.getElementById("categoryCountEndTop").innerHTML=intCountEnd.toString();
			if(document.getElementById("categoryCountTop"))
				document.getElementById("categoryCountTop").innerHTML=frm.fCategory_count.value.toString();
		}
	},
	
	getCategoryList:function(frm)
	{
		var strHtml="";
		
		//clear select all
		if(document.getElementById("selectAll"))
			document.getElementById("selectAll").checked=false;
		
		//clear category list
		while(document.getElementById("categoryListContainer").firstChild)
			document.getElementById("categoryListContainer").removeChild(document.getElementById("categoryListContainer").firstChild);
		
		//add loading message
		var eleLoading=document.createElement("tr");
		eleLoading.appendChild(document.createElement("td"));
		eleLoading.childNodes[0].colSpan=3;
		eleLoading.childNodes[0].appendChild(document.createTextNode(CMS_Main.getLoadingMessage()));
		document.getElementById("categoryListContainer").appendChild(eleLoading);
		
		//get category list
		var objCategoryListRequest=CMS_Main.createRequest();
		objCategoryListRequest.open("GET","get_element_xml.php?function=getFileCategoryListJson&fFilter_alpha="+encodeURIComponent(CMS_File_Category.strFilterAlpha)+"&fShow_count="+frm.fShow_count.value.toString()+"&fPage_number="+frm.fPage_number.value.toString(),true);
		objCategoryListRequest.onreadystatechange=function(){
			if(objCategoryListRequest.readyState==4)
			{
				if(objCategoryListRequest.status==200)
				{
					//clear loading message
					while(document.getElementById("categoryListContainer").firstChild)
						document.getElementById("categoryListContainer").removeChild(document.getElementById("categoryListContainer").firstChild);
					
					var objCategoryList=eval("("+objCategoryListRequest.responseText+")");
					document.getElementById("fCategory_count").value=objCategoryList.intCategoryCount.toString();
					
					//add rows
					for(var i in objCategoryList.arrCategories)
					{
						var eleRow=CMS_File_Category.createRow(objCategoryList.arrCategories[i]);
						
						if(i%2==0)
							eleRow.className="first";
						else
							eleRow.className="second";

						document.getElementById("categoryListContainer").appendChild(eleRow);
					}
					
					if(objCategoryList.arrCategories.length==0)
						document.getElementById("categoryListContainer").appendChild(CMS_File_Category.createEmptyRow());
					
					CMS_File_Category.updatePaginationLinks(document.getElementById("frmManageCategories"));
					CMS_File_Category.updatePaginationNumbers(document.getElementById("frmManageCategories"));
				}
			}
		};
		objCategoryListRequest.send(null);
		
		return false;
	},
	
	onActionChange:function(frm,eleSelect)
	{
	},
	
	onActionClick:function(frm,eleSelect)
	{
		if(frm)
		{
			switch(Number(eleSelect.value))
			{
				case(1): //delete categories
					CMS_File_Category.deleteCategories(frm);
					break;
				default:
			}
		}
		return false;
	},
	
	deleteCategories:function(frm)
	{
		var arrCategoryIds=new Array();
		var arrCategoryTitles=new Array();
		
		for(var i=0;i<frm.length;i++)
		{
			if(frm.elements[i].name && frm.elements[i].name.indexOf("selectCategory")==0 && frm.elements[i].type=="checkbox" && frm.elements[i].checked)
			{
				arrCategoryIds[arrCategoryIds.length]=frm.elements[i].value;
				arrCategoryTitles[arrCategoryTitles.length]=frm.elements[i+1].value;
			}
		}
		if(arrCategoryIds.length==0)
		{
			alert("You do not have any categories selected.");
		}
		else if(confirm("Are you sure you want to delete "+(arrCategoryIds.length==1 ? arrCategoryTitles[0]+"?" : "the following categories?\n\n\t"+arrCategoryTitles.join("\n\t")+"\n ")))
		{
			CMS_Main.objRequest.open("GET","get_page_xml.php?page="+CMS_Main.getPage()+"&fAction=deleteFileCategories&fCategory_id[]="+arrCategoryIds.join("&fCategory_id[]="),true);
			CMS_Main.objRequest.onreadystatechange=CMS_Main.updatePage;
			CMS_Main.objRequest.send(null);
		}
		
		return false;
	},
	
	selectAllClick:function(frm)
	{
		for(var i=0;i<frm.length;i++)
			if(frm.elements[i].name && frm.elements[i].name.indexOf("selectCategory")==0)
				frm.elements[i].checked=true;
		return false;
	},
	
	deselectAllClick:function(frm)
	{
		for(var i=0;i<frm.length;i++)
			if(frm.elements[i].name && frm.elements[i].name.indexOf("selectCategory")==0)
				frm.elements[i].checked=false;
		return false;
	},
	
	addCategory:function()
	{
		CMS_Main.objRequest.open("GET","get_page_xml.php?page=editCategory",true);
		CMS_Main.objRequest.onreadystatechange=CMS_Main.updatePage;
		CMS_Main.objRequest.send(null);
		
		return false;
	},
	
	editCategory:function(intCategoryId)
	{
		CMS_Main.objRequest.open("GET","get_page_xml.php?page=editCategory&fCategory_id="+intCategoryId.toString(),true);
		CMS_Main.objRequest.onreadystatechange=CMS_Main.updatePage;
		CMS_Main.objRequest.send(null);
		
		return false;
	},
	
	editCategoryFormInitialize:function(frm)
	{
		if(frm)
		{
			CMS_Main.textEditorInit("fDescription");
			
			if(frm.fName)
			{
				frm.fName.focus();
				frm.fName.select();
			}
		}
	},
	
	editCategoryFormSubmit:function(frm)
	{
		//declare variables
		var blnReturnValue=true;

		CMS_Main.textEditorUpdate("fDescription");
		
		if(frm.fName.value.length==0)
		{
			alert("Please enter a name");
			frm.fName.focus();
			blnReturnValue=false;
		}
		
		if(blnReturnValue)
		{
			document.getElementById("fSubmit").disabled=true;
			
			CMS_Main.objRequest.open("POST","get_page_xml.php",true);
			CMS_Main.objRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
			CMS_Main.objRequest.onreadystatechange=CMS_Main.updatePage;
			CMS_Main.objRequest.send(CMS_Main.formEncode(frm)+"&page="+CMS_Main.getPage());
		}
		
		return false;
	},
	
	editCategoryFormCancel:function(frm)
	{
		CMS_Main.objRequest.open("GET","get_page_xml.php?page="+CMS_Main.getPage(),true);
		CMS_Main.objRequest.onreadystatechange=CMS_Main.updatePage;
		CMS_Main.objRequest.send(null);
		
		return false;
	},
	
	deleteCategory:function(intCategoryId)
	{
		var strCategoryName=document.getElementById("selectCategoryName"+intCategoryId).value.toString();
		
		if(confirm("Are you sure you want to delete "+strCategoryName+"?"))
		{
			CMS_Main.objRequest.open("GET","get_page_xml.php?page="+CMS_Main.getPage()+"&fAction=deleteCategory&fCategory_id="+intCategoryId,true);
			CMS_Main.objRequest.onreadystatechange=CMS_Main.updatePage;
			CMS_Main.objRequest.send(null);
		}
		
		return false;
	},
	
	assignCategory:function()
	{
		var blnReturnValue=false;
		var intCount=0;
		var intIndex=0;
		var strHtml="";
		var objCategoryRequest=CMS_Main.createRequest();
		
		intCount=document.getElementById("fCategory_select_count").value.valueOf();
		intIndex=document.getElementById("fCategory_select_max_index").value.valueOf();
		
		intCount++;
		intIndex++;
		
		//update count and max index
		document.getElementById("fCategory_select_count").value=intCount;
		document.getElementById("fCategory_select_max_index").value=intIndex;
		
		//create container
		eleDiv=document.createElement("div");
		eleDiv.className="categorySelect";
		eleDiv.id="categorySelect"+intIndex.toString();
		eleDiv.innerHTML=CMS_Main.getLoadingMessage();
		document.getElementById("categoryListContainer").appendChild(eleDiv);

		objCategoryRequest.open("GET","get_element_xml.php?function=getCategorySelectXml&fCategory_select_index="+intIndex.toString(),true);
		objCategoryRequest.onreadystatechange=function(){
			if(objCategoryRequest.readyState==4)
			{
				if(objCategoryRequest.status==200)
				{
					var eleDoc=objCategoryRequest.responseXML.documentElement;
					
					if(eleDoc.getElementsByTagName("categorySelect").length>0)
					{
						if(eleDoc.getElementsByTagName("categorySelect")[0].firstChild)
						{
							//update container contents
							strHtml=eleDoc.getElementsByTagName("categorySelect")[0].firstChild.nodeValue;
							document.getElementById("categorySelect"+intIndex.toString()).innerHTML=strHtml;
							
							//initialize
							CMS_File.startDateEnabledClick(document.getElementById("fStart_date_enabled"+intIndex.toString()),intIndex);
							DTS.insert("fStart_date"+intIndex.toString());
							
							CMS_File.endDateEnabledClick(document.getElementById("fEnd_date_enabled"+intIndex.toString()),intIndex);
							DTS.insert("fEnd_date"+intIndex.toString());
						}
					}
				}
			}
		};
		objCategoryRequest.send(null);
		
		return false;
	},
	
	unassignCategory:function(intIndex)
	{
		//remove container
		eleParent=document.getElementById("categorySelect"+intIndex.toString()).parentNode;
		eleParent.removeChild(document.getElementById("categorySelect"+intIndex.toString()));
		
		//update count
		if(document.getElementById("fCategory_select_count"))
			document.getElementById("fCategory_select_count").value=document.getElementById("fCategory_select_count").value.valueOf()-1;
		
		return false;
	},
	
	//utility methods
	
	//create row from passed category data
	createRow:function(objCategoryData)
	{
		//create row
		var eleRow=document.createElement("tr");
		eleRow.id="categoryRow"+objCategoryData.intCategoryId;
		
		var eleTd1=document.createElement("td");
		eleTd1.appendChild(document.createTextNode(objCategoryData.strName));
		eleRow.appendChild(eleTd1);

		var eleTd6=document.createElement("td");
		if(objCategoryData.blnActive)
			eleTd6.innerHTML="<span class=\"approved\">Active</span>";
		else
			eleTd6.innerHTML="<span class=\"denied\">Disabled</span>";
		eleRow.appendChild(eleTd6);

		var eleTd9=document.createElement("td");
		eleTd9.innerHTML=" \
		<div class=\"actions\"> \
			<ul> \
				<li><a class=\"action5\" href=\"#\" onclick=\"return CMS_File_Category.editCategory("+objCategoryData.intCategoryId.toString()+");\" title=\"Edit\">Edit</a></li> \
				<li><a class=\"action4\" href=\"#\" onclick=\"return CMS_File_Category.deleteCategory("+objCategoryData.intCategoryId.toString()+");\" title=\"Delete\">Delete</a></li> \
			</ul> \
			<div style=\"float:right;\"> \
				<input class=\"radio\" name=\"selectCategory\" id=\"selectCategory"+objCategoryData.intCategoryId.toString()+"\" type=\"checkbox\" value=\""+objCategoryData.intCategoryId.toString()+"\" /> \
				<input name=\"selectCategoryName\" id=\"selectCategoryName"+objCategoryData.intCategoryId.toString()+"\" type=\"hidden\" value=\""+objCategoryData.strName+"\" /> \
			</div> \
		</div>";
		eleRow.appendChild(eleTd9);

		return eleRow;
	},
	
	createEmptyRow:function()
	{
		var eleRow=document.createElement("tr");
		eleRow.id="noRecords";
		
		var eleTd1=document.createElement("td");
		eleTd1.colSpan=3;
		eleTd1.appendChild(document.createTextNode("No categories to display"));
		eleRow.appendChild(eleTd1);
		
		return eleRow;
	}	
}/*--------------------------------------------------
	Project:	The November Group - CMS Administration
	Script:		cms_file_code.js
	Includes:	CMS_File_Code
--------------------------------------------------*/

var CMS_File_Code={
	
	manageCodes:function()
	{
		CMS_Main.setPage("manageFileCodes"); //store page selection

		CMS_Main.objRequest.open("GET","get_page_xml.php?page="+CMS_Main.getPage(),true);
		CMS_Main.objRequest.onreadystatechange=CMS_Main.updatePage;
		CMS_Main.objRequest.send(null);
		
		return false;
	},
	
	addCode:function()
	{
		CMS_Main.objRequest.open("GET","get_page_xml.php?page=editFileCode",true);
		CMS_Main.objRequest.onreadystatechange=CMS_Main.updatePage;
		CMS_Main.objRequest.send(null);
		
		return false;
	},
	
	editCode:function(intCodeId)
	{
		CMS_Main.objRequest.open("GET","get_page_xml.php?page=editFileCode&fCode_id="+intCodeId.toString(),true);
		CMS_Main.objRequest.onreadystatechange=CMS_Main.updatePage;
		CMS_Main.objRequest.send(null);
		
		return false;
	},
	
	editCodeText:function(intCodeId)
	{
		CMS_Main.objRequest.open("GET","get_page_xml.php?page=editFileCodeText&fCode_id="+intCodeId.toString(),true);
		CMS_Main.objRequest.onreadystatechange=CMS_Main.updatePage;
		CMS_Main.objRequest.send(null);
		
		return false;
	},
	
	editCodeInitialize:function(frm)
	{
		this.onTypeChange(frm);
		
		if(frm)
		{
			if(frm.fTitle)
			{
				frm.fTitle.focus();
				frm.fTitle.select();
			}
		}
		return false;
	},
	
	onTypeChange:function(frm)
	{
		if(frm && frm.fType)
		{
			switch(frm.fType.value)
			{
				case("0"):
					document.getElementById("displayCount").style.display="none";
					break;
				case("1"):
					document.getElementById("displayCount").style.display="block";
					break;
				default:
			}
		}
	},
	
	editCodeSubmit:function(frm)
	{
		var blnReturnValue=true;
		
		if(frm.fTitle.value.length==0)
		{
			alert("Please enter a title");
			frm.fTitle.focus();
			blnReturnValue=false;
		}
		else if(frm.fType.value==1 && isNaN(frm.fDisplay_count.value))
		{
			alert("Please enter a valid number");
			frm.fDisplay_count.focus();
			frm.fDisplay_count.select();
			blnReturnValue=false;
		}
		else if(frm.fType.value==1 && frm.fDisplay_count.value==0)
		{
			alert("Please enter a number greater than 0");
			frm.fDisplay_count.focus();
			frm.fDisplay_count.select();
			blnReturnValue=false;
		}
		
		if(blnReturnValue)
		{
			document.getElementById("fSubmit").disabled=true;

			CMS_Main.objRequest.open("POST","get_page_xml.php",true);
			CMS_Main.objRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
			CMS_Main.objRequest.onreadystatechange=CMS_Main.updatePage;
			CMS_Main.objRequest.send(CMS_Main.formEncode(frm)+"&page="+CMS_Main.getPage());
		}
		
		return false;
	},	
	
	editCodeTextSubmit:function(frm)
	{
		var blnReturnValue=true;
		
		if(blnReturnValue)
		{
			document.getElementById("fSubmit").disabled=true;

			CMS_Main.objRequest.open("POST","get_page_xml.php",true);
			CMS_Main.objRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
			CMS_Main.objRequest.onreadystatechange=CMS_Main.updatePage;
			CMS_Main.objRequest.send(CMS_Main.formEncode(frm)+"&page="+CMS_Main.getPage());
		}
		
		return false;
	},	
	
	editCodeCancel:function()
	{
		CMS_Main.objRequest.open("GET","get_page_xml.php?page="+CMS_Main.getPage(),true);
		CMS_Main.objRequest.onreadystatechange=CMS_Main.updatePage;
		CMS_Main.objRequest.send(null);
		
		return false;
	},
	
	deleteCode:function(intCodeId,strTitle)
	{
		if(confirm("Are you sure you want to delete "+strTitle+"?"))
		{
			CMS_Main.objRequest.open("GET","get_page_xml.php?page="+CMS_Main.getPage()+"&fAction=deleteFileCode&fCode_id="+intCodeId,true);
			CMS_Main.objRequest.onreadystatechange=CMS_Main.updatePage;
			CMS_Main.objRequest.send(null);
		}
		
		return false;
	}
}/*--------------------------------------------------
	Project:	The November Group - CMS Administration
	Script:		cms_dynamic_entry.js
	Includes:	CMS_Dynamic_Entry
--------------------------------------------------*/

var CMS_Dynamic_Entry={
	
	objEntryListRequest:null,
	intCurrentFormId:-1,
	blnFilterPublished:true,
	blnFilterNotPublished:true,
	blnFilterArchived:true,
	blnFilterStaging:true,
	strFilterAlpha:"all",
	intCurrentOrderType:0,
	
	//pagination attributes
	intPageNumber:1,

	manageEntriesSelect:function()
	{
		CMS_Main.setPage("manageDynamicEntriesSelect");
		
		CMS_Main.objRequest.open("GET","get_page_xml.php?page="+CMS_Main.getPage(),true);
		CMS_Main.objRequest.onreadystatechange=CMS_Main.updatePage;
		CMS_Main.objRequest.send(null);
		
		return false;
	},
	
	manageEntries:function(intFormId)
	{
		CMS_Main.setPage("manageDynamicEntries");
		
		CMS_Main.objRequest.open("GET","get_page_xml.php?page="+CMS_Main.getPage()+"&fForm_id="+intFormId.toString(),true);
		CMS_Main.objRequest.onreadystatechange=CMS_Main.updatePage;
		CMS_Main.objRequest.send(null);
		
		return false;
	},
	
	manageEntriesInitialize:function(frm)
	{
		if(frm)
		{
			//reselect previously selected filters
			if(document.getElementById("fFilter_published")) document.getElementById("fFilter_published").checked=this.blnFilterPublished;
			if(document.getElementById("fFilter_published_top")) document.getElementById("fFilter_published_top").checked=this.blnFilterPublished;
			if(document.getElementById("fFilter_not_published")) document.getElementById("fFilter_not_published").checked=this.blnFilterNotPublished;
			if(document.getElementById("fFilter_not_published_top")) document.getElementById("fFilter_not_published_top").checked=this.blnFilterNotPublished;
			if(document.getElementById("fFilter_archived")) document.getElementById("fFilter_archived").checked=this.blnFilterArchived;
			if(document.getElementById("fFilter_archived_top")) document.getElementById("fFilter_archived_top").checked=this.blnFilterArchived;
			if(document.getElementById("fFilter_staging")) document.getElementById("fFilter_staging").checked=this.blnFilterStaging;
			if(document.getElementById("fFilter_staging_top")) document.getElementById("fFilter_staging_top").checked=this.blnFilterStaging;

			frm.fFilter_alpha.value=this.strFilterAlpha;
			
			//alpha
			if(document.getElementById("filterAlpha"))
			{
				var arrLinks=document.getElementById("filterAlpha").getElementsByTagName("a");
				for(var i=0;i<arrLinks.length;i++)
				{
					if(arrLinks[i].firstChild.firstChild.firstChild.nodeValue.toLowerCase()==frm.fFilter_alpha.value.toString())
					{
						arrLinks[i].className+=" current_page";
						break;
					}
				}
			}
			if(document.getElementById("filterAlphaTop"))
			{
				var arrLinks=document.getElementById("filterAlphaTop").getElementsByTagName("a");
				for(var i=0;i<arrLinks.length;i++)
				{
					if(arrLinks[i].firstChild.firstChild.firstChild.nodeValue.toLowerCase()==frm.fFilter_alpha.value.toString())
					{
						arrLinks[i].className+=" current_page";
						break;
					}
				}
			}
			
			//reselect previously selected show count
			var blnSelected=false;
			if(document.getElementById("fShow_count"))
			{
				var eleSelect2=document.getElementById("fShow_count");
				for(var i=0;i<eleSelect2.options.length;i++)
				{
					if(Number(eleSelect2.options[i].value)==CMS_Client_User_Settings.getShowCountDynamicEntries())
					{
						eleSelect2.options[i].selected=true;
						blnSelected=true;
						break;
					}
				}
				if(!blnSelected)
				{
					eleSelect2.options[0].selected=true;
					CMS_Client_User_Settings.setShowCountDynamicEntries(Number(eleSelect2.options[0].value));
				}
			}
			blnSelected=false;
			if(document.getElementById("fShow_count_top"))
			{
				var eleSelect2=document.getElementById("fShow_count_top");
				for(var i=0;i<eleSelect2.options.length;i++)
				{
					if(Number(eleSelect2.options[i].value)==CMS_Client_User_Settings.getShowCountDynamicEntries())
					{
						eleSelect2.options[i].selected=true;
						blnSelected=true;
						break;
					}
				}
				if(!blnSelected)
				{
					eleSelect2.options[0].selected=true;
					CMS_Client_User_Settings.setShowCountDynamicEntries(Number(eleSelect2.options[0].value));
				}
			}

			//retrieve previously selected page number
			if(frm.fPage_number)
				frm.fPage_number.value=this.intPageNumber.toString();
			
			//enable or disable "publish entries" option
			if(document.getElementById("fAction_index"))
			{
				var eleSelect2=document.getElementById("fAction_index");
				for(var i=0;i<eleSelect2.length;i++)
				{
					if(eleSelect2.options[i].value==2)
					{
						if(CMS_Client_User_Settings.canPublishDynamicEntries())
						{
							eleSelect2.options[i].disabled=false;
						}
						else
						{
							if(eleSelect2.options[i].selected)
								eleSelect2.options[0].selected=true;
								
							//disable option
							eleSelect2.options[i].disabled=true;
						}
						break;
					}
				}
			}
			if(document.getElementById("fAction_index_top"))
			{
				var eleSelect2=document.getElementById("fAction_index_top");
				for(var i=0;i<eleSelect2.length;i++)
				{
					if(eleSelect2.options[i].value==2)
					{
						if(CMS_Client_User_Settings.canPublishDynamicEntries())
						{
							eleSelect2.options[i].disabled=false;
						}
						else
						{
							if(eleSelect2.options[i].selected)
								eleSelect2.options[0].selected=true;
								
							//disable option
							eleSelect2.options[i].disabled=true;
						}
						break;
					}
				}
			}
			
			this.onCategoryOrFilterChange(frm);
		}
	},
	
	onCategoryOrFilterChange:function(frm)
	{
		this.intCurrentFormId=document.getElementById("fForm_id").value;
		
		this.getEntryList(frm);
	},

	onFilterPublishedClick:function(frm,eleInput)
	{
		this.blnFilterPublished=eleInput.checked;

		if(document.getElementById("fFilter_published"))
			document.getElementById("fFilter_published").checked=eleInput.checked;
		if(document.getElementById("fFilter_published_top"))
			document.getElementById("fFilter_published_top").checked=eleInput.checked;
		
		this.onCategoryOrFilterChange(frm);
	},
	
	onFilterNotPublishedClick:function(frm,eleInput)
	{
		this.blnFilterNotPublished=eleInput.checked;

		if(document.getElementById("fFilter_not_published"))
			document.getElementById("fFilter_not_published").checked=eleInput.checked;
		if(document.getElementById("fFilter_not_published_top"))
			document.getElementById("fFilter_not_published_top").checked=eleInput.checked;
		
		this.onCategoryOrFilterChange(frm);
	},
	
	onFilterArchivedClick:function(frm,eleInput)
	{
		this.blnFilterArchived=eleInput.checked;

		if(document.getElementById("fFilter_archived"))
			document.getElementById("fFilter_archived").checked=eleInput.checked;
		if(document.getElementById("fFilter_archived_top"))
			document.getElementById("fFilter_archived_top").checked=eleInput.checked;
		
		this.onCategoryOrFilterChange(frm);
	},
	
	onFilterStagingClick:function(frm,eleInput)
	{
		this.blnFilterStaging=eleInput.checked;

		if(document.getElementById("fFilter_staging"))
			document.getElementById("fFilter_staging").checked=eleInput.checked;
		if(document.getElementById("fFilter_staging_top"))
			document.getElementById("fFilter_staging_top").checked=eleInput.checked;
		
		this.onCategoryOrFilterChange(frm);
	},
	
	onAlphaClick:function(frm,eleA)
	{
		if(frm && eleA)
		{
			frm.fFilter_alpha.value=eleA.firstChild.firstChild.firstChild.nodeValue.toLowerCase(); //retrieve selected value
			this.strFilterAlpha=frm.fFilter_alpha.value.toString();

			//reset classes
			if(document.getElementById("filterAlpha"))
			{
				var arrLinks=document.getElementById("filterAlpha").getElementsByTagName("a");
				for(var i=0;i<arrLinks.length;i++)
				{
					if(arrLinks[i].className.indexOf("current_page")>-1)
						arrLinks[i].className=arrLinks[i].className.replace("current_page","");
					if(arrLinks[i].firstChild.firstChild.firstChild.nodeValue.toLowerCase()==frm.fFilter_alpha.value)
						arrLinks[i].className+=" current_page";
				}
			}
			if(document.getElementById("filterAlphaTop"))
			{
				var arrLinks=document.getElementById("filterAlphaTop").getElementsByTagName("a");
				for(var i=0;i<arrLinks.length;i++)
				{
					if(arrLinks[i].className.indexOf("current_page")>-1)
						arrLinks[i].className=arrLinks[i].className.replace("current_page","");
					if(arrLinks[i].firstChild.firstChild.firstChild.nodeValue.toLowerCase()==frm.fFilter_alpha.value)
						arrLinks[i].className+=" current_page";
				}
			}
			
			//update filter
			CMS_Dynamic_Entry.onCategoryOrFilterChange(frm);
		}
		
		return false; //cancel link
	},
	
	onShowCountChange:function(frm,eleSelect)
	{
		if(frm)
		{
			var intPages=1;

			if(document.getElementById("fShow_count"))
			{
				var eleSelect2=document.getElementById("fShow_count");
				for(var i=0;i<eleSelect2.options.length;i++)
				{
					if(Number(eleSelect2.options[i].value)==Number(eleSelect.options[eleSelect.selectedIndex].value))
						eleSelect2.options[i].selected=true;
				}
			}
			if(document.getElementById("fShow_count_top"))
			{
				var eleSelect2=document.getElementById("fShow_count_top");
				for(var i=0;i<eleSelect2.options.length;i++)
				{
					if(Number(eleSelect2.options[i].value)==Number(eleSelect.options[eleSelect.selectedIndex].value))
						eleSelect2.options[i].selected=true;
				}
			}
			
			CMS_Client_User_Settings.setShowCountDynamicEntries(Number(eleSelect.value)); //store selected value
			
			//calculate number of pages
			if(Number(eleSelect.value)>0)
				intPages=Math.ceil(Number(frm.fEntry_count.value)/Number(eleSelect.value));
			if(intPages==0)
				intPages++;
			
			//check if current page number will exist for new show count
			if(Number(frm.fPage_number.value)>intPages)
				frm.fPage_number.value="1"; //reset page number
			
			this.getEntryList(frm);
		}
	},
	
	onPageClick:function(frm,eleNumber)
	{
		if(frm && eleNumber)
		{
			frm.fPage_number.value=eleNumber.firstChild.firstChild.firstChild.nodeValue; //retrieve selected value
			this.getEntryList(frm);
		}
		return false;
	},
	
	updatePagination:function(frm)
	{
		if(frm && frm.fShow_count)
		{
			var intPages=1;
			
			//calculate number of pages
			if(Number(frm.fShow_count.value)>0)
				intPages=Math.ceil(Number(frm.fEntry_count.value)/Number(frm.fShow_count.value));
			if(intPages==0)
				intPages++;
			
			//rebuild page links
			if(document.getElementById("filterPage"))
			{
				document.getElementById("filterPage").innerHTML="";
				for(var i=0;i<intPages;i++)
					document.getElementById("filterPage").innerHTML+="<li><a href=\"#\" onclick=\"return CMS_Dynamic_Entry.onPageClick(document.getElementById('frmManageDynamicEntries'),this);\"><span><span>"+(i+1).toString()+"</span></span></a></li>";
			}
			if(document.getElementById("filterPageTop"))
			{
				document.getElementById("filterPageTop").innerHTML="";
				for(var i=0;i<intPages;i++)
					document.getElementById("filterPageTop").innerHTML+="<li><a href=\"#\" onclick=\"return CMS_Dynamic_Entry.onPageClick(document.getElementById('frmManageDynamicEntries'),this);\"><span><span>"+(i+1).toString()+"</span></span></a></li>";
			}
			
			//select page link
			var blnSelected=false;
			if (document.getElementById("filterPage")) 
			{
				var arrLinks=document.getElementById("filterPage").getElementsByTagName("a");
				for(var i=0;i<arrLinks.length;i++)
				{
					if(arrLinks[i].firstChild.firstChild.firstChild.nodeValue==frm.fPage_number.value.toString())
					{
						//change class
						arrLinks[i].className+=" current_page";
						blnSelected=true;
						break;
					}
				}
				if(!blnSelected)
				{
					arrLinks[0].className+=" current_page";
					frm.fPage_number.value=arrLinks[0].firstChild.firstChild.firstChild.nodeValue;
				}
			}
			blnSelected=false;
			if (document.getElementById("filterPageTop")) 
			{
				var arrLinks=document.getElementById("filterPageTop").getElementsByTagName("a");
				for(var i=0;i<arrLinks.length;i++)
				{
					if(arrLinks[i].firstChild.firstChild.firstChild.nodeValue==frm.fPage_number.value.toString())
					{
						//change class
						arrLinks[i].className+=" current_page";
						blnSelected=true;
						break;
					}
				}
				if(!blnSelected)
				{
					arrLinks[0].className+=" current_page";
					frm.fPage_number.value=arrLinks[0].firstChild.firstChild.firstChild.nodeValue;
				}
			}

			//store selected value
			this.intPageNumber=Number(frm.fPage_number.value);
			
			//calculate entry count
			var intCountStart=(Number(frm.fPage_number.value)-1)*Number(frm.fShow_count.value);
			var intCountEnd=(Number(frm.fShow_count.value)==0 ? Number(frm.fEntry_count.value) : Math.min(Number(frm.fShow_count.value)+intCountStart,Number(frm.fEntry_count.value)));
			
			//update entry count
			if(document.getElementById("entryCountStart"))
				document.getElementById("entryCountStart").innerHTML=(Math.min(intCountStart+1,Number(frm.fEntry_count.value))).toString();
			if(document.getElementById("entryCountEnd"))
				document.getElementById("entryCountEnd").innerHTML=intCountEnd.toString();
			if(document.getElementById("entryCount"))
				document.getElementById("entryCount").innerHTML=frm.fEntry_count.value.toString();

			if(document.getElementById("entryCountStartTop"))
				document.getElementById("entryCountStartTop").innerHTML=(Math.min(intCountStart+1,Number(frm.fEntry_count.value))).toString();
			if(document.getElementById("entryCountEndTop"))
				document.getElementById("entryCountEndTop").innerHTML=intCountEnd.toString();
			if(document.getElementById("entryCountTop"))
				document.getElementById("entryCountTop").innerHTML=frm.fEntry_count.value.toString();
		}
	},
	
	getEntryList:function(frm)
	{
		var strHtml="";
		
		//clear select all
		if(document.getElementById("selectAll"))
			document.getElementById("selectAll").checked=false;
		
		//clear entry list
		while(document.getElementById("entryListContainer").firstChild)
			document.getElementById("entryListContainer").removeChild(document.getElementById("entryListContainer").firstChild);
		
		//add loading message
		var eleLoading=document.createElement("tr");
		
		eleLoading.appendChild(document.createElement("td"));
		eleLoading.childNodes[0].colSpan=4;
		eleLoading.childNodes[0].appendChild(document.createTextNode(CMS_Main.getLoadingMessage()));
		document.getElementById("entryListContainer").appendChild(eleLoading);
		
		//get entry list
		this.objEntryListRequest=CMS_Main.createRequest();
		this.objEntryListRequest.open("GET","get_element_xml.php?function=getDynamicEntryListJson&fForm_id="+CMS_Dynamic_Entry.intCurrentFormId.toString()+"&fFilter_published="+(CMS_Dynamic_Entry.blnFilterPublished ? "1" : "0")+"&fFilter_not_published="+(CMS_Dynamic_Entry.blnFilterNotPublished ? "1" : "0")+"&fFilter_archived="+(CMS_Dynamic_Entry.blnFilterArchived ? "1" : "0")+"&fFilter_staging="+(CMS_Dynamic_Entry.blnFilterStaging ? "1" : "0")+"&fFilter_alpha="+encodeURIComponent(CMS_Dynamic_Entry.strFilterAlpha)+"&fShow_count="+frm.fShow_count.value.toString()+"&fPage_number="+frm.fPage_number.value.toString(),true);
		this.objEntryListRequest.onreadystatechange=function(){
			if(CMS_Dynamic_Entry.objEntryListRequest.readyState==4)
			{
				if(CMS_Dynamic_Entry.objEntryListRequest.status==200)
				{
					//clear loading message
					while(document.getElementById("entryListContainer").firstChild)
						document.getElementById("entryListContainer").removeChild(document.getElementById("entryListContainer").firstChild);
					
					//var arrEntryData=eval("("+CMS_Dynamic_Entry.objEntryListRequest.responseText+")");
					var objEntryData=eval("("+CMS_Dynamic_Entry.objEntryListRequest.responseText+")");
					document.getElementById("fEntry_count").value=objEntryData.intEntryCount.toString();
					
					//store order type
					CMS_Dynamic_Entry.intCurrentOrderType=objEntryData.intOrderType;
					
					//add rows
					for(i in objEntryData.arrEntries)
					{
						var eleRow=CMS_Dynamic_Entry.createRow(objEntryData.arrEntries[i]);
						
						if(i%2==0)
							eleRow.className="first";
						else
							eleRow.className="second";

						document.getElementById("entryListContainer").appendChild(eleRow);
					}
					
					if(objEntryData.arrEntries.length==0)
					{
						var eleRow=CMS_Dynamic_Entry.createEmptyRow();
						document.getElementById("entryListContainer").appendChild(eleRow);
					}
					
					CMS_Dynamic_Entry.initializeOrder(document.getElementById("frmManageDynamicEntries"));
					CMS_Dynamic_Entry.updatePagination(document.getElementById("frmManageDynamicEntries"));
				}
			}
		};
		this.objEntryListRequest.send(null);
		
		return false;
	},
	
	initializeOrder:function(frm)
	{
		blnDisabled=true; //default value
		
		if(frm && frm.fForm_id)
		{
			//check form selection
			if(CMS_Dynamic_Entry.intCurrentOrderType==8 && frm.fForm_id.value > 0)
			{
				//check filter selection
				if(frm.fFilter_published.checked && frm.fFilter_not_published.checked && frm.fFilter_archived.checked && frm.fFilter_alpha.value.toLowerCase()=="all")
				{
					//check pagination list
					if(Number(frm.fShow_count.value)==0 || Number(frm.fEntry_count.value)<=Number(frm.fShow_count.value)) //show count is "all" or greater than entry count
					{
						blnDisabled=false;
						
						//initialize the drag drop
						$("#entryListContainer").tableDnD();
					}
				}
			}
			
			//enable or disable "save current file order" option
			//frm.saveOrder.disabled=blnDisabled;
		}
	},
	
	createRow:function(objEntryData)
	{
		var eleRow=document.createElement("tr");
		
		var eleTd1=document.createElement("td");
		eleTd1.appendChild(document.createTextNode(objEntryData.strTitle));
		eleRow.appendChild(eleTd1);
		
		var eleTd2=document.createElement("td");
		eleTd2.appendChild(document.createTextNode(objEntryData.strDateCreated));
		eleRow.appendChild(eleTd2);
		
		var eleTd4=document.createElement("td");
		eleTd4.appendChild(document.createTextNode(objEntryData.strStatus));
		eleRow.appendChild(eleTd4);
		
		var eleTd5=document.createElement("td");
		eleTd5.style.width="96px";
		eleTd5.innerHTML=" \
		<div class=\"actions\"> \
			<ul> \
				"+(objEntryData.blnUserCanEdit ? " \
					<li><a class=\"action5\" href=\"#\" onclick=\"return CMS_Dynamic_Entry.editEntry("+objEntryData.intEntryId.toString()+","+objEntryData.intFormId.toString()+");\" title=\"Edit\">Edit</a></li> \
					"+(objEntryData.blnStagingAreaCopyExists ? "<li><a class=\"action6\" href=\"#\" onclick=\"return CMS_Dynamic_Entry.editEntry("+objEntryData.intEntryId.toString()+","+objEntryData.intFormId.toString()+",true);\" title=\"Edit copy\">Edit copy</a></li>" : "")+" \
				" : "")+" \
				"+(objEntryData.blnLocked ? "<li><a class=\"action12\" href=\"#\" onclick=\"return false;\" title=\"Locked\">Locked</a></li>" : (objEntryData.blnUserCanDelete ? "<li><a class=\"action4\" href=\"#\" onclick=\"return CMS_Dynamic_Entry.deleteEntry("+objEntryData.intFormId.toString()+","+objEntryData.intEntryId.toString()+");\" title=\"Delete\">Delete</a></li>" : ""))+" \
			</ul> \
			<div style=\"float:right;\"> \
				<input class=\"radio\" name=\"selectEntry\" id=\"selectEntry"+objEntryData.intEntryId.toString()+"\" type=\"checkbox\" value=\""+objEntryData.intEntryId.toString()+"\" /> \
				<input name=\"selectEntryTitle\" id=\"selectEntryTitle"+objEntryData.intEntryId.toString()+"\" type=\"hidden\" value=\""+objEntryData.strTitle+"\" /> \
			</div> \
		</div>";
		eleRow.appendChild(eleTd5);
		
		return eleRow;
	},
	
	createEmptyRow:function()
	{
		var eleRow=document.createElement("tr");
		
		var eleTd1=document.createElement("td");
		eleTd1.colSpan=4;
		eleTd1.appendChild(document.createTextNode("No entries to display"));
		eleRow.appendChild(eleTd1);
		
		return eleRow;
	},
	
	selectAllClick:function(frm)
	{
		for(var i=0;i<frm.length;i++)
			if(frm.elements[i].name && frm.elements[i].name.indexOf("selectEntry")==0)
				frm.elements[i].checked=true;
		return false;
	},
	
	deselectAllClick:function(frm)
	{
		for(var i=0;i<frm.length;i++)
			if(frm.elements[i].name && frm.elements[i].name.indexOf("selectEntry")==0)
				frm.elements[i].checked=false;
		return false;
	},
	
	onActionChange:function(frm,eleSelect,eleContainer)
	{
		if(frm && eleSelect)
		{
			switch(Number(eleSelect.value))
			{
				case(4): //copy
					eleContainer.style.display="inline";
					break;
				default:
					eleContainer.style.display="none";
			}
		}
	},
	
	onActionClick:function(frm,eleSelect)
	{
		if(frm && eleSelect)
		{
			switch(Number(eleSelect.value))
			{
				case(1): //delete
					this.deleteEntries(frm);
					break;
				case(2): //publish
					this.publishEntries(frm);
					break;
				case(3): //archive
					this.archiveEntries(frm);
					break;
				case(4): //copy
					this.copyEntries(frm);
					break;
				default:
			}
		}
		return false; //cancel link
	},
	
	deleteEntries:function(frm)
	{
		var arrEntryIds=new Array();
		var arrEntryTitles=new Array();
		
		for(var i=0;i<frm.length;i++)
		{
			if(frm.elements[i].name && frm.elements[i].name.indexOf("selectEntry")==0 && frm.elements[i].type=="checkbox" && frm.elements[i].checked)
			{
				arrEntryIds[arrEntryIds.length]=frm.elements[i].value;
				arrEntryTitles[arrEntryTitles.length]=frm.elements[i+1].value;
			}
		}
		if(arrEntryIds.length==0)
		{
			alert("You do not have any entries selected.");
		}
		else if(confirm("Are you sure you want to delete "+(arrEntryIds.length==1 ? arrEntryTitles[0]+"?" : "the following entries?\n\n\t"+arrEntryTitles.join("\n\t")+"\n ")))
		{
			CMS_Main.objRequest.open("POST","get_page_xml.php",true);
			CMS_Main.objRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
			CMS_Main.objRequest.onreadystatechange=CMS_Main.updatePage;
			CMS_Main.objRequest.send("page="+CMS_Main.getPage()+"&fForm_id="+frm.fForm_id.value.toString()+"&fAction=deleteDynamicEntries&fEntry_id[]="+arrEntryIds.join("&fEntry_id[]="));
		}
		
		return false;
	},
	
	publishEntries:function(frm)
	{
		var arrEntryIds=new Array();
		var arrEntryTitles=new Array();
		
		for(var i=0;i<frm.length;i++)
		{
			if(frm.elements[i].name && frm.elements[i].name.indexOf("selectEntry")==0 && frm.elements[i].type=="checkbox" && frm.elements[i].checked)
			{
				arrEntryIds[arrEntryIds.length]=frm.elements[i].value;
				arrEntryTitles[arrEntryTitles.length]=frm.elements[i+1].value;
			}
		}
		if(arrEntryIds.length==0)
		{
			alert("You do not have any entries selected.");
		}
		else if(confirm("Are you sure you want to publish "+(arrEntryIds.length==1 ? arrEntryTitles[0]+"?" : "the following entries?\n\n\t"+arrEntryTitles.join("\n\t")+"\n ")))
		{
			CMS_Main.objRequest.open("POST","get_page_xml.php",true); //must be a POST submit or URL can exceed length limit when there are many records
			CMS_Main.objRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
			CMS_Main.objRequest.onreadystatechange=CMS_Main.updatePage;
			CMS_Main.objRequest.send("page="+CMS_Main.getPage()+"&fForm_id="+frm.fForm_id.value.toString()+"&fAction=publishDynamicEntries&fEntry_id[]="+arrEntryIds.join("&fEntry_id[]="));
		}
		
		return false;
	},
	
	archiveEntries:function(frm)
	{
		var arrEntryIds=new Array();
		var arrEntryTitles=new Array();
		
		for(var i=0;i<frm.length;i++)
		{
			if(frm.elements[i].name && frm.elements[i].name.indexOf("selectEntry")==0 && frm.elements[i].type=="checkbox" && frm.elements[i].checked)
			{
				arrEntryIds[arrEntryIds.length]=frm.elements[i].value;
				arrEntryTitles[arrEntryTitles.length]=frm.elements[i+1].value;
			}
		}
		if(arrEntryIds.length==0)
		{
			alert("You do not have any entries selected.");
		}
		else if(confirm("Are you sure you want to archive "+(arrEntryIds.length==1 ? arrEntryTitles[0]+"?" : "the following entries?\n\n\t"+arrEntryTitles.join("\n\t")+"\n ")))
		{
			CMS_Main.objRequest.open("POST","get_page_xml.php",true);
			CMS_Main.objRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
			CMS_Main.objRequest.onreadystatechange=CMS_Main.updatePage;
			CMS_Main.objRequest.send("page="+CMS_Main.getPage()+"&fForm_id="+frm.fForm_id.value.toString()+"&fAction=archiveDynamicEntries&fEntry_id[]="+arrEntryIds.join("&fEntry_id[]="));
		}
		
		return false;
	},
	
	copyEntries:function(frm)
	{
		var arrEntryIds=new Array();
		var arrEntryTitles=new Array();
		
		for(var i=0;i<frm.length;i++)
		{
			if(frm.elements[i].name && frm.elements[i].name.indexOf("selectEntry")==0 && frm.elements[i].type=="checkbox" && frm.elements[i].checked)
			{
				arrEntryIds[arrEntryIds.length]=frm.elements[i].value;
				arrEntryTitles[arrEntryTitles.length]=frm.elements[i+1].value;
			}
		}
		if(arrEntryIds.length==0)
		{
			alert("You do not have any entries selected.");
		}
		else if(confirm("Are you sure you want to copy "+(arrEntryIds.length==1 ? arrEntryTitles[0]+" to "+frm.fForm_destination_id.options[frm.fForm_destination_id.selectedIndex].text+"?" : "the following entries to "+frm.fForm_destination_id.options[frm.fForm_destination_id.selectedIndex].text+"?\n\n\t"+arrEntryTitles.join("\n\t")+"\n ")))
		{
			CMS_Main.objRequest.open("POST","get_page_xml.php",true);
			CMS_Main.objRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
			CMS_Main.objRequest.onreadystatechange=CMS_Main.updatePage;
			CMS_Main.objRequest.send("page="+CMS_Main.getPage()+"&fForm_id="+frm.fForm_id.value.toString()+"&fAction=copyDynamicEntries&fForm_destination_id="+frm.fForm_destination_id.value.toString()+"&fEntry_id[]="+arrEntryIds.join("&fEntry_id[]="));
		}
		
		return false;
	},
	
	saveOrder:function(frm)
	{
		var arrEntryIds=new Array();
		var arrEntryTitles=new Array();
		
		if(frm && frm.fForm_id && Number(frm.fForm_id.value)>0)
		{
			for(var i=0;i<frm.length;i++)
			{
				if(frm.elements[i].name && frm.elements[i].name.indexOf("selectEntry")==0 && frm.elements[i].type=="checkbox")
				{
					arrEntryIds[arrEntryIds.length]=frm.elements[i].value;
					arrEntryTitles[arrEntryTitles.length]=frm.elements[i+1].value;
				}
			}
			if(arrEntryIds.length==0)
			{
				alert("There are no entries for this form.");
			}
			else
			{
				CMS_Main.objRequest.open("POST","get_page_xml.php",true);
				CMS_Main.objRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
				CMS_Main.objRequest.onreadystatechange=CMS_Main.updatePage;
				CMS_Main.objRequest.send("page="+CMS_Main.getPage()+"&fAction=saveOrder&fForm_id="+frm.fForm_id.value.toString()+"&fEntry_id[]="+arrEntryIds.join("&fEntry_id[]="));
			}
		}
		
		return false;
	},
	
	addEntry:function(intFormId)
	{
		CMS_Main.objRequest.open("GET","get_page_xml.php?page=editDynamicEntry&fForm_id="+intFormId.toString(),true);
		CMS_Main.objRequest.onreadystatechange=CMS_Main.updatePage;
		CMS_Main.objRequest.send(null);
		
		return false;
	},	
	
	deleteEntry:function(intFormId,intEntryId)
	{
		var strTitle=document.getElementById("selectEntryTitle"+intEntryId).value.toString();
		
		if(confirm("Are you sure you want to delete "+strTitle+"?"))
		{
			CMS_Main.objRequest.open("GET","get_page_xml.php?page="+CMS_Main.getPage()+"&fForm_id="+intFormId.toString()+"&fAction=deleteDynamicEntry&fEntry_id="+intEntryId.toString(),true);
			CMS_Main.objRequest.onreadystatechange=CMS_Main.updatePage;
			CMS_Main.objRequest.send(null);
		}
		
		return false;
	},
	
	editEntry:function(intEntryId,intFormId,blnUseStagingAreaCopy)
	{
		CMS_Main.objRequest.open("GET","get_page_xml.php?page=editDynamicEntry&fEntry_id="+intEntryId.toString()+"&fForm_id="+intFormId.toString()+(blnUseStagingAreaCopy ? "&fUse_staging_area_copy=1" : ""),true);
		CMS_Main.objRequest.onreadystatechange=CMS_Main.updatePage;
		CMS_Main.objRequest.send(null);
		
		return false;
	},
	
	
	editEntryInitialize:function(frm)
	{
		if(frm)
		{
			//reset file request variables
			this.arrFileSelectFieldId=new Array();
			this.arrValidFileRequest=new Array();
			this.intSizeUploadingTotal=0;
			this.intUploadCount=0;
			this.arrUploadCount=new Array();
			
			CMS_File.preloadProgressImages();

			//insert date-time select boxes
			if(document.getElementById("fDate_start"))
			{
				DTS.insert("fDate_start",DTS.intTypeDateOnly);
				this.onDateEnabledClick(frm.fDate_start_enabled,"dateStart");
			}
			if(document.getElementById("fDate_end"))
			{
				DTS.insert("fDate_end",DTS.intTypeDateOnly);
				this.onDateEnabledClick(frm.fDate_end_enabled,"dateEnd");
			}
			if(document.getElementById("fDisplay_date_start"))
			{
				DTS.insert("fDisplay_date_start",DTS.intTypeDateOptional);
				this.onDateEnabledClick(frm.fDisplay_date_start_enabled,"displayDateStart");
			}
			if(document.getElementById("fDisplay_date_end"))
			{
				DTS.insert("fDisplay_date_end",DTS.intTypeDateOptional);
				this.onDateEnabledClick(frm.fDisplay_date_end_enabled,"displayDateEnd");
			}
			
			//initialize necessary fields
			if(frm.fField_id)
			{
				var arrFieldIds=new Array();
				if(frm.fField_id && frm.fField_id.length)
					for(var i=0;i<frm.fField_id.length;i++)
						arrFieldIds.push(frm.fField_id[i].value);
				else if(frm.fField_id) //if there is only one field, then frm.fField_id is not an array
					arrFieldIds.push(frm.fField_id.value);
				
				for(var i=0;i<arrFieldIds.length;i++)
				{
					if(document.getElementById("fField_text_editor"+arrFieldIds[i].toString())) //initialize text editor
					{
						CMS_Main.textEditorInit("fField_text_editor"+arrFieldIds[i].toString());
					}
					else if(document.getElementById("fField_count_down_date"+arrFieldIds[i].toString())) //initialize count down date
					{
						DTS.insert("fField_count_down_date"+arrFieldIds[i].toString(),DTS.intTypeDateRequired);
						this.onDateEnabledClick(frm.elements["fField_count_down_date_enabled"+arrFieldIds[i].toString()],"countDownDate"+arrFieldIds[i].toString());
						this.onRepeatClick(frm.elements["fField_count_down_repeat"+arrFieldIds[i].toString()],"countDownRepeatOptions"+arrFieldIds[i].toString());
					}
					else if(document.getElementById("eleUploader"+arrFieldIds[i].toString())) //initialize uploader
					{
						//move the uploader in the DOM (so IE will correctly observe the the z-index property)
						document.getElementsByTagName("body")[0].insertBefore(document.getElementById("eleUploader"+arrFieldIds[i].toString()),document.getElementsByTagName("body")[0].firstChild);
						
						//instantiate uploader
						YAHOO.widget.Uploader.SWFURL=CMS_File.getUploaderSWFURL();
						document.getElementById("eleUploader"+arrFieldIds[i].toString()).innerHTML=CMS_File.strUploaderInitialContent;
						this.arrUploader[arrFieldIds[i]]=new YAHOO.widget.Uploader("eleUploader"+arrFieldIds[i].toString());
						
						this.hideUploader(arrFieldIds[i]);
			
						//set uploader event handlers
						this.arrUploader[arrFieldIds[i]].addListener("contentReady",this.onContentReady);
						this.arrUploader[arrFieldIds[i]].addListener('fileSelect',this.onFileSelect);
						this.arrUploader[arrFieldIds[i]].addListener('uploadStart',this.onUploadStart);
						this.arrUploader[arrFieldIds[i]].addListener('uploadProgress',this.onUploadProgress);
						this.arrUploader[arrFieldIds[i]].addListener('uploadCancel',this.onUploadCancel);
						this.arrUploader[arrFieldIds[i]].addListener('uploadComplete',this.onUploadComplete);
						this.arrUploader[arrFieldIds[i]].addListener('uploadCompleteData',this.onUploadCompleteData);
						this.arrUploader[arrFieldIds[i]].addListener('uploadError',this.onUploadError);
						//set more uploader event handlers
						this.arrUploader[arrFieldIds[i]].addListener("rollOver",this.onRollOver);
						this.arrUploader[arrFieldIds[i]].addListener("rollOut",this.onRollOut);
						this.arrUploader[arrFieldIds[i]].addListener("click",this.onClick);
						
						this.arrUploader[arrFieldIds[i]].intFieldId=arrFieldIds[i]; //create object attribute to store field id
						this.arrUploadCount[arrFieldIds[i]]=0;
					}
				}
			}

			this.onPublishedClick(frm.fPublished);
			
			//remove and store the file attachment form
			if(document.getElementById("fileAttach"))
			{
				this.eleFileAttach=document.getElementById("fileAttach").parentNode.removeChild(document.getElementById("fileAttach"));
				this.eleFileAttach.style.display="block";
			}
			
			frm.fTitle.focus();
			frm.fTitle.select();
		}
		
		return false;
	},
	
	onPublishedClick:function(eleInput)
	{
		if(document.getElementById("unpublishOptions"))
		{
			if(eleInput.checked)
			{
				document.getElementById("unpublishOptions").style.display="none";
			}
			else
			{
				try
				{
					document.getElementById("unpublishOptions").style.display="table-row";
				}
				catch(e)
				{
					document.getElementById("unpublishOptions").style.display="block";
				}
			}
		}
	},

	onTextChange:function(eleInput,intMaxLength,blnNumeric)
	{
		if(intMaxLength > 0 && eleInput.value.length > intMaxLength)
			eleInput.value=eleInput.value.substr(0,intMaxLength);
		if(blnNumeric && isNaN(eleInput.value))
			eleInput.value=0;
	},
	
	onDateEnabledClick:function(eleInput,strId)
	{
		//DTS.disabled(strId,!eleInput.checked);
		if(document.getElementById(strId))
			if(eleInput.checked)
				document.getElementById(strId).style.display="inline";
			else
				document.getElementById(strId).style.display="none";
		
		return true;
	},
	
	onRepeatClick:function(eleInput,strId)
	{
		if(document.getElementById(strId))
			if(eleInput.checked)
				document.getElementById(strId).style.display="block";
			else
				document.getElementById(strId).style.display="none";
		
		return true;
	},
	
	urlTargetIdChange:function(eleSelect)
	{
		var strId="";
		
		if(eleSelect)
		{
			strId=eleSelect.id.replace("fField_url_target_id","");
			
			if(Number(eleSelect.value)==1)
			{
				if(document.getElementById("urlOptionsOther"+strId))
					document.getElementById("urlOptionsOther"+strId).style.display="inline";
			}
			else
			{
				if(document.getElementById("urlOptionsOther"+strId))
					document.getElementById("urlOptionsOther"+strId).style.display="none";
			}
		}
	},
	
	categorySelectTypeChange:function(eleSelectType,eleSelectCategory)
	{
		if(eleSelectType && eleSelectCategory)
		{
			var intTypeId=Number(eleSelectType.value);
			
			//clear options
			while(eleSelectCategory.options.length>0)
				eleSelectCategory.remove(0);
			
			if(eleSelectType.value>0)
			{
				var eleOptionLoading=document.createElement("option");
				eleOptionLoading.text=CMS_Main.getLoadingMessage();
				eleOptionLoading.value="0";
				try{
					eleSelectCategory.add(eleOptionLoading,null);
				}catch(e){
					eleSelectCategory.add(eleOptionLoading);
				}
				
				var objRequest=CMS_Main.createRequest();
				objRequest.open("GET",CMS_Main.getRootDirectory()+"/get_element_xml.php?function=getCategorySelectorCategoryList&fField_category_selector_type_id="+intTypeId.toString(),true);
				objRequest.onreadystatechange=function()
				{
					if(objRequest.readyState==4 && objRequest.status==200)
					{
						//clear loading message
						while(eleSelectCategory.options.length>0)
							eleSelectCategory.remove(0);
				
						objRequestData=eval("("+objRequest.responseText+")");
						
						//add blank option
						var eleOption=document.createElement("option");
						eleOption.value="0";
						eleOption.text=" ";
						try{
							eleSelectCategory.add(eleOption,null);
						}catch(e){
							eleSelectCategory.add(eleOption);
						}
										
						//add categories
						for(var i=0;i<objRequestData.arrCategories.length;i++)
						{
							var eleOption=document.createElement("option");
							eleOption.value=objRequestData.arrCategories[i].intCategoryId;
							eleOption.text=objRequestData.arrCategories[i].strCategoryName;
							try{
								eleSelectCategory.add(eleOption,null);						
							}catch(e){
								eleSelectCategory.add(eleOption);						
							}
						}
					}
				};
				objRequest.send(null);
			}
		}
	},
	
	entrySelectTypeChange:function(eleSelectType,eleSelectCategory,eleSelectEntry)
	{
		if(eleSelectType && eleSelectCategory && eleSelectEntry)
		{
			var intTypeId=Number(eleSelectType.value);
			
			//clear options
			while(eleSelectCategory.options.length>0)
				eleSelectCategory.remove(0);
			while(eleSelectEntry.options.length>0)
				eleSelectEntry.remove(0);
			
			if(eleSelectType.value>0)
			{
				var eleOptionLoading=document.createElement("option");
				eleOptionLoading.text=CMS_Main.getLoadingMessage();
				eleOptionLoading.value="0";
				try{
					eleSelectCategory.add(eleOptionLoading,null);
				}catch(e){
					eleSelectCategory.add(eleOptionLoading);
				}
				
				var objRequest=CMS_Main.createRequest();
				objRequest.open("GET",CMS_Main.getRootDirectory()+"/get_element_xml.php?function=getEntrySelectorCategoryList&fField_entry_selector_type_id="+intTypeId.toString(),true);
				objRequest.onreadystatechange=function()
				{
					if(objRequest.readyState==4 && objRequest.status==200)
					{
						//clear loading message
						while(eleSelectCategory.options.length>0)
							eleSelectCategory.remove(0);
				
						objRequestData=eval("("+objRequest.responseText+")");
						
						//add blank option
						var eleOption=document.createElement("option");
						eleOption.value="0";
						eleOption.text=" ";
						try{
							eleSelectCategory.add(eleOption,null);
						}catch(e){
							eleSelectCategory.add(eleOption);
						}
						
						//add categories
						for(var i=0;i<objRequestData.arrCategories.length;i++)
						{
							var eleOption=document.createElement("option");
							eleOption.value=objRequestData.arrCategories[i].intCategoryId;
							eleOption.text=objRequestData.arrCategories[i].strCategoryName;
							try{
								eleSelectCategory.add(eleOption,null);						
							}catch(e){
								eleSelectCategory.add(eleOption);						
							}
						}
					}
				};
				objRequest.send(null);
			}
		}
	},
	
	entrySelectCategoryChange:function(eleSelectType,eleSelectCategory,eleSelectEntry)
	{
		if(eleSelectType && eleSelectCategory && eleSelectEntry)
		{
			var intTypeId=Number(eleSelectType.value);
			var intCategoryId=Number(eleSelectCategory.value);
			
			//clear options
			while(eleSelectEntry.options.length>0)
				eleSelectEntry.remove(0);
			
			if(eleSelectCategory.value>0)
			{
				var eleOptionLoading=document.createElement("option");
				eleOptionLoading.text=CMS_Main.getLoadingMessage();
				eleOptionLoading.value="0";
				try{
					eleSelectEntry.add(eleOptionLoading,null);
				}catch(e){
					eleSelectEntry.add(eleOptionLoading);
				}
				
				var objRequest=CMS_Main.createRequest();
				objRequest.open("GET",CMS_Main.getRootDirectory()+"/get_element_xml.php?function=getEntrySelectorEntryList&fField_entry_selector_type_id="+intTypeId.toString()+"&fField_entry_selector_category_id="+intCategoryId.toString(),true);
				objRequest.onreadystatechange=function()
				{
					if(objRequest.readyState==4 && objRequest.status==200)
					{
						//clear loading message
						while(eleSelectEntry.options.length>0)
							eleSelectEntry.remove(0);
				
						objRequestData=eval("("+objRequest.responseText+")");
						
						//add blank option
						var eleOption=document.createElement("option");
						eleOption.value="0";
						eleOption.text=" ";
						try{
							eleSelectEntry.add(eleOption,null);
						}catch(e){
							eleSelectEntry.add(eleOption);
						}
						
						//add categories
						for(var i=0;i<objRequestData.arrEntries.length;i++)
						{
							var eleOption=document.createElement("option");
							eleOption.value=objRequestData.arrEntries[i].intEntryId;
							eleOption.text=objRequestData.arrEntries[i].strEntryName;
							try{
								eleSelectEntry.add(eleOption,null);						
							}catch(e){
								eleSelectEntry.add(eleOption);
							}
						}
					}
				};
				objRequest.send(null);
			}
		}
	},
	
	openFileAttach:function(intFieldDefId,strAllowedFileTypes)
	{
		//show dialogue
		CMS_Main.addOverlay(this.eleFileAttach);
		
		if(document.getElementById("frmFileAttach"))
			frm=document.getElementById("frmFileAttach");
		
		//set field definition id
		if(frm.fField_id)
			frm.fField_id.value=intFieldDefId;
		//set allowed file types
		if(frm.fAllowed_file_types)
			frm.fAllowed_file_types.value=strAllowedFileTypes;
		
		this.onFileAttachTypeClick();
		
		return false;
	},
	
	syncUploader:function(intFieldId,strId)
	{
		try
		{
			document.getElementById("eleUploader"+intFieldId.toString()).style.left=$("#"+strId).offset().left+"px";
			document.getElementById("eleUploader"+intFieldId.toString()).style.top=$("#"+strId).offset().top+"px";
		}
		catch(e)
		{
		}
	},
	
	onFileAttachTypeClick:function()
	{
		frm=document.getElementById("frmFileAttach");
		
		if(frm.fFile_attach_type0.checked)
		{
			document.getElementById("fileAttach0").style.height="auto";
			document.getElementById("fileAttach1").style.height="0px";
			
			this.hideUploader(frm.fField_id.value);
			
			if(frm.fFile_category_id)
				this.onCategoryChange(frm.fFile_category_id);
		}
		else if(frm.fFile_attach_type1.checked)
		{
			document.getElementById("fileAttach1").style.height="auto";
			document.getElementById("fileAttach0").style.height="0px";

			//store field id
			this.intFileUploadFieldId=frm.fField_id.value;
			//set file type filter
			this.arrUploader[this.intFileUploadFieldId].setFileFilters(eval(frm.fAllowed_file_types.value));

			//resize uploader to same size as uploadFiles
			document.getElementById("eleUploader"+this.intFileUploadFieldId).style.width=document.getElementById("uploadFiles").offsetWidth.toString()+"px";
			document.getElementById("eleUploader"+this.intFileUploadFieldId).style.height=document.getElementById("uploadFiles").offsetHeight.toString()+"px";
			//move uploader to same position as uploadFiles
			this.syncUploader(this.intFileUploadFieldId,"uploadFiles");
			//display uploader
			document.getElementById("eleUploader"+this.intFileUploadFieldId).style.zIndex=6;

			//start synchronizing uploader synchronized with upload files button
			window.onscroll=function()
			{
				if(document.getElementById("frmFileAttach"))
					CMS_Dynamic_Entry.syncUploader(document.getElementById("frmFileAttach").fField_id.value,"uploadFiles");
			};
			window.onresize=function()
			{
				if(document.getElementById("frmFileAttach"))
					CMS_Dynamic_Entry.syncUploader(document.getElementById("frmFileAttach").fField_id.value,"uploadFiles");
			};
		}
		else
		{
			document.getElementById("fileAttach0").style.height="0px";
			document.getElementById("fileAttach1").style.height="0px";
		}
	},
	
	onCategoryChange:function(eleSelectCategory)
	{
		var frm=eleSelectCategory.form;
		var objCategorySelectRequest=CMS_Main.createRequest();
		objCategorySelectRequest.open("GET",CMS_Main.getRootDirectory()+"/get_element_xml.php?function=getDynamicFileListJson&fCategory_id="+eleSelectCategory.value.toString()+"&fField_id="+frm.fField_id.value.toString(),true);
		objCategorySelectRequest.onreadystatechange=function()
		{
			if(objCategorySelectRequest.readyState==4)
			{
				if(objCategorySelectRequest.status==200)
				{
					objListData=eval("("+objCategorySelectRequest.responseText+")");
					
					eleSelectFiles=frm.fAvailable_file_ids;
					
					//clear file list
					for(i in eleSelectFiles.options)
					{
						eleSelectFiles.remove(i);
					}
					
					//populate file list
					for(i in objListData.arrFiles)
					{
						var eleOpt=document.createElement("option");
						eleOpt.text=objListData.arrFiles[i].strTitle;
						eleOpt.value=objListData.arrFiles[i].intFileId.toString();
						eleOpt.title=objListData.arrFiles[i].strName;
						eleSelectFiles.options[eleSelectFiles.length]=eleOpt;
					}
				}
			}
		};
		objCategorySelectRequest.send(null);
	},

	addSelectedFiles:function(eleSelect)
	{
		var blnFileSelected=false;
		
		for(var i=0;i<eleSelect.options.length;i++)
		{
			if(eleSelect.options[i].selected)
			{
				blnFileSelected=true;
				
				var j=this.arrFileSelectRequest.length+1;
				
				this.arrFileSelectFieldId[j]=eleSelect.form.fField_id.value;
				
				this.arrFileSelectRequest[j]=CMS_Main.createRequest();
				this.arrFileSelectRequest[j].open("GET",CMS_Main.getRootDirectory()+"/get_element_xml.php?function=getFileDataJson&fFile_id="+eleSelect.options[i].value.toString(),true);
				this.arrFileSelectRequest[j].onreadystatechange=this.addSelectedFilesResponse;
				this.arrFileSelectRequest[j].send(null);
			}
		}

		if(blnFileSelected)
			CMS_Main.removeOverlay();
	},
	
	addSelectedFilesResponse:function()
	{
		for(i in CMS_Dynamic_Entry.arrFileSelectRequest)
		{
			if(CMS_Dynamic_Entry.arrFileSelectRequest[i] && CMS_Dynamic_Entry.arrFileSelectRequest[i].readyState==4)
			{
				if(CMS_Dynamic_Entry.arrFileSelectRequest[i].status==200)
				{
					objFileData=eval("("+CMS_Dynamic_Entry.arrFileSelectRequest[i].responseText+")");
					
					//hide file select container
					document.getElementById("fileSelectContainer"+CMS_Dynamic_Entry.arrFileSelectFieldId[i].toString()).style.display="none";
					
					var eleFileDataContainer=document.getElementById("fileDataContainer"+CMS_Dynamic_Entry.arrFileSelectFieldId[i].toString());
					
					//clear file data container
					while(eleFileDataContainer.firstChild)
						eleFileDataContainer.removeChild(eleFileDataContainer.firstChild);
					
					//create row 
					var eleRow=document.createElement("tr");

					var eleTd1=document.createElement("td");
					var eleInput=CMS_Main.createNamedElement("input","fField_file_id"+CMS_Dynamic_Entry.arrFileSelectFieldId[i].toString());
					eleInput.id="fField_file_id"+CMS_Dynamic_Entry.arrFileSelectFieldId[i].toString();
					eleInput.type="hidden";
					eleInput.value=objFileData.intFileId.toString();
					eleTd1.appendChild(eleInput);
					eleTd1.appendChild(document.createTextNode(objFileData.strTitle));
					eleRow.appendChild(eleTd1);
					
					var eleTd2=document.createElement("td");
					eleTd2.appendChild(document.createTextNode(objFileData.strStatus));
					eleRow.appendChild(eleTd2);
					
					var eleTd3=document.createElement("td");
					eleTd3.innerHTML="<div class=\"actions\"><ul><li><a class=\"action4\" href=\"#\" onclick=\"return CMS_Dynamic_Entry.removeFile("+CMS_Dynamic_Entry.arrFileSelectFieldId[i].toString()+","+objFileData.intFileId.toString()+");\" title=\"Remove\">Remove</a></li></ul></div>";
					eleRow.appendChild(eleTd3);

					eleFileDataContainer.appendChild(eleRow);
					
					//remove from arrays
					CMS_Dynamic_Entry.arrFileSelectRequest.splice(i,1);
					CMS_Dynamic_Entry.arrFileSelectFieldId.splice(i,1);
				}
			}
		}
	},
	
	closeFileAttach:function(intFieldId)
	{
		this.hideUploader(intFieldId);
		
		CMS_Main.removeOverlay();

		//stop synchronizing uploader synchronized with upload files button
		window.onscroll=null;
		window.onresize=null;
	},
	
	hideUploader:function(intFieldId)
	{
		//this seems to be the only method of hiding the uploader that doesn't cause the browser to unload the Flash object (and lose any selected files)
		if(document.getElementById("eleUploader"+intFieldId.toString()))
			document.getElementById("eleUploader"+intFieldId.toString()).style.zIndex=-1;
	},
	
	removeFile:function(intFieldId,intFileId)
	{
		if(document.getElementById("fileDataContainer"+intFieldId.toString()))
		{
			var eleFileDataContainer=document.getElementById("fileDataContainer"+intFieldId.toString());
			
			//clear file data container
			while(eleFileDataContainer.firstChild)
				eleFileDataContainer.removeChild(eleFileDataContainer.firstChild);
					
			//show file select container
			document.getElementById("fileSelectContainer"+intFieldId.toString()).style.display="block";
		}
		
		return false;
	},
	
	editSubmit:function(frm)
	{
		var blnReturnValue=true;
		
		if(frm.fField_id)
		{
			for(var i=0;i<frm.fField_id.length;i++)
			{
				if(document.getElementById("fField_text_editor"+frm.fField_id[i].value.toString()))
					CMS_Main.textEditorUpdate("fField_text_editor"+frm.fField_id[i].value.toString());
			}
			if(!frm.fField_id.length) //if there is only one field, then frm.fField_id is not an array
			{
				if(document.getElementById("fField_text_editor"+frm.fField_id.value.toString()))
					CMS_Main.textEditorUpdate("fField_text_editor"+frm.fField_id.value.toString());
			}
		}

		if(frm.fTitle.value.length==0)
		{
			alert("Please enter a title");
			frm.fTitle.focus();
			blnReturnValue=false;
		}
		else if((frm.fDate_start_enabled && frm.fDate_end_enabled) && (frm.fDate_start_enabled.checked && frm.fDate_end_enabled.checked) && (Number(frm.fDate_start.value) > Number(frm.fDate_end.value)))
		{
			alert("Please make sure the end date is not earlier than the start date.");
			blnReturnValue=false;
		}
		else if((frm.fDisplay_date_start_enabled && frm.fDisplay_date_end_enabled) && (frm.fDisplay_date_start_enabled.checked && frm.fDisplay_date_end_enabled.checked) && (Number(frm.fDisplay_date_start.value) > Number(frm.fDisplay_date_end.value)))
		{
			alert("Please make sure the display end date is not earlier than the display start date.");
			blnReturnValue=false;
		}
		else if(frm.fField_id)
		{
			if(frm.fField_id.length) //there is more than one field
			{
				for(var i=0;i<frm.fField_id.length;i++)
				{
					//check for valid field attributes
					var strId=frm.fField_id[i].value;
					
					if(!this.editFieldSubmit(frm,strId))
					{
						blnReturnValue=false;
						break;
					}
				}
			}
			else //there is only one field
			{
				//check for valid field attributes
				var strId=frm.fField_id.value;
				
				if(!this.editFieldSubmit(frm,strId))
				{
					blnReturnValue=false;
				}
			}
		}
		
		if(blnReturnValue)
		{
			document.getElementById("fSubmit").disabled=true;
			
			//check if there are files to upload
			if(CMS_Dynamic_Entry.intUploadCount>0)
			{
				for(i in CMS_Dynamic_Entry.arrUploader)
				{
					//upload
					if(CMS_Dynamic_Entry.arrUploadCount[i]>0)
						CMS_Dynamic_Entry.arrUploader[i].uploadAll(CMS_Main.getRootDirectory()+'/file_upload.php',"POST",{sessionId:CMS_Cookie.get(CMS_Main.getSessionName()), fEnd_action:2, fPublished:1, fNew:0},"fFile");
				}
			}
			else
			{
				//submit form
				this.editSubmitFinal(frm);
			}
		}
		
		return false;
	},
	
	editFieldSubmit:function(frm,strFieldId)
	{
		var blnReturnValue=true;
		
		switch(Number(frm.elements["fField_type"+strFieldId].value))
		{
			case(CMS_Dynamic_Form.intTextTypeId):
				if(frm.elements["fField_required"+strFieldId].value==1 && frm.elements["fField_text"+strFieldId].value=="")
				{
					alert(frm.elements["fField_name"+strFieldId].value.toString()+" is a required field. Please enter a value.");
					frm.elements["fField_text"+strFieldId].focus();
					frm.elements["fField_text"+strFieldId].select();
					blnReturnValue=false;
				}
				break;
			case(CMS_Dynamic_Form.intTextAreaTypeId):
				if(frm.elements["fField_required"+strFieldId].value==1 && frm.elements["fField_text"+strFieldId].value=="")
				{
					alert(frm.elements["fField_name"+strFieldId].value.toString()+" is a required field. Please enter a value.");
					frm.elements["fField_text"+strFieldId].focus();
					frm.elements["fField_text"+strFieldId].select();
					blnReturnValue=false;
				}
				break;
			case(CMS_Dynamic_Form.intFileTypeId):
				if(frm.elements["fField_required"+strFieldId].value==1 && ((!frm.elements["fField_file_id"+strFieldId] && this.arrUploadCount[strFieldId]==0) || (frm.elements["fField_file_id"+strFieldId] && frm.elements["fField_file_id"+strFieldId].value==0)))
				{
					alert(frm.elements["fField_name"+strFieldId].value.toString()+" is a required field. Please select a file.");
					try
					{
						document.getElementById("fileSelect"+strFieldId).focus();
					}
					catch(e)
					{
					}
					blnReturnValue=false;
				}
				break;
			case(CMS_Dynamic_Form.intUrlTypeId):
				if(frm.elements["fField_required"+strFieldId].value==1 && frm.elements["fField_url"+strFieldId].value=="")
				{
					alert(frm.elements["fField_name"+strFieldId].value.toString()+" is a required field. Please enter a URL for this link.");
					frm.elements["fField_url"+strFieldId].focus();
					frm.elements["fField_url"+strFieldId].select();
					blnReturnValue=false;
				}
				else if(Number(frm.elements["fField_url_target_id"+strFieldId].value)==1 && frm.elements["fField_url_target_other"+strFieldId].value=="")
				{
					alert("Please enter a target value");
					frm.elements["fField_url_target_other"+strFieldId].focus();
					blnReturnValue=false;
				}
				break;
			case(CMS_Dynamic_Form.intCategoryTypeId):
				if(frm.elements["fField_required"+strFieldId].value==1 && frm.elements["fField_category_selector_type_id"+strFieldId].value<1)
				{
					alert(frm.elements["fField_name"+strFieldId].value.toString()+" is a required field. Please select a category type.");
					frm.elements["fField_category_selector_type_id"+strFieldId].focus();
					blnReturnValue=false;
				}
				else if(frm.elements["fField_required"+strFieldId].value==1 && frm.elements["fField_category_selector_category_id"+strFieldId].value<1)
				{
					alert(frm.elements["fField_name"+strFieldId].value.toString()+" is a required field. Please select a category.");
					frm.elements["fField_category_selector_category_id"+strFieldId].focus();
					blnReturnValue=false;
				}
				break;
			case(CMS_Dynamic_Form.intEntryTypeId):
				if(frm.elements["fField_required"+strFieldId].value==1 && frm.elements["fField_entry_selector_type_id"+strFieldId].value<1)
				{
					alert(frm.elements["fField_name"+strFieldId].value.toString()+" is a required field. Please select a category type.");
					frm.elements["fField_entry_selector_type_id"+strFieldId].focus();
					blnReturnValue=false;
				}
				else if(frm.elements["fField_required"+strFieldId].value==1 && frm.elements["fField_entry_selector_category_id"+strFieldId].value<1)
				{
					alert(frm.elements["fField_name"+strFieldId].value.toString()+" is a required field. Please select a category.");
					frm.elements["fField_entry_selector_category_id"+strFieldId].focus();
					blnReturnValue=false;
				}
				else if(frm.elements["fField_required"+strFieldId].value==1 && frm.elements["fField_entry_selector_entry_id"+strFieldId].value<1)
				{
					alert(frm.elements["fField_name"+strFieldId].value.toString()+" is a required field. Please select an entry.");
					frm.elements["fField_entry_selector_entry_id"+strFieldId].focus();
					blnReturnValue=false;
				}
				break;
		}
		
		return blnReturnValue;
	},
	
	editSubmitFinal:function(frm)
	{
		this.editClose(frm);
		
		CMS_Main.objRequest.open("POST","get_page_xml.php",true);
		CMS_Main.objRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		CMS_Main.objRequest.onreadystatechange=CMS_Main.updatePage;
		CMS_Main.objRequest.send(CMS_Main.formEncode(frm)+"&page="+CMS_Main.getPage());
	},
	
	editCancel:function(frm)
	{
		this.editClose(frm);
		
		CMS_Main.objRequest.open("GET","get_page_xml.php?page="+CMS_Main.getPage()+"&fForm_id="+frm.fForm_id.value.toString(),true);
		CMS_Main.objRequest.onreadystatechange=CMS_Main.updatePage;
		CMS_Main.objRequest.send(null);
		
		return false;
	},
	
	editClose:function(frm)
	{
		var arrFieldIds=new Array();
		if(frm.fField_id && frm.fField_id.length)
			for(var i=0;i<frm.fField_id.length;i++)
				arrFieldIds.push(frm.fField_id[i].value);
		else if(frm.fField_id) //if there is only one field, then frm.fField_id is not an array
			arrFieldIds.push(frm.fField_id.value);
			
		for(var i=0;i<arrFieldIds.length;i++)
		{
			//remove the uploaders
			if(document.getElementById("eleUploader"+arrFieldIds[i].toString()))
			{
				document.getElementById("eleUploader"+arrFieldIds[i].toString()).innerHTML=""; //unload the Flash object to prevent error in IE when removing element from the DOM
				document.getElementById("eleUploader"+arrFieldIds[i].toString()).parentNode.removeChild(document.getElementById("eleUploader"+arrFieldIds[i].toString()));
			}
		}
	},
	
	editRevert:function(frm)
	{
		if(confirm("Are you sure you want to revert this entry back to the original version?"))
		{
			this.editClose(frm);
			
			CMS_Main.objRequest.open("GET","get_page_xml.php?page="+CMS_Main.getPage()+"&fForm_id="+frm.fForm_id.value.toString()+"&fAction=revertDynamicEntry&fEntry_id="+frm.fEntry_id.value.toString(),true);
			CMS_Main.objRequest.onreadystatechange=CMS_Main.updatePage;
			CMS_Main.objRequest.send(null);
		}
		
		return false;
	},
	
	//file select and upload methods

	arrFileSelectRequest:new Array(),
	arrFileSelectFieldId:new Array(),
	intFileUploadFieldId:0,
	eleFileAttach:null,

	arrUploader:new Array(),
	arrFileList:new Array(),
	arrValidFileRequest:new Array(),
	intSizeUploadingTotal:0,
	intUploadCount:0,
	arrUploadCount:new Array(),

	onContentReady:function()
	{
		//set file uploader properties
		this.setAllowMultipleFiles(false);
		this.setSimUploadLimit(1); //set simultaneous upload limit
	},
	
	uploadFiles:function(frm)
	{
		return false;
	},
	
	onFileSelect:function(event)
	{
		CMS_Dynamic_Entry.closeFileAttach(this.intFieldId);
		
		CMS_Dynamic_Entry.arrFileList[this.intFieldId]=event.fileList;
		
		//add files to form
		for(var i in event.fileList)
		{
			var strTitle=event.fileList[i].name.substr(0,event.fileList[i].name.lastIndexOf("."));

			//hide file select container
			document.getElementById("fileSelectContainer"+this.intFieldId).style.display="none";
			
			var eleFileDataContainer=document.getElementById("fileDataContainer"+this.intFieldId);
			
			//clear file data container
			while(eleFileDataContainer.firstChild)
				eleFileDataContainer.removeChild(eleFileDataContainer.firstChild);
			
			//create row 
			var eleRow=document.createElement("tr");

			var eleTd1=document.createElement("td");
			eleTd1.appendChild(document.createTextNode(strTitle));
			eleRow.appendChild(eleTd1);
			
			var eleTd2=document.createElement("td");
			eleTd2.id="fileStatus"+this.intFieldId;
			eleTd2.appendChild(document.createTextNode("\u00A0"));
			eleRow.appendChild(eleTd2);
			
			var eleTd3=document.createElement("td");
			eleTd3.id="fileAction"+this.intFieldId;
			eleTd3.innerHTML="<div class=\"actions\"><ul><li><a class=\"action4\" href=\"#\" onclick=\"return CMS_Dynamic_Entry.cancel("+this.intFieldId.toString()+",'"+event.fileList[i].id+"');\" title=\"Remove\">Remove</a></li></ul></div>";
			eleRow.appendChild(eleTd3);

			eleFileDataContainer.appendChild(eleRow);

			//check for valid file
			var j=CMS_Dynamic_Entry.arrValidFileRequest.length+1;
			CMS_Dynamic_Entry.arrValidFileRequest[j]=CMS_Main.createRequest();
			CMS_Dynamic_Entry.arrValidFileRequest[j].open("GET","get_element_xml.php?function=isValidFileXml&fFile_id=0&fileId="+event.fileList[i].id+"&fName="+encodeURIComponent(event.fileList[i].name)+"&fSize="+event.fileList[i].size+"&sizeUploadingTotal="+CMS_Dynamic_Entry.intSizeUploadingTotal.toString()+"&fTitle=&fField_id="+this.intFieldId.toString(),true);
			CMS_Dynamic_Entry.arrValidFileRequest[j].onreadystatechange=CMS_Dynamic_Entry.uploadFileResponse;
			CMS_Dynamic_Entry.arrValidFileRequest[j].send(null);
		}
	},
	
	uploadFileResponse:function()
	{
		//loop through all open requests
		for(i in CMS_Dynamic_Entry.arrValidFileRequest)
		{
			if(CMS_Dynamic_Entry.arrValidFileRequest[i] && CMS_Dynamic_Entry.arrValidFileRequest[i].readyState==4 && CMS_Dynamic_Entry.arrValidFileRequest[i].status==200)
			{
				var eleDoc=CMS_Dynamic_Entry.arrValidFileRequest[i].responseXML.documentElement;
				
				if(eleDoc.getElementsByTagName("validFile"))
				{
					var strId=eleDoc.getElementsByTagName("fileId")[0].firstChild.nodeValue;
					var intFieldId=eleDoc.getElementsByTagName("fieldId")[0].firstChild.nodeValue;
					
					//add to size uploading total
					CMS_Dynamic_Entry.intSizeUploadingTotal+=CMS_Dynamic_Entry.arrFileList[intFieldId][strId].size;
					CMS_Dynamic_Entry.intUploadCount++;
					CMS_Dynamic_Entry.arrUploadCount[intFieldId]++;
					
					if(eleDoc.getElementsByTagName("validFile")[0].firstChild.nodeValue==0)
					{
						//cancel
						//CMS_Dynamic_Entry.arrUploader[intFieldId].removeFile(intFieldId,strId);
						CMS_Dynamic_Entry.cancel(intFieldId,strId,(eleDoc.getElementsByTagName("message") ? eleDoc.getElementsByTagName("message")[0].firstChild.nodeValue : ""));
					}
				}
				//remove from array
				CMS_Dynamic_Entry.arrValidFileRequest.splice(i,1);
			}
		}
	},
	
	cancel:function(intFieldId,id,strStatus)
	{
		//cancel upload
		this.arrUploader[intFieldId].cancel(id);
		this.arrUploader[intFieldId].removeFile(id);
		
		//enable submit button again
		if(document.getElementById("fSubmit"))
			document.getElementById("fSubmit").disabled=false;
		
		//remove from size uploading total
		CMS_Dynamic_Entry.intSizeUploadingTotal-=CMS_Dynamic_Entry.arrFileList[intFieldId][id].size;
		CMS_Dynamic_Entry.intUploadCount--;
		CMS_Dynamic_Entry.arrUploadCount[intFieldId]--;
		
		if(!strStatus)
			strStatus="Cancelled.";
		
		document.getElementById("fileStatus"+intFieldId).innerHTML=strStatus;
		document.getElementById("fileAction"+intFieldId).innerHTML="<div class=\"actions\"><ul><li><a class=\"action4\" href=\"#\" onclick=\"return CMS_Dynamic_Entry.removeFile("+intFieldId.toString()+",'"+id+"');\" title=\"Remove\">Remove</a></li></ul></div>";

		return false;
	},
	
	onUploadStart:function(event)
	{
		//CMS_Dynamic_Entry.updateProgress(this.intFieldId,0);
		document.getElementById("fileStatus"+this.intFieldId).innerHTML="Waiting...";
	},
	onUploadProgress:function(event)
	{
		//check if progress bar exists
		if(!document.getElementById("progressBar"+this.intFieldId))
		{
			//create progress bar
			eleContainer=document.createElement("div");
			eleContainer.className="progressBar";
			eleContainer.id="progressBar"+this.intFieldId;
			
			eleImg=document.createElement("img");
			eleImg.src=CMS_Main.getRootDirectory()+"/css/tng/progressbar/box.gif";
			eleImg.id="progressBarImage"+this.intFieldId;
			eleImg.width="150";
			eleImg.height="12";
			eleImg.alt="";
			eleImg.title="";
			
			eleSpan=document.createElement("span");
			eleSpan.className="progressBarPercent";
			eleSpan.id="progressBarPercent"+this.intFieldId;
			eleSpan.appendChild(document.createTextNode("0%"));
			
			eleContainer.appendChild(eleImg);
			document.getElementById("fileStatus"+this.intFieldId).innerHTML="";
			document.getElementById("fileStatus"+this.intFieldId).appendChild(eleContainer);
			document.getElementById("fileStatus"+this.intFieldId).appendChild(document.createTextNode(" "));
			document.getElementById("fileStatus"+this.intFieldId).appendChild(eleSpan);
		}
		
		CMS_Dynamic_Entry.updateProgress(this.intFieldId,(event.bytesLoaded/event.bytesTotal)*100);
	},
	
	updateProgress:function(intFieldId,dblPercent)
	{
		strHtml="";
		strPercent=Math.round(dblPercent).toString()+"%";
		intPosition=Math.round((100-dblPercent)/100*150) * -1;
		
		if(document.getElementById("progressBar"+intFieldId.toString()))
		{
			document.getElementById("progressBar"+intFieldId.toString()).style.backgroundPosition=intPosition+"px 0px";
			document.getElementById("progressBarPercent"+intFieldId.toString()).replaceChild(document.createTextNode(strPercent),document.getElementById("progressBarPercent"+intFieldId.toString()).firstChild);
		}
	},

	onUploadCancel:function(event)
	{
		//this event doesn't seem to fire
	},
	onUploadComplete:function(event)
	{
		CMS_Dynamic_Entry.updateProgress(this.intFieldId,100);

		//remove "remove" link
		document.getElementById("fileAction"+this.intFieldId).innerHTML="\u00A0";
	},
	onUploadCompleteData:function(event)
	{
		var objFileData=eval("("+event.data+")");
		
		//remove from size uploading total
		CMS_Dynamic_Entry.intSizeUploadingTotal-=CMS_Dynamic_Entry.arrFileList[this.intFieldId][event.id].size;
		CMS_Dynamic_Entry.intUploadCount--;
		CMS_Dynamic_Entry.arrUploadCount[this.intFieldId]--;
		
		if(!objFileData.blnSuccess)
		{
			CMS_Dynamic_Entry.cancel(this.intFieldId,event.id,objFileData.strMessages);
		}
		else
		{
			var eleInput=CMS_Main.createNamedElement("input","fField_file_id"+this.intFieldId);
			eleInput.id="fField_file_id"+this.intFieldId;
			eleInput.type="hidden";
			eleInput.value=objFileData.intFileId.toString();
				
			//add element to form
			document.getElementById("fileDataContainer"+this.intFieldId).appendChild(eleInput);
		}

		//check for remaining file uploads
		if(CMS_Dynamic_Entry.intUploadCount==0)
		{
			//submit form
			CMS_Dynamic_Entry.editSubmitFinal(document.getElementById("frmEditDynamicEntry"));
		}
		
		return false;
	},
	onUploadError:function(event)
	{
		//CMS_Dynamic_Entry.cancel(this.intFieldId,event.status);
		CMS_Dynamic_Entry.cancel(this.intFieldId,"Error uploading file, please try again.");
	},

	onRollOver:function()
	{
	},
	onRollOut:function()
	{
	},
	onClick:function()
	{
	}
}/*--------------------------------------------------
	Project:	The November Group - CMS Administration
	Script:		cms_dynamic_form.js
	Includes:	CMS_Dynamic_Form
--------------------------------------------------*/

var CMS_Dynamic_Form={
	
	eleFieldOptions:null,
	intNewFieldIndex:0,
	intTextTypeId:1,
	intTextAreaTypeId:2,
	intTextEditorTypeId:4,
	intFileTypeId:3,
	intCheckboxTypeId:5,
	intDropDownTypeId:6,
	intYearTypeId:7,
	intUrlTypeId:8,
	intCountDownTypeId:9,
	intCategoryTypeId:10,
	intEntryTypeId:11,
	
	adminDynamic:function()
	{
		CMS_Main.setPage("adminDynamic"); //store page selection

		CMS_Main.objRequest.open("GET","get_page_xml.php?page="+CMS_Main.getPage(),true);
		CMS_Main.objRequest.onreadystatechange=CMS_Main.updatePage;
		CMS_Main.objRequest.send(null);
		
		return false;
	},
	
	manageForms:function()
	{
		CMS_Main.setPage("manageDynamicForms");
		
		CMS_Main.objRequest.open("GET","get_page_xml.php?page="+CMS_Main.getPage(),true);
		CMS_Main.objRequest.onreadystatechange=CMS_Main.updatePage;
		CMS_Main.objRequest.send(null);
		
		return false;
	},
	
	addForm:function(intType)
	{
		if(!intType)
			var intType=0;
		
		CMS_Main.objRequest.open("GET","get_page_xml.php?page=editDynamicForm&fType="+intType.toString(),true);
		CMS_Main.objRequest.onreadystatechange=CMS_Main.updatePage;
		CMS_Main.objRequest.send(null);
		
		return false;
	},
	
	deleteForm:function(intFormId,strTitle)
	{
		if(confirm("Are you sure you want to delete "+strTitle+" and all of its entries?"))
		{
			CMS_Main.objRequest.open("GET","get_page_xml.php?page="+CMS_Main.getPage()+"&fAction=deleteDynamicForm&fForm_id="+intFormId.toString(),true);
			CMS_Main.objRequest.onreadystatechange=CMS_Main.updatePage;
			CMS_Main.objRequest.send(null);
		}
		
		return false;
	},
	
	editForm:function(intFormId)
	{
		CMS_Main.objRequest.open("GET","get_page_xml.php?page=editDynamicForm&fForm_id="+intFormId.toString(),true);
		CMS_Main.objRequest.onreadystatechange=CMS_Main.updatePage;
		CMS_Main.objRequest.send(null);
		
		return false;
	},
	
	duplicateForm:function(intFormId)
	{
		CMS_Main.objRequest.open("GET","get_page_xml.php?page=duplicateDynamicForm&fForm_id="+intFormId.toString(),true);
		CMS_Main.objRequest.onreadystatechange=CMS_Main.updatePage;
		CMS_Main.objRequest.send(null);
		
		return false;
	},
	
	editFormInitialize:function(frm)
	{
		if(frm)
		{
			//store field options html
			if(document.getElementById("fieldOptions"))
			{
				this.eleFieldOptions=document.getElementById("fieldOptions").parentNode.removeChild(document.getElementById("fieldOptions"));
			}
			
			//initialize the drag drop
			this.initializeOrder(frm);
			
			//initialize show field checkboxes
			this.onShowFieldClick(frm);
			
			frm.fTitle.focus();
			frm.fTitle.select();
		}
		
		return false;
	},
	
	initializeOrder:function(frm)
	{
		//initialize the drag drop
		$("#fieldListContainer").tableDnD();
	},
	
	onFileTypeChange:function(eleSelect)
	{
		if(eleSelect)
		{
			var strId=eleSelect.id.replace("fFile_allowed_file_types","");
			
			if(document.getElementById("fileImageOptions"+strId))
			{
				var blnShowImageOptions=false;
				
				for(var i=0;i<document.getElementById("fFile_allowed_file_types"+strId).length;i++)
				{
					if(document.getElementById("fFile_allowed_file_types"+strId).options[i].selected && Number(document.getElementById("fFile_allowed_file_types"+strId).options[i].value)==CMS_File.intImageTypeId)
					{
						blnShowImageOptions=true;
						break;
					}
				}
				
				if(blnShowImageOptions)
					document.getElementById("fileImageOptions"+strId).style.display="block";
				else
					document.getElementById("fileImageOptions"+strId).style.display="none";
				
				this.onResizeClick(document.getElementById("fFile_image_resize"+strId));
			}
		}
	},
	
	onResizeClick:function(eleInput)
	{
		if(eleInput)
		{
			var strId=eleInput.id.replace("fFile_image_resize","");
			
			if(document.getElementById("fileImageResizeOptions"+strId))
			{
				if(document.getElementById("fFile_image_resize"+strId).checked)
					document.getElementById("fileImageResizeOptions"+strId).style.display="block";
				else
					document.getElementById("fileImageResizeOptions"+strId).style.display="none";
			}
		}
	},

	editCancel:function(frm)
	{
		CMS_Main.objRequest.open("GET","get_page_xml.php?page="+CMS_Main.getPage(),true);
		CMS_Main.objRequest.onreadystatechange=CMS_Main.updatePage;
		CMS_Main.objRequest.send(null);
		
		return false;
	},
	
	editSubmit:function(frm)
	{
		var blnReturnValue=true;
		
		if(frm.fTitle.value.length==0)
		{
			alert("Please enter a title");
			frm.fTitle.focus();
			blnReturnValue=false;
		}
		else if(frm.fTitle_title.value.length==0)
		{
			alert("Please enter a name for the title field");
			frm.fTitle_title.focus();
			blnReturnValue=false;
		}
		else if(frm.fDate_start_title.value.length==0)
		{
			alert("Please enter a name for the event start date field");
			frm.fDate_start_title.focus();
			blnReturnValue=false;
		}
		else if(frm.fDate_end_title.value.length==0)
		{
			alert("Please enter a name for the event end date field");
			frm.fDate_end_title.focus();
			blnReturnValue=false;
		}
		else if(frm.fDisplay_date_start_title.value.length==0)
		{
			alert("Please enter a name for the display start date field");
			frm.fDisplay_date_start_title.focus();
			blnReturnValue=false;
		}
		else if(frm.fDisplay_date_end_title.value.length==0)
		{
			alert("Please enter a name for the display end date field");
			frm.fDisplay_date_end_title.focus();
			blnReturnValue=false;
		}
		else if(frm.fField_id)
		{
			if(frm.fField_id.length) //there is more than one field
			{
				for(var i=0;i<frm.fField_id.length;i++)
				{
					//check for valid field attributes
					var strId=frm.fField_id[i].value;
					
					if(!this.editFieldSubmit(frm,strId))
					{
						blnReturnValue=false;
						break;
					}
				}
			}
			else //there is only one field
			{
				//check for valid field attributes
				var strId=frm.fField_id.value;
				
				if(!this.editFieldSubmit(frm,strId))
				{
					blnReturnValue=false;
				}
			}
		}
		
		if(blnReturnValue)
		{
			document.getElementById("fSubmit").disabled=true;
			
			CMS_Main.objRequest.open("POST","get_page_xml.php",true);
			CMS_Main.objRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
			CMS_Main.objRequest.onreadystatechange=CMS_Main.updatePage;
			CMS_Main.objRequest.send(CMS_Main.formEncode(frm)+"&page="+CMS_Main.getPage());
		}
		
		return false;
	},
	
	editFieldSubmit:function(frm,strFieldId)
	{
		var blnReturnValue=true;
		
		//check for valid field attributes
		if(frm.elements["fField_title"+strFieldId] && frm.elements["fField_title"+strFieldId].value.length==0)
		{
			alert("Please enter a field name");
			frm.elements["fField_title"+strFieldId].focus();
			frm.elements["fField_title"+strFieldId].select();
			blnReturnValue=false;
		}
		else if(frm.elements["fField_type"+strFieldId] && frm.elements["fField_type"+strFieldId].value==0)
		{
			alert("Please select a field type");
			frm.elements["fField_type"+strFieldId].focus();
			blnReturnValue=false;
		}
		else if(frm.elements["fField_type"+strFieldId] && frm.elements["fField_type"+strFieldId].value==this.intFileTypeId && frm.elements["fFile_allowed_file_types"+strFieldId] && frm.elements["fFile_allowed_file_types"+strFieldId].selectedIndex==-1)
		{
			alert("Please select at least one allowed file type");
			frm.elements["fFile_allowed_file_types"+strFieldId].focus();
			blnReturnValue=false;
		}
		else if(frm.elements["fField_type"+strFieldId] && frm.elements["fField_type"+strFieldId].value==this.intFileTypeId && frm.elements["fFile_allowed_file_types"+strFieldId] && Number(frm.elements["fFile_allowed_file_types"+strFieldId][frm.elements["fFile_allowed_file_types"+strFieldId].selectedIndex].value)==CMS_File.intImageTypeId && frm.elements["fFile_image_resize"+strFieldId] && frm.elements["fFile_image_resize"+strFieldId].checked && frm.elements["fFile_image_max_width"+strFieldId] && frm.elements["fFile_image_max_height"+strFieldId] && Number(frm.elements["fFile_image_max_width"+strFieldId].value)==0 && Number(frm.elements["fFile_image_max_height"+strFieldId].value)==0)
		{
			alert("Please enter a maximum width, height, or both");
			frm.elements["fFile_image_max_width"+strFieldId].focus();
			frm.elements["fFile_image_max_width"+strFieldId].select();
			blnReturnValue=false;
		}
		else if(frm.elements["fField_type"+strFieldId] && frm.elements["fField_type"+strFieldId].value==this.intUrlTypeId && frm.elements["fUrl_target_id"+strFieldId] && Number(frm.elements["fUrl_target_id"+strFieldId].value)==1 && frm.elements["fUrl_target_other"+strFieldId].value=="")
		{
			alert("Please enter a target value");
			frm.elements["fUrl_target_other"+strFieldId].focus();
			blnReturnValue=false;
		}
		
		return blnReturnValue;
	},
	
	getFieldOptions:function()
	{
		return this.eleFieldOptions.cloneNode(true);
	},
	
	onShowFieldClick:function(frm)
	{
		if(frm)
		{
			if(frm.fShow_date_start && frm.fRequire_date_start && !frm.fShow_date_start.checked)
				frm.fRequire_date_start.disabled=true;
			else
				frm.fRequire_date_start.disabled=false;
				
			if(frm.fShow_date_end && frm.fRequire_date_end && !frm.fShow_date_end.checked)
				frm.fRequire_date_end.disabled=true;
			else
				frm.fRequire_date_end.disabled=false;
				
			if(frm.fShow_display_date_start && frm.fRequire_display_date_start && !frm.fShow_display_date_start.checked)
				frm.fRequire_display_date_start.disabled=true;
			else
				frm.fRequire_display_date_start.disabled=false;
				
			if(frm.fShow_display_date_end && frm.fRequire_display_date_end && !frm.fShow_display_date_end.checked)
				frm.fRequire_display_date_end.disabled=true;
			else
				frm.fRequire_display_date_end.disabled=false;
		}
	},
	
	addField:function(frm)
	{
		if(document.getElementById("fieldListContainer"))
		{
			//increment index
			this.intNewFieldIndex++;
			var strId="new"+this.intNewFieldIndex.toString();
			
			//add field options to document
			document.getElementById("fieldListContainer").appendChild(this.getFieldOptions());
			
			//update element ids
			document.getElementById("removeField").id+=strId;

			document.getElementById("fieldOptions").id+=strId;
			document.getElementById("fField_title").name+=strId;
			document.getElementById("fField_title").id+=strId;
			document.getElementById("fField_type").name+=strId;
			document.getElementById("fField_type").id+=strId;
			
			document.getElementById("textOptions").id+=strId;
			document.getElementById("fText_size").name+=strId;
			document.getElementById("fText_size").id+=strId;
			document.getElementById("fText_size_label").id+=strId;
			document.getElementById("fText_size_label"+strId).htmlFor="fText_size"+strId;
			document.getElementById("fText_type").name+=strId;
			document.getElementById("fText_type").id+=strId;
			document.getElementById("fText_type_label").id+=strId;
			document.getElementById("fText_type_label"+strId).htmlFor="fText_type"+strId;
			
			document.getElementById("textEditorOptions").id+=strId;
			
			document.getElementById("fileOptions").id+=strId;
			document.getElementById("fFile_allowed_file_types").name+=strId;
			document.getElementById("fFile_allowed_file_types").id+=strId;
			
			document.getElementById("fileImageOptions").id+=strId;
			document.getElementById("fFile_image_resize").name+=strId;
			document.getElementById("fFile_image_resize").id+=strId;
			document.getElementById("fFile_image_resize_label").id+=strId;
			document.getElementById("fFile_image_resize_label"+strId).htmlFor="fFile_image_resize"+strId;
			
			document.getElementById("fileImageResizeOptions").id+=strId;
			document.getElementById("fFile_image_max_width").name+=strId;
			document.getElementById("fFile_image_max_width").id+=strId;
			document.getElementById("fFile_image_max_width_label").id+=strId;
			document.getElementById("fFile_image_max_width_label"+strId).htmlFor="fFile_image_max_width"+strId;
			document.getElementById("fFile_image_max_height").name+=strId;
			document.getElementById("fFile_image_max_height").id+=strId;
			document.getElementById("fFile_image_max_height_label").id+=strId;
			document.getElementById("fFile_image_max_height_label"+strId).htmlFor="fFile_image_max_height"+strId;
			
			document.getElementById("checkboxOptions").id+=strId;
			
			document.getElementById("dropDownOptions").id+=strId;
			document.getElementById("fDrop_down_options").name+=strId;
			document.getElementById("fDrop_down_options").id+=strId;
			
			document.getElementById("yearOptions").id+=strId;
			document.getElementById("fYear_start").name+=strId;
			document.getElementById("fYear_start").id+=strId;
			document.getElementById("fYear_start_label").id+=strId;
			document.getElementById("fYear_start_label"+strId).htmlFor="fYear_start"+strId;
			document.getElementById("fYear_end").name+=strId;
			document.getElementById("fYear_end").id+=strId;
			document.getElementById("fYear_end_label").id+=strId;
			document.getElementById("fYear_end_label"+strId).htmlFor="fYear_end"+strId;
			
			document.getElementById("urlOptions").id+=strId;
			document.getElementById("urlOptionsOther").id+=strId;
			document.getElementById("fUrl_target_id_label").id+=strId;
			document.getElementById("fUrl_target_id_label"+strId).htmlFor="fUrl_target_id"+strId;
			document.getElementById("fUrl_target_id").name+=strId;
			document.getElementById("fUrl_target_id").id+=strId;
			document.getElementById("fUrl_target_other").name+=strId;
			document.getElementById("fUrl_target_other").id+=strId;
			
			document.getElementById("countDownOptions").id+=strId;

			document.getElementById("categorySelectOptions").id+=strId;
			document.getElementById("fCategory_selector_type_id").name+=strId;
			document.getElementById("fCategory_selector_type_id").id+=strId;
			document.getElementById("fEntry_selector_type_id").name+=strId;
			document.getElementById("fEntry_selector_type_id").id+=strId;
			document.getElementById("fEntry_selector_category_id").name+=strId;
			document.getElementById("fEntry_selector_category_id").id+=strId;
			CMS_Main.addListener(document.getElementById("fEntry_selector_type_id"+strId),"change",function(e){
				CMS_Dynamic_Form.entrySelectTypeChange(CMS_Main.getEventSrc(e),document.getElementById("fEntry_selector_category_id"+strId));
			});

			document.getElementById("entrySelectOptions").id+=strId;
			
			document.getElementById("requiredOptions").id+=strId;
			document.getElementById("fField_required").name+=strId;
			document.getElementById("fField_required").id+=strId;
			document.getElementById("fField_required_label").id+=strId;
			document.getElementById("fField_required_label"+strId).htmlFor="fField_required"+strId;
			
			//update stored id
			if(frm.fField_id.length)
				frm.fField_id[frm.fField_id.length-1].value=strId;
			else
				frm.fField_id.value=strId;
				
			//display field options
			try
			{
				document.getElementById("fieldOptions"+strId).style.display="table-row";
			}
			catch(e)
			{
				//IE
				try
				{
					document.getElementById("fieldOptions"+strId).style.display="block";
				}
				catch(e)
				{
					document.nativeGetElementById("fieldOptions"+strId).style.display="block";
				}
			}
			
			//set focus
			if(document.getElementById("fField_title"+strId))			
				document.getElementById("fField_title"+strId).focus();
			
			//re-initialize the drag drop
			this.initializeOrder(frm);
		}
		return false;
	},
	
	fieldTypeChange:function(frm,eleInput)
	{
		if(frm)
		{
			//get id
			var strId=eleInput.id.replace("fField_type","");
			
			switch(eleInput.value)
			{
				case(this.intTextTypeId.toString()):
					document.getElementById("fileOptions"+strId).style.display="none";
					document.getElementById("checkboxOptions"+strId).style.display="none";
					document.getElementById("textEditorOptions"+strId).style.display="none";
					document.getElementById("dropDownOptions"+strId).style.display="none";
					document.getElementById("yearOptions"+strId).style.display="none";
					document.getElementById("urlOptions"+strId).style.display="none";
					document.getElementById("countDownOptions"+strId).style.display="none";
					document.getElementById("categorySelectOptions"+strId).style.display="none";
					document.getElementById("entrySelectOptions"+strId).style.display="none";
					document.getElementById("textOptions"+strId).style.display="block";
					
					document.getElementById("requiredOptions"+strId).style.display="block";
					break;
				case(this.intTextAreaTypeId.toString()):
					document.getElementById("fileOptions"+strId).style.display="none";
					document.getElementById("checkboxOptions"+strId).style.display="none";
					document.getElementById("textEditorOptions"+strId).style.display="none";
					document.getElementById("dropDownOptions"+strId).style.display="none";
					document.getElementById("yearOptions"+strId).style.display="none";
					document.getElementById("urlOptions"+strId).style.display="none";
					document.getElementById("countDownOptions"+strId).style.display="none";
					document.getElementById("categorySelectOptions"+strId).style.display="none";
					document.getElementById("entrySelectOptions"+strId).style.display="none";
					document.getElementById("textOptions"+strId).style.display="block";
					
					document.getElementById("requiredOptions"+strId).style.display="block";
					break;
				case(this.intFileTypeId.toString()):
					document.getElementById("textOptions"+strId).style.display="none";
					document.getElementById("checkboxOptions"+strId).style.display="none";
					document.getElementById("textEditorOptions"+strId).style.display="none";
					document.getElementById("dropDownOptions"+strId).style.display="none";
					document.getElementById("yearOptions"+strId).style.display="none";
					document.getElementById("urlOptions"+strId).style.display="none";
					document.getElementById("countDownOptions"+strId).style.display="none";
					document.getElementById("categorySelectOptions"+strId).style.display="none";
					document.getElementById("entrySelectOptions"+strId).style.display="none";
					document.getElementById("fileOptions"+strId).style.display="block";
					
					document.getElementById("requiredOptions"+strId).style.display="block";
					break;
				case(this.intTextEditorTypeId.toString()):
					document.getElementById("textOptions"+strId).style.display="none";
					document.getElementById("fileOptions"+strId).style.display="none";
					document.getElementById("checkboxOptions"+strId).style.display="none";
					document.getElementById("dropDownOptions"+strId).style.display="none";
					document.getElementById("yearOptions"+strId).style.display="none";
					document.getElementById("urlOptions"+strId).style.display="none";
					document.getElementById("countDownOptions"+strId).style.display="none";
					document.getElementById("categorySelectOptions"+strId).style.display="none";
					document.getElementById("entrySelectOptions"+strId).style.display="none";
					document.getElementById("textEditorOptions"+strId).style.display="block";
					
					document.getElementById("requiredOptions"+strId).style.display="none";
					break;
				case(this.intCheckboxTypeId.toString()):
					document.getElementById("textOptions"+strId).style.display="none";
					document.getElementById("fileOptions"+strId).style.display="none";
					document.getElementById("textEditorOptions"+strId).style.display="none";
					document.getElementById("dropDownOptions"+strId).style.display="none";
					document.getElementById("yearOptions"+strId).style.display="none";
					document.getElementById("urlOptions"+strId).style.display="none";
					document.getElementById("countDownOptions"+strId).style.display="none";
					document.getElementById("categorySelectOptions"+strId).style.display="none";
					document.getElementById("entrySelectOptions"+strId).style.display="none";
					document.getElementById("checkboxOptions"+strId).style.display="block";
					
					document.getElementById("requiredOptions"+strId).style.display="none";
					break;
				case(this.intDropDownTypeId.toString()):
					document.getElementById("textOptions"+strId).style.display="none";
					document.getElementById("fileOptions"+strId).style.display="none";
					document.getElementById("textEditorOptions"+strId).style.display="none";
					document.getElementById("checkboxOptions"+strId).style.display="none";
					document.getElementById("yearOptions"+strId).style.display="none";
					document.getElementById("urlOptions"+strId).style.display="none";
					document.getElementById("countDownOptions"+strId).style.display="none";
					document.getElementById("categorySelectOptions"+strId).style.display="none";
					document.getElementById("entrySelectOptions"+strId).style.display="none";
					document.getElementById("dropDownOptions"+strId).style.display="block";
					
					document.getElementById("requiredOptions"+strId).style.display="none";
					break;
				case(this.intYearTypeId.toString()):
					document.getElementById("textOptions"+strId).style.display="none";
					document.getElementById("fileOptions"+strId).style.display="none";
					document.getElementById("textEditorOptions"+strId).style.display="none";
					document.getElementById("checkboxOptions"+strId).style.display="none";
					document.getElementById("dropDownOptions"+strId).style.display="none";
					document.getElementById("urlOptions"+strId).style.display="none";
					document.getElementById("countDownOptions"+strId).style.display="none";
					document.getElementById("categorySelectOptions"+strId).style.display="none";
					document.getElementById("entrySelectOptions"+strId).style.display="none";
					document.getElementById("yearOptions"+strId).style.display="block";
					
					document.getElementById("requiredOptions"+strId).style.display="none";
					break;
				case(this.intUrlTypeId.toString()):
					document.getElementById("textOptions"+strId).style.display="none";
					document.getElementById("fileOptions"+strId).style.display="none";
					document.getElementById("textEditorOptions"+strId).style.display="none";
					document.getElementById("checkboxOptions"+strId).style.display="none";
					document.getElementById("dropDownOptions"+strId).style.display="none";
					document.getElementById("yearOptions"+strId).style.display="none";
					document.getElementById("countDownOptions"+strId).style.display="none";
					document.getElementById("categorySelectOptions"+strId).style.display="none";
					document.getElementById("entrySelectOptions"+strId).style.display="none";
					document.getElementById("urlOptions"+strId).style.display="block";
					
					document.getElementById("requiredOptions"+strId).style.display="block";
					break;
				case(this.intCountDownTypeId.toString()):
					document.getElementById("textOptions"+strId).style.display="none";
					document.getElementById("fileOptions"+strId).style.display="none";
					document.getElementById("textEditorOptions"+strId).style.display="none";
					document.getElementById("checkboxOptions"+strId).style.display="none";
					document.getElementById("dropDownOptions"+strId).style.display="none";
					document.getElementById("yearOptions"+strId).style.display="none";
					document.getElementById("urlOptions"+strId).style.display="none";
					document.getElementById("categorySelectOptions"+strId).style.display="none";
					document.getElementById("entrySelectOptions"+strId).style.display="none";
					document.getElementById("countDownOptions"+strId).style.display="block";
					
					document.getElementById("requiredOptions"+strId).style.display="block";
					break;
				case(this.intCategoryTypeId.toString()):
					document.getElementById("textOptions"+strId).style.display="none";
					document.getElementById("fileOptions"+strId).style.display="none";
					document.getElementById("textEditorOptions"+strId).style.display="none";
					document.getElementById("checkboxOptions"+strId).style.display="none";
					document.getElementById("dropDownOptions"+strId).style.display="none";
					document.getElementById("yearOptions"+strId).style.display="none";
					document.getElementById("urlOptions"+strId).style.display="none";
					document.getElementById("countDownOptions"+strId).style.display="none";
					document.getElementById("entrySelectOptions"+strId).style.display="none";
					document.getElementById("categorySelectOptions"+strId).style.display="block";
					
					document.getElementById("requiredOptions"+strId).style.display="block";
					break;
				case(this.intEntryTypeId.toString()):
					document.getElementById("textOptions"+strId).style.display="none";
					document.getElementById("fileOptions"+strId).style.display="none";
					document.getElementById("textEditorOptions"+strId).style.display="none";
					document.getElementById("checkboxOptions"+strId).style.display="none";
					document.getElementById("dropDownOptions"+strId).style.display="none";
					document.getElementById("yearOptions"+strId).style.display="none";
					document.getElementById("urlOptions"+strId).style.display="none";
					document.getElementById("countDownOptions"+strId).style.display="none";
					document.getElementById("categorySelectOptions"+strId).style.display="none";
					document.getElementById("entrySelectOptions"+strId).style.display="block";
					
					document.getElementById("requiredOptions"+strId).style.display="block";
					break;
				default:
					document.getElementById("textOptions"+strId).style.display="none";
					document.getElementById("fileOptions"+strId).style.display="none";
					document.getElementById("textEditorOptions"+strId).style.display="none";
					document.getElementById("checkboxOptions"+strId).style.display="none";
					document.getElementById("dropDownOptions"+strId).style.display="none";
					document.getElementById("yearOptions"+strId).style.display="none";
					document.getElementById("urlOptions"+strId).style.display="none";
					document.getElementById("countDownOptions"+strId).style.display="none";
					document.getElementById("categorySelectOptions"+strId).style.display="none";
					document.getElementById("entrySelectOptions"+strId).style.display="none";
					
					document.getElementById("requiredOptions"+strId).style.display="none";
					break;
			}
		}
	},
	
	urlTargetIdChange:function(eleSelect)
	{
		var strId="";
		
		if(eleSelect)
		{
			strId=eleSelect.id.replace("fUrl_target_id","");
			
			if(Number(eleSelect.value)==1)
			{
				if(document.getElementById("urlOptionsOther"+strId))
					document.getElementById("urlOptionsOther"+strId).style.display="inline";
			}
			else
			{
				if(document.getElementById("urlOptionsOther"+strId))
					document.getElementById("urlOptionsOther"+strId).style.display="none";
			}
		}
	},

	entrySelectTypeChange:function(eleSelectType,eleSelectCategory)
	{
		if(eleSelectType && eleSelectCategory)
		{
			var intTypeId=Number(eleSelectType.value);
			
			//clear options
			while(eleSelectCategory.options.length>0)
				eleSelectCategory.remove(0);
			
			if(eleSelectType.value>0)
			{
				var eleOptionLoading=document.createElement("option");
				eleOptionLoading.text=CMS_Main.getLoadingMessage();
				eleOptionLoading.value="0";
				try{
					eleSelectCategory.add(eleOptionLoading, null);
				}catch(e){
					eleSelectCategory.add(eleOptionLoading);
				}
				
				var objRequest=CMS_Main.createRequest();
				objRequest.open("GET",CMS_Main.getRootDirectory()+"/get_element_xml.php?function=getEntrySelectorCategoryList&fField_entry_selector_type_id="+intTypeId.toString(),true);
				objRequest.onreadystatechange=function()
				{
					if(objRequest.readyState==4 && objRequest.status==200)
					{
						//clear loading message
						while(eleSelectCategory.options.length>0)
							eleSelectCategory.remove(0);
				
						objRequestData=eval("("+objRequest.responseText+")");
						
						//add blank option
						var eleOption=document.createElement("option");
						eleOption.value="0";
						eleOption.text=" ";
						try{
							eleSelectCategory.add(eleOption,null);
						}catch(e){
							eleSelectCategory.add(eleOption);
						}
						
						//add categories
						for(var i=0;i<objRequestData.arrCategories.length;i++)
						{
							var eleOption=document.createElement("option");
							eleOption.value=objRequestData.arrCategories[i].intCategoryId;
							eleOption.text=objRequestData.arrCategories[i].strCategoryName;
							try{
								eleSelectCategory.add(eleOption,null);						
							}catch(e){
								eleSelectCategory.add(eleOption);						
							}
						}
					}
				};
				objRequest.send(null);
			}
		}
	},
		
	removeField:function(eleA)
	{
		if(eleA)
		{
			//get id
			var strId=eleA.id.replace("removeField","");
			
			//remove field
			try
			{
				document.getElementById("fieldOptions"+strId).parentNode.removeChild(document.getElementById("fieldOptions"+strId));
			}
			catch(e)
			{
				document.all["fieldOptions"+strId].parentNode.removeChild(document.all["fieldOptions"+strId]); //IE
			}
		}
		
		return false;
	}
}/*--------------------------------------------------
	Project:	The November Group - CMS Administration
	Script:		cms_dynamic_code.js
	Includes:	CMS_Dynamic_Code
--------------------------------------------------*/

var CMS_Dynamic_Code={
	
	objEntryListRequest:null,
	objCodeListRequest:null,
	strFilterAlpha:"all",
	intPageNumber:1,
	
	manageCodes:function()
	{
		CMS_Main.setPage("manageDynamicCodes"); //store page selection

		CMS_Main.objRequest.open("GET","get_page_xml.php?page="+CMS_Main.getPage(),true);
		CMS_Main.objRequest.onreadystatechange=CMS_Main.updatePage;
		CMS_Main.objRequest.send(null);
		
		return false;
	},
	
	manageCodesInitialize:function(frm)
	{
		if(frm)
		{
			//reselect previously selected filters
			frm.fFilter_alpha.value=this.strFilterAlpha;

			//alpha
			if(document.getElementById("filterAlpha"))
			{
				var arrLinks=document.getElementById("filterAlpha").getElementsByTagName("a");
				for(var i=0;i<arrLinks.length;i++)
				{
					if(arrLinks[i].firstChild.firstChild.firstChild.nodeValue.toLowerCase()==frm.fFilter_alpha.value.toString())
					{
						arrLinks[i].className+=" current_page";
						break;
					}
				}
			}
			if(document.getElementById("filterAlphaTop"))
			{
				var arrLinks=document.getElementById("filterAlphaTop").getElementsByTagName("a");
				for(var i=0;i<arrLinks.length;i++)
				{
					if(arrLinks[i].firstChild.firstChild.firstChild.nodeValue.toLowerCase()==frm.fFilter_alpha.value.toString())
					{
						arrLinks[i].className+=" current_page";
						break;
					}
				}
			}
			
			//reselect previously selected show count
			var blnSelected=false;
			if(document.getElementById("fShow_count"))
			{
				var eleSelect2=document.getElementById("fShow_count");
				for(var i=0;i<eleSelect2.options.length;i++)
				{
					if(Number(eleSelect2.options[i].value)==CMS_Client_User_Settings.getShowCountDynamicCodes())
					{
						eleSelect2.options[i].selected=true;
						blnSelected=true;
						break;
					}
				}
				if(!blnSelected)
				{
					eleSelect2.options[0].selected=true;
					CMS_Client_User_Settings.setShowCountDynamicCodes(Number(eleSelect2.options[0].value));
				}
			}
			blnSelected=false;
			if(document.getElementById("fShow_count_top"))
			{
				var eleSelect2=document.getElementById("fShow_count_top");
				for(var i=0;i<eleSelect2.options.length;i++)
				{
					if(Number(eleSelect2.options[i].value)==CMS_Client_User_Settings.getShowCountDynamicCodes())
					{
						eleSelect2.options[i].selected=true;
						blnSelected=true;
						break;
					}
				}
				if(!blnSelected)
				{
					eleSelect2.options[0].selected=true;
					CMS_Client_User_Settings.setShowCountDynamicCodes(Number(eleSelect2.options[0].value));
				}
			}

			//retrieve previously selected page number
			if(frm.fPage_number)
				frm.fPage_number.value=this.intPageNumber.toString();
			
			this.onCategoryOrFilterChange(frm);
		}
	},
	
	onCategoryOrFilterChange:function(frm)
	{
		this.getCodeList(frm);
	},
	
	onAlphaClick:function(frm,eleA)
	{
		if(frm && eleA)
		{
			frm.fFilter_alpha.value=eleA.firstChild.firstChild.firstChild.nodeValue.toLowerCase(); //retrieve selected value
			this.strFilterAlpha=frm.fFilter_alpha.value.toString();
			
			//reset classes
			if(document.getElementById("filterAlpha"))
			{
				var arrLinks=document.getElementById("filterAlpha").getElementsByTagName("a");
				for(var i=0;i<arrLinks.length;i++)
				{
					if(arrLinks[i].className.indexOf("current_page")>-1)
						arrLinks[i].className=arrLinks[i].className.replace("current_page","");
					if(arrLinks[i].firstChild.firstChild.firstChild.nodeValue.toLowerCase()==frm.fFilter_alpha.value)
						arrLinks[i].className+=" current_page";
				}
			}
			if(document.getElementById("filterAlphaTop"))
			{
				var arrLinks=document.getElementById("filterAlphaTop").getElementsByTagName("a");
				for(var i=0;i<arrLinks.length;i++)
				{
					if(arrLinks[i].className.indexOf("current_page")>-1)
						arrLinks[i].className=arrLinks[i].className.replace("current_page","");
					if(arrLinks[i].firstChild.firstChild.firstChild.nodeValue.toLowerCase()==frm.fFilter_alpha.value)
						arrLinks[i].className+=" current_page";
				}
			}
			
			//update filter
			CMS_Dynamic_Code.onCategoryOrFilterChange(frm);
		}
		
		return false; //cancel link
	},
	
	onShowCountChange:function(frm,eleSelect)
	{
		if(frm)
		{
			var intPages=1;

			if(document.getElementById("fShow_count"))
			{
				var eleSelect2=document.getElementById("fShow_count");
				for(var i=0;i<eleSelect2.options.length;i++)
				{
					if(Number(eleSelect2.options[i].value)==Number(eleSelect.options[eleSelect.selectedIndex].value))
						eleSelect2.options[i].selected=true;
				}
			}
			if(document.getElementById("fShow_count_top"))
			{
				var eleSelect2=document.getElementById("fShow_count_top");
				for(var i=0;i<eleSelect2.options.length;i++)
				{
					if(Number(eleSelect2.options[i].value)==Number(eleSelect.options[eleSelect.selectedIndex].value))
						eleSelect2.options[i].selected=true;
				}
			}
			
			CMS_Client_User_Settings.setShowCountDynamicCodes(Number(eleSelect.value)); //store selected value
			
			//calculate number of pages
			if(Number(eleSelect.value)>0)
				intPages=Math.ceil(Number(frm.fCode_count.value)/Number(eleSelect.value));
			if(intPages==0)
				intPages++;
			
			//check if current page number will exist for new show count
			if(Number(frm.fPage_number.value)>intPages)
				frm.fPage_number.value="1"; //reset page number
			
			this.getCodeList(frm);
		}
	},
	
	onPageClick:function(frm,eleNumber)
	{
		if(frm && eleNumber)
		{
			frm.fPage_number.value=eleNumber.firstChild.firstChild.firstChild.nodeValue; //retrieve selected value
			this.getCodeList(frm);
		}
		return false;
	},
	
	updatePagination:function(frm)
	{
		if(frm && frm.fShow_count)
		{
			var intPages=1;
			
			//calculate number of pages
			if(Number(frm.fShow_count.value)>0)
				intPages=Math.ceil(Number(frm.fCode_count.value)/Number(frm.fShow_count.value));
			if(intPages==0)
				intPages++;
			
			//rebuild page links
			if(document.getElementById("filterPage"))
			{
				document.getElementById("filterPage").innerHTML="";
				for(var i=0;i<intPages;i++)
					document.getElementById("filterPage").innerHTML+="<li><a href=\"#\" onclick=\"return CMS_Dynamic_Code.onPageClick(document.getElementById('frmManageDynamicCodes'),this);\"><span><span>"+(i+1).toString()+"</span></span></a></li>";
			}
			if(document.getElementById("filterPageTop"))
			{
				document.getElementById("filterPageTop").innerHTML="";
				for(var i=0;i<intPages;i++)
					document.getElementById("filterPageTop").innerHTML+="<li><a href=\"#\" onclick=\"return CMS_Dynamic_Code.onPageClick(document.getElementById('frmManageDynamicCodes'),this);\"><span><span>"+(i+1).toString()+"</span></span></a></li>";
			}
			
			//select page link
			var blnSelected=false;
			if (document.getElementById("filterPage")) 
			{
				var arrLinks=document.getElementById("filterPage").getElementsByTagName("a");
				for(var i=0;i<arrLinks.length;i++)
				{
					if(arrLinks[i].firstChild.firstChild.firstChild.nodeValue==frm.fPage_number.value.toString())
					{
						//change class
						arrLinks[i].className+=" current_page";
						blnSelected=true;
						break;
					}
				}
				if(!blnSelected)
				{
					arrLinks[0].className+=" current_page";
					frm.fPage_number.value=arrLinks[0].firstChild.firstChild.firstChild.nodeValue;
				}
			}
			blnSelected=false;
			if (document.getElementById("filterPageTop")) 
			{
				var arrLinks=document.getElementById("filterPageTop").getElementsByTagName("a");
				for(var i=0;i<arrLinks.length;i++)
				{
					if(arrLinks[i].firstChild.firstChild.firstChild.nodeValue==frm.fPage_number.value.toString())
					{
						//change class
						arrLinks[i].className+=" current_page";
						blnSelected=true;
						break;
					}
				}
				if(!blnSelected)
				{
					arrLinks[0].className+=" current_page";
					frm.fPage_number.value=arrLinks[0].firstChild.firstChild.firstChild.nodeValue;
				}
			}
			
			//store selected value
			this.intPageNumber=Number(frm.fPage_number.value);
			
			//calculate code count
			var intCountStart=(Number(frm.fPage_number.value)-1)*Number(frm.fShow_count.value);
			var intCountEnd=(Number(frm.fShow_count.value)==0 ? Number(frm.fCode_count.value) : Math.min(Number(frm.fShow_count.value)+intCountStart,Number(frm.fCode_count.value)));
			
			//update code count
			if(document.getElementById("codeCountStart"))
				document.getElementById("codeCountStart").innerHTML=(Math.min(intCountStart+1,Number(frm.fCode_count.value))).toString();
			if(document.getElementById("codeCountEnd"))
				document.getElementById("codeCountEnd").innerHTML=intCountEnd.toString();
			if(document.getElementById("codeCount"))
				document.getElementById("codeCount").innerHTML=frm.fCode_count.value.toString();

			if(document.getElementById("codeCountStartTop"))
				document.getElementById("codeCountStartTop").innerHTML=(Math.min(intCountStart+1,Number(frm.fCode_count.value))).toString();
			if(document.getElementById("codeCountEndTop"))
				document.getElementById("codeCountEndTop").innerHTML=intCountEnd.toString();
			if(document.getElementById("codeCountTop"))
				document.getElementById("codeCountTop").innerHTML=frm.fCode_count.value.toString();
		}
	},
	
	getCodeList:function(frm)
	{
		var strHtml="";
		
		//clear code list
		while(document.getElementById("codeListContainer").firstChild)
			document.getElementById("codeListContainer").removeChild(document.getElementById("codeListContainer").firstChild);
		
		//add loading message
		var eleLoading=document.createElement("tr");
		
		eleLoading.appendChild(document.createElement("td"));
		eleLoading.childNodes[0].colSpan=5;
		eleLoading.childNodes[0].appendChild(document.createTextNode(CMS_Main.getLoadingMessage()));
		document.getElementById("codeListContainer").appendChild(eleLoading);
		
		//get code list
		this.objCodeListRequest=CMS_Main.createRequest();
		this.objCodeListRequest.open("GET","get_element_xml.php?function=getDynamicCodeListJson&fFilter_alpha="+encodeURIComponent(CMS_Dynamic_Code.strFilterAlpha)+"&fShow_count="+frm.fShow_count.value.toString()+"&fPage_number="+frm.fPage_number.value.toString(),true);
		this.objCodeListRequest.onreadystatechange=function(){
			if(CMS_Dynamic_Code.objCodeListRequest.readyState==4)
			{
				if(CMS_Dynamic_Code.objCodeListRequest.status==200)
				{
					//clear loading message
					while(document.getElementById("codeListContainer").firstChild)
						document.getElementById("codeListContainer").removeChild(document.getElementById("codeListContainer").firstChild);
					
					var objCodeData=eval("("+CMS_Dynamic_Code.objCodeListRequest.responseText+")");
					document.getElementById("fCode_count").value=objCodeData.intCodeCount.toString();
					
					//add rows
					for(i in objCodeData.arrCodes)
					{
						var eleRow=CMS_Dynamic_Code.createRow(objCodeData.arrCodes[i]);
						
						if(i%2==0)
							eleRow.className="first";
						else
							eleRow.className="second";
						
						document.getElementById("codeListContainer").appendChild(eleRow);
					}
					
					if(objCodeData.arrCodes.length==0)
					{
						var eleRow=CMS_Dynamic_Code.createEmptyRow();
						document.getElementById("codeListContainer").appendChild(eleRow);
					}
					
					CMS_Dynamic_Code.updatePagination(document.getElementById("frmManageDynamicCodes"));
				}
			}
		};
		this.objCodeListRequest.send(null);
		
		return false;
	},
	
	createRow:function(objCode)
	{
		var eleRow=document.createElement("tr");
		
		var eleTd1=document.createElement("td");
		eleTd1.appendChild(document.createTextNode(objCode.strTitle));
		eleRow.appendChild(eleTd1);
		
		var eleTd3=document.createElement("td");
		eleTd3.appendChild(document.createTextNode(objCode.strFormTitle));
		eleRow.appendChild(eleTd3);
		
		var eleTd4=document.createElement("td");
		eleTd4.appendChild(document.createTextNode(objCode.strShow));
		eleRow.appendChild(eleTd4);
		
		var eleTd2=document.createElement("td");
		eleTd2.appendChild(document.createTextNode(objCode.strDateCreated));
		eleRow.appendChild(eleTd2);
		
		var eleTd5=document.createElement("td");
		eleTd5.style.width="96px";
		eleTd5.innerHTML=" \
		<div class=\"actions\"> \
			<ul> \
				<li><a class=\"action7\" href=\"#\" onclick=\"return CMS_Dynamic_Code.duplicateCode("+objCode.intCodeId.toString()+");\" title=\"Copy\">Copy</a></li> \
				<li><a class=\"action5\" href=\"#\" onclick=\"return CMS_Dynamic_Code.editCode("+objCode.intCodeId.toString()+");\" title=\"Edit\">Edit</a></li> \
				<li><a class=\"action8\" href=\"#\" onclick=\"return CMS_Dynamic_Code.editCodeText("+objCode.intCodeId.toString()+");\" title=\"Edit code text\">Edit code text</a></li> \
				<li><a class=\"action4\" href=\"#\" onclick=\"return CMS_Dynamic_Code.deleteCode("+objCode.intCodeId.toString()+");\" title=\"Delete\">Delete</a></li> \
			</ul> \
			<div style=\"float:right;\"> \
				<input class=\"radio\" name=\"selectCode\" id=\"selectCode"+objCode.intCodeId.toString()+"\" type=\"checkbox\" value=\""+objCode.intCodeId.toString()+"\" /> \
				<input name=\"selectCodeTitle\" id=\"selectCodeTitle"+objCode.intCodeId.toString()+"\" type=\"hidden\" value=\""+objCode.strTitle+"\" /> \
			</div> \
		</div>";
		eleRow.appendChild(eleTd5);
		
		return eleRow;
	},
	
	createEmptyRow:function()
	{
		var eleRow=document.createElement("tr");
		
		var eleTd1=document.createElement("td");
		eleTd1.colSpan=5;
		eleTd1.appendChild(document.createTextNode("No codes to display"));
		eleRow.appendChild(eleTd1);
		
		return eleRow;
	},
	
	selectAllClick:function(frm)
	{
		for(var i=0;i<frm.length;i++)
			if(frm.elements[i].name && frm.elements[i].name.indexOf("selectCode")==0)
				frm.elements[i].checked=true;
		return false;
	},
	
	deselectAllClick:function(frm)
	{
		for(var i=0;i<frm.length;i++)
			if(frm.elements[i].name && frm.elements[i].name.indexOf("selectCode")==0)
				frm.elements[i].checked=false;
		return false;
	},
	
	onActionChange:function(frm,eleSelect)
	{
		if(frm)
		{
		}
	},
	
	onActionClick:function(frm,eleSelect)
	{
		if(eleSelect)
		{
			switch(Number(eleSelect.value))
			{
				case(1): //delete
					this.deleteCodes(frm);
					break;
				default:
			}
		}
		return false; //cancel link
	},
	
	deleteCodes:function(frm)
	{
		var arrCodeIds=new Array();
		var arrCodeTitles=new Array();
		
		for(var i=0;i<frm.length;i++)
		{
			if(frm.elements[i].name && frm.elements[i].name.indexOf("selectCode")==0 && frm.elements[i].type=="checkbox" && frm.elements[i].checked)
			{
				arrCodeIds[arrCodeIds.length]=frm.elements[i].value;
				arrCodeTitles[arrCodeTitles.length]=frm.elements[i+1].value;
			}
		}
		if(arrCodeIds.length==0)
		{
			alert("You do not have any codes selected.");
		}
		else if(confirm("Are you sure you want to delete "+(arrCodeIds.length==1 ? arrCodeTitles[0]+"?" : "the following codes?\n\n\t"+arrCodeTitles.join("\n\t")+"\n ")))
		{
			CMS_Main.objRequest.open("POST","get_page_xml.php",true);
			CMS_Main.objRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
			CMS_Main.objRequest.onreadystatechange=CMS_Main.updatePage;
			CMS_Main.objRequest.send("page="+CMS_Main.getPage()+"&fAction=deleteDynamicCodes&fCode_id[]="+arrCodeIds.join("&fCode_id[]="));
		}
		
		return false;
	},
	

	addCode:function()
	{
		CMS_Main.objRequest.open("GET","get_page_xml.php?page=editDynamicCode",true);
		CMS_Main.objRequest.onreadystatechange=CMS_Main.updatePage;
		CMS_Main.objRequest.send(null);
		
		return false;
	},
	
	editCode:function(intCodeId)
	{
		CMS_Main.objRequest.open("GET","get_page_xml.php?page=editDynamicCode&fCode_id="+intCodeId.toString(),true);
		CMS_Main.objRequest.onreadystatechange=CMS_Main.updatePage;
		CMS_Main.objRequest.send(null);
		
		return false;
	},
	
	duplicateCode:function(intCodeId)
	{
		CMS_Main.objRequest.open("GET","get_page_xml.php?page=duplicateDynamicCode&fCode_id="+intCodeId.toString(),true);
		CMS_Main.objRequest.onreadystatechange=CMS_Main.updatePage;
		CMS_Main.objRequest.send(null);
		
		return false;
	},
	
	updateFieldIds:function(intCodeId,intFormIdOriginal,strFormTitleOriginal,intFormId,strFormTitle)
	{
		if(intCodeId!=0)
		{
			if(confirm("Would you like to update the id numbers in this code for any fields from "+strFormTitleOriginal+" with the same names as the fields in "+strFormTitle+"?"))
			{
				var objRequest=CMS_Main.createRequest();
				objRequest.open("GET","get_element_xml.php?function=updateDynamicCodeFieldIds&fCode_id="+intCodeId.toString()+"&fForm_id_original="+intFormIdOriginal.toString()+"&fForm_id="+intFormId.toString(),true);
				objRequest.onreadystatechange=function()
				{
					if(objRequest.readyState==4 && objRequest.status==200)
					{
						var objData=eval("("+objRequest.responseText+")");
						
						if(objData.strResults)
							alert(objData.strResults);
					}
				};
				objRequest.send(null);
			}
		}
	},
	
	editCodeText:function(intCodeId)
	{
		CMS_Main.objRequest.open("GET","get_page_xml.php?page=editDynamicCodeText&fCode_id="+intCodeId.toString(),true);
		CMS_Main.objRequest.onreadystatechange=CMS_Main.updatePage;
		CMS_Main.objRequest.send(null);
		
		return false;
	},
	
	editCodeInitialize:function(frm)
	{
		this.onTypeChange(frm);
		this.onSelectEntriesClick(frm.fSelect_entries);
		
		if(document.getElementById("fCode"))
			CMS_Main.allowTabs(document.getElementById("fCode"));
		
		if(frm)
		{
			if(frm.fTitle)
			{
				frm.fTitle.focus();
				frm.fTitle.select();
			}
		}
		return false;
	},
	
	onFormIdChange:function(frm)
	{
		this.getEntryList(frm);
		
		//get new and original form titles
		var strFormTitle=frm.fForm_id.options[frm.fForm_id.selectedIndex].text;
		var strFormTitleOriginal="";
		for(var intIndex=0;intIndex<frm.fForm_id.options.length;intIndex++)
		{
			if(frm.fForm_id.options[intIndex].value==frm.fForm_id_original.value)
			{
				strFormTitleOriginal=frm.fForm_id.options[intIndex].text;
				break;
			}
		}
			
		this.updateFieldIds(frm.fCode_id.value,frm.fForm_id_original.value,strFormTitleOriginal,frm.fForm_id.value,strFormTitle)
	},
	
	onTypeChange:function(frm)
	{
		if(frm && frm.fType)
		{
			switch(Number(frm.fType.value))
			{
				case(1): //display limited number of entries
					document.getElementById("displayOptions").style.display="block";
					document.getElementById("randomOptions").style.display="none";
					break;
				case(2): //display random entries
					document.getElementById("randomOptions").style.display="block";
					document.getElementById("displayOptions").style.display="none";
					break;
				default:
					document.getElementById("displayOptions").style.display="none";
					document.getElementById("randomOptions").style.display="none";
			}
		}
	},
	
	onSelectEntriesClick:function(eleInput)
	{
		if(eleInput)
		{
			if(eleInput.checked)
			{
				document.getElementById("selectEntries").style.display="block";
				this.getEntryList(eleInput.form);
			}
			else
			{
				document.getElementById("selectEntries").style.display="none";
			}
		}
		return false;
	},
	
	getEntryList:function(frm)
	{
		var strHtml="";
		
		//clear frm.fEntry_ids_available
		while(frm.fEntry_ids_available.length>0)
			frm.fEntry_ids_available.remove(0);
		
		//clear frm.fEntry_ids_available
		while(frm.fEntry_ids_selected.length>0)
			frm.fEntry_ids_selected.remove(0);
		
		//add loading message
		var eleOpt=document.createElement("option");
		eleOpt.text=CMS_Main.getLoadingMessage();
		eleOpt.value="0";
		frm.fEntry_ids_available.options[frm.fEntry_ids_available.length]=eleOpt;
		
		//get entry list
		this.objEntryListRequest=CMS_Main.createRequest();
		this.objEntryListRequest.open("GET","get_element_xml.php?function=getDynamicEntryListJson&fForm_id="+frm.fForm_id.value.toString(),true);
		this.objEntryListRequest.onreadystatechange=function(){
			if(CMS_Dynamic_Code.objEntryListRequest.readyState==4)
			{
				if(CMS_Dynamic_Code.objEntryListRequest.status==200)
				{
					//clear loading message
					while(frm.fEntry_ids_available.length>0)
						frm.fEntry_ids_available.remove(0);
					
					var objEntryData=eval("("+CMS_Dynamic_Code.objEntryListRequest.responseText+")");
					
					//add options
					for(i in objEntryData.arrEntries)
					{
						var eleOpt=document.createElement("option");
						eleOpt.text=objEntryData.arrEntries[i].strTitle;
						eleOpt.value=objEntryData.arrEntries[i].intEntryId;
						var blnSelected=false;
						//check if option should be in the selected list
						for(j=0;j<frm.fEntry_ids_selected_original.options.length;j++)
						{
							if(frm.fEntry_ids_selected_original.options[j].value==eleOpt.value)
							{
								blnSelected=true;
								break;
							}
						}
						//add option to correct list
						if(blnSelected)
							frm.fEntry_ids_selected.options[frm.fEntry_ids_selected.length]=eleOpt;
						else
							frm.fEntry_ids_available.options[frm.fEntry_ids_available.length]=eleOpt;
					}
				}
			}
		};
		this.objEntryListRequest.send(null);
		
		return false;
	},
	
	addEntryId:function(frm)
	{
		if(frm.fEntry_ids_available)
		{
			for(var i=0;i<frm.fEntry_ids_available.length;i++)
			{
				if(frm.fEntry_ids_available.options[i].selected)
				{
					frm.fEntry_ids_available.options[i].selected=false;
					try
					{
						frm.fEntry_ids_selected.add(frm.fEntry_ids_available.options[i],null);
					}
					catch(e) //ie
					{
						var eleOpt=document.createElement("option");
						eleOpt.text=frm.fEntry_ids_available.options[i].text;
						eleOpt.value=frm.fEntry_ids_available.options[i].value;
						
						frm.fEntry_ids_selected.options[frm.fEntry_ids_selected.length]=eleOpt;
						frm.fEntry_ids_available.remove(i);
					}
					i--; //retry at current index after removing current index
				}
			}
		}
	},
	
	removeEntryId:function(frm)
	{
		for(var i=0;i<frm.fEntry_ids_selected.options.length;i++)
		{
			if(frm.fEntry_ids_selected.options[i].selected)
			{
				frm.fEntry_ids_selected.options[i].selected=false;
				try
				{
					frm.fEntry_ids_available.add(frm.fEntry_ids_selected.options[i],null);
				}
				catch(e) //ie
				{
					var eleOpt=document.createElement("option");
					eleOpt.text=frm.fEntry_ids_selected.options[i].text;
					eleOpt.value=frm.fEntry_ids_selected.options[i].value;
					
					frm.fEntry_ids_available.options[frm.fEntry_ids_available.length]=eleOpt;
					frm.fEntry_ids_selected.remove(i);
				}
				i--; //retry at current index after removing current index
			}
		}
	},

	editCodeSubmit:function(frm)
	{
		var blnReturnValue=true;
		
		if(frm.fTitle.value.length==0)
		{
			alert("Please enter a title");
			frm.fTitle.focus();
			blnReturnValue=false;
		}
		else if(frm.fType.value==1 && isNaN(frm.fDisplay_count.value))
		{
			alert("Please enter a valid number");
			frm.fDisplay_count.focus();
			frm.fDisplay_count.select();
			blnReturnValue=false;
		}
		else if(frm.fType.value==1 && frm.fDisplay_count.value==0)
		{
			alert("Please enter a number greater than 0");
			frm.fDisplay_count.focus();
			frm.fDisplay_count.select();
			blnReturnValue=false;
		}
		
		if(blnReturnValue)
		{
			//select all items in fEntry_ids_selected
			if(frm.fEntry_ids_selected)
			{
				for(var i=0;i<frm.fEntry_ids_selected.length;i++)
				{
					frm.fEntry_ids_selected.options[i].selected=true;
				}
			}
			//select all entries in fEntry_ids_available
			if(frm.fEntry_ids_available)
			{
				for(var i=0;i<frm.fEntry_ids_available.length;i++)
				{
					frm.fEntry_ids_available.options[i].selected=true;
				}
			}

			document.getElementById("fSubmit").disabled=true;

			CMS_Main.objRequest.open("POST","get_page_xml.php",true);
			CMS_Main.objRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
			CMS_Main.objRequest.onreadystatechange=CMS_Main.updatePage;
			CMS_Main.objRequest.send(CMS_Main.formEncode(frm)+"&page="+CMS_Main.getPage());
		}
		
		return false;
	},	
	
	editCodeTextSubmit:function(frm)
	{
		var blnReturnValue=true;
		
		if(blnReturnValue)
		{
			document.getElementById("fSubmit").disabled=true;

			CMS_Main.objRequest.open("POST","get_page_xml.php",true);
			CMS_Main.objRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
			CMS_Main.objRequest.onreadystatechange=CMS_Main.updatePage;
			CMS_Main.objRequest.send(CMS_Main.formEncode(frm)+"&page="+CMS_Main.getPage());
		}
		
		return false;
	},	
	
	editCodeCancel:function()
	{
		CMS_Main.objRequest.open("GET","get_page_xml.php?page="+CMS_Main.getPage(),true);
		CMS_Main.objRequest.onreadystatechange=CMS_Main.updatePage;
		CMS_Main.objRequest.send(null);
		
		return false;
	},
	
	deleteCode:function(intCodeId)
	{
		var strTitle=document.getElementById("selectCodeTitle"+intCodeId).value.toString();

		if(confirm("Are you sure you want to delete "+strTitle+"?"))
		{
			CMS_Main.objRequest.open("GET","get_page_xml.php?page="+CMS_Main.getPage()+"&fAction=deleteDynamicCode&fCode_id="+intCodeId,true);
			CMS_Main.objRequest.onreadystatechange=CMS_Main.updatePage;
			CMS_Main.objRequest.send(null);
		}
		
		return false;
	}
}/*--------------------------------------------------
	Project:	The November Group - CMS Administration
	Script:		cms_dynamic_category.js
	Includes:	CMS_Dynamic_Category
--------------------------------------------------*/

var CMS_Dynamic_Category={
	
	manageCategories:function()
	{
		CMS_Main.setPage("manageDynamicCategories"); //store page selection

		CMS_Main.objRequest.open("GET","get_page_xml.php?page="+CMS_Main.getPage(),true);
		CMS_Main.objRequest.onreadystatechange=CMS_Main.updatePage;
		CMS_Main.objRequest.send(null);
		
		return false;
	},
	
	addCategory:function()
	{
		CMS_Main.objRequest.open("GET","get_page_xml.php?page=editDynamicCategory",true);
		CMS_Main.objRequest.onreadystatechange=CMS_Main.updatePage;
		CMS_Main.objRequest.send(null);
		
		return false;
	},
	
	editCategory:function(intCategoryId)
	{
		CMS_Main.objRequest.open("GET","get_page_xml.php?page=editDynamicCategory&fCategory_id="+intCategoryId.toString(),true);
		CMS_Main.objRequest.onreadystatechange=CMS_Main.updatePage;
		CMS_Main.objRequest.send(null);
		
		return false;
	},
	
	editCategoryInitialize:function(frm)
	{
		if(frm)
		{
			this.onFormIdChange(frm);
			
			if(frm.fName)
			{
				frm.fName.focus();
				frm.fName.select();
			}
		}
		return false;
	},
	
	onFormIdChange:function(frm)
	{
		if(frm && frm.fEntry_id && frm.fEntry_id_selected)
		{
			//store and remove "none" option
			var eleOptNone=frm.fEntry_id.options[0];
			frm.fEntry_id.remove(0);
			
			//remove remaining options
			while(frm.fEntry_id.length>0)
			{
				frm.fEntry_id.remove(0);
			}
			
			//add "loading" option
			var eleOptLoading=document.createElement("option");
			eleOptLoading.text=CMS_Main.strLoadingMessage;
			eleOptLoading.value=-1;
			frm.fEntry_id.options[0]=eleOptLoading;
			
			var objRequest=CMS_Main.createRequest();
			objRequest.open("GET","get_element_xml.php?function=getDynamicEntryListJson&fForm_id="+frm.fForm_id.value.toString(),true);
			objRequest.onreadystatechange=function()
			{
				if(objRequest.readyState==4 && objRequest.status==200)
				{
					var objData=eval("("+objRequest.responseText+")");
					
					if(objData.arrEntries)
					{
						//remove loading message
						frm.fEntry_id.remove(0);
						
						//restore "none" option
						frm.fEntry_id.options[0]=eleOptNone;
						
						//load entry options
						for(i in objData.arrEntries)
						{
							var eleOpt=document.createElement("option");
							eleOpt.text=objData.arrEntries[i].strTitle;
							eleOpt.value=objData.arrEntries[i].intEntryId;
							eleOpt.selected=(objData.arrEntries[i].intEntryId==frm.fEntry_id_selected.value);
							frm.fEntry_id.options[frm.fEntry_id.length]=eleOpt;
						}
					}
				}
			};
			objRequest.send(null);
		}
	},
	
	onParentIdChange:function(frm)
	{
		if(frm && frm.fCategory_id && frm.fParent_id && frm.fUrl)
		{
			if(Number(frm.fCategory_id.value)==0)
			{
				var objRequest=CMS_Main.createRequest();
				objRequest.open("GET","get_element_xml.php?function=getDynamicCategoryDefaultUrlJson&fCategory_id="+frm.fParent_id.value.toString(),true);
				objRequest.onreadystatechange=function()
				{
					if(objRequest.readyState==4 && objRequest.status==200)
					{
						var objData=eval("("+objRequest.responseText+")");
						
						if(objData.strDefaultUrl)
						{
							frm.fUrl.value=objData.strDefaultUrl;
							
							if(frm.fDefault_url)
								frm.fDefault_url.value=objData.strDefaultUrl;
						}
					}
				};
				objRequest.send(null);
			}
		}
	},
	
	editCategorySubmit:function(frm)
	{
		var blnReturnValue=true;
		
		if(frm.fName && frm.fName.value.length==0)
		{
			alert("Please enter a name");
			frm.fName.focus();
			blnReturnValue=false;
		}
		
		if(blnReturnValue)
		{
			document.getElementById("fSubmit").disabled=true;

			CMS_Main.objRequest.open("POST","get_page_xml.php",true);
			CMS_Main.objRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
			CMS_Main.objRequest.onreadystatechange=CMS_Main.updatePage;
			CMS_Main.objRequest.send(CMS_Main.formEncode(frm)+"&page="+CMS_Main.getPage());
		}
		
		return false;
	},	
	
	editCategoryCancel:function()
	{
		CMS_Main.objRequest.open("GET","get_page_xml.php?page="+CMS_Main.getPage(),true);
		CMS_Main.objRequest.onreadystatechange=CMS_Main.updatePage;
		CMS_Main.objRequest.send(null);
		
		return false;
	},
	
	deleteCategory:function(intCategoryId,strTitle)
	{
		if(confirm("Are you sure you want to delete "+strTitle+" and all of its subcategories?"))
		{
			CMS_Main.objRequest.open("GET","get_page_xml.php?page="+CMS_Main.getPage()+"&fAction=deleteDynamicCategory&fCategory_id="+intCategoryId,true);
			CMS_Main.objRequest.onreadystatechange=CMS_Main.updatePage;
			CMS_Main.objRequest.send(null);
		}
		
		return false;
	}
}/*--------------------------------------------------
	Project:	The November Group - CMS Administration
	Script:		cms_dynamic_category_code.js
	Includes:	CMS_Dynamic_Category_Code
--------------------------------------------------*/

var CMS_Dynamic_Category_Code={
	
	manageCodes:function()
	{
		CMS_Main.setPage("manageDynamicCategoryCodes"); //store page selection

		CMS_Main.objRequest.open("GET","get_page_xml.php?page="+CMS_Main.getPage(),true);
		CMS_Main.objRequest.onreadystatechange=CMS_Main.updatePage;
		CMS_Main.objRequest.send(null);
		
		return false;
	},
	
	addCode:function()
	{
		CMS_Main.objRequest.open("GET","get_page_xml.php?page=editDynamicCategoryCode",true);
		CMS_Main.objRequest.onreadystatechange=CMS_Main.updatePage;
		CMS_Main.objRequest.send(null);
		
		return false;
	},
	
	editCode:function(intCodeId)
	{
		CMS_Main.objRequest.open("GET","get_page_xml.php?page=editDynamicCategoryCode&fCode_id="+intCodeId.toString(),true);
		CMS_Main.objRequest.onreadystatechange=CMS_Main.updatePage;
		CMS_Main.objRequest.send(null);
		
		return false;
	},
	
	editCodeText:function(intCodeId)
	{
		CMS_Main.objRequest.open("GET","get_page_xml.php?page=editDynamicCategoryCodeText&fCode_id="+intCodeId.toString(),true);
		CMS_Main.objRequest.onreadystatechange=CMS_Main.updatePage;
		CMS_Main.objRequest.send(null);
		
		return false;
	},
	
	editCodeInitialize:function(frm)
	{
		if(frm)
		{
			if(frm.fTitle)
			{
				frm.fTitle.focus();
				frm.fTitle.select();
			}
		}
		return false;
	},
	
	editCodeSubmit:function(frm)
	{
		var blnReturnValue=true;
		
		if(frm.fTitle.value.length==0)
		{
			alert("Please enter a title");
			frm.fTitle.focus();
			blnReturnValue=false;
		}
		
		if(blnReturnValue)
		{
			document.getElementById("fSubmit").disabled=true;

			CMS_Main.objRequest.open("POST","get_page_xml.php",true);
			CMS_Main.objRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
			CMS_Main.objRequest.onreadystatechange=CMS_Main.updatePage;
			CMS_Main.objRequest.send(CMS_Main.formEncode(frm)+"&page="+CMS_Main.getPage());
		}
		
		return false;
	},	
	
	editCodeTextSubmit:function(frm)
	{
		var blnReturnValue=true;
		
		if(blnReturnValue)
		{
			document.getElementById("fSubmit").disabled=true;

			CMS_Main.objRequest.open("POST","get_page_xml.php",true);
			CMS_Main.objRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
			CMS_Main.objRequest.onreadystatechange=CMS_Main.updatePage;
			CMS_Main.objRequest.send(CMS_Main.formEncode(frm)+"&page="+CMS_Main.getPage());
		}
		
		return false;
	},	
	
	editCodeCancel:function()
	{
		CMS_Main.objRequest.open("GET","get_page_xml.php?page="+CMS_Main.getPage(),true);
		CMS_Main.objRequest.onreadystatechange=CMS_Main.updatePage;
		CMS_Main.objRequest.send(null);
		
		return false;
	},
	
	deleteCode:function(intCodeId,strTitle)
	{
		if(confirm("Are you sure you want to delete "+strTitle+"?"))
		{
			CMS_Main.objRequest.open("GET","get_page_xml.php?page="+CMS_Main.getPage()+"&fAction=deleteDynamicCategoryCode&fCode_id="+intCodeId,true);
			CMS_Main.objRequest.onreadystatechange=CMS_Main.updatePage;
			CMS_Main.objRequest.send(null);
		}
		
		return false;
	}
}/*--------------------------------------------------
	Project:	The November Group - CMS Administration
	Script:		cms_page_content.js
	Includes:	CMS_Page_Content
--------------------------------------------------*/

var CMS_Page_Content={
	
	objPageContentListRequest:null,
	blnFilterPublished:true,
	blnFilterNotPublished:true,
	blnFilterArchived:true,
	blnFilterStaging:true,
	strFilterAlpha:"all",
	
	//pagination attributes
	intPageNumber:1,

	editPages:function()
	{
		CMS_Main.setPage("editPages");
		
		CMS_Main.objRequest.open("GET","get_page_xml.php?page="+CMS_Main.getPage(),true);
		CMS_Main.objRequest.onreadystatechange=CMS_Main.updatePage;
		CMS_Main.objRequest.send(null);
		
		return false;
	},
	
	editPagesInitialize:function(frm)
	{
		if(frm)
		{
			//reselect previously selected filters
			if(document.getElementById("fFilter_published")) document.getElementById("fFilter_published").checked=this.blnFilterPublished;
			if(document.getElementById("fFilter_published_top")) document.getElementById("fFilter_published_top").checked=this.blnFilterPublished;
			if(document.getElementById("fFilter_not_published")) document.getElementById("fFilter_not_published").checked=this.blnFilterNotPublished;
			if(document.getElementById("fFilter_not_published_top")) document.getElementById("fFilter_not_published_top").checked=this.blnFilterNotPublished;
			if(document.getElementById("fFilter_archived")) document.getElementById("fFilter_archived").checked=this.blnFilterArchived;
			if(document.getElementById("fFilter_archived_top")) document.getElementById("fFilter_archived_top").checked=this.blnFilterArchived;
			if(document.getElementById("fFilter_staging")) document.getElementById("fFilter_staging").checked=this.blnFilterStaging;
			if(document.getElementById("fFilter_staging_top")) document.getElementById("fFilter_staging_top").checked=this.blnFilterStaging;
				
			frm.fFilter_alpha.value=this.strFilterAlpha;
			
			//alpha
			if(document.getElementById("filterAlpha"))
			{
				var arrLinks=document.getElementById("filterAlpha").getElementsByTagName("a");
				for(var i=0;i<arrLinks.length;i++)
				{
					if(arrLinks[i].firstChild.firstChild.firstChild.nodeValue.toLowerCase()==frm.fFilter_alpha.value.toString())
					{
						arrLinks[i].className+=" current_page";
						break;
					}
				}
			}
			if(document.getElementById("filterAlphaTop"))
			{
				var arrLinks=document.getElementById("filterAlphaTop").getElementsByTagName("a");
				for(var i=0;i<arrLinks.length;i++)
				{
					if(arrLinks[i].firstChild.firstChild.firstChild.nodeValue.toLowerCase()==frm.fFilter_alpha.value.toString())
					{
						arrLinks[i].className+=" current_page";
						break;
					}
				}
			}
			
			//reselect previously selected show count
			var blnSelected=false;
			if(document.getElementById("fShow_count"))
			{
				var eleSelect2=document.getElementById("fShow_count");
				for(var i=0;i<eleSelect2.options.length;i++)
				{
					if(Number(eleSelect2.options[i].value)==CMS_Client_User_Settings.getShowCountPages())
					{
						eleSelect2.options[i].selected=true;
						blnSelected=true;
						break;
					}
				}
				if(!blnSelected)
				{
					eleSelect2.options[0].selected=true;
					CMS_Client_User_Settings.setShowCountPages(Number(eleSelect2.options[0].value));
				}
			}
			blnSelected=false;
			if(document.getElementById("fShow_count_top"))
			{
				var eleSelect2=document.getElementById("fShow_count_top");
				for(var i=0;i<eleSelect2.options.length;i++)
				{
					if(Number(eleSelect2.options[i].value)==CMS_Client_User_Settings.getShowCountPages())
					{
						eleSelect2.options[i].selected=true;
						blnSelected=true;
						break;
					}
				}
				if(!blnSelected)
				{
					eleSelect2.options[0].selected=true;
					CMS_Client_User_Settings.setShowCountPages(Number(eleSelect2.options[0].value));
				}
			}

			//retrieve previously selected page number
			if(frm.fPage_number)
				frm.fPage_number.value=this.intPageNumber.toString();

			//enable or disable "publish pages" option
			if(document.getElementById("fAction_index"))
			{
				var eleSelect2=document.getElementById("fAction_index");
				for(var i=0;i<eleSelect2.length;i++)
				{
					if(eleSelect2.options[i].value==2)
					{
						if(CMS_Client_User_Settings.canPublishPageContents())
						{
							eleSelect2.options[i].disabled=false;
						}
						else
						{
							if(eleSelect2.options[i].selected)
								eleSelect2.options[0].selected=true;
								
							//disable option
							eleSelect2.options[i].disabled=true;
						}
						break;
					}
				}
			}
			if(document.getElementById("fAction_index_top"))
			{
				var eleSelect2=document.getElementById("fAction_index_top");
				for(var i=0;i<eleSelect2.length;i++)
				{
					if(eleSelect2.options[i].value==2)
					{
						if(CMS_Client_User_Settings.canPublishPageContents())
						{
							eleSelect2.options[i].disabled=false;
						}
						else
						{
							if(eleSelect2.options[i].selected)
								eleSelect2.options[0].selected=true;
								
							//disable option
							eleSelect2.options[i].disabled=true;
						}
						break;
					}
				}
			}
			
			this.onCategoryOrFilterChange(frm);
		}
	},
	
	onCategoryOrFilterChange:function(frm)
	{
		this.getContentList(frm);
	},
	
	onFilterPublishedClick:function(frm,eleInput)
	{
		this.blnFilterPublished=eleInput.checked;

		if(document.getElementById("fFilter_published"))
			document.getElementById("fFilter_published").checked=eleInput.checked;
		if(document.getElementById("fFilter_published_top"))
			document.getElementById("fFilter_published_top").checked=eleInput.checked;
		
		this.onCategoryOrFilterChange(frm);
	},
	
	onFilterNotPublishedClick:function(frm,eleInput)
	{
		this.blnFilterNotPublished=eleInput.checked;

		if(document.getElementById("fFilter_not_published"))
			document.getElementById("fFilter_not_published").checked=eleInput.checked;
		if(document.getElementById("fFilter_not_published_top"))
			document.getElementById("fFilter_not_published_top").checked=eleInput.checked;
		
		this.onCategoryOrFilterChange(frm);
	},
	
	onFilterArchivedClick:function(frm,eleInput)
	{
		this.blnFilterArchived=eleInput.checked;

		if(document.getElementById("fFilter_archived"))
			document.getElementById("fFilter_archived").checked=eleInput.checked;
		if(document.getElementById("fFilter_archived_top"))
			document.getElementById("fFilter_archived_top").checked=eleInput.checked;
		
		this.onCategoryOrFilterChange(frm);
	},
	
	onFilterStagingClick:function(frm,eleInput)
	{
		this.blnFilterStaging=eleInput.checked;

		if(document.getElementById("fFilter_staging"))
			document.getElementById("fFilter_staging").checked=eleInput.checked;
		if(document.getElementById("fFilter_staging_top"))
			document.getElementById("fFilter_staging_top").checked=eleInput.checked;
		
		this.onCategoryOrFilterChange(frm);
	},
	
	onAlphaClick:function(frm,eleA)
	{
		if(frm && eleA)
		{
			frm.fFilter_alpha.value=eleA.firstChild.firstChild.firstChild.nodeValue.toLowerCase(); //retrieve selected value
			this.strFilterAlpha=frm.fFilter_alpha.value.toString();
			
			//reset classes
			if(document.getElementById("filterAlpha"))
			{
				var arrLinks=document.getElementById("filterAlpha").getElementsByTagName("a");
				for(var i=0;i<arrLinks.length;i++)
				{
					if(arrLinks[i].className.indexOf("current_page")>-1)
						arrLinks[i].className=arrLinks[i].className.replace("current_page","");
					if(arrLinks[i].firstChild.firstChild.firstChild.nodeValue.toLowerCase()==frm.fFilter_alpha.value)
						arrLinks[i].className+=" current_page";
				}
			}
			if(document.getElementById("filterAlphaTop"))
			{
				var arrLinks=document.getElementById("filterAlphaTop").getElementsByTagName("a");
				for(var i=0;i<arrLinks.length;i++)
				{
					if(arrLinks[i].className.indexOf("current_page")>-1)
						arrLinks[i].className=arrLinks[i].className.replace("current_page","");
					if(arrLinks[i].firstChild.firstChild.firstChild.nodeValue.toLowerCase()==frm.fFilter_alpha.value)
						arrLinks[i].className+=" current_page";
				}
			}
			
			//update filter
			CMS_Page_Content.onCategoryOrFilterChange(frm);
		}
		
		return false; //cancel link
	},
	
	onShowCountChange:function(frm,eleSelect)
	{
		if(frm)
		{
			var intPages=1;

			if(document.getElementById("fShow_count"))
			{
				var eleSelect2=document.getElementById("fShow_count");
				for(var i=0;i<eleSelect2.options.length;i++)
				{
					if(Number(eleSelect2.options[i].value)==Number(eleSelect.options[eleSelect.selectedIndex].value))
						eleSelect2.options[i].selected=true;
				}
			}
			if(document.getElementById("fShow_count_top"))
			{
				var eleSelect2=document.getElementById("fShow_count_top");
				for(var i=0;i<eleSelect2.options.length;i++)
				{
					if(Number(eleSelect2.options[i].value)==Number(eleSelect.options[eleSelect.selectedIndex].value))
						eleSelect2.options[i].selected=true;
				}
			}
			
			CMS_Client_User_Settings.setShowCountPages(Number(eleSelect.value)); //store selected value
			
			//calculate number of pages
			if(Number(frm.fShow_count.value)>0)
				intPages=Math.ceil(Number(frm.fPage_count.value)/Number(eleSelect.value));
			if(intPages==0)
				intPages++;
			
			//check if current page number will exist for new show count
			if(Number(frm.fPage_number.value)>intPages)
				frm.fPage_number.value="1"; //reset page number
			
			this.getContentList(frm);
		}
	},
	
	onPageClick:function(frm,eleNumber)
	{
		if(frm && eleNumber)
		{
			frm.fPage_number.value=eleNumber.firstChild.firstChild.firstChild.nodeValue; //retrieve selected value
			this.getContentList(frm);
		}
		return false;
	},
	
	updatePagination:function(frm)
	{
		if(frm && frm.fShow_count)
		{
			var intPages=1;
			
			//calculate number of pages
			if(Number(frm.fShow_count.value)>0)
				intPages=Math.ceil(Number(frm.fPage_count.value)/Number(frm.fShow_count.value));
			if(intPages==0)
				intPages++;
			
			//rebuild page links
			if(document.getElementById("filterPage"))
			{
				document.getElementById("filterPage").innerHTML="";
				for(var i=0;i<intPages;i++)
					document.getElementById("filterPage").innerHTML+="<li><a href=\"#\" onclick=\"return CMS_Page_Content.onPageClick(document.getElementById('frmManagePageContents'),this);\"><span><span>"+(i+1).toString()+"</span></span></a></li>";
			}
			if(document.getElementById("filterPageTop"))
			{
				document.getElementById("filterPageTop").innerHTML="";
				for(var i=0;i<intPages;i++)
					document.getElementById("filterPageTop").innerHTML+="<li><a href=\"#\" onclick=\"return CMS_Page_Content.onPageClick(document.getElementById('frmManagePageContents'),this);\"><span><span>"+(i+1).toString()+"</span></span></a></li>";
			}
			
			//select page link
			var blnSelected=false;
			if (document.getElementById("filterPage")) 
			{
				var arrLinks=document.getElementById("filterPage").getElementsByTagName("a");
				for(var i=0;i<arrLinks.length;i++)
				{
					if(arrLinks[i].firstChild.firstChild.firstChild.nodeValue==frm.fPage_number.value.toString())
					{
						//change class
						arrLinks[i].className+=" current_page";
						blnSelected=true;
						break;
					}
				}
				if(!blnSelected)
				{
					arrLinks[0].className+=" current_page";
					frm.fPage_number.value=arrLinks[0].firstChild.firstChild.firstChild.nodeValue;
				}
			}
			blnSelected=false;
			if (document.getElementById("filterPageTop")) 
			{
				var arrLinks=document.getElementById("filterPageTop").getElementsByTagName("a");
				for(var i=0;i<arrLinks.length;i++)
				{
					if(arrLinks[i].firstChild.firstChild.firstChild.nodeValue==frm.fPage_number.value.toString())
					{
						//change class
						arrLinks[i].className+=" current_page";
						blnSelected=true;
						break;
					}
				}
				if(!blnSelected)
				{
					arrLinks[0].className+=" current_page";
					frm.fPage_number.value=arrLinks[0].firstChild.firstChild.firstChild.nodeValue;
				}
			}

			//store selected value
			this.intPageNumber=Number(frm.fPage_number.value);
			
			//calculate page count
			var intCountStart=(Number(frm.fPage_number.value)-1)*Number(frm.fShow_count.value);
			var intCountEnd=(Number(frm.fShow_count.value)==0 ? Number(frm.fPage_count.value) : Math.min(Number(frm.fShow_count.value)+intCountStart,Number(frm.fPage_count.value)));
			
			//update page count
			if(document.getElementById("pageCountStart"))
				document.getElementById("pageCountStart").innerHTML=(Math.min(intCountStart+1,Number(frm.fPage_count.value))).toString();
			if(document.getElementById("pageCountEnd"))
				document.getElementById("pageCountEnd").innerHTML=intCountEnd.toString();
			if(document.getElementById("pageCount"))
				document.getElementById("pageCount").innerHTML=frm.fPage_count.value.toString();

			if(document.getElementById("pageCountStartTop"))
				document.getElementById("pageCountStartTop").innerHTML=(Math.min(intCountStart+1,Number(frm.fPage_count.value))).toString();
			if(document.getElementById("pageCountEndTop"))
				document.getElementById("pageCountEndTop").innerHTML=intCountEnd.toString();
			if(document.getElementById("pageCountTop"))
				document.getElementById("pageCountTop").innerHTML=frm.fPage_count.value.toString();
		}
	},
	
	getContentList:function(frm)
	{
		var strHtml="";
		
		//clear select all
		if(document.getElementById("selectAll"))
			document.getElementById("selectAll").checked=false;
		
		//clear content list
		while(document.getElementById("contentListContainer").firstChild)
			document.getElementById("contentListContainer").removeChild(document.getElementById("contentListContainer").firstChild);
		
		//add loading message
		var eleLoading=document.createElement("tr");
		eleLoading.style.backgroundColor="#ffffff";
		
		eleLoading.appendChild(document.createElement("td"));
		eleLoading.appendChild(document.createElement("td"));
		eleLoading.childNodes[0].appendChild(document.createTextNode(" "));
		eleLoading.childNodes[0].style.width="2em";
		eleLoading.childNodes[1].colSpan=4;
		eleLoading.childNodes[1].appendChild(document.createTextNode(CMS_Main.getLoadingMessage()));
		document.getElementById("contentListContainer").appendChild(eleLoading);
		
		//get content list
		this.objPageContentListRequest=CMS_Main.createRequest();
		this.objPageContentListRequest.open("GET","get_element_xml.php?function=getPageContentListJson&fFilter_published="+(CMS_Page_Content.blnFilterPublished ? "1" : "0")+"&fFilter_not_published="+(CMS_Page_Content.blnFilterNotPublished ? "1" : "0")+"&fFilter_archived="+(CMS_Page_Content.blnFilterArchived ? "1" : "0")+"&fFilter_staging="+(CMS_Page_Content.blnFilterStaging ? "1" : "0")+"&fFilter_alpha="+encodeURIComponent(CMS_Page_Content.strFilterAlpha)+"&fShow_count="+frm.fShow_count.value.toString()+"&fPage_number="+frm.fPage_number.value.toString(),true);
		this.objPageContentListRequest.onreadystatechange=function(){
			if(CMS_Page_Content.objPageContentListRequest.readyState==4)
			{
				if(CMS_Page_Content.objPageContentListRequest.status==200)
				{
					//clear loading message
					while(document.getElementById("contentListContainer").firstChild)
						document.getElementById("contentListContainer").removeChild(document.getElementById("contentListContainer").firstChild);
					
					//var arrContentData=eval("("+CMS_Page_Content.objPageContentListRequest.responseText+")");
					var objContentData=eval("("+CMS_Page_Content.objPageContentListRequest.responseText+")");
					document.getElementById("fPage_count").value=objContentData.intPageCount.toString();
					
					//add rows
					for(i in objContentData.arrContents)
					{
						var eleRow=CMS_Page_Content.createRow(objContentData.arrContents[i]);
						
						if(i%2==0)
							eleRow.className="first";
						else
							eleRow.className="second";

						document.getElementById("contentListContainer").appendChild(eleRow);
					}
					
					if(objContentData.arrContents.length==0)
						document.getElementById("contentListContainer").appendChild(CMS_Page_Content.createEmptyRow());
					
					CMS_Page_Content.updatePagination(document.getElementById("frmManagePageContents"));
				}
			}
		};
		this.objPageContentListRequest.send(null);
		
		return false;
	},
	
	createRow:function(objContentData)
	{
		var eleRow=document.createElement("tr");
		
		var eleTd8=document.createElement("td");
		eleTd8.style.width="2em";
		eleTd8.appendChild(document.createTextNode(objContentData.intPageId.toString()));
		eleRow.appendChild(eleTd8);
		
		var eleTd7=document.createElement("td");
		eleTd7.appendChild(document.createTextNode(objContentData.strPageName));
		eleRow.appendChild(eleTd7);
		
		var eleTd1=document.createElement("td");
		eleTd1.appendChild(document.createTextNode(objContentData.strTitle));
		eleRow.appendChild(eleTd1);
		
		var eleTd2=document.createElement("td");
		eleTd2.appendChild(document.createTextNode(objContentData.strDateCreated));
		eleRow.appendChild(eleTd2);
		
		/*
		var eleTd4=document.createElement("td");
		eleTd4.appendChild(document.createTextNode(objContentData.strStatus));
		eleRow.appendChild(eleTd4);
		*/
		
		var eleTd5=document.createElement("td");
		eleTd5.style.width="96px";
		/*
		eleTd5.innerHTML=" \
		<div class=\"actions\"> \
			<ul> \
				<li><a class=\"action5\" href=\"#\" onclick=\"return CMS_Page_Content.editPageContent("+objContentData.intPageId.toString()+");\" title=\"Edit\">Edit</a></li> \
				"+(objContentData.blnStagingAreaCopyExists ? "<li><a class=\"action6\" href=\"#\" onclick=\"return CMS_Page_Content.editPageContent("+objContentData.intPageId.toString()+",true);\" title=\"Edit copy\">Edit copy</a></li>" : "")+" \
				<li><a class=\"action4\" href=\"#\" onclick=\"return CMS_Page_Content.deletePageContent("+objContentData.intPageId.toString()+","+objContentData.intContentId.toString()+");\" title=\"Delete\">Delete</a></li> \
			</ul> \
			<div style=\"float:right;\"> \
				<input class=\"radio\" name=\"selectPage\" id=\"selectPage"+objContentData.intContentId.toString()+"\" type=\"checkbox\" value=\""+objContentData.intContentId.toString()+"\" /> \
				<input name=\"selectContentTitle\" id=\"selectContentTitle"+objContentData.intContentId.toString()+"\" type=\"hidden\" value=\""+objContentData.strTitle+"\" /> \
			</div> \
		</div>";
		*/
		eleTd5.innerHTML=" \
		<div class=\"actions\"> \
			<ul> \
				<li><a class=\"action5\" href=\"#\" onclick=\"return CMS_Page_Content.editPageContent("+objContentData.intPageId.toString()+");\" title=\"Edit\">Edit</a></li> \
				"+(objContentData.blnStagingAreaCopyExists ? "<li><a class=\"action6\" href=\"#\" onclick=\"return CMS_Page_Content.editPageContent("+objContentData.intPageId.toString()+",true);\" title=\"Edit copy\">Edit copy</a></li>" : "")+" \
			</ul> \
		</div>";
		eleRow.appendChild(eleTd5);
		
		return eleRow;
	},
	
	createEmptyRow:function()
	{
		var eleRow=document.createElement("tr");
		
		var eleTd0=document.createElement("td");
		eleRow.appendChild(eleTd0);
		
		var eleTd1=document.createElement("td");
		eleTd1.colSpan=4;
		eleTd1.appendChild(document.createTextNode("No pages to display"));
		eleRow.appendChild(eleTd1);
		
		return eleRow;
	},
	
	selectAllClick:function(frm)
	{
		for(var i=0;i<frm.length;i++)
			if(frm.elements[i].name && frm.elements[i].name.indexOf("selectContent")==0)
				frm.elements[i].checked=true;
		return false;
	},
	
	deselectAllClick:function(frm)
	{
		for(var i=0;i<frm.length;i++)
			if(frm.elements[i].name && frm.elements[i].name.indexOf("selectContent")==0)
				frm.elements[i].checked=false;
		return false;
	},
	
	onActionChange:function(frm)
	{
	},
	
	onActionClick:function(frm)
	{
		if(frm.fAction_index)
		{
			switch(Number(frm.fAction_index.value))
			{
				case(1): //delete
					this.deleteContents(frm);
					break;
				case(2): //publish
					this.publishContents(frm);
					break;
				case(3): //archive
					this.archiveContents(frm);
					break;
				default:
			}
		}
		return false;
	},
	
	deleteContents:function(frm)
	{
		var arrContentIds=new Array();
		var arrContentTitles=new Array();
		
		for(var i=0;i<frm.length;i++)
		{
			if(frm.elements[i].name.indexOf("selectContent")==0 && frm.elements[i].type=="checkbox" && frm.elements[i].checked)
			{
				arrContentIds[arrContentIds.length]=frm.elements[i].value;
				arrContentTitles[arrContentTitles.length]=frm.elements[i+1].value;
			}
		}
		if(arrContentIds.length==0)
		{
			alert("You do not have any pages selected.");
		}
		else if(confirm("Are you sure you want to delete "+(arrContentIds.length==1 ? arrContentTitles[0]+"?" : "the following pages?\n\n\t"+arrContentTitles.join("\n\t")+"\n ")))
		{
			CMS_Main.objRequest.open("GET","get_page_xml.php?page="+CMS_Main.getPage()+"&fPage_id="+frm.fPage_id.value.toString()+"&fAction=deletePageContents&fContent_id[]="+arrContentIds.join("&fContent_id[]="),true);
			CMS_Main.objRequest.onreadystatechange=CMS_Main.updatePage;
			CMS_Main.objRequest.send(null);
		}
		
		return false;
	},
	
	publishContents:function(frm)
	{
		var arrContentIds=new Array();
		var arrContentTitles=new Array();
		
		for(var i=0;i<frm.length;i++)
		{
			if(frm.elements[i].name.indexOf("selectContent")==0 && frm.elements[i].type=="checkbox" && frm.elements[i].checked)
			{
				arrContentIds[arrContentIds.length]=frm.elements[i].value;
				arrContentTitles[arrContentTitles.length]=frm.elements[i+1].value;
			}
		}
		if(arrContentIds.length==0)
		{
			alert("You do not have any pages selected.");
		}
		else if(confirm("Are you sure you want to publish "+(arrContentIds.length==1 ? arrContentTitles[0]+"?" : "the following pages?\n\n\t"+arrContentTitles.join("\n\t")+"\n ")))
		{
			CMS_Main.objRequest.open("GET","get_page_xml.php?page="+CMS_Main.getPage()+"&fPage_id="+frm.fPage_id.value.toString()+"&fAction=publishPageContents&fContent_id[]="+arrContentIds.join("&fContent_id[]="),true);
			CMS_Main.objRequest.onreadystatechange=CMS_Main.updatePage;
			CMS_Main.objRequest.send(null);
		}
		
		return false;
	},
	
	archiveContents:function(frm)
	{
		var arrContentIds=new Array();
		var arrContentTitles=new Array();
		
		for(var i=0;i<frm.length;i++)
		{
			if(frm.elements[i].name.indexOf("selectContent")==0 && frm.elements[i].type=="checkbox" && frm.elements[i].checked)
			{
				arrContentIds[arrContentIds.length]=frm.elements[i].value;
				arrContentTitles[arrContentTitles.length]=frm.elements[i+1].value;
			}
		}
		if(arrContentIds.length==0)
		{
			alert("You do not have any pages selected.");
		}
		else if(confirm("Are you sure you want to archive "+(arrContentIds.length==1 ? arrContentTitles[0]+"?" : "the following pages?\n\n\t"+arrContentTitles.join("\n\t")+"\n ")))
		{
			CMS_Main.objRequest.open("GET","get_page_xml.php?page="+CMS_Main.getPage()+"&fPage_id="+frm.fPage_id.value.toString()+"&fAction=archivePageContents&fContent_id[]="+arrContentIds.join("&fContent_id[]="),true);
			CMS_Main.objRequest.onreadystatechange=CMS_Main.updatePage;
			CMS_Main.objRequest.send(null);
		}
		
		return false;
	},
	
	deletePageContent:function(intPageId,intContentId)
	{
		var strTitle=document.getElementById("selectContentTitle"+intContentId).value.toString();
		
		if(confirm("Are you sure you want to delete "+strTitle+"?"))
		{
			CMS_Main.objRequest.open("GET","get_page_xml.php?page="+CMS_Main.getPage()+"&fPage_id="+intPageId.toString()+"&fAction=deletePageContent&fContent_id="+intContentId.toString(),true);
			CMS_Main.objRequest.onreadystatechange=CMS_Main.updatePage;
			CMS_Main.objRequest.send(null);
		}
		
		return false;
	},
	
	editPageContent:function(intPageId,blnUseStagingAreaCopy)
	{
		CMS_Main.objRequest.open("GET","get_page_xml.php?page=editPageContent&fPage_id="+intPageId.toString()+(blnUseStagingAreaCopy ? "&fUse_staging_area_copy=1" : ""),true);
		CMS_Main.objRequest.onreadystatechange=CMS_Main.updatePage;
		CMS_Main.objRequest.send(null);
		
		return false;
	},
	
	
	editPageContentInitialize:function(frm)
	{
		if(frm)
		{
			//reset file request variables
			this.arrValidFileRequest=new Array();
			this.intSizeUploadingTotal=0;
			this.arrUsedFileIds=new Array();
			this.intUploadCount=0;
			this.arrUploadCount=new Array();

			CMS_File.preloadProgressImages();

			//insert date-time select boxes
			if(document.getElementById("fDate_start"))
			{
				DTS.insert("fDate_start",DTS.intTypeDateOnly);
				this.onDateEnabledClick(frm.fDate_start_enabled,"dateStart");
			}
			if(document.getElementById("fDate_end"))
			{
				DTS.insert("fDate_end",DTS.intTypeDateOnly);
				this.onDateEnabledClick(frm.fDate_end_enabled,"dateEnd");
			}
			if(document.getElementById("fDisplay_date_start"))
			{
				DTS.insert("fDisplay_date_start",DTS.intTypeDateOptional);
				this.onDateEnabledClick(frm.fDisplay_date_start_enabled,"displayDateStart");
			}
			if(document.getElementById("fDisplay_date_end"))
			{
				DTS.insert("fDisplay_date_end",DTS.intTypeDateOptional);
				this.onDateEnabledClick(frm.fDisplay_date_end_enabled,"displayDateEnd");
			}
			
			CMS_Main.textEditorInit("fText");
			
			//initialize necessary fields
			if(frm.fField_id)
			{
				var arrFieldIds=new Array();
				if(frm.fField_id && frm.fField_id.length)
					for(var i=0;i<frm.fField_id.length;i++)
						arrFieldIds.push(frm.fField_id[i].value);
				else if(frm.fField_id) //if there is only one field, then frm.fField_id is not an array
					arrFieldIds.push(frm.fField_id.value);
				
				for(var i=0;i<arrFieldIds.length;i++)
				{
					if(document.getElementById("fField_text_editor"+arrFieldIds[i].toString())) //initialize text editor
					{
						CMS_Main.textEditorInit("fField_text_editor"+arrFieldIds[i].toString());
					}
					else if(document.getElementById("fField_count_down_date"+arrFieldIds[i].toString())) //initialize count down date
					{
						DTS.insert("fField_count_down_date"+arrFieldIds[i].toString(),DTS.intTypeDateRequired);
						this.onDateEnabledClick(frm.elements["fField_count_down_date_enabled"+arrFieldIds[i].toString()],"countDownDate"+arrFieldIds[i].toString());
						this.onRepeatClick(frm.elements["fField_count_down_repeat"+arrFieldIds[i].toString()],"countDownRepeatOptions"+arrFieldIds[i].toString());
					}
					else if(document.getElementById("eleUploader"+arrFieldIds[i].toString())) //initialize uploader
					{
						//move the uploader in the DOM (so IE will correctly observe the the z-index property)
						document.getElementsByTagName("body")[0].insertBefore(document.getElementById("eleUploader"+arrFieldIds[i].toString()),document.getElementsByTagName("body")[0].firstChild);
						
						//instantiate uploader
						YAHOO.widget.Uploader.SWFURL=CMS_File.getUploaderSWFURL();
						document.getElementById("eleUploader"+arrFieldIds[i].toString()).innerHTML=CMS_File.strUploaderInitialContent;
						this.arrUploader[arrFieldIds[i]]=new YAHOO.widget.Uploader("eleUploader"+arrFieldIds[i].toString());
						
						this.hideUploader(arrFieldIds[i]);
			
						//set uploader event handlers
						this.arrUploader[arrFieldIds[i]].addListener("contentReady",this.onContentReady);
						this.arrUploader[arrFieldIds[i]].addListener('fileSelect',this.onFileSelect);
						this.arrUploader[arrFieldIds[i]].addListener('uploadStart',this.onUploadStart);
						this.arrUploader[arrFieldIds[i]].addListener('uploadProgress',this.onUploadProgress);
						this.arrUploader[arrFieldIds[i]].addListener('uploadCancel',this.onUploadCancel);
						this.arrUploader[arrFieldIds[i]].addListener('uploadComplete',this.onUploadComplete);
						this.arrUploader[arrFieldIds[i]].addListener('uploadCompleteData',this.onUploadCompleteData);
						this.arrUploader[arrFieldIds[i]].addListener('uploadError',this.onUploadError);
						//set more uploader event handlers
						this.arrUploader[arrFieldIds[i]].addListener("rollOver",this.onRollOver);
						this.arrUploader[arrFieldIds[i]].addListener("rollOut",this.onRollOut);
						this.arrUploader[arrFieldIds[i]].addListener("click",this.onClick);
						
						this.arrUploader[arrFieldIds[i]].intFieldId=arrFieldIds[i]; //create object attribute to store field id
						this.arrUploadCount[arrFieldIds[i]]=0;
					}
				}
			}

			this.onPublishedClick(frm.fPublished);
			
			//remove and store the file attachment form
			if(document.getElementById("fileAttach"))
			{
				this.eleFileAttach=document.getElementById("fileAttach").parentNode.removeChild(document.getElementById("fileAttach"));
				this.eleFileAttach.style.display="block";
			}
			
			frm.fTitle.focus();
			frm.fTitle.select();
		}
		
		return false;
	},
	
	onPublishedClick:function(eleInput)
	{
		if(document.getElementById("unpublishOptions"))
		{
			if(eleInput.checked)
			{
				document.getElementById("unpublishOptions").style.display="none";
			}
			else
			{
				try
				{
					document.getElementById("unpublishOptions").style.display="table-row";
				}
				catch(e)
				{
					document.getElementById("unpublishOptions").style.display="block";
				}
			}
		}
	},

	onTextChange:function(eleInput,intMaxLength,blnNumeric)
	{
		if(intMaxLength > 0 && eleInput.value.length > intMaxLength)
			eleInput.value=eleInput.value.substr(0,intMaxLength);
		if(blnNumeric && isNaN(eleInput.value))
			eleInput.value=0;
	},
	
	onDateEnabledClick:function(eleInput,strId)
	{
		//DTS.disabled(strId,!eleInput.checked);
		if(document.getElementById(strId))
			if(eleInput.checked)
				document.getElementById(strId).style.display="inline";
			else
				document.getElementById(strId).style.display="none";
		
		return true;
	},
	
	onRepeatClick:function(eleInput,strId)
	{
		if(document.getElementById(strId))
			if(eleInput.checked)
				document.getElementById(strId).style.display="block";
			else
				document.getElementById(strId).style.display="none";
		
		return true;
	},
	
	urlTargetIdChange:function(eleSelect)
	{
		var strId="";
		
		if(eleSelect)
		{
			strId=eleSelect.id.replace("fField_url_target_id","");
			
			if(Number(eleSelect.value)==1)
			{
				if(document.getElementById("urlOptionsOther"+strId))
					document.getElementById("urlOptionsOther"+strId).style.display="inline";
			}
			else
			{
				if(document.getElementById("urlOptionsOther"+strId))
					document.getElementById("urlOptionsOther"+strId).style.display="none";
			}
		}
	},
	
	openFileAttach:function(intFieldDefId,strAllowedFileTypes)
	{
		//show dialogue
		CMS_Main.addOverlay(this.eleFileAttach);
		
		if(document.getElementById("frmFileAttach"))
			frm=document.getElementById("frmFileAttach");
		
		//set field definition id
		if(frm.fField_id)
			frm.fField_id.value=intFieldDefId;
		//set allowed file types
		if(frm.fAllowed_file_types)
			frm.fAllowed_file_types.value=strAllowedFileTypes;
		
		this.onFileAttachTypeClick();
		
		return false;
	},
	
	syncUploader:function(intFieldId,strId)
	{
		try
		{
			document.getElementById("eleUploader"+intFieldId.toString()).style.left=$("#"+strId).offset().left+"px";
			document.getElementById("eleUploader"+intFieldId.toString()).style.top=$("#"+strId).offset().top+"px";
		}
		catch(e)
		{
		}
	},
	
	onFileAttachTypeClick:function()
	{
		frm=document.getElementById("frmFileAttach");
		
		if(frm.fFile_attach_type0.checked)
		{
			document.getElementById("fileAttach0").style.height="auto";
			document.getElementById("fileAttach1").style.height="0px";
			
			this.hideUploader(frm.fField_id.value);
			
			if(frm.fFile_category_id)
				this.onCategoryChange(frm.fFile_category_id);
		}
		else if(frm.fFile_attach_type1.checked)
		{
			document.getElementById("fileAttach1").style.height="auto";
			document.getElementById("fileAttach0").style.height="0px";

			//store field id
			this.intFileUploadFieldId=frm.fField_id.value;
			//set file type filter
			this.arrUploader[this.intFileUploadFieldId].setFileFilters(eval(frm.fAllowed_file_types.value));

			//resize uploader to same size as uploadFiles
			document.getElementById("eleUploader"+this.intFileUploadFieldId).style.width=document.getElementById("uploadFiles").offsetWidth.toString()+"px";
			document.getElementById("eleUploader"+this.intFileUploadFieldId).style.height=document.getElementById("uploadFiles").offsetHeight.toString()+"px";
			//move uploader to same position as uploadFiles
			this.syncUploader(this.intFileUploadFieldId,"uploadFiles");
			//display uploader
			document.getElementById("eleUploader"+this.intFileUploadFieldId).style.zIndex=6;

			//start synchronizing uploader synchronized with upload files button
			window.onscroll=function()
			{
				if(document.getElementById("frmFileAttach"))
					CMS_Page_Content.syncUploader(document.getElementById("frmFileAttach").fField_id.value,"uploadFiles");
			};
			window.onresize=function()
			{
				if(document.getElementById("frmFileAttach"))
					CMS_Page_Content.syncUploader(document.getElementById("frmFileAttach").fField_id.value,"uploadFiles");
			};
		}
		else
		{
			document.getElementById("fileAttach0").style.height="0px";
			document.getElementById("fileAttach1").style.height="0px";
		}
	},
	
	onCategoryChange:function(eleSelectCategory)
	{
		var frm=eleSelectCategory.form;
		var objCategorySelectRequest=CMS_Main.createRequest();
		objCategorySelectRequest.open("GET",CMS_Main.getRootDirectory()+"/get_element_xml.php?function=getPageFileListJson&fCategory_id="+eleSelectCategory.value.toString()+"&fField_id="+frm.fField_id.value.toString(),true);
		objCategorySelectRequest.onreadystatechange=function()
		{
			if(objCategorySelectRequest.readyState==4)
			{
				if(objCategorySelectRequest.status==200)
				{
					objListData=eval("("+objCategorySelectRequest.responseText+")");
					
					eleSelectFiles=frm.fAvailable_file_ids;
					
					//clear file list
					for(i in eleSelectFiles.options)
					{
						eleSelectFiles.remove(i);
					}
					
					//populate file list
					for(i in objListData.arrFiles)
					{
						var eleOpt=document.createElement("option");
						eleOpt.text=objListData.arrFiles[i].strTitle;
						eleOpt.value=objListData.arrFiles[i].intFileId.toString();
						eleOpt.title=objListData.arrFiles[i].strName;
						eleSelectFiles.options[eleSelectFiles.length]=eleOpt;
					}
				}
			}
		};
		objCategorySelectRequest.send(null);
	},

	addSelectedFiles:function(eleSelect)
	{
		var blnFileSelected=false;
		
		for(var i=0;i<eleSelect.options.length;i++)
		{
			if(eleSelect.options[i].selected)
			{
				blnFileSelected=true;
				
				var j=this.arrFileSelectRequest.length+1;
				
				this.arrFileSelectFieldId[j]=eleSelect.form.fField_id.value;
				
				this.arrFileSelectRequest[j]=CMS_Main.createRequest();
				this.arrFileSelectRequest[j].open("GET",CMS_Main.getRootDirectory()+"/get_element_xml.php?function=getFileDataJson&fFile_id="+eleSelect.options[i].value.toString(),true);
				this.arrFileSelectRequest[j].onreadystatechange=this.addSelectedFilesResponse;
				this.arrFileSelectRequest[j].send(null);
			}
		}

		if(blnFileSelected)
			CMS_Main.removeOverlay();
	},
	
	addSelectedFilesResponse:function()
	{
		for(i in CMS_Page_Content.arrFileSelectRequest)
		{
			if(CMS_Page_Content.arrFileSelectRequest[i] && CMS_Page_Content.arrFileSelectRequest[i].readyState==4)
			{
				if(CMS_Page_Content.arrFileSelectRequest[i].status==200)
				{
					objFileData=eval("("+CMS_Page_Content.arrFileSelectRequest[i].responseText+")");
					
					//hide file select container
					document.getElementById("fileSelectContainer"+CMS_Page_Content.arrFileSelectFieldId[i].toString()).style.display="none";
					
					var eleFileDataContainer=document.getElementById("fileDataContainer"+CMS_Page_Content.arrFileSelectFieldId[i].toString());
					
					//clear file data container
					while(eleFileDataContainer.firstChild)
						eleFileDataContainer.removeChild(eleFileDataContainer.firstChild);
					
					//create row 
					var eleRow=document.createElement("tr");

					var eleTd1=document.createElement("td");
					var eleInput=CMS_Main.createNamedElement("input","fField_file_id"+CMS_Page_Content.arrFileSelectFieldId[i].toString());
					eleInput.id="fField_file_id"+CMS_Page_Content.arrFileSelectFieldId[i].toString();
					eleInput.type="hidden";
					eleInput.value=objFileData.intFileId.toString();
					eleTd1.appendChild(eleInput);
					eleTd1.appendChild(document.createTextNode(objFileData.strTitle));
					eleRow.appendChild(eleTd1);
					
					var eleTd2=document.createElement("td");
					eleTd2.appendChild(document.createTextNode(objFileData.strStatus));
					eleRow.appendChild(eleTd2);
					
					var eleTd3=document.createElement("td");
					eleTd3.innerHTML="<div class=\"actions\"><ul><li><a class=\"action4\" href=\"#\" onclick=\"return CMS_Page_Content.removeFile("+CMS_Page_Content.arrFileSelectFieldId[i].toString()+","+objFileData.intFileId.toString()+");\" title=\"Remove\">Remove</a></li></ul></div>";
					eleRow.appendChild(eleTd3);

					eleFileDataContainer.appendChild(eleRow);
					
					//remove from arrays
					CMS_Page_Content.arrFileSelectRequest.splice(i,1);
					CMS_Page_Content.arrFileSelectFieldId.splice(i,1);
				}
			}
		}
	},
	
	closeFileAttach:function(intFieldId)
	{
		this.hideUploader(intFieldId);
		
		CMS_Main.removeOverlay();

		//stop synchronizing uploader synchronized with upload files button
		window.onscroll=null;
		window.onresize=null;
	},
	
	hideUploader:function(intFieldId)
	{
		//this seems to be the only method of hiding the uploader that doesn't cause the browser to unload the Flash object (and lose any selected files)
		if(document.getElementById("eleUploader"+intFieldId.toString()))
			document.getElementById("eleUploader"+intFieldId.toString()).style.zIndex=-1;
	},
	
	removeFile:function(intFieldId,intFileId)
	{
		if(document.getElementById("fileDataContainer"+intFieldId.toString()))
		{
			var eleFileDataContainer=document.getElementById("fileDataContainer"+intFieldId.toString());
			
			//clear file data container
			while(eleFileDataContainer.firstChild)
				eleFileDataContainer.removeChild(eleFileDataContainer.firstChild);
					
			//show file select container
			document.getElementById("fileSelectContainer"+intFieldId.toString()).style.display="block";
		}
		
		return false;
	},
	
	editSubmit:function(frm)
	{
		var blnReturnValue=true;
		
		CMS_Main.textEditorUpdate("fText");
		
		if(frm.fField_id)
		{
			for(var i=0;i<frm.fField_id.length;i++)
			{
				if(document.getElementById("fField_text_editor"+frm.fField_id[i].value.toString()))
					CMS_Main.textEditorUpdate("fField_text_editor"+frm.fField_id[i].value.toString());
			}
			if(!frm.fField_id.length) //if there is only one field, then frm.fField_id is not an array
			{
				if(document.getElementById("fField_text_editor"+frm.fField_id.value.toString()))
					CMS_Main.textEditorUpdate("fField_text_editor"+frm.fField_id.value.toString());
			}
		}

		if(frm.fTitle.value.length==0)
		{
			alert("Please enter a title");
			frm.fTitle.focus();
			blnReturnValue=false;
		}
		else if((frm.fDate_start_enabled && frm.fDate_end_enabled) && (frm.fDate_start_enabled.checked && frm.fDate_end_enabled.checked) && (Number(frm.fDate_start.value) > Number(frm.fDate_end.value)))
		{
			alert("Please make sure the end date is not earlier than the start date.");
			blnReturnValue=false;
		}
		else if((frm.fDisplay_date_start_enabled && frm.fDisplay_date_end_enabled) && (frm.fDisplay_date_start_enabled.checked && frm.fDisplay_date_end_enabled.checked) && (Number(frm.fDisplay_date_start.value) > Number(frm.fDisplay_date_end.value)))
		{
			alert("Please make sure the display end date is not earlier than the display start date.");
			blnReturnValue=false;
		}
		else if(frm.fField_id)
		{
			if(frm.fField_id.length) //there is more than one field
			{
				for(var i=0;i<frm.fField_id.length;i++)
				{
					//check for valid field attributes
					var strId=frm.fField_id[i].value;
					
					if(!this.editFieldSubmit(frm,strId))
					{
						blnReturnValue=false;
						break;
					}
				}
			}
			else //there is only one field
			{
				//check for valid field attributes
				var strId=frm.fField_id.value;
				
				if(!this.editFieldSubmit(frm,strId))
				{
					blnReturnValue=false;
				}
			}
		}
		
		if(blnReturnValue)
		{
			document.getElementById("fSubmit").disabled=true;
			
			//check if there are files to upload
			if(CMS_Page_Content.intUploadCount>0)
			{
				for(i in CMS_Page_Content.arrUploader)
				{
					//upload
					if(CMS_Page_Content.arrUploadCount[i]>0)
						CMS_Page_Content.arrUploader[i].uploadAll(CMS_Main.getRootDirectory()+'/file_upload.php',"POST",{sessionId:CMS_Cookie.get(CMS_Main.getSessionName()), fEnd_action:2, fPublished:1, fNew:0},"fFile");
				}
			}
			else
			{
				//submit form
				this.editSubmitFinal(frm);
			}
		}
		
		return false;
	},
	
	editFieldSubmit:function(frm,strFieldId)
	{
		var blnReturnValue=true;
		
		switch(Number(frm.elements["fField_type"+strFieldId].value))
		{
			case(CMS_Dynamic_Form.intTextTypeId):
				break;
			case(CMS_Dynamic_Form.intTextAreaTypeId):
				break;
			case(CMS_Dynamic_Form.intFileTypeId):
				break;
			case(CMS_Dynamic_Form.intUrlTypeId):
				if(Number(frm.elements["fField_url_target_id"+strFieldId].value)==1 && frm.elements["fField_url_target_other"+strFieldId].value=="")
				{
					alert("Please enter a target value");
					frm.elements["fField_url_target_other"+strFieldId].focus();
					blnReturnValue=false;
				}
				break;
		}
		
		return blnReturnValue;
	},
	
	editSubmitFinal:function(frm)
	{
		this.editClose(frm);
		
		CMS_Main.objRequest.open("POST","get_page_xml.php",true);
		CMS_Main.objRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		CMS_Main.objRequest.onreadystatechange=CMS_Main.updatePage;
		CMS_Main.objRequest.send(CMS_Main.formEncode(frm)+"&page="+CMS_Main.getPage());
	},
	
	editCancel:function(frm)
	{
		this.editClose(frm);
		
		CMS_Main.objRequest.open("GET","get_page_xml.php?page="+CMS_Main.getPage()+"&fPage_id="+frm.fPage_id.value.toString(),true);
		CMS_Main.objRequest.onreadystatechange=CMS_Main.updatePage;
		CMS_Main.objRequest.send(null);
		
		return false;
	},
	
	editClose:function(frm)
	{
		var arrFieldIds=new Array();
		if(frm.fField_id && frm.fField_id.length)
			for(var i=0;i<frm.fField_id.length;i++)
				arrFieldIds.push(frm.fField_id[i].value);
		else if(frm.fField_id) //if there is only one field, then frm.fField_id is not an array
			arrFieldIds.push(frm.fField_id.value);
			
		for(var i=0;i<arrFieldIds.length;i++)
		{
			//remove the uploaders
			if(document.getElementById("eleUploader"+arrFieldIds[i].toString()))
			{
				document.getElementById("eleUploader"+arrFieldIds[i].toString()).innerHTML=""; //unload the Flash object to prevent error in IE when removing element from the DOM
				document.getElementById("eleUploader"+arrFieldIds[i].toString()).parentNode.removeChild(document.getElementById("eleUploader"+arrFieldIds[i].toString()));
			}
		}
	},
	
	editRevert:function(frm)
	{
		if(confirm("Are you sure you want to revert this page back to the original version?"))
		{
			this.editClose(frm);
			
			CMS_Main.objRequest.open("GET","get_page_xml.php?page="+CMS_Main.getPage()+"&fPage_id="+frm.fPage_id.value.toString()+"&fAction=revertPageContent&fContent_id="+frm.fContent_id.value.toString(),true);
			CMS_Main.objRequest.onreadystatechange=CMS_Main.updatePage;
			CMS_Main.objRequest.send(null);
		}
		
		return false;
	},
	
	//file select and upload methods

	arrFileSelectRequest:new Array(),
	arrFileSelectFieldId:new Array(),
	intFileUploadFieldId:0,
	eleFileAttach:null,

	arrUploader:new Array(),
	arrFileList:new Array(),
	arrValidFileRequest:new Array(),
	intSizeUploadingTotal:0,
	intUploadCount:0,
	arrUploadCount:new Array(),

	onContentReady:function()
	{
		//set file uploader properties
		this.setAllowMultipleFiles(false);
		this.setSimUploadLimit(1); //set simultaneous upload limit
	},
	
	uploadFiles:function(frm)
	{
		return false;
	},
	
	onFileSelect:function(event)
	{
		CMS_Page_Content.closeFileAttach(this.intFieldId);
		
		CMS_Page_Content.arrFileList[this.intFieldId]=event.fileList;
		
		//add files to form
		for(var i in event.fileList)
		{
			var strTitle=event.fileList[i].name.substr(0,event.fileList[i].name.lastIndexOf("."));

			//hide file select container
			document.getElementById("fileSelectContainer"+this.intFieldId).style.display="none";
			
			var eleFileDataContainer=document.getElementById("fileDataContainer"+this.intFieldId);
			
			//clear file data container
			while(eleFileDataContainer.firstChild)
				eleFileDataContainer.removeChild(eleFileDataContainer.firstChild);
			
			//create row 
			var eleRow=document.createElement("tr");

			var eleTd1=document.createElement("td");
			eleTd1.appendChild(document.createTextNode(strTitle));
			eleRow.appendChild(eleTd1);
			
			var eleTd2=document.createElement("td");
			eleTd2.id="fileStatus"+this.intFieldId;
			eleTd2.appendChild(document.createTextNode("\u00A0"));
			eleRow.appendChild(eleTd2);
			
			var eleTd3=document.createElement("td");
			eleTd3.id="fileAction"+this.intFieldId;
			eleTd3.innerHTML="<div class=\"actions\"><ul><li><a class=\"action4\" href=\"#\" onclick=\"return CMS_Page_Content.cancel("+this.intFieldId+",'"+event.fileList[i].id+"');\" title=\"Remove\">Remove</a></li></ul></div>";
			eleRow.appendChild(eleTd3);

			eleFileDataContainer.appendChild(eleRow);

			//check for valid file
			var j=CMS_Page_Content.arrValidFileRequest.length+1;
			CMS_Page_Content.arrValidFileRequest[j]=CMS_Main.createRequest();
			CMS_Page_Content.arrValidFileRequest[j].open("GET","get_element_xml.php?function=isValidFileXml&fFile_id=0&fileId="+event.fileList[i].id+"&fName="+encodeURIComponent(event.fileList[i].name)+"&fSize="+event.fileList[i].size+"&sizeUploadingTotal="+CMS_Page_Content.intSizeUploadingTotal.toString()+"&fTitle=&fPage_field_id="+this.intFieldId.toString(),true);
			CMS_Page_Content.arrValidFileRequest[j].onreadystatechange=CMS_Page_Content.uploadFileResponse;
			CMS_Page_Content.arrValidFileRequest[j].send(null);
		}
	},
	
	uploadFileResponse:function()
	{
		//loop through all open requests
		for(i in CMS_Page_Content.arrValidFileRequest)
		{
			if(CMS_Page_Content.arrValidFileRequest[i] && CMS_Page_Content.arrValidFileRequest[i].readyState==4 && CMS_Page_Content.arrValidFileRequest[i].status==200)
			{
				var eleDoc=CMS_Page_Content.arrValidFileRequest[i].responseXML.documentElement;
				
				if(eleDoc.getElementsByTagName("validFile"))
				{
					var strId=eleDoc.getElementsByTagName("fileId")[0].firstChild.nodeValue;
					var intFieldId=eleDoc.getElementsByTagName("pageFieldId")[0].firstChild.nodeValue;
					
					//add to size uploading total
					CMS_Page_Content.intSizeUploadingTotal+=CMS_Page_Content.arrFileList[intFieldId][strId].size;
					CMS_Page_Content.intUploadCount++;
					CMS_Page_Content.arrUploadCount[intFieldId]++;
					
					if(eleDoc.getElementsByTagName("validFile")[0].firstChild.nodeValue==0)
					{
						//cancel
						//CMS_Page_Content.arrUploader[intFieldId].removeFile(intFieldId,strId);
						CMS_Page_Content.cancel(intFieldId,strId,(eleDoc.getElementsByTagName("message") ? eleDoc.getElementsByTagName("message")[0].firstChild.nodeValue : ""));
					}
				}
				//remove from array
				CMS_Page_Content.arrValidFileRequest.splice(i,1);
			}
		}
	},
	
	cancel:function(intFieldId,id,strStatus)
	{
		//cancel upload
		this.arrUploader[intFieldId].cancel(id);
		this.arrUploader[intFieldId].removeFile(id);
		
		//enable submit button again
		if(document.getElementById("fSubmit"))
			document.getElementById("fSubmit").disabled=false;
		
		//remove from size uploading total
		CMS_Page_Content.intSizeUploadingTotal-=CMS_Page_Content.arrFileList[intFieldId][id].size;
		CMS_Page_Content.intUploadCount--;
		CMS_Page_Content.arrUploadCount[intFieldId]--;
		
		if(!strStatus)
			strStatus="Cancelled.";
		
		document.getElementById("fileStatus"+intFieldId).innerHTML=strStatus;
		document.getElementById("fileAction"+intFieldId).innerHTML="<div class=\"actions\"><ul><li><a class=\"action4\" href=\"#\" onclick=\"return CMS_Page_Content.removeFile("+intFieldId.toString()+",'"+id+"');\" title=\"Remove\">Remove</a></li></ul></div>";

		return false;
	},
	
	onUploadStart:function(event)
	{
		//CMS_Page_Content.updateProgress(this.intFieldId,0);
		document.getElementById("fileStatus"+this.intFieldId).innerHTML="Waiting...";
	},
	onUploadProgress:function(event)
	{
		//check if progress bar exists
		if(!document.getElementById("progressBar"+this.intFieldId))
		{
			//create progress bar
			eleContainer=document.createElement("div");
			eleContainer.className="progressBar";
			eleContainer.id="progressBar"+this.intFieldId;
			
			eleImg=document.createElement("img");
			eleImg.src=CMS_Main.getRootDirectory()+"/css/tng/progressbar/box.gif";
			eleImg.id="progressBarImage"+this.intFieldId;
			eleImg.width="150";
			eleImg.height="12";
			eleImg.alt="";
			eleImg.title="";
			
			eleSpan=document.createElement("span");
			eleSpan.className="progressBarPercent";
			eleSpan.id="progressBarPercent"+this.intFieldId;
			eleSpan.appendChild(document.createTextNode("0%"));
			
			eleContainer.appendChild(eleImg);
			document.getElementById("fileStatus"+this.intFieldId).innerHTML="";
			document.getElementById("fileStatus"+this.intFieldId).appendChild(eleContainer);
			document.getElementById("fileStatus"+this.intFieldId).appendChild(document.createTextNode(" "));
			document.getElementById("fileStatus"+this.intFieldId).appendChild(eleSpan);
		}
		
		CMS_Page_Content.updateProgress(this.intFieldId,(event.bytesLoaded/event.bytesTotal)*100);
	},
	
	updateProgress:function(intFieldId,dblPercent)
	{
		strHtml="";
		strPercent=Math.round(dblPercent).toString()+"%";
		intPosition=Math.round((100-dblPercent)/100*150) * -1;
		
		if(document.getElementById("progressBar"+intFieldId))
		{
			document.getElementById("progressBar"+intFieldId).style.backgroundPosition=intPosition+"px 0px";
			document.getElementById("progressBarPercent"+intFieldId).replaceChild(document.createTextNode(strPercent),document.getElementById("progressBarPercent"+intFieldId).firstChild);
		}
	},

	onUploadCancel:function(event)
	{
		//this event doesn't seem to fire
	},
	onUploadComplete:function(event)
	{
		CMS_Page_Content.updateProgress(this.intFieldId,100);

		//remove "remove" link
		document.getElementById("fileAction"+this.intFieldId).innerHTML="\u00A0";
	},
	onUploadCompleteData:function(event)
	{
		var objFileData=eval("("+event.data+")");
		
		//remove from size uploading total
		CMS_Page_Content.intSizeUploadingTotal-=CMS_Page_Content.arrFileList[this.intFieldId][event.id].size;
		CMS_Page_Content.intUploadCount--;
		CMS_Page_Content.arrUploadCount[this.intFieldId]--;
		
		if(!objFileData.blnSuccess)
		{
			CMS_Page_Content.cancel(this.intFieldId,event.id,objFileData.strMessages);
		}
		else
		{
			var eleInput=CMS_Main.createNamedElement("input","fField_file_id"+this.intFieldId);
			eleInput.id="fField_file_id"+this.intFieldId;
			eleInput.type="hidden";
			eleInput.value=objFileData.intFileId.toString();
				
			//add element to form
			document.getElementById("fileDataContainer"+this.intFieldId).appendChild(eleInput);
		}

		//check for remaining file uploads
		if(CMS_Page_Content.intUploadCount==0)
		{
			//submit form
			CMS_Page_Content.editSubmitFinal(document.getElementById("frmEditPageContent"));
		}
		
		return false;
	},	
	onUploadError:function(event)
	{
		//CMS_Page_Content.cancel(this.intFieldId,event.status);
		CMS_Page_Content.cancel(this.intFieldId,"Error uploading file, please try again.");
	},

	onRollOver:function()
	{
	},
	onRollOut:function()
	{
	},
	onClick:function()
	{
	}
}/*--------------------------------------------------
	Project:	The November Group - CMS Administration
	Script:		cms_page_form.js
	Includes:	CMS_Page_Form
--------------------------------------------------*/

var CMS_Page_Form={
	
	eleFieldOptions:null,
	intNewFieldIndex:0,
	intTextTypeId:1,
	intTextAreaTypeId:2,
	intTextEditorTypeId:4,
	intFileTypeId:3,
	intCheckboxTypeId:5,
	intDropDownTypeId:6,
	intYearTypeId:7,
	intUrlTypeId:8,
	intCountDownTypeId:9,

	objPageFormListRequest:null,
	blnFilterPublished:true,
	blnFilterNotPublished:true,
	blnFilterArchived:true,
	blnFilterStaging:true,
	strFilterAlpha:"all",
	
	//pagination attributes
	intPageNumber:1,

	adminPage:function()
	{
		CMS_Main.setPage("adminPage"); //store page selection

		CMS_Main.objRequest.open("GET","get_page_xml.php?page="+CMS_Main.getPage(),true);
		CMS_Main.objRequest.onreadystatechange=CMS_Main.updatePage;
		CMS_Main.objRequest.send(null);
		
		return false;
	},
	
	managePages:function()
	{
		CMS_Main.setPage("managePages");
		
		CMS_Main.objRequest.open("GET","get_page_xml.php?page="+CMS_Main.getPage(),true);
		CMS_Main.objRequest.onreadystatechange=CMS_Main.updatePage;
		CMS_Main.objRequest.send(null);
		
		return false;
	},
	
	managePagesInitialize:function(frm)
	{
		if(frm)
		{
			//reselect previously selected filters
			frm.fFilter_alpha.value=this.strFilterAlpha;
			
			//alpha
			if(document.getElementById("filterAlpha"))
			{
				var arrLinks=document.getElementById("filterAlpha").getElementsByTagName("a");
				for(var i=0;i<arrLinks.length;i++)
				{
					if(arrLinks[i].firstChild.firstChild.firstChild.nodeValue.toLowerCase()==frm.fFilter_alpha.value.toString())
					{
						arrLinks[i].className+=" current_page";
						break;
					}
				}
			}
			if(document.getElementById("filterAlphaTop"))
			{
				var arrLinks=document.getElementById("filterAlphaTop").getElementsByTagName("a");
				for(var i=0;i<arrLinks.length;i++)
				{
					if(arrLinks[i].firstChild.firstChild.firstChild.nodeValue.toLowerCase()==frm.fFilter_alpha.value.toString())
					{
						arrLinks[i].className+=" current_page";
						break;
					}
				}
			}
			
			//reselect previously selected show count
			var blnSelected=false;
			if(document.getElementById("fShow_count"))
			{
				var eleSelect2=document.getElementById("fShow_count");
				for(var i=0;i<eleSelect2.options.length;i++)
				{
					if(Number(eleSelect2.options[i].value)==CMS_Client_User_Settings.getShowCountPages())
					{
						eleSelect2.options[i].selected=true;
						blnSelected=true;
						break;
					}
				}
				if(!blnSelected)
				{
					eleSelect2.options[0].selected=true;
					CMS_Client_User_Settings.setShowCountPages(Number(eleSelect2.options[0].value));
				}
			}
			blnSelected=false;
			if(document.getElementById("fShow_count_top"))
			{
				var eleSelect2=document.getElementById("fShow_count_top");
				for(var i=0;i<eleSelect2.options.length;i++)
				{
					if(Number(eleSelect2.options[i].value)==CMS_Client_User_Settings.getShowCountPages())
					{
						eleSelect2.options[i].selected=true;
						blnSelected=true;
						break;
					}
				}
				if(!blnSelected)
				{
					eleSelect2.options[0].selected=true;
					CMS_Client_User_Settings.setShowCountPages(Number(eleSelect2.options[0].value));
				}
			}
			
			//retrieve previously selected page number
			if(frm.fPage_number)
				frm.fPage_number.value=this.intPageNumber.toString();
			
			//enable or disable "publish pages" option
			if(document.getElementById("fAction_index"))
			{
				var eleSelect2=document.getElementById("fAction_index");
				for(var i=0;i<eleSelect2.length;i++)
				{
					if(eleSelect2.options[i].value==2)
					{
						if(CMS_Client_User_Settings.canPublishPageContents())
						{
							eleSelect2.options[i].disabled=false;
						}
						else
						{
							if(eleSelect2.options[i].selected)
								eleSelect2.options[0].selected=true;
								
							//disable option
							eleSelect2.options[i].disabled=true;
						}
						break;
					}
				}
			}
			if(document.getElementById("fAction_index_top"))
			{
				var eleSelect2=document.getElementById("fAction_index_top");
				for(var i=0;i<eleSelect2.length;i++)
				{
					if(eleSelect2.options[i].value==2)
					{
						if(CMS_Client_User_Settings.canPublishPageContents())
						{
							eleSelect2.options[i].disabled=false;
						}
						else
						{
							if(eleSelect2.options[i].selected)
								eleSelect2.options[0].selected=true;
								
							//disable option
							eleSelect2.options[i].disabled=true;
						}
						break;
					}
				}
			}
			
			this.onCategoryOrFilterChange(frm);
		}
	},
	
	onCategoryOrFilterChange:function(frm)
	{
		this.getPageList(frm);
	},
	
	onAlphaClick:function(frm,eleA)
	{
		if(frm && eleA)
		{
			frm.fFilter_alpha.value=eleA.firstChild.firstChild.firstChild.nodeValue.toLowerCase(); //retrieve selected value
			this.strFilterAlpha=frm.fFilter_alpha.value.toString();
			
			//reset classes
			if(document.getElementById("filterAlpha"))
			{
				var arrLinks=document.getElementById("filterAlpha").getElementsByTagName("a");
				for(var i=0;i<arrLinks.length;i++)
				{
					if(arrLinks[i].className.indexOf("current_page")>-1)
						arrLinks[i].className=arrLinks[i].className.replace("current_page","");
					if(arrLinks[i].firstChild.firstChild.firstChild.nodeValue.toLowerCase()==frm.fFilter_alpha.value)
						arrLinks[i].className+=" current_page";
				}
			}
			if(document.getElementById("filterAlphaTop"))
			{
				var arrLinks=document.getElementById("filterAlphaTop").getElementsByTagName("a");
				for(var i=0;i<arrLinks.length;i++)
				{
					if(arrLinks[i].className.indexOf("current_page")>-1)
						arrLinks[i].className=arrLinks[i].className.replace("current_page","");
					if(arrLinks[i].firstChild.firstChild.firstChild.nodeValue.toLowerCase()==frm.fFilter_alpha.value)
						arrLinks[i].className+=" current_page";
				}
			}
			
			//update filter
			CMS_Page_Form.onCategoryOrFilterChange(frm);
		}
		
		return false; //cancel link
	},
	
	onShowCountChange:function(frm,eleSelect)
	{
		if(frm && frm.fShow_count)
		{
			var intPages=1;

			if(document.getElementById("fShow_count"))
			{
				var eleSelect2=document.getElementById("fShow_count");
				for(var i=0;i<eleSelect2.options.length;i++)
				{
					if(Number(eleSelect2.options[i].value)==Number(eleSelect.options[eleSelect.selectedIndex].value))
						eleSelect2.options[i].selected=true;
				}
			}
			if(document.getElementById("fShow_count_top"))
			{
				var eleSelect2=document.getElementById("fShow_count_top");
				for(var i=0;i<eleSelect2.options.length;i++)
				{
					if(Number(eleSelect2.options[i].value)==Number(eleSelect.options[eleSelect.selectedIndex].value))
						eleSelect2.options[i].selected=true;
				}
			}
			
			CMS_Client_User_Settings.setShowCountPages(Number(eleSelect.value)); //store selected value
			
			//calculate number of pages
			if(Number(frm.fShow_count.value)>0)
				intPages=Math.ceil(Number(frm.fPage_count.value)/Number(eleSelect.value));
			if(intPages==0)
				intPages++;
			
			//check if current page number will exist for new show count
			if(Number(frm.fPage_number.value)>intPages)
				frm.fPage_number.value="1"; //reset page number
			
			this.getPageList(frm);
		}
	},
	
	onPageClick:function(frm,eleNumber)
	{
		if(frm && eleNumber)
		{
			frm.fPage_number.value=eleNumber.firstChild.firstChild.firstChild.nodeValue; //retrieve selected value
			this.getPageList(frm);
		}
		return false;
	},
	
	updatePagination:function(frm)
	{
		if(frm && frm.fShow_count)
		{
			var intPages=1;
			
			//calculate number of pages
			if(Number(frm.fShow_count.value)>0)
				intPages=Math.ceil(Number(frm.fPage_count.value)/Number(frm.fShow_count.value));
			if(intPages==0)
				intPages++;
			
			//rebuild page links
			if(document.getElementById("filterPage"))
			{
				document.getElementById("filterPage").innerHTML="";
				for(var i=0;i<intPages;i++)
					document.getElementById("filterPage").innerHTML+="<li><a href=\"#\" onclick=\"return CMS_Page_Form.onPageClick(document.getElementById('frmManagePages'),this);\"><span><span>"+(i+1).toString()+"</span></span></a></li>";
			}
			if(document.getElementById("filterPageTop"))
			{
				document.getElementById("filterPageTop").innerHTML="";
				for(var i=0;i<intPages;i++)
					document.getElementById("filterPageTop").innerHTML+="<li><a href=\"#\" onclick=\"return CMS_Page_Form.onPageClick(document.getElementById('frmManagePages'),this);\"><span><span>"+(i+1).toString()+"</span></span></a></li>";
			}
			
			//select page link
			var blnSelected=false;
			if (document.getElementById("filterPage")) 
			{
				var arrLinks=document.getElementById("filterPage").getElementsByTagName("a");
				for(var i=0;i<arrLinks.length;i++)
				{
					if(arrLinks[i].firstChild.firstChild.firstChild.nodeValue==frm.fPage_number.value.toString())
					{
						//change class
						arrLinks[i].className+=" current_page";
						blnSelected=true;
						break;
					}
				}
				if(!blnSelected)
				{
					arrLinks[0].className+=" current_page";
					frm.fPage_number.value=arrLinks[0].firstChild.firstChild.firstChild.nodeValue;
				}
			}
			blnSelected=false;
			if (document.getElementById("filterPageTop")) 
			{
				var arrLinks=document.getElementById("filterPageTop").getElementsByTagName("a");
				for(var i=0;i<arrLinks.length;i++)
				{
					if(arrLinks[i].firstChild.firstChild.firstChild.nodeValue==frm.fPage_number.value.toString())
					{
						//change class
						arrLinks[i].className+=" current_page";
						blnSelected=true;
						break;
					}
				}
				if(!blnSelected)
				{
					arrLinks[0].className+=" current_page";
					frm.fPage_number.value=arrLinks[0].firstChild.firstChild.firstChild.nodeValue;
				}
			}

			//store selected value
			this.intPageNumber=Number(frm.fPage_number.value);
			
			//calculate page count
			var intCountStart=(Number(frm.fPage_number.value)-1)*Number(frm.fShow_count.value);
			var intCountEnd=(Number(frm.fShow_count.value)==0 ? Number(frm.fPage_count.value) : Math.min(Number(frm.fShow_count.value)+intCountStart,Number(frm.fPage_count.value)));
			
			//update page count
			if(document.getElementById("pageCountStart"))
				document.getElementById("pageCountStart").innerHTML=(Math.min(intCountStart+1,Number(frm.fPage_count.value))).toString();
			if(document.getElementById("pageCountEnd"))
				document.getElementById("pageCountEnd").innerHTML=intCountEnd.toString();
			if(document.getElementById("pageCount"))
				document.getElementById("pageCount").innerHTML=frm.fPage_count.value.toString();

			if(document.getElementById("pageCountStartTop"))
				document.getElementById("pageCountStartTop").innerHTML=(Math.min(intCountStart+1,Number(frm.fPage_count.value))).toString();
			if(document.getElementById("pageCountEndTop"))
				document.getElementById("pageCountEndTop").innerHTML=intCountEnd.toString();
			if(document.getElementById("pageCountTop"))
				document.getElementById("pageCountTop").innerHTML=frm.fPage_count.value.toString();
		}
	},
	
	getPageList:function(frm)
	{
		var strHtml="";
		
		//clear select all
		if(document.getElementById("selectAll"))
			document.getElementById("selectAll").checked=false;
		
		//clear content list
		while(document.getElementById("pageListContainer").firstChild)
			document.getElementById("pageListContainer").removeChild(document.getElementById("pageListContainer").firstChild);
		
		//add loading message
		var eleLoading=document.createElement("tr");
		eleLoading.appendChild(document.createElement("td"));
		eleLoading.childNodes[0].colSpan=4;
		eleLoading.childNodes[0].appendChild(document.createTextNode(CMS_Main.getLoadingMessage()));
		document.getElementById("pageListContainer").appendChild(eleLoading);
		
		//get content list
		this.objPageFormListRequest=CMS_Main.createRequest();
		this.objPageFormListRequest.open("GET","get_element_xml.php?function=getPageFormListJson&fFilter_alpha="+encodeURIComponent(CMS_Page_Form.strFilterAlpha)+"&fShow_count="+frm.fShow_count.value.toString()+"&fPage_number="+frm.fPage_number.value.toString(),true);
		this.objPageFormListRequest.onreadystatechange=function(){
			if(CMS_Page_Form.objPageFormListRequest.readyState==4)
			{
				if(CMS_Page_Form.objPageFormListRequest.status==200)
				{
					//clear loading message
					while(document.getElementById("pageListContainer").firstChild)
						document.getElementById("pageListContainer").removeChild(document.getElementById("pageListContainer").firstChild);
					
					var objPageData=eval("("+CMS_Page_Form.objPageFormListRequest.responseText+")");
					document.getElementById("fPage_count").value=objPageData.intPageCount.toString();
					
					//add rows
					for(i in objPageData.arrPages)
					{
						var eleRow=CMS_Page_Form.createRow(objPageData.arrPages[i]);
						
						if(i%2==0)
							eleRow.className="first";
						else
							eleRow.className="second";

						document.getElementById("pageListContainer").appendChild(eleRow);
					}
					
					if(objPageData.arrPages.length==0)
						document.getElementById("pageListContainer").appendChild(CMS_Page_Form.createEmptyRow());
					
					CMS_Page_Form.updatePagination(document.getElementById("frmManagePages"));
				}
			}
		};
		this.objPageFormListRequest.send(null);
		
		return false;
	},
	
	createRow:function(objPageData)
	{
		var eleRow=document.createElement("tr");
		
		var eleTd7=document.createElement("td");
		eleTd7.appendChild(document.createTextNode(objPageData.strName));
		eleRow.appendChild(eleTd7);
		
		var eleTd1=document.createElement("td");
		eleTd1.appendChild(document.createTextNode(objPageData.strContentTitle));
		eleRow.appendChild(eleTd1);
		
		var eleTd2=document.createElement("td");
		eleTd2.appendChild(document.createTextNode(objPageData.strDateCreated));
		eleRow.appendChild(eleTd2);
		
		var eleTd4=document.createElement("td");
		eleTd4.style.width="96px";
		eleTd4.innerHTML=" \
		<div class=\"actions\"> \
			<ul> \
				<li><a class=\"action7\" href=\"#\" onclick=\"return CMS_Page_Form.duplicatePage("+objPageData.intPageId.toString()+");\" title=\"Copy\">Copy</a></li> \
				<li><a class=\"action5\" href=\"#\" onclick=\"return CMS_Page_Form.editPage("+objPageData.intPageId.toString()+");\" title=\"Edit\">Edit</a></li> \
				<li><a class=\"action4\" href=\"#\" onclick=\"return CMS_Page_Form.deletePage("+objPageData.intPageId.toString()+");\" title=\"Delete\">Delete</a></li> \
			</ul> \
			<div style=\"float:right;\"> \
				<input class=\"radio\" name=\"selectPage\" id=\"selectPage"+objPageData.intPageId.toString()+"\" type=\"checkbox\" value=\""+objPageData.intPageId.toString()+"\" /> \
				<input name=\"selectPageName\" id=\"selectPageName"+objPageData.intPageId.toString()+"\" type=\"hidden\" value=\""+objPageData.strName+"\" /> \
			</div> \
		</div>";
		eleRow.appendChild(eleTd4);
		
		return eleRow;
	},
	
	createEmptyRow:function()
	{
		var eleRow=document.createElement("tr");
		
		var eleTd1=document.createElement("td");
		eleTd1.colSpan=4;
		eleTd1.appendChild(document.createTextNode("No pages to display"));
		eleRow.appendChild(eleTd1);
		
		return eleRow;
	},
	
	selectAllClick:function(frm)
	{
		for(var i=0;i<frm.length;i++)
			if(frm.elements[i].name && frm.elements[i].name.indexOf("selectPage")==0)
				frm.elements[i].checked=true;
		return false;
	},
	
	deselectAllClick:function(frm)
	{
		for(var i=0;i<frm.length;i++)
			if(frm.elements[i].name && frm.elements[i].name.indexOf("selectPage")==0)
				frm.elements[i].checked=false;
		return false;
	},
	
	onActionChange:function(frm,eleSelect)
	{
	},
	
	onActionClick:function(frm,eleSelect)
	{
		if(frm && eleSelect)
		{
			switch(Number(eleSelect.value))
			{
				case(1): //delete
					this.deletePages(frm);
					break;
				case(2): //publish
					this.publishPages(frm);
					break;
				case(3): //archive
					this.archivePages(frm);
					break;
				default:
			}
		}
		return false;
	},
	
	deletePages:function(frm)
	{
		var arrPageIds=new Array();
		var arrPageNames=new Array();
		
		for(var i=0;i<frm.length;i++)
		{
			if(frm.elements[i].name && frm.elements[i].name.indexOf("selectPage")==0 && frm.elements[i].type=="checkbox" && frm.elements[i].checked)
			{
				arrPageIds[arrPageIds.length]=frm.elements[i].value;
				arrPageNames[arrPageNames.length]=frm.elements[i+1].value;
			}
		}
		if(arrPageIds.length==0)
		{
			alert("You do not have any pages selected.");
		}
		else if(confirm("Are you sure you want to delete "+(arrPageIds.length==1 ? arrPageNames[0]+"?" : "the following pages?\n\n\t"+arrPageNames.join("\n\t")+"\n ")))
		{
			CMS_Main.objRequest.open("GET","get_page_xml.php?page="+CMS_Main.getPage()+"&fAction=deletePages&fPage_id[]="+arrPageIds.join("&fPage_id[]="),true);
			CMS_Main.objRequest.onreadystatechange=CMS_Main.updatePage;
			CMS_Main.objRequest.send(null);
		}
		
		return false;
	},
	
	addPage:function(intType)
	{
		if(!intType)
			var intType=0;
		
		CMS_Main.objRequest.open("GET","get_page_xml.php?page=editPageForm&fType="+intType.toString(),true);
		CMS_Main.objRequest.onreadystatechange=CMS_Main.updatePage;
		CMS_Main.objRequest.send(null);
		
		return false;
	},
	
	deletePage:function(intPageId)
	{
		var strTitle=document.getElementById("selectPageName"+intPageId).value.toString();
		
		if(confirm("Are you sure you want to delete "+strTitle+"?"))
		{
			CMS_Main.objRequest.open("GET","get_page_xml.php?page="+CMS_Main.getPage()+"&fAction=deletePageForm&fPage_id="+intPageId.toString(),true);
			CMS_Main.objRequest.onreadystatechange=CMS_Main.updatePage;
			CMS_Main.objRequest.send(null);
		}
		
		return false;
	},
	
	editPage:function(intPageId)
	{
		CMS_Main.objRequest.open("GET","get_page_xml.php?page=editPageForm&fPage_id="+intPageId.toString(),true);
		CMS_Main.objRequest.onreadystatechange=CMS_Main.updatePage;
		CMS_Main.objRequest.send(null);
		
		return false;
	},
	
	duplicatePage:function(intPageId)
	{
		CMS_Main.objRequest.open("GET","get_page_xml.php?page=duplicatePageForm&fPage_id="+intPageId.toString(),true);
		CMS_Main.objRequest.onreadystatechange=CMS_Main.updatePage;
		CMS_Main.objRequest.send(null);
		
		return false;
	},
	
	
	editPageInitialize:function(frm)
	{
		if(frm)
		{
			//store field options html
			if(document.getElementById("fieldOptions"))
			{
				this.eleFieldOptions=document.getElementById("fieldOptions").parentNode.removeChild(document.getElementById("fieldOptions"));
			}
			
			//initialize the drag drop
			this.initializeOrder(frm);
			
			frm.fName.focus();
			frm.fName.select();
		}
		
		return false;
	},
	
	initializeOrder:function(frm)
	{
		//initialize the drag drop
		$("#fieldListContainer").tableDnD();
	},

	onFileTypeChange:function(eleSelect)
	{
		if(eleSelect)
		{
			var strId=eleSelect.id.replace("fFile_allowed_file_types","");
			
			if(document.getElementById("fileImageOptions"+strId))
			{
				var blnShowImageOptions=false;
				
				for(var i=0;i<document.getElementById("fFile_allowed_file_types"+strId).length;i++)
				{
					if(document.getElementById("fFile_allowed_file_types"+strId).options[i].selected && Number(document.getElementById("fFile_allowed_file_types"+strId).options[i].value)==CMS_File.intImageTypeId)
					{
						blnShowImageOptions=true;
						break;
					}
				}
				
				if(blnShowImageOptions)
					document.getElementById("fileImageOptions"+strId).style.display="block";
				else
					document.getElementById("fileImageOptions"+strId).style.display="none";
				
				this.onResizeClick(document.getElementById("fFile_image_resize"+strId));
			}
		}
	},
	
	onResizeClick:function(eleInput)
	{
		if(eleInput)
		{
			var strId=eleInput.id.replace("fFile_image_resize","");
			
			if(document.getElementById("fileImageResizeOptions"+strId))
			{
				if(document.getElementById("fFile_image_resize"+strId).checked)
					document.getElementById("fileImageResizeOptions"+strId).style.display="block";
				else
					document.getElementById("fileImageResizeOptions"+strId).style.display="none";
			}
		}
	},

	editCancel:function(frm)
	{
		CMS_Main.objRequest.open("GET","get_page_xml.php?page="+CMS_Main.getPage(),true);
		CMS_Main.objRequest.onreadystatechange=CMS_Main.updatePage;
		CMS_Main.objRequest.send(null);
		
		return false;
	},
	
	editSubmit:function(frm)
	{
		var blnReturnValue=true;
		
		if(frm.fName.value.length==0)
		{
			alert("Please enter a name");
			frm.fName.focus();
			blnReturnValue=false;
		}
		else if(frm.fField_id)
		{
			if(frm.fField_id.length) //there is more than one field
			{
				for(var i=0;i<frm.fField_id.length;i++)
				{
					//check for valid field attributes
					var strId=frm.fField_id[i].value;
					
					if(!this.editFieldSubmit(frm,strId))
					{
						blnReturnValue=false;
						break;
					}
				}
			}
			else //there is only one field
			{
				//check for valid field attributes
				var strId=frm.fField_id.value;
				
				if(!this.editFieldSubmit(frm,strId))
				{
					blnReturnValue=false;
				}
			}

		}
		
		if(blnReturnValue)
		{
			document.getElementById("fSubmit").disabled=true;
			
			CMS_Main.objRequest.open("POST","get_page_xml.php",true);
			CMS_Main.objRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
			CMS_Main.objRequest.onreadystatechange=CMS_Main.updatePage;
			CMS_Main.objRequest.send(CMS_Main.formEncode(frm)+"&page="+CMS_Main.getPage());
		}
		
		return false;
	},
	
	editFieldSubmit:function(frm,strFieldId)
	{
		var blnReturnValue=true;
		
		if(frm.elements["fField_title"+strFieldId] && frm.elements["fField_title"+strFieldId].value.length==0)
		{
			alert("Please enter a field name");
			frm.elements["fField_title"+strFieldId].focus();
			frm.elements["fField_title"+strFieldId].select();
			blnReturnValue=false;
		}
		else if(frm.elements["fField_type"+strFieldId] && frm.elements["fField_type"+strFieldId].value==0)
		{
			alert("Please select a field type");
			frm.elements["fField_type"+strFieldId].focus();
			blnReturnValue=false;
		}
		else if(frm.elements["fField_type"+strFieldId] && frm.elements["fField_type"+strFieldId].value==this.intFileTypeId && frm.elements["fFile_allowed_file_types"+strFieldId] && frm.elements["fFile_allowed_file_types"+strFieldId].selectedIndex==-1)
		{
			alert("Please select at least one allowed file type");
			frm.elements["fFile_allowed_file_types"+strFieldId].focus();
			blnReturnValue=false;
		}
		else if(frm.elements["fField_type"+strFieldId] && frm.elements["fField_type"+strFieldId].value==this.intFileTypeId && frm.elements["fFile_allowed_file_types"+strFieldId] && Number(frm.elements["fFile_allowed_file_types"+strFieldId][frm.elements["fFile_allowed_file_types"+strFieldId].selectedIndex].value)==CMS_File.intImageTypeId && frm.elements["fFile_image_resize"+strFieldId] && frm.elements["fFile_image_resize"+strFieldId].checked && frm.elements["fFile_image_max_width"+strFieldId] && frm.elements["fFile_image_max_height"+strFieldId] && Number(frm.elements["fFile_image_max_width"+strFieldId].value)==0 && Number(frm.elements["fFile_image_max_height"+strFieldId].value)==0)
		{
			alert("Please enter a maximum width, height, or both");
			frm.elements["fFile_image_max_width"+strFieldId].focus();
			frm.elements["fFile_image_max_width"+strFieldId].select();
			blnReturnValue=false;
		}
		else if(frm.elements["fField_type"+strFieldId] && frm.elements["fField_type"+strFieldId].value==this.intUrlTypeId && frm.elements["fUrl_target_id"+strFieldId] && Number(frm.elements["fUrl_target_id"+strFieldId].value)==1 && frm.elements["fUrl_target_other"+strFieldId].value=="")
		{
			alert("Please enter a target value");
			frm.elements["fUrl_target_other"+strFieldId].focus();
			blnReturnValue=false;
		}
		
		return blnReturnValue;
	},
	
	getFieldOptions:function()
	{
		return this.eleFieldOptions.cloneNode(true);
	},
	
	addField:function(frm)
	{
		if(document.getElementById("fieldListContainer"))
		{
			//increment index
			this.intNewFieldIndex++;
			var strId="new"+this.intNewFieldIndex.toString();
			
			//add field options to document
			document.getElementById("fieldListContainer").appendChild(this.getFieldOptions());
			
			//update element ids
			document.getElementById("removeField").id+=strId;

			document.getElementById("fieldOptions").id+=strId;
			document.getElementById("fField_title").name+=strId;
			document.getElementById("fField_title").id+=strId;
			document.getElementById("fField_type").name+=strId;
			document.getElementById("fField_type").id+=strId;
			
			document.getElementById("textOptions").id+=strId;
			document.getElementById("fText_size").name+=strId;
			document.getElementById("fText_size").id+=strId;
			document.getElementById("fText_size_label").id+=strId;
			document.getElementById("fText_size_label"+strId).htmlFor="fText_size"+strId;
			document.getElementById("fText_type").name+=strId;
			document.getElementById("fText_type").id+=strId;
			document.getElementById("fText_type_label").id+=strId;
			document.getElementById("fText_type_label"+strId).htmlFor="fText_type"+strId;
			
			document.getElementById("textEditorOptions").id+=strId;
			
			document.getElementById("fileOptions").id+=strId;
			document.getElementById("fFile_allowed_file_types").name+=strId;
			document.getElementById("fFile_allowed_file_types").id+=strId;
			
			document.getElementById("fileImageOptions").id+=strId;
			document.getElementById("fFile_image_resize").name+=strId;
			document.getElementById("fFile_image_resize").id+=strId;
			document.getElementById("fFile_image_resize_label").id+=strId;
			document.getElementById("fFile_image_resize_label"+strId).htmlFor="fFile_image_resize"+strId;
			
			document.getElementById("fileImageResizeOptions").id+=strId;
			document.getElementById("fFile_image_max_width").name+=strId;
			document.getElementById("fFile_image_max_width").id+=strId;
			document.getElementById("fFile_image_max_width_label").id+=strId;
			document.getElementById("fFile_image_max_width_label"+strId).htmlFor="fFile_image_max_width"+strId;
			document.getElementById("fFile_image_max_height").name+=strId;
			document.getElementById("fFile_image_max_height").id+=strId;
			document.getElementById("fFile_image_max_height_label").id+=strId;
			document.getElementById("fFile_image_max_height_label"+strId).htmlFor="fFile_image_max_height"+strId;
			
			document.getElementById("checkboxOptions").id+=strId;
			
			document.getElementById("dropDownOptions").id+=strId;
			document.getElementById("fDrop_down_options").name+=strId;
			document.getElementById("fDrop_down_options").id+=strId;
			
			document.getElementById("yearOptions").id+=strId;
			document.getElementById("fYear_start").name+=strId;
			document.getElementById("fYear_start").id+=strId;
			document.getElementById("fYear_start_label").id+=strId;
			document.getElementById("fYear_start_label"+strId).htmlFor="fYear_start"+strId;
			document.getElementById("fYear_end").name+=strId;
			document.getElementById("fYear_end").id+=strId;
			document.getElementById("fYear_end_label").id+=strId;
			document.getElementById("fYear_end_label"+strId).htmlFor="fYear_end"+strId;
			
			document.getElementById("urlOptions").id+=strId;
			document.getElementById("urlOptionsOther").id+=strId;
			document.getElementById("fUrl_target_id_label").id+=strId;
			document.getElementById("fUrl_target_id_label"+strId).htmlFor="fUrl_target_id"+strId;
			document.getElementById("fUrl_target_id").name+=strId;
			document.getElementById("fUrl_target_id").id+=strId;
			document.getElementById("fUrl_target_other").name+=strId;
			document.getElementById("fUrl_target_other").id+=strId;
			
			document.getElementById("countDownOptions").id+=strId;
			
			//update stored id
			if(frm.fField_id.length)
				frm.fField_id[frm.fField_id.length-1].value=strId;
			else
				frm.fField_id.value=strId;
				
			//display field options
			try
			{
				document.getElementById("fieldOptions"+strId).style.display="table-row";
			}
			catch(e)
			{
				//IE
				try
				{
					document.getElementById("fieldOptions"+strId).style.display="block";
				}
				catch(e)
				{
					document.nativeGetElementById("fieldOptions"+strId).style.display="block";
				}
			}
			
			if(document.getElementById("fField_title"+strId))
				document.getElementById("fField_title"+strId).focus();
			
			//re-initialize the drag drop
			this.initializeOrder(frm);
		}
		return false;
	},
	
	fieldTypeChange:function(frm,eleInput)
	{
		if(frm)
		{
			//get id
			var strId=eleInput.id.replace("fField_type","");
			
			switch(eleInput.value)
			{
				case(this.intTextTypeId.toString()):
					document.getElementById("fileOptions"+strId).style.display="none";
					document.getElementById("checkboxOptions"+strId).style.display="none";
					document.getElementById("textEditorOptions"+strId).style.display="none";
					document.getElementById("dropDownOptions"+strId).style.display="none";
					document.getElementById("yearOptions"+strId).style.display="none";
					document.getElementById("urlOptions"+strId).style.display="none";
					document.getElementById("textOptions"+strId).style.display="block";
					document.getElementById("countDownOptions"+strId).style.display="none";
					break;
				case(this.intTextAreaTypeId.toString()):
					document.getElementById("fileOptions"+strId).style.display="none";
					document.getElementById("checkboxOptions"+strId).style.display="none";
					document.getElementById("textEditorOptions"+strId).style.display="none";
					document.getElementById("dropDownOptions"+strId).style.display="none";
					document.getElementById("yearOptions"+strId).style.display="none";
					document.getElementById("urlOptions"+strId).style.display="none";
					document.getElementById("textOptions"+strId).style.display="block";
					document.getElementById("countDownOptions"+strId).style.display="none";
					break;
				case(this.intFileTypeId.toString()):
					document.getElementById("textOptions"+strId).style.display="none";
					document.getElementById("checkboxOptions"+strId).style.display="none";
					document.getElementById("textEditorOptions"+strId).style.display="none";
					document.getElementById("dropDownOptions"+strId).style.display="none";
					document.getElementById("yearOptions"+strId).style.display="none";
					document.getElementById("urlOptions"+strId).style.display="none";
					document.getElementById("fileOptions"+strId).style.display="block";
					document.getElementById("countDownOptions"+strId).style.display="none";
					break;
				case(this.intTextEditorTypeId.toString()):
					document.getElementById("textOptions"+strId).style.display="none";
					document.getElementById("fileOptions"+strId).style.display="none";
					document.getElementById("checkboxOptions"+strId).style.display="none";
					document.getElementById("dropDownOptions"+strId).style.display="none";
					document.getElementById("yearOptions"+strId).style.display="none";
					document.getElementById("urlOptions"+strId).style.display="none";
					document.getElementById("textEditorOptions"+strId).style.display="block";
					document.getElementById("countDownOptions"+strId).style.display="none";
					break;
				case(this.intCheckboxTypeId.toString()):
					document.getElementById("textOptions"+strId).style.display="none";
					document.getElementById("fileOptions"+strId).style.display="none";
					document.getElementById("textEditorOptions"+strId).style.display="none";
					document.getElementById("dropDownOptions"+strId).style.display="none";
					document.getElementById("yearOptions"+strId).style.display="none";
					document.getElementById("urlOptions"+strId).style.display="none";
					document.getElementById("checkboxOptions"+strId).style.display="block";
					document.getElementById("countDownOptions"+strId).style.display="none";
					break;
				case(this.intDropDownTypeId.toString()):
					document.getElementById("textOptions"+strId).style.display="none";
					document.getElementById("fileOptions"+strId).style.display="none";
					document.getElementById("textEditorOptions"+strId).style.display="none";
					document.getElementById("checkboxOptions"+strId).style.display="none";
					document.getElementById("yearOptions"+strId).style.display="none";
					document.getElementById("urlOptions"+strId).style.display="none";
					document.getElementById("dropDownOptions"+strId).style.display="block";
					document.getElementById("countDownOptions"+strId).style.display="none";
					break;
				case(this.intYearTypeId.toString()):
					document.getElementById("textOptions"+strId).style.display="none";
					document.getElementById("fileOptions"+strId).style.display="none";
					document.getElementById("textEditorOptions"+strId).style.display="none";
					document.getElementById("checkboxOptions"+strId).style.display="none";
					document.getElementById("dropDownOptions"+strId).style.display="none";
					document.getElementById("urlOptions"+strId).style.display="none";
					document.getElementById("yearOptions"+strId).style.display="block";
					document.getElementById("countDownOptions"+strId).style.display="none";
					break;
				case(this.intUrlTypeId.toString()):
					document.getElementById("textOptions"+strId).style.display="none";
					document.getElementById("fileOptions"+strId).style.display="none";
					document.getElementById("textEditorOptions"+strId).style.display="none";
					document.getElementById("checkboxOptions"+strId).style.display="none";
					document.getElementById("dropDownOptions"+strId).style.display="none";
					document.getElementById("yearOptions"+strId).style.display="none";
					document.getElementById("urlOptions"+strId).style.display="block";
					document.getElementById("countDownOptions"+strId).style.display="none";
					break;
				case(this.intCountDownTypeId.toString()):
					document.getElementById("textOptions"+strId).style.display="none";
					document.getElementById("fileOptions"+strId).style.display="none";
					document.getElementById("textEditorOptions"+strId).style.display="none";
					document.getElementById("checkboxOptions"+strId).style.display="none";
					document.getElementById("dropDownOptions"+strId).style.display="none";
					document.getElementById("yearOptions"+strId).style.display="none";
					document.getElementById("urlOptions"+strId).style.display="none";
					document.getElementById("countDownOptions"+strId).style.display="block";
					break;
				default:
					document.getElementById("textOptions"+strId).style.display="none";
					document.getElementById("fileOptions"+strId).style.display="none";
					document.getElementById("textEditorOptions"+strId).style.display="none";
					document.getElementById("checkboxOptions"+strId).style.display="none";
					document.getElementById("dropDownOptions"+strId).style.display="none";
					document.getElementById("yearOptions"+strId).style.display="none";
					document.getElementById("urlOptions"+strId).style.display="none";
					document.getElementById("countDownOptions"+strId).style.display="none";
					break;
			}
		}
	},
	
	urlTargetIdChange:function(eleSelect)
	{
		var strId="";
		
		if(eleSelect)
		{
			strId=eleSelect.id.replace("fUrl_target_id","");
			
			if(Number(eleSelect.value)==1)
			{
				if(document.getElementById("urlOptionsOther"+strId))
					document.getElementById("urlOptionsOther"+strId).style.display="inline";
			}
			else
			{
				if(document.getElementById("urlOptionsOther"+strId))
					document.getElementById("urlOptionsOther"+strId).style.display="none";
			}
		}
	},
	
	removeField:function(eleA)
	{
		if(eleA)
		{
			//get id
			var strId=eleA.id.replace("removeField","");
			
			//remove field
			try
			{
				document.getElementById("fieldOptions"+strId).parentNode.removeChild(document.getElementById("fieldOptions"+strId));
			}
			catch(e)
			{
				document.all["fieldOptions"+strId].parentNode.removeChild(document.all["fieldOptions"+strId]); //IE
			}
		}
		
		return false;
	}
}/*--------------------------------------------------
	Project:	The November Group - CMS Administration
	Script:		cms_page_code.js
	Includes:	CMS_Page_Code
--------------------------------------------------*/

var CMS_Page_Code={
	
	manageCodes:function()
	{
		CMS_Main.setPage("managePageCodes"); //store page selection

		CMS_Main.objRequest.open("GET","get_page_xml.php?page="+CMS_Main.getPage(),true);
		CMS_Main.objRequest.onreadystatechange=CMS_Main.updatePage;
		CMS_Main.objRequest.send(null);
		
		return false;
	},
	
	addCode:function()
	{
		CMS_Main.objRequest.open("GET","get_page_xml.php?page=editPageCode",true);
		CMS_Main.objRequest.onreadystatechange=CMS_Main.updatePage;
		CMS_Main.objRequest.send(null);
		
		return false;
	},
	
	editCode:function(intCodeId)
	{
		CMS_Main.objRequest.open("GET","get_page_xml.php?page=editPageCode&fCode_id="+intCodeId.toString(),true);
		CMS_Main.objRequest.onreadystatechange=CMS_Main.updatePage;
		CMS_Main.objRequest.send(null);
		
		return false;
	},
	
	editCodeText:function(intCodeId)
	{
		CMS_Main.objRequest.open("GET","get_page_xml.php?page=editPageCodeText&fCode_id="+intCodeId.toString(),true);
		CMS_Main.objRequest.onreadystatechange=CMS_Main.updatePage;
		CMS_Main.objRequest.send(null);
		
		return false;
	},
	
	editCodeInitialize:function(frm)
	{
		if(document.getElementById("fCode"))
			CMS_Main.allowTabs(document.getElementById("fCode"));
		
		if(frm)
		{
			if(frm.fTitle)
			{
				frm.fTitle.focus();
				frm.fTitle.select();
			}
		}
		return false;
	},
	
	editCodeSubmit:function(frm)
	{
		var blnReturnValue=true;
		
		if(frm.fTitle.value.length==0)
		{
			alert("Please enter a title");
			frm.fTitle.focus();
			blnReturnValue=false;
		}
		
		if(blnReturnValue)
		{
			document.getElementById("fSubmit").disabled=true;

			CMS_Main.objRequest.open("POST","get_page_xml.php",true);
			CMS_Main.objRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
			CMS_Main.objRequest.onreadystatechange=CMS_Main.updatePage;
			CMS_Main.objRequest.send(CMS_Main.formEncode(frm)+"&page="+CMS_Main.getPage());
		}
		
		return false;
	},	
	
	editCodeTextSubmit:function(frm)
	{
		var blnReturnValue=true;
		
		if(blnReturnValue)
		{
			document.getElementById("fSubmit").disabled=true;

			CMS_Main.objRequest.open("POST","get_page_xml.php",true);
			CMS_Main.objRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
			CMS_Main.objRequest.onreadystatechange=CMS_Main.updatePage;
			CMS_Main.objRequest.send(CMS_Main.formEncode(frm)+"&page="+CMS_Main.getPage());
		}
		
		return false;
	},	
	
	editCodeCancel:function()
	{
		CMS_Main.objRequest.open("GET","get_page_xml.php?page="+CMS_Main.getPage(),true);
		CMS_Main.objRequest.onreadystatechange=CMS_Main.updatePage;
		CMS_Main.objRequest.send(null);
		
		return false;
	},
	
	deleteCode:function(intCodeId,strTitle)
	{
		if(confirm("Are you sure you want to delete "+strTitle+"?"))
		{
			CMS_Main.objRequest.open("GET","get_page_xml.php?page="+CMS_Main.getPage()+"&fAction=deletePageCode&fCode_id="+intCodeId,true);
			CMS_Main.objRequest.onreadystatechange=CMS_Main.updatePage;
			CMS_Main.objRequest.send(null);
		}
		
		return false;
	}
}/*--------------------------------------------------
	Project:	The November Group - CMS Administration
	Script:		cms_calendar_category.js
	Includes:	CMS_Calendar_Category
--------------------------------------------------*/

var CMS_Calendar_Category={
	
	manageCategories:function()
	{
		CMS_Main.setPage("manageCalendarCategories"); //store page selection

		CMS_Main.objRequest.open("GET","get_page_xml.php?page="+CMS_Main.getPage(),true);
		CMS_Main.objRequest.onreadystatechange=CMS_Main.updatePage;
		CMS_Main.objRequest.send(null);
		
		return false;
	},
	
	addCategory:function()
	{
		CMS_Main.objRequest.open("GET","get_page_xml.php?page=editCalendarCategory",true);
		CMS_Main.objRequest.onreadystatechange=CMS_Main.updatePage;
		CMS_Main.objRequest.send(null);
		
		return false;
	},
	
	editCategory:function(intCategoryId)
	{
		CMS_Main.objRequest.open("GET","get_page_xml.php?page=editCalendarCategory&fCategory_id="+intCategoryId.toString(),true);
		CMS_Main.objRequest.onreadystatechange=CMS_Main.updatePage;
		CMS_Main.objRequest.send(null);
		
		return false;
	},
	
	editCategoryInitialize:function(frm)
	{
		if(frm)
		{
			if(frm.fName)
			{
				frm.fName.focus();
				frm.fName.select();
			}
		}
		return false;
	},
	
	editCategorySubmit:function(frm)
	{
		var blnReturnValue=true;
		
		if(frm.fName.value.length==0)
		{
			alert("Please enter a name");
			frm.fName.focus();
			blnReturnValue=false;
		}
		
		if(blnReturnValue)
		{
			document.getElementById("fSubmit").disabled=true;

			CMS_Main.objRequest.open("POST","get_page_xml.php",true);
			CMS_Main.objRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
			CMS_Main.objRequest.onreadystatechange=CMS_Main.updatePage;
			CMS_Main.objRequest.send(CMS_Main.formEncode(frm)+"&page="+CMS_Main.getPage());
		}
		
		return false;
	},	
	
	editCategoryCancel:function()
	{
		CMS_Main.objRequest.open("GET","get_page_xml.php?page="+CMS_Main.getPage(),true);
		CMS_Main.objRequest.onreadystatechange=CMS_Main.updatePage;
		CMS_Main.objRequest.send(null);
		
		return false;
	},
	
	deleteCategory:function(intCategoryId,strTitle)
	{
		if(confirm("Are you sure you want to delete "+strTitle+"?"))
		{
			CMS_Main.objRequest.open("GET","get_page_xml.php?page="+CMS_Main.getPage()+"&fAction=deleteCalendarCategory&fCategory_id="+intCategoryId,true);
			CMS_Main.objRequest.onreadystatechange=CMS_Main.updatePage;
			CMS_Main.objRequest.send(null);
		}
		
		return false;
	}
}/*--------------------------------------------------
	Project:	The November Group - CMS Administration
	Script:		cms_calendar_item.js
	Includes:	CMS_Calendar_Item
--------------------------------------------------*/

var CMS_Calendar_Item={
	
	objItemListRequest:null,
	intCurrentCategoryId:-1,
	blnFilterPublished:true,
	blnFilterNotPublished:true,
	blnFilterArchived:true,
	blnFilterStaging:true,
	strFilterAlpha:"all",
	
	//pagination attributes
	intPageNumber:1,

	//item manage methods
	
	adminCalendar:function()
	{
		CMS_Main.setPage("adminCalendar"); //store page selection

		CMS_Main.objRequest.open("GET","get_page_xml.php?page="+CMS_Main.getPage(),true);
		CMS_Main.objRequest.onreadystatechange=CMS_Main.updatePage;
		CMS_Main.objRequest.send(null);
		
		return false;
	},
	
	manageItems:function()
	{
		CMS_Main.setPage("manageCalendarItems"); //store page selection

		CMS_Main.objRequest.open("GET","get_page_xml.php?page="+CMS_Main.getPage(),true);
		CMS_Main.objRequest.onreadystatechange=CMS_Main.updatePage;
		CMS_Main.objRequest.send(null);
		
		return false;
	},
	
	initializeItemManager:function(frm)
	{
		var blnSelected=false;
		
		if(frm)
		{
			//reselect previously selected category
			blnSelected=false;
			if(document.getElementById("fCategory_id") && document.getElementById("fCategory_id").length)
			{
				for(var i=0;i<document.getElementById("fCategory_id").options.length;i++)
				{
					if(document.getElementById("fCategory_id").options[i].value==this.intCurrentCategoryId)
					{
						document.getElementById("fCategory_id").options[i].selected=true;
						blnSelected=true;
						break;
					}
				}
				if(!blnSelected)
				{
					document.getElementById("fCategory_id").options[0].selected=true;
					this.intCurrentCategoryId=document.getElementById("fCategory_id").options[0].value;
				}
			}
			blnSelected=false;
			if(document.getElementById("fCategory_id_top") && document.getElementById("fCategory_id_top").length)
			{
				for(var i=0;i<document.getElementById("fCategory_id_top").options.length;i++)
				{
					if(document.getElementById("fCategory_id_top").options[i].value==this.intCurrentCategoryId)
					{
						document.getElementById("fCategory_id_top").options[i].selected=true;
						blnSelected=true;
						break;
					}
				}
				if(!blnSelected)
				{
					document.getElementById("fCategory_id_top").options[0].selected=true;
					this.intCurrentCategoryId=document.getElementById("fCategory_id_top").options[0].value;
				}
			}

			//reselect previously selected filters
			if(document.getElementById("fFilter_published")) document.getElementById("fFilter_published").checked=this.blnFilterPublished;
			if(document.getElementById("fFilter_published_top")) document.getElementById("fFilter_published_top").checked = this.blnFilterPublished;
			if(document.getElementById("fFilter_not_published")) document.getElementById("fFilter_not_published").checked=this.blnFilterNotPublished;
			if(document.getElementById("fFilter_not_published_top")) document.getElementById("fFilter_not_published_top").checked=this.blnFilterNotPublished;
			if(document.getElementById("fFilter_archived")) document.getElementById("fFilter_archived").checked=this.blnFilterArchived;
			if(document.getElementById("fFilter_archived_top")) document.getElementById("fFilter_archived_top").checked=this.blnFilterArchived;
			if(document.getElementById("fFilter_staging")) document.getElementById("fFilter_staging").checked=this.blnFilterStaging;
			if(document.getElementById("fFilter_staging_top")) document.getElementById("fFilter_staging_top").checked=this.blnFilterStaging;

			frm.fFilter_alpha.value=this.strFilterAlpha;
			
			//alpha
			if(document.getElementById("filterAlpha"))
			{
				var arrLinks=document.getElementById("filterAlpha").getElementsByTagName("a");
				for(var i=0;i<arrLinks.length;i++)
				{
					if(arrLinks[i].firstChild.firstChild.firstChild.nodeValue.toLowerCase()==frm.fFilter_alpha.value.toString())
					{
						arrLinks[i].className+=" current_page";
						break;
					}
				}
			}
			if(document.getElementById("filterAlphaTop"))
			{
				var arrLinks=document.getElementById("filterAlphaTop").getElementsByTagName("a");
				for(var i=0;i<arrLinks.length;i++)
				{
					if(arrLinks[i].firstChild.firstChild.firstChild.nodeValue.toLowerCase()==frm.fFilter_alpha.value.toString())
					{
						arrLinks[i].className+=" current_page";
						break;
					}
				}
			}
			
			//reselect previously selected show count
			blnSelected=false;
			if(document.getElementById("fShow_count"))
			{
				var eleSelect2=document.getElementById("fShow_count");
				for(var i=0;i<eleSelect2.options.length;i++)
				{
					if(Number(eleSelect2.options[i].value)==CMS_Client_User_Settings.getShowCountCalendarItems())
					{
						eleSelect2.options[i].selected=true;
						blnSelected=true;
						break;
					}
				}
				if(!blnSelected)
				{
					eleSelect2.options[0].selected=true;
					CMS_Client_User_Settings.setShowCountCalendarItems(Number(eleSelect2.options[0].value));
				}
			}
			blnSelected=false;
			if(document.getElementById("fShow_count_top"))
			{
				var eleSelect2=document.getElementById("fShow_count_top");
				for(var i=0;i<eleSelect2.options.length;i++)
				{
					if(Number(eleSelect2.options[i].value)==CMS_Client_User_Settings.getShowCountCalendarItems())
					{
						eleSelect2.options[i].selected=true;
						blnSelected=true;
						break;
					}
				}
				if(!blnSelected)
				{
					eleSelect2.options[0].selected=true;
					CMS_Client_User_Settings.setShowCountCalendarItems(Number(eleSelect2.options[0].value));
				}
			}

			//retrieve previously selected page number
			if(frm.fPage_number)
				frm.fPage_number.value=this.intPageNumber.toString();
			
			//enable or disable "publish files" option
			if(document.getElementById("fAction_index"))
			{
				var eleSelect2=document.getElementById("fAction_index");
				for(var i=0;i<eleSelect2.length;i++)
				{
					if(eleSelect2.options[i].value==2)
					{
						if(CMS_Client_User_Settings.canPublishCalendarItems())
						{
							eleSelect2.options[i].disabled=false;
						}
						else
						{
							if(eleSelect2.options[i].selected)
								eleSelect2.options[0].selected=true;
								
							//disable option
							eleSelect2.options[i].disabled=true;
						}
						break;
					}
				}
			}
			if(document.getElementById("fAction_index_top"))
			{
				var eleSelect2=document.getElementById("fAction_index_top");
				for(var i=0;i<eleSelect2.length;i++)
				{
					if(eleSelect2.options[i].value==2)
					{
						if(CMS_Client_User_Settings.canPublishCalendarItems())
						{
							eleSelect2.options[i].disabled=false;
						}
						else
						{
							if(eleSelect2.options[i].selected)
								eleSelect2.options[0].selected=true;
								
							//disable option
							eleSelect2.options[i].disabled=true;
						}
						break;
					}
				}
			}
			
			this.onCategoryChangeManager(frm,document.getElementById("fCategory_id"));
		}
	},
	
	
	addItem:function(intCategoryId)
	{
		CMS_Main.objRequest.open("GET","get_page_xml.php?page=editCalendarItem&fCategory_id="+intCategoryId.toString(),true);
		CMS_Main.objRequest.onreadystatechange=CMS_Main.updatePage;
		CMS_Main.objRequest.send(null);
		
		return false;
	},
	
	editItem:function(intItemId,blnUseStagingAreaCopy)
	{
		CMS_Main.objRequest.open("GET","get_page_xml.php?page=editCalendarItem&fItem_id="+intItemId.toString()+(blnUseStagingAreaCopy ? "&fUse_staging_area_copy=1" : ""),true);
		CMS_Main.objRequest.onreadystatechange=CMS_Main.updatePage;
		CMS_Main.objRequest.send(null);
		
		return false;
	},
	
	deleteItem:function(intItemId)
	{
		var strTitle=document.getElementById("selectItemName"+intItemId).value.toString();
		
		if(confirm("Are you sure you want to delete "+strTitle+"?"))
		{
			CMS_Main.objRequest.open("GET","get_page_xml.php?page="+CMS_Main.getPage()+"&fAction=deleteCalendarItem&fItem_id="+intItemId,true);
			CMS_Main.objRequest.onreadystatechange=CMS_Main.updatePage;
			CMS_Main.objRequest.send(null);
		}
		
		return false;
	},

	onCategoryOrFilterChange:function(frm)
	{
		this.getItemList(frm);
	},

	onCategoryChangeManager:function(frm,eleSelect)
	{
		this.intCurrentCategoryId=eleSelect.options[eleSelect.selectedIndex].value;
		
		if(document.getElementById("fCategory_id"))
		{
			var eleSelect2=document.getElementById("fCategory_id");
			for(var i=0;i<eleSelect2.options.length;i++)
			{
				if(eleSelect2.options[i].value==this.intCurrentCategoryId)
					eleSelect2.options[i].selected=true;
				else
					eleSelect2.options[i].selected=false;
			}
		}
		if(document.getElementById("fCategory_id_top"))
		{
			var eleSelect2=document.getElementById("fCategory_id_top");
			for(var i=0;i<eleSelect2.options.length;i++)
			{
				if(eleSelect2.options[i].value==this.intCurrentCategoryId)
					eleSelect2.options[i].selected=true;
				else
					eleSelect2.options[i].selected=false;
			}
		}

		this.onCategoryOrFilterChange(frm);
	},
	
	onFilterPublishedClick:function(frm,eleInput)
	{
		this.blnFilterPublished=eleInput.checked;

		if(document.getElementById("fFilter_published"))
			document.getElementById("fFilter_published").checked=eleInput.checked;
		if(document.getElementById("fFilter_published_top"))
			document.getElementById("fFilter_published_top").checked=eleInput.checked;
		
		this.onCategoryOrFilterChange(frm);
	},
	
	onFilterNotPublishedClick:function(frm,eleInput)
	{
		this.blnFilterNotPublished=eleInput.checked;

		if(document.getElementById("fFilter_not_published"))
			document.getElementById("fFilter_not_published").checked=eleInput.checked;
		if(document.getElementById("fFilter_not_published_top"))
			document.getElementById("fFilter_not_published_top").checked=eleInput.checked;
		
		this.onCategoryOrFilterChange(frm);
	},
	
	onFilterArchivedClick:function(frm,eleInput)
	{
		this.blnFilterArchived=eleInput.checked;

		if(document.getElementById("fFilter_archived"))
			document.getElementById("fFilter_archived").checked=eleInput.checked;
		if(document.getElementById("fFilter_archived_top"))
			document.getElementById("fFilter_archived_top").checked=eleInput.checked;
		
		this.onCategoryOrFilterChange(frm);
	},
	
	onFilterStagingClick:function(frm,eleInput)
	{
		this.blnFilterStaging=eleInput.checked;

		if(document.getElementById("fFilter_staging"))
			document.getElementById("fFilter_staging").checked=eleInput.checked;
		if(document.getElementById("fFilter_staging_top"))
			document.getElementById("fFilter_staging_top").checked=eleInput.checked;
		
		this.onCategoryOrFilterChange(frm);
	},
	
	onAlphaClick:function(frm,eleA)
	{
		if(frm && eleA)
		{
			frm.fFilter_alpha.value=eleA.firstChild.firstChild.firstChild.nodeValue.toLowerCase(); //retrieve selected value
			this.strFilterAlpha=frm.fFilter_alpha.value.toString();
			
			//reset classes
			if(document.getElementById("filterAlpha"))
			{
				var arrLinks=document.getElementById("filterAlpha").getElementsByTagName("a");
				for(var i=0;i<arrLinks.length;i++)
				{
					if(arrLinks[i].className.indexOf("current_page")>-1)
						arrLinks[i].className=arrLinks[i].className.replace("current_page","");
					if(arrLinks[i].firstChild.firstChild.firstChild.nodeValue.toLowerCase()==frm.fFilter_alpha.value)
						arrLinks[i].className+=" current_page";
				}
			}
			if(document.getElementById("filterAlphaTop"))
			{
				var arrLinks=document.getElementById("filterAlphaTop").getElementsByTagName("a");
				for(var i=0;i<arrLinks.length;i++)
				{
					if(arrLinks[i].className.indexOf("current_page")>-1)
						arrLinks[i].className=arrLinks[i].className.replace("current_page","");
					if(arrLinks[i].firstChild.firstChild.firstChild.nodeValue.toLowerCase()==frm.fFilter_alpha.value)
						arrLinks[i].className+=" current_page";
				}
			}
			
			//update filter
			CMS_Calendar_Item.onCategoryOrFilterChange(frm);
		}
		return false; //cancel link
	},
	
	onShowCountChange:function(frm,eleSelect)
	{
		if(frm && frm.fShow_count)
		{
			var intPages=1;

			if(document.getElementById("fShow_count"))
			{
				var eleSelect2=document.getElementById("fShow_count");
				for(var i=0;i<eleSelect2.options.length;i++)
				{
					if(Number(eleSelect2.options[i].value)==Number(eleSelect.options[eleSelect.selectedIndex].value))
						eleSelect2.options[i].selected=true;
				}
			}
			if(document.getElementById("fShow_count_top"))
			{
				var eleSelect2=document.getElementById("fShow_count_top");
				for(var i=0;i<eleSelect2.options.length;i++)
				{
					if(Number(eleSelect2.options[i].value)==Number(eleSelect.options[eleSelect.selectedIndex].value))
						eleSelect2.options[i].selected=true;
				}
			}

			CMS_Client_User_Settings.setShowCountCalendarItems(Number(frm.fShow_count.value)); //store selected value
			
			//calculate number of pages
			if(Number(frm.fShow_count.value)>0)
				intPages=Math.ceil(Number(frm.fItem_count.value)/Number(frm.fShow_count.value));
			if(intPages==0)
				intPages++;
			
			//check if current page number will exist for new show count
			if(Number(frm.fPage_number.value)>intPages)
				frm.fPage_number.value="1"; //reset page number
			
			this.getItemList(frm);
		}
	},
	
	onPageClick:function(frm,eleNumber)
	{
		if(frm && eleNumber)
		{
			frm.fPage_number.value=eleNumber.firstChild.firstChild.firstChild.nodeValue; //retrieve selected value
			this.getItemList(frm);
		}
		return false;
	},
	
	updatePagination:function(frm)
	{
		if(frm && frm.fShow_count)
		{
			var intPages=1;
			
			//calculate number of pages
			if(Number(frm.fShow_count.value)>0)
				intPages=Math.ceil(Number(frm.fItem_count.value)/Number(frm.fShow_count.value));
			if(intPages==0)
				intPages++;
			
			//rebuild page links
			if(document.getElementById("filterPage"))
			{
				document.getElementById("filterPage").innerHTML="";
				for(var i=0;i<intPages;i++)
					document.getElementById("filterPage").innerHTML+="<li><a href=\"#\" onclick=\"return CMS_Calendar_Item.onPageClick(document.getElementById('frmManageItems'),this);\"><span><span>"+(i+1).toString()+"</span></span></a></li>";
			}
			if(document.getElementById("filterPageTop"))
			{
				document.getElementById("filterPageTop").innerHTML="";
				for(var i=0;i<intPages;i++)
					document.getElementById("filterPageTop").innerHTML+="<li><a href=\"#\" onclick=\"return CMS_Calendar_Item.onPageClick(document.getElementById('frmManageItems'),this);\"><span><span>"+(i+1).toString()+"</span></span></a></li>";
			}
			
			//select page link
			var blnSelected=false;
			if (document.getElementById("filterPage")) 
			{
				var arrLinks=document.getElementById("filterPage").getElementsByTagName("a");
				for(var i=0;i<arrLinks.length;i++)
				{
					if(arrLinks[i].firstChild.firstChild.firstChild.nodeValue==frm.fPage_number.value.toString())
					{
						//change class
						arrLinks[i].className+=" current_page";
						blnSelected=true;
						break;
					}
				}
				if(!blnSelected)
				{
					arrLinks[0].className+=" current_page";
					frm.fPage_number.value=arrLinks[0].firstChild.firstChild.firstChild.nodeValue;
				}
			}
			blnSelected=false;
			if (document.getElementById("filterPageTop")) 
			{
				var arrLinks=document.getElementById("filterPageTop").getElementsByTagName("a");
				for(var i=0;i<arrLinks.length;i++)
				{
					if(arrLinks[i].firstChild.firstChild.firstChild.nodeValue==frm.fPage_number.value.toString())
					{
						//change class
						arrLinks[i].className+=" current_page";
						blnSelected=true;
						break;
					}
				}
				if(!blnSelected)
				{
					arrLinks[0].className+=" current_page";
					frm.fPage_number.value=arrLinks[0].firstChild.firstChild.firstChild.nodeValue;
				}
			}

			//store selected value
			this.intPageNumber=Number(frm.fPage_number.value);
			
			//calculate item count
			var intCountStart=(Number(frm.fPage_number.value)-1)*Number(frm.fShow_count.value);
			var intCountEnd=(Number(frm.fShow_count.value)==0 ? Number(frm.fItem_count.value) : Math.min(Number(frm.fShow_count.value)+intCountStart,Number(frm.fItem_count.value)));
			
			//update item count
			if(document.getElementById("itemCountStart"))
				document.getElementById("itemCountStart").innerHTML=(Math.min(intCountStart+1,Number(frm.fItem_count.value))).toString();
			if(document.getElementById("itemCountEnd"))
				document.getElementById("itemCountEnd").innerHTML=intCountEnd.toString();
			if(document.getElementById("itemCount"))
				document.getElementById("itemCount").innerHTML=frm.fItem_count.value.toString();

			if(document.getElementById("itemCountStartTop"))
				document.getElementById("itemCountStartTop").innerHTML=(Math.min(intCountStart+1,Number(frm.fItem_count.value))).toString();
			if(document.getElementById("itemCountEndTop"))
				document.getElementById("itemCountEndTop").innerHTML=intCountEnd.toString();
			if(document.getElementById("itemCountTop"))
				document.getElementById("itemCountTop").innerHTML=frm.fItem_count.value.toString();
		}
	},
	
	getItemList:function(frm)
	{
		var strHtml="";
		
		//clear select all
		if(document.getElementById("selectAll"))
			document.getElementById("selectAll").checked=false;
		
		//clear item list
		while(document.getElementById("itemListContainer").firstChild)
			document.getElementById("itemListContainer").removeChild(document.getElementById("itemListContainer").firstChild);
		
		//add loading message
		var eleLoading=document.createElement("tr");
		eleLoading.appendChild(document.createElement("td"));
		eleLoading.childNodes[0].colSpan=5;
		eleLoading.childNodes[0].appendChild(document.createTextNode(CMS_Main.getLoadingMessage()));
		document.getElementById("itemListContainer").appendChild(eleLoading);
		
		//get item list
		this.objItemListRequest=CMS_Main.createRequest();
		this.objItemListRequest.open("GET","get_element_xml.php?function=getCalendarItemListJson&fCategory_id="+CMS_Calendar_Item.intCurrentCategoryId.toString()+"&fFilter_published="+(CMS_Calendar_Item.blnFilterPublished ? "1" : "0")+"&fFilter_not_published="+(CMS_Calendar_Item.blnFilterNotPublished ? "1" : "0")+"&fFilter_archived="+(CMS_Calendar_Item.blnFilterArchived ? "1" : "0")+"&fFilter_staging="+(CMS_Calendar_Item.blnFilterStaging ? "1" : "0")+"&fFilter_alpha="+encodeURIComponent(CMS_Calendar_Item.strFilterAlpha)+"&fShow_count="+frm.fShow_count.value.toString()+"&fPage_number="+frm.fPage_number.value.toString(),true);
		this.objItemListRequest.onreadystatechange=function(){
			if(CMS_Calendar_Item.objItemListRequest.readyState==4)
			{
				if(CMS_Calendar_Item.objItemListRequest.status==200)
				{
					//clear loading message
					while(document.getElementById("itemListContainer").firstChild)
						document.getElementById("itemListContainer").removeChild(document.getElementById("itemListContainer").firstChild);
					
					var objItemData=eval("("+CMS_Calendar_Item.objItemListRequest.responseText+")");
					document.getElementById("fItem_count").value=objItemData.intItemCount.toString();
					
					//add rows
					for(i in objItemData.arrItems)
					{
						var eleRow=CMS_Calendar_Item.createRow(objItemData.arrItems[i]);
						
						if(i%2==0)
							eleRow.className="first";
						else
							eleRow.className="second";

						document.getElementById("itemListContainer").appendChild(eleRow);
					}
					
					if(objItemData.arrItems.length==0)
						document.getElementById("itemListContainer").appendChild(CMS_Calendar_Item.createEmptyRow());
					
					CMS_Calendar_Item.updatePagination(document.getElementById("frmManageItems"));
				}
			}
		};
		this.objItemListRequest.send(null);
		
		return false;
	},
	
	createRow:function(objItemData)
	{
		var eleRow=document.createElement("tr");
		
		var eleTd1=document.createElement("td");
		eleTd1.appendChild(document.createTextNode(objItemData.strDateStart));
		eleRow.appendChild(eleTd1);
		
		var eleTd2=document.createElement("td");
		eleTd2.appendChild(document.createTextNode(objItemData.strName));
		eleRow.appendChild(eleTd2);
		
		var eleTd3=document.createElement("td");
		eleTd3.appendChild(document.createTextNode(objItemData.strCategoryName));
		eleRow.appendChild(eleTd3);
		
		var eleTd4=document.createElement("td");
		eleTd4.appendChild(document.createTextNode(objItemData.strStatus));
		eleRow.appendChild(eleTd4);
		
		var eleTd5=document.createElement("td");
		eleTd5.innerHTML="<a href=\"#\" onclick=\"return CMS_Calendar_Item.editItem("+objItemData.intItemId.toString()+");\"><img src=\"images/edit.png\" width=\"16\" height=\"16\" alt=\"Edit\"></a>"+(objItemData.blnStagingAreaCopyExists ? " <a href=\"#\" onclick=\"return CMS_Calendar_Item.editItem("+objItemData.intItemId.toString()+",true);\"><img src=\"images/editstage.png\" width=\"16\" height=\"16\" alt=\"Edit copy\" title=\"Edit copy\"></a>" : "");
		
		eleTd5.style.width="96px";
		eleTd5.innerHTML=" \
		<div class=\"actions\"> \
			<ul> \
				<li><a class=\"action5\" href=\"#\" onclick=\"return CMS_Calendar_Item.editItem("+objItemData.intItemId.toString()+");\" title=\"Edit\">Edit</a></li> \
				"+(objItemData.blnStagingAreaCopyExists ? "<li><a class=\"action6\" href=\"#\" onclick=\"return CMS_Calendar_Item.editItem("+objItemData.intItemId.toString()+",true);\" title=\"Edit copy\">Edit copy</a></li>" : "")+" \
				<li><a class=\"action4\" href=\"#\" onclick=\"return CMS_Calendar_Item.deleteItem("+objItemData.intItemId.toString()+");\" title=\"Delete\">Delete</a></li> \
			</ul> \
			<div style=\"float:right;\"> \
				<input class=\"radio\" name=\"selectItem\" id=\"selectItem"+objItemData.intItemId.toString()+"\" type=\"checkbox\" value=\""+objItemData.intItemId.toString()+"\" /> \
				<input name=\"selectItemName\" id=\"selectItemName"+objItemData.intItemId.toString()+"\" type=\"hidden\" value=\""+objItemData.strName+"\" /> \
			</div> \
		</div>";
		eleRow.appendChild(eleTd5);
		
		return eleRow;
	},
	
	createEmptyRow:function()
	{
		var eleRow=document.createElement("tr");
		
		var eleTd1=document.createElement("td");
		eleTd1.colSpan=5;
		eleTd1.appendChild(document.createTextNode("No items to display"));
		eleRow.appendChild(eleTd1);
		
		return eleRow;
	},
	
	onActionChange:function(frm,eleSelect)
	{
	},
	
	onActionClick:function(frm,eleSelect)
	{
		if(frm && eleSelect)
		{
			switch(Number(eleSelect.value))
			{
				case(1): //delete
					this.deleteItems(frm);
					break;
				case(2): //publish
					this.publishItems(frm);
					break;
				case(3): //archive
					this.archiveItems(frm);
					break;
				default:
			}
		}
		return false;
	},
	
	deleteItems:function(frm)
	{
		var arrItemIds=new Array();
		var arrItemNames=new Array();
		
		for(var i=0;i<frm.length;i++)
		{
			if(frm.elements[i].name && frm.elements[i].name.indexOf("selectItem")==0 && frm.elements[i].type=="checkbox" && frm.elements[i].checked)
			{
				arrItemIds[arrItemIds.length]=frm.elements[i].value;
				arrItemNames[arrItemNames.length]=frm.elements[i+1].value;
			}
		}
		if(arrItemIds.length==0)
		{
			alert("You do not have any items selected.");
		}
		else if(confirm("Are you sure you want to delete "+(arrItemIds.length==1 ? arrItemNames[0]+"?" : "the following items?\n\n\t"+arrItemNames.join("\n\t")+"\n ")))
		{
			CMS_Main.objRequest.open("GET","get_page_xml.php?page="+CMS_Main.getPage()+"&fAction=deleteCalendarItems&fItem_id[]="+arrItemIds.join("&fItem_id[]="),true);
			CMS_Main.objRequest.onreadystatechange=CMS_Main.updatePage;
			CMS_Main.objRequest.send(null);
		}
		
		return false;
	},
	
	publishItems:function(frm)
	{
		var arrItemIds=new Array();
		var arrItemNames=new Array();
		
		for(var i=0;i<frm.length;i++)
		{
			if(frm.elements[i].name && frm.elements[i].name.indexOf("selectItem")==0 && frm.elements[i].type=="checkbox" && frm.elements[i].checked)
			{
				arrItemIds[arrItemIds.length]=frm.elements[i].value;
				arrItemNames[arrItemNames.length]=frm.elements[i+1].value;
			}
		}
		if(arrItemIds.length==0)
		{
			alert("You do not have any items selected.");
		}
		else if(confirm("Are you sure you want to publish "+(arrItemIds.length==1 ? arrItemNames[0]+"?" : "the following items?\n\n\t"+arrItemNames.join("\n\t")+"\n ")))
		{
			CMS_Main.objRequest.open("GET","get_page_xml.php?page="+CMS_Main.getPage()+"&fAction=publishCalendarItems&fItem_id[]="+arrItemIds.join("&fItem_id[]="),true);
			CMS_Main.objRequest.onreadystatechange=CMS_Main.updatePage;
			CMS_Main.objRequest.send(null);
		}
		
		return false;
	},
	
	archiveItems:function(frm)
	{
		var arrItemIds=new Array();
		var arrItemNames=new Array();
		
		for(var i=0;i<frm.length;i++)
		{
			if(frm.elements[i].name && frm.elements[i].name.indexOf("selectItem")==0 && frm.elements[i].type=="checkbox" && frm.elements[i].checked)
			{
				arrItemIds[arrItemIds.length]=frm.elements[i].value;
				arrItemNames[arrItemNames.length]=frm.elements[i+1].value;
			}
		}
		if(arrItemIds.length==0)
		{
			alert("You do not have any items selected.");
		}
		else if(confirm("Are you sure you want to archive "+(arrItemIds.length==1 ? arrItemNames[0]+"?" : "the following items?\n\n\t"+arrItemNames.join("\n\t")+"\n ")))
		{
			CMS_Main.objRequest.open("GET","get_page_xml.php?page="+CMS_Main.getPage()+"&fAction=archiveCalendarItems&fItem_id[]="+arrItemIds.join("&fItem_id[]="),true);
			CMS_Main.objRequest.onreadystatechange=CMS_Main.updatePage;
			CMS_Main.objRequest.send(null);
		}
		
		return false;
	},
	
	selectAllClick:function(frm)
	{
		for(var i=0;i<frm.length;i++)
			if(frm.elements[i].name && frm.elements[i].name.indexOf("selectItem")==0)
				frm.elements[i].checked=true;
		return false;
	},
	
	deselectAllClick:function(frm)
	{
		for(var i=0;i<frm.length;i++)
			if(frm.elements[i].name && frm.elements[i].name.indexOf("selectItem")==0)
				frm.elements[i].checked=false;
		return false;
	},
	
	//item edit methods
	
	arrFileSelectRequest:new Array(),
	eleFileAttach:null,
	
	editItemInitialize:function(frm)
	{
		if(frm)
		{
			//move the uploader in the DOM (so IE will correctly observe the the z-index property)
			if(document.getElementById("eleUploader"))
				document.getElementsByTagName("body")[0].insertBefore(document.getElementById("eleUploader"),document.getElementsByTagName("body")[0].firstChild);
			
			//instantiate uploader
			YAHOO.widget.Uploader.SWFURL=CMS_File.getUploaderSWFURL();
			document.getElementById("eleUploader").innerHTML=CMS_File.strUploaderInitialContent;
			this.objUploader=new YAHOO.widget.Uploader("eleUploader");

			this.hideUploader();

			//set uploader event handlers
			this.objUploader.addListener("contentReady",this.onContentReady);
			this.objUploader.addListener('fileSelect',this.onFileSelect);
			this.objUploader.addListener('uploadStart',this.onUploadStart);
			this.objUploader.addListener('uploadProgress',this.onUploadProgress);
			this.objUploader.addListener('uploadCancel',this.onUploadCancel);
			this.objUploader.addListener('uploadComplete',this.onUploadComplete);
			this.objUploader.addListener('uploadCompleteData',this.onUploadCompleteData);
			this.objUploader.addListener('uploadError',this.onUploadError);
			//set more uploader event handlers
			this.objUploader.addListener("rollOver",this.onRollOver);
			this.objUploader.addListener("rollOut",this.onRollOut);
			this.objUploader.addListener("click",this.onClick);
			//reset file request variables
			this.arrValidFileRequest=new Array();
			this.intSizeUploadingTotal=0;
			this.arrUsedFileIds=new Array();
			this.intUploadCount=0;
			
			//start synchronizing uploader synchronized with upload files button
			window.onscroll=function()
			{
				CMS_Calendar_Item.syncUploader("uploadFiles");
			};
			window.onresize=function()
			{
				CMS_Calendar_Item.syncUploader("uploadFiles");
			};
			
			CMS_File.preloadProgressImages();
			
			//initialize Date/Time select
			if(document.getElementById("fDate_start"))
			{
				DTS.insert("fDate_start",DTS.intTypeDateOptional);
			}
			if(document.getElementById("fDate_end"))
			{
				DTS.insert("fDate_end",DTS.intTypeDateOptional);
				
				//show or hide end date
				if(frm.fDate_end_enabled.checked)
					document.getElementById("dateEnd").style.display="inline";
				else
					document.getElementById("dateEnd").style.display="none";
			}
			
			//initialize text editor
			CMS_Main.textEditorInit("fDescription");
			
			CMS_Calendar_Item.onPublishedClick(frm.fPublished);

			//remove and store the file attachment form
			if(document.getElementById("fileAttach"))
			{
				this.eleFileAttach=document.getElementById("fileAttach").parentNode.removeChild(document.getElementById("fileAttach"));
				this.eleFileAttach.style.display="block";
			}
			
			if(frm.fName)
			{
				frm.fName.focus();
				frm.fName.select();
			}
		}
		return false;
	},
	
	onPublishedClick:function(eleInput)
	{
		if(document.getElementById("unpublishOptions"))
		{
			if(eleInput.checked)
			{
				document.getElementById("unpublishOptions").style.display="none";
			}
			else
			{
				try
				{
					document.getElementById("unpublishOptions").style.display="table-row";
				}
				catch(e)
				{
					document.getElementById("unpublishOptions").style.display="block";
				}
			}
		}
	},
	
	onDateEnabledClick:function(eleInput,strId)
	{
		//DTS.disabled(strId,!eleInput.checked);
		if(document.getElementById(strId))
			if(eleInput.checked)
			{
				//get start date
				var dtmEnd=DTS.getDateObject("fDate_start");
				//set end date to start date + 1 day
				dtmEnd.setDate(dtmEnd.getDate()+1);
				//update end date
				document.getElementById("fDate_end").value=Math.round(dtmEnd.getTime()/1000);
				DTS.update("fDate_end");
				
				document.getElementById(strId).style.display="inline";
			}
			else
			{
				document.getElementById(strId).style.display="none";
			}
		
		return true;
	},
	
	urlTargetIdChange:function(eleSelect)
	{
		if(eleSelect)
		{
			if(Number(eleSelect.value)==1)
			{
				if(document.getElementById("urlOptionsOther"))
					document.getElementById("urlOptionsOther").style.display="inline";
			}
			else
			{
				if(document.getElementById("urlOptionsOther"))
					document.getElementById("urlOptionsOther").style.display="none";
			}
		}
	},
	
	openFileAttach:function()
	{
		//show dialogue
		CMS_Main.addOverlay(this.eleFileAttach);
		
		this.onFileAttachTypeClick();
	},
	
	syncUploader:function(strId)
	{
		if(document.getElementById(strId))
		{
			try
			{
				document.getElementById("eleUploader").style.left=$("#"+strId).offset().left+"px";
				document.getElementById("eleUploader").style.top=$("#"+strId).offset().top+"px";
			}
			catch(e)
			{
			}
		}
	},
	
	onFileAttachTypeClick:function()
	{
		frm=document.getElementById("frmFileAttach");
		
		if(frm.fFile_attach_type0.checked)
		{
			document.getElementById("fileAttach0").style.height="auto";
			document.getElementById("fileAttach1").style.height="0px";
			
			this.hideUploader();
			
			if(frm.fFile_category_id)
				this.onCategoryChange(frm.fFile_category_id);
		}
		else if(frm.fFile_attach_type1.checked)
		{
			document.getElementById("fileAttach1").style.height="auto";
			document.getElementById("fileAttach0").style.height="0px";
			
			//resize uploader to same size as uploadFiles
			document.getElementById("eleUploader").style.width=document.getElementById("uploadFiles").offsetWidth.toString()+"px";
			document.getElementById("eleUploader").style.height=document.getElementById("uploadFiles").offsetHeight.toString()+"px";
			//display uploader
			document.getElementById("eleUploader").style.zIndex=6;
			//move uploader to same position as uploadFiles
			this.syncUploader("uploadFiles");
		}
		else
		{
			document.getElementById("fileAttach0").style.height="0px";
			document.getElementById("fileAttach1").style.height="0px";
		}
	},
	
	onCategoryChange:function(eleSelectCategory)
	{
		var objCategorySelectRequest=CMS_Main.createRequest();
		objCategorySelectRequest.open("GET",CMS_Main.getRootDirectory()+"/get_element_xml.php?function=getFileListJson&fCategory_id="+eleSelectCategory.value.toString(),true);
		objCategorySelectRequest.onreadystatechange=function()
		{
			if(objCategorySelectRequest.readyState==4)
			{
				if(objCategorySelectRequest.status==200)
				{
					objListData=eval("("+objCategorySelectRequest.responseText+")");
					
					eleSelectFiles=eleSelectCategory.form.fAvailable_file_ids;
					
					//clear file list
					for(i in eleSelectFiles.options)
					{
						eleSelectFiles.remove(i);
					}
					
					//populate file list
					for(i in objListData.arrFiles)
					{
						var eleOpt=document.createElement("option");
						eleOpt.text=objListData.arrFiles[i].strTitle;
						eleOpt.value=objListData.arrFiles[i].intFileId.toString();
						eleOpt.title=objListData.arrFiles[i].strName;
						eleSelectFiles.options[eleSelectFiles.length]=eleOpt;
					}
				}
			}
		};
		objCategorySelectRequest.send(null);
	},
	
	addSelectedFiles:function(eleSelect)
	{
		var blnFileSelected=false;
		
		for(var i=0;i<eleSelect.options.length;i++)
		{
			if(eleSelect.options[i].selected)
			{
				blnFileSelected=true;
				
				var j=this.arrFileSelectRequest.length+1;
				this.arrFileSelectRequest[j]=CMS_Main.createRequest();
				this.arrFileSelectRequest[j].open("GET",CMS_Main.getRootDirectory()+"/get_element_xml.php?function=getFileDataJson&fFile_id="+eleSelect.options[i].value.toString(),true);
				this.arrFileSelectRequest[j].onreadystatechange=this.addSelectedFilesResponse;
				this.arrFileSelectRequest[j].send(null);
			}
		}

		if(blnFileSelected)
			CMS_Main.removeOverlay();
	},
	
	addSelectedFilesResponse:function()
	{
		for(i in CMS_Calendar_Item.arrFileSelectRequest)
		{
			if(CMS_Calendar_Item.arrFileSelectRequest[i] && CMS_Calendar_Item.arrFileSelectRequest[i].readyState==4)
			{
				if(CMS_Calendar_Item.arrFileSelectRequest[i].status==200)
				{
					objFileData=eval("("+CMS_Calendar_Item.arrFileSelectRequest[i].responseText+")");
					
					//check if file is already attached
					if(!document.getElementById("fFile_id"+objFileData.intFileId.toString()))
					{
						var eleRow=document.createElement("tr");
						eleRow.id="fileRow"+objFileData.intFileId;
						
						var eleTd1=document.createElement("td");
						var eleInput1=CMS_Main.createNamedElement("input","fFile_id");
						eleInput1.id="fFile_id"+objFileData.intFileId.toString();
						eleInput1.type="hidden";
						eleInput1.value=objFileData.intFileId.toString();
						eleTd1.appendChild(eleInput1);
						eleTd1.appendChild(document.createTextNode(objFileData.strTitle));
						eleRow.appendChild(eleTd1);
						
						var eleTd2=document.createElement("td");
						eleTd2.appendChild(document.createTextNode(objFileData.strStatus));
						eleRow.appendChild(eleTd2);
						
						var eleTd3=document.createElement("td");
						eleTd3.innerHTML="<div class=\"actions\"><ul><li><a class=\"action4\" href=\"#\" onclick=\"return CMS_Calendar_Item.removeFile("+objFileData.intFileId.toString()+");\" title=\"Remove\">Remove</a></li></ul></div>";
						eleRow.appendChild(eleTd3);
						
						//add row to table
						document.getElementById("fileListContainer").insertBefore(eleRow,document.getElementById("fileListContainer").firstChild);
					}
					
					//remove from array
					CMS_Calendar_Item.arrFileSelectRequest.splice(i,1);
				}
			}
		}
	},
	
	closeFileAttach:function()
	{
		this.hideUploader();

		CMS_Main.removeOverlay();
	},
	
	hideUploader:function()
	{
		//this seems to be the only method of hiding the uploader that doesn't cause the browser to unload the Flash object (and lose any selected files)
		document.getElementById("eleUploader").style.zIndex=-1;
	},
	
	removeFile:function(intFileId)
	{
		if(document.getElementById("fileRow"+intFileId.toString()))
			document.getElementById("fileRow"+intFileId.toString()).parentNode.removeChild(document.getElementById("fileRow"+intFileId.toString()));
		
		return false;
	},
	
	editItemSubmit:function(frm)
	{
		var blnReturnValue=true;
		
		CMS_Main.textEditorUpdate("fDescription");
	
		if(frm.fName.value.length==0)
		{
			alert("Please enter a name");
			frm.fName.focus();
			blnReturnValue=false;
		}
		if(!frm.fCategory_id.value>0)
		{
			alert("Please select a category");
			frm.fCategory_id.focus();
			blnReturnValue=false;
		}
		else if(frm.fDate_end_enabled && frm.fDate_end_enabled.checked && (Number(frm.fDate_start.value) > Number(frm.fDate_end.value)))
		{
			alert("Please make sure the end date is not earlier than the start date.");
			blnReturnValue=false;
		}
		else if(frm.fUrl_target_id && Number(frm.fUrl_target_id.value)==1 && frm.fUrl_target_other.value=="")
		{
			alert("Please enter a target value");
			frm.fUrl_target_other.focus();
			blnReturnValue=false;
		}
		
		if(blnReturnValue)
		{
			document.getElementById("fSubmit").disabled=true;
			
			//check if there are files to upload
			if(CMS_Calendar_Item.intUploadCount>0)
			{
				//upload
				CMS_Calendar_Item.objUploader.uploadAll(CMS_Main.getRootDirectory()+'/file_upload.php',"POST",{sessionId:CMS_Cookie.get(CMS_Main.getSessionName()), fEnd_action:2, fPublished:1, fNew:0},"fFile");
			}
			else
			{
				//submit form
				this.editItemSubmitFinal(frm);
			}
		}
		
		return false;
	},
	
	editItemSubmitFinal:function(frm)
	{
		this.editItemClose();
			
		CMS_Main.objRequest.open("POST","get_page_xml.php",true);
		CMS_Main.objRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		CMS_Main.objRequest.onreadystatechange=CMS_Main.updatePage;
		CMS_Main.objRequest.send(CMS_Main.formEncode(frm)+"&page="+CMS_Main.getPage());
	},
	
	editItemCancel:function()
	{
		this.editItemClose();
		
		CMS_Main.objRequest.open("GET","get_page_xml.php?page="+CMS_Main.getPage(),true);
		CMS_Main.objRequest.onreadystatechange=CMS_Main.updatePage;
		CMS_Main.objRequest.send(null);
		
		return false;
	},
	
	editItemClose:function()
	{
		//stop synchronizing uploader synchronized with upload files button
		window.onscroll=null;
		window.onresize=null;
		
		//remove the uploader
		if(document.getElementById("eleUploader"))
		{
			document.getElementById("eleUploader").innerHTML=""; //unload the Flash object to prevent error in IE when removing element from the DOM
			document.getElementById("eleUploader").parentNode.removeChild(document.getElementById("eleUploader"));
		}
	},
	
	editItemFormRevert:function(frm)
	{
		if(confirm("Are you sure you want to revert this item back to the original version?"))
		{
			this.editItemClose();
			
			CMS_Main.objRequest.open("GET","get_page_xml.php?page="+CMS_Main.getPage()+"&fAction=revertCalendarItem&fItem_id="+frm.fItem_id.value.toString(),true);
			CMS_Main.objRequest.onreadystatechange=CMS_Main.updatePage;
			CMS_Main.objRequest.send(null);
		}
		
		return false;
	},
	
	//file uploader methods
	
	objUploader:null,
	objFileList:null,
	arrUsedFileIds:new Array(),
	arrValidFileRequest:new Array(),
	intSizeUploadingTotal:0,
	intUploadCount:0,
	
	onContentReady:function()
	{
		//set file uploader properties
		CMS_Calendar_Item.objUploader.setAllowMultipleFiles(true);
		CMS_Calendar_Item.objUploader.setSimUploadLimit(1); //set simultaneous upload limit
		CMS_Calendar_Item.objUploader.setFileFilters(CMS_Client.getAllowedFileTypes());
	},
	
	uploadFiles:function()
	{
		//this.objUploader.browse(true, CMS_Client.getAllowedFileTypes());
		//this.closeFileAttach();
		
		return false;
	},
	
	onFileSelect:function(event)
	{
		CMS_Calendar_Item.closeFileAttach();
		
		CMS_Calendar_Item.objFileList=event.fileList;
		
		//add files to table
		for(var i in event.fileList)
		{
			if(!CMS_Calendar_Item.isUsed(event.fileList[i].id))
			{
				CMS_Calendar_Item.setUsed(event.fileList[i].id);
				
				var strTitle=event.fileList[i].name.substr(0,event.fileList[i].name.lastIndexOf("."));

				//create row
				var eleRow=document.createElement("tr");
				eleRow.id="fileRow"+event.fileList[i].id;
				
				var eleTd1=document.createElement("td");
				eleTd1.appendChild(document.createTextNode(strTitle));
				eleRow.appendChild(eleTd1);
				
				var eleTd2=document.createElement("td");
				eleTd2.id="fileStatus"+event.fileList[i].id;
				eleTd2.appendChild(document.createTextNode(" "));
				eleRow.appendChild(eleTd2);
				
				var eleTd3=document.createElement("td");
				eleTd3.id="fileAction"+event.fileList[i].id;
				eleTd3.innerHTML="<div class=\"actions\"><ul><li><a class=\"action4\" href=\"#\" onclick=\"return CMS_Calendar_Item.cancel('"+event.fileList[i].id+"');\" title=\"Remove\">Remove</a></li></ul></div>";
				eleRow.appendChild(eleTd3);
				
				//add row to table
				document.getElementById("fileListContainer").insertBefore(eleRow,document.getElementById("fileListContainer").firstChild);
	
				//check for valid file
				var j=CMS_Calendar_Item.arrValidFileRequest.length+1;
				CMS_Calendar_Item.arrValidFileRequest[j]=CMS_Main.createRequest();
				CMS_Calendar_Item.arrValidFileRequest[j].open("GET","get_element_xml.php?function=isValidFileXml&fFile_id=0&fileId="+event.fileList[i].id+"&fName="+encodeURIComponent(event.fileList[i].name)+"&fSize="+event.fileList[i].size+"&sizeUploadingTotal="+CMS_Calendar_Item.intSizeUploadingTotal+"&fTitle=",true);
				CMS_Calendar_Item.arrValidFileRequest[j].onreadystatechange=CMS_Calendar_Item.uploadFileResponse;
				CMS_Calendar_Item.arrValidFileRequest[j].send(null);
			}
		}
	},
	
	uploadFileResponse:function()
	{
		//loop through all open requests
		for(i in CMS_Calendar_Item.arrValidFileRequest)
		{
			if(CMS_Calendar_Item.arrValidFileRequest[i] && CMS_Calendar_Item.arrValidFileRequest[i].readyState==4)
			{
				if(CMS_Calendar_Item.arrValidFileRequest[i].status==200)
				{
					var eleDoc=CMS_Calendar_Item.arrValidFileRequest[i].responseXML.documentElement;
					
					if(eleDoc.getElementsByTagName("validFile"))
					{
						var strId=eleDoc.getElementsByTagName("fileId")[0].firstChild.nodeValue;
						
						//add to size uploading total
						CMS_Calendar_Item.intSizeUploadingTotal+=CMS_Calendar_Item.objFileList[strId].size;
						CMS_Calendar_Item.intUploadCount++;
						
						if(eleDoc.getElementsByTagName("validFile")[0].firstChild.nodeValue==0)
						{
							//cancel
							//CMS_Calendar_Item.objUploader.removeFile(strId);
							CMS_Calendar_Item.cancel(strId,(eleDoc.getElementsByTagName("message") ? eleDoc.getElementsByTagName("message")[0].firstChild.nodeValue : ""));
						}
					}
					//remove from array
					CMS_Calendar_Item.arrValidFileRequest.splice(i,1);
				}
			}
		}
	},
	
	//mark file id as used
	setUsed:function(id)
	{
		//mark id as used
		this.arrUsedFileIds.push(id);
	},
	isUsed:function(id)
	{
		blnReturnValue=false;
		
		for(var i=0;i<this.arrUsedFileIds.length;i++)
		{
			if(this.arrUsedFileIds[i]==id)
			{
				blnReturnValue=true;
				break;
			}
		}
		
		return blnReturnValue;
	},
	
	cancel:function(id,strStatus)
	{
		//cancel upload
		this.objUploader.cancel(id);
		this.objUploader.removeFile(id);
		
		//enable submit button again
		if(document.getElementById("fSubmit"))
			document.getElementById("fSubmit").disabled=false;

		//remove from size uploading total
		CMS_Calendar_Item.intSizeUploadingTotal-=CMS_Calendar_Item.objFileList[id].size;
		CMS_Calendar_Item.intUploadCount--;
		
		if(!strStatus)
			strStatus="Cancelled.";
		
		document.getElementById("fileStatus"+id).innerHTML=strStatus;
		document.getElementById("fileAction"+id).innerHTML="<div class=\"actions\"><ul><li><a class=\"action4\" href=\"#\" onclick=\"return CMS_Calendar_Item.removeFile('"+id+"');\" title=\"Remove\">Remove</a></li></ul></div>";

		return false;
	},
	
	onUploadStart:function(event)
	{
		//CMS_Calendar_Item.updateProgress(event.id,0);
		document.getElementById("fileStatus"+event.id).innerHTML="Waiting...";
	},
	onUploadProgress:function(event)
	{
		//check if progress bar exists
		if(!document.getElementById("progressBar"+event.id))
		{
			//create progress bar
			eleContainer=document.createElement("div");
			eleContainer.className="progressBar";
			eleContainer.id="progressBar"+event.id;
			
			eleImg=document.createElement("img");
			eleImg.src=CMS_Main.getRootDirectory()+"/css/tng/progressbar/box.gif";
			eleImg.id="progressBarImage"+event.id;
			eleImg.width="150";
			eleImg.height="12";
			eleImg.alt="";
			eleImg.title="";
			
			eleSpan=document.createElement("span");
			eleSpan.className="progressBarPercent";
			eleSpan.id="progressBarPercent"+event.id;
			eleSpan.appendChild(document.createTextNode("0%"));
			
			eleContainer.appendChild(eleImg);
			document.getElementById("fileStatus"+event.id).innerHTML="";
			document.getElementById("fileStatus"+event.id).appendChild(eleContainer);
			document.getElementById("fileStatus"+event.id).appendChild(document.createTextNode(" "));
			document.getElementById("fileStatus"+event.id).appendChild(eleSpan);
		}
		
		CMS_Calendar_Item.updateProgress(event.id,(event.bytesLoaded/event.bytesTotal)*100);
	},
	updateProgress:function(strId,dblPercent)
	{
		strHtml="";
		strPercent=Math.round(dblPercent).toString()+"%";
		intPosition=Math.round((100-dblPercent)/100*150) * -1;
		
		if(document.getElementById("progressBar"+strId))
		{
			document.getElementById("progressBar"+strId).style.backgroundPosition=intPosition+"px 0px";
			document.getElementById("progressBarPercent"+strId).replaceChild(document.createTextNode(strPercent),document.getElementById("progressBarPercent"+strId).firstChild);
		}
	},
	onUploadCancel:function(event)
	{
		//this event doesn't seem to fire
	},
	onUploadComplete:function(event)
	{
		CMS_Calendar_Item.updateProgress(event.id,100);

		//remove "remove" link
		document.getElementById("fileAction"+event.id).innerHTML="\u00A0";
	},
	onUploadCompleteData:function(event)
	{
		var objFileData=eval("("+event.data+")");
		
		//remove from size uploading total
		CMS_Calendar_Item.intSizeUploadingTotal-=CMS_Calendar_Item.objFileList[event.id].size;
		CMS_Calendar_Item.intUploadCount--;
		
		if(!objFileData.blnSuccess)
		{
			CMS_Calendar_Item.cancel(event.id,objFileData.strMessages);
		}
		else
		{
			var eleInput1=CMS_Main.createNamedElement("input","fFile_id");
			eleInput1.id="fFile_id"+objFileData.intFileId;
			eleInput1.type="hidden";
			eleInput1.value=objFileData.intFileId;
			
			//add element to form
			document.getElementById("fileRow"+event.id).firstChild.appendChild(eleInput1);
		}

		//check for remaining file uploads
		if(CMS_Calendar_Item.intUploadCount==0)
		{
			//submit form
			CMS_Calendar_Item.editItemSubmitFinal(document.getElementById("frmEditItem"));
		}
		
		return false;
	},	
	onUploadError:function(event)
	{
		//CMS_Calendar_Item.cancel(event.id,event.status);
		CMS_Calendar_Item.cancel(event.id,"Error uploading file, please try again.");
	},

	onRollOver:function()
	{
	},
	onRollOut:function()
	{
	},
	onClick:function()
	{
	}
}/*--------------------------------------------------
	Project:	The November Group - CMS Administration
	Script:		cms_calendar_code.js
	Includes:	CMS_Calendar_Code
--------------------------------------------------*/

var CMS_Calendar_Code={
	
	manageCodes:function()
	{
		CMS_Main.setPage("manageCalendarCodes"); //store page selection

		CMS_Main.objRequest.open("GET","get_page_xml.php?page="+CMS_Main.getPage(),true);
		CMS_Main.objRequest.onreadystatechange=CMS_Main.updatePage;
		CMS_Main.objRequest.send(null);
		
		return false;
	},
	
	addCode:function()
	{
		CMS_Main.objRequest.open("GET","get_page_xml.php?page=editCalendarCode",true);
		CMS_Main.objRequest.onreadystatechange=CMS_Main.updatePage;
		CMS_Main.objRequest.send(null);
		
		return false;
	},
	
	editCode:function(intCodeId)
	{
		CMS_Main.objRequest.open("GET","get_page_xml.php?page=editCalendarCode&fCode_id="+intCodeId.toString(),true);
		CMS_Main.objRequest.onreadystatechange=CMS_Main.updatePage;
		CMS_Main.objRequest.send(null);
		
		return false;
	},
	
	editCodeText:function(intCodeId)
	{
		CMS_Main.objRequest.open("GET","get_page_xml.php?page=editCalendarCodeText&fCode_id="+intCodeId.toString(),true);
		CMS_Main.objRequest.onreadystatechange=CMS_Main.updatePage;
		CMS_Main.objRequest.send(null);
		
		return false;
	},
	
	editCodeInitialize:function(frm)
	{
		this.onTypeChange(frm);
		
		if(document.getElementById("fCode_calendar"))
			CMS_Main.allowTabs(document.getElementById("fCode_calendar"));
		if(document.getElementById("fCode_month"))
			CMS_Main.allowTabs(document.getElementById("fCode_month"));

		if(frm)
		{
			if(frm.fTitle)
			{
				frm.fTitle.focus();
				frm.fTitle.select();
			}
		}
		return false;
	},
	
	onTypeChange:function(frm)
	{
		if(frm && frm.fType)
		{
			switch(frm.fType.value)
			{
				case("0"):
					document.getElementById("displayCount").style.display="none";
					break;
				case("1"):
					document.getElementById("displayCount").style.display="block";
					break;
				default:
			}
		}
	},
	
	editCodeSubmit:function(frm)
	{
		var blnReturnValue=true;
		
		if(frm.fTitle.value.length==0)
		{
			alert("Please enter a title");
			frm.fTitle.focus();
			blnReturnValue=false;
		}
		else if(frm.fType.value==1 && isNaN(frm.fDisplay_count.value))
		{
			alert("Please enter a valid number");
			frm.fDisplay_count.focus();
			frm.fDisplay_count.select();
			blnReturnValue=false;
		}
		else if(frm.fType.value==1 && frm.fDisplay_count.value==0)
		{
			alert("Please enter a number greater than 0");
			frm.fDisplay_count.focus();
			frm.fDisplay_count.select();
			blnReturnValue=false;
		}
		
		if(blnReturnValue)
		{
			document.getElementById("fSubmit").disabled=true;

			CMS_Main.objRequest.open("POST","get_page_xml.php",true);
			CMS_Main.objRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
			CMS_Main.objRequest.onreadystatechange=CMS_Main.updatePage;
			CMS_Main.objRequest.send(CMS_Main.formEncode(frm)+"&page="+CMS_Main.getPage());
		}
		
		return false;
	},	
	
	editCodeTextSubmit:function(frm)
	{
		var blnReturnValue=true;
		
		if(blnReturnValue)
		{
			document.getElementById("fSubmit").disabled=true;

			CMS_Main.objRequest.open("POST","get_page_xml.php",true);
			CMS_Main.objRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
			CMS_Main.objRequest.onreadystatechange=CMS_Main.updatePage;
			CMS_Main.objRequest.send(CMS_Main.formEncode(frm)+"&page="+CMS_Main.getPage());
		}
		
		return false;
	},	
	
	editCodeCancel:function()
	{
		CMS_Main.objRequest.open("GET","get_page_xml.php?page="+CMS_Main.getPage(),true);
		CMS_Main.objRequest.onreadystatechange=CMS_Main.updatePage;
		CMS_Main.objRequest.send(null);
		
		return false;
	},
	
	deleteCode:function(intCodeId,strTitle)
	{
		if(confirm("Are you sure you want to delete "+strTitle+"?"))
		{
			CMS_Main.objRequest.open("GET","get_page_xml.php?page="+CMS_Main.getPage()+"&fAction=deleteCalendarCode&fCode_id="+intCodeId,true);
			CMS_Main.objRequest.onreadystatechange=CMS_Main.updatePage;
			CMS_Main.objRequest.send(null);
		}
		
		return false;
	}
}/*--------------------------------------------------
	Project:	The November Group - CMS Administration
	Script:		cms_gallery_category.js
	Includes:	CMS_Gallery_Category
--------------------------------------------------*/

var CMS_Gallery_Category={
	
	manageCategories:function()
	{
		CMS_Main.setPage("manageGalleryCategories"); //store page selection

		CMS_Main.objRequest.open("GET","get_page_xml.php?page="+CMS_Main.getPage(),true);
		CMS_Main.objRequest.onreadystatechange=CMS_Main.updatePage;
		CMS_Main.objRequest.send(null);
		
		return false;
	},
	
	addCategory:function()
	{
		CMS_Main.objRequest.open("GET","get_page_xml.php?page=editGalleryCategory",true);
		CMS_Main.objRequest.onreadystatechange=CMS_Main.updatePage;
		CMS_Main.objRequest.send(null);
		
		return false;
	},
	
	editCategory:function(intCategoryId)
	{
		CMS_Main.objRequest.open("GET","get_page_xml.php?page=editGalleryCategory&fCategory_id="+intCategoryId.toString(),true);
		CMS_Main.objRequest.onreadystatechange=CMS_Main.updatePage;
		CMS_Main.objRequest.send(null);
		
		return false;
	},
	
	editCategoryInitialize:function(frm)
	{
		if(frm)
		{
			//initialize text editor
			CMS_Main.textEditorInit("fDescription");

			if(frm.fName)
			{
				frm.fName.focus();
				frm.fName.select();
			}
		}
		return false;
	},
	
	editCategorySubmit:function(frm)
	{
		var blnReturnValue=true;
		
		CMS_Main.textEditorUpdate("fDescription");

		if(frm.fName.value.length==0)
		{
			alert("Please enter a name");
			frm.fName.focus();
			blnReturnValue=false;
		}
		
		if(blnReturnValue)
		{
			document.getElementById("fSubmit").disabled=true;

			CMS_Main.objRequest.open("POST","get_page_xml.php",true);
			CMS_Main.objRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
			CMS_Main.objRequest.onreadystatechange=CMS_Main.updatePage;
			CMS_Main.objRequest.send(CMS_Main.formEncode(frm)+"&page="+CMS_Main.getPage());
		}
		
		return false;
	},	
	
	editCategoryCancel:function()
	{
		CMS_Main.objRequest.open("GET","get_page_xml.php?page="+CMS_Main.getPage(),true);
		CMS_Main.objRequest.onreadystatechange=CMS_Main.updatePage;
		CMS_Main.objRequest.send(null);
		
		return false;
	},
	
	deleteCategory:function(intCategoryId,strTitle)
	{
		if(confirm("Are you sure you want to delete "+strTitle+" and all of its subcategories and photo galleries?"))
		{
			CMS_Main.objRequest.open("GET","get_page_xml.php?page="+CMS_Main.getPage()+"&fAction=deleteGalleryCategory&fCategory_id="+intCategoryId,true);
			CMS_Main.objRequest.onreadystatechange=CMS_Main.updatePage;
			CMS_Main.objRequest.send(null);
		}
		
		return false;
	}
}/*--------------------------------------------------
	Project:	The November Group - CMS Administration
	Script:		cms_gallery.js
	Includes:	CMS_Gallery
--------------------------------------------------*/

var CMS_Gallery={
	
	objGalleryListRequest:null,
	intCurrentCategoryId:-1,
	blnFilterPublished:true,
	blnFilterNotPublished:true,
	blnFilterArchived:true,
	blnFilterStaging:true,
	strFilterAlpha:"all",
	
	//pagination attributes
	intPageNumber:1,

	//gallery manage methods
	
	adminGallery:function()
	{
		CMS_Main.setPage("adminGallery"); //store page selection

		CMS_Main.objRequest.open("GET","get_page_xml.php?page="+CMS_Main.getPage(),true);
		CMS_Main.objRequest.onreadystatechange=CMS_Main.updatePage;
		CMS_Main.objRequest.send(null);
		
		return false;
	},
	
	manageGalleries:function()
	{
		CMS_Main.setPage("manageGalleries"); //store page selection

		CMS_Main.objRequest.open("GET","get_page_xml.php?page="+CMS_Main.getPage(),true);
		CMS_Main.objRequest.onreadystatechange=CMS_Main.updatePage;
		CMS_Main.objRequest.send(null);
		
		return false;
	},
	
	initializeGalleryManager:function(frm)
	{
		var blnSelected=false;
		
		if(frm)
		{
			//reselect previously selected category
			blnSelected=false;
			if(document.getElementById("fCategory_id") && document.getElementById("fCategory_id").length)
			{
				for(var i=0;i<document.getElementById("fCategory_id").options.length;i++)
				{
					if(document.getElementById("fCategory_id").options[i].value==this.intCurrentCategoryId)
					{
						document.getElementById("fCategory_id").options[i].selected=true;
						blnSelected=true;
						break;
					}
				}
				if(!blnSelected)
				{
					document.getElementById("fCategory_id").options[0].selected=true;
					this.intCurrentCategoryId=document.getElementById("fCategory_id").options[0].value;
				}
			}
			blnSelected=false;
			if(document.getElementById("fCategory_id_top") && document.getElementById("fCategory_id_top").length)
			{
				for(var i=0;i<document.getElementById("fCategory_id_top").options.length;i++)
				{
					if(document.getElementById("fCategory_id_top").options[i].value==this.intCurrentCategoryId)
					{
						document.getElementById("fCategory_id_top").options[i].selected=true;
						blnSelected=true;
						break;
					}
				}
				if(!blnSelected)
				{
					document.getElementById("fCategory_id_top").options[0].selected=true;
					this.intCurrentCategoryId=document.getElementById("fCategory_id_top").options[0].value;
				}
			}
			
			//reselect previously selected filters
			if(document.getElementById("fFilter_published")) document.getElementById("fFilter_published").checked=this.blnFilterPublished;
			if(document.getElementById("fFilter_published_top")) document.getElementById("fFilter_published_top").checked=this.blnFilterPublished;
			if(document.getElementById("fFilter_not_published")) document.getElementById("fFilter_not_published").checked=this.blnFilterNotPublished;
			if(document.getElementById("fFilter_not_published_top")) document.getElementById("fFilter_not_published_top").checked=this.blnFilterNotPublished;
			if(document.getElementById("fFilter_archived")) document.getElementById("fFilter_archived").checked=this.blnFilterArchived;
			if(document.getElementById("fFilter_archived_top")) document.getElementById("fFilter_archived_top").checked=this.blnFilterArchived;
			if(document.getElementById("fFilter_staging")) document.getElementById("fFilter_staging").checked=this.blnFilterStaging;
			if(document.getElementById("fFilter_staging_top")) document.getElementById("fFilter_staging_top").checked=this.blnFilterStaging;
				
			frm.fFilter_alpha.value=this.strFilterAlpha;
			
			//alpha
			if(document.getElementById("filterAlpha"))
			{
				var arrLinks=document.getElementById("filterAlpha").getElementsByTagName("a");
				for(var i=0;i<arrLinks.length;i++)
				{
					if(arrLinks[i].firstChild.firstChild.firstChild.nodeValue.toLowerCase()==frm.fFilter_alpha.value.toString())
					{
						arrLinks[i].className+=" current_page";
						break;
					}
				}
			}
			if(document.getElementById("filterAlphaTop"))
			{
				var arrLinks=document.getElementById("filterAlphaTop").getElementsByTagName("a");
				for(var i=0;i<arrLinks.length;i++)
				{
					if(arrLinks[i].firstChild.firstChild.firstChild.nodeValue.toLowerCase()==frm.fFilter_alpha.value.toString())
					{
						arrLinks[i].className+=" current_page";
						break;
					}
				}
			}
			
			//reselect previously selected show count
			blnSelected=false;
			if(document.getElementById("fShow_count"))
			{
				var eleSelect2=document.getElementById("fShow_count");
				for(var i=0;i<eleSelect2.options.length;i++)
				{
					if(Number(eleSelect2.options[i].value)==CMS_Client_User_Settings.getShowCountGalleries())
					{
						eleSelect2.options[i].selected=true;
						blnSelected=true;
						break;
					}
				}
				if(!blnSelected)
				{
					eleSelect2.options[0].selected=true;
					CMS_Client_User_Settings.setShowCountGalleries(Number(eleSelect2.options[0].value));
				}
			}
			blnSelected=false;
			if(document.getElementById("fShow_count_top"))
			{
				var eleSelect2=document.getElementById("fShow_count_top");
				for(var i=0;i<eleSelect2.options.length;i++)
				{
					if(Number(eleSelect2.options[i].value)==CMS_Client_User_Settings.getShowCountGalleries())
					{
						eleSelect2.options[i].selected=true;
						blnSelected=true;
						break;
					}
				}
				if(!blnSelected)
				{
					eleSelect2.options[0].selected=true;
					CMS_Client_User_Settings.setShowCountGalleries(Number(eleSelect2.options[0].value));
				}
			}

			//retrieve previously selected page number
			if(frm.fPage_number)
				frm.fPage_number.value=this.intPageNumber.toString();
			
			//enable or disable "publish files" option
			if(document.getElementById("fAction_index"))
			{
				var eleSelect2=document.getElementById("fAction_index");
				for(var i=0;i<eleSelect2.length;i++)
				{
					if(eleSelect2.options[i].value==2)
					{
						if(CMS_Client_User_Settings.canPublishGalleries())
						{
							eleSelect2.options[i].disabled=false;
						}
						else
						{
							if(eleSelect2.options[i].selected)
								eleSelect2.options[0].selected=true;
								
							//disable option
							eleSelect2.options[i].disabled=true;
						}
						break;
					}
				}
			}
			if(document.getElementById("fAction_index_top"))
			{
				var eleSelect2=document.getElementById("fAction_index_top");
				for(var i=0;i<eleSelect2.length;i++)
				{
					if(eleSelect2.options[i].value==2)
					{
						if(CMS_Client_User_Settings.canPublishGalleries())
						{
							eleSelect2.options[i].disabled=false;
						}
						else
						{
							if(eleSelect2.options[i].selected)
								eleSelect2.options[0].selected=true;
								
							//disable option
							eleSelect2.options[i].disabled=true;
						}
						break;
					}
				}
			}
			
			this.onCategoryOrFilterChange(frm);
		}
	},
	
	
	addGallery:function(intCategoryId)
	{
		CMS_Main.objRequest.open("GET","get_page_xml.php?page=editGallery&fCategory_id="+intCategoryId.toString(),true);
		CMS_Main.objRequest.onreadystatechange=CMS_Main.updatePage;
		CMS_Main.objRequest.send(null);
		
		return false;
	},
	
	editGallery:function(intGalleryId,blnUseStagingAreaCopy)
	{
		CMS_Main.objRequest.open("GET","get_page_xml.php?page=editGallery&fGallery_id="+intGalleryId.toString()+(blnUseStagingAreaCopy ? "&fUse_staging_area_copy=1" : ""),true);
		CMS_Main.objRequest.onreadystatechange=CMS_Main.updatePage;
		CMS_Main.objRequest.send(null);
		
		return false;
	},
	
	deleteGallery:function(intGalleryId)
	{
		var strTitle=document.getElementById("selectGalleryName"+intGalleryId).value.toString();
		
		if(confirm("Are you sure you want to delete "+strTitle+"?"))
		{
			CMS_Main.objRequest.open("GET","get_page_xml.php?page="+CMS_Main.getPage()+"&fAction=deleteGallery&fGallery_id="+intGalleryId,true);
			CMS_Main.objRequest.onreadystatechange=CMS_Main.updatePage;
			CMS_Main.objRequest.send(null);
		}
		
		return false;
	},

	onCategoryOrFilterChange:function(frm)
	{
		this.getGalleryList(frm);
	},

	onCategoryChange:function(frm,eleSelect)
	{
		this.intCurrentCategoryId=eleSelect.options[eleSelect.selectedIndex].value;
		
		if(document.getElementById("fCategory_id"))
		{
			var eleSelect2=document.getElementById("fCategory_id");
			for(var i=0;i<eleSelect2.options.length;i++)
			{
				if(eleSelect2.options[i].value==this.intCurrentCategoryId)
					eleSelect2.options[i].selected=true;
				else
					eleSelect2.options[i].selected=false;
			}
		}
		if(document.getElementById("fCategory_id_top"))
		{
			var eleSelect2=document.getElementById("fCategory_id_top");
			for(var i=0;i<eleSelect2.options.length;i++)
			{
				if(eleSelect2.options[i].value==this.intCurrentCategoryId)
					eleSelect2.options[i].selected=true;
				else
					eleSelect2.options[i].selected=false;
			}
		}
		
		this.onCategoryOrFilterChange(frm);
	},
	
	onFilterPublishedClick:function(frm,eleInput)
	{
		this.blnFilterPublished=eleInput.checked;

		if(document.getElementById("fFilter_published"))
			document.getElementById("fFilter_published").checked=eleInput.checked;
		if(document.getElementById("fFilter_published_top"))
			document.getElementById("fFilter_published_top").checked=eleInput.checked;
		
		this.onCategoryOrFilterChange(frm);
	},
	
	onFilterNotPublishedClick:function(frm,eleInput)
	{
		this.blnFilterNotPublished=eleInput.checked;

		if(document.getElementById("fFilter_not_published"))
			document.getElementById("fFilter_not_published").checked=eleInput.checked;
		if(document.getElementById("fFilter_not_published_top"))
			document.getElementById("fFilter_not_published_top").checked=eleInput.checked;
		
		this.onCategoryOrFilterChange(frm);
	},
	
	onFilterArchivedClick:function(frm,eleInput)
	{
		this.blnFilterArchived=eleInput.checked;

		if(document.getElementById("fFilter_archived"))
			document.getElementById("fFilter_archived").checked=eleInput.checked;
		if(document.getElementById("fFilter_archived_top"))
			document.getElementById("fFilter_archived_top").checked=eleInput.checked;
		
		this.onCategoryOrFilterChange(frm);
	},
	
	onFilterStagingClick:function(frm,eleInput)
	{
		this.blnFilterStaging=eleInput.checked;

		if(document.getElementById("fFilter_staging"))
			document.getElementById("fFilter_staging").checked=eleInput.checked;
		if(document.getElementById("fFilter_staging_top"))
			document.getElementById("fFilter_staging_top").checked=eleInput.checked;
		
		this.onCategoryOrFilterChange(frm);
	},
	
	onAlphaClick:function(frm,eleA)
	{
		if(frm && eleA)
		{
			frm.fFilter_alpha.value=eleA.firstChild.firstChild.firstChild.nodeValue.toLowerCase(); //retrieve selected value
			this.strFilterAlpha=frm.fFilter_alpha.value.toString();
			
			//reset classes
			if(document.getElementById("filterAlpha"))
			{
				var arrLinks=document.getElementById("filterAlpha").getElementsByTagName("a");
				for(var i=0;i<arrLinks.length;i++)
				{
					if(arrLinks[i].className.indexOf("current_page")>-1)
						arrLinks[i].className=arrLinks[i].className.replace("current_page","");
					if(arrLinks[i].firstChild.firstChild.firstChild.nodeValue.toLowerCase()==frm.fFilter_alpha.value)
						arrLinks[i].className+=" current_page";
				}
			}
			if(document.getElementById("filterAlphaTop"))
			{
				var arrLinks=document.getElementById("filterAlphaTop").getElementsByTagName("a");
				for(var i=0;i<arrLinks.length;i++)
				{
					if(arrLinks[i].className.indexOf("current_page")>-1)
						arrLinks[i].className=arrLinks[i].className.replace("current_page","");
					if(arrLinks[i].firstChild.firstChild.firstChild.nodeValue.toLowerCase()==frm.fFilter_alpha.value)
						arrLinks[i].className+=" current_page";
				}
			}
			
			//update filter
			CMS_Gallery.onCategoryOrFilterChange(frm);
		}
		return false; //cancel link
	},
	
	onShowCountChange:function(frm,eleSelect)
	{
		if(frm && frm.fShow_count)
		{
			var intPages=1;

			if(document.getElementById("fShow_count"))
			{
				var eleSelect2=document.getElementById("fShow_count");
				for(var i=0;i<eleSelect2.options.length;i++)
				{
					if(Number(eleSelect2.options[i].value)==Number(eleSelect.options[eleSelect.selectedIndex].value))
						eleSelect2.options[i].selected=true;
				}
			}
			if(document.getElementById("fShow_count_top"))
			{
				var eleSelect2=document.getElementById("fShow_count_top");
				for(var i=0;i<eleSelect2.options.length;i++)
				{
					if(Number(eleSelect2.options[i].value)==Number(eleSelect.options[eleSelect.selectedIndex].value))
						eleSelect2.options[i].selected=true;
				}
			}
			
			CMS_Client_User_Settings.setShowCountGalleries(Number(frm.fShow_count.value)); //store selected value
			
			//calculate number of pages
			if(Number(frm.fShow_count.value)>0)
				intPages=Math.ceil(Number(frm.fGallery_count.value)/Number(frm.fShow_count.value));
			if(intPages==0)
				intPages++;
			
			//check if current page number will exist for new show count
			if(Number(frm.fPage_number.value)>intPages)
				frm.fPage_number.value="1"; //reset page number
			
			this.getGalleryList(frm);
		}
	},
	
	onPageClick:function(frm,eleNumber)
	{
		if(frm && eleNumber)
		{
			frm.fPage_number.value=eleNumber.firstChild.firstChild.firstChild.nodeValue; //retrieve selected value
			this.getGalleryList(frm);
		}
		return false;
	},
	
	updatePagination:function(frm)
	{
		if(frm && frm.fShow_count)
		{
			var intPages=1;
			
			//calculate number of pages
			if(Number(frm.fShow_count.value)>0)
				intPages=Math.ceil(Number(frm.fGallery_count.value)/Number(frm.fShow_count.value));
			if(intPages==0)
				intPages++;
			
			//rebuild page links
			if(document.getElementById("filterPage"))
			{
				document.getElementById("filterPage").innerHTML="";
				for(var i=0;i<intPages;i++)
					document.getElementById("filterPage").innerHTML+="<li><a href=\"#\" onclick=\"return CMS_Gallery.onPageClick(document.getElementById('frmManageGalleries'),this);\"><span><span>"+(i+1).toString()+"</span></span></a></li>";
			}
			if(document.getElementById("filterPageTop"))
			{
				document.getElementById("filterPageTop").innerHTML="";
				for(var i=0;i<intPages;i++)
					document.getElementById("filterPageTop").innerHTML+="<li><a href=\"#\" onclick=\"return CMS_Gallery.onPageClick(document.getElementById('frmManageGalleries'),this);\"><span><span>"+(i+1).toString()+"</span></span></a></li>";
			}
			
			//select page link
			var blnSelected=false;
			if (document.getElementById("filterPage")) 
			{
				var arrLinks=document.getElementById("filterPage").getElementsByTagName("a");
				for(var i=0;i<arrLinks.length;i++)
				{
					if(arrLinks[i].firstChild.firstChild.firstChild.nodeValue==frm.fPage_number.value.toString())
					{
						//change class
						arrLinks[i].className+=" current_page";
						blnSelected=true;
						break;
					}
				}
				if(!blnSelected)
				{
					arrLinks[0].className+=" current_page";
					frm.fPage_number.value=arrLinks[0].firstChild.firstChild.firstChild.nodeValue;
				}
			}
			blnSelected=false;
			if (document.getElementById("filterPageTop")) 
			{
				var arrLinks=document.getElementById("filterPageTop").getElementsByTagName("a");
				for(var i=0;i<arrLinks.length;i++)
				{
					if(arrLinks[i].firstChild.firstChild.firstChild.nodeValue==frm.fPage_number.value.toString())
					{
						//change class
						arrLinks[i].className+=" current_page";
						blnSelected=true;
						break;
					}
				}
				if(!blnSelected)
				{
					arrLinks[0].className+=" current_page";
					frm.fPage_number.value=arrLinks[0].firstChild.firstChild.firstChild.nodeValue;
				}
			}

			//store selected value
			this.intPageNumber=Number(frm.fPage_number.value);
			
			//calculate gallery count
			var intCountStart=(Number(frm.fPage_number.value)-1)*Number(frm.fShow_count.value);
			var intCountEnd=(Number(frm.fShow_count.value)==0 ? Number(frm.fGallery_count.value) : Math.min(Number(frm.fShow_count.value)+intCountStart,Number(frm.fGallery_count.value)));
			
			//update gallery count
			if(document.getElementById("galleryCountStart"))
				document.getElementById("galleryCountStart").innerHTML=(Math.min(intCountStart+1,Number(frm.fGallery_count.value))).toString();
			if(document.getElementById("galleryCountEnd"))
				document.getElementById("galleryCountEnd").innerHTML=intCountEnd.toString();
			if(document.getElementById("galleryCount"))
				document.getElementById("galleryCount").innerHTML=frm.fGallery_count.value.toString();

			if(document.getElementById("galleryCountStartTop"))
				document.getElementById("galleryCountStartTop").innerHTML=(Math.min(intCountStart+1,Number(frm.fGallery_count.value))).toString();
			if(document.getElementById("galleryCountEndTop"))
				document.getElementById("galleryCountEndTop").innerHTML=intCountEnd.toString();
			if(document.getElementById("galleryCountTop"))
				document.getElementById("galleryCountTop").innerHTML=frm.fGallery_count.value.toString();
		}
	},
	
	getGalleryList:function(frm)
	{
		var strHtml="";
		
		//clear select all
		if(document.getElementById("selectAll"))
			document.getElementById("selectAll").checked=false;
		
		//clear gallery list
		while(document.getElementById("galleryListContainer").firstChild)
			document.getElementById("galleryListContainer").removeChild(document.getElementById("galleryListContainer").firstChild);
		
		//add loading message
		var eleLoading=document.createElement("tr");
		eleLoading.appendChild(document.createElement("td"));
		eleLoading.childNodes[0].colSpan=4;
		eleLoading.childNodes[0].appendChild(document.createTextNode(CMS_Main.getLoadingMessage()));
		document.getElementById("galleryListContainer").appendChild(eleLoading);
		
		//get gallery list
		this.objGalleryListRequest=CMS_Main.createRequest();
		this.objGalleryListRequest.open("GET","get_element_xml.php?function=getGalleryListJson&fCategory_id="+CMS_Gallery.intCurrentCategoryId.toString()+"&fFilter_published="+(CMS_Gallery.blnFilterPublished ? "1" : "0")+"&fFilter_not_published="+(CMS_Gallery.blnFilterNotPublished ? "1" : "0")+"&fFilter_archived="+(CMS_Gallery.blnFilterArchived ? "1" : "0")+"&fFilter_staging="+(CMS_Gallery.blnFilterStaging ? "1" : "0")+"&fFilter_alpha="+encodeURIComponent(CMS_Gallery.strFilterAlpha)+"&fShow_count="+frm.fShow_count.value.toString()+"&fPage_number="+frm.fPage_number.value.toString(),true);
		this.objGalleryListRequest.onreadystatechange=function(){
			if(CMS_Gallery.objGalleryListRequest.readyState==4 && CMS_Gallery.objGalleryListRequest.status==200)
			{
				//clear loading message
				while(document.getElementById("galleryListContainer").firstChild)
					document.getElementById("galleryListContainer").removeChild(document.getElementById("galleryListContainer").firstChild);
				
				var objGalleryData=eval("("+CMS_Gallery.objGalleryListRequest.responseText+")");
				document.getElementById("fGallery_count").value=objGalleryData.intGalleryCount.toString();
				
				//add rows
				for(i in objGalleryData.arrGalleries)
				{
					var eleRow=CMS_Gallery.createRow(objGalleryData.arrGalleries[i]);
					
					if(i%2==0)
						eleRow.className="first";
					else
						eleRow.className="second";

					document.getElementById("galleryListContainer").appendChild(eleRow);
				}
				
				if(objGalleryData.arrGalleries.length==0)
					document.getElementById("galleryListContainer").appendChild(CMS_Gallery.createEmptyRow());
				
				CMS_Gallery.updatePagination(document.getElementById("frmManageGalleries"));
			}
		};
		this.objGalleryListRequest.send(null);
		
		return false;
	},
	
	createRow:function(objGalleryData)
	{
		var eleRow=document.createElement("tr");
		
		var eleTd0=document.createElement("td");
		eleTd0.style.padding=".5em";
		eleTd0.style.textAlign="center";
		eleTd0.style.width="20px";
		eleInput1=CMS_Main.createNamedElement("input","selectGallery");
		eleInput1.type="checkbox";
		eleInput1.id="selectGallery"+objGalleryData.intGalleryId.toString();
		eleInput1.value=objGalleryData.intGalleryId.toString();
		eleTd0.appendChild(eleInput1);
		eleInput2=CMS_Main.createNamedElement("input","selectGalleryName");
		eleInput2.type="hidden";
		eleInput2.id="selectGalleryName"+objGalleryData.intGalleryId.toString();
