/*
--REQUIRES JQUERY--
*/

function limitChars(textarea, limit, infodiv) {
	var text = textarea.value;
	var textlength = text.length;
	var info = document.getElementById(infodiv);
	if(textlength > limit) {
		info.innerHTML = 'You cannot write more then '+limit+' characters!';
		textarea.value = text.substr(0,limit);
		return false;
	}
	else {
		info.innerHTML = 'You have '+ (limit - textlength) +' characters left.';
		return true;
	}
}

$().ready(function() {  
 $('#addin').click(function() {  
  return !$('#courses option:selected').remove().appendTo('#selectin');
 });
 $('#addnotin').click(function() {  
  return !$('#courses option:selected').remove().appendTo('#selectnotin');  
 });
 $('#removein').click(function() {  
  return !$('#selectin option:selected').remove().appendTo('#courses');
 });
 $('#removenotin').click(function() {  
  return !$('#selectnotin option:selected').remove().appendTo('#courses');
 });
 $('#clearin').click(function() {
  $('#selectin option').each(function(i) {  
  	$(this).remove().appendTo('#courses');
  });
  return false;
 });
 $('#clearnotin').click(function() {
  $('#selectnotin option').each(function(i) {  
  	$(this).remove().appendTo('#courses');
  });
  return false;
 });
 $('#filterform').submit(function() {
 	$('#selectin option').each(function(i) {
 		$(this).attr("selected", "selected");
 	});
 	$('#selectnotin option').each(function(j) {
 		$(this).attr("selected", "selected");
 	});
 	return true;
 });
 $('#smsform').submit(function() {
 	if( $('#smsmessage').val() == '' ) {
 		alert('Unable to send a blank message');
 		return false;
 		
 	}
 	else {
 		if(confirm('Are you sure you want to send this sms?') == true) {
 			$('#smssubmit').attr('disabled','disabled');
 			return true;
 		}
 		else {
 			return false;
 		}
 	}
 });
 
 $('#emailform').submit(function() {
 	if( $('#emailmessage').val() == '' ) {
 		alert('Unable to send a blank e-mail');
 		return false;
 		
 	}
 	else {
 		if(confirm('Are you sure you want to send this e-mail?') == true) {
 			$('#emailsubmit').attr('disabled','disabled');
 			return true;
 		}
 		else {
 			return false;
 		}
 	}
 });
 
 $('#user_email').change(function() {
 	$.post('index.php?component=urbanCourse&function=checkEmail', { email : $('#user_email').val() },
 	function(data){
 		if(data == 'true') {
 			$('#errorMessage').fadeIn('slow');
 		}
 		else {
 			$('#errorMessage').fadeOut('slow');
 		}
 	}, 'text');
 });
 
 
 

 
});


