//<!--

function checkDelete(type)
{
	var addltext = '';
	if (type == 'vocabulary')
		addltext = '\r(Note: This will also delete any related terms!)';
	return confirm("Are you sure you want to delete this "+type+"?"+addltext);
}

function checkTermName(theForm)
{
	if (theForm.term_name.value == '') {
		alert("You must specify a name for your new term first.");
		theForm.term_name.focus();
		return false;
	}
}

function changeRowColor(id,checkbox)
{
	if (checkbox.checked == true) {
		id.className = 'rowOn';
	} else {
		id.className = 'rowOff';
	}
}

function flagFileLine(rowid,itemid)
{
	currentrow = eval(rowid);
	currentrow.className = 'rowOn';
	if (document.holder.prevSelected.value) {
		prevrow = eval(document.holder.prevSelected.value);
		prevrow.className = 'rowOff';
	}
	document.holder.prevSelected.value = rowid;
}

function checkUserRecord(theField)
{
	theForm = theField.form;
	username = theForm.fname.value+' '+theForm.lname.value;
	if (theForm.deleteuser.checked == true) {
		return confirm('Are you sure you want to delete the user "'+username+'"?');
	}
}

function flagChangedField(theField)
{
	if (theField.type == 'select') {
		theForm = theField.form;
		for (var i = 0; i < document.theForm.theField.length; i++) {
			if (document.theForm.theField.options[i].selected != document.theForm.theField.options[i].defaultSelected)
				changeField = true;
				break;
		}
		if (changeField == true)
			theField.className = 'rowOn';
	} else {
		if (theField.value != theField.defaultValue)
			theField.className = 'rowOn';
	}
}

function toggleVocabularyList(vocID)
{
	var listObj = document.getElementById('vocabList'+vocID);
	var imgObj = document.getElementById('vocabToggle'+vocID);
	state = listObj.style.display;
	if (state == 'none') {
		listObj.style.display = 'block';
		imgObj.src = '/cms/images/directoryicons/collapse.gif';
	} else if (state == 'block') {
		listObj.style.display = 'none';
		imgObj.src = '/cms/images/directoryicons/expand.gif';
	}
}

// Scripts for 'Manage Stories' area

function getRowClassName(id,theCheckedState)
{
	if (theCheckedState == true)
		return 'rowHL';
	else
		return 'row'+((id % 2 > 0) ? 'Off' : 'On');
}

function fixCheckbox(theField,id,cols)
{
	theForm = theField.form;
	if (theField.value != theField.defaultValue) theForm['iid['+id+']'].checked = true;
}

function updateCheckbox(checkbox,rowid)
{
	currentrow = eval('row'+rowid);
	currentrow.className = getRowClassName(rowid,checkbox.checked);
}

function commentWindow(itemID)
{
	commentsPopUp = window.open('comments.php?iid='+itemID, 'Feedback', 'toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=1,width=520,height=400');
	commentsPopUp.focus();
}

function confirmDelete()
{
	return confirm('Are you sure you want to delete these items?');
}

function showPreview(iid,editorapp)
{
	previewPopUp = window.open('../'+editorapp+'/preview/'+iid+'.html', 'preview', 'toolbar=1,location=1,directories=0,status=1,menubar=0,scrollbars=1,resizable=1'); // ,width=820,height=600
	previewPopUp.moveTo(10,30);
	previewPopUp.focus();
}

function getSplashPageSelections(loop,theForm)
{
	cidsList = theForm['cids['+loop+']'].value;
	cLevelPopUp = window.open('c_level_assignment.php?loop='+loop+'&cidsList='+cidsList, 'c-level', 'toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=1,width=640,height=480');
	cLevelPopUp.focus();
}

function checkSearchField(theField)
{
	if (theField.value == 'keyword(s)')
		theField.value = '';
}

function checkSearchForm(theForm)
{
	if (theForm.str.value == 'keyword(s)' || theForm.str.value == '') {
		alert('Please enter a keyword.');
		return false;
	} else {
		return true;
	}
}

function scheduleStory(loop)
{
	startdate = document.modform['startdate['+loop+']'].value;
	enddate = document.modform['enddate['+loop+']'].value;
	schedulePopUp = window.open('schedule.php?loop='+loop+'&startdate='+startdate+'&enddate='+enddate, 'schedule', 'toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=1,width=250,height=200');
	schedulePopUp.moveTo(10,30);
	schedulePopUp.focus();
}

function checkScheduleDates(theForm)
{
	var sday = theForm.sday.options[theForm.sday.selectedIndex].value;
	var smonth = theForm.smonth.options[theForm.smonth.selectedIndex].value;
	var syear = theForm.syear.options[theForm.syear.selectedIndex].value;

	if (sday != '' && smonth != '' && syear != '') {
		checkStart = new Date ();
		checkStart.setFullYear(syear, smonth, sday);
		startint = checkStart.getTime();
	} else {
		startint = 0;
	}

	var eday = theForm.eday.options[theForm.eday.selectedIndex].value;
	var emonth = theForm.emonth.options[theForm.emonth.selectedIndex].value;
	var eyear = theForm.eyear.options[theForm.eyear.selectedIndex].value;

	if (eday != '' && emonth != '' && eyear != '') {
		checkEnd = new Date ();
		checkEnd.setFullYear(eyear, emonth, eday);
		endint = checkEnd.getTime();
	} else {
		endint = 0;
	}
	
	if (startint > 0 && endint > 0) { // 2 valid dates; comparison is necessary
		datediff = new Number (endint-startint);
		if (datediff < 0) {
			alert('The end date must be later than the start date.');
			return false;
		}
	} else if (startint == 0 && endint == 0) {
		alert('You must choose a start date AND/OR an end date.');
		return false;
	}
	return true;
}

function resetScheduleDateGroup(field)
{
	if (field.selectedIndex == 0) {
		fieldname = new String(field.name);
		prefix = fieldname.charAt(0);
		field.form[prefix+'month'].selectedIndex = 0;
		field.form[prefix+'day'].selectedIndex = 0;
		field.form[prefix+'year'].selectedIndex = 0;
	}
}

function checkInternalLink(theForm,formType)
{
	var checkWhiteSpace = theForm.phrase.value.replace(/[ ]+/i,"");

	if (formType == 'delete') {
		return confirm('Are you sure you want to delete this keyword?');
	}
	else if (checkWhiteSpace.length < 2) {
		alert('Keywords must be at least 2 characters in length.');
		theForm.phrase.focus();
		return false;
	}
}

// site-building scripts

function confirmSiteMapUpdate()
{
	return confirm("Are you sure you want to publish the site map?\n(WARNING: This cannot be undone!)");
}

// blog-management scripts

function confirmBlogCommentDelete()
{
	return confirm("Are you sure you want to delete this comment?");
}


// scripts for surveys / polls

function confirmSetupCancel()
{
	return confirm('Are you sure you want to cancel?');
}

function confirmSetupComplete(theMode)
{
	if (theMode != 'edit' ) {
			return confirm('Are you sure you want to finalize this survey\rand add it to the database?');
	}
}

function confirmSurveyDelete()
{
	return confirm('Are you sure you want to delete this survey?\r(All questions and responses will be deleted also).')
}

function confirmSurveyReset()
{
	return confirm('Are you sure you want to reset this survey?\r(All responses will be deleted).');
}

function downloadResults(theSurveyID)
{
	popupWin = window.open('survey_download.php?sid='+theSurveyID, theSurveyID, 'resizable=yes,scrollbars=no,width=300,height=100')
}

function viewTemplate(templateName)
{
	popupWin = window.open(templateName, 'templateView', 'resizable=yes,scrollbars=no,toolbar=no,width=800,height=600')
}

function formCheck()
{
	if(document.step1.theQuestions.value!="" && document.step1.numQuestions.value != 0 && document.step1.numQuestions.value != "" && document.step1.poll_name.value!="") {
		return true;
	}
	else {
		alert("Invalid # of options or empty textbox");
		return false
	}
}

// Functions used specifically on survey form pages.

// Toggle radios/selects in conjunction with 'other' fields

function toggle_multi(theForm,qid,type)
{
	if (type == 0 && theForm['other'+qid]) {								// a click on a radio: empty 'other' field
		theForm['other'+qid].value = "";
		theForm['other'+qid].blur();
	} else if (type == 1 && theForm['ans'+qid].type == 'select-one') {		// a click in the 'other' field: reset select
		theForm['ans'+qid].selectedIndex = 0;
	} else if (type == 1) {													// a click in the 'other' field: reset radio
		for (x=0; x < theForm['ans'+qid].length; x++) {
			theForm['ans'+qid][x].checked = false;
		}
	}
}

// preload images -- mainly for ie
function preloadImages()
{
	var d=document;
	if(d.images) {
		if(!d.p) d.p=new Array();
		var i, j=d.p.length, a=preloadImages.arguments;
		for(i=0; i<a.length; i++)
			if (a[i].indexOf("#")!=0) {
				d.p[j]=new Image;
				d.p[j++].src=a[i];
			}
	}
}

preloadImages('/cms/images/directoryicons/expand.gif', 
				 '/cms/images/directoryicons/collapse.gif', 
				 '/cms/images/directoryicons/end.gif');
//-->

