// JavaScript functions required, and included automatically, by intranet_include.asp

function initHTMLEditBoxes() {
/*
Add to onload event of BODY tag so that all HTMLEdit boxes on the page will be initialized when
page loads via hidden DIV tags generated by HTMLEditBox routine.
Using innerText to access DIV tags because had to use Server.HTMLEncode when populating them.
*/
	var all = document.all;
	var htmleditboxes = all('htmleditbox');
	if (htmleditboxes) {
		if (htmleditboxes.length) {
			var htmleditboxname;
			for (var i=0;i<htmleditboxes.length;i++) {
				htmleditboxname = htmleditboxes[i].name;
				all('html'+htmleditboxname).value = all('div'+htmleditboxname).innerText;
			}
		} else {
			all('html'+htmleditboxes.name).value = all('div'+htmleditboxes.name).innerText;
		}
	}
}

function copyHTMLEditBoxes() {
// Copies the value of all HTMLEdit boxes on the page to their corresponding hidden TEXTAREA's.
// Must be called in validate() function before actually validating the TEXTAREA contents.
	var all = document.all;
	var htmleditboxes = all('htmleditbox');
	if (htmleditboxes) {
		if (htmleditboxes.length) {
			var htmleditboxname;
			for (var i=0;i<htmleditboxes.length;i++) {
				htmleditbox = htmleditboxes[i];
				htmleditbox.value = all('html'+htmleditbox.name).value;
			}
		} else {
			htmleditboxes.value = all('html'+htmleditboxes.name).value;
		}
	}
}

function resetHTMLEditBoxes() {
// Should be called after resetting the form in resetCallBack routine so that all HTMLEdit boxes will be set back when user resets.
	var all = document.all;
	var htmleditboxes = all('htmleditbox');
	if (htmleditboxes) {
		if (htmleditboxes.length) {
			for (var i=0;i<htmleditboxes.length;i++)
				all('html'+htmleditboxes[i].name).reset();
		} else {
			all('html'+htmleditboxes.name).reset();
		}
	}
}

function selFile(fileType,hiddenIDName,hiddenURLName,displayName) {
// Enables user to pick a file of the specified type via standard dialog and puts selected values into specified fields.
	var file = showModalDialog("/scriptlet/selfile.asp?Context=I&FileType="+fileType+"&IDFile="+document.all(hiddenIDName).value+"&FileURL="+escape(document.all(hiddenURLName).value),"","dialogWidth:600px; dialogHeight:450px; status:no; help:no");
	if (file != null) {
		if (file[1] != null) {
			document.all(hiddenIDName).value = file[1];
			document.all(hiddenURLName).value = '';
			document.all(displayName).value = file[4];
		} else {
			document.all(hiddenIDName).value = '';
			document.all(hiddenURLName).value = file[3];
			document.all(displayName).value = file[3];
		}
		parent.updateChange(true);
	}
}

function selColor(colorBoxName) {
// Enables user to pick a color via standard dialog and puts selected value into specified field.
	try {
		var color = showModalDialog("/scriptlet/selcolor.asp",document.all[colorBoxName].value,"dialogWidth:600px; dialogHeight:450px; status:no; help:no");
		if (color != null) {
			document.all[colorBoxName+'_display'].style.backgroundColor = color;
			document.all[colorBoxName].value = color;
			parent.updateChange(true);
		}
	}
	catch(e) {
		if (color != null) {
			alert(color + " is not a valid color.  Please specify a different value.");
			document.all[colorBoxName].focus();
		}
	}
}

function displayColor(colorBoxName) {
// Displays color found in colorBoxName as background color of colorBoxName+'_preview' table cell.
	try {
		document.all[colorBoxName+'_display'].style.backgroundColor = document.all[colorBoxName].value;
	}
	catch (e) {
		alert(document.all[colorBoxName].value + " is not a valid color.  Please specify a different value.");
		document.all[colorBoxName].focus();
	}
}

function resetColors() {
// Should be called after resetting the form in resetCallBack routine so that the original colors will be displayed when user resets.
	var colorboxes = document.all('colorbox');
	if (colorboxes) {
		if (colorboxes.length) {
			for (var i=0; i<colorboxes.length; i++)
				displayColor(colorboxes[i].name);
		} else {
			displayColor(colorboxes.name);
		}
	}
}

function resetLinkDetails() {
// Re-shows/hides the overridden link appearance sections after the user resets the main page.
// Called after form.reset in resetCallBack routine.
	var all = document.all;
	var usedefaults = all('usedefaults');
	if (usedefaults) {
		if (usedefaults.length) {
			for (var i=0;i<usedefaults.length;i++)
				all('tbl'+usedefaults[i].lang+'Override').style.visibility = usedefaults[i].checked?'hidden':'';
		} else {
			all('tbl'+usedefaults.lang+'Override').style.visibility = usedefaults.checked?'hidden':'';
		}
	}
}
