$(document).ready(function() {
	$('.search_result_more').hide();
	
	$('.search_result_more_link').click(function(event) {
		event.preventDefault();
		$(this).parent().find('.search_result_more:first').show();
	});
	
	$("#schedule tr:even td").css("background-color", "#afd652").css("color", "#ffffff");
	$("#schedule tr:odd td").css("color", "#79b977");
	
	$("#refineSearchContent select").selectbox({
		speed: 100
	});
	
	$('.edit_account_link').click(function(event) {
		event.preventDefault();
		$('#edit_account').show();
		$('html,body').animate({'scrollTop':300}, 1000);
		$('#edit_account').css('border', '3px solid #78b977');
	});

	function supports_input_placeholder() {
	  var i = document.createElement('input');
	  return 'placeholder' in i;
	}

	if(supports_input_placeholder() == false) {
		
	$('[placeholder]').focus(function() {
	  var input = $(this);
	  if (input.val() == input.attr('placeholder')) {
	    input.val('');
	    input.removeClass('placeholder');
	  }
	}).blur(function() {
	  var input = $(this);
	  if (input.val() == '' || input.val() == input.attr('placeholder')) {
	    input.addClass('placeholder');
	    input.val(input.attr('placeholder'));
	  }
	}).blur();
	
	$('[placeholder]').parents('form').submit(function() {
	  $(this).find('[placeholder]').each(function() {
	    var input = $(this);
	    if (input.val() == input.attr('placeholder')) {
	      input.val('');
	    }
	  })
	});
	}
	
	$('.set_schedule_table input[type=checkbox]').click(function(e) {
		var checkeder = $(this).is(':checked');
		var day = $(this).attr('data-day');
		var period = $(this).attr('data-period');
		var state = 0;
		if(checkeder == true) {
			state = 1;
		}
		
		$('.set_schedule_table input[type=checkbox]').attr('disabled', true);
		
		$.get('/xmlrpc/setschedule.php?day='+day+'&period='+period+'&state='+state, function(data) {
			if(data == "OK") {
				$('#setscheduleresult').html("Your schedule was successfully updated").addClass('success_notice');
			} else {
				$('#setscheduleresult').html("We failed to update your schedule. Please try again").addClass('error_notice');
			}
			$('.set_schedule_table input[type=checkbox]').attr('disabled', false);
		});
	});
	
	
	var b = $('#qualifications_input').autocomplete({ 
		serviceUrl:'/xmlrpc/account_add_qualification.php',
		minChars:2,
		width:250,
		zIndex: 9999,
		deferRequestBy: 150, //miliseconds
		onSelect: function(value, data){ document.location.href="/account/update_account.php?add_qualification="+data;/*alert(data); $('#caretype').val(data);*/}
	});

});

