function trim(s)
{
	if ( s == null || s == "" ) return s;

	var c, i, start, end;

	for( i=0; i < s.length && ((c = s.charAt(i)) == " " || c == "\t"); i++ );
	start = i;
	if ( s.length == start ) return "";

	for( i=s.length-1; i >= 0 && ((c = s.charAt(i)) == " " || c == "\t"); i-- );
	end = i;

	return s.substring(start, end+1);
}


function checkAll(chk)
{
	var f = document.Form1;
	
	for ( var i=0; i < f.elements.length; i++ ) 
	{
		if ( f.elements[i].type == "checkbox" && f.elements[i].id.indexOf("checkID") > 0 && f.elements[i].disabled == false)
		{
			f.elements[i].checked = chk.checked;
		}
	}
}


function getCheckID()
{
	var f = document.Form1;
	var strValue = "";
	
	for ( var i=0; i < f.elements.length; i++ ) 
	{
		if ( f.elements[i].type == "checkbox" && f.elements[i].id.indexOf("checkID") > 0 && f.elements[i].checked)
		{
			if (strValue != "") strValue += ",";
			strValue += f.elements[i].value;
		}
	}
	
	return strValue;
}

function saveAll()
{
	var f = document.Form1;
	var strValue = "";
	
	for ( var i=0; i < f.elements.length; i++ ) 
	{
		if ( f.elements[i].type == "checkbox" && f.elements[i].id.indexOf("checkID") > 0)
		{
			if (strValue != "") strValue += ",";
			strValue += f.elements[i].value;
		}
	}
	
	if (strValue == "")
		alert("´ãÀ» ³ë·¡°¡ ¾ø½À´Ï´Ù.");
	else
		saveTrackToMyAlbum(strValue);
}

function saveSelect()
{	
	var strValue = getCheckID();
	
	if (strValue == "")
		alert("´ãÀ» ³ë·¡¸¦ ¼±ÅÃÇÏ¼¼¿ä.");
	else
		saveTrackToMyAlbum(strValue);
}


function moveSelect()
{
	var f = document.Form1;
	var strValue = "";
	
	for ( var i=0; i < f.elements.length; i++ ) 
	{
		if ( f.elements[i].type == "checkbox" && f.elements[i].id.indexOf("checkID") > 0 && f.elements[i].checked)
		{
			if (strValue != "") strValue += ",";
			strValue += f.elements[i].albumNo + "|" + f.elements[i].value;
		}
	}
	
	if (strValue == "")
		alert("ÀÌµ¿ÇÒ ³ë·¡¸¦ ¼±ÅÃÇÏ¼¼¿ä.");
	else
		moveTrackToMyAlbum(strValue);
}

function goArtistPage(artistID)
{
	location.href = "http://music.imbc.com/RetrieveArtistInfo.aspx?artistID=" + artistID;
}

function goArtistPageBlank(artistID)
{
	window.open("http://music.imbc.com/RetrieveArtistInfo.aspx?artistID=" + artistID);
}


function goAlbumPage(albumID)
{
	location.href = "http://music.imbc.com/RetrieveAlbumInfo.aspx?albumID=" + albumID;
}

function goAlbumPageBlank(albumID)
{
	window.open("http://music.imbc.com/RetrieveAlbumInfo.aspx?albumID=" + albumID);
}


function saveTrackToMyAlbum(trackIDs)
{
	window.open("http://music.imbc.com/MyAlbum/RegisterMyAlbumSongInfo.aspx?trackIDs=" + trackIDs, "_RegiSong", "width=360, height=180");
}


function moveTrackToMyAlbum(trackIDs)
{
	window.open("http://music.imbc.com/MyAlbum/MoveMyAlbumSongInfo.aspx?trackIDs=" + trackIDs, "_MoveSong", "width=360, height=180");
}


function saveMVToMyAlbum(mvID)
{
	window.open("http://music.imbc.com/MyAlbum/RegisterMyMVInfo.aspx?mvID=" + mvID, "_RegiMV", "width=360, height=180");
}


function saveMyArtist(artistID)
{
	window.open("http://music.imbc.com/MyAlbum/RegisterMyArtistInfo.aspx?artistID=" + artistID, "_RegiArtist", "width=360, height=180");
}


function saveMyMusicAlbum(albumID)
{
	window.open("http://music.imbc.com/MyAlbum/RegisterMyMusicAlbumInfo.aspx?albumID=" + albumID, "_RegiMyMusicAlbum", "width=360, height=180");
}

function viewLyrics(trackID)
{
	window.open("http://music.imbc.com/RetrieveTrackLyrics.aspx?trackID=" + trackID, "_viewLyrics", "width=360, height=550");
}

function downloadMP3(trackIDs)
{
	window.open("http://music.imbc.com/Charge/MP3Download.aspx?trackIDs=" + trackIDs, "_downloadMp3", "width=360, height=490");
}

function downloadAlbumMP3(albumID)
{
	window.open("http://music.imbc.com/Charge/MP3Download.aspx?albumID=" + albumID, "_downloadMp3", "width=360, height=490");
}

function downloadSelect()
{	
	var strValue = getCheckID();
	
	if (strValue == "")
		alert("±¸ÀÔÇÒ ³ë·¡¸¦ ¼±ÅÃÇÏ¼¼¿ä.");
	else
		downloadMP3(strValue);
}


function playMusic(trackIDs)
{
//	var MusicPlayerWin = window.open("http://music.imbc.com/Player/PlayerOCX.aspx?playerURL=http://music.imbc.com/Player/MusicPlayer.aspx?trackIDs=" + trackIDs, "_playMusic", "width=400, height=200");
	var MusicPlayerWin = window.open("http://music.imbc.com/Player/MusicPlayer.aspx?trackIDs=" + trackIDs, "_playMusic", "width=1, height=1");
	if (MusicPlayerWin.focus) MusicPlayerWin.focus();
}

function playAll()
{
	var f = document.Form1;
	var strValue = "";
	
	for ( var i=0; i < f.elements.length; i++ ) 
	{
		if ( f.elements[i].type == "checkbox" && f.elements[i].id.indexOf("checkID") > 0 && f.elements[i].disabled == false)
		{
			if (strValue != "") strValue += ",";
			strValue += f.elements[i].value;
		}
	}
	
	if (strValue == "")
		alert("ÇÃ·¹ÀÌ ÇÒ ³ë·¡°¡ ¾ø½À´Ï´Ù.");
	else
		playMusic(strValue);
}

function playSelect()
{
	var strValue = getCheckID();
	
	if (strValue == "")
		alert("ÇÃ·¹ÀÌ ÇÒ ³ë·¡¸¦ ¼±ÅÃÇÏ¼¼¿ä.");
	else
		playMusic(strValue);
}


function playMV(mvID)
{
	var MVPlayerWin = window.open("http://music.imbc.com/Player/PlayerOCX.aspx?mvID=" + mvID, "_playMV", "width=1, height=1");
	if (MVPlayerWin.focus) MVPlayerWin.focus();
//	objMusicPlayer.Popup("http://music.imbc.com/Player/VideoPlayer.aspx?mvID=" + mvID, 0, 0);
}

function isSP2Win()
{
	if (window.navigator.userAgent.indexOf("SV1") != -1)
	{
		return true;
	}
	else
	{
		return false;
	}
}

function isIE70Win()
{
	if (window.navigator.userAgent.indexOf("MSIE 7") != -1)
	{
		return true;
	}
	else
	{
		return false;
	}
}

function winResize(winX,winY)
{
	window.resizeTo(winX, winY);
	
	if (isSP2Win()) 
		window.resizeBy(0, 20);
	else if (isIE70Win())
		window.resizeBy(0, 40);

//	  var Dwidth = winX - 25; 
//    var Dheight = winY - 40; 
//    var divEl = document.createElement("div"); 
//    divEl.style.position = "absolute"; 
//    divEl.style.left = "0px"; 
//    divEl.style.top = "0px"; 
//    divEl.style.width = "100%"; 
//    divEl.style.height = "100%"; 
//
//    document.body.appendChild(divEl); 
//
//    window.resizeBy(Dwidth-divEl.offsetWidth, Dheight-divEl.offsetHeight); 
//    document.body.removeChild(divEl); 

}