IE = (document.all) ? 1: 0;
NS = (navigator.appName.indexOf("Netscape") != -1) ? 1 : 0;
function web_logout(){
  UserSetCookie('WPHPSESSID','',0,'.kkbox.com.tw','/');
  UserSetCookie('USER_LOGIN','',0,'.kkbox.com.tw','/');
  UserSetCookie('PRE_FLAG','',0,'.kkbox.com.tw','/');
  UserSetCookie('USER_ID','',0,'.kkbox.com.tw','/');
  //parent.location.href="http://www.kkbox.com.tw/";
  //window.location.reload();
  window.location.href="/";
}
function web_login(from,to){
  var url_str ="/login.php";
  if(typeof(to)!="undefined" && to.length>0 ){
    url_str +="?to="+escape(to);
  }else{
    if(typeof(from)!="undefined" && from.length>0 ){
      if(from=="/login.php"){
	from ="/";
      }
      url_str +="?from="+escape(from);
    }else{
      url_str ="/";
    }
  }
  window.location.href = url_str ;
}

function UserSetCookie(cookieName,cookieValue,nSecs,domain,path) {
  now=new Date( );
  now.setTime(now.getTime( ) + nSecs);
  document.cookie = cookieName+"="+escape(cookieValue)
    + ";expires="+now.toGMTString()+";domain="+domain+";path="+path;
}
function getCookie(name) {
  var theCookies = document.cookie.split(/[; ]+/);
  for (var i = 0 ; i < theCookies.length; i++) {
    var aName = theCookies[i].substring(0,theCookies[i].indexOf('='));
    if (aName == name) {
      return theCookies[i];
    }
  }
}

function getCookieValue(name) {
  var aCookie = getCookie(name);
  if (aCookie != null) {
    var arr = aCookie.split("=");
    return arr[1];
  }
}
//check id cookie
var cuid = getCookieValue('USER_ID');
if(cuid){
  var ori_html = document.getElementById('login_msg').innerHTML;
  document.getElementById('login_msg').innerHTML = unescape(cuid) +" 您好！ "+ori_html;
  document.getElementById('login_link').href="javascript:web_logout();";
  document.getElementById('login_link').innerHTML ="登出";
  document.getElementById('reg_link').href="javascript:wp_open2();";
  document.getElementById('reg_link').innerHTML ="開啟網頁播放器";

}
