



function displayFiledReport(){
	if(document.getElementById("bySearches_company").select){		
		document.getElementById("bySearches_project").style.visibility="visible";
		document.getElementById("bySearches_project_status").style.visibility="visible";	
		document.getElementById("ListProjectAnsStatus").style.visibility="visible";
	}
	if(document.getElementById("bySearches_project").select){		
		if(document.getElementById("bySearches_project").value !='')		
				document.getElementById("ListSearchesAndStatus").style.visibility="visible";
	
	}
}



//function setfield allow to display fields when checkbox is checked

 function setfield(){
	if( document.getElementById("CandidateEnvoiMail").checked==true){
		document.getElementById("champs").style.visibility="visible";
	}else {
		document.getElementById("champs").style.visibility="hidden";
	}
	
 }

//function to display text field (number of positions, in projects/add view), just when type of service equals to 'Shortlisting'
function displayField() {	 
	   
	      var select = document.getElementById("ProjectServiceTypeId" );
	      
	      var valeur = select.options[select.selectedIndex].text;	  
	      
	      if(valeur=="Shortlisting") {
	    	  document.getElementById("ProjectPositions").style.visibility="visible";
	      document.getElementById("ProjectPosition").style.visibility="visible";
	      }else {
	    	  document.getElementById("ProjectPositions").style.visibility="hidden";
	    	  document.getElementById("ProjectPosition").style.visibility="hidden";
	    	  
	      }
	    
	     
	
  }

//function to create a new question
function create_Response(question) {

var valLines = document.getElementById('Question'+question+'ResponseCount');

var countLine = parseInt(valLines.value)+1;

var response = document.getElementById("Question1Response1").cloneNode(true);

var td_item = document.getElementById("response"+question);

var div_action = document.createElement("div");


response.setAttribute("id","Question"+question+"response"+countLine);
response.setAttribute("name","data[Question]["+question+"][response]["+countLine+"]");

response.innerHTML="N/A";

div_action.setAttribute("id","delfield_"+question+"_"+countLine);


//div_action.innerHTML+='<span><a href="javascript:remove_Response('Question1Response1','1');">Supprimer</a></span>';
div_action.innerHTML+='<span id="addedfields_'+question+'_'+countLine+'"><a href="javascript:remove_Response(\''+countLine+'\',\''+question+'\');">Supprimer</a></span><br> <br> ';


td_item.appendChild(response);

td_item.appendChild(div_action);

}

function remove_Response(countLine,question) {
var t = document.getElementById("response"+question);

var l=document.getElementById('Question'+question+'response'+countLine);
var l2=document.getElementById('delfield_'+question+'_'+countLine);
t.removeChild(l);
t.removeChild(l2);
}





//function to create a new question
function create_Question() {

i=1;
var valQuestions = 1;
var valLines = document.getElementById('QuestionLinesCount');
items = document.getElementsByTagName("tr");
if (valLines.value=="") valLines.value=items.length;

var countLine = ( parseInt(valQuestions)+ (items.length-parseInt(valLines.value))+1);
var i2 = i + 1;

var question = document.getElementById("Question1Question").cloneNode(true);
var questiontypeid = document.getElementById("Question1QuestionTypeId").cloneNode(true);
var search = document.getElementById("Question1SearchId").cloneNode(true);
var num = document.getElementById("Question1Num").cloneNode(true);
var response1 = document.getElementById("Question1Response1").cloneNode(true);
var response2 = document.getElementById("Question1Response2").cloneNode(true);
var responseCount = document.getElementById("Question1ResponseCount").cloneNode(true);



question.setAttribute("id","Question"+countLine+"Question");
question.setAttribute("name","data[Question]["+countLine+"][question]");


questiontypeid.setAttribute("id","Question"+countLine+"QuestionTypeId");
questiontypeid.setAttribute("name","data[Question]["+countLine+"][question_type_id]");

search.setAttribute("id","Question"+countLine+"SearchId");
search.setAttribute("name","data[Question]["+countLine+"][search_id]");

num.setAttribute("id","Question"+countLine+"Num");
num.setAttribute("name","data[Question]["+countLine+"][num]");
num.setAttribute("value","+countLine+");

responseCount.setAttribute("value","2");


response1.setAttribute("id","Question"+countLine+"Response1");
response1.setAttribute("name","data[Question]["+countLine+"][response][1]");


response2.setAttribute("id","Question"+countLine+"Response2");
response2.setAttribute("name","data[Question]["+countLine+"][response][2]");

responseCount.setAttribute("id","Question"+countLine+"ResponseCount");
responseCount.setAttribute("name","data[Question]["+countLine+"][responseCount][2]");



var body = document.getElementsByTagName("tbody")[0];

var row = document.createElement("tr");
var cell = document.createElement("td");
cell.setAttribute("style","border-right:1px solid #eae9e9;border-bottom:1px solid #eae9e9;text-align:center");
var cell2 = document.createElement("td");
cell2.setAttribute("style","border-right:1px solid #eae9e9;border-bottom:1px solid #eae9e9");
var cell3 = document.createElement("td");
cell3.setAttribute("id","response"+countLine);
cell3.setAttribute("style","border-bottom:1px solid #eae9e9;padding-left:20px");

var div_action = document.createElement("div");
var div_action2 = document.createElement("div");
row.setAttribute("id",countLine);
cell.innerHTML=countLine;

div_action.innerHTML+='<span id="addedfields_'+countLine+'" style="margin-left:30px"><a href="javascript:remove_Question('+countLine+');">Supprimer</a></span>';

cell2.appendChild(question);
cell2.appendChild(search);
cell2.appendChild(num);
cell2.appendChild(questiontypeid);
cell2.appendChild(div_action);

div_action2.innerHTML+='<span id="addedresponse_'+countLine+'"><a href="javascript:create_Response('+countLine+')">Ajouter</a></span>';

cell3.appendChild(div_action2);
cell3.innerHTML+='<br>';
cell3.appendChild(response1);
cell3.innerHTML+='<br>';
cell3.innerHTML+='<br>';
cell3.appendChild(response2);
cell3.innerHTML+='<br>';
cell3.innerHTML+='<br>';
cell3.appendChild(responseCount);


row.appendChild(cell);
row.appendChild(cell2);
row.appendChild(cell3);
body.appendChild(row);

//body.innerHTML += '<td><input type="text" name="toto"></td><td><input type="text" name="toto"></td>';
}

function remove_Question(varline) {
var t = document.getElementsByTagName("tbody")[0];
var l=document.getElementById(varline);
t.removeChild(l);
}


var checkflag = "false";
function check(field, msgSelect,msgNoSelect) {
if (checkflag == "false") {
  for (i = 0; i < field.length; i++) {
  field[i].checked = true;}
  checkflag = "true";
  return msgNoSelect; }
else {
  for (i = 0; i < field.length; i++) {
  field[i].checked = false; }
  checkflag = "false";
  return msgSelect; }
}


//to show/hide date selection on period report
function updatePeriod(form) {

	ob=document.getElementById(form+"_period");
	ob2=document.getElementById(form+"_dates");
	test=0;
	for (i =0; i < ob.options.length; i++) {
			if ((ob.options[i].selected) && (ob.options[i].value == 6)){
				test=1;
				Effect.Appear(ob2);
				//ob2.setAttribute("style","display:true;");
  			}	
	}
	if (test == 0)
	Effect.DropOut(ob2);
	//alert(test);
}

//to show/hide date selection on period report
	function displayDate() {

	ob=document.getElementById("Action");
	ob3=document.getElementById("divActionOn");
	ob2=document.getElementById("divActionDate");
	test=0;
	test2=0;
	
	for (i =0; i < ob.options.length; i++) {
	
			if ((ob.options[i].selected) && (ob.options[i].value == 2)){
				test=1;
				Effect.Appear(ob2);
  			}	
  			if ((ob.options[i].selected) && ((ob.options[i].value == 3)||(ob.options[i].value == 4))){
				test2=1;
				Effect.Appear(ob3);
  			}
	}

	if (test == 0)
	Effect.DropOut(ob2);
	if (test2 == 0)
	Effect.DropOut(ob3);
}

//to show/hide date selection on period report
	function displaySourcingPack(){

	ob1=document.getElementById("CandidateEventTypeId4");
	ob2=document.getElementById("CandidateEventTypeId2");
	ob3=document.getElementById("CandidateEventTypeId3");
	ob=document.getElementById("divSPOn");
	test=0;
	
			if (ob3.checked){
				test=1;
				Effect.Appear(ob);
  			}
	
	if (test == 0)
	Effect.DropOut(ob);
	
}


function updateUsers(n,m) {
	i=1;
	var valObjectives = 1;
	var valLines = document.getElementById('ObjectiveLinesCount');
	items = document.getElementsByTagName("tr");
	if (valLines.value=="") valLines.value=items.length;

	var countLine = ( parseInt(valObjectives)+ (items.length-parseInt(valLines.value))+1);
	var i2 = i + 1;

	//when user change search criterion
	if (n==1){

		ob=document.getElementById("Objective"+m+"UserId");
		ob2=document.getElementById("ObjectiveUserId");
	//	ob2.setAttribute("type","select");
		//ob=ob2;
		for (i =0; i < ob2.options.length; i++) {
			test=-1;
			for (j =0; j < ob.options.length; j++) {
				if (ob.options[j].value==ob2.options[i].value) test=j;
			}
	 
			tmpOptions=ob2.options[i].cloneNode(true);
			if (test==-1) {
				//if (ob2.options[i].selected) {
					try {
					ob.add(tmpOptions, null); // standards compliant; doesn't work in IE
					}
					catch(ex) {
						ob.add(tmpOptions); // IE only
					}
				//}
			}else{
				if (!(ob2.options[i].selected)) {
					//ob.remove(test);
				}	
			}
		}
	}
	for (i =1; i < countLine; i++) {
		for (k = 1; k < countLine; k++) {
			if ((document.getElementById("Objective"+k+"SearchId").selectedIndex==document.getElementById("Objective"+i+"SearchId").selectedIndex)&&(i!=k)){
				selected = new Array(); 
				ob=document.getElementById("Objective"+i+"UserId");
				ob2=document.getElementById("Objective"+k+"UserId");
				//for (var j = 0; j < ob.options.length; j++) if (ob.options[j].selected) selected.push(ob.options[j].value);
				for (var j = 0; j < ob.options.length; j++)  selected.push(ob.options[j].value);

				for ( var l=0;l<selected.length;l++) {
					for ( var m=0;m<ob2.options.length;m++) {
						if (ob2.options[m].value==selected[l])   ob2.remove(m);
					}
				}

				if (ob2.options.length==0) {
				}
			} 
		}
	}
}



//function to create a line in the task table(new task)
function create_Objective() {
i=1;
var valObjectives = 1;
var valLines = document.getElementById('ObjectiveLinesCount');
items = document.getElementsByTagName("tr");
if (valLines.value=="") valLines.value=items.length;

var countLine = ( parseInt(valObjectives)+ (items.length-parseInt(valLines.value))+1);
var i2 = i + 1;

var search = document.getElementById("Objective"+(countLine-1)+"SearchId").cloneNode(true);
if (search.options.length>1){
search.setAttribute("id","Objective"+countLine+"SearchId");
search.setAttribute("name","data[Objective]["+countLine+"][search_id]");
search.setAttribute("onChange","updateUsers(1,"+countLine+")");
//search.remove(document.getElementById("Objective"+(countLine-1)+"SearchId").selectedIndex);

var user = document.getElementById("Objective"+i+"UserId").cloneNode(true);
user.setAttribute("id","Objective"+countLine+"UserId");
user.setAttribute("name","data[Objective]["+countLine+"][user_id][]");

var cvp = document.getElementById("Objective"+i+"CVP").cloneNode(true);
cvp.setAttribute("id","Objective"+countLine+"CVP");
cvp.setAttribute("name","data[Objective]["+countLine+"][CVP]");

var acps = document.getElementById("Objective"+i+"ACPS").cloneNode(true);
acps.setAttribute("id","Objective"+countLine+"ACPS");
acps.setAttribute("name","data[Objective]["+countLine+"][ACPS]");

var pca = document.getElementById("Objective"+i+"PCA").cloneNode(true);
pca.setAttribute("id","Objective"+countLine+"PCA");
pca.setAttribute("name","data[Objective]["+countLine+"][PCA]");

var body = document.getElementsByTagName("tbody")[0];
var row = document.createElement("tr");
var cell = document.createElement("td");
var cell2 = document.createElement("td");
var cell3= document.createElement("td");
var cell4 = document.createElement("td");
var cell5= document.createElement("td");
var cell6 = document.createElement("td");

cell.appendChild(search);
cell2.appendChild(user);
cell3.appendChild(cvp);
cell4.appendChild(acps);
cell5.appendChild(pca);

row.appendChild(cell);
row.appendChild(cell2);
row.appendChild(cell3);
row.appendChild(cell4);
row.appendChild(cell5);
row.appendChild(cell6);

body.appendChild(row);

//body.innerHTML += '<td><input type="text" name="toto"></td><td><input type="text" name="toto"></td>';
}
updateUsers(1,countLine);
}


//to add fields in a form

function create_champ(i,name,name2,label,radio,val1,val2,label1,label2) {

var i2 = i + 1;

if (radio){
	document.getElementById('addedfields_'+i).innerHTML = '<table id="table_05"><tr><td><label for="'+name+'Op'+i+name2+'" >'+label1+'</label></td><td><input type="radio" value="'+val1+'" name="'+name+'Op'+i+name2+'"></td><td><label for="'+name+'Op'+i+name2+'" >'+label2+'</label> </td><td><input type="radio" value="'+val2+'" name="'+name+'Op'+i+name2+'"> </td> </tr></table>';
	
	
	//document.getElementById('addedfields_'+i).innerHTML += '<td><input type="radio" value="'+val1+'" name="'+name+'Op'+i+name2+'"></td></tr></table>';
	

	
	//document.getElementById('addedfields_'+i).innerHTML += '<br><br><label for="'+name+'Op'+i+name2+'" >'+label2+'</label>';

	//document.getElementById('addedfields_'+i).innerHTML += '<input type="radio" value="'+val2+'" name="'+name+'Op'+i+name2+'">';
	
	document.getElementById('addedfields_'+i).innerHTML += '<input type="text" name="'+name+'Value'+i+name2+'" style="width:300px"></span><br />';
	
}else{
	document.getElementById('addedfields_'+i).innerHTML = '<input type="text" name="'+name+'Value'+i+name2+'"></span><br />';
}
document.getElementById('addedfields_'+i).innerHTML += (i <= 10) ? '<span id="addedfields_'+i2+'"><a href="javascript:create_champ('+i2+',\''+name+'\',\''+name2+'\',\''+label+'\',\''+radio+'\',\''+val1+'\',\''+val2+'\',\''+label1+'\',\''+label2+'\')">'+label+'</a></span>' : '';
}

//function to create a line in the task table(new task)
function create_line(i,label) {
var valProjects = document.getElementById('TaskProjectsCount');
var valLines = document.getElementById('TaskLinesCount');
items = document.getElementsByTagName("tr");
if (valLines.value=="") valLines.value=items.length;

var countLine = ( parseInt(valProjects.value)+ (items.length-parseInt(valLines.value))+1);
var i2 = i + 1;

var search = document.getElementById("Task"+i+"SearchId").cloneNode(true);
search.setAttribute("id","Task"+countLine+"SearchId");
search.setAttribute("name","data[Task]["+countLine+"][search_id]");

var projectId = document.getElementById("Task"+i+"ProjectId").cloneNode(true);
projectId.setAttribute("id","Task"+countLine+"ProjectId");
projectId.setAttribute("name","data[Task]["+countLine+"][project_id]");

var projectsUser = document.getElementById("Task"+i+"ProjectsUserId").cloneNode(true);
projectsUser.setAttribute("id","Task"+countLine+"ProjectsUserId");
projectsUser.setAttribute("name","data[Task]["+countLine+"][projects_user_id]");

var taskDate = document.getElementById("Task"+i+"TaskDate").cloneNode(true);
taskDate.setAttribute("id","Task"+countLine+"TaskDate");
taskDate.setAttribute("name","data[Task]["+countLine+"][task_date]");

var activity = document.getElementById("Task"+i+"ActivityId").cloneNode(true);
activity.setAttribute("id","Task"+countLine+"ActivityId");
activity.setAttribute("name","data[Task]["+countLine+"][activity_id]");

var project = document.getElementById("Task"+i+"ProjectName");
projectName = document.createTextNode(project.value);

var duration = document.getElementById("Task"+i+"Duration").cloneNode(true);
duration.setAttribute("id","Task"+countLine+"Duration");
duration.setAttribute("value","0");
duration.setAttribute("name","data[Task]["+countLine+"][duration]");
var labelDuration = document.createElement("label");
labelDuration.setAttribute("for","Task"+countLine+"Duration");
labelDuration.innerHTML += label;

var btn1 = document.createElement("input");
btn1.setAttribute("type","button");
btn1.setAttribute("onclick","javascript:increments('"+countLine+"',0,'toto',true)");
btn1.setAttribute("value","+");

var btn2 = document.createElement("input");
btn2.setAttribute("type","button");
btn2.setAttribute("onclick","javascript:decrements('"+countLine+"','toto')");
btn2.setAttribute("value","-");

var body = document.getElementsByTagName("tbody")[0];
var row = document.createElement("tr");
var cell = document.createElement("td");
var cell2 = document.createElement("td");
var cell3= document.createElement("td");
var cell4 = document.createElement("td");
var cell5= document.createElement("td");
var cell6 = document.createElement("td");
var cell7= document.createElement("td");



cell.appendChild(projectName);
cell.appendChild(projectId);
cell.appendChild(projectsUser);
cell.appendChild(taskDate);
cell2.appendChild(search);
cell3.appendChild(activity);
cell4.appendChild(labelDuration);
cell4.appendChild(duration);
//cell4.appendChild(btn1);
//cell4.appendChild(btn2);
row.appendChild(cell);
row.appendChild(cell2);
row.appendChild(cell3);
row.appendChild(cell4);
row.appendChild(cell5);
row.appendChild(cell6);
row.appendChild(cell7);

body.appendChild(row);

	//body.innerHTML += '<td><input type="text" name="toto"></td><td><input type="text" name="toto"></td>';

}



function create_ObjectiveLine(i,label) {
var valProjects = document.getElementById('TaskProjectsCount');
var valLines = document.getElementById('TaskLinesCount');
items = document.getElementsByTagName("tr");
if (valLines.value=="") valLines.value=items.length;

var countLine = ( parseInt(valProjects.value)+ (items.length-parseInt(valLines.value))+1);
var i2 = i + 1;

var search = document.getElementById("Task"+i+"SearchId").cloneNode(true);
search.setAttribute("id","Task"+countLine+"SearchId");
search.setAttribute("name","data[Task]["+countLine+"][search_id]");

var projectId = document.getElementById("Task"+i+"ProjectId").cloneNode(true);
projectId.setAttribute("id","Task"+countLine+"ProjectId");
projectId.setAttribute("name","data[Task]["+countLine+"][project_id]");

var projectsUser = document.getElementById("Task"+i+"ProjectsUserId").cloneNode(true);
projectsUser.setAttribute("id","Task"+countLine+"ProjectsUserId");
projectsUser.setAttribute("name","data[Task]["+countLine+"][projects_user_id]");

var taskDate = document.getElementById("Task"+i+"TaskDate").cloneNode(true);
taskDate.setAttribute("id","Task"+countLine+"TaskDate");
taskDate.setAttribute("name","data[Task]["+countLine+"][task_date]");

var activity = document.getElementById("Task"+i+"ActivityId").cloneNode(true);
activity.setAttribute("id","Task"+countLine+"ActivityId");
activity.setAttribute("name","data[Task]["+countLine+"][activity_id]");

var project = document.getElementById("Task"+i+"ProjectName");
projectName = document.createTextNode(project.value);

var duration = document.getElementById("Task"+i+"Duration").cloneNode(true);
duration.setAttribute("id","Task"+countLine+"Duration");
duration.setAttribute("value","0");
duration.setAttribute("name","data[Task]["+countLine+"][duration]");
var labelDuration = document.createElement("label");
labelDuration.setAttribute("for","Task"+countLine+"Duration");
labelDuration.innerHTML += label;

var btn1 = document.createElement("input");
btn1.setAttribute("type","button");
btn1.setAttribute("onclick","javascript:increments('"+countLine+"',0,'toto',true)");
btn1.setAttribute("value","+");

var btn2 = document.createElement("input");
btn2.setAttribute("type","button");
btn2.setAttribute("onclick","javascript:decrements('"+countLine+"','toto')");
btn2.setAttribute("value","-");

var body = document.getElementsByTagName("tbody")[0];
var row = document.createElement("tr");
var cell = document.createElement("td");
var cell2 = document.createElement("td");
var cell3= document.createElement("td");
var cell4 = document.createElement("td");
var cell5= document.createElement("td");
var cell6 = document.createElement("td");
var cell7= document.createElement("td");



cell.appendChild(projectName);
cell.appendChild(projectId);
cell.appendChild(projectsUser);
cell.appendChild(taskDate);
cell2.appendChild(search);
cell3.appendChild(activity);
cell4.appendChild(labelDuration);
cell4.appendChild(duration);
cell4.appendChild(btn1);
cell4.appendChild(btn2);
row.appendChild(cell);
row.appendChild(cell2);
row.appendChild(cell3);
row.appendChild(cell4);
row.appendChild(cell5);
row.appendChild(cell6);
row.appendChild(cell7);

body.appendChild(row);

	//body.innerHTML += '<td><input type="text" name="toto"></td><td><input type="text" name="toto"></td>';

}





//function to increment duration task value
function increments(i,j,message,view) {
var task_val = document.getElementById('Task'+i+'Duration');
task_val.value = parseFloat(task_val.value)+0.25;
var task_tot =0;

var valProjects = document.getElementById('TaskProjectsCount');
var valLines = document.getElementById('TaskLinesCount');
items = document.getElementsByTagName("tr");
if (valLines.value=="") valLines.value=items.length;


var countLine = ( parseInt(valProjects.value)+ (items.length-parseInt(valLines.value)));


if (view){

	for (k=1; k<(countLine+1); k++) {

	task_tot =parseFloat(task_tot) + parseFloat(document.getElementById('Task'+parseInt(k)+'Duration').value);

	}
}else{

	while(i>5){
		i=i-5;
	}

	for (k=0; k<(countLine); k++) {
		task_tot =parseFloat(task_tot) + parseFloat(document.getElementById('Task'+parseInt(parseInt(i)+k*5)+'Duration').value);
	}
}

if (task_tot>1){
	task_val.value= parseFloat(task_val.value)-0.25;
	alert(message);
}

}

//function to decrement duration task value
function decrements(i,message) {

var task_val = document.getElementById('Task'+i+'Duration');
task_val.value = parseFloat(task_val.value)-0.25;

if (parseFloat(task_val.value)<0){
	task_val.value= parseFloat(task_val.value)+0.25;
	alert(message);
	}
}


function displayCalendar(){
	if (document.getElementById('RecruitmentStartDate').selectedIndex == 0)
	{
		document.getElementById('selectDate').style.display='none';
	}
	
	if (document.getElementById('RecruitmentStartDate').selectedIndex == 1)
	{
		document.getElementById('selectDate').style.display='block';
	}
}

function displayEditCalendar(){
	if (document.getElementById('RecruitmentChooseDate').selectedIndex == 0 || document.getElementById('RecruitmentChooseDate').selectedIndex == 1)
	{
		document.getElementById('selectDate').style.display='none';
	}
	
	if (document.getElementById('RecruitmentChooseDate').selectedIndex == 2)
	{
		document.getElementById('selectDate').style.display='block';
	}
}

function injectDateStart(){
	var day = document.getElementById('TaskStartChooseDateDay').options[document.getElementById('TaskStartChooseDateDay').selectedIndex].value;
	var month = document.getElementById('TaskStartChooseDateMonth').options[document.getElementById('TaskStartChooseDateMonth').selectedIndex].value;
	var year = document.getElementById('TaskStartChooseDateYear').options[document.getElementById('TaskStartChooseDateYear').selectedIndex].value;

	document.getElementById('TaskStartDate').value = day+'-'+month+'-'+year;
	document.getElementById('TaskStartDateHide').value = year+'-'+month+'-'+day;
}

function injectDateEnd(){
	var day = document.getElementById('TaskEndChooseDateDay').options[document.getElementById('TaskEndChooseDateDay').selectedIndex].value;
	var month = document.getElementById('TaskEndChooseDateMonth').options[document.getElementById('TaskEndChooseDateMonth').selectedIndex].value;
	var year = document.getElementById('TaskEndChooseDateYear').options[document.getElementById('TaskEndChooseDateYear').selectedIndex].value;
	
	document.getElementById('TaskEndDate').value = day+'-'+month+'-'+year;
	document.getElementById('TaskEndDateHide').value = year+'-'+month+'-'+day;
}

function displayJobName(server_name, project_id){
	openPage('http://' + server_name + '/recruitments/add/' + project_id + '/' + document.getElementById('RecruitmentJobId').value);
}

function openPage(url){
	location.href = url;
}

function reload(server_name){
	openPage('http://' + server_name + '/recruitments/index/' + document.getElementById('filter').value);
}

function reloadDashboards()
{
	document.getElementById('DashboardDash2Form').submit();
}

function activeDelai(i)
{
	var validation_type_selected = document.getElementById('ValidationCircuit'+i+'ValidationTypeId').value;
	var delai = document.getElementById('ValidationCircuit'+i+'Delai');
	
	if (validation_type_selected == 1)
		delai.disabled = false;
	else
		delai.disabled = true;
}

//functions for precodif
function create_Answer(precodif) {
	var valLines = document.getElementById('Precodif'+precodif+'AnswerNumber');
	var countLine = parseInt(valLines.value)+1;
	var answer = document.getElementById("Precodif1Answer1").cloneNode(true);
	var td_item = document.getElementById("answer"+precodif);
	var div_action = document.createElement("div");
		
	answer.setAttribute("id","Precodif"+precodif+"Answer"+countLine);
	//answer.setAttribute("name","data[Precodif]["+precodif+"][answer]["+countLine+"]");
	answer.innerHTML="";
	answer.disabled = false;
	
	div_action.setAttribute("id","div_"+precodif+"_"+countLine);
	div_action.appendChild(answer);
	div_action.innerHTML+="<br>";
	td_item.appendChild(div_action);
	
	//increments AnswerCount & AnswerNumber
	document.getElementById('Precodif'+precodif+'AnswerNumber').value++;
	document.getElementById('Precodif'+precodif+'AnswerCount').value++;
}
function remove_Answer(countLine,precodif) {
	
	var t = document.getElementById("answer"+precodif);
	var l=document.getElementById('Precodif'+precodif+'Answer'+countLine);
	var l2=document.getElementById('div_'+precodif+'_'+countLine);

	l2.removeChild(l);
	t.removeChild(l2);
	
	//decrement le AnswerCount
	document.getElementById('Precodif'+precodif+'AnswerCount').value--;
}

function create_Weighting(precodif) {

	var valLines = document.getElementById('Precodif'+precodif+'WeightingNumber');
	var countLine = parseInt(valLines.value)+1;
	var weighting = document.getElementById("Precodif1Weighting1").cloneNode(true);
	var td_item = document.getElementById("weighting"+precodif);
	var div_action = document.createElement("div");
		
	weighting.setAttribute("id","Precodif"+precodif+"Weighting"+countLine);
	//weighting.setAttribute("name","data[Precodif]["+precodif+"][weighting]["+countLine+"]");
	weighting.innerHTML="0";
	weighting.disabled = false;
	
	div_action.setAttribute("id","div_"+precodif+"_"+countLine);
	
	div_action.appendChild(weighting);
	div_action.innerHTML+="<br>";
	td_item.appendChild(div_action);
		
	//increments WeightingCount & WeightingNumber
	document.getElementById('Precodif'+precodif+'WeightingNumber').value++;
	document.getElementById('Precodif'+precodif+'WeightingCount').value++;

}
function remove_Weighting(countLine,precodif) {
	
	var t = document.getElementById("weighting"+precodif);
	var l=document.getElementById('Precodif'+precodif+'Weighting'+countLine);
	var l2=document.getElementById('div_'+precodif+'_'+countLine);

	l2.removeChild(l);
	t.removeChild(l2);
	
	//decrement WeightingCount
	document.getElementById('Precodif'+precodif+'WeightingCount').value--;
}

function create_Precodif() {

	var countLine = (document.getElementById('PrecodifLinesCount').value);
	countLine++;
	document.getElementById('PrecodifLinesCount').value = countLine;
	
	var precodif = document.getElementById("Precodif1Precodif").cloneNode(true);
	var search = document.getElementById("Precodif1SearchId").cloneNode(true);
	var num = document.getElementById("Precodif1Num").cloneNode(true);
	var answertype = document.getElementById("Precodif1AnswerType").cloneNode(true);
		
	var answer1 = document.getElementById("Precodif1Answer1").cloneNode(true);
	var answerCount = document.getElementById("Precodif1AnswerCount").cloneNode(true);
	var answerNumber = document.getElementById("Precodif1AnswerNumber").cloneNode(true);

	var weighting1 = document.getElementById("Precodif1Weighting1").cloneNode(true);
	var weightingCount = document.getElementById("Precodif1WeightingCount").cloneNode(true);
	var weightingNumber = document.getElementById("Precodif1WeightingNumber").cloneNode(true);
	
	var criticity = document.getElementById("Precodif1Criticity").cloneNode(true);
	
	precodif.setAttribute("id","Precodif"+countLine+"Precodif");
	precodif.setAttribute("name","data[Precodif]["+countLine+"][precodif]");
	precodif.value = "";
	
	answertype.setAttribute("id","Precodif"+countLine+"AnswerType");
	answertype.setAttribute("name","data[Precodif]["+countLine+"][answer_type]");
	answertype.setAttribute("onchange","type_Choice("+countLine+")");
	if(document.all){answertype.onchange = function(){type_Choice(countLine);};}
		
	search.setAttribute("id","Precodif"+countLine+"SearchId");
	search.setAttribute("name","data[Precodif]["+countLine+"][search_id]");

	num.setAttribute("id","Precodif"+countLine+"Num");
	num.setAttribute("name","data[Precodif]["+countLine+"][num]");
	num.setAttribute("value",countLine);//OCR avant "+countLine+"

	answer1.setAttribute("id","Precodif"+countLine+"Answer1");
	answer1.setAttribute("name","data[Precodif]["+countLine+"][answer][1]");
	answer1.disabled = true;
	
	answerCount.setAttribute("value","1");
	answerCount.setAttribute("id","Precodif"+countLine+"AnswerCount");
	answerCount.setAttribute("name","data[Precodif]["+countLine+"][answerCount]");
	
	answerNumber.setAttribute("value","1");
	answerNumber.setAttribute("id","Precodif"+countLine+"AnswerNumber");
	answerNumber.setAttribute("name","data[Precodif]["+countLine+"][answerNumber]");

	weighting1.setAttribute("id","Precodif"+countLine+"Weighting1");
	weighting1.setAttribute("name","data[Precodif]["+countLine+"][weighting][1]");
		
	weightingCount.setAttribute("value","1");
	weightingCount.setAttribute("id","Precodif"+countLine+"WeightingCount");
	weightingCount.setAttribute("name","data[Precodif]["+countLine+"][weightingCount]");
	
	weightingNumber.setAttribute("value","1");
	weightingNumber.setAttribute("id","Precodif"+countLine+"WeightingNumber");
	weightingNumber.setAttribute("name","data[Precodif]["+countLine+"][weightingNumber]");
	
	criticity.setAttribute("id","Precodif"+countLine+"Criticity");
	criticity.setAttribute("name","data[Precodif]["+countLine+"][criticity]");
	criticity.disabled = false;
	
	var body = document.getElementsByTagName("tbody")[0];

	var row = document.createElement("tr");
	var cell = document.createElement("td");
		cell.setAttribute("style","border-right:1px solid #eae9e9;border-bottom:1px solid #eae9e9;text-align:center");
		if (document.all) cell.style.setAttribute("cssText","border-right:1px solid #eae9e9;border-bottom:1px solid #eae9e9;text-align:center");  //compatibilité IE
	var cell2 = document.createElement("td");
		cell2.setAttribute("style","border-right:1px solid #eae9e9;border-bottom:1px solid #eae9e9");
		if (document.all) cell2.style.setAttribute("cssText","border-right:1px solid #eae9e9;border-bottom:1px solid #eae9e9");
	var cell3 = document.createElement("td");
		cell3.setAttribute("id","value_type"+countLine);
		cell3.setAttribute("style","border-right:1px solid #eae9e9;border-bottom:1px solid #eae9e9;text-align:center;");
		if (document.all) cell3.style.setAttribute("cssText","border-right:1px solid #eae9e9;border-bottom:1px solid #eae9e9;text-align:center;");
	var cell4 = document.createElement("td");
		cell4.setAttribute("id","answer"+countLine);
		cell4.setAttribute("style","border-right:1px solid #eae9e9;border-bottom:1px solid #eae9e9;");
		if (document.all) cell4.style.setAttribute("cssText","border-right:1px solid #eae9e9;border-bottom:1px solid #eae9e9;");
	var cell5 = document.createElement("td");
		cell5.setAttribute("id","weighting"+countLine);
		cell5.setAttribute("style","border-right:1px solid #eae9e9;border-bottom:1px solid #eae9e9;text-align:center;");
		if (document.all) cell5.style.setAttribute("cssText","border-right:1px solid #eae9e9;border-bottom:1px solid #eae9e9;text-align:center;");
	var cell6 = document.createElement("td");
		cell6.setAttribute("id","criticity"+countLine);
		cell6.setAttribute("style","border-right:1px solid #eae9e9;border-bottom:1px solid #eae9e9;text-align:center;");
		if (document.all) cell6.style.setAttribute("cssText","border-right:1px solid #eae9e9;border-bottom:1px solid #eae9e9;text-align:center;");

	
	var div_action = document.createElement("div");
	var div_action2 = document.createElement("div");
	row.setAttribute("id",countLine);
	cell.innerHTML=countLine;

	div_action.innerHTML+='<span id="addedfields_'+countLine+'" style="margin-left:30px"><a href="javascript:remove_Precodif('+countLine+');">Supprimer</a></span>';

	cell2.appendChild(precodif);
	cell2.appendChild(search);
	cell2.appendChild(num);
	cell2.appendChild(div_action);

	cell3.appendChild(answertype);
	
	cell4.appendChild(div_action2);
	cell4.appendChild(answer1);
	cell4.appendChild(answerCount);
	cell4.appendChild(answerNumber);

	cell5.appendChild(div_action2);
	cell5.appendChild(weighting1);
	cell5.appendChild(weightingCount);
	cell5.appendChild(weightingNumber);
	
	cell6.appendChild(criticity);
	
	row.appendChild(cell);
	row.appendChild(cell2);
	row.appendChild(cell3);
	row.appendChild(cell4);
	row.appendChild(cell5);
	row.appendChild(cell6);
	body.appendChild(row);

}
function remove_Precodif(varline) {
	var t = document.getElementsByTagName("tbody")[0];
	var l = document.getElementById(varline);
	t.removeChild(l);
}

function type_Choice(precodif) {
	var liste = document.getElementById('Precodif'+precodif+'AnswerType');
	var choice = liste.options[liste.selectedIndex].value;

	var valLine1 = document.getElementById('Precodif'+precodif+'WeightingNumber');
	var maxWeighting = parseInt(valLine1.value);
	
	var valLine2 = document.getElementById('Precodif'+precodif+'AnswerNumber');
	var maxAnswer = parseInt(valLine2.value);
	
	switch(choice){
		case "1":  //Oui-non
			for(i=2;i<=maxAnswer;i++){
				if (document.getElementById('Precodif'+precodif+'Answer'+i) != null) {
					remove_Answer(i,precodif);
				}
			}
			document.getElementById('Precodif'+precodif+'AnswerNumber').value = 1;
			var l = document.getElementById('Precodif'+precodif+'Answer1');
			l.value = "Sans objet";
			l.disabled = true;
			for(i=2;i<=maxWeighting;i++){
				if (document.getElementById('Precodif'+precodif+'Weighting'+i) != null) {
					remove_Weighting(i,precodif);
				}
			}
			document.getElementById('Precodif'+precodif+'WeightingNumber').value = 1;
			var p = document.getElementById('Precodif'+precodif+'Weighting1');
			p.disabled = false;
			var c = document.getElementById('Precodif'+precodif+'Criticity');
			c.value = "3";
			c.disabled = false;
			break;
		case "2":  // Numerique
			for(i=2;i<=maxAnswer;i++){
				if (document.getElementById('Precodif'+precodif+'Answer'+i) != null) {
					remove_Answer(i,precodif);
				}
			}
			document.getElementById('Precodif'+precodif+'AnswerNumber').value = 1;
			var l = document.getElementById('Precodif'+precodif+'Answer1');
			l.value = "Rentrez vos valeurs";
			l.disabled = false;
			create_Answer(precodif);
			document.getElementById("Precodif"+precodif+"Answer2").setAttribute("name","data[Precodif]["+precodif+"][answer][2]");
			create_Answer(precodif);
			document.getElementById("Precodif"+precodif+"Answer3").setAttribute("name","data[Precodif]["+precodif+"][answer][3]");
			create_Answer(precodif);
			document.getElementById("Precodif"+precodif+"Answer4").setAttribute("name","data[Precodif]["+precodif+"][answer][4]");
			for(i=2;i<=maxWeighting;i++){
				if (document.getElementById('Precodif'+precodif+'Weighting'+i) != null) {
					remove_Weighting(i,precodif);
				}
			}
			document.getElementById('Precodif'+precodif+'WeightingNumber').value = 1;
			var p = document.getElementById('Precodif'+precodif+'Weighting1');
			p.disabled = false;
			create_Weighting(precodif);
			document.getElementById("Precodif"+precodif+"Weighting2").setAttribute("name","data[Precodif]["+precodif+"][weighting][2]");
			create_Weighting(precodif);
			document.getElementById("Precodif"+precodif+"Weighting3").setAttribute("name","data[Precodif]["+precodif+"][weighting][3]");
			create_Weighting(precodif);
			document.getElementById("Precodif"+precodif+"Weighting4").setAttribute("name","data[Precodif]["+precodif+"][weighting][4]");
			var c = document.getElementById('Precodif'+precodif+'Criticity');
			c.value = "3";
			c.disabled = false;
			break;
		case "3":  // Ouvert
			for(i=2;i<=maxAnswer;i++){
				if (document.getElementById('Precodif'+precodif+'Answer'+i) != null) {
					remove_Answer(i,precodif);
				}
			}
			document.getElementById('Precodif'+precodif+'AnswerNumber').value = 1;
			var l = document.getElementById('Precodif'+precodif+'Answer1');
			l.value = "Sans objet";
			l.disabled = true;
			for(i=2;i<=maxWeighting;i++){
				if (document.getElementById('Precodif'+precodif+'Weighting'+i) != null) {
					remove_Weighting(i,precodif);
				}
			}
			document.getElementById('Precodif'+precodif+'WeightingNumber').value = 1;
			var p = document.getElementById('Precodif'+precodif+'Weighting1');
			p.disabled = false;
			p.value = "0";
			var c = document.getElementById('Precodif'+precodif+'Criticity');
			c.value = "3";
			c.disabled = true;
			break;
		default:
			alert("Erreur technique");
			break;
	
	}
}


//function to select/deselect all checkbox button in a line
function global_select_line(chkboxselected, id, fields) {
	var selected = document.getElementById(chkboxselected + id);
	var boolaction = selected.checked;
	var arrayFields = fields.split("|");
	for(i=0;i<arrayFields.length;i++) {
		document.getElementById(arrayFields[i] + id).checked = boolaction;
	}
}

//function to select/deselect all checkbox button in a column
function global_select_column(theform, chkboxselected, id, chkboxfirst) {
	var selected = document.getElementById(chkboxselected + id);
	var boolaction = selected.checked;
	var myform = document.getElementById(theform);
	if (boolaction) {
		for(i=0;i<myform.length;i++) {
			if (myform.elements[i].type == "checkbox" && (myform.elements[i].id).substring(0,chkboxselected.length) == chkboxselected) myform.elements[i].checked = false;
			if (chkboxfirst != '') {
				if ((myform.elements[i].id).substring(0,chkboxfirst.length) == chkboxfirst) myform.elements[i].checked = false;
			}
		}
		selected.checked = true;
	} else {
		for(i=0;i<myform.length;i++) {
			if (chkboxfirst != '') {
				if ((myform.elements[i].id).substring(0,chkboxfirst.length) == chkboxfirst) myform.elements[i].checked = false;
			}
		}
	}
}

//function to deselect all checkbox buttons in a form unless this radio button
function global_clear_form(theform, chkboxselected) {
	var selected = document.getElementById(chkboxselected);
	var boolaction = selected.checked;
	var myform = document.getElementById(theform);
	if (boolaction) {
		for(i=0;i<myform.length;i++) {
			if (myform.elements[i].type == "checkbox") myform.elements[i].checked = false;
		}
		selected.checked = true;
	}
}

//function to add numeric fields values into another field
// this function replace "," by "."
// if a value is not numeric, replace value by ""
// by default return 0
function add_value_fields(fields, resultfield) {
	var arrayFields = fields.split("|");
	var result = 0;
	for(i=0;i<arrayFields.length;i++) {
		val = document.getElementById(arrayFields[i]).value;
		val = val.replace(/\,/g,".");
		document.getElementById(arrayFields[i]).value = val;
		if (val == "") val = 0;
		if (!isNaN(val)) {
			result += eval(val);
		} else {
			document.getElementById(arrayFields[i]).value = "";
		}
	}
	document.getElementById(resultfield).value = result;
}

//function to validate mandatories competences in job form
function valideJobCompetences(prefix, suffix, endloop, minnb, errormessage) {
	var nbCompetences = 0;
	for(i=0;i<=endloop;i++) {
		if (document.getElementById(prefix+i+suffix).value != "") nbCompetences++;
	}
	if (nbCompetences < minnb) {
		window.alert(errormessage);
		document.getElementById(prefix+"0"+suffix).focus();
		return false;
	}
	return true;
}

//function to deselect all checkbox buttons for a name type checkbox in a form
function global_clear_checkbox(theform, chkboxfirst, inactif) {
	var myform = document.getElementById(theform);
	if (inactif == "false") {
		for(i=0;i<myform.length;i++) {
			if (myform.elements[i].type == "checkbox") {
				if ((myform.elements[i].id).substring(0,chkboxfirst.length) == chkboxfirst) myform.elements[i].checked = false;
			}
		}
	}
}

//function to validate jobads diffusion
function validate_diffusion() {
	var myform = document.getElementById("formJobad");
	var chkboxfirst = "Jobboard";
	var countDiffusion = 0;
	for(i=0;i<myform.length;i++) {
		if (myform.elements[i].type == "checkbox") {
			if ((myform.elements[i].id).substring(0,chkboxfirst.length) == chkboxfirst) {
				if (myform.elements[i].checked) countDiffusion++;
			}
		}
	}
	if (countDiffusion == 0) {
		return false;
	} else {
	}	return true;
}
// function to dipslay Chronometer (from 30 to 0 seconds)in candidates/endResponse view
i=0;
function chrono(){
	i++;
	document.getElementById("temp").innerHTML=" "+(30-i)+" secondes";
	if(i==30){
		 clearTimeout(compteur);
	}else{
		compteur=setTimeout('chrono()',1000);
	}
}























