﻿// JScript File
function switchTab(id)
{
    document.getElementById(id).className='menuItemSelected';
}

function checkContactField()
{
    if(!mandatoryFields()){
       alert("Invoice Company\n\nFöljande fält är obligatoriska.\n\nFöretagsnamn\nOrganisationsnummer\nKontaktperson\nEpost");
       return false;
    }
    
    if(!checkZipcode())
    {
        alert("Invoice Company\n\nPostnr anges med 5 siffror. \nKontrollera din inmatning.");
        return false;
    }
    
    if(!checkEmail())
    {
        alert("Invoice Company\n\nDen angivna epostadress verkar ogiltig.\nKontrollera din inmatning.");
        document.getElementById('tbxEmail').focus();
        return false;
    }
    
    return true;
}

function checkZipcode()
{
    var match = false;
    if(document.getElementById('tbxZipcode').value!="")
    {
        var zip = document.getElementById('tbxZipcode').value;
        match = /\d{5}/.test(zip);
    }else{
        match = true;
    }
    if(!match)document.getElementById('tbxZipcode').focus();
    return match
}

function checkEmail() {
    if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(document.getElementById('tbxEmail').value)){
        return true;
    }
    return false;
}

function mandatoryFields()
{
    if(document.getElementById('tbxCompanyName').value=="" || document.getElementById('tbxOrgnr').value=="" || document.getElementById('tbxContactperson').value=="" || document.getElementById('tbxEmail').value=="")
    {
        return false;
    }else{
        return true;
    }
}


