
function doShowHidePanel(sid) 
		{
			titleid = "t_" + sid;
			contentid = "c_" + sid;
			if (document.getElementById(contentid).className=='content_block')
				{document.getElementById(contentid).className='content_none';
				document.getElementById(titleid).className='title_none';}
			else
				{document.getElementById(contentid).className='content_block';
				document.getElementById(titleid).className='title_block';}
}

function newShowHideBox(sid) 
    {
      titleid = "t_" + sid;
      contentid = "c_" + sid;
      if (document.getElementById(titleid).className=='title_block')
        {document.getElementById(contentid).style.display="none";
        document.getElementById(titleid).className='title_none';}
      else
        {document.getElementById(contentid).style.display="";
        document.getElementById(titleid).className='title_block';}
}

//Change class name:
function ChangeClass(sid,sclassname) {
	document.getElementById(sid).className = sclassname;
}
			
function insertSymbol(symbol){
	var obj=$('comment_content');
	if (document.selection)
	{
		obj.focus();
		sel = document.selection.createRange();
		sel.text = symbol;
	}
	else if (obj.selectionStart || obj.selectionStart == 0)
	{
		var startPos = obj.selectionStart;
		var endPos = obj.selectionEnd;
		obj.value = obj.value.substring(0, startPos)
					+ symbol
					+ obj.value.substring(endPos, obj.value.length);
	} 
	else
	{
		obj.value += symbol;
	}
}

function ShowFullLyric() {
	ChangeClass('lyric-short','lyric-short display-none');
	ChangeClass('lyric-full','lyric-full display-block');
	ChangeClass('cmd_view_full','display-none text-right fontSize-11');
	ChangeClass('cmd_view_short','display-block text-right fontSize-11');					
}

function ShowShortLyric() {
	ChangeClass('lyric-short','lyric-short display-block');
	ChangeClass('lyric-full','lyric-full display-none');
	ChangeClass('cmd_view_full','display-block text-right fontSize-11');
	ChangeClass('cmd_view_short','display-none text-right fontSize-11');					
}
                                                            
function show_embed_dialog(elt, skin){
	elt=$('eanchor');
	$('embed_image').src = '';
	var offset = Element.positionedOffset(elt);
	$('embed_dialog').style.top = (offset.top + 30) + 'px';
	$('embed_dialog').style.left = (offset.left-20)+'px';
	
	$('embed_image').src = '/images/fplayer'+skin+'_preview.gif';
	for (i = 0; i < 2; i++)
	{
		if ($('embed_text_'+i) != null)
		{
			$('embed_text_'+i).style.display = "none";
		}
	}
	$('embed_text_'+skin).style.display = "";
	
	Effect.Appear('embed_dialog', { duration: 0.5 });
}

function close_embed_dialog(){
	Effect.BlindUp('embed_dialog', { duration: 0.8 });			
	$('embed_image').src = '';
	for (i = 0; i < 4; i++)
	{
		if ($('embed_text_'+i) != null)
		{
			$('embed_text_'+i).style.display = "none";
		}
	}
}

function toggle_selectall(checkname, exby){
  for (i = 0; i < checkname.length; i++){
    if (checkname[i].type=='checkbox' && checkname[i].name != 'all')
      checkname[i].checked = exby.checked? true:false
  }
}

function ntoggle_selectall(obj){
  $$('.classForSel').each(function(item){
    item.checked = obj.checked?true:false;
  });
}

function nmymusic_submit(){
  var checkname = document.admin_form;
  var havecheck = false;
  $$('.classForSel').each(function(item){
    if (item.checked)
      havecheck=true;
  });
  if (!havecheck)
  {
    alert('Bạn phải chọn ít nhất 1 bài hát để thực hiện!');
    return false;
  }
  else
  {
    if (confirm('Bạn có chắc chắn muốn thực hiện hành động này?'))
      return true;
    else 
      return false;
  }  
}

function mymusic_submit()
{
	var checkname = document.admin_form;
	var havecheck = false;
	for (i = 0; i < checkname.length; i++)
  		if (checkname[i].type=='checkbox' && checkname[i].checked)
  		{
  			havecheck = true;
  			break;
  		}
  	if (!havecheck || (typeof(checkname.admin_action)!='undefined' && checkname.admin_action.value==0))
  	{
  		alert('Bạn phải chọn 1 hành động và ít nhất 1 bài hát để thực hiện!');
  		return false;
  	}
  	else
  	{
  		if (confirm('Bạn có chắc chắn muốn thực hiện hành động này?')){
  			return true;
  		} else {
  			return false;
  		}
  	}
}

function setHomepage()
{
if (document.all)
{
document.body.style.behavior='url(#default#homepage)';
document.body.setHomePage('http://www.tamtay.vn');

}
else if (window.sidebar)
{
if(window.netscape)
{
try
{
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
}
catch(e)
{
alert("Trình duyệt của bạn không hỗ trợ thao tác này. Nếu bạn muốn thực hiện tiếp, hãy làm theo hướng dẫn sau:\ngõ about:config vào thanh địa chỉ, sau đó thay đổi giá trị của tham số signed.applets.codebase_principal_support thành true");
}
}
var prefs = Components.classes['@mozilla.org/preferences-service;1'].getService(Components. interfaces.nsIPrefBranch);
prefs.setCharPref('browser.startup.homepage','http://www.tamtay.vn');
}
} 

function myCookie(name, value, options) {
    if (typeof value != 'undefined') { // name and value given, set cookie
        options = options || {};
        if (value === null) {
            value = '';
            options.expires = -1;
        }
        var expires = '';
        if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) {
            var date;
            if (typeof options.expires == 'number') {
                date = new Date();
                date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));
            } else {
                date = options.expires;
            }
            expires = '; expires=' + date.toUTCString(); // use expires attribute, max-age is not supported by IE
        }
        // CAUTION: Needed to parenthesize options.path and options.domain
        // in the following expressions, otherwise they evaluate to undefined
        // in the packed version for some reason...
        var path = options.path ? '; path=' + (options.path) : '';
        var domain = options.domain ? '; domain=' + (options.domain) : '';
        var secure = options.secure ? '; secure' : '';
        document.cookie = name+'='+ encodeURIComponent(value)+expires+path+domain+secure;
    } else { // only name given, get cookie
        var cookieValue = null;
        if (document.cookie && document.cookie != '') {
            var cookies = document.cookie.split(';');
            for (var i = 0; i < cookies.length; i++) {
                var cookie = cookies[i];
                cookie = cookie.replace(/^\s+|\s+$/g, '') ;
                if (cookie.substring(0, name.length + 1) == (name + '=')) {
                    cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
                    break;
                }
            }
        }
        return cookieValue;
    }
}

function toggle_popup()
{
	var popup = $('popupcheck').checked;
	myCookie('play_popup',null);
	myCookie('play_popup',popup,{ expires: 7, path: '/', domain: 'tamtay.vn', secure: false });
}

function get_popup_cookie(){
	var popup = myCookie('play_popup');
	if (popup==null){
		popup = true;
		myCookie('play_popup',popup,{ expires: 7, path: '/', domain: 'tamtay.vn', secure: false });
	}
	if (popup=='true')
		$('popupcheck').checked = true;
	else
		$('popupcheck').checked = false;		
}

function resizeImage(img,nsize)
{
	var nWidth=img.width;
	var	nHeight=img.height;	
	nScale = nWidth/nHeight;		
	//Check:
	if (nScale > 1) {
		nWidth = nsize;		
		nHeight = (nWidth*img.height)/img.width;
		//fix vertical-align:	
		nMargin = (nWidth - nHeight)/2;
		//Set style to image:
		img.width = nWidth;
		img.height = nHeight;
		img.style.margin = nMargin + 'px 0px';
		}
	else {
		//Return size:
		nHeight = nsize;
		nWidth = (nHeight*img.width)/img.height;
		//fix align:	
		nMargin = (nHeight - nWidth)/2;	
		//Set style to image:	
		img.width = nWidth;
		img.height = nHeight;
		img.style.margin = '0px ' + nMargin + 'px';
	}	
}

var pl_embed_code = '<object width="395" height="360"><param name="movie" value="http://music2.tamtay.vn/players/ttplayer_2.swf?path=http://music2.tamtay.vn/main/embed/type/2/id/__url__" /><param name="quality" value="high" /><param name="wmode" value="transparent" /><embed width="395" height="360" src="http://music2.tamtay.vn/players/ttplayer_2.swf?path=http://music2.tamtay.vn/main/embed/type/2/id/__url__" quality="high" wmode="transparent" type="application/x-shockwave-flash"></embed></object>';

function setPlaylistEmbedCode(ename, pid, auto)
{
  var str = pid;
  if (auto) str += '&auto=true';
    
  document.getElementById(ename).value = pl_embed_code.replace(/__url__/g,str);
}

function changeEmbedAutoPlay(elm, ename, pid)
{
  if(elm.checked)
    setPlaylistEmbedCode(ename, pid, true);
  else
    setPlaylistEmbedCode(ename, pid);
}

function changeEmbedBackgroundPlay(elm, ename, autoname,pid)
{
  if (elm.checked){
    document.getElementById(autoname).disabled = true;
    var autoplay = pl_embed_code.replace(/__url__/g,pid+'&auto=true'); 
    document.getElementById(ename).value = autoplay.replace(/width="[0-9]*" height="[0-9]*"/g,'width="1" height="1"');
  } else {
    document.getElementById(autoname).disabled = false;
    changeEmbedAutoPlay(document.getElementById(autoname), ename, pid);
  }
}

function copyToClipboard2(elt) {
  elt.select();
}

function changeArtistTab(type,aid){
  if ($('artist_'+type).hasClassName('active'))
    return false;
  $$('#cat_tab a.active').each(function(item){item.removeClassName('active').toggleClassName('inActive')});
  $('artist_'+type).removeClassName('inActive').toggleClassName('active');
  switch(type){
    case 'song':
      url='/artist/printsingersong?aid='+aid;
      break;
    case 'compose':
      url='/artist/printartistsong?aid='+aid;
      break;
    case 'album':
      url='/artist/albumsofartist?aid='+aid;
      break;
  }
  new Ajax.Request(url, 
                   {
                     asynchronous:true, 
                     evalScripts:false, 
                     onComplete:function(request, json){
                       $('artist_content').innerHTML=request.responseText;
                       $('loading_indicator').hide();
                     }, 
                     onLoading:function(request, json){
                       $('loading_indicator').show();
                     }
                   });
  
  return false;
}
function check_search_content() {
  var content = $F("searchContent");
  if (content == 'Nhập từ khóa cần tìm...')
    $("searchContent").value = "";
  var cat = $('selected_cat').innerHTML;
  if (cat=='Nhạc'){
    $('searchMore').setStyle({'visibility':'visible'});
  }
}

function key_press(e) {
  var Ucode=e.keyCode? e.keyCode : e.charCode;
  
  if (Ucode == 13)
    goto_search_page();
}

function goto_search_page() {
  
  var cat = $('selected_cat').innerHTML;
  if (cat=="Nhạc"){
    url = 'http://music2.tamtay.vn/search/'+$F('type')+'/1?q='+$F("searchContent");
    window.location.href = url;
  } else {
    var sel_cat="";
    var url="http://search.tamtay.vn/?q=";
    
    switch (cat)
    {
      case "Video":
        sel_cat="video";      
        break;
      case 'Ảnh':
        sel_cat="photo";      
        break;
      case 'Blog':
        sel_cat="blog";        
        break;
      default:
        sel_cat = "";
    }    
    
    if(sel_cat!="")          
      window.location.href = url+$F("searchContent") + "&f=" + sel_cat;    
    else
       window.location.href = url+$F("searchContent");    
  }
}
function hide_search_form(){
  $('searchMore').setStyle({'visibility':'hidden'});
  $("searchContent").setStyle({'color':'#CCC'});
}
function delCategory(cid)
{
    $('cid').setValue(cid);
    doSubmit('delete'); 
    return false;  
}

function addCategory()
{
    doSubmit('add');
    return false;
}

function doSubmit(action)
{
    if (action == 'add') {
        if (!checkCategoryName()) {
            alert("Bạn cần nhập tên danh mục");
            return;
        }                       
    } 
    if (action == 'delete') {
        if (!confirm("Bạn chắc chắn muốn xóa danh mục này?")) {
            return;     
        }               
    }                      
    $('command').setValue(action);
    document.getElementById("categoryForm").submit();
}

function checkCategoryName()
{
    if ($F('categoryName')== '') {
        return false;
    }
    return true;                
}
