﻿
function RequestChat(userName) {
    $.ajax({
        url: homeURL+ "Profile/RequestChat",
        data: ({ userName: userName }),
        type: "POST",
        success: function (result) {
            
            $("#dialog").dialog("option", "title", "Chat request");
            $("#dialog").html("<p>Chat request sent</p>");
            $("#dialog").dialog("open");
        }
    });
}



$(this).ready(function () {

    $('#contentPanel').click(function () {
        $('.popup').hide();
    });

    $('.RedLink').hover(function () {
        $(this).addClass("RedLinkHover");
    },
    function () {
        $(this).removeClass("RedLinkHover");
    });

    $('.Date').datepicker();
    $('.DOB').datepicker({ changeYear: true });
    $(".DOB").datepicker("option", "yearRange", '1950:2000');
    $(".DOB").datepicker("option", "defaultDate", '-18y');


    $('#LoadingDiv').dialog({
        modal: true,
        resizable: false,
        hide: "explode",
        show: 'scale',
        autoOpen: false
    }).ajaxStart(function () {
        $(this).dialog('open');
    })
    .ajaxStop(function () {
        $(this).dialog('close');
    });

    $('#dialog').dialog({
        modal: false,
        resizable: false,
        hide: "explode",
        show: 'scale',
        autoOpen: false
    });

    $('#inviteDiv').dialog({
        modal: false,
        resizable: false,
        hide: "explode",
        show: 'scale',
        autoOpen: false,
        title: "Invite people to join club2gether"
    });

    $('#ReportAbuseDiv').dialog({
        modal: true,
        resizable: false,
        hide: "explode",
        show: 'scale',
        autoOpen: false,
        title: "Report abuse"
    });

    $('.ClearText').focus(function () {
        $(this).val('');
        $(this).css('color', '#000000');
        $(this).css('font-style', 'normal');
    });

    $('#MainSearchTextBox').focus(function () {
        $(this).val('');
        $(this).css('color', '#000000');
        $(this).css('font-style', 'normal');
    });

    $('div.SearchButton').click(function () {
        if ($('#MainSearchTextBox').val() == '' || $('#MainSearchTextBox').val() == 'Search for Events People or Venues') {
            alert("Please enter some text to search");
            $('#MainSearchTextBox').focus();
        }
        else {
            $('#ClubAdvisorForm').submit();
        }
    });
});


$(function () {
    $("#Flikrdialog").dialog({
        modal: true,
        autoOpen: false,
        hide: "explode",
        show: 'scale',
        resizable: false
    });
});

function OpenReportAbuse(memberID, topicId, postId) {
    $('#ReportAbuseDiv #memberID').val(memberID);
    $('#ReportAbuseDiv #topicID').val(topicId);
    $('#ReportAbuseDiv #postID').val(postId);
    $('#ReportAbuseDiv').dialog('open');
}

function ReportAbuse() {
    MemberID = $('#ReportAbuseDiv #memberID').val();
    Text = $('#ReportAbuseDiv #Abuse').val();
    topicid = $('#ReportAbuseDiv #topicID').val();
    postid = $('#ReportAbuseDiv #postID').val();

    $.ajax({
        url: homeURL + "Profile/ReportAbuse",
        data: { text: Text, memberID: MemberID, TopicID: topicid, PostID: postid },
        type: "POST",
        dataType: "json",
        success: function () {
            $('#ReportAbuseDiv').dialog('close');
            $("#dialog").html("Abuse report to the club2gether administrators");
            $("#dialog").dialog("option", "buttons", { "OK": function () { $(this).dialog("close"); } });
            $("#dialog").dialog("option", "title", "Abuse reported");
            $("#dialog").dialog("open");
        },
        error: function () {
            alert('error');
        }
    });
}

function ImGoing(eventID) {
    $.ajax({
        url: homeURL + "Event/ImGoing",
        data: { EventID: eventID },
        type: "POST",
        success: function () {
            $("#dialog").html("<div id='EnjoyTheParty'></div>");
            $("#dialog").dialog("option", "buttons", { "OK": function () { $(this).dialog("close"); } });
            $("#dialog").dialog("option", "title", "Enjoy the Party!");
            $("#dialog").dialog("open");
        },
        error: function () {
            alert('error');
        }
    });
}

function RemoveEvent(eventID) {
    $.ajax({
        url: homeURL + "Event/RemoveEvent",
        data: { EventID: eventID },
        type: "POST",
        success: function () {
            document.location = document.location;
        },
        error: function () {
            alert('error');
        }
    });
}

function OpenPhotoUpload() {

//    $("#dialog").html("<p>Choose Photos to upload:</p><input type='file' class='button' />");
//    $("#dialog").dialog("option", "buttons", { "Upload": function () { PhotoUpload(); }, "Close": function () { $(this).dialog("close"); } });
    $("#Flikrdialog").dialog("open");
}



function GetJsonData(context) {
    // Load and deserialize the returned JSON data
    var json = context.get_data();
    var data = Sys.Serialization.JavaScriptSerializer.deserialize(json);
    return data;
}


