function open_list( obj, changed ) {
	var menu_o = obj + "_o";
	var menu_c = obj + "_c";
	if ( changed ) {
		setElementClassById( obj, 'disp_on' );
		setElementClassById( menu_o, 'disp_off' );
		setElementClassById( menu_c, 'disp_on' );
	} else {
		menu = obj + "_c";
		setElementClassById( obj, 'disp_off' );
		setElementClassById( menu_o, 'disp_on' );
		setElementClassById( menu_c, 'disp_off' );
	}
}

// class要素の追加・変更
function setElementClassById(elem, value) {
	if ( document.getElementById ) {
		var obj = document.getElementById( elem );
		if ( obj ) {
			obj.className = value;
		}
	}
}

function o_win( url, width, height ) {
	window.open( url, 'mywin', 'width=' + width + ',height=' + height + ',menubar=no,toolbar=no,scrollbars=no' );
}


// 編集画面
function editLink( link, title ) {
	Lightview.show({
		href: link,
		rel: 'iframe',
		title: 'EMI Contents Management System',
		caption: title,
		options: { fullscreen: true }});
}

// メニューを更新する
function changeMenu( obj, sel ) {
	
	httpObj = createXMLHttp();
	if ( httpObj ) {
		httpObj.onreadystatechange = requestData;
		httpObj.open( "GET", sel + '.tmpl' );
		httpObj.send( null );
	}
	
	setMenuSrc( obj );
	
}

function chg_release( sel ) {
	
	httpObj = createXMLHttp();
	if ( httpObj ) {
		httpObj.onreadystatechange = releaseData;
		httpObj.open( "GET", '/release/' + sel + 'release.tmpl' );
		httpObj.send( null );
		
		var menuArry = [
//			[ "p", "ピックアップ" ],
			[ "j", "邦楽" ],
			[ "e", "洋楽" ],
			[ "z", "ジャズ" ],
			[ "c", "クラシック" ],
			[ "o", "その他" ]
		];
		
		for ( var i = 0; i < 5; i++ ) {
			
			var npmMenu = document.getElementById( 'npm' + menuArry[ i ][ 0 ] );
			var npmRes = menuArry[ i ][ 1 ];
			if ( menuArry[ i ][ 0 ] == sel ) npmRes = "<b>▼" + npmRes + "</b>";
			npmMenu.innerHTML = npmRes;
			
		}
		
	}
	
}

function chg_campaign( sel ) {
	
	httpObj = createXMLHttp();
	if ( httpObj ) {
		httpObj.onreadystatechange = campaignData;
		httpObj.open( "GET", '/campaign/' + sel + '.campaign' );
		httpObj.send( null );
		
		var cmenuArry = [
			[ "a", "全て" ],
			[ "j", "邦楽" ],
			[ "e", "洋楽" ],
			[ "z", "ジャズ" ],
			[ "c", "クラシック" ],
//			[ "o", "その他" ]
		];
		
		for ( var i = 0; i < 5; i++ ) {
			
			var npmMenu = document.getElementById( 'cam' + cmenuArry[ i ][ 0 ] );
			var npmRes = cmenuArry[ i ][ 1 ];
			if ( cmenuArry[ i ][ 0 ] == sel ) npmRes = "<b>▼" + npmRes + "</b>";
			npmMenu.innerHTML = npmRes;
			
		}
		
	}
	
}

function createXMLHttp() {
	
	if ( window.ActiveXObject ) {
		// Win e4,e5,e6用
		try {
			return new ActiveXObject( "Msxml2.XMLHTTP" );
		} catch ( e ) {
			try {
				return new ActiveXObject( "Microsoft.XMLHTTP" );
			} catch ( e2 ) {
				return null ;
			}
 		}
	} else if ( window.XMLHttpRequest ) {
		// Win Mac Linux m1,f1,o8 Mac s1 Linux k3用
		return new XMLHttpRequest();
	} else {
		return null;
	}
	
}

// メニューのHTMLを生成する
function setMenuSrc( num ) {
	
	for ( var i = 1; i < 11; i++ ) {
		
		if ( i == 1 || i == 4 ) {
			cname = "mfn";
			if ( i == num ) cname = "mfa";
		} else {
			cname = "mnn";
			if ( i == num ) cname = "mna";
		}
		
		setElementClassById( "menu" + i, cname );
		
	}
	
}

// 取得したHTMLデータをページに反映させる
function requestData()
{
	if (httpObj.readyState == 4 && httpObj.status == 200) {
		if ( httpObj.responseText ) {
			
			var embedWin = document.getElementById( 'infoWin' );
			embedWin.innerHTML = httpObj.responseText;
			
		}
		else alert( "データの取得に失敗しました。" );
	}
}

function releaseData()
{
	if (httpObj.readyState == 4 && httpObj.status == 200) {
		if ( httpObj.responseText ) {
			
			var embedWin = document.getElementById( 'newrelease' );
			embedWin.innerHTML = httpObj.responseText;
			
		}
		else alert( "データの取得に失敗しました。" );
	}
}

function campaignData()
{
	if (httpObj.readyState == 4 && httpObj.status == 200) {
		if ( httpObj.responseText ) {
			
			var embedWin = document.getElementById( 'campaign' );
			embedWin.innerHTML = httpObj.responseText;
			
		}
		else alert( "データの取得に失敗しました。" );
	}
}

function showTips(obj, url) {
	new Tip( obj, {
	    title : 'ケータイにアドレスを送る',
	    showOn: 'click',
		target: $( obj ),
		ajax: {
			url: url,
			options: {
				onComplete: function(transport) {
				}
			}
		},
		hideOn: { element: 'closeButton', event: 'click' },
		width: 'auto',
		hook: { target: 'bottomMiddle', tip: 'topRight' },
		stem: 'topRight',
		offset: { x: 6, y: 0 }
	});
}

function showPullDown( obj )
{
	
	var l = document.getElementById( obj );
	l.style.visibility='visible';
	
}

function hidePullDown( obj )
{
	
	var l = document.getElementById( obj );
	l.style.visibility='hidden';
	
}

function showSearch() {
	
	var kwd = document.getElementById( 'kwd' ).value;
	location.href = '/search/?q=' + encodeURL( kwd );
}

function encodeURL( str ) {
	
	var character = '';
	var unicode = '';
	var string    = '';
	var i         = 0;
	
	for (i = 0; i < str.length; i++) {
		character = str.charAt(i);
		unicode   = str.charCodeAt(i);
		
		if (character == ' ') {
			string += '+';
		} else {
			if (unicode == 0x2a || unicode == 0x2d || unicode == 0x2e || unicode == 0x5f || ((unicode >= 0x30) && (unicode <= 0x39)) || ((unicode >= 0x41) && (unicode <= 0x5a)) || ((unicode >= 0x61) && (unicode <= 0x7a))) {
				string = string + character;
			} else {
				if ((unicode >= 0x0) && (unicode <= 0x7f)) {
					character   = '0' + unicode.toString(16);
					string += '%' + character.substr(character.length - 2);
				} else if (unicode > 0x1fffff) {
					string += '%' + (oxf0 + ((unicode & 0x1c0000) >> 18)).toString(16);
					string += '%' + (0x80 + ((unicode & 0x3f000) >> 12)).toString(16);
					string += '%' + (0x80 + ((unicode & 0xfc0) >> 6)).toString(16);
					string += '%' + (0x80 + (unicode & 0x3f)).toString(16);
				} else if (unicode > 0x7ff) {
					string += '%' + (0xe0 + ((unicode & 0xf000) >> 12)).toString(16);
					string += '%' + (0x80 + ((unicode & 0xfc0) >> 6)).toString(16);
					string += '%' + (0x80 + (unicode & 0x3f)).toString(16);
				} else {
					string += '%' + (0xc0 + ((unicode & 0x7c0) >> 6)).toString(16);
					string += '%' + (0x80 + (unicode & 0x3f)).toString(16);
				}
			}
		}
  	}
	
	return string;
	
}


function writeFlashHTML
( 
  /**
   * 引数
   */
   
     _swf      // フラッシュのURL
    ,_quality  // 画質
    ,_loop     // 繰り返し
    ,_bgcolor  // 背景色
    ,_wmode    // 背景透明(WinIEのみ)
    ,_play     // 自動再生
    ,_menu     // 右クリックメニュー
    ,_scale    // 幅高さが%の時の縦横比等
    ,_salign   // 表示領域内表示位置
    ,_height   // ムービーの高さ
    ,_width    // ムービーの幅
    ,_hspace   // まわりの余白(水平方向)
    ,_vspace   // まわりの余白(垂直方向)
    ,_align    // 表示位置
    ,_class    // クラス
    ,_id       // ID名
    ,_name     // ムービー名
    ,_style    // スタイル
    ,_declare  // 読み込まれるだけで実行しない

)
{
  /**
   * スクリプト
   */

  // タグ用文字列生成
  var htm = ""
  
  htm+="<object classid='clsid:d27cdb6e-ae6d-11cf-96b8-444553540000'"
  htm+="        codebase='http://download.macromedia.com/pub/shockwave/"
                    htm+="cabs/flash/swflash.cab'"
  htm+="        width    = '" + _width   + "'"
  htm+="        height   = '" + _height  + "'"
  htm+="        hspace   = '" + _hspace  + "'"
  htm+="        vspace   = '" + _vspace  + "'"
  htm+="        align    = '" + _align   + "'"
  htm+="        class    = '" + _class   + "'"
  htm+="        id       = '" + _id      + "'"
  htm+="        name     = '" + _name    + "'"
  htm+="        style    = '" + _style   + "'"
  htm+="                    " + _declare  
  htm+="        >"
  htm+="<param  name     = 'movie'   value ='" + _swf     + "'>"
  htm+="<param  name     = 'quality' value ='" + _quality + "'>"
  htm+="<param  name     = 'loop'    value ='" + _loop    + "'>"
  htm+="<param  name     = 'bgcolor' value ='" + _bgcolor + "'>"
  htm+="<param  name     = 'play'    value ='" + _play    + "'>"
  htm+="<param  name     = 'menu'    value ='" + _menu    + "'>"
  htm+="<param  name     = 'scale'   value ='" + _scale   + "'>"
  htm+="<param  name     = 'salign'  value ='" + _salign  + "'>"
  htm+="<param  name     = 'wmode'   value ='" + _wmode   + "'>"
  htm+=""
  htm+="<embed                          "
  htm+="        pluginspage='http://www.macromedia.com/go/getflashplayer'"
  htm+="        width    = '" + _width   + "'"
  htm+="        height   = '" + _height  + "'"
  htm+="        hspace   = '" + _hspace  + "'"
  htm+="        vspace   = '" + _vspace  + "'"
  htm+="        align    = '" + _align   + "'"
  htm+="        class    = '" + _class   + "'"
  htm+="        id       = '" + _id      + "'"
  htm+="        name     = '" + _name    + "'"
  htm+="        style    = '" + _style   + "'"
  htm+="        type     = 'application/x-shockwave-flash' "
  htm+="                    " + _declare  
  htm+="        src      = '" + _swf     + "'"
  htm+="        quality  = '" + _quality + "'"
  htm+="        loop     = '" + _loop    + "'"
  htm+="        bgcolor  = '" + _bgcolor + "'"
  htm+="        play     = '" + _play    + "'"
  htm+="        menu     = '" + _menu    + "'"
  htm+="        scale    = '" + _scale   + "'"
  htm+="        salign   = '" + _salign  + "'"
  htm+="        wmode    = '" + _wmode  + "'"
  htm+="></embed>"
  htm+="</object>"

  //書き出し処理
  document.write(htm)
}


function writeFlashHtmlParam
( 
  /**
   * 引数
   */
   
     _swf      // フラッシュのURL
    ,_quality  // 画質
    ,_loop     // 繰り返し
    ,_bgcolor  // 背景色
    ,_wmode    // 背景透明(WinIEのみ)
    ,_play     // 自動再生
    ,_menu     // 右クリックメニュー
    ,_scale    // 幅高さが%の時の縦横比等
    ,_salign   // 表示領域内表示位置
    ,_height   // ムービーの高さ
    ,_width    // ムービーの幅
    ,_hspace   // まわりの余白(水平方向)
    ,_vspace   // まわりの余白(垂直方向)
    ,_align    // 表示位置
    ,_class    // クラス
    ,_id       // ID名
    ,_name     // ムービー名
    ,_style    // スタイル
    ,_declare  // 読み込まれるだけで実行しない
    ,_flashvars  // 変数

)
{
  /**
   * スクリプト
   */

  // タグ用文字列生成
  var htm = ""
  
  htm+="<object classid='clsid:d27cdb6e-ae6d-11cf-96b8-444553540000'"
  htm+="        codebase='http://download.macromedia.com/pub/shockwave/"
                    htm+="cabs/flash/swflash.cab'"
  htm+="        width    = '" + _width   + "'"
  htm+="        height   = '" + _height  + "'"
  htm+="        hspace   = '" + _hspace  + "'"
  htm+="        vspace   = '" + _vspace  + "'"
  htm+="        align    = '" + _align   + "'"
  htm+="        class    = '" + _class   + "'"
  htm+="        id       = '" + _id      + "'"
  htm+="        name     = '" + _name    + "'"
  htm+="        style    = '" + _style   + "'"
  htm+="        flashvars    = '" + _flashvars   + "'"
  htm+="                    " + _declare  
  htm+="        >"
  htm+="<param  name     = 'movie'   value ='" + _swf     + "'>"
  htm+="<param  name     = 'quality' value ='" + _quality + "'>"
  htm+="<param  name     = 'loop'    value ='" + _loop    + "'>"
  htm+="<param  name     = 'bgcolor' value ='" + _bgcolor + "'>"
  htm+="<param  name     = 'play'    value ='" + _play    + "'>"
  htm+="<param  name     = 'menu'    value ='" + _menu    + "'>"
  htm+="<param  name     = 'scale'   value ='" + _scale   + "'>"
  htm+="<param  name     = 'salign'  value ='" + _salign  + "'>"
  htm+="<param  name     = 'wmode'   value ='" + _wmode   + "'>"
  htm+=""
  htm+="<embed                          "
  htm+="        pluginspage='http://www.macromedia.com/go/getflashplayer'"
  htm+="        width    = '" + _width   + "'"
  htm+="        height   = '" + _height  + "'"
  htm+="        hspace   = '" + _hspace  + "'"
  htm+="        vspace   = '" + _vspace  + "'"
  htm+="        align    = '" + _align   + "'"
  htm+="        class    = '" + _class   + "'"
  htm+="        id       = '" + _id      + "'"
  htm+="        name     = '" + _name    + "'"
  htm+="        style    = '" + _style   + "'"
  htm+="        flashvars   = '" + _flashvars  + "'"
  htm+="        type     = 'application/x-shockwave-flash' "
  htm+="                    " + _declare  
  htm+="        src      = '" + _swf     + "'"
  htm+="        quality  = '" + _quality + "'"
  htm+="        loop     = '" + _loop    + "'"
  htm+="        bgcolor  = '" + _bgcolor + "'"
  htm+="        play     = '" + _play    + "'"
  htm+="        menu     = '" + _menu    + "'"
  htm+="        scale    = '" + _scale   + "'"
  htm+="        salign   = '" + _salign  + "'"
  htm+="        wmode    = '" + _wmode  + "'"
  htm+="></embed>"
  htm+="</object>"

  //書き出し処理
  document.write(htm)
}


