var job_forms = Array();

function confirm_remove(id){
	var confirmation=window.confirm("Are you sure you want to delete Job #"+id);
	if (confirmation){
		window.location = base_url+"admin/careers/remove/"+id;
	}
}

window.onload = function(){
	if($('post_date')){
		var dpck	= new DatePicker({
			relative	: 'post_date',
			language	: 'en',
			disableFutureDate: false,
			dateFormat 	: [ ["yyyy", "mm", "dd"], "-" ]
		});
	}
	
	if($("list_to_sort")){
		Sortable.create("list_to_sort", {
			tag: "div",
			only: "job_row",
			handle: "interface_move_green",
			scroll: window,
			onUpdate: function() {
				new Ajax.Request(base_url+"admin/careers/reorder_jobs", {  
					method: "post",  
					parameters: { data: Sortable.serialize("list_to_sort") },
					onSuccess: function(){
						reclass_rows("list_to_sort");
					}
				});
			}
		});
	};
	
}

function reclass_rows(elm){
	var rows = $(elm).select("div.job_row");
	var row_num = 0;
	for(x=0; x<rows.length; x++){
		elm = $(rows[x]);
		if(elm.hasClassName("job_row")){
			row_num++;
			row_class = (row_num % 2)+1;
			if(elm.hasClassName("row1")){
				elm.removeClassName('row1');
			}
			if(elm.hasClassName("row2")){
				elm.removeClassName('row2');
			}
			elm.addClassName("row"+row_class);
		}
	}
}

function open_resume_form(form_holder, contact_email, job_name){
	var resume_form = $(form_holder);
	
	job_forms.each(function(s){
		//if not the current element
		if(s != form_holder){
			//Element.hide(s);
			Effect.BlindUp(s,{
				duration: 0.4,
				afterFinish: function(){
					$(s).innerHTML = "";
				}
			});
			//$(s).innerHTML = "";
		}
	});
	
	if(resume_form.getStyle('display') == 'none'){
		resume_form.innerHTML = $('form_temp_holder').innerHTML;

		$('send_resume_form').contact_email.value = contact_email;
		$('send_resume_form').job_name.value = job_name;
		$('send_resume_form').form_id.value = form_holder;
		
		Effect.BlindDown(resume_form,{duration: 0.5});
	}else{
		Effect.BlindUp(resume_form,{
			duration: 0.4,
			afterFinish: function(){
				$(resume_form).innerHTML = "";
			}
		});
	}
}