﻿// 常用JS类

function CreateAlphaBg() {
	document.write('<div id="AlphaBg" style="width:500px;top:0;left:0;display:none;position:absolute;z-index:6;"><div style="height:460px;background:black;filter:alpha(opacity=30);-moz-opacity:0.30;opacity:0.30;">&nbsp;</div></div>');
}
function ShowAlphaBg() {
	document.getElementById("AlphaBg").style.display="block";
}
function UnShowAlphaBg() {
	document.getElementById("AlphaBg").style.display="none";
}
function DivChange(name,splittime,count,ismove,changed_callback)
{
    this.count = count;
    this.splittime = splittime;
    this.now = 0;
    this.name = name;
    this.timeid1;
    this.timeid2;
    this.ismove = ismove;
    this.changed_callback = changed_callback;
    this.next_button = document.getElementById(name+"_next_button");
    this.previous_button = document.getElementById(name+"_previous_button");
    this.isplay = true;
    var self = this;
    this.SetFocus = function() {
		if(self.now>=self.count) self.now=0;
		self.now = self.now+1;
        self.SelectLayer(self.now);
    };
	this.SelectLayer = function(i) {
      for(var j=1;j<=self.count;j++) {
        try
		    {
            if (j==i) {
                document.getElementById(name+"_panel_"+j).style.display="block";
                //document.getElementById(name+"__"+j).style.display="block";
            } else {
		        document.getElementById(name+"_panel_"+j).style.display="none";
		        //document.getElementById(name+"_panel_"+j).style.display="block";
            }
        }catch(e)
		    {}
      }
      if(typeof self.changed_callback == "function")
      {
        self.changed_callback(i);
      }
    };
    this.ChangeImg = function() {
        if(self.isplay)
        {
            self.timeid1 = setTimeout(self.SetFocus,self.splittime);
        }
        self.timeid2 = setTimeout(self.ChangeImg,self.splittime);
    };
	this.ChangeImg();
    
    this.Stop = function()
    {
        clearTimeout(this.timeid1);
        clearTimeout(this.timeid2);
    };
    this.Start = function()
    {
        this.ChangeImg();
    };
    this.Reset = function()
    {
        this.Stop();
        this.Start();
    };
    
	if(this.ismove!=1)
	{
        if(this.next_button)
        {
            this.next_button.onclick = function()
            {
			    self.Stop();
                if(self.now>=self.count)
                {
                    self.now = 0;
                }
                self.SelectLayer(self.now+1);
		        self.now = self.now+1;
			    self.Start();
            }
        }
        if(this.previous_button)
        {
            this.previous_button.onclick = function()
            {
			    self.Stop();
                if(self.now<=1)
                {
                    self.now = self.count+1;
                }
                self.SelectLayer(self.now-1);
			    self.now = self.now-1;
			    self.Start();
            }
        }
        for(var j=1;j<=count;j++)
        {
		    try
		    {
			    var now_button = document.getElementById(name+"_button_"+j);
			    if(now_button)
			    {
				    now_button.onclick = function()
				    {
					    self.Stop();
					    var num = parseInt(this.id.replace(name+"_button_",""));
					    self.SelectLayer(num);
					    self.now = num;
					    self.Start();
				    }
			    }
		    }catch(e)
		    {}
        }
    }
    else
    {
        if(this.next_button)
        {
            this.next_button.onmouseover = function()
            {
			    self.Stop();
                if(self.now>=self.count)
                {
                    self.now = 0;
                }
                self.SelectLayer(self.now+1);
		        self.now = self.now+1;
			    self.Start();
            }
        }
        if(this.previous_button)
        {
            this.previous_button.onmouseover = function()
            {
			    self.Stop();
                if(self.now<=1)
                {
                    self.now = self.count+1;
                }
                self.SelectLayer(self.now-1);
			    self.now = self.now-1;
			    self.Start();
            }
        }
        for(var j=1;j<=count;j++)
        {
		    try
		    {
			    var now_button = document.getElementById(name+"_button_"+j);
			    if(now_button)
			    {
				    now_button.onmouseover = function()
				    {
					    self.Stop();
					    var num = parseInt(this.id.replace(name+"_button_",""));
					    self.SelectLayer(num);
					    self.now = num;
				    }
				    now_button.onmouseout = function()
				    {
					    self.Start();
				    }
			    }
		    }catch(e)
		    {}
        }
    }
    for(var j=1;j<=count;j++)
    {
		try
		{
			var now_panel = document.getElementById(name+"_panel_"+j);
			if(now_panel)
			{
				now_panel.onmouseover = function()
				{
					self.Stop();
				}
				now_panel.onmousemove = function()
				{
					self.Stop();
				}
				now_panel.onmouseout = function()
				{
					self.Start();
				}
			}
		}catch(e)
		{}
    }
};
//
function InfoWindow(windowid,titleid,closeid,r)
{
	this.move = false;
	this.windowObject = document.getElementById(windowid);
	this.windowTitle = document.getElementById(titleid);
	this.windowClose = document.getElementById(closeid);
	this.windowObject.style.display = "block";
	this.r = r;
	var self = this;
	
	ShowAlphaBg();
	//this.windowObject.firstChild.onmousedown=function(){return false;};
		//this.windowObject.firstChild.onmousedown=function(){return false;};
	this.windowTitle.onmousedown=function(a){
		var d=document;if(!a)a=window.event;
			var x=a.layerX?a.layerX:a.offsetX,y=a.layerY?a.layerY:a.offsetY;
			if(self.windowTitle.setCapture)
				self.windowTitle.setCapture();
			else if(window.captureEvents)
				window.captureEvents(Event.MOUSEMOVE|Event.MOUSEUP);
			self.windowTitle.onmousemove=function(a){
				if(!a)a=window.event;
				if(!a.pageX)a.pageX=a.clientX;
				if(!a.pageY)a.pageY=a.clientY;
				var tx=a.pageX-x,ty=a.pageY-y-5;
				var newx = tx<self.r[0]?self.r[0]:tx>self.r[1]?self.r[1]:tx;
				var newy = ty<self.r[2]?self.r[2]:ty>self.r[3]?self.r[3]:ty;
				self.windowObject.style.left = newx+"px";
				self.windowObject.style.top = newy+"px";
			};
	
			self.windowTitle.onmouseup=function(){
				if(self.windowTitle.releaseCapture)
					self.windowTitle.releaseCapture();
				else if(window.captureEvents)
					window.captureEvents(Event.MOUSEMOVE|Event.MOUSEUP);
				self.windowTitle.onmousemove=null;
				self.windowTitle.onmouseup=null;
			};
	};
	this.windowClose.onclick = function()
	{
	    UnShowAlphaBg();
		self.windowObject.style.display = "none";
	};
}
function Ajax() {
	this.xmlhttp = false;
	if(window.XMLHttpRequest) { 
		this.xmlhttp = new XMLHttpRequest();
		if (this.xmlhttp.overrideMimeType)
			this.xmlhttp.overrideMimeType("text/xml");
	}
	else if (window.ActiveXObject) {
		try {
			this.xmlhttp = new ActiveXObject("Msxml2.XMLHTTP.3.0");
		} catch (e) {
			try {
				this.xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e) {}
		}
	}
	
	this.GetData = function(url, obj, callback) {
		var self = this;
		if(!this.xmlhttp) { alert("请更新你的浏览器"); return; }
		this.xmlhttp.onreadystatechange = (typeof callback == "function") ? callback : function() {
			if (self.xmlhttp.readyState == 4) {
				if (self.xmlhttp.status == 200)
					$(obj).innerHTML = self.xmlhttp.responseText;
				else
					$(obj).innerHTML = "加载失败";
			}
		}
		this.xmlhttp.open("GET", url, true);
		this.xmlhttp.setRequestHeader("If-Modified-Since", "0");
		this.xmlhttp.send(null);
	}
	
	this.PostData = function(url, data, obj, callback) {
		var self = this;
		if(!this.xmlhttp) { alert("请更新你的浏览器"); return; }
		this.xmlhttp.onreadystatechange = (typeof callback == "function") ? callback : function() {
			if (self.xmlhttp.readyState == 4) {
				if (self.xmlhttp.status == 200)
					$(obj).innerHTML = self.xmlhttp.responseText;
				else
					$(obj).innerHTML = "加载失败";
			}
		}
		this.xmlhttp.open("POST", url, true);
		this.xmlhttp.setRequestHeader("If-Modified-Since", "0");
		this.xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		this.xmlhttp.send(data);
	}
}
function Marquee(name,speed,splittime,height) {  
  this.interval;
  this.timeid1;  
  this.num = 1;
  this.stopscroll = false;
  var self = this;
  var wrapObj = document.getElementById(name + "_wrap");
  var contentObj = document.getElementById(name + "_content");
  var bottomObj = document.getElementById(name + "_bottom");  
  var topObj = document.getElementById(name + "_top");
  var up_button = document.getElementById(name+"_up_button");
  var down_button = document.getElementById(name+"_down_button");
  this.rank = Math.floor(contentObj.offsetHeight/height);
  bottomObj.innerHTML = contentObj.innerHTML;
  topObj.innerHTML = contentObj.innerHTML;
  wrapObj.scrollTop = contentObj.offsetHeight;
  
  this.ScrollUP = function() {
    if(self.stopscroll==true) return;
    if(wrapObj.scrollTop<self.num*height+contentObj.offsetHeight) {
      wrapObj.scrollTop+=speed;
    }
    else {
      if(self.num==self.rank) {
        wrapObj.scrollTop = contentObj.offsetHeight;
        self.num=1;
      }
      else
        self.num++;
      self.Stop();
      self.timeid1 = setTimeout(self.Start,splittime);
    }
  };
  this.ScrollDown = function() {
    if(self.stopscroll==true) return;
    if(wrapObj.scrollTop>(self.num-2)*height+contentObj.offsetHeight)
      wrapObj.scrollTop-=speed;
    else {
      if(wrapObj.scrollTop<contentObj.offsetHeight) {
        wrapObj.scrollTop = contentObj.offsetHeight*2-height;
        self.num=self.rank;
      }
      else
        self.num--;
      self.Stop();
      self.timeid1 = setTimeout(self.Start,splittime);
    }
  };
  this.Start = function() {
    self.interval = setInterval(self.ScrollUP,1);
  };
  this.Stop = function() {
    clearInterval(self.interval);
    clearTimeout(self.timeid1);
  };
  this.ClickUP = function() {
    self.Stop();
    self.interval = setInterval(self.ScrollUP,1);
  }
  this.ClickDown = function() {
    self.Stop();
    self.interval = setInterval(self.ScrollDown,1);
  }
  if(up_button) {
    up_button.onmouseover = function() { self.ClickUP(); }
  }
  if(down_button) {
    down_button.onmouseover = function() { self.ClickDown(); }
  }
  wrapObj.onmouseover = function() { self.stopscroll=true; };
  wrapObj.onmouseout = function() { self.stopscroll=false; };
  self.timeid1 = setTimeout(self.Start,splittime);
}
function CheckUser()
{
    this.KugooID = 0;
    this.IsLogin = false;
    this.myCookies = document.cookie.toLowerCase();
    this.re=/kugooid=(\d+)&kugoopwd=/g;
    if(this.re.test(this.myCookies))
    {
        this.IsLogin = true;
        this.KugooID= parseInt(RegExp.$1);
    }
    else
    {
        this.IsLogin = false;
        ShowLogin();
    }
}
function sleep(n) {   
  var start=new Date().getTime();
  while(true) {
    if(new Date().getTime()-start>n)
      break;
  }
}
function ShowSignerTipInfo(singerid,singername,a)
{
	sleep(200);
	var max_width = 632;
	var max_height = 528;
	var place_x = 0;
	var place_y = 0;
	var tip_info_width = 247;
	var tip_info_height = 57;
    if(!a)a=window.event;
	if(!a.pageX)a.pageX=a.clientX;
	if(!a.pageY)a.pageY=a.clientY;
    var infostr = "";
    infostr+='  <div class="tip_info_inside">';
    infostr+='    <div class="tip_info_inside2">';
    infostr+='      <div class="tip_info_title blue ">****<a href="/minihome/singer/songlist.aspx?singerid='+singerid+'" class="orange2">'+singername+'</a>，！</div>';
    infostr+='      <div class="tip_info_content" ><span class="tip_info_button"><a href="javascript:void(0)" onclick="RelateNews(\''+singername+'\')" title="*'+singername+'*" >**</a></span><span class="tip_info_button"><a href="http://sdn.kugoo.com/link_641.html?url=http://www.kugou.com/minihome/singer/songlist.aspx?singerid='+singerid+'">***</a></span><span class="tip_info_button"><a href="http://sdn.kugoo.com/link_650.html?url=http://bar.kugou.com/singer/'+singerid+'.htm?k=9CEE9A4A56" target="_blank">****</a></span><span class="tip_info_button"><a href="http://sdn.kugoo.com/link_645.html?url=defau.html?Key='+escape(singername)+'">***</a></span></div>';
    infostr+='    </div>';
    infostr+='  </div>';
    place_x = a.clientX;
    place_y = a.clientY;
    if(place_y+tip_info_height>max_height)
    {
    	place_y = place_y-tip_info_height;
    }
    if(place_x+tip_info_width>max_width)
    {
    	place_x = place_x-tip_info_width;
    }
    var tip_info = document.getElementById("tip_info");
    tip_info.innerHTML = infostr;   
    tip_info.style.left = place_x+"px";
    tip_info.style.top = place_y+"px";
    tip_info.style.display = "block";
}
function UnShowSignerTipInfo()
{
    document.getElementById("tip_info").style.display = "none";
}
function JustShowSignerTipInfo()
{
    document.getElementById("tip_info").style.display = "block";
}
function AddSingerTipEvent()
{
    var allLinks = document.links;
    for(var i=0;i<allLinks.length;i++)
    {
        if(allLinks[i].id.indexOf("singer_")==0)
        {
            allLinks[i].onmouseover = function(m)
            {
                var singerid = this.id.split('_')[1];
                if(this.title != null && this.title != "") {this.pop = this.title; this.title = "";}
                ShowSignerTipInfo(singerid,this.pop,m);
            }
            allLinks[i].onmouseout = UnShowSignerTipInfo;
        }
    }
}
function showflash(url, w, h, t) {
	document.write('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" width="'+w+'" height="'+h+'">');
	document.write('<param name="movie" value="'+url+'">');
	document.write('<param name="quality" value="high">');
	if(t) document.write('<param name="wmode" value="transparent">');
	document.write('<param name="menu" value="false">');
	document.write('<embed src="'+url+'" width="'+w+'" height="'+h+'" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" wmode="transparent"></embed>');
	document.write('</object>');
}

function checkComment(form) {
	if(form.Content.value.length==0) {
		alert("内容不能为空！");
		form.Content.focus();
		return false;
  	}
	if(form.Content.value.length>300) {
		alert("内容太长了！");
		return false;
	}
	return true;
}



