jQuery.fn.toggleFade = function(speed, easing, callback) {
	return this.animate({opacity: 'toggle'}, speed, easing, callback);
};
jQuery.toggleCookie = function(Cookie) {
	$.cookie(Cookie,$.cookie(Cookie) == 1 ? 0 : 1);
};
function getProgramsByKeywords(keywords) {
	if(keywords.length > 3){
		$.AjaxCFC(
		{
			url: _ajaxConfig._cfscriptLocation,
			method: "ajaxGetProgramByKeywords",
			data: {"Keywords":keywords},
			success: function(rs) {
				popRS(rs);
			}
		}
		);
	}
}
function cycleInit(id,progID,bCurrent,msgDiv,bActive) {
	$.AjaxCFC(
	{
		url: _ajaxConfig._cfscriptLocation,
		method: "getAllProgramTerms",
		data: {"Program_ID":progID,"bShowCurrent":bCurrent,"bShowActive":bActive},
		success: function(rs) {
			populateSelectBox(id,rs,true);
			if(bCurrent){
				$('#cycleMsg').show();
				$('#cycleMsg2').hide();
			} else {
				$('#cycleMsg').hide();
				$('#cycleMsg2').show();
			}
		}
	}
	);
}
function responseInit(id,callingId,targetId,spID,selFirst) {
	$.AjaxCFC(
	{
		url: _ajaxConfig._cfscriptLocation,
		method: "ajaxGetStudentParamUniqueResponses",
		data: {"Student_Param_ID":spID},
		success: function(rs) {
			populateSelectBox(id,rs,selFirst);
			$('#'+targetId).show();
			$('#'+callingId).hide();
			$('#'+id+' option:eq(1)').css({'background-color':'#efefef'});
			try {
				eval('_cb_restoreSP'+spID+'()');
			} catch(e) {}
		}
	}
	);
}
function responseDefault(id,callingId,targetId,spID,selFirst) {
	$.AjaxCFC(
	{
		url: _ajaxConfig._cfscriptLocation,
		method: "ajaxGetStudentParamAllOptionValues",
		data: {"Student_Param_ID":spID},
		success: function(rs) {
			populateSelectBox(id,rs,selFirst);
			$('#'+targetId).show();
			$('#'+callingId).hide();
			$('#'+id+' option:eq(1)').css({'background-color':'#efefef'});
			try {
				eval('_cb_restoreSP'+spID+'()');
			} catch(e) {}
		}
	}
	);
}
function prgInit(id) {
		$.AjaxCFC(
		{
			url: _ajaxConfig._cfscriptLocation,
			method: "ajaxGetPrograms",
			data: {},
			success: function(rs) {
				populateSelectBox(id,rs);
			}
		}
	);
}
function prgGrpInit(id) {
		$.AjaxCFC(
		{
			url: _ajaxConfig._cfscriptLocation,
			method: "ajaxGetProgramGroups",
			data: {},
			success: function(rs) {
				populateSelectBox(id,rs);
			}
		}
	);
}
function sponsorInit(id) {
		$.AjaxCFC(
		{
			url: _ajaxConfig._cfscriptLocation,
			method: "ajaxGetSponsors",
			data: {},
			success: function(rs) {
				populateSelectBox(id,rs);
			}
		}
	);
}
function meta01Init(id) {
		$.AjaxCFC(
		{
			url: _ajaxConfig._cfscriptLocation,
			method: "ajaxGetMETA01",
			data: {},
			success: function(rs) {
				populateSelectBox(id,rs);
			}
		}
	);
}
function meta02Init(id) {
		$.AjaxCFC(
		{
			url: _ajaxConfig._cfscriptLocation,
			method: "ajaxGetMETA02",
			data: {},
			success: function(rs) {
				populateSelectBox(id,rs);
			}
		}
	);
}
function spInit(id,types) {
		$.AjaxCFC(
		{
			url: _ajaxConfig._cfscriptLocation,
			method: "ajaxGetStudentParameters",
			data: {"restrictToTypes":types},
			success: function(rs) {
				populateSelectBox(id,rs);
			}
		}
	);
}
function spValuesInit(id,sp) {
		$.AjaxCFC(
		{
			url: _ajaxConfig._cfscriptLocation,
			method: "ajaxGetStudentParameterValues",
			data: {"id":sp},
			success: function(rs) {
				populateSelectBox(id,rs);
			}
		}
	);
}
function paramValInit(id,val) {
		$.AjaxCFC(
		{
			url: _ajaxConfig._cfscriptLocation,
			method: "ajaxGetProgramParameterValues",
			data: {"Param_ID":val},
			success: function(rs) {
				populateSelectBox(id,rs);
			}
		}
	);
}
function fscInit(id,context,val) {
		$.AjaxCFC(
		{
			url: _ajaxConfig._cfscriptLocation,
			method: "ajaxGetSchools",
			data: {"vchcontext":context, "vchvalue":val},
			success: function(rs) {
				populateSelectBox(id,rs);
			}
		}
	);
}
function termInit(id,msgDiv) {
		$.AjaxCFC(
		{
			url: _ajaxConfig._cfscriptLocation,
			method: "getApplicationCycleTerms",
			data: {"Status": "all"},
			success: function(rs) {
				populateSelectBox(id,rs);
				$('#'+msgDiv).hide();
			}
		}
	);
}
function killObjPermission(iUserID,iObjectID,vchKeyID,objDiv,bRemoveAll){
		$.AjaxCFC(
		{
			url: _ajaxConfig._cfscriptLocation,
			method: "ajaxRemoveObjectPermission",
			data: {"iUserID": iUserID,"iObjectID":iObjectID,"vchKeyID":vchKeyID,"bRemoveAll":bRemoveAll},
			success: function(rs) {
				if(bRemoveAll){
					$('#all-'+objDiv).remove();
					$('#rem-'+objDiv).remove();
				} else {
					$('#'+objDiv).remove();
					var tmp = objDiv.split('-')[0];
					if($.trim($('#all-'+tmp).html())=='') {
						$('#rem-'+tmp).remove();
					}
				}
			}
		}
	);
}
function killGroupObjPermission(iGroupID,iObjectID,vchKeyID,objDiv,bRemoveAll){
		$.AjaxCFC(
		{
			url: _ajaxConfig._cfscriptLocation,
			method: "ajaxRemoveGroupObjectPermission",
			data: {"iGroupID": iGroupID,"iObjectID":iObjectID,"vchKeyID":vchKeyID,"bRemoveAll":bRemoveAll},
			success: function(rs) {
				if(bRemoveAll){
					$('#all-'+objDiv).remove();
					$('#rem-'+objDiv).remove();
				} else {
					$('#'+objDiv).remove();
					var tmp = objDiv.split('-')[0];
					if($.trim($('#all-'+tmp).html())=='') {
						$('#rem-'+tmp).remove();
					}
				}
			}
		}
	);
}
function populateSelectBox(id,rs,bSelFirst) {
	RS = eval(rs['DATA']);
	var frmElem = document.getElementById(id);
	var options = '';
	if(RS.length > 0){
		for (var i = 0; i < RS.length; i++) {
			options += '<option value="' + RS[i].id + '">' + RS[i].name + '</option>';
		}
		$("select#"+id).html(options);
		if(!bSelFirst){
			frmElem.selectedIndex = -1;
		} else {
			frmElem.selectedIndex = 0;
		}
		frmElem.disabled=false;
	} else {
		$("select#"+id).html('No records exit.');
	}
}

function selectItems(id,itemArray) {
	var frmElem = document.getElementById(id);
	for(i=0;i<frmElem.options.length;i++){
		optValue = frmElem.options[i].value;
		for(j=0;j<itemArray.length;j++){
			if(optValue === itemArray[j]){
				frmElem.options[i].selected = true;
			}
		}
	}
}
function ammapcont(continent) {
		$.AjaxCFC(
		{
			url: _ajaxConfig._cfscriptLocation,
			method: "GetAmapContinent",
			data: {"vchContinent":continent},
			success: function(rs) {
				flashMovie.setData(rs['DATA']);
			}
		}
	);
}
function setProgramPins(country) {
		$.AjaxCFC(
		{
			url: _ajaxConfig._cfscriptLocation,
			method: "GetAmapProgramPins",
			data: {"vchCountry":country},
			success: function(rs) {
				flashMovie.setData(rs['DATA']);

			/*	flashMovie.setSettings("<settings><area> <color_selected>#000000</color_selected></area></settings>");*/
			/*flashMovie.setParam('area.color_selected', "#000000")	;

*/
			}
		}
	);
}
function getNote(id) {
		$.AjaxCFC(
		{
			url: _ajaxConfig._cfscriptLocation,
			method: "getNoteData",
			data: {"id":id},
			success: function(rs) {
			document.getElementById('notes-content-border').innerHTML="";
			for(i=0;i<rs.length;i++){
			document.getElementById('notes-content-border').innerHTML = document.getElementById('notes-content-border').innerHTML +'<b>'
			+rs[i]['NOTE_DATE']+'</b>'+'&nbsp;'+'<span	class="fc" onclick="deleteNote('+rs[i]['NOTEID']+','+id+');">[X]</span></font>'+'<br>'+ rs[i]['TEXT']+'<br>'
			+'<br>';

			}

			}
		}
	);
}

function adNotes(id,cont,noteDate) {
		$.AjaxCFC(
		{
			url: _ajaxConfig._cfscriptLocation,
			method: "addNotes",
			data: {"id":id,"cont":cont,"noteDate":noteDate},
			success: function(rs) {	getNote(id);
				document.getElementById('newNote').style.display='none';
			}
		}
	);
}

function informAboutActivation(){
	alert('The Terra Dotta Location Web Service requires activation before its initial use. You will be take to the activation area now.');
	location.href='index.cfm?FuseAction=Administration.ActivateTDCL';
}

function getLocation(program_city) {
		$.AjaxCFC(
		{
			url: _ajaxConfig._cfscriptLocation,
			method: "getLocatn",
			data: {"program_city":program_city},
			success: function(rs)
			{
				if(rs == 999) {
					informAboutActivation();
				} else {
					document.getElementById('selAvailable').length = 0;
					if(rs.length>0){
						for(i=0;i<rs.length;i++){ /*qryTDCLContent.asciiname = replaceList(qryTDCLContent.asciiname,chr(8216) & "," & chr(8217) & "," & chr(8220) & "," & chr(8221) & "," & chr(8212) & "," & chr(8213) & "," & chr(8230),"',',"","",--,--,..."); */
							if(rs[i]['COUNTRY'] != '')
								var info=rs[i]['TEXT']+','+' '+rs[i]['COUNTRY']+' ('+rs[i]['REGION']+')';
							else
								var info=rs[i]['TEXT'];
							var latLong=rs[i]['LATITUDE']+'/'+rs[i]['LONGITUDE'];
							document.getElementById('selAvailable').options[i] = new Option(info,latLong);
						}
					} else {
						alert('The Terra Dotta Location Web Service did not find a match for this location. You may choose to modify the name and search again.');
					}
				}
			}
		}
	);
}
function getLatitude(program_city,program_country,optionValue,latitude,longitude)
{
	$.AjaxCFC(
	{
		url: _ajaxConfig._cfscriptLocation,
		method: "getLocatn",
		data: {"program_city":program_city,"optionValue":optionValue,"program_country":program_country},
		success: function(rs)
		{
			if(rs == 999) {
				informAboutActivation();
			} else {
				if(rs.length == 0) {
					alert("This location could not be found in the TDLWS");
				} else if (rs.length == 1) {
					document.getElementById(latitude).value = rs[0]['LATITUDE'];
					document.getElementById(longitude).value = rs[0]['LONGITUDE'];
				} else {
					alert('There is more than one location in the Terra Dotta Location Database matching your input: ['+program_city+'], ['+program_country+'].	Use another resource to identify the proper coordinates and enter them manually.');
				}
			}
		}
	});
}
function fetchInfo(program_city,optionValue,listCount)
{
	$.AjaxCFC(
	{
		url: _ajaxConfig._cfscriptLocation,
		method: "getLocatn",
		data: {"program_city":program_city,"optionValue":optionValue},
		success: function(rs)
		{
			if(rs == 999) {
				informAboutActivation();
			} else if (rs["error"]){
				alert('an error occurred.');
			} else {
				alert(rs.length+' out of '+listCount+' locations have been updated with latitude/longitude data. Those not updated were either not found or exist as duplicate city name within the same country. For such cases, use another resource to identify the proper coordinates and enter them manually.');
				location.href='index.cfm?FuseAction=SystemSettings.Locations';
			}
		}
	});
}
function deleteNotes(noteid,id) {
		$.AjaxCFC(
		{
			url: _ajaxConfig._cfscriptLocation,
			method: "deleteNotes",
			data: {"noteid":noteid,"id":id},
			success: function(rs) {	getNote(id);
			}
		}
	);
}

