//
//  JavaScript for Keirex technology website
//  
//  (C) Copyright Keirex Technology Inc. 2009 All Rights Reserved.
//
//      Written by N. Fudanuki
//
//――――――――――――――――――――――――――――――――――――――
// Define global variable.
//――――――――――――――――――――――――――――――――――――――

	// Global variable for page id and background image.
	var KtiWebPageId = "index";
	var KtiWebPageEnglish = "";
        var KtiWebPageJapanese = "";
	var KtiWebBgimageUrl = "";
	var KtiWebLanguage = "j";

	// Global variable for intra-page jump count.
	var njump = 1;

	// Global variable for pulldown menu.
	var KtiWebOpenedMenu = null;
	var KtiWebTimerOfMenu;
	var KtiWebOpenedSubMenu = null;
	var KtiWebTimerOfSubMenu;

	// Define standard font size for small, medium and large.
	// Modify here if you want to change standard font size.
	// ------------------------------------------------------------
	var KtiWebFontS = "8pt";
	var KtiWebFontM = "9.5pt";
	var KtiWebFontL = "11pt";
	// ------------------------------------------------------------

	// Define colors of the string or button in the website.
	// Modify here if you want to change standard color.
	// ------------------------------------------------------------
	var ColorSelected = "#ff8800"
	var ColorUnselected = "#000000"
	var ColorMouseout = "#660000"
	var ColorMouseover = "#e8af9e"
	var ColorSubmit = "#008844"
	var ColorCancel = "#cc0000"
	var bkgroundColorSelected = "#eeeeee";
	var bkgroundColorUnselected = "#aaaaaa";
	// ------------------------------------------------------------

	// Define mail addess parts.
	// Modify KtiMailAd if you want to change mail addess.
	// NOTE THAT YOU HAVE TO REPLACE "-" WITH "." TO DEFINE. 
	// ------------------------------------------------------------
	var KtiMailAd = "keirex.support";
	var KtiDomain = "keirex.com";
	// ------------------------------------------------------------

//――――――――――――――――――――――――――――――――――――――
// Function to Set Page ID.
//――――――――――――――――――――――――――――――――――――――

function SetPageId(){

	var i, l, pname, obj, bgimage;

	pname = window.location.pathname;

	KtiWebLanguage = "j";
	KtiWebBgimageUrl = "url(";
	if( pname.indexOf( "/e/" ) >= 0 ){
		KtiWebLanguage = "e";
		KtiWebBgimageUrl += "../";
	}
	KtiWebBgimageUrl += "background/";
	i = pname.lastIndexOf( "/" );
	l = pname.lastIndexOf( "-j.html" );
	if( l < 0 ){
		l = pname.lastIndexOf( "-e.html" );
	}
	if( l < 0 ){
		KtiWebPageId = "index";
	}
	else{
		KtiWebPageId = pname.substring( ++i, l );
	}

	// Exceptions.
	if( KtiWebPageId.indexOf( "press" ) == 0 ){
		KtiWebPageId = "press";
	}

	// Set background image
	SetBackgroundImage();

//	window.alert( "Page id = " + KtiWebPageId );

	return true;

}


//――――――――――――――――――――――――――――――――――――――
// Change global font size throughout Keirex website.
//――――――――――――――――――――――――――――――――――――――

function ChangeFontSize( obj ){

	// Get font size.
	if( obj.id ) {
		var size = obj.id.charAt( 8 );

	// Set font size.
		if( size == "S" || size == "M" || size == "L" ) {
			SetFontSize( size );

	// Save size data in cookie.
			var expire = new Date();
 			expire.setFullYear( expire.getFullYear() + 1 );
			expire = expire.toGMTString();
			document.cookie = "KtiWebFontSize=" + size + ";expires=" + expire+ ";";

	// Set button color.
			SetButtonColor( size );
		}
	}

}

// Set font size.

function SetFontSize( size ){

	var obj, frames, frameObj;
	var point = KtiWebFontS;

//	if( size == "S" ) point = KtiWebFontS;
	if( size == "M" ) point = KtiWebFontM;
	if( size == "L" ) point = KtiWebFontL;

	// Change font size of the body.
	if( document.body ) {
		obj = document.body;
	}
	else if( document.getElementsByTagName ) {
		obj = document.getElementsByTagName( "body" )[ 0 ];
	}

	if( obj.style ) {
		obj.style.fontSize = point;
	}

	// Check if iframe is used.
	if( document.getElementsByTagName ) {
		frames = document.getElementsByTagName( "iframe" );

	// Change font size of the body in the iframe.
		if( frames.length > 0 ) {
			for( i = 0; i <  frames.length; i++ ) {
				obj = frames[ i ].contentWindow;
				if( obj.document.body ) {
					frameObj = obj.document.body;
				}
				else if( obj.document.getElementsByTagName ) {
					frameObj = obj.document.getElementsByTagName( "body" )[ 0 ];
				}
				if( frameObj.style ) {
					frameObj.style.fontSize = point;
				}
			}
		}
	}
}


//――――――――――――――――――――――――――――――――――――――
// Check font size stored.
//――――――――――――――――――――――――――――――――――――――

function CheckFontSize(){

	// Set title background image.
	var obj = document.getElementById( "title-back" );
	if( obj != null ){
		obj.style.backgroundImage = KtiWebBgimageUrl;
	}

	// Get cookie and check if the size is saved.
	var size = "";
	var ck = document.cookie.split( "; " );
	for( i in ck ) {
		data = ck[ i ].split( "=" );
		if( data[ 0 ] == "KtiWebFontSize" ) {
			size = data[ 1 ];
			break;
		}
	}

	// If size is saved, change font size.
	if( size != "S" && size != "M" && size != "L" ) {
//		alert( "Invalid size data restored from cookie. <- CheckFontSize" );
		size = "S";
	}

	SetFontSize( size );

	// Set button color.
	SetButtonColor( size );

}


//――――――――――――――――――――――――――――――――――――――
// Set color of size buttons.
//――――――――――――――――――――――――――――――――――――――

function SetButtonColor( size ){

	var obj;

	obj = document.getElementById( "FontSizeS" );
	if( obj != null ) {
		if( size == "S" )
			obj.style.backgroundColor = bkgroundColorSelected;
		else
			obj.style.backgroundColor = bkgroundColorUnselected;
	}

	obj = document.getElementById( "FontSizeM" );
	if( obj != null ) {
		if( size == "M" )
			obj.style.backgroundColor = bkgroundColorSelected;
		else
			obj.style.backgroundColor = bkgroundColorUnselected;
	}

	obj = document.getElementById( "FontSizeL" );
	if( obj != null ) {
		if( size == "L" )
			obj.style.backgroundColor = bkgroundColorSelected;
		else
			obj.style.backgroundColor = bkgroundColorUnselected;
	}

	return true;
}


//――――――――――――――――――――――――――――――――――――――
// Change color of the element.
//――――――――――――――――――――――――――――――――――――――

function ChangeColor( obj, color ){

	if( obj.id ){
		if( document.getElementById )
			document.getElementById( obj.id ).style.color = color;
		else if( document.all )
			document.all( obj.id ).style.color = color;
		else if( document.layers )
			document.layers[ obj.id ].color = color;
	}

	return true;
}


//――――――――――――――――――――――――――――――――――――――
// Change back-ground color of the element.
//――――――――――――――――――――――――――――――――――――――

function ChangebkgroundColor( obj, color ){

	if( obj.id ){
		if( document.getElementById )
			document.getElementById( obj.id ).style.backgroundColor = color;
		else if( document.all )
			document.all( obj.id ).style.backgroundColor = color;
		else if( document.layers )
			document.layers[ obj.id ].backgroundColor = color;
	}

	return true;
}


//――――――――――――――――――――――――――――――――――――――
// Open pulldown menu.
//――――――――――――――――――――――――――――――――――――――

function CheckMenu( id ){

	// Close opened menu if any.
	if( KtiWebOpenedMenu && KtiWebOpenedMenu != id )
		CloseMenu();

	// Display pulldown menu.
	OpenMenu( id );
}

// Display pulldown menu.

function OpenMenu( id ){ 

	if( document.getElementById )
		document.getElementById( id ).style.visibility = 'visible';
	else if( document.all )
		document.all( id ).style.visibility = 'visible';
	else if( document.layers )
		document.layers[ id ].visibility = 'show';

	clearTimeout( KtiWebTimerOfMenu );
	KtiWebOpenedMenu = id;
}

// Check if sub-menu is openend.

function CheckSubMenu( id ){

	// Close opened menu if any.
	if( KtiWebOpenedSubMenu && KtiWebOpenedSubMenu != id )
		CloseSubMenu();

	// Display pulldown menu.
	OpenSubMenu( id );
}

// Display pulldown sub-menu.

function OpenSubMenu( id ){ 

	if( document.getElementById )
		document.getElementById( id ).style.visibility = 'visible';
	else if( document.all )
		document.all( id ).style.visibility = 'visible';
	else if( document.layers )
		document.layers[ id ].visibility = 'show';

	clearTimeout( KtiWebTimerOfSubMenu );
	KtiWebOpenedSubMenu = id;
}


//――――――――――――――――――――――――――――――――――――――
// Close pulldown menu.
//――――――――――――――――――――――――――――――――――――――

function CloseMenu(){ 

	if( document.getElementById ){
		document.getElementById( KtiWebOpenedMenu ).style.visibility = 'hidden';
	}
	else if( document.all ){
		document.all( KtiWebOpenedMenu ).style.visibility = 'hidden';
	}
	else if( document.layers ){
		document.layers[ KtiWebOpenedMenu ].visibility = 'hide';
	}

	KtiWebOpenedMenu = null;

}


function CloseSubMenu(){ 

	if( document.getElementById ){
		document.getElementById( KtiWebOpenedSubMenu ).style.visibility = 'hidden';
	}
	else if( document.all ){
		document.all( KtiWebOpenedSubMenu ).style.visibility = 'hidden';
	}
	else if( document.layers ){
		document.layers[ KtiWebOpenedSubMenu ].visibility = 'hide';
	}

	KtiWebOpenedSubMenu = null;

}


//――――――――――――――――――――――――――――――――――――――
// Change language to Japanese.
//――――――――――――――――――――――――――――――――――――――

function ChangeLanguage2Japanese(){

	var page_jp, page_en, page, i;

	if( KtiWebPageJapanese != "N/A" ){
		page_en = window.location.pathname;
		i = page_en.lastIndexOf( "/e" ) + 1;
		page_jp = page_en.substr( 0, i );
		i = page_en.lastIndexOf( "/" ) + 1;
		page = page_en.substr( i );

		if( page.indexOf( "-e" ) >= 0 ){
			if( KtiWebPageJapanese == "" ){
				page_jp = page_jp + page.replace( "-e", "-j" );
			}
			else if( KtiWebPageJapanese.indexOf( "http//" ) >= 0 ){
				page_jp = KtiWebPageJapanese;
			}
			else if( KtiWebPageJapanese != "N/A" ){
				page_jp = page_jp + KtiWebPageJapanese + "-j.html";
			}
		}
		else{
			page_en = page_en + "index.html";
		}

		while( page_jp.search( "%20" ) >= 0 ){
			page_jp = page_jp.replace( "%20", " " );
		}

		window.location.pathname = page_jp;
	}
	else{
		alert( "Japanese page not available." );
	}
}


//――――――――――――――――――――――――――――――――――――――
// Change language to English.
//――――――――――――――――――――――――――――――――――――――

function ChangeLanguage2English(){

	var page_jp, page_en, page, new_window;

	if( KtiWebPageEnglish.indexOf( "http://" ) >= 0 ){

		new_window = window.open( KtiWebPageEnglish, "_blank");

	}
	else if( KtiWebPageEnglish != "N/A" ){
		page_jp = window.location.pathname;
		i = page_jp.lastIndexOf( "/" ) + 1;
		page_en = page_jp.substr( 0, i ) + "e/";
		page = page_jp.substr( i );

		if( page.indexOf( "-j" ) >= 0 ){
			if( KtiWebPageEnglish == "" ){
				page_en += page.replace( "-j", "-e" );
			}
			else if( KtiWebPageEnglish != "N/A" ){
				page_en += KtiWebPageEnglish + "-e.html";
			}
		}
		else{
			page_en += "index.html";
		}

		while( page_en.search( "%20" ) >= 0 ){
			page_en = page_en.replace( "%20", " " );
		}

		window.location.pathname = page_en;
	}
	else{
		alert( "English page not available." );
	}
}


//――――――――――――――――――――――――――――――――――――――
// End of file.
//――――――――――――――――――――――――――――――――――――――
