/*
Filename: script.js
Version:  3.0
Author:   Kevin Parker (www.administerweb.com)
Purpose:  Included when JavaScript is needed for this component.
*/
/* This function is used to handle all functions needing to be in the window.onload event.
    See pg. 221 of Visual Quickstart Guide JavaScript & AJAX 6th edition for notes.
   To add functions to the window.onload event, call the following for each function name:
      addOnload(myFunctionName); */
function addOnload(newFunction) {
	var oldOnload = window.onload;
	if (typeof oldOnload == "function") {
		window.onload = function() {
			if (oldOnload) {
				oldOnload();
			}
			newFunction();
		}
	} else {
		window.onload = newFunction;
	}
}

function checkScreenSize() {
/* This upper case value of "UASCREENSIZE=UNKNOWN" is very important.
   For browsers that accept cookies (and they are turned on), this value will be set the very 
	first page request by the application's "checkScreenSize()" method.
   For browsers that do NOT accept cookies (or they are turned off), this value won't exist anyway
	and they will not be redirected. Works great for bots or other non-cookie/non-session people. */
	if (document.cookie.indexOf("UASCREENSIZE=UNKNOWN") != -1) {
		//alert("UASCREENSIZE=UNKNOWN was found!");
		var intScreenWidth = screen.width;
		var intScreenHeight = screen.height;
		// Small screens are less than 800 in width; includes mobile devices.
		if (intScreenWidth < 800) {
			document.cookie="UASCREENSIZE=SMALL";
		// Medium screens are 800 to 1024 in width.
		} else if (intScreenWidth < 1025) {
			document.cookie="UASCREENSIZE=MEDIUM";
		// Large screens are over 1024 in width.
		} else {
			document.cookie="UASCREENSIZE=LARGE";
		}
		// For user agents that accept cookies (per the IF statement), set width and height for application.
		document.cookie="UASCREENWIDTH=" + intScreenWidth;
		document.cookie="UASCREENHEIGHT=" + intScreenHeight;
		// Redirect the user back to this page but with the screen size set. This will only happen once while
		//  the cookie persists.
		// For user agents with no cookies and/or no JavaScript, this never happens.
		document.location.reload();
	//} else {
		//alert("UASCREENSIZE=UNKNOWN was NOT found!");
	}
}
/* Here's how to call this on the page (or else add it to a function for calling multiple functions): 
     addOnload(checkScreenSize); */


function confirmAction(message, url) {
	if (confirm(message)) location.href = url;
}

// Main Tabs for content edit form.
function showMyTab(tabid) {
	switch (tabid) {
		case "Content":
			document.getElementById("contentFormTabBodyContent").style.display = "block";
			document.getElementById("contentFormTabContent").className = "activeTab";
			document.getElementById("contentFormTabBodyDetails").style.display = "none";
			document.getElementById("contentFormTabDetails").className = "inactiveTab";
			document.getElementById("contentFormTabBodyDates").style.display = "none";
			document.getElementById("contentFormTabDates").className = "inactiveTab";
			document.getElementById("contentFormTabBodyVersions").style.display = "none";
			document.getElementById("contentFormTabVersions").className = "inactiveTab";
			break;
		case "Details":
			document.getElementById("contentFormTabBodyContent").style.display = "none";
			document.getElementById("contentFormTabContent").className = "inactiveTab";
			document.getElementById("contentFormTabBodyDetails").style.display = "block";
			document.getElementById("contentFormTabDetails").className = "activeTab";
			document.getElementById("contentFormTabBodyDates").style.display = "none";
			document.getElementById("contentFormTabDates").className = "inactiveTab";
			document.getElementById("contentFormTabBodyVersions").style.display = "none";
			document.getElementById("contentFormTabVersions").className = "inactiveTab";
			break;
		case "Dates":
			document.getElementById("contentFormTabBodyContent").style.display = "none";
			document.getElementById("contentFormTabContent").className = "inactiveTab";
			document.getElementById("contentFormTabBodyDetails").style.display = "none";
			document.getElementById("contentFormTabDetails").className = "inactiveTab";
			document.getElementById("contentFormTabBodyDates").style.display = "block";
			document.getElementById("contentFormTabDates").className = "activeTab";
			document.getElementById("contentFormTabBodyVersions").style.display = "none";
			document.getElementById("contentFormTabVersions").className = "inactiveTab";
			break;
		case "Versions":
			document.getElementById("contentFormTabBodyContent").style.display = "none";
			document.getElementById("contentFormTabContent").className = "inactiveTab";
			document.getElementById("contentFormTabBodyDetails").style.display = "none";
			document.getElementById("contentFormTabDetails").className = "inactiveTab";
			document.getElementById("contentFormTabBodyDates").style.display = "none";
			document.getElementById("contentFormTabDates").className = "inactiveTab";
			document.getElementById("contentFormTabBodyVersions").style.display = "block";
			document.getElementById("contentFormTabVersions").className = "activeTab";
			break;
	}
}
// Secondary Tabs for content edit form.
function showMyTab2(tabid) {
	switch (tabid) {
		case "1":
			var blnTab1 = document.getElementById("previousVersionsTabBody1"); // Test to make sure each tab exists.
			if (blnTab1!=null) {
				document.getElementById("previousVersionsTabBody1").style.display = "block";
				document.getElementById("previousVersionsTab1").className = "activeTab";
			}
			var blnTab2 = document.getElementById("previousVersionsTabBody2");
			if (blnTab2!=null) {
				document.getElementById("previousVersionsTabBody2").style.display = "none";
				document.getElementById("previousVersionsTab2").className = "inactiveTab";
			}
			var blnTab3 = document.getElementById("previousVersionsTabBody3");
			if (blnTab3!=null) {
				document.getElementById("previousVersionsTabBody3").style.display = "none";
				document.getElementById("previousVersionsTab3").className = "inactiveTab";
			}
			var blnTab4 = document.getElementById("previousVersionsTabBody4");
			if (blnTab4!=null) {
				document.getElementById("previousVersionsTabBody4").style.display = "none";
				document.getElementById("previousVersionsTab4").className = "inactiveTab";
			}
			var blnTab5 = document.getElementById("previousVersionsTabBody5");
			if (blnTab5!=null) {
				document.getElementById("previousVersionsTabBody5").style.display = "none";
				document.getElementById("previousVersionsTab5").className = "inactiveTab";
			}
			break;
		case "2":
			var blnTab1 = document.getElementById("previousVersionsTabBody1");
			if (blnTab1!=null) {
				document.getElementById("previousVersionsTabBody1").style.display = "none";
				document.getElementById("previousVersionsTab1").className = "inactiveTab";
			}
			var blnTab2 = document.getElementById("previousVersionsTabBody2");
			if (blnTab2!=null) {
				document.getElementById("previousVersionsTabBody2").style.display = "block";
				document.getElementById("previousVersionsTab2").className = "activeTab";
			}
			var blnTab3 = document.getElementById("previousVersionsTabBody3");
			if (blnTab3!=null) {
				document.getElementById("previousVersionsTabBody3").style.display = "none";
				document.getElementById("previousVersionsTab3").className = "inactiveTab";
			}
			var blnTab4 = document.getElementById("previousVersionsTabBody4");
			if (blnTab4!=null) {
				document.getElementById("previousVersionsTabBody4").style.display = "none";
				document.getElementById("previousVersionsTab4").className = "inactiveTab";
			}
			var blnTab5 = document.getElementById("previousVersionsTabBody5");
			if (blnTab5!=null) {
				document.getElementById("previousVersionsTabBody5").style.display = "none";
				document.getElementById("previousVersionsTab5").className = "inactiveTab";
			}
			break;
		case "3":
			var blnTab1 = document.getElementById("previousVersionsTabBody1");
			if (blnTab1!=null) {
				document.getElementById("previousVersionsTabBody1").style.display = "none";
				document.getElementById("previousVersionsTab1").className = "inactiveTab";
			}
			var blnTab2 = document.getElementById("previousVersionsTabBody2");
			if (blnTab2!=null) {
				document.getElementById("previousVersionsTabBody2").style.display = "none";
				document.getElementById("previousVersionsTab2").className = "inactiveTab";
			}
			var blnTab3 = document.getElementById("previousVersionsTabBody3");
			if (blnTab3!=null) {
				document.getElementById("previousVersionsTabBody3").style.display = "block";
				document.getElementById("previousVersionsTab3").className = "activeTab";
			}
			var blnTab4 = document.getElementById("previousVersionsTabBody4");
			if (blnTab4!=null) {
				document.getElementById("previousVersionsTabBody4").style.display = "none";
				document.getElementById("previousVersionsTab4").className = "inactiveTab";
			}
			var blnTab5 = document.getElementById("previousVersionsTabBody5");
			if (blnTab5!=null) {
				document.getElementById("previousVersionsTabBody5").style.display = "none";
				document.getElementById("previousVersionsTab5").className = "inactiveTab";
			}
			break;
		case "4":
			var blnTab1 = document.getElementById("previousVersionsTabBody1");
			if (blnTab1!=null) {
				document.getElementById("previousVersionsTabBody1").style.display = "none";
				document.getElementById("previousVersionsTab1").className = "inactiveTab";
			}
			var blnTab2 = document.getElementById("previousVersionsTabBody2");
			if (blnTab2!=null) {
				document.getElementById("previousVersionsTabBody2").style.display = "none";
				document.getElementById("previousVersionsTab2").className = "inactiveTab";
			}
			var blnTab3 = document.getElementById("previousVersionsTabBody3");
			if (blnTab3!=null) {
				document.getElementById("previousVersionsTabBody3").style.display = "none";
				document.getElementById("previousVersionsTab3").className = "inactiveTab";
			}
			var blnTab4 = document.getElementById("previousVersionsTabBody4");
			if (blnTab4!=null) {
				document.getElementById("previousVersionsTabBody4").style.display = "block";
				document.getElementById("previousVersionsTab4").className = "activeTab";
			}
			var blnTab5 = document.getElementById("previousVersionsTabBody5");
			if (blnTab5!=null) {
				document.getElementById("previousVersionsTabBody5").style.display = "none";
				document.getElementById("previousVersionsTab5").className = "inactiveTab";
			}
			break;
		case "5":
			var blnTab1 = document.getElementById("previousVersionsTabBody1");
			if (blnTab1!=null) {
				document.getElementById("previousVersionsTabBody1").style.display = "none";
				document.getElementById("previousVersionsTab1").className = "inactiveTab";
			}
			var blnTab2 = document.getElementById("previousVersionsTabBody2");
			if (blnTab2!=null) {
				document.getElementById("previousVersionsTabBody2").style.display = "none";
				document.getElementById("previousVersionsTab2").className = "inactiveTab";
			}
			var blnTab3 = document.getElementById("previousVersionsTabBody3");
			if (blnTab3!=null) {
				document.getElementById("previousVersionsTabBody3").style.display = "none";
				document.getElementById("previousVersionsTab3").className = "inactiveTab";
			}
			var blnTab4 = document.getElementById("previousVersionsTabBody4");
			if (blnTab4!=null) {
				document.getElementById("previousVersionsTabBody4").style.display = "none";
				document.getElementById("previousVersionsTab4").className = "inactiveTab";
			}
			var blnTab5 = document.getElementById("previousVersionsTabBody5");
			if (blnTab5!=null) {
				document.getElementById("previousVersionsTabBody5").style.display = "block";
				document.getElementById("previousVersionsTab5").className = "activeTab";
			}
			break;
	}
}

// This function allows for easy and standardized opening of dialog boxes like the Upload Asset form.
// CAN ONLY BE USED ONCE PER PAGE TO WORK BECAUSE OF THE newDialogWindow OBJECT!!!
var newDialogWindow;
function openDialogWindow(url, windowname, windowwidth, windowheight, xposition, yposition) {
	if (!newDialogWindow || newDialogWindow.closed) {
		// screen.availLeft takes into account multiple monitors. On the second monitor, it equal's the width of the first.
		var myleftposition = (screen.availLeft + xposition);
		newDialogWindow = window.open(url, windowname, "menubar=0,status=0,resizable=0,width=" + windowwidth + ",height=" + windowheight + ",screenX=" + myleftposition + ",screenY=" + yposition);
	} else {
		// The window is already open, so bring it to the front without reloading it.
		newDialogWindow.focus();
	}
}

// Required by jumpToFolder and other forms...
function submitForm(formName) {
	document.forms[formName].submit();
}

// Main Tabs for content edit form.
function showMyFormTab(tabToShow,tabToHide1,tabToHide2,tabToHide3,tabToHide4,tabToHide5,tabToHide6,tabToHide7) {
	var txtTabBodyShow = "contentFormTabBody" + tabToShow;
	var txtTabNameShow = "contentFormTab" + tabToShow;
	var blnTabShow = document.getElementById(txtTabNameShow); // Test to make sure each tab exists.
	if (blnTabShow!=null) {
		document.getElementById(txtTabBodyShow).style.display = "block";
		document.getElementById(txtTabNameShow).className = "activeTab";
	}
	var txtTabBody1 = "contentFormTabBody" + tabToHide1;
	var txtTabName1 = "contentFormTab" + tabToHide1;
	var blnTab1 = document.getElementById(txtTabName1); // Test to make sure each tab exists.
	if (blnTab1!=null) {
		document.getElementById(txtTabBody1).style.display = "none";
		document.getElementById(txtTabName1).className = "inactiveTab";
	}
	var txtTabBody2 = "contentFormTabBody" + tabToHide2;
	var txtTabName2 = "contentFormTab" + tabToHide2;
	var blnTab2 = document.getElementById(txtTabName2); // Test to make sure each tab exists.
	if (blnTab2!=null) {
		document.getElementById(txtTabBody2).style.display = "none";
		document.getElementById(txtTabName2).className = "inactiveTab";
	}
	var txtTabBody3 = "contentFormTabBody" + tabToHide3;
	var txtTabName3 = "contentFormTab" + tabToHide3;
	var blnTab3 = document.getElementById(txtTabName3); // Test to make sure each tab exists.
	if (blnTab3!=null) {
		document.getElementById(txtTabBody3).style.display = "none";
		document.getElementById(txtTabName3).className = "inactiveTab";
	}
	var txtTabBody4 = "contentFormTabBody" + tabToHide4;
	var txtTabName4 = "contentFormTab" + tabToHide4;
	var blnTab4 = document.getElementById(txtTabName4); // Test to make sure each tab exists.
	if (blnTab4!=null) {
		document.getElementById(txtTabBody4).style.display = "none";
		document.getElementById(txtTabName4).className = "inactiveTab";
	}
	var txtTabBody5 = "contentFormTabBody" + tabToHide5;
	var txtTabName5 = "contentFormTab" + tabToHide5;
	var blnTab5 = document.getElementById(txtTabName5); // Test to make sure each tab exists.
	if (blnTab5!=null) {
		document.getElementById(txtTabBody5).style.display = "none";
		document.getElementById(txtTabName5).className = "inactiveTab";
	}
	var txtTabBody6 = "contentFormTabBody" + tabToHide6;
	var txtTabName6 = "contentFormTab" + tabToHide6;
	var blnTab6 = document.getElementById(txtTabName6); // Test to make sure each tab exists.
	if (blnTab6!=null) {
		document.getElementById(txtTabBody6).style.display = "none";
		document.getElementById(txtTabName6).className = "inactiveTab";
	}
	var txtTabBody7 = "contentFormTabBody" + tabToHide7;
	var txtTabName7 = "contentFormTab" + tabToHide7;
	var blnTab7 = document.getElementById(txtTabName7); // Test to make sure each tab exists.
	if (blnTab7!=null) {
		document.getElementById(txtTabBody7).style.display = "none";
		document.getElementById(txtTabName7).className = "inactiveTab";
	}
}

// Dynamically show or hide a portion of a form or page.
function toggleHideSection(idCheckBox,idToHide,whenToHide) {
	var block = document.getElementById(idToHide);
	var checkBox = document.getElementById(idCheckBox);
	if (block!=null) {
		if (checkBox!=null) {
			if (checkBox.checked == true) {
				if (whenToHide == "on") {
					block.style.display = "none";
				}
				else {
					block.style.display = "block";
				}
			}
			else {
				if (whenToHide == "on") {
					block.style.display = "block";
				}
				else {
					block.style.display = "none";
				}
			}
		}
	}
}
// Dynamically show the expire date field or not.
function toggle_end_date() {
	var block = document.getElementById("div_end_date");
	var checkBox = document.getElementById("set_end_date");
	if (block!=null) {
		if (checkBox!=null) {
			if (checkBox.checked == true) {
				block.style.display = "block";
				//JACS.show(document.getElementById('end_date'),this,'jacs2');
			}
			else {
				block.style.display = "none";
				//JACS.hide(document.jacs2,this);
			}
		}
	}
}
function changeDateMoveEndDate() {
	var newStartDate = new Date();
	var newEndDate = new Date();
	var intDateDifference = new Number(document.getElementById("date_difference").value);
	var strFormStartDate = new String(document.getElementById("start_date").value);
	var intStartDateMonth = strFormStartDate.substring(0,2);
	var intStartDateDays = strFormStartDate.substring(3,5);
	var intStartDateYear = strFormStartDate.substring(6,10);
	newStartDate.setMonth(intStartDateMonth - 1); //Zero-based months;
	newStartDate.setDate(intStartDateDays);
	newStartDate.setYear(intStartDateYear);
	newEndDate = newStartDate
	newEndDate.setDate(newEndDate.getDate() + intDateDifference);
	var intEndDateMonth = newEndDate.getMonth() + 1;
	if (intEndDateMonth < 10) {
		intEndDateMonth = "0" + String(intEndDateMonth);
	}
	var intEndDateDays = newEndDate.getDate();
	if (intEndDateDays < 10) {
		intEndDateDays = "0" + String(intEndDateDays);
	}
	var intEndDateYear = String(newEndDate.getFullYear());
	document.getElementById("end_date").value = intEndDateMonth + "/" + intEndDateDays + "/" + intEndDateYear;
	//window.alert("Start date: " + newStartDate);
	//window.alert("intDateDifference: " + intDateDifference);
	//window.alert("End date: " + newEndDate);
	//The following is required to update the calendar of the End Date when the date is updated...
	JACS.show(document.getElementById('end_date'),'jacs2');
}
function changeDateDifference() {
	//Create date objects:
	var newStartDate = new Date();
	var newEndDate = new Date();
	//Get the string values of the form currently:
	var strFormStartDate = new String(document.getElementById("start_date").value);
	var strFormEndDate = new String(document.getElementById("end_date").value);
	var strStartLabel = new String(document.getElementById("start_date_label").value);
	var strEndLabel = new String(document.getElementById("end_date_label").value);
	//Get the month/day/year values from the strings:
	var intStartDateMonth = strFormStartDate.substring(0,2);
	var intStartDateDays = strFormStartDate.substring(3,5);
	var intStartDateYear = strFormStartDate.substring(6,10);
	var intEndDateMonth = strFormEndDate.substring(0,2);
	var intEndDateDays = strFormEndDate.substring(3,5);
	var intEndDateYear = strFormEndDate.substring(6,10);
	//Set the date object parts according to the string values above: 
	newStartDate.setMonth(intStartDateMonth - 1); //Zero-based months;
	newStartDate.setDate(intStartDateDays);
	newStartDate.setYear(intStartDateYear);
	newEndDate.setMonth(intEndDateMonth - 1); //Zero-based months;
	newEndDate.setDate(intEndDateDays);
	newEndDate.setYear(intEndDateYear);
	//Set the value into a variable:
	var intDateDifference = getDateDifference(newStartDate, newEndDate);
	//If it's less than zero:
	if (intDateDifference < 0) {
		//Change it to 0:
		intDateDifference = 0;
		//Set it to 0 in the form:
		document.getElementById("date_difference").value = intDateDifference;
		//Alert the user:
		window.alert('\'' + strEndLabel + '\' cannot be before \'' + strStartLabel + '\', so it will be set equal to \'' + strStartLabel + '\'.');
		//Make the end date the same as the beginning:
		changeDateMoveEndDate();
	} else {
		//If it's equal or greater than the start date, then set the date difference:
		document.getElementById("date_difference").value = intDateDifference;
	}
}

function getDateDifference(date1, date2) {
	var DSTAdjust = 0;
	// constants used for our calculations below
	var oneMinute = 1000 * 60;
	var oneDay = oneMinute * 60 * 24;
	// equalize times in case date objects have them
	date1.setHours(0);
	date1.setMinutes(0);
	date1.setSeconds(0);
	date2.setHours(0);
	date2.setMinutes(0);
	date2.setSeconds(0);
	// take care of spans across Daylight Saving Time changes
	if (date2 > date1) {
		DSTAdjust = (date2.getTimezoneOffset() - date1.getTimezoneOffset()) * oneMinute;
	} else {
		DSTAdjust = (date1.getTimezoneOffset() - date2.getTimezoneOffset()) * oneMinute;
	}
	var diff = (date2.getTime() - date1.getTime()) - DSTAdjust;
	return Math.ceil(diff/oneDay);
}

// Disable Submit button after click, but still submit the form.
function disable_submit() {
	document.getElementById("btnSaveDisabled").style.display = "inline";
	document.getElementById("btnSave").style.display = "none";
	document.getElementById("btnCancelDisabled").style.display = "inline";
	document.getElementById("btnCancel").style.display = "none";
	document.getElementById("spanFormSubmitted").style.display = "inline";
	}

//Validation stuff
function validateTime(fieldID, fieldName, formID) {
	var isValid = true;
	var strMessage = "";
	var strTime = document.getElementById(fieldID).value;
	var re = /^\d{1,2}[:]\d{2}$/;
	var strFieldName = fieldName;
	if (strFieldName == "") {
		strFieldName = "The time";
	}
	if (re.test(strTime)) {
		//If this passes the RegEx test, test to make sure the parts are no more than 12:59.
		var intHourEnd = strTime.indexOf(':');
		var intMinuteStart = intHourEnd + 1;
		var intMinuteEnd = strTime.length;
		var intHour = strTime.substring(0,intHourEnd);
		var intMinute = strTime.substring(intMinuteStart,intMinuteEnd);
		if ((intHour > 12) || (intHour == 0)) {
			strMessage = strMessage + "The hour must be between 1 and 12. ";
			isValid = false;
		}
		if (intMinute > 59) {
			isValid = false;
			strMessage = strMessage + "The minutes must be between 0 and 59. ";
		}
	} else {
		strMessage = strMessage + "It does not appear to be a valid time (e.g. 12:34 PM). ";
		isValid = false;
	}
	if (isValid != true) {
		alert(strFieldName + ' is not valid. ' + strMessage);
		//FIELD FOCUS NEEDED HERE! ;)
	}
}

//WorkSpace Podcast/Media Player
function openPodcastPlayer(channelid, episodeid) {
	var strURL = "/?go=podcast&action=player&channelid=" + channelid + "&episodeid=" + episodeid;
	var workspacePodcastPlayerUndefined = (typeof workspacePodcastPlayer == "undefined");
	if (workspacePodcastPlayerUndefined || workspacePodcastPlayer.closed) {
		workspacePodcastPlayer = window.open(strURL, "workspacePodcastPlayer", "menubar=0,status=0,location=0,directories=0,resizable=1,screenX=100,screenY=120,height=550px,width=750px");
	} else {
		workspacePodcastPlayer.focus();
		workspacePodcastPlayer = window.open(strURL, "workspacePodcastPlayer", "menubar=0,status=0,location=0,directories=0,resizable=1,screenX=100,screenY=120,height=550px,width=750px");
	}
}


//Asset Workspace Stuff
function openAssetBrowser(folderid, typeid, selecttype) {
	var strURL = "/?go=assetmanager&action=assetbrowserdialog&folderid=" + folderid + "&typeid=" + typeid + "&select=" + selecttype;
	var assetManagerUndefined = (typeof assetManagerWindow == "undefined");
	if (assetManagerUndefined || assetManagerWindow.closed) {
		assetManagerWindow = window.open(strURL, "assetworkspace", "menubar=0,status=0,location=0,directories=0,resizable=1,screenX=100,screenY=120,height=550px,width=800px");
	} else {
		assetManagerWindow.focus();
		assetManagerWindow = window.open(strURL, "assetworkspace", "menubar=0,status=0,location=0,directories=0,resizable=1,screenX=100,screenY=120,height=550px,width=800px");
	}
}
function closeAssetBrowser() {
	var blnConfirm = confirm("Are you sure you want to close the Asset Browser and cancel your selection?");
	if (blnConfirm == true) {
		window.close();
	} else {
		return false;
	}
}
function openAssetUpload(folderid, typeid, selecttype) {
	var strURL = "/?go=assetmanager&action=asseteditor&folderid=" + folderid + "&typeid=" + typeid + "&select=" + selecttype;
	location.href = strURL;
}
function openAssetUploadDialog(folderid, typeid, selecttype) {
	var strURL = "/?go=assetmanager&action=asseteditordialog&folderid=" + folderid + "&typeid=" + typeid + "&select=" + selecttype;
	location.href = strURL;
}
function toggleAssetItem(assetid, asseturl, assetwidth, assetheight, assetalt, selecttype) {
	if (selecttype == "single") {
		var assetIdItem = document.getElementById("assetIdList").value;
		var assetElementIdNew = "assetListItem" + assetid;
		var assetElementIdCurrent = "assetListItem" + assetIdItem;
		var assetSelectLinkIdNew = "toggleAssetItemLink" + assetid;
		var assetSelectLinkIdCurrent = "toggleAssetItemLink" + assetIdItem;
		document.getElementById(assetElementIdNew).className = "assetListItemSelected";
		document.getElementById("assetIdList").value = assetid;
		document.getElementById("assetUrlField").value = asseturl;
		document.getElementById("assetWidthField").value = assetwidth;
		document.getElementById("assetHeightField").value = assetheight;
		document.getElementById("assetAltField").value = assetalt;
		document.getElementById(assetSelectLinkIdNew).innerHTML = "selected";
		if (document.getElementById(assetElementIdCurrent) != null) {
			if (assetIdItem != assetid) {
				document.getElementById(assetElementIdCurrent).className = "assetListItem";
				document.getElementById(assetSelectLinkIdCurrent).innerHTML = "select";
			}
		}
	} else {
		var assetWasChecked = false; //used to decide what to do below.
		var assetIdList = document.getElementById("assetIdList").value;
		var assetElementId = "assetListItem" + assetid;
		var assetSelectLinkId = "toggleAssetItemLink" + assetid;
		var newAssetIdList = "";
		var assetIdArray = assetIdList.split(",");
		for (var i=0; i<assetIdArray.length; i++) {
			//do something by accessing assetIdArray[i];
			if (assetIdArray[i] == assetid) {
				assetWasChecked = true;
				//change its class to unselected
				document.getElementById(assetElementId).className = "assetListItem";
				document.getElementById(assetSelectLinkId).innerHTML = "select";
			} else {
				//if this is in the list but not the item in question, add it to the new list;
				if (newAssetIdList == "") {
					newAssetIdList = assetIdArray[i];
				} else {
					newAssetIdList = newAssetIdList + "," + assetIdArray[i];
				}
			}
		}
		if (assetWasChecked == false) {
			//add it to the field's list
			if (newAssetIdList == "") {
				newAssetIdList = assetid;
			} else {
				newAssetIdList = newAssetIdList + "," + assetid;
			}
			//change its class to selected
			document.getElementById(assetElementId).className = "assetListItemSelected";
			document.getElementById(assetSelectLinkId).innerHTML = "deselect";
		}
		//set the form's hidden field:
		document.getElementById("assetIdList").value = newAssetIdList;
	}
}
//This script is here to change the "go" field value of the form generated on the calling page.
function changeDialogFolderAssetTypeID(typeid, selecttype) {
	document.getElementById("jumpToFolderGo").value = "assetmanager&action=assetbrowserdialog&typeid=" + typeid + "&select=" + selecttype;
	switch(typeid) {
		case 1:
			showMyFormTab('Images','Audio','Video','PDFs','Other');
			break;
		case 2:
			showMyFormTab('Audio','Images','Video','PDFs','Other');
			break;
		case 3:
			showMyFormTab('Video','Images','Audio','PDFs','Other');
			break;
		case 4:
			showMyFormTab('PDFs','Images','Audio','Video','Other');
			break;
		case 5:
			showMyFormTab('Other','Images','Audio','Video','PDFs');
			break;
		default:
			showMyFormTab('Images','Audio','Video','PDFs','Other');
			break;
	}
}
//Altered for asset manager in main browser window
function changeFolderAssetTypeID(typeid, selecttype) {
	document.getElementById("jumpToFolderGo").value = "assetmanager&action=assetbrowser&typeid=" + typeid + "&select=" + selecttype;
	switch(typeid) {
		case 1:
			showMyFormTab('Images','Audio','Video','PDFs','Other');
			break;
		case 2:
			showMyFormTab('Audio','Images','Video','PDFs','Other');
			break;
		case 3:
			showMyFormTab('Video','Images','Audio','PDFs','Other');
			break;
		case 4:
			showMyFormTab('PDFs','Images','Audio','Video','Other');
			break;
		case 5:
			showMyFormTab('Other','Images','Audio','Video','PDFs');
			break;
		default:
			showMyFormTab('Images','Audio','Video','PDFs','Other');
			break;
	}
}

function deleteSelectedAsset(assetid) {
	var blnConfirm = confirm("Are you sure you want to delete this asset? THIS CANNOT BE UNDONE!");
	if (blnConfirm == true) {
		var assetElementId = "assetListItem" + assetid;
		var thisAssetNode = document.getElementById(assetElementId);
		var strCFNavLink = "/?go=assetmanager&action=deleteasset&id=" + assetid;
		var strCFNavID = "assetUtilityItems" + assetid;
		ColdFusion.navigate(strCFNavLink, strCFNavID);
		thisAssetNode.parentNode.removeChild(thisAssetNode);
		document.getElementById("assetBrowserPreviewPane").innerHTML = "&nbsp;";
		return true;
	} else {
		return false;
	}
}
function changeAssetPreview(assetid) {
	var assetPreviewID = "assetBrowserPreviewHidden" + assetid;
	document.getElementById("assetBrowserPreviewPane").innerHTML = document.getElementById(assetPreviewID).innerHTML;
}
function toggleReplaceAssetUpload(chkBoxID,showID,hideID) {
	var showBlock = document.getElementById(showID);
	var hideBlock = document.getElementById(hideID);
	var checkBox = document.getElementById(chkBoxID);
	if (showBlock!=null) {
		if (checkBox!=null) {
			if (checkBox.checked == true) {
				showBlock.style.display = "block";
				hideBlock.style.display = "none";
			}
			else {
				hideBlock.style.display = "block";
				showBlock.style.display = "none";
			}
		}
	}
}
function deleteAssetFile(strRelPath, strFileName, cfdivID) {
	var blnConfirm = confirm("Are you sure you want to delete this file? THIS CANNOT BE UNDONE!");
	if (blnConfirm == true) {
		var strCFNavLink = "/?go=assetmanager&action=deletefile&path=" + strRelPath + "&file=" + strFileName;
		ColdFusion.navigate(strCFNavLink, cfdivID);
		return true;
	} else {
		return false;
	}
}
function selectSingleAssetContinue() {
	var assetUrl = document.getElementById("assetUrlField").value;
	var assetWidth = document.getElementById("assetWidthField").value;
	var assetHeight = document.getElementById("assetHeightField").value;
	var assetAlt = document.getElementById("assetAltField").value;
	if (assetUrl == "") {
		alert("Please select an asset to continue.");
		return false;
	} else {
		window.opener.SetUrl(assetUrl, assetWidth, assetHeight, assetAlt);
		window.close();
	}
}
function selectMultipleAssetsContinue() {
	var assetIdList = document.getElementById("assetIdList").value;
	//Multiple items are added to a gallery as follows:
	opener.document.forms["hiddenAssetsForm"].hiddenAssetsIds.value = assetIdList;
	opener.document.forms["hiddenAssetsForm"].submit();
	window.close();
}
function cancelContentSubmission(strGo,strFolderID) {
	var blnConfirm = confirm("Are you sure you want to cancel without saving your changes?");
	if (blnConfirm == true) {
		var strCFNavLink = "/?go=" + strGo + "&folderid=" + strFolderID;
		ColdFusion.navigate(strCFNavLink);
		return true;
	} else {
		return false;
	}
}
function limitTextbox(fieldid, counterid, charlimit) {
	var objTextarea = document.getElementById(fieldid);
	var objCounter = document.getElementById(counterid);
	if (objTextarea.value.length > charlimit) {
		objTextarea.value = objTextarea.value.substring(0, charlimit);
	} else {
		objCounter.innerHTML = charlimit - objTextarea.value.length;
		var objWrapperID = fieldid + "-counter-wrapper";
		var objWrapper = document.getElementById(objWrapperID);
		if (objTextarea.value.length > (charlimit - 11)) {
			objWrapper.style.color = '#FF0000';
		} else {
			objWrapper.style.color = '#555555';
		}
	}
}
function openPrintVersion(url) {
//	var strURL = "/?go=assetmanager&action=assetbrowserdialog&folderid=" + folderid + "&typeid=" + typeid + "&select=" + selecttype;
	var printVersionUndefined = (typeof printVersionWindow == "undefined");
	if (printVersionUndefined || printVersionWindow.closed) {
		printVersionWindow = window.open(url, "printworkspace", "menubar=0,status=1,location=0,directories=0,scrollbars=1,resizable=0,screenX=50%,screenY=50%,height=450px,width=703px");
	} else {
		printVersionWindow.focus();
		printVersionWindow = window.open(url, "printworkspace", "menubar=0,status=1,location=0,directories=0,scrollbars=1,resizable=0,screenX=50%,screenY=50%,height=450px,width=703px");
	}
}

/* YUI Stuff */
function openModalGalleryView(url) {
	window.open(url, "galleryViewerWindow", "width=750,height=600,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=yes,copyhistory=no,modal=yes");
}
function resizeModalGalleryView() {
	var screenWidth = 750;
	var screenHeight = 600;
	window.resizeTo(screenWidth, screenHeight);
	window.moveTo(
		Math.round((screen.availWidth - screenWidth) / 2),
		Math.round((screen.availHeight - screenHeight) / 2));
}