/*公用js檔*/

//var mat
//if(mat = document.title.match(/(.*) 線上音樂NO.1(.*)/)) {
//  document.title = mat[1] + mat[2]
//}

if (!window.kkgo) {
  window.kkgo = function (act) {
    theName="IsInstallKKBOX=";
    theData="";
    theCookie=document.cookie+";";
    start=theCookie.indexOf(theName);
    if (start != -1)
    {
      end=theCookie.indexOf(";",start);
      theData=unescape(theCookie.substring(start+theName.length,end));
    }

    if ((parent.topFrame) && (theData == 1)) {    // 已安裝KKBOX且在frame裡面，就不用中繼頁
      parent.topFrame.location.href=act;
    }
    else {
      window.open("/relay.php?target="+act, 'KKBOX', 'width=700,height=500,scrollbars,resizable');
    }

  }
}
var cl = document.all? 'className': 'class';
function page_toggle(id, total, which) {
  var i
    for(i = 1; i <= total; i++) {
      if(which == i) {
	document.getElementById('t_' + id + i).setAttribute(cl, 'subtitlebar_selected');
	document.getElementById('t_' + id + '_' + i).style.display = 'block';
      } else {
	document.getElementById('t_' + id + i).setAttribute(cl, 'subtitlebar_unselected');
	document.getElementById('t_' + id + '_' + i).style.display = 'none';
      }
      /*
	 if(which == 1){ //only show song's
	 document.getElementById(id + '_playadd').style.visibility = "visible";
	 }else{
	 document.getElementById(id + '_playadd').style.visibility = "hidden";
	 }*/
    }
}

function mymusic_exec(command)
{
    document.getElementById('func_frame').src = command;
      return true;
}



function getElementsByName(tag, name){
  var elem = document.getElementsByTagName(tag);
  var arr = new Array();
  for(i = 0,iarr = 0; i < elem.length; i++) {
    att = elem[i].getAttribute("name");
    if(att == name) {
      arr[iarr++] = elem[i];
    }
  }
  return arr;
}

function setCSS(id){ //設定tab的css
  var objs = getElementsByName('DIV', document.getElementById(id).getAttribute("name"));
  for(x=0;x<objs.length;x++) {
    if (!objs[x].firstChild) {continue;}
    if (objs[x].getAttribute("id") != id) {
      if( x == 4){
	objs[x].parentNode.className = "tab";
      }else{
	objs[x].parentNode.className = "tab";
      }
    } else {
      objs[x].parentNode.className = "tab_highlight";
    }
  }
}
function goto_web(url){ //portal開啟web page用
  if(url){
    document.getElementById('func_frame').src = url;
  }
}
/* check_login()使用範例
 *  function A(){
 *   if(check_login()){
 *     //執行動作
 *   }else{
 *     //不執行動作
 *  }
 * }
 */
function check_login(){ //return true or false for js function using
  if(ap=="WEB"){
    var uid =getCookieValue('USER_ID');
    var ulogin =getCookieValue('USER_LOGIN');

    if(uid!='' && typeof(uid)!="undefined" && ulogin!='' && typeof(ulogin)!="undefined"){
      return true;
    }else{
      web_login(location.pathname,'');
      return false;
    }
  }else if(ap=="PORTAL"){
    return true; //portal的一律在寫or update資料時去做登入判斷
  }else{
    return false;
  }
}

function change_more_link(oid,url_value,title_value,target){
  if(document.getElementById(oid)){
    var obj =document.getElementById(oid);
    var title = title_value;
    var url = url_value;
    obj.innerHTML = '<a href="'+url+'" title="'+title+'" target="'+target+'">'+ title +'</a>';
  }
}

function toPush(cate,website,title,link,act){
  if(link=='' || link==undefined){
    link = document.URL;
  }
  title = title.replace("(","（");  //將半形括號替換成全形
  title = title.replace(")","）");
  if(website=='plurk'){
    toPlurk(act,cate,title,link);

  }else if(website=='twitter'){
    toTwitter(cate,title,link);

  }else if(website=='facebook'){
    toFacebook(act,title,link);
  }
}
//分享連結到Plurk
function toPlurk(act,cate,title,link){
  window.open('http://www.plurk.com/?qualifier='+act+'&status=' .concat(encodeURIComponent(cate)) .concat(' ') .concat(encodeURIComponent(link)) .concat(' ') .concat('(') .concat(encodeURIComponent(title)) .concat(')'));
}
//分享連結到Twitter
function toTwitter(cate,title,link){
  window.open('http://twitter.com/home/?status=' .concat(encodeURIComponent(cate)) .concat(' ') .concat(encodeURIComponent(title)) .concat(' ') .concat(encodeURIComponent(link)))
}
//分享連結到Facebook
function toFacebook(act,title,link){
  window.open('http://www.facebook.com/sharer.php?u='+encodeURIComponent(link)+'&t='+encodeURIComponent(title),act,'toolbar=0,status=0,width=626,height=436');
}

