window.onerror=function(){ return true; };
CurrentID = 1;
function ChangeLayer(iSrc)
{
	var TarOB = eval("document.all.VW_" + CurrentID);
	if(TarOB != null){TarOB.style.display = "none";}

	var SrcOB = eval("document.all.VW_" + iSrc);
	SrcOB.style.display = "block";

	var TarOB = eval("document.all.VC_" + CurrentID);
	var SrcOB = eval("document.all.VC_" + iSrc);
	TarOB.className = "right238_BG_select2";
	SrcOB.className = "right238_BG_select";
	CurrentID = iSrc;
}
$$ = function(em) {
    if (document.getElementById){ return document.getElementById(em); }
    else if (document.all){ return document.all[em]; }
    else if (document.layers){ return document.layers[em]; }
    else{ return null; }
};

$$F = function(em){	return document.getElementById(em).value;	};

function show_select(_title, _options, _input){
    option_obj = $$(_options);
    option_obj.style.display = (option_obj.style.display == '') ? 'none' : '';
    option_obj.onblur = function() { option_obj.style.display = 'none'; };
    option_obj.focus();
    for (var i = 0; i < option_obj.childNodes.length; i++){
        option_obj.childNodes[i].onmouseover = function(){ this.className = 'options_over pointer'; };
        option_obj.childNodes[i].onmouseout = function(){ this.className = 'options_out pointer'; };
        option_obj.childNodes[i].onclick = function(){
            $$(_title).innerHTML = this.innerHTML;
            $$(_input).value = this.id;
            option_obj.blur();
            option_obj.style.display = 'none';
        }
    }
 };


function get_tags(parentobj, tag){
    if (typeof parentobj.getElementsByTagName != 'undefined'){ return parentobj.getElementsByTagName(tag);
    }else if (parentobj.all && parentobj.all.tags){ return parentobj.all.tags(tag);
    }else{ return new Array(); }
};

function clk(_act, _id) {
    var v = [];
    var a = get_tags($$(_id), 'input');

    for (var i = 0; i < a.length; i++) {
        if (_act == 'all' ) {a[i].checked = true;}
        else if (_act == 'un' ) { a[i].checked = (a[i].checked) ? false : true; }
		else if (_act == 'rundom' ) {
			var checkobj=document.getElementById(_id);
			var cboxs=checkobj.getElementsByTagName("input");
			var num=cboxs.length;			
			for(i=0;i<cboxs.length;i++){
				if(cboxs[i].type=="checkbox") cboxs[i].checked=false;
			}
			for(j=0;j<51;j++){
				var roundNum=Math.random()*num;
				if(cboxs[roundNum].type=="checkbox") {
						cboxs[roundNum].checked=true;
				}
			}			
		}else { if (0 < a[i].value && a[i].checked){ v.push(a[i].value); } }
    }
    if ( 'play' == _act ) {
        if (3 > v.length){ 
			alert('至少选择三首歌曲以上才能进行连播！'); 
			return; 
		}else if(v.length > 60){
			alert('一次最多连续播放30首歌曲！'); 
			return; 
		}else{
			window.open('../../playsong.php?id=' + v.join(','), 'play');
		}
    }
};
function ChangIterm(s,ss,sss,n) {
        for(var i=1;i<=5;i++){
            var curC=document.getElementById(s+i);
            var curB=document.getElementById(ss+i);
            if(n==i){
                curC.style.display="block";
                curB.className=sss;
            }else{
                curC.style.display="none";
                curB.className=""
            }
       } 
}

function ChangClass(s,ss,sss,n) {
        for(var i=1;i<=5;i++){
            var curC=document.getElementById(s+i);
            var curB=document.getElementById(ss+i);
            if(n==i){
                curC.style.display="block";
                curB.className=sss;
            }else{
                curC.style.display="none";
                curB.className="";
        }
     }
}

function ChangUser(s,ss,sss,n) {
        for(var i=1;i<=5;i++){
            var curC=document.getElementById(s+i);
            var curB=document.getElementById(ss+i);
            if(n==i){
                curC.style.display="block";
                curB.className=sss;
            }else{
                curC.style.display="none";
                curB.className="";
        }
     }
}

function setMenuPosition(showid, offset) {
var showobj = $Obj(showid);
var menuobj = $Obj(showid + '_menu');
if(isUndefined(offset)) offset = 0;
if(showobj) {
   showobj.pos = fetchOffset(showobj);
   showobj.X = showobj.pos['left'];
   showobj.Y = showobj.pos['top'];
   showobj.w = showobj.offsetWidth;
   showobj.h = showobj.offsetHeight;
   menuobj.w = menuobj.offsetWidth;
   menuobj.h = menuobj.offsetHeight;
   if(offset != -1) {
    menuobj.style.left = (showobj.X + menuobj.w > document.body.clientWidth) && (showobj.X + showobj.w - menuobj.w >= 0) ? showobj.X + showobj.w - menuobj.w + 'px' : showobj.X + 'px';
    menuobj.style.top = offset == 1 ? showobj.Y + 'px' : (offset == 2 || ((showobj.Y + showobj.h + menuobj.h > document.documentElement.scrollTop + document.documentElement.clientHeight) && (showobj.Y - menuobj.h >= 0)) ? (showobj.Y - menuobj.h) + 'px' : showobj.Y + showobj.h + 'px');
   } else if(offset == -1) {
    menuobj.style.left = (document.body.clientWidth-menuobj.w)/2 + 'px';
    var divtop = document.documentElement.scrollTop + (document.documentElement.clientHeight-menuobj.h)/2;
    if(divtop > 100) divtop = divtop - 100;
    menuobj.style.top = divtop + 'px';
   }
   if(menuobj.style.clip && !is_opera) {
    menuobj.style.clip = 'rect(auto, auto, auto, auto)';
   }
}
}
function fetchOffset(obj) {
var left_offset = obj.offsetLeft;
var top_offset = obj.offsetTop;
while((obj = obj.offsetParent) != null) {
   left_offset += obj.offsetLeft;
   top_offset += obj.offsetTop;
}
return { 'left' : left_offset, 'top' : top_offset };
}
function $Obj(id) {
return document.getElementById(id);
}
function isUndefined(variable) {
return typeof variable == 'undefined' ? true : false;
}
function strlen(str) {
    var ie
return (ie && str.indexOf('\n') != -1) ? str.replace(/\r?\n/g, '_').length : str.length;
}
function insertContent(target, text) {
var obj = $Obj(target);
selection = document.selection;
if(!obj.hasfocus) {
   obj.focus();
}
if(!isUndefined(obj.selectionStart)) {
   var opn = obj.selectionStart + 0;
   obj.value = obj.value.substr(0, obj.selectionStart) + text + obj.value.substr(obj.selectionEnd);
} else if(selection && selection.createRange) {
   var sel = selection.createRange();
   sel.text = text;
   sel.moveStart('character', -strlen(text));
} else {
   obj.value += text;
}
}
//显示表情菜单
function showFace(showid, target) {
var div = $Obj('face_bg');
if(div) {
   div.parentNode.removeChild(div);
}
div = document.createElement('div');
div.id = 'face_bg';
div.style.position = 'absolute';
div.style.left = div.style.top = '0px';
div.style.width = '50%';
div.style.height = document.body.scrollHeight + 'px';
div.style.backgroundColor = '#000';
div.style.zIndex = 10000;
div.style.display = 'none';
div.style.filter = 'progid:DXImageTransform.Microsoft.Alpha(opacity=0,finishOpacity=100,style=0)';
div.style.opacity = 0;
div.onclick = function() {
   $Obj(showid+'_menu').style.display = 'none';
   $Obj('face_bg').style.display = 'none';
}
$Obj('face_show').appendChild(div);

if($Obj(showid + '_menu') != null) {
   $Obj(showid+'_menu').style.display = '';
} else {
   var faceDiv = document.createElement("div");
   faceDiv.id = showid+'_menu';
   faceDiv.className = 'facebox';
   faceDiv.style.position = 'absolute';
   var faceul = document.createElement("ul");
   for(i=1; i<31; i++) {
    var faceli = document.createElement("li");
    faceli.innerHTML = '<img src="images/face/'+i+'.gif" onclick="insertFace(\''+showid+'\','+i+', \''+ target +'\')" style="cursor:pointer; position:relative;" />';
    faceul.appendChild(faceli);
   }
   faceDiv.appendChild(faceul);
   $Obj('face_show').appendChild(faceDiv)
}
//定位菜单
setMenuPosition(showid, 0);
div.style.display = '';
}
//插入表情
function insertFace(showid, id, target) {
var faceText = '[em:'+id+']';
if($Obj(target) != null) {
   insertContent(target, faceText);
}
$Obj(showid+'_menu').style.display = 'none';
$Obj('face_bg').style.display = 'none';
}

function textCounter(obj, showid, maxlimit) {
var len = strLen(obj.value);
var showobj = $Obj(showid);
if(len > maxlimit) {
   obj.value = getStrbylen(obj.value, maxlimit);
   showobj.innerHTML = '0';
} else {
   shengyu = maxlimit - len+"个字";
   showobj.innerHTML = "还剩"+ shengyu;
}
if(maxlimit - len > 0) {
   showobj.parentNode.style.color = "";
} else {
   showobj.parentNode.style.color = "red";
}

}
function getStrbylen(str, len) {
var num = 0;
var strlen = 0;
var newstr = "";
var obj_value_arr = str.split("");
for(var i = 0; i < obj_value_arr.length; i ++) {
   if(i < len && num + byteLength(obj_value_arr[i]) <= len) {
    num += byteLength(obj_value_arr[i]);
    strlen = i + 1;
   }
}
if(str.length > strlen) {
   newstr = str.substr(0, strlen);
} else {
   newstr = str;
}
return newstr;
}
function byteLength (sStr) {
aMatch = sStr.match(/[^\x00-\x80]/g);
return (sStr.length + (! aMatch ? 0 : aMatch.length));
}
function strLen(str) {
var charset = document.charset; 
var len = 0;
for(var i = 0; i < str.length; i++) {
   len += str.charCodeAt(i) < 0 || str.charCodeAt(i) > 255 ? (charset == "utf-8" ? 3 : 2) : 1;
}
return len;
}
