

function strTeamName_clear() {
    
    var strTeamName = $('strTeamName').value;

    if (strTeamName == 'Ert lagnamn') {
        $('strTeamName').value = '';
    }
    else {
        strTeamName_check();
    }

}

function strTeamName_check() {

    var intCheck = -1;
    var intRunCheck = -1;
    var strTeamName = $('strTeamName').value;

    if (strTeamName.length >= 3 || intRunCheck == 1) {
        
        var strPattern = new RegExp(/^\w{3,20}$/);

        if (strPattern.test(strTeamName) == true) {

            new Ajax.Request('skapasida-do-1.html', {
                method: 'post', parameters: 'strTeamName=' + strTeamName,
                onSuccess: function(transport) {
                    var response = transport.responseText || "no response text";

                    if (transport.getHeader('intCheck') == 1) {

                        $('reg_name_status').update('Lagnamnet är ledigt');
                        $('reg_name_status').setStyle({ 'color': 'green' });

                    }
                    else {
                        $('reg_name_status').update('Lagnamnet är upptaget');
                        $('reg_name_status').setStyle({ 'color': 'red' });
                    }



                },
                onFailure: function() { alert('Ett fel har uppstått') }
            });

        }
        else {
            $('reg_name_status').update('Innehåller ogiltiga tecken');
            $('reg_name_status').setStyle({ 'color': 'red' });
        }
        
        intRunCheck = 1;
        
    }
    else {

        var strPattern = new RegExp(/^\w{0,20}$/);

        if (strPattern.test(strTeamName) == true) 
            $('reg_name_status').update('');
        else
            $('reg_name_status').update('Innehåller ogiltiga tecken');
            $('reg_name_status').setStyle({ 'color': 'red' });
        
    
    }

    
}

function form_reg_step1_validate() {

    var intCheck = 1;

    if ($('reg_name_status').innerHTML != 'Lagnamnet är ledigt') {
        intCheck = -1;
        $('strTeamName').focus();
        if ($('reg_name_status').innerHTML == '') {
            $('reg_name_status').update('Minst 3 tecken');
            $('reg_name_status').setStyle({ 'color': 'red' });
        }
    }
        
    if (intCheck == 1) {
        return true;
    }
    else {
        return false;
    }
   
}



function find_intCountyId_check() {

    var intCountyId = $('select2').value;

    if (intCountyId > 0) {

        new Ajax.Request('hitta-ajax-1.html', {
            method: 'post', parameters: 'intCountyId=' + intCountyId,
            onSuccess: function(transport) {
                var response = transport.responseText || "no response text";

                $('select3').update(response);

            },
            onFailure: function() { alert('Ett fel har uppstått') }
        });

    }
    else {
        $('select3').update('<option value="">-- Välj först ett län --</option>');
    }

}


function form_reg_step2_validate() {

    var intCheck = 1;

    $('intSportId_status').setStyle({ 'display': 'none' });
    $('intDfId_status').setStyle({ 'display': 'none' });
    $('intDcId_status').setStyle({ 'display': 'none' });
    $('intCountyId_status').setStyle({ 'display': 'none' });
    $('intMunicipalityId_status').setStyle({ 'display': 'none' });
    $('intAgeId_status').setStyle({ 'display': 'none' });

    if ($('intSportId').value <= 0) {
        intCheck = -1;
        $('intSportId_status').setStyle({ 'display': 'inline' });
        $('strStep2_status').update('<p>Välj en sport</p>');
        return false;
    }
    

    if ($('intNoDcId').checked == false) {

        if ($('intDfId').value <= 0) {
            intCheck = -1;
            $('intDfId_status').setStyle({ 'display': 'inline' });
            $('strStep2_status').update('<p>Välj ett förbund eller att ni inte tillhör en förening</p>');
            return false;
        }
        
        if ($('intDcId').value <= 0) {
            intCheck = -1;
            $('intDcId_status').setStyle({ 'display': 'inline' });
            $('strStep2_status').update('<p>Välj en förening eller att ni inte tillhör en förening</p>');
            return false;
        }
        
    }

    if ($('intCountyId').value <= 0) {
        intCheck = -1;
        $('intCountyId_status').setStyle({ 'display': 'inline' });
        $('strStep2_status').update('<p>Välj ett län</p>');
        return false;
    }
    

    if ($('intMunicipalityId').value <= 0) {
        intCheck = -1;
        $('intMunicipalityId_status').setStyle({ 'display': 'inline' });
        $('strStep2_status').update('<p>Välj en kommun</p>');
        return false;
    }

    if ($('intAgeId').value <= 0) {
        intCheck = -1;
        $('intAgeId_status').setStyle({ 'display': 'inline' });
        $('strStep2_status').update('<p>Välj en ålder</p>');
        return false;
    } 

    if (intCheck == 1) {
        $('strStep2_status').update('');
        return true;
    }
    else {
        return false;
    }

}

function strTroopMail2_check() {
    
    var strPattern = new RegExp(/^(([\w-]+\.?)+@([a-zA-Z0-9-]{1,}\.?)+\.[a-zA-Z]{2,4}){1}$/);
    if (strPattern.test($('strTroopMail').value) == true) {
        if ($('strTroopMail').value == $('strTroopMail2').value) {
            if ($('strTroopUserName').value == '') {
                $('strTroopUserName').value = $('strTroopMail').value;
            }
        }
    }
    
}

function form_reg_step3_validate() {

    var intCheck = 1;

    $('strTroopForename_status').setStyle({ 'display': 'none' });
    $('strTroopSurname_status').setStyle({ 'display': 'none' });
    $('strTroopMail_status').setStyle({ 'display': 'none' });
    $('strTroopMail2_status').setStyle({ 'display': 'none' });
    $('strTroopUserName_status').setStyle({ 'display': 'none' });
    $('strTroopPassword_status').setStyle({ 'display': 'none' });
    $('strTroopPassword2_status').setStyle({ 'display': 'none' });

    var strPattern = new RegExp(/^.{2,50}$/);
    if (strPattern.test($('strTroopForename').value) == false) {
        intCheck = -1;
        $('strTroopForename_status').setStyle({ 'display': 'inline' });
        $('strTroopForename').focus();
        $('strStep3_status').update('<p>Ange ditt förnamn</p>');
        return false;
    }

    var strPattern = new RegExp(/^.{2,50}$/);
    if (strPattern.test($('strTroopSurname').value) == false) {
        intCheck = -1;
        $('strTroopSurname_status').setStyle({ 'display': 'inline' });
        $('strTroopSurname').focus();
        $('strStep3_status').update('<p>Ange ditt efternamn</p>');
        return false;
    }
    
    var strPattern = new RegExp(/^(([\w-]+\.?)+@([a-zA-Z0-9-]{1,}\.?)+\.[a-zA-Z]{2,4}){1}$/);
    if (strPattern.test($('strTroopMail').value) == false) {
        intCheck = -1;
        $('strTroopMail_status').setStyle({ 'display': 'inline' });
        $('strTroopMail').focus();
        $('strStep3_status').update('<p>E-postadress är inte giltig</p>');
        return false;
    }
    else {
        if ($('strTroopMail').value != $('strTroopMail2').value) {
            intCheck = -1;
            $('strTroopMail2_status').setStyle({ 'display': 'inline' });
            $('strTroopMail2').focus();
            $('strStep3_status').update('<p>E-postadresserna är inte lika</p>');
            return false;
        }
    }

    var strPattern = new RegExp(/^.{4,50}$/);
    if (strPattern.test($('strTroopUserName').value) == false) {
        intCheck = -1;
        $('strTroopUserName_status').setStyle({ 'display': 'inline' });
        $('strTroopUserName').focus();
        $('strStep3_status').update('<p>Ange önskat användarnamn, minst 4 tecken</p>');
        return false;
    }

    var strPattern = new RegExp(/^.{6,50}$/);
    if (strPattern.test($('strTroopPassword').value) == false) {
        intCheck = -1;
        $('strTroopPassword_status').setStyle({ 'display': 'inline' });
        $('strTroopPassword').focus();
        $('strStep3_status').update('<p>Ange önskat lösenord, minst 6 tecken</p>');
        return false;
    }
    else {
        if ($('strTroopPassword').value != $('strTroopPassword2').value) {
            intCheck = -1;
            $('strTroopPassword2_status').setStyle({ 'display': 'inline' });
            $('strTroopPassword2').focus();
            $('strStep3_status').update('<p>Lösenorden är inte lika</p>');
            return false;
        }
    }


    
    if ($('intAccept').checked == false) {
        intCheck = -1;
        $('strStep3_status').update('<p>Du måste acceptera de allmänna villkoren</p>');
        return false;
    }
        

    if (intCheck == 1) {
        return true;
    }
    else {
        return false;
    }

}
