
// ========= DHTML Window functions ================

	var win;
	
	function open_win(src, width, height, title)
	{
		if (!title)	title='-';
			
		win = dhtmlwindow.open("win-container", "iframe", src, title, "width=" + width + "px,height=" + height + "px,resize=1,scrolling=1,center=1");
	}
	
	function close_win()
	{
		parent.win.close();
	}

	
	// when viewing image, scrollbars should not be visible and height+width don't matter as window is resized
	
	function view_image(src)
	{
		win = dhtmlwindow.open("win-container", "iframe", src, 'title', "width=100px,height=100px,resize=1,scrolling=0,center=1");		
	}
	
	function close_image()
	{
		parent.win.close();
	}		
	
	
	// open send email window (global use)	
	function send_email(to, subject, template)
	{
		src = '../mail/send.php?to='+escape(to)+'&subject='+escape(subject)+'&template='+template;
		
		win = dhtmlwindow.open("win-container", "iframe", src, 'Send Email Message', "width=600px,height=450px,resize=1,scrolling=1,center=1");		
	}
	
	function close_email()
	{
		parent.win.close();
	}	
	
// ================================================
	
	
		
	
	
/* ================================================================== * 
 * 		CLIENTS
 * ================================================================== */	
	
	// opens client resume in a pop-up window
	function view_resume(id)
	{
		window.open('../clients/resume-view.php?client='+id, '', 'width=850,height=700,status=1,resizable=1,scrollbars=1');		
	}
	
	
	// send acction to validate a pending client account 
	function client_validate(id)
	{
		if (!confirm('Are you sure you want to validate this client account?'))
			return;
		
		f = document.action_form;
		
		f.action.value = "validate-client";
		f.client_id.value = id;
		f.submit();
	}
	
	
	// send action to delete one client
	function client_delete(id, redirect)
	{
		if (!confirm('Are you sure you want to delete this Client account?'))
			return;		
		
		f = document.action_form;
		
		f.action.value = "delete-client";
		f.client_id.value = id;
		f.redirect.value = redirect;
		f.submit();		
	}
	
	
	// sending email to client
	function client_send_email(client_id, template)
	{
		open_win('email-send.php?client='+client_id+'&template='+template, 600, 450);
	}
	
	
	// send action to delete selected clients in listing
	function client_delete_selected()
	{	
		f = document.action_form;
		field = f.elements['selected_clients[]'];
	
		if (!ck_checkbox(field, "Please select clients to delete"))
			return; 
	
		if (!confirm('Are you sure you want to delete selected clients?'))
			return;				
		
		f.action.value = "delete-selected-clients";
		f.submit();		
	}
	
	
	// send action to Reactivate selected clients 
	function client_reactivate_selected()
	{	
		f = document.action_form;
		field = f.elements['selected_clients[]'];
	
		if (!ck_checkbox(field, "Please select Clients"))
			return; 
	
		if (!confirm('Are you sure you want to Reactivate selected clients?'))
			return;				
		
		f.action.value = "reactivate-selected-clients";
		f.submit();		
	}	
	
	
	function clients_add_to_job_order()
	{
		f = document.action_form;
		field = f.elements['selected_clients[]'];
	
		if (!ck_checkbox(field, "Please select clients to add on Job Order"))
			return; 
	
		if (!confirm('Are you sure you want to add clients on the Job Order?'))
			return;		
		
		f.action.value = "add-to-job-order";
		f.submit();
		
	} // END function
	
	
	
	
/* ================================================================== * 
 * 		CUSTOMERS
 * ================================================================== */	
	
	// send delete customer action 
	function customer_delete(id)
	{
		if (!confirm('Are you sure you want to delete this Customer?'))
			return;
		
		f = document.action_form;
		f.action.value='delete-customer';
		f.customer_id.value = id;
		f.submit();
	}
	
	
	
	
	
/* ================================================================== * 
 * 		JOBS 
 * ================================================================== */	
		
	// send job delete action
	function job_delete(id)
	{
		if (!confirm('Are you sure you want to delete this Job?'))
			return;
		
		f = document.action_form;
		f.action.value='delete-job';
		f.job_id.value = id;
		f.submit();
	}
	

	//used when client applies for a job
	function job_apply(job_id)
	{
		if (!confirm('Are you sure you want to apply to this Job?'))
			return;
		
		f = document.action_form;
		
		f.action.value = "job-apply";
		f.job_id.value = job_id;
		f.submit();		
	}	
	
	
	// opens DHTML Win to edit job application status
	function job_status_form(application_id)
	{		
		open_win('applications-status-form.php?application='+application_id, 500, 230, '-');
	}

	
	// open DHTML window to select job category and submit approve action
	function job_approve_form(job_id)
	{
		f = document.job_approve_form;
		f.job_id.value = job_id;
		
		win = dhtmlwindow.open('divbox', 'div', 'job-approve', ' Approve Job', 'width=350px,height=150px,top=150px,resize=1,scrolling=1,center=1');			
	}
	
	
	
	
	
/* ================================================================== * 
* 		TRAINING PROGRAMS
* ================================================================== */	
	
	// send training delete action
	function training_delete(id)
	{
		if (!confirm('Are you sure you want to delete this Training Program?'))
			return;
		
		f = document.action_form;
		f.action.value='delete-training-program';
		f.training_id.value = id;
		f.submit();
	}
	
	
	// used when admin aproves client to attend training program 
	function training_accept_client(id)
	{
		if (!confirm('Are you sure you want to accept this client?'))
			return;
		
		f = document.action_form;
				
		f.action.value = "accept-client";
		f.client_training_id.value = id;
		f.submit();
	}
	
	
	// send a command to delete selected training applicants
	function training_reject_clients()
	{
		f = document.action_form;
		field = f.elements['selected[]'];
	
		if (!ck_checkbox(field, "Please select applications to delete"))
			return; 
	
		if (!confirm('Are you sure you want to delete selected training applications?'))
			return;			
		
		f.action.value = "reject-clients";
		f.submit();
	}
	
	
	//used when client applies for a training program
	function training_apply(training_id)
	{
		if (!confirm('Are you sure you want to apply to this Training Program?'))
			return;
		
		f = document.action_form;
		
		f.action.value = "training-apply";
		f.training_id.value = training_id;
		f.submit();		
	}
	
	
	// deleting category (used on job/training admin listings)
	function folder_delete(id)
	{
		if (!confirm('Are you sure you want to delete this category?'))
			return;
		
		f = document.folder_form;
		f.action.value='delete-folder';
		f.folder_id.value = id;
		f.submit();		
	}
	
	
	
	
	
/* ======================================================================================== * 
 * 									JOB ORDERS
 * ======================================================================================== */
	
	
	
	/* makes rows with Recruitment Phase to transition in a lighter color when hovering */
	function InitRecruitmentPhasesTable()
	{
		// hover effect for table rows
		$$('table.recruitment tr.row').each(function(item, index)
		{ 				
			item.addEvent('mouseenter',function(){ this.morph({'background-color':'#0654CA'}); });
			item.addEvent('mouseleave',function(){ this.morph({'background-color':'#003399'}); });
		});
	}	
	
	
	// send action to archive a Job Order
	function job_order_archive_selected()
	{
		f = document.action_form;
		
		if (!ck_checkbox(f.elements['selected[]'], 'Please select Job Orders to archive'))
			return;
		
		if (!confirm('Are you sure you want to archive selected Job Orders?'))
			return;
		
		f.action.value = "archive-selected-job-orders";
		f.submit();
	}
	

	// send action to delete a job order
	function job_order_delete(id)
	{
		if (!confirm('Are you sure you want to delete selected Job Order?'))
			return;

		f = document.action_form;
		
		f.action.value = 'delete-job-order';
		f.job_order_id.value = id; 
		f.submit();
	}
															/* =========== RECRUITMENT PROCESS ========= */
	
	var recruitment = {
			
		// update the progress completed / not_applicable checkboxes
		update_status: function(button) 
		{			
			var completed = $('status-completed');
			var not_applicable = $('status-not-applicable');
				
			if (button == 1 && not_applicable)
			{	
				not_applicable.checked = false;
				$('not-applicable').setStyle("display", completed.checked ? "none" : "inline");
			}
					
			if (button == 2 && completed)
			{	
				completed.checked = false;					
				$('completed').setStyle("display", not_applicable.checked ? "none" : "inline");						
			}
				
				
			var status = 0;
			if (completed && completed.checked) status = 1;
			if (not_applicable && not_applicable.checked) status = 2;
				
			// preparing an Ajax request to update status
			var f = document.action_form;
				
			data  = 'action=update-progress-status'; 
			data += '&job_order_id=' + f.job_order_id.value;
			data += '&step_id=' + f.step_id.value; 
			data += '&status=' + status;
				
			var req = new Request({url: 'recruitment-proc.php'}).send(data);
								
		}, // function END
	
		
		// opens form to send advertise emails to I&D partners	
		advertise_with_partners_open_form: function() 
		{			
			var f = document.action_form;
						
			var field = f.elements['selected_partners[]'];
			var job_order_id = f.job_order_id.value;
			var str = '';
			
			if (!ck_checkbox(field,'Please select partners to send emails'))
				return;
				
			for (i=0;i<field.length;i++)
				if (field[i].checked)
					str = str + field[i].value + ',';	
			
			open_win('11-advertise-with-partners.php?partners=' + str + '&job_order=' + job_order_id, 600, 450);
			
		}, // END function
		
		
		// open form to send an email to JO Customer
		customer_notification_open_form: function()
		{
			var f = document.action_form;
			var job_order_id = f.job_order_id.value;
			
			open_win('13-customer-notification.php?job_order=' + job_order_id, 600, 450);
			
		}, // END function
		
		
		// send action to accept applicant
		accept_applicant: function(id)
		{
			if (!confirm('Are you sure you want to accept this applicant?'))
				return;			
						
			var f = document.action_form;
			
			f.action.value = "accept-applicant";
			f.applicant_id.value = id;			
			f.submit();
			
		}, // END function
		
		
		//	send email to applicant
		email_applicant: function(applicant_id)
		{
			var f = document.action_form;			
			var step_id = f.step_id.value;
			
			open_win('recruitment-applicant-email.php?applicant='+applicant_id+'&step='+step_id, 600, 450);
			
		}, // END function
		
		
		// send action to accept applicant
		reject_applicant: function(id)
		{	
			if (!confirm('Are you sure you want to reject this applicant?'))
				return;
		
			var f = document.action_form;			
			
			f.action.value = "reject-applicant";
			f.applicant_id.value = id;
			f.submit();
			
		}, // END function		
		
		
		
		add_applicants: function() 							// 1.4.2 Add Applicants (step_id = 6)
		{
			var f = document.action_form;
			
			f.action.value = "add-applicants";
			f.submit();
			
		}, // END function		

				
		search_database: function()							// 1.4.3 Search Database (step_id = 7)
		{
			var f = document.action_form;
			
			f.action.value = "search-database";
			f.submit();			
			
		}, // END function				
		
		customer_approval_open_form: function()
		{
			var f = document.action_form;
			var job_order_id = f.job_order_id.value;
			
			open_win('32-customer-approval.php?job_order=' + job_order_id, 600, 450);
			
		}, // END function
		
															// 2.5 Managerial Review and Prioritization
		order_applicants: function()
		{
			var f = document.action_form;
			
			f.action.value = "order-applicants";
			f.submit();
			
		} // END function
		
		
	}; // recruitment END
	
	
																	/* ======= JOB ORDER NOTES ====== */
	// Recruitement Step Notes
	var recruitment_notes = {
		
		// opens form to add/edit a JobOrder Note	
		open_form: function(note_id) 
		{
			var job_order_id = document.action_form.job_order_id.value;
			var step_id = document.action_form.step_id.value;
		
			var url = "recruitment-notes-form.php?note="+note_id+"&job_order="+job_order_id+"&step="+step_id;
			
			open_win(url, 500, 260); 
		},
		
		
		// sends action to delete a JobOrder Note
		delete_note: function(note_id)
		{
			if (!confirm('Are you sure you want to delete this note?'))
				return;
			
			var f = document.action_form;
			f.action.value = "delete-job-order-note";
			f.note_id.value = note_id;
			
			f.submit();			
		}	
			
		
	}; // END recruitment notes
	
																		/* ======= APPLICANT NOTES ======= */
	
	// Applicant Notes
	var recruitment_applicant_notes = {
			
			open: function(applicant_id)
			{
				var step_id = document.action_form.step_id.value;
				var url = 'recruitment-applicant-notes.php?applicant=' + applicant_id + '&step=' + step_id;
				
				open_win(url, 600, 400);
				
			},	// END function
			
			
			delete_note: function(note_id)
			{
				if (!confirm('Are you sure you want to delete this note?'))
					return;
				
				var f = document.action_form;
				f.action.value = "delete-applicant-note";
				f.note_id.value = note_id;
				
				f.submit();				
				
				
			} // END function
			
	}; // recruitment_applicant_notes
	
																			/* ===== TIME TRACKER ======= */
	
	var recruitment_time = {
	
		open: function()
		{
			var job_order_id = document.action_form.job_order_id.value;
			var step_id = document.action_form.step_id.value;
	
			var url = "time-tracker.php?job_order="+job_order_id+"&step="+step_id;		
			
			open_win(url, 650, 380);
		
		}, // END function
	
		
		delete_entry: function(time_id)
		{
			if (!confirm('Are you sure you want to delete this time entry?'))
				return;
			
			var f = document.time_tracker_form;

			f.action.value = f.action_delete.value;
			f.time_id.value = time_id;
			f.submit();
			
		} // END function
		
		
	}; // recruitment_time_tracker END
	
	
	
	
																	/* ======== PHASE 4: ENROLLMENT ======== */
	
	
	
	var enroll = {
			
		step_form: function(id,value)
		{
			var title = id ? "Update Category" : "Add Category";		
		
			win = dhtmlwindow.open('divbox', 'div', 'prompt-win', title, 'width=350px,height=100px,top=150px,resize=1,scrolling=1');
			
			win.moveTo(120, 'middle');
			
			$('prompt-label').innerHTML = "Category";		
		
			var f = document.action_form;
			
			f.step_id.value = id;
			f.name.value = value;						
			f.action.value = id ? "update-step" : "add-step";
						
		}, // END function
	

		step_delete: function(id)
		{
			var f = document.action_form;
			
			if (!confirm('Are you sure you want to delete this Category?'))
				return;
			
			f.action.value = "delete-step";
			f.step_id.value = id;
			
			f.submit();
			
		}, // END function	
		
		
		field_form: function(id, step_id, value)
		{
			var title = id ? "Update Step" : "Add Step";		
			
			win = dhtmlwindow.open('divbox', 'div', 'prompt-win', title, 'width=350px,height=100px,top=150px,resize=1,scrolling=1');
			
			win.moveTo(120, 'middle');
			
			$('prompt-label').innerHTML = "Step";		
		
			var f = document.action_form;
			
			f.field_id.value = id;
			f.step_id.value = step_id;
			f.name.value = value;						
			f.action.value = id ? "update-field" : "add-field";
			
		}, // END function	
		
		
		field_delete: function(id)
		{
			var f = document.action_form;
			
			if (!confirm('Are you sure you want to delete this Enrollment Step?'))
				return;
			
			f.action.value = "delete-field";
			f.field_id.value = id;
			
			f.submit();
			
		}, // END function	
		
		
		step_info_form: function(step_id, applicant_id)
		{
			open_win('4-enrollment-step.php?step='+step_id+'&applicant='+applicant_id, 530, 360);
			
		}, // END function
		
		
		save_as_template_form: function()
		{	
			win = dhtmlwindow.open('divbox', 'div', 'prompt-win', 'Save as Template', 'width=350px,height=100px,top=150px,resize=1,scrolling=1');			
			win.moveTo(120, 'middle');
			
			$('prompt-label').innerHTML = "Name";		
		
			document.action_form.action.value = "save-as-template";
			
		}, // END function
		
		
		load_template: function()
		{
			var f = document.action_form;
			
			if (!confirm('Are you sure you want to load this template as Enrollment Steps for current Job Order?'))
				return;
			
			f.action.value = "load-template";
			f.submit();			
			
		}, // END function
		
		
		delete_template: function(id)
		{
			var f = document.action_form;
			
			if (!confirm('Are you sure you want to DELETE this Template?'))
				return;
			
			f.action.value = "delete-template";
			f.template_id.value = id;
			f.submit();				
			
		} // END function
		
		
		
		
	}; // enroll END
	
	

	
	/* ======================================================================================== * 
	 * 									QUICK SEARCH
	 * ======================================================================================== */
	
	var quick_search = {
			
		update_subskills: function(skill_id)
		{
			// sending an ajax request to get html (see Mootools Request.HTML: http://www.mootools.net/docs/Request/Request.HTML)
			$('subskill-control').load('search-proc.php?action=skills-get-subskills&skill=' + skill_id);			
		
		}, // END function
			
		
		// refresh Skill filter criteria list
		refresh_skills_filter: function()
		{			
			$('skill-criteria').load('search-proc.php?action=skills-refresh-filter');
			
		}, // END function
		
		
		// sends request to add a subskill to filter criteria and refreshes the list
		add_subskill: function()
		{
			subskill_id = $('subskill-control').value;
			
			if (!subskill_id) 
			{
				alert('Please select Subskill');
				$('subskill-control').focus();
				return;
			}	
			
			$('skill-criteria').load('search-proc.php?action=skill-filter-add&subskill_id='+subskill_id);			
			
		}, // END function
		
		
		// sends request to remove a subskill from filter criteria and refreshes the list
		remove_subskill: function(subskill_id)
		{		
			$('skill-criteria').load('search-proc.php?action=skill-filter-remove&subskill_id='+subskill_id);			
			
		}, // END function		
		
		
		
		
		
		update_residence_cities: function(state)
		{
			// sending an ajax request to get html (see Mootools Request.HTML: http://www.mootools.net/docs/Request/Request.HTML)
			$('cities-control').load('search-proc.php?action=residence-get-cities&state=' + state);			
		
		}, // END function		
		
		
		// refresh Residence filter criteria list
		refresh_residence_filter: function()
		{			
			$('residence-criteria').load('search-proc.php?action=residence-refresh-filter');
			
		}, // END function		
		
		
		// sends request to add a residence condition to filter criteria and refreshes the list
		add_residence: function()
		{
			state = $('states-control').value;
			city = $('cities-control').value;
			city_select = $('cities-control');			// this is a multi select
			
			// building an array with selected Cities
			var selected = new Array(); 			
			for (var i = 0; i < city_select.options.length; i++) 
				if (city_select.options[i].selected) 
					selected.push(city_select.options[i].value);			
			
			if (!state)
			{				
				$('states-control').focus();
				alert('Please select State');
				return;
			}	
			
			if (city == '' || city == '0')
			{
				$('cities-control').focus();
				alert('Please select City');
				return;				
			}	
				
			$('residence-criteria').load('search-proc.php?action=residence-filter-add&state='+state+'&city='+selected.join('|'));			
			
		}, // END function
		
		
		// sends request to remove a subskill from filter criteria and refreshes the list
		remove_residence: function(index)
		{		
			$('residence-criteria').load('search-proc.php?action=residence-filter-remove&index='+index);			
			
		} // END function		
		
		
		
	}; // END quick_search
	
	
	
	
	/* ======================================================================================== * 
	 * 									SPECIAL REPORTS
	 * ======================================================================================== */	
	
	
	
	var reports = {
		
		hide_recruiter_reports: function()
		{ 
			f = document.action_form;
			field = f.elements['selected_admins[]'];
			
			if (!ck_checkbox(field, "Please select Reports to delete"))
				return; 
		
			if (!confirm('Are you sure you want to delete selected Reports?'))
				return;			
			
			f.action.value = "hide-recruiter-reports";
			f.submit();
			
		},  // END function
	
		
		
		report_by_applicant_hide_entries: function()
		{
			f = document.action_form;
			field = f.elements['selected[]'];
			
			if (!ck_checkbox(field, "Please select entries that you want to remove from report"))
				return; 
		
			if (!confirm('Are you sure you want to remove selected entries from this report?'))
				return;						
			
			f.action.value = 'report-by-applicant-hide-selected';
			f.submit();
			
		} // END function
		
		
	} // END reports
	
	
	
	
	
	
	
	
	
	
	/* ======================================================================================== * 
	 * 									TIME TRAKING
	 * ======================================================================================== */
		
		// send action to delete one time_client
		function time_tracking_delete(id, redirect)
		{
			if (!confirm('Are you sure you want to delete this time entry?'))
				return;		
			
			f = document.action_form;
			
			f.action.value = "delete-time";
			f.id.value = id;
			f.redirect.value = redirect;
			f.submit();		
		}
		
		
	
	
	


	
	
	
	
	
	
	
	