// Removes leading whitespaces
function LTrim( value ) {
	var re = /\s*((\S+\s*)*)/;
	return value.replace(re, "$1");
}

// Removes ending whitespaces
function RTrim( value ) {
	var re = /((\s*\S+)*)\s*/;
	return value.replace(re, "$1");
}

// Removes leading and ending whitespaces
function trim( value ) {
	return LTrim(RTrim(value));
}


function enable(val, checker){
	if (document.getElementById(checker).checked){
		document.getElementById(val).disabled = false;
		}
	else{
		document.getElementById(val).disabled = true;
		}
	}


function onselect_disable(id, id_dis){
	if (document.getElementById(id).value == 2 || document.getElementById(id).value == 3 || document.getElementById(id).value == 4){
		document.getElementById(id_dis).disabled = 'true';
		}
	else{
		document.getElementById(id_dis).disabled = '';
		}
	}



function enable_if(exp, val, checker){
	if (exp){
		document.getElementById(val).disabled = false;
		}
	else{
		document.getElementById(val).disabled = true;
		}
	}


function view(id){
	if(document.getElementById(id).style.display == 'none'){
		document.getElementById(id).style.display = '';
	}else{
		document.getElementById(id).style.display =	'none';
	}
}

function sendMail(){
	if(document.getElementById('sendmail').checked == true){
		document.getElementById('message').style.display = "";
	}else{
		document.getElementById('message').style.display = "none";
	}
}


function confirmAct(msg){
	var agree=confirm(msg);
	if (agree)
		return true;
	else
		return false ;
	}


function display_if(idz, id_div){
	if (document.getElementById(idz).value == 1){
		document.getElementById('exp1' + id_div).style.display = '';
		document.getElementById('exp2' + id_div).style.display = 'none';
		document.getElementById('exp3' + id_div).style.display = 'none';
		document.getElementById('exp4' + id_div).style.display = 'none';
	}

	if (document.getElementById(idz).value == 2){
		document.getElementById('exp1' + id_div).style.display = 'none';
		document.getElementById('exp2' + id_div).style.display = '';
		document.getElementById('exp3' + id_div).style.display = 'none';
		document.getElementById('exp4' + id_div).style.display = 'none';
	}

	if (document.getElementById(idz).value == 3){
		document.getElementById('exp1' + id_div).style.display = 'none';
		document.getElementById('exp2' + id_div).style.display = 'none';
		document.getElementById('exp3' + id_div).style.display = '';
		document.getElementById('exp4' + id_div).style.display = 'none';
	}

	if (document.getElementById(idz).value == 4){
		document.getElementById('exp1' + id_div).style.display = 'none';
		document.getElementById('exp2' + id_div).style.display = 'none';
		document.getElementById('exp3' + id_div).style.display = 'none';
		document.getElementById('exp4' + id_div).style.display = '';
	}
}


function changeCouleur(ligne){
	ligne.bgColor = 'red';
	}

function remetCouleur(ligne){
	ligne.bgColor = 'red';
	}

function addLoadEvent(func) {
	var oldonload = (typeof window.onload == 'function')?window.onload:null;
	window.onload = function() {
		if(oldonload != null && typeof oldonload == 'function') oldonload();
		eval(func);
	}
}

function addInputField(val,i) {
  divv=document.getElementById("cv_inputs");
  div2=document.createElement('div');
  //div2.innerHTML
  str  = '<table>';
  str +=   '<tr>';
	str +=     '<td rowspan="2" width="50px"><input id="rad_'+i+'" type="radio" value="'+i+'" name="cv_activated" '+val+'></td>';
  str +=			'<td class="text1_small" nowrap>CV Name :</td>';
  str +=			'<td> <input id="name_'+i+'" class="field_small2" style="width:154px;" type="text" name="candidate_cv_name[]"> </td>';
  str +=		'</tr>';
  str +=		'<tr>';
  str +=			'<td class="text1_small">File : </td>';
  str +=			'<td><input type="file" id="file_'+i+'" class="field_small2" style="width:156px;" name="candidate_cv_file[]" ></td>';
  str +=		'</tr>';
  str +=	'</table>';
  div2.innerHTML = str;
  divv.appendChild(div2);
}


function disableCheckbox(i)
{
	if(document.getElementById('rad_'+i).checked)
	{
		if(document.getElementById('cv_name_'+i).value!='' && document.getElementById('cv_file_'+i).value!='')
			document.getElementById('candidate_enable_cv_search').disabled=false; 
		else 
			document.getElementById('candidate_enable_cv_search').disabled=true;
	}
}

function verify_extension(file)
{
	var v = file.split('.');
	var ext = v[v.length-1];
	if(ext!='doc' && ext!='DOC' && ext!='docx' && ext!='DOCX' && ext!='odt' && ext!='ODT' && ext!='pdf' && ext!='PDF')
	{
		alert('The file must have one of the following extension: doc, docx, odt, pdf');
		return false;	
	}
	else return true;
}


function checkCheckbox(i)
{
	if(document.getElementById('rad_'+i).checked)
	{
		if(trim(document.getElementById('cv_name_'+i).value)!='' && trim(document.getElementById('cv_file_'+i).value)!='')
			document.getElementById('candidate_enable_cv_search').checked=true; 
		else 
			document.getElementById('candidate_enable_cv_search').checked=false;
	}
}

function addInputFieldReg(val,i) {
  divv=document.getElementById("cv_inputs");
  div2=document.createElement('div');
  str  = '<table>';
  str +=   '<tr>';
	str +=     '<td rowspan="2" width="50px"><input id="rad_'+i+'" type="radio" value="'+i+'"';
	if(i == 0) 
	str += ' checked="checked" ';
	str += ' onclick="checkCheckbox('+i+')" name="radio_active" '+val+'></td>';
  str +=			'<td class="text1_small" nowrap>CV Name :</td>';
  if(i == 0) 
  	str +=			'<td> <input onchange="checkCheckbox('+i+')" id="cv_name_' + i + '" class="field_small2" value="My CV" style="width:154px;" type="text" name="cv_name_' + i + '"> </td>';
  else
  	str +=			'<td> <input onchange="checkCheckbox('+i+')" id="cv_name_' + i + '" class="field_small2" value="" style="width:154px;" type="text" name="cv_name_' + i + '"> </td>';
  str +=		'</tr>';
  str +=		'<tr>';
  str +=			'<td class="text1_small">CV File : </td>';

  str +=			'<td><input onchange="if(!verify_extension(this.value)) this.value=\'\'; checkCheckbox('+i+');" type="file" id="cv_file_' + i + '" class="field_small2" style="width:156px;" name="cv_file_' + i + '" ></td>';
	
  str +=		'</tr>';
  str +=	'</table>';
  div2.innerHTML = str;
  divv.appendChild(div2);
  //document.getElementById("cv_count").value = (i+1);
  
}

function addInputFieldReg2(val,i) {
  divv=document.getElementById("cv_inputs");
  div2=document.createElement('div');
  str  = '<table>';
  str +=   '<tr>';
  str +=     '<td rowspan="2" width="50px"><input id="rad_'+i+'" type="radio" value="'+i+'"';
  if(i == 0) 
  str += ' checked="checked" ';  
  str += ' onclick="checkCheckbox('+i+')" name="radio_active"></td>';
  str +=			'<td class="text1_small" nowrap>CV Name :</td>';
  if(i == 0) 
  	str +=			'<td> <input onchange="checkCheckbox('+i+')" id="cv_name_' + i + '" class="field_small2" value="My CV" style="width:154px;" type="text" name="cv_name['+i+']"> </td>';
  else
  	str +=			'<td> <input onchange="checkCheckbox('+i+')" id="cv_name_' + i + '" class="field_small2" value="" style="width:154px;" type="text" name="cv_name['+i+']"> </td>';
  str +=		'</tr>';
  str +=		'<tr>';
  str +=			'<td class="text1_small">CV File : </td>';

  str +=			'<td><input onchange="if(!verify_extension(this.value)) this.value=\'\'; checkCheckbox('+i+');" type="file" id="cv_file_' + i + '" class="field_small2" style="width:156px;" name="cv_file['+i+']" ></td>';
	
  str +=		'</tr>';
  str +=	'</table>';
  div2.innerHTML = str;
  divv.appendChild(div2);
  //document.getElementById("cv_count").value = (i+1);
  
}



var i=0;
function disableEnable(sel)
{

  if(sel.options[0].selected==true || sel.options[1].selected==true || sel.options[3].selected==true)
  {
    sel.form.candidate_looking_min_salary.disabled=false;
    sel.form.candidate_looking_max_salary.disabled=false;
  }else{
    sel.form.candidate_looking_min_salary.disabled=true;
    sel.form.candidate_looking_max_salary.disabled=true;
  }
  if(sel.options[2].selected==true)
  {
    sel.form.candidate_minimum_daily_rate.disabled=false;
  }else{
    sel.form.candidate_minimum_daily_rate.disabled=true;
  }
}

function disableEnable2(sel)
{

 if(sel.options[0].selected===false && sel.options[1].selected===false && sel.options[3].selected===false && sel.options[2].selected === true)
  {
   	document.getElementById('per_type').innerHTML = 'Per Day';
	document.getElementById('per_type_input').value = 'PerDay';
  }
  else
  {
	document.getElementById('per_type').innerHTML = 'Per Year';
	document.getElementById('per_type_input').value = 'PerYear';
  }

}

function candidateSubmitCheck(form, cvCount, uploadedCvCount, back_button ) {
	if ( back_button == 1 ) {
		return true;
	}
	var arrCVs = new Array();
	for (idx = 0; idx < arrUploadedCvs.length; idx++) {
		arrCVs[idx] = arrUploadedCvs[idx];
	}
	for( idx=uploadedCvCount; idx < cvCount; idx++ ) {
		cvName = eval('document.getElementById("cv_name_' + idx + '").value');
		//alert(cvName);
		for ( j=0; j < arrCVs.length; j++ ) {
			if ( cvName == arrCVs[j] ) {
				alert("You can not asign the same name for 2 CVs");
				return false;
			}
		}
		arrCVs[idx] = cvName;
	}
  flagName = true;
  for( a=uploadedCvCount; a < cvCount; a++ ) {
    names = eval('document.getElementById("cv_name_' + a + '").value');
    files = eval('document.getElementById("cv_file_' + a + '").value');
    if(files!="" && names==""){
      flagName = false;
      break;
    }
  }
  if ( !flagName ) {
    alert("Please assign names to all cv files");
    return false;
  }
  form.cv_count.value = cvCount;
  //alert(form.cv_count.value);
  
  //return true;
  // check if is selected active CV
  flagActive = false;
  if ( form["radio_active"].length ) {
    for (i=0; i<form["radio_active"].length; i++) {
    	if (form.radio_active[i].checked) {
    		flagActive = true
    		break;
    	}
    }
    
    if ( !flagActive ) {
      alert("Please select active CV");
      return false;
    }
  }
  else {
 		if ( !form.radio_active.checked ) {
      alert("Please select active CV");
      return false;
 		}
  	
  }
  
  //alert(form.cv_count.value);
  //return false;
  
  return true;
}

function candidateEditSubmitCheck(form, cvCount, uploadedCvCount ) {
	var arrCVs = new Array();
	for (idx = 0; idx < arrUploadedCvs.length; idx++) {
		arrCVs[idx] = arrUploadedCvs[idx];
	}
	for( idx=uploadedCvCount; idx < cvCount; idx++ ) {
		cvName = eval('document.getElementById("cv_name_' + idx + '").value');
		//alert(cvName);
		for ( j=0; j < arrCVs.length; j++ ) {
			if ( cvName == arrCVs[j] ) {
				alert("You can not asign the same name for 2 CVs");
				return false;
			}
		}
		arrCVs[idx] = cvName;
	}

	activeCvOk = true;
  for ( myi =uploadedCvCount; myi<cvCount; myi++) {
  	selectedFile = document.getElementById("cv_file_" + myi).value;
  	if ( form.radio_active[myi].checked && selectedFile == "" ) {
  		activeCvOk = false;
	    break;
  	}
  }
  
  if ( !activeCvOk ) {
    alert("Please select a file for active CV");
    return false;
  }
	//return false;
  
  flagName = true;
  for( a=uploadedCvCount; a < cvCount; a++ ) {
    names = eval('document.getElementById("cv_name_' + a + '").value');
    files = eval('document.getElementById("cv_file_' + a + '").value');
    if(files!="" && names==""){
      flagName = false;
      break;
    }
  }
  if ( !flagName ) {
    alert("Please assign names to all cv files");
    return false;
  }
  
  form.cv_count.value = cvCount;
  //alert(form.cv_count.value);
  
  //return true;
  // check if is selected active CV
  flagActive = false;
  if ( form["radio_active"].length ) {
    for (i=0; i<form["radio_active"].length; i++) {
    	if (form.radio_active[i].checked) {
    		flagActive = true
    		break;
    	}
    }
    
    if ( !flagActive ) {
      alert("Please select active CV");
      return false;
    }
  }
  else {
 		if ( !form.radio_active.checked ) {
      alert("Please select active CV");
      return false;
 		}
  	
  }
  
  //alert(form.cv_count.value);
  return true;
  
  //form.submit();
}

function isInteger(str) {
  regex = /[^\-0-9]/;
  if ( regex.test(str) ) {
    return false;
  }
  else {
    return true;
  }
}

function getChecked(frmId, checkboxName) {
  frm    = document.getElementById(frmId);
  elm    = frm[checkboxName + "[]"];
  values = '';
  if ( elm.length ) {
    for (i = 0; i < elm.length; i++) {
      if ( elm[i].checked == true ) {
        values = values + (values != '' ? "," + elm[i].value : elm[i].value);
      }
    }
  }
  else {
    if ( elm.checked == true  ) {
      values = elm.value;
    }
  }
  return values;
}

var Cookies = {
	init: function () {
		var allCookies = document.cookie.split('; ');
		for (var i=0;i<allCookies.length;i++) {
			var cookiePair = allCookies[i].split('=');
			this[cookiePair[0]] = cookiePair[1];
		}
	},
	create: function (name,value,days) {
		if (days) {
			var date = new Date();
			date.setTime(date.getTime()+(days*24*60*60*1000));
			var expires = "; expires="+date.toGMTString();
		}
		else var expires = "";
		document.cookie = name+"="+value+expires+"; path=/";
		this[name] = value;
	},
	erase: function (name) {
		this.create(name,'',-1);
		this[name] = undefined;
	}
};
Cookies.init();

/*
function cookieCreate(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function cookieRead(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function cookieErase(name) {
	cookieCreate(name,"",-1);
}
*/

	function cv_search_check()
	{
		if($('#candidate_enable_cv_search').attr('checked') == true)
		{
			$('#candidate_enable_cv_search').val('1');
			$('#candidate_enable_cv_search').attr('checked',true);
		}			
		else{
			$('#candidate_enable_cv_search').val('2');
			$('#candidate_enable_cv_search').attr('checked',false);
		}
	}
	
	function weekly_check()
	{
		if($('#candidate_automatic_updates').attr('checked') == true)
		{
			$('#candidate_automatic_updates').val('1');
			$('#candidate_automatic_updates').attr('checked',true);
		}			
		else{
			$('#candidate_automatic_updates').val('2');
			$('#candidate_automatic_updates').attr('checked',false);
		}
		
	}
	
	function check_small_form(frm,nr)
	{
		
		if(document.getElementById('candidate_username_apply').value == '')	
		{
			alert('Please enter an username');
			return false;
		}
		if(document.getElementById('candidate_password_apply').value == '')	
		{
			alert('Please enter a password');
			return false;
		}
		if(document.getElementById('small_login_s'))
		{
			if(document.getElementById('cv_name_0_s').value == '')	
			{
				alert('Please enter a CV name');
				return false;
			}	
			if(document.getElementById('cv_file_0_s').value == '')	
			{
				alert('Please upload a CV');
				return false;
			}	
		}
	
		if(checkForm(frm,nr))
			return true;
		else
			return false;
	}
	
	function check_login_block(frm,nr)
	{		
		
		/*if(document.getElementById('cv_name_0'))
		{
			if(document.getElementById('cv_name_0').value == '')	
			{
				alert('Please enter a CV name');
				return false;
			}	
			if(document.getElementById('cv_file_0').value == '')	
			{
				alert('Please upload a CV');
				return false;
			}	
			if(checkForm(frm,nr))
				return true;
			else
				return false;
		}
		if(document.getElementById('candidate_firstname').value == '')	
		{
			alert('Please enter first name');
			return false;
		}
		if(document.getElementById('candidate_surname').value == '')	
		{
			alert('Please enter surname');
			return false;
		}
		if(document.getElementById('candidate_email').value == '')	
		{
			alert('Please enter an email');
			return false;
		}
		if (echeck(document.getElementById('candidate_email').value)==false)
		{
			document.getElementById('candidate_email').value='';
			document.getElementById('candidate_email').focus();
			return false;
		}	
		
		if(document.getElementById('repeat_email').value == '')	
		{
			alert('Please enter repeat the email');
			return false;
		}
		if (echeck(document.getElementById('repeat_email').value)==false){
			document.getElementById('repeat_email').value='';
			document.getElementById('repeat_email').focus();
				return false;
			}	
		if(document.getElementById('repeat_email').value != document.getElementById('candidate_email').value)	
		{
			alert('The email doesn\'t match');
			document.getElementById('repeat_email').value='';
			document.getElementById('repeat_email').focus();
			return false;
		}
		if(document.getElementById('candidate_username').value == '')	
		{
			alert('Please enter an username');
			return false;
		}
		if(document.getElementById('candidate_password').value == '')	
		{
			alert('Please enter a password');
			return false;
		}
		
		if(document.getElementById('candidate_password_repeat').value == '')	
		{
			alert('Please repeat the password');
			return false;
		}
		if(document.getElementById('candidate_password_repeat').value != document.getElementById('candidate_password').value)	
		{
			alert('The password doesn\'t match');
			document.getElementById('candidate_password_repeat').value='';
			document.getElementById('candidate_password_repeat').focus();
			return false;
		}
		if(document.getElementById('cv_name_0').value == '')	
		{
			alert('Please enter a CV name');
			return false;
		}	
		if(document.getElementById('cv_file_0').value == '')	
		{
			alert('Please upload a CV');
			return false;
		}
		if(!document.getElementById('accept').checked)	
		{
			alert('You must accept Terms and Conditions ');
			return false;
		}*/
		
		
		if(checkForm(frm,nr))
		{			
			
			return true;			
		}
		else
			return false;
			
	}


function echeck(str) {

		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
		   alert("Invalid Email")
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   alert("Invalid Email")
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    alert("Invalid Email")
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    alert("Invalid Email")
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    alert("Invalid Email")
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    alert("Invalid Email")
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		    alert("Invalid Email")
		    return false
		 }

 		 return true					
	}
	
	function check_registration()
	{		
		if(trim(document.getElementById('candidate_firstname').value) == '')	
		{
			alert('Please enter first name');
			return false;
		}
		if(trim(document.getElementById('candidate_surname').value) == '')	
		{
			alert('Please enter surname');
			return false;
		}
		if(trim(document.getElementById('candidate_email').value) == '')	
		{
			alert('Please enter an email');
			return false;
		}
		if (echeck(document.getElementById('candidate_email').value)==false)
		{
			document.getElementById('candidate_email').value='';
			document.getElementById('candidate_email').focus();
			return false;
		}	
		
	/*	if(document.getElementById('repeat_email').value == '')	
		{
			alert('Please enter repeat the email');
			return false;
		}
		if (echeck(document.getElementById('repeat_email').value)==false){
			document.getElementById('repeat_email').value='';
			document.getElementById('repeat_email').focus();
				return false;
			}*/	
		/*if(document.getElementById('repeat_email').value != document.getElementById('candidate_email').value)	
		{
			alert('The email doesn\'t match');
			document.getElementById('repeat_email').value='';
			document.getElementById('repeat_email').focus();
			return false;
		}*/
		if(trim(document.getElementById('candidate_username').value) == '')	
		{
			alert('Please enter an username');
			return false;
		}
		if(trim(document.getElementById('candidate_password').value) == '')	
		{
			alert('Please enter a password');
			return false;
		}
		
		/*if(document.getElementById('candidate_password_repeat').value == '')	
		{
			alert('Please repeat the password');
			return false;
		}
		if(document.getElementById('candidate_password_repeat').value != document.getElementById('candidate_password').value)	
		{
			alert('The password doesn\'t match');
			document.getElementById('candidate_password_repeat').value='';
			document.getElementById('candidate_password_repeat').focus();
			return false;
		}*/
		
		if(document.getElementById('candidate_experience_1').value != '' && isNaN(document.getElementById('candidate_experience_1').value))	
		{
			alert('Please enter a number');
			document.getElementById('candidate_experience_1').value = '';
			document.getElementById('candidate_experience_1').focus();
			return false;
		}
		if(document.getElementById('candidate_experience_2').value != '' && isNaN(document.getElementById('candidate_experience_2').value))	
		{
			alert('Please enter a number');
			document.getElementById('candidate_experience_2').value = '';
			document.getElementById('candidate_experience_2').focus();
			return false;
		}
		if(document.getElementById('candidate_experience_3').value != '' && isNaN(document.getElementById('candidate_experience_3').value))	
		{
			alert('Please enter a number');
			document.getElementById('candidate_experience_3').value = '';
			document.getElementById('candidate_experience_3').focus();
			return false;
		}
		
		if(document.getElementById('candidate_looking_min_salary').value != '' && isNaN(document.getElementById('candidate_looking_min_salary').value))	
		{
			alert('Please enter a number');
			document.getElementById('candidate_looking_min_salary').value = '';
			document.getElementById('candidate_looking_min_salary').focus();
			return false;
		}
		
		if(document.getElementById('candidate_looking_max_salary').value != '' && isNaN(document.getElementById('candidate_looking_max_salary').value))	
		{
			alert('Please enter a number');
			document.getElementById('candidate_looking_max_salary').value = '';
			document.getElementById('candidate_looking_max_salary').focus();
			return false;
		}
		if(typeof(document.getElementById('accept'))=='object'){	
			if(!document.getElementById('accept').checked)	
			{
				alert('You must accept Terms and Conditions ');
				return false;
			}
		}
		
	}
	
	function getSubsectorsById(id)
	{
		$('#subsector_div').empty();
		$('#subsector_div').html('<img src="/images/ajax-loader.gif" />');
		$('#subsector_div').load('getsubsector.php?id='+id);
	}

	function getSubsectorsById2(id)
	{
		$('#job_subsector').empty();
		$('#subsector_div').html('<img src="/images/ajax-loader.gif" />');
		$.getJSON("getsubsector2.php?id="+id,function(json){
			var opt = document.createElement("OPTION");
			opt.value = 0;
			opt.text  = "Sub Sector";

			var urlstr = window.location.href;
			//alert(urlstr);
			if(urlstr.indexOf('p=display_jobs')!=-1){
				$('#subsector_div').html('<select name="job_subsector" id="job_subsector" class="field" style="width:260px;"></select>');
			}else if(urlstr.indexOf('action=create_new_role')!=-1){
				$('#subsector_div').html('<select name="job_subsector" id="job_subsector" class="field" style="width:300px;"></select>');
			}else if(urlstr.indexOf('p=advanced_search_form')!=-1){
				$('#subsector_div').html('<select name="job_subsector" id="job_subsector" class="field" style="width:300px;"></select>');
			}else if(urlstr.indexOf('p=advanced_search_results')!=-1){
				$('#subsector_div').html('<select name="job_subsector" id="job_subsector" class="field" style="width:260px;"></select>');
			}else if(urlstr.indexOf('p=login_candidate')!=-1){
				$('#subsector_div').html('<select name="job_subsector" id="job_subsector" class="field" style="width:260px;"></select>');
			}
			$("#job_subsector")[0].options.add(opt);
			if(json){
				//var json = eval(json);
				var len = json.length;
				for (i = 0; i < len; i ++ ){
					var opt = document.createElement("OPTION");
					opt.value = json[i].sec_id;
					opt.text  = json[i].sec_name;
					$("#job_subsector")[0].options.add(opt);
				}
			}
		});
		//$('#subsector_div').empty();
	}

	function show_progress()
	{
		$('#progress_bar').show();
		$('#login_block').hide();
		$('#table_questions').hide();
	}

	function getMaxSalary(min,type)
	{
		$('#job_salary_range_max').empty();
		$.getJSON("getsalary.php?min="+min+"&type="+type,function(json){
			if(json){
				var json = eval(json);
				var len = json.length;
				for (i = 0; i < len; i ++ ){
					var opt = document.createElement("OPTION");
					opt.value = json[i].skey;
					opt.text  = json[i].svalue;
					$("#job_salary_range_max")[0].options.add(opt);
				}
			}
		});
	}

	function getSalaryRate(type)
	{
		if(type=='PerDay' || type=='PerYear'){
			$('#job_salary_range_min').empty();
			$('#loader_div').html('<img src="/images/ajax-loader.gif" />');
			$.getJSON("getsalary.php?type="+type,function(json){
			var urlstr = window.location.href;
			if(urlstr.indexOf('p=display_jobs')!=-1){
				$('#loader_div').html('<select name="job_salary_range_min" id="job_salary_range_min" class="text1_small" style="width:100px;">');
			}else if(urlstr.indexOf('p=advanced_search_results')!=-1){
				$('#loader_div').html('<select name="job_salary_range_min" id="job_salary_range_min" class="text1_small" style="width:100px;">');
			}else if(urlstr.indexOf('p=login_candidate')!=-1 && urlstr.indexOf('action=advanced_search_form')==-1){
				$('#loader_div').html('<select name="job_salary_range_min" id="job_salary_range_min" class="text1_small" style="width:100px;">');
			}else if(urlstr.indexOf('p=login_candidate')!=-1 && urlstr.indexOf('action=advanced_search_form')!=-1){
				$('#loader_div').html('<select name="job_salary_range_min" id="job_salary_range_min" class="text1_small" style="width:300px;">');
			}else{
				$('#loader_div').html('<select name="job_salary_range_min" id="job_salary_range_min" class="text1_small" style="width:300px;">');
			}
				if(json){
					var json = eval(json);
					var len = json.length;
					$("#job_salary_range_max").empty();
					for (i = 0; i < len; i ++ ){
						var opt_min = document.createElement("OPTION");
						var opt_max = document.createElement("OPTION");
						opt_min.value = json[i].skey;
						opt_min.text  = json[i].svalue;
						opt_max.value = json[i].skey;
						opt_max.text  = json[i].svalue;
						$("#job_salary_range_min")[0].options.add(opt_min);
						$("#job_salary_range_max")[0].options.add(opt_max);
					}
				}
			});
		}else{
			var urlstr = window.location.href;
			if(urlstr.indexOf('p=display_jobs')!=-1){
				$('#loader_div').html('<select name="job_salary_range_min" id="job_salary_range_min" class="text1_small" style="width:100px;">');
			}else if(urlstr.indexOf('p=advanced_search_results')!=-1){
				$('#loader_div').html('<select name="job_salary_range_min" id="job_salary_range_min" class="text1_small" style="width:100px;">');
			}else if(urlstr.indexOf('p=login_candidate')!=-1 && urlstr.indexOf('action=advanced_search_form')==-1){
				$('#loader_div').html('<select name="job_salary_range_min" id="job_salary_range_min" class="text1_small" style="width:100px;">');
			}else if(urlstr.indexOf('p=login_candidate')!=-1 && urlstr.indexOf('action=advanced_search_form')!=-1){
				$('#loader_div').html('<select name="job_salary_range_min" id="job_salary_range_min" class="text1_small" style="width:300px;">');
			}else{
				$('#loader_div').html('<select name="job_salary_range_min" id="job_salary_range_min" class="text1_small" style="width:300px;">');
			}
			var opt_min = document.createElement("OPTION");
			var opt_max = document.createElement("OPTION");
			opt_min.value = 0;
			opt_min.text  = 'Min salary';
			opt_max.value = 0;
			opt_max.text  = 'Max salary';
			$('#job_salary_range_min')[0].options.length = 0;  
			$('#job_salary_range_max')[0].options.length = 0;  
			$("#job_salary_range_min")[0].options.add(opt_min);
			$("#job_salary_range_max")[0].options.add(opt_max);
		}
		//$('#loader_div').empty();
	}

