function loadDepartmentData(ctrl, defaultValue, useValue)
{
    $('select.department').attr("disabled",true).emptySelect();
    loadListData(ctrl, defaultValue, 'department', '/xml/ServicesArea.ashx', useValue);
}


function loadListData(ctrl, defaultValue, dropdown, url, useValue)
{
    //debugger;
    var value = ''; 

    if(useValue)
    {
        value = ctrl.value;
	}
	else
	{
        for (var i=0; i < ctrl.length;i++) {
	        value += ctrl.options[i].value + ',';
	    }	 
	}

    var dropdownSet = $('select.' + dropdown);
 
    if (value == defaultValue  || value == '') 
    {
          dropdownSet.attr("disabled",true);
          dropdownSet.emptySelect();
          
  
    }
    else
    {
        dropdownSet.attr("disabled",false);
        $.getJSON(
             url,
            {id:value},
            function(data){
              dropdownSet.loadSelect(data);
            }
        );
    }
}



function selectAll(cbxBox)
{

    var bChecked = cbxBox.checked;
	
	var tbl = document.getElementById("applicantList");
	var row, cell, ctrl;
	
	for(var i=0;i<tbl.rows.length;i++)
	{
		row = tbl.rows[i];
		
		cell = row.cells[row.cells.length-1];
		
		for(var y = 0;y<cell.childNodes.length;y++)
		{
		    ctrl = cell.childNodes[y];
    		
		    if(ctrl != null && ctrl.tagName != null && ctrl.tagName == "INPUT")
		    {
			    //alert(ctrl.tagName);
			    ctrl.checked = bChecked;
		    }
		}
	}
}


function ConfirmAttach()
{
	return confirm("Are you sure you wish to attach this applicant to this vacancy?");
}

function printSelector(url)
{
	printUrl = url;
	var preview = document.getElementById("previewSelector");
	
	if(preview != null)
	{
	    preview.style.display = "block";
	    changedPreviewValue();
	}
}

function printApplicationForm(url, type)
{
	window.location.href = url + type;
}

function deleteDocument()
{
    return confirm("Are you sure you wish to delete this document?");
}

function uploadDocument(id)
{
    var obj = document.getElementById(id);
    
    if(obj != null)
    {
        try
        {
            obj.style.display = 'table-row';
        }
        catch(err)
        {
            obj.style.display = 'inline';
        }
    }
    
}

function showHideApplicationSection(ctrlId, id, valueToShow)
{
    var ctrl = document.getElementsByName(ctrlId);
    
    if(ctrl == null)
    {
        return;
    }

    for(var i=0;i<ctrl.length;i++)
    {
        if(ctrl[i].value == valueToShow)
        {
            if(ctrl[i].checked)
            {
                showRow(id);
            }
            else
            {
                hideRow(id);
            }
        }
    }
}

function showHideApplicationSectionCheckBox(ctrlId, id)
{
    var ctrl = document.getElementsByName(ctrlId);
    
    if(ctrl == null)
    {
        return;
    }

    for(var i=0;i<ctrl.length;i++)
    {
        
        if(ctrl[i].checked)
        {
            showRow(id);
        }
        else
        {
            hideRow(id);
        }
        
    }
}

function showHideApplicationSectionDDL(ctrlId, id, valueToShow)
{

    var ctrl = document.getElementsByName(ctrlId);
    
    if(ctrl == null)
    {
        return;
    }
    
    for(var i=0;i<ctrl.length;i++)
    {
       
        if(ctrl[i].value == valueToShow)
        {
            showRow(id);
        }
        else
        {
            hideRow(id);
        }
    }
}

//FJN, version 1
/*
function showHideEthnicOriginDDL(ctrlId, id)
{  
    //following are "id" values from "ehnics" Database table 
    //for all ethnicity fields with "please specify".
    var valuesToShow = new Array(5);
    valuesToShow[0] = 3;
    valuesToShow[1] = 7;
    valuesToShow[2] = 11;
    valuesToShow[3] = 14;
    valuesToShow[4] = 16;
    
    var ctrl = document.getElementsByName(ctrlId);   
    
    if(ctrl == null)
    {
        return;
    }
   
    for(var i=0; i<ctrl.length; i++)
    {
      for(var j=0; j<valuesToShow.length; j++)
      { 
            
        if(ctrl[i].value == valuesToShow[j])
        {
          showRow(id);
          return;
        }
        else
        {
          hideRow(id);
        }
      }   
    }
}
*/


//FJN 
function showHideEthnicOriginDDL(ctrlId, id, valuesToShow)
{      
    var ctrl = document.getElementsByName(ctrlId);   
    
    if(ctrl == null)
    {
        return;
    }
   
    for(var i=0; i<ctrl.length; i++)
    {
      for(var j=0; j<valuesToShow.length; j++)
      { 
            
        if(ctrl[i].value == valuesToShow[j])
        {
          showRow(id);
          return;
        }
        else
        {
          hideRow(id);
        }
      }   
    }
}


function hideRow(id)
{
    var strIds = new String(id);
    var Ids = strIds.split(" ,, ");
        
    for(var j=0; j<Ids.length;j++)
    {
        var obj = document.getElementById(Ids[j]);
    
        if(obj != null)
        {
            obj.style.display = 'none';
        }
    }
}

function showRow(id)
{
    var strIds = new String(id);
    var Ids = strIds.split(" ,, ");
        
    for(var j=0; j<Ids.length;j++)
    {
        var obj = document.getElementById(Ids[j]);
        
        if(obj != null)
        {
            try
            {
                obj.style.display = 'table-row';
            }
            catch(err)
            {
                obj.style.display = 'inline';
            }
        }
    }
}

function showHideApplicationSectionDL(ctrlId, id, id1, valueToShow, endosorsementsId)
{
    var ctrl = document.getElementsByName(ctrlId);
    
    if(ctrl == null)
    {
        return;
    }
    
    for(var i=0;i<ctrl.length;i++)
    {
        if(ctrl[i].value == valueToShow)
        {
            if(ctrl[i].checked)
            {
                showRow(id);
            }
            else
            {
                var obj = document.getElementsByName(endosorsementsId);
        
                for(var j=0;j<obj.length;j++)
                {
                    obj[j].checked = false;
                }
                
                hideRow(id + ' ,, ' + id1);
            }
        }
    }
}

function ControlValidators(state)
{
    if(typeof(Page_Validators)!="undefined")
	{
        for(var i=0;i<Page_Validators.length;i++)
        {
           // alert(Page_Validators[i]);
            ValidatorEnable(Page_Validators[i], state);
        }
    }
}
function showHideEmploymentContract(control, id, valueToshow, id2, valueToShow2)
{
    var ctrl = document.getElementById(control);
    if(ctrl == null)
    {
        return;
    }
    if (ctrl.options[ctrl.selectedIndex].value == id) 
    {
        showRow(valueToshow); 
        hideRow(valueToShow2);
    } 
    else if (ctrl.options[ctrl.selectedIndex].value == id2) 
    {
        showRow(valueToShow2); 
        hideRow(valueToshow);
    }
    else 
    {
        hideRow(valueToShow2); 
        hideRow(valueToshow);
    }

}
 
 function showHideEqualOpsSection(ctrlId, id, valueToShow, ctrlIds, id2, valueToShow2)
{

    var ctrl = document.getElementsByName(ctrlId);
    var strctrls = new String(ctrlIds);
    var ctrls = strctrls.split(" ,, ");
   
   
        
    if(ctrl == null)
    {
        return;
    }
    
    for(var i=0;i<ctrl.length;i++)
    {
        if(ctrl[i].value == valueToShow)
        {
            if(ctrl[i].checked)
            {
                showRow(id);
                for(var j=0; j < ctrls.length; j++)
                {
                 var obj = document.getElementById(ctrls[j]);
                 var val = document.getElementById(ctrls[j+1]);
        
                        if(obj != null && val !=null)
                        {
                        if(obj.checked &&  val.value == valueToShow2)
                            {
                                showRow(id2);
                            }
                            
                            else
                            {
                                hideRow(id2);
                            }
                        }
                        j++;

                }
            }
            else
            {
                hideRow(id);
            }
        }
    }
   
}

