function sAlert(str,msgwidth,msgheight){
       var msgw,msgh,bordercolor;
	   if(msgheight == undefined && msgwidth == undefined)
		{
			msgw=800;//提示窗口的宽度
			msgh=700;//提示窗口的高度
		}
		else
		{
				msgw = 	msgwidth;
				msgh = msgheight;
		}
       titleheight=25 //提示窗口标题高度
       bordercolor="#336699";//提示窗口的边框颜色
       titlecolor="#99CCFF";//提示窗口的标题颜色

       window.parent.document.getElementById("indexframe").rows = '0,*';
       var sWidth,sHeight;
       sWidth=document.body.offsetWidth;
       sHeight=screen.height;
       var bgObj=document.createElement("div");
       bgObj.setAttribute('id','bgDiv');
       bgObj.style.position="absolute";
       bgObj.style.top="0";
       bgObj.style.background="#777";
       bgObj.style.filter="progid:DXImageTransform.Microsoft.Alpha(style=3,opacity=25,finishOpacity=75";
       bgObj.style.opacity="0.6";
       bgObj.style.left="0";
       bgObj.style.width=sWidth + "px";
       bgObj.style.height=sHeight + "px";
       bgObj.style.zIndex = "100";
       document.body.appendChild(bgObj);
   
       var msgObj=document.createElement("div")
       msgObj.setAttribute("id","msgDiv");
       msgObj.setAttribute("align","center");
       msgObj.style.background="white";
       msgObj.style.border="1px solid " + bordercolor;
           msgObj.style.position = "absolute";
       msgObj.style.left = "60%";
                  msgObj.style.top = "20%";
                  msgObj.style.font="12px/1.6em Verdana, Geneva, Arial, Helvetica, sans-serif";
                  msgObj.style.marginLeft = "-525px" ;
                  msgObj.style.marginTop = -75+document.documentElement.scrollTop+"px";
                  msgObj.style.width = msgw + "px";
                  msgObj.style.height =msgh + "px";
                  msgObj.style.textAlign = "center";
                  msgObj.style.lineHeight ="25px";
                  msgObj.style.zIndex = "101";
   
         var title=document.createElement("h4");
         title.setAttribute("id","msgTitle");
         title.setAttribute("align","right");
         title.style.margin="0";
         title.style.padding="3px";
         title.style.background=bordercolor;
         title.style.filter="progid:DXImageTransform.Microsoft.Alpha(startX=20, startY=20, finishX=100, finishY=100,style=1,opacity=75,finishOpacity=100);";
         title.style.opacity="0.75";
         title.style.border="1px solid " + bordercolor;
         title.style.height="18px";
         title.style.font="12px Verdana, Geneva, Arial, Helvetica, sans-serif";
         title.style.color="white";
         title.style.cursor="pointer";
         title.innerHTML="关闭";
         title.onclick=function(){
			 window.parent.document.getElementById("indexframe").rows = '150,*';
              document.body.removeChild(bgObj);
                    document.getElementById("msgDiv").removeChild(title);
                    document.body.removeChild(msgObj);
                    }
         document.body.appendChild(msgObj);
         document.getElementById("msgDiv").appendChild(title);
         var txt=document.createElement("div");
         txt.style.margin="1em 0"
         txt.setAttribute("id","msgTxt");
         txt.innerHTML=str;
               document.getElementById("msgDiv").appendChild(txt);
                }

function ajax_form(url,msgwidth,msgheight,fckname)
{
	$.post(url,
		{Action:"POST"},
		function (data)
		{
			sAlert(data,msgwidth,msgheight);
			if(fckname != undefined)
			{
				create_fck_div(fckname);
			}
		}, 
		"html");
}

function action_url(url)
{
	window.location.href=url+$("#action_page").val();
	return false;
}

function ajax_go(url)
{
	$.post(url,{Action:"POST"},function(data){alert(data);window.parent.document.getElementById("indexframe").rows = '150,*';window.location.reload();},"html");
}

function create_fck_div(name)
{
	var sBasePath ='http://'+document.location.host+'/fckeditor/';
	var oFCKeditor = new FCKeditor(name) ;
	oFCKeditor.BasePath	= sBasePath ;
	oFCKeditor.Height	= 440 ;
	oFCKeditor.Width	= 750 ;
	oFCKeditor.Value	= document.getElementById("fckdiv").innerHTML ;
	fckhtml = oFCKeditor.CreateFckDiv();
	document.getElementById("fckdiv").innerHTML=fckhtml;
}



//新建用户
function admin_create_check()
{
	
	var flag = true;
	var admin_name = $("#admin_name").val();
	var real_name = $("#real_name").val();
	var admin_password = $("#admin_password").val();
	if($("#if_question_admin").attr('checked')==undefined)
	{
		var if_question_admin = 0;
	}
	else
	{
		var if_question_admin = $("input[@name='if_question_admin']").attr("value");
	}
	if($("#if_question_admin_del").attr('checked')==undefined)
	{
		var if_question_admin_del = 0;
	}
	else
	{
		var if_question_admin_del = $("input[@name='if_question_admin_del']").attr("value");
	}
	var right_list = '';
	$("input[@name='rights']").each(function()
	{
		if($(this).attr('checked') == undefined)
		{
			
		}
		else
		{
			right_list = right_list + $(this).val() + ',';
		}
	})
	right_list = right_list.replace(/(,*$)/g, "");
	if($("#admin_name").val()!=''&&$("#admin_password").val()!='')
	{

	}
	else
	{
		alert('请输入帐号密码！');
		$("#admin_name").focus();
		flag = false;
	}

	if($("#admin_password").val()!=$("#admin_password_confirm").val())
	{
		alert('请确认密码！');
		$("#admin_password_confirm").focus();
		flag = false;
	}
	
	if($("#real_name").val()== '')
	{
		alert('请填写真实姓名');
		$("#real_name").focus();
		flag = false;
	}
	
	if(flag != false)
	{
	
		$.post("http://"+document.location.host+"/admin/admin_user/create_admin_user_proc",
		{Action:"POST",admin_name:admin_name,admin_password:admin_password,right_list:right_list,real_name:real_name,if_question_admin:if_question_admin,if_question_admin_del:if_question_admin_del},
		function (data)
		{
			if(data[2] == 'success')
			{
				alert(data[0]+data[1]);
			}
			else
			{
				alert(data[0]+data[1]);
			}
			$("#msgTitle").click();
			window.location.reload(); 
		}, 
		"json");
		
	}
}


//编辑用户
function admin_edit_check()
{
	var flag = true;
	var admin_name = $("#admin_name").val();
	var real_name = $("#real_name").val();
	var admin_password = $("#admin_password").val();
	var user_id = $("#user_id").val();
	if($("#if_question_admin").attr('checked')==undefined)
	{
		var if_question_admin = 0;
	}
	else
	{
		var if_question_admin = $("input[@name='if_question_admin']").attr("value");
	}
	if($("#if_question_admin_del").attr('checked')==undefined)
	{
		var if_question_admin_del = 0;
	}
	else
	{
		var if_question_admin_del = $("input[@name='if_question_admin_del']").attr("value");
	}
	var right_list = '';
	$("input[@name='rights']").each(function()
	{
		if($(this).attr('checked') == undefined)
		{
			
		}
		else
		{
			right_list = right_list + $(this).val() + ',';
		}
	})
	right_list = right_list.replace(/(,*$)/g, "");
	
	if($("#admin_name").val()!='')
	{

	}
	else
	{
		alert('用户名不能为空！');
		$("#admin_name").focus();
		flag = false;
	}

	if($("#admin_password").val() != '' && $("#admin_password").val()!=$("#admin_password_confirm").val())
	{
		alert('请确认密码！');
		$("#admin_password_confirm").focus();
		flag = false;
	}
	
	if($("#real_name").val()== '')
	{
		alert('真实姓名不能为空');
		$("#real_name").focus();
		flag = false;
	}

	if(flag != false)
	{
		$.post("http://"+document.location.host+"/admin/admin_user/edit_admin_user_proc/"+user_id,
		{Action:"POST",user_id:user_id,admin_password:admin_password,right_list:right_list,real_name:real_name,if_question_admin:if_question_admin,if_question_admin_del:if_question_admin_del},
		function (data)
		{
			if(data[2] == 'success')
			{
				alert(data[0]+data[1]);
			}
			else
			{
				alert(data[0]+data[1]);
			}
			$("#msgTitle").click();
			window.location.reload(); 
		}, 
		"json");
	}
}

//修改密码
function admin_modify_pwd_check()
{
	var flag = true;

	var admin_password_old = $("#admin_password_old").val();
	var admin_password_new = $("#admin_password_new").val();
	var admin_password_new_confirm = $("#admin_password_new_confirm").val();
	var user_id = $("#user_id").val();
	
	if( admin_password_old == '' || admin_password_new == '' || admin_password_new_confirm == '')
	{
		alert('密码不能为空！');
		$("#admin_password_new").focus();
		flag = false;
	}
	
	if($("#admin_password_new").val() != $("#admin_password_new_confirm").val())
	{
		alert('请确认密码！');
		$("#admin_password_new_confirm").focus();
		flag = false;
	}
	

	if(flag != false)
	{
		$.post("http://"+document.location.host+"/admin/admin_user/modify_user_pwd_proc/"+user_id,
		{Action:"POST",user_id:user_id,admin_password_old:admin_password_old,admin_password_new:admin_password_new,admin_password_new_confirm:admin_password_new_confirm},
		function (data)
		{
			if(data[2] == 'success')
			{
				alert(data[0]+data[1]);
			}
			else
			{
				alert(data[0]+data[1]);
			}
			window.location = "http://"+document.location.host+"/admin/admin_index/welcome";
		}, 
		"json");
	}
}

//新建新闻
function news_create_check()
{
	
	var flag = true;
	var title = $("#title").val();
	if($("#bflag").attr("checked")==true)
	{
		var bflag = 1;
	}
	else
	{
		var bflag = 0;
	}
	var type_id = $("select[@name=news_type] option[@selected]").val();
	var display_date = $("#display_date").val();
	var news_author = $("#news_author").val();
	var news_content = GetMessageContent("news_content");
	
	if($("#title").val()!='')
	{
		if(/^.{2,40}$/.test(title))
		{

		}
		else
		{
			alert('标题必须在2-40字以内');
			$("#title").focus();
			flag = false;
		}
	}
	else
	{
		alert('请输入标题！');
		$("#title").focus();
		flag = false;
	}


	if(GetMessageLength("news_content")!='0')
	{
	
	}
	else
	{
		alert('请输入内容！');
		$("#news_content").focus();
		flag = false;
	}

	
	if($("#news_author").val()== '')
	{
		alert('请填写发表人');
		$("#news_author").focus();
		flag = false;
	}

	if(flag != false)
	{
	
		$.post("http://"+document.location.host+"/admin/admin_news/create_news_proc",
		{Action:"POST",title:title,type_id:type_id,display_date:display_date,news_author:news_author,news_content:news_content,bflag:bflag},
		function (data)
		{
			if(data[2] == 'success')
			{
				alert(data[0]+data[1]);
			}
			else
			{
				alert(data[0]+data[1]);
			}
			$("#msgTitle").click();
			window.location.reload(); 
		}, 
		"json");
		
	}
}

//编辑新闻
function news_edit_check()
{
	var flag = true;
	var news_id = $("#news_id").val();
	var title = $("#title").val();
	var type_id = $("select[@name=news_type] option[@selected]").val();
	var display_date = $("#display_date").val();
	var news_author = $("#news_author").val();
	var news_content = GetMessageContent("news_content");
	
	if($("#title").val()!='')
	{
		if(/^.{2,40}$/.test(title))
		{

		}
		else
		{
			alert('标题必须在2-40字以内');
			$("#title").focus();
			flag = false;
		}
	}
	else
	{
		alert('请输入标题！');
		$("#title").focus();
		flag = false;
	}

	

	if(GetMessageLength("news_content")!='0')
	{
	
	}
	else
	{
		alert('请输入内容！');
		$("#news_content").focus();
		flag = false;
	}

	
	if($("#news_author").val()== '')
	{
		alert('请填写发表人');
		$("#news_author").focus();
		flag = false;
	}

	if(flag != false)
	{
		$.post("http://"+document.location.host+"/admin/admin_news/edit_news_proc/"+news_id,
		{Action:"POST",news_id:news_id,title:title,type_id:type_id,display_date:display_date,news_author:news_author,news_content:news_content},
		function (data)
		{
			if(data[2] == 'success')
			{
				alert(data[0]+data[1]);
			}
			else
			{
				alert(data[0]+data[1]);
			}
			$("#msgTitle").click();
			window.location.reload(); 
		}, 
		"json");
		
	}
}

//新建经验心得
function experience_create_check()
{
	
	var flag = true;
	var title = $("#title").val();
	var experience_author = $("#experience_author").val();
	var experience_content = GetMessageContent("experience_content");
	
	if($("#title").val()!='')
	{
		if(/^.{2,30}$/.test(title))
		{

		}
		else
		{
			alert('标题必须在2-30字以内');
			$("#title").focus();
			flag = false;
		}
	}
	else
	{
		alert('请输入标题！');
		$("#title").focus();
		flag = false;
	}


	if(GetMessageLength("experience_content")!='0')
	{
	
	}
	else
	{
		alert('请输入内容！');
		$("#experience_content").focus();
		flag = false;
	}

	
	if($("#experience_author").val()== '')
	{
		alert('请填写作者');
		$("#experience_author").focus();
		flag = false;
	}

	if(flag != false)
	{
	
		$.post("http://"+document.location.host+"/admin/admin_experience/create_experience_proc",
		{Action:"POST",title:title,experience_author:experience_author,experience_content:experience_content},
		function (data)
		{
			if(data[2] == 'success')
			{
				alert(data[0]+data[1]);
			}
			else
			{
				alert(data[0]+data[1]);
			}
			$("#msgTitle").click();
			window.location.reload(); 
		}, 
		"json");
		
	}
}

//编辑经验心得
function experience_edit_check()
{
	var flag = true;
	var experience_id = $("#experience_id").val();
	var title = $("#title").val();
	var experience_author = $("#experience_author").val();
	var experience_content = GetMessageContent("experience_content");
	
	if($("#title").val()!='')
	{
		if(/^.{2,30}$/.test(title))
		{

		}
		else
		{
			alert('标题必须在2-30字以内');
			$("#title").focus();
			flag = false;
		}
	}
	else
	{
		alert('请输入标题！');
		$("#title").focus();
		flag = false;
	}

	

	if(GetMessageLength("experience_content")!='0')
	{
	
	}
	else
	{
		alert('请输入内容！');
		$("#experience_content").focus();
		flag = false;
	}

	
	if($("#experience_author").val()== '')
	{
		alert('请填写作者');
		$("#experience_author").focus();
		flag = false;
	}

	if(flag != false)
	{
		$.post("http://"+document.location.host+"/admin/admin_experience/edit_experience_proc/"+experience_id,
		{Action:"POST",experience_id:experience_id,title:title,experience_author:experience_author,experience_content:experience_content},
		function (data)
		{
			if(data[2] == 'success')
			{
				alert(data[0]+data[1]);
			}
			else
			{
				alert(data[0]+data[1]);
			}
			$("#msgTitle").click();
			window.location.reload(); 
		}, 
		"json");
		
	}
}

//新建游戏
function download_create_check()
{
	var flag = true;
	var game_name = $("#game_name").val();
	var type_id = $("select[@name=type_id] option[@selected]").val();
	var userfile = $("#userfile").val();
	var hot_order = $("#hot_order").val();
	var download_url = $("#download_url").val();
	if(game_name == '')
	{
		alert('请填写游戏名称');
		$("#game_name").focus();
		flag = false;
	}
	
	if(flag != false)
	{
		$("#game_create_form").submit();
	}

}

//编辑游戏
function download_edit_check()
{
	var flag = true;
	var game_name = $("#game_name").val();
	var type_id = $("select[@name=type_id] option[@selected]").val();
	var userfile = $("#userfile").val();
	var hot_order = $("#hot_order").val();
	var download_url = $("#download_url").val();
	if(game_name == '')
	{
		alert('请填写游戏名称');
		$("#game_name").focus();
		flag = false;
	}
	
	if(flag != false)
	{
		$("#game_edit_form").submit();
	}

}


//编辑游戏帮助
function download_help_edit_check()
{
	var flag = true;
	var game_id = $("#game_id").val();
	var help_num = $("#help_num").val();
	var help_content = GetMessageContent("content"+help_num);
	$.post("http://"+document.location.host+"/admin/admin_download/edit_help_proc/",
		{Action:"POST",game_id:game_id,help_num:help_num,help_content:help_content},
		function (data)
		{
			if(data[2] == 'success')
			{
				alert(data[0]+data[1]);
			}
			else
			{
				alert(data[0]+data[1]);
			}
			$("#msgTitle").click();
			window.location.reload(); 
		}, 
		"json");

}

//回复提问
function qa_reply_check()
{
	
	var flag = true;
	var qa_id = $("#qa_id").val();
	var answer_content = $("#answer_content").val();
	var admin_name = $("#admin_name").val();
	var admin_id = $("#admin_id").val();

	if($("#answer_content").val()== '')
	{
		alert('请填写回复内容');
		$("#answer_content").focus();
		flag = false;
	}

	if(flag != false)
	{
		//alert(answer_content);
		$.post("http://"+document.location.host+"/admin/admin_qa/reply_qa_proc/"+qa_id,
		{Action:"POST",qa_id:qa_id,answer_content:answer_content,admin_name:admin_name,admin_id:admin_id},
		function (data)
		{
			if(data[2] == 'success')
			{
				alert(data[0]+data[1]);
			}
			else
			{
				alert(data[0]+data[1]);
			}
			$("#msgTitle").click();
			window.location.reload(); 
		}, 
		"json");
	}
}

//取fck内容长度
function GetMessageLength(str)
{
    var oEditor = FCKeditorAPI.GetInstance(str) ;
    var oDOM = oEditor.EditorDocument ;
    var iLength ;

    if ( document.all )        // If Internet Explorer.
    {
        iLength = oDOM.body.innerText.length ;
    }
    else                    // If Gecko.
    {
        var r = oDOM.createRange() ;
        r.selectNodeContents( oDOM.body );
        iLength = r.toString().length ;
    }
	return iLength;
}   

//取fck内容
function GetMessageContent(str)
{
    var oEditor = FCKeditorAPI.GetInstance(str) ;
	return oEditor.GetXHTML();
} 

//全选
function checkboxfunction()
{
	if ($("#checkflag").val() == 'true')
	{
		$(':checkbox').attr('checked','checked');
		$("#checkflag").attr('value','false');
	}
	else
	{
		$(':checkbox').attr('checked','');
		$("#checkflag").attr('value','true');
	}
}

function del_all(url)
{
	if(confirm("确定删除"))
	{
		$("input[@name='the_checkbox']").each(function()
		{
			if($(this).attr('checked') == undefined)
			{
				
			}
			else
			{
				url = url + $(this).val() + '_';
				
			}
		})
		$.post(url,{Action:"POST"},function(data){alert(data);window.location.reload();}, "text");
	}
}

function reply_all()
{
	var flag = true;
	$("input[@name='the_checkbox']").each(function()
	{
		if($(this).attr('checked') == undefined || flag == false)
		{
			
		}
		else
		{
			ajax_form("http://"+document.location.host+"/admin/admin_qa/reply_qa/"+$(this).val(),600,600);
			flag = false;
		}
	})
}


function game_edit_all()
{
	var flag = true;
	$("input[@name='the_checkbox']").each(function()
	{
		if($(this).attr('checked') == undefined || flag == false)
		{
			
		}
		else
		{
			ajax_form("http://"+document.location.host+"/admin/admin_download/edit_game/"+$(this).val(),600,450);
			flag = false;
		}
	})
}

function question_create_check()
{
	var flag = true;
	var kf_name = $("#kf_name").val();
	var maketime = $("#maketime").val();
	var kh_name = $("#kh_name").val();
	var question_type_id = $("select[@name=create_question_type] option[@selected]").val();
	var kh_tel = $("#kh_tel").val();
	var kh_qq = $("#kh_qq").val();
	var status = $("input[@name=create_status][@checked]").val();
	var question_desc = $("#question_desc").val();
	if(kf_name == '')
	{
		alert('客服名不能为空');
		$("#kf_name").focus();
		flag = false;
	}
	if(question_desc == '')
	{
		alert('问题描述不能为空');
		$("#question_desc").focus();
		flag = false;
	}
	
	if(flag != false)
	{
		$.post("http://"+document.location.host+"/admin/admin_question/create_question_proc",
		{Action:"POST",kf_name:kf_name,status:status,maketime:maketime,kh_name:kh_name,question_type_id:question_type_id,kh_tel:kh_tel,kh_qq:kh_qq,question_desc:question_desc},
		function (data)
		{
			if(data[2] == 'success')
			{
				alert(data[0]+data[1]);
			}
			else
			{
				alert(data[0]+data[1]);
			}
			$("#msgTitle").click();
			window.location.reload(); 
		}, 
		"json");
	}
}

function question_edit_check()
{
	alert('修改');
	var flag = true;
	var kf_name = $("#kf_name").val();
	var question_id = $("#question_id").val();
	var maketime = $("#maketime").val();
	var kh_name = $("#kh_name").val();
	var question_type_id = $("select[@name=edit_question_type] option[@selected]").val();
	var kh_tel = $("#kh_tel").val();
	var kh_qq = $("#kh_qq").val();
	var status = $("input[@name=edit_status][@checked]").val();
	var question_desc = $("#question_desc").val();
	
	if(kf_name == '')
	{
		alert('客服名不能为空');
		$("#kf_name").focus();
		flag = false;
	}
	if(question_desc == '')
	{
		alert('问题描述不能为空');
		$("#question_desc").focus();
		flag = false;
	}
	if(status == '1')
	{
		if(confirm("确定修改？"))
		{
			flag = true;
		}
		else
		{
			flag = false;
		}
	}
	if(flag != false)
	{
		$.post("http://"+document.location.host+"/admin/admin_question/edit_question_proc",
		{Action:"POST",kf_name:kf_name,question_id:question_id,status:status,maketime:maketime,kh_name:kh_name,question_type_id:question_type_id,kh_tel:kh_tel,kh_qq:kh_qq,question_desc:question_desc},
		function (data)
		{
			if(data[2] == 'success')
			{
				alert(data[0]+data[1]);
			}
			else
			{
				alert(data[0]+data[1]);
			}
			window.location.reload(); 
		}, 
		"json");
	}
}

function swap_question_div()
{
	if($("#rights9").attr('checked')==undefined)
	{
		$("#if_question_admin").attr("checked",'');
		$("#if_question_admin_del").attr("checked",'');
		$("#question_div").hide();
	}
	else
	{
		$("#question_div").show();
	}
}

function question_admin_check()
{
	var flag = true;
	
	var question_id = $("#question_id").val();
	var admin_status = $("input[@name=admin_status][@checked]").val();
	var admin_desc = $("#admin_desc").val();
	

	if(admin_desc == '')
	{
		alert('主管处理不能为空');
		$("#admin_desc").focus();
		flag = false;
	}
	if(flag != false)
	{
		$.post("http://"+document.location.host+"/admin/admin_question/admins_question_proc",
		{Action:"POST",question_id:question_id,admin_status:admin_status,admin_desc:admin_desc},
		function (data)
		{
			if(data[2] == 'success')
			{
				alert(data[0]+data[1]);
			}
			else
			{
				alert(data[0]+data[1]);
			}
			$("#msgTitle").click();
			window.location.reload(); 
		}, 
		"json");
	}
}

function appeal_deal_check()
{
	var appeal_id = $("#appeal_id").val();
	var status = $("input[@name=status][@checked]").val();
	var deal_time = $("#deal_time").val();
	var deal_desc = $("#deal_desc").val();

	$.post("http://"+document.location.host+"/admin/admin_userappeal/appeal_deal_proc",
	{Action:"POST",appeal_id:appeal_id,status:status,deal_time:deal_time,deal_desc:deal_desc},
	function (data)
	{
		if(data[2] == 'success')
		{
			alert(data[0]+data[1]);
		}
		else
		{
			alert(data[0]+data[1]);
		}
		$("#msgTitle").click();
		window.location.reload(); 
	}, 
	"json");
	
}
