﻿// JSLint Config:
/*jslint browser: true */
/*global cc, jQuery, cc_resx_TR_Are_you_sure_unfan, cc_resx_TR_Message_Successfully_Sent, 
cc_resx_TR_Are_you_sure_delete_user, cc_resx_TR_Are_you_sure_change_gender
*/

//  
//  Author: Kevin Burkitt
//  Date:   2010-03-22
//  
//  CC User Profile Page Helper Functions
//
cc.userprofile = function() {

    return {
        mailSubmitting: false,

        init: function(target) {
            var t = target;

            jQuery('.cc-send-pm', target).unbind('click').click(function() {
                var username = jQuery(this, t).attr('cc:username');
                cc.ui.colorbox('/userprofile/send-private-message/' + username + '/', function() {
                    // Init Response Form for Ajax Submit
                    jQuery('#mail-form').unbind('submit').submit(function() {
                        return cc.userprofile.sendMailSubmit('#mail-form');
                    });
                });
            });




            jQuery('.cc-view-wishlist', target).unbind('click').click(function() {
                var memberid = jQuery(this, t).attr('cc:memberid');
                cc.ui.colorbox('/boutique/view-wishlist/' + memberid + '/', function() {

                });
            });



            jQuery('.cc-boutique-large', target).unbind('click').click(function() {

                var imgSrc = '/boutique-zoom/' + escape(jQuery(this, t).attr('cc:imageurl')) + '/';

                cc.ui.colorbox(imgSrc, function() {

                });
            });




            jQuery('#cc-up-unfan', target).unbind('click').click(function() {

                var target = jQuery(this).attr('cc:target');
                var url = jQuery(this).attr('cc:href');

                cc.ui.showModalConfirm(cc_resx_TR_Are_you_sure_unfan,
                    function() {
                        cc.ajax.load(target, url);
                        jQuery.fn.colorbox.close();
                    }, null);
                return false;
            });



        },




        sendMailSubmit: function(formId) {

            var url = jQuery(formId).attr('action');
            url += '?format=json';

            if (typeof cc.userprofile.mailSubmitting !== 'undefined' && cc.userprofile.mailSubmitting === true) {
                return false;
            }
            cc.userprofile.mailSubmitting = true;

            cc.userprofile.showOverlayPleaseWait();

            cc.ajax.formSubmit(
                    formId,
                    {
                        dataType: 'json',
                        url: url
                    },
                    function(data, statusText) {
                        if (data.success === false) {
                            cc.userprofile.updateOverlayResponseMsg(data.message);
                            cc.userprofile.hideOverlayPleaseWait();
                        }
                        else {
                            jQuery('.spm-wait p').html(cc_resx_TR_Message_Successfully_Sent);
                            setTimeout(function() {
                                jQuery.fn.colorbox.close();
                            }, 1200);
                        }
                    },
                    function() {
                        cc.userprofile.mailSubmitting = false;
                    });

            return false;
        },




        ChangeTitle: function(sitename) {
            document.getElementById('sitelogo').innerHTML = '<span class="sprite">' + sitename + '</h1>';
        },


        userInfoShowAll: function(id) {

            jQuery('.' + id).css('overflow', 'visible');
            jQuery('.' + id).css('max-height', '2000px');
            jQuery('.up-showall-info').hide();
            jQuery('.up-hideall-info').show();

        },

        userInfoHideAll: function(id) {
            jQuery('.' + id).css('overflow', 'hidden');
            jQuery('.' + id).css('max-height', '42px');
            jQuery('.up-showall-info').show();
            jQuery('.up-hideall-info').hide();

        },

        showOverlayPleaseWait: function() {
            jQuery('.spm-wait-bg, .spm-wait').show();
        },

        hideOverlayPleaseWait: function() {
            jQuery('.spm-wait-bg, .spm-wait').hide();
        },




        adminDeleteUser: function(memberId) {
            cc.ui.showModalConfirm(cc_resx_TR_Are_you_sure_delete_user,
                function() {
                    cc.userprofile.deleteUser(memberId);
                    jQuery.fn.colorbox.close();
                }, null);

            return false;
        },



        adminChangeGender: function(memberId) {
            cc.ui.showModalConfirm(cc_resx_TR_Are_you_sure_change_gender,
                function() {
                    cc.userprofile.changeGender(memberId);
                    jQuery.fn.colorbox.close();
                }, null);

            return false;
        },


        
        
        
        changeGender: function(memberId) {
            if (typeof cc.mail.actionInProgress !== 'undefined' && cc.mail.actionInProgress === true) {
                return false;
            }
            cc.mail.actionInProgress = true;
            cc.ajax.load('#userprofile', '/admin/change-gender/' + memberId + "/");

        },

        deleteUser: function(memberId) {
            if (typeof cc.mail.actionInProgress !== 'undefined' && cc.mail.actionInProgress === true) {
                return false;
            }
            cc.mail.actionInProgress = true;
            cc.ajax.load('#userprofile', '/admin/delete/user/' + memberId + "/");
        },

        adminDeleteAvatar: function(memberId) {
            if (typeof cc.mail.actionInProgress !== 'undefined' && cc.mail.actionInProgress === true) {
                return false;
            }
            cc.mail.actionInProgress = true;
            cc.ajax.load('#userprofile', '/admin/delete/avatar/' + memberId + "/");
        },


        WebCamScheduleBook: function(date, scheduleid, memberid) {

            var hour = jQuery(".webcambook:checked").val();
            //var url = '/webcam-schedule-book/' + date + '/' + hour + '/' + scheduleid + '/' + memberid;

            cc.ajax.getJSON(
                '/userprofile/webcam-schedule-book/',
                {
                    date: date,
                    time: hour,
                    scheduleid: scheduleid,
                    memberid: memberid

                },
                function(resp) {
                    if (typeof resp !== 'undefined' && typeof resp.success !== 'undefined' && resp.success === true) {
                        return cc.ui.showModalConfirmNo();
                    }
                    else {
                        if (typeof resp !== 'undefined' && typeof resp.message !== 'undefined' && typeof resp.message !== '') {


                            var msg = resp.message;
                            cc.ui.showModalErrorMessage(msg);
                        }
                        else {

                            cc.ui.showModalErrorMessage(cc_resx_TR_An_error_occurred_deleting);
                        }
                    }
                },
                function() {

                }
            );

        },


        SchedulingCheckBoxFix: function(control) {

            jQuery('.webcambook:checked').attr('checked', false);
            jQuery(control).attr('checked', true);
            return;


        },

        WebCamScheduleShowTimeOverlay: function(timeid, date, scheduleid, memberid) {



            var msg = '';



            switch (timeid) {
                case '1':
                    msg += '<div id="wc-bookoverlay"><h1>I\'d Like to chat to you...</h1><p>Sometime between 04:00-05:00 <input id=\"04\"  onclick="cc.userprofile.SchedulingCheckBoxFix(this);" onclick="cc.userprofile.SchedulingCheckBoxFix(this);" type=\"checkbox\" value=\"04\" name=\"webcambook\"  class=\"webcambook\" />' +
                        '</p><p>Sometime between 05:00-06:00 <input id=\"05\" onclick="cc.userprofile.SchedulingCheckBoxFix(this);" type=\"checkbox\"  value=\"05\" name=\"webcambook\"  class=\"webcambook\" />	</p>' +
                        '<p>Sometime between 07:00-08:00 <input id=\"06\" onclick="cc.userprofile.SchedulingCheckBoxFix(this);" type=\"checkbox\" value=\"07\" name=\"webcambook\"  class=\"webcambook\"  class=\"webcambook\" />	</p>' +
                        '<p>Sometime between 08:00-09:00 <input id=\"07\" onclick="cc.userprofile.SchedulingCheckBoxFix(this);" type=\"checkbox\" value=\"08\" name=\"webcambook\"  class=\"webcambook\" />	</p>' +
                        '<a id="submit" href="#" onclick="cc.userprofile.WebCamScheduleBook( \'' + date + '\', \'' + scheduleid + '\', \'' + memberid + '\');" class="sprite button" >Submit</a><br/><p>*GMT</p></div>';
                    break;
                case '2':
                    msg += '<div id="wc-bookoverlay"><h1>I\'d Like to chat to you...</h1><p>Sometime between 09:00-10:00	<input id=\"09\" onclick="cc.userprofile.SchedulingCheckBoxFix(this);" type=\"checkbox\" value=\"09\"	 name=\"webcambook\"  class=\"webcambook\" />	</p>' +
                        '<p>Sometime between 10:00-11:00 <input id=\"10\" onclick="cc.userprofile.SchedulingCheckBoxFix(this);" type=\"checkbox\" value=\"10\" name=\"webcambook\"  class=\"webcambook\" />	</p>' +
                        '<p>Sometime between 11:00-12:00 <input id=\"11\" onclick="cc.userprofile.SchedulingCheckBoxFix(this);" type=\"checkbox\" value=\"11\" name=\"webcambook\"  class=\"webcambook\" /></p>' +
                        '<p>Sometime between 12:00-13:00 <input id=\"12\" onclick="cc.userprofile.SchedulingCheckBoxFix(this);" type=\"checkbox\" value=\"12\" name=\"webcambook\"  class=\"webcambook\" />	</p>' +
                        '<p>Sometime between 13:00-14:00 <input id=\"13\" onclick="cc.userprofile.SchedulingCheckBoxFix(this);" type=\"checkbox\" value=\"13\" name=\"webcambook\"  class=\"webcambook\" />	</p>' +
                        '<p>Sometime between 14:00-15:00 <input id=\"14\" onclick="cc.userprofile.SchedulingCheckBoxFix(this);" type=\"checkbox\" value=\"14\" name=\"webcambook\"  class=\"webcambook\" />	</p>' +
                        '<p>Sometime between 15:00-16:00 <input id=\"15\" onclick="cc.userprofile.SchedulingCheckBoxFix(this);" type=\"checkbox\" value=\"15\" name=\"webcambook\"  class=\"webcambook\" />	</p>' +
                        '<p>Sometime between 16:00-17:00 <input id=\"16\" onclick="cc.userprofile.SchedulingCheckBoxFix(this);" type=\"checkbox\" value=\"16\" name=\"webcambook\"  class=\"webcambook\" />	</p>' +
                        '<a id="submit" onclick="cc.userprofile.WebCamScheduleBook( \'' + date + '\', \'' + scheduleid + '\', \'' + memberid + '\');" href="#" class="sprite button" >Submit</a><br/><p>*GMT</p></div>';
                    break;
                case '3':
                    msg += '<div id="wc-bookoverlay"><h1>I\'d Like to chat to you...</h1><p>Sometime between	17:00-18:00	<input id=\"17\" onclick="cc.userprofile.SchedulingCheckBoxFix(this);" type=\"checkbox\" value=\"17\"	 name=\"webcambook\"  class=\"webcambook\" />	</p>' +
                        '<p>Sometime between 18:00-19:00 <input id=\"18\" onclick="cc.userprofile.SchedulingCheckBoxFix(this);" type=\"checkbox\" value=\"18\" name=\"webcambook\"  class=\"webcambook\" />	</p>' +
                        '<p>Sometime between 19:00-20:00 <input id=\"19\" onclick="cc.userprofile.SchedulingCheckBoxFix(this);" type=\"checkbox\" value=\"19\" name=\"webcambook\"  class=\"webcambook\" />	</p>' +
                        '<p>Sometime between 20:00-21:00 <input id=\"20\" onclick="cc.userprofile.SchedulingCheckBoxFix(this);" type=\"checkbox\" value=\"20\" name=\"webcambook\"  class=\"webcambook\" /></p>' +
                        '<a id="submit" onclick="cc.userprofile.WebCamScheduleBook( \'' + date + '\', \'' + scheduleid + '\', \'' + memberid + '\');" href="#" class="sprite button" >Submit</a><br/><p>*GMT</p></div>';
                    break;
                case '4':
                    msg += '<div id="wc-bookoverlay"><h1>I\'d Like to chat to you...</h1><p>Sometime between	21:00-22:00	<input id=\"21\" onclick="cc.userprofile.SchedulingCheckBoxFix(this);" type=\"checkbox\" value=\"21\"	name=\"webcambook\"  class=\"webcambook\" /></p>' +
                        '<p>Sometime between 22:00-23:00	<input id=\"22\" onclick="cc.userprofile.SchedulingCheckBoxFix(this);" type=\"checkbox\" value=\"22\"	 name=\"webcambook\"  class=\"webcambook\" /></p>' +
                        '<p>Sometime between 23:00-00:00	<input id=\"23\" onclick="cc.userprofile.SchedulingCheckBoxFix(this);" type=\"checkbox\" value=\"23\"  name=\"webcambook\"  class=\"webcambook\" />	</p>' +
                        '<a id="submit" onclick="cc.userprofile.WebCamScheduleBook( \'' + date + '\', \'' + scheduleid + '\', \'' + memberid + '\');" href="#" class="sprite button" >Submit</a><br/><p>*GMT</p></div>';
                    break;
                case '5':
                    msg += '<div id="wc-bookoverlay"><h1>I\'d Like to chat to you...</h1><p>Sometime between 00:00-01:00	<input id=\"00\" onclick="cc.userprofile.SchedulingCheckBoxFix(this);" type=\"checkbox\" value=\"00\" name=\"webcambook\"  class=\"webcambook\" />	</p>' +
                        '<p>Sometime between 01:00-02:00 <input id=\"01\" onclick="cc.userprofile.SchedulingCheckBoxFix(this);" type=\"checkbox\" value=\"01\" name=\"webcambook\"  class=\"webcambook\" />	</p>' +
                        '<p>Sometime between 02:00-03:00 <input id=\"02\" onclick="cc.userprofile.SchedulingCheckBoxFix(this);" type=\"checkbox\" value=\"02\" name=\"webcambook\"  class=\"webcambook\" />	</p>' +
                        '<p>Sometime between 03:00-04:00 <input id=\"03\" onclick="cc.userprofile.SchedulingCheckBoxFix(this);" type=\"checkbox\" value=\"03\" name=\"webcambook\"  class=\"webcambook\" />	</p>' +
                        '<a id="submit" onclick="cc.userprofile.WebCamScheduleBook( \'' + date + '\', \'' + scheduleid + '\', \'' + memberid + '\');" href="#" class="sprite button" >Submit</a><br/><p>*GMT</p></div>';
                    break;
            }


            //msg += '</form>';

            jQuery('body').append("<div style='display:none'><div id='modal-msg'><div class='schedulebg'></div><div class='schedulemsg'></div></div></div>");

            if (timeid === '2') {

                jQuery('#modal-msg .schedulebg').css('height', '240px');
                jQuery('#modal-msg .schedulemsg').css('height', '220px');
            } else {
                jQuery('#modal-msg .schedulebg').css('height', '170px');
                jQuery('#modal-msg .schedulemsg').css('height', '146px');
            }

            jQuery('#modal-msg .schedulemsg').html(msg);

            jQuery.fn.colorbox({
                href: '#modal-msg',
                inline: true,
                opacity: 0.65,
                close: 'X'

            });

        },


        AppendWishListPopUp: function(value) {

            jQuery('#up-wishlist .send-pm-bg').css('height', parseInt(value) + 20);
            jQuery('#up-wishlist .send-pm-content').css('height', value);

            // jQuery('#modal-msg .schedulemsg').css('height', '220px');


        },


        AppendWishListBackground: function() {

            jQuery('#up-wishlist .send-pm-bg').css('background-color', ' #000000');
            jQuery('#up-wishlist .send-pm-content').css('background-color', ' #000000');

            // jQuery('#modal-msg .schedulemsg').css('height', '220px');


        },


        updateOverlayResponseMsg: function(msg) {
            jQuery('.send-pm-overlay .spm-error').html(msg);
            if (jQuery('.send-pm-overlay .spm-msg').size() > 0) {
                jQuery('.send-pm-overlay .spm-msg').fadeOut(100, function() {
                    jQuery('.send-pm-overlay .spm-error').fadeIn(300);
                });
            } else {
                jQuery('.send-pm-overlay .spm-error').fadeIn(300);
            }
        }

    };

} ();



