// file : search.js
// mnb-photo ver.5.1
// javascript custom function
// Copyright(C)Manabu Nakamoto All Rights Reserved.


/*-------------------------------------------------------------------------------------------*

	VOID	chkSearch( VOID )

	[機能]　起動引数のチェック
		引数無効のときはディフォルト引数に変換してURLジャンプ

	[引数]　無し

	[戻値]　無し

*-------------------------------------------------------------------------------------------*/
function	chkSearch (){

	var	str	= new Array();
	var	url	= "";

	// 引数代入
	getPalam();

	// デバッグログ出力
	if( DBG_OUT )		writeLog( location.href );

	// 「起動引数のチェックをしない」オプション
	if( !CHK_SEARCH ){
		if( DBG_OUT )	writeLog( "CHK_SEARCH=<b><font color='"	+ DBG_CLR1 + "'>" + CHK_SEARCH + "</font></b>" );
		return;
	}

	// url, search分離
	str	= splitURL();
	url	= str[0];

	if( debug == 1 || INTNL ){
		document.write( "<b>[PROCESS : chkSearch( )</b>" + "&nbsp;" );
		document.write( "<b>URL</b> : " );
		if( FULL_PATH )		document.write( url );
		else			document.write( removePath( url ) );
		document.write( "<b>&nbsp;SEARCH</b> : " + str[1] + "<br>" );
	}

	// 引数値から適正サーチ文字列作成後、
	// saerch文字列を付加し、基のURLと比較する
	url += chkSearchE();

	// 修正後のURLにジャンプ判定
	if( location.href == url )		urlFlg = true;

	if	( debug == 1 || INTNL ){
		document.write( "<b>urlFlg : " + urlFlg + "</b>&nbsp;" );
		document.write( "<b>URL</b> : " );
		if( FULL_PATH )		document.write( url );
		else			document.write( removePath( url ) );
		document.write( "<b>&nbsp;chkSearch( ) : End]</b>" + "<br>" );
	}

	// debug OFF時は修正後のURLにジャンプ
	else  if( debug != 1 || !INTNL ){
		if( !urlFlg )	location.replace( url );
	}

	// デバッグログ出力・引数値など表示
	if( DBG_OUT ){
		writeLog( url );
		dispPalam();
	}

}
/* end of chkSearch() */


/*-------------------------------------------------------------------------------------------*

	Array	splitURL( VOID )

	[機能]　URLと引数を分離

	[引数]　無し

	[戻値]　URLと引数の配列

*-------------------------------------------------------------------------------------------*/
function	splitURL (){

	var	url	= "";
	var	search	= "";
	var	str	= new Array();

	if( debug == 1 || INTNL )		document.write(	"<b>[PROCESS : splitURL( )</b>" );

	// URLと引数を分離
	str = location.href.split( "?" );
	url	= str[0];
	search	= str[1];
	if( !search )	search = "";// Error防止

	// html引数フォーマット不正
	if( str[2] ){
		if( debug == 1 || INTNL )	document.write( "&nbsp;dupulicate'?'[" + str[2] + "]->deleted" );
	}

	if( debug == 1 || INTNL ){
		document.write( "&nbsp;<b>URL</b> : " );
		if( FULL_PATH )		document.write( url );
		else			document.write( removePath( url ) );
		document.write( "&nbsp;<b>SEARCH</b> : " + search );
		document.write(	"<b> End]</b><br>" );
	}

	str[0] = url;
	str[1] = search;

	return( str );

}
/* end of splitURL() */


/*-------------------------------------------------------------------------------------------*

	VOID	getPalam( VOID )

	[機能]	URLから引数値を分離、引数値修正処理

	[引数]	無し

	[戻値]　無し

*-------------------------------------------------------------------------------------------*/
function	getPalam (){

	type		= getType();
	page		= getPage();
	lang		= getLang();
	color		= getColor();
	debug		= getDebugMode();

	// lang
	if( type == TOP || type== SAMPLE || type == MBTN || type == COPY || type > MAP )	lang = -1;

	// page
	if( type == GALLERY || type == MOVIE || type == CPAGE || type == SAMPLE ){
		// 変数代入
		if	( type == GALLERY )		PAGE_NUM = PAGE_NUM_GALLERY;
		else  if( type == MOVIE )		PAGE_NUM = PAGE_NUM_MOVIE;
		else  if( type == CPAGE )		PAGE_NUM = PAGE_NUM_COLUMN;
		else  if( type == SAMPLE )		PAGE_NUM = PAGE_NUM_SAMPLE;
		if( page < 0 || page >= PAGE_NUM )	page = 0;
	}
	else						page = -1;

	// debug
	if( debug > DEFAULT_STRD.length - 1 )		debug = 0;

	//エラー出力レベル設定
//	if( debug > 2 )					DBG_OUT = debug + DSUBS;	// 拡張用
	if( debug > 2 )					DBG_OUT = 1;

	// デバッグログwindowを起動
	if( DBG_OUT )					openLogFile();

	// CSS決定
	if( type == GALLERY || type == MOVIE || type == MBTN )		defBodyCSS();

	if( debug == 1 || INTNL ){
		document.write( "<b>[PROCESS : getPalam( )</b>&nbsp;" );
		document.write( "type=" + type + "&nbsp;lang=" + lang + "&nbsp;page=" + page + "&nbsp;color=" + color );
		document.write(	"&nbsp;<b>debug</b> : " + debug );
		if( INTNL )		document.write( "<b>&nbsp;*Intrenal&nbsp;</b>" );
		document.write( "<b> End]</b>", "<br>" );
	}

}
/* end of getPalam() */


/*-------------------------------------------------------------------------------------------*

	String	chkSearchE( VOID )

	[機能]　引数値から適正サーチ文字列作成

	[引数]　無し

	[戻値]　適正URL

*-------------------------------------------------------------------------------------------*/
function	chkSearchE (){

	var	str	= new Array();
	var	search	= "";

	// for debug
	if( debug == 1 || INTNL )	document.write( "<b>[PROCESS : chkSearchE( )</b>&nbsp;" );

	// lang付加
	if( lang >= 0 && type < MAP )	search = "?" + "lang=" + lang;

	// form.phpはlang引数が与えられているときのみ付加
	if( type == FORM_PHP ){
		if( location.search.indexOf( "lang=", 0 ) > 0 ){
			search = "?" + "lang=" + lang;
		}
		else	search = "";
	}

	// page付加
	if( page >= 0 ){
		if( search.length )	search += "&";
		else			search  = "?";
		search += "page=" + page;
	}

	// color付加（MBTNのみ）
	if( color >= 0 && type == MBTN ){
		if( search.length )	search += "&";
		else			search  = "?";
		search += "color=" + color;
	}

	// debug付加
	if( debug > 0 ){
		if( search.length )	search += "&";
		else			search  = "?";
		search += DEFAULT_STRD0 + debug;
	}

	// for debug
	if( debug == 1 || INTNL ){
		document.write( "&nbsp;&nbsp;" );
		document.write( "return [", search, "]&nbsp;&nbsp;" );
		document.write( "<b> End]</b>", "<br>" );
	}

	return( search );

}
/* end of chkSearchE() */


/*-------------------------------------------------------------------------------------------*

	Number	getPage( VOID )

	[機能]	URLからpage値を分離して返す

	[引数]	無し

	[戻値]　page値

*-------------------------------------------------------------------------------------------*/
function	getPage (){

	var	ar	= new Array();
	var	str	= location.search;
	var	p	= -1;

	if( str.indexOf( "page=", 0 ) > 0 ){
		ar = str.split( "page=" );
		ar = ar[1].split( "&" );
		if( ar[0] )	p = ar[0];
	}

	return( p );

}
/* end of getPage() */


/*-------------------------------------------------------------------------------------------*

	Number	getDebugMode( VOID )

	[機能]	URLからdebug値を分離して返す

	[引数]　無し

	[戻値]　debug値

*-------------------------------------------------------------------------------------------*/
function	getDebugMode (){

	var	ar	= new Array();
	var	str	= location.search;
	var	mode	= 0;

	if( str.indexOf( DEFAULT_STRD0, 0 ) > 0 ){
		ar = str.split( DEFAULT_STRD0 );
		ar = ar[1].split( "&" );
		if( ar[0] )	mode = ar[0];
	}

	if( mode )	mode = parseInt( mode )

	return( parseInt( mode ) );

}
/* end of getDebugMode() */


/*-------------------------------------------------------------------------------------------*

	Number	getLang( VOID )

	[機能]	URLからlang値を分離して返す

	[引数]	無し

	[戻値]　japanese : 0、english : 1

*-------------------------------------------------------------------------------------------*/
function	getLang (){

	if	( location.href.indexOf( "lang=0"	, 0 ) > 0 )	return( 0 );
	else  if( location.href.indexOf( "lang=1"	, 0 ) > 0 )	return( 1 );

	else  if( location.href.indexOf( MAP_PATH + uej[0], 0 ) > 0 )	return( 0 );
	else  if( location.href.indexOf( MAP_PATH + uej[1], 0 ) > 0 )	return( 1 );

	else								return( 1 );/* default */

}
/* end of getLang() */


/*-------------------------------------------------------------------------------------------*

	Number	getType( VOID )

	[機能]	URL中の文字列からカレントURLを判定し、値を返す

	[引数]　無し

	[戻値]　本体参照

*-------------------------------------------------------------------------------------------*/
function	getType ( url ){

	var	type = -1;

	if( !url )	url = location.href;

	if	( url.indexOf( WEB_DOMAIN, 0 ) > 0 && url.charAt( url.length - 1 ) == "/" )	type = TOP;
	else  if( url.indexOf( WEB_DOMAIN	+ TOP_PATH, 0 ) > 0 ) 				type = TOP;
	else  if( url.indexOf( LOCAL_DOMAIN	+ TOP_PATH, 0 ) > 0 ) 				type = TOP;

	else  if( url.indexOf( ABOUT_PATH		, 0 ) > 0 )		type = ABOUT;
	else  if( url.indexOf( GALLERY_PATH		, 0 ) > 0 )		type = GALLERY;
	else  if( url.indexOf( FLASH_PATH		, 0 ) > 0 )		type = FLASH;
	else  if( url.indexOf( COLUMN_PATH		, 0 ) > 0 )		type = COLUMN;
	else  if( url.indexOf( INFO_PATH		, 0 ) > 0 )		type = INFO;
	else  if( url.indexOf( LINK_PATH		, 0 ) > 0 )		type = LINK;
	else  if( url.indexOf( BIO_PATH			, 0 ) > 0 )		type = BIO;

	else  if( url.indexOf( MAP_PATH			, 0 ) > 0 )		type = MAP;
	else  if( url.indexOf( MAPS_PATH		, 0 ) > 0 )		type = MAPS;
	else  if( url.indexOf( VIEW_PATH		, 0 ) > 0 )		type = VIEW;
	else  if( url.indexOf( PBL_PATH			, 0 ) > 0 )		type = PBL;

	else  if( url.indexOf( MOVIE_PATH		, 0 ) > 0 )		type = MOVIE;
	else  if( url.indexOf( PAGE_PATH		, 0 ) > 0 )		type = CPAGE;
	else  if( url.indexOf( SAMPLE_PATH		, 0 ) > 0 )		type = SAMPLE;
	else  if( url.indexOf( FORM_PHP_PATH		, 0 ) > 0 )		type = FORM_PHP;
	else  if( url.indexOf( FORM_PATH		, 0 ) > 0 )		type = FORM;
	else  if( url.indexOf( COPY_PATH		, 0 ) > 0 )		type = COPY;
	else  if( url.indexOf( "/mbtn.html"		, 0 ) > 0 )		type = MBTN;

	else  if( url.indexOf( "/form_test/form.html"	, 0 ) > 0 )		type = FORM;	/* for develop */

	else  if( url.indexOf( GSP_PATH			, 0 ) > 0 )		type = GSP;	// 旧ページ

	return( type );

}
/* end of getType() */


/*-------------------------------------------------------------------------------------------*

	Number	getColor( VOID )

	[機能]	swf背景色決定のためURL中の文字列からカレントURLを判定し、値を返す

	[引数]	無し

	[戻値]　Black : 0, White : 1

*-------------------------------------------------------------------------------------------*/
function	getColor (){

	var	url = location.href;

	if	( url.indexOf( TOP_PATH		, 0 ) > 0 )					return( 1 );
	else  if( url.indexOf( ABOUT_PATH	, 0 ) > 0 )					return( 1 );
	else  if( url.indexOf( GALLERY_PATH	, 0 ) > 0 && url.indexOf( "page=8", 0 ) > 0 )	return( 1 );
	else  if( url.indexOf( MOVIE_PATH	, 0 ) > 0 && url.indexOf( "page=0", 0 ) > 0 )	return( 1 );
	else  if( url.indexOf( FORM_PATH	, 0 ) > 0 )					return( 1 );
	else  if( url.indexOf( FORM_PHP_PATH	, 0 ) > 0 )					return( 1 );
	else  if( url.indexOf( "?color=1"	, 0 ) > 0 )					return( 1 );
	else  if( url.indexOf( "/form_test/form", 0 ) > 0 )					return( 1 );/* for develop */

	// ディフォルトは 0 = black
	else											return( 0 );

}
/* end of getColor() */


/*-------------------------------------------------------------------------------------------*

	

	[機能]　

	[引数]　

	[戻値]　

	[備考]　

*-------------------------------------------------------------------------------------------*/
/* end of  */
