var particulier = true;
var instantie = false;
$(document).on('click','#adverteer_cancel','data',function(){
wl_alert('confirm','Weet u zeker dat u wilt cancellen?',cancel_add);
})
function cancel_add(){
location.href='?cancelled';
}
$(document).on('change','#overdragen','',function(){
console.log('overdragen',$(this).val());
if ($(this).val()=='op_termijn') {
$('.row_reden').hide();
}else{
$('.row_reden').show();
}
});
$(document).on('click','#adverteer_payment','data',function(){
var aantal = 1;
var price = 4.5;
var entryID = $('#entryID').val();
if(aantal>0){
$('#loading').show(400);
$.ajax({
url: "/process_ajax.php",
type: "POST",
data: {task:'prepare_payment',aantal:aantal,unit_price:price,entryID:entryID},
cache: false,
async: true,
timeout: 15000,
dataType: 'json',
success: function (p) {
//var ems = JSON.parse(html);
//console.log(html);
for (var key in p) {
if (p.hasOwnProperty(key)) {
console.log(key + " -> " + p[key]);
$("").attr("type", "hidden")
.attr("name", key)
.attr("value", p[key])
.appendTo("#payment_form");
}
}
$('#payment_form').submit();
},
error: function(xhr, textStatus, errorThrown){
$('#loading').hide(400);
//alert('Verzenden mislukt, probeer het later nog eens. ('+errorThrown+')');
var txt = 'Verzenden mislukt, probeer het later nog eens. ('+errorThrown+')';
wl_alert('alert',txt,false,false,'OK');
},
complete: function(){
$('.loading').hide();
}
});
}else{
wl_alert('alert','Aantal credits moet ingevuld zijn en groter dan 0');
}
});
$(document).on('click','#advertentie_plaatsen','data',function(){
$('#loading').show(400);
var entryID = $('#entryID').val();
$.ajax({
url: "/process_ajax.php",
type: "POST",
data: {task:'advertentie_plaatsen',entryID:entryID},
cache: false,
async: true,
timeout: 15000,
// dataType: 'json',
success: function (html) {
//var ems = JSON.parse(html);
//console.log(html);
wl_alert('alert',html,to_homepage,false,'OK');
},
error: function(xhr, textStatus, errorThrown){
$('#loading').hide(400);
//alert('Verzenden mislukt, probeer het later nog eens. ('+errorThrown+')');
var txt = 'Verzenden mislukt, probeer het later nog eens. ('+errorThrown+')';
wl_alert('alert',txt,false,false,'OK');
},
complete: function(){
$('.loading').hide();
}
});
});
function to_homepage(){
location.href='/';
}
$(document).on('click','.instantie_a','data',function(){
console.log($(this).data('showhide'));
if ($(this).hasClass('instantie_a_active')){
return false;
}
if($(this).data('showhide')=='particulier'){
//$('#particulier_bx').show(400);
particulier = true;
instantie = false;
$('#idvoornaam').attr('placeholder','Naam');
$('.idvoornaam').text('Naam');
$('#instantie_bx').hide(400);
$('#show_add').show(400);
$('#adverteer').hide();
$('.adver_akkoord').hide();
$('.upload_label').hide();
$('.particulier_upload_label').show();
if ($('#show_add').hasClass('show_add_active')){
$('.upload_form').show();
}else{
$('.upload_form').hide();
}
}else{
particulier = false;
instantie = true;
$('#idvoornaam').attr('placeholder','Contactpersoon');
$('.idvoornaam').text('Contactpersoon (wordt niet vermeld op website)');
//$('#particulier_bx').hide(400);
$('#instantie_bx').show(400);
$('#show_add').hide(400).removeClass('show_add_active');
$('#adverteer').show(400);
$('.adver_akkoord').show(400);
$('.add_row').hide(400);
$('.upload_label').hide();
$('.instantie_upload_label').show();
window.setTimeout(function(){
$('.upload_form').show();
}, 450);
}
$('.instantie_a').removeClass('instantie_a_active')
$(this).addClass('instantie_a_active');
});
var add_row_toggled_on = true;
$(document).on('click','#show_add','data',function(){
var deze = $(this);
$('.add_row').toggle(400);
if (add_row_toggled_on){
deze.addClass('show_add_active');
window.setTimeout(function(){
$('.add_row').css('display','flex');
}, 450);
add_row_toggled_on = false;
}else{
deze.removeClass('show_add_active');
add_row_toggled_on = true;
}
$('#adverteer').toggle();
$('.adver_akkoord').toggle();
});
$(document).on('click','#adverteer_credit','data',function(){
var aantal = -1;
var entryID = $('#entryID').val()*1;
// if(aantal>0){
$('#loading').show(400);
$.ajax({
url: "/process_ajax.php",
type: "POST",
data: {task:'gebruik_credit',aantal:aantal,entryID:entryID},
cache: false,
async: true,
timeout: 15000,
// dataType: 'json',
success: function (html) {
$('#adverteren_form').html(html);
location.href='?account=1&message='+html;
},
error: function(xhr, textStatus, errorThrown){
$('#loading').hide(400);
//alert('Verzenden mislukt, probeer het later nog eens. ('+errorThrown+')');
var txt = 'Verzenden mislukt, probeer het later nog eens. ('+errorThrown+')';
wl_alert('alert',txt,false,false,'OK');
},
complete: function(){
$('.loading').hide();
}
});
// }else{
// wl_alert('alert','Aantal credits moet ingevuld zijn en groter dan 0');
// }
})
$(document).on('change','.adverdata','data',function(){
$(this).removeClass('errorfield');
});
$(document).on('click','#adverteer','data',function(){
//alert('hier');
var error = '';
$('.adverdata:visible').each(function(){
var dit = $(this);
val=dit.val();
name=dit.attr("name");
id=dit.attr("id");
required=dit.attr("required");
//console.log(instantie,particulier);
if(instantie && (dit.hasClass('required_instantie'))){
// if($(this).val().trim()==''){
// error +=name+' is een verplicht veld
';
// }
/////////error = notEmpty_required(id, error);
error += notEmpty_required_new(id);
}
if(particulier && (dit.hasClass('required_particulier') || required)){
// if($(this).val().trim()==''){
// error +=name+' is een verplicht veld
';
// }
//////////error = notEmpty_required(id, error);
if (dit.is(':visible')){
error += notEmpty_required_new(id);
}
}
//if(required)error = notEmpty_required(id, error);
});
if (!$('#akkoord_voorwaarden').is(":checked") && $('#akkoord_voorwaarden').is(":visible")){
error += "