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";
	    
	    var previewOptions = document.getElementById(previewSelector);
	    
	    if(previewOptions != null)
	    {
	        if(previewOptions.options.length == 1)
	        {
	            hideRow("previewActionsRow");
	            hideRow("previewActionsRow1");
	        }
	        else
	        {
	            showRow("previewActionsRow");
	            showRow("previewActionsRow1");
	        }
	    }
	    
	    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 showHideApplicationSections(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)
            {
                showRows(id);
            }
            else
            {
                hideRows(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);
        }
    }
}

function showHideControlDDL(ctrlId, id, valuesToShow)
{      
     var ctrl = document.getElementsByName(ctrlId);
    
   
    if(ctrl == null)
    {
        return;
    }
    
   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 showHideApplicationSections_JQuery(ctrlId) // new jquery method. The jquery[.min].js file must exist.
{
    var ctrl = document.getElementsByName(ctrlId);
    var args = showHideApplicationSections_JQuery.arguments;
    
    if(ctrl == null)
    {
        return;
    }
    
    var checkedValue = "";
    for(var i=0;i<ctrl.length;i++)
    {
        if(ctrl[i].checked)
        {
            checkedValue = ctrl[i].value;
        }
    }
    //alert(checkedValue);
    for(var i=1;i<args.length; i=i+2)
    {
        //alert(checkedValue + "==" + args[i] + " ?= " + "." + args[i+1]);
        if(checkedValue==args[i])
        {
            $("." + args[i+1]).show();
        }
        else
        {
            $("." + args[i+1]).hide();
        }
    }
}

function showHideApplicationSections_JQuery_DoubleQuestionOverride(InitialId, SecondaryId, ClassName, InitialValue, SecondaryValue)
{

    // Sort out InitialId.value
    var ctrl = document.getElementsByName(InitialId);
    
    if(ctrl == null)
    {
        return;
    }
    
    var initialChecked;
    for(var i=0;i<ctrl.length;i++)
    {
        if(ctrl[i].checked)
        {
            initialChecked = ctrl[i].value;
            break;
        }
    }
    
    // Sort out SecondaryId.value
    var ctrl = document.getElementsByName(SecondaryId);
    
    if(ctrl == null)
    {
        return;
    }
    
    var secondaryChecked;
    for(var i=0;i<ctrl.length;i++)
    {
        if(ctrl[i].checked)
        {
            secondaryChecked = ctrl[i].value;
            break;
        }
    }
    //alert(initialChecked + " && " + secondaryChecked);
    if(initialChecked==InitialValue && secondaryChecked==SecondaryValue)
    {
        $("." + ClassName).show();
        //alert('show');
    }
    else //if(initialChecked=="2") //&& secondaryChecked=="2")
    {
        $("." + ClassName).hide();
        //alert('hide');
    }
    
}

/*
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);
        }
      }   
    }
}
*/


 
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 hideRows(ids)
{
    var strIds = ids;
    var IdsArray = strIds.split(",");
     
    for(var j=0; j<IdsArray.length;j++)
    {
        var obj = document.getElementById(IdsArray[j]);
    
        if(obj != null)
        {
            obj.style.display = 'none';
        }
    }
}

function showRows(ids)
{
    var strIds = ids;
    var IdsArray = strIds.split(",");
        
    for(var j=0; j<IdsArray.length;j++)
    {
        var obj = document.getElementById(IdsArray[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 showHideApplicationSectionYesNo(ctrlId, yesIds, noIds)
{
    var ctrl = document.getElementsByName(ctrlId);
    
    if(ctrl == null)
    {
        return;
    }
    
    for(var i=0;i<ctrl.length;i++)
    {
        if(ctrl[i].value == 1)
        {
            if(ctrl[i].checked)
            {
                showRow(yesIds);
            }
            else
            {
                hideRow(yesIds);
            }
        }
        else if(ctrl[i].value == 2)
        {
            if(ctrl[i].checked)
            {
                showRow(noIds);
            }
            else
            {
                hideRow(noIds);
            }
        }
    }
}

function showHideInterviewDDL(ctrlId, id, valuesToShow)
{      
     var ctrl = document.getElementsByName(ctrlId);
    
   
    if(ctrl == null)
    {
        return;
    }
    
   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 CheckCheckboxItems(ctrlId, ctrlValue, valuesToShow)
{

var ctrl = document.getElementById(ctrlId);
var row = document.getElementById(valuesToShow);   
   
    if(ctrl != null)
    {
       if ((ctrl.checked == true) && (ctrlValue == "9" || ctrlValue == "13"))
       {
       
        showRow(valuesToShow);
       // return;
       }
       else
       {
        hideRow(valuesToShow);
       }
    }
}

function openWindow(theURL) {
  
  //variables
 
  var theWinName = "intIslingtonWin";

  
   	var features = 'status=yes,scrollbars=yes,resizable=yes,height=' + (((screen.availHeight)-46)-screen.availTop) + ',width=' + (((screen.availWidth)-7)-screen.availLeft) + ',left=' + screen.availLeft + ',top=' + screen.availTop;
    	window.open(theURL,theWinName,features); 	
  
}

function QualificationCheck(ctrlId)
{
    var ctrl = document.getElementsByName(ctrlId);
    
    if(ctrl == null)
    {
        return;
    }
    
    for(var i=0;i<ctrl.length;i++)
    {
        if(ctrl[i].value == 1 && ctrl[i].checked)
        {
           $(".HasQualification").show();
           return;
        }
        else
        {
           $(".NoQualification").hide();
           return;
        }
    }
}

function QualificationCheckIsEnglish(ctrlId)
{
    var ctrl = document.getElementsByName(ctrlId);
    
    if(ctrl == null)
    {
        return;
    }
    
    for(var i=0;i<ctrl.length;i++)
    {
        if(ctrl[i].value == 1 && ctrl[i].checked)
        {
           $(".QualificationInUk").show();
           $(".QualificationsNotInUK").hide();
           return;
        }
        else if(ctrl[i].value == 2 && ctrl[i].checked)
        {
           $(".QualificationInUk").hide();
           $(".QualificationsNotInUK").show();
           return;
        }
    }
    
   $(".QualificationInUk").hide();
   $(".QualificationsNotInUK").hide();
}