// Input field style


function update_job_categories() {
	
	var options = '';
	
	$('#select_from option').each(function(){
		options = options + $(this).val() + ',';
	});
	options = options.substr(0,options.length-1);
	$('#job_categories_off').val(options);
	
	options = '';
	
	$('#select_to option').each(function(){
		options = options + $(this).val() + ',';
	});
	options = options.substr(0,options.length-1);

	$('#job_categories').val(options);

}

$(document).ready(function(){
  	
   	//*******************************************************************************************************************
	//EXECUTES TIMEOUT TO KEEP THE USERS SESSION ALIVE
	//*******************************************************************************************************************
	var stayalive = setTimeout(stay_alive,30000);
	

	$('#btn_add').click(function(){
		$('#select_from option:selected').each( function() {
			$('#select_to').append("<option value='"+$(this).val()+"'>"+$(this).text()+"</option>");
			$(this).remove();
			update_job_categories();
		});
	});
	
	$('#btn_remove').click(function(){
		$('#select_to option:selected').each( function() {
			$('#select_from').append("<option value='"+$(this).val()+"'>"+$(this).text()+"</option>");
			$(this).remove();
			update_job_categories();
		});
	});
	
	update_job_categories();
	
	$('#agreement-field').val($('#agreement').html());
	
	$('#add-references').click(function(){
		
		var start = $('input[name="references_count[]"]').length;
		
		$.post('#', { action: 'add-references', start: start },function(data) {
			$('#references_wrapper').append(data);
		});
	
	});
	
	$('#add-employment').click(function(){
		
		var start = $('input[name="employment_count[]"]').length;
		
		$.post('#', { action: 'add-employment', start: start },function(data) {
			$('#employment_wrapper').append(data);
		});
	
	});
	
/*
	$('.inputfile_wrapper').file({name:'file'}).choose(function(e, input) {
   		$('.inputfile_text',this).val(input.val());
	});
*/



});

// ===================================================================
// Author: Matt Kruse <matt@mattkruse.com>
// WWW: http://www.mattkruse.com/
//
// NOTICE: You may use this code for any purpose, commercial or
// private, without any further permission from the author. You may
// remove this notice from your final code if you wish, however it is
// appreciated by the author if at least my web site address is kept.
//
// You may *NOT* re-distribute this code in any way except through its
// use. That means, you can include it in your product, or your web
// site, or any other form where the code is actually being used. You
// may not put the plain javascript up on your site for download or
// include it in your javascript libraries for download. 
// If you wish to share this code with others, please just point them
// to the URL instead.
// Please DO NOT link directly to my .js files from your site. Copy
// the files to your server and use them there. Thank you.
// ===================================================================

// -------------------------------------------------------------------
// TabNext()
// Function to auto-tab phone field
// Arguments:
//   obj :  The input object (this)
//   event: Either 'up' or 'down' depending on the keypress event
//   len  : Max length of field - tab when input reaches this length
//   next_field: input object to get focus after this one
// -------------------------------------------------------------------
var phone_field_length=0;
function TabNext(obj,event,len,next_field) {
	if (event == "down") {
		phone_field_length=obj.value.length;
		}
	else if (event == "up") {
		if (obj.value.length != phone_field_length) {
			phone_field_length=obj.value.length;
			if (phone_field_length == len) {
				next_field.focus();
				}
			}
		}
	}

//***********************************************************************************************************************
//SETS RECURSIVE TIMEOUT TO KEEP THE USERS SESSION ALIVE
//***********************************************************************************************************************
function stay_alive() {
	$.post("index.php", { action: "stayalive" });
	stayalive = setTimeout(stay_alive,30000);
}
