//=====================================================//
var LoadReadyLocal = {
    uploadProfilePic: function(){
        $(function() {
		    $('td.del a').livequery('click', function(e){
		        e.preventDefault();
		        var media_id    = $(this).attr('id');
		        var record_type = $(this).attr('record_type');
		        var link        = $(this);
		        var url         = '/index.php?_room=media&_spAction=deleteMedia&media_id=' + media_id + '&showHTML=0';
		
		         Util.showProgressInd();
		
		        $.get(url, function(){
		            var container = $(link).closest('.mediaFilesDisplayWrap');
		            Media.reloadMediaFileNamesDisplay(container);
		        });
		    });
		    $('a.uploadQueue').livequery('click', function(e){
		        e.preventDefault();
		        var fileID    = $('input[type=file]', $(this).parent()).attr('id');
		        var record_type = $(this).attr('record_type');
		
		        $('#' + fileID).uploadifySettings('scriptData', {'recordType': record_type});
                $('#' + fileID).uploadifyUpload();
		    });
		
		    $('a.clearQueue').livequery('click', function(e){
		        e.preventDefault();
		        var fileID = $('input[type=file]', $(this).parent()).attr('id');
		        $('#' + fileID).uploadifyClearQueue();
		    });        
		});
    },

    forgotPassword: function(){
        $(function() {
            Dialog.setUpForm('forgotPasswordForm');
        });
    },

    changePassword: function(){
        $(function() {
            Dialog.setUpForm('changePasswordForm');
        });
    },

    eventForm: function(){
        $(function() {
            Member.setupEventForm();
        });
    },

    login: function(){
        $(function() {
            Dialog.setUpForm('loginForm');
            $('#btnLoginForm').livequery('click', function(e) {
                e.preventDefault();
                Dialog.openDialog.call(this, 'loginForm', 'Login');
                //Member.loginForm.call(this, e);
            });

            $('#btnForgotPassword').click(function(e){
                e.preventDefault();
                Dialog.openDialog.call(this, 'forgotPasswordForm', 'Password Retrieval Form', 500, 300);
            });
                                  
            $('#btnNewPwdForm').click(function(e){
                e.preventDefault();
                Dialog.openDialog.call(this, 'changePasswordForm', 'New Password Form', 500, 300);
            });

        });
    },

    editProfileForm: function(){
        $(function() {
            Util.setUpAjaxFormGeneral.call(this, 'editProfileForm');
        });
    },

    forum: function(){
       $(function() {
            $('#createNewTopic').click(function(e) {
                e.preventDefault();
                Forum.createNewTopic();
            });

            $('#cancelForumNew').click(function(e) {
                e.preventDefault();
                Forum.cancelNewTopic();
            });


            $('#submitForumNew').click(function(e) {
                e.preventDefault();
                var options = {
                    url: '/index.php?_room=forum&_spAction=newSubmit&showHTML=0',
					success: function(json, statusText, jqFormObj) {
		            	Validate.validateFormData(json, statusText, jqFormObj);
						Util.hideProgressInd();
					},
                    beforeSubmit: function() {
                        Util.showProgressInd();
                        $('#frmForumNew .progressSpan').addClass('progress').css('display', 'block');
                    },
                    dataType: 'json'
                };
                $('#frmForumNew').ajaxForm(options);
                $('#frmForumNew').submit()
            });

            $('#replyTopic').click(function(e) {
                e.preventDefault();
                Forum.replyTopic();
            });

            $('#cancelReply').click(function(e) {
                e.preventDefault();
                Forum.cancelReplyTopic();
            });

            $('#submitReply').click(function(e) {
                e.preventDefault();

                var options = {
                    url: '/index.php?_room=forum&_spAction=replySubmit&showHTML=0',
					success: function(json, statusText, jqFormObj) {
		            	Validate.validateFormData(json, statusText, jqFormObj);
						Util.hideProgressInd();
					},
		            beforeSubmit: function() {
						Util.showProgressInd();
		            },
                    dataType: 'json'
                };
                $('#frmForumReply').ajaxForm(options);
                $('#frmForumReply').submit()

            });

        });
    },

    registerForm: function(){
        $(function() {
            $("div[id='fld_title_other']").hide();
            $("div[id='fld_position_other']").hide();
            $("div[class='fld_amex_code']").hide();

            $('#btnSubmit').click(Member.submitRegisterForm);
            Member.setupRegisterForm();
        });
    }

};

LoadReady = $.extend(LoadReady, LoadReadyLocal);


$(function() {


    // set the border right of last item to 0 //
    $('#list li:nth-child(even)').css({'background-color': '#eff3ef'});
    $('table.generic tr:nth-child(even)').css({'background-color': '#f3f3f3'});
    $('table.eventList tr:nth-child(even)').css({'background-color': '#B8CCE0'});
    $('table.eventList tr:nth-child(odd)').css({'background-color': '#8DACCC'});
    $('table.siteSearchResult tr:nth-child(even)').css({'background-color': '#D1DEEF'});
    $('table.memberDirectory tr:nth-child(even)').css({'background-color': '#D1DEEF'});

    $('#siteSearch').submit(function(e){
        e.preventDefault();
        Util.clearPrepopulatedTextbox($(this));
        $(this).unbind('submit');
        $(this).trigger('submit');
    });

    $('#keyword').focus(function(){
        var value = $(this).val();
        if ($(this).val() == 'keyword search'){
            $(this).val("");
        }
    });


    $('#ui-datepicker-div').draggable();
    
    $('input[name=payment_method]').click(function(){
        var value = $(this).val();
        if(value == "Credit Card"){
            $('.creditCardInfo').css('display', 'block');
        }else {
            $('.creditCardInfo').css('display', 'none');
        }

    });

    $('#fld_title').change(function(){
        var value = $(this).val();
        if(value == "Other"){
            $('#fld_title_other').css('display', 'block');
        }else {
            $('#fld_title_other').css('display', 'none');
        }

    });

    $('#fld_position').change(function(){
        var value = $(this).val();
        if(value == "Other"){
            $('#fld_position_other').css('display', 'block');
        }else {
            $('#fld_position_other').css('display', 'none');
        }

    });

    $('#fld_card_type').change(function(){
        var value = $(this).val();
        if(value == "Amex"){
            $('.fld_amex_code').css('display', 'block');
        }else {
            $('.fld_amex_code').css('display', 'none');
        }

    });
});

$(function() {
    var dateObj = new Date();
    var currentYear = dateObj.getFullYear();
    $("#fld_date_of_birth").livequery(function(){
        $(this).datepicker({
            showOn: 'button',
            buttonImage: '/images/icons/calendar_icon.gif',
            dateFormat: 'yy-mm-dd',
            buttonImageOnly: true,
            changeYear: true,
            yearRange: '1920:' + currentYear
        })
        .focus(function(){
            $(this).blur();
        });
        
        $('#ui-datepicker-div').draggable();
    });   

    $("a[title]").css({'text-decoration':'underline', 'color' : '#0071BC'}).tooltip();
});
