/**
*【Drama Network Inc. 多瑪數位廣告】
* web http://www.drama.com.tw
* email service@drama.com.tw
* tel 02 2771 0701
* fax 02 2771 1767
*/ 

var drama;
if (!drama) drama = {};

drama.indexInit = function() {
	changeGoodContent();
	
	$('#goodR')
			.hover(function() {
					$('body').stopTime('getGood');
				},
				function() {
					changeGoodContent();
				});
	
	function changeGoodContent() {
		$('body').everyTime(8000, 'getGood', function() {
			$.post('ajax_index_good_change.php', '', function($res) {
				$('#goodAjaxContent').html($res)
			});
		});
	}
}

drama.dcplayer_searchAllinit = function() {
    var $kwd = $('#keyword');
    
    function searchProcess() {
        var $type = $('#searchType option:selected').val();
        // 檢查有沒有輸入關鍵字
        if ($kwd.val() == '') {
            alert('請填寫關鍵字');
            $kwd.focus();
            return false;
        } else {
            // 將關鍵字寫入資料庫
            $.post('ajax_save_keyword.php', {keyword: $kwd.val(), type: $type}, function() {
                // 搜尋
                window.location = 'dcplayer_searchAll.php?type=' + encodeURI($type) + '&keyword=' + encodeURI($kwd.val());
            });
        }
    }
    
    $('#btnSearch').bind('click', function() {
        searchProcess();
        return false;
    });
    
    $('#searchForm').submit(function() {
        searchProcess();
        return false;
    });
}

drama.spp_indexInit = function() {
	// top 10 ajax
    $.post('ajax_top10_book.php','', function($data) {
        var $xml = $($data).find('top10');
        $.each($xml.find('book'), function($k, $v) {
			if ($k < 7) {
				if ($k == 0) {
					var $url = $($v).find('url').text(),
						$img = $($v).find('img').text(),
						$title = $($v).find('title').text(),
						$author = $($v).find('pho').text(),
						$price = $($v).find('vpri').text(),
						$date = $($v).find('vdate').text();
					$('#billboard ul:first').append('<li class="first"><em>' + ($k + 1) + '</em><ul><li class="img"><a href="' + $url + '"><img src="' + $img + '" /></a></li><li><a href="' + $url + '">' + $title + '</a></li><li>' + $author + '</li><li>出版日期：' + $date + '</li><li>特價：<span class="highlight">' + $price + '</span>元</li><li><a href="' + $url + '" class="btnDetail">我要購買</a></li></ul></li>');
				} else {
					$('#billboard ul:first').append('<li><em>' + ($k + 1) + '</em><a href="' + $($v).find('url').text() + '" target="_blank">' + drama.cutFont($($v).find('title').text(), 22) + '</a></li>');
				}
			}
        });
    }, 'xml');
}

drama.album_photo = function() {
    var $frm = $('#messageForm');
    
    // 熱鍵
    $(document).bind('keydown', 'c', function() {
        if ($('a.next').is('*')) {
            window.location = $('a.next').attr('href');
        }
    });
    
    $(document).bind('keydown', 'x', function() {
        if ($('a.pre').is('*')) {
            window.location = $('a.pre').attr('href');
        }
    });
    
    // 小圖Lighbox
    $('a.replyIMG').lightBox();
	
    // 版主回覆按鈕
    $('a[name="btnReply"]').each(function() {
        $(this).click(function() {
            $(this).prev().slideDown();
            $(this).hide();
            return false;
        });
    });
	
    // 版主編輯內容按鈕
    $('a[name="btnEdit"]').each(function() {
        $(this).click(function() {
			$(this).hide();
            $(this).parent().next().slideDown();
            return false;
        });
    });
    
    // 版主取消按鈕
    $('a[name="btnCancel"]').each(function() {
		$(this).click(function() {
			$(this)
				.parents('li:first')
					.find('.editArea')
						.slideUp()
				.end()
					.find('a[name="btnEdit"], a[name="btnReply"]')
						.show();
			return false;
		});
    });
	
	// 版主送出按鈕
    $('a[name="btnReplySubmit"]').each(function() {
        $(this).click(function() {
            var $id = $(this).attr('id'),
                $contents = $(this).prevAll('div.inputArea:first').find('textarea').val(),
				$secret = $(this).parents('li:first').find('input[name="editScecret"]').is(':checked') ? 1 : 0;		
				
            drama.showModal('');
            $.post('ajax_photos_board_reply.php', {id: $id, contents: $contents, secret: $secret}, function($res) {
				if ($res.err == '') {
					drama.showModal($res.msg);
					$(document).oneTime(1500, function() {
						window.location.reload();
					});
				} else {
					drama.showModal($res.err);
					drama.hideModal('');
				}
            }, 'json');
            return false;
        });

    });
              
    // 表單驗證
    $frm.validate({
        rules: {
            captcha: {
                required: true,
                digits: true,
                rangelength: [4, 4]
            },
            contents: 'required'
        },
        messages: {
            captcha: {
                required: '請輸入驗證碼',
                digits: '請輸入正確格式',
                rangelength: '請輸入正確格式'
            },
            contents: {
                required: '請輸入內容'
            }

        },
         errorPlacement: function(error, element) {
            error.appendTo(element.parents("li:first"));
        }
    });
	
    // 重新取得驗證碼
    $('a.refresh').click(function() {
        drama.showModal('');
        $.post('ajax_reload_captcha.php', '', function($res) {
            drama.hideModal();
            $('div#captcha').html($res);
        });
        return false;
    });
    
    // 留言板送出按鈕
    $('a#btnSubmit').click(function() {
        $frm.submit();
        return false;
    });
    
    // 留言板重填按鈕
    $('a#btnRest').click(function() {
        $('input, textarea', $frm).val('');
        return false;
    });
    
    // 顏色相間
    $('#message > li:even').addClass('gray');
	
	// Ajax分頁
	drama.pager();
    
	// 超連結換色
    drama.urlChangeColor();
}

drama.album_content = function() {
    var $frm = $('#messageForm'),
        $albumDescription = $('#albumDescription');
        
    // 麵包屑對應
    $('.subNav li:contains("相簿")')
        .html('<span>' + $('.subNav a:contains("相簿")').html() + '</span>');
        
    // 相簿簡介modal設定
    $albumDescription
        .css({width: 640, height: 500, backgroundColor: '#FFFFFF', padding: 4})
        .hide();
    
    // 詳細內容按鈕
    $('#btnShowAlbumDescription').click(function() {
        $.blockUI({
            message: $albumDescription,
            css: {
                border: 'none',
                cursor: 'default',
                textAlign: 'left',
                width: $albumDescription.width(),
                height: $albumDescription.height(),
                top: ($(window).height() - $albumDescription.height()) / 2,
                left: ($(window).width() - $albumDescription.width()) / 2
            },
            overlayCSS: {
                cursor: 'default'
            }
        });
        $('.blockOverlay').click($.unblockUI);
        return false;
    });
	
    // 小圖Lighbox
    $('a.replyIMG').lightBox();
    
    // 版主回覆按鈕
    $('a[name="btnReply"]').each(function() {
        $(this).click(function() {
            $(this).prev().slideDown();
            $(this).hide();
            return false;
        });
    });
	
    // 版主編輯內容按鈕
    $('a[name="btnEdit"]').each(function() {
        $(this).click(function() {
			$(this).hide();
            $(this).parent().next().slideDown();
            return false;
        });
    });
    
    // 版主取消按鈕
    $('a[name="btnCancel"]').each(function() {
		$(this).click(function() {
			$(this)
				.parents('li:first')
					.find('.editArea')
						.slideUp()
				.end()
					.find('a[name="btnEdit"], a[name="btnReply"]')
						.show();
			return false;
		});
    });
	
	// 版主送出按鈕
    $('a[name="btnReplySubmit"]').each(function() {
        $(this).click(function() {
            var $id = $(this).attr('id'),
                $contents = $(this).prevAll('div.inputArea:first').find('textarea').val(),
				$secret = $(this).parents('li:first').find('input[name="editScecret"]').is(':checked') ? 1 : 0;		
				
            drama.showModal('');
            $.post('ajax_album_board_reply.php', {id: $id, contents: $contents, secret: $secret}, function($res) {
				if ($res.err == '') {
					drama.showModal($res.msg);
					$(document).oneTime(1500, function() {
						window.location.reload();
					});
				} else {
					drama.showModal($res.err);
					drama.hideModal('');
				}
            }, 'json');
            return false;
        });

    });
              
    // 表單驗證
    $frm.validate({
        rules: {
            captcha: {
                required: true,
                digits: true,
                rangelength: [4, 4]
            },
            contents: 'required'
        },
        messages: {
            captcha: {
                required: '請輸入驗證碼',
                digits: '請輸入正確格式',
                rangelength: '請輸入正確格式'
            },
            contents: {
                required: '請輸入內容'
            }

        },
         errorPlacement: function(error, element) {
            error.appendTo(element.parents("li:first"));
        }
    });
	
    // 重新取得驗證碼
    $('a.refresh').click(function() {
        drama.showModal('');
        $.post('ajax_reload_captcha.php', '', function($res) {
            drama.hideModal();
            $('div#captcha').html($res);
        });
        return false;
    });
    
    // 留言板送出按鈕
    $('a#btnSubmit').click(function() {
        $frm.submit();
        return false;
    });
    
    // 留言板重填按鈕
    $('a#btnRest').click(function() {
        $('input, textarea', $frm).val('');
        return false;
    });
    
    // 顏色相間
    $('#comment > li:even').addClass('gray');
	
	// Ajax分頁
	drama.pager();
    
	// 超連結換色
    drama.urlChangeColor();
}

drama.works_contentInit = function() {
    var $frm = $('#messageForm')
        $lock = $('#albumLock').val();
    
    // 上鎖功能
    if ($lock == 0) {
        $('<div>')
        .attr('id', 'albumCover')
        .css({width: '100%', height: 415, position: 'absolute', top: 0, left: 0, zIndex: 1000, display: 'block', backgroundColor: 'red', opacity: 0})
        .prependTo($('#photoSlider'));
    }
    
	// 小圖Lighbox
    $('a.replyIMG').lightBox();

	// 送出按鈕
    $('a[name="btnReplySubmit"]').each(function() {
        $(this).click(function() {
            var $id = $(this).attr('id'),
                $contents = $(this).prevAll('div.inputArea:first').find('textarea').val(),
				$secret = $(this).parents('li:first').find('input[name="editScecret"]').is(':checked') ? 1 : 0;		
				
            drama.showModal('');
            $.post('ajax_album_board_reply.php', {id: $id, contents: $contents, secret: $secret}, function($res) {
				if ($res.err == '') {
					drama.showModal($res.msg);
					$(document).oneTime(1500, function() {
						window.location.reload();
					});
				} else {
					drama.showModal($res.err);
					drama.hideModal('');
				}
            }, 'json');
            return false;
        });

    });
    
    // 版主回覆按鈕
    $('a[name="btnReply"]').each(function() {
        $(this).click(function() {
            $(this).prev().slideDown();
            $(this).hide();
            return false;
        });
    });
    
    // 取消按鈕
    $('a[name="btnCancel"]').each(function() {
		$(this).click(function() {
			$(this)
				.parents('li:first')
					.find('.editArea')
						.slideUp()
				.end()
					.find('a[name="btnEdit"], a[name="btnReply"]')
						.show();
			return false;
		});
    });
    
    // 編輯內容按鈕
    $('a[name="btnEdit"]').each(function() {
        $(this).click(function() {
			$(this).hide();
            $(this).parent().next().slideDown();
            return false;
        });
    });
    
    // 重新取得驗證碼
    $('a.refresh').click(function() {
        drama.showModal('');
        $.post('ajax_reload_captcha.php', '', function($res) {
            drama.hideModal();
            $('div#captcha').html($res);
        });
        return false;
    });
    
    // 表單驗證
    $frm.validate({
        rules: {
            captcha: {
                required: true,
                digits: true,
                rangelength: [4, 4]
            },
            contents: 'required'
        },
        messages: {
            captcha: {
                required: '請輸入驗證碼',
                digits: '請輸入正確格式',
                rangelength: '請輸入正確格式'
            },
            contents: {
                required: '請輸入內容'
            }

        },
         errorPlacement: function(error, element) {
            error.appendTo(element.parents("li:first"));
        }
    });
    
    // 送出按鈕
    $('a#btnSubmit').click(function() {
        $frm.submit();
        return false;
    });
    
    // 重填按鈕
    $('a#btnRest').click(function() {
        $('input, textarea', $frm).val('');
        return false;
    });
    
    // 顏色相間
    $('#comment > li:even').addClass('gray');
    
    drama.urlChangeColor();
}

drama.beauty_works_listInit = function($cate) {
    // 地點下拉選單
    $('#catePos2').dependent({parent: 'catePos1', defaultText: '請選擇'});
    
    // 列表篩選按鈕
    $('a#btnFilter').click(function() {
        var $catePos1 = $('#catePos1 option:selected').val(),
            $catePos2 = $('#catePos2 option:selected').val(),
            $url = 'beauty_works_list.php?cate=' + $cate + '&catePos1=' + $catePos1 + '&catePos2=' + $catePos2;
        window.location = $url;
        return false;
    });
}

drama.works_listInit = function($mid) {
    // 分類下拉選單
    $('#cateAlbum2').dependent({parent: 'cateAlbum1', defaultText: '請選擇'});
    
    // 地點下拉選單
    $('#catePos2').dependent({parent: 'catePos1', defaultText: '請選擇'});
    
    // 列表篩選按鈕
    $('a#btnFilter').click(function() {
        var $cateAlbum1 = $('#cateAlbum1 option:selected').val(),
            $cateAlbum2 = $('#cateAlbum2 option:selected').val(),
            $catePos1 = $('#catePos1 option:selected').val(),
            $catePos2 = $('#catePos2 option:selected').val(),
            $url = 'works_list.php?mid=' + $mid + '&cateAlbum1=' + $cateAlbum1 + '&cateAlbum2=' + $cateAlbum2 + '&catePos1=' + $catePos1 + '&catePos2=' + $catePos2;
        window.location = $url;
        return false;
    });
    
    drama.urlChangeColor();
}

drama.message_boardInit = function() {
    var $frm = $('#messageForm');
	
	// 小圖Lighbox
	$('a.replyIMG').lightBox();
	
	// 編輯與回覆按鈕
	$('a[name="btnEdit"], a[name="btnReply"]').each(function() {
		$(this).click(function() {
			$(this)
				.hide()
				.parents('li:first')
					.find('.editArea')
						.slideDown();
			return false;
		});
	});
	
	// 送出按鈕
	$('a[name="btnBoardSubmit"]').each(function() {
		$(this).click(function() {
			var $id = $(this).attr('id'),
				$secret = $(this).parents('li:first').find('input[name="editScecret"]').is(':checked') ? 1 : 0,
				$cts = $(this).parents('li:first').find('textarea[name="editTextArea"]').val();
			
			drama.showModal('處理中…');
			
			$.post('ajax_front_board.php', {id: $id, secret: $secret, cts: $cts}, function($res) {
				
				if ($res.err == '') {
					drama.showModal($res.msg);
					$(document).oneTime(1500, function() {
						window.location.reload();
					});
				} else {
					drama.showModal($res.err);
					drama.hideModal('');
				}
			}, 'json');
			
			return false;
		});
	});
	
	// 取消按鈕
	$('a[name="btnBoardCancel"]').each(function() {
		$(this).click(function() {
			$(this)
				.parents('li:first')
					.find('.editArea')
						.slideUp()
				.end()
					.find('a[name="btnEdit"], a[name="btnReply"]')
						.show();
			return false;
		});
	});
	
    // 重新取得驗證碼
    $('a.refresh').click(function() {
        drama.showModal('');
        $.post('ajax_reload_captcha.php', '', function($res) {
            drama.hideModal();
            $('div#captcha').html($res);
        });
        return false;
    });
    
    // 表單驗證
    $frm.validate({
        rules: {
            captcha: {
                required: true,
                digits: true,
                rangelength: [4, 4]
            },
            contents: 'required'
        },
        messages: {
            captcha: {
                required: '請輸入驗證碼',
                digits: '請輸入正確格式',
                rangelength: '請輸入正確格式'
            },
            contents: {
                required: '請輸入內容'
            }

        },
         errorPlacement: function(error, element) {
            error.appendTo(element.parents("li:first"));
        }
    });
    
    // 送出按鈕
    $('a#btnSubmit').click(function() {
        $frm.submit();
        return false;
    });
    
    // 重填按鈕
    $('a#btnRest').click(function() {
        $('input, textarea', $frm).val('');
        return false;
    });
    
    // 顏色相間
    $('#message > li:even').addClass('gray');
    
    drama.urlChangeColor();
}

drama.imageListInit = function($id) {
    drama.pager();
    drama.selectAll();
    drama.funcDel('topic');
    drama.funcOn('topic');
    
    // 儲存按鈕
    $('a[name="btnEditSave"]').each(function() {
        $(this).click(function() {
            var $val = $(this).prev().find('input[name="editTitle"]').val(),
                $id = $(this).attr('id'),
                $temp = $(this).parents('li:first');
            if ($.trim($val) == '') {
                alert('請輸入文字');
            } else {
                drama.showModal('');
                $.post('ajax_topic_upd.php', {id: $id, title: $val}, function($res) {
                    $('#loader').html($res);
                    drama.hideModal('');
                    if ($res == '更新成功') {
                        $temp.find('.textArea').find('.textTitle').html($val);
                        $temp.find('.textArea').show();
                        $temp.find('.editArea').hide();
                    }
                });
            }
            return false;
        });
    });
    
    // 編輯按鈕
    $('a.edit').each(function() {
        $(this).click(function() {
            // 將文字區域隱藏
            $(this).parents('li:first').find('.textArea').hide();
            // 顯示編輯區域
            $(this).parents('li:first').find('.editArea').show();
            
            return false;
        });
    });
    
    // 取消按鈕
    $('a[name="btnEditCancel"]').each(function() {
        $(this).click(function() {
            // 將編輯區域隱藏
            $(this).parents('li:first').find('.textArea').show();
            // 顯示文字區域
            $(this).parents('li:first').find('.editArea').hide();
            return false;
        });
    });
    
   // 排序
    $('#movable').sortable({
        change: function() {
            $('a.save').fadeIn();
        },
        stop: function() {
            $('#movable > li')
                .removeClass('gray')
                .filter(':odd')
                .addClass('gray');
        }
    });
    
    // 儲存排序按鈕
    $('a.save').click(function() {
        drama.showModal('儲存中');
        $.post('ajax_topic_sort.php', $('#movable').sortable('serialize') + '&pageNum_RecTopicImages=' + $('#nowPage').val(), function($res) {
            $('#loader').html($res);
            $('a.save').fadeOut();
            drama.hideModal('');
        });
        return false;
    });
    
    // 顏色相間
    $('#movable > li:odd').addClass('gray');
    
    // 列表篩選按鈕
    $('a.abtn1').click(function() {
        var $tm = $('#topicMax option:selected').val(),
            $url = 'imageList.php';
        
        $.post($url, {filterSet: 1, tm: $tm}, function() {
            window.location = $url;
        });
        return false;
    });
    
    // 新增按鈕
    $('a.addBtn').click(function() {
        $('#imageListForm').submit();
        return false;
    });
    
    // 表單驗證
    $('#imageListForm').validate({
        rules: {
            title: 'required',
            img: 'required',
            on: 'required'
        },
        messages: {
            title: {
                required: '請輸入圖片標題'
            },
            img: {
                required: '請上傳圖片'
            },
            on: {
                required: '請選擇上下架'
            }
        },
        errorPlacement: function(error, element) {
            element.parent().after(error);
        },
        submitHandler: function() {
            drama.showModal('');
            var $title = $('#title').val(),
                $on = $('input[name="on"]:checked').val(),
                $img = $('#img').val();
            $.post('ajax_topic_add.php', {title: $title, on: $on, img: $img}, function($res) {
                $('#loader').html($res);
                drama.hideModal('');
                if ($res == '新增成功') {
                    window.location.reload();
                }
            });
        }
    });

    // 初始上傳
    $('#myFile').uploadify({
        scriptData: {id: $id},
        multi: true,
        method: 'post',
        auto: true,
        fileDesc: '只能選用jpg或gif',
        fileExt: '*.jpg;*.gif',
        script: 'upload_topic.php',
        buttonImg: 'images/account/uploadBtn.gif',
        rollover: true,
        onComplete: function(ev, qu, fi, res) {
            var $json = eval('(' + res + ')');
            $('#loader').html($json.msg);
            drama.hideModal('');
            if ($json.msg == '上傳成功') {
                $('#topicBox').html('<img src="uploads/topic/' + $json.img + '" width="270" height="77" />');
                $('#img').val($json.img);
            }
            return false;
        },
        onProgress: function() {
            drama.showModal('上傳中');
        },
        onSelect: function() {
            return false;
        }
    });
}

drama.family_replyInit = function() {
    drama.pager();
    drama.selectAll();
    drama.funcDel('familyReply');
    drama.funcOn('familyReply');
    
    // 回覆按鈕
    $('a[name="btnReply"]').each(function() {
        $(this).click(function() {
            $(this).parents('.notReply:first').hide();
            $(this).parents('td:first').find('.replyBox').show();
            return false;
        });
    });
    
    // 編輯按鈕
    $('a.edit').each(function() {
       $(this).click(function() {
           $(this).parents('.replyText:first').hide();
           $(this).parents('td:first').find('.replyBox').show();
           return false;
       });
    });
    
    // 取消按鈕
    $('a[name="btnCancel"]').each(function() {
        $(this).click(function() {
            $(this).parent().hide();
            $(this).parents('td:first').find('.replyText').show();
            $(this).parents('td:first').find('.notReply').show();
            return false;
        });
    });
    
    // 儲存按鈕
    $('a[name="btnSave"]').each(function() {
        $(this).click(function() {
            var $id = $(this).attr('id'),
                $contents = $(this).prevAll('div.inputArea:first').find('textarea').val();
            drama.showModal('');
            $.post('ajax_family_board_reply.php', {id: $id, contents: $contents}, function() {
                window.location.reload();
            });
            return false;
        });
    });
    
    // 顏色相間
    $('#commentList tr:gt(0)')
        .filter(':odd')
        .addClass('gray');
        
    // 列表篩選按鈕
    $('a.abtn1').click(function() {
        var $frm = $('#familyReplyMax option:selected').val(),
            $frs = $('#familyReplyStatus option:selected').val();
        $.post('family_reply.php', {filterSet: 1, frm: $frm, frs: $frs}, function() {
            window.location = 'family_reply.php';
        });
        return false;
    });
}

drama.photoReplyInit = function() {
    drama.pager();
    drama.selectAll();
    drama.funcDel('photoReply');
    drama.funcOn('photoReply');
    
    // 回覆按鈕
    $('a[name="btnReply"]').each(function() {
        $(this).click(function() {
            $(this).parents('.notReply:first').hide();
            $(this).parents('td:first').find('.replyBox').show();
            return false;
        });
    });
    
    // 編輯按鈕
    $('a.edit').each(function() {
       $(this).click(function() {
           $(this).parents('.replyText:first').hide();
           $(this).parents('td:first').find('.replyBox').show();
           return false;
       });
    });
    
    // 取消按鈕
    $('a[name="btnCancel"]').each(function() {
        $(this).click(function() {
            $(this).parent().hide();
            $(this).parents('td:first').find('.replyText').show();
            $(this).parents('td:first').find('.notReply').show();
            return false;
        });
    });
    
    // 儲存按鈕
    $('a[name="btnSave"]').each(function() {
        $(this).click(function() {
            var $id = $(this).attr('id'),
                $contents = $(this).prevAll('div.inputArea:first').find('textarea').val();
            drama.showModal('');
            $.post('ajax_photos_board_reply.php', {id: $id, contents: $contents}, function() {
                window.location.reload();
            });
            return false;
        });
    });
    
    // 顏色相間
    $('#commentList tr:gt(0)')
        .filter(':odd')
        .addClass('gray');
        
    // 列表篩選按鈕
    $('a.abtn1').click(function() {
        var $prm = $('#photoReplyMax option:selected').val(),
            $prs = $('#photoReplyStatus option:selected').val();
        $.post('photo_reply.php', {filterSet: 1, prm: $prm, prs: $prs}, function() {
            window.location = 'photo_reply.php';
        });
        return false;
    });
}

drama.replyInit = function() {
    drama.pager();
    drama.selectAll();
    drama.funcDel('reply');
    drama.funcOn('reply');
    
    // 回覆按鈕
    $('a[name="btnReply"]').each(function() {
        $(this).click(function() {
            $(this).parents('.notReply:first').hide();
            $(this).parents('td:first').find('.replyBox').show();
            return false;
        });
    });
    
    // 編輯按鈕
    $('a.edit').each(function() {
       $(this).click(function() {
           $(this).parents('.replyText:first').hide();
           $(this).parents('td:first').find('.replyBox').show();
           return false;
       });
    });
    
    // 取消按鈕
    $('a[name="btnCancel"]').each(function() {
        $(this).click(function() {
            $(this).parent().hide();
            $(this).parents('td:first').find('.replyText').show();
            $(this).parents('td:first').find('.notReply').show();
            return false;
        });
    });
    
    // 儲存按鈕
    $('a[name="btnSave"]').each(function() {
        $(this).click(function() {
            var $id = $(this).attr('id'),
                $contents = $(this).prevAll('div.inputArea:first').find('textarea').val();
            drama.showModal('');
            $.post('ajax_album_board_reply.php', {id: $id, contents: $contents}, function() {
                window.location.reload();
            });
            return false;
        });
    });
    
    // 顏色相間
    $('#commentList tr:gt(0)')
        .filter(':odd')
        .addClass('gray');
        
    // 列表篩選按鈕
    $('a.abtn1').click(function() {
        var $rm = $('#replyMax option:selected').val(),
            $rs = $('#replyStatus option:selected').val();
        $.post('reply.php', {filterSet: 1, rm: $rm, rs: $rs}, function() {
            window.location = 'reply.php';
        });
        return false;
    });
}

drama.routeNewInit = function($mid) {
    // 圖片上傳
    $('#myFile').uploadify({
        scriptData: {mid: $mid},
        multi: true,
        method: 'post',
        auto: true,
        fileDesc: '只能選用jpg或gif',
        fileExt: '*.jpg;*.gif',
        script: 'ajax_path_upload.php',
        buttonImg: 'images/account/uploadBtn.gif',
        rollover: true,
        onComplete: function(ev, qu, fi, res) {
            drama.hideModal('1500');
            if (res.indexOf('.') != -1) {
                $('#routeBox').html('<img src="uploads/path/' + res + '" />');
                $('#img').val(res);
            } else {
                alert('上傳失敗');
            }
            return false;
        },
        onProgress: function() {
            drama.showModal('上傳中');
        },
        onSelect: function() {
            return false;
        }
    });
    
    // 編輯器
    $('#contents').fck({
        path: 'fckeditor/',
        toolbar: 'Basic',
        width: 650,
        height: 370
    });
    
    // 下一步按鈕
    $('a#btnSubmit').click(function() {
        $('#formPath').submit();
        return false;
    });
    
    // 表單驗證
    $('#formPath').validate({
        rules: {
            title: 'required',
            on: 'required'
        },
        messages: {
            title: {
                required: '請輸入標題'
            },
            on: {
                required: '請選擇路線設定'
            }
        },
        errorPlacement: function(error, element) {
            error.appendTo(element.parents("td:first"));
        }
    });
}

drama.familyManageInit = function() {
    drama.pager();
    drama.selectAll();
    drama.funcDel('familyMemMax');
    
    // 列表篩選按鈕
    $('a.editBtn').click(function() {
        var $fmm = $('#familyMemMax option:selected').val(),
            $url = 'edit_familyManage.php';
        
        $.post($url, {filterSet: 1, fmm: $fmm}, function() {
            window.location = $url;
        });
        return false;
    });
}

drama.routeListInit = function() {
    drama.pager();
    drama.selectAll();
    drama.funcDel('path');
    drama.funcOn('path');
    
    // 顏色相間
    $('.listStyle > li').not('.listTitle').filter(':odd').addClass('gray');
    
    // 列表篩選按鈕
    $('a.abtn1').click(function() {
        var $pm = $('#pathMax option:selected').val(),
            $url = 'routeList.php';
        
        $.post($url, {filterSet: 1, pm: $pm}, function() {
            window.location = $url;
        });
        return false;
    });
}

drama.uploadPInit = function($mid, $albumid) {
    $('#myFile2').uploadify({
        scriptData: {mid: $mid, aid: $albumid},
        fileDesc: '只能選用jpg或gif',
        fileExt: '*.jpg;*.gif',
        multi: true,
        auto: false,
        script: 'ajax_multi_upload.php',
        buttonImg: 'images/account/uploadP.jpg',
        rollover: true,
        onComplete: function(ev, qu, fi, res) {
            $('#myFile2' + qu).find('span.fileName2').css('color', 'red').append(' ' + res);
            if (res == '相簿空間已滿') {
                alert(res);
                $('#myFile2').uploadifyClearQueue();
            }
            return false;
        },
        onProgress: function($event, $queue) {
            var $index = $('div.uploadBg input[type="text"]').index($('#' + $queue)),
                $val = $('div.uploadBg input[type="text"]').eq($index + 1).val() == '' ? 'dramanone' : $('div.uploadBg input[type="text"]').eq($index + 1).val();
            $('#myFile2').uploadifySettings('scriptData', {newFileName: $val});
        },
        onAllComplete: function() {
            $.blockUI({
                message: $('#checkOK'),
                css: {
                    width: 291,
                    left: ($(window).width() - 291) / 2,
                    top: ($(window).height() - 61) / 2,
                    border: 'none',
                    cursor: 'default'
                },
                overlayCSS: {
                    cursor: 'default'
                }
            });
        }
    });
    $('#upload2').bind('click', function() {
        var $val = $('div.uploadBg input[type="text"]:first').val() == '' ? 'dramanone' : $('div.uploadBg input[type="text"]:first').val();
        $('#myFile2').uploadifySettings('scriptData', {newFileName: $val});
        $('#myFile2').uploadifyUpload();
        return false;
    });
    

    
    $('#btnUploadContinue').click(function() {
        $.unblockUI();
        return false;
    });
}

drama.uploadSInit = function() {
    // 上傳按鈕
    $('a#btnUpload').click(function() {
        $('#photoForm').submit();
        return false;
    });
}

drama.photoListInit = function($albumid) {
    drama.pager();
    drama.selectAll();
    drama.funcDel('photo');
    drama.funcOn('photo');
    
    // 設為封面按鈕
    $('a.cover').click(function() {
        var $chk = $('input[name="idCheck"]:checked');
        if ($chk.size() == 0) {
            alert('您尚未選取相片');
        } else if($chk.size() > 1) {
            alert('只能選擇單張相片作為相簿封面！');
        } else {
            drama.showModal('');
            var $id = $chk.attr('id');
            $.post('ajax_photo_frontpage.php', {id: $id, albumid: $albumid}, function($res) {
                if ($res == '設定完成') {
                    window.location.reload();
                } else {
                    $('#loader').html($res);
                    drama.hideModal('');
                }
            });
        }
        return false;
    });
    
    // 儲存按鈕
    $('a[name="btnSave"]').each(function() {
        $(this).click(function() {
            drama.showModal('');
            var $id = $(this).attr('id'),
                $str = $(this).parents('.editArea:first').find('input:first').val(),
                $temp = $(this);
            $.post('ajax_photo_edit.php', {id: $id, str: $str}, function($res) {
                $('#loader').html($res);
                $temp.next().trigger('click');
                if ($res == '編輯成功') {
                    $temp.parents('li:first').find('.textArea').find('span').html($str);
                }
                drama.hideModal('');
            });
            return false;
        });
    });
    
    // 取消按鈕
    $('a[name="btnCancel"]').each(function() {
        $(this).click(function() {
            $(this).parents('li:first').find('.editArea').hide();
            $(this).parents('li:first').find('.textArea').show()
            return false;
        });
    });
    
    // 編輯按鈕
    $('a.edit').each(function() {
        $(this).click(function() {
            $(this).parents('li:first').find('.editArea').show();
            $(this).parents('li:first').find('.textArea').hide()
            return false;
        });
    });
    
    // 顏色相間
    $('#movable > li:odd').addClass('gray');
    
    // 列表篩選按鈕
    $('a.abtn1').click(function() {
        var $pm = $('#photoMax option:selected').val(),
            $url = 'photoList.php?albumid=' + $albumid;
                   
        $.post($url, {filterSet: 1, pm: $pm}, function() {
            window.location = $url;
        });
        return false;
    });
    
    // 排序
    $('#movable').sortable({
        change: function() {
            $('a.save').fadeIn();
        },
        stop: function() {
            $('#movable > li')
                .removeClass('gray')
                .filter(':odd')
                .addClass('gray');
        }
    });
    
    // 儲存排序按鈕
    $('a.save').click(function() {
        drama.showModal('儲存中');
        $.post('ajax_photo_sort.php', $('#movable').sortable('serialize') + '&albumid=' + $albumid + '&pageNum_RecPhotos=' + $('#nowPage').val(), function($res) {
            $('#loader').html($res);
            $('a.save').fadeOut();
            drama.hideModal('');
        });
        return false;
    });
}

drama.linkListInit = function($mid) {
    drama.pager();
    drama.selectAll();
    drama.funcDel('link');
    drama.funcOn('link');
    
    // 排序
    $('#movable').sortable({
        change: function() {
            $('a.save').fadeIn();
        },
        stop: function() {
            $('#movable > li')
                .removeClass('gray')
                .filter(':odd')
                .addClass('gray');
        }
    });
    
    // 儲存排序按鈕
    $('a.save').click(function() {
        drama.showModal('儲存中');
        $.post('ajax_link_sort.php', $('#movable').sortable('serialize') + '&pageNum_RecAlbum=' + $('#nowPage').val(), function($res) {
            $('#loader').html($res);
            $('a.save').fadeOut();
            drama.hideModal('');
        });
        return false;
    });
    
    // 顏色相間
    $('#movable > li:odd').addClass('gray');
    
    // 列表篩選按鈕
    $('a.abtn1').click(function() {
        var $lm = $('#linkMax option:selected').val(),
            $url = 'linkList.php';
        
        $.post($url, {filterSet: 1, lm: $lm}, function() {
            window.location = $url;
        });
        return false;
    });
    
    // 編輯按鈕
    $('a.edit').each(function() {
        $(this).click(function() {
            $(this).parents('ul:first').next().slideToggle();
            return false;
        });
    });
    
    // 儲存按鈕
    $('a.editBtn').each(function() {
        $(this).click(function() {
            var $title = $(this).parents('ul:first').find('input[name="editTitle"]').val(),
                $url = $(this).parents('ul:first').find('input[name="editUrl"]').val(),
                $contents = $(this).parents('ul:first').find('input[name="editContents"]').val(),
                $id = $(this).attr('id'),
                $temp = $(this).parents('ul:first');
                
            if ($title == '') {
                alert('請輸入網站標題');
                return false;
            }
            if ($url == '') {
                alert('請輸入網址');
                return false;
            }
            if ($contents == '') {
                alert('請輸入網站說明');
                return false;
            }
            
            drama.showModal('');
            $.post('ajax_link_upd.php', {id: $id, title: $title, url: $url, contents: $contents}, function($res) {
                $('#loader').html($res);
                drama.hideModal('');
                $temp.slideUp();
            });
                        
            return false;
        });
    });
    
    // 表單驗證
    $('#linkForm').validate({
        rules: {
            title: 'required',
            contents: 'required',
            img: 'required',
            url: {
                required: true,
                url: true
            }
        },
        messages: {
            title: {
                required: '請輸入網站標題'
            },
            contents: {
                required: '請輸入網站說明'
            },
            img: {
                required: '請上傳圖片'
            },
            url: {
                required: '請輸入網址',
                url: '請輸入正確格式'
            }
        },
        errorPlacement: function(error, element) {
            element.parent().after(error);
        },
        submitHandler: function() {
            drama.showModal('');
            var $title = $('#title').val(),
                $contents = $('#contents').val(),
                $url = $('#url').val(),
                $img = $('#img').val();
            $.post('ajax_link_add.php', {title: $title, contents: $contents, url: $url, img: $img}, function($res) {
                $('#loader').html($res);
                drama.hideModal('');
                if ($res == '新增成功') {
                    window.location.reload();
                }
            });
        }
    });
    
    // 新增按鈕
    $('a.addBtn').click(function() {
        $('#linkForm').submit();
        return false;
    });
    
    // 圖片上傳
    $('#myFile').uploadify({
        scriptData: {mid: $mid},
        multi: true,
        method: 'post',
        auto: true,
        fileDesc: '只能選用jpg或gif',
        fileExt: '*.jpg;*.gif',
        script: 'ajax_link_upload.php',
        buttonImg: 'images/account/uploadBtn.gif',
        rollover: true,
        onComplete: function(ev, qu, fi, res) {
            drama.hideModal('1500');
            if (res.indexOf('.') != -1) {
                $('#imgBox').html('<img src="uploads/link/' + res + '" />');
                $('#img').val(res);
            } else {
                alert('上傳失敗');
            }
            return false;
        },
        onProgress: function() {
            drama.showModal('上傳中');
        },
        onSelect: function() {
            return false;
        }
    });
}

drama.goodNewInit = function($mid) {
    // 取消按鈕
    $('a#btnCancel').click(function() {
        window.history.back();
        return false;
    });
    
    // 表單驗證
    $('#formGood').validate({
        rules: {
            title: 'required',
            url: {
                required: true,
                url: true
            },
            img: 'required',
            contents: 'required'
        },
        messages: {
            title: {
                required: '請輸入標題'
            },
            url: {
                required: '請輸入引用網址',
                url: '請輸入正確格式'
            },
            img: {
                required: '請上傳圖片'
            },
            contents: {
                required: '請輸入說明內容'
            }
        },
        errorPlacement: function(error, element) {
            error.appendTo(element.parents("td:first"));
        }
    });
    
    // 送出按鈕
    $('#btnSubmit').click(function() {
        $('#formGood').submit();
        return false;
    });
    
    // 圖片上傳
    $('#myFile').uploadify({
        scriptData: {mid: $mid, type: 1},
        multi: true,
        method: 'post',
        auto: true,
        fileDesc: '只能選用jpg或gif',
        fileExt: '*.jpg;*.gif',
        script: 'ajax_good_upload.php',
        buttonImg: 'images/account/uploadBtn.gif',
        rollover: true,
        onComplete: function(ev, qu, fi, res) {
            drama.hideModal('1500');
            if (res.indexOf('.') != -1) {
                $('#imgBox').html('<img src="uploads/good/' + res + '" />');
                $('#img').val(res);
            } else {
                alert('上傳失敗');
            }
            return false;
        },
        onProgress: function() {
            drama.showModal('上傳中');
        },
        onSelect: function() {
            return false;
        }
    });
}

drama.goodListInit = function() {
    drama.pager();
    drama.selectAll();
    drama.funcDel('good');
    drama.funcOn('good');
    
    // 顏色相間
    $('ul.listStyle > li')
        .not('.listTitle')
        .filter(':odd')
        .addClass('gray');
    
    // 列表篩選按鈕
    $('a.abtn1').click(function() {
        var $gm = $('#goodMax option:selected').val(),
            $url = 'goodList.php';
        
        $.post($url, {filterSet: 1, gm: $gm}, function() {
            window.location = $url;
        });
        return false;
    });
}

drama.messageInit = function() {
    drama.pager();
    drama.selectAll();
    drama.funcDel('board');
    drama.funcOn('board');
    
    // 回覆按鈕
    $('a[name="btnReply"]').each(function() {
        $(this).click(function() {
            $(this).parents('.notReply:first').hide();
            $(this).parents('td:first').find('.replyBox').show();
            return false;
        });
    });
    
    // 編輯按鈕
    $('a.edit').each(function() {
       $(this).click(function() {
           $(this).parents('.replyText:first').hide();
           $(this).parents('td:first').find('.replyBox').show();
           return false;
       });
    });
    
    // 取消按鈕
    $('a[name="btnCancel"]').each(function() {
        $(this).click(function() {
            $(this).parent().hide();
            $(this).parents('td:first').find('.replyText').show();
            $(this).parents('td:first').find('.notReply').show();
            return false;
        });
    });
    
    // 儲存按鈕
    $('a[name="btnSave"]').each(function() {
        $(this).click(function() {
            var $id = $(this).attr('id'),
                $contents = $(this).prevAll('div.inputArea:first').find('textarea').val();
            drama.showModal('');
            $.post('ajax_board_reply.php', {id: $id, contents: $contents}, function() {
                window.location.reload();
            });
            return false;
        });
    });
    
    // 顏色相間
    $('#commentList tr:gt(0)')
        .filter(':odd')
        .addClass('gray');
        
    // 列表篩選按鈕
    $('a.abtn1').click(function() {
        var $mm = $('#messageMax option:selected').val(),
            $st = $('#messageStatus option:selected').val();
        $.post('message.php', {filterSet: 1, mm: $mm, st: $st}, function() {
            window.location = 'message.php';
        });
        return false;
    });
}

drama.familyListInit = function() {
    drama.pager();
    drama.selectAll();
    drama.funcDel('family');
    drama.funcTop('family');
    drama.funcOn('family');
    
    // 相間顏色
    $('ul.listStyle > li')
        .not('.listTitle')
        .not('.noData')
        .filter(':odd')
        .addClass('gray');
    
    // 列表篩選按鈕
    $('a.abtn1').click(function() {
        var $fm = $('#familyMax option:selected').val();
        $.post('familyList.php', {filterSet: 1, fm: $fm}, function() {
            window.location = 'familyList.php';
        });
        return false;
    });
}

drama.familyNewInit = function() {
    // 表單驗證
    $('#formFamily').validate({
        rules: {
            title: 'required',
            publish_date: 'required',
            top: 'required'
        },
        messages: {
            title: {
                required: '請輸入訊息標題'
            },
            publish_date: {
                required: '請選擇日期'
            },
            top: {
                required: '請選擇是否置頂'
            }
        },
        errorPlacement: function(error, element) {
            error.appendTo(element.parents("td:first"));
        }
    });
    
    $('#date').datepicker({
        prevText: '上個月',
        nextText: '下個月',
        dateFormat: 'yy-mm-dd'
    });
    
    // 儲存按鈕
    $('a#btnSave').click(function() {
        $('#formFamily').submit();
        return false;
    });
    
    // 編輯器
    $('#message').fck({
        path: 'fckeditor/',
        toolbar: 'Basic',
        width: 935,
        height: 270
    });
}

drama.shareInit = function() {
    // 儲存facebook按鈕
    $('a#btnSaveFacebook').click(function() {
        drama.showModal('');
        var $fbUrl = $('#facebook_url').val(),
            $fbSc = $('#facebook_sorcecode').val();
        $.post('ajax_share_save.php', {type: 1, fbUrl: $fbUrl, fbSc: $fbSc}, function($res) {
            $('#loader').html($res);
            drama.hideModal('');
        });
        return false;
    });
    
    // 儲存plurk按鈕
    $('a#btnSavePlurk').click(function() {
        drama.showModal('');
        var $plurkUrl = $('#plurk_url').val(),
            $plurkSc = $('#plurk_sorucecode').val();
        $.post('ajax_share_save.php', {type: 2, plurkUrl: $plurkUrl, plurkSc: $plurkSc}, function($res) {
            $('#loader').html($res);
            drama.hideModal('');
        });
        return false;
    });
    
    // 取消按鈕
    $('a#btnCancel').click(function() {
        window.history.back();
        return false;
    });
}

drama.memberProfileInit = function() {
     $.validator.addMethod("engOnly", function(value, element) {
         var $re = /^[a-zA-Z0-9]+$/;
         return this.optional(element) || $re.test(value);
    }, "請輸入正確的格式");
    
    // 還原核取方塊
    var $ck = $('#camera_kind').val().split(','),
        $ft = $('#favorite_topic').val().split(','),
        $ic = $('#interest_class').val().split(',');
    
    $('input[name="camera_kind_arr"]').each(function() {
        if (drama.inArray($(this).val(), $ck)) $(this).attr('checked', true);
    });
    $('input[name="favorite_topic_arr"]').each(function() {
        if (drama.inArray($(this).val(), $ft)) $(this).attr('checked', true);
    });
    $('input[name="interest_class_arr"]').each(function() {
        if (drama.inArray($(this).val(), $ic)) $(this).attr('checked', true);
    });
    
    // 表單驗證
    $('#memberForm').validate({
        rules: {
			realname: {
				required: true
			},
            password: {
                required: true,
                rangelength: [4,15],
                engOnly: true
            },
            confirm: {
                equalTo: '#password'
            },
            nickname: 'required',
            ident: 'required',
            ident_type: 'required',
            phone_area: 'required',
            phone: 'required'
        },
         messages: {
			realname: {
				required: '請填寫真實姓名'
			},
            password: {
                required: '英文及數字，4-15字以內',
                rangelength: '請輸入正確長度'
            },
            confirm: {
                equalTo: '密碼不相符'
            },
            nickname: {
                required: '請輸入暱稱'
            },
            ident: {
                required: '請填寫身份證號'
            },
            ident_type: {
                required: '請選擇身份類型'
            },
            phone_area: {
                required: '請填寫聯絡電話區碼'
            },
            phone: {
                required: '請填寫聯絡電話'
            }
        },
        errorPlacement: function(error, element) {
            error.appendTo(element.parents("td:first"));
        }
    });
    
    
    $('a.btnSave').click(function() {
        var $camera_kind_str = '',
            $favorite_topic_str = '',
            $interest_class_str = '';
        
        // 組合您擁有的相機類型
        $('input[name="camera_kind_arr"]').each(function() {
            if ($(this).is(':checked')) $camera_kind_str += $(this).val() + ',';
        });
        $('#camera_kind').val($camera_kind_str.substring(0, $camera_kind_str.length - 1));
        
        // 組合您最喜愛的拍照題材
        $('input[name="favorite_topic_arr"]').each(function() {
            if ($(this).is(':checked')) $favorite_topic_str += $(this).val() + ',';
        });
        $('#favorite_topic').val($favorite_topic_str.substring(0, $favorite_topic_str.length - 1));
        
        // 組合您會有興趣的攝影課程類型
        $('input[name="interest_class_arr"]').each(function() {
            if ($(this).is(':checked')) $interest_class_str += $(this).val() + ',';
        });
        $('#interest_class').val($interest_class_str.substring(0, $interest_class_str.length - 1));
        
        $('#memberForm').submit();
        return false;
    });
    
    // 取消按鈕
    $('a.btnCancel').click(function() {
        window.history.back();
        return false;
    });
}

drama.albumListInit = function() {
    drama.pager();
    drama.selectAll();
    drama.funcDel('album');
    drama.funcOn('album');
    drama.funcTop('album');
    
    // 顏色相間
    $('#movable > li:odd').addClass('gray');
    
    // 列表篩選按鈕
    $('a.abtn1').click(function() {
        var $am = $('#albumMax option:selected').val(),
            $ac = $('#albumCate option:selected').val(),
            $asc = $('#albumSubCate option:selected').val();
        $.post('albumList.php', {filterSet: 1, am: $am, ac: $ac, asc: $asc}, function() {
            window.location = 'albumList.php';
        });
        return false;
    });
    
    // 排序
    $('#movable').sortable({
        change: function() {
            $('a.save').fadeIn();
        },
        stop: function() {
            $('#movable > li')
                .removeClass('gray')
                .filter(':odd')
                .addClass('gray');
        }
    });
    
    // 儲存排序按鈕
    $('a.save').click(function() {
        drama.showModal('儲存中');
        $.post('ajax_album_sort.php', $('#movable').sortable('serialize') + '&pageNum_RecAlbum=' + $('#nowPage').val(), function($res) {
            $('#loader').html($res);
            $('a.save').fadeOut();
            drama.hideModal('');
        });
        return false;
    });
}

drama.albumNewInit = function($detail) {
    albumLoad();
    
    var $tbl = $('#addalbumTable');
    $('tr', $tbl)
        .slice(5, 13)
            .hide();
   
    // 設定切換按鈕
    $('#btnSetting')
        .data('setting', 'basic')
        .click(function() {
            
            switch ($(this).data('setting')) {
                case 'basic':
                    // 基本設定
                    $(this)
                        .html('基本設定')
                        .data('setting', 'more');
                    $('tr', $tbl)
                        .slice(5, 13)
                            .show();
                    break;
                case 'more':
                    // 更多設定
                    $(this)
                        .html('更多設定')
                        .data('setting', 'basic');
                    $('tr', $tbl)
                        .slice(5, 13)
                            .hide();
                    break;
            }
            return false;
        });
		
	// 判斷是否為編輯細節
	if ($detail != '') $('#btnSetting').trigger('click');
    
    // 相機管理按鈕
    $('#btnAddCameraPop').click(function() {
        albumLoad();
        $.blockUI({
            message: $('.cameraBlock'),
            css: {
                width: 410,
                left: ($(window).width() - 410) / 2,
                top: ($(window).height() - 336) / 2,
                cursor: 'default',
                border: 0
            },
            overlayCSS: {
                cursor: 'default'
            }
        });
        return false;
    });
       
    // 鏡頭管理按鈕
    $('#btnAddLensPop').click(function() {
        albumLoad();
        $.blockUI({
            message: $('.lensBlock'),
            css: {
                width: 570,
                left: ($(window).width() - 570) / 2,
                top: ($(window).height() - 336) / 2,
                cursor: 'default',
                border: 0
            },
            overlayCSS: {
                cursor: 'default'
            }
        });
        return false;
    });
    
    // 相機廠牌與型號確認按鈕
    $('.cameraBlock .confirm').click(function() {
        var $chk = $(this).parent().find('input[type="radio"]:checked'),
            $cb = $chk.parents('tr:first').find('td').eq(1).html(),
            $c = $chk.parents('tr:first').find('td').eq(2).html();
            
            if ($cb != null) {
                $('#cameraBrand').val($cb);
                $('#camera').val($c);
            }
            
            $.unblockUI();
        return false;
    });
    
    // 鏡頭廠牌與型號確認按鈕
    $('.lensBlock .confirm').click(function() {
        var $chk = $(this).parent().find('input[type="radio"]:checked'),
            $cb = $chk.parents('tr:first').find('td').eq(1).html(),
            $c = $chk.parents('tr:first').find('td').eq(2).html();
            
            if ($cb != null) {
                $('#lensBrand').val($cb);
                $('#lens').val($c);
            }
            
            $.unblockUI();
        return false;
    });
    
    // 關閉popup按鈕
    $('.close').each(function() {
        $(this).click(function() {
            $.unblockUI();
            return false;
        });
    });
    
    // 新增相機按鈕
    $('a#btnAddCamera').click(function() {
        var $brand = $('#cameraBrandSel option:selected').text(),
            $model = $('#cameraSel option:selected').text();
            
        $.post('ajax_album_insert_info.php', {ins: 1, brand: $brand, model: $model, type: 1}, function() {
            albumLoad();
        });
        return false;
    });
    
    // 新增鏡頭按鈕
    $('a#btnAddLens').click(function() {
        var $brand = $('#lensBrandSel option:selected').text(),
            $model = $('#lensSel option:selected').text();
            
        $.post('ajax_album_insert_info.php', {ins: 1, brand: $brand, model: $model, type: 2}, function() {
            albumLoad();
        });
        return false;
    });
    
    // 載入紀錄資訊
    function albumLoad() {
        $.post('ajax_album_load_camera_lens.php', {albumType: 1}, function($res) {
            $('div#cameraData').html($($res).filter('#res').html());

            // 刪除相機按鈕
            $('a[name="btnCameraDel"]').each(function() {
                $(this).click(function() {
                    var $id = $(this).attr('id'),
                        $tempCamera = $(this).parents('tr:first');
                    $.post('ajax_album_insert_info.php', {del: 1, id: $id}, function() {
                        $tempCamera.fadeOut('normal');
                    });
                    return false;
                });
            });
        });
        $.post('ajax_album_load_camera_lens.php', {albumType: 2}, function($res) {
            $('div#lensData').html($($res).filter('#res').html());

            // 刪除鏡頭按鈕
            $('a[name="btnLensDel"]').each(function() {
                $(this).click(function() {
                    var $id = $(this).attr('id'),
                        $tempLens = $(this).parents('tr:first');
                    $.post('ajax_album_insert_info.php', {del: 1, id: $id}, function() {
                        $tempLens.fadeOut('normal');
                    });
                    return false;
                });
            });
        });
    }
    
    // 編輯器
    $('#contents').fck({
        path: 'fckeditor/',
        toolbar: 'Basic',
        width: 398,
        height: 240
    });
    
    $.validator.addMethod("latlng", function(value, element) {
         var $re = /^[0-9]+\.+[0-9]+$/;
         return this.optional(element) || $re.test(value);
    }, "請輸入正確的經緯度格式");
    
    // 驗證
    $('#formAlbum').validate({
        rules: {
            name: 'required',
            lng: {
                latlng: true
            },
            lat: {
                latlng: true
            },
            on: 'required',
            lock: 'required'
        },
        messages: {
            name: {
                required: '請輸入相簿標題'
            },
            on: {
                required: '請選擇上下架'
            },
            lock: {
                required: '請選擇是否開放下載'
            }
        },
        errorPlacement: function(error, element) {
            error.appendTo(element.parents("td:first"));
        }
    });
    
    // 新增相簿按鈕
    $('a#btnSubmit').click(function() {
        $('#url').val(1);
        $('#formAlbum').submit();
        return false;
    });
    $('a#btnSubmit2').click(function() {
        $('#url').val(2);
        $('#formAlbum').submit();
        return false;
    });
    
    // 取消按鈕
    $('a#btnCancel').click(function() {
        window.history.back();
        return false;
    });
}

drama.aboutInit = function($id) {
    // 儲存按鈕
    $('a#btnSave').click(function() {
        if (confirm('確定要儲存嗎？')) {
            $('#formAbout').submit();
        }
        return false;
    });
    
    // 取消按鈕
    $('a#btnCancel').click(function() {
        window.history.back();
        return false;
    });
    
    // 編輯器
    $('#info').fck({
        path: 'fckeditor/',
        toolbar: 'Basic',
        width: 585,
        height: 330
    });
    
    // 初始上傳
    $('#myFile').uploadify({
        scriptData: {id: $id},
        multi: false,
        method: 'post',
        auto: true,
        fileDesc: '只能選用jpg或gif',
        fileExt: '*.jpg;*.gif',
        script: 'upload_portrait.php',
        buttonImg: 'images/account/uploadBtn.gif',
        rollover: true,
        onComplete: function(ev, qu, fi, res) {
            $('#loader').html(res);
            drama.hideModal('1500');
            if (res == '上傳成功') {
                $.post('ajax_load_portrait.php', '', function($res) {
                    $('div#aboutBox').html($($res).filter('#res').html());
                });
            }
            return false;
        },
        onProgress: function() {
            drama.showModal('上傳中');
        },
        onSelect: function() {
            return false;
        }
    });
}

drama.memberInit = function() {
        var $usn = $('#username'),
            $pass = $('#password'),
            $usnCheck = $('#usernameCheck'),
            $identCheck = $('#identCheck'),
            $emailCheck = $('#emailCheck'),
            $activeMail = $('#activeMail');
    
    $emailCheck.dramaClickClear('請輸入註冊時使用的電子信箱');
    $activeMail.dramaClickClear('請輸入註冊時使用的電子信箱');
    
/*    $.getScript('js/jquery.hotkeys-0.7.9.min.js', function() {
        $('#loginIn input')
            .focus(function() {
                $(document).bind('keydown', 'return', function() {
                    $('a#btnLogin').trigger('click');
                });
            })
            .blur(function() {
                $(document).unbind('keydown', 'return');
            });
    });
    
    $.getScript('js/jquery.hotkeys-0.7.9.min.js', function() {
        $('#pwIn input')
            .focus(function() {
                $(document).bind('keydown', 'return', function() {
                    $('a#btnLogin').trigger('click');
                });
            })
            .blur(function() {
                $(document).unbind('keydown', 'return');
            });
    });*/
    
    // 補寄認證信
    $('#btnActiveMail').click(function() {
        if ($activeMail.val() == '' || $activeMail.val() == '請輸入註冊時使用的電子信箱') {
            alert('請輸入Email');
            $activeMail.focus();
        } else {
            drama.showModal('處理中…');
            $.post('ajax_send_active_mail.php', {mail: $activeMail.val()}, function($res) {
                $('#loader').html($res);
                drama.hideModal(1500);
            })
        }
        return false;
    });
    
    // 查詢按鈕
    $('#btnCheck').click(function() {
        if ($usnCheck.val() == '' && $identCheck.val() == '') {
            alert('會員帳號或身份證字號請擇一輸入');
            return false;
        }
        if ($emailCheck.val() == '請輸入註冊時使用的電子信箱' || $emailCheck.val() == '') {
            alert('請輸入正確的Email');
            return false;
        }
        drama.showModal('');
        $.post('ajax_send_password.php', {usn: $usnCheck.val(), ident: $identCheck.val(), email: $emailCheck.val()}, function($res) {
            $('#loader').html($res);
            drama.hideModal(1500);
        });
        return false;
    });
    
    // 登入按鈕
    $('#btnLogin').click(function() {

        if ($usn.val() == '') {
            alert('請輸入帳號');
            $usn.focus();
            return false;
        }
        if ($pass.val() == '') {
            alert('請輸入密碼');
            $pass.focus();
            return false;
        }
        $('#formLogin').submit();
        return false;
    });
}

drama.joinInit = function() {
    // 還原核取方塊
    var $ck = $('#camera_kind').val().split(','),
        $ft = $('#favorite_topic').val().split(','),
        $ic = $('#interest_class').val().split(',');
    
    $('input[name="camera_kind_arr"]').each(function() {
        if (drama.inArray($(this).val(), $ck)) $(this).attr('checked', true);
    });
    $('input[name="favorite_topic_arr"]').each(function() {
        if (drama.inArray($(this).val(), $ft)) $(this).attr('checked', true);
    });
    $('input[name="interest_class_arr"]').each(function() {
        if (drama.inArray($(this).val(), $ic)) $(this).attr('checked', true);
    }); 
    
    $.validator.addMethod("engOnly", function(value, element) {
         var $re = /^[a-zA-Z0-9]+$/;
         return this.optional(element) || $re.test(value);
    }, "請輸入正確的格式");
    
    // 取消按鈕
    $('a.btnCancel').bind('click', function() {
        window.history.back(); // 按下後回上一頁
        return false;
    });
    
    // 檢查帳號按鈕
    $('#btnCheckAccount').click(function() {
        $usn = $('#username').val();
        if ($usn == '') {
            alert('尚未輸入帳號');
        } else {
            drama.showModal('');
            $.post('ajax_check_account.php', {usn: $usn}, function($data) {
                var $res = '';
                if ($data == '0') $res = '此帳號可使用'; else $res = '此帳號已有人使用';
                $('#loader').html($res);
                drama.hideModal(1500);
            });
        }
        return false;
    });
    
    // 表單驗證
    $('#memberForm').validate({
        rules: {
            username: {
                required: true,
                rangelength: [4,15],
                engOnly: true
            },
            password: {
                required: true,
                rangelength: [4,15],
                engOnly: true
            },
            confirm: {
                equalTo: '#password'
            },
            nickname: 'required',
            email: {
                required: true,
                email: true
            },
            realname: 'required',
            gender: 'required',
            ident: 'required',
            ident_type: 'required',
            phone_area: 'required',
            phone: 'required'
        },
         messages: {
            username: {
                required: '必須為4-15英文及數字組成，完成後無法修改。',
                rangelength: '請輸入正確長度'
            },
            password: {
                required: '英文及數字，4-15字以內',
                rangelength: '請輸入正確長度'
            },
            confirm: {
                equalTo: '密碼不相符'
            },
            nickname: {
                required: '請輸入暱稱'
            },
            email: {
                required: '請輸入Email',
                email: '請輸入正確格式'
            },
            realname: {
                required: '請輸入姓名'
            },
            gender: {
                required: '請選擇性別'
            },
            ident: {
                required: '請填寫身份證號'
            },
            ident_type: {
                required: '請選擇身份類型'
            },
            phone_area: {
                required: '請填寫聯絡電話區碼'
            },
            phone: {
                required: '請填寫聯絡電話'
            }
        },
        errorPlacement: function(error, element) {
            error.appendTo(element.parents("td:first"));
        }
    });
    $('a.btnJoin').click(function() {
        var $camera_kind_str = '',
            $favorite_topic_str = '',
            $interest_class_str = '';
        
        // 組合您擁有的相機類型
        $('input[name="camera_kind_arr"]').each(function() {
            if ($(this).is(':checked')) $camera_kind_str += $(this).val() + ',';
        });
        $('#camera_kind').val($camera_kind_str.substring(0, $camera_kind_str.length - 1));
        
        // 組合您最喜愛的拍照題材
        $('input[name="favorite_topic_arr"]').each(function() {
            if ($(this).is(':checked')) $favorite_topic_str += $(this).val() + ',';
        });
        $('#favorite_topic').val($favorite_topic_str.substring(0, $favorite_topic_str.length - 1));
        
        // 組合您會有興趣的攝影課程類型
        $('input[name="interest_class_arr"]').each(function() {
            if ($(this).is(':checked')) $interest_class_str += $(this).val() + ',';
        });
        $('#interest_class').val($interest_class_str.substring(0, $interest_class_str.length - 1));
        
        $('#memberForm').submit();
        return false;
    });
}

drama.about_meInit = function() {
    drama.urlChangeColor();
}

drama.news_listInit = function() {
    drama.urlChangeColor();
}

// 加入家族功能
drama.addFamily = function($mid) {
    drama.showModal('加入家族中…');
    $.post('ajax_add_family.php', {mid: $mid}, function($res) {
        if ($res.err != '') {
            drama.showModal($res.err);
        } else {
            drama.showModal($res.msg);
        }
        drama.hideModal('');
    }, 'json');
}

drama.familynews_listInit = function($mid) {
    // 加入粉絲按鈕
    $('#btnAddFamily').click(function() {
        drama.addFamily($mid);
        return false;
    });
    
    drama.urlChangeColor();
}

drama.familynews_contentInit = function($mid) {
    // 加入粉絲按鈕
    $('#btnAddFamily').click(function() {
        drama.addFamily($mid);
        return false;
    });
	
    var $frm = $('#messageForm');
	
    // 版主回覆按鈕
    $('a[name="btnReply"]').each(function() {
        $(this).click(function() {
            $(this).prev().slideDown();
            $(this).hide();
            return false;
        });
    });
	
    // 版主編輯內容按鈕
    $('a[name="btnEdit"]').each(function() {
        $(this).click(function() {
			$(this).hide();
            $(this).parent().next().slideDown();
            return false;
        });
    });
    
    // 版主取消按鈕
    $('a[name="btnCancel"]').each(function() {
		$(this).click(function() {
			$(this)
				.parents('li:first')
					.find('.editArea')
						.slideUp()
				.end()
					.find('a[name="btnEdit"], a[name="btnReply"]')
						.show();
			return false;
		});
    });
	
	// 版主送出按鈕
    $('a[name="btnReplySubmit"]').each(function() {
        $(this).click(function() {
            var $id = $(this).attr('id'),
                $contents = $(this).prevAll('div.inputArea:first').find('textarea').val(),
				$secret = $(this).parents('li:first').find('input[name="editScecret"]').is(':checked') ? 1 : 0;		
				
            drama.showModal('');
            $.post('ajax_family_board_reply.php', {id: $id, contents: $contents, secret: $secret}, function($res) {
				if ($res.err == '') {
					drama.showModal($res.msg);
					$(document).oneTime(1500, function() {
						window.location.reload();
					});
				} else {
					drama.showModal($res.err);
					drama.hideModal('');
				}
            }, 'json');
            return false;
        });

    });
              
    // 表單驗證
    $frm.validate({
        rules: {
            captcha: {
                required: true,
                digits: true,
                rangelength: [4, 4]
            },
            contents: 'required'
        },
        messages: {
            captcha: {
                required: '請輸入驗證碼',
                digits: '請輸入正確格式',
                rangelength: '請輸入正確格式'
            },
            contents: {
                required: '請輸入內容'
            }

        },
         errorPlacement: function(error, element) {
            error.appendTo(element.parents("li:first"));
        }
    });
	
    // 重新取得驗證碼
    $('a.refresh').click(function() {
        drama.showModal('');
        $.post('ajax_reload_captcha.php', '', function($res) {
            drama.hideModal();
            $('div#captcha').html($res);
        });
        return false;
    });
    
    // 留言板送出按鈕
    $('a#btnSubmit').click(function() {
        $frm.submit();
        return false;
    });
    
    // 留言板重填按鈕
    $('a#btnRest').click(function() {
        $('input, textarea', $frm).val('');
        return false;
    });
    
    // 顏色相間
    $('#comment > li:even').addClass('gray');
	
	// Ajax分頁
	drama.pager();
    
    drama.urlChangeColor();
}

drama.class_listInit = function() {
    drama.urlChangeColor();
}

drama.routes_listInit = function() {
    drama.urlChangeColor();
}

drama.news_contentInit = function() {
    drama.urlChangeColor();
}



drama.class_calendarInit = function() {
    drama.urlChangeColor();
}

drama.class_contentInit = function() {
    drama.urlChangeColor();
}

drama.routes_contentInit = function() {
    drama.urlChangeColor();
}

drama.relative_linkInit = function() {
    drama.urlChangeColor();
}

drama.goodthing_listInit = function() {
    drama.urlChangeColor();
}

drama.goodthingInit = function() {
    drama.urlChangeColor();
}

drama.urlChangeColor = function() {
    $.getScript('js/jquery.url.packed.js', function() {
        var $url = $.url.attr('file'),
            $fileArr = $url.split('_'),
            $urlStr = $fileArr[0];

        $.url.attr('query') ? $url += '?' + $.url.attr('query') : '';
        $('ul.subNav li').each(function() {
            if ($(this).find('a').length != 0) {
                 var $href = $(this).find('a').attr('href'),
                $hrefArr = $href.split('_'),
                $hrefStr = $hrefArr[0];
                if ($hrefStr == $urlStr) {
                    // $(this).html('<span>' + $(this).find('a').text() + '</span>');
					$(this).find('a').html('<span>' + $(this).find('a').html() + '</span>');
                }
            }
        });
    });
}

/**
* 擷取字串
*/
drama.cutFont = function($str, $lmt) {
    var $len = $str.length;
    if ($len > $lmt) {
        return $str.substring(0, $lmt) + '...';
    } else {
        return $str;
    }
}

/**
* 檢查陣列值
*/
drama.inArray = function($val, $arr) {
    for (var $v in $arr) {
        if ($arr[$v] == $val) return true;
    }
    return false;
}

/**
* 隱藏訊息
*/
drama.hideModal = function($sec) {
    if ($sec == '') $sec = 2000;
    setTimeout(function() {
        $.unblockUI();
    }, $sec)
}

/**
* 秀訊息
*/
drama.showModal = function($str) {
    var $msg = $str == '' ? '處理中，請稍後...' : $str,
        $html = '<div id="loader"><div id="modalMsg">' + $msg + '</div><img src="images/loader.gif" alt="loader" /></div>';
        $.blockUI({
            message: $html,
            css: {
                border: 'none',
                cursor: 'default'
            },
            overlayCSS: {
                cursor: 'default',
				opacity: 0
            }
        })
}

/**
* 分頁
*/
drama.pager = function() {
    if (!$('div.pager').is('*')) return false;
    var $mover = $('#mover'), // 移動的物件
        $slider = $('.track'); // slider
        $sum = 0,
        $sum2 = 0,
        $index = $('a, span', $mover).index($('span:first', $mover)), // span在超連結中的索引
        $parentWidth = $mover.parent().width(); // 移動的物件母物件寬度
    
    // 計算出外框的寬度
    $('span ,a', $mover).each(function(i) {
        $sum += $(this).outerWidth(true);
    });
    
    // 指定外移動物件外框寬度
    $mover.width($sum + 10);
    
    // slider的最大值
    var $max = $sum - $parentWidth;
    
    if ($('span, a', $mover).size() > 10) {
        // slider起始
        $slider.slider({
            min: 0,
            max: $max,
            slide: function(ev, ui) {
                $mover.css('left', ui.value * -1);
            }
        });
        
        // 計算出預設頁面移動距離
        $('span ,a', $mover).slice(0, $index).each(function() {
            $sum2 += $(this).outerWidth(true);
        });
        // 如果移動的範圍超出最大值時，限制為最大值
        if ($sum2 >= $max) $sum2 = $max;
        
        // 移動移動物件
        $mover.css('left', $sum2 * -1);
        
        // 指定slider的位置
        $slider.slider('value', $sum2);
    } else {
        $('.slider').hide();
    }
}

/**
* 選取全部
* $obj - 選取按鈕
* $all - 被選取者名稱
*/
drama.selectAll = function() {
    $('#selectAll').click(function() {
        $(this).is(':checked') ? $('input[name="idCheck"]').attr('checked', true) : $('input[name="idCheck"]').attr('checked', false);
    });
}

// 多重刪除
drama.funcDel  = function($type) {
    // 單一刪除
    $('a[name="del"]').each(function() {
        $(this).click(function() {
            if (confirm('確定要刪除嗎？')) {
                var $id = $(this).attr('id');
                drama.showModal('');
                $.post('ajax_multi_del.php', {type: $type, id: $id}, function($res) {
                    $('#loader').html($res);
                    drama.hideModal('');
                    if ($res == '刪除成功') {
                        setTimeout(function() {
                            window.location.reload();
                        }, 1500);                       
                    }
                });
            }
            return false;
        });
    });
    
    // 多重刪除
    $('a#btnDelAll').click(function() {
        var $count = $('input[name="idCheck"]:checked').size();
        if ($count == 0) {
            alert('您尚未選取任何項目');
        } else {
            if (confirm('確定要刪除嗎？')) {
                var $arr = new Array();
                $('input[name="idCheck"]:checked').each(function($i) {
                    $arr[$i] = $(this).attr('id');
                });
                var $arrStr = $arr.join(',');
                drama.showModal('');
                $.post('ajax_multi_del.php', {type: $type, id: $arrStr}, function($res) {
                    $('#loader').html($res);
                    drama.hideModal('');
                    if ($res == '刪除成功') {
                        setTimeout(function() {
                            window.location.reload();
                        }, 1500);                       
                    }
                });
            }
        }
        return false;
    });
}

// 更改置頂狀態
drama.funcTop = function($type) {
    // 單一改變狀態
    $('a[name="btnTop"]').click(function() {
        drama.showModal('');
        var $status = $(this).attr('status'),
            $id = $(this).attr('id');
        switch($status) {
            case '0': var $way = 1; break;
            case '1': var $way = 0; break;
        }
        $.post('ajax_func_top.php', {type: $type, way: $way, id: $id}, function() {
            window.location.reload();
        });
        return false;
    });
}

// 更改上架狀態
drama.funcOn = function($type) {  
    // 單一改變狀態
    $('a[name="btnOn"]').each(function() {
        if ($(this).attr('status') == 0) $(this).addClass('off');
        $(this).click(function() {
            drama.showModal('');
            var $status = $(this).attr('status'),
                $id = $(this).attr('id');
            switch($status) {
                case '0': var $way = 1; break;
                case '1': var $way = 0; break;
            }
            $.post('ajax_func_on.php', {type: $type, way: $way, id: $id}, function() {
                window.location.reload();
            });
            return false;
        });
    })
    
    // 全部上架
    $('a#btnAllOn').click(function() {
        var $count = $('input[name="idCheck"]:checked').size();
        if ($count == 0) {
            alert('您尚未選取任何項目');
        } else {
            var $arr = new Array();
            $('input[name="idCheck"]:checked').each(function() {
                $arr.push($(this).attr('id'));
            });
            var $arrStr = $arr.join(',');
            drama.showModal('');
            $.post('ajax_func_on.php', {type: $type, way: 1, id: $arrStr}, function($res) {
                window.location.reload();
            });
        }
        return false;
    });
    
    // 全部下架
    $('a#btnAllDown').click(function() {
        var $count = $('input[name="idCheck"]:checked').size();
        if ($count == 0) {
            alert('您尚未選取任何項目');
        } else {
            var $arr = new Array();
            $('input[name="idCheck"]:checked').each(function() {
                $arr.push($(this).attr('id'));
            });
            var $arrStr = $arr.join(',');
            drama.showModal('');
            $.post('ajax_func_on.php', {type: $type, way: 0, id: $arrStr}, function($res) {
                window.location.reload();
            });
        }
        return false;
    });
}

// 編碼跳脫字元
drama.jsonIn = function($str) {
    return $str.replace(/"/gi, '\\"').replace(/\//gi, '\\/');
}

// 禁按右鍵
drama.contextmenuForbidden = function() {
	$(document).bind('contextmenu', function() {
		return false;
	});
}
