function submitNeedCohost(thisPtr,checks,submode) {
	var check,checkPtr,formPtr,inputType,value,error;
	error = '';
	formPtr = thisPtr.form;
	if (typeof(checks) == 'object') {
		for (check in checks) {
			checkPtr = formPtr[check];
			if (checkPtr) {
				inputType = checkPtr.type;
				value = '';
				if (inputType == 'text') {
					value = trim(checkPtr.value);
				}
				else if (inputType == 'select-one') {
					value = checkPtr.selectedIndex;
				}
				if (!value) {
					error += "Please enter a"+checks[check]+"\n";
				}
			}
		}
		if (error) {
			alert(error);
		}
		else {
			submitSubmodeForm(thisPtr,submode);
		}
	}
}

// Called by body onload
function catalogInit(maxTime)
{
	var venueFormPtr,countDownPtr;
	venueFormPtr = document.getElementById('venue_form');
	if (venueFormPtr) {
		registerTextareaInput(textareas);
		inputSumUpdate(venueFormPtr.p_products_price,['p_products_price','p_reservation_fee','p_donation_amt'],'p_total');
		countDownPtr = document.getElementById('countDown');
		if (countDownPtr && (maxTime !== undefined) && (maxTime > 0)) {
			catalogTimer.countDownPtr = stepToNode(countDownPtr,'span:0');
			catalogTimer.countDown = maxTime; // Set countdown timer to 300 seconds
			window.setInterval(catalogTimer,1000);
		}
	}
}

function catalogTimer()
{
	var countDown,countDownPtr,seconds;
	countDownPtr = catalogTimer.countDownPtr;
	if (countDownPtr && (catalogTimer.countDown > 0)) {
		--catalogTimer.countDown;
		countDown = catalogTimer.countDown;
		seconds = countDown%60;
		catalogTimer.countDownPtr.innerHTML = 'Time Remaining ' + Math.floor(countDown/60) + ':' + ( seconds < 10 ? '0' : '')+seconds;
	}
}

function spellCheck(formId,elementId)
{
	var formPtr,currentValue;
	if (formId && elementId) {
		getSpellCheckArray(formId,elementId);
		formPtr = document.getElementById(formId);
		if (formPtr) {
			if (spellCheck[formId] === undefined) {
				spellCheck[formId] = {};
			}
			if (spellCheck[formId][elementId] === undefined) {
				spellCheck[formId][elementId] = '';
			}
			currentValue = trim(formPtr[elementId].value);
			//if ((currentValue !== '') && (currentValue != spellCheck[formId][elementId])) {
				jspellcheck();
			//}
			spellCheck[formId][elementId] = currentValue;
		}
	}
	return true;
}

function getSpellCheckArray(formId,elementIds)
{
  var i,fieldsToCheck;
	fieldsToCheck = [];
	if ((formId === undefined) || (elementIds === undefined)) {
		if (getSpellCheckArray.elements !== undefined) {
			fieldsToCheck = getSpellCheckArray.elements;
		}
	}
	else {
		formPtr = document.getElementById(formId);
		if ((typeof elementIds != 'object') || (elementIds.length === undefined)) {
			elementIds = [elementIds];
		}
		if (formPtr) {
			getSpellCheckArray.elements = [];
			for (i=0; i<elementIds.length; ++i) {
				getSpellCheckArray.elements[i] = 'document.forms["'+formId+'"].'+formPtr[elementIds[i]].name;
			}
		}
	}
  return fieldsToCheck;
}
 
var language;

function open_location_search(formId)
{
	var formPtr;
	formPtr = (formId ? document.getElementById(formId) : null);
	if (formPtr) {
		winCoSearch = window.open('locations_search.php?mode=search&prefix=p_&criteria='+formPtr.loc_criteria.value, 'cosearch', 'scrollbars=yes,resizable=yes,width=450,height=300,menubar=no,location=no,left=200,top=150');
		//winCoSearch.document.location.reload();
		winCoSearch.focus();
	}
}

function blurThis(thisPtr)
{
	thisPtr.blur();
}

function applicationCellPhone(formId,phoneNumber) {
	var formPtr;
	formPtr = (formId ? document.getElementById(formId) : null);
	if (formPtr) {
		formPtr.p_products_phone.value = phoneNumber;
		optionKeyup(formPtr);
	}
}

function applicationLocation(thisPtr,loc_name,loc_address,loc_city,loc_state,loc_post_code)
{
	thisPtr.form.p_products_location.value = loc_name;
	thisPtr.form.p_products_street_address.value = loc_address;
	thisPtr.form.p_products_city.value = loc_city;
	thisPtr.form.p_products_state.value = loc_state;
	thisPtr.form.p_products_post_code.value = loc_post_code;
}

function clear_cohost(formId,cohostNum)
{
	var formPtr,elementPrefixes,i;
	formPtr = document.getElementById(formId);
	if (formPtr) {
		elementPrefixes = ['t_customers_id','h_customers_name_email','h_customers_gender'];
		for (i=0; i<elementPrefixes.length; i++) {
			elementName = elementPrefixes[i]+cohostNum;
			if (formPtr[elementName] !== undefined) {
				formPtr[elementName].value = '';
			}
		}
	}
	return false;
}

function open_cohost_search(formId,cohostNum)
{
	var formPtr,criteriaNum,criteriaValue,guestId,name_email,gender;
	formPtr = document.getElementById(formId);
	if (formPtr) {
		criteriaNum = 'criteria'+cohostNum;
		if (formPtr[criteriaNum].value.length < 2) {
			alert('Please enter in at least two characters.');
		} else {
			criteriaValue = formPtr[criteriaNum].value;
			guestId = 'guestId=t_customers_id'+cohostNum;
			name_email = 'name_email=h_customers_name_email'+cohostNum;
			gender = 'gender=h_customers_gender'+cohostNum;
			winCoSearch = window.open('/cgi-bin/elife/catalog/cohost_search.php?mode=search&criteria='+criteriaValue+'&AA=1&'+guestId+'&'+name_email+'&'+gender, 'cohosearch', 'scrollbars=yes,resizable=yes,width=450,height=300,menubar=no,location=no,left=200,top=150');
			winCoSearch.focus();
		}
	}
	return false;
}

function urlTest(thisPtr,fieldName) {
	var url,urlBits,urlType,formPtr,testDivId,testDivPtr;
	url = formPtr = null;
	if (thisPtr) {
		formPtr = findParentNode(thisPtr,'form');
	}
	if (formPtr && (formPtr[fieldName] !== undefined)) {
		url = trim(formPtr[fieldName].value);
	}
	if (url) {
		urlBits = url.split('//');
		urlType = urlBits[0].toLowerCase();
		if ((urlType != 'http:') && (urlType != 'https:')) {
			url = 'http://'+url;
		}
		guestSearch = window.open(url, 'guestSearch', 'scrollbars=yes,resizable=yes,width=500,height=350,menubar=no,location=no,left=200,top=150');
		guestSearch.focus();
	}
	return false;
}

// Modify calendar cells to create a new month
function calendarMonth(thisPtr,offset) {
	var thisDate,thisMonth,thisYear,newMonth,newYear,row,cellaPtr,calendarDivPtr;
	calendarDivPtr = findParentNode(thisPtr,'div,div,div');
	thisDate = calendarDate(calendarDivPtr);
	if (thisDate) {
		thisMonth = thisDate.getMonth();
		thisYear = thisDate.getFullYear();
		newMonth = (thisMonth + offset +12) % 12;
		newYear = thisYear + ( (newMonth==0) && (offset>0) ? 1 : ( (newMonth==11) && (offset<0) ? -1 : 0 ) );
		thisDate.setMonth(newMonth);
		thisDate.setFullYear(newYear);
		for (row=0; row<6; ++row) {//6
			for (cell=0; cell<7; ++cell) {//7
				cellContent = '';
				if ((newMonth == thisDate.getMonth()) && (cell == thisDate.getDay())) {
					cellContent = thisDate.getDate();
					thisDate.setDate(cellContent+1);
				}
				aPtr = calendarRowCell(thisPtr,row,cell+',a:0');
				if (aPtr) {
					aPtr.innerHTML = cellContent;
				}
			}
		}
		calendarDate(findParentNode(thisPtr,'div,div,div'),monthToText(newMonth+1)+' '+newYear);
		
		// Show the previous month link if we are in the future
		now = new Date();
		backPtr = stepToNode(calendarDivPtr,'div:1,div:1');
		if (backPtr) {
			backPtr.className = ( (newYear > now.getFullYear()) || ((newYear == now.getFullYear()) && (newMonth > now.getMonth())) ? 'calendarNav' : 'noDisplay' );
		}
	}
	return false;
}

// Reture a date object representing day clicked for the current month displayed
function calendarDate(thisPtr,newDate) {
	var tablePtr,datePtr,date,thisDate;
	thisDate = null;
	newDate = (newDate === undefined ? null : newDate);
	datePtr = stepToNode(thisPtr,'div:1,div:2');
	if (datePtr) {
		date = ( datePtr ? datePtr.innerHTML.split(' ') : ['',''] );
		if (date[0] && date[1]) {
			month = monthToOrd(date[0]);
			year = date[1];
			day = 1;
			if (month && day && year) {
				thisDate = new Date(month+'/'+day+'/'+year);
			}
		}
	}
	if (newDate) {
		datePtr.innerHTML = newDate;
	}
	return thisDate;
}
function calendar(thisPtr,calId,inputIds)
{
	var i,inputPtr,thisDate,thisDateStr,day,calendarDivPtr;
	if (typeof inputIds != 'object') {
		inputIds = [inputIds];
	}
	thisDateStr = '';
	calendarDivPtr = findParentNode(thisPtr,'div');
	thisDate = calendarDate(calendarDivPtr);
	if (thisDate) {
		day = trim(thisPtr.innerHTML);
		if (!parseInt(day)) {
			day = 1;
		}
		thisDateStr = (thisDate.getMonth()+1)+'/'+day+'/'+thisDate.getFullYear();
		for (i=0; i<inputIds.length; ++i) {
			inputPtr = document.getElementById(inputIds[i]);
			if (inputPtr && (inputPtr.value !== undefined)) {
				inputPtr.value = thisDateStr;
			}
			else {
				inputPtr.innerHTML = thisDateStr;
			}
		}
	}
	showHide('c');
	return false;
}

// Return a reference to the selected calendar row and cell
function calendarRowCell(thisPtr,row,cell,debug)
{
	var tablePtr,rowCellPtr;
	debug = (debug !== undefined) && debug;
	rowCellPtr = null;
	tablePtr = findParentNode(thisPtr,'div,div,div');
	tablePtr = (tablePtr ? stepToNode(tablePtr,'table:0') : null);
	if (tablePtr) {
		rowCellPtr = stepToNode(tablePtr,'tr:'+row+',td:'+cell);
		if (debug) { 'row='+row+', cell='+cell+"\n"; }
	}
	return rowCellPtr;
}

// Convert a month name or abbreviation to the numeric equivalent
function monthToOrd(month)
{
	var months = { 'jan':1, 'feb':2, 'mar':3, 'apr':4, 'may':5, 'jun':6, 'jul':7, 'aug':8, 'sep':9, 'oct':10, 'nov':11, 'dec':12 };
	month = month.toLowerCase().substr(0,3);
	monthOrd = ( months[month] !== undefined ? months[month] : null );
	return monthOrd;
}

// Convert ordinal month to Text month
function monthToText(month)
{
	var months;
	monthText = '';
	months = { '1':'January','2':'February','3':'March','4':'April','5':'May','6':'June','7':'July','8':'August','9':'September','10':'October','11':'November','12':'December' };
	if (typeof month == 'string') {
		month = parseInt(trim(month));
	}
	month = ''+month;
	if (months[month] !== undefined) {
		monthText = months[month];
	}
	return monthText;
}

function expand(thisPtr,tableId,classname)
{
	var imgPtr,src,img,tablePtr;
	imgPtr = stepToNode(thisPtr,'img:0');
	tablePtr = document.getElementById(tableId);
	if (imgPtr && tablePtr) {
		src = imgPtr.src;
		img = src.search(/\w+\.gif/)
		src = src.substring(0,img);
		if (tablePtr.className == 'noDisplay') {
			tablePtr.className = classname;
			imgPtr.src = src+'minus.gif';
		}
		else {
			tablePtr.className = 'noDisplay';
			imgPtr.src = src+'plus.gif';
		}
	}
	return false;
}

function changeAge(thisPtr)
{
	var ageRange,ageRangeInt,hostsAge,fromAge,toAge;
	ageRange = thisPtr.options[thisPtr.selectedIndex].value;
	if (ageRange) {
		if (ageRange == 'All') {
			fromAge = '18';
			toAge = '99';
		}
		else {
			ageRangeInt = parseInt(ageRange);
			hostsAge = parseInt(thisPtr.form.s_hostAge.value);
			fromAge = hostsAge - Math.floor(ageRangeInt/2);
			toAge = fromAge + ageRangeInt;
			fromAge = Math.max(fromAge,18);
		}
		thisPtr.form.c_age_range_start.value = fromAge
		thisPtr.form.c_age_range_end.value = toAge;
	}
}

// Open up the text input for entry if a key is pressed inside the box
function optionKeyup(formPtr)
{
	var optionDivPtr,optionName;
	optionDivPtr = findParentNode(formPtr.p_products_phone,'div');
	if (optionDivPtr) {
		optionDivPtr.className = '';
	}
	optionName = formPtr.p_products_phone.name.substr(2);
	formPtr[optionName][0].checked = true;
}

// Show or hide optional form elements
function optionClick(thisPtr,fieldNames,hideShowName,showClass,showHideName,showHideClass) {
	var h,i,thisPtrYes,thisPtrNo,showHidePtr,fieldPtr,fieldInputPtr,fieldInputPtrs,checkDivId,checkDivPtr,dateDivPtr;
	thisPtrYes = false;
	thisPtrNo = false;
	if (thisPtr && (thisPtr.type !== undefined)) {
		switch(thisPtr.type) {
			case 'radio':
				thisPtrYes = (thisPtr.value == 'Y');
				thisPtrNo = (thisPtr.value == 'N');
				break;
			case 'checkbox':
				if (thisPtr.checked) {
					thisPtrYes = true;
				}
				break;
		}
	}
	showHidePtr = (showHideName != '' ? document.getElementById(showHideName) : null);
	fieldPtr = document.getElementById(hideShowName);
	fieldNames = fieldNames.split(',');
	for (h=0; h<fieldNames.length; h++) {
		fieldName = fieldNames[h];
		fieldInputPtrs = (thisPtr ? thisPtr.form[fieldName] : null );
		if (!fieldInputPtrs) {
			fieldInputPtrs = (thisPtr ? thisPtr.form[fieldName+'[]'] : null );
		}
		//alert('fieldName='+fieldName+', fieldPtr='+fieldPtr+', fieldInputPtrs='+fieldInputPtrs);
		if (fieldPtr) {
			fieldPtr.className = (thisPtrYes ? showClass : 'noDisplay');
		}
		if (showHidePtr) {
			showHidePtr.className = (thisPtrYes ? 'noDisplay' : showHideClass);
		}
		if (fieldInputPtrs) {
			if (fieldInputPtrs.name !== undefined) {
				fieldInputPtrs = [fieldInputPtrs];
			}
			for (i=0; i<fieldInputPtrs.length; ++i ) {
				fieldInputPtr = fieldInputPtrs[i];
				if (thisPtrYes) {
					if (fieldInputPtr.type != 'hidden') {
						fieldInputPtr.className = showClass;
					}
				}
				else if (thisPtrNo) {
					if (fieldInputPtr.type != 'hidden') {
						fieldInputPtr.className = 'optional';
					}
					if ((fieldInputPtr.type == 'text') || (fieldInputPtr.type == 'name') || (fieldInputPtr.type == 'phone') || (fieldInputPtr.type == 'textarea')) {
						fieldInputPtr.value = '';
					}
					else if (fieldInputPtr.type == 'select-one') {
						fieldInputPtr.selectedIndex = 0;
					}
					else if (fieldInputPtr.type == 'checkbox') {
						fieldInputPtr.checked = false;
						checkDivId = 'check_'+fieldInputPtr.value;
						checkDivPtr = document.getElementById(checkDivId);
						if (checkDivPtr) {
							checkDivPtr.className = 'noDisplay';
						}
					}
					else if (fieldInputPtr.type == 'hidden') {
						fieldInputPtr.value = '';
						if (fieldInputPtr.className == 'date') {
							dateDivPtr = document.getElementById('date'+fieldInputPtr.name);
							if (dateDivPtr) {
								dateDivPtr.innerHTML = '&nbsp;';
							}
						}
					}
				}
			}
		}
	}
}

function optionFocus(thisPtr) {
	if (thisPtr.className == 'optional') {
		this.blur();
	}
}

// Copy an text field from one part of a form to other parts
function copyInputText(thisPtr,putIds) {
	var i,input,parts,inputName;
	if (typeof thisPtr == 'string') {
		inputName = null;
		if (thisPtr.indexOf('.') >= 0) {
			parts = thisPtr.split('.');
			thisPtr = parts[0];
			inputName = parts[1];
		}
		thisPtr = document.getElementById(thisPtr);
		if (inputName) {
			thisPtr = thisPtr[inputName];
		}
	}
	if (thisPtr) {
		for (i=0; i<putIds.length;++i) {
			putId = putIds[i];
			if (thisPtr.form[putId] !== undefined) {
				putPtr = thisPtr.form[putId];
				if (putPtr) {
					putPtr.value = thisPtr.value;
				}
			}
			else {
				putPtr = document.getElementById(putId);
				if (putPtr) {
					putPtr.innerHTML = thisPtr.value;
				}
			}
		}
	}
	return false;
}

// Put the total of two dollar amounts into a third
function inputSumUpdate(thisPtr,ops,total) {
	var i,opPtr,valueError,totalValue;
	totalValue = 0.0;
	if (ops) {
		if (typeof ops == 'string') {
			ops = [ ops ];
		}
		for (i=0; i<ops.length; ++i) {
			if (thisPtr.form[ops[i]] != undefined) {
				opPtr = thisPtr.form[ops[i]];
				valueError = checkApplicationElement(opPtr,false,'price',10,false);
				if (!valueError[1]) {
					thisValue = parseFloat(valueError[0]);
					if (!isNaN(thisValue)) {
						totalValue += thisValue;
					}
				}
			}
		}
	}
	thisPtr.form[total].value = '$'+formatFloat(totalValue,2);
}

// Only one of these text boxes may be set
function thisOrThat(thisPtr,thisName,thatName) {
	if (thisPtr) {
		if (thisPtr.name == thatName) {
			thisTemp = thisName;
			thisName = thatName;
			thatName = thisTemp;
		}
		// Reset the other if this one containsa a value
		if (trim(thisPtr.value) !== '') {
			thisPtr.form[thatName].value = '';
		}
	}
}

function formatFloat(number,points) {
	var numberStr,decimalPoint,parts,rounding;
	numberStr = number.toString();
	parts = [numberStr,''];
	decimalPoint = numberStr.indexOf('.');
	if (decimalPoint >= 0) {
		parts = numberStr.split('.');
	}
	if (parts[1].length > points) {
		rounding = parseFloat('.'+parts[1].substr(points));
		parts[1] = (parseInt(parts[1].substr(0,points)) + (rounding > 0.5 ? 1 : 0))+'';
	}
	while (parts[1].length < points) {
		parts[1] += '0';
	}
	return parts[0]+'.'+parts[1];
}

function showPreview(infoId,productId) {
	var infoPtr,showDiv;
	if (productId && infoId) {
		infoPtr = document.getElementById(infoId);
	}
	if (infoPtr) {
		loadContent('/cgi-bin/elife/catalog/product_info.php','products_id='+productId+'&printable_page=Y','get',infoId);
		showDiv = findParentNode(infoPtr,'div');
		if (showDiv) {
			showDiv.className = '';
		}
	}
}

function mapTest(thisPtr,mapDivId) {
	var address,city,state,zip,message,mapDivPtr,showDiv,thisForm;
	thisForm = thisPtr.form;
	address = thisForm.p_products_street_address.value;
	city = thisForm.p_products_city.value;
	state = (thisForm.p_products_state.selectedIndex ? thisForm.p_products_state.options[thisForm.p_products_state.selectedIndex].text : '');
	zip = thisForm.p_products_post_code.value;
	mapDivPtr = document.getElementById(mapDivId);
	message = '';
	if (address=='') {
		message += "Please enter an address\n";
	}
	if (city=='') {
		message += "Please enter a city\n";
	}
	if (state=='') {
		message += "Please enter a state\n";
	}
	if (zip=='') {
		message += "Please enter a zip\n";
	}
	if (message) {
		alert(message);
	}
	else if (mapDivPtr) {
		guestSearch = window.open('http://www.mapquest.com/maps/map.adp?'+'address='+encodeURI(address)+'&zipcode='+zip, 'guestSearch', 'scrollbars=yes,resizable=yes,width=800,height=700,menubar=no,location=no,left=40,top=150');
	}
}

function hostFaithReview(thisPtr,allTabIds,allIds,fieldSpecs,status) {
	var errors,errorMsg,stopError,checkFields;
	errorMsg = '';
	if (allTabIds) {
		showHide(allIds,allIds,'applicationBody');
		highLightAll('applicationMenuTitleSel','applicationBody');
	}
	if (fieldSpecs) {
		checkFields = {  };
		checkFieldChecks = [  ];
		errors = checkActivityForm(thisPtr.form,fieldSpecs,checkFields,checkFieldChecks);
		errorMsg = errors[0];
		stopError = errors[1];
	}
	if (errorMsg) {
		alert("Please fix the higlighted elements.\n\n"+errorMsg);
	}
	else {
		thisPtr.form.submode.value = status;
		if (status == '') {
			thisPtr.form.step.value = '';
		}
		thisPtr.form.submit();
	}
	return false;
}
function hostAppReview(thisPtr,allTabIds,allIds,fieldSpecs,status) {
	var errors,errorMsg,stopError,checkFields;
	checkFields = { 'i_characteristics[]':['',''] };
	checkFieldChecks = [ checkBoxesCount ];
	showHide(allIds,allIds,'applicationBody');
	highLightAll('applicationMenuTitleSel','applicationBody');
	errors = checkActivityForm(thisPtr.form,fieldSpecs,checkFields,checkFieldChecks);
	errorMsg = errors[0];
	stopError = errors[1];
	if (errorMsg) {
		alert("Please fix the higlighted elements.\n\n"+errorMsg);
	}
	else {
		thisPtr.form.submode.value = status;
		thisPtr.form.submit();
	}
	return false;
}

// Review the Activity application.  Alert a message if there are errors
function finalReview(thisPtr,allTabIds,allIds,fieldSpecs,categories_status) {
	var errors,errorMsg,stopError,checkFields,checkFieldChecks,checkFieldStopChecks;
	checkFields = {
		'c_date_start':['',''],'c_date_end':['',''],
		'p_products_time_arrival':['',''],'p_products_time_start':['',''],'p_products_time_end':['',''],'p_products_time_end_estimate':['',''],
		'p_participant_type':['',''],'p_any_cohost_reason':['',''],'h_customers_gender0':['',''],'s_customers_gender':['',''],
		'c_age_range_start':['',''],'c_age_range_end':['',''],'c_life_stage':['',''],'c_permit_alcohol':['',''],
		't_customers_id0':['',''],'p_products_potluck_type':['',''],'p_signupDate':['','']
	};
	checkFieldChecks = [checkActivityDate,checkActivityCohost,checkActivityAgeRange,checkOptional];
	checkFieldStopChecks = [checkActivityConflicts];

	conflictTimer.categories_status = categories_status;
	conflictTimer.thisPtr = thisPtr;
	showHide(allIds,allIds,'applicationBody');
	highLightAll('applicationMenuTitleSel','applicationBody');
	errors = checkActivityForm(thisPtr.form,fieldSpecs,checkFields,checkFieldChecks,checkFieldStopChecks);
	errorMsg = errors[0];
	stopError = errors[1];
	if (errorMsg) {
		alert("Please fix the higlighted elements.\n\n"+errorMsg);
	}
	return false;
}

function submitSubmodeForm(thisPtr,submode) {
	thisPtr.form.submode.value=submode;
	thisPtr.form.submit();
}

function submitForApproval(thisPtr,allTabIds,allIds,fieldSpecs,submitMode) {
	var errors,errorMsg,stopError;
	checkFields = {
		'c_date_start':['',''],'c_date_end':['',''],
		'p_products_time_arrival':['',''],'p_products_time_start':['',''],'p_products_time_end':['',''],'p_products_time_end_estimate':['',''],
		'p_participant_type':['',''],'p_any_cohost_reason':['',''],'h_customers_gender0':['',''],'s_customers_gender':['',''],
		'c_age_range_start':['',''],'c_age_range_end':['',''],'c_life_stage':['',''],'c_permit_alcohol':['',''],
		't_customers_id0':['',''],'p_products_potluck_type':['',''],'p_signupDate':['','']
	};
	checkFieldChecks = [checkActivityDate,checkActivityCohost,checkActivityAgeRange,checkOptional];
	checkFieldStopChecks = [checkActivityConflicts];
	showHide(allIds,allIds,'applicationBody');
	highLightAll('applicationMenuTitleSel','applicationBody');
	errors = checkActivityForm(thisPtr.form,fieldSpecs,checkFields,checkFieldChecks,checkFieldStopChecks);
	errorMsg = errors[0];
	stopError = errors[1];
	if (errorMsg) {
		alert("Please fix the higlighted elements.\n"+errorMsg);
	}
	if (!stopError) {
		thisPtr.form.submode.value=submitMode;
		thisPtr.form.submit();
	}
	return false;
}

function checkActivityForm(thisPtr,fieldSpecs,checkFields,checkFieldChecks,checkFieldStopChecks) {
	var i,fieldSpec,element,elementName,required,optional,optionalName,fieldType,error,errorMsg,stopError,checkErrors;

	errorMsg = '';
	stopError = false;
	for (i=0; i<fieldSpecs.length; i++) {
		thisFieldSpec = fieldSpecs[i]+'|||||';
		fieldSpec = thisFieldSpec.split('|');
		elementName = fieldSpec[0];
		element = thisPtr[elementName];
		required = (fieldSpec[1].indexOf('R') >= 0);
		optional = (fieldSpec[1].indexOf('O') >= 0);
		optionHeader = (fieldSpec[1].indexOf('H') >= 0);
		optionalName = (fieldSpec[1].indexOf('Z') >= 0);
		fieldType = ( optionalName ? 'optional' : fieldSpec[2] );
		fieldSize = fieldSpec[3];
		fieldDesc = fieldSpec[4];
		if (element) {
			nonAlertClass = '';
			valueError = checkApplicationElement(element,required,fieldType,fieldSize,optional,elementName);
			value = valueError[0];
			error = valueError[1];
			if (fieldType == 'date') {
				element = 'date'+elementName;
				nonAlertClass = 'dateInput';
			}
			else if (fieldType == 'extrayn') {
				nonAlertClass = 'applicationExtra';
			}
			error = applicationElementClass(element,required,error,nonAlertClass);
			if (error) {
				//alert('elementName='+elementName+', value='+value+', fieldDesc='+fieldDesc);
				errorMsg += fieldDesc+"\n";
				value = '';
				stopError = true;
			}
			if (checkFields[elementName] !== undefined) {
				checkFields[elementName] = [value,fieldDesc];
			}
		}
	}
	checkErrors = [];
	if (checkFieldChecks !== undefined) {
		for (i=0; i<checkFieldChecks.length; ++i) {
			checkErrors[i] = checkFieldChecks[i](thisPtr,checkFields);
		}
	}
	for (i=0; i<checkErrors.length; ++i) {
		errorMsg += checkErrors[i][0];
		stopError = stopError || checkErrors[i][1];
	}
	if (!stopError) {
		if (checkFieldStopChecks !== undefined) {
			for (i=0; i<checkFieldStopChecks.length; ++i) {
				checkFieldStopChecks[i](thisPtr,checkFields);
			}
		}
	}
	return [errorMsg,stopError];
}

function xmlNodeContent(xmlNode) {
	var nodeValue;
	nodeValue = '';
	// Extract and decode the xml content
	if (xmlNode) {
		if (xmlNode.textContent !== undefined) {
			nodeValue = xmlNode.textContent;
		} else {
			nodeValue = (xmlNode.nodeTypedValue !== undefined ? xmlNode.nodeTypedValue : '');
		}
		nodeValue = decodeURIComponent(nodeValue.replace(/[+]/g,' '));
	}
	return nodeValue;
}

function checkOptional(thisPtr,checkFields)
{
	var participationText;
	errorMsg = '';
	stopError = false;
	if (thisPtr.products_potluck_type[0].checked) {
		participationText = trim(checkFields.p_products_potluck_type[0]);
		if (participationText.length < 2) {
			errorMsg += 'Guest Participation Text is missing'+"\n";
			applicationElementClass('venue_form.p_products_potluck_type',false,true);
			stopError = true;
		}
	}
	return [errorMsg,stopError];
}
function checkBoxesCount(thisPtr,checkFields)
{
	var i,checked;
	errorMsg = '';
	stopError = false;
	checked = 0;
	i_characteristics = thisPtr['i_characteristics[]'];
	if (i_characteristics !== undefined) {
		for (i=0; i<i_characteristics.length; ++i) {
			if (i_characteristics[i].checked) {
				++checked;
			}
		}
	}
	if (checked < 10) {
		errorMsg += 'You must check at least 10 characteristics'+"\n";
		applicationElementClass('venue_form.i_characteristics[]',false,true,'checkBox');
		stopError = true;
	}
	return [errorMsg,stopError];
}
function checkActivityConflicts(formPtr,checkFields)
{
	var c_date_start,c_date_end,p_products_time_arrival,p_products_time_end,date_start,date_end,hostId,cohostId,loadTimeStamp;
	var i,j,conflictsNodes,conflictNodes,conflict,xmlHttpResultPtr,xmlProcessor,location;
	c_date_start = checkFields.c_date_start[0];
	c_date_end = checkFields.c_date_end[0];
	p_products_time_arrival = checkFields.p_products_time_arrival[0];
	p_products_time_end = checkFields.p_products_time_end[0];
	if (!p_products_time_end) {
		p_products_time_end = checkFields.p_products_time_end_estimate[0];
	}
	hostId = formPtr.hostId.value;
	categories_id = formPtr.linkId.value;
	cohostId = checkFields.t_customers_id0[0];
	if (c_date_start && c_date_end && p_products_time_arrival && p_products_time_end) {
		c_date_start = c_date_start/1000;
		c_date_end = c_date_end/1000;
		date_time_start = c_date_start + (p_products_time_arrival/100)*3600 + (p_products_time_arrival%100)*60;
		date_time_end = c_date_end+(p_products_time_end/100)*3600 + (p_products_time_end%100)*60;
		formPtr.xmlHttpResult.value = '';
		xmlHttpResultPtr = document.getElementById('xmlHttpResult');

		xmlProcessor = function (xml) {
			var conflicts;
			if (xmlHttpResultPtr) {
				xmlHttpResultPtr.value = '';
				conflictsNodes = (typeof xml == 'object' ? xml.getElementsByTagName('conflicts') : []);
				for (i=0; i<conflictsNodes.length; ++i) {
					conflictNodes = conflictsNodes[i].getElementsByTagName('conflict');
					for (j=0; j<conflictNodes.length; ++j) {
						conflictNode = conflictNodes[j];
						xmlHttpResultPtr.value += xmlNodeContent(conflictNode)+"\n";
					}
				}
			}
			xmlHttpResultPtr.value += "enddne\n";
		}

		location = window.location.toString().split('/');
		location.pop();
		location.pop();
		location = location.join('/');
		loadContent(location+'/catalog/checkConflicts.php','start='+c_date_start+'_'+p_products_time_arrival+'&end='+c_date_end+'_'+p_products_time_end+'&hid='+hostId+'&chid='+cohostId+'&cid='+categories_id,'get',null,xmlProcessor);
		checkActivityConflicts.url = 'start='+c_date_start+'_'+p_products_time_arrival+'&end='+c_date_end+'_'+p_products_time_end+'&hid='+hostId+'&chid='+cohostId+'&cid='+categories_id;
		conflictTimer.loadTimeStamp = timeStampSeconds();
		window.setTimeout(conflictTimer,100);
	}
}

// Timer waits for the conflict fetch to end
function conflictTimer()
{
	var xmlHttpResultPtr,results,i,end;
	xmlHttpResultPtr = document.getElementById('xmlHttpResult');
	if (xmlHttpResultPtr && ((timeStampSeconds() - conflictTimer.loadTimeStamp) < 30) && (xmlHttpResultPtr.value.indexOf('enddne')<0)) {
		window.setTimeout(conflictTimer,100);
	}
	else if (xmlHttpResultPtr.value.indexOf('enddne') >= 0) {
		results = xmlHttpResultPtr.value.split('enddne');
		if (results[0]) {
			alert(results[0]);
		}
		else if (conflictTimer.categories_status != 'C') {
			conflictTimer.thisPtr.className = 'noDisplay';
			conflictTimer.thisPtr.form.forApproval.className = '';
			if (conflictTimer.thisPtr.forReturn !== undefined) {
				conflictTimer.thisPtr.forReturn.className = '';
			}
		}
	}
	else {
		alert('Timeout: '+checkActivityConflicts.url);
	}
}

function checkActivityAgeRange(thisPtr,checkFields)
{
	var c_age_range_start,c_age_range_end,c_life_stage,c_permit_alcohol,errorMsg,stopError;
	errorMsg = '';
	stopError = false;
	// Check for cohost problems
	c_age_range_start = parseInt(checkFields.c_age_range_start[0]);
	c_age_range_end = parseInt(checkFields.c_age_range_end[0]);
	c_life_stage = checkFields.c_life_stage[0];
	c_permit_alcohol = checkFields.c_permit_alcohol[0];
	if (c_permit_alcohol=='P') {
		if ((c_age_range_start !== '') && (c_age_range_start < 21)) {
			thisPtr.c_age_range_start.value = '21';
			errorMsg += 'For all eLife activities where adult beverages are an individual choice, the minimum age is automatically set to 21'+"\n";
			c_age_range_start = 21;
		}
		if ((c_age_range_start !== '') && (c_age_range_end !== '')) {
			if (c_age_range_start>c_age_range_end) {
				errorMsg += 'Start Age is Greater than End Age'+"\n";
				applicationElementClass('venue_form.c_age_range_start',false,true);
				applicationElementClass('venue_form.c_age_range_end',false,true);
				stopError = true;
			}
		}
		if (c_life_stage=='Y') {
			thisPtr.c_life_stage[0].checked = false;
			thisPtr.c_life_stage[1].checked = true;
		}
	}
	else if (c_age_range_start && (c_age_range_start < 18)) {
		thisPtr.c_age_range_start.value = '18';
		errorMsg += 'The minimum age for adult guests is automatically set to 18'+"\n";
	}
	return [errorMsg,stopError];
}

function checkActivityDate(thisPtr,checkFields)
{
	var errorMsg,thisStopError,stopError,today,todayStr;
	var c_date_start,c_date_end,p_products_time_arrival,p_products_time_start,p_products_time_end,products_time_end_estimate;
	var p_signupDate;
	errorMsg = '';
	stopError = false;
	// Check for Date sanity
	today = new Date();
	todayStr = (today.getMonth()+1)+'/'+today.getDate()+'/'+today.getFullYear();
	today = Date.parse(todayStr);
	c_date_start = checkFields.c_date_start[0];
	c_date_end = checkFields.c_date_end[0];
	p_signupDate = checkFields.p_signupDate[0];
	if (c_date_start && (c_date_start < today)) {
		errorMsg += checkFields.c_date_start[1]+' is in the past '+"\n";
		applicationElementClass('datec_date_start',false,true);
		stopError = true;
	}
	if (c_date_end && (c_date_end < today)) {
		errorMsg += checkFields.c_date_end[1]+' is in the past '+"\n";
		applicationElementClass('datec_date_end',false,true);
		stopError = true;
	}
	if (c_date_start && c_date_end && (c_date_start > c_date_end)) {
		errorMsg += checkFields.c_date_end[1]+' is before '+checkFields.c_date_start[1]+"\n";
		applicationElementClass('datec_date_end',false,true);
		stopError = true;
	}
	thisStopError = false;
	if (p_signupDate && c_date_start && (p_signupDate >= c_date_start)) {
		errorMsg += 'Signup Date is after or on the Start Date'+"\n";
		stopError = thisStopError = true;
	}
	applicationElementClass('datep_signupDate',false,thisStopError,'dateInput');
	// Check time sanity
	p_products_time_arrival = checkFields.p_products_time_arrival[0];
	p_products_time_start = checkFields.p_products_time_start[0];
	p_products_time_end = checkFields.p_products_time_end[0];
	p_products_time_end_estimate = checkFields.p_products_time_end_estimate[0];
	if (p_products_time_arrival && p_products_time_start && (p_products_time_arrival > p_products_time_start)) {
		errorMsg += checkFields.p_products_time_arrival[1]+' is after '+checkFields.p_products_time_start[1]+"\n";
		applicationElementClass('venue_form.p_products_time_arrival',false,true);
		applicationElementClass('venue_form.p_products_time_start',false,true);
		stopError = true;
	}
	if (!p_products_time_end && !p_products_time_end_estimate) {
		errorMsg += "End Time or Estimated End Time is required\n";
		applicationElementClass('venue_form.p_products_time_end',false,true);
		applicationElementClass('venue_form.p_products_time_end_estimate',false,true);
		stopError = true;
	}
	if (p_products_time_start) {
		if ((c_date_start == c_date_end) && p_products_time_end && (p_products_time_start > p_products_time_end)) {
			errorMsg += checkFields.p_products_time_end[1]+' is before '+checkFields.p_products_time_start[1]+"\n";
			applicationElementClass('venue_form.p_products_time_end',false,true);
			stopError = true;
		}
		if ((c_date_start == c_date_end) && p_products_time_end_estimate && (p_products_time_start > p_products_time_end_estimate)) {
			errorMsg += checkFields.p_products_time_end_estimate[1]+' is before '+checkFields.p_products_time_start[1]+"\n";
			applicationElementClass('venue_form.p_products_time_end_estimate',false,true);
			stopError = true;
		}
	}
	return [errorMsg,stopError];
}

function checkActivityCohost(thisPtr,checkFields)
{
	var p_participant_type,p_any_cohost_reason,s_customers_gender,h_customers_gender,errorMsg;
	errorMsg = '';
	hostError = cohostError = false;
	// Check for cohost problems.
	p_participant_type = checkFields.p_participant_type[0];
	p_any_cohost_reason = checkFields.p_any_cohost_reason[0];
	host_gender = checkFields.s_customers_gender[0];
	cohost_gender = checkFields.h_customers_gender0[0];
	//alert('p_participant_type='+p_participant_type+', host_gender='+host_gender+', cohost_gender='+cohost_gender);
	if (p_participant_type) {
		if (((p_participant_type=='M') || (p_participant_type=='F')) && (host_gender!=p_participant_type)) {
			errorMsg += 'Gender Category is incorrent '+"\n";
			hostError = true;
		}
	}
	else {
		hostError = true;
	}
	if (false && cohost_gender) {
		if (!p_any_cohost_reason && cohost_gender && ((p_participant_type=='M') || (p_participant_type=='F')) && (cohost_gender!=p_participant_type)) {
			errorMsg += 'CoHost gender is incorrect '+"\n";
			cohostError = true;
		}
		if (!p_any_cohost_reason && host_gender && cohost_gender && (p_participant_type=='C') && (host_gender == cohost_gender)) {
			errorMsg += 'CoHost gender is incorrect '+"\n";
			cohostError = true;
		}
	}
	else {
		cohostError = false;
	}
	applicationElementClass('venue_form.p_participant_type',false,hostError);
	applicationElementClass('venue_form.h_customers_name_email0',false,cohostError);
	return [errorMsg,hostError || cohostError];
}

function activity_application_timer(evt) {
	if (!evt) {
		evt = window.event;
	}
	if (activity_application_timer.startTime == undefined) {
		today = new Date();
		//todayStr = (today.getMonth()+1)+'/'+today.getDate()+'/'+today.getFullYear();
		activity_application_timer.startTime = Date.parse(today);
		alert(activity_application_timer.startTime);
	}
}



