function go_home() { 
  var ajaxBaseUrl = base_url;
  //alert(ajaxBaseUrl);
  if (!ajaxBaseUrl) {
    var ajaxBaseUrl = document.location.href;
    var ajaxTemp = ajaxBaseUrl.indexOf("/", 7) + 1;
    ajaxBaseUrl = ajaxBaseUrl.substring(0, ajaxTemp);
  }

//  alert(ajaxBaseUrl);
//  return true;
  
  SetCustomerArea();
  document.location = ajaxBaseUrl;

}

function callback_booster(customer_profile_id) {
  
  if (!customer_profile_id) {
    simple_alert($("#trn_login_employer").text());
    return false;
  }
  
  confirm_message = $("#trn_callback").text();
  //alert(confirm_message);

  simple_confirm(confirm_message, function(){  
    var ajaxBaseUrl = document.location.href;
    var ajaxTemp = ajaxBaseUrl.lastIndexOf("/") + 1;
    ajaxBaseUrl = ajaxBaseUrl.substring(0, ajaxTemp);
    var requestStr = ajaxBaseUrl + "index.html?__ajaxMethod=jv_callback_request";      
    $.ajax({
            async: false,
            //timeout: 3000,
            type: 'POST',
            url: requestStr,
            data: { customer_profile_id: customer_profile_id },
            success: function(answ) {
              //alert(answ);
              if(answ == "correct"){
                //alert(ajaxBaseUrl + "callback_sent.html");
                //document.location.href = ajaxBaseUrl + "callback_sent.html";
                simple_alert($("#trn_thanks").text());
                //return true;
              }
              if (answ == "no_agent") {
                simple_alert($("#trn_no_agent").text());
                //return false;
              }
            },
            error: function() {
              simple_alert($("#trn_warning").text()); 
              return false;
            }
          })
    
  }, true);

}

function SetCustomerArea(flag) {
  var ajaxBaseUrl = document.location.href;
  var ajaxTemp = ajaxBaseUrl.lastIndexOf("/") + 1;
  ajaxBaseUrl = ajaxBaseUrl.substring(0, ajaxTemp);
  var requestStr = ajaxBaseUrl + "index.html?__ajaxMethod=jv_set_customer_area";      
  var code = "user";
  if (flag) {
    code = "employer";
  }
//  alert(requestStr);
//  alert(code);
//  return false;
  $.ajax({
          async: false,
          type: 'POST',
          url: requestStr,
          data: { code: code }
        })
  
//  if (flag) {
//    Set_Cookie("user_type_area", "employer");
//  } else {
//    Set_Cookie("user_type_area", "user");
//  }
  return true;

}

function set_language (code) {
  var ajaxBaseUrl = document.location.href;
  var ajaxTemp = ajaxBaseUrl.lastIndexOf("/") + 1;
  ajaxBaseUrl = ajaxBaseUrl.substring(0, ajaxTemp);
  var requestStr = ajaxBaseUrl + "index.html?__ajaxMethod=jv_do_ajax_change_language";      
  $.ajax({
          async: false,
          type: 'POST',
          url: requestStr,
          data: { lang_code: code },
          success: function(answ) {
            cms_page_refresh();
          }
        })
}

function set_country_language (country, language) {

  var ajaxBaseUrl = document.location.href;
  var ajaxTemp = ajaxBaseUrl.lastIndexOf("/") + 1;
  ajaxBaseUrl = ajaxBaseUrl.substring(0, ajaxTemp);
  var requestStr = ajaxBaseUrl + "index.html?__ajaxMethod=jv_do_ajax_change_country_language";
   
  $.ajax({
          async: false,
          type: 'POST',
          url: requestStr,
          data: { country_id: country , lang_id: language}
//          success: function(answ) {
//            cms_page_refresh();
//          }
        })
}

function clear_prof_from(overlay_id){
  if(typeof(overlay_id) == 'undefined'){
    overlay_id = 'profl_overlay';
  }
  //$('#prof_popup').validate(); 
  $('#prof_popup').clearForm();
  $('#profl_country_id').val(curr_dom); 
  show_hdivs_prof();  
  clear_multi_selects($('#access_companies'), $('#access_companies1'));
  clear_multi_selects($('#access_levels'), $('#access_levels1'));
  $('#profl_type_id_contact').attr('checked','checked');
  $('#profl_type_id_contact').change();
  $("#is_edit_prof_id").val('new');
  $('#finish_button_addr').val($('#finish_button_addr').attr('sav'));
  show_overlay('profl_overlay', 'undefined', 'undefined', overlay_id);
  //alert($('#prof_popup').attr('id'));
  //$('#prof_popup').clearForm();  
  $('#prof_popup').validate();  
}

function show_hdivs_prof(){
  $('.ifnn').removeClass('weg');
  $('#profl_email').addClass('required');
  $('#profl_email').addClass('uniqueLogin');
  $('#profl_email2').addClass('required');
  $('#profl_password').addClass('required');
  $('#profl_password2').addClass('required');
}

function hide_hdivs_prof(){
  $('.ifnn').addClass('weg');
  $('#profl_email').removeClass('required');
  $('#profl_email').removeClass('uniqueLogin');
  $('#profl_email2').removeClass('required');
  $('#profl_password').removeClass('required');
  $('#profl_password2').removeClass('required');
}

function show_overlay(elid, callback, close_immediately, overlay_id){ 
  if(typeof(overlay_id) == 'undefined'){
    overlay_id = 'edit_adress_overlay';
  } else {
      if(overlay_id == null){
	    overlay_id = 'edit_adress_overlay';
	  }
  }
  if(typeof(close_immediately) == 'undefined'){
    close_immediately = false;
  } else {
    if(!close_immediately){
      close_immediately = false;
    }
  }
	$('#'+overlay_id).modal({
		close:false,
		position: ["20px",],
		overlayId:'confirmModalOverlay',
		containerId:'overlayModalContainer', 
		onShow: function (dialog) {//
		  app = $('#'+elid).html();
		  app = str_replace('_placeholder_','',app);		  
			dialog.data.find('.message').append(app);
			dialog.data.find('.header').append($('#profl_overlay_hdr').html());
                  if (overlay_id == 'edit_adress_overlay') {
                    var screeny=600;
                    if (self.innerHeight)  {
                      screeny = self.innerHeight;
                    } else if (document.documentElement && document.documentElement.clientHeight) {
                      screeny = document.documentElement.clientHeight;
                    } else if (document.body) {
                      screeny = document.body.clientHeight;
                    }
                    var height = $('#'+overlay_id).height();
                    if (screeny < 40 + height) {
                      $('#'+overlay_id).css({'top':'5px', 'margin-top':'0px'});
                      $('#'+overlay_id).height(screeny-40);
                    }
                  }
		}
	});
}

/*jQuery.fn.center = function () {
    this.css("position","absolute");
    this.css("top", (($(window).height() - this.outerHeight()) / 2) + $(window).scrollTop() + "px");
    this.css("left", (($(window).width() - this.outerWidth()) / 2) + $(window).scrollLeft() + "px");
    return this;
}*/

function simple_alert(message, title){
  console.log(title);
  if (typeof(title) == undefined || title == undefined) title = "Alert";
//simplemodal-close
  $.modal('<div id="confirmModalContainer" class="simplemodal-container" style="position: fixed; z-index: 1002; /*left: 422px; left:35%;*/ top: 20%;"><div style="" id="confirm" class="simplemodal-data"><div style="" id="confirm" class="simplemodal-data"><a class="modalCloseX simplemodal-close" title="Close" href="#"><img src="/resources/close.gif"></a><div class="header"><table width="100%" cellspacing="0" cellpadding="0"><tbody><tr><td><img src="/resources/tabBarLeft-orange.gif"/></td><td width="99%" class="cfghdr"><span>'+title+'</span></td><td><img src="/resources/popup_title_right.gif"/></td></tr></tbody></table></div><p class="message">'+message+'</p><div class="buttons"><div class="no simplemodal-close"><table width="100%" cellspacing="0" cellpadding="0"><tbody><tr><td><img src="/resources/blue_button_left.gif"/></td><td width="99%" class="back">'+trn_ok_button+'</td><td><img src="/resources/blue_button_right.gif"/></td></tr></tbody></table></div></div></div></div>');
  $('.simplemodal-data p').addClass('message');
  var first = true;
  $('.simplemodal-data p').each(function (item){
    if (first)
      first = false
    else
      $(this).attr("style", "margin:0px;padding:2px;");
  });
  //$('.simplemodal-container').css("left", (($(window).width() - $('.simplemodal-container').outerWidth()) / 2) - 60 + $(window).scrollLeft() + "px");
  var WidthInPercent = ($('.simplemodal-container').outerWidth()) * 100 / $(window).width();
  $('.simplemodal-container').css("left", ((100 - WidthInPercent) / 2) - 4 + "%");
}

function simple_confirm(message, callback, close_immediately) {
  if(typeof(close_immediately) == 'undefined'){
    close_immediately = false;
  } else {
    if(!close_immediately){
      close_immediately = false;
    }
  }
  $('#confirm').modal({
    close:false,
    position: ["20%",],
    overlayId:'confirmModalOverlay',
    containerId:'confirmModalContainer', 
    onShow: function (dialog) {
      dialog.data.find('.message').append(message);
      $('#confirmModalContainer #confirm .header').html('<table width="100%" cellpadding="0" cellspacing="0"><tr><td><img src="/resources/tabBarLeft-orange.gif"></td><td width=99% class="cfghdr">'+$('#confirmModalContainer #confirm .header').html()+'</td><td><img src="/resources/popup_title_right.gif"></td></tr></table>');
      $('div.yes').html('<table width="100%" cellpadding="0" cellspacing="0"><tr><td><img src="/resources/blue_button_left.gif"></td><td width=99% class="back">'+$('div.yes').html()+'</td><td><img src="/resources/blue_button_right.gif"></td></tr></table>');
      $('div.no').html('<table width="100%" cellpadding="0" cellspacing="0"><tr><td><img src="/resources/blue_button_left.gif"></td><td width=99% class="back">'+$('div.no').html()+'</td><td><img src="/resources/blue_button_right.gif"></td></tr></table>');
      // if the user clicks "yes"
      dialog.data.find('.yes').click(function () {
        if(close_immediately){
          $.modal.close();
        }
        // call the callback
        if ($.isFunction(callback)) {
          callback.apply();
        }
        // close the dialog
        if(!close_immediately){
          $.modal.close(); 
        }        
      });
    }
  });  
}

function simple_confirm_custom(message, callback, close_immediately) {
  if(typeof(close_immediately) == 'undefined'){
    close_immediately = false;
  } else {
    if(!close_immediately){
      close_immediately = false;
    }
  }
	$('#confirm').modal({
		close:false,
		position: ["20%",],
		overlayId:'confirmModalOverlay',
		containerId:'confirmModalContainer', 
		onShow: function (dialog) {
			dialog.data.find('.message').append(message);
      var hdr = $('#confirmModalContainer #confirm .header').html();
      $('#confirmModalContainer #confirm .header').html('<table width="100%" cellpadding="0" cellspacing="0"><tr><td><img src="/resources/tabBarLeft-orange.gif"></td><td width=99% class="cfghdr">'+$('#confirmModalContainer #confirm .header').html()+'</td><td><img src="/resources/popup_title_right.gif"></td></tr></table>');
      $('div.yes').html('<table width="100%" cellpadding="0" cellspacing="0"><tr><td><img src="/resources/blue_button_left.gif"></td><td width=99% class="back">'+hdr+'</td><td><img src="/resources/blue_button_right.gif"></td></tr></table>');
      //$('div.yes').html('<table width="100%" cellpadding="0" cellspacing="0"><tr><td><img src="/resources/blue_button_left.gif"></td><td width=99% class="back">'+$('div.yes').html()+'</td><td><img src="/resources/blue_button_right.gif"></td></tr></table>');
      //$('div.no').html('<table width="100%" cellpadding="0" cellspacing="0"><tr><td><img src="/resources/blue_button_left.gif"></td><td width=99% class="back">'+$('div.no').html()+'</td><td><img src="/resources/blue_button_right.gif"></td></tr></table>');
			// if the user clicks "yes"
			dialog.data.find('.yes').click(function () {
			  if(close_immediately){
			    $.modal.close();
			  }
				// call the callback
				if ($.isFunction(callback)) {
					callback.apply();
				}
				// close the dialog
				if(!close_immediately){
				  $.modal.close(); 
				}				
			});
		}
	});	
}

function show_bio_div(div_numb){
  if(typeof( __jsox_dynamic_param ) != "undefined"){    
    switch(div_numb){ 
      case 1:
        __jsox_dynamic_param[0] = $('#country_id').val();
      break;
      case 2:
        __jsox_dynamic_param[0] = $('#country_id_2').val();
      break;
    }
  }
   
  for(var i=1;i<7;i++){
    $('#selbio'+i).css('padding','0');
    $('#selbiohr'+i).css('padding','0');      
    if(i == div_numb){
      //$('#selbio'+i).attr('disabled','disabled');            
      $('#selbio'+i).css('display','');
      $('#selbiohr'+i).css('display','none');      
      $('#dbio'+i).show();      
    } else {
      $('#selbiohr'+i).css('display','');
      $('#selbio'+i).css('display','none');
      //$('#selbio'+i).attr('disabled',null);
      $('#dbio'+i).hide();
    }
  }
  return false;
}

function hide_bio_div(div_numb){
  var $div = $('#subbio'+div_numb);
  if ($div.closest('form').data('thisformischanged') == true && !confirm($('#trn_cancel_edit').text())) return;
  is_bio_new = false;
  $div.hide();
   if(div_numb == 5){
    $('#language_id').attr('disabled', null);
  }
  $('#dbio'+div_numb+' .biography_control_button').attr('disabled', null);  
  lis = $('#dbio'+div_numb).find('li');
  for(i=0;i<lis.length;i++){
    dvs = $(lis[i]).find('div');
	//alert(1)
  if(dvs[0])
    $(dvs[0]).show();
  }
  $("#list"+div_numb).sortable({axis: 'y',containment: '#dbio'+div_numb,cursor: 'default', dropOnEmpty: false, stop: function(event, ui) { change_order(div_numb); }});
  $("#list1"+div_numb).disableSelection();
}

function clear_bio_form(id){
  bio_validator_forms[id].resetForm();
  elms = $('#subbio'+id+' input:text');
  var val;
  for(var i=0;i<elms.length;i++){
    if(typeof($(elms[i]).attr('defval')) == 'undefined'){
      val = '';
    } else {
      val=$(elms[i]).attr('defval');
    }        
    $(elms[i]).val(val);
  }
  elms = $('#subbio'+id+' textarea');
  for(var i=0;i<elms.length;i++){
    if(typeof($(elms[i]).attr('defval')) == 'undefined'){
      val = '';
    } else {
      val=$(elms[i]).attr('defval');
    }        
    $(elms[i]).val(val);
  }
  elms = $('#subbio'+id+' input:checkbox');
  for(var i=0;i<elms.length;i++){
    if(typeof($(elms[i]).attr('defval')) == 'undefined'){
      val = null;
    } else {
      val=$(elms[i]).attr('defval');
    }        
    $(elms[i]).attr('checked', val);
  }
  elms = $('#subbio'+id+' select');
  for(var i=0;i<elms.length;i++){
    if(typeof($(elms[i]).attr('defval')) == 'undefined'){
      val = '';
    } else {
      val=$(elms[i]).attr('defval');
    }        
    $(elms[i]).val(val);
  }
  $('#degree_names_mfbox').html('');
  AddMultiInput('', 'degree_name');
  $('#skills_mfbox').html('');
  AddMultiInput('', 'skill');
  if(id == 2){
    $('.ongoing').show();
	  $('#date_till_2_month').addClass('positiveDatesJob');
  }
  //$('#subbio'+id+' input:text').val( $(this).attr('defval') );
  
  
}

function str_replace(search, replace, subject, count) {    
 
    var i = 0, j = 0, temp = '', repl = '', sl = 0, fl = 0,
            f = [].concat(search),
            r = [].concat(replace),
            s = subject,
            ra = r instanceof Array, sa = s instanceof Array;
    s = [].concat(s);
    if (count) {
        this.window[count] = 0;
    }
 
    for (i=0, sl=s.length; i < sl; i++) {
        if (s[i] === '') {
            continue;
        }
        for (j=0, fl=f.length; j < fl; j++) {
            temp = s[i]+'';
            repl = ra ? (r[j] !== undefined ? r[j] : '') : r[0];
            s[i] = (temp).split(f[j]).join(repl);
            if (count && s[i] !== temp) {
                this.window[count] += (temp.length-s[i].length)/f[j].length;}
        }
    }
    return sa ? s : s[0];
}

function add_bio_study(el, id, cv_id){
  if(is_bio_new){
    is_bio_new = false;
    bio_mode[id] = 0;
  }
  if(typeof(cv_id) == 'udefined'){
	cv_id = 0;
	}
  var ci = document.getElementById('city_id_3[text]');  
  if(!$('#dbioform1').valid()){
    return false; 
  }  
  $(el).attr('disabled', 'disabled');
    var ajaxBaseUrl = document.location.href;
    var ajaxTemp = ajaxBaseUrl.lastIndexOf("/") + 1;
    ajaxBaseUrl = ajaxBaseUrl.substring(0, ajaxTemp);
    var requestStr = ajaxBaseUrl + "index.html?__ajaxMethod=jv_add_bio_study";     
	  
    var comment_text = '';
    if (typeof(FCKeditorAPI) != 'indefined') {
      comment_text = FCKeditorAPI.GetInstance('comment').GetXHTML();
    } else {
      comment_text = $('#comment').html();
    }
    inpts = { 
              id: bio_mode[id],
              degree_type: $('#degree_type').val(),
              //degree_name: $('#degree_name').val(),              
              date_from: $('#date_from_year').val()+"-"+$('#date_from_month').val()+'-01',
              date_till: $('#date_till_year').val()+"-"+$('#date_till_month').val()+'-01',
              is_not_completed: $('#is_not_completed').attr('checked') ? 1 :0,
              degree_university: $('#degree_university').val(),
              country_id: $('#country_id_3').val(),
              city: ci.value,
              comment : comment_text,
			        cv_id: cv_id,
			        degrees: ''
            };
	tminps = $('input[id^="edit_degree_name_"]');	
	
	for(i=0;i<tminps.length;i++){
    if ($(tminps[i]).val())
	    inpts.degrees += ("##_"+$(tminps[i]).val());
	}
	
	tminps = $('input[id^="add_degree_name_"]');
	for(i=0;i<tminps.length;i++){
    if ($(tminps[i]).val())
	    inpts.degrees += ("##_"+$(tminps[i]).val());
	}
	
    $.ajax({
      async: false,
      //timeout: 3000,
      type: 'POST',
      url: requestStr,
      data: inpts,
      success: function(answ) {
        if(answ.substr(0,7)  == "correct"){
          $(el).attr('disabled', null);
          $('#subbio1').closest('form').data('thisformischanged', false);
          hide_bio_div(1);
          if(bio_mode[id] < 1){
            var iscm = $('#trn_bio_stydy_is_not_completed_no').html();
            if($('#is_not_completed').attr('checked')){
              iscm = $('#trn_bio_stydy_is_not_completed_yes').html();
            }
            var ci = document.getElementById('city_id_3[text]');
            html_text = '<li id="list1_'+answ.substr(7)+'" value="'+answ.substr(7)+'" class="ui-state-default"><div><table width="100%" cellpadding="0" cellspacing="0"><tr><td><div class="list_bio">' + str_replace('%degree_type%', $('#degree_type option:selected').text(), str_replace('%degree_name%', trim(inpts.degrees.replace(/##_/g, '; '),'; '), str_replace('%date_from%', $('#date_from_year').val()+"-"+$('#date_from_month').val(), str_replace('%date_till%', $('#date_till_year').val()+"-"+$('#date_till_month').val(), str_replace('%is_not_completed%', iscm, str_replace('%degree_university%', $('#degree_university').val(), str_replace('%country%', $('#country_id_3 option:selected').text(), str_replace('%city%', ci.value, str_replace('%comment%', comment_text ,$('#trn_bio_stydy_tpl').html())))))))))+'</div></td><td><input type="button" value="'+$('#trn_bio_edit').html()+'" class="biography_control_button" pid="1" act="edit" eid="lb1_'+answ.substr(7)+'" /><br /><input type="button" value="'+$('#trn_bio_delete').html()+'" class="biography_control_button" pid="1" act="del" /></td></tr></table></div><div id="lb1_'+answ.substr(7)+'"></div></li>';
            //$('#list1').html($('#list1').html()+'<li id="list1_'+answ.substr(7)+'" value="'+answ.substr(7)+'" class="ui-state-default">'+$('#degree_university').val()+', '+$('#degree_name').val()+', '+$('#degree_type option:selected').text()+'</li>');
            $('#list1').html($('#list1').html()+html_text);
            $("#list1").sortable({axis: 'y',containment: '#dbio1',cursor: 'default', dropOnEmpty: false, stop: function(event, ui) { change_order(1); }});
            $("#list1").disableSelection();
            set_bio_attr();
          } else { 
              var iscm = $('#trn_bio_stydy_is_not_completed_no').html();
              if($('#is_not_completed').attr('checked')){
                iscm = $('#trn_bio_stydy_is_not_completed_yes').html();
              }
               var ci = document.getElementById('city_id_3[text]');
               html_text = '<div class="list_bio">' + str_replace('%degree_type%', $('#degree_type option:selected').text(), str_replace('%degree_name%', trim(inpts.degrees.replace(/##_/g, '; '),'; '), str_replace('%date_from%', $('#date_from_year').val()+"-"+$('#date_from_month').val(), str_replace('%date_till%', $('#is_not_completed').attr('checked') ? '-' : ($('#date_till_year').val()+"-"+$('#date_till_month').val()), str_replace('%is_not_completed%', iscm, str_replace('%degree_university%', $('#degree_university').val(), str_replace('%country%', $('#country_id_3 option:selected').text(), str_replace('%city%', ci.value, str_replace('%comment%', comment_text ,$('#trn_bio_stydy_tpl').html())))))))))+'</div>';
               tds = $('#list1_'+bio_mode[id]+' div table tbody td');
               $(tds[0]).html(html_text);
               $("#list1").sortable({axis: 'y',containment: '#dbio1',cursor: 'default', dropOnEmpty: false, stop: function(event, ui) { change_order(1); }});
               $("#list1").disableSelection();
          }          
        }
        dvs = $('#list1_'+bio_mode[id]).find('div');
        if(dvs[0])
          $(dvs[0]).show();
      
        $("#list1").contents().filter(function(){ 
          return this.nodeType == 3; 
        }).remove();
        
      }
    });  
}

var added_degrees = 0;
function fill_bio_study(id, reel){

  var ajaxBaseUrl = document.location.href;
  var ajaxTemp = ajaxBaseUrl.lastIndexOf("/") + 1;
  ajaxBaseUrl = ajaxBaseUrl.substring(0, ajaxTemp);
  var requestStr = ajaxBaseUrl + "?__jsoxMethod=jv_get_bio_study&__jsoxParam[0]="+$('#list1_value').val()+"&__jsoxParam[1]=bio_study&__jsoxParam[2]=";         
  $.getJSON(requestStr,{}, function(j){
    if (!j) {
      simple_alert($("#trn_try_later").text());
      return;
    }
    $("#list1").sortable( 'destroy' );  
    $("#list1").attr('unselectable', 'off').css('MozUserSelect', '').unbind('selectstart.ui');
    added_degrees = 0;
    currFCKId = 'comment';
    if((j.comment == null) || (typeof(j.comment) == 'undefined') || (j.comment == 'null') || (j.comment == '')) {
      currFCKValue = '';
    } else {
      currFCKValue = j.comment;
    }
    //alert('first');
    
	   $('#subbio'+id).prependTo('#'+reel);
	   
	   $('#subbio'+id).show(); 
       $('#dbio'+id+' .biography_control_button').attr('disabled', 'disabled');
       $('#subbio'+id+' .biography_control_button').attr('disabled', null);

       $('#degree_type').val(j.degree_type_id);
       $('#degree_name').val('');
       $('#date_from_month').val(j.from.month);
       $('#date_from_day').val(j.from.day);
       $('#date_from_year').val(j.from.year);
       $('#date_till_month').val(j.till.month);
       $('#date_till_day').val(j.till.day);
       $('#date_till_year').val(j.till.year);
       if(j.is_not_completed == '1'){
         $('#is_not_completed').attr('checked', 'checked');
         $('label[for="is_not_completed"]').addClass("checked");
		     //$('.ongoing2').hide();
		     $('#date_till_month').removeClass('positiveDatesStudy');
       } else {
         $('#is_not_completed').attr('checked', false);
         $('label[for="is_not_completed"]').removeClass("checked");
		     //$('.ongoing2').show();
		     $('#date_till_month').addClass('positiveDatesStudy');
       }
       $('#degree_university').val(j.degree_university);
       $('#country_id_3').val(j.country_id);	   
	   
     SetMultiInput(j.degree_names, 'degree_name');
	   dvs = $('#'+reel).parent().find('div');
	   $(dvs[0]).hide();	   
	   
       var ci = document.getElementById('city_id_3[text]');
       ci.value = j.city_name;       

      if (typeof(FCKeditorAPI) != 'undefined') {
        if (FCKeditorAPI.GetInstance('comment')) {
          FCKeditorAPI.GetInstance('comment').SetHTML(currFCKValue.toString());
        }
      } else {
        $('#comment').html(currFCKValue.toString());
      }            
		});
}

function SetMultiInput(values, mulifield_name) {
  
  ret = false;
  eval('if(typeof(mf_tpl_'+mulifield_name+')=="undefined") ret=true;');
  if(ret) return false;
  
  add_html = '';
  //if (typeof('mf_tpl_'+mulifield_name) == 'undefined') return false;
  if (typeof(values)=='object'&&(values instanceof Array)) {
    
    for(var i in values) {
      if(typeof(values[i].id) != 'undefined') {    
        if((values[i].name != 'null')&&(values[i].name != null)){
          input = eval('mf_tpl_'+mulifield_name);
          add_html += str_replace(["|value|", "|action|", "|iteration|"], [values[i].name, "edit", values[i].id], input);
        }
      }
    }
  }

  $('#' + mulifield_name + 's_mfbox').html('');
  if (add_html.length > 0) {
    $('#' + mulifield_name + 's_mfbox').html(add_html);
  } else {
    input = eval('mf_tpl_'+mulifield_name);
    input = str_replace(["|value|", "|action|", "|iteration|"], ["", "add", added_degrees], input);
    $('#' + mulifield_name + 's_mfbox').html(input);
  }
  
}

function AddMultiInput(previous_element, mulifield_name){

  added_degrees++;
  //alert('mf_tpl_'+mulifield_name+' - '+typeof('mf_tpl_'+mulifield_name));
  var good_res = false;
  eval("if (typeof(mf_tpl_"+mulifield_name+") != 'undefined') good_res=true ");
  if (good_res) {
    input = eval('mf_tpl_'+mulifield_name);
    input = str_replace(["|value|", "|action|", "|iteration|"], ["", "add", added_degrees], input);
    if (previous_element.length) {
      $('#'+previous_element).after(input);
    } else {
      $('#'+mulifield_name+'s_mfbox').append(input);
    }
  }
}

function DelMultiInput(id, mulifield_name){

  size = $('div#'+id).parent().children().size();
  if (size > 1) {
    $('div#'+id).remove();
  } else {
    $('div#'+id+' input').val('');
  }
  
}

function changeFCKValue(){
  if (typeof(FCKeditorAPI.GetInstance(currFCKId)) != 'undefined')
    FCKeditorAPI.GetInstance(currFCKId).SetHTML(currFCKValue, true);
}

/*
function DeleteAddedDegree(id){
	$('#degree_div_'+id).remove();	  
}
function DeleteEditedDegree(id){
	$('#edit_div_'+id).remove();	  
}
function AddDegreeNameInput(){
  if($('#degree_name').val().length > 0){
    added_degrees++;
    $('#degree_names').append('<div id="degree_div_'+added_degrees+'"><input value="'+$('#degree_name').val()+'" id="add_degree_name_'+added_degrees+'"><img src="'+base_url+'resources/minus.gif" class="finger" onclick="DeleteAddedDegree('+added_degrees+')" /></div>');
	$('#degree_name').val('');
  }
}
*/

function add_bio_job(el, id, cv_id){
  if(is_bio_new){
    is_bio_new = false;
    bio_mode[id] = 0;
  }
  if(typeof(cv_id) == 'udefined'){
	cv_id = 0;
	}
  var ci = document.getElementById('city_id_2[text]');  
  if(!$('#dbioform2').valid()){
    return false; 
  }
  $(el).attr('disabled', 'disabled');
    var ajaxBaseUrl = document.location.href;
    var ajaxTemp = ajaxBaseUrl.lastIndexOf("/") + 1;
    ajaxBaseUrl = ajaxBaseUrl.substring(0, ajaxTemp);
    var requestStr = ajaxBaseUrl + "index.html?__ajaxMethod=jv_add_bio_job";
    
    var comment_text = '';
    if (typeof(FCKeditorAPI) != 'indefined') {
      comment_text = FCKeditorAPI.GetInstance('comment_2').GetXHTML();
    } else {
      comment_text = $('#comment_2').html();
    }
     
    inpts = { 
              id: bio_mode[id],
              position: $('#position').val(),
              company_name: $('#company_name').val(),
              workscope_id: $('#workscope_id').val(),
              country_id: $('#country_id_2').val(),
              city: ci.value,              
              date_from: $('#date_from_2_year').val()+"-"+$('#date_from_2_month').val()+"-01",
              date_till: $('#date_till_2_year').val()+"-"+$('#date_till_2_month').val()+"-01",
              skills: '',
			        flag_ongoing: $('#flag_ongoing').attr('checked') ? 1 :0,
              comment : comment_text,
			        cv_id: cv_id			  
            };
	tminps = $('input[id^="edit_skill_"]');	
	
	for(i=0;i<tminps.length;i++){
    if ($(tminps[i]).val())
	    inpts.skills += ("##_"+$(tminps[i]).val());
	}
	
	tminps = $('input[id^="add_skill_"]');
	for(i=0;i<tminps.length;i++){
    if ($(tminps[i]).val())
	    inpts.skills += ("##_"+$(tminps[i]).val());
	}
    $.ajax({
      async: false,
      //timeout: 3000,
      type: 'POST',
      url: requestStr,
      data: inpts,
      success: function(answ) {
        if(answ.substr(0,7)  == "correct"){
          $(el).attr('disabled', null);          
          $('#subbio2').closest('form').data('thisformischanged', false);
          hide_bio_div(2);
          if(bio_mode[id] < 1){
		  var ci = document.getElementById('city_id_2[text]');  
		  //pls_w
		  html_text = '<li id="list2_'+answ.substr(7)+'" value="'+answ.substr(7)+'" class="ui-state-default"><div><table width="100%" cellpadding="0" cellspacing="0"><tr><td><div class="list_bio">'+ str_replace('%position%', $('#position').val(),str_replace('%company_name%', $('#company_name').val(),str_replace('%workscope%', $('#workscope_id option:selected').text(),str_replace('%country%', $('#country_id_2 option:selected').text(),str_replace('%city%', ci.value,str_replace('%date_from%', $('#date_from_2_year').val()+"-"+$('#date_from_2_month').val(),str_replace('%date_till%', $('#date_till_2_year').val()+"-"+$('#date_till_2_month').val(),str_replace('%skills%', trim(inpts.skills.replace(/##_/g, '; '),'; '),str_replace('%comment%', comment_text , $('#trn_bio_job_tpl').html())))))))))+'</div></td><td><input type="button" value="'+$('#trn_bio_edit').html()+'" class="biography_control_button" pid="2" eid="lb2_'+answ.substr(7)+'" act="edit" /><br /><input type="button" value="'+$('#trn_bio_delete').html()+'" class="biography_control_button" pid="2" act="del" /></td></tr></table></div><div id="lb2_'+answ.substr(7)+'"></div></li>';
			  //$('#list2').html($('#list2').html()+'<li id="list2_'+answ.substr(7)+'" value="'+answ.substr(7)+'" class="ui-state-default">'+$('#company_name').val()+', '+$('#position').val()+'</li>');
			  $('#list2').html($('#list2').html()+html_text);
			  $("#list2").sortable({axis: 'y',containment: '#dbio2',cursor: 'default', dropOnEmpty: false, stop: function(event, ui) { change_order(2); }});
			  $("#list2").disableSelection();
   			  set_bio_attr();			  
          } else {
		  var ci = document.getElementById('city_id_2[text]');		  
           html_text = '<div class="list_bio">'+ str_replace('%position%', $('#position').val(),str_replace('%company_name%', $('#company_name').val(),str_replace('%workscope%', $('#workscope_id option:selected').text(),str_replace('%country%', $('#country_id_2 option:selected').text(),str_replace('%city%', ci.value,str_replace('%date_from%', $('#date_from_2_year').val()+"-"+$('#date_from_2_month').val(),str_replace('%date_till%', $('#date_till_2_year').val()+"-"+$('#date_till_2_month').val(),str_replace('%skills%', trim(inpts.skills.replace(/##_/g, '; '), '; '),str_replace('%comment%', comment_text , $('#trn_bio_job_tpl').html())))))))))+'</div>';
		   
		   tds = $('#list2_'+bio_mode[id]+' div table tbody td');
		   
		   $(tds[0]).html(html_text);					  
		   $("#list2").sortable({axis: 'y',containment: '#dbio2',cursor: 'default', dropOnEmpty: false, stop: function(event, ui) { change_order(2); }});
			  $("#list2").disableSelection();
			//  $('#list2_'+bio_mode[id]).html($('#company_name').val()+', '+$('#position').val());					  
            //ADD/CHANGE LI $('#list2 option[@value='+bio_mode[id]+']').text($('#company_name').val()+','+$('#position').val());                                     
          }          
        }
		    dvs = $('#list1_'+bio_mode[id]).find('div');
        if(dvs[0])
          $(dvs[0]).show();
      
        $("#list2").contents().filter(function(){ 
          return this.nodeType == 3; 
        }).remove();
        
      }
    });
}

function trim (str, charlist) {
    var whitespace, l = 0, i = 0;
    str += '';    
    if (!charlist) {        
        whitespace = " \n\r\t\f\x0b\xa0\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a\u200b\u2028\u2029\u3000";
    } else {        
        charlist += '';
        whitespace = charlist.replace(/([\[\]\(\)\.\?\/\*\{\}\+\$\^\:])/g, '$1');
    }    
    l = str.length;
    for (i = 0; i < l; i++) {
        if (whitespace.indexOf(str.charAt(i)) === -1) {
            str = str.substring(i);
            break;
        }
    }
    
    l = str.length;
    for (i = l - 1; i >= 0; i--) {
        if (whitespace.indexOf(str.charAt(i)) === -1) {
            str = str.substring(0, i + 1);
            break;
        }
    }    
    return whitespace.indexOf(str.charAt(0)) === -1 ? str : '';
}

var added_skills = 0;
function fill_bio_job(id, reel){
  var ajaxBaseUrl = document.location.href;
  var ajaxTemp = ajaxBaseUrl.lastIndexOf("/") + 1;
  ajaxBaseUrl = ajaxBaseUrl.substring(0, ajaxTemp);
  var requestStr = ajaxBaseUrl + "?__jsoxMethod=jv_get_bio_job&__jsoxParam[0]="+$('#list2_value').val()+"&__jsoxParam[1]=bio_job&__jsoxParam[2]=";         
  $.getJSON(requestStr,{}, function(j){   
    if (!j) {
      simple_alert($("#trn_try_later").text());
      return;
    }
    $("#list2").sortable( 'destroy' );  
    $("#list2").attr('unselectable', 'off').css('MozUserSelect', '').unbind('selectstart.ui');
    currFCKId = 'comment_2';
    if((j.comment == null) || (typeof(j.comment) == 'undefined') || (j.comment == 'null') || (j.comment == '')) {
      currFCKValue = '';
    } else {
      currFCKValue = j.comment;
    }
//    alert('first');
    
    $('#subbio'+id).prependTo('#'+reel);
    $('#subbio'+id).show(); 
    added_skills = 0;
    $('#dbio'+id+' .biography_control_button').attr('disabled', 'disabled');
    $('#subbio'+id+' .biography_control_button').attr('disabled', null);

    $('#position').val(j.position || '');
	   
	  if(j.flag_ongoing == '1'){
        $('#flag_ongoing').attr('checked', 'checked');
		    $('.ongoing').hide();
		    $('#date_till_2_month').removeClass('positiveDatesStudy');
    } else {
        $('#flag_ongoing').attr('checked', null);
		    $('.ongoing').show();
		    $('#date_till_2_month').addClass('positiveDatesStudy');
    }
    $('#company_name').val(j.company_name || '');
    $('#workscope_id').val(j.workscope_id);
    $('#date_from_2_month').val(j.from.month);
    $('#date_from_2_day').val(j.from.day);
    $('#date_from_2_year').val(j.from.year);
    $('#date_till_2_month').val(j.till.month);
    $('#date_till_2_day').val(j.till.day);
    $('#date_till_2_year').val(j.till.year);
    $('#country_id_2').val(j.country_id);
    var ci = document.getElementById('city_id_2[text]');
    ci.value = j.city_name || '';

    dvs = $('#'+reel).parent().find('div');
    $(dvs[0]).hide();

    if (typeof(FCKeditorAPI) != 'undefined') {
      if (FCKeditorAPI.GetInstance('comment_2')) {
        FCKeditorAPI.GetInstance('comment_2').SetHTML(currFCKValue.toString());
      }
    } else {
      $('#comment_2').html(currFCKValue.toString());
    }      
  });
}

/*
function DeleteAddedSkill(id){
	$('#skill_div_'+id).remove();	  
}
function DeleteEditedSkill(id){
	$('#edit_skill_div_'+id).remove();	  
}
function AddSkillInput(){
  if($('#skills').val().length > 0){  
    added_skills++;
    $('#skillss').append('<div id="skill_div_'+added_skills+'"><input value="'+$('#skills').val()+'" id="add_skill_'+added_skills+'"><img src="'+base_url+'resources/minus.gif" class="finger" onclick="DeleteAddedSkill('+added_skills+')" /></div>');
	$('#skills').val('');
  }
}
*/

function add_bio_hobby(el, id, cv_id){  
  if(is_bio_new){
    is_bio_new = false;
    bio_mode[id] = 0;
  }
  if(typeof(cv_id) == 'udefined'){
	cv_id = 0;
	}
  if(!$('#dbioform4').valid()){
    return false; 
  }  
  $(el).attr('disabled', 'disabled');
    var ajaxBaseUrl = document.location.href;
    var ajaxTemp = ajaxBaseUrl.lastIndexOf("/") + 1;
    ajaxBaseUrl = ajaxBaseUrl.substring(0, ajaxTemp);
    var requestStr = ajaxBaseUrl + "index.html?__ajaxMethod=jv_add_bio_hobby";
         
    $.ajax({
      async: false,
      //timeout: 3000,
      type: 'POST',
      url: requestStr,
      data: { 
              id: bio_mode[id],
              hobby: $('#hobby').val(),
			  cv_id: cv_id
              },
      success: function(answ) {
        if(answ.substr(0,7)  == "correct"){
          $(el).attr('disabled', null);          
          $('#subbio4').closest('form').data('thisformischanged', false);
          hide_bio_div(4);
          if(bio_mode[id] < 1){
              //ADD/CHANGE LI $('#list4').html($('#list4').html()+'<option value="'+answ.substr(7)+'">'+$('#hobby').val()+'</option>');              
			  html_text = '<li id="list4_'+answ.substr(7)+'" value="'+answ.substr(7)+'" class="ui-state-default"><div><table width="100%" cellpadding="0" cellspacing="0"><tr><td><div class="list_bio">'+$('#hobby').val()+'</div></td><td><input type="button" value="'+$('#trn_bio_edit').html()+'" class="biography_control_button" pid="4" eid="lb4_'+answ.substr(7)+'" act="edit" /><br /><input type="button" value="'+$('#trn_bio_delete').html()+'" class="biography_control_button" pid="4" act="del" /></td></tr></table></div><div id="lb4_'+answ.substr(7)+'"></div></li>';

			  $('#list4').html($('#list4').html()+html_text);
			  $("#list4").sortable({axis: 'y',containment: '#dbio4',cursor: 'default', dropOnEmpty: false, stop: function(event, ui) { change_order(4); }});
			  $("#list4").disableSelection();
   			  set_bio_attr();	
          } else {    
		     html_text = '<div class="list_bio">'+$('#hobby').val()+'</div>';
		     tds = $('#list4_'+bio_mode[id]+' div table tbody td');		   
		     $(tds[0]).html(html_text);	
         $("#list4").sortable({axis: 'y',containment: '#dbio4',cursor: 'default', dropOnEmpty: false, stop: function(event, ui) { change_order(4); }});
         $("#list4").disableSelection();
		    //$('#list4_'+bio_mode[id]).html($('#hobby').val());	
          //ADD/CHANGE LI   $('#list4 option[@value='+bio_mode[id]+']').text($('#hobby').val());                                     
          }          
        }
		    dvs = $('#list1_'+bio_mode[id]).find('div');
        if(dvs[0])
          $(dvs[0]).show();

        $("#list4").contents().filter(function(){ 
          return this.nodeType == 3; 
        }).remove();
        
        }
    });
}


function fill_bio_hobby(id, reel){
  var ajaxBaseUrl = document.location.href;
  var ajaxTemp = ajaxBaseUrl.lastIndexOf("/") + 1;
  ajaxBaseUrl = ajaxBaseUrl.substring(0, ajaxTemp);
  var requestStr = ajaxBaseUrl + "?__jsoxMethod=jv_get_bio_hobby&__jsoxParam[0]="+$('#list4_value').val()+"&__jsoxParam[1]=bio_hobby&__jsoxParam[2]=";       
  $('#subbio'+id).prependTo('#'+reel);
  $.getJSON(requestStr,{}, function(j){
    if (!j) {
      simple_alert($("#trn_try_later").text());
      return;
    }
     $("#list4").sortable( 'destroy' );  
     $("#list4").attr('unselectable', 'off').css('MozUserSelect', '').unbind('selectstart.ui');
	   $('#subbio'+id).show(); 
	   dvs = $('#'+reel).parent().find('div');
	   $(dvs[0]).hide();
       $('#dbio'+id+' .biography_control_button').attr('disabled', 'disabled');
       $('#subbio'+id+' .biography_control_button').attr('disabled', null);

       $('#hobby').val(j.hobby);       
		});
}


function add_bio_literature(el, id, cv_id){  
  if(is_bio_new){
    is_bio_new = false;
    bio_mode[id] = 0;
  }
  if(typeof(cv_id) == 'udefined'){
	cv_id = 0;
	}
  
  var comment_text = '';
  if (typeof(FCKeditorAPI) != 'indefined') {
    comment_text = FCKeditorAPI.GetInstance('literature').GetXHTML();
  } else {
    comment_text = $('#literature').html();
  }

  $('#literature').val(comment_text);
  if(!$('#dbioform6').valid()){
    return false; 
  }  
  $(el).attr('disabled', 'disabled');
    var ajaxBaseUrl = document.location.href;
    var ajaxTemp = ajaxBaseUrl.lastIndexOf("/") + 1;
    ajaxBaseUrl = ajaxBaseUrl.substring(0, ajaxTemp);
    var requestStr = ajaxBaseUrl + "index.html?__ajaxMethod=jv_add_bio_literature";
         
    $.ajax({
      async: false,
      //timeout: 3000,
      type: 'POST',
      url: requestStr,
      data: { 
              id: bio_mode[id],
              literature: comment_text,
			  cv_id: cv_id
              },
      success: function(answ) {
        if(answ.substr(0,7)  == "correct"){
        
          $(el).attr('disabled', null);          
        
          $('#subbio6').closest('form').data('thisformischanged', false);
          hide_bio_div(6);
        
          vl = split("#|x", answ);
          if(bio_mode[id] < 1){  
              html_text = '<li id="list6_'+vl[2]+'" value="'+vl[2]+'" class="ui-state-default"><div><table width="100%" cellpadding="0" cellspacing="0"><tr><td><div class="list_bio">'+vl[1]+'</div></td><td><input type="button" value="'+$('#trn_bio_edit').html()+'" class="biography_control_button" eid="lb6_'+vl[2]+'" pid="6" act="edit" /><br /><input type="button" value="'+$('#trn_bio_delete').html()+'" class="biography_control_button" pid="6" act="del" /></td></tr></table></div><div id="lb6_'+vl[2]+'"></div></li>';
			  //$('#list5').html($('#list5').html()+'<li id="list5_'+answ.substr(7)+'" value="'+answ.substr(7)+'" class="ui-state-default">'+$('#language_id option:selected').text()+'</li>');
			  $('#list6').html($('#list6').html()+html_text);		  
              //ADD/CHANGE LI $('#list6').html($('#list6').html()+'<option value="'+vl[0].substr(7)+'">'+vl[1]+'</option>');              
			  //$('#list6').html($('#list6').html()+'<li id="list6_'+vl[0].substr(7)+'" value="'+vl[0].substr(7)+'" class="ui-state-default">'+vl[1]+'</li>');
			  
			  
			  $("#list6").sortable({axis: 'y',containment: '#dbio6',cursor: 'default', dropOnEmpty: false, stop: function(event, ui) { change_order(6); }});
			  $("#list6").disableSelection();
   			  set_bio_attr();
          } else { 		  
            //ADD/CHANGE LI $('#list6 option[@value='+bio_mode[id]+']').text(vl[1]);                                     			
			html_text = '<div class="list_bio">'+vl[1]+'</div>';
		    tds = $('#list6_'+bio_mode[id]+' div table tbody td');		   
		    $(tds[0]).html(html_text);
        $("#list6").sortable({axis: 'y',containment: '#dbio6',cursor: 'default', dropOnEmpty: false, stop: function(event, ui) { change_order(6); }});
			  $("#list6").disableSelection();
        
			//$('#list6_'+bio_mode[id]).html(vl[1]);	
          }          
        }
      dvs = $('#list1_'+bio_mode[id]).find('div');
      if(dvs[0])
        $(dvs[0]).show();
      
        $("#list6").contents().filter(function(){ 
          return this.nodeType == 3; 
        }).remove();

      }
    });
}


function fill_bio_literature(id, reel){

  var ajaxBaseUrl = document.location.href;
  var ajaxTemp = ajaxBaseUrl.lastIndexOf("/") + 1;
  ajaxBaseUrl = ajaxBaseUrl.substring(0, ajaxTemp);
  var requestStr = ajaxBaseUrl + "?__jsoxMethod=jv_get_bio_literature&__jsoxParam[0]="+$('#list6_value').val()+"&__jsoxParam[1]=bio_literature&__jsoxParam[2]=";         
  $.getJSON(requestStr,{}, function(j){
    if (!j) {
      simple_alert($("#trn_try_later").text());
      return;
    }
     $("#list6").sortable( 'destroy' );
     $("#list6").attr('unselectable', 'off').css('MozUserSelect', '').unbind('selectstart.ui');
       currFCKId = 'literature';
      if((j.literature == null) || (typeof(j.literature) == 'undefined') || (j.literature == 'null') || (j.literature == '')) {
        currFCKValue = '';
      } else {
        currFCKValue = j.literature;
      }
    //alert('first');
    
	   $('#subbio'+id).prependTo('#'+reel);
	   
	   $('#subbio'+id).show(); 	   
	   dvs = $('#'+reel).parent().find('div');
	   $(dvs[0]).hide();
       $('#dbio'+id+' .biography_control_button').attr('disabled', 'disabled');
       $('#subbio'+id+' .biography_control_button').attr('disabled', null);
       

      if (typeof(FCKeditorAPI) != 'undefined') {
        if (FCKeditorAPI.GetInstance('literature')) {
          FCKeditorAPI.GetInstance('literature').SetHTML(currFCKValue.toString());
        }
      } else {
        $('#literature').html(currFCKValue.toString());
      }      
            
		});
}





function add_bio_expertise(el, id, cv_id){  
  if(is_bio_new){
    is_bio_new = false;
    bio_mode[id] = 0;
  }
  if(typeof(cv_id) == 'udefined'){
	cv_id = 0;
	}
  if(!$('#dbioform3').valid()){
    return false; 
  }  
  $(el).attr('disabled', 'disabled');
    var ajaxBaseUrl = document.location.href;
    var ajaxTemp = ajaxBaseUrl.lastIndexOf("/") + 1;
    ajaxBaseUrl = ajaxBaseUrl.substring(0, ajaxTemp);
    var requestStr = ajaxBaseUrl + "index.html?__ajaxMethod=jv_add_bio_expertise";
         
    var comment_text = '';
    if (typeof(FCKeditorAPI) != 'indefined') {
      comment_text = FCKeditorAPI.GetInstance('comment_3').GetXHTML();
    } else {
      comment_text = $('#comment_3').html();
    }
    $.ajax({
      async: false,
      //timeout: 3000,
      type: 'POST',
      url: requestStr,
      data: { 
              id: bio_mode[id],
              qualification_name: $('#qualification_name').val(),
          	  qualification_type_id: $('#qualification_type_id').val(),
          	  date_from: $('#date_from_3_year').val()+"-"+$('#date_from_3_month').val()+"-"+$('#date_from_3_day').val(),
          	  organization_name: $('#organization_name').val(),
          	  comment : comment_text,
			  cv_id: cv_id
          	  //comment : $('#comment_3').val()
              },
      success: function(answ) {
        if(answ.substr(0,7)  == "correct"){
          $(el).attr('disabled', null);          
          $('#subbio3').closest('form').data('thisformischanged', false);
          hide_bio_div(3);
          if(bio_mode[id] < 1){
              //ADD/CHANGE LI $('#list3').html($('#list3').html()+'<option value="'+answ.substr(7)+'">'+$('#qualification_name').val()+','+$('#organization_name').val()+'</option>');              			  
			  html_text = '<li id="list3_'+answ.substr(7)+'" value="'+answ.substr(7)+'" class="ui-state-default"><div><table width="100%" cellpadding="0" cellspacing="0"><tr><td><div class="list_bio">'+str_replace('%qualification_name%', $('#qualification_name').val(),str_replace('%qualification_type%', $('#qualification_type_id option:selected').text(),str_replace('%date_from%', $('#date_from_3_year').val()+"-"+$('#date_from_3_month').val()+"-"+$('#date_from_3_day').val(),str_replace('%organization_name%', $('#organization_name').val(),str_replace('%comment%', comment_text ,$('#trn_bio_expertise_tpl').html())))))+'</div></td><td><input type="button" value="'+$('#trn_bio_edit').html()+'" class="biography_control_button" eid="lb3_'+answ.substr(7)+'" pid="3" act="edit" /><br /><input type="button" value="'+$('#trn_bio_delete').html()+'" class="biography_control_button" pid="3" act="del" /></td></tr></table></div><div id="lb3_'+answ.substr(7)+'"></div></li>';
			  $('#list3').html($('#list3').html()+html_text);
			  
			  //$('#list3').html($('#list3').html()+'<li id="list3_'+answ.substr(7)+'" value="'+answ.substr(7)+'" class="ui-state-default">'+$('#qualification_name').val()+', '+$('#organization_name').val()+'</li>');
			  $("#list3").sortable({axis: 'y',containment: '#dbio3',cursor: 'default', dropOnEmpty: false, stop: function(event, ui) { change_order(3); }});
			  $("#list3").disableSelection();
   			  set_bio_attr();	
          } else {             
          //ADD/CHANGE LI   $('#list3 option[@value='+bio_mode[id]+']').text(         $('#qualification_name').val()+','+$('#organization_name').val()            );                                     
		  html_text = '<div class="list_bio">'+str_replace('%qualification_name%', $('#qualification_name').val(),str_replace('%qualification_type%', $('#qualification_type_id option:selected').text(),str_replace('%date_from%', $('#date_from_3_year').val()+"-"+$('#date_from_3_month').val()+"-"+$('#date_from_3_day').val(),str_replace('%organization_name%', $('#organization_name').val(),str_replace('%comment%', comment_text ,$('#trn_bio_expertise_tpl').html())))))+'</div>';
		  tds = $('#list3_'+bio_mode[id]+' div table tbody td');		   
		  $(tds[0]).html(html_text);
      $("#list3").sortable({axis: 'y',containment: '#dbio3',cursor: 'default', dropOnEmpty: false, stop: function(event, ui) { change_order(3); }});
			$("#list3").disableSelection();
		  //$('#list3_'+bio_mode[id]).html($('#qualification_name').val()+', '+$('#organization_name').val());	
          }          
        }
		dvs = $('#list1_'+bio_mode[id]).find('div');
      if(dvs[0])
        $(dvs[0]).show();

        $("#list3").contents().filter(function(){ 
          return this.nodeType == 3; 
        }).remove();
        
      }	  
    });
}


function fill_bio_expertise(id, reel){
  var ajaxBaseUrl = document.location.href;
  var ajaxTemp = ajaxBaseUrl.lastIndexOf("/") + 1;
  ajaxBaseUrl = ajaxBaseUrl.substring(0, ajaxTemp);
  var requestStr = ajaxBaseUrl + "?__jsoxMethod=jv_get_bio_expertise&__jsoxParam[0]="+$('#list3_value').val()+"&__jsoxParam[1]=bio_expertise&__jsoxParam[2]=";       
  
  $.getJSON(requestStr,{}, function(j){  
    if (!j) {
      simple_alert($("#trn_try_later").text());
      return;
    }
    $("#list3").sortable( 'destroy' );
    $("#list3").attr('unselectable', 'off').css('MozUserSelect', '').unbind('selectstart.ui');
       currFCKId = 'comment_3';
    if((j.comment == null) || (typeof(j.comment) == 'undefined') || (j.comment == 'null') || (j.comment == '')) {
      currFCKValue = '';
    } else {
      currFCKValue = j.comment;
    }
    //alert('first');
    
	   $('#subbio'+id).prependTo('#'+reel);
  
	   $('#subbio'+id).show(); 
	   dvs = $('#'+reel).parent().find('div');
	   $(dvs[0]).hide();
       $('#dbio'+id+' .biography_control_button').attr('disabled', 'disabled');
       $('#subbio'+id+' .biography_control_button').attr('disabled', null);

       $('#qualification_name').val(j.qualification_name || '');
       $('#qualification_type_id').val(j.qualification_type_id);
       $('#organization_name').val(j.organization_name || '');
       $('#date_from_3_month').val(j.from.month);
       $('#date_from_3_day').val(j.from.day);
       $('#date_from_3_year').val(j.from.year);       

      if (typeof(FCKeditorAPI) != 'undefined') {
        if (FCKeditorAPI.GetInstance('comment_3')) {
          FCKeditorAPI.GetInstance('comment_3').SetHTML(currFCKValue.toString());
        }
      } else {
        $('#comment_3').html(currFCKValue.toString());
      }            
        
		});
}

function add_bio_language(el, id, cv_id){  
  if(is_bio_new){
    is_bio_new = false;
    bio_mode[id] = 0;
  }
  if(typeof(cv_id) == 'udefined'){
	cv_id = 0;
	}
  if(!$('#dbioform5').valid()){
    return false; 
  }  
  $(el).attr('disabled', 'disabled');
    var ajaxBaseUrl = document.location.href;
    var ajaxTemp = ajaxBaseUrl.lastIndexOf("/") + 1;
    ajaxBaseUrl = ajaxBaseUrl.substring(0, ajaxTemp);
    var requestStr = ajaxBaseUrl + "index.html?__ajaxMethod=jv_add_bio_language";
         
    $.ajax({
      async: false,
      //timeout: 3000,
      type: 'POST',
      url: requestStr,
      data: { 
              id: bio_mode[id],
              language_id: $('#language_id').val(),
          	  knowledge_id: $('#srtr'+$('#language_knowledge_id').val()).attr('enid'),
			  cv_id: cv_id
              },
      success: function(answ) {
        if(answ.substr(0,7)  == "correct"){
          $(el).attr('disabled', null);
          $('#subbio5').closest('form').data('thisformischanged', false);
          hide_bio_div(5);
          $('#language_id').attr('disabled', null);              
          if(bio_mode[id] < 2){
              //ADD/CHANGE LI $('#list5').html($('#list5').html()+'<option value="'+answ.substr(7)+'">'+$('#language_id option:selected').text()+'</option>');   //language_knowledge_id           
			  html_text = '<li id="list5_'+answ.substr(7)+'" value="'+answ.substr(7)+'" class="ui-state-default"><div><table width="100%" cellpadding="0" cellspacing="0"><tr><td><div class="list_bio"><b>'+$('#language_id option:selected').text()+':</b> '+$('#srtr'+$('#language_knowledge_id').val()).attr('value')+'</div></td><td><input type="button" value="'+$('#trn_bio_edit').html()+'" class="biography_control_button" pid="5" eid="lb5_'+answ.substr(7)+'" act="edit" /><br /><input type="button" value="'+$('#trn_bio_delete').html()+'" class="biography_control_button" pid="5" act="del" /></td></tr></table></div><div id="lb5_'+answ.substr(7)+'"></div></li>';
			  //$('#list5').html($('#list5').html()+'<li id="list5_'+answ.substr(7)+'" value="'+answ.substr(7)+'" class="ui-state-default">'+$('#language_id option:selected').text()+'</li>');
			  $('#list5').html($('#list5').html()+html_text);
			  $("#list5").sortable({axis: 'y',containment: '#dbio5',cursor: 'default', dropOnEmpty: false, stop: function(event, ui) { change_order(5); }});
			  $("#list5").disableSelection();
   			  set_bio_attr();	
          } else {            
            //ADD/CHANGE LI $('#list5 option[@value='+bio_mode[id]+']').text($('#language_id option:selected').text());
            html_text = '<b>'+$('#language_id option:selected').text()+':</b> '+$('#srtr'+$('#language_knowledge_id').val()).attr('value');
            $('#list5_'+bio_mode[id]+' .list_bio').html(html_text);	
            $("#list5").sortable({axis: 'y',containment: '#dbio5',cursor: 'default', dropOnEmpty: false, stop: function(event, ui) { change_order(5); }});
            $("#list5").disableSelection();
          }          
        } else {
            if(answ == "changed"){
              $(el).attr('disabled', null);          
              hide_bio_div(5); 
			  html_text = '<div class="list_bio"><b>'+$('#language_id option:selected').text()+':</b> '+$('#srtr'+$('#language_knowledge_id').val()).attr('value')+'</div>';
		      tds = $('#list5_'+bio_mode[id]+' div table tbody td');		   
		      $(tds[0]).html(html_text);
              $('#language_id').attr('disabled', null);              
            }
        }
		dvs = $('#list1_'+bio_mode[id]).find('div');
      if(dvs[0])
        $(dvs[0]).show();
      
        $("#list5").contents().filter(function(){ 
          return this.nodeType == 3; 
        }).remove();
        
      }
    });
    return false;
}


function fill_bio_language(id, reel){
  $('#language_id').attr('disabled', null);              
  var ajaxBaseUrl = document.location.href;
  var ajaxTemp = ajaxBaseUrl.lastIndexOf("/") + 1;
  ajaxBaseUrl = ajaxBaseUrl.substring(0, ajaxTemp);
  var requestStr = ajaxBaseUrl + "?__jsoxMethod=jv_get_bio_language&__jsoxParam[0]="+$('#list5_value').val()+"&__jsoxParam[1]=bio_language&__jsoxParam[2]=";       
  $('#subbio'+id).prependTo('#'+reel);
  $.getJSON(requestStr,{}, function(j){  
    if (!j) {
      simple_alert($("#trn_try_later").text());
      return;
    }
    $("#list5").sortable( 'destroy' );
    $("#list5").attr('unselectable', 'off').css('MozUserSelect', '').unbind('selectstart.ui');
	   $('#subbio'+id).show(); 
	   dvs = $('#'+reel).parent().find('div');
	   $(dvs[0]).hide();
       $('#dbio'+id+' .biography_control_button').attr('disabled', 'disabled');
       $('#subbio'+id+' .biography_control_button').attr('disabled', null);
	   document.getElementById('language_id').value = j.language_id;

       for(var i=0;i<5;i++){
         if(lag_know[i] == j.knowledge_id){
           $('#language_knowledge_id').val(i+1);
           set_stars_move(i+1);
         }
       }
		});
}

function delete_bio_row(id){

  if(bio_mode[id] > 0){
    simple_confirm($('#confirm_del_dio').html(), function(){
      var ajaxBaseUrl = document.location.href;
      var ajaxTemp = ajaxBaseUrl.lastIndexOf("/") + 1;
      ajaxBaseUrl = ajaxBaseUrl.substring(0, ajaxTemp);
      var requestStr = ajaxBaseUrl + "index.html?__ajaxMethod=jv_delete_bio_element";
      $('#list'+id).attr('disabled', 'disabled');
      $.ajax({
        async: false,
        //timeout: 3000,
        type: 'POST',
        url: requestStr,
        data: { 
                id: bio_mode[id],
                window_id: id
                },
        success: function(answ) {
          if(answ == "correct"){
		    //DEL!!! LI 
            //$('#list'+id+' option:selected').remove();
			$('#list'+id+'_'+bio_mode[id]).remove();
            $('#list'+id).attr('disabled', null);
          }
        }
      });
    });
  }
}

function explode( delimiter, string, limit ) {
 
    var emptyArray = { 0: '' };
    

    if ( arguments.length < 2 ||
        typeof arguments[0] == 'undefined' ||
        typeof arguments[1] == 'undefined' )
    {
        return null;
    }
 
    if ( delimiter === '' ||
        delimiter === false ||
        delimiter === null )
    {
        return false;
    }
 
    if ( typeof delimiter == 'function' ||
        typeof delimiter == 'object' ||
        typeof string == 'function' ||
        typeof string == 'object' )
    {
        return emptyArray;
    }
 
    if ( delimiter === true ) {
        delimiter = '1';
    }
    
    if (!limit) {
        return string.toString().split(delimiter.toString());
    } else {

        var splitted = string.toString().split(delimiter.toString());
        var partA = splitted.splice(0, limit - 1);
        var partB = splitted.join(delimiter.toString());
        partA.push(partB);
        return partA;
    }
}

function split( delimiter, string ) { 
    return this.explode( delimiter, string );
}

function change_order(id){
  var order_link = "jv_change_bio_order";
  if(typeof(is_cv_page) != 'undefined'){
    cv_id = is_cv_page;
	order_link = "jv_change_cv_bio_order";
  } else {
	cv_id = 0;
  }
  if(bio_mode[id] > 0){
      var ajaxBaseUrl = document.location.href;
      var ajaxTemp = ajaxBaseUrl.lastIndexOf("/") + 1;
      ajaxBaseUrl = ajaxBaseUrl.substring(0, ajaxTemp);
      var requestStr = ajaxBaseUrl + "index.html?__ajaxMethod="+order_link;
	  var arr = $('#list'+id).sortable('toArray');
	  var arr_str = '';
	  for(var i=0;i<arr.length;i++){
	    arr_str += arr[i]+';';
	  }
	  
      $.ajax({
        async: false,        
        type: 'POST',
        url: requestStr,
        data: {
                window_id: id,
                array: arr_str,
				cv_id: cv_id
                }        
      });
  }
}

function delete_cv_bio_row(id, cv_id){
  if(bio_mode[id] > 0){
    simple_confirm($('#confirm_del_dio').html(), function(){
      var ajaxBaseUrl = document.location.href;
      var ajaxTemp = ajaxBaseUrl.lastIndexOf("/") + 1;
      ajaxBaseUrl = ajaxBaseUrl.substring(0, ajaxTemp);
      var requestStr = ajaxBaseUrl + "index.html?__ajaxMethod=delete_cv_bio_row";
      $('#list'+id).attr('disabled', 'disabled');
      $.ajax({
        async: false,
        //timeout: 3000,
        type: 'POST',
        url: requestStr,
        data: { 
                id: bio_mode[id],
                window_id: id,
                cv_id: cv_id
                },
        success: function(answ) {
          if(answ == "correct"){		    
			$('#list'+id+'_'+bio_mode[id]).remove();
            $('#list'+id).attr('disabled', null);
          }
        }
      });
    });
  }
}

//jv_change_cv_bio_order

function change_bio_box_order(){  
  if(typeof(is_cv_page) != 'undefined'){
    cv_id = is_cv_page;	
  } else {  
	return false;
  }  
      var ajaxBaseUrl = document.location.href;
      var ajaxTemp = ajaxBaseUrl.lastIndexOf("/") + 1;
      ajaxBaseUrl = ajaxBaseUrl.substring(0, ajaxTemp);
      var requestStr = ajaxBaseUrl + "index.html?__ajaxMethod=jv_change_cv_bio_order_box";
	  var arr = $('#bio_box').sortable('toArray');
	  var arr_str = '';
	  for(var i=0;i<arr.length;i++){
	    arr_str += arr[i]+';';
	  }
	  
      $.ajax({
        async: false,        
        type: 'POST',
        url: requestStr,
        data: {                
                array: arr_str,
				cv_id: cv_id
                }        
      });
}

getElementsByClassNameAdditional = function(className)
{   var outArray = new Array();
    var item;
    try {
        var xpathResult = document.evaluate('//*[class = "' + className + '"]', document, null, 0, null);
        while (item = xpathResult.iterateNext())
            outArray[outArray.length] = item;
    }
    catch(err) {
        // ie fix
        var currentIndex = 0;
        var allElements = document.getElementsByTagName('*');
        for(var i=0; i < allElements.length; i++)
        {   if(allElements[i].className.match(className))
            {   outArray[currentIndex] = allElements[i];
                currentIndex++;
            }
        }
    }
    return outArray;
}

function set_bio_attr(){
elms = getElementsByClassNameAdditional('biography_control_button');
  if((elms.length == 'undefined')||(elms.length == '0')){
    elms = $('.biography_control_button');
  }  

  $(elms).click(function(){
    
    $('#literature').addClass('required');
    
    if($(this).attr('act') == 'del'){
	  if(typeof(is_cv_id_create) != 'undefined'){
	    if(is_cv_id_create > 0){
		  delete_cv_bio_row($(this).attr('pid'), is_cv_id_create);
		} else {
		  delete_bio_row($(this).attr('pid'));
		}
	  } else {
	    delete_bio_row($(this).attr('pid'));
	  }
      
    }    
    
    if($(this).attr('act') == 'edit'){     
      if($('#list'+$(this).attr('pid')+'_value').val() > 0){
        //bio_mode[$(this).attr('pid')] = $('#list'+$(this).attr('pid')+'_value').val();          
        switch($(this).attr('pid')){
          case '1':
            fill_bio_study($(this).attr('pid'), $(this).attr('eid'));
          break;
          case '2':          
            fill_bio_job($(this).attr('pid'), $(this).attr('eid'));
          break;
          case '3':          
            fill_bio_expertise($(this).attr('pid'), $(this).attr('eid'));
          break;
          case '4':          
            fill_bio_hobby($(this).attr('pid'), $(this).attr('eid'));
          break;
          case '5':          
            fill_bio_language($(this).attr('pid'), $(this).attr('eid'));
          break;
          case '6':
            fill_bio_literature($(this).attr('pid'), $(this).attr('eid'));
          break;
        }
      }      
    }
    
  });
  
  $('#dbio1 li').mousedown(function(){
    $('#dbio1 li').removeClass('selected');
    $(this).addClass('selected');
    $('#list1_value').val($(this).attr('value'));
    bio_mode[1] = $(this).attr('value');
  });
  $('#dbio2 li').mousedown(function(){
    $('#dbio2 li').removeClass('selected');
    $(this).addClass('selected');
    $('#list2_value').val($(this).attr('value'));
    bio_mode[2] = $(this).attr('value');
  });
  $('#dbio3 li').mousedown(function(){
    $('#dbio3 li').removeClass('selected');
    $(this).addClass('selected');
    $('#list3_value').val($(this).attr('value'));
    bio_mode[3] = $(this).attr('value');
  });
  $('#dbio4 li').mousedown(function(){
    $('#dbio4 li').removeClass('selected');
    $(this).addClass('selected');
    $('#list4_value').val($(this).attr('value'));
    bio_mode[4] = $(this).attr('value');
  });
  $('#dbio5 li').mousedown(function(){
    $('#dbio5 li').removeClass('selected');
    $(this).addClass('selected');
    $('#list5_value').val($(this).attr('value'));
    bio_mode[5] = $(this).attr('value');
  });
  $('#dbio6 li').mousedown(function(){
    $('#dbio6 li').removeClass('selected');
    $(this).addClass('selected');
    $('#list6_value').val($(this).attr('value'));
    bio_mode[6] = $(this).attr('value');
  });
}

function change_cv_name(cv_id){
  var ajaxBaseUrl = document.location.href;
  var ajaxTemp = ajaxBaseUrl.lastIndexOf("/") + 1;
  ajaxBaseUrl = ajaxBaseUrl.substring(0, ajaxTemp);
  var requestStr = ajaxBaseUrl + "index.html?__ajaxMethod=jv_change_cv_name";
  var text = $('#cv_name').val();
  $.ajax(
    {
      async: false,
      timeout: 3000,
      type: 'POST',
      url: requestStr,
      data: { id: cv_id,  name: text},
      success: function(answ){
        if (answ == 'correct') {
          $('#cv_name_save').fadeOut('slow');
          $('#cv_name_old').val($('#cv_name').val());
        } else { 
          if (answ == 'empty') {
            $('#cv_name').val($('#cv_name_old').val());
            $('#cv_name_save').fadeOut('slow');
          } else {
            $('#cv_name_save').val('Error...');
          }
        }
      }
    })
}


function save_search_logout_callback(data) {
  return false;
}

function save_search_login_callback(login) {  
  $('#login_error', '#simplemodal-container2').css('display', 'none');
  $('#name_empty_error', '#simplemodal-container2').css('display', 'none');
  $('#account_error', '#simplemodal-container2').css('display', 'none');
  if(login < 0){
    $('#login_error', '#simplemodal-container2').css('display', 'block');
    return false;
  } 
  
  if(login == 2) {
    $('#account_error', '#simplemodal-container2').css('display', 'block');
    cms_do_ajax_logout(save_search_logout_callback);
    return false;
  }   
  
  var ajaxBaseUrl = document.location.href;
  var ajaxTemp = ajaxBaseUrl.lastIndexOf("/") + 1;
  ajaxBaseUrl = ajaxBaseUrl.substring(0, ajaxTemp);
  var requestStr = ajaxBaseUrl + "index.html?__ajaxMethod=jv_save_search_profile";
  $.ajax({
    async: false,
    //timeout: 3000,
    type: 'POST',
    url: requestStr,
    data: { 
            reg: 1,  
            search_name: $('#name', '#simplemodal-container2').val(),
            search_service_status_id: $('#mail_service_status_id', '#simplemodal-container2').val(),
            search_url_string: document.location.href
          },
    success: function(answ) {     
      if ($('#logon_rememberme', '#simplemodal-container2').attr('checked') == false) {
        $('#popupclose', '#simplemodal-container2').click();
        cms_do_ajax_logout(save_search_logout_callback);
        simple_alert($("#trn_success").text());
      } else {
        $('#popupclose', '#simplemodal-container2').click();
        var ajaxBaseUrl = document.location.href;
        var ajaxTemp    = ajaxBaseUrl.lastIndexOf("/") + 1;
        ajaxBaseUrl     = ajaxBaseUrl.substring(0, ajaxTemp);
        if(typeof(redirect_path_myjobvector) == 'undefined') redirect_path_myjobvector  = 'myjobvector.html';
        document.location=ajaxBaseUrl + redirect_path_myjobvector;
      }
    }
  });
  return false;  
}

function SaveSearchProfile() { 
  if($.trim($('#name', '#simplemodal-container2').val()) == '') {
    $('#name_empty_error', '#simplemodal-container2').css('display', 'block');  
    return false;
  }
  
  var reg = $(':input[checked="true"]', '#simplemodal-container2').val();
  if(reg == 1) { 
    res = jv_do_ajax_login($('#logon_name', '#simplemodal-container2').val(), $('#logon_password', '#simplemodal-container2').val(), 0, 'save_search_login_callback');
  } else { 
    var ajaxBaseUrl = document.location.href;
    var ajaxTemp = ajaxBaseUrl.lastIndexOf("/") + 1;
    ajaxBaseUrl = ajaxBaseUrl.substring(0, ajaxTemp);
    //alert(document.location.href);
    var requestStr = ajaxBaseUrl + "index.html?__ajaxMethod=jv_save_search_profile";
    $.ajax({
      async: false,
      type: 'POST',
      url: requestStr,
      data: { 
              reg: 0,  
              search_name: $('#name', '#simplemodal-container2').val(),
              search_service_status_id: $('#mail_service_status_id', '#simplemodal-container2').val(),
              search_url_string: document.location.href
            },
      success: function(answ) {
        $('#popupclose', '#simplemodal-container2').click();
        var ajaxBaseUrl = document.location.href;
        var ajaxTemp    = ajaxBaseUrl.lastIndexOf("/") + 1;
        ajaxBaseUrl     = ajaxBaseUrl.substring(0, ajaxTemp);
        if(typeof(redirect_path_entry_req) == 'undefined') redirect_path_entry_req = 'entry_req.html';
        document.location=ajaxBaseUrl + redirect_path_entry_req;
      }
    });
    
  }
}

function SetRequiredJobLocation(enumeration_id){
  if(typeof(job_location_ids) == 'undefined'){
    return false;
  }
  if(enumeration_id == job_location_ids[0]){  
    $('#country_id').attr('class', 'required');	
	$('#country_required').html('*');	
	city_el = document.getElementById('city_id[text]');	
	$(city_el).attr('class', 'required');
	$('#city_required').html('*');	
	$('#zip').attr('class', 'required');	
	$('#zip_required').html('*');
	$('.job_location').show();
  }
  
  if(enumeration_id == job_location_ids[1]){
    //$('#country_id').attr('class', 'required');
	//$('#country_required').html('*');
	$('#country_id').attr('class', '');
	$('#country_required').html('');
	city_el = document.getElementById('city_id[text]');
	$(city_el).attr('class', '');
	$('#city_required').html('');
	$('#zip').attr('class', '');
	$('#zip_required').html('');
	$('.job_location').show();
  }
  
  if(enumeration_id == job_location_ids[2]){
    $('#country_id').attr('class', '');
	city_el = document.getElementById('city_id[text]');
	$(city_el).attr('class', '');
	$('#zip').attr('class', '');
	$('.job_location').hide();
  }
  
}

function SetRequiredApplyMethod() {
  /*if($('input[name="external_url"]').val()) {
    SetChecked('apply_method_1');
  } else
  if($('input[name="direct_email"]').val()) {
    SetChecked('apply_method_2');
  } else
    SetChecked('apply_method_3');*/
  $("[name=apply_method]").click(function(){
    if ($(this).attr('id') == 'apply_method_1' && $(this).attr('checked') == 'checked') {
      $('input[name="external_url"]').addClass('required').removeAttr('disabled');
      $('input[name="direct_email"]').removeClass('required').val('').attr('disabled', 'disabled');
    } else
    if ($(this).attr('id') == 'apply_method_2' && $(this).attr('checked') == 'checked') {
      $('input[name="external_url"]').removeClass('required').val('').attr('disabled', 'disabled');
      $('input[name="direct_email"]').addClass('required').removeAttr('disabled');
    } else {
      $('input[name="external_url"]').removeClass('required').val('').attr('disabled', 'disabled');
      $('input[name="direct_email"]').removeClass('required').val('').attr('disabled', 'disabled');
    }
  });
  
}

function ChangeIsNotCompleted(){
    if($('#flag_ongoing').attr('checked')){
      $('.ongoing').hide();
      $('#date_till_2_month').removeClass('positiveDatesJob');
      $('#date_till_2_month').val('');
      $('#date_till_2_year').val('');
    } else {
      $('.ongoing').show();
      $('#date_till_2_month').addClass('positiveDatesJob');
    }
}
  
function ChangeIsNotCompletedStudy(){
    if($('#is_not_completed').attr('checked')){
      //$('.ongoing2').hide();
	    $('#date_till_month').removeClass('positiveDatesStudy');
	    $('#date_till_month').val('');
	    $('#date_till_year').val('');
    } else {
      //$('.ongoing2').show();
		  $('#date_till_month').addClass('positiveDatesStudy');
    }
}
  
function delete_applicant() {
  simple_confirm($('#confirm_delete').html(), function(){
      var ajaxBaseUrl = document.location.href;
      var ajaxTemp = ajaxBaseUrl.lastIndexOf("/") + 1;
      ajaxBaseUrl = ajaxBaseUrl.substring(0, ajaxTemp);
      var requestStr = ajaxBaseUrl + "index.html?__ajaxMethod=jv_delete_account";
      $.ajax({
        async: false,
        //timeout: 3000,
        type: 'POST',
        url: requestStr,
        data: {  },
        success: function(answ) {
          if(answ == "correct"){		    
			      cms_do_ajax_logout('go_home');
          }
        }
      });
    });
  return false;
}

function CreateApplicationEmail(application_id, applicant_id, job_id , and_send){

    if(and_send == true) {
      and_send = 1;
      txt = $("#trn_create_and_send_email").html();
    } else {
      txt = $("#trn_create_email").html();
    }
    simple_confirm(txt, function(){
    var ajaxBaseUrl = document.location.href;
    var ajaxTemp = ajaxBaseUrl.lastIndexOf("/") + 1;
    ajaxBaseUrl = ajaxBaseUrl.substring(0, ajaxTemp);
    var requestStr = ajaxBaseUrl + "index.html?__ajaxMethod=jv_create_application_email";       
    $.ajax(
      {
        async: false,
        timeout: 3000,
        type: 'POST',
        url: requestStr,
        data: { application_id: application_id
              , applicant_id  : applicant_id
              , job_id        : job_id
              , and_send      : and_send
              },
        success: function(answ){
         if(answ == "correct") {  
          //document.location.href = ajaxBaseUrl + "list_application_emails.html";
          txt = $("#trn_create_email_ok").html();
          $("#email_container").html(txt);
         } else if(answ == "limit_exceeded"){          
          $(".simplemodal-close").click();
          setTimeout('simple_alert($("#trn_limit_exceeded_app").text());', 0);
         } else {
          $(".simplemodal-close").click();
          setTimeout('simple_alert($("#trn_create_email_failed").text());', 0);
         }
        },
        error: function() {
          simple_alert($("#trn_create_email_failed").html());
        }
        
      }
     )
  });

}



