﻿	/// <reference path="~/Scripts/IntelliSense/Intellisense.js" />

(function()
{
    BSC.UI.Ws.Home = function()
    {
        // Private Properties
        var localdata = {};
        var loading_findfriends = false;
        var load = function(p1)
        {
            var guid = p1;

            var w = BSC.UI.Ws.Get(guid);
            var jQ = BSC.U.ParseQuery(w.query);

            if (jQ.login && !BSC.D.P.IsLoggedIn())
                BSC.UI.AlertLogin();

            localdata[guid] = { days: 3, page : 1 };
            BSC.D.AjaxAbort(guid);
            var w = BSC.UI.Ws.Get(guid);
            var jQ = BSC.U.ParseQuery(w.query, { activation: '' });

            $("#" + guid + " ul.yourgroups li:first").addClass("first");
            $("#" + guid + " ul.yourgroups li:last").addClass("bottom");

            if (jQ)
            {
                if (jQ.activation == "success")
                {
                    BSC.UI.Alert(BSC.T.Get("JS.BSC.UI.Ws.Home.Loaddata.StartNow"), null, BSC.T.Get("JS.BSC.UI.Ws.Home.Loaddata.Title"), BSC.T.Get("JS.BSC.UI.Ws.Home.Loaddata.Desc"), function() { GO("/home"); }, null, "info");
                }
                else if (jQ.activation == "isVerified")
                    BSC.UI.Alert(BSC.T.Get("JS.BSC.UI.Ws.Home.Loaddata.StartNow"), null, "Email is already verified", BSC.T.Get("JS.BSC.UI.Ws.Home.Loaddata.Desc"), function() { GO("/home"); }, null, "info");
                else if (jQ.activation == "notVerified")
                    BSC.UI.Alert("Ok", null, "Email not verified", "Unable to verify your email at the moment,<br />please try again later.", function() { GO("/home"); }, null, "info");

                if (jQ.activationcode)
                {
                    BSC.D.AjaxPost("/Home/EmailActivation", { ActivationCode: jQ.activationcode, guid: guid }, function(res)
                    {
                        //do callback logic here!!!
                        if (res.success)
                        {
                            GO("/home/editprofile/profileinfo");
                            return;
                        }
                        BSC.UI.HideStatus(guid, 200);
                    }, "json", guid);
                }
            }

            if (BSC.D.P.IsLoggedIn())
            {
                var w = BSC.UI.Ws.Get(guid);
                var jQ = BSC.U.ParseQuery(w.query);
                if (jQ)
                    var feedid = jQ.feedid;

                BSC.D.AjaxGet("/Home/SocialStreamList", { feedid: feedid, reset: true }, function(res)
                {
                    document.getElementById(guid + "_feeds").innerHTML = res;

                    if (feedid != null)
                    {
                        $("#" + guid + "_showentire").css("display", "");
                        $("#" + guid + "_seeolderboarditems").css("display", "none");
                    }
                    $("#" + guid + "_feedsloader").hide();
                    BSC.E.MapHrefs();
                    $("#" + guid + "_Template textarea.expand").autogrow();
                    $("#" + guid + "_showentire").bind("click", guid, function(e)
                    {
                        var guid = e.data;
                        BSC.D.AjaxGet("/Home/SocialStreamList", { reset: false }, function(res)
                        {
                            $("#" + guid + "_feeds").html(res);
                            $("#" + guid + "_showentire").css("display", "none");
                            $("#" + guid + "_seeolderboarditems").css("display", "");
                            BSC.UI.Ws.Get(guid).uri = "/home";
                            BSC.P.ChangeURI(BSC.UI.Ws.Get(guid).uri);
                            $("#" + guid + "_feedsloader").hide();
                            BSC.E.MapHrefs();
                            try
                            {
                                $("#" + guid + " textarea.expand").autogrow();
                            }
                            catch (e) { }
                            //            		var json = $("#" + guid + "_feed_json").val();
                            //            		var data = BSC.D.JSON.Parse(json);
                        }, "html", guid);
                    });
                }, "html", guid);
            }
        };


        function getInternetExplorerVersion()
        // Returns the version of Windows Internet Explorer or a -1
        // (indicating the use of another browser).
        {
            var rv = -1; // Return value assumes failure.
            if (navigator.appName == 'Microsoft Internet Explorer')
            {
                var ua = navigator.userAgent;
                var re = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");
                if (re.exec(ua) != null)
                    rv = parseFloat(RegExp.$1);
            }
            return rv;
        }

        var bind = function(p1)
        {
            var guid = p1;



            var w = BSC.UI.Ws.Get(guid);
            var jQ = BSC.U.ParseQuery(w.query);
            if (jQ.login && !BSC.D.P.IsLoggedIn())
                BSC.UI.AlertLogin();

            /// Resent Email verification email
            $("#" + guid + "_resendmail").bind("click", guid, function(p1)
            {
                var e = p1;
                var guid = e.data;
                //select value fra textarea
                var newEmail = $("#" + guid + "_profileemail").val();
                BSC.D.AjaxPost("/Profile/ResendActivationEmail", { newEmail: newEmail }, function(res)
                {
                    //do callback logic here!!!
                    if (res.success)
                    {
                        var profile = BSC.D.P.GetData();
                        BSC.UI.Alert(BSC.T.Get("JS.BSC.UI.Ws.Home.VoteMeAgainOk"), null, BSC.T.Get("JS.BSC.UI.Ws.Home.MailSent"), BSC.T.Get("JS.BSC.UI.Ws.Home.Verification").replace(/\{useremail\}/i, profile.Email), GO("/home"), null, "info");
                    }
                    else
                    {
                        if (res.message == "Email exists" || res.statuscode == -2)
                            BSC.UI.Alert(BSC.T.Get("JS.BSC.UI.Ws.Home.VoteMeAgainOk"), null, BSC.T.Get("JS.BSC.UI.Ws.Home.VerificationFailed"), BSC.T.Get("JS.BSC.UI.Ws.Home.VerificationFailedDesc"), null, null, "info");
                    }
                    BSC.UI.HideStatus(guid, 200);
                }, "json", guid);
            });
            /// Send review changed to validation
            $("#" + guid + "_review").bind("click", { guid: guid }, BSC.UI.Ws.Home.SendToValidation);
            /// Feed
            $("#" + guid + "_reviewappl").bind("click", { guid: guid }, BSC.UI.Ws.Home.SendToValidation);
            /// Rate me again
            $("#" + guid + "_ratemeagain").bind("click", { guid: guid }, function(e)
            {
                var el = BSC.E.GetElement(e, "div", "span");
                if (!el.id) return;
                var t = ((el.firstChild).id).split("_");
                var profileid = t[0];
                var name = t[1];
                BSC.D.AjaxPost("/Profile/VoteMeAgain", { profileid: profileid }, function(res)
                {
                    if (res.success)
                    {
                        BSC.UI.Alert(BSC.T.Get("JS.BSC.UI.Ws.Home.VoteMeAgainOk"), null, BSC.T.Get("JS.BSC.UI.Ws.Home.VoteMeAgainDesc"), "", null, null, "info");
                        GO("/home");
                        return;
                    }
                }, "json", guid);
            });
            /// Feed
            $("#" + guid + "_feeds").bind("click", guid, function(e)
            {
                var guid = e.data;
                var el = BSC.E.GetElement(e, "div", "a");
                if (el.id)
                {
                    if ($(el).hasClass("streamaction"))
                    {
                        BSC.UI.ShowStatus(guid, "Sending request...");
                        var t = (el.id).split("_");
                        var feedID = t[0];
                        var action = t[1];

                        var data = { feedID: feedID, action: action };

                        BSC.D.AjaxPost("/SocialStream/RequestAction", data, function(res)
                        {
                            if (res.success)
                            {
                                BSC.UI.W.Reload(guid);
                                // Change feed
//                                $("#" + feedID + "_notifications").fadeOut(300, function(e)
//                                {
//                                    $(this).remove();
//                                    // check if more notification
//                                    if ($("#" + guid + "_notifications div.innerwrap div").length == 0)
//                                        $("#" + guid + "_notifications").remove();
//                                });
                                BSC.UI.HideStatus(guid, 200);
                            }
                            else
                            {
                                if (res.message == "profilegroup")
                                    BSC.UI.Alert("Ok", null, "Info", "You have to be full member<br />before you can join the group", null, null, "info");

                                // Change feed
                                $("#" + feedID + "_notifications").fadeOut(300, function(e)
                                {
                                    $(this).remove();
                                    // check if more notification
                                    if ($("#" + guid + "_notifications div.innerwrap div").length == 0)
                                        $("#" + guid + "_notifications").remove();
                                });
                                //alert("An error occured");
                            }
                        }, "json", guid);
                    }
                    else if ($(el).hasClass("menuaction"))
                    {
                        $(el).next().show();
                        e.preventDefault(); e.stopPropagation();
                    }
                    else if ($(el).hasClass("menuaction_item"))
                    {
                        var guid = e.data;
                        var t = (el.id).split("_");
                        var feedID = t[0];
                        var action = t[1];
                        switch (action)
                        {
                            case "delete":
                                $("#social_" + feedID).fadeOut(300, function(e) { $(this).remove(); });
                                BSC.D.Send({ data: feedID }, "Content.Profile", "SocialStreamEntry_Remove", function(res)
                                {
                                    if (res.succes)
                                        BSC.D.AjaxPost("/Stream/ClearSocialStreamCache", {}, function(res) { }, "json", guid);
                                });
                                break;
                        }
                    }
                    else if ($(el).hasClass("addfeedcomment"))
                    {
                        var guid = e.data;
                        var t = (el.id).split("_");
                        var feedID = t[1];

                        if (!BSC.D.P.IsLoggedIn())
                        {
                            BSC.UI.AlertLogin();
                            return false;
                        }
                        else if (BSC.D.P.IsFullMember() && !BSC.D.P.IsPaying())
                        {
                            BSC.UI.AlertCurrentlyFREE();
                            return false;
                        }

                        $("#" + guid + "_" + feedID + "_addcomment").remove();
                        $("#" + guid + "_" + feedID + "_comments").slideDown("fast");
                    }
                    else if ($(el).hasClass("savefeedcomment"))
                    {
                        var guid = e.data;
                        var t = (el.id).split("_");
                        var feedID = t[1];
                        var comment = $("#" + guid + "_" + feedID + "_feedcomment").getValue();
                        var commentsCount = $("#" + guid + "_" + feedID + "_comments div.entrycomment").length;

                        if (comment.length == 0)
                        {
                            BSC.UI.Alert("OK", null, "Please add some text", "", null, null, "info");
                            return false;
                        }

                        BSC.D.AjaxPost("/Stream/AddFeedComment", { comment: comment, feedID: feedID, commentsCount: commentsCount }, function(res)
                        {
                            $("#" + guid + "_" + feedID + "_feedcomment").val("").css({ height: 0 });
                            $("#" + guid + "_" + feedID + "_comments div.pointer").remove();
                            $("#" + guid + "_" + feedID + "_addcomment").remove();
                            $("#" + guid + "_" + feedID + "_newcomment").before(res.FeedHtml);
                            //$("#" + guid + "_" + feedID + "_comments div.t").after(res.FeedHtml);
                            $("#" + guid + "_" + res.ID + "_entry").fadeIn("slow");
                        }, "json", guid);
                    }
                    else if ($(el).hasClass("removefeedcomment"))
                    {
                        var guid = e.data;
                        var t = (el.id).split("_");
                        var feedCommentID = t[1];
                        var feedID = t[3];

                        BSC.UI.Alert("Remove", "Cancel", "Are you sure ?", "You are about to remove a feedcomment. This cannot be undone.", function(e)
                        {
                            $("#" + guid + "_" + feedCommentID + "_entry").fadeOut("fast", function()
                            {
                                // Server call
                                BSC.D.AjaxPost("/Stream/RemoveFeedComment", { feedCommentID: feedCommentID, feedID: feedID }, function(res) { }, "json", guid);
                                $(this).remove();
                            });
                        }, null, "info");
                    }

                }
            });

            /// Feed
            $("#" + guid + "_seeolderboarditems").bind("click", guid,
	            function(e)
	            {
	                var guid = e.data;
	                localdata[guid].days++;

	                localdata[guid].page++;

	                $("#" + guid + "_feedsloader").show();

	                BSC.D.AjaxGet("/Home/SocialStreamList", { reset: false, page : localdata[guid].page }, function(res)
	                {
	                    localdata[guid].page++;
	                    // Hide See Older button
	                    if (res == "")
	                        $("#" + guid + "_seeolderboarditems").hide();
	                        
	                    $("#" + guid + "_feeds").append(res);
	                    $("#" + guid + "_feedsloader").hide();
	                    // Event bind
	                    BSC.E.MapHrefs();
	                    // Hide Loading Status
	                    BSC.UI.HideStatus(guid, 200);
	                }, "html", guid);
	            }
			);

            $("a#" + guid + "_setProfileKey").bind("click", guid,
	            function(e)
	            {
	                var guid = e.data;
	                //	            	var w = BSC.UI.Ws.Get(guid);
	                //	            	var jQ = BSC.U.ParseQuery(w.query);
	                //	            	if (!jQ.id) return;
	                var pkey = $("#" + guid + "_profilekeytext").getValue();
	                if (pkey === "")
	                {
	                    //ok_key, cancel_key, header, description, callback, data, icon
	                    BSC.UI.Alert("Ok", null, "Info", "Please enter profilekey value", null, null, "info");
	                    return;
	                }
	                if (pkey.length > 100 && pkey.length < 4)
	                {
	                    BSC.UI.Alert("Ok", null, "Info", "Key length must be between 5 and 100", null, null, "info");
	                    return;
	                }

	                if (!BSC.R.ProfileKey.test(pkey))
	                {
	                    BSC.UI.Alert(BSC.T.Get("JS.BSC.UI.Ws.Admin.OK"), null, "Info", "Invalid profile key.<br/><br/>The only valid characters is (a-zA-Z0-9.-_)", null, null, "info");
	                    return;
	                }

	                BSC.D.AjaxPost("/profile/UpdateProfileKey", { profileKey: pkey }, function(res)
	                {
	                    if (res.success)
	                    {
	                        BSC.UI.Alert("Ok", null, "Info", "Profilekey was updated successfully.", null, null, "info");
	                        $("#" + guid + "_profilekeyupdate").hide();
	                    }
	                    else
	                    {
	                        $("#" + guid + "_resulttext").html(res.message);
	                    }
	                }, "json", guid);
	            }
			);

            $("#" + guid + "_statustext").bind("focus", guid,
            function(e)
            {

                $("#" + guid + "_statustext").val("");
                if (!BSC.D.P.IsLoggedIn())
                {
                    $(this).trigger("blur");
                    BSC.UI.AlertLogin();
                    return false;
                }
                else if (BSC.D.P.IsFullMember() && !BSC.D.P.IsPaying())
                {
                    $(this).trigger("blur");
                    BSC.UI.AlertCurrentlyFREE();
                    return false;
                }
            });

            $("a#" + guid + "_setStatus").bind("click", guid, function(e)
            {
                if (!BSC.D.P.IsLoggedIn())
                {
                    BSC.UI.AlertLogin();
                    return false;
                }
                else if (BSC.D.P.IsFullMember() && !BSC.D.P.IsPaying())
                {
                    BSC.UI.AlertCurrentlyFREE();
                    return false;
                }
	                var guid = e.data;
	                //	            	var w = BSC.UI.Ws.Get(guid);
	                //	            	var jQ = BSC.U.ParseQuery(w.query);
	                //	            	if (!jQ.id) return;
	                var status = $("#" + guid + "_statustext").getValue();
	                if (status === "")
	                {
	                    //ok_key, cancel_key, header, description, callback, data, icon
	                    BSC.UI.Alert("Ok", null, "Info", "No text inserted in status field. Insert text.", null, null, "info");
	                    return;
	                }
	                if (status.length > 2249)
	                {
	                    BSC.UI.Alert("Ok", null, "Info", "Text in status field too long.", null, null, "info");
	                    return;
	                }
	                if (BSC.R.TextField.test(status))
	                {
	                    BSC.UI.Alert(BSC.T.Get("JS.BSC.UI.Ws.Admin.OK"), null, "Info", "Invalid text inserted.", null, null, "info");
	                    return;
	                }
	                var p = new BSC.D.Param("BSC.WS.JS.Profile.ChangeStatus");
	                p.Add("status", status);
	                
	                $("#" + guid + "_statustext").val("");
	                $("#" + guid + "_lateststatustext").html(status);
	                
	                BSC.D.Send(p, "Content.Profile", "ChangeStatus", function(res)
	                {
	                    if (res.d.success)
	                    {
	                        $("#" + guid + "_feeds div.section.first").removeClass("first");
	                        $("#" + guid + "_feeds div.iconwrap.first").removeClass("first");
	                        $("#" + guid + "_emptyfeed").after(res.d.message);
	                    }
	                });
	            }
			);
            $("#" + guid + "_closefriendfinder").bind("click", guid, function(e)
            {
                if ($("#" + guid + "_keepfriendfinderclosed").attr('checked'))
                {
                    var show = false;
                    BSC.D.AjaxPost("/Home/HideFriendFinder", { show: show }, function(res)
                    {
                        if (res.success)
                        {
                            $("#" + guid + "_friendfinderbox").hide();
                            $("#" + guid + "_sidebar").show();
                            $("#" + guid + "_contents").show();
                        }
                    }, "json", guid);

                }
                else
                {
                    $("#" + guid + "_friendfinderbox").hide();
                    $("#" + guid + "_sidebar").show();
                    $("#" + guid + "_contents").show();
                }

            });



            $("#" + guid + "_findfriends").bind("click", guid, function(e)
            {
                if (loading_findfriends)
                {
                    alert("Getting your contacts, please wait...");
                    return false;
                }
                var email = $("#" + guid + "_email").getValue();
                var password = $("#" + guid + "_password").getValue();

                var data = {
                    email: email,
                    password: password
                };

                var buttonContainer = $(this).parent();
                $("#" + guid + "_errormessage").hide();
                $("#" + guid + "_loading").show();
                //buttonContainer.hide();

                BSC.D.AjaxPost("/Members/FindFriends", data, function(res)
                {
                    loading_findfriends = false;
                    //buttonContainer.show();
                    if (!res.success)
                    {
                        $("#" + guid + "_loading").hide();
                        $("#" + guid + "_errormessage").html(res.message + " - <a>Try again</a>").show();
                        return false;
                    }

                    $("#" + guid + "_resultpage").html(res.message);
                    $("#" + guid + "_friendfinderbox").css("scroll.setVisible(false)");


                    BSC.E.MapHrefs();

                    // Bind Select/Deselect All
                    $("#" + guid + " input.selectall").bind("change", guid, function(e)
                    {
                        $("#" + guid + " input[type='checkbox']").attr('checked', $(this).attr("checked"));
                    });

                    // Bind Add button
                    $("#" + guid + " a.add").bind("click", guid, function(e)
                    {
                        var emails = $("#" + guid + " input.contact").fieldArray();
                        var data = { emails: emails };

                        $(this).hide();
                        $("#" + guid + " div.add_loader").show();

                        BSC.D.AjaxPost("/Members/SendFriendsRequests", data, function(res)
                        {
                            BSC.UI.ShowStatus(guid, "Sending...");
                            $("#" + guid + "_loading").show();

                            if (!res.success)
                            {
                                $("#" + guid + "_loading").hide();
                                $("#" + guid + " a.add").show();
                                BSC.UI.Alert(BSC.T.Get("JS.BSC.UI.Ws.Admin.OK"), null, "Error seding friends requests", "", null, null, "info")
                                return;
                            }
                            else
                            {
                                $("#" + guid + "_friendfinderbox").hide();
                                $("#" + guid + "_sidebar").show();
                                $("#" + guid + "_contents").show();
                                var show = false;
                                BSC.D.AjaxPost("/Home/HideFriendFinder", { show: show }, function(res)
                                {
                                    BSC.UI.Alert(BSC.T.Get("JS.BSC.UI.Ws.Admin.OK"), null, "Friends requests sent", "Scan other mail accounts <br/>to find more peoplpe you know.", GO("/home"), null, "info")
                                }, "json", guid);
                            }
                            BSC.UI.HideStatus(guid, 200);
                        }, "json", guid);
                        //

                    });
                }, "json", guid);
                loading_findfriends = true;
                return false;
            });

        };

        var sendToValidation = function(e)
        {
            var el = BSC.E.GetElement(e, "div", "span");
            if (!el.id) return;
            var t = ((this.firstChild).id).split("_");
            var reportid = t[0];
            var name = t[1];

            BSC.D.AjaxPost("/Profile/ValidateSuspendState", { reportid: reportid }, function(res)
            {
                if (res.success)
                {
                    BSC.UI.Alert(BSC.T.Get("JS.BSC.UI.Ws.Home.SuspendedProfile.OK"), null, BSC.T.Get("JS.BSC.UI.Ws.Home.SuspendedProfile.Desc"), "", null, null, "info");
                    GO("/home");
                    return;
                }
            }, "json", guid);
        };

        var unbind = function(p1)
        {
            var guid = p1;
            $("#" + guid + "_resendactivationemail").unbind();
            $("#" + guid + "_joinevent").unbind();
        };

        return {
            Load: load,
            Bind: bind,
            Unbind: unbind,
            SendToValidation: sendToValidation,
            ValidateProfileKeyInput: function(e)
            {
                var key;
                var keychar;

                if (window.event)
                    key = e.keyCode;
                else if (e.which)
                    key = e.which;

                if (isNaN(key)) return true;

                // check for backspace or delete
                if (key == 8) return true;
                // DOT .
                if (key == 46) return true;
                // DASH _
                if (key == 45) return true;

                keychar = String.fromCharCode(key);
                var reg = /\w/;
                var isValid = reg.test(keychar);
                return isValid;
            }
        };
    } ();
})();
BSC.E.Subscribe("bind", BSC.UI.Ws.Home.Bind, null, "home");
BSC.E.Subscribe("load", BSC.UI.Ws.Home.Load, null, "home");
BSC.E.Subscribe("unbind", BSC.UI.Ws.Home.Unbind, null, "home");



(function()
{
    BSC.UI.Ws.Home.Bookmarks = function()
    {
        /// Private End

        var bind = function(p1)
        {
            var guid = p1;
            $("#" + guid + " a.delete").bind("click", guid, BSC.UI.Ws.Home.Bookmarks.OnBookmarkRemoveClick);
        };

        var load = function(p1)
        {
            var guid = p1;
            var w = BSC.UI.Ws.Get(guid);
            var json = $("#" + guid + "_json").getValue();
            var data = BSC.D.JSON.Parse(json);
            if (data)
            {
                BSC.P.SetTitle(guid, data.Header);
            }
        };

        var onBookmarkRemoveClick = function(e)
        {
            BSC.UI.Alert(
		        BSC.T.Get("JS.BSC.UI.Ws.Home.onBookmarkRemoveClick.Confirm"),
		        BSC.T.Get("JS.BSC.UI.Ws.Home.onBookmarkRemoveClick.Cancel"),
		        BSC.T.Get("JS.BSC.UI.Ws.Home.onBookmarkRemoveClick.Title"),
		        BSC.T.Get("JS.BSC.UI.Ws.Home.onBookmarkRemoveClick.Desc"),
	            function(e)
	            {
	                var guid = e.data;
	                var el = BSC.E.GetElement(e, "tr", "a");
	                if (!el.id)
	                    return;
	                var t = (el.id).split("_");
	                var id = t[0];
	                var type = t[2];
	                $("#" + id + "_tr").fadeOut("fast", function()
	                {
	                    $("#" + id + "_tr").remove();
	                    if ($("#" + guid + "_list_" + type + " tr").length == 0)
	                    {
	                        $("#" + guid + "_no_" + type).css("display", "block");
	                        $("#" + guid + "_" + type).css("display", "none");
	                        $("#" + guid + "_viewall_" + type).css("display", "none");
	                    }
	                });
	                var p = new BSC.D.Param("BSC.WS.JS.Bookmark.ID");
	                p.Add("id", id);
	                BSC.D.Send(p, "Content.Bookmark", "Remove");
	            }, e, "info");
        };

        return {
            Load: load,
            Bind: bind,
            OnBookmarkRemoveClick: onBookmarkRemoveClick
        };
    } ();
})();
// Subscribe to events
BSC.E.Subscribe("bind", BSC.UI.Ws.Home.Bookmarks.Bind, null, "home.bookmarks");
BSC.E.Subscribe("load", BSC.UI.Ws.Home.Bookmarks.Load, null, "home.bookmarks");




//******************************************************
//******************************************************
// EditAccount
//******************************************************
//******************************************************

(function()
{
    BSC.Require("BSC.UI.Ws.Home.Editaccount");
    BSC.UI.Ws.Home.Editaccount.RemoveProfile = function()
    {
        return {
            //            Loaddata: function(guid) 
            //            {            
            //            },
            //            Render: function(guid) 
            //            {
            //            },
            Bind: function(guid)
            {
                $("#" + guid + "_deleteprofile a").bind("click", guid,
                // OnRemoveProfile Click
                function(e)
                {

                    BSC.UI.Alert(BSC.T.Get("JS.BSC.UI.Ws.Home.Editaccount.Yes"), BSC.T.Get("JS.BSC.UI.Ws.Home.Editaccount.No"), BSC.T.Get("JS.BSC.UI.Ws.Home.Editaccount.Title"), BSC.T.Get("JS.BSC.UI.Ws.Home.Editaccount.Desc"),
                    // On Confirm YES Click
                            function()
                            {
                                // Callback after server call
                                $.ajax({
                                    type: "POST",
                                    url: "/Home/Profile_Remove", ///?__guid=" + guid + "&" + BSC.U.QueryToString(jQ),
                                    data: {},
                                    contentType: 'text/html; charset=utf-8',
                                    dataType: "json",
                                    beforeSend: (function(xml) { xml.setRequestHeader("X-OnlyContent", "true"); }),
                                    success: function(res)
                                    {
                                        if (res.success)
                                            BSC.UI.Alert("OK", null, BSC.T.Get("JS.BSC.UI.Ws.Home.ProfileDeletedTitle"), BSC.T.Get("JS.BSC.UI.Ws.Home.ProfileDeletedDesc"), function()
                                            {
                                                top.location.href = "/ProfileRemoved";
                                            }, "alert");
                                        else
                                            BSC.UI.Alert("OK", null, BSC.T.Get("JS.BSC.UI.Ws.Home.ProfileDeletedError"), null, null, "alert");
                                    }
                                },
                                function()
                                {
                                    alert("profile removed");
                                    BSC.P.OnSignout();
                                }, null, null);
                            }, null, "alert");
                }
                );
            },

            OnRemoveProfileClick: function(e)
            {
                //alert("REMOVE");
            },
            Unbind: function(guid)
            {
                $("#" + guid + " a").unbind();
            }
        };
    } ();
})();
BSC.E.Subscribe("unbind", BSC.UI.Ws.Home.Editaccount.RemoveProfile.Unbind, null, "home.accountsettings.removeprofile");
BSC.E.Subscribe("bind", BSC.UI.Ws.Home.Editaccount.RemoveProfile.Bind, null, "home.accountsettings.removeprofile");




//******************************************************
//******************************************************
// EmailSettings
//******************************************************
//******************************************************
(function()
{
	BSC.Require("BSC.UI.Ws.Home.Editaccount");
	BSC.UI.Ws.Home.Editaccount.EmailSettings = function()
	{


		var bind = function(p1)
		{
			var guid = p1;
			$(':checkbox').iphoneStyle({ callback: function(id, state)
			{
				//alert(id + " == " + state);
				var t = id.split("_");
				var emailTemplateID = t[1];

				BSC.D.AjaxPost("/profile/ChangeEmailBlocking", { id: emailTemplateID, doBlock: !state }, function(res)
				{
				}, "json", guid);
			}
			});
			$("#" + guid + " table th:odd").addClass("alt");
			$("#" + guid + " table td:odd").addClass("alt");
			
		}

		var unbind = function(p1)
		{
			var guid = p1;
		}

		return {
			Bind: bind,
			Unbind: unbind
		};
	} ();
})();
BSC.E.Subscribe("unbind", BSC.UI.Ws.Home.Editaccount.EmailSettings.Unbind, null, "home.accountsettings.emailsettings");
BSC.E.Subscribe("bind", BSC.UI.Ws.Home.Editaccount.EmailSettings.Bind, null, "home.accountsettings.emailsettings");




//******************************************************
//******************************************************
// advanced Settings
//******************************************************
//******************************************************
(function()
{
    BSC.Require("BSC.UI.Ws.Home.Editaccount");
    BSC.UI.Ws.Home.Editaccount.AdvancedSettings = function()
    {
        var pleaseWait = false;

        var bind = function(p1)
        {
            var guid = p1;
            $(':checkbox').iphoneStyle({ callback: function(id, state)
            {
                if (!BSC.D.P.IsPaying() && id == "premium_showbanners")
                {
                    BSC.UI.AlertCurrentlyFREE();
                    return false;
                }


                if (pleaseWait)
                {
                    alert("Please wait.");
                    return false;
                }

                pleaseWait = true;
                BSC.D.AjaxPost("/profile/ChangeAdvancedSettings", { action: id, state: state }, function(res)
                {
                    pleaseWait = false;

                    if (res.success && res.action == "premium_showbanners")
                    {
                        // JS.Home.AS.AS.SB.H.SetOn
                        // JS.Home.AS.AS.SB.H.SetOff
                        // JS.Home.AS.AS.SB.M.SetOn
                        // JS.Home.AS.AS.SB.M.SetOff

                        var header = (state) ? BSC.T.Get("JS.Home.AS.AS.SB.H.SetOn") : BSC.T.Get("JS.Home.AS.AS.SB.H.SetOff");
                        var message = (state) ? BSC.T.Get("JS.Home.AS.AS.SB.M.SetOn") : BSC.T.Get("JS.Home.AS.AS.SB.M.SetOff");

                        BSC.UI.Alert(null, null, header, message, function()
                        {
                            self.location.reload();
                        }, guid, "info");
                    }
                    else if (res.success && res.action == "hide_from_se")
                    {
                        // JS.Home.AS.AS.SE.H.SetOn
                        // JS.Home.AS.AS.SE.H.SetOff
                        // JS.Home.AS.AS.SE.M.SetOn
                        // JS.Home.AS.AS.SE.M.SetOff

                        var header = (state) ? BSC.T.Get("JS.Home.AS.AS.SE.H.SetOff") : BSC.T.Get("JS.Home.AS.AS.SE.H.SetOn");
                        var message = (state) ? BSC.T.Get("JS.Home.AS.AS.SE.M.SetOff") : BSC.T.Get("JS.Home.AS.AS.SE.M.SetOn");
                        BSC.UI.Alert(null, null, header, message, function() { }, guid, "info");
                    }
                }, "json", guid);
            }
            });
            $("#" + guid + " table th:odd").addClass("alt");
            $("#" + guid + " table td:odd").addClass("alt");



            $("#beautyscore_filter_value").bind("change", guid, function(e) { var v = $(this).val(); var guid = e.data; SetNewBeautyFilter(v, guid); });

        }

        var unbind = function(p1)
        {
            var guid = p1;
        }

        function SetNewBeautyFilter(v, guid)
        {
            BSC.D.AjaxPost("/profile/SetBeautyFilter", { value: v }, function(r)
            {
               // alert(r.tc + " -- " + r.t);
                if (!r.success)
                {
                    BSC.UI.Alert(null, null, "Error", "text", null, null, "alert");
                    return;
                }

                if (v == 0)
                    BSC.UI.Alert(null, null, "Beauty Filter Set", "Anyone can contact you.", null, null, "info");
                else if (v == -1)
                    BSC.UI.Alert(null, null, "Beauty Filter Set", "Aside from your friends, only members with a Beauty Score like or above your own Score will be able to contact you.", null, null, "info");
                else
                    BSC.UI.Alert(null, null, "Beauty Filter Set", "Aside from your friends, only members with a Beauty Score of minimum "+(v/100)+" will be able to contact you.", null, null, "info");

            }, "json", guid);
        }

        return {
            Bind: bind,
            Unbind: unbind
        };
    } ();
})();
BSC.E.Subscribe("unbind", BSC.UI.Ws.Home.Editaccount.AdvancedSettings.Unbind, null, "home.accountsettings.advancedsettings");
BSC.E.Subscribe("bind", BSC.UI.Ws.Home.Editaccount.AdvancedSettings.Bind, null, "home.accountsettings.advancedsettings");



//******************************************************
//******************************************************
// EditProfile
//******************************************************
//******************************************************

// EditProfile - ProfileInfo
(function()
{
    BSC.Require("BSC.UI.Ws.Home.EditProfile");
    BSC.UI.Ws.Home.EditProfile.ProfileInfo = function()
    {
        var BindCityState = function(guid, countryCode)
        {
            // autocomplete city
            $("#" + guid + "_city").unbind().autocomplete("/home/GetCities/",
			    {
			        delay: 10,
			        minChars: 1,
			        cacheLength: 10,
			        matchSubset: 1,
			        matchContains: 0,
			        autoFill: true,
			        selectFirst: true,
			        lineSeparator: ",",
			        maxItemsToShow: 10,
			        divelement: guid + "_city",
			        extraParams: { country: countryCode }
			    }
			);

            // autocomplete stateprovince
            $("#" + guid + "_stateProvince").unbind().autocomplete("/home/GetStateProvinces/",
			    {
			        delay: 10,
			        minChars: 1,
			        cacheLength: 10,
			        matchSubset: 1,
			        matchContains: 0,
			        autoFill: true,
			        selectFirst: true,
			        lineSeparator: ",",
			        maxItemsToShow: 10,
			        divelement: guid + "_stateprovince",
			        extraParams: { country: countryCode }
			    }
			);
        };

        function getInternetExplorerVersion()
        // Returns the version of Windows Internet Explorer or a -1
        // (indicating the use of another browser).
        {
            var rv = -1; // Return value assumes failure.
            if (navigator.appName == 'Microsoft Internet Explorer')
            {
                var ua = navigator.userAgent;
                var re = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");
                if (re.exec(ua) != null)
                    rv = parseFloat(RegExp.$1);
            }
            return rv;
        }

        var OpenPane = function(id, guid)
        {
            var el = $("#" + guid + "_" + id);
            $("#" + guid + "_properties dd.current").hide().removeClass("current");
            el.next().addClass("current").show();
            $('#' + guid + '_content').stop().scrollTo(el, 400);
        };

        var bind = function(p1)
        {
            var guid = p1;

            var country = $("#" + guid + "_countryid").getValue();

            var browser = getInternetExplorerVersion();

            if (browser >= 8 || browser <= 0)
                BindCityState(guid, country);

            var w = BSC.UI.Ws.Get(guid);
            var jQ = BSC.U.ParseQuery(w.query); //, { id: 'string?' }

            if (jQ.open)
                OpenPane(jQ.open, guid);

            $("#" + guid + "_savename").bind("click", guid, BSC.UI.Ws.Home.EditProfile.ProfileInfo.SaveProfile_Name);
            $("#" + guid + "_savelogin").bind("click", guid, BSC.UI.Ws.Home.EditProfile.ProfileInfo.SaveProfile_Login);
            $("#" + guid + "_savedescription").bind("click", guid, BSC.UI.Ws.Home.EditProfile.ProfileInfo.SaveProfile_Description);
            $("#" + guid + "_saveinfo").bind("click", guid, BSC.UI.Ws.Home.EditProfile.ProfileInfo.SaveProfile_Info);
            $("#" + guid + "_saveoccupation").bind("click", guid, BSC.UI.Ws.Home.EditProfile.ProfileInfo.SaveProfile_Occupation);
            $("#" + guid + "_savefacts").bind("click", guid, BSC.UI.Ws.Home.EditProfile.ProfileInfo.SaveProfile_Facts);
            //$("#" + guid + "_changepassword").click(BSC.UI.Ws.Home.EditProfile.ProfileInfo.ChangePassword);
            $("#" + guid + "_countryid").bind("change", guid, BSC.UI.Ws.Home.EditProfile.ProfileInfo.OnChangeCountry);
            //$("#" + guid + "_stateid").bind("change", guid, BSC.UI.Ws.Home.EditProfile.ProfileInfo.OnChangeState);
            $("#" + guid + "_properties").bind("click", guid,
					function(e)
					{
					    var guid = e.data;
					    if (BSC.E.GetElement(e, "dl", "dd").id) return;

					    var el = BSC.E.GetElement(e, "dl", "dt");
					    $("#" + guid + "_properties dd.current").hide().removeClass("current");
					    $(el).next().addClass("current").show();
					    $('#' + guid + '_content').stop().scrollTo($(el), 400);
					}
				);


            $("#" + guid + "_changeemail a").unbind().bind("click", guid, function(e)
            {
                var guid = e.data;
                var email = $(this).siblings("input").val(); //.firstElementChild.id;
                BSC.D.AjaxPost("/home/Change_Email", { email: email }, function(res)
                {
                    if (res.success)
                    {
                        GO("/home/editprofile/profileinfo/?open=login"); return;
                    }
                    else
                        alert("email is already you current");
                }, "json", guid);
            });
            //Add new email to profile
            $("#" + guid + "_addemail").bind("click", guid, function(e)
            {
                $("#" + guid + "_newemail").toggle();
                $("#" + guid + "_saveemail").toggle();
                if ($("#" + guid + "_newemail").css("display") == "none")
                    $("#" + guid + "_addemail").html("+ Add email");
                else
                    $("#" + guid + "_addemail").html("- Close");
            });
            $("#" + guid + "_saveemail").bind("click", guid, function(e)
            {
                var guid = e.data;
                var email = $("#" + guid + "_newemail").val();
                var EmailRegex = /^(("[\w-\s]+")|([\w-]+(?:\.[\w-]+)*)|("[\w-\s]+")([\w-]+(?:\.[\w-]+)*))(@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][0-9]\.|1[0-9]{2}\.|[0-9]{1,2}\.))((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){2}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\]?$)/i;
                if (!email || !EmailRegex.test(email))
                {
                    BSC.UI.Alert("Ok", null, "Invalid Email", "Please enter a valid email address", null, null, "info");
                    return false;
                }
                BSC.D.AjaxPost("/home/Add_Email", { email: email }, function(res)
                {
                    if (res.success)
                        BSC.UI.Alert("Ok", null, "Confirm new email", "Please click on the <br/> confirmation link in the email<br/> we have sent to <br/>" + res.message + ".", GO("/home/editprofile/profileinfo"), null, "info");
                    else
                        BSC.UI.Alert("Ok", null, "Email already exist", "Please check, and try again.", null, null, "info");
                }, "json", guid);

            });

            //			$("#" + guid + "_addemaiel").unbind().bind("click", guid, function(e)
            //			{
            //				var guid = e.data;
            //				alert(guid + " - 1 - " + $("#" + guid + "_newemail").css("display"));
            //				$("#" + guid + "_newemail").show();
            //				alert(guid + " - 2 - " + $("#" + guid + "_newemail").css("display"));
            //				$("#" + guid + "_newemail").css("display", "block");
            //				alert(guid + " - 3 - " + $("#" + guid + "_newemail").css("display"));
            //				$("#" + guid + "_saveemail").show();
            //				$("#" + guid + "_addemail").html("- Close");

            //				$("#" + guid + "_saveemail").bind("click", guid, function(e)
            //				{
            //					var guid = e.data;
            //					var email = $("#" + guid + "_newemail").val();
            //					BSC.D.AjaxPost("/home/Add_Email", { email: email }, function(res)
            //					{
            //						if (res.success)
            //							alert("success");
            //						else
            //							alert("email already excists");
            //					}, "json", guid);

            //				});
            //				$("#" + guid + "_addemail").unbind().bind("click", guid, function(e)
            //				{
            //					/*
            //					$("#" + guid + "_newemail").css("display", "none");
            //					$("#" + guid + "_saveemail").css("display", "none");
            //					$("#" + guid + "_addemail").html("+ Add email");
            //					*/
            //				});
            //			});

        };

        var unbind = function(p1)
        {
            var guid = p1;
            $("#" + guid + " a.button.save").unbind();
            $("#" + guid + "_changepassword").unbind();
            $("#" + guid + "_stateid").unbind();
            $("#" + guid + "_property").unbind();
        };

        var onChangeCountry = function(e)
        {
            var guid = e.data;
            var country = this.value;

            var browser = getInternetExplorerVersion();

            if (browser >= 8 || browser <= 0)
                BindCityState(guid, country);
        };

        var onChangeState = function(e)
        {
            //			var guid = e.data;
            //			var state = this.value;
            //			var p = new BSC.D.Param("BSC.WS.JS.Home.City");
            //			p.Add("state", state);

            //			$("#" + guid + "_cityloader").show();
            //			BSC.D.Send(p, "Content.Home", "GetCities", function(res)
            //			{
            //				if (res.d.success)
            //				{
            //					$("#" + guid + "_cities").html(res.d.message.replace(/{id}/g, guid));
            //					setTimeout(function()
            //					{
            //						$("#" + guid + "_cityloader").hide();
            //					}, 600);
            //				}
            //			});
        };

        var saveProfile_Name = function(e)
        {
            var guid = e.data;
            var firstname = $("#" + guid + "_firstname").getValue();
            var middlename = $("#" + guid + "_middlename").getValue();
            var lastname = $("#" + guid + "_lastname").getValue();
            var screenname = $("#" + guid + "_screenname").getValue();
            var displaynameformat = $("#" + guid + "_displaynameformat").getValue();


            if (BSC.D.P.IsFullMember() && !BSC.D.P.IsPaying())
            {
                BSC.UI.AlertCurrentlyFREE();
                return false;
            }

            if (firstname.length == 0)
            {
                BSC.UI.Alert("OK", null, BSC.T.Get("JS.BSC.UI.Ws.Home.SaveProfile_Name.Title"), BSC.T.Get("JS.BSC.UI.Ws.Home.SaveProfile_Name.Desc"), function(guid) { $("#" + guid + "_firstname").trigger("focus"); }, guid, "alert");
                //BSC.UI.InputError(guid, "#" + guid + "_firstname", "alert", BSC.T.Get("JS.BSC.UI.Ws.Home.SaveProfile_Name.Title"), BSC.T.Get("JS.BSC.UI.Ws.Home.SaveProfile_Name.Desc"), "#" + guid + "_container");
                return false;
            }

            if (displaynameformat == 3 && screenname.length == 0)
            {
                BSC.UI.Alert("OK", null, BSC.T.Get("JS.BSC.UI.Ws.Home.SaveProfile_ScreenName.Title"), BSC.T.Get("JS.BSC.UI.Ws.Home.SaveProfile_ScreenName.Desc"), function(guid) { $("#" + guid + "_screenname").trigger("focus"); }, guid, "alert");
                //BSC.UI.InputError(guid, "#" + guid + "_screenname", "alert", BSC.T.Get("JS.BSC.UI.Ws.Home.SaveProfile_ScreenName.Title"), BSC.T.Get("JS.BSC.UI.Ws.Home.SaveProfile_ScreenName.Desc"), "#" + guid + "_container");
                return false;
            }

            var p = new BSC.D.Param("BSC.WS.JS.Home.SaveProfileName");
            p.Add("firstname", firstname);
            p.Add("middlename", middlename);
            p.Add("lastname", lastname);
            p.Add("screenname", screenname);
            p.Add("displaynameformat", displaynameformat);

            BSC.UI.ShowStatus(guid, "Saving...");
            BSC.D.Send(p, "Content.Home", "SaveProfileName", function() { BSC.UI.HideStatus(this.d); BSC.UI.Alert(null, null, BSC.T.Get("JS.BSC.UI.Ws.Home.SaveProfile_ChangesSaved"), "", null, null, "info"); }, null, guid);
        };

        var saveProfile_Login = function(e)
        {
            var guid = e.data;
            var anyChanges = false;
            //            var email = $("#" + guid + "_email").getValue();
            //            var emailOld = $("#" + guid + "_email").attr("title");
            //            if (email != emailOld)
            //            {
            //                if (email.length == 0)
            //                {
            //                    BSC.UI.Alert("OK", null, BSC.T.Get("JS.BSC.UI.Ws.Home.SaveProfile_Login.Title"), BSC.T.Get("JS.BSC.UI.Ws.Home.SaveProfile_Login.Desc"), function(guid) { $("#" + guid + "_email").trigger("focus"); }, guid, "alert");
            //                    //BSC.UI.InputError(guid, "#" + guid + "_email", "alert", BSC.T.Get("JS.BSC.UI.Ws.Home.SaveProfile_Login.Title"), BSC.T.Get("JS.BSC.UI.Ws.Home.SaveProfile_Login.Desc"), "#" + guid + "_container");
            //                    return false;
            //                }
            //                anyChanges = true;
            //            }


            var password = $("#" + guid + "_changepassword").getValue().replace(/\*\*\*\*\*\*\*\*\*\*\*/gi, "");

            if (password.length > 0)
            {
                if (password.length < 5)
                {
                    BSC.UI.Alert("OK", null, BSC.T.Get("JS.BSC.UI.Ws.Home.SaveProfile_Password.Title"), BSC.T.Get("JS.BSC.UI.Ws.Home.SaveProfile_Password.Desc"), function(guid) { $("#" + guid + "_changepassword").trigger("focus"); }, guid, "alert");
                    //BSC.UI.InputError(guid, "#" + guid + "_password", "alert", BSC.T.Get("JS.BSC.UI.Ws.Home.SaveProfile_Password.Title"), BSC.T.Get("JS.BSC.UI.Ws.Home.SaveProfile_Password.Desc"), "#" + guid + "_container");
                    return false;
                }

                var password_repeat = $("#" + guid + "_changepassword2").getValue();
                if (password != password_repeat)
                {
                    BSC.UI.Alert("OK", null, BSC.T.Get("JS.BSC.UI.Ws.Home.SaveProfile_Password.NM.Title"), BSC.T.Get("JS.BSC.UI.Ws.Home.SaveProfile_Password.NM.Desc"), function(guid) { $("#" + guid + "_changepassword2").trigger("focus"); }, guid, "alert");
                    //BSC.UI.InputError(guid, "#" + guid + "_password", "alert", BSC.T.Get("JS.BSC.UI.Ws.Home.SaveProfile_Password.Title"), BSC.T.Get("JS.BSC.UI.Ws.Home.SaveProfile_Password.Desc"), "#" + guid + "_container");
                    return false;
                }

                password = password.replace(/\*\*\*\*\*\*\*\*\*\*\*/gi, "");
                if (password.length == 4) password = null;

                if (password != null)
                    anyChanges = true;
            }


            if (anyChanges)
            {
                var password_verify = $("#" + guid + "_changepassword3").getValue();
                if (password_verify.length == 0)
                {
                    BSC.UI.Alert("OK", null, BSC.T.Get("JS.BSC.UI.Ws.Home.SaveProfile_Password.V.Title"), BSC.T.Get("JS.BSC.UI.Ws.Home.SaveProfile_Password.V.Desc"), function(guid) { $("#" + guid + "_changepassword3").trigger("focus"); }, guid, "alert");
                    //BSC.UI.InputError(guid, "#" + guid + "_password", "alert", BSC.T.Get("JS.BSC.UI.Ws.Home.SaveProfile_Password.Title"), BSC.T.Get("JS.BSC.UI.Ws.Home.SaveProfile_Password.Desc"), "#" + guid + "_container");
                    return false;
                }

                var p = new BSC.D.Param("BSC.WS.JS.Home.SaveProfileLogin");
                //p.Add("email", email);
                p.Add("password", password);
                p.Add("passwordOld", password_verify);

                BSC.UI.ShowStatus(guid, "Saving...");
                BSC.D.Send(p, "Content.Home", "SaveProfileLogin", function(res)
                {
                    BSC.UI.HideStatus(this.d);
                    if (res.d.success)
                    {
                        //$("#" + this.d + "_changepassword").val("***********");
                        $("#" + this.d + "_changepassword").val("");
                        $("#" + this.d + "_changepassword2").val("");
                        $("#" + this.d + "_changepassword3").val("");
                        BSC.UI.Alert(null, null, BSC.T.Get("JS.BSC.UI.Ws.Home.SaveProfile_ChangesSaved"), "", null, null, "info");
                        //BSC.UI.Alert("OK", null, "Password changed", "", null, guid, "alert");
                    }
                    else
                    {
                        BSC.UI.Alert("OK", null, BSC.T.Get("JS.BSC.UI.Ws.Home.SaveProfile_Error.Title"), BSC.T.Get("JS.BSC.UI.Ws.Home.SaveProfile_Error.Desc") + ":<br/><br/>" + res.d.message, function(guid) { $("#" + guid + "_changepassword3").trigger("focus"); }, guid, "alert");
                    }
                }, null, guid);
            }
        };

        var saveProfile_Description = function(e)
        {
            if (BSC.D.P.IsFullMember() && !BSC.D.P.IsPaying())
            {
                BSC.UI.AlertCurrentlyFREE();
                return false;
            }
            
            var guid = e.data;
            var text = $("#" + guid + "_text").getValue();
            var internationtext = $("#" + guid + "_internationtext").getValue();

            var p = new BSC.D.Param("BSC.WS.JS.Home.SaveProfileDescription");
            p.Add("text", text);
            p.Add("internationtext", internationtext);

            BSC.UI.ShowStatus(guid, "Saving...");
            BSC.D.Send(p, "Content.Home", "SaveProfileDescription", function() { BSC.UI.HideStatus(this.d); BSC.UI.Alert(null, null, BSC.T.Get("JS.BSC.UI.Ws.Home.SaveProfile_ChangesSaved"), "", null, null, "info"); }, null, guid);
        };

        var saveProfile_Info = function(e)
        {
            var el = BSC.E.GetElement(e, "div", "a");
            var t = (el.id).split("_");
            var guid = t[0];

            var country = $("#" + guid + "_countryid").getValue();
            var country_old = $("#" + guid + "_countryid_old").getValue();
            var address = $("#" + guid + "_address").getValue();
            var zipcode = $("#" + guid + "_zipcode").getValue();
            var city = $("#" + guid + "_city").getValue();
            var privatewebsite = $("#" + guid + "_privatewebsite").getValue();
            var workwebsite = $("#" + guid + "_workwebsite").getValue();
            var mobile = $("#" + guid + "_mobile").getValue();
            var stateProvince = $("#" + guid + "_stateProvince").getValue();
            var city = $("#" + guid + "_city").getValue();

            var day = $("#" + guid + "_day").getValue();
            var month = $("#" + guid + "_month").getValue();
            var year = $("#" + guid + "_year").getValue();

            var p = new BSC.D.Param("BSC.WS.JS.Home.SaveProfileInfo");
            p.Add("country", country);
            p.Add("address", address);
            p.Add("zipcode", zipcode);
            p.Add("city", city);
            p.Add("privatewebsite", privatewebsite);
            p.Add("workwebsite", workwebsite);
            p.Add("mobile", mobile);
            p.Add("stateProvince", stateProvince);
            p.Add("city", city);
            p.Add("day", day);
            p.Add("month", month);
            p.Add("year", year);

            BSC.UI.ShowStatus(guid, "Saving...");
            BSC.D.Send(p, "Content.Home", "SaveProfileInfo", function()
            {
                BSC.UI.HideStatus(this.d);
                var description = (country != country_old) ? "You have changed your country,<br/>the page will now reload." : "";
                BSC.UI.Alert(null, null, BSC.T.Get("JS.BSC.UI.Ws.Home.SaveProfile_ChangesSaved"), description, function()
                {
                    if (country != country_old)
                        self.location.reload();

                }, country, "info");
            }, null, { guid: guid, country: country });
        };

        var saveProfile_Occupation = function(e)
        {
            var el = BSC.E.GetElement(e, "div", "a");
            var t = (el.id).split("_");
            var guid = t[0];

            var education = $("#" + guid + "_education").getValue();
            var job = $("#" + guid + "_job").getValue();
            var jobdescription = $("#" + guid + "_jobdescription").getValue();

            var p = new BSC.D.Param("BSC.WS.JS.Home.SaveProfileOccupation");
            p.Add("education", education);
            p.Add("jobdescription", jobdescription);
            p.Add("job", job);

            BSC.UI.ShowStatus(guid, "Saving...");
            BSC.D.Send(p, "Content.Home", "SaveProfileOccupation", function() { BSC.UI.HideStatus(this.d); BSC.UI.Alert(null, null, BSC.T.Get("JS.BSC.UI.Ws.Home.SaveProfile_ChangesSaved"), "", null, null, "info"); }, null, guid);
        };

        var saveProfile_Facts = function(e)
        {
            var el = BSC.E.GetElement(e, "div", "a");
            var t = (el.id).split("_");
            var guid = t[0];

            var hascar = document.getElementById(guid + "_hascar").checked;
            var smoker = document.getElementById(guid + "_smoker").checked;
            var bodytype = $("#" + guid + "_bodytype").getValue();
            var eyecolor = $("#" + guid + "_eyecolor").getValue();
            var haircolor = $("#" + guid + "_haircolor").getValue();
            var homestatus = $("#" + guid + "_homestatus").getValue();
            //var reasonforuse = $("#" + guid + "_reasonforuse").getValue();
            var relationshipstatus = $("#" + guid + "_relationshipstatus").getValue();
            var reasonforuse = ($("#" + guid + " input[name=" + guid + "_reasonforuse]").getValue()).split(",");
            //			if (reasonforuse == "") reasonforuse[0] = 505;
            var height = $("#" + guid + "_height").getValue();
            var weight = $("#" + guid + "_weight").getValue();

            var p = new BSC.D.Param("BSC.WS.JS.Home.SaveProfileFacts");
            p.Add("hascar", hascar);
            p.Add("smoker", smoker);
            p.Add("bodytype", bodytype);
            p.Add("eyecolor", eyecolor);
            p.Add("haircolor", haircolor);
            p.Add("homestatus", homestatus);
            if (reasonforuse != "") p.Add("reasonforuse", reasonforuse);
            p.Add("relationshipstatus", relationshipstatus);
            p.Add("height", height);
            p.Add("weight", weight);

            BSC.UI.ShowStatus(guid, "Saving...");
            BSC.D.Send(p, "Content.Home", "SaveProfileFacts", function() { BSC.UI.HideStatus(this.d); BSC.UI.Alert(null, null, BSC.T.Get("JS.BSC.UI.Ws.Home.SaveProfile_ChangesSaved"), "", null, null, "info"); }, null, guid);
        };

        return {
            Bind: bind,
            Unbind: unbind,
            OnChangeCountry: onChangeCountry,
            OnChangeState: onChangeState,
            SaveProfile_Name: saveProfile_Name,
            SaveProfile_Login: saveProfile_Login,
            SaveProfile_Description: saveProfile_Description,
            SaveProfile_Info: saveProfile_Info,
            SaveProfile_Occupation: saveProfile_Occupation,
            SaveProfile_Facts: saveProfile_Facts
        };
    } ();
})();
   // Subscribe to events
   BSC.E.Subscribe("bind", BSC.UI.Ws.Home.EditProfile.ProfileInfo.Bind, null, "home.editprofile.profileinfo");
   BSC.E.Subscribe("unbind", BSC.UI.Ws.Home.EditProfile.ProfileInfo.Unbind, null, "home.editprofile.profileinfo");



   // EditProfile - Myphotos
(function()
{
    BSC.UI.Ws.Home.EditProfile.Myphotos = function()
    {
        return {

            Bind: function(guid)
            {
                $("#" + guid + "_addphotos").bind("click", guid, function()
                {
                    var title = $("#" + guid + "_albumtitle").getValue();

                    if (!title || title.length == 0)
                    {
                        BSC.UI.Alert("Ok", null, "Please enter a title", "", null, null, "info");
                        return;
                    }

                    $("#" + guid + "_addphotos").hide();
                    $("#" + guid + "_addphotos_loader").show();

                    BSC.D.AjaxPost("/home/Photoalbum_Save", { albumid: null, albumtitle: title }, function(res)
                    {
                        if (!res.success)
                        {
                            $("#" + guid + "_addphotos_loader").hide();
                            $("#" + guid + "_addphotos").show();

                            BSC.UI.Alert("Ok", null, "Could not create photoalbum", res.message, null, null, "info");
                            return false;
                        }
                        GO("/home/editprofile/editphotos/?id=" + res.id); return;
                    }, "json", guid);
                });
            },
            Unbind: function(guid)
            {
                $("#" + guid + " a").unbind();
            }
        };
    } ();
})();
BSC.E.Subscribe("bind", BSC.UI.Ws.Home.EditProfile.Myphotos.Bind, null, "home.editprofile.myphotos");
BSC.E.Subscribe("unbind", BSC.UI.Ws.Home.EditProfile.Myphotos.Unbind, null, "home.editprofile.myphotos");



// EditProfile - ViewPhotos
(function()
{
    BSC.UI.Ws.Home.EditProfile.Editphotos = function()
    {
        /// <summary>Private: Local cache to hold temporary information, while window is open</summary>
        var cache = {};

        var localdata = {};

        var BindTextFields = function(p1)
        {
            var guid = p1;
            $("#" + guid + "_picturelist input:text").unbind().bind("focus", guid, function(e)
            {
                var t = (this.id).split("_");
                var pictureid = t[1];

                var data = { guid: guid, id: pictureid };

                $(this).bind("blur", data, function(e)
                {
                    $(this).unbind("blur");
                    var title = $(this).getValue();

                    var p = new BSC.D.Param("BSC.WS.JS.Picture.SaveTitle");
                    p.Add("PictureID", pictureid);
                    p.Add("Title", title);
                    BSC.UI.Loader(guid);

                    $("li#" + pictureid).addClass("greenfade");
                    setTimeout(function() { $("li#" + pictureid).removeClass("greenfade"); }, 1500);

                    BSC.D.Send(p, "Content.Picture", "SaveTitle", function(res)
                    {
                        //alert("picture title changed");
                    });
                });
                return;
            });

        };

        function RenderEditPhotoItems(guid)
        {
            var w = BSC.UI.Ws.Get(guid);
            if (!w.query) return;
            var jQ = BSC.U.ParseQuery(w.query);
            if (!jQ.id) return;

            var albumid = jQ.id;

            BSC.UI.ShowStatus(guid, "Loading...");
            BSC.D.AjaxGet("/Home/EditProfile/EditPhotoItems", jQ, function(res)
            {
                $("#" + guid + "_picturelist").html(res);
                // CHANGE PICTURE TITLE
                BindTextFields(guid);
                BSC.UI.HideStatus(guid, 200);
            }, "html", guid);

            //			$.ajax({
            //				type: "GET",
            //				url: "/Home/EditProfile/EditPhotoItems/?__guid=" + guid + "&" + BSC.U.QueryToString(jQ),
            //				data: {},
            //				contentType: 'text/html; charset=utf-8',
            //				dataType: "html",
            //				beforeSend: (function(xml) { xml.setRequestHeader("X-OnlyContent", "true"); }),
            //				success: function(res) {
            //					$("#" + guid + "_picturelist").html(res);
            //					// CHANGE PICTURE TITLE
            //					BindTextFields(guid);
            //					BSC.UI.HideStatus(guid, 200);
            //				}
            //			});
        }

        function DeletePictures(pictureids, guid)
        {
            BSC.D.AjaxPost("/home/Pictures_Delete", { pictureIDs: pictureids }, function(res)
            {
                BSC.UI.HideLoader(guid);
                var l = res.length;
                for (i = 0; i < l; i++)
                {
                    var p = res[i];
                    if (p.success)
                    {
                        $("#" + p.id).fadeOut(300, function()
                        {
                            $(this).prev().remove();
                            $(this).remove();

                            if ($("#" + guid + "_picturelist li").length == 0)
                            {
                                localdata[guid].data.hascover = false;
                                $("#" + guid + "_coverpicture").remove();
                                $("#" + guid + "_notvisible").show();
                            }
                        });


                        if (p.fkeyid && p.fkeyid!="00000000-0000-0000-0000-000000000000")
                        {
                            $("#" + guid + "_picturelist div.primarypic_container").removeClass("active");
                            $("#" + p.fkeyid + " div.primarypic_container").addClass("active");
                            $("#" + guid + "_coverpicture").hide().attr("src", BSC.PicturePath(p.fkeyid, "medium")).fadeIn(800);
                            //SetAsCoverPicture(guid, p.fkeyid);
                        }
                    }
                    else if (!p.success)
                    {
                        if (p.statuscode == 100)
                        {
                            BSC.UI.Alert("Ok", null, "Unable to delete profile picture", "Please select another profilepicture<br /> before you delete the current.", null, null, "info");
                        }
                    }
//                    if (p.message == "deleted")
//                    {
//                        GO("/home/editprofile/myphotos");
//                        return;
//                    }
//                    if ((res[0].fkeyid == null || res[0].fkeyid == "00000000-0000-0000-0000-000000000000") && res[0].statuscode == 1)
                }
            }, "json", guid);

            //            var p = new BSC.D.Param("BSC.WS.JS.Picture.Delete");
            //            p.Add("Pictures", pictureids);
            //            BSC.UI.Loader(guid);
            //            BSC.D.Send(p, "Content.Picture", "DeletePictures", function(res)
            //            {
            //                BSC.UI.HideLoader(guid);
            //                var l = res.d.length;
            //                for (i = 0; i < l; i++)
            //                {
            //                    var p = res.d[i];
            //                    if (p.success)
            //                    {
            //                        $("#" + p.id).fadeOut(300, function()
            //                        {
            //                            $(this).prev().remove();
            //                            $(this).remove();

            //                            if ($("#" + guid + "_picturelist li").length == 0)
            //                            {
            //                                localdata[guid].data.hascover = false;
            //                                $("#" + guid + "_coverpicture").remove();
            //                                $("#" + guid + "_notvisible").show();
            //                            }
            //                        });


            //                        if (i == 0 && p.fkeyid)
            //                        {
            //                            SetAsCoverPicture(guid, p.fkeyid);
            //                        }
            //                    }
            //                    if (p.message == "deleted")
            //                    {
            //                        GO("/home/editprofile/myphotos");
            //                        return;
            //                    }
            //                    if ((res.d[0].fkeyid == null || res.d[0].fkeyid == "00000000-0000-0000-0000-000000000000") && res.d[0].statuscode == 1)
            //                        BSC.UI.Alert("Ok", null, "Unable to delete profilepicture", "Please select another profilepicture<br /> before you delete the current.", null, null, "info");
            //                }

            //            }, null, null);
        };


        var SetAsCoverPicture = function(p1, p2)
        {
            var guid = p1;
            var pictureid = p2;
            var w = BSC.UI.Ws.Get(guid);
            if (!w.query) return;
            var jQ = BSC.U.ParseQuery(w.query);
            if (!jQ.id) return;
            var p = new BSC.D.Param("BSC.WS.JS.Picture.SetAsCover");
            p.Add("PictureID", pictureid);
            p.Add("PhotoalbumID", jQ.id);
            BSC.UI.Loader(guid);

            $("#" + guid + "_picturelist div.primarypic_container").removeClass("active");
            $("#" + pictureid + " div.primarypic_container").addClass("active");
            $("#" + guid + "_coverpicture").hide().attr("src", BSC.PicturePath(pictureid, "medium")).fadeIn(800);
            BSC.D.Send(p, "Content.Picture", "SetAsCover", function() { localdata[guid].data.hascover = true; return; });
        };

        /// Private End
        return {
            /// <summary>Retrieves album and picture data</summary>
            /// <param name="guid">Unique identifier for selected window</param>			
            Load: function(guid)
            {
                if (!localdata[guid])
                    localdata[guid] = {};
                // if any pictures
                var json = $("#" + guid + "_json").getValue();
                var data = BSC.D.JSON.Parse(json);

                localdata[guid].data = data;

                if (data.anyphotos)
                {
                    $("#" + guid + "_picturelist input:text").unbind();
                    $("#" + guid + "_picturelist").html("<li id=\"" + guid + "_loader\"></li>");
                    var flashvars = {};
                    var params = { wmode: 'transparent' };
                    var attributes = params;
                    swfobject.embedSWF(BSC.BASE_MEDIA_PATH + "Content/Flash/loader.swf", guid + "_loader", "160", "80", "9.0.0", flashvars, params, attributes);

                    RenderEditPhotoItems(guid);
                }
            },
            /// <summary>Binds window events</summary>
            /// <param name="guid">Unique identifier for selected window</param>
            Bind: function(guid)
            {
                if (!localdata[guid])
                    localdata[guid] = {};

                var w = BSC.UI.Ws.Get(guid);
                if (!w.query) return;
                var jQ = BSC.U.ParseQuery(w.query);
                if (!jQ.id) return;
                // List Click   
                $("#" + guid + "_picturelist").click(BSC.UI.Ws.Home.EditProfile.Editphotos.OnPhotoListClick);
                // Add more photos
                $("#" + guid + "_addphotos").click(BSC.UI.Ws.Home.EditProfile.Editphotos.OnAddPhotosClick);
                $("#" + guid + "_selectoptions").change(BSC.UI.Ws.Home.EditProfile.Editphotos.OnSelectOptionClick);
                $("#" + guid + "_deletealbum").click(BSC.UI.Ws.Home.EditProfile.Editphotos.DeletePhotoAlbum);

                $("#" + guid + "_deletephotos").bind("click", guid, BSC.UI.Ws.Home.EditProfile.Editphotos.OnDeleteClick);

                $("#" + guid + "_savesettings").bind("click", guid, function(e)
                {
                    var el = BSC.E.GetElement(e, "ul", "a");
                    if (!el.id)
                        return;
                    var t = (el.id).split("_");
                    var guid = t[0];
                    var title = $("#" + guid + "_albumtitle").val();
                    var temp = ((el.firstChild).id).split("_");
                    var albumids = temp[0];
                    $.post("/home/Photoalbum_Save", { albumid: albumids, albumtitle: title }, function(res)
                    {
                        GO("/home/editprofile/myphotos"); return;
                    }, "json");
                });

                localdata[guid].firstElement = $("#" + guid + "_picturelist li:first").id;


                // Bind fileupload
                var settings = {
                    button_image_url: BSC.BASE_STATIC_PATH + "beautifulpeoplecdn/images/buttons/blue/flash_btn.png",
                    button_placeholder_id: guid + "_selectpictures",
                    button_width: 115,
                    button_height: 18,
                    button_text_top_padding: 0,
                    button_text: '<span class="btnupl">Browse picture</span>',
                    button_text_style: '.btnupl { font-family: Verdana; font-weight:bold; color:#ffffff; font-size: 11px; line-height:18px; text-align:center; cursor:pointer; }',
                    file_types_description: "Select group picture file",
                    file_upload_limit: 0,
                    file_queue_limit: 0,
                    file_types: "*.jpg;*.gif;*.png;*.bmp",
                    button_action: SWFUpload.BUTTON_ACTION.SELECT_FILES,
                    upload_complete_handler: function(p1)
                    {
                        var file = p1;

                        localdata[guid].firstElement = $("#" + guid + "_picturelist li:first").id;
                        try
                        {
                            if (this.getStats().files_queued > 0)
                            {
                                this.startUpload();
                            }
                            else
                            {
                                this.setButtonDisabled(false);
                                BindTextFields(guid);
                                //SetAsCoverPicture(guid,
                                //RenderEditPhotoItems(guid);
                                if ($("#" + guid + "_coverpicture").length == 0 || !localdata[guid].data.hascover)
                                {
                                    $("#" + guid + "_coverpicture_container").append("<img id=\"" + guid + "_coverpicture\" src=\"\" alt=\"\" />");
                                    var temp = $("#" + guid + "_picturelist li:first");
                                    var id = temp[0].id;
                                    SetAsCoverPicture(guid, id);
                                }


                            }
                        } catch (ex)
                        {
                            this.debug(ex);
                        }
                    },

                    upload_success_handler: function(p1, p2)
                    {
                        try
                        {
                            var file = p1;
                            var data = BSC.D.JSON.Parse(p2);
                            var tempPictureID = file.name.replace(/[ ]/g, "").replace(/\./g, "");
                            var html = BSC.D.Ts.Get("Home.EditProfile.EditPhotoItem");

                            html = html.replace(/\{class\}/g, "");
                            html = html.replace(/\{title\}/g, file.name);
                            html = html.replace(/\{id\}/g, guid);
                            html = html.replace(/\{pictureid\}/g, data.id);
                            //$("#" + guid + "_picturelist").prepend(html);
                            $("li#" + tempPictureID).prev().remove();
                            $("li#" + tempPictureID).replaceWith(html);

                        } catch (ex)
                        {
                            this.debug(ex);
                        }
                        //this.setButtonDisabled(false);

                    },
                    file_queued_handler: function(p1)
                    {
                        var file = p1;
                        var html = BSC.D.Ts.Get("Home.EditProfile.EditPhotoItem");

                        var tempPictureID = file.name.replace(/[ ]/g, "").replace(/\./g, "");

                        html = html.replace(/\{class\}/g, "greenfade");
                        html = html.replace(/\{title\}/g, file.name);
                        html = html.replace(/\{id\}/g, guid);
                        html = html.replace(/\{pictureid\}/g, tempPictureID);

                        $("#" + guid + "_notvisible").hide();

                        if (localdata[guid].firstElement)
                        {
                            $("#" + localdata[guid].firstElement).prev().before(html)
                        }
                        else
                            $("#" + guid + "_picturelist").append(html);





                    },
                    upload_start_handler: function(p1, p2)
                    {
                        var file = p1;
                        var tempPictureID = file.name.replace(/[ ]/g, "").replace(/\./g, "");

                        var tempGuid = BSC.U.NewGUID();
                        $("#" + guid + "_open_" + tempPictureID).html("<span id=" + tempGuid + "></span>");
                        var flashvars = {};
                        var params = { wmode: 'transparent' };
                        var attributes = params;
                        swfobject.embedSWF(BSC.BASE_MEDIA_PATH + "Content/Flash/loader.swf", tempGuid, "80", "50", "9.0.0", flashvars, params, attributes);

                        // PostParams
                        var postParams = {
                            p1: jQ.id,
                            p2: (BSC.D.P.GetData()).TicketID,
                            //p3: jQ.id,
                            p4: guid
                        };
                        this.setPostParams(postParams);
                        //this.setButtonDisabled(true);
                    }
                };
                BSC.F.GetUpload(guid, settings);
            },
            /// <summary>Unbinds window events</summary>
            /// <param name="guid">Unique identifier for selected window</param>    		
            Unbind: function(guid)
            {
                $("#" + guid + " ul").unbind();
                $("#" + guid + " a").unbind();
                $("#" + guid + " div").unbind();
                $("#" + guid + " input").unbind();
                cache[guid] = null;
            },

            /// <summary>Profile clicks on picture</summary>
            /// <param name="e">Event</param>   
            OnPhotoListClick: function(e)
            {
                var el = BSC.E.GetElement(e, "ul", "a");
                if (el.id)
                {
                    var t = (el.id).split("_");
                    var guid = t[0];
                    var action = t[1];
                    var pictureid = t[2];

                    if (action == "open")
                    {
                        GO("/picture/?id=" + pictureid);
                        return;
                    }
                    else if (action === "setprimary")
                    {
                        SetAsCoverPicture(guid, pictureid);
                    }
                }

                return;
            },

            /// <summary>Chatches the edit photo event</summary>
            /// <param name="e">Event information</param>		
            OnEditPhotoButtonClick: function(e)
            {
                var guid = e.data.guid;
                var pictureid = e.data.pictureid;
                var albumid = e.data.albumid;
                var el = BSC.E.GetElement(e, "div", "a");
                var t = (el.id).split("_");
                var action = t[1];

                if (action === "cancel")
                {
                    $("#" + pictureid + "_edit a").unbind();
                    $("#" + pictureid + " a.arrow").removeClass("activated");
                    $("#" + pictureid + "_edit").remove();
                }
                // Delete picture
                else if (action === "delete")
                {
                    DeletePictures([pictureid], guid);
                }
                // Save infomation on picture
                else if (action === "save")
                {
                    var title = $("#" + pictureid + "_editphotoitem input").val();
                    var text = $("#" + pictureid + "_editphotoitem textarea").val();
                    // Validation
                    BSC.UI.Loader(guid);
                    if (!BSC.R.TextField.test(title) && !BSC.R.TextField.test(text))
                    {
                        var p = new BSC.D.Param("BSC.WS.JS.Profile.UpdatePicture");
                        p.Add("pictureid", pictureid);
                        p.Add("albumid", albumid);
                        p.Add("headline", title);
                        p.Add("picturetxt", text);
                        BSC.D.Send(p, "Content.Picture", "UpdatePicture", function()
                        {
                            setTimeout(function() { BSC.UI.Ws.Home.EditProfile.Editphotos.Loaddata(guid); }, 600);
                        });
                    }
                }

            },

            DeletePhotoAlbum: function(e)
            {
                var el = BSC.E.GetElement(e, "ul", "a");
                if (!el.id)
                    return;
                var t = (el.id).split("_");
                var guid = t[0];
                var temp = ((el.firstChild).id).split("_");
                var albumid = temp[0];

                BSC.UI.Alert("Yes", "No", "Are you sure...", "", function(e)
                {
                    var guid = e.guid;
                    var albumid = e.albumid;

                    BSC.UI.ShowStatus(guid, "Deleting...");
                    $.ajax({
                        type: "POST",
                        url: "/Home/Photoalbum_Remove?albumid=" + albumid,
                        data: {},
                        contentType: 'application/json; charset=utf-8',
                        dataType: "json",
                        beforeSend: (function(xml) { xml.setRequestHeader("X-IsJson", "true"); }),
                        success: function(res)
                        {
                            if (res.success)
                                GO("/home/editprofile/myphotos");
                            BSC.UI.HideStatus(guid, 200);
                        }
                    });

                }, { guid: guid, albumid: albumid }, "info");
            },

            SaveAlbumSettings: function(e)
            {
                var el = BSC.E.GetElement(e, "ul", "a");
                if (!el.id)
                    return;
                var t = (el.id).split("_");
                var guid = t[0];
                var albumTitle = $("#" + guid + "_albumtitle").val();
                var temp = ((el.firstChild).id).split("_");
                var albumid = temp[0];

                var toSend = {};
                toSend["albumtitle"] = albumTitle;
                toSend["albumid"] = albumid;
                //				if (!toSend) toSend = {};
                //				var dd = JSON.stringify(toSend);

                BSC.UI.ShowStatus(guid, "Saving...");
                $.ajax({
                    type: "GET",
                    url: "/Home/Photoalbum_Saves",
                    data: toSend,
                    contentType: 'application/json; charset=utf-8',
                    dataType: "json",
                    beforeSend: (function(xml) { xml.setRequestHeader("X-IsJson", "true"); }),
                    success: function(res)
                    {
                        if (res.success)
                            GO("/home/editprofile/myphotos");
                        // CHANGE PICTURE TITLE
                        BindTextFields(guid);
                        BSC.UI.HideStatus(guid, 200);
                    }
                });

            },


            /// <summary>Chatches the select option event</summary>
            /// <param name="e">Event information</param>
            OnSelectOptionClick: function(e)
            {
                var t = (this.id).split("_");
                var guid = t[0];
                var action = this.value;
                if (e.target.value.toLowerCase() === "all")
                {
                    $("#" + guid + "_picturelist input[type='checkbox']").attr('checked', true);
                    return;
                }
                else if (e.target.value.toLowerCase() === "none")
                {
                    $("#" + guid + "_picturelist input[type='checkbox']").attr('checked', false);
                    return;
                }
                return;
            },
            /// <summary>Opens image file uploader</summary>
            /// <param name="e">Event information</param>
            OnAddPhotosClick: function(e)
            {
                var el = BSC.E.GetElement(e, "a", "span");
                var t = (el.id).split("_");
                var guid = t[0];
                GO("/file/upload/?id=" + cache[guid].album.id);
            },


            /// <summary>Gathers pictures marked to be deleted</summary>
            /// <param name="e">Event information</param>
            OnDeleteClick: function(e)
            {
                var el = BSC.E.GetTarget(e);
                var t = (el.id).split("_");
                var guid = t[0];
                var picturetodelete = [];
                var pictures = $("#" + guid + "_picturelist input[type='checkbox']");
                for (i = 0; i < pictures.length; i++)
                {
                    if (!pictures[i].checked) continue;
                    var id = ((pictures[i].id).split("_"))[2];
                    picturetodelete.push(id);
                }
                if (picturetodelete.length > 0)
                    DeletePictures(picturetodelete, guid);
                else
                    BSC.UI.Alert(BSC.T.Get("JS.BSC.UI.Ws.Home.OnDeleteClick.OK"), null, BSC.T.Get("JS.BSC.UI.Ws.Home.OnDeleteClick.Title"), BSC.T.Get("JS.BSC.UI.Ws.Home.OnDeleteClick.Desc"), null, null, "info");
            }
        };
    } ();
})();

   // Subscribe to events
   BSC.E.Subscribe("load", BSC.UI.Ws.Home.EditProfile.Editphotos.Load, null, "home.editprofile.editphotos");
   BSC.E.Subscribe("bind", BSC.UI.Ws.Home.EditProfile.Editphotos.Bind, null, "home.editprofile.editphotos");
   BSC.E.Subscribe("unbind", BSC.UI.Ws.Home.EditProfile.Editphotos.Unbind, null, "home.editprofile.editphotos");


   (function()
   {
       BSC.UI.Ws.Home.PremiumMember = function()
       {
           /// Private End

           var bind = function(p1)
           {
               var guid = p1;
               $("#" + guid + "_UpdatePremium").bind("click", guid, BSC.UI.Ws.Home.PremiumMember.OnPremiumButtonClick);

           };

           var load = function(p1)
           {
               var guid = p1;
               var w = BSC.UI.Ws.Get(guid);
               var json = $("#" + guid + "_json").getValue();
               var data = BSC.D.JSON.Parse(json);
               if (data)
               {
                   BSC.P.SetTitle(guid, data.Header);
                   alert(data.Header);
               }

           };

           return {
               Load: load,
               Bind: bind,

               /// <summary>Chatches the edit premium settings event</summary>
               /// <param name="e">Event information</param>		
               OnPremiumButtonClick: function(e)
               {
                   var guid = e.data;

                   // Update infomation

                   var showbanners = $("#premium_showbanners").is(":checked");
                   var visibilityscope = 0;
                   if ($("#premium_hiddenactive").is(":checked"))
                   {
                       if ($('input[name=premium_secretvalue]:checked').val() != undefined)
                           visibilityscope = $('input[name=premium_secretvalue]:checked').val();
                   }

                   //alert("banners: " + showbanners + " | hidden: " + visibilityscope);

                   var data = { showbanner: showbanners, visibilityscope: visibilityscope };

                   BSC.D.AjaxPost("/Home/PremiumMemberUpdate", data, function(res)
                   {
                       if (res.success)
                       {
                           //GO("/home/accountsettings/premiummember");
                           self.location.reload();
                       }
                       else
                       {
                           alert("An error occured");
                       }
                   }, "json", guid);
               }
           };
       } ();
   })();
   // Subscribe to events
   BSC.E.Subscribe("bind", BSC.UI.Ws.Home.PremiumMember.Bind, null, "home.accountsettings.premiummember");
   BSC.E.Subscribe("load", BSC.UI.Ws.Home.PremiumMember.Load, null, "home.accountsettings.premiummember");

  

   
