﻿var logined=false;
var openForm;
function ControlSearchValue(trigger , default_value){
    this.searchInput = document.getElementById(trigger);
    this.value = default_value;
    this.init();
}

ControlSearchValue.prototype.init = function(){
    this.searchInput.value = this.value;
    this.searchInput.style.color = "#ccc";
}

ControlSearchValue.prototype.judgeInput = function(){
    var _this = this;
    this.searchInput.onfocus = function(){
        _this.searchInput.style.color = "#666";
        if( _this.searchInput.value == _this.value ) _this.searchInput.value = "";
    }
    this.searchInput.onblur = function(){
        var current_value = _this.searchInput.value;
        if(current_value == ""){
             _this.searchInput.value = _this.value;
             _this.searchInput.style.color = "#ccc";
        }
    }
}


//Fuc provide many methods to do with node
var Func = {
	getNode : function( elem ){	
		var value = [];
		for(var i=0 ; i<elem.length ; i++ ){
			if (elem[i].nodeType == 1){
				value.push( elem[i] );
			}
		}
		return value;
	},
	getChildsByClassName : function( /*Father Node */ fartherNode , /*Class name to find*/ className ){//return a array of elemNode
		var elem = [];
		var child = [];
		elem = Func.getNode(fartherNode.childNodes);
		for(var i=0 ; i<elem.length ; i++ ){
			if(elem[i].className == className){
				child.push( elem[i] );
			}
		}
		return child;
	}
};

function openTable(  /* Element ID */ target ){
	if(!document.getElementById(target)) return;
	this.target = document.getElementById(target);
	var now = this;
	setTimeout(function(){
		openTable.show(now.target);
	}, 100);
	var close = Func.getChildsByClassName( this.target , "closeDiv" );
	for( i=0 ; i<close.length ; i++ ){
		close[i].onclick = function(){
			openTable.close(now.target);
		};
	}
}
openTable.show = function( target ){
	var lock = document.getElementById("lockBack");
	lock.style.display = "block";
	target.style.display = "block";
	if(target.id=="userLogin")
	    document.getElementById("userName").focus();
}
openTable.close = function( target ){
	var lock = document.getElementById("lockBack");
	lock.style.display = "none";
	target.style.display = "none";
	return false;
}
window.onload = function(){
    var searchbox = new ControlSearchValue("mainSearch" , "搜索专辑/歌手/音乐");
    searchbox.judgeInput();
}

function doLogin()
{
     if(!logined) 
     {   
         var open = new openTable( "userLogin" );
     }
}

function openplayer(url)
{
    if(getCookie("player").indexOf("true")<0)
    {
        setSessionCookie("player","true");
        openForm=window.open(url,"","width=560,height=380,resizable=no,scrollbars=no,status=no,toolbar=no,menubar=no,location=no,left="+((window.screen.width-560)/2)+",top="+((window.screen.height-380)/2));
    }
    else if(getCookie("ReallyPlaying").indexOf("true")<0)
    {
		setTimeout(function(){openForm=window.open(url,"","width=560,height=380,resizable=no,scrollbars=no,status=no,toolbar=no,menubar=no,location=no,left="+((window.screen.width-560)/2)+",top="+((window.screen.height-380)/2));},1000);
    }    
    return false;
}

function setSessionCookie(sName,sValue)
{
    document.cookie   =   sName   +   "="   +   sValue ;   
}

function getCookie(sName)
{
    var reg = new RegExp("(^| )"+sName+"=([^;]*)(;|$)","gi");
	var ck = reg.exec(document.cookie);
	if(ck==null||typeof(ck) == "undefined"||ck.length==0)
	    return "false";
	if(ck[2] == null || typeof(ck[2]) == "undefined"||ck[2].length==0) 
	    return "false";
	return ck[2];
}

//show self_link area in head 08.8.12 by hr
function showquicklink(id,display)
{   
	document.getElementById(id).style.display=display;	
}

function getdiggcdBlogNews()
{
    var HttpRequest = new HTTPRequest();
    HttpRequest.onresponse=function(res)
    {
        if(res.responseText!="Error")
        {
            document.getElementById("journal").innerHTML=res.responseText;
        }
   }
   HttpRequest.send("action/getDiggCDBlogNews.aspx");
}
