function clearEmployeeListFontStyle(el)
{
	if(!$(el)) return false;
	var list = $$("a.hrEmployeeList");

		list.each( function(a){

			a.style.fontWeight = 'normal';

		});
		
	$('div1').update(); 
	el.style.fontWeight = 'bold';

}

function editGeneralInfo(form)
{

	var message = '';

	if(!$F('userFirstName')) {message += 'first name\n'; }
	if(!$F('userLastName')) {message += 'last name\n'; }
	if(!$F('userBirthDate')) {message += 'birth date\n'; }
	if(!$F('userAddress')) {message += 'address\n'; }
	if(!$F('userCity')) {message += 'city\n'; }
	if(!$F('userState')) {message += 'state\n'; }
	if(!$F('userZip')) {message += 'zip\n'; }
	if(!$F('userPhone')) {message += 'phone'; }
	if(!$F('userCompanyId')) {message += 'company ID'; }
	
	if(message) { 
	
		alert('missing required field(s)\n ' + message);
		return false;
	}

	$('update1').disabled = true;
	$('update2').disabled = true;
	$('update3').disabled = true;

	new Ajax.Updater('div1', 'processEmployees.php', {asynchronous:true, evalScripts:true, parameters:Form.serialize(form)}); 

	return false;

}

function employeeSearch(type)
{
	
	$('searchBy').value = type;

	new Ajax.Updater('divUserList', 'processEmployees.php', {asynchronous:true, evalScripts:true, parameters:Form.serialize('mainform')}); 


	return false;

}

function addEmployeeProject(form)
{
		new Ajax.Updater('divEmployeeProject', 'processEmployees.php', {asynchronous:true, evalScripts:true, parameters:Form.serialize(form)}); 
		$('contractorId').value = '';
		$('projectId').focus();

		return false;

}

function deleteEmployeeProject(employeeProjectId, employeeId)
{
		new Ajax.Updater('divEmployeeProject', 'processEmployees.php?mode=deleteEmployeeProject&employeeProjectId=' + employeeProjectId + '&employeeId=' + employeeId, {asynchronous:true, evalScripts:true}); 

		return false;

}

function deactivateEmployeeProject(employeeProjectId, employeeId)
{
		new Ajax.Updater('divEmployeeProject', 'processEmployees.php?mode=deactivateEmployeeProject&employeeProjectId=' + employeeProjectId + '&employeeId=' + employeeId, {asynchronous:true, evalScripts:true}); 

		return false;

}

function addContractor(form)
{
	var message='';

	if(!$('firstName').value) { message += 'First Name\n'; }
	if(!$('lastName').value) { message += 'Last Name\n'; }
	if(!$('locationId').value) { message += 'Office\n'; }
	if(!$('orientation').checked) { message += 'Orientation\n'; }

	if(message) { alert('Please enter the following\n' + message);  return false; }

	new Ajax.Updater('divContractorList', 'processContractor.php', {asynchronous:true, evalScripts:true, parameters:Form.serialize(form)}); 
	
	form.reset();

	return false;
	
}

function showContractorForm(contractorId)
{
	new Ajax.Updater('divContractor', 'processContractor.php?mode=showContractorForm&contractorId=' + contractorId, {asynchronous:true, evalScripts:true}); 

}

function updateContractorField(field, contractorId, checked)
{

	if(checked) { checked = 1;}else{ checked = 0; }

	new Ajax.Updater('divContractor', 'processContractor.php?mode=updateContractorField&field=' + field + '&contractorId=' + contractorId + '&checked=' + checked, {asynchronous:true, evalScripts:true, onComplete:refeshContractorList}); 
}

function deleteContractor(contractorId)
{

	if(!confirm('Delete this contractor?')) return false;

	new Ajax.Updater('divContractorList', 'processContractor.php?mode=deleteContractor&contractorId=' + contractorId, {asynchronous:true, evalScripts:true}); 
	$('divContractor').update();
	return true;

}

function refeshContractorList()
{
	
	//alert('refeshContractorList');
	new Ajax.Updater('divContractorList', 'processContractor.php?mode=refeshContractorList', {asynchronous:true, evalScripts:true}); 
	
}

function archiveEmployee(employeeId)
{
	var parms = 'mode=archiveEmployee&employeeId=' + employeeId;
	new Ajax.Updater('archive', 'processEmployees.php', {asynchronous:true, evalScripts:true, parameters:parms }); 

	return false;
}

function addEmpNote(employeeId){

    var parms = 'mode=addEmpNote&employeeId=' + employeeId + '&empNote=' + document.getElementById('newEmpNote').value;
    new Ajax.Updater('empNote', 'processEmployees.php', {asynchronous:true, evalScripts:true, parameters:parms }); 
    //new Ajax.Updater('archive', 'processEmployees.php?mode=selectUser&selectUserId3='+employeeId, {asynchronous:true, evalScripts:true}); 
    return false;
}

function loadArchive(employeeArchiveId)
{
	
	var parms = 'mode=selectUser&employeeArchiveId=' + employeeArchiveId;
	new Ajax.Updater('userInfo', 'processEmployees.php', {asynchronous:true, evalScripts:true, parameters:parms }); 

	return false;

}

function deleteArchive(employeeArchiveId, employeeId)
{
	if(!confirm('Delete this record?')) { return false; }
	var parms = 'mode=deleteEmployeeArchive&employeeArchiveId=' + employeeArchiveId + '&employeeId=' + employeeId;
	new Ajax.Updater('archive', 'processEmployees.php', {asynchronous:true, evalScripts:true, parameters:parms }); 

	return false;

}

// for AFLAC Plans Costs
function isChecked(check_input){
    var cost_input = document.getElementById(check_input.id + "Cost")
    if(check_input.checked){
        cost_input.disabled = false;
    } else {
        cost_input.disabled = true;
    }
}

// Data for benefit cost child list
// the rest of the child options are database drivin
// the child options are loaded in from processEmployees.php
var healthChildListData = "";
var dentalChildListData = "";
var visionChildListData = "";

// onchange is called when the parent value is changed
function healthPlan_OnChange(objList, curPlan, curCost) {
    var healthPlanCost = document.getElementById("healthPlanCost");

    // Remove all options from the child list
    while (healthPlanCost.options.length > 0)
        healthPlanCost.options[0] = null;

    // Lookup and get the array of values for the child list, using the parents selected value
    var healthChildData = healthChildListData[objList.options[objList.selectedIndex].value];

    // Add the options to child list
    if (healthChildData) {
        for (var i = 0; i < healthChildData.length; i++) {
            healthPlanCost.options[i] = new Option(healthChildData[i], healthChildData[i]);

            //alert(((objList.selectedIndex-2)+1) + ' : '  + curPlan  + ' / ' +  healthPlanCost.options[i].value  + ' : ' + curCost);

            // select the current value
            if(healthPlanCost.options[i].value == curCost){
                healthPlanCost.options[i].selected = true;
            }
        }
    }
}

// onchange is called when the parent value is changed
function dentalPlan_OnChange(objList, curPlan, curCost) {
    var dentalPlanCost = document.getElementById("dentalPlanCost");

    // Remove all options from the child list
    while (dentalPlanCost.options.length > 0)
        dentalPlanCost.options[0] = null;

    // Lookup and get the array of values for the child list, using the parents selected value
    var dentalChildData = dentalChildListData[objList.options[objList.selectedIndex].value];

    // Add the options to child list
    if (dentalChildData) {
        for (var i = 0; i < dentalChildData.length; i++) {
            dentalPlanCost.options[i] = new Option(dentalChildData[i], dentalChildData[i]);
            
            if(dentalPlanCost.options[i].value == curCost){
                dentalPlanCost.options[i].selected = true;
            }
        }
    }
}

// onchange is called when the parent value is changed
function visionPlan_OnChange(objList, curPlan, curCost) {
    var visionPlanCost = document.getElementById("visionPlanCost");

    // Remove all options from the child list
    while (visionPlanCost.options.length > 0)
        visionPlanCost.options[0] = null;

    // Lookup and get the array of values for the child list, using the parents selected value
    var visionChildData = visionChildListData[objList.options[objList.selectedIndex].value];

    // Add the options to child list
    if (visionChildData) {
        for (var i = 0; i < visionChildData.length; i++) {
            visionPlanCost.options[i] = new Option(visionChildData[i], visionChildData[i]);
            
            if(visionPlanCost.options[i].value == curCost){
                visionPlanCost.options[i].selected = true;
            }
        }
    }
}

// for benefit plan managment - from edit button
function editBenefitPlan(){

	var benefitPlanList = document.getElementById('benefitEdit_benefitPlan');

	var benefitPlan = benefitPlanList.options[benefitPlanList.selectedIndex].value.split("|");
	
	var benefitPlanId = document.getElementById('benefitEdit_benefitPlanId');
	var benefitPlanText = document.getElementById('benefitEdit_benefitPlanText');
	var benefitPlanCost = document.getElementById('benefitEdit_benefitPlanCost');
	var benefitPlanType = document.getElementById('benefitEdit_benefitPlanType');
	var benefitPlanActive = document.getElementById('benefitEdit_active');
	
	// if this option does not have a value, reset the fields 
	if(benefitPlanList.options[benefitPlanList.selectedIndex].value == "" || benefitPlanList.options[benefitPlanList.selectedIndex].value == "N/A"){
        benefitPlanId.value = "";
        benefitPlanText.value = "";
        benefitPlanCost.value = "";
        benefitPlanType.options[0].selected = true;
        benefitPlanActive.checked = false
        
        return false;
    }
	
	benefitPlanId.value = benefitPlan[0];
	benefitPlanText.value = benefitPlan[3];
	benefitPlanCost.value = benefitPlan[4];
	
	// benefit type dropdownlist
    for(var i=0; i < benefitPlanType.options.length; i++) {
        if(benefitPlanType.options[i].value == benefitPlan[2]){
            benefitPlanType.options[i].selected = true;
        }
     }
     
     // active checkbox
     if(benefitPlan[1] == 1){
        benefitPlanActive.checked = true;
     }
}

// for benefit plan managment - from update button
function updateBenefitPlan(){
    var benefitPlanId = document.getElementById('benefitEdit_benefitPlanId').value;
	var benefitPlanText = document.getElementById('benefitEdit_benefitPlanText').value;
	var benefitPlanCost = document.getElementById('benefitEdit_benefitPlanCost').value;
	var benefitPlanType = document.getElementById('benefitEdit_benefitPlanType');
	var benefitPlanActive = document.getElementById('benefitEdit_active').value;
	
	benefitPlanType = benefitPlanType.options[benefitPlanType.selectedIndex].value;
	
	var parms = 'mode=updateBenefitPlan&planId=' + benefitPlanId + '&planText=' + benefitPlanText + '&planCost=' + benefitPlanCost + '&planType=' + benefitPlanType + '&planActive=' + benefitPlanActive;
    new Ajax.Updater('benefitPlanUpdate', 'processEmployees.php', {asynchronous:true, evalScripts:true, parameters:parms });
    
    return false;
}

// for benefit plan managment - from create button
function createBenefitPlan(){
	var benefitPlanText = document.getElementById('benefitNew_benefitPlanText').value;
	var benefitPlanCost = document.getElementById('benefitNew_benefitPlanCost').value;
	var benefitPlanType = document.getElementById('benefitNew_benefitPlanType').value;
	
	var parms = 'mode=createBenefitPlan&planText=' + benefitPlanText + '&planCost=' + benefitPlanCost + '&planType=' + benefitPlanType + '&planActive=1';
    new Ajax.Updater('benefitPlanCreate', 'processEmployees.php', {asynchronous:true, evalScripts:true, parameters:parms }); 
    
    return false;
}
