///////////////////////////////////////////////////////////////////
// Author:dahong | E-mail: dahongy@gmail.com
// Copyright (c) Http://www.phpstcms.cn
// This is not a free software, please to pay for more functions
// $Id: 2009-10-06 version 3.2 biz $
///////////////////////////////////////////////////////////////////
var STCMS_VERSION = "V3.2";
$(document).ajaxStart(function(){showLoad()});
$(document).ajaxError(function(event,request, settings){showDialog("Ajax 查询错误，其检查浏览器兼容或者访问本程序网站获取帮助！<br>事件：发送Ajax请求<br>请求地址："+settings.url);});
$(document).ajaxComplete(function(){hideLoad();})
$(function(){
	$("tr:even").addClass("tr1");
	$("tr:odd").addClass("tr2");
	$("input:text").focus(function(){$(this).addClass("focus")});
	$("input:text").blur(function(){$(this).removeClass("focus")});
	$("input:password").focus(function(){$(this).addClass("focus")});
	$("input:password").blur(function(){$(this).removeClass("focus")});
	$("input:file").focus(function(){$(this).addClass("focus")});
	$("input:file").blur(function(){$(this).removeClass("focus")});
});
function showLoad() {
	if($$("load_span")){hideLoad();}
	var x = 0; var y = 0;
	var event = window.event;
	if(event) {
		x = event.clientX;
		y = event.clientY + document.documentElement.scrollTop;
	} else {
		x = screen.width/2;
		y = screen.height/2;
	}
	var loadObj = document.createElement("span");
	loadObj.setAttribute("id","load_span");
	loadObj.style.top=(y+10)+"px";
	loadObj.style.left=(x+10)+"px";
	loadObj.style.position = "absolute";
	loadObj.innerHTML = "<image src='../images/loading.gif'>正在加载中……";
	loadObj.style.zIndex = "1000";
	document.body.appendChild(loadObj);
}
function hideLoad() {
	if($$("load_span")){document.body.removeChild($$("load_span"));}	
}

function showDialog(str,width,height,isClose,time) { 
   var msgw,msgh,bordercolor,titleMsg;
	titleMsg = "提示信息";
	time = time ? time : 3000;
    msgw = width ? width : 600;	//提示窗口的宽度 
    msgh = height ? height : 75;	//提示窗口的高度 
    titleheight=20;  //提示窗口标题高度 
    bordercolor="#6692cb";	//提示窗口的边框颜色 
    titlecolor="#99CCFF";	//提示窗口的标题颜色 

    var sWidth,sHeight; 
    sWidth=document.body.offsetWidth;	//浏览器工作区域内页面宽度 
    sHeight=document.body.offsetHeight;	//屏幕高度（垂直分辨率） 

    var bgObj=document.createElement("div");//创建一个div对象（背景层） 
    bgObj.setAttribute("id","bgDiv");
    bgObj.style.position="absolute"; 
    bgObj.style.top="0px"; 
    bgObj.style.background="#FFFFFF"; 
    bgObj.style.filter="progid:DXImageTransform.Microsoft.Alpha(style=0,opacity=50)"; 
    bgObj.style.opacity="0.6"; 
    bgObj.style.left="0"; 
    bgObj.style.width=sWidth + "px"; 
    bgObj.style.height=document.body.offsetHeight+"px"; 
    bgObj.style.zIndex   =  "10000"; 
    document.body.appendChild(bgObj);//在body内添加该div对象 

	var msgObj=document.createElement("div")//创建一个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   =  (sWidth-msgw)/2+"px"; 
    msgObj.style.top   =  (screen.height/2)-200+document.documentElement.scrollTop+"px"; 
    msgObj.style.width  =   msgw   +  "px"; 
    msgObj.style.height  = "auto"; 
    msgObj.style.textAlign  =  "center"; 
    msgObj.style.lineHeight  = "25px"; 
    msgObj.style.zIndex = "10001"; 

    var   title=document.createElement("div");
    title.setAttribute("id","msgTitle"); 
    title.setAttribute("align","left"); 
    title.style.margin="0"; 
    title.style.padding="3px"; 
    title.style.background=bordercolor; 
    title.style.opacity="0.75"; 
    title.style.border="1px solid "+bordercolor; 
    title.style.height="12px"; 
    title.style.font="12px   Verdana,   Geneva,   Arial,   Helvetica,   sans-serif"; 
    title.style.color="white"; 
    title.innerHTML="<span style='float:right; cursor:pointer; marin-right:10px;'><img src='../images/close.gif'></span>"+titleMsg; 
	title.onclick=removeObj;
	function   removeObj(){ 
        if($$("msgDiv")) {
			document.body.removeChild(bgObj);
			document.getElementById("msgDiv").removeChild(title);
			document.body.removeChild(msgObj);
		}
    } 
    document.body.appendChild(msgObj);//在body内添加提示框div对象msgObj 
    document.getElementById("msgDiv").appendChild(title);//在提示框div中添加标题栏对象title 

    var   txt=document.createElement("div");//创建一个p对象（提示框提示信息） 
    txt.setAttribute("id","msgTxt"); 
    txt.style.margin="0"; 
	txt.style.height = "auto";
	txt.style.padding = "50px 15px 50px 15px";
	txt.style.color="red";
	txt.style.fontSize = "16px";
    txt.style.padding="3px"; 
    txt.innerHTML=str;//来源于函数调用时的参数值 
    document.getElementById("msgDiv").appendChild(txt);//在提示框div中添加提示信息对象txt 
	if(isClose){
		setTimeout(function(){removeObj();},time)	
	}
	title.focus();
}

function del(url,id) {
	if(confirm("删除后将无法恢复数据，是否真的要删除？")) {
		location.href = url + "?action=del&id=" + id;	
	}
}

function edit(sUrl,sId) {
	location.href = sUrl + "?action=edit&id=" + sId;
}
function checkAll(id) {
	$("form#"+id+" input:checkbox").each(function(i){$(this).attr("checked", true);});
}
function cancleAll(id) {
	$("form#"+id+" input:checkbox").each(function(i){$(this).attr("checked",false);});
}
function delAll(id,url) {
	var ids = "";
	$("form#"+id+" input:checkbox[checked]").each(function(){ids = ids + $(this).val() + ",";});
	if(!ids)
	{
		showDialog("请选择列表！",'400','50',true,1000);return false;
	} else {
		if(confirm("删除后将无法恢复数据，是否真的要删除？")) {
			location.href = url + "?action=del&id=" + ids;
		}
	}
}
function cancle() {
	history.back();	
}
function selectAdminType() {
	  var type = $$("admin_group").value;
	  if(type == "categoryAdmin") {
		  $.ajax({
			  url:"ajax.php?action=getCategory",
			  type:"POST",
			  success:function(data){$$("categorySelect").innerHTML = data}
		  });
	  } else {
		  $$("categorySelect").innerHTML="";
	  }
}
function tblStruct(table) {
	$.ajax({
		url:"data.php?action=tblStruct&table="+table,
		success:function(data){$$("result").innerHTML = "<pre>"+data+"</pre>";}
	});	
}
function backUp(table) {
	var url="data.php?action=backup&table="+table;
	location.href=url;
}
function truncate(table) {
	if(confirm("数据将无法恢复，你真的要清空吗？")) {
		var url="data.php?action=truncate&table="+table;
		location.href=url;
	}
}
function delBackUp(id) {
	if(confirm("你真的要删该除备份吗？")) {
		var url="data.php?action=delbackup&id="+id;
		location.href=url;
	}
}
function backUpAll() {
		location.href = "data.php?action=backup&table=allTable";
}
function delBackUpAll(id)
{
	var ids = "";
	$("#"+id+" input:checked").each(function(){ids = ids + $(this).val() + ",";});
	if(!ids) {
		showDialog("请选择列表！",'400','50',true,1000);return false;
	} else {
		if(confirm("删除后将无法恢复数据，是否真的要删除？")) {
			location.href = "data.php?action=delbackup&id=" + ids;
		}
	}
}
function repair() {
	location.href="data.php?action=repair";	
}
function optimize() {
	location.href="data.php?action=optimize";	
}
function alter() {
	location.href="data.php?action=alter";	
}
function recover(id) {
	if(confirm("还原后数据将改变，你真的要还原该次备份吗？"))	{
		location.href="data.php?action=recover&from=file&id="+id;
	}
}
function showDiv(id) {
	var styleDis = $$(id).style.display;
	$$(id).style.display = styleDis != "none" ? "none" : "block";
}
function inputMedia(path,type) {
	if(confirm("真的要录入该文件或文件夹下的音乐文件吗？")){
		location.href="input.php?action=input&path="+path+"&type="+type;
	}
}
function $$(id){return document.getElementById(id)}
function login() {
	var obj={'name':'管理员','pwd':'密码','verify':'验证码'}
	for(i in obj) {
		if($$(i).value=="") {
			alert(obj[i]+"不能为空！");
			$$(i).focus();
			return false;
		}
	}
	return true;
}

function selectSort(value) {
	value = value ? value : $$("category").value; 
	$.ajax({
		   url:"ajax.php?action=selectSort&category="+encodeURIComponent(value),
		   success:function(data){$$("select_sort").innerHTML=data}
	});
}
function selectArtist(value) {
	$.ajax({
		   url:"ajax.php?action=selectArtist",
		   data:"sort="+encodeURIComponent(value)+"&category="+encodeURIComponent($$("category").value),
		   success:function(data){$$("select_artist").innerHTML=data}
	});
}
function selectOneArtist(value) {
	$$("artist").value = value;
}
function selectSpecialSort() {
	$.ajax({
		url:"ajax.php?action=selectSpecialSort",
		data:"category="+$$("category").value+"&artist="+encodeURIComponent($$("artist").value),
		success:function(data){$$("sort_list").innerHTML=data}
	});
}
function selectOneSort(sortid) {
	$.ajax({
		url:"ajax.php?action=selectOneSort",
		data:"sort="+sortid+"&category="+$$("category").value,
		success:function(data){$$("special_list").innerHTML=data}
	});
}
function html(action) {
	if(confirm("确定要生成吗？")){location.href="html.php?action="+action}
}
function showFields(table) {
	if(table){
		$.ajax({
			url:'ajax.php?action=showFields&table='+table,
			success:function(data){info = eval('('+data+')'); $('td.fields').html(info[0]);$('td.cnd_fields').html(info[1])}
		});
	}
}
function addMusicField() {
	var html='';
	if($$('musicNum').value) {
		var num = $$('musicNum').value;
		for(var i=0; i<num; i++) {
			html = html + "顺序：<input name='order[]' style='width:15px;' value='"+(i+6)+"' type='text' />&nbsp;名称：<input type='text' name='name[]'>&nbsp;地址：<input type='text' name='url[]'><br><br>";
		}
		$('#setMusicList').append(html);
	}
}
function checkVersion() {
	$.ajax({
		url:"check_version.php",
		success:function(data){
				if(data) {
					showDialog(data);
				}
			}
	});
}
function uploadCheck(id, value){
	if(id && confirm('确认审核歌曲？')) {
		location.href='music.php?action=check&id='+id +"&value="+value;
	}
}
function uploadCheckAll(id, value){
	var ids = "";
	$("form#"+id+" input:checkbox[checked]").each(function(){ids = ids + $(this).val() + ",";});
	if(!ids){
		showDialog("请选择列表！",'400','50',true,1000);return false;
	} else {
		if(confirm("确认要审核这些歌曲？")) {
			location.href = "music.php?action=check&id=" + ids +"&value="+value;
		}
	}
}
function uploadCheckSpecial(id, value){
	if(id && confirm('确认审核专辑？')) {
		location.href='special.php?action=check&id='+id +"&value="+value;
	}
}
function uploadCheckAllSpecial(id, value){
	var ids = "";
	$("form#"+id+" input:checkbox[checked]").each(function(){ids = ids + $(this).val() + ",";});
	if(!ids){
		showDialog("请选择列表！",'400','50',true,1000);return false;
	} else {
		if(confirm("确认要审核这些专辑？")) {
			location.href = "special.php?action=check&id=" + ids +"&value="+value;
		}
	}
}
function getVersion() {
	document.write(STCMS_VERSION);
}
