function readyLoginLinks () {
  $('.aanmeldenGebruikerLink').fancybox({
    'type' : 'ajax',
    'href' : '/aanmelden/template=40',
    'title' : 'aanmelden als werkzoekende',
		'scrolling' : 'no',
		'padding' : 20,
    'onComplete' : function () {
      readyLoginLinks();
    }
  });
    
    
  $('.origineleLink a').click(function(event) {
    event.preventDefault();
    window.open($(this).attr('href'));
  });
   
  /*
  $('.ITVacatureAanmaken').fancybox({
    'type' : 'ajax',
    'href' : '/werkgevers/template=40',
    'title' : 'aanmelden als werkgever',
		'scrolling' : 'no',
		'padding' : 20,
    'onComplete' : function() {
      readyLoginLinks();
    }
 }); 
 */     
    
  $('.aanmeldenWerkgeversLink').fancybox({
    'type' : 'ajax',
    'href' : '/werkgevers_aanmelden/template=40',
    'title' : 'aanmelden als werkgever',
		'scrolling' : 'no',
		'padding' : 20,
    'onComplete' : function() {
      readyLoginLinks();
    }
 });    
  /*
  $('.werkgeverVacaturesLink, .sticker').fancybox({
    'type' : 'ajax',
    'href' : '/wizard',
    'title' : 'mijn IT vacatures',
		'scrolling' : 'no',
		'padding' : 20,
    'onComplete' : function() {
      readyLoginLinks();
    }
 }); 
 */  
 
 $('.werkgeverVacaturesLink, .sticker').click(function() {
   document.location.href = '/wizard/';
 }); 
 
  $('.werkgeverVacatureToevoegenLink').fancybox({
    'type' : 'ajax',
    'href' : '/werkgevers/vacature_toevoegen/template=40',
    'title' : 'IT vacature toevoegen',
		'scrolling' : 'no',
		'padding' : 20,
    'onComplete' : function() {
      readyLoginLinks();
    }
 });  
 
  $('.werkgeverGegevensWijzigenLink').fancybox({
    'type' : 'ajax',
    'href' : '/werkgevers/gegevens/template=40',
    'title' : 'mijn gegevens',
		'scrolling' : 'no',
		'padding' : 20,
    'onComplete' : function() {
      readyLoginLinks();
    }
 });     
    
  $('.werkgeverGegevensWachtwoordWijzigenLink').fancybox({
    'type' : 'ajax',
    'href' : '/werkgevers/wachtwoord/template=40',
    'title' : 'wachtwoord wijzigen',
		'scrolling' : 'no',
		'padding' : 20,
    'onComplete' : function() {
      readyLoginLinks();
    }
 });      
    
  $('.mijnITlink').fancybox({
    'type' : 'ajax',
    'href' : '/mijn-ITvacature/template=40',
		'scrolling' : 'no',
		'padding' : 20,
    'onComplete' : function() {
      readyLoginLinks();
    }
 });  
 
   $('.mijn_gegevens').fancybox({
    'type' : 'ajax',
    'href' : '/mijn_gegevens/template=40',
		'scrolling' : 'yes',
		'padding' : 20,
    'onComplete' : function() {
      readyLoginLinks();
    }
 });    
 
  $('.loginLink').fancybox({
    'type' : 'ajax',
    'href' : '/mijn-ITvacature/template=40',
    'title' : 'inloggen als werkzoekende',
		'scrolling' : 'no',
		'padding' : 20,
    'onComplete' : function() {
      readyLoginLinks();
    }
 });   
 
  $('.emailLink').click(function(e) {
    e.preventDefault();
    
    var wat = $(this).parent().parent().find('.zoekWat .textVeld').val();
    var waar = $(this).parent().parent().find('.zoekWaar .textVeld').val();
    var straal = $(this).parent().parent().find('.zoekStraal .textVeld').val();
    var omschrijving = $(this).parent().parent().find('#omschrijving_zoeken:checked').length;
    
    if(waar == 'stad, provincie of postcode') { waar = ''; }
    if(wat == 'functie, trefwoorden of bedrijf') { wat = ''; }
    
    var url = '/mailservice/template=40/wat=' + wat + '/waar=' + waar + '/straal=' + straal + '/omschrijving=' + omschrijving;

    $.fancybox({
    'type' : 'ajax',
    'href' : url,
    'title' : 'Vacatures per e-mail ontvangen',
		'scrolling' : 'no',
		'padding' : 20,
    'onComplete' : function() {
      readyLoginLinks();
    }
    });
 });  
 
   $('.wachtwoordVergetenLink').fancybox({
    'type' : 'ajax',
    'href' : '/wachtwoord_vergeten/template=40',
		'scrolling' : 'yes',
		'padding' : 20,
    'onComplete' : function() {
      readyLoginLinks();
    }
 });     
 
   $('.wachtwoordVergetenWerkgeversLink').fancybox({
    'type' : 'ajax',
    'href' : '/wachtwoord_vergeten_werkgevers/template=40',
		'scrolling' : 'yes',
		'padding' : 20,
    'onComplete' : function() {
      readyLoginLinks();
    }
 }); 
 
 
    
   $('.gebruikerGegevensWijzigenLink').fancybox({
    'type' : 'ajax',
    'href' : '/gebruikers/gegevens/template=40',
		'scrolling' : 'yes',
		'padding' : 20,
    'onComplete' : function() {
      readyLoginLinks();
    }
 });       
    
 
   $('.gebruikerGegevensWachtwoordWijzigenLink').fancybox({
    'type' : 'ajax',
    'href' : '/gebruikers/wachtwoord/template=40',
		'scrolling' : 'yes',
		'padding' : 20,
    'onComplete' : function() {
      readyLoginLinks();
    }
  });   
  
  
    $('.verwijderZoekOpdracht').click(function(event) {
      event.preventDefault();
      
      var url = '/php/verwerk/ajaxVerwijderZoekOpdracht.php';
      var id = $(this).attr('href');
      var rij = $(this).parent();
  
    	$.ajax({
    		type		: "POST",
    		cache	: false,
    		url		: url,
    		data		: { zoekopdracht: id },
    		success: function(data) {

          rij.fadeOut(function() {
            rij.remove();
          });
    		}
    	});
    });
   
  
 
  $(".zoekformulier").unbind("submit").bind("submit", function() {
    var wat = $(this).find('.zoekWat .textVeld').val();
    var waar = $(this).find('.zoekWaar .textVeld').val();
    var straal = $(this).find('.zoekStraal .textVeld').val();
    var omschrijving = $(this).find('#omschrijving_zoeken:checked').length;
    
    var actie = $(this).attr('action');    
    
    if (actie.substr(0, 7) == '/beheer') {
      var url = '/beheer/vacatures/resultaten/';
    } else {
      var url = '/';
    }
    
    var teken = '?';
    
    if(wat.length > 0 && wat != 'functie, trefwoorden of bedrijf') {
      url += teken + 'wat=' + wat;
      teken = '&';
    }
    
    if(waar.length > 0 && waar != 'stad, provincie of postcode') {
      url += teken + 'waar=' + waar;
      teken = '&';
    }
    
    if(straal.length > 0 && straal != '0 km' && straal != '-') {
      url += teken + 'straal=' + straal;
      teken = '&';
    }
    
    if (!omschrijving) {
      url += teken + 'o=0';
    }

    document.location.href = url;
    
    return false;    
  }); 
 
 
  $(".mailserviceAanmelden, .snelAanmelden, .gebruikersLoginForm, .werkgeversLoginForm, .werkgeverVacatureToevoegenForm, .werkgeversWachtwoordWijzigenForm, .gebruikersWachtwoordWijzigenForm, .gebruikersWachtwoordVergetenForm, .werkgeversWachtwoordVergetenForm").unbind("submit").bind("submit", function() {
  	$.fancybox.showActivity();
  
    var url = $(this).attr('action') + '/template=40';

  	$.ajax({
  		type		: "POST",
  		cache	: false,
  		url		: url,
  		data		: $(this).serializeArray(),
  		success: function(data) {
  			$.fancybox({'content' : data});
        readyLoginLinks();
  		}
  	});
  
  	return false;
  }); 
  
  $(".wizardStap .werkgeversLoginForm").unbind("submit");
  
  $(".formgebruikers").unbind("submit").bind("submit", function() {
  	$.fancybox.showActivity();
  
  	$.ajax({
  		type		: "POST",
  		cache	: false,
  		url		: "/aanmelden/template=40",
  		data		: $(this).serializeArray(),
  		success: function(data) {
  			$.fancybox({'content' : data});
        readyLoginLinks();
  		}
  	});
  
  	return false;
  }); 
  
  $(".formwerkgevers").unbind("submit").bind("submit", function() {
  	$.fancybox.showActivity();
  
  	$.ajax({
  		type		: "POST",
  		cache	: false,
  		url		: "/werkgevers_aanmelden/template=40",
  		data		: $(this).serializeArray(),
  		success: function(data) {
  			$.fancybox({'content' : data});
        readyLoginLinks();
  		}
  	});
  
  	return false;
  });   
  
  $(".formwerkgevers2").unbind("submit").bind("submit", function() {
  	$.fancybox.showActivity();
  
  	$.ajax({
  		type		: "POST",
  		cache	: false,
  		url		: "/werkgevers/gegevens/template=40",
  		data		: $(this).serializeArray(),
  		success: function(data) {
  			$.fancybox({'content' : data});
        readyLoginLinks();
  		}
  	});
  
  	return false;
  });    
  
  $(".formgebruikers2").unbind("submit").bind("submit", function() {
  	$.fancybox.showActivity();
  
  	$.ajax({
  		type		: "POST",
  		cache	: false,
  		url		: "/gebruikers/gegevens/template=40",
  		data		: $(this).serializeArray(),
  		success: function(data) {
  			$.fancybox({'content' : data});
        readyLoginLinks();
  		}
  	});
  
  	return false;
  });   
  
  
  
  $(".solliciteerFormulier").unbind("submit").bind("submit", function() {
  	$.fancybox.showActivity();
  
    var url = $(this).attr('action') + '/template=40';  
  
  	$.ajax({
  		type		: "POST",
  		cache	: false,
  		url		: url,
  		data		: $(this).serializeArray(),
  		success: function(data) {
  			$.fancybox({'content' : data});
        readyLoginLinks();
  		}
  	});
  
  	return false;
  }); 
   
}

$(document).ready(function() {
  /* Login functies */
    readyLoginLinks();

  /* Zoekvak */
    $('.selecteerStraalIcon').click(function () {
      $(this).parent().find('.selecteerStraalSelectie').slideToggle();
    });
    
    $('.selecteerStraalSelectie').mouseleave(function () {
      $(this).slideUp();
    });
    
    $('.selecteerStraalSelectie li').click(function () {
      //$('#zoekStraal').val($(this).text());
      
      $(this).parent().parent().parent().find('.textStraal').val($(this).text());
    
      $(this).parent().parent().slideUp();
    });
    
    $('#solliciteerNaam').click(function () { if ($(this).val() == 'Je naam') { $(this).val(''); } });
    $('#solliciteerNaam').blur(function () { if ($(this).val() == '') { $(this).val('Je naam'); } });
    
    $('#solliciteerEmail').click(function () { if ($(this).val() == 'Je e-mailadres') { $(this).val(''); } });
    $('#solliciteerEmail').blur(function () { if ($(this).val() == '') { $(this).val('Je e-mailadres'); } });
    
    $('#solliciteerMotivatie').click(function () { if ($(this).val() == 'Je motivatie') { $(this).val(''); } });
    $('#solliciteerMotivatie').blur(function () { if ($(this).val() == '') { $(this).val('Je motivatie'); } });
    
    $('#solliciteerTelefoon').click(function () { if ($(this).val() == 'Je tel. nummer') { $(this).val(''); } });
    $('#solliciteerTelefoon').blur(function () { if ($(this).val() == '') { $(this).val('Je tel. nummer'); } });    
    
//    $(".zoekWaar .textVeld").autocomplete("/php/verwerk/autocomplete/locatie.php");
//    $(".zoekWat .textVeld").autocomplete("/php/verwerk/autocomplete/trefwoord.php");
    $(".zoekWat .textVeld").click(function() {
      if($(this).val() == 'functie, trefwoorden of bedrijf') { $(this).val(''); }
    });
    
    $(".zoekWat .textVeld").blur(function() {
      if($(this).val() == '') { $(this).val('functie, trefwoorden of bedrijf'); }
    });
    
    $(".zoekWaar .textVeld").click(function() {
      if($(this).val() == 'stad, provincie of postcode') { $(this).val(''); }
    });
    
    $(".zoekWaar .textVeld").blur(function() {
      if($(this).val() == '') { $(this).val('stad, provincie of postcode'); }
    });
    
    $('.meerBladeren').click(function () {
      var aantal = 0;
      var echtskippen = 1;
    
      $(this).parent().parent().find('li:hidden').each(function() {
        aantal++;
        
        if (aantal > 10) { echtskippen = 0; }
        
        if (echtskippen) {
          $(this).slideDown();
        }
      });
      
      if (echtskippen) {
        $(this).parent().fadeOut();
      }
    });
    
    $('.suggestieLijst .wissen a').click(function(e) {
      e.preventDefault();
      
      $.ajax({ url: "/opdrachtenWissen=1" });
      $(this).parent().parent().fadeOut();      
    });
    
    $('.suggestieLijst .kop').click(function () {
      if ($(this).parent().find('ul').is(':visible')) {
        $(this).parent().find('ul').slideToggle();
        $(this).removeClass('actiefKop'); 
      } else {
        $(this).parent().find('ul').slideToggle();
        $(this).addClass('actiefKop');      
      }
    });
    
    $('.suggesties .verbergen').click(function () {
      $(this).hide();
      $('.suggesties .weergeven').fadeIn('fast');
   
      $('.suggesties .suggestieLijst').each(function () {
        $(this).find('ul').slideUp();
        $(this).find('.kop').removeClass('actiefKop');       
      });         
    });
    
    $('.suggesties .weergeven').click(function () {
      $(this).hide();    
      $('.suggesties .verbergen').fadeIn('fast');
      
      $('.suggesties .suggestieLijst').each(function () {
        $(this).find('ul').slideDown();
        $(this).find('.kop').addClass('actiefKop');       
      });         
    });    
    
  	// faq
  	$('#slider').accordion({ 
  		autoheight: false,
  		alwaysOpen: false
  	});    
    
    ///tabs
    $('.tabdetails').click(function() {
      if (!$(this).hasClass('actief')) {
        $(this).addClass('actief');
        $('.tablogboek').removeClass('actief');
        $('.tablogboekcontent').fadeOut('fast', function() {
          $('.tabdetailscontent').fadeIn('fast');      
        });
      }
    });
    
    $('.tablogboek').click(function() {
      if (!$(this).hasClass('actief')) {
        $(this).addClass('actief');
        $('.tabdetails').removeClass('actief');
        $('.tabdetailscontent').fadeOut('fast', function() {
          $('.tablogboekcontent').fadeIn('fast');      
        });
      }
    });     
    
    $('.wizardFormTabel tr').hover(function() {
      $(this).addClass('actieveRij');
    }, function() {
      $(this).removeClass('actieveRij');
    });   
    
    /*
    $('.wizardFormTabel tr').hover(function() {
      $(this).find(\'.opmerking\').show();      
    }, function() {
      $(this).find(\'.opmerking\').hide();
    });
    */
    
    $('.voorbeeldLink').click(function(e) {
      e.preventDefault();
      window.open($(this).attr('href'), 'newWindow', 'status=0,toolbar=0');
    });
});

function wijzigVacatureEigenschap(id, titel, eigenschap, waardeID, waarde, type, autocompleteType, selectOpties) {
  var numRand = Math.floor(Math.random()*101);
  var box = 'box' + numRand;
  var waarde = $('#' + eigenschap + ' .waardeVeld').val();
  
  if (waarde == '0')  { waarde = ''; }
  
  var html  = '<div class="box" id="' + box + '">';
      html += '<div class="screenOverlay"></div>';
      html += '<div class="screenBox" style="display: none">';
      html += '<div class="titel">' + titel + ' <a class="sluiten" href="#">[ x ]</a></div>';
      html += '<div class="contents">';
      
      if (type == 'select') {
        html += '<div class="textVeld"><input type="hidden" class="textWaardeID" value="' + waardeID + '" /><select class="textWaarde"><option value=""></option>';
        
        for (x = 0; x < selectOpties.length; x++) {
          if (waarde == selectOpties[x]) {
            html += '<option value="' + selectOpties[x] + '" SELECTED>' + selectOpties[x] + '</option>';
          } else {
            html += '<option value="' + selectOpties[x] + '">' + selectOpties[x] + '</option>';
          }
        }
        
        html += '</select></div>';
      } else {
        html += '<div class="textVeld"><input type="hidden" class="textWaardeID" value="' + waardeID + '" /><input type="text" class="textWaarde" size="20" value="' + waarde + '" /></div>';
      }
      
      html += '<div class="opslaanButton"><input type="image" class="noborder" src="' + webadres + 'img/itvacature/button_opslaan_wit.jpg" size="20" value="' + waarde + '" /></div>';
      
      html += '</div>';
      html += '</div>';
      html += '</div>';
  
  $('body').append(html);
  var height = $(document).height();
  $('#' + box).css('height', height);
  $('#' + box + ' .screenOverlay').show();
  $('#' + box + ' .screenBox').fadeIn();
  
  if (autocompleteType == 'bedrijf') {
    $('#' + box + ' .textWaarde').autocomplete("/php/verwerk/autocomplete/trefwoord.php");
  }
  
  if (autocompleteType == 'locatie') {
    $('#' + box + ' .textWaarde').autocomplete("/php/verwerk/autocomplete/locatie.php");
  }  
  
  if (autocompleteType == 'plaats') {
    $('#' + box + ' .textWaarde').autocomplete("/php/verwerk/autocomplete/plaats.php");
  }   
  
  if (autocompleteType == 'categorie') {
    $('#' + box + ' .textWaarde').autocomplete("/php/verwerk/autocomplete/categorie.php");
  } 
  
  if (autocompleteType == 'dienstverband') {
    $('#' + box + ' .textWaarde').autocomplete("/php/verwerk/autocomplete/dienstverband.php");
  }      
  
  if (autocompleteType == 'opleidingsniveau') {
    $('#' + box + ' .textWaarde').autocomplete("/php/verwerk/autocomplete/opleidingsniveau.php");
  } 
  
  if (autocompleteType == 'salaris') {
    $('#' + box + ' .textWaarde').autocomplete("/php/verwerk/autocomplete/salaris.php");
  }    
    
  $('#' + box + ' .sluiten').click(function () {
    $(this).parent().parent().parent().fadeOut(function () {
      $(this).remove();
    });
  });
  
  $('#' + box + ' .opslaanButton').click(function () {
    var text = $(this).parent().find('.textWaarde').val();
//    alert(text);
    $('#' + eigenschap + ' .waardeVeld').val(text);
    $('#' + eigenschap + ' .waarde').html(text);
    
    $(this).parent().parent().parent().fadeOut(function () {
      $(this).remove();
    });    
  });
}
