﻿///////////////////////////////////////////////////////////////////
// Author:dahong | E-mail: dahongy@gmail.com
// Copyright (c) Http://www.phpstcms.com
// This is not a free software, please to pay for more functions
// $Id: 2010-10-14 version 3.5 $
///////////////////////////////////////////////////////////////////
var STCMS_VERSION = "V3.5";
$(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');});
});
var STCMS_PLAYER=false;
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 = "1001";
	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];
		e.checked = true;
	}
}
function ancheck(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();
	var n = 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[n] = e.value;
			n++;
		}
	}
	var music_id_str = music_id.join('_');
	if(!music_id_str) {
		alert('请选择歌曲后再试！'); return false;
	}
	play(music_id_str)
}
function play(id, server) {
	var height = 465;
	var width = 600;
	var h = (screen.height-height)/2;
	var w = (screen.width-width)/2;
	if(!STCMS_PLAYER || STCMS_PLAYER.closed) {
		STCMS_PLAYER = window.open(WEB_URL+'player.php?id='+id+'&server='+server, 'STCMS_PLAYER_WINDOW', 'scrollbars=no,menubar=no,statusbar=no,locationbar=no,height='+height+',width='+width+',top='+h+',left='+w);
		STCMS_PLAYER.focus();
	} else  {
		STCMS_PLAYER.addplay(id)
		return false;
	}
	return false;
}
function addList(id) {
	var lists = id.split('_');
	var plylststr = lists.join('_');
	var height = 465;
	var width = 600;
	var h = (screen.height-height)/2;
	var w = (screen.width-width)/2;
	if(!STCMS_PLAYER || STCMS_PLAYER.closed) {
		STCMS_PLAYER = window.open(WEB_URL+'player.php?id='+plylststr, 'STCMS_PLAYER_WINDOW', 'scrollbars=no,menubar=no,statusbar=no,locationbar=no,height='+height+',width='+width+',top='+h+',left='+w);
	} else {
		STCMS_PLAYER.addonly(plylststr);
	}
	return false;
}
function playSpecial(id,server) {
	var height = 465;
	var width = 600;
	server = parseInt(server);
	var h = (screen.height-height)/2;
	var w = (screen.width-width)/2;
	window.open(WEB_URL+'player.php?special='+id+'&server='+server, 'STCMS_PLAYER', 'scrollbars=no,menubar=no,statusbar=no,locationbar=no,height='+height+',width='+width+',top='+h+',left='+w);
	return false;
}
function clearList() {
	setCookie('STCMS_music_list', '');
	location.href=WEB_URL;
}
function openWin(url) {
	window.open(url);
	return false;
}
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 downLrc(id) {
	var height = 465;
	var width = 590;
	var h = (screen.height-height)/2;
	var w = (screen.width-width)/2;
	window.open(WEB_URL+'lrc.php?action=showLrc&id='+id, 'STCMS_LRC', 'scrollbars=no,menubar=no,statusbar=no,locationbar=no,height='+height+',width='+width+',top='+h+',left='+w);
	return false;
}
function showDown(id) {
	var height = 465;
	var width = 590;
	var h = (screen.height-height)/2;
	var w = (screen.width-width)/2;
	window.open(WEB_URL+'download.php?action=showDown&id='+id, 'STCMS_DOWN', 'scrollbars=no,menubar=no,statusbar=no,locationbar=no,height='+height+',width='+width+',top='+h+',left='+w);
	return false;
}
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">';
			html = html + '<div class="tt">';
				html = html + '<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']+'</h4>';
			html = html +'</div>';
			html = html+ '<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>';
				html = html +'<div border="0">Time:'+list[i]['time']+'&nbsp;&nbsp;From:'+list[i]['from']+'</div>';
			html = html+ '</div>';
		html = html+ '</div>';
	}
	$("#comment_list").html(html);
}

function comment(type,typeid) {
	if($('#comment_guest').val()=='') {
		alert('填写好网名再开始吧！'); $('#comment_guest').focus(); return false;
	}
	if($('#comment_content').val() == '') {
		alert('内容还没填呢，急什么！'); $('#comment_content').focus(); return false;
	}
	$.ajax({
		url:WEB_URL+"ajax.php?action=addComment&type="+type+"&typeid="+typeid,
		data:$("#addComment").formSerialize(),
		success:function (data){
				var info = eval("("+data+")");
				alert(info['msg']);
				if(info['reload']== "1"){
					getCommentPage('1',type,typeid);
				}
				$("#addComment").resetForm();
			}
	});
}
function download(money) {
	return confirm('下载歌曲会扣除积分'+ money +'，你是否继续下载？');
}
function down(url) {
	location.href=WEB_URL+'media.php?url='+encodeURIComponent(url);
}
function uploadLyric(id) {
	if(getCookie('STCMS_member')=='') {
		if(confirm('你还没有登录，无法上传歌词，现在是否登录？')) {
			window.open(WEB_URL+'member/?action=login');
			return false;
		} else {
			return false;
		}
	}
	height = 465; width = 590;
	h = (screen.height-height)/2;
	w = (screen.width-width)/2;
	window.open(WEB_URL+'lrc.php?action=upload&id='+id, 'STCMS_UPLOAD_LYRIC', 'scrollbars=no,menubar=no,statusbar=no,locationbar=no,height='+height+',width='+width+',top='+h+',left='+w);
	return false;
}
function uploadedLyric(id) {
	if($('#lrc_title').val()=='') {
		alert('歌词标题不能为空！'); return false;
	}
	if($('#lrc_content').val()=='') {
		alert('歌词内容不能为空！'); return false;
	}
	$.ajax({
		url:WEB_URL+'lrc.php?action=uploaded&id='+id,
		type:'POST',
		data:$('#uploadLyricForm').formSerialize(),
		success:function(data) {
			var info = eval('('+data+')');
			if(info['msg']) alert(info['msg']);
			if(info['js']) eval(info['js']);
		}
	});
	return false;
}
function reportError(id) {
	if(id) {
		$.ajax({
			url:WEB_URL+"ajax.php?action=reportError&id="+escape(id),
			type:"POST",
			success:function(data){alert(data)}
		})
	}
}
function recommend(id) {
	if(id) {
		$.ajax({
			url:WEB_URL+"ajax.php?action=recommend&id="+id,
			type:"POST",
			success:function(data){alert(data); location.reload();}
		});
	}
}
function delFav(form){
	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=music&typeid="+escape(music_id_str);
	} else {
		alert('请选择列表！');	
	}
}
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 {
		alert('请选择列表！');	
	}
}
function delFavSpecial(id) {
	if(confirm('你确定要从收藏中删除吗？') && id) {
		location.href = WEB_URL+"member/fav.php?action=del&type=special&typeid="+id;
	}
	return false;
}
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+')'); alert(info['msg']); if(info['url']){location.href=info['url']}}
		});
	}
}
function mLogin(url) {
	if($('#name').val()=="") {
		alert('会员名不能为空！'); $('#name').focus(); return false;
	}
	if($('#pwd').val()=="") {
		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").html(info['hit']); $("#add_download").html(info['download']);}
	});
}
function lostPwd() {
	var html = '<div align="left"><form onsubmit="return doLostPwd()">用户名：<input type="text" name="uname" id="uname" /><br>邮　件：<input type="text" name="mail" id="mail" /><br><input type="submit" value="确定" />&nbsp;<span id="losePwdMsg" style="color=red; font-size:12px"></span></form></div>';
	showDialog(html, 300);
	return false;
}
function doLostPwd() {
	var uname = $('#uname').val();
	if(uname == '') {
		alert('用户名必须填写！'); $('#uname').focus(); return false;
	}
	var mail = $('#mail').val();
	if(mail == '') {
		alert('注册邮件必须填写！'); $('#mail').focus(); return false;
	}
	$('#losePwdMsg').html('系统正在处理...');
	$.ajax({
		url:WEB_URL+'ajax.php?action=lostPwd&uname='+uname+'&mail='+mail,
		type:'POST',
		success:function(data){
			var info = eval('('+data+')');
			if(info['msg']) {
				alert(info['msg']);
			}
			if(info['url']) {
				location.href=info['url'];
			}
			if(info['js']) {
				eval(info['js']);
			}
		}
	});
	$('#losePwdMsg').html('');
	return false;
}
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 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").html(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").html(data)}
	});
}
function selectOneArtist(value) {
	$$("artist").value = value;
}
function delUploadSpecial(id) {
	if(id && confirm('你确认要删除该专辑吗？')) {
		location.href = WEB_URL+'member/m_special.php?action=del&id='+encodeURIComponent(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);
	}
}

