﻿///////////////////////////////////////////////////////////////////
// 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){alert("Ajax 查询错误，请检查浏览器兼容或者访问本程序网站获取帮助！");});
$(document).ajaxComplete(function(){hideLoad();})
$(function(){
	$('input:text').focus(function(){$(this).addClass('focus');});
	$('input:text').blur(function(){$(this).removeClass('focus');});
	if(getCookie('__userAgent__')=='' && navigator.userAgent.indexOf('MSIE 6.0') != -1){
		showDialog('您使用的是IE6.0浏览器，为了达到更好的效果，建议您使用IE8浏览器。'); setCookie('__userAgent__', 'MSIE 6.0');
	}
});
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='"+WEB_URL+"images/loading.gif' >正在加载中……";
	loadObj.style.zIndex = "1000";
	document.body.appendChild(loadObj);
}
function hideLoad() {
	if($$("load_span")){document.body.removeChild($$("load_span"));}	
}
function checkbox(form) {
	for (var i=0; i<form.elements.length; i++) {
		var e = form.elements[i];
		if (e.checked==false) {
			e.checked = true;
		} else {
			e.checked = false;
		}
	}
}
function cancle() {
	history.go(-1);
}
function playAll(form, action) {
	var music_id = Array();
	for(var i = 0; i < form.elements.length; i++) {
		var e = form.elements[i];
		if(e.checked && e.type=="checkbox" && i < form.elements.length-1) {
			music_id[i] = e.value;	
		}
	}
	var music_id_str = music_id.join('_');
	if(music_id_str) {
		window.open(WEB_URL+"player.php?id="+music_id_str+(action ? "&action="+action : ""), "STCMS_PLAYER");
	} else {
		showDialog("请选择歌曲后再点此按钮！");
	}
}
function more(url){if(url != "false")location.href=url}

function $$(id){return document.getElementById(id)}

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='"+WEB_URL+"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 getCommentPage(page,type,typeid) {
	$.ajax({
		url:WEB_URL+"ajax.php?action=getComment&type="+type+"&typeid="+typeid+"&page="+page,
		type:"POST",
		success:function (data){handComment(data);}
	});
}
function handComment(data) {
	var arr = eval("("+data+")");
	$("#pageDiv").html(arr[1]);
	var list = arr[0];
	var html="";
	if(!list) {return false}
	for(var i=0;i<list.length;i++){
		html = html + '<div class="box autobox verdana wfull mtop box-4"><div class="tt"><h4>Guest:'+list[i]['guest']+'　E-mail:<a href="mailto:'+list[i]['mail']+'" title="'+list[i]['mail']+'">'+list[i]['mail']+'</a>　QQ:'+list[i]['qq']+'　<span title="'+list[i]['from']+'"></span></h4></div><div class="ct">'+list[i]['content'];
		if(list[i]['reply']) {
			html = html + '<div class="reply_box"><b>回复:</b>'+ list[i]['reply'] +'</div>';	
		}
		html = html +'<br><br><div>Time:'+list[i]['time']+'&nbsp;&nbsp;From:'+list[i]['from']+'</div></div></div>';
	}
	$("#comment_list").html(html);
}

function comment(type,typeid) {
	$.ajax({
		url:WEB_URL+"ajax.php?action=addComment&type="+type+"&typeid="+typeid,
		data:$("#addComment").formSerialize(),
		success:function (data){
				var info = eval("("+data+")");
				showDialog(info['msg']);
				if(info['reload']== "1"){
					getCommentPage('1',type,typeid);
				}
				$("#addComment").resetForm();
			}
	});
}
function download(id) {
	if(id) {
		$.ajax({
			url:WEB_URL+"download.php?id="+id,
			success:function(data){
				var info = eval("("+data+")"); 
				if(info['msg']){
					showDialog(info['msg']);
				}
				if(info['url']) {
					setTimeout(function(){location.href=WEB_URL+'media.php?url='+encodeURIComponent(info['url']);});				}
			}
		});
	}
}
function reportError(id) {
	if(id) {
		$.ajax({
			url:WEB_URL+"ajax.php?action=reportError&id="+escape(id),
			type:"POST",
			success:function(data){showDialog(data)}
		})
	}
}
function recommend(id) {
	if(id) {
		$.ajax({
			url:WEB_URL+"ajax.php?action=recommend&id="+id,
			type:"POST",
			success:function(data){showDialog(data)}
		});
	}
}
function delFav(form, type){
	var music_id = Array();
	for(var i = 0; i < form.elements.length; i++) {
		var e = form.elements[i];
		if(e.checked && e.type=="checkbox" && i < form.elements.length-1)
		{
			music_id[i] = e.value;	
		}
	}
	var music_id_str = music_id.join('_');
	if(music_id_str) {
		if(confirm('你确定要从收藏中删除吗？')) location.href = WEB_URL+"member/fav.php?action=del&type="+escape(type)+"&typeid="+escape(music_id_str);
	} else {
		showDialog('请选择列表！');	
	}
}
function delUpload(form) {
	var music_id = Array();
	var num = 0;
	for(var i = 0; i < form.elements.length; i++) {
		var e = form.elements[i];
		if(e.checked && e.type=="checkbox" && i < form.elements.length-1) {
			music_id[num] = e.value;
			num++;
		}
	}
	var music_id_str = music_id.join('_');
	if(music_id_str) {
		if(confirm('删除歌曲将减少你的积分，你确定要删除该歌曲吗？')) location.href = WEB_URL+"member/upload.php?action=del&id="+escape(music_id_str);
	} else {
		showDialog('请选择列表！');	
	}
}
function delFavSpecial(id) {
	if(confirm('你确定要从收藏中删除吗？')) {
		location.href=WEB_URL+"member/fav.php?action=del&type=2&typeid="+id;
	}
}
function addFav(type, typeid) {
	if(getCookie('STCMS_member')=='') {
		if(confirm('你还没有登录不允许使用收藏功能，现在是否登录？')) {
			location.href=WEB_URL+'member/?action=login';
		} else {
			return false;
		}
	}
	if(type && typeid) {
		$.ajax({
			url:WEB_URL+'ajax.php?action=addFav&type='+escape(type)+'&typeid='+escape(typeid),
			type:'POST',
			success:function(data){ var info = eval('('+data+')'); showDialog(info['msg']); if(info['url']){location.href=info['url']}}
		});
	}
}
function mRegister() {
	if($('#name').val()=="") {
		alert('用户名必须填写'); $('#name').focus(); return false;
	}
	if($('#pwd1').val()=="" || $('#pwd2').val()=='') {
		alert('密码必须填写！'); $('#pwd1').focus(); return false;
	}
	if($('#mail').val()=="") {
		alert('邮箱必须填写！'); $('#mail').focus(); return false;
	}
	if($('#pwdquestion').val()=="") {
		alert("密码提示问题必须填写！"); $('#pwdquestion').focus(); return false;
	}
	if($('#pwdanswer').val()=="") {
		alert("密码提示问题答案必须填写！"); $('#pwdanswer').focus(); return false;
	}
	var imgPath = $('#file').val();
	if(imgPath && !imgPath.match(/\.(jpg|bmp|png|gif|jpeg)$/i)) {
		alert('系统禁止上传此种文件的头像！'); $('#file').focus(); return false;
	}
	var pic = $('#picture').val();
	if(pic && !pic.match(/\.(jpg|bmp|png|gif|jpeg)$/i)) {
		alert('系统禁止使用此种文件的头像！'); $('#picture').focus(); return false;
	}
	return true;
}
function mEdit() {
	if($('#name').val()=="") {
		alert('用户名必须填写'); $('#name').focus(); return false;
	}
	if($('#pwd').val()=="") {
		alert('原密码必须填写！'); $('#pwd').focus(); return false;
	}
	if($('#mail').val()=="") {
		alert('邮箱必须填写！'); $('#mail').focus(); return false;
	}
	if($('#pwdquestion').val()=="") {
		alert("密码提示问题必须填写！"); $('#pwdquestion').focus(); return false;
	}
	if($('#pwdanswer').val()=="") {
		alert("密码提示问题答案必须填写！"); $('#pwdanswer').focus(); return false;
	}
	var imgPath = $('#file').val();
	var pic = $('#picture').val();
	if(imgPath &&  pic=="" && !imgPath.match(/\.(jpg|bmp|png|gif|jpeg)$/i)) {
		alert('系统禁止上传此种文件的头像！'); $('#file').focus(); return false;
	}
	if(pic && !imgPath && !pic.match(/\.(jpg|bmp|png|gif|jpeg)$/i)) {
		alert('系统禁止使用此种文件的头像！'); $('#picture').focus(); return false;
	}
	return true;
}
function mLogin(url) {
	if($('#name').value=="") {
		alert('会员名不能为空！'); $('#name').focus(); return false;
	}
	if($('#pwd').value=="") {
		alert('密码不能为空！'); $('#pwd').focus(); return false;
	}
	return true;
}
function showDiv(id) {
	var styleDis = $$(id).style.display;
	$$(id).style.display = styleDis != "none" ? "none" : "block";
}
function addHit(type, typeid) {
	$.ajax({
		url:WEB_URL+"ajax.php?action=addHit&type="+type+"&typeid="+typeid,
		success:function(data){var info = eval("("+data+")"); $$("add_hit").innerHTML = info['hit'];$$("add_download").innerHTML=info['download']}
	});
}
function printVersion() {
	document.write(STCMS_VERSION);
}
function setCookie(c_name,value,expiredays) {
	var exdate=new Date();
	exdate.setDate(exdate.getDate()+expiredays);
	document.cookie=c_name+ "=" +escape(value)+((expiredays==null) ? "" : ";expires="+exdate.toGMTString())+"; path=/";
}
function getCookie(c_name) {
	if (document.cookie.length>0) {
		c_start=document.cookie.indexOf(c_name + "=");
		if (c_start!=-1) { 
			c_start=c_start + c_name.length+1;
			c_end=document.cookie.indexOf(";",c_start);
			if (c_end==-1) {
				c_end=document.cookie.length;
			}
			return unescape(document.cookie.substring(c_start, c_end));
		} 
	}
	return "";
}
function clearList() {
	setCookie('STCMS_music_list', '');
	location.href=WEB_URL;
}
function addList(id) {
	if(id) {
		var music_list = getCookie('STCMS_music_list');
		if(music_list == '') {
			setCookie('STCMS_music_list', id, 1)	
		} else {
			var array = music_list.split("_");
			var num = array.length;
			array[num] = id;
			music_list = array.join('_');
			setCookie('STCMS_music_list', music_list, 1);
		}
		window.open(WEB_URL+'player.php', 'STMCS_PALYER');
	}
}
function checkUpload() {
	var name = $('#name').val();
	var artist = $('#artist').val()
	var file = $('#file').val();
	var url =$('#url').val();
	var category = $('#category').val()
	if(!name) {
		alert('歌曲名称必须填写！'); $('#name').focus();
		return false;
	} 
	else if(!file && !url) {
		alert('歌曲网络地址或上传路径必须填写一项！'); $('#url').focus();
		return false;
	} else if(!category){
		alert('必选选择音乐分类'); $('#category').focus();
		return false;
	} else if(!artist) {
		alert('歌手必须填写！'); $('#artist').focus();
		return false;
	} else {
		var reg = new RegExp("\\.("+MEMBER_UPLOAD_EXT+")(\\\?|$)",'i');
		if(!file && !reg.test(url)) {
			if(url.indexOf("?")<0) {
				alert('系统不允许上传该种音乐文件！'); $('#url').focus(); return false;
			}
		}
		if(file && !reg.test(file)) {
			alert('系统不允许上传该种音乐文件！'); $('#file').focus(); return false;
		}
		var lrcPath = $('#uploadLyric').val();
		if(lrcPath && !lrcPath.match(/\.lrc$/i)) {
		 	alert('系统不允许上传*.LRC以外的歌词文件！'); $('#uploadLyric').focus(); return false;
		}
		var lyric = $('#lyric').val();
		if(lyric.length>10*1024) {
		 	alert('系统不允许歌词超出10K！'); $('#lyric').focus(); return false;
		}
		return true;
	}
}
function checkSpecialUpload() {
	var items = {'name':'专辑名', 'category':'分类', 'artist':'歌手', 'introduction':'专辑介绍'};
	for(i in items) {
		if($('#'+i).val()==''){
			alert(items[i]+'不能为空！'); $('#'+i).focus(); return false;
		}
	}
	var picture = $('#picture').val();
	var file = $('#file').val();
	if(picture=='' && file=='') {
		alert('专辑图片必须填写一项！'); $('#picture').focus(); return false;
	}
	if(file && !file.match(/\.(jpg|bmp|png|gif|jpeg)$/i)) {
		alert('系统禁止上传此种文件的图片！'); $('#file').focus(); return false;
	}
	if(picture && !picture.match(/\.(jpg|bmp|png|gif|jpeg)$/i)) {
		alert('系统禁止上传此种文件的图片！'); $('#picture').focus(); return false;
	}
	if($('#introduction').val().length>10*1024) {
		alert('专辑介绍不能超过2K！'); $('#introduction').focus(); return false;	
	}
	return true;
}
function selectSort(value) {
	value = value ? value : $$("category").value; 
	$.ajax({
		   url:WEB_URL+"ajax.php?action=selectSort&category="+encodeURIComponent(value),
		   success:function(data){$$("select_sort").innerHTML=data}
	});
}
function selectArtist(value) {
	$.ajax({
		   url:WEB_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 delUploadSpecial(id) {
	if(id && confirm('你确认要删除该专辑吗？')) {
		location.href=WEB_URL+'member/m_special.php?action=del&id='+id;
	}
}
function redirect(url, time, msg, isclose) {
	if(msg) {alert(msg);}
	time = parseInt(time);
	if(isclose) {
		setTimeout(function(){window.open(url, 'new');
		window.opener=null;
		window.close();}, time*1000);
	} else {
		setTimeout(function(){location.href=url;}, time*1000);
	}
}