function DaysInMonth(WhichMonth, WhichYear) {
    var DaysInMonth = 31;
    if (WhichMonth == "04" || WhichMonth == "06" || WhichMonth == "09" || WhichMonth == "11") DaysInMonth = 30;
    if (WhichMonth == "02" && (WhichYear / 4) != Math.floor(WhichYear / 4)) DaysInMonth = 28;
    if (WhichMonth == "02" && (WhichYear / 4) == Math.floor(WhichYear / 4)) DaysInMonth = 29;
    return DaysInMonth;
}



function ChangeOptionDays(Which, where) {
    DaysObject = eval("document." + where + "." + Which + "Day");
    MonthObject = eval("document." + where + "." + Which + "Month");
    YearObject = eval("document." + where + "." + Which + "Year");

    Month = MonthObject[MonthObject.selectedIndex].text;
    Year = YearObject[YearObject.selectedIndex].text;

    DaysForThisSelection = DaysInMonth(Month, Year);
    CurrentDaysInSelection = DaysObject.length - 1;

    if (CurrentDaysInSelection > DaysForThisSelection) {
        for (i = 0; i < (CurrentDaysInSelection - DaysForThisSelection); i++) {
            DaysObject.options[DaysObject.options.length - 1] = null
        }
    }
    if (DaysForThisSelection > CurrentDaysInSelection) {
        for (i = 0; i < (DaysForThisSelection - CurrentDaysInSelection); i++) {
            NewOption = new Option(DaysObject.options.length);
            DaysObject.add(NewOption);
        }
    }
    if (DaysObject.selectedIndex < 0) DaysObject.selectedIndex == 0;
}


function UpdatePage() {

    document.getElementById('UpdatePageForm').submit();

}

function ShowHide(id) {

    var el = document.getElementById(id);

    if (el.style.display != 'none') {
        el.style.display = 'none';
    }
    else {
        el.style.display = 'block';
    }
}

function Subscribe() {

    if (document.getElementById('SubscribeForm').Email.value == 'E-mail address' || document.getElementById('SubscribeForm').Email.value == '') {

        alert('Please enter your e-mail address');

        return;

    }

    document.getElementById('SubscribeForm').submit();

}

function UploadImages() {

    var Images = 0;

    for (var i = 1; i <= 5; i++) {

        if (document.getElementsByName('ImageFile[' + i + ']')[0].value) {

            var Images = Images + 1;

            var extension = document.getElementsByName('ImageFile[' + i + ']')[0].value.split('.').pop().toLowerCase();

            if (extension != 'jpg' && extension != 'jpeg' && extension != 'png' && extension != 'gif') {

                alert('The file ' + i + ' is not a valid image file');

                return;

            }

        }

    }
    

    if (Images == 0) {

        alert('Chose at least one image to upload');

        return;

    }

    if (document.getElementById('UploadImagesForm').ImageName.value == '') {

        alert('Please enter your name');

        return;

    }

    if (document.getElementById('UploadImagesForm').ImageEmail.value == '') {

        alert('Please enter your e-mail address');

        return;

    }

    document.getElementById('UploadImagesForm').style.display = 'none';

    document.getElementById('UploadImagesProgress').style.display = 'block';

    document.getElementById('UploadImagesForm').submit();

}


function PublishImage(PageId, ImageId) {

    Hidden.location = '/?_PageId=' + PageId + '&_ActionName=PublishImage&ImageId=' + ImageId;

}


function DeleteImage(PageId,ImageId){

    if (confirm('This deletes the image')) {

        Hidden.location = '/?_PageId=' + PageId + '&_ActionName=DeleteImage&ImageId=' + ImageId;

    }

}


function PopularImage(PageId, ImageId) {

    if (document.getElementById('Image[' + ImageId + ']IsPopular').checked == true) {

        Hidden.location = '/?_PageId=' + PageId + '&_ActionName=PopularImage&ImageId=' + ImageId + '&ImageIsPopular=1';
        
    }

    if (document.getElementById('Image[' + ImageId + ']IsPopular').checked == false) {

        Hidden.location = '/?_PageId=' + PageId + '&_ActionName=PopularImage&ImageId=' + ImageId + '&ImageIsPopular=NULL';

    }

}

function CreateVideo() {

    if (document.getElementById('CreateVideoForm').VideoYoutubeUrl.value == '') {

        alert('Please enter a link to your YouTube video');

        return;

    }

    if (document.getElementById('CreateVideoForm').VideoName.value == '') {

        alert('Please enter your name');

        return;

    }

    if (document.getElementById('CreateVideoForm').VideoEmail.value == '') {

        alert('Please enter your e-mail address');

        return;

    }

    document.getElementById('CreateVideoForm').style.display = 'none';

    document.getElementById('CreateVideoProgress').style.display = 'block';

    document.getElementById('CreateVideoForm').submit();

}


function PublishVideo(PageId, VideoId) {

    Hidden.location = '/?_PageId=' + PageId + '&_ActionName=PublishVideo&VideoId=' + VideoId;

}


function DeleteVideo(PageId, VideoId) {

    if (confirm('This deletes the video')) {

        Hidden.location = '/?_PageId=' + PageId + '&_ActionName=DeleteVideo&VideoId=' + VideoId;

    }

}


function PopularVideo(PageId, VideoId) {

    if (document.getElementById('Video[' + VideoId + ']IsPopular').checked == true) {

        Hidden.location = '/?_PageId=' + PageId + '&_ActionName=PopularVideo&VideoId=' + VideoId + '&VideoIsPopular=1';

    }

    if (document.getElementById('Video[' + VideoId + ']IsPopular').checked == false) {

        Hidden.location = '/?_PageId=' + PageId + '&_ActionName=PopularVideo&VideoId=' + VideoId + '&VideoIsPopular=NULL';

    }

}


function CreateComment() {

    if (document.getElementById('CreateCommentForm').CommentText.value == '') {

        alert('Please enter a comment');

        return;

    }

    if (document.getElementById('CreateCommentForm').CommentName.value == '') {

        alert('Please enter your name');

        return;

    }

    if (document.getElementById('CreateCommentForm').CommentEmail.value == '') {

        alert('Please enter your e-mail address');

        return;

    }

    if (document.getElementById('CreateCommentForm').Code.value == '') {

        alert('Please enter the verification code');

        return;

    }

    document.getElementById('CreateCommentForm').style.display = 'none';

    document.getElementById('CreateCommentProgress').style.display = 'block';

    document.getElementById('CreateCommentForm').submit();

}


function PublishComment(PageId, CommentId) {

    Hidden.location = '/?_PageId=' + PageId + '&_ActionName=PublishComment&CommentId=' + CommentId;

}


function DeleteComment(PageId, CommentId) {

    if (confirm('This deletes the comment')) {

        Hidden.location = '/?_PageId=' + PageId + '&_ActionName=DeleteComment&CommentId=' + CommentId;

    }

}



function CreateParticipant() {

    if (document.getElementById('CreateParticipantForm').ParticipantName.value == '') {

        alert('Please enter your name');

        return;

    }

    if (document.getElementById('CreateParticipantForm').ParticipantEmail.value == '') {

        alert('Please enter your e-mail address');

        return;

    }

    if (!confirm('By pressing OK you accept the terms and conditions of entry')) {

        return;

    }

    document.getElementById('CreateParticipantForm').style.display = 'none';

    document.getElementById('CreateParticipantProgress').style.display = 'block';

    document.getElementById('CreateParticipantForm').submit();

}


function DeleteParticipant(PageId, ParticipantId) {

    if (confirm('This deletes the participant')) {

        Hidden.location = '/?_PageId=' + PageId + '&_ActionName=DeleteParticipant&ParticipantId=' + ParticipantId;

    }

}


function CreateSendlist() {

    if (document.getElementById('CreateSendlistForm').Status1.checked != 1 && document.getElementById('CreateSendlistForm').Status2.checked != 1 && document.getElementById('CreateSendlistForm').Status3.checked != 1 && document.getElementById('CreateSendlistForm').Status4.checked != 1) {

        alert('Please check at least one status box');

        return;

    }

    if (document.getElementById('CreateSendlistForm').SendlistName.value == '') {

        alert('Please enter the sendlist name');

        return;

    }

    document.getElementById('CreateSendlistForm').submit();

}


function CreatePartner() {

    if (document.getElementById('CreatePartnerForm').PartnerName.value == '') {

        alert('Please enter the groups name');

        return;

    }

    document.getElementById('CreatePartnerForm').submit();

}

function DeletePartner(PageId, PartnerId) {

    if (confirm('This deletes the partner and moves all participants to the general group')) {

        Hidden.location = '/?_PageId=' + PageId + '&_ActionName=DeletePartner&PartnerId=' + PartnerId;

    }

}


function DeletePartnerImage(PageId, PartnerId) {

    if (confirm('This deletes the image')) {

        Hidden.location = '/?_PageId=' + PageId + '&_ActionName=DeletePartnerImage&PartnerId=' + PartnerId;

    }

}


function UpdateTab() {

    document.getElementById('UpdateTabForm').submit();

}



function CreateBlog() {

    if (document.getElementById('CreateBlogForm').BlogTitle.value == '') {

        alert('Please enter a title for the blog entry');

        return;

    }

    if (document.getElementById('CreateBlogForm').BlogText.value == '') {

        alert('Please select text for the blog entry');

        return;

    }

    document.getElementById('CreateBlogForm').style.display = 'none';

    document.getElementById('CreateBlogProgress').style.display = 'block';

    document.getElementById('CreateBlogForm').submit();

}



function DeleteBlog(PageId, BlogId) {

    if (confirm('This deletes the blog entry')) {

        Hidden.location = '/?_PageId=' + PageId + '&_ActionName=DeleteBlog&BlogId=' + BlogId;

    }

}


function DeleteBlogImage(PageId, BlogId) {

    if (confirm('This deletes the image')) {

        Hidden.location = '/?_PageId=' + PageId + '&_ActionName=DeleteBlogImage&BlogId=' + BlogId;

    }

}



function CreateTestimonial() {

    if (document.getElementById('CreateTestimonialForm').ImageFile.value == '') {

        alert('Please select an image');

        return;

    }

    if (document.getElementById('CreateTestimonialForm').TestimonialName.value == '') {

        alert('Please enter a name');

        return;

    }

    if (document.getElementById('CreateTestimonialForm').TestimonialText.value == '') {

        alert('Please enter a text');

        return;

    }

    document.getElementById('CreateTestimonialForm').style.display = 'none';

    document.getElementById('CreateTestimonialProgress').style.display = 'block';

    document.getElementById('CreateTestimonialForm').submit();

}



function DeleteTestimonial(PageId, TestimonialId) {

    if (confirm('This deletes the testimonial')) {

        Hidden.location = '/?_PageId=' + PageId + '&_ActionName=DeleteTestimonial&TestimonialId=' + TestimonialId;

    }

}

function CreateMedia() {

    if (document.getElementById('CreateMediaForm').ImageFile.value == '') {

        alert('Please select an image');

        return;

    }

    if (document.getElementById('CreateMediaForm').PdfFile.value == '') {

        alert('Please select a PDF file');

        return;

    }

    if (document.getElementById('CreateMediaForm').MediaTitle.value == '') {

        alert('Please enter a title');

        return;

    }

    document.getElementById('CreateMediaForm').style.display = 'none';

    document.getElementById('CreateMediaProgress').style.display = 'block';

    document.getElementById('CreateMediaForm').submit();

}


function DeleteMedia(PageId, MediaId) {

    if (confirm('This deletes the media clip')) {

        Hidden.location = '/?_PageId=' + PageId + '&_ActionName=DeleteMedia&MediaId=' + MediaId;

    }

}
