//
// Ajax & jQuery Functions
//

//
// Multi-variable AJAX GET function with replaces "id" with data returned from "page"
// Sends all inputs, textareas, etc. from "form"
// Jessica Voytek 05/2009
//

function getPHPAjax(id, page, form) {
	
	// format variables from the form into JSON style array
	vars = $("form#" + form).serialize();
	
	// send vars to page and then execute function which replaces id with data
	$.get(page, vars, function(data) {
    	$("#" + id).replaceWith(data);
	});
}

function postPHPAjax(id, page, form) {
	
	// format variables from the form into JSON style array
	vars = $("form#" + form).serialize();
	
	// send vars to page and then execute function which replaces id with data
	$.post(page, vars, function(data) {
    	$("#" + id).replaceWith(data);
	});
}

function getPHPAjax_CMS_Revert(div_id, page, content_id) {
	
	// format variables from the form into JSON style array
	// vars = $("form#" + form).serialize();
	
	// send vars to page and then execute function which puts the content in the right place
	$.get(page, { id: content_id, code: div_id }, function(data) {
    	$("#" + div_id).replaceWith(data);
	});
	
	// Change content_id in _save form
	$('#' + div_id + '_save input[name="content_id"]').val(content_id);

	// Change content_id in _publish form
	$('#' + div_id + '_publish input[name="content_id"]').val(content_id);

	// Change content_id in _publish form
	$('#' + div_id + '_edit input[name="content_id"]').val(content_id);
	
	// Change edit_type in _save form
	$('#' + div_id + '_save input[name="edit_type"]').val("revert");

}

//
// Other JavaScript Functions
//

function ValidateTrainingLogin() {
	form = document.user_lookup;
	
	// Required Fields
	// First Name, Email, Address, Phone Number
	if (form.firstname.value == "") {
		alert("Please supply your first name");
		return false;
	}

	if (form.s_email.value == "") {
		alert("Please supply your email address");
		return false;
	}

	if (form.s_address.value == "") {
		alert("Please supply your street address");
		return false;
	}

	if (form.s_phone1.value == "") {
		alert("Please supply your phone number");
		return false;
	}

	form.submit();
	return true;
}

function ValidateTrainingRecover() {
	form = document.contact_recover;
	
	// Required Fields
	// First Name, and Email
	if (form.r_firstname.value == "") {
		alert("Please supply your first name");
		return false;
	}

	if (form.r_email.value == "") {
		alert("Please supply your email address");
		return false;
	}

	postPHPAjax('user_recover_div','/common/ajax/trainingRecover_email.php','contact_recover');
	return true;
}

function loading(id) {
	$("#" + id).html("<p align=\"center\"><img src='/images/loading.gif' /><br />Loading...</p>");
}

function toggleDisplay(id) {
	$("#" + id).toggle();
}

function toggleVisibility(id) {
	if ($("#" + id).css("visibility") == "hidden") {
		$("#" + id).css("visibility", "visible");
	} else {
		$("#" + id).css("visibility", "hidden");
	}
}

function toggleInlineDisplay(id) {
	if ($("#" + id).css("display") == "none") {
		$("#" + id).css("display", "inline");
	} else {
		$("#" + id).css("display", "none");
	}
}

function toggleImgSrc(id, src1, src2) {
	if ($("#" + id).attr("src") == src1) {
		$("#" + id).attr("src", src2);
	} else {
		$("#" + id).attr("src", src1);
	}
}


function NewWindow(url, name, options) {
	mynewwindow = window.open(url, name, options);
	mynewwindow.document.close();
}

function show(id) {
	$("#" + id).css("display", "block");
}

function hide(id) {
	$("#" + id).css("display", "none");
}

function showInline(id) {
	$("#" + id).css("display", "inline");
}

function change(id, theclass) {
	$("#" + id).attr("class", theclass);
}

function writeTextField(id, text) {
	$("#" + id).attr("value", text);
}


function OnlineReg(regionid, eventtype) {
	// eventtype:
	// PE = Program Events
	// AT = Adult Training
	// OG = Older Girls
	// CM = Camps
	
//	sel = document.calendar.eventtype.selectedIndex;
//	eventtype = document.calendar.eventtype.options[sel].value;

	window.open('https://www2.e-council.net/code/onlinereg?council=636&Jumpto=Step2&Type=' + eventtype + '&regionid=' + regionid, 'remote', 'top=10,left=10,width=770,height=770,scrollbars=yes,resizable=yes,status=yes,menubar=no');
}

function OnlineEventReg(regionid, eventtype, month, year) {
	// eventtype:
	// PE = Program Events
	// AT = Adult Training
	// OG = Older Girls
	// CM = Camps
	
	window.open('https://www2.e-council.net/code/onlinereg/?council=636&Jumpto=Step2&Type=' + eventtype + '&regionid=' + regionid + '&month=' + month + '&year=' + year, 'remote', 'top=10,left=10,width=770,height=770,scrollbars=yes,resizable=yes,status=yes,menubar=no');
//	window.open('https://www2.e-council.net/code/onlinereg?council=625&Jumpto=Step2&Type=' + eventtype, 'remote', 'top=10,left=10,width=770,height=550,scrollbars=yes,resizable=yes,status=yes,menubar=no');
}

function bookmark(title,url) {
	//For Internet Explorer
	if (BrowserDetect.browser == "Explorer") {
		window.external.AddFavorite(url, title);
	//For Firefox
	} else if (BrowserDetect.browser == "Firefox") {
		window.sidebar.addPanel(title, url, "");
	//For Opera
	} else if (BrowserDetect.browser == "Opera") {
		var elem = document.createElement('a');
		elem.setAttribute('href',url);
		elem.setAttribute('title',title);
		elem.setAttribute('rel','sidebar');
		elem.click();
	} else if (BrowserDetect.browser == "Safari") {
		alert("To bookmark this page using Safari, press and hold the Command key and then press the D key.");
	}
}

function PageResults(formname, pagenum) {
	theform = eval("document." + formname);
	theform.pagenum.value = pagenum;
	theform.submit();
	return true;
}

function SortCols(formname, sortval, ascval) {
	var theform = eval("document." + formname);
	theform.sort.value = sortval;
	if (ascval == "asc") {
		theform.asc.value = "desc";
	} else {
		theform.asc.value = "asc";
	}
	theform.submit();
	return true;
}

function SubmitForm(formname, pagename) {
	theform = eval("document." + formname);
	theform.action = pagename;
	theform.submit();
	return true;
}

function SubmitFormSetVar(formname, pagename, varname, varvalue) {
	theform = eval("document." + formname);
	thevar = eval("document." + formname + "." + varname);
	thevar.value = varvalue;
	if (pagename != "") {
		theform.action = pagename;
	}
	theform.submit();
	return true;
}

function ShowHideCountry(divName, countrySelectName)
{
	var selectbox = eval("document." + countrySelectName);
	country = selectbox.options[selectbox.selectedIndex].value;
	if (country == "other") {
		showInline(divName);
	} else {
		hide(divName);
	}
}

function ShowHideStates(divUS, divCanada, divOther, countrySelectName)
{
	var selectbox = eval("document." + countrySelectName);
	country = selectbox.options[selectbox.selectedIndex].value;
	if (country == "USA") {
		show(divUS);
		hide(divCanada);
		hide(divOther);
	} else if (country == "Canada") {
		hide(divUS);
		show(divCanada);
		hide(divOther);
	} else {
		hide(divUS);
		hide(divCanada);
		show(divOther);
	}
}

var stateNames = [
	'Alabama', 'Alaska', 'Arizona', 'Arkansas', 'California',
	'Colorado', 'Connecticut', 'Delaware', 'Washington D.C.', 'Florida',
	'Georgia', 'Hawaii', 'Idaho', 'Illinois', 'Indiana',
	'Iowa', 'Kansas', 'Kentucky', 'Louisiana', 'Maine',
	'Maryland', 'Massachusetts', 'Michigan', 'Minnesota', 'Mississippi',
	'Missouri', 'Montana', 'Nebraska', 'Nevada', 'New Hampshire',
	'New Jersey', 'New Mexico', 'New York', 'North Carolina', 'North Dakota',
	'Ohio', 'Oklahoma', 'Oregon', 'Pennsylvania', 'Puerto Rico',
	'Rhode Island', 'South Carolina', 'South Dakota', 'Tennessee', 'Texas',
	'Utah', 'Vermont', 'Virginia', 'Washington', 'West Virginia',
	'Wisconsin', 'Wyoming'
];

var provinceNames = [
	'Alberta', 'British Columbia', 'Manitoba', 'New Brunswick', 'Newfoundland',
	'Nova Scotia', 'Northwest Territories', 'Ontario', 'Prince Edward Island', 'Quebec', 
	'Saskatchewan', 'Yukon Territory'
];

var stateCodes = [
	'AL', 'AK', 'AZ', 'AR', 'CA',
	'CO', 'CT', 'DE', 'DC', 'FL',
	'GA', 'HI', 'ID', 'IL', 'IN',
	'IA', 'KS', 'KY', 'LA', 'ME',
	'MD', 'MA', 'MI', 'MN', 'MS',
	'MO', 'MT', 'NE', 'NV', 'NH',
	'NJ', 'NM', 'NY', 'NC', 'ND',
	'OH', 'OK', 'OR', 'PA', 'PR',
	'RI', 'SC', 'SD', 'TN', 'TX',
	'UT', 'VT', 'VA', 'WA', 'WV',
	'WI', 'WY'
];

var provinceCodes = [
	'AB', 'BC', 'MB', 'NB', 'NF',
	'NS', 'NT', 'ON', 'PE', 'QC',
	'SK', 'YT'
];

function ReFillStates(countrysel, statesel)
{
	var countrybox = eval("document." + countrysel);
	var statebox = eval("document." + statesel);
	country = countrybox.options[countrybox.selectedIndex].value;
	
	statebox.options.length = 0;
	statebox.options[0] = new Option("(whole country)", "all");
	if (country == "USA") {
		for (i = 0;  i < stateNames.length;  i++) {
			statebox.options[i+1] = new Option(stateNames[i] + " (" + stateCodes[i] + ")", stateCodes[i]);
		}
	} else if (country == "Canada") {
		for (i = 0;  i < provinceNames.length;  i++) {
			statebox.options[i+1] = new Option(provinceNames[i] + " (" + provinceCodes[i] + ")", provinceCodes[i]);
		}
	}
}

function calPrev() {
	// Change thefunction to "prev"
	//$("#thefunction").attr("value", 'prev');
	
	// Add 1 month to from_year and from_month
	month = $("#from_month option:selected").text();
	
	if (month == "Jan") {
		$("#from_month option:last").attr("selected", true);
		$("#from_year option:selected").prev().attr("selected", true);
	} else {
		$("#from_month option:selected").prev().attr("selected", true);
	}

	// Load the Calendar
	postPHPAjax('the_calendar', '/common/ajax/getMasterCal.php', 'calendar');	
	
}

function calNext() {
	// Change thefunction to "next"
	//$("#thefunction").attr("value", 'next');
	
	// Subtract 1 month to from_year and from_month
	month = $("#from_month option:selected").text();
	
	if (month == "Dec") {
		$("#from_month option:first").attr("selected", true);
		$("#from_year option:selected").next().attr("selected", true);
	} else {
		$("#from_month option:selected").next().attr("selected", true);
	}
		

	// Load the Calendar
	postPHPAjax('the_calendar', '/common/ajax/getMasterCal.php', 'calendar');	

}

function submitMC() {
	$("#findevents_button").html("<img src='/images/loading.gif' />")
	postPHPAjax('the_calendar', '/common/ajax/getMasterCal.php', 'calendar');
}

function enableFindMC() {
	$("#findevents_button").html("<input type='button' name='findevents' value='&nbsp;&nbsp;Start Search&nbsp;&nbsp;' onclick='submitMC();' />")
}

function SUcalPrev() {
	// Change thefunction to "prev"
	//$("#thefunction").attr("value", 'prev');
	
	// Add 1 month to from_year and from_month
	month = $("#from_month option:selected").text();
	
	if (month == "Jan") {
		$("#from_month option:last").attr("selected", true);
		$("#from_year option:selected").prev().attr("selected", true);
	} else {
		$("#from_month option:selected").prev().attr("selected", true);
	}

	// Load the Calendar
	postPHPAjax('the_calendar', '/common/ajax/getSUCal.php', 'calendar');	
	
	
}

function SUcalNext() {
	// Change thefunction to "next"
	//$("#thefunction").attr("value", 'next');
	
	// Subtract 1 month to from_year and from_month
	month = $("#from_month option:selected").text();
	
	if (month == "Dec") {
		$("#from_month option:first").attr("selected", true);
		$("#from_year option:selected").next().attr("selected", true);
	} else {
		$("#from_month option:selected").next().attr("selected", true);
	}
		

	// Load the Calendar
	postPHPAjax('the_calendar', '/common/ajax/getSUCal.php', 'calendar');	

}

//
// Master Calendar Functions
// Jessica Voytek 05/2010
//

function toggleMCTypeSelect(id) {
	if (id == "month") {
		$("#month_select").css("display", "block");
		$("#list_select").css("display", "none");
	} else {
		$("#month_select").css("display", "none");
		$("#list_select").css("display", "block");
	}
}

function toggleCheckAll(domElement, theclass) {
	if (domElement.checked == false) {
		$('.' + theclass).attr('checked', false);	
	} else {
		$('.' + theclass).attr('checked', true);		
	}
}
function disableButton(theid){
	$("#" + theid).attr("disabled", "disabled");
}

function enableButton(theid){
	$("#" + theid).attr("disabled", "");
}


//Format phone numbers

function phoneFormat(style, theID) {

	phoneNumber = document.getElementById(theID);
	phoneNumberRaw = phoneNumber.value;

	if (phoneNumberRaw != "") {
		phoneNumberRaw = phoneNumberRaw.replace(new RegExp("\\.", "g"), "");
		phoneNumberRaw = phoneNumberRaw.replace(new RegExp("\\/", "g"), "");
		phoneNumberRaw = phoneNumberRaw.replace(/\\/g, "");
		phoneNumberRaw = phoneNumberRaw.replace(new RegExp("-", "g"), "");
		phoneNumberRaw = phoneNumberRaw.replace(new RegExp(" ", "g"), "");
		phoneNumberRaw = phoneNumberRaw.replace(/\(/g, "");
		phoneNumberRaw = phoneNumberRaw.replace(/\)/g, "");
		phoneNumberRaw = phoneNumberRaw.replace(new RegExp("[A-Z]", "g"), "");
		phoneNumberRaw = phoneNumberRaw.replace(new RegExp("[a-z]", "g"), "");
		
		ext = "";
		if (phoneNumberRaw.length >= 10) {
			if (phoneNumberRaw.length == 10) {
				suffix = phoneNumberRaw.slice(6);
			} else {
				suffix = phoneNumberRaw.slice(6,10);
				ext = phoneNumberRaw.slice(10);
			}
			prefix = phoneNumberRaw.slice(3,6);
			area = phoneNumberRaw.slice(0,3);	
			// 0 ##########
			if (style == 0) {
				phoneNumber.value = phoneNumberRaw;
			// 1 ###-###-####
			} else if (style == 1) {
				phoneNumber.value = area + "-" + prefix + "-" + suffix;
			// 2 ###.###.####
			} else if (style == 2) {
				phoneNumber.value = area + "." + prefix + "." + suffix;
	
			// 3 (###) ###-####
			} else if (style == 3) {
				phoneNumber.value = "(" + area + ") " + prefix + "-" + suffix;
			}
			
			if (ext != "") {
				phoneNumber.value += ", ext. " + ext;
			}
		
		} else {
			phoneNumber.value = "";
			alert("Phone Number is formatted incorrectly, please fix to continue.  Please include an area code.");
		}
	}
}

function addressFormat(style, theID) {


	address = document.getElementById(theID);
	addressRaw = address.value;

	if (style = 'ecouncil' && addressRaw != '') {
		addressRaw = addressRaw.replace(new RegExp("P\.O\. Box ", "gi"), "P O Box ");
		addressRaw = addressRaw.replace(new RegExp("PO Box ", "gi"), "P O Box ");
		addressRaw = addressRaw.replace(new RegExp("p\.o\. box ", "gi"), "P O Box ");
		addressRaw = addressRaw.replace(new RegExp("po box ", "gi"), "P O Box ");
		addressRaw = addressRaw.replace(new RegExp(" Alley", "gi"), " Aly");
		addressRaw = addressRaw.replace(new RegExp(" Annex", "gi"), " Anx");
		addressRaw = addressRaw.replace(new RegExp(" Avenue", "gi"), " Ave");
		addressRaw = addressRaw.replace(new RegExp(" ave\.", "gi"), " Ave");
		addressRaw = addressRaw.replace(new RegExp(" Boulevard", "gi"), " Blvd");
		addressRaw = addressRaw.replace(new RegExp(" Circle", "gi"), " Cir");
		addressRaw = addressRaw.replace(new RegExp(" Common", "gi"), " Cmn");
		addressRaw = addressRaw.replace(new RegExp(" Court", "gi"), " Ct");
		addressRaw = addressRaw.replace(new RegExp(" ct\.", "gi"), " Ct");
		addressRaw = addressRaw.replace(new RegExp(" Drive", "gi"), " Dr");
		addressRaw = addressRaw.replace(new RegExp(" Estate", "gi"), " Est");
		addressRaw = addressRaw.replace(new RegExp(" Expressway", "gi"), " Expy");
		addressRaw = addressRaw.replace(new RegExp(" Freeway", "gi"), " Fwy");
		addressRaw = addressRaw.replace(new RegExp(" Gateway", "gi"), " Gtwy");
		addressRaw = addressRaw.replace(new RegExp("Highway", "gi"), "Hwy");
		addressRaw = addressRaw.replace(new RegExp("Hwy\.", "gi"), "Hwy");
		addressRaw = addressRaw.replace(new RegExp(" Lane", "gi"), " Ln");
		addressRaw = addressRaw.replace(new RegExp(" Loop", "gi"), " Lp");
		addressRaw = addressRaw.replace(new RegExp(" Parkway", "gi"), " Pkwy");
		addressRaw = addressRaw.replace(new RegExp(" Place", "gi"), " Pl");
		addressRaw = addressRaw.replace(new RegExp(" Plaza", "gi"), " Plz");
		addressRaw = addressRaw.replace(new RegExp(" Road", "gi"), " Rd");
		addressRaw = addressRaw.replace(new RegExp(" Street", "gi"), " St");
		addressRaw = addressRaw.replace(new RegExp(" Terrace", "gi"), " Terr");
		addressRaw = addressRaw.replace(new RegExp(" Trail", "gi"), " Trl");
		addressRaw = addressRaw.replace(new RegExp(" Way", "gi"), " Wy");
		addressRaw = addressRaw.replace(new RegExp(" Apt ", "gi"), " #");
		addressRaw = addressRaw.replace(new RegExp(" Suite ", "gi"), " Ste ");
	}
	
	address.value = addressRaw;

}

//
// Capitalize the first letter of each word
// Jessica Voytek 07/2010
//

function capitalize(theid) {
	txt = $("#" + theid).val();
	// Regex taken from php.js (http://phpjs.org/functions/ucwords:569)
	txt = txt.replace( 
		/([A-Z])([A-Z])/g , 
		function(m,p1,p2) { 
			return p1.toLowerCase()+p2.toLowerCase(); 
		} 
	);
	txt = txt.replace( 
		/(^|\s)([a-z])/g , 
		function(m,p1,p2) { 
			return p1+p2.toUpperCase(); 
		} 
	);
	txt = txt.replace( 
		/([A-Z])($|\s)/g , 
		function(m,p1,p2) { 
			return p1.toLowerCase()+p2; 
		} 
	);
	txt = txt.replace( 
		/(^|\s)([a-z])($|\s)/g , 
		function(m,p1,p2,p3) { 
			return p1+p2.toUpperCase()+p3; 
		} 
	);
	
	$("#" + theid).val(txt);
}

// A simpler way to validate forms
// Jessica Voytek

function validateForm(form, action, submit) {
	var errors = "";
	var error_count = 0;
	var error_div = document.getElementById('errors');
	
	var required = document.getElementById('required').value;
	required_array = required.split(",");
	
	for (x in required_array) {
		input = document.getElementById(required_array[x]);
		value = input.value;
		name = input.name;
		if (value == "") {
			errors += name + ", ";
			error_count ++;
		}
	}
	
	if (error_count != 0) {
		error_div.innerHTML = "<span class='error-text'>The following fields are required: " + errors;
		error_div.style.display = 'block';
	} else if (submit == true) {
		SubmitForm(form, action);
	}

}

// Submit data to a PHP page and then submit a form
function runPHP_submit(str, str2, formID, phpPage) { 
	xmlHttp=GetXmlHttpObject()
	if (xmlHttp==null) {
		alert ("Browser does not support HTTP Request")
		return
	}
	theForm=formID
	var url=phpPage
	url=url+"?q="+str+"&r="+str2
	url=url+"&sid="+Math.random()
	xmlHttp.onreadystatechange=no_return_stateChanged
	xmlHttp.open("GET",url,true)
	xmlHttp.send(null)
}

//Test correction for multiple choice tests
//Jessica Voytek 05/2008
//Requires an array of answers (q1, q2, etc.)
//Requires questions with inputs (id = q10 q11, q20, q21 etc)
//Requires right and wrong div boxed (id = q0right q0wrong etc)

function correctTest(test, num_questions, showNext) {
	var errors = "";
	var error_count = 0;
	var x;
	var y;
	
	//check the answers
	for ( i = 0; i < num_questions; i++ ) {
		for ( j = 0; j <= 6; j++) {
			var user_answer = 1;
			if ( eval("document.getElementById('q" + i + j + "').checked") == false || eval("document.getElementById('q" + i + j + "').value") == 0) {
				user_answer = 0;
			}
			if ( eval("q" + i + "[" + j + "]") != user_answer) {
				errors += i + ";";
				error_count++;
			}
		}
	}
	
	var errors_array = errors.split(";");
	
	//pop the last empty entry off the end of the array
	errors_array.pop();
	
	//show wrong divs if there are errors
	if ( error_count > 0 ) {
		for (x in errors_array) {
			value = errors_array[x];
			//show the wrong div and hide the right div
			if( value != "" ) {
				eval("document.getElementById('q" + value + "wrong').style.display = 'block'");
				eval("document.getElementById('q" + value + "right').style.display = 'none'");
			}
		}
	}
	
	var right_answer = true;
	
	//show right divs if there are correct questions
	for ( k = 0; k < num_questions; k++ ) {
		//start by setting right_answer to true
		right_answer = true;
		
		//check if there are any errors
		if ( error_count > 0 ) {
			//if so, go through and compare with k (0,1)
			for (y in errors_array) {
				the_value = errors_array[y];
				//if k = something in the errors array, set right_answer for k to false
				if (k == the_value) {
					right_answer = false;
				}
			}
		}
		
		//if after all of that the right_answer is still true, show the right div and hide the wrong div
		if ( right_answer == true ) {
			eval("document.getElementById('q" + k + "right').style.display = 'block'");		
			eval("document.getElementById('q" + k + "wrong').style.display = 'none'");		
		}
	}
	
	if (showNext == true && error_count == 0) {
		document.getElementById('submitNext').style.display = 'block';
		document.getElementById('next_note').style.display = 'none';
	}
}

//
// Delete CMS Page Function
// For deleteing an "un-protected" page
// Jessica Voytek, June 2010
//

function DeleteCMSPage() {
	
	//Check to see if box is checked
	checked = document.reveal_cms.delete_page.checked;
	if (checked == false) {
		alert('If you would like to delete this page, please select the check box next to "Delete this page" and click on "Go"')
	} else {
	
		//Confirm deletion
		msg = "Are you sure you want to delete this page?  This action cannot be undone.";
		if (!confirm(msg)) {
			return false;
		}
		
		vars = $("form#reveal_cms").serialize();
		//Send window.location to delete page
		$.post('/common/ajax/pageDelete.php', vars, function() {
    		//alert("Data Loaded: " + data);
			//Return to admin navigation section with success message
			window.location = "/admin/nav.php?message=Page%20Deleted";
		});

	}
	
}


//
// tinyMCE Functions (In-browser HTML Editor
// read more about tinyMCE here:
// http://tinymce.moxiecode.com
//


function toggle_tinyMCE() {
	spans = document.getElementsByTagName('span');
	
	for (i = 0; i < spans.length; i++) {
		if (spans[i].className == "tinyMCE_load") {
			spans[i].className = "tinyMCE_load hidden";
		} else if (spans[i].className == "tinyMCE_load hidden") {
			spans[i].className = "tinyMCE_load";
		}
	}
}

function cms_tiny_mce() {
	
	//toggle_tinyMCE();
	
	tinyMCE.init({
		mode : "textareas",
		theme : "advanced",
		plugins : "safari,pagebreak,style,layer,table,save,advhr,advimage,advlink,emotions,iespell,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template,spellchecker,jmform,imagemanager",
		spellchecker_languages : "+English=en",
		spellchecker_report_misspellings : true,
		theme_advanced_buttons1 : "save,cancelbutton,|,spellchecker,|,code,preview,visualchars,|,template,|,removeformat,|,undo,redo,cut,copy,paste,pastetext,search,replace",
		theme_advanced_buttons2 : "bold,italic,underline,strikethrough,forecolor,backcolor,sub,sup,|,justifyleft,justifycenter,justifyright,justifyfull,bullist,numlist,|,outdent,indent,blockquote",
		theme_advanced_buttons3 : "styleselect,formatselect,fontsizeselect,|,link,unlink,anchor,image,|,advhr,charmap,nonbreaking",
		theme_advanced_buttons4 : "tablecontrols",
		theme_advanced_toolbar_location : "top",
		theme_advanced_toolbar_align : "left",
		theme_advanced_resizing : true,
		relative_urls : false,
		remove_script_host : true,
		document_base_url : "http://www.girlscoutsnorcal.org/",
		content_css : "/common/css/content.css",
		editor_selector : "mceAdvanced",
		extended_valid_elements : "form[name|id|action|method|enctype|accept-charset|onsubmit|onreset|target],ol[start|style|id|class],input[id|name|type|value|size|maxlength|checked|accept|src|width|height|disabled|readonly|tabindex|accesskey|onfocus|onblur|onchange|onselect|onclick|onkeyup|onkeydown|required|style],textarea[id|name|rows|cols|maxlength|disabled|readonly|tabindex|accesskey|onfocus|onblur|onchange|onselect|onclick|onkeyup|onkeydown|required|style],option[name|id|value|selected|style],select[id|name|type|value|size|maxlength|checked|width|height|disabled|readonly|tabindex|accesskey|onfocus|onblur|onchange|onselect|onclick|multiple|style],img[align<bottom?left?middle?right?top|alt|border|class|dir<ltr?rtl|height|hspace|id|ismap<ismap|lang|longdesc|name|onload|onclick|ondblclick|onkeydown|onkeypress|onkeyup|onmousedown|onmousemove|onmouseout|onmouseover|onmouseup|src|style|title|usemap|vspace|width],script[charset|defer|language|src|type]",
		
		setup : function(ed) {
			// custom cancel button
			ed.addButton('cancelbutton', {
				title : 'Cancel',
				image : '/images/cancel.gif',
				onclick : function() {
					// Add your own code to execute something on click
					window.location = window.location.pathname;
				}
			});
		}	
	});

	tinyMCE.init({
		mode : "textareas",
		theme : "advanced",
		plugins : "safari,pagebreak,style,layer,table,save,advhr,advimage,advlink,emotions,iespell,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template,spellchecker,imagemanager",
		spellchecker_languages : "+English=en",
		spellchecker_report_misspellings : true,
		theme_advanced_buttons1 : "save,cancelbutton,|,spellchecker,|,code,preview,visualchars,|,template,|,removeformat,|,undo,redo,cut,copy,paste,pastetext,search,replace",
		theme_advanced_buttons2 : "bold,italic,underline,strikethrough,forecolor,backcolor,sub,sup,|,justifyleft,justifycenter,justifyright,justifyfull,bullist,numlist,|,outdent,indent,blockquote",
		theme_advanced_buttons3 : "styleselect,formatselect,fontsizeselect,|,link,unlink,anchor,image,|,advhr,charmap,nonbreaking",
		theme_advanced_buttons4 : "tablecontrols",
		theme_advanced_toolbar_location : "top",
		theme_advanced_toolbar_align : "left",
		theme_advanced_resizing : true,
		relative_urls : true,
		remove_script_host : true,
		document_base_url : "http://www.camprocks.org/",
		content_css : "common/camp_style.css",
		editor_selector : "mceAdvanced-Camp",
		extended_valid_elements : "form[name|id|action|accept|accept-charset|enctype|method],img[align<bottom?left?middle?right?top|alt|border|class|dir<ltr?rtl|height|hspace|id|ismap<ismap|lang|longdesc|name|onload|onclick|ondblclick|onkeydown|onkeypress|onkeyup|onmousedown|onmousemove|onmouseout|onmouseover|onmouseup|src|style|title|usemap|vspace|width],script[charset|defer|language|src|type]",
		
		setup : function(ed) {
			// custom cancel button
			ed.addButton('cancelbutton', {
				title : 'Cancel',
				image : '/images/cancel.gif',
				onclick : function() {
					// Add your own code to execute something on click
					window.location = window.location.pathname;
				}
			});
		}	
	});

	tinyMCE.init({
		mode : "textareas",
		theme : "advanced",
		plugins : "safari,pagebreak,style,layer,table,save,advhr,advimage,advlink,emotions,iespell,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template,spellchecker,imagemanager",
		spellchecker_languages : "+English=en",
		spellchecker_report_misspellings : true,
		theme_advanced_buttons1 : "spellchecker,|,code,preview,visualchars,|,template,|,removeformat,|,undo,redo,cut,copy,paste,pastetext,search,replace",
		theme_advanced_buttons2 : "bold,italic,underline,strikethrough,forecolor,backcolor,sub,sup,|,justifyleft,justifycenter,justifyright,justifyfull,bullist,numlist,|,outdent,indent,blockquote",
		theme_advanced_buttons3 : "styleselect,formatselect,fontsizeselect,|,link,unlink,anchor,image,|,advhr,charmap,nonbreaking",
		theme_advanced_buttons4 : "tablecontrols",
		theme_advanced_toolbar_location : "top",
		theme_advanced_toolbar_align : "left",
		theme_advanced_resizing : true,
		relative_urls : false,
		remove_script_host : true,
		document_base_url : "http://www.girlscoutsnorcal.org/",
		content_css : "/common/css/content.css",
		editor_selector : "mceAdvanced-Alt",
		extended_valid_elements : "form[name|id|action|accept|accept-charset|enctype|method],img[align<bottom?left?middle?right?top|alt|border|class|dir<ltr?rtl|height|hspace|id|ismap<ismap|lang|longdesc|name|onload|onclick|ondblclick|onkeydown|onkeypress|onkeyup|onmousedown|onmousemove|onmouseout|onmouseover|onmouseup|src|style|title|usemap|vspace|width],script[charset|defer|language|src|type]"
		
	});

	tinyMCE.init({
		mode : "textareas",
		theme : "advanced",
		plugins : "save,spellchecker,imagemanager",
		spellchecker_languages : "+English=en",
		spellchecker_report_misspellings : true,
		theme_advanced_buttons1 : "save,cancelbutton,|,spellchecker,|,code,|,removeformat,|,undo,redo,cut,copy,paste,pastetext,|,link,unlink,anchor,image",
		theme_advanced_buttons2 : "bold,italic,underline,strikethrough,forecolor,backcolor,sub,sup,|,justifyleft,justifycenter,justifyright,justifyfull,bullist,numlist,|,outdent,indent,blockquote",
		theme_advanced_buttons3 : "styleselect,formatselect,fontsizeselect",
		theme_advanced_toolbar_location : "top",
		theme_advanced_toolbar_align : "left",
		theme_advanced_resizing : true,
		relative_urls : false,
		remove_script_host : true,
		document_base_url : "http://www.girlscoutsnorcal.org/",
		content_css : "/common/css/content.css",
		editor_selector : "mceMedium",
		extended_valid_elements : "form[name|id|action|accept|accept-charset|enctype|method],img[align<bottom?left?middle?right?top|alt|border|class|dir<ltr?rtl|height|hspace|id|ismap<ismap|lang|longdesc|name|onload|onclick|ondblclick|onkeydown|onkeypress|onkeyup|onmousedown|onmousemove|onmouseout|onmouseover|onmouseup|src|style|title|usemap|vspace|width],script[charset|defer|language|src|type]",

		setup : function(ed) {
			// custom cancel button
			ed.addButton('cancelbutton', {
				title : 'Cancel',
				image : '/images/cancel.gif',
				onclick : function() {
					// Add your own code to execute something on click
					window.location = window.location.pathname;
				}
			});
		}	
	});

	tinyMCE.init({
		mode : "textareas",
		theme : "advanced",
		plugins : "save,spellchecker,imagemanager",
		spellchecker_languages : "+English=en",
		spellchecker_report_misspellings : true,
		theme_advanced_buttons1 : "spellchecker,|,undo,redo,|,bold,italic,underline,strikethrough,|,forecolor,backcolor,|,justifyleft,justifycenter,justifyright,justifyfull,bullist,numlist,|,outdent,indent,|,link,unlink,anchor,image",
		theme_advanced_buttons2 : "",
		theme_advanced_buttons3 : "",
		theme_advanced_toolbar_location : "top",
		theme_advanced_toolbar_align : "left",
		theme_advanced_resizing : true,
		relative_urls : false,
		remove_script_host : true,
		document_base_url : "http://www.girlscoutsnorcal.org/",
		content_css : "/common/css/content.css",
		editor_selector : "mceBasic-Alt",
		extended_valid_elements : "form[name|id|action|accept|accept-charset|enctype|method],img[align<bottom?left?middle?right?top|alt|border|class|dir<ltr?rtl|height|hspace|id|ismap<ismap|lang|longdesc|name|onload|onclick|ondblclick|onkeydown|onkeypress|onkeyup|onmousedown|onmousemove|onmouseout|onmouseover|onmouseup|src|style|title|usemap|vspace|width],script[charset|defer|language|src|type]"
	});

	tinyMCE.init({
		mode : "textareas",
		theme : "advanced",
		plugins : "save,spellchecker,imagemanager",
		spellchecker_languages : "+English=en",
		spellchecker_report_misspellings : true,
		theme_advanced_buttons1 : "save,cancelbutton,|,spellchecker,|,undo,redo,|,bold,italic,underline,strikethrough,|,forecolor,backcolor,|,justifyleft,justifycenter,justifyright,justifyfull,bullist,numlist,|,outdent,indent,|,link,unlink,anchor,image",
		theme_advanced_buttons2 : "",
		theme_advanced_buttons3 : "",
		theme_advanced_toolbar_location : "top",
		theme_advanced_toolbar_align : "left",
		theme_advanced_resizing : true,
		relative_urls : false,
		remove_script_host : true,
		document_base_url : "http://www.girlscoutsnorcal.org/",
		content_css : "/common/css/content.css",
		editor_selector : "mceBasic",
		extended_valid_elements : "form[name|id|action|accept|accept-charset|enctype|method],img[align<bottom?left?middle?right?top|alt|border|class|dir<ltr?rtl|height|hspace|id|ismap<ismap|lang|longdesc|name|onload|onclick|ondblclick|onkeydown|onkeypress|onkeyup|onmousedown|onmousemove|onmouseout|onmouseover|onmouseup|src|style|title|usemap|vspace|width],script[charset|defer|language|src|type]",
		setup : function(ed) {
			// custom cancel button
			ed.addButton('cancelbutton', {
				title : 'Cancel',
				image : '/images/cancel.gif',
				onclick : function() {
					// Add your own code to execute something on click
					window.location = window.location.pathname;
				}
			});
		}	
	});

	tinyMCE.init({
		mode : "textareas",
		theme : "advanced",
		plugins : "save,spellchecker,imagemanager",
		spellchecker_languages : "+English=en",
		spellchecker_report_misspellings : true,
		theme_advanced_buttons1 : "save,cancelbutton,|,spellchecker,|,undo,redo,|,bold,italic,underline",
		theme_advanced_buttons2 : "",
		theme_advanced_buttons3 : "",
		theme_advanced_toolbar_location : "top",
		theme_advanced_toolbar_align : "left",
		theme_advanced_resizing : true,
		relative_urls : true,
		remove_script_host : true,
		document_base_url : "http://www.camprocks.org/",
		content_css : "common/camp_style.css",
		editor_selector : "mceBasic-Camp",
		extended_valid_elements : "form[name|id|action|accept|accept-charset|enctype|method],img[align<bottom?left?middle?right?top|alt|border|class|dir<ltr?rtl|height|hspace|id|ismap<ismap|lang|longdesc|name|onload|onclick|ondblclick|onkeydown|onkeypress|onkeyup|onmousedown|onmousemove|onmouseout|onmouseover|onmouseup|src|style|title|usemap|vspace|width],script[charset|defer|language|src|type]",
		setup : function(ed) {
			// custom cancel button
			ed.addButton('cancelbutton', {
				title : 'Cancel',
				image : '/images/cancel.gif',
				onclick : function() {
					// Add your own code to execute something on click
					window.location = window.location.pathname;
				}
			});
		}	
	});

	tinyMCE.init({
		mode : "textareas",
		theme : "advanced",
		plugins : "save,spellchecker,imagemanager",
		spellchecker_languages : "+English=en",
		spellchecker_report_misspellings : true,
		theme_advanced_buttons1 : "save,cancelbutton,|,undo,redo,|,link,unlink,anchor,image,code",
		theme_advanced_buttons2 : "",
		theme_advanced_buttons3 : "",
		theme_advanced_toolbar_location : "top",
		theme_advanced_toolbar_align : "left",
		theme_advanced_resizing : true,
		relative_urls : false,
		remove_script_host : true,
		document_base_url : "http://www.girlscoutsnorcal.org/",
		content_css : "/common/content.css",
		editor_selector : "cms-header-img",
		extended_valid_elements : "form[name|id|action|accept|accept-charset|enctype|method],img[align<bottom?left?middle?right?top|alt|border|class|dir<ltr?rtl|height|hspace|id|ismap<ismap|lang|longdesc|name|onload|onclick|ondblclick|onkeydown|onkeypress|onkeyup|onmousedown|onmousemove|onmouseout|onmouseover|onmouseup|src|style|title|usemap|vspace|width],script[charset|defer|language|src|type]",
		setup : function(ed) {
			// custom cancel button
			ed.addButton('cancelbutton', {
				title : 'Cancel',
				image : '/images/cancel.gif',
				onclick : function() {
					// Add your own code to execute something on click
					window.location = window.location.pathname;
				}
			});
		}	
	});

}


// Global Variables for Ajax
var xmlHttp
var theDiv
var theForm

function OneVarAjax(str, divID, phpPage) { 
	xmlHttp=GetXmlHttpObject()
	if (xmlHttp==null) {
		alert ("Browser does not support HTTP Request")
		return
	}
	var url=phpPage
	url=url+"?q="+str
	theDiv = divID
	url=url+"&theDiv="+theDiv
	url=url+"&sid="+Math.random()
	xmlHttp.onreadystatechange=stateChanged 
	xmlHttp.open("GET",url,true)
	xmlHttp.send(null)
}

function TwoVarAjax(str, str2, divID, phpPage) { 
	xmlHttp=GetXmlHttpObject()
	if (xmlHttp==null) {
		alert ("Browser does not support HTTP Request")
		return
	}
	var url=phpPage
	url=url+"?q="+str+"&r="+str2
	theDiv = divID
	url=url+"&theDiv="+theDiv
	url=url+"&sid="+Math.random()
	xmlHttp.onreadystatechange=stateChanged 
	xmlHttp.open("GET",url,true)
	xmlHttp.send(null)
}

function ThreeVarAjax(str, str2, str3, divID, phpPage) { 
	xmlHttp=GetXmlHttpObject()
	if (xmlHttp==null) {
		alert ("Browser does not support HTTP Request")
		return
	}
	var url=phpPage
	url=url+"?q="+str+"&r="+str2+"&s="+str3
	theDiv = divID
	url=url+"&theDiv="+theDiv
	url=url+"&sid="+Math.random()
	xmlHttp.onreadystatechange=stateChanged 
	xmlHttp.open("GET",url,true)
	xmlHttp.send(null)
}

function stateChanged() { 
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") { 
		document.getElementById(theDiv).innerHTML=xmlHttp.responseText 
	}
}

function no_return_stateChanged() {
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") {
		document.getElementById(theForm).submit();
	} 
}

function GetXmlHttpObject() {
	var xmlHttp=null;
	try {
		// Firefox, Opera 8.0+, Safari
		xmlHttp=new XMLHttpRequest();
	}
	catch (e) {
		//Internet Explorer
		try {
			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e) {
			xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
		}
	}
	return xmlHttp;
}



