
function closeDomainCheckForm()
{
    $('#domain_result').slideUp();
    $('#orderform').slideUp({duration: 1000, easing: 'easeOutBounce'});
    $('#checkform').slideDown();
}

function submitDomainCheckForm()
{
    var values = {};
    $.each($('#domaincheck_form').serializeArray(), function(index,value){values[value.name] = value.value;});
    doGetDomainAvailability(values['domain']);  
    return false;          
}


function doGetDomainAvailability(domain)
{
    $.ajax({
        url:'ajax_handler.php',
        data:{
            action: 'get_domain_availability',
            domain: domain
        },
        dataType:'json',
        type:'post',
        beforeSend:function()
        {
            $('#loader').fadeIn();
        },
        success:function(t,s,x)
        {
            $('#loader').fadeOut();
            if(t.status == 'free')
            {
                $('#orderform').slideDown({duration: 1000, easing: 'easeOutBounce'});
                $('#domain_result').html('<b>Gefeliciteerd!</b><br /><span style="font-size:14pt;background-color:#00DD00;color:#ffffff;padding:0 10px;"><b>'+t.domain+'.'+t.ext+'</b> is beschikbaar!</span><br /><span style="font-size:9pt;color:#ffffff;margin-top:5px;">Kosten: &euro; '+number_format(t.price,2,',','.')+' per jaar | <b>Wij accepteren iDEAL</b><input type="hidden" id="checked_domain" name="checked_domain" value="'+t.domain+'.'+t.ext+'" />');
                $('#checkform').slideUp({duration: 1000, easing: 'easeOutCirc'})    ;
                $('#domain_result').slideDown();                
            }
            else if(t.status == 'active')
            {
                //original_html = $('#checkform').html();
                $('#domain_result').html('<b>Helaas...</b><br /><span style="font-size:14pt;background-color:#ff0000;color:#ffffff;padding:0 10px;"><b>'+t.domain+'.'+t.ext+'</b> is niet beschikbaar</span>');
                $('#checkform').slideUp();
                $('#domain_result').slideDown({duration: 1000, easing: 'easeOutBounce'});
                $('#checkform').delay(2500).fadeOut();  
                window.setTimeout(function(){
                    $('#domain_result').slideUp();
                    //$('#checkform').delay(200).html(original_html);  
                    $('#checkform').fadeIn();  
                },3200);
                
                //alert(t.domain+'.'+t.ext+' is helaas niet beschikbaar');
            }
            else if(t.status == 'error')
            {
                //original_html = $('#checkform').html();
                $('#domain_result').html('<b>Sorry! :-(</b><br />Er is iets fout gegaan, probeer het a.u.b. later nog eens.');
                $('#checkform').slideUp();
                $('#domain_result').slideDown({duration: 1000, easing: 'easeOutBounce'});
                $('#checkform').delay(2500).fadeOut();  
                window.setTimeout(function(){
                    $('#domain_result').slideUp();
                    //$('#checkform').delay(200).html(original_html);  
                    $('#checkform').fadeIn();  
                },3200);
            }
        }
    });
    return false;
}

function doSetDomainOrder(form)
{
    $('#'+form).ajaxSubmit(
    {                                                  
        type:"post",
        url:"ajax_handler.php",
        data:{
            action: 'set_domain_order',
            domain: $('#checked_domain').val()
        },
        dataType:'json',
        type:'post',
        beforeSend:function()
        {
            $('#loader').fadeIn();
        },
        success:function(t,s,x)
        {
            $('#loader').fadeOut();
            $('#orderform2').slideUp();
            $('#payment').slideDown({duration: 1000, easing: 'easeOutBounce'});
            $('#ideal_link').attr('href', 'https://www.dsj.nl/iDEAL/'+t.ideal_code);
        }
    });
    return false;

}


function number_format(a, b, c, d) {
 a = Math.round(a * Math.pow(10, b)) / Math.pow(10, b);
 e = a + '';
 f = e.split('.');
 if (!f[0]) {
  f[0] = '0';
 }
 if (!f[1]) {
  f[1] = '--';
 }
 if (f[1].length < b) {
  g = f[1];
  for (i=f[1].length + 1; i <= b; i++) {
   g += '0';
  }
  f[1] = g;
 }
 if(d != '' && f[0].length > 3) {
  h = f[0];
  f[0] = '';
  for(j = 3; j < h.length; j+=3) {
   i = h.slice(h.length - j, h.length - j + 3);
   f[0] = d + i +  f[0] + '';
  }
  j = h.substr(0, (h.length % 3 == 0) ? 3 : (h.length % 3));
  f[0] = j + f[0];
 }
 c = (b <= 0) ? '' : c;
 return f[0] + c + f[1];
}

