function CreateComment(){

    if(document.getElementById('CreateCommentForm').CommentText.value == ''){
        
        alert('Skriv ett meddelande');
        
        return;
    
    }

    document.getElementById('CreateCommentForm').style.display = 'none';
    
    document.getElementById('CreateCommentProgress').style.display = 'block';
    
    document.getElementById('CreateCommentForm').submit();

}



function DeleteComment(PageId,CommentId){

    if(confirm('Detta raderar gästboksinlägget')){
    
        Hidden.location = '/?_PageId=' + PageId + '&_ActionName=DeleteComment&CommentId=' + CommentId;
    
    }


}


function CreateBlog(){

    if(document.getElementById('CreateBlogForm').PageTitle.value == ''){
        
        alert('Skriv en rubrik');
        
        return;
    
    }

    if(document.getElementById('CreateBlogForm').BlogText.value == ''){
        
        alert('Skriv ett meddelande');
        
        return;
    
    }

    for(var i = 1; i <= 5; i++){
    
        if(document.getElementsByName('ImageFile['+i+']')[0].value){
        
            var extension = document.getElementsByName('ImageFile['+i+']')[0].value.split('.').pop().toLowerCase();
        
            if(extension != 'jpg' && extension != 'jpeg' && extension != 'png' && extension != 'gif'){
              
                alert('Fil '+i+' är inte ett giltigt bildformat');
                
                return;
            
            }
          
        }
        
    }
          
    document.getElementById('CreateBlogForm').style.display = 'none';
    
    document.getElementById('CreateBlogProgress').style.display = 'block';
        
    document.getElementById('CreateBlogForm').submit();

}


function DeleteBlog(PageId,BlogId){

    if(confirm('Detta raderar blogginlägget')){
    
        Hidden.location = '/?_PageId=' + PageId + '&_ActionName=DeleteBlog&BlogId=' + BlogId;
    
    }


}


function EditBlog(PageId,BlogId){

    MakeHttpRequest('/?_PageId=' + PageId + '&_ActionName=EditBlog&BlogId=' + BlogId, 'Blog[' + BlogId + ']');

}


function UpdateBlog(BlogId){

    if(document.getElementById('UpdateBlogForm[' + BlogId + ']').BlogTitle.value == ''){
        
        alert('Skriv en rubrik');
        
        return;
    
    }

    if(document.getElementById('UpdateBlogForm[' + BlogId + ']').BlogText.value == ''){
        
        alert('Skriv ett meddelande');
        
        return;
    
    }
    
    document.getElementById('UpdateBlogForm[' + BlogId + ']').submit();

}


function CreateCommentReply(CommentId){

    if(document.getElementById('CreateCommentReplyForm[' + CommentId + ']').CommentText.value == ''){
        
        alert('Skriv ett meddelande');
        
        return;
    
    }

    document.getElementById('CreateCommentReplyForm[' + CommentId + ']').style.display = 'none';
    
    document.getElementById('CreateCommentReplyProgress[' + CommentId + ']').style.display = 'block';
    
    document.getElementById('CreateCommentReplyForm[' + CommentId + ']').submit();    
    
}



function CreateLaptime(){

    if(document.getElementById('CreateLaptimeForm').LaptimeMinutes.value == '' || document.getElementById('CreateLaptimeForm').LaptimeSeconds.value == '' || document.getElementById('CreateLaptimeForm').LaptimeTenths.value == ''){
        
        alert('Ange din varvtid med minuter, sekunder och tiondelar');
        
        return;
    
    }

    if(document.getElementById('CreateLaptimeForm').LaptimeCarPageId.value == '' && document.getElementById('CreateLaptimeForm').LaptimeCar.value == ''){
    
        alert('Ange vilken bil du använt');
        
        return;    
    
    }
    

    if(document.getElementsByName('LaptimeFile')[0].value){
    
        var extension = document.getElementsByName('LaptimeFile')[0].value.split('.').pop().toLowerCase();
    
        if(extension != 'dbn'){
          
            alert('Filen är inte en giltig driftbox loggfil');
            
            return;
        
        }
      
    }

    document.getElementById('CreateLaptimeForm').style.display = 'none';
    
    document.getElementById('CreateLaptimeProgress').style.display = 'block';
  
    document.getElementById('CreateLaptimeForm').submit();

}


function DeleteLaptime(PageId,LaptimeId){

    if(confirm('Detta raderar varvtiden')){
    
        Hidden.location = '/?_PageId=' + PageId + '&_ActionName=DeleteLaptime&LaptimeId=' + LaptimeId;
    
    }

}


function SelectCar(CarPageId){

    if(CarPageId == ''){
        
        document.getElementById('LaptimeCarOther').style.display = 'block';
        
    }
        
    else{
        
        document.getElementById('LaptimeCarOther').style.display = 'none';
        
    }

}


function DeleteLog(PageId,LogId){

    if(confirm('Detta raderar logghändelsen')){
    
        Hidden.location = '/?_PageId=' + PageId + '&_ActionName=DeleteLog&LogId=' + LogId;
    
    }

}
