Cufon.replace('div#blocks h1', {fontFamily:'Museo Sans 500'});
Cufon.replace('div.block h3', {fontFamily:'Museo Sans 500'});
Cufon.replace('div#content h1', {fontFamily:'Museo Sans 500'});
Cufon.replace('div#content h2', {fontFamily:'Museo Sans 500'});
Cufon.replace('div.h2-container h2', {fontFamily:'Museo Sans 500'});


//config
var aDomeinnaamprijzen;
var iPrijsdomein;
var iTotaalprijs;

var sSpamfilterDiscountDomain;
var bSpamfilterDiscount = false;


function checkDomainInput(domainname){
    var filter = /^([a-zA-z0-9]{1}[a-zA-z0-9-]{0,66}[a-zA-z0-9]{1})$/i
    if (filter.test(domainname))
    {
        if(domainname.indexOf('--') > -1){
            return 'Meerdere koppeltekens na elkaar zijn niet toegestaan.';
        }else{
            if(domainname.indexOf('_') > -1){
                return 'De domeinnaam mag alleen alfanumerieke tekens en een koppelteken (-) bevatten.';
            }else{
                return 'ok';
            }
        }
    }
    else
    {
        return 'De domeinnaam mag alleen alfanumerieke tekens en een koppelteken (-) bevatten.';
    }
}

$(window).load(function()
{
	$('div#visual').cycle(
	{
		fx:'fade',
		speed:500,
		timeout:5000,
		pause:true,
		pauseOnPagerHover:true,
		cleartype:true,
		cleartypeNoBg:true,
		pager:'div#news ul',
		activePagerClass:'current',
		pagerEvent:'mouseover.cycle',
		pagerAnchorBuilder:function(idx, slide)
		{
			return 'div#news ul li:eq('+idx+') a';
		},
		before:function(cur, next)
		{
			var idx = $(next).index();
			var $current = $('div#news ul li:eq('+idx+')');
			var sHtml = $('div.news-desc', $current).text();
			var $img = $(this).find('img');

			$('div#subtext span').html(sHtml);
			Cufon.replace('div#subtext span', {fontFamily:'Museo Sans 500', color: '#ffffff'});

			$('div#news li.current').removeClass('current');
			$current.addClass('current')

			$(this).css({top: '50%', marginTop: -$(this).height()/2});

			$img.css('filter', "progid:DXImageTransform.Microsoft.AlphaImageLoader (src='" + $img.attr('src') + "') !important"); // IE FIX for jaded background
		}
	});
});


$(document).ready(function(){
	$('a.cms-login-button').click(function()
	{
		var sSelectedCms = $('select[name="cms"] option:selected').val();
		if(sSelectedCms == 'siteconnect2')
		{
			var sFormAction 		= 'http:\/\/www.siteconnect.nl/login.php';
			var sCustomerFieldName 	= 'sitenaam';
			var sUsernameFieldName	= 'gebruikersnaam';
		}
		else if(sSelectedCms == 'siteconnect3')
		{
			var sFormAction 		= 'http:\/\/cms.siteconnect3.nl/auth/login/';
			var sCustomerFieldName 	= 'domain';
			var sUsernameFieldName	= 'username';
		}
		else
		{
			var sFormAction 		= 'http:\/\/login.flexscreen.nl/auth/login/';
			var sCustomerFieldName 	= 'customername';
			var sUsernameFieldName	= 'username';
		}

		$oForm = $('form.loginform');
		$oForm.attr('action',sFormAction);
		$oForm.find('input.domain').attr('name', sCustomerFieldName);
		$oForm.find('input.username').attr('name', sUsernameFieldName);
		$oForm.submit();
	});

	$('select[name="cms"]').change(function()
	{
		var sSelectedCms = $(this).find('option:selected').val();
		if(sSelectedCms == 'flexscreen')
		{
			$('form.loginform table tr:first td').html('Klant');
		}
		else
		{
			$('form.loginform table tr:first td').html('Website');
		}
	});

	$('div#news li a').click(function()
	{
		window.location = $(this).attr('href');
	});

	$.extend($.validator.messages, {
        required: "Dit veld is verplicht",
        email: "Voer een geldig e-mail adres in"
    });

	$('#loginsiteconnect2').validate(
	{
		errorClass: 'jqerror'
	});
	$('#newslettersignup').validate(
	{
		errorLabelContainer: '#newslettererror',
		errorClass: 'jqerror'
	});

	$('#checkdomain').validate(
	{
		errorLabelContainer : '#checkdomainerror',
		errorClass: 'jqerror'
	});

	//var logintype = getCookie('logintype');
	var logintype = cookie.get('logintype');

    $('#domainname').focus();

	$('#loginsiteconnect2, #loginsiteconnect3, #loginflexscreen, label.loginsitename').hide();

	if (logintype !== null)
	{
		$('#'+logintype).show();
		$('option[value="'+logintype+'"]').attr("selected","selected");
	}

    ////
    // Hosting
    ////

    //top navigation hover event
    $('ul.hosting-steps2 li').hover(function(){
        if($(this).find('a').length > 0){
            $(this).css('cursor','pointer');
            $(this).find('a').css('text-decoration','underline');
        }
    },function(){
        $(this).css('cursor','default');
        $(this).find('a').css('text-decoration','none');
    });

    //top navigation click event
    $('ul.hosting-steps2 li').click(function(){
        if($(this).find('a').length > 0){
            gotolink = $(this).find('a').attr('href');
            if(gotolink.substr(0,7) == 'http://')
            {
                window.location.href = gotolink;
            }
            else
            {
                window.location.href = 'http://' + window.location.href.split('/')[2] + gotolink;
            }

        }
    });

    //cursor on links
    $('form.hostingform a').live('mouseover',function(){
        $(this).css('cursor','pointer');
    });
    $('form.hostingform a').live('mouseout',function(){
        $(this).css('cursor','default');
    });


    ////
    // Niews
    ////

	$('ul.paging li').click(function()
	{
		location.href = $(this).find('a').attr('href');
	});

    ////
    // Step 1: Domainname
    ////

    //check domain on page ready
    if($('#domainname').length > 0 && $('#domainname').val() != ''){
        checkdomain();
    }

    //check domain availability and show results
    $('form.hostingform a.checkavailability').click(function(){
        checkdomain();
    });

    //enter key event
    $('input#domainname, input#domainextension').each(function(){
        $(this).attr('onKeyPress','return submitcheck(this,event)');
    });

    //update cost/year for domain
    $('form.hostingform td.domainperiod select.domainperiodselect').livequery("change",function(){

        var aPeriodPrice = $(this).find('option:selected').attr('value').split(':');
        $(this).parent().parent().find('td.domainprice').html('&euro; ' + addSeparatorsNF(aPeriodPrice[1], '.', ',', '.',true));
    });

    //update cost/year for domain
    $('form.hostingform select.domainperiodselect2').livequery("change",function(){
        var aPeriodPrice = $(this).find('option:selected').attr('value').split(':');
        $(this).parent().parent().find('span.domainprice').html('&euro; ' + addSeparatorsNF(aPeriodPrice[1], '.', ',', '.',true));
    });

    //add domain to shopping cart
    $('form.hostingform a.adddomain, form.hostingform a.movedomain').live("click",function(){
        var $tablerow = $(this).parent().parent();
        var sDomainname = $tablerow.find('td.domainname').text();
        var aDomainPeriodPrice = $tablerow.find('select.domainperiodselect option:selected').attr('value').split(':');
        var iDomainPeriod = aDomainPeriodPrice[0];
        var iDomainPrice = aDomainPeriodPrice[1];
        var sDomainStatus = $tablerow.find('td.domainavailable img').attr('alt');
        if(sDomainStatus == 'beschikbaar'){
            sStatusImg = '<img src="/img/hostingadd.png" alt="Nieuwe domeinnaam registratie" title="Nieuwe domeinnaam registratie" />';
        }else{
            sStatusImg = '<img src="/img/hostingmove.png" alt="Domeinnaam wordt verhuisd" title="Domeinnaam wordt verhuisd" />';
        }

        $.ajax({
            type: "POST",
            url: "/ajax/sessionhandler.php",
            data: "adddomain=" + sDomainname + "&addperiod=" + iDomainPeriod + "&addstatus=" + sDomainStatus,
            success: function(response){
                if(response == 'ok')
                {
                    $tablerow.find('td.domainperiod, td.domainprice, td.domainadd, td.domainmove').fadeOut(500, function(){
                        $tablerow.find('td.domainstatus').html('toegevoegd').fadeIn(1000);
                    });
                    $('.shoppingcart').fadeIn(1000);
                    var iCountRows =  $('table.shoppingcart tr').length;
                    var sClassName = '';

                    if(iCountRows%2)
                    {
                    	sClassName = 'even';
                    }
                    else
                    {
                    	sClassName = 'odd';
                    }

                    $('table.shoppingcart').append('<tr class="' + sClassName + '" style="display: none;"><td class="domainavailable">' + sStatusImg + '<td class="domainname">' + sDomainname + '</td><td>' + iDomainPeriod + ' jaar</td><td>&euro; ' + iDomainPrice + '</td><td><a class="removedomain"><img src="/img/hostingremove.png" /> verwijder</a></td></tr>');
                    $('table.shoppingcart tr').fadeIn(1000);
                    $('div.shoppingcartstatus').fadeOut(500);
                    $('div.shoppingcartstatus').remove();
                    $('a.nextstep').fadeIn(1000);
                    resetHeight();
                }
            }
        });
    });


    //remove domain from shopping cart
    $('form.hostingform a.removedomain').live("click",function(){
        var $tablerow = $(this).parent().parent();
        var sDomainname = $tablerow.find('td.domainname').text();

        $.ajax({
            type: "POST",
            url: "/ajax/sessionhandler.php",
            data: "removedomain=" + sDomainname,
            success: function(response){
                if(response == 'ok')
                {
                    $('td.domainname').each(function(){ //loop through other extensions
                        if($(this).text() == sDomainname)                           //check if extension equals domainname to remove
                        {
                            var $tablerow = $(this).parent();

                            $tablerow.find('td.domainstatus').fadeOut(500, function(){
                                $tablerow.find('td.domainperiod, td.domainprice, td.domainadd').fadeIn(1000);
                                if($tablerow.find('td.domainavailable img').attr('alt') == "niet beschikbaar"){
                                    $tablerow.find('td.domainmove').show();
                                    $tablerow.find('td.domainstatus').html('niet beschikbaar');
                                }
                            });
                        }
                    });


                    $tablerow.remove();

                    //check if shopping cart is empty
                    if($('table.shoppingcart tr').length < 2)
                    {
                        $('a.nextstep').fadeOut(500);
                        $('table.shoppingcart').fadeOut(500, function(){
                            $('div.shoppingcart').append('<div class="shoppingcartstatus" style="display: none">Uw winkelmandje is leeg</div>');
                            $('div.shoppingcartstatus').fadeIn(1000);
                        });
                    }
                    else
                	{
                		var iCount = 0;
                		$('table.shoppingcart tr').each(function()
                		{
                			if(iCount != 0)
                			{
	                			if(iCount%2)
	                			{
		                			$(this).attr('class','even');
		                		}
		                		else
								{
									$(this).attr('class','odd');
								}
							}
							iCount++;
                		});
                	}
                    resetHeight();
                }

            }
        });
    });


    //show move domain warning message on
    $('form.hostingform a.movedomain').live('mouseover',function(){
        var relpos = $(this).position();
        $(this).append('<div class="tooltip">U kunt een domeinnaam alleen verhuizen indien deze op uw naam geregistreerd staat.</div>');
        $(this).find('.tooltip').css({left: relpos.left-10, top: relpos.top+20});
        $('.tooltip').fadeIn(300);
    });

    $('form.hostingform a.movedomain').live('mouseout',function(){
        $('.tooltip').fadeOut(100);
        $(this).children('div').remove();
    });


    ////
    // Step 2: Hosting package
    ////

    //transfer package radio button click event to parent
    $('div.hostingdetails input[type=radio]').click(function(){
        $(this).parent().click();
    });

    //package choice click event
    $('table.hostingdetails td:not(.hostingitem), div.colredirect, div.colnohosting').click(function(){

        $('a.nextstep').fadeIn(500);

        //reset background colors
        $('.hostingdetails th').each(function(){
            if($(this).attr('class')){
                $('.'+$(this).attr('class')).css({'background-color':'', 'color' : '#000000'});
            }
        });
        $('.colredirect').css({'background-color':'', 'color' : '#000000'});
        $('.colnohosting').css({'background-color':'', 'color' : '#000000'});


        $('.' + $(this).attr('class')).css({'background-color':'#00a0da', 'color' : '#FFFFFF'});

        $('.packagechoice').removeAttr('checked');
        $('.packagechoice').filter('[value=' + $(this).attr('class').substring(3) + ']').attr('checked', true);

        var chosenPackage;



        if($(this).attr('class') == 'colredirect'){
            chosenPackage = 'redirect';

            $('#spamfilter').removeAttr('disabled');

            $('div.spamfilter table.shoppingcart').hide();
            $('div.spamfiltercheckboxes').show();

            $('.premiumdiscount, .maindomain, .extraftpuserbox').slideUp(500);

            $('.orderoptions, .pop3accountbox').slideDown(500,function(){
                resetHeight();
            });

            $('.redirect').slideDown(500,function(){
                resetHeight();
                applyNoHostingSpamfilterPrices();
            });

            if(countSelectedSpamfilterUsers() == 0){
                $('input#spamfilter').removeAttr('checked');
                $('input.spamfilter').next('label').css({'color':'black','font-weight':'normal'});
                $('div.spamfilter').slideUp(500);
            }

            if($('#pop3account').is(':checked')){
                $('#spamfilter').removeAttr('disabled');
            }else{
                $('#spamfilter').attr('disabled', true);
                $('#spamfilter').removeAttr('checked');
                $('div.spamfilter').slideUp(500);
            }

        }else if($(this).attr('class') == 'colnohosting'){
            chosenPackage = 'nohosting';

            $('.redirect, '
            //+ '.orderoptions, '
            + '.premiumdiscount, '
            + '.maindomain, '
            + '.extraftpuserbox').slideUp(500);

            $('div.spamfilter table.shoppingcart').hide();
            $('div.spamfiltercheckboxes').show();

            $('.orderoptions, .pop3accountbox').slideDown(500,function(){
                resetHeight();
                applyNoHostingSpamfilterPrices();
            });

            if($('#pop3account').is(':checked')){
                $('#spamfilter').removeAttr('disabled');
            }else{
                $('#spamfilter').attr('disabled', true);
                $('#spamfilter').removeAttr('checked');
                $('div.spamfilter').slideUp(500);
            }

            if(countSelectedSpamfilterUsers() == 0){
                $('input#spamfilter').removeAttr('checked');
                $('input.spamfilter').next('label').css({'color':'black','font-weight':'normal'});
                $('div.spamfilter').slideUp(500);
            }

        }else{

            $('#spamfilter').removeAttr('disabled');

            $('div.spamfilter table.shoppingcart').show();
            $('div.spamfiltercheckboxes').hide();


            $('.redirect, .pop3accountbox').slideUp(500);

            $('.orderoptions').slideDown(500,function(){
                resetHeight();
            });

            if($('.maindomainselect option').length > 1){
                $('div.maindomain').slideDown(500,function(){
                    applyMainDomain();
                    resetHeight();
                });
            }

            var $colclass = $(this).attr('class');
            chosenPackage = $('th.' + $colclass).text();

            $('.hostingdetails').find('.hostingitem').each(function(){

                if($(this).text() == 'FTP accounts'){
                    var ftpaccounts = $(this).parent().find('.' + $colclass).text();
                    if(isNaN(ftpaccounts)){
                        $('.extraftpuserbox').slideUp(500);
                    }else{
                        $('.extraftpuserbox').slideDown(500,function(){
                            resetHeight();
                        });
                    }
                }

                if($(this).text() == 'Spamfilter'){
                    var spamfiltertype = $(this).parent().find('.' + $colclass).text();
                    if(spamfiltertype == 'premium'){
                        //apply spamfilter discount
                        bSpamfilterDiscount = true;
                        $('input.spamfilter').attr('checked',true);

                        $('div.spamfilter').slideDown(500,function(){
                            $('div.premiumdiscount').slideDown(500,function(){
                                resetHeight();
                            });
                            applySpamfilterDiscount();
                        });
                        $('div.spamfilter').find('td.domainname').each(function(){
                            var tempDomainName = $(this).text();
                            var tempDomainTd = $(this);
                            var tempDiscountSelect = $('select.discountselect option:selected').attr('value');
                            if(tempDomainName == tempDiscountSelect){
                                var aDiscountPeriodPrice = $(this).parent().find('select.spamfilteruserselect option:selected').attr('value').split(':');
                                iDiscountUsers = aDiscountPeriodPrice[0];
                            }
                        });

                        if(iDiscountUsers == 0 && countSelectedSpamfilterUsers() > 0){

                            $('select.discountselect option[value="' + $('select.spamfilteruserselect option:selected:not([value^=0]):first').parents('tr').find('td.domainname:first').text() + '"]').attr('selected', 'selected');
                            applySpamfilterDiscount();
                        }

                    }else{
                        var iCount = countSelectedSpamfilterUsers();
                        if(iCount == 0){
                            $('input#spamfilter').removeAttr('checked');
                            $('input.spamfilter').next('label').css({'color':'black','font-weight':'normal'});
                            $('div.spamfilter').slideUp(500);
                        }
                        bSpamfilterDiscount = false;
                        $('.premiumdiscount').slideUp(500);
                        resetSpamfilterPrices();
                    }
                }
            });
        }

        $.ajax({
            type: "POST",
            url: "/ajax/sessionhandler.php",
            data: "package=" + chosenPackage
        });


    });

    //package choice hover event
    $('table.hostingdetails td:not(.hostingitem), div.colredirect, div.colnohosting').hover(function(){
        $(this).css('cursor','pointer');
    },function(){
        $(this).css('cursor','default');
    });

    $('select.discountselect').livequery("change",function(){
        applySpamfilterDiscount();
    });

    $('select.maindomainselect').livequery("change",function(){
        applyMainDomain();
    });

    $('#extraftpusertext').change(function(){
        var extraftpusers = 0;
        if(parseInt($(this).val()) > 0){
            extraftpusers = parseInt($(this).val());
        }

        if($(this).val() != ''){
            $('#extraftpuser').attr('checked','checked');
            $.ajax({
                type: "POST",
                url: "/ajax/sessionhandler.php",
                data: "extraftpuser=" + extraftpusers + "&extraftpuserapply=yes"
            });
        }else{
            $('#extraftpuser').removeAttr('checked');
            $.ajax({
                type: "POST",
                url: "/ajax/sessionhandler.php",
                data: "extraftpuser=" + extraftpusers + "&extraftpuserapply=no"
            });

        }
    });

    $('#extraftpuser').change(function(){
        var extraftpusers = 0;
        if(parseInt($('#extraftpusertext').val()) > 0){
            extraftpusers = parseInt($('#extraftpusertext').val());
        }
        if($(this).is(':checked')){
            $.ajax({
                type: "POST",
                url: "/ajax/sessionhandler.php",
                data: "extraftpuser=" + extraftpusers + "&extraftpuserapply=yes"
            });
        }else{
            $.ajax({
                type: "POST",
                url: "/ajax/sessionhandler.php",
                data: "extraftpuser=" + extraftpusers + "&extraftpuserapply=no"
            });
        }
    });

    $('a.showmore').live('click',function(){
        var $link = $(this);
        $('.hideable').each(function(){
            var tr = $(this);
            tr.children('td').each(function(){
                if($(this).find('div').length == 0){
                    $(this).wrapInner("<div style='display: none'></div>");
                }
                tr.show();
                $(this).children('div').slideDown(500);
            });
        });
        setTimeout("resetHeight()",1200);
        $link.removeClass('showmore');
        $link.addClass('showless');
        $link.text('Verberg gegevens');

		//Fix for jagged border
		$('table.hostingdetails th, table.hostingdetails td').css({'border-right' : '0px'});
		setTimeout(function()
		{
        	$('table.hostingdetails th, table.hostingdetails td').css({'border-right' : '1px dotted #3D99D5'});
        }, 1);
    });

    $('a.showless').live('click',function(){
        var $link = $(this);
        $('.hideable').each(function(){
            var tr = $(this);
            tr.children('td').each(function(){
                if($(this).find('div').length == 0){
                    $(this).wrapInner("<div></div>");
                }
                $(this).children('div').slideUp(500,function(){
                    tr.hide();
                });
            });
        });
        $link.removeClass('showless');
        $link.addClass('showmore');
        $link.text('Toon meer gegevens');
    });

    //spamfilter checkbox
    $('input.spamfilter').click(function(){
        if($('input.spamfilter:checked').length > 0){

            $('div.spamfilter').slideDown(500,function(){
                resetHeight();
            });
        }else{
            $('input.spamfilter').next('label').css({'color':'black','font-weight':'normal'});
            $('div.spamfilter').slideUp(500);
        }
    });

    $('div.spamfiltercheckboxes input[type="checkbox"]').click(function(){
        var spamfilterdomainname = $(this).next().text();
        var index = $('div.spamfiltercheckboxes input[type="checkbox"]').index(this);
        if($(this).is(':checked')){
            $.ajax({
                type: "POST",
                url: "/ajax/sessionhandler.php",
                data:   "spamfilterdomainname=" + spamfilterdomainname +
                        "&spamfilterusers=25" +
                        "&spamfilterdiscount=" + $('select.discountselect option:selected').attr('value')
            });

            //remove selected from all options of this select
            $('select.spamfilteruserselect:eq(' + index + ') option').removeAttr('selected');

            //select option with value 25
            $('select.spamfilteruserselect:eq(' + index + ') option[value^="25:"]').attr('selected', true);

        }else{
            $.ajax({
                type: "POST",
                url: "/ajax/sessionhandler.php",
                data:   "spamfilterdomainname=" + spamfilterdomainname +
                        "&spamfilterusers=0" +
                        "&spamfilterdiscount=" + $('select.discountselect option:selected').attr('value')
            });

            //remove selected from all options of this select
            $('select.spamfilteruserselect:eq(' + index + ') option').removeAttr('selected');

            //select option with value 25
            $('select.spamfilteruserselect:eq(' + index + ') option[value^="25:"]').attr('selected', true);
        }
    });

    $('input.pop3account').click(function(){
        if($('input.pop3account:checked').length > 0){

            $('div.pop3account').slideDown(500,function(){
                resetHeight();
            });

            var countPop3Accounts = 0;
            $('.pop3accountselect option:selected').each(function(){
                if($.trim($(this).attr('value').split(':')[0]) != '0'){
                    countPop3Accounts++;
                }
            });
            if(countPop3Accounts > 0){
                $('#spamfilter').removeAttr('disabled');
            }
        }else{
            $('input.pop3account').next('label').css({'color':'black','font-weight':'normal'});
            $('div.pop3account').slideUp(500);
            //if($('.packagechoice:checked').attr('value') == "nohosting"){
                $('#spamfilter').attr('disabled', true);
                $('#spamfilter').removeAttr('checked');
                $('div.spamfilter').slideUp(500);
            //}

        }
    });


    //update cost/year for pop3accounts
    $('select.pop3accountselect').livequery("change",function(){
        var $pop3accountselect = $(this);

        var countPop3Accounts = 0;

        $('.pop3accountselect option:selected').each(function(){
            if($.trim($(this).attr('value').split(':')[0]) != '0'){
                countPop3Accounts++;
            }
        });
        if(countPop3Accounts == 0){
            $('#pop3account').next('label').css({'color':'red','font-weight':'bold'});
            $('#spamfilter').attr('disabled', true).removeAttr('checked');
            $('div.spamfilter').slideUp(500);
        }else{
            $('#pop3account').next('label').css({'color':'black','font-weight':'normal'});
        }

        if(countPop3Accounts > 0){
            $('#spamfilter').removeAttr('disabled');
        }

        var aPeriodPrice = $(this).find('option:selected').attr('value').split(':');

        var pop3domainname = $(this).parent().parent().find('td.domainname').text();

        $.ajax({
            type: "POST",
            url: "/ajax/sessionhandler.php",
            data:   "pop3domainname=" + pop3domainname +
                    "&pop3accounts=" + $.trim(aPeriodPrice[0])
        });
        $pop3accountselect.parent().parent().find('td.pop3accountprice').html('&euro; ' + addSeparatorsNF(aPeriodPrice[1], '.', ',', '.',true));

        var index = $('select.pop3accountselect').index(this);
        if(aPeriodPrice[0] == 0 && ($('.packagechoice:checked').val() == 'nohosting' || $('.packagechoice:checked').val() == 'redirect')){
            $('div.spamfiltercheckboxes input[type="checkbox"]:eq(' + index + ')').attr('disabled', true).removeAttr('checked');
        }else{
            //var index = $('select.pop3accountselect').index(this);
            $('div.spamfiltercheckboxes input[type="checkbox"]:eq(' + index + ')').removeAttr('disabled');
        }
    });

    //update cost/year for spamfilter users
    $('select.spamfilteruserselect').livequery("change",function(){
        var $spamfilteruserselect = $(this);
        var iDiscountUsers = 0;

        var countSpamfilterAccounts = 0;

        $('.spamfilteruserselect option:selected').each(function(){
            if($.trim($(this).attr('value').split(':')[0]) != '0'){
                countSpamfilterAccounts++;
            }
        });
        if(countSpamfilterAccounts == 0){
            $('#spamfilter').next('label').css({'color':'red','font-weight':'bold'});
        }else{
            $('#spamfilter').next('label').css({'color':'black','font-weight':'normal'});
        }


        if(bSpamfilterDiscount == true){

            $('div.spamfilter').find('td.domainname').each(function(){
                var tempDomainName = $(this).text();
                var tempDomainTd = $(this);
                var tempDiscountSelect = $('select.discountselect option:selected').attr('value');
                if(tempDomainName == tempDiscountSelect){
                    var aDiscountPeriodPrice = $(this).parent().find('select.spamfilteruserselect option:selected').attr('value').split(':');
                    iDiscountUsers = aDiscountPeriodPrice[0];
                }
            });

            if(($('select.discountselect option:selected').attr('value') != $(this).parent().parent().find('td.domainname').text()) && (iDiscountUsers == 0)){
                $('select.discountselect option[value="' + $(this).parent().parent().find('td.domainname').text() + '"]').attr('selected', 'selected');
                applySpamfilterDiscount();
            }
        }
        var aPeriodPrice = $(this).find('option:selected').attr('value').split(':');

        var spamfilterdomainname = $(this).parent().parent().find('td.domainname').text();

        $.ajax({
            type: "POST",
            url: "/ajax/sessionhandler.php",
            data:   "spamfilterdomainname=" + spamfilterdomainname +
                    "&spamfilterusers=" + $.trim(aPeriodPrice[0]) +
                    "&spamfilterdiscount=" + $('select.discountselect option:selected').attr('value')
        });
        $spamfilteruserselect.parent().parent().find('td.spamfilterprice').html('&euro; ' + addSeparatorsNF(aPeriodPrice[1], '.', ',', '.',true));

        var index = $('select.spamfilteruserselect').index(this);
        if($.trim(aPeriodPrice[0]) == 0){
            $('div.spamfiltercheckboxes input[type="checkbox"]:eq(' + index + ')').removeAttr('checked');
        }else{
            $('div.spamfiltercheckboxes input[type="checkbox"]:eq(' + index + '):not("[disabled]"').attr('checked', true);
        }

    });

    //expand / collapse administrative contact
    $('input#otherthandomainnameholder').click(function(){
        if($(this).is(":checked")){
            $('div.administrative').slideDown(500, function(){
                resetHeight();
            });
        }else{
            $('div.administrative').slideUp(500);
        }
    });

    //expand / collapse invoice contact
    $('input#otherthanaddress').click(function(){
        if($(this).is(":checked")){
            $('div.invoice').slideDown(500, function(){
                resetHeight();
            });
        }else{
            $('div.invoice').slideUp(500);
        }
    });

    //goto step 3
    $('form#hostingpackageform a.nextstep').click(function(){
        var sData = "redirectdetails=yes";

        var error = false;
        if($('input.packagechoice[value=redirect]').is(':checked')){
            var validUrl = /^(http|https|ftp|sftp):\/\/[A-Za-z0-9-]+\.[A-Za-z0-9]+/i;
            $('form#hostingpackageform div.redirect input').each(function(){
                if(!validUrl.test($(this).val())) {
                    $(this).next('label').fadeIn(500);
                    error = true;
                }else{
                    $(this).next('label').hide();
                }
            });
        }
        $('form#hostingpackageform div.redirect input').each(function(){
            sData += '&' + $(this).attr('name') + '=' + escape($(this).val());
        });

        if($('#extraftpuser').is(":checked") && $('.extraftpuserbox').css('display') != 'none' && $('.orderoptions').css('display') != 'none'){
            if( (parseInt($('#extraftpusertext').val()) < 1) || isNaN( parseInt( $('#extraftpusertext').val() ) ) ){
                $('#extraftpuser').next('label').css({'color':'red','font-weight':'bold'}).next('label').css({'color':'red','font-weight':'bold'});
                error = true;
            }else{
                $('#extraftpuser').next('label').css({'color':'black','font-weight':'normal'}).next('label').css({'color':'black','font-weight':'normal'});
            }
        }
        if($('#spamfilter').is(":checked") && $('.orderoptions')){
            var countSpamfilterAccounts = 0;

            if($('div.spamfiltercheckboxes').is(":visible")){
                countSpamfilterAccounts = $('div.spamfiltercheckboxes input[type="checkbox"]:checked').length;
            }else{
                $('.spamfilteruserselect option:selected:not("[disabled]")').each(function(){
                    if($.trim($(this).attr('value').split(':')[0]) != '0'){
                        countSpamfilterAccounts++;
                    }
                });
            }
            if(countSpamfilterAccounts == 0){
                $('#spamfilter').removeAttr('checked');
                $('div.spamfilter').slideUp(500);
                $('#spamfilter').next('label').css({'color':'black','font-weight':'normal'});
                sData += '&spamfilter=no';
            }else{
                sData += '&spamfilter=yes';
            }
        }else{
            sData += '&spamfilter=no';
        }

        if($('#pop3account').is(":checked")){
            var countPop3Accounts = 0;

            $('.pop3accountselect option:selected').each(function(){
                if($.trim($(this).attr('value').split(':')[0]) != '0'){
                    countPop3Accounts++;
                }
            });
            if(countPop3Accounts == 0){
                $('#pop3account').removeAttr('checked');
                $('div.pop3account').slideUp(500);
                $('#pop3account').next('label').css({'color':'black','font-weight':'normal'});
                sData += '&pop3account=no';
            }else{
                sData += '&pop3account=yes';
            }
        }else{
            sData += '&pop3account=no';
        }

        if(error == true){
            return false;
        }
        $.ajax({
            type: "POST",
            url: "/ajax/sessionhandler.php",
            data: sData,
            success: function(response){
                if(response == 'ok')
                {
                    window.location.href = 'http://' + window.location.href.split('/')[2] + '/bestelhosting/gegevens';
                }
            }
        });
    });

    //goto step 1
    $('form#hostingpackageform a.previousstep').click(function(){
        var sData = "redirectdetails=yes";

        $('form#hostingpackageform div.redirect input').each(function(){
            sData += '&' + $(this).attr('name') + '=' + $(this).val();
        });
        if($('#spamfilter').is(":checked")){
            sData += '&spamfilter=yes';
        }else{
            sData += '&spamfilter=no';
        }
        if($('#pop3account').is(":checked")){
            sData += '&pop3account=yes';
        }else{
            sData += '&pop3account=no';
        }

        $.ajax({
            type: "POST",
            url: "/ajax/sessionhandler.php",
            data: sData,
            success: function(response){
                if(response == 'ok')
                {
                    window.location.href = 'http://' + window.location.href.split('/')[2] + '/bestelhosting/domeinnaam';
                }
            }
        });
    });


    ////
    // Step 3: Personal data
    ////

    $('input#otherthandomainnameholder').click(function(){
        if($(this).is(":checked")){
            $('div.administrative').slideDown(500, function(){
                resetHeight();
            });
        }else{
            $('div.administrative').slideUp(500);
        }
    });

    $('input#otherthanaddress').click(function(){
        if($(this).is(":checked")){
            $('div.invoice').slideDown(500, function(){
                resetHeight();
            });
        }else{
            $('div.invoice').slideUp(500);
        }
    });


    $('form#personaldetailsform a.previousstep').click(function(){
        var sData = "personaldetails=yes";

        sData += "&contact[gender]=" + $('#gender option:selected').attr('value');
        sData += "&administrative[gender]=" + $('#administrativegender option:selected').attr('value');
        sData += "&invoice[gender]=" + $('#invoicegender option:selected').attr('value');

        if($('#otherthandomainnameholder').is(':checked')){
            sData += "&alternativeadministrative=yes";
        }else{
            sData += "&alternativeadministrative=no";
        }
        if($('#otherthanaddress').is(':checked')){
            sData += "&alternativeinvoice=yes";
        }else{
            sData += "&alternativeinvoice=no";
        }

        $('form#personaldetailsform input').each(function(){
            if($(this).attr('name').search('telephone') > -1){
                sData += '&' + $(this).attr('name') + '=' + encodeURIComponent($(this).val());
            }else{
                sData += '&' + $(this).attr('name') + '=' + SpecialChars.encode($(this).val());
            }

        });

        $.ajax({
            type: "POST",
            url: "/ajax/sessionhandler.php",
            data: sData,
            success: function(response){
                if(response == 'ok')
                {
                    window.location.href = 'http://' + window.location.href.split('/')[2] + '/bestelhosting/hosting';
                }
            }
        });
    });

    $('form#personaldetailsform a.nextstep').click(function(){

        $form = $("form#personaldetailsform");
        $form.removeClass('error');
        $form.find(".domainnameholder input[type=text],textarea").each(function() {
            var $field = $(this);
            var $label = $field.closest('tr').find('label');

            // required fields
            if ($label.html().toString().indexOf('*') > -1) {
                var error = false;
                switch ($field.attr('name')) {
                    case "contact[email]":
                        var filter = /^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i
                        if (!filter.test($field.val())) {
                            error = true;
                        }
                        break;

                    case "contact[zipcode]":
                        var filter = /^[1-9]\d{3}[A-Z]{2}$/;
                        var zipcode = $field.val().toUpperCase().split(' ').join('')
                        if (!filter.test(zipcode)) {
                            error = true;
                        }else{
                            $field.val(zipcode.substr(0, 4) + ' ' + zipcode.substr(4, 2))
                        }
                        break;

                    case "contact[telephone]":
                        var filter = /^((\+\d)?)([0-9]{10}|[0-9]{2}\-[0-9]{8}|[0-9]{3}\-[0-9]{7}|[0-9]{4}\-[0-9]{6})$/;
                        var phone = $field.val().toUpperCase().split(' ').join('')
                        if (!filter.test(phone)) {
                            error = true;
                        }else{

                            $field.val(phone)
                        }
                        break;

                    case "contact[housenumber]":
                            var filter = /^[0-9]+$/;
                            var housenumber = $field.val().toUpperCase().split(' ').join('');
                            if (!filter.test(housenumber)) {
                                error = true;
                            }else{

                                $field.val(housenumber)
                            }
                            break;

                    case "contact[lastname]":
                            var filter = /^[^0-9]+$/;
                            var lastname = $field.val();
                            if (!filter.test(lastname)) {
                                error = true;
                            }else{

                                $field.val(lastname)
                            }
                            break;

                    case "contact[bankaccount]":
                            var filter = /^[0-9]+$/;
                            var bankaccount = $field.val().replace(/\D/g,'');
                            if (!filter.test(bankaccount)) {
                                error = true;
                            }else{

                                $field.val(bankaccount)
                            }
                            break;

                    default:
                        if($.trim($field.val()).length == 0)
                        {
                            error = true;
                        }

                }
                if (error) {

                    $label.addClass('error');
                    $form.addClass('error');
                } else {
                    $label.removeClass('error');
                }
            }
        });

       /**
        * Rewrite initials
        */

        $('input.initials').each(function(){
            var sInitials = $.trim($(this).val());
            $(this).val(rewrite_initials(sInitials));
        });

        if($('#otherthandomainnameholder').is(':checked')){
            $form.find(".domainnameadministrative input[type=text]").each(function() {
                var $field = $(this);
                var $label = $field.closest('tr').find('label');

                /* required fields */
                if ($label.html().toString().indexOf('*') > -1) {
                    var error = false;
                    switch ($field.attr('name')) {
                        case "administrative[email]":
                            var filter = /^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i
                            if (!filter.test($field.val())) {
                                error = true;
                            }
                            break;

                        case "administrative[telephone]":
                            var filter = /^((\+\d)?)([0-9]{10}|[0-9]{2}\-[0-9]{8}|[0-9]{3}\-[0-9]{7}|[0-9]{4}\-[0-9]{6})$/;
                            var phone = $field.val().toUpperCase().split(' ').join('');
                            if (!filter.test(phone)) {
                                error = true;
                            }else{

                                $field.val(phone)
                            }
                            break;

                        case "administrative[lastname]":
                            var filter = /^[^0-9]+$/;
                            var lastname = $field.val();
                            if (!filter.test(lastname)) {
                                error = true;
                            }else{

                                $field.val(lastname)
                            }
                            break;


                        default:
                            if($.trim($field.val()).length == 0)
                            {
                                error = true;
                            }

                    }
                    if (error) {
                        $label.addClass('error');
                        $form.addClass('error');
                    } else {
                        $label.removeClass('error');
                    }
                }
            });
        }

        if($('#otherthanaddress').is(':checked')){
            $form.find(".domainnameinvoice input[type=text]").each(function() {
                var $field = $(this);
                var $label = $field.closest('tr').find('label');

                /* required fields */
                if ($label.html().toString().indexOf('*') > -1) {
                    var error = false;
                    switch ($field.attr('name')) {
                        case "invoice[email]":
                            var filter = /^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i
                            if (!filter.test($field.val())) {
                                error = true;
                            }
                            break;

                        case "invoice[zipcode]":
                            var filter = /^[1-9]\d{3}[A-Z]{2}$/;
                            var zipcode = $field.val().toUpperCase().split(' ').join('');
                            if (!filter.test(zipcode)) {
                                error = true;
                            }else{
                                $field.val(zipcode.substr(0, 4) + ' ' + zipcode.substr(4, 2))
                            }
                            break;

                        case "invoice[housenumber]":
                            var filter = /^[0-9]+$/;
                            var housenumber = $field.val().toUpperCase().split(' ').join('');
                            if (!filter.test(housenumber)) {
                                error = true;
                            }else{

                                $field.val(housenumber)
                            }
                            break;

                        default:
                            if($.trim($field.val()).length == 0)
                            {
                                error = true;
                            }

                    }
                    if (error) {
                        $label.addClass('error');
                        $form.addClass('error');
                    } else {
                        $label.removeClass('error');
                    }
                }
            });
        }

        if ($form.hasClass('error')) {
            return false;
        }else{

            var sData = "personaldetails=yes";

            sData += "&contact[gender]=" + $('#gender option:selected').attr('value');
            sData += "&administrative[gender]=" + $('#administrativegender option:selected').attr('value');
            sData += "&invoice[gender]=" + $('#invoicegender option:selected').attr('value');

            if($('#otherthandomainnameholder').is(':checked')){
                sData += "&alternativeadministrative=yes";
            }else{
                sData += "&alternativeadministrative=no";
            }
            if($('#otherthanaddress').is(':checked')){
                sData += "&alternativeinvoice=yes";
            }else{
                sData += "&alternativeinvoice=no";
            }


            $('form#personaldetailsform input').each(function(){
                if($(this).attr('name').search('telephone') > -1){
                    sData += '&' + $(this).attr('name') + '=' + encodeURIComponent($(this).val());
                }else{
                    sData += '&' + $(this).attr('name') + '=' + SpecialChars.encode($(this).val());
                }
            });

            $.ajax({
                type: "POST",
                url: "/ajax/sessionhandler.php",
                data: sData,
                success: function(response){
                    if(response == 'ok')
                    {
                        window.location.href = 'http://' + window.location.href.split('/')[2] + '/bestelhosting/controle';
                    }
                }
            });
        }
    });

    ////
    // Step 4: Check data
    ////

    //check terms of use
    $('a.finalstep').click(function(){
        if($('#termsofuse').is(':checked')){
            $('#termsofuse').next('label').css({'color':'black','font-weight':'normal'});

            if($('div.captcha').length){
                $('#captchaerror').hide();

                var url = 'http://' + window.location.href.split('/')[2] + '/bestelhosting/bevestiging';
                var sData = 'captcha_code=' + $('#captchacode').val();

                $.ajax({
                    type: "POST",
                    url: "/ajax/captchacheck.php",
                    data: sData,
                    success: function(response){
                        if(response == 'ok'){
                            window.location.href = url + '/?captcha_code=' + $('#captchacode').val();
                        }else{
                            document.getElementById('captcha').src = '/phpcaptcha/securimage_show.php?' + Math.random();
                            $('#captchacode').val('');
                            $('#captchaerror').show();
                        }
                    }
                });
            }else{
                window.location.href = 'http://' + window.location.href.split('/')[2] + '/bestelhosting/bevestiging/?captcha_code=' + $('#captchacode').val();
            }

        }else{
            $('#termsofuse').next('label').css({'color':'red','font-weight':'bold'});
        }
    });

    ////
    // Hosting END
    ////

    //change contactform links to buttons
    $('#col-center a').each(function(){
        if($(this).attr('href'))
        {
            var link = $(this).attr('href');
            if(link.search('/contactform/') > -1)
            {
                //exclude img links
                if($(this).children('img').size() == 0){
                    $(this).addClass('contact-button');
                }
            }
        }
    });

    //submit with enter
    $('div.menu-right-container input').each(function(){
        if($(this).attr('type'))
        {
            if($(this).attr('type') == "password")
            {
                $(this).attr('onKeyPress','return submitenter(this,event)');
            }
        }
    });

    //portfolio / news hover event
    $('ul.thumb li h2,ul.thumb li img').hover(function() {
        $(this).css({'cursor':'pointer','color':'#2F80B5'});
    }, function() {
        $(this).css({'cursor':'default','color':'black'});
    });

    $('ul.thumb li').click(function() {
        gotolink = $(this).find('a').attr('href');
        if(gotolink.substr(0,7) == 'http://')
        {
            window.location.href = gotolink;
        }
        else
        {
            window.location.href = 'http://' + window.location.hostname + gotolink;
        }
    });

    $('a.lightbox').lightBox();
    $('a.overviewImageLightBox').lightBox();

    if($('select#subject option:selected').attr('value'))
    {
        if($('select#subject option:selected').attr('value') != 'other')
        {
            $('form#contactform div#listother').hide();
        }
    }

    $('form#contactform select#subject').change(function(){
        if($('select#subject option:selected').attr('value')){
            if($('select#subject option:selected').attr('value') == 'other'){
                $('div#listother').slideDown('slow');
            }else{
                $('div#listother').slideUp('slow');
            }
        }
    });

    $("form#contactform a.form-button").click(function(){
        $(this).parents('form:first').submit();
    });

    $("a.newsletter-form-button").click(function(){
    	$('form#newsletterform').submit();
    });

    $("form#newsletterform").submit(function(){
        $form = $("form#newsletterform");
        $form.removeClass('error');
        $form.find("input[type=text],textarea").each(function() {
            var $field = $(this);
            var $label = $field.parent().prev('td').find('label');
            if($label.length == 0)
            {
            	$label = $field.prev('label');
            }

            /* required fields */
            if ($label.html().toString().indexOf('*') > -1) {
                var error = false;
                switch ($field.attr('name')) {
                    case "subscription[email]":
                        var filter = /^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i
                        if (!filter.test($field.val())) {
                            error = true;
                        }
                        break;

                    default:
                        if($.trim($field.val()).length == 0)
                        {
                            error = true;
                        }
                }
                if (error) {
                    $label.addClass('error');
                    $form.addClass('error');
                } else {
                    $label.removeClass('error');
                }
            }
        });

        var iCountCheckedCategories = 0;
        $form.find("input.categorycheckbox").each(function() {
            if($(this).attr('checked')){
                iCountCheckedCategories++;
            }
        });

        if(iCountCheckedCategories == 0){
            $('#mailingcategorylistlabel').addClass('error');
            $form.addClass('error');
        }else{
            $('#mailingcategorylistlabel').removeClass('error');
        }

       /**
        * Rewrite initials
        */
        var sInitials = $.trim($('#initials').val());
        $('#initials').val(rewrite_initials(sInitials));


       /**
        * Uppercase first lastname
        */
        if($.trim($('#lastname').val()).length > 0){
            $('#lastname').val($.trim($('#lastname').val()).substr(0, 1).toUpperCase() + $.trim($('#lastname').val()).substr(1));
        }



       /**
        * Rewrite full name
        */
        var name = $.trim($('#initials').val());
        if($.trim($('#tussenvoegsel').val()).length > 0){
            name = name + ' ' + $.trim($('#tussenvoegsel').val());
        }
        name = name + ' ' + $.trim($('#lastname').val());
        $("#recipientname").val(name);


       /**
        * Uppercase first tussenvoegsel
        */
        if($.trim($('#tussenvoegsel').val()).length > 0){
            $('#tussenvoegselucfirst').val($.trim($('#tussenvoegsel').val()).substr(0, 1).toUpperCase() + $.trim($('#tussenvoegsel').val()).substr(1));
        }

        if($('div.captcha').length){
            $('#captchaerror').hide();

            var sData = 'captcha_code=' + $('#captchacode').val();

            var returnValue = false;

            $.ajax({
                type: "POST",
                url: "/ajax/captchacheck.php",
                data: sData,
                async: false,
                success: function(response){
                    if(response != 'ok'){
                        $form.addClass('error');
                        document.getElementById('captcha').src = '/phpcaptcha/securimage_show.php?' + Math.random();
                        $('#captchacode').val('');
                        $('#captchaerror').show();
                        returnValue = false;
                    }else{
                        if ($form.hasClass('error')) {
                            returnValue = false;
                        }else{
                            returnValue = true;
                            //return true;
                        }
                    }
                }
            });
            return returnValue;
        }else{
            if ($form.hasClass('error')) {
                return false;
            }else{
                return true;
            }
        }


    });


    $("form#contactform").submit(function(){
        $form = $("form#contactform");
        $form.removeClass('error');
        $form.find("input[type=text],textarea").each(function() {
            var $field = $(this);

            if($field.attr('id') != 'subjectother')
            {
				if($field.parent().prev().find('label').length == 1)
				{
					var $label = $field.parent().prev().find('label');
				}
				else if($field.prev('label').length == 1)
				{
					var $label = $field.prev('label');
				}
				else
				{
					var $label = $field.prev().prev();
				}

	            /* required fields */
	            if ($label.html().toString().indexOf('*') > -1) {
	                var error = false;
	                switch ($field.attr('name')) {
	                    case "email":
	                        var filter = /^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i
	                        if (!filter.test($field.val())) {
	                            error = true;
	                        }
	                        break;

	                    default:
	                        if($.trim($field.val()).length == 0)
	                        {
	                            error = true;
	                        }
	                }
	                if (error) {
	                    $label.addClass('error');
	                    $form.addClass('error');
	                } else {
	                    $label.removeClass('error');
	                }
	            }
            }
        });
        /*
        if ($form.hasClass('error')) {
            return false;
        }

        return true;*/
        if($('div.captcha').length){

            $('#captchaerror').hide();

            var sData = 'captcha_code=' + $('#captchacode').val();

            var returnValue = false;

            $.ajax({
                type: "POST",
                url: "/ajax/captchacheck.php",
                data: sData,
                async: false,
                success: function(response){
                    if(response != 'ok'){
                        $form.addClass('error');
                        document.getElementById('captcha').src = '/phpcaptcha/securimage_show.php?' + Math.random();
                        $('#captchacode').val('');
                        $('#captchaerror').show();
                        returnValue = false;
                    }else{
                        if ($form.hasClass('error')) {
                            returnValue = false;
                        }else{
                            returnValue = true;
                            //return true;
                        }
                    }
                }
            });
            return returnValue;
        }else{
            if ($form.hasClass('error')) {
                return false;
            }

            return true;
        }

    });





    $('input.savelogin').click(function(){
        $form = $(this).parents('form:first');
        if($form.find('input.savelogin').is(':checked')){

        }else{
            //document.cookie = $form.attr('id') + "=" + escape('') + ";expires=Thu, 01-Jan-1970 00:00:01 GMT";
			//document.cookie = 'logintype' + "=" + escape('') + ";expires=Thu, 01-Jan-1970 00:00:01 GMT";
			cookie.remove($form.attr('id'));
			cookie.remove('logintype');
        }
    });

    /** FAQ **/

    $('div#content.faq li h3.question').click(function()
    {
    	var $oShownAnswer 	= $('div#content.faq li div.answer:visible');
    	var $oClickedAnswer = $(this).next('div.answer');
		if($oClickedAnswer.is(':visible'))
		{
			return false;
		}
    	if($oShownAnswer.length == 1)
    	{
	    	$oShownAnswer.slideUp('slow',function()
	    	{
	    		$oClickedAnswer.slideDown('slow');
	    	});
	    }
	    else
	    {
	    	$oClickedAnswer.slideDown('slow');
	    }
    });

    $('ul#menu-main li.main').hover(function()
    {
    	$oCurrentLi = $('ul#menu-main li.current');
    	if($(this).not('.current'))
    	{
    		$oCurrentLi.removeClass('current');
			$(this).find('div.sub-with-children,div.sub').slideDown('fast');
    	}
    },
    function()
    {
    	$oCurrentLi.addClass('current');
    	$(this).find('div.sub-with-children,div.sub').slideUp('fast');
    });
});

$(window).load(function(){
    resetLayout();
    $('div#col-center img').each(function(index) {
        if (($(this).width()>450))
        {
            var wrapper = $('<div/>').attr('class','resizewrapper');
            $(this).css({width : '450px'});
        }
    });
});
function resetHeight(){
    $('#col-center, #col-left, #col-right').removeAttr('style');
    resetLayout();
}

function resetLayout()
{
    $('#col-center, #col-left, #col-right').removeAttr('style');

	if ( $("#col-center").height() > $("#col-left").height() )
    {
		var newHeight = $("#col-center").height() + 100;
		$("#col-left").height(newHeight);
	}
	else if( $("#col-right").height() > $("#col-center").height() && $("#col-right").height() > $("#col-left").height())
    {
		$("#col-left").height($("#col-right").height());
	}
	else if( $("#col-center").height() < $("#col-left").height() )
    {
		$("#col-center").height($("#col-left").height());
		var newHeight = $("#col-center").height() - 100;
		$("#col-center").height(newHeight);
	}
}

function submitenter(myfield,e)
{
var keycode;
if (window.event) keycode = window.event.keyCode;
else if (e) keycode = e.which;
else return true;

if (keycode == 13)
   {
   myfield.form.submit();
   return false;
   }
else
   return true;
}

function checkdomain(){
    var domainname = $('#domainname').val();
    var checkResult = checkDomainInput(domainname);
    if(checkResult == 'ok')
    {
        $('.errormsg').hide();
        $('div.domainnameresult').html('<div style="width: 100%; text-align: center;"><img src="/img/spinner.gif" /></div>');
        $('div.domainnameresult').show('fast');
        var domainextension = $('#domainextension option:selected').val();

        $.ajax({
            type: "POST",
            url: "/ajax/domainavailability.php",
            data: "domain=" + domainname + "&extension=" + domainextension,
            success: function(response){
                var aResponse = response.split('---');

                $('div.domainnameresult').html(aResponse[0]);
                $('div.shoppingcart').html(aResponse[1]);
                //check if shopping cart is empty
                if($('table.shoppingcart tr').length < 2)
                {
                    $('table.shoppingcart').fadeOut(500, function(){
                        $('div.shoppingcart-fieldset-center').append('<div class="shoppingcartstatus" style="display: none">Uw winkelmandje is leeg</div>');
                        $('div.shoppingcartstatus').fadeIn(1000,function(){
                            resetLayout();
                        });
                    });
                }
                else
                {
                    $('.shoppingcart').fadeIn(1000,function(){
                        resetLayout();
                    });
                }
                resetHeight();
                Cufon.replace('div#content h2', {fontFamily:'Museo Sans 500'});
            }
        });
    }
    else
    {
        $('.errormsg').html(checkResult).fadeIn('slow');
    }
}

function submitcheck(myfield,e)
        {
        var keycode;
        if (window.event) keycode = window.event.keyCode;
        else if (e) keycode = e.which;
        else return true;

        if (keycode == 13)
        {
            checkdomain();
           return false;
   }
else
   return true;
}

function applyMainDomain(){
    $.ajax({
        type: "POST",
        url: "/ajax/sessionhandler.php",
        data:   "maindomain=" + $('select.maindomainselect option:selected').attr('value')
    });
}

function applySpamfilterDiscount(){

    $.ajax({
        type: "POST",
        url: "/ajax/sessionhandler.php",
        data:   "spamfilterdiscount=" + $('select.discountselect option:selected').attr('value')
    });


    var sDiscountDomain = $('select.discountselect').find('option:selected').attr('value');
    $('div.spamfilter table.shoppingcart td.domainname').each(function(){
        if($(this).text() == sDiscountDomain){
            var $select = $(this).parent().find('select.spamfilteruserselect');
            $select.find('option').each(function(){
                var aUserPrice = $(this).attr('value').split(':');
                $(this).attr(
                            'value',
                            aUserPrice[0] + ":" +
                            aUserPrice[2] + ":" +
                            aUserPrice[2] + ":" +
                            aUserPrice[3] + ":" +
                            aUserPrice[4]
                            );

            });
            var aUserPrice = $select.find('option:selected').attr('value').split(':');
            $(this).parent().find('td.spamfilterprice').html('&euro; ' + addSeparatorsNF(aUserPrice[2], '.', ',', '.',true));
        }else{
        //reset other domains
            var $select = $(this).parent().find('select.spamfilteruserselect');
            $select.find('option').each(function(){
                var aUserPrice = $(this).attr('value').split(':');
                $(this).attr(
                            'value',
                            aUserPrice[0] + ":" +
                            aUserPrice[3] + ":" +
                            aUserPrice[2] + ":" +
                            aUserPrice[3] + ":" +
                            aUserPrice[4]
                            );
            });
            var aUserPrice = $select.find('option:selected').attr('value').split(':');
            $(this).parent().find('td.spamfilterprice').html('&euro; ' + addSeparatorsNF(aUserPrice[3], '.', ',', '.',true));
        }
    });
}

function applyNoHostingSpamfilterPrices(){
    $('div.spamfilter table.shoppingcart td.domainname').each(function(){
        var $select = $(this).parent().find('select.spamfilteruserselect');
        $select.find('option').each(function(){
            var aUserPrice = $(this).attr('value').split(':');
            $(this).attr(
                        'value',
                        aUserPrice[0] + ":" +
                        aUserPrice[4] + ":" +
                        aUserPrice[2] + ":" +
                        aUserPrice[3] + ":" +
                        aUserPrice[4]
                        );

        });
        var aUserPrice = $select.find('option:selected').attr('value').split(':');
        //$(this).parent().find('td.spamfilterprice').html('&euro; ' + addSeparatorsNF(aUserPrice[1], '.', ',', '.',true));
        /*
        if($select.is('[disabled]')){
            $(this).parent().find('td.spamfilterprice').html('');
        }else{
            $(this).parent().find('td.spamfilterprice').html('&euro; ' + addSeparatorsNF(aUserPrice[1], '.', ',', '.',true));
        }
        */

    });
}

function resetSpamfilterPrices(){
    $('div.spamfilter table.shoppingcart td.domainname').each(function(){
        var $select = $(this).parent().find('select.spamfilteruserselect');
        $select.find('option').each(function(){
            var aUserPrice = $(this).attr('value').split(':');
            $(this).attr(
                        'value',
                        aUserPrice[0] + ":" +
                        aUserPrice[3] + ":" +
                        aUserPrice[2] + ":" +
                        aUserPrice[3] + ":" +
                        aUserPrice[4]
                        );

        });
        var aUserPrice = $select.find('option:selected').attr('value').split(':');
        /*
        if($select.is('[disabled]')){
            $(this).parent().find('td.spamfilterprice').html('');
        }else{
            $(this).parent().find('td.spamfilterprice').html('&euro; ' + addSeparatorsNF(aUserPrice[1], '.', ',', '.',true));
        }
        */
    });
}

function countSelectedSpamfilterUsers(){
    var iCountSelectedSpamfilterUsers = 0;

    $('div.spamfilter select.spamfilteruserselect option:selected').each(function(){
        iCountSelectedSpamfilterUsers += parseInt($(this).val().split(':')[0]);
    });

    return iCountSelectedSpamfilterUsers;
}

function addSeparatorsNF(nStr, inD, outD, sep, shorten)
{
    //source:http://www.mredkj.com/javascript/nfbasic.html
	nStr += '';
	var dpos = nStr.indexOf(inD);
	var nStrEnd = '';
	if (dpos != -1) {
		nStrEnd = outD + nStr.substring(dpos + 1, nStr.length);
        nStrEnd2 = outD + '00';
        if(shorten == true && $.trim(nStrEnd) == nStrEnd2){
            nStrEnd = outD + '-';
        }
		nStr = nStr.substring(0, dpos);
	}
	var rgx = /(\d+)(\d{3})/;
	while (rgx.test(nStr)) {
		nStr = nStr.replace(rgx, '$1' + sep + '$2');
	}
	return nStr + nStrEnd;
}


/**
*
*  URL encode / decode
*  http://www.webtoolkit.info/
*
**/

var SpecialChars = {

	// public method for url encoding
	encode : function (string) {
		return escape(this._utf8_encode(string));
	},

	// public method for url decoding
	decode : function (string) {
		return this._utf8_decode(unescape(string));
	},

	// private method for UTF-8 encoding
	_utf8_encode : function (string) {
		string = string.replace(/\r\n/g,"\n");
		var utftext = "";

		for (var n = 0; n < string.length; n++) {

			var c = string.charCodeAt(n);

			if (c < 128) {
				utftext += String.fromCharCode(c);
			}
			else if((c > 127) && (c < 2048)) {
				utftext += String.fromCharCode((c >> 6) | 192);
				utftext += String.fromCharCode((c & 63) | 128);
			}
			else {
				utftext += String.fromCharCode((c >> 12) | 224);
				utftext += String.fromCharCode(((c >> 6) & 63) | 128);
				utftext += String.fromCharCode((c & 63) | 128);
			}

		}

		return utftext;
	},

	// private method for UTF-8 decoding
	_utf8_decode : function (utftext) {
		var string = "";
		var i = 0;
		var c = c1 = c2 = 0;

		while ( i < utftext.length ) {

			c = utftext.charCodeAt(i);

			if (c < 128) {
				string += String.fromCharCode(c);
				i++;
			}
			else if((c > 191) && (c < 224)) {
				c2 = utftext.charCodeAt(i+1);
				string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
				i += 2;
			}
			else {
				c2 = utftext.charCodeAt(i+1);
				c3 = utftext.charCodeAt(i+2);
				string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
				i += 3;
			}

		}

		return string;
	}

}

function rewrite_initials(sInitials){
    var sInitials = sInitials;
    var iLength = sInitials.length;
    var sInitialsFormatted = "";

    var skipnext = false;
    for (i = 0; i < iLength; i++){

        //check if character is alpha
        if(
            ((sInitials.charCodeAt(i) > 64) && (sInitials.charCodeAt(i) < 91)) ||
            ((sInitials.charCodeAt(i) > 96) && (sInitials.charCodeAt(i) < 123))
        ){
            if(!skipnext){
                if(sInitials.charAt(i) == 'T'){
                    sInitialsFormatted = sInitialsFormatted + 'T';

                    if(sInitials.charAt(i + 1) == 'h'){
                        sInitialsFormatted = sInitialsFormatted + 'h';
                        skipnext = true;
                    }

                    sInitialsFormatted = sInitialsFormatted + '.';
                }else{
                    sInitialsFormatted = sInitialsFormatted + sInitials.charAt(i).toUpperCase() + '.';
                }
            }else{
                skipnext = false;
            }
        }else{
            if(skipnext){
                skipnext = false;
            }
        }
    }

    return sInitialsFormatted;
}

var cookie = {

	get : function(sName)
	{
		var sName = sName+'=';
		var aCookies = document.cookie.split(';');

		for (var i in aCookies)
		{
			//var sCookie = aCookies[i];
			var sCookie = aCookies[i].toString();

			while(sCookie.charAt(0) == ' ')
			{
				sCookie = sCookie.substring(1, sCookie.length);
			}

			if (sCookie.indexOf(sName) == 0)
			{
				return sCookie.substring(sName.length, sCookie.length);
			}
		}

		return null;
	},

	create : function(sName, sValue, iHours)
	{
		if (iHours)
		{
			var date = new Date();
			date.setTime(date.getTime()+(iHours*60*60*1000));

			var sExpires = '; expires='+date.toGMTString();
		}
		else
		{
			var sExpires = '';
		}

		document.cookie = sName+"="+sValue+sExpires+"; path=/";
	},

	remove : function(sName)
	{
		cookie.create(sName, '', -1);
	}
}
