//=====================================================//
var LoadReadyLocal = {
    emailToFriend: function(){
        $(function() {
            $('#btnEmailToFriend').live('click', Job.emailToFriendForm);            
        });
    },
    
    login: function(){
        $(function() {
            $('.btnLoginForm').live('click', Member.loginForm);
        });
    },
    
    alertSignUpForm: function(){
        $(function() {
            var options = {
                success: function(json, statusText, jqFormObj) {
                    Validate.validateFormData(json, statusText, jqFormObj);
                    Util.hideProgressInd();
                },
                beforeSubmit: function() {
                    Util.showProgressInd();
                },
                dataType: 'json'
            };
            $('#alertSignUpForm').ajaxForm(options);
        });
    },
    
    /**
     * Used for new member and quick submit
     */
    register: function(){
        $(function() {
            var options = {
                success: function(json, statusText, jqFormObj) {
                    Validate.validateFormData(json, statusText, jqFormObj);
                    Util.hideProgressInd();
                },
                beforeSubmit: function() {
                    Util.showProgressInd();
                },
                dataType: 'json'
            };
            $('#registerForm').ajaxForm(options);
            Util.showNoFlashMessage()

        });
    },
    
    /**
     *
     */
    quickSubmit: function(){
        $(function() {
            var options = {
                success: function(json, statusText, jqFormObj) {
                    Validate.validateFormData(json, statusText, jqFormObj);
                    Util.hideProgressInd();
                },
                beforeSubmit: function() {
                    Util.showProgressInd();
                },
                dataType: 'json'
            };
            $('#quickSubmitForm').ajaxForm(options);
            Util.showNoFlashMessage()

        });
    },

    editProfile: function(){
        $(function() {
            var options = {
                success: function(json, statusText, jqFormObj) {
                    Validate.validateFormData(json, statusText, jqFormObj);
                    Util.hideProgressInd();
                },
                beforeSubmit: function() {
                    Util.showProgressInd();
                },
                dataType: 'json'
            };
            $('#editProfileForm').ajaxForm(options);

		    $('td.del a').live('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').live('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').live('click', function(e){
		        e.preventDefault();
		        var fileID = $('input[type=file]', $(this).parent()).attr('id');
		        $('#' + fileID).uploadifyClearQueue();
		    });
            
            Util.showNoFlashMessage()

		});
    },
    
    jobDetail: function(){
        $(function() {
		    var autoApplyJob = $('#autoApplyJob').val();
		    var job_id       = $('#job_id').val();
            if (autoApplyJob == 1) {
                Job.applyJob(job_id);
            }

		});
    }

};

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.tblJobList tr:nth-child(even)').css({'background-color': '#EFEFEF'});
    $('.footerBar ul li:last').addClass('last');
    $('#keyword').focus(function(){
        $(this).val("");
    });

    $('#newsList>div:nth-child(even)').css({'background-color': '#EFEFEF'});

});


$(function() {
    $('ul.sf-menu').superfish();

    //Add comment
    $('.addComment').live('click', function(e){
        e.preventDefault();
        link = $(this);

		Util.showProgressInd();
		var parent = $(link).closest('.commentHltBox');
		var commentsBox = $('.commentsList', parent);
		if($(commentsBox).css('display') == 'none'){
		    $('a.showComments', parent).click();
		}
		Comments.showCommentsForm.call(link);
    });

    $('.showComments').click(function(e){
        e.preventDefault();
        var rec_id = $(this).attr('id');
        var url    = '/index.php?_room=comment&_spAction=list&record_id=' + rec_id + '&showHTML=0';
        var link   = $(this);

        var parent = $(link).closest('.commentHltBox');
        var commentsBox = $('.commentsList', parent);
		if($(commentsBox).css('display') == 'block'){
	        $(commentsBox).slideUp();
	        return;
		}
    
        Util.showProgressInd();
        $.get(url, function(data){
            $(commentsBox).html(data);
            $(commentsBox).slideDown();
            Util.hideProgressInd();
        });
    });

	$('#description').live('click', Content.getDescription);

    //forgot password 
    $('#btnForgotPassword').live('click', function(e){
        e.preventDefault();
        Dialog.setUpForm('frmForgotPassword');
        Util.openFormInDialog.call(this, 'frmForgotPassword', 'Password Retrieval Form', 450, 370);
    });
    
    //resend activation link
    $('#btnResendActivationLink').live('click', function(e){
        e.preventDefault();
        Dialog.setUpForm('frmResendActivationLink');
        Util.openFormInDialog.call(this, 'frmResendActivationLink', 'Resend Member Activation Link', 450, 430);
    });

    //activate button
    $('#btnActivateMember').click(function(e){
        //e.preventDefault();
        Util.showProgressInd();

    });

});


