errors = new Array();

$(document).ready(function()
{
    $('.link_conditions').bind('click', function() { window.open(this.href, 'condition', 'width=550,height=500,scrollbars=yes,resizable=no,status=no,toolbar=no');return false; });
    
    on_load();
    if (last_error > 0)
        on_error(last_error);
});

function on_load()
{
    errors[1] = 'Please fill out a country code, e.g. 44';
    errors[2] = 'Vul alstublieft uw mobiele nummer in.';
    errors[3] = 'Het mobiele nummer moet numeriek zijn.';
    errors[4] = 'U moet akkoord gaan met de gebruikersovereenkomst.';
    errors[5] = 'Please choose a language to download.';
    errors[6] = 'Please wait, we are <br/>sending a message to your mobile phone...';
    errors[7] = 'Invalid country code!';
    errors[8] = 'Ongeldig mobiel nummer!';
    errors[9] = 'An unkown error occured while sending a message to your mobile!';
    errors[10] = 'We are sorry, you are only allowed to send 20 messages an hour!';
    errors[11] = 'Please fill out your mobile device!';
    errors[12] = 'We are sorry, but your device is not supported.';
    success = 'Bedankt! Er !<br/>Please follow the instructions to install the application.';
}

function onload_sms()
{
    $('input:text:first').focus();
    $('.submit_button').bind('click', function() {

        if (checkfield('#country_code', 1, false) && checkfield('#mobile_number', 2, false) && ischecked($('#check_conditions'), 4, false)) {
            $('#form_sms').submit();
        }

    });
}

function cable_step1()
{
    $('input:text:first').focus();
    $('.link_allbrands').bind('click', function() {  $('#popbrands').hide(); $('#allbrands').show(); return false; } );
    $('.link_populairbrands').bind('click', function() {  $('#popbrands').show(); $('#allbrands').hide(); return false; } );
    $('#popbrands_brands').makeacolumnlists({cols: 4, colWidth: 130, equalHeight: 'ol', startN: 1});
    $('#allbrands_brands').makeacolumnlists({cols: 4, colWidth: 130, equalHeight: 'ol', startN: 1});
    $('#allbrands').hide();
}

function cable_step2()
{
   $("#device_name").autocomplete(devices, {
            minChars: 0,
            max: 12,
            autoFill: false,
            mustMatch: false,
            matchContains: true,
            scrollHeight: 320
    });
   
    $('input#device_name').result(function(event, data, formatted) {
        if (data) {
            location.href = url + data;
        }
    });
   
    $('input:text:first').focus();
    $("input#device_name").bind('keydown', function(event) {
        if (event.keyCode == 13)
            return false;
        else
            return true;
    });
}

function cable_step3()
{
    $('.method').bind('click', function() {
        
        if (ischecked($('#check_conditions'), 4, false)) {
        
            if ($(this).hasClass('usb'))
                location.href = url + 'usb';
            else
                location.href = url + 'bt';
        }
    });
}

function on_error(errorno, inline_error)
{
    if (inline_error)
        $('.error').html('Error: ' + errors[errorno]);
    else
        alert(errors[errorno]);
    
    switch (errorno) {
        case 1:
        case 7:
                $('#country_code').focus();
                break;
        case 2:
        case 8:
                $('#mobile_number').focus();
                break;
    }
}

function checkfield(element, errorno, inline_error)
{
    inline_error = inline_error == undefined ? false : inline_error;
    
    if ($(element).val() == '') {
        on_error(errorno, inline_error);
        return false;
    }
    return true;
}

function ischecked(element, errorno, inline_error)
{
    if (!$(element).get(0).checked) {
        on_error(errorno, inline_error);
        return false;
    }
    else return true;
}