var Ajax;
if (Ajax && (Ajax != null)) {
	Ajax.Responders.register( {
		onCreate : function() {
			if ($('spinner') && Ajax.activeRequestCount > 0)
				Effect.Appear('spinner', {
					duration : 0.5,
					queue : 'end'
				});
		},
		onComplete : function() {
			if ($('spinner') && Ajax.activeRequestCount == 0)
				Effect.Fade('spinner', {
					duration : 0.5,
					queue : 'end'
				});
		}
	});
}
function clickButton(id) {
	$(id).click();
}
function countChar(evt, t, cnt) {
	if (t.value.length <= 250) {
		$(cnt).innerHTML = "(" + (250 - t.value.length) + ")";
		return true;
	} else
		return false;
}

function countWords(w, cnt) {
	var y = w.value;
	var r = 0;
	a = y.replace(/\s/, ' ');
	a = a.split(' ');
	for (z = 0; z < a.length; z++) {
		if (a[z].length > 0)
			r++;
	}
//	if (r <= 250) {
		$(cnt).innerHTML = "(" + (250 - r) + ")";
		return true;
//	} else {
//		return false;

//	}

}

function setLength(t, i) {
	i.innerHTML = "(" + (250 - (t.value.length)) + ")";
}
function checkCandidateForm() {
	var ids = [ "visitedEventsNo", "tutorEventsNo", "speakerEventsNo",
			"lectureEventsNo", "yearsAsProfessor", "papersNo", "booksNo",
			"onlineSrcNo" ];
	for (i = 0; i < ids.length; i++)
		checkSingeInput(ids[i]);
}
function checkSingeInput(id) {
	if ($(id).value.match(/^Enter/))
		$(id).value = "";
}
function checkNumber(evt) {
	charCode = getCharCode(evt);
	if (charCode > 31 && (charCode < 48 || charCode > 57))
		return false;
	return true;
}
function getCharCode(evt) {
	if (!evt)
		var evt = window.event; // IE
	if (evt.keyCode)
		var charCode = evt.keyCode; // IE
	else if (evt.which)
		var charCode = evt.which; // FF
	return charCode;
}
function fnOnFocus(obj, m) {
	if (!obj.value.match(/^\d*$/) || obj.value.match(/^Enter/))
		obj.value = '';
}
function fnOnBlur(obj, m) {
	if (obj.value == '' || !obj.value.match(/^\d*$/))
		obj.value = m;
}

function confirmPasswordReset() {
	var agree = confirm("Are you sure you wish to reset the user's password?");
	if (agree)
		return true;
	else
		return false;
}

function confirmReopen() {
	var agree = confirm("Do you really want to reopen this applicant's application?");
	if (agree)
		return true;
	else
		return false;
}

function confirmSubmitApplication() {
	var agree = confirm("Are you sure you wish to submit this application? Changes cannot be made after submission.");
	if (agree)
		return true;
	else
		return false;
}
function clearSearchField(id) {
	$(id).value = '';
	return true;
}
