﻿/// <reference path="~/Scripts/IntelliSense/Intellisense.js" />
(function()
{
    BSC.UI.Ws.Admin = function()
    {
        var resetPassword = function(e, p1)
        {
            var guid = p1;
            var newPassword = BSC.U.GenerateRandomPassword();
            BSC.UI.Alert("Change password", "Cancel", "Are you sure ?", "You are about to change the password of this profile.<br/><br/>This action can't be undone.<br/><br/>This action will be log and an email will be sent to the profile.<br/><br/>Please type the new password:<br/><input id=\"newpassword_admin_reset\" name=\"newpassword_admin_reset\" value=\"" + newPassword + "\" />", function(e)
            {
                var newpassword = $("#newpassword_admin_reset").getValue();
                var w = BSC.UI.Ws.Get(guid);
                var Key = w.data.key;

                if (!Key) return;

                $.post("/admin/resetpassword", { p: newpassword, profilekey: Key }, function()
                {
                    BSC.UI.W.Reload(guid);
                    BSC.UI.Alert("Change password", null, "New password saved.");

                }, "json");

            }, null, "info");

        };

        var viewPassword = function(e, p1)
        {
            var password = p1;
            alert("Please note!!\n\nPasswords are confidetiel are must not been\ngiven or used by others than there owner.\n\nPassword:\n\n" + password);
        };

        var setEmailAsVerified = function(e, p1)
        {
            BSC.UI.Alert("Ok", "Cancel", "Are you sure ?", "Make sure YOU have verified the email yourself.", function(e)
            {
                var w = BSC.UI.Ws.Get(guid);
                var Key = w.data.key;

                if (!Key) return;

                $.post("/admin/SetEmailAsVerified", { profilekey: Key }, function()
                {
                    Alert("Profile's email is now verified.");

                }, "json");

            }, null, "info");
        };

        var cancelSubscription = function(e, p1)
        {
            var guid = p1;

            BSC.UI.Alert("Ok", "Cancel", "Are you sure ?", "This will cancel any active subscription the user has.", function(e)
            {
                var w = BSC.UI.Ws.Get(guid);
                var Key = w.data.key;

                if (!Key) return;

                if (!profileID) return;

                $.post("/admin/CancelSubscription", { profilekey: Key }, function()
                {
                    Alert("Subscription cancelled.");

                }, "json");

            }, null, "info");
        };

        var banProfile = function(e, p1)
        {
            var guid = p1;

            BSC.UI.Alert("Ok", "Cancel", "Are you sure ?", "This will ban the profile permanently.", function(e)
            {
                var w = BSC.UI.Ws.Get(guid);
                var Key = w.data.key;

                if (!Key) return;

                $.post("/admin/BanProfile", { profilekey: Key }, function()
                {
                    alert("Profile Banned");

                }, "json");

            }, null, "info");
        };

        var changeGender = function(e, p1)
        {
            var guid = p1;

            BSC.UI.Alert("Ok", "Cancel", "Are you sure ?", "You will change gender on this profile.", function(e)
            {
                var w = BSC.UI.Ws.Get(guid);
                var Key = w.data.key;

                if (!Key) return;

                $.post("/admin/ChangeGender", { profilekey: Key }, function()
                {
                    alert("Gender Changed");

                }, "json");

            }, null, "info");
        };

        var giveSubscription = function(e, p1)
        {
            var guid = p1;

            var days = $("#" + guid + "_days").val();

            if (days.trim() == "" || Number(days) != days || !$("input[name='" + guid + "_subscriptiontype']:checked").val())
            {
                alert("Please select subscription, and enter days.");
            }
            else
            {
                BSC.UI.Alert("Ok", "Cancel", "Are you sure ?", "This will add subscription days to the profile.", function(e)
                {
                    var w = BSC.UI.Ws.Get(guid);
                    var Key = w.data.key;

                    if (!Key) return;

                    var subscriptiontype = $("input[name='" + guid + "_subscriptiontype']:checked").val();

                    $.post("/admin/GiveSubscription", { profilekey: Key, days: days, subscriptiontype: subscriptiontype }, function()
                    {
                        BSC.UI.W.Reload(guid);
                    }, "json");



                }, null, "info");
            }

        };

        return {

            /// <summary></summary>
            /// <param name="data"></param>
            /// <return></return>
            ResetPassword: resetPassword,

            /// <summary></summary>
            /// <param name="data"></param>
            /// <return></return>
            ViewPassword: viewPassword,

            /// <summary></summary>
            /// <param name="data"></param>
            /// <return></return>
            SetEmailAsVerified: setEmailAsVerified,

            /// <summary></summary>
            /// <param name="data"></param>
            /// <return></return>
            CancelSubscription: cancelSubscription,

            /// <summary></summary>
            /// <param name="data"></param>
            /// <return></return>
            BanProfile: banProfile,

            /// <summary></summary>
            /// <param name="data"></param>
            /// <return></return>
            ChangeGender: changeGender,
            GiveSubscription: giveSubscription,
            GGC: function(p, guid)
            {
                $.post("/admin/makeninjas", { profileID: p }, function(r)
                {
                    alert("Success");
                    BSC.UI.W.Reload(guid);
                }, "json");
            }
        };
    } ();
})();


/// <reference path="~/Scripts/IntelliSense/Intellisense.js" />
(function()
{
    BSC.UI.Ws.Admin.Statistic = function()
    {
        var updateTimer = null;
        
        var bind = function(p1)
        {
            var guid = p1;
            
            if (updateTimer)
                clearInterval(updateTimer);
                
            updateTimer = setInterval(function()
            {
                BSC.D.AjaxPost("/admin/OnlineStatistic", null, function(res)
                {
                    $("#OnlineNum").html(res.OnlineCount);
                    BSC.UI.GetFlash("OnlineGraph").sendTextToFlash(res.OnlineCount);

                    $("#AppNum").html(res.ApplicantCount);
                    BSC.UI.GetFlash("AppGraph").sendTextToFlash(res.ApplicantCount);
                    
                }, "json", guid);
            }, 30000);

            BSC.D.AjaxPost("/admin/OnlineStatistic", null, function(res)
            {
                $("#OnlineNum").html(res.OnlineCount);
                BSC.UI.GetFlash("OnlineGraph").sendTextToFlash(res.OnlineCount);

                $("#AppNum").html(res.ApplicantCount);
                BSC.UI.GetFlash("AppGraph").sendTextToFlash(res.ApplicantCount);

            }, "json", guid);

        };

        return {

            Bind: bind,
            Unload: function(p1)
            {
                var guid = p1;

                if (updateTimer)
                    clearInterval(updateTimer);
            }
        };
    } ();
})();

BSC.E.Subscribe("bind", BSC.UI.Ws.Admin.Statistic.Bind, null, "admin.statistic");
BSC.E.Subscribe("unload", BSC.UI.Ws.Admin.Statistic.Unload, null, "admin.statistic");
BSC.E.Subscribe("unbind", BSC.UI.Ws.Admin.Statistic.Unbind, null, "admin.statistic");


(function()
{
    BSC.Require("BSC.UI.Ws.Admin.ProfileResolution");
    BSC.UI.Ws.Admin.ProfileResolution.Profiles = function()
    {

        var basebind = function(p1)
        {
            var guid = p1;
            var w = BSC.UI.Ws.Get(guid);
            var jQ = BSC.U.ParseQuery(w.query);
            if (jQ.groupid)
            {
                BSC.UI.Ws.Get(guid).query = "profileid=" + jQ.groupid;
                $("#" + guid + "_tabs_content_ul li a").map(function()
                {
                    var h = this.href;
                    // Replace with new id
                    if (h.indexOf("/?profileid=") > -1)
                        this.href = h.replace(/\/\?groupid=(.*)/i, "/?profileid=" + jQ.groupid);
                    else
                        this.href = h + "/?profileid=" + jQ.groupid
                });
            }
        };



        /// <summary>
        /// Bind events to ui elements
        /// </summary>
        var bind = function(p1)
        {
            var guid = p1;

            $("#" + guid + "_reportedProfiles a.button").bind("click", guid, BSC.UI.Ws.Admin.ProfileResolution.Profiles.Action);
            basebind(guid);
        };

        var action = function(e)
        {
            BSC.UI.Ws.Admin.ProfileResolution.Profiles.TakeAction(e, "profile");
        };
        /// <summary>
        /// Unbind events to ui elements
        /// </summary>
        var unbind = function(p1)
        {
            var guid = p1;
            $("#" + guid + " a").unbind();
            $("#" + guid + " div").unbind();
            $("#" + guid + " ul").unbind();
            $("#" + guid + " li").unbind();
        };

        var close = function()
        {
            return;
        };

        var takeAction = function(e, page)
        {

            var el = BSC.E.GetElement(e, "a", "span");
            var info = (el.id).split("_");
            var guid = info[0];
            var action = info[1];
            var t = ((el.parentNode).id).split("_");
            var profileid = t[0];
            var test = BSC.E.GetElement(e, "ul", "li");
            var reportid = (test.id).split("_")[0];
            var additionalComments = "" + $("#" + profileid + "_comments").getValue();
            var sendPost = {};
            if (action == "Approve")
            {
                sendPost["guid"] = guid;
                sendPost["profileid"] = profileid;
                sendPost["reportid"] = reportid;
                sendPost["comments"] = additionalComments;
                sendPost["status"] = "Approve";

                BSC.UI.TwoOptionAlert(BSC.T.Get("JS.BSC.UI.Ws.Admin.OK"), BSC.T.Get("JS.BSC.UI.Ws.Admin.Cancel"), BSC.T.Get("JS.BSC.UI.Ws.Admin.takeAction.Approve.Title"), BSC.T.Get("JS.BSC.UI.Ws.Admin.takeAction.Approve.Desc"), BSC.UI.Ws.Admin.ProfileResolution.Profiles.Send, { SendPost: sendPost, Page: page }, BSC.UI.Ws.Admin.ProfileResolution.Profiles.Close, null, "info")
            }
            else if (action == "ApproveChanges")
            {
                sendPost["guid"] = guid;
                sendPost["profileid"] = profileid;
                sendPost["reportid"] = reportid;
                sendPost["comments"] = additionalComments;
                sendPost["status"] = "ApproveChanges";
                BSC.UI.TwoOptionAlert(BSC.T.Get("JS.BSC.UI.Ws.Admin.OK"), BSC.T.Get("JS.BSC.UI.Ws.Admin.Cancel"), BSC.T.Get("JS.BSC.UI.Ws.Admin.takeAction.Changes.Title"), BSC.T.Get("JS.BSC.UI.Ws.Admin.takeAction.Changes.Desc"), BSC.UI.Ws.Admin.ProfileResolution.Profiles.Send, { SendPost: sendPost, Page: page }, BSC.UI.Ws.Admin.ProfileResolution.Profiles.Close, null, "info")
            }
            else if (action == "ReactivateSuspended")
            {
                sendPost["guid"] = guid;
                sendPost["profileid"] = profileid;
                sendPost["reportid"] = reportid;
                sendPost["comments"] = "";
                sendPost["status"] = "ApproveChanges";
                BSC.UI.TwoOptionAlert(BSC.T.Get("JS.BSC.UI.Ws.Admin.OK"), BSC.T.Get("JS.BSC.UI.Ws.Admin.Cancel"), BSC.T.Get("JS.BSC.UI.Ws.Admin.takeAction.reactivate.Title"), BSC.T.Get("JS.BSC.UI.Ws.Admin.takeAction.reactivate.Desc"), BSC.UI.Ws.Admin.ProfileResolution.Profiles.Send, { SendPost: sendPost, Page: page }, BSC.UI.Ws.Admin.ProfileResolution.Profiles.Close, null, "info")
            }
            else if (action == "Suspend")
            {

                sendPost["guid"] = guid;
                sendPost["profileid"] = profileid;
                sendPost["reportid"] = reportid;
                sendPost["comments"] = additionalComments;
                sendPost["status"] = "Suspend";
                //(left_key, right_key, header, description, callback_left, data_left, callback_right, data_right, icon)
                BSC.UI.TwoOptionAlert(BSC.T.Get("JS.BSC.UI.Ws.Admin.OK"), BSC.T.Get("JS.BSC.UI.Ws.Admin.Cancel"), BSC.T.Get("JS.BSC.UI.Ws.Admin.takeAction.Suspend.Title"), BSC.T.Get("JS.BSC.UI.Ws.Admin.takeAction.Suspend.Desc"), BSC.UI.Ws.Admin.ProfileResolution.Profiles.Send, { SendPost: sendPost, Page: page }, BSC.UI.Ws.Admin.ProfileResolution.Profiles.Close, null, "info")
            }
            else if (action == "ContinueRating")
            {

                sendPost["guid"] = guid;
                sendPost["profileid"] = profileid;
                sendPost["reportid"] = reportid;
                sendPost["comments"] = additionalComments;
                sendPost["status"] = "ContinueRating";
                //(left_key, right_key, header, description, callback_left, data_left, callback_right, data_right, icon)
                BSC.UI.TwoOptionAlert(BSC.T.Get("JS.BSC.UI.Ws.Admin.OK"), BSC.T.Get("JS.BSC.UI.Ws.Admin.Cancel"), BSC.T.Get("JS.BSC.UI.Ws.Admin.takeAction.Applicant.Continue"), BSC.T.Get("JS.BSC.UI.Ws.Admin.takeAction.Applicant.ToRating"), BSC.UI.Ws.Admin.ProfileResolution.Profiles.Send, { SendPost: sendPost, Page: page }, BSC.UI.Ws.Admin.ProfileResolution.Profiles.Close, null, "info")
            }
            else if (action == "DeleteFromRating")
            {

                sendPost["guid"] = guid;
                sendPost["profileid"] = profileid;
                sendPost["reportid"] = reportid;
                sendPost["comments"] = additionalComments;
                sendPost["status"] = "deleteFromRating";
                //(left_key, right_key, header, description, callback_left, data_left, callback_right, data_right, icon)
                BSC.UI.TwoOptionAlert(BSC.T.Get("JS.BSC.UI.Ws.Admin.OK"), BSC.T.Get("JS.BSC.UI.Ws.Admin.Cancel"), BSC.T.Get("JS.BSC.UI.Ws.Admin.takeAction.Applicant.Title"), BSC.T.Get("JS.BSC.UI.Ws.Admin.takeAction.Applicant.DeleteInfo"), BSC.UI.Ws.Admin.ProfileResolution.Profiles.Send, { SendPost: sendPost, Page: page }, BSC.UI.Ws.Admin.ProfileResolution.Profiles.Close, null, "info")
            }
            else if (action == "ChangeGender")
            {

                sendPost["guid"] = guid;
                sendPost["profileid"] = profileid;
                sendPost["reportid"] = reportid;
                if (additionalComments == "")
                    additionalComments = BSC.T.Get("JS.BSC.UI.Ws.Admin.ChangegenderComment");

                sendPost["comments"] = additionalComments;
                sendPost["status"] = "changeGender";
                //(left_key, right_key, header, description, callback_left, data_left, callback_right, data_right, icon)
                BSC.UI.TwoOptionAlert(BSC.T.Get("JS.BSC.UI.Ws.Admin.OK"), BSC.T.Get("JS.BSC.UI.Ws.Admin.Cancel"), BSC.T.Get("JS.BSC.UI.Ws.Admin.Changegender"), BSC.T.Get("JS.BSC.UI.Ws.Admin.ChangegenderDesc"), BSC.UI.Ws.Admin.ProfileResolution.Profiles.Send, { SendPost: sendPost, Page: page }, BSC.UI.Ws.Admin.ProfileResolution.Profiles.Close, null, "info")
            }

        }

        var send = function(p1)
        {

            var sendPost = p1.SendPost;
            var page = p1.Page;
            var guid = sendPost["guid"];
            delete sendPost["guid"];

            BSC.D.AjaxPost("/Admin/ReportedProfileAction", sendPost, function(res)
            {

                // Html
                if (res.success)
                {
                    $("#" + res.id + "_wrapline").remove();
                    $("#" + res.id + "_profileItem").remove();
                    BSC.UI.Alert(BSC.T.Get("JS.BSC.UI.Ws.Admin.OK"), null, BSC.T.Get("JS.BSC.UI.Ws.Admin.Send.Success.Title"), BSC.T.Get("JS.BSC.UI.Ws.Admin.Send.Success.Desc"), null, null, "info")

                }
                else
                {
                    BSC.UI.Alert(BSC.T.Get("JS.BSC.UI.Ws.Admin.OK"), null, BSC.T.Get("JS.BSC.UI.Ws.Admin.Send.Error.Title"), BSC.T.Get("JS.BSC.UI.Ws.Admin.Send.Error.Desc"), null, guid, "info")
                    BSC.UI.HideStatus(guid, 200);

                }
            }, "json", guid);
        };

        var resetPassword = function(e)
        {
            alert(e);
        };

        var viewPassword = function(e, p1)
        {
            alert(e);
        };

        return {

            /// <summary></summary>
            /// <param name="data"></param>
            /// <return></return>
            Basebind: basebind,

            /// <summary></summary>
            /// <param name="data"></param>
            /// <return></return>
            Close: close,

            /// <summary></summary>
            /// <param name="data"></param>
            /// <return></return>
            Bind: bind,

            /// <summary></summary>
            /// <param name="data"></param>
            /// <return></return>
            Send: send,

            /// <summary></summary>
            /// <param name="data"></param>
            /// <return></return>
            Unbind: unbind,

            /// <summary></summary>
            /// <param name="data"></param>
            /// <return></return>
            Action: action,

            /// <summary></summary>
            /// <param name="data"></param>
            /// <return></return>
            TakeAction: takeAction,

            /// <summary></summary>
            /// <param name="data"></param>
            /// <return></return>
            ResetPassword: resetPassword,

            /// <summary></summary>
            /// <param name="data"></param>
            /// <return></return>
            ViewPassword: viewPassword
        };
    } ();
})();
BSC.E.Subscribe("load", BSC.UI.Ws.Admin.ProfileResolution.Profiles.Loaddata, null, "admin.profileresolution.profiles");
BSC.E.Subscribe("bind", BSC.UI.Ws.Admin.ProfileResolution.Profiles.Bind, null, "admin.profileresolution.profiles");
BSC.E.Subscribe("unbind", BSC.UI.Ws.Admin.ProfileResolution.Profiles.Unbind, null, "admin.profileresolution.profiles");


/// Validate
///		Suspended
/// ***************************************************************************
(function() {
	BSC.Require("BSC.UI.Ws.Admin.ProfileResolution");
	BSC.UI.Ws.Admin.ProfileResolution.ProfilesSuspended = function() {
		return {
		Bind: function(guid) {
				$("#" + guid + "_suspendedProfiles a.button").bind("click", guid, BSC.UI.Ws.Admin.ProfileResolution.ProfilesSuspended.TakeAction);
				$("#" + guid + "_pendingSuspensions a.button").bind("click", guid, BSC.UI.Ws.Admin.ProfileResolution.ProfilesSuspended.TakeAction);
			},
			Unbind: function(guid) {
				$("#" + guid + " a").unbind();
				$("#" + guid + " div").unbind();
				$("#" + guid + " ul").unbind();
				$("#" + guid + " li").unbind();
			},
			TakeAction: function(e) {
			BSC.UI.Ws.Admin.ProfileResolution.Profiles.TakeAction(e, "suspendedprofiles");
			},


			OnDenyChangesClick: function(e) {
				var el = BSC.E.GetElement(e, "li", "span", "a"); //stop ved "li" og find "a"
				var t = (el.id).split("_");
				var profileid = t[0];
				var p = new BSC.D.Param("BSC.WS.JS.Admin.Profile");
				var reason = $("#" + guid + "_" + profileid + "_suspendeditem h4").html();
				var value = $("#" + guid + "_" + profileid + "_notice").val();
				var date = $("#" + guid + "_" + profileid + "_suspendeditem span.date").html();
				p.Add("id", profileid);
				p.Add("notice", value);
				p.Add("reason", reason);
				p.Add("date", date);
				//BSC.D.Send(p, "Content.Admin", "SuspendProfile", null, null, "ProfileSuspended");
				$("#" + guid + "_" + profileid + "_wrapline").remove();
				$("#" + guid + "_" + profileid + "_suspendeditem").remove();
			},

			OnApproveChangesClick: function(e) {
			
				var el = BSC.E.GetElement(e, "li", "span", "a"); //stop ved "li" og find "a"
				var t = (el.id).split("_");
				var guid = t[0];
				var profileid = t[1];
				var p = new BSC.D.Param("BSC.WS.JS.Admin.Profile");
				var value = $("#" + guid + "_" + profileid + "_notice").val();
				var date = $("#" + guid + "_" + profileid + "_date").html();
				p.Add("id", profileid);
				p.Add("notice", value);
				p.Add("date", date);
				if (el.className.toLowerCase() == "approve") {
					var review = true;
					p.Add("review", review)
					//BSC.D.Send(p, "Content.Admin.Validation", "ApproveProfile", null, null, "ProfileSuspended");

					BSC.D.Send(p, "Content.Admin.Validation", "ApproveProfile",
                        function() {
                        	BSC.D.Send(null, "Content.Admin.Validation", "GetSuspendedProfilesReview", BSC.UI.Ws.Admin.ProfileResolution.ProfilesSuspended.RenderProfiles, null, guid);
                        }, null, profileid);

					$("#" + guid + "_" + profileid + "_wrapline").remove();
					$("#" + guid + "_" + profileid + "_suspendeditem").remove();
				}
				else if (el.className.toLowerCase() == "deny") {
					var review = true;
					var reason = $("#" + guid + "_" + profileid + "_suspendeditem h4").html();
					p.Add("reason", reason);
					p.Add("review", review)
					//BSC.D.Send(p, "Content.Admin.Validation", "SuspendProfile", null, null, "ProfileSuspended");
					BSC.D.Send(p, "Content.Admin.Validation", "SuspendProfile",
                        function() {
                        	BSC.D.Send(null, "Content.Admin.Validation", "GetPendingSuspensions", BSC.UI.Ws.Admin.ProfileResolution.ProfilesSuspended.RenderPendingSuspensions, null, guid);
                        }, null, profileid);


					$("#" + guid + "_" + profileid + "_wrapline").remove();
					$("#" + guid + "_" + profileid + "_suspendeditem").remove();
				}
				else if (el.className.toLowerCase() == "reactivate") {

					var review = false;
					var value = "";
					p.Add("notice", value);
					p.Add("review", review)
					//BSC.D.Send(p, "Content.Admin.Validation", "ApproveProfile", null, null, "ProfileSuspended");
					BSC.D.Send(p, "Content.Admin.Validation", "ApproveProfile",
                        function() {
                        	BSC.D.Send(null, "Content.Admin.Validation", "GetPendingSuspensions", BSC.UI.Ws.Admin.ProfileResolution.ProfilesSuspended.RenderPendingSuspensions, null, guid);
                        }, null, profileid);


					$("#" + guid + "_" + profileid + "_wrapline").remove();
					$("#" + guid + "_" + profileid + "_suspendeditem").remove();
				}
			}
		};
	} ();
})();
BSC.E.Subscribe("bind", BSC.UI.Ws.Admin.ProfileResolution.ProfilesSuspended.Bind, null, "admin.profileresolution.profilessuspended");
BSC.E.Subscribe("unbind", BSC.UI.Ws.Admin.ProfileResolution.ProfilesSuspended.Unbind, null, "admin.profileresolution.profilessuspended");

/// Validate
///		Applicants
/// ***************************************************************************
(function()
{
    BSC.Require("BSC.UI.Ws.Admin.Validate");
    BSC.UI.Ws.Admin.ProfileResolution.Applicants = function()
    {
        return {

            Bind: function(guid)
            {
            	$("#" + guid + "_suspendedApplicants").bind("click", guid, BSC.UI.Ws.Admin.ProfileResolution.Applicants.TakeAction);
            },

            TakeAction: function(e) {
            	BSC.UI.Ws.Admin.ProfileResolution.Profiles.TakeAction(e, "applicant");
            },
            
            Unbind: function(guid)
            {
                $("#" + guid + " a").unbind();
                $("#" + guid + " div").unbind();
                $("#" + guid + " ul").unbind();
                $("#" + guid + " li").unbind();
            }
	      };
    } ();
})();
BSC.E.Subscribe("bind", BSC.UI.Ws.Admin.ProfileResolution.Applicants.Bind, null, "admin.profileresolution.applicants");
BSC.E.Subscribe("unbind", BSC.UI.Ws.Admin.ProfileResolution.Applicants.Unbind, null, "admin.profileresolution.applicants");


/// Validate
///		Broadcast
/// ***************************************************************************
(function()
{
	BSC.Require("BSC.UI.Ws.Admin.ContentManagement");
	BSC.UI.Ws.Admin.ContentManagement.Broadcast = function()
	{

		return {
			Bind: function(guid)
			{
				$("#" + guid + "_broadcasts a.button").bind("click", guid, BSC.UI.Ws.Admin.ContentManagement.Broadcast.Editbroadcast);
			},
			Unbind: function(guid)
			{
				$("#" + guid + " a").unbind();
				$("#" + guid + " div").unbind();
				$("#" + guid + " ul").unbind();
				$("#" + guid + " li").unbind();
			},

			Editbroadcast: function(e)
			{
				var guid = e.data;
				var el = BSC.E.GetElement(e, "li", "span", "a"); //stop ved "li" og find "a"
				var t = (el.id).split("_");
				var broadcastID = t[0];
				var b = ((el.parentNode).id).split("_"); ; //stop ved "li" og find "a"
				var profileid = b[0];
				var action = el.className;
				var broadcast = $("#" + broadcastID + "_message").val();

				var data = {
					updateaction: action,
					bcid: broadcastID,
					profileid: profileid,
					message : broadcast
				};

				BSC.D.AjaxPost("/Admin/Updatebroadcast", data, function(res)
				{
					if (res.success)
						BSC.UI.Alert(BSC.T.Get("JS.BSC.UI.Ws.Admin.OK"), null, "Broadcast updated!", GO("/admin/contentmanagement/broadcast"), null, "info");
					else
						BSC.UI.Alert(BSC.T.Get("JS.BSC.UI.Ws.Admin.OK"), null, "Failed occured, please try again!", GO("/admin/contentmanagement/broadcast"), null, "info");
				}, "json", guid);
			},

			EditBroadcasst: function(e)
			{
				var el = BSC.E.GetElement(e, "li", "span", "a"); //stop ved "li" og find "a"
				var t = (el.id).split("_");
				var broadcastID = t[0];
				var b = (el.offsetParent.id).split("_"); ; //stop ved "li" og find "a"
				var guid = b[0];
				var profileid = b[1];
				var broadcast = $("#" + guid + "_" + profileid + "_bc").val();
				var p = new BSC.D.Param("BSC.WS.JS.Admin.BroadcastUpdate");
				p.Add("id", broadcastID);
				p.Add("message", broadcast);
				if (el.className.toLowerCase() == "delete")
				{
					BSC.D.Send(p, "Content.Admin.Validation", "Broadcast_NOGO",
                        function()
                        {
                        	BSC.D.Send(null, "Content.Admin.Validation", "GetBroadCast", BSC.UI.Ws.Admin.ContentManagement.Broadcast.RenderBroadcasts, null, guid);
                        }, null, profileid);
					$("#" + guid + "_" + profileid + "_wrapline").remove();
					$("#" + guid + "_" + profileid + "_broadcast").remove();
				}
				else
				{
					BSC.D.Send(p, "Content.Admin.Validation", "Broadcast_OK",
                        function()
                        {
                        	BSC.D.Send(null, "Content.Admin.Validation", "GetBroadCast", BSC.UI.Ws.Admin.ContentManagement.Broadcast.RenderBroadcasts, null, guid);
                        }, null, profileid);
					$("#" + guid + "_" + profileid + "_wrapline").remove();
					$("#" + guid + "_" + profileid + "_broadcast").remove();
				}
			},

			RenderBroadcasts: function(data)
			{
				var len = data.d.length;
				var guid = this.d;
				BSC.UI.Loader(guid);
				if (len != 0)
				{
					$("#" + guid + "_broadcast li").remove();
					$("#" + guid + "_broadcast b").remove();
					$("#" + guid + "_broadcast span").remove();
					for (i = 0; i < len; i++)
					{
						var broadcast = BSC.D.Ts.Get("Broadcasts");
						broadcast = broadcast.replace(/\{pictureid\}/ig, data.d[i].pictureid);
						broadcast = broadcast.replace(/\{reason\}/ig, data.d[i].reportReason);
						broadcast = broadcast.replace(/\{Creater\}/ig, data.d[i].profilename);
						broadcast = broadcast.replace(/\{time\}/ig, data.d[i].timeLeft);
						broadcast = broadcast.replace(/\{date\}/ig, data.d[i].reportDate);
						broadcast = broadcast.replace(/\{id\}/ig, guid + "_" + data.d[i].profileid);

						broadcast = broadcast.replace(/\{bid\}/ig, data.d[i].ID);
						broadcast = broadcast.replace(/\{broadcast\}/ig, data.d[i].message);
						if (data.d[i].gender == true)
						{
							var gender = BSC.T.Get("JS.BSC.UI.Ws.Admin.Male");
						}
						else
						{
							var gender = BSC.T.Get("JS.BSC.UI.Ws.Admin.Female");
						}
						broadcast = broadcast.replace(/\{gender\}/ig, gender);
						$("#" + guid + "_broadcast").append(broadcast);
					}
					$("#" + guid + "_broadcast a span.Save").click(BSC.UI.Ws.Admin.ContentManagement.Broadcast.EditBroadcast);
					$("#" + guid + "_broadcast a span.Delete").click(BSC.UI.Ws.Admin.ContentManagement.Broadcast.EditBroadcast);
					$("#" + guid + "_broadcast a.thumbs").click(BSC.UI.Ws.Admin.ProfileResolution.Profile.OnPictureClick);
				}
				else
				{
					var status = BSC.T.Get("JS.BSC.UI.Ws.Admin.RenderBroadcasts.NoBroadcasts");
					var html = "<span style=\"margin:0 auto; width:30%\">" + status + "</span>";
					$("#" + guid + "_broadcast").append(html);
				}
				BSC.UI.HideLoader(guid);
			}
		};
	} ();
})();
BSC.E.Subscribe("bind", BSC.UI.Ws.Admin.ContentManagement.Broadcast.Bind, null, "admin.contentmanagement.broadcast");
BSC.E.Subscribe("unbind", BSC.UI.Ws.Admin.ContentManagement.Broadcast.Unbind, null, "admin.contentmanagement.broadcast");


/// Feedback
///		Main
/// ***************************************************************************
(function()
{
	BSC.Require("BSC.UI.Ws.Admin");
	BSC.UI.Ws.Admin.Feedback = function()
	{
		var bind = function(p1)
		{
			var guid = p1;
			$(".markassolved").bind("click", guid, function(e)
			{
				var feedbackid = $(this).attr("name");
				var solved = $(this).attr("checked");
				var data = {
					feedbackID: feedbackid,
					Solved: solved
				};
				BSC.D.AjaxPost("/feedback/markassolved", data, function(res)
				{
					//do callback logic here!!!
					if (res.success)
					{

					}
					else
					{
						BSC.UI.Alert("Error", null, "Try again", null, null, "info");
					}
					BSC.UI.HideStatus(guid, 200);
				}, "json", guid);
			}); //alert($('input:checkbox[name=mark]:checked'));

			$("#" + guid + " _entries").bind("change", function(e)
			{
				alert($("#" + guid + " _entries").val());
			});
		};

		var unbind = function(p1)
		{
			var guid = p1;
		};

		return {
			Bind: bind,

			Unbind: unbind
		};
	} ();
})();
BSC.E.Subscribe("bind", BSC.UI.Ws.Admin.Feedback.Bind, null, "admin.feedback");
BSC.E.Subscribe("unbind", BSC.UI.Ws.Admin.Feedback.Unbind, null, "admin.feedback");

/// Support
///		Main
/// ***************************************************************************
(function()
{
	BSC.Require("BSC.UI.Ws.Admin");
	BSC.UI.Ws.Admin.Support = function()
	{
		var loaddata = function(p1)
		{
			var guid = p1;
			BSC.UI.HideStatus(guid, 200);
		};

		var render = function(p1)
		{
			var guid = p1;
			BSC.UI.HideStatus(guid, 200);
		};

		var bind = function(p1)
		{
			var guid = p1;

			$("#" + guid + "_getentries").bind("click", guid, function(e)
			{
				var entryvalue = $("#entries").val();
				var data = {
					entryvalue: entryvalue
				}
				BSC.D.AjaxGet("/admin/support", data, function(res)
				{
					//do callback logic here!!!
					if (!res.success)
						BSC.UI.Alert("Error", null, "Try again", null, null, "info");
					BSC.UI.HideStatus(guid, 200);
				}, "json", guid);
			});

			$("#" + guid + "_searchemail").bind("click", guid, function(e)
			{
				var email = $("#" + guid + "_emailinput").val();
				if (email == "")
				{
					alert("insert mail");
					return;
				}
				var data = {
					email: email
				}
				BSC.D.AjaxGet("/admin/profile_byemail_get", data, function(res)
				{
					if (res.success)
						alert("Name: " + res.data.Name + " # Password: " + res.data.Password + " # Status: " + res.data.ProfileGroupID + " # (Admin : 300, Premium : 100, Standard : 50, Suspended : 30, Applicant : 40, Ratet out : 20, Deleted : -200)");
					else
						alert("No results");
				}, "json", guid);
			});

			$("#" + guid + "_getarchive").bind("click", guid, function(e)
			{
				var entryvalue = $("#entries").val();
				var data = {
					entryvalue: entryvalue
				}
				BSC.D.AjaxGet("/admin/support/archive", data, function(res)
				{
					//do callback logic here!!!
					if (!res.success)
						BSC.UI.Alert("Error", null, "Try again", null, null, "info");
					BSC.UI.HideStatus(guid, 200);
				}, "json", guid);
			});


			$(".markassolved").bind("click", guid, function(e)
			{
				var feedbackid = $(this).attr("name");
				var solved = $(this).attr("checked");
				var data = {
					feedbackID: feedbackid,
					Solved: solved
				};
				BSC.D.AjaxPost("/feedback/markassolved", data, function(res)
				{
					//do callback logic here!!!
					if (res.success)
					{

					}
					else
					{
						BSC.UI.Alert("Error", null, "Try again", null, null, "info");
					}
					BSC.UI.HideStatus(guid, 200);
				}, "json", guid);
			});

			BSC.UI.HideStatus(guid, 200);
		};

		var unbind = function(p1)
		{
			var guid = p1;
		};

		return {
			Loaddata: loaddata,

			Render: render,

			Bind: bind,

			Unbind: unbind
		};
	} ();
})();
BSC.E.Subscribe("bind", BSC.UI.Ws.Admin.Support.Bind, null, "admin.support");
BSC.E.Subscribe("unbind", BSC.UI.Ws.Admin.Support.Unbind, null, "admin.support");
BSC.E.Subscribe("bind", BSC.UI.Ws.Admin.Support.Bind, null, "admin.support.archive");
BSC.E.Subscribe("unbind", BSC.UI.Ws.Admin.Support.Unbind, null, "admin.support.archive");


/// Content Management
///		Language
/// ***************************************************************************
(function()
{
	BSC.Require("BSC.UI.Ws.Admin.ContentManagement");
	BSC.UI.Ws.Admin.ContentManagement.Languages = function()
	{
		var languageID;
		var emailtemplatetype;
		var render = function(p1)
		{
			var guid = p1;
		};

		var bind = function(p1)
		{
			var guid = p1;
			var w = BSC.UI.Ws.Get(guid);
			var jQ = BSC.U.ParseQuery(w.query);
			if (jQ && jQ.language)
			{
				languageID = jQ.language;
				if (jQ.language)
				{
					$("#" + guid + "_wordsearch").bind("click", guid, BSC.UI.Ws.Admin.ContentManagement.Languages.WordSearch);
				}
				if (jQ.page)
				{
					$("#" + guid + "_wordtable td.savecolumn a").bind("click", guid, BSC.UI.Ws.Admin.ContentManagement.Languages.SaveWord);
					//$("#" + guid + "_wordtable td.savecolumn a").bind("click", guid, BSC.UI.Ws.Admin.ContentManagement.Languages.SaveAll);
				}
				else if (jQ.property || jQ.property == 0)
				{
					$("#" + guid + "_wordtable td.savecolumn a").bind("click", guid, BSC.UI.Ws.Admin.ContentManagement.Languages.SaveProperty);
					//$("#" + guid + "_wordtable td.savecolumn a").bind("click", guid, BSC.UI.Ws.Admin.ContentManagement.Languages.SaveAll);
				}
				else if (jQ.zodiacsign || jQ.zodiacsign == 0)
				{
					$("#" + guid + "_wordtable td.savecolumn a").bind("click", guid, BSC.UI.Ws.Admin.ContentManagement.Languages.SaveZodiacSign);
					//$("#" + guid + "_wordtable td.savecolumn a").bind("click", guid, BSC.UI.Ws.Admin.ContentManagement.Languages.SaveAll);
				}
				else if (jQ.groupcategories || jQ.groupcategories == 0)
				{
					$("#" + guid + "_wordtable td.savecolumn a").bind("click", guid, BSC.UI.Ws.Admin.ContentManagement.Languages.SaveGroupCategory);
					//$("#" + guid + "_wordtable td.savecolumn a").bind("click", guid, BSC.UI.Ws.Admin.ContentManagement.Languages.SaveAll);
				}
				else if (jQ.reportreasons || jQ.reportreasons == 1)
				{
					$("#" + guid + "_table td.savecolumn a").bind("click", guid, BSC.UI.Ws.Admin.ContentManagement.Languages.SaveReportReason);
				}
				else if (jQ.email)
				{
					$("#" + guid + "_tablefoot td.savecolumn a").bind("click", guid, BSC.UI.Ws.Admin.ContentManagement.Languages.SaveEmailTemplate);
				}
				else if (jQ.systemmail)
				{
					$("#" + guid + "_tablefoot td.savecolumn a").bind("click", guid, BSC.UI.Ws.Admin.ContentManagement.Languages.SaveSystemMail);
				}
				else if (jQ.menu)
				{
					$("#" + guid + "_tablefoot td.savecolumn a").bind("click", guid, BSC.UI.Ws.Admin.ContentManagement.Languages.SaveMenu);
				}
				else if (jQ.redflaged)
				{
					$("#" + guid + "_content a").bind("click", guid, BSC.UI.Ws.Admin.ContentManagement.Languages.SaveRedFlaged);
				}
				else if (jQ.searchword)
				{
					$("#" + guid + "_content a.button").bind("click", guid, BSC.UI.Ws.Admin.ContentManagement.Languages.SaveRedFlaged);
				}
			}
		};

		var saveredflaged = function(p1)
		{
			var e = p1;
			var guid = e.data;
			var element = BSC.E.GetElement(e, "td", "a");
			var id = element.id.split('_');
			var type = id[2];
			switch (type)
			{
				case "word":
					BSC.UI.Ws.Admin.ContentManagement.Languages.SaveWord(e);
					break;
				case "emailtemplate":
					BSC.UI.Ws.Admin.ContentManagement.Languages.SaveEmailTemplate(e);
					break;
				case "systemmail":
					BSC.UI.Ws.Admin.ContentManagement.Languages.SaveSystemMail(e);
					break;
				case "menu":
					BSC.UI.Ws.Admin.ContentManagement.Languages.SaveMenu(e);
					break;
				case "property":
					BSC.UI.Ws.Admin.ContentManagement.Languages.SaveProperty(e);
					break;
				case "reportreason":
					BSC.UI.Ws.Admin.ContentManagement.Languages.SaveReportReason(e);
					break;
				case "zodiacsign":
					BSC.UI.Ws.Admin.ContentManagement.Languages.SaveZodiacSign(e);
					break;
				case "groupcategory":
					BSC.UI.Ws.Admin.ContentManagement.Languages.SaveGroupCategory(e);
					break;
			}
		}

		var wordsearch = function(p1)
		{
			var e = p1;
			var guid = e.data;
			var text = $("#" + guid + "_textsearch").val();
			//validate input
			if (text === "")
			{
				BSC.UI.Alert("Ok", "Cancel", "Info", "No text inserted in title field. Insert text.", null, null, "info"); //ok_key, cancel_key, header, description, callback, data, icon
				return;
			}
			if (BSC.R.TextField.test(text))
			{
				BSC.UI.Alert(BSC.T.Get("JS.BSC.UI.Ws.Admin.OK"), BSC.T.Get("JS.BSC.UI.Ws.Admin.Cancel"), BSC.T.Get("JS.BSC.UI.Ws.Admin.saveemailtemplate.Subject"), null, null, "info");
				return;
			}
			text = encodeURIComponent(text);
			BSC.UI.ShowStatus(guid, "Loading...");
			GO("/admin/contentmanagement/languages/?language=" + languageID + "&searchword=" + text);
		}

		var unbind = function(p1)
		{
			var guid = p1;
		};

		var savemenu = function(p1)
		{
			var e = p1;
			var guid = e.data;
			var element = BSC.E.GetElement(e, "td", "a");
			var id = element.id.split('_');
			var menuID = id[1];

			// Input validation and 
			var title = $("#" + guid + '_' + menuID + '_menutitle').val();
			if (title === "")
			{
				BSC.UI.Alert("Ok", "Cancel", "Info", "No text inserted in title field. Insert text.", null, null, "info"); //ok_key, cancel_key, header, description, callback, data, icon
				return;
			}
			if (BSC.R.TextField.test(title))
			{
				BSC.UI.Alert(BSC.T.Get("JS.BSC.UI.Ws.Admin.OK"), BSC.T.Get("JS.BSC.UI.Ws.Admin.Cancel"), BSC.T.Get("JS.BSC.UI.Ws.Admin.saveemailtemplate.Subject"), null, null, "info");
				return;
			}
			var windowtitle = $("#" + guid + '_' + menuID + '_windowtitle').val();
			if (windowtitle === "")
			{
				BSC.UI.Alert("Ok", "Cancel", "Info", "No text inserted in windowtitle text field. Insert text.", null, null, "info");
				return;
			}
			if (BSC.R.TextField.test(windowtitle))
			{
				BSC.UI.Alert(BSC.T.Get("JS.BSC.UI.Ws.Admin.OK"), BSC.T.Get("JS.BSC.UI.Ws.Admin.Cancel"), BSC.T.Get("JS.BSC.UI.Ws.Admin.saveemailtemplate.Text"), null, null, "info");
				return;
			}
			var languageid = languageID;

			BSC.UI.ShowStatus(guid, "Loading...");

			var data ={ menuID: menuID, languageID: languageid, title: title, windowtitle: windowtitle };

			BSC.D.AjaxPost("/Admin/MenuTranslate", data, function(res)
			{
				//do callback logic here!!!
				if (res.success)
				{
					$("#" + guid + '_tbody_' + menuID + ' td span.redalert').remove();
					$("#" + guid + '_tbody_' + menuID + ' tr').animate({ backgroundColor: '#E3EADC' }, 500);
					//BSC.UI.Alert(BSC.T.Get("JS.BSC.UI.Ws.Admin.OK"), null, BSC.T.Get("JS.BSC.UI.Ws.Admin.Saved"), null, null, "info");
				}
				else
					BSC.UI.Alert("Error", null, "Try again", null, null, "info");

				BSC.UI.HideStatus(guid, 200);
			}, "json", guid);

//			$.ajax({
//				type: "Get",
//				url: "/Admin/MenuTranslate/?__guid=" + guid,
//				data: { menuID: menuID, languageID: languageid, title: title, windowtitle: windowtitle },
//				contentType: 'application/json; charset=utf-8',
//				dataType: "json",
//				beforeSend: (function(xml) { xml.setRequestHeader("X-IsJson", "true"); }),
//				success: function(res)
//				{
//					//do callback logic here!!!
//					if (res.success)
//					{
//						$("#" + guid + '_tbody_' + menuID + ' td span.redalert').remove();
//						$("#" + guid + '_tbody_' + menuID + ' tr').animate({ backgroundColor: '#E3EADC' }, 500);
//						//BSC.UI.Alert(BSC.T.Get("JS.BSC.UI.Ws.Admin.OK"), null, BSC.T.Get("JS.BSC.UI.Ws.Admin.Saved"), null, null, "info");
//					}
//					else
//						BSC.UI.Alert("Error", null, "Try again", null, null, "info");

//					BSC.UI.HideStatus(guid, 200);
//				}
//			});
		}

		/// Save word region
		var saveword = function(p1)
		{
			var e = p1;
			var guid = e.data;
			var element = BSC.E.GetElement(e, "td", "a");
			var id = element.id.split('_');
			var textID = id[0];
			var text = $("#" + guid + '_' + textID + " textarea").val();
			if (text === "")
			{
				BSC.UI.Alert("Ok", "Cancel", "Info", "No text inserted in text field. Insert text.", null, null, "info"); //ok_key, cancel_key, header, description, callback, data, icon
				return;
			}
			if (BSC.R.TextField.test(text))
			{
				BSC.UI.Alert(BSC.T.Get("JS.BSC.UI.Ws.Admin.OK"), BSC.T.Get("JS.BSC.UI.Ws.Admin.Cancel"), BSC.T.Get("JS.BSC.UI.Ws.Admin.saveword.InvalidInput"), null, null, "info");
				return;
			}
			var languageid = languageID;

			BSC.UI.ShowStatus(guid, "Loading...");
			$.post("/Admin/SaveTranslatedWords/?__guid=" + guid, { text: escape(text), languageID: languageid, textID: textID }, function(res)
			{
				//do callback logic here!!!
				if (res.success)
				{
					$("#" + textID + "_alert").remove();
					$("#" + guid + '_' + textID).animate({ backgroundColor: '#E3EADC' }, 500);
				}
				else
					BSC.UI.Alert("Error", null, "Try again", null, null, "info");

				BSC.UI.HideStatus(guid, 200);
			}, "json");
		}

		var saveall = function(p1)
		{
			var e = p1;
			var t = BSC.E.GetElement(e, "td", "a");
		}

		/// Save profile property region
		var saveproperty = function(p1)
		{
			var e = p1;
			var guid = e.data;
			var element = BSC.E.GetElement(e, "td", "a");
			var elementid = element.id.split('_');
			var id = elementid[0];
			var name = $("#" + guid + '_' + id + " textarea").val();
			if (name === "")
			{
				BSC.UI.Alert("Ok", "Cancel", "Info", "No text inserted in name field. Insert text.", null, null, "info"); //ok_key, cancel_key, header, description, callback, data, icon
				return;
			}
			if (BSC.R.TextField.test(name))
			{
				BSC.UI.Alert(BSC.T.Get("JS.BSC.UI.Ws.Admin.OK"), BSC.T.Get("JS.BSC.UI.Ws.Admin.Cancel"), BSC.T.Get("JS.BSC.UI.Ws.Admin.saveword.InvalidInput"), null, null, "info");
				return;
			}
			var languageid = languageID;

			BSC.UI.ShowStatus(guid, "Loading...");
			$.post("/Admin/SaveTranslatedProperty/?__guid=" + guid, { name: name, languageID: languageid, id: id }, function(res)
			{
				//do callback logic here!!!
				if (res.success)
				{
					$("#" + id + "_alert").remove();
					$("#" + guid + '_' + id).animate({ backgroundColor: '#E3EADC' }, 500);
				}
				else
					BSC.UI.Alert("Error", null, "Try again", null, null, "info");

				BSC.UI.HideStatus(guid, 200);
			}, "json");
		}

		/// Save report reason region
		var savereportreason = function(p1)
		{
			var e = p1;
			var guid = e.data;
			var element = BSC.E.GetElement(e, "td", "a");
			var elementid = element.id.split('_');
			var id = elementid[1];
			var title = $("#" + guid + '_' + id + "_title").val();
			if (title === "")
			{
				BSC.UI.Alert("Ok", "Cancel", "Info", "No text inserted in title field. Insert text.", null, null, "info"); //ok_key, cancel_key, header, description, callback, data, icon
				return;
			}
			if (BSC.R.TextField.test(title))
			{
				BSC.UI.Alert(BSC.T.Get("JS.BSC.UI.Ws.Admin.OK"), BSC.T.Get("JS.BSC.UI.Ws.Admin.Cancel"), BSC.T.Get("JS.BSC.UI.Ws.Admin.saveword.InvalidInput"), null, null, "info");
				return;
			}
			var description = $("#" + guid + '_' + id + "_description").val();
			if (description === "")
			{
				BSC.UI.Alert("Ok", "Cancel", "Info", "No text inserted in description field. Insert text.", null, null, "info"); //ok_key, cancel_key, header, description, callback, data, icon
				return;
			}
			if (BSC.R.TextField.test(description))
			{
				BSC.UI.Alert(BSC.T.Get("JS.BSC.UI.Ws.Admin.OK"), BSC.T.Get("JS.BSC.UI.Ws.Admin.Cancel"), BSC.T.Get("JS.BSC.UI.Ws.Admin.saveword.InvalidInput"), null, null, "info");
				return;
			}
			var languageid = languageID;

			BSC.UI.ShowStatus(guid, "Loading...");
			$.post("/Admin/SaveTranslatedReportReason/?__guid=" + guid, { title: title, description: description, languageID: languageid, id: id }, function(res)
			{
				//do callback logic here!!!
				if (res.success)
				{
					$("#" + guid + '_' + id + '_tbody span.redalert').remove();
					$("#" + guid + '_' + id + '_tbody tr').animate({ backgroundColor: '#E3EADC' }, 500);
				}
				else
					BSC.UI.Alert("Error", null, "Try again", null, null, "info");

				BSC.UI.HideStatus(guid, 200);
			}, "json");
		}

		/// Save profile zodiacsign region
		var savezodiacsign = function(p1)
		{
			var e = p1;
			var guid = e.data;
			var element = BSC.E.GetElement(e, "td", "a");
			var elementid = element.id.split('_');
			var id = elementid[0];
			var name = $("#" + guid + '_' + id + " textarea").val();
			if (name === "")
			{
				BSC.UI.Alert("Ok", "Cancel", "Info", "No text inserted in name field. Insert text.", null, null, "info"); //ok_key, cancel_key, header, description, callback, data, icon
				return;
			}
			if (BSC.R.TextField.test(name))
			{
				BSC.UI.Alert(BSC.T.Get("JS.BSC.UI.Ws.Admin.OK"), BSC.T.Get("JS.BSC.UI.Ws.Admin.Cancel"), BSC.T.Get("JS.BSC.UI.Ws.Admin.saveword.InvalidInput"), null, null, "info");
				return;
			}
			var languageid = languageID;

			BSC.UI.ShowStatus(guid, "Loading...");
			$.post("/Admin/SaveZodiacSign/?__guid=" + guid, { id: id, languageID: languageid, name: name }, function(res)
			{
				//do callback logic here!!!
				if (res.success)
				{
					$("#" + id + "_alert").remove();
					$("#" + guid + '_' + id).animate({ backgroundColor: '#E3EADC' }, 500);
				}
				else
					BSC.UI.Alert("Error", null, "Try again", null, null, "info");

				BSC.UI.HideStatus(guid, 200);
			}, "json");
		}

		/// Save group category region
		var savegroupcategory = function(p1)
		{
			var e = p1;
			var guid = e.data;
			var element = BSC.E.GetElement(e, "td", "a");
			var elementid = element.id.split('_');
			var id = elementid[0];
			var title = $("#" + guid + '_' + id + " textarea").val();
			if (title === "")
			{
				BSC.UI.Alert("Ok", "Cancel", "Info", "No text inserted in title field. Insert text.", null, null, "info"); //ok_key, cancel_key, header, description, callback, data, icon
				return;
			}
			if (BSC.R.TextField.test(name))
			{
				BSC.UI.Alert(BSC.T.Get("JS.BSC.UI.Ws.Admin.OK"), BSC.T.Get("JS.BSC.UI.Ws.Admin.Cancel"), BSC.T.Get("JS.BSC.UI.Ws.Admin.saveword.InvalidInput"), null, null, "info");
				return;
			}
			var languageid = languageID;

			BSC.UI.ShowStatus(guid, "Loading...");
			$.post("/Admin/SaveTranslatedGroupCategory/?__guid=" + guid, { id: id, languageID: languageid, title: title }, function(res)
			{
				//do callback logic here!!!
				if (res.success)
				{
					$("#" + id + "_alert").remove();
					$("#" + guid + '_' + id).animate({ backgroundColor: '#E3EADC' }, 500);
				}
				else
					BSC.UI.Alert("Error", null, "Try again", null, null, "info");

				BSC.UI.HideStatus(guid, 200);
			}, "json");
		}

		///save email template region
		var saveemailtemplate = function(p1)
		{
			var e = p1;
			var guid = e.data;
			var element = BSC.E.GetElement(e, "td", "a");
			var id = element.id.split('_');
			var emailID = id[1];

			// Input validation and 
			var subject = $("#" + guid + '_' + emailID + '_subject').val();
			if (subject === "")
			{
				BSC.UI.Alert("Ok", "Cancel", "Info", "No text inserted in subject field. Insert text.", null, null, "info"); //ok_key, cancel_key, header, description, callback, data, icon
				return;
			}
			if (BSC.R.TextField.test(subject))
			{
				BSC.UI.Alert(BSC.T.Get("JS.BSC.UI.Ws.Admin.OK"), BSC.T.Get("JS.BSC.UI.Ws.Admin.Cancel"), BSC.T.Get("JS.BSC.UI.Ws.Admin.saveemailtemplate.Subject"), null, null, "info");
				return;
			}
			var text = $("#" + guid + '_' + emailID + '_text').val();
			if (text === "")
			{
				BSC.UI.Alert("Ok", "Cancel", "Info", "No text inserted in text field. Insert text.", null, null, "info");
				return;
			}
			if (BSC.R.TextField.test(text))
			{
				BSC.UI.Alert(BSC.T.Get("JS.BSC.UI.Ws.Admin.OK"), BSC.T.Get("JS.BSC.UI.Ws.Admin.Cancel"), BSC.T.Get("JS.BSC.UI.Ws.Admin.saveemailtemplate.Text"), null, null, "info");
				return;
			}
			var html = ""; //$("#" + guid + '_' + emailID + '_html').val();
			//            if (html === "")
			//            {
			//                BSC.UI.Alert("Ok", "Cancel", "Info", "No text inserted in html field. Insert text.", null, null, "info");
			//                return;
			//            }
			//            if (BSC.R.TextField.test(html))
			//            {
			//                BSC.UI.Alert(BSC.T.Get("JS.BSC.UI.Ws.Admin.OK"), BSC.T.Get("JS.BSC.UI.Ws.Admin.Cancel"), BSC.T.Get("JS.BSC.UI.Ws.Admin.saveemailtemplate.HTML"), null, null, "info");
			//                return;
			//            }
			var languageid = languageID;

			BSC.UI.ShowStatus(guid, "Loading...");
			// string emailID, string type, string languageID, string subject, string text, string html
			$.post("/Admin/SaveEmailTemplate/?__guid=" + guid, { emailID: emailID, languageID: languageid, subject: subject, text: text, html: escape(html) }, function(res)
			{
				//do callback logic here!!!
				if (res.success)
				{
					$("#" + guid + '_tbody_' + emailID + ' td span.redalert').remove();
					$("#" + guid + '_tbody_' + emailID + ' tr').animate({ backgroundColor: '#E3EADC' }, 500);
					//BSC.UI.Alert(BSC.T.Get("JS.BSC.UI.Ws.Admin.OK"), null, BSC.T.Get("JS.BSC.UI.Ws.Admin.Saved"), null, null, "info");
				}
				else
					BSC.UI.Alert("Error", null, "Try again", null, null, "info");

				BSC.UI.HideStatus(guid, 200);
			}, "json");
		}

		var savesystemmail = function(p1)
		{
			var e = p1;
			var guid = e.data;
			var element = BSC.E.GetElement(e, "td", "a");
			var id = element.id.split('_');
			var systemmailID = id[1];

			// Input validation and 
			var subject = $("#" + guid + '_' + systemmailID + '_subject').val();
			if (subject === "")
			{
				BSC.UI.Alert("Ok", "Cancel", "Info", "No text inserted in subject field. Insert text.", null, null, "info"); //ok_key, cancel_key, header, description, callback, data, icon
				return;
			}
			if (BSC.R.TextField.test(subject))
			{
				BSC.UI.Alert(BSC.T.Get("JS.BSC.UI.Ws.Admin.OK"), BSC.T.Get("JS.BSC.UI.Ws.Admin.Cancel"), BSC.T.Get("JS.BSC.UI.Ws.Admin.savesystemmail.InvalidInput"), null, null, "info");
				return;
			}
			var fromname = $("#" + guid + '_' + systemmailID + '_fromname').val();
			if (fromname === "")
			{
				BSC.UI.Alert("Ok", "Cancel", "Info", "No text inserted in text field. Insert text.", null, null, "info");
				return;
			}
			if (BSC.R.TextField.test(fromname))
			{
				BSC.UI.Alert(BSC.T.Get("JS.BSC.UI.Ws.Admin.OK"), BSC.T.Get("JS.BSC.UI.Ws.Admin.Cancel"), BSC.T.Get("JS.BSC.UI.Ws.Admin.savesystemmail.InvalidFromname"), null, null, "info");
				return;
			}
			var body = $("#" + guid + '_' + systemmailID + '_body').val();
			if (body === "")
			{
				BSC.UI.Alert("Ok", "Cancel", "Info", "No text inserted in html field. Insert text.", null, null, "info");
				return;
			}
			if (BSC.R.TextField.test(body))
			{
				BSC.UI.Alert(BSC.T.Get("JS.BSC.UI.Ws.Admin.OK"), BSC.T.Get("JS.BSC.UI.Ws.Admin.Cancel"), BSC.T.Get("JS.BSC.UI.Ws.Admin.savesystemmail.Invalidbody"), null, null, "info");
				return;
			}
			var languageid = languageID;

			BSC.UI.ShowStatus(guid, "Loading...");
			$.post("/Admin/SaveTranslatedSystemMail/?__guid=" + guid, { systemMailID: systemmailID, languageID: languageid, subject: subject, fromname: fromname, body: escape(body) }, function(res)
			{
				//do callback logic here!!!
				if (res.success)
				{
					$("#" + guid + '_tbody_' + systemmailID + ' td span.redalert').remove();
					$("#" + guid + '_tbody_' + systemmailID + ' tr').animate({ backgroundColor: '#E3EADC' }, 500);
					//BSC.UI.Alert(BSC.T.Get("JS.BSC.UI.Ws.Admin.OK"), null, BSC.T.Get("JS.BSC.UI.Ws.Admin.Saved"), null, null, "info");
				}
				else
					BSC.UI.Alert("Error", null, "Try again", null, null, "info");

				BSC.UI.HideStatus(guid, 200);
			}, "json");
		}

		return {
			// Loaddata: loaddata,

			Render: render,

			Bind: bind,

			Unbind: unbind,

			SaveWord: saveword,

			SaveProperty: saveproperty,

			SaveZodiacSign: savezodiacsign,

			SaveGroupCategory: savegroupcategory,

			SaveMenu: savemenu,

			SaveReportReason: savereportreason,

			SaveEmailTemplate: saveemailtemplate,

			SaveSystemMail: savesystemmail,

			WordSearch: wordsearch,

			SaveRedFlaged: saveredflaged
		};
	} ();
})();
BSC.E.Subscribe("bind", BSC.UI.Ws.Admin.ContentManagement.Languages.Bind, null, "admin.contentmanagement.languages");
BSC.E.Subscribe("unbind", BSC.UI.Ws.Admin.ContentManagement.Languages.Unbind, null, "admin.contentmanagement.languages");



/// Content Management
///		OriginLanguage
/// ***************************************************************************
(function() {
    BSC.Require("BSC.UI.Ws.Admin.ContentManagement");
    BSC.UI.Ws.Admin.ContentManagement.OriginLanguage = function() {
        var languageID;
        var render = function(p1) {
            var guid = p1;
        };

        var bind = function(p1) {
            var guid = p1;
            var w = BSC.UI.Ws.Get(guid);
            var jQ = BSC.U.ParseQuery(w.query);
            if (jQ) {
                if (jQ.page) {
                    $("#" + guid + "_wordtable td.savecolumn a").bind("click", guid, BSC.UI.Ws.Admin.ContentManagement.OriginLanguage.SaveWord);
                    //                    $("#" + guid + "_wordtable td.savecolumn a").bind("click", guid, BSC.UI.Ws.Admin.ContentManagement.OriginLanguage.SaveAll);
                }
                if (jQ.email) {
                    $("#" + guid + "_tablefoot td.savecolumn a").bind("click", guid, BSC.UI.Ws.Admin.ContentManagement.OriginLanguage.SaveEmailTemplate);
                }
                else if (jQ.systemmail) {
                    $("#" + guid + "_tablefoot td.savecolumn a").bind("click", guid, BSC.UI.Ws.Admin.ContentManagement.OriginLanguage.SaveSystemMail);
                }
                else if (jQ.menu) {
                    $("#" + guid + "_tablefoot td.savecolumn a").bind("click", guid, BSC.UI.Ws.Admin.ContentManagement.OriginLanguage.SaveMenu);
                }
                else if (jQ.property) {
                    $("#" + guid + "_wordtable td.savecolumn a").bind("click", guid, BSC.UI.Ws.Admin.ContentManagement.OriginLanguage.SaveProperty);
                }
                else if (jQ.zodiacsign || jQ.zodiacsign == 0) {
                    $("#" + guid + "_wordtable td.savecolumn a").bind("click", guid, BSC.UI.Ws.Admin.ContentManagement.OriginLanguage.SaveZodiacSign);
                    //$("#" + guid + "_wordtable td.savecolumn a").bind("click", guid, BSC.UI.Ws.Admin.ContentManagement.Languages.SaveAll);
                }
                else if (jQ.groupcategories || jQ.groupcategories == 0) {
                    $("#" + guid + "_wordtable td.savecolumn a").bind("click", guid, BSC.UI.Ws.Admin.ContentManagement.OriginLanguage.SaveGroupCategory);
                    //$("#" + guid + "_wordtable td.savecolumn a").bind("click", guid, BSC.UI.Ws.Admin.ContentManagement.Languages.SaveAll);
                }
                else if (jQ.reportreasons || jQ.reportreasons == 1) {
                    $("#" + guid + "_table td.savecolumn a").bind("click", guid, BSC.UI.Ws.Admin.ContentManagement.OriginLanguage.SaveReportReason);
                }
            }
        };

        var unbind = function(p1) {
            var guid = p1;
        };

        /// Save word region
        var saveword = function(p1) {
            var e = p1;
            var guid = e.data;
            var element = BSC.E.GetElement(e, "td", "a");
            var id = element.id.split('_');
            var textID = id[0];
            var text = $("#" + guid + '_' + textID).val();
            if (text === "") {
                BSC.UI.Alert("Ok", "Cancel", "Info", "No text inserted in text field. Insert text.", null, null, "info"); //ok_key, cancel_key, header, description, callback, data, icon
                return;
            }
            if (BSC.R.TextField.test(text)) {
                BSC.UI.Alert(BSC.T.Get("JS.BSC.UI.Ws.Admin.OK"), BSC.T.Get("JS.BSC.UI.Ws.Admin.Cancel"), BSC.T.Get("JS.BSC.UI.Ws.Admin.saveword.InvalidInput"), null, null, "info");
                return;
            }
            var isUpdate = false;

            BSC.UI.ShowStatus(guid, "Loading...");
            if (id[1] === "save")
                isUpdate = false;
            else if (id[1] === "update")
                isUpdate = true;

            $.post("/Admin/SaveOriginLanguageWords/?__guid=" + guid, { text: escape(text), textID: textID, isUpdate: isUpdate }, function(res) {
                //do callback logic here!!!
                if (res.success) {
                    $("#" + guid + '_tbody tr').animate({ backgroundColor: '#E3EADC' }, 500);
                }
                else
                    BSC.UI.Alert("Error", null, "Try again", null, null, "info");

                BSC.UI.HideStatus(guid, 200);
            }, "json");
        }

        /// Save group category region
        var savegroupcategory = function(p1) {
            var e = p1;
            var guid = e.data;
            var element = BSC.E.GetElement(e, "td", "a");
            var elementid = element.id.split('_');
            var id = elementid[0];
            var title = $("#" + guid + '_' + id + " textarea").val();
            if (title === "") {
                BSC.UI.Alert("Ok", "Cancel", "Info", "No text inserted in title field. Insert text.", null, null, "info"); //ok_key, cancel_key, header, description, callback, data, icon
                return;
            }
            if (BSC.R.TextField.test(title)) {
                BSC.UI.Alert(BSC.T.Get("JS.BSC.UI.Ws.Admin.OK"), BSC.T.Get("JS.BSC.UI.Ws.Admin.Cancel"), BSC.T.Get("JS.BSC.UI.Ws.Admin.saveword.InvalidInput"), null, null, "info");
                return;
            }
            var isUpdate = false;

            if (id[1] === "save")
                isUpdate = false;
            else if (id[1] === "update")
                isUpdate = true;

            BSC.UI.ShowStatus(guid, "Loading...");
            $.post("/Admin/SaveOriginGroupCategory/?__guid=" + guid, { id: id, title: title, isUpdate: isUpdate }, function(res) {
                //do callback logic here!!!
                if (res.success) {
                    $("#" + id + "_alert").remove();
                    $("#" + guid + '_' + id).animate({ backgroundColor: '#E3EADC' }, 500);
                }
                else
                    BSC.UI.Alert("Error", null, "Try again", null, null, "info");

                BSC.UI.HideStatus(guid, 200);
            }, "json");
        }

        // Menu
        var savemenu = function(p1) {
            var e = p1;
            var guid = e.data;
            var element = BSC.E.GetElement(e, "td", "a");
            var id = element.id.split('_');
            var menuID = id[0];

            // Input validation and 
            var title = $("#" + guid + '_menutitle').val();
            if (!title && title === "") {
                BSC.UI.Alert("Ok", "Cancel", "Info", "No text inserted in title field. Insert text.", null, null, "info"); //ok_key, cancel_key, header, description, callback, data, icon
                return;
            }
            if (BSC.R.TextField.test(title)) {
                BSC.UI.Alert(BSC.T.Get("JS.BSC.UI.Ws.Admin.OK"), BSC.T.Get("JS.BSC.UI.Ws.Admin.Cancel"), BSC.T.Get("JS.BSC.UI.Ws.Admin.saveemailtemplate.Subject"), null, null, "info");
                return;
            }
            var windowtitle = $("#" + guid + '_windowtitle').val();
            if (!windowtitle && windowtitle === "") {
                BSC.UI.Alert("Ok", "Cancel", "Info", "No text inserted in windowtitle text field. Insert text.", null, null, "info");
                return;
            }
            if (BSC.R.TextField.test(windowtitle)) {
                BSC.UI.Alert(BSC.T.Get("JS.BSC.UI.Ws.Admin.OK"), BSC.T.Get("JS.BSC.UI.Ws.Admin.Cancel"), BSC.T.Get("JS.BSC.UI.Ws.Admin.saveemailtemplate.Text"), null, null, "info");
                return;
            }
            var isUpdate = false;

            if (id[1] === "save")
                isUpdate = false;
            else if (id[1] === "update")
                isUpdate = true;

            BSC.UI.ShowStatus(guid, "Loading...");
            $.post("/Admin/SaveOriginMenu/?__guid=" + guid, { menuID: menuID, title: title, windowtitle: windowtitle, isUpdate: isUpdate }, function(res) {
                //do callback logic here!!!
                if (res.success) {
                    $("#" + guid + '_tbody tr').animate({ backgroundColor: '#E3EADC' }, 500);
                }
                else
                    BSC.UI.Alert("Error", null, "Try again", null, null, "info");

                BSC.UI.HideStatus(guid, 200);
            }, "json");
        }

        /// Save profile property region
        var saveproperty = function(p1) {
            var e = p1;
            var guid = e.data;
            var element = BSC.E.GetElement(e, "td", "a");
            var elementid = element.id.split('_');
            var id = elementid[0];
            var name = $("#" + guid + '_' + id + " textarea").val();
            if (name === "") {
                BSC.UI.Alert("Ok", "Cancel", "Info", "No text inserted in text field. Insert text.", null, null, "info"); //ok_key, cancel_key, header, description, callback, data, icon
                return;
            }
            if (BSC.R.TextField.test(name)) {
                BSC.UI.Alert(BSC.T.Get("JS.BSC.UI.Ws.Admin.OK"), BSC.T.Get("JS.BSC.UI.Ws.Admin.Cancel"), BSC.T.Get("JS.BSC.UI.Ws.Admin.saveword.InvalidInput"), null, null, "info");
                return;
            }
            var isUpdate = false;

            if (id[1] === "save")
                isUpdate = false;
            else if (id[1] === "update")
                isUpdate = true;

            BSC.UI.ShowStatus(guid, "Loading...");
            $.post("/Admin/SaveOriginProperty/?__guid=" + guid, { name: name, id: id, isUpdate: isUpdate }, function(res) {
                //do callback logic here!!!
                if (res.success) {
                    $("#" + id + "_alert").remove();
                    $("#" + guid + '_' + id).animate({ backgroundColor: '#E3EADC' }, 500);
                }
                else
                    BSC.UI.Alert("Error", null, "Try again", null, null, "info");

                BSC.UI.HideStatus(guid, 200);
            }, "json");
        }

        /// Save report reason region
        var savereportreason = function(p1) {
            var e = p1;
            var guid = e.data;
            var element = BSC.E.GetElement(e, "td", "a");
            var elementid = element.id.split('_');
            var id = elementid[0];
            var title = $("#" + guid + '_' + id + "_title").val();
            if (title === "") {
                BSC.UI.Alert("Ok", "Cancel", "Info", "No text inserted in title text field. Insert text.", null, null, "info"); //ok_key, cancel_key, header, description, callback, data, icon
                return;
            }
            if (BSC.R.TextField.test(title)) {
                BSC.UI.Alert(BSC.T.Get("JS.BSC.UI.Ws.Admin.OK"), BSC.T.Get("JS.BSC.UI.Ws.Admin.Cancel"), BSC.T.Get("JS.BSC.UI.Ws.Admin.saveword.InvalidInput"), null, null, "info");
                return;
            }
            var description = $("#" + guid + '_' + id + "_description").val();
            if (description === "") {
                BSC.UI.Alert("Ok", "Cancel", "Info", "No text inserted in description text field. Insert text.", null, null, "info"); //ok_key, cancel_key, header, description, callback, data, icon
                return;
            }
            if (BSC.R.TextField.test(description)) {
                BSC.UI.Alert(BSC.T.Get("JS.BSC.UI.Ws.Admin.OK"), BSC.T.Get("JS.BSC.UI.Ws.Admin.Cancel"), BSC.T.Get("JS.BSC.UI.Ws.Admin.saveword.InvalidInput"), null, null, "info");
                return;
            }
            var isUpdate = false;

            if (id[1] === "save")
                isUpdate = false;
            else if (id[1] === "update")
                isUpdate = true;
            BSC.UI.ShowStatus(guid, "Loading...");
            $.post("/Admin/SaveOriginReportReason/?__guid=" + guid, { title: title, description: description, id: id, isUpdate: isUpdate }, function(res) {
                //do callback logic here!!!
                if (res.success) {
                    $("#" + guid + '_' + id + '_tbody span.redalert').remove();
                    $("#" + guid + '_' + id + '_tbody tr').animate({ backgroundColor: '#E3EADC' }, 500);
                }
                else
                    BSC.UI.Alert("Error", null, "Try again", null, null, "info");

                BSC.UI.HideStatus(guid, 200);
            }, "json");
        }

        // System mail
        var savesystemmail = function(p1) {
            var e = p1;
            var guid = e.data;
            var element = BSC.E.GetElement(e, "td", "a");
            var id = element.id.split('_');
            var systemmailID = id[0];

            // Input validation and 
            var subject = $("#" + guid + '_subject').val();
            if (subject === "") {
                BSC.UI.Alert("Ok", "Cancel", "Info", "No text inserted in subject field. Insert text.", null, null, "info"); //ok_key, cancel_key, header, description, callback, data, icon
                return;
            }
            if (BSC.R.TextField.test(subject)) {
                BSC.UI.Alert(BSC.T.Get("JS.BSC.UI.Ws.Admin.OK"), BSC.T.Get("JS.BSC.UI.Ws.Admin.Cancel"), BSC.T.Get("JS.BSC.UI.Ws.Admin.savesystemmail.InvalidInput"), null, null, "info");
                return;
            }
            var fromname = $("#" + guid + '_fromname').val();
            if (text === "") {
                BSC.UI.Alert("Ok", "Cancel", "Info", "No text inserted in text field. Insert text.", null, null, "info");
                return;
            }
            if (BSC.R.TextField.test(fromname)) {
                BSC.UI.Alert(BSC.T.Get("JS.BSC.UI.Ws.Admin.OK"), BSC.T.Get("JS.BSC.UI.Ws.Admin.Cancel"), BSC.T.Get("JS.BSC.UI.Ws.Admin.savesystemmail.InvalidFromname"), null, null, "info");
                return;
            }
            var body = $("#" + guid + '_body').val();
            if (html === "") {
                BSC.UI.Alert("Ok", "Cancel", "Info", "No text inserted in html field. Insert text.", null, null, "info");
                return;
            }
            if (BSC.R.TextField.test(body)) {
                BSC.UI.Alert(BSC.T.Get("JS.BSC.UI.Ws.Admin.OK"), BSC.T.Get("JS.BSC.UI.Ws.Admin.Cancel"), BSC.T.Get("JS.BSC.UI.Ws.Admin.savesystemmail.Invalidbody"), null, null, "info");
                return;
            }
            var isUpdate = false;

            if (id[1] === "save")
                isUpdate = false;
            else if (id[1] === "update")
                isUpdate = true;

            BSC.UI.ShowStatus(guid, "Loading...");
            $.post("/Admin/SaveOriginSystemMail/?__guid=" + guid, { systemMailID: systemmailID, subject: subject, fromname: fromname, body: escape(body), isUpdate: isUpdate }, function(res) {
                //do callback logic here!!!
                if (res.success) {
                    $("#" + guid + '_tbody td span.redalert').remove();
                    $("#" + guid + '_tbody tr').animate({ backgroundColor: '#E3EADC' }, 500);
                    //BSC.UI.Alert(BSC.T.Get("JS.BSC.UI.Ws.Admin.OK"), null, BSC.T.Get("JS.BSC.UI.Ws.Admin.Saved"), null, null, "info");
                }
                else
                    BSC.UI.Alert("Error", null, "Try again", null, null, "info");

                BSC.UI.HideStatus(guid, 200);
            }, "json");
        }

        /// Save profile zodiacsign region
        var savezodiacsign = function(p1) {
            var e = p1;
            var guid = e.data;
            var element = BSC.E.GetElement(e, "td", "a");
            var elementid = element.id.split('_');
            var id = elementid[0];
            var name = $("#" + guid + '_' + id + " textarea").val();
            if (name === "") {
                BSC.UI.Alert("Ok", "Cancel", "Info", "No text inserted in text field. Insert text.", null, null, "info"); //ok_key, cancel_key, header, description, callback, data, icon
                return;
            }
            if (BSC.R.TextField.test(name)) {
                BSC.UI.Alert(BSC.T.Get("JS.BSC.UI.Ws.Admin.OK"), BSC.T.Get("JS.BSC.UI.Ws.Admin.Cancel"), BSC.T.Get("JS.BSC.UI.Ws.Admin.saveword.InvalidInput"), null, null, "info");
                return;
            }
            var isUpdate = false;

            if (id[1] === "save")
                isUpdate = false;
            else if (id[1] === "update")
                isUpdate = true;

            BSC.UI.ShowStatus(guid, "Loading...");
            $.post("/Admin/SaveOriginZodiacSign/?__guid=" + guid, { id: id, name: name, isUpdate: isUpdate }, function(res) {
                //do callback logic here!!!
                if (res.success) {
                    $("#" + id + "_alert").remove();
                    $("#" + guid + '_' + id).animate({ backgroundColor: '#E3EADC' }, 500);
                }
                else
                    BSC.UI.Alert("Error", null, "Try again", null, null, "info");

                BSC.UI.HideStatus(guid, 200);
            }, "json");
        }

        ///save email template region
        var saveemailtemplate = function(p1) {
            var e = p1;
            var guid = e.data;
            var element = BSC.E.GetElement(e, "td", "a");
            var id = element.id.split('_');
            var emailID = id[0];

            // Input validation and 
            var subject = $("#" + guid + '_subject').val();
            if (subject === "") {
                BSC.UI.Alert("Ok", "Cancel", "Info", "No text inserted in subject field. Insert text.", null, null, "info"); //ok_key, cancel_key, header, description, callback, data, icon
                return;
            }
            if (BSC.R.TextField.test(subject)) {
                BSC.UI.Alert(BSC.T.Get("JS.BSC.UI.Ws.Admin.OK"), BSC.T.Get("JS.BSC.UI.Ws.Admin.Cancel"), BSC.T.Get("JS.BSC.UI.Ws.Admin.saveemailtemplate.Subject"), null, null, "info");
                return;
            }
            var text = $("#" + guid + '_text').val();
            if (text === "") {
                BSC.UI.Alert("Ok", "Cancel", "Info", "No text inserted in text field. Insert text.", null, null, "info");
                return;
            }
            if (BSC.R.TextField.test(text)) {
                BSC.UI.Alert(BSC.T.Get("JS.BSC.UI.Ws.Admin.OK"), BSC.T.Get("JS.BSC.UI.Ws.Admin.Cancel"), BSC.T.Get("JS.BSC.UI.Ws.Admin.saveemailtemplate.Text"), null, null, "info");
                return;
            }
            var html = ""; //$("#" + guid + '_html').val();
//            if (html === "") {
//                BSC.UI.Alert("Ok", "Cancel", "Info", "No text inserted in html field. Insert text.", null, null, "info");
//                return;
//            }
//            if (BSC.R.TextField.test(html)) {
//                BSC.UI.Alert(BSC.T.Get("JS.BSC.UI.Ws.Admin.OK"), BSC.T.Get("JS.BSC.UI.Ws.Admin.Cancel"), BSC.T.Get("JS.BSC.UI.Ws.Admin.saveemailtemplate.HTML"), null, null, "info");
//                return;
//            }
            var isUpdate = false;

            BSC.UI.ShowStatus(guid, "Loading...");
            if (id[1] === "save")
                isUpdate = false;
            else if (id[1] === "update")
                isUpdate = true;

            // string emailID, string type, string languageID, string subject, string text, string html
            $.post("/Admin/SaveOriginEmailTemplate/?__guid=" + guid, { emailID: emailID, subject: subject, text: escape(text), html: escape(html), isUpdate: isUpdate }, function(res) {
                //do callback logic here!!!
                if (res.success) {
                    $("#" + guid + '_tbody td span.redalert').remove();
                    $("#" + guid + '_tbody tr').animate({ backgroundColor: '#E3EADC' }, 500);
                    //BSC.UI.Alert(BSC.T.Get("JS.BSC.UI.Ws.Admin.OK"), null, BSC.T.Get("JS.BSC.UI.Ws.Admin.Saved"), null, null, "info");
                }
                else
                    BSC.UI.Alert("Error", null, "Try again", null, null, "info");

                BSC.UI.HideStatus(guid, 200);
            }, "json");
        }

        return {
            // Loaddata: loaddata,

            Render: render,

            Bind: bind,

            Unbind: unbind,

            SaveWord: saveword,

            SaveEmailTemplate: saveemailtemplate,

            SaveSystemMail: savesystemmail,

            SaveMenu: savemenu,

            SaveProperty: saveproperty,

            SaveZodiacSign: savezodiacsign,

            SaveGroupCategory: savegroupcategory,

            SaveReportReason: savereportreason
        };
    } ();
})();
BSC.E.Subscribe("bind", BSC.UI.Ws.Admin.ContentManagement.OriginLanguage.Bind, null, "admin.contentmanagement.originlanguage");
BSC.E.Subscribe("unbind", BSC.UI.Ws.Admin.ContentManagement.OriginLanguage.Unbind, null, "admin.contentmanagement.originlanguage");

/// Content Management
///		SendMailSystem
/// ***************************************************************************
(function()
{
    BSC.Require("BSC.UI.Ws.Admin.ContentManagement");
    BSC.UI.Ws.Admin.ContentManagement.SendMails = function()
    {
        var languageID;
        var cache = {};

        var load = function(p1)
        {
            var guid = p1;
            var w = BSC.UI.Ws.Get(guid);
            if (!(w.query) && cache[guid].Countries)
            {
                for (key in cache[guid].Countries)
                {
                    var countryCode = cache[guid].Countries[key];
                    var countryName = $("#" + guid + "_" + countryCode).html();
                    $("#" + guid + "_" + countryCode).remove();
                    var html = "<li><a id=\"" + guid + "_" + countryCode + "\">" + countryName + "</a></li>";
                    $("#" + guid + "_selectedlist").append(html);
                }
                return;
            }
            var jQ = BSC.U.ParseQuery(w.query);
            if (jQ)
            {
                if (jQ.sendmail || jQ.sendmail == 3)
                {
                    var html_countries = "<li>Countries: ";
                    for (key in cache[guid].Countries)
                    {
                        html_countries += "" + cache[guid].Countries[key] + ", ";
                    }                    
                    html_countries += "</li>";
                    $("#" + guid + "_filterlist").append(html_countries);

                    var html_profilegroup = "<li>Profilegroup: " + cache[guid].Criteria["profilegroup"] + "</li>";
                    $("#" + guid + "_filterlist").append(html_profilegroup);

                    var html_gender = "<li>Gender: " + cache[guid].Criteria["gender"] + "</li>";
                    $("#" + guid + "_filterlist").append(html_gender);
                }
            }

        };

        var bind = function(p1)
        {
            var guid = p1;
            if (!cache[guid])
            {
                cache[guid] = {};
                cache[guid].Countries = {};
                cache[guid].Criteria = {};
                cache[guid].Criteria["gender"] = "Both";
                cache[guid].Criteria["profilegroup"] = 10;
                cache[guid].MessageType = "board";
            }

            var w = BSC.UI.Ws.Get(guid);
            var jQ = BSC.U.ParseQuery(w.query);
            if (jQ)
            {
                if (jQ.sendmail || jQ.sendmail == 3)
                {
                    $("#" + guid + "_sendmessage").bind("click", guid, BSC.UI.Ws.Admin.ContentManagement.SendMails.OnSendClick);
                    $("#" + guid + "_previewmessage").bind("click", guid, BSC.UI.Ws.Admin.ContentManagement.SendMails.OnSendPreviewClick);
                    $("#" + guid + "_inputform input.messagetype").bind("change", guid, BSC.UI.Ws.Admin.ContentManagement.SendMails.OnChangeMessageType);
                    return;
                }
                if (jQ.recievers || jQ.recievers == 2)
                {
                    $("#" + guid + "_genderfilter label").bind("click", guid, BSC.UI.Ws.Admin.ContentManagement.SendMails.OnRadioButtonClick);
                    $("#" + guid + "_profilegroupfilter label").bind("click", guid, BSC.UI.Ws.Admin.ContentManagement.SendMails.OnCheckboxClick);
                    return;
                }
                // Step 1: Filter by country
                $("#" + guid + "_selectlist").bind("click", guid, BSC.UI.Ws.Admin.ContentManagement.SendMails.OnAddCountryClick);
                $("#" + guid + "_selectedlist").bind("click", guid, BSC.UI.Ws.Admin.ContentManagement.SendMails.OnRemoveCountryClick);
                $("#" + guid + "_addall").bind("click", guid, BSC.UI.Ws.Admin.ContentManagement.SendMails.OnAddAllCountryClick);
                $("#" + guid + "_removeall").bind("click", guid, BSC.UI.Ws.Admin.ContentManagement.SendMails.OnRemoveAllCountryClick);
            }
        };

        var unbind = function(p1)
        {
            var guid = p1;
            $("#" + guid + "_selectedlist").unbind();
            $("#" + guid + "_selectlist").unbind();
            $("#" + guid + "_next_2").unbind();
            $("#" + guid + "_sendmail").unbind();
        };

        // Step 1: filter by country
        var onAddCountryClick = function(p1)
        {
            var e = p1;
            var guid = e.data;
            var element = BSC.E.GetElement(e, "ul", "a");
            var id = element.id.split('_');
            var countryCode = id[1];
            var countryName = $(element).html();
            cache[guid].Countries[countryCode] = countryCode;
            $(element).remove();
            var html = "<li><a id=\"" + guid + "_" + countryCode + "\">" + countryName + "</a></li>";
            $("#" + guid + "_selectedlist").append(html);
        }

        var onAddAllCountryClick = function(p1)
        {
            var e = p1;
            var guid = e.data;
            var lielements = $("#" + guid + "_selectlist li");
            for (i = 0; i < lielements.length; i++)
            {
                var element = lielements[i];
                var id = element.firstChild.id.split("_");
                var countryCode = id[1];
                cache[guid].Countries[countryCode] = countryCode;
            }
            $("#" + guid + "_selectedlist").append(lielements);
        }

        var onRemoveAllCountryClick = function(p1)
        {
            var e = p1;
            var guid = e.data;
            var lielements = $("#" + guid + "_selectedlist li");
            cache[guid].Countries = {};
            $("#" + guid + "_selectlist").append(lielements);
        }

        var onRemoveCountryClick = function(p1)
        {
            var e = p1;
            var guid = e.data;
            var element = BSC.E.GetElement(e, "ul", "a");
            if (!element) return;
            var id = element.id.split('_');
            var countryCode = id[1];
            var countryName = $(element).html();
            delete cache[guid].Countries[countryCode];
            $(element).remove();
            var html = "<li><a id=\"" + guid + "_" + countryCode + "\">" + countryName + "</a></li>";
            $("#" + guid + "_selectlist").append(html);
        }

        // Step 2: Filter by criteria
        var onCheckboxClick = function(p1)
        {
            var e = p1;
            var guid = e.data;
            var element = BSC.E.GetElement(e, "div", "input");
            var profilegroup = element.id;
            cache[guid].Criteria["profilegroup"] = profilegroup;
        }

        var onRadioButtonClick = function(p1)
        {
            var e = p1;
            var guid = e.data;
            var element = BSC.E.GetElement(e, "div", "input");
            cache[guid].Criteria["gender"] = element.id;
        }

        // Step 3: Send message
        var onSendClick = function(p1)
        {
            var e = p1;
            var guid = e.data;
            var e = BSC.E.GetElement(e, "div", "a");
            if (/\inactive/.test(e.className))
            {
                BSC.UI.Alert(BSC.T.Get("JS.BSC.UI.Ws.Admin.OK"), null, "Info", "Press preview before sending message.", null, null, "info");
                return;
            }
            var text = $("#" + guid + "_textarea").val();
            if (BSC.R.TextField.test(text))
            {
                BSC.UI.Alert(BSC.T.Get("JS.BSC.UI.Ws.Admin.OK"), BSC.T.Get("JS.BSC.UI.Ws.Admin.Cancel"), BSC.T.Get("JS.BSC.UI.Ws.Admin.saveemailtemplate.HTML"), null, null, "info");
                return;
            }
            var countries = "";
            for (key in cache[guid].Countries)
            {
                countries += cache[guid].Countries[key];
                countries += ",";
            }
            if (countries === "")
                BSC.UI.Alert(BSC.T.Get("JS.BSC.UI.Ws.Admin.OK"), BSC.T.Get("JS.BSC.UI.Ws.Admin.Cancel"), "No countries are selected!!!", "Are you sure you want to send it??", null, null, "info");

            var profilegroup = cache[guid].Criteria["profilegroup"];
            var gender = cache[guid].Criteria["gender"];
            var messageType = cache[guid].MessageType;
            if (messageType == "mail")
            {
                var subject = $("#" + guid + "_subjectheader input").getValue();
                if (subject === "")
                {
                    BSC.UI.Alert(BSC.T.Get("JS.BSC.UI.Ws.Admin.OK"), null, "Info", "No text inserted in text field. Insert text.", null, null, "info");
                    return;
                }
                if (BSC.R.TextField.test(subject))
                {
                    BSC.UI.Alert(BSC.T.Get("JS.BSC.UI.Ws.Admin.OK"), BSC.T.Get("JS.BSC.UI.Ws.Admin.Cancel"), BSC.T.Get("JS.BSC.UI.Ws.Admin.saveemailtemplate.HTML"), null, null, "info");
                    return;
                }
            }

            $("#" + guid + "_sendmessage").addClass("inactive");

            BSC.UI.ShowStatus(guid);
            // eventually: countrycodes, profilegroup, message type, text
            $.post("/Admin/SendSystemMessage/?__guid=" + guid, { text: escape(text), countrycodes: countries, profilegroup: profilegroup, gender: gender, messagetype: messageType, subject: escape(subject) }, function(res)
            {
                //do callback logic here!!!
                if (res.success)
                {
                    BSC.UI.Alert(BSC.T.Get("JS.BSC.UI.Ws.Admin.OK"), null, "Info", "Message send", null, null, "info");
                }
                else
                {
                    BSC.UI.Alert(BSC.T.Get("JS.BSC.UI.Ws.Admin.OK"), null, "Error", "Try again", null, null, "error");
                }
                BSC.UI.HideStatus(guid, 200);
            }, "json");
        }

        var onSendPreviewClick = function(p1)
        {
            var e = p1;
            var guid = e.data;
            var text = $("#" + guid + "_textarea").val();
            if (text === "")
            {
                BSC.UI.Alert(BSC.T.Get("JS.BSC.UI.Ws.Admin.OK"), null, "Info", "No text inserted in text field. Insert text.", null, null, "info");
                return;
            }
            if (BSC.R.TextField.test(text))
            {
                BSC.UI.Alert(BSC.T.Get("JS.BSC.UI.Ws.Admin.OK"), BSC.T.Get("JS.BSC.UI.Ws.Admin.Cancel"), BSC.T.Get("JS.BSC.UI.Ws.Admin.saveemailtemplate.HTML"), null, null, "info");
                return;
            }
            var messageType = cache[guid].MessageType;
            if (messageType == "mail")
            {
                var subject = $("#" + guid + "_subjectheader input").getValue();
                if (subject === "")
                {
                    BSC.UI.Alert(BSC.T.Get("JS.BSC.UI.Ws.Admin.OK"), null, "Info", "No text inserted in text field. Insert text.", null, null, "info");
                    return;
                }
                if (BSC.R.TextField.test(subject))
                {
                    BSC.UI.Alert(BSC.T.Get("JS.BSC.UI.Ws.Admin.OK"), BSC.T.Get("JS.BSC.UI.Ws.Admin.Cancel"), BSC.T.Get("JS.BSC.UI.Ws.Admin.saveemailtemplate.HTML"), null, null, "info");
                    return;
                }
            }
            BSC.UI.ShowStatus(guid);
            // eventually: countrycodes, profilegroup, message type, text
            $.post("/Admin/SendPreviewMessage/?__guid=" + guid, { text: escape(text), messageType: messageType, subject: escape(subject) }, function(res)
            {
                //do callback logic here!!!
                if (res.success)
                {
                    $("#" + guid + "_sendmessage").removeClass("inactive");
                    BSC.UI.Alert("Ok", null, "Info", "Message send", null, null, "info");
                }
                else
                    BSC.UI.Alert("Error", null, "Try again", res.message, null, null, "info");
                BSC.UI.HideStatus(guid, 200);
            }, "json");
        }

        var onChangeMessageType = function(p1)
        {
            var e = p1;
            var guid = e.data;
            if (cache[guid].MessageType == "board")//($("#" + guid + "_subjectheader")[0].className === "hidden")
            {
                $("#" + guid + "_subjectheader").fadeIn(1000, function() { $("#" + guid + "_subjectheader").removeClass("hidden"); });
                cache[guid].MessageType = "mail";
            }
            else
            {
                $("#" + guid + "_subjectheader").fadeOut(1000); //, function() { $("#" + guid + "_subjectheader").addClass("hidden"); });
                cache[guid].MessageType = "board";
            }
            //$("#" + guid + "_subjectheader").toggle();
        }

        return {
            Load: load,

            // Render: render,

            Bind: bind,

            Unbind: unbind,

            // Step 1: Filter by country
            OnAddCountryClick: onAddCountryClick,

            OnRemoveCountryClick: onRemoveCountryClick,

            OnAddAllCountryClick: onAddAllCountryClick,

            OnRemoveAllCountryClick: onRemoveAllCountryClick,

            // Step 2: Filter by criteria
            OnCheckboxClick: onCheckboxClick,

            OnRadioButtonClick: onRadioButtonClick,

            // Step 3: Send message
            OnSendClick: onSendClick,

            OnSendPreviewClick: onSendPreviewClick,

            OnChangeMessageType: onChangeMessageType
        };
    } ();
})();
BSC.E.Subscribe("load", BSC.UI.Ws.Admin.ContentManagement.SendMails.Load, null, "admin.contentmanagement.sendmails");
BSC.E.Subscribe("bind", BSC.UI.Ws.Admin.ContentManagement.SendMails.Bind, null, "admin.contentmanagement.sendmails");
BSC.E.Subscribe("unbind", BSC.UI.Ws.Admin.ContentManagement.SendMails.Unbind, null, "admin.contentmanagement.sendmails");




