
var ldcms_js_debug_switch = false ;

function dates_check(form_id,select_name_prefix,start_end) {

	var formref = document.getElementById(form_id);
	var selects = ['year','month','day','hour','min'];
	var datetypes = ['start','end'];
	var datevals = ['',''];

	if ( formref.elements[select_name_prefix + 'end' + '_hour'].value == '' || formref.elements[select_name_prefix + 'end' + '_min'].value == '' ) {
		// only work on dates
		selects = ['year','month','day'];
	}
	
	for (n = 0; n < datetypes.length; n++) {
		
		for (i = 0; i < selects.length; i++) {
			var temp_value = formref.elements[select_name_prefix + datetypes[n] + '_' + selects[i]].value;
			if (temp_value == '9999') {
				datevals[n] += '0000';
			} else if (temp_value == '99') {
				datevals[n] += '00';
			} else if (temp_value == '') {
				if (selects[i] == 'year') {
					datevals[n] += '0000';
				} else {
					datevals[n] += '00';
				}
			} else {
				datevals[n] += temp_value;
			}
		}
		if (ldcms_js_debug_switch) {
			alert(datetypes[n] + ': ' + datevals[n]);
		}
	}

	if (datevals[0] > datevals[1]) {
		if (start_end == 'end') {
			datetypes = ['end','start'];
		}
		for (i=0; i<selects.length; i++) {
			formref.elements[select_name_prefix + datetypes[1] + '_' + selects[i]].selectedIndex = formref.elements[select_name_prefix + datetypes[0] + '_' + selects[i]].selectedIndex;
		}
	}

}


function showimage()
{
if (!document.images)
return
document.images.con_imgs.src=
document.con_form.con_img.options[document.con_form.con_img.selectedIndex].value
}


function checkAll(formId, cName, check ) {
	for (i=0,n=formId.elements.length;i<n;i++)
	if (formId.elements[i].className.indexOf(cName) !=-1)
		formId.elements[i].checked = check;
}


function openWin(url,name) {
	window.open(url, help, 'Width=300,Height=450,SCROLLBARS=1,RESIZABLE=1')
}


function icon_help_win(help_url) {
	var mainWin=null;
	if (navigator.appName == "Microsoft Internet Explorer") {
		mainWin = window.open(help_url, 'help', 'Width=300,Height=450,top=0,left=0,menubar=0,toolbar=0, SCROLLBARS=1');
   	}
	if (navigator.appName == "Netscape") {
		mainWin = window.open(help_url, 'help', 'Width=300,Height=450,top=0,left=0,menubar=0,toolbar=0, scrollbars=yes');
   	}	
   	self.name = "main";
}

function validate_mailer_form() {
	if ((! document.getElementById('choose_individuals_all') ) || document.getElementById('choose_individuals_all').checked) {
		// option to send to all users in selected groups is checked, or doesn't exist on the page meaning that we've got a list of users to choose from
		if (document.getElementById('mailing_subject').value.length > 0) {
			return confirm('Send broadcast e-mail now?');
		} else {
			alert('You must enter an e-mail subject before attempting to send your message.');
			document.getElementById('mailing_subject').focus();
			return false;
		}
	} else {
		return true;
	}
}




/**
 * This script contains embed functions for common TinyMCE plugins. This scripts are complety free to use for any purpose.
 */

function writeFlash(p) {
	writeEmbed(
		'D27CDB6E-AE6D-11cf-96B8-444553540000',
		'http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0',
		'application/x-shockwave-flash',
		p
	);
}

function writeShockWave(p) {
	writeEmbed(
	'166B1BCA-3F9C-11CF-8075-444553540000',
	'http://download.macromedia.com/pub/shockwave/cabs/director/sw.cab#version=8,5,1,0',
	'application/x-director',
		p
	);
}

function writeQuickTime(p) {
	writeEmbed(
		'02BF25D5-8C17-4B23-BC80-D3488ABDDC6B',
		'http://www.apple.com/qtactivex/qtplugin.cab#version=6,0,2,0',
		'video/quicktime',
		p
	);
}

function writeRealMedia(p) {
	writeEmbed(
		'CFCDAA03-8BE4-11cf-B84B-0020AFBBCCFA',
		'http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0',
		'audio/x-pn-realaudio-plugin',
		p
	);
}

function writeWindowsMedia(p) {
	p.url = p.src;
	writeEmbed(
		'6BF52A52-394A-11D3-B153-00C04F79FAA6',
		'http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=5,1,52,701',
		'application/x-mplayer2',
		p
	);
}

function writeEmbed(cls, cb, mt, p) {
	var h = '', n;

	h += '<object classid="clsid:' + cls + '" codebase="' + cb + '"';
	h += typeof(p.id) != "undefined" ? 'id="' + p.id + '"' : '';
	h += typeof(p.name) != "undefined" ? 'name="' + p.name + '"' : '';
	h += typeof(p.width) != "undefined" ? 'width="' + p.width + '"' : '';
	h += typeof(p.height) != "undefined" ? 'height="' + p.height + '"' : '';
	h += typeof(p.align) != "undefined" ? 'align="' + p.align + '"' : '';
	h += '>';

	for (n in p)
		h += '<param name="' + n + '" value="' + p[n] + '">';

	h += '<embed type="' + mt + '"';

	for (n in p)
		h += n + '="' + p[n] + '" ';

	h += '></embed></object>';

	document.write(h);
}


// JQUERY STUFF

var arrow_up_html = '&#x25BC;' ;
var arrow_down_html = '&#x25B2;' ;

$(document).ready(function(){

	// MAKE FIELDSETS COLLAPSIBLE

	$("fieldset.collapsible legend").append('<span class="collapse-arrow"> ' + arrow_down_html + '</span>').wrapInner('<a href="#"></a>');

	$("fieldset.collapsible legend a").click( function(){
		var thisfieldset = $(this).parent().parent() ;
		thisfieldset.children().filter("p,table,div").toggle('fast');
		if ( thisfieldset.hasClass('collapsed') ) {
			thisfieldset.find('.collapse-arrow').html(' ' + arrow_down_html);
			thisfieldset.removeClass('collapsed');
			$(this).attr('title','Click to show');
		} else {
			thisfieldset.find('.collapse-arrow').html(' ' + arrow_up_html);
			thisfieldset.addClass('collapsed');
			$(this).attr('title','Click to hide');
		}
		return false;
	} );

	// TOGGLE UP/DOWN ARROW ON HOVER
	$("fieldset.collapsible legend a").hover( function(){
		$(this).find('.collapse-arrow').html(' ' + ($(this).parent().parent().hasClass('collapsed') ? arrow_down_html : arrow_up_html));
	}, function(){
		$(this).find('.collapse-arrow').html(' ' + ($(this).parent().parent().hasClass('collapsed') ? arrow_up_html : arrow_down_html));
	} );

	// COLLAPSE ANY FIELDSETS THAT ARE MEANT TO START OUT COLLAPSED
	$('fieldset.collapsible').filter('.collapsed').find('legend a').trigger('click');

});