﻿var regu=new Regular();

/** about float **/
window.onload=function(){	
	

	$(".bot2-close a").click(function(){
		$(".modalbox-wrap").hide();
		$("#modalback").hide();
	});
	
	$(".bot-close a").click(function(){
		$(".modalbox-wrap").hide();
		$("#modalback").hide();
	});
	
	$(".modalbox-close a").click(function(){
		$(".modalbox-wrap").hide();
		$("#modalback").hide();
	});
	
	$(".yes button").click(function(){
		$(".modalbox-wrap").hide();
		$("#modalback").hide();
	});
	//if($(".wrapper")[0].id=="params" || $(".wrapper")[0].id=="rules"){$('html,body').animate({scrollTop:472}, 1000);}
}
var showBack=function(){
	$("#modalback").css("height",$(document).height()+"px");
	$(".modalbox-wrap").css("top","50px");
	$(".modalbox-wrap").css("left","50%");
	$(".modalbox-wrap3").css("left","60%");
	$("#modalback").show();
}

var showRegister=function(){
	showBack();
	$("#modalregister").css("margin","100px 0 0 -200px");
	$("#modalregister").show();
}
var showFailure1=function(){
	showBack();
	$("#modalfailure1").css("margin","100px 0 0 -200px");
	$("#modalfailure1").show();
}
var showFailure2=function(){
	showBack();
	$("#modalfailure2").css("margin","100px 0 0 -300px");
	$("#modalfailure2").show();
}
var showproAll=function(){
	showBack();
	$("#proAll").hide();
	$("#proAll").css("margin","100px 0 0 -300px");
	$("#proAll").show();
}
var login=function(){
	showBack();
	$("#modalregister").hide();
	$("#registreturn").css("margin","100px 0 0 -300px");
	$("#registreturn").show();
}
var showDiaocha=function(){
	showBack();
	$("#diaoCha").hide();
	$("#diaoCha").css("margin","100px 0 0 -200px");
	$("#diaoCha").show();
}
var showTry=function(){
	showBack();
	$("#proAll2").hide();
	$("#proAll2").css("margin","100px 0 0 -300px");
	$("#proAll2").show();
}
function AddPhotoReplay(id,name)
{
    if(name==""&&name.length==0)
    {
        alert("您没有登陆，不能发表评论！");
        return;
    }
    var context=$("#txtReplay").val();
    $.ajax({
        url:"/ajax/photo/PhotoPL.ashx",
        type:"POST",
        dateType:"xml",
        data:{photoid:id,Username:name,Content:context},
        success:function(xml){
            $(xml).find("result").each(function(){
                alert($(this).text());
                if($(this).attr("flag")=="1")
                {
                    location.href=location.href;
                }
            });
        },
        error:function()
        {
            alert("错误，请稍后重试！");
        }
    });
}
/** end of float **/


/** about favorite **/
function saveFavorites(blogid) {
    $.ajax({
        url: "/ajax/favorites/Add_Favori.ashx",
        type: "POST",
        dataType: "xml",
        data: { id: blogid, date: new Date() },
        success: function(xml) {
            $(xml).find("result").each(function() {
                alert($(this).text());
            });
        },
        error: function() {
            alert("文件载入错误，请稍后重试！");
        }
    });
}
function deleFavo(favid) {
    $.ajax({
        url: "/ajax/favorites/Delete_Favori.ashx",
        type: "POST",
        dataType: "xml",
        data: { id: favid, date: new Date() },
        success: function(xml) {
            $(xml).find("result").each(function() {
                alert($(this).text());
                if ($(this).attr("flag") == "1") {
                    location.href = location.href;
                }
            });
        },
        error: function() {
            alert("文件载入错误，请稍后重试！");
        }
    });
}
/** end of favorite **/


function checkAddCata(){
    var txtName=$.trim($("#txtName").val());
    if (regu.isEmpty(txtName)){
        alert("请输入目录名称");
        return false;
    }
    return true;    
}
function saveAddCata(){
    if (checkAddCata()){
        var txtName=$.trim($("#txtName").val());
        $("#btnSave").attr("disabled","disabled");
        $.ajax({
            url:"/ajax/blog/addCatalog.ashx",
            type:"POST",
            dataType:"xml",
            data:{txtName:txtName,date:new Date()},
            success:function(xml){
                $(xml).find("result").each(function(){
                    if ($(this).attr("flag")=="1"){
                        location.href=location.href;
                    }else{
                        alert($(this).text());
                    }
                });
                $("#btnSave").attr("disabled","");
            },
            error:function(){
                alert("文件载入错误！");
                $("#btnSave").attr("disabled","");
            }
        })
    }
}
function deleteCata(id){
    if (id>0){
        $.ajax({
            url:"/ajax/blog/deleteCatalog.ashx",
            type:"POST",
            dataType:"xml",
            data:{id:id,date:new Date()},
            success:function(xml){
                $(xml).find("result").each(function(){
                    alert($(this).text());
                    if ($(this).attr("flag")=="1"){
                        location.href=location.href;
                    }
                });
            },
            error:function(){
                alert("文件载入错误！");
            }
        })
    }    
}
function getCata(id){
    if (id>0){
        $.ajax({
            url:"/ajax/blog/getCatalog.ashx",
            type:"GET",
            dataType:"xml",
            data:{id:id,date:new Date()},
            success:function(xml){
                $(xml).find("result").each(function(){
                    if ($(this).attr("flag")=="0"){
                        alert($(this).text());
                    }else{
                        $(this).find("id").each(function(){$("#hidID").val($(this).text());});
                        $(this).find("name").each(function(){$("#txtCatalog").val($(this).text());});
                    }
                });
            },
            error:function(){
                alert("文件载入错误！");
            }
        })
    }
}
function checkEditCata(){
    var hidID=$.trim($("#hidID").val());
    var txtName=$.trim($("#txtCatalog").val());
    if (regu.isEmpty(hidID)){
        alert("请选择要修改的目录");
        return false;
    } else if (hidID=="0"){
        alert("请输入目录名");
        return false;
    } else if (regu.isEmpty(txtName)){
        alert("请输入目录名");
        return false;
    }
    return true;    
}
function saveEditCata(){
    if (checkEditCata()){
        var hidID=$.trim($("#hidID").val());
        var txtName=$.trim($("#txtCatalog").val());
        $.ajax({
            url:"/ajax/blog/addCatalog.ashx",
            type:"POST",
            dataType:"xml",
            data:{id:hidID,txtName:txtName,date:new Date()},
            success:function(xml){
                $(xml).find("result").each(function(){
                    if ($(this).attr("flag")=="1"){
                        location.href=location.href;
                    }else{
                        alert($(this).text());
                    }
                });
            },
            error:function(){
                alert("文件载入错误！");
            }
        })
    }
}
function saveBlog(id){
    if (checkBlog()){        
        $("#btnSave").attr("disabled", "disabled");
        var txtTitle=$("#txtTitle").val();
        var selClass=$.trim($("#selClass").val());
        var txtKeyword=$("#txtKey").val();
        var areaContent=CKEDITOR.instances.areaContent.getData();
        $.ajax({
            url:"/ajax/blog/saveBlogs.ashx",
            type:"POST",
            dataType:"xml",
            data:{id:id,title:txtTitle,blogclass:selClass,keyword:txtKeyword,content:areaContent,date:new Date()},
            success:function(xml){
                $(xml).find("result").each(function(){
                    alert($(this).text());
                    if ($(this).attr("flag")=="1"){
                        location.href="blog-"+$(this).attr("id")+".aspx";                        
                    }
                });
                $("#btnSave").attr("disabled","");        
            },
            error:function(){
                alert("文件载入错误，请稍后重试！");
                $("#btnSave").attr("disabled","");
            }
        });
    }    
}
function checkBlog(){
    var txtTitle=$.trim($("#txtTitle").val());
    var selClass=$.trim($("#selClass").val());
    var txtKey=$.trim($("#txtKey").val());
    var areaContent=$.trim(CKEDITOR.instances.areaContent.getData());
    var reg=new Regular();
    if (reg.isEmpty(txtTitle)){
        alert("请输入标题！");
        return false;
    }else if (reg.isEmpty(selClass)){
        alert("请选择类别！");
        return false;
    }else if (reg.isEmpty(txtKey)){
        alert("请输入关键字！");
        return false;
    }else if (reg.isEmpty(areaContent)){
        alert("请输入博文内容！");
        return false;
    }    
    return true;
}
function saveBlogReply(id){
    if (checkBlogReply()){        
        var content=$.trim($("#replyContent").val());
        $.ajax({
            url:"/ajax/blog/saveBlogReply.ashx",
            type:"POST",
            dataType:"xml",
            data:{blogid:id,content:content,date:new Date()},
            success:function(xml){
                $(xml).find("result").each(function(){
                $("#txtUsername").focus();
                
                    alert($(this).text());
                   
                 
                    if ($(this).attr("flag")=="1"){
                        location.href=location.href;
                    }
                });
                $("#btnReply").attr("disabled","");        
            },
            error:function(){
                alert("文件载入错误，请稍后重试！");
                $("#btnReply").attr("disabled","");
            }
        });
    }    
}
function checkBlogReply(){    
    var content=$.trim($("#replyContent").val());
    var reg=new Regular();
    if (reg.isEmpty(content)){
   
        alert("请输入评论内容！");
        return false;
    }
    return true;
}


function DelBlogReply(id)
{
    $.ajax({
        url:"/ajax/blog/DelBlogReply.ashx",
        type:"POST",
        dataType:"xml",
        data:{repid:id},
        success:function(xml){
            $(xml).find("result").each(function(){
                alert($(this).text());
                if($(this).attr("flag")=="1")
                {
                    location.href=location.href;
                }
            });
        },
        error:function(){
            alert("删除时出现错误，请稍后重试！");
        }
    });
}
function DelBlog(id)
{
    $.ajax({
        url:"/ajax/blog/DelBlog.ashx",
        type:"POST",
        dataType:"xml",
        data:{id:id},
        success:function(xml){
            $(xml).find("result").each(function(){
                alert($(this).text());
                if($(this).attr("flag")==1){
                    location.href=location.href;
                }
            });
        },
        error:function(){
            alert("文件加载错误，请稍后重试！");
        }
    });
}
