//
//  JavaScript for Anova Solutions website
//  
//  (C) Copyright Anova Solutions, Inc. 2008 All Rights Reserved.
//
//      Written by N. Fudanuki
//
//――――――――――――――――――――――――――――――――――――――
// Define global variable.
//――――――――――――――――――――――――――――――――――――――

	// Global variable for page id.
	var page_id = "index";
	var page_otherLanguage = "";
	var bgimage_url;

	// Global variable for intra-page jump count.
	var njump = 1;

	// Global variable for pulldown menu.
	var openedMenu = null;
	var TimerOfMenu;
	var openedSubMenu = null;
	var TimerOfSubMenu;

	// Define standard font size for small, medium and large.
	// Modify here if you want to change standard font size.
	// ------------------------------------------------------------
	var anovaFontS = "8pt";
	var anovaFontM = "9.5pt";
	var anovaFontL = "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 ColorSubmit = "#008844"
	var ColorCancel = "#cc0000"
	var bkgroundColorSelected = "#eeeeee";
	var bkgroundColorUnselected = "#aaaaaa";
	// ------------------------------------------------------------


//――――――――――――――――――――――――――――――――――――――
// Initial setting.
//――――――――――――――――――――――――――――――――――――――

function SetPageId(){

	var i, l, pname, obj, bgimage;

	pname = window.location.pathname;

	bgimage_url = "url(";
	if( pname.indexOf( "\/jp\/" ) >= 0 ){
		bgimage_url = bgimage_url + "../";
	}
	bgimage_url = bgimage_url + "background/";
	i = pname.lastIndexOf( "\/" );
	l = pname.lastIndexOf( "-j.html" );
	if( l < 0 ){
		l = pname.lastIndexOf( "-e.html" );
	}
	if( l < 0 ){
		page_id = "index";
	}
	else{
		page_id = pname.substring( ++i, l );
	}

	// Exceptions.
	if( page_id.indexOf( "press" ) == 0 ){
		page_id = "press";
	}
	if( page_id.indexOf( "beemsusr" ) == 0 ){
		page_id = "beemsusr";
	}

	// Change back-ground image of the title
	// and jump address at change of language.

	bgimage = "";
	page_otherLanguage = "";

	switch( page_id ){

	case "index":
		bgimage = "illumination.jpg";
		break;

	case "news":
		bgimage = "news.jpg";
		break;

	case "press":
		bgimage = "newspaper.jpg";
		break;

	case "edsf2008":
		bgimage = "EDSF2008.jpg";
		break;

	case "edsf2009":
		bgimage = "EDSF2009.jpg";
		break;

	case "technology":
		bgimage = "technology.jpg";
		break;

	case "tech-background":
		bgimage = "device.jpg";
		page_otherLanguage = "technology";
		break;

	case "tech-variation":
		bgimage = "ler.jpg";
		page_otherLanguage = "technology";
		break;

	case "tech-objective":
		bgimage = "carrier.jpg";
		page_otherLanguage = "technology";
		break;

	case "tech-lesspesim":
		bgimage = "diffusion.jpg";
		page_otherLanguage = "technology";
		break;

	case "tech-modeling":
		bgimage = "pdf.jpg";
		page_otherLanguage = "technology";
		break;

	case "tech-SAPmodel":
		bgimage = "statistics.jpg";
		page_otherLanguage = "technology";
		break;

	case "tech-HSAP":
		bgimage = "hierarchy.jpg";
		page_otherLanguage = "technology";
		break;

	case "tech-SSTA":
		bgimage = "schematic.jpg";
		page_otherLanguage = "technology";
		break;

	case "tech-unifiedmodel":
		bgimage = "polymar.jpg";
		page_otherLanguage = "technology";
		break;

	case "products":
		bgimage = "workstation.jpg";
		break;

	case "designsolutions":
		bgimage = "histgram.jpg";
		break;

	case "chronova-fm":
		bgimage = "clock1.jpg";
		break;

	case "chronova-lc":
		bgimage = "clock2.jpg";
		break;

	case "chronova-lva":
		bgimage = "clock3.jpg";
		break;

	case "chronova-ssta":
		bgimage = "timing-analyzer.jpg";
		break;

	case "chronova-ca":
		bgimage = "circuit-analyzer.jpg";
		break;

	case "chronova-pa":
		bgimage = "clock4.jpg";
		break;

	case "chipscope":
		bgimage = "scope.jpg";
		break;

	case "chronova-ex":
		bgimage = "wafer.jpg";
		break;

	case "beems3":
		bgimage = "layout.jpg";
		break;

	case "beems3-help":
		bgimage = "question.jpg";
		break;

	case "beems3-faq":
		bgimage = "question.jpg";
		page_otherLanguage = "beems3";
		break;

	case "beemsx":
		bgimage = "layout.jpg";
		break;

	case "PyCell":
		bgimage = "pycell.jpg";
		break;

	case "beemsx-help":
		bgimage = "question.jpg";
		break;

	case "beemsx-faq":
		bgimage = "question.jpg";
		page_otherLanguage = "beemsx";
		break;

	case "beemsusr":
		bgimage = "keys.jpg";
		break;

	case "artwork":
		bgimage = "artwork.jpg";
		page_otherLanguage = "N/A";
		break;

	case "endoflife":
		bgimage = "end.jpg";
		page_otherLanguage = "N/A";
		break;

	case "ASM500":
		bgimage = "artwork.jpg";
		page_otherLanguage = "N/A";
		break;

	case "gbr2dxf":
		bgimage = "artwork.jpg";
		page_otherLanguage = "N/A";
		break;

	case "ASM600":
		bgimage = "artwork.jpg";
		page_otherLanguage = "N/A";
		break;

	case "ASM3500":
		bgimage = "artwork.jpg";
		page_otherLanguage = "N/A";
		break;

	case "gbrvu":
		bgimage = "artwork.jpg";
		page_otherLanguage = "N/A";
		break;

	case "netex-g":
		bgimage = "artwork.jpg";
		page_otherLanguage = "N/A";
		break;

	case "gbrunion":
		bgimage = "artwork.jpg";
		page_otherLanguage = "N/A";
		break;

	case "qckvu":
		bgimage = "artwork.jpg";
		page_otherLanguage = "N/A";
		break;

	case "gdsplot":
		bgimage = "artwork.jpg";
		page_otherLanguage = "N/A";
		break;

	case "gdsplot-c":
		bgimage = "artwork.jpg";
		page_otherLanguage = "N/A";
		break;

	case "gdsvu":
		bgimage = "artwork.jpg";
		page_otherLanguage = "N/A";
		break;

	case "gdsfilt":
		bgimage = "artwork.jpg";
		page_otherLanguage = "N/A";
		break;

	case "mbsvu":
		bgimage = "artwork.jpg";
		page_otherLanguage = "N/A";
		break;

	case "artwork-faq":
		bgimage = "question.jpg";
		page_otherLanguage = "N/A";
		break;

	case "cws":
		bgimage = "noise.jpg";
		page_otherLanguage = "N/A";
		break;

	case "service":
		bgimage = "service.jpg";
		break;

	case "company":
		bgimage = "company.jpg";
		break;

	case "access-c":
		bgimage = "SantaClara.jpg";
		break;

	case "access-y":
		bgimage = "ShinYokohama.jpg";
		break;

	case "carriers":
		bgimage = "keyboard.jpg";
		break;

	case "inquiry":
		bgimage = "post.jpg";
		break;

	case "privacy":
		bgimage = "field.jpg";
		page_otherLanguage = "N/A";
		break;

	case "environment":
		bgimage = "env.jpg";
		break;

	case "site-policy":
		bgimage = "leaves.jpg";
		break;

	case "site-map":
		bgimage = "directions.jpg";
		break;

	default:
		bgimage = "grain.jpg";
		break;
	}

	bgimage_url = bgimage_url + bgimage + ")";

	return true;

}


//――――――――――――――――――――――――――――――――――――――
// Change global font size throughout Anova 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 = "AnovaFontSize=" + size + ";expires=" + expire+ ";";

	// Set button color.
			SetButtonColor( size );
		}
	}

}

// Set font size.

function SetFontSize( size ){

	var obj;
	var point = anovaFontS;

//	if( size == "S" ) point = anovaFontS;
	if( size == "M" ) point = anovaFontM;
	if( size == "L" ) point = anovaFontL;

	// 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 )
		var 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 )
				obj = obj.document.body;
			else if( obj.document.getElementsByTagName )
				obj = obj.document.getElementsByTagName( "body" )[ 0 ];
			if( obj.style )
				obj.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 = bgimage_url;
	}

	// 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 ] == "AnovaFontSize" ) {
			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( openedMenu && openedMenu != 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( TimerOfMenu );
	openedMenu = id;
}

// Check if sub-menu is openend.

function CheckSubMenu( id ){

	// Close opened menu if any.
	if( openedSubMenu && openedSubMenu != 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( TimerOfSubMenu );
	openedSubMenu = id;
}


//――――――――――――――――――――――――――――――――――――――
// Close pulldown menu.
//――――――――――――――――――――――――――――――――――――――

function CloseMenu(){ 

	if( document.getElementById ){
		document.getElementById( openedMenu ).style.visibility = 'hidden';
	}
	else if( document.all ){
		document.all( openedMenu ).style.visibility = 'hidden';
	}
	else if( document.layers ){
		document.layers[ openedMenu ].visibility = 'hide';
	}

	openedMenu = null;

}


function CloseSubMenu(){ 

	if( document.getElementById ){
		document.getElementById( openedSubMenu ).style.visibility = 'hidden';
	}
	else if( document.all ){
		document.all( openedSubMenu ).style.visibility = 'hidden';
	}
	else if( document.layers ){
		document.layers[ openedSubMenu ].visibility = 'hide';
	}

	openedSubMenu = null;

}


//――――――――――――――――――――――――――――――――――――――
// Change language to English.
//――――――――――――――――――――――――――――――――――――――

function ChangeLanguage2English(){

	var page_jp, page_en, page, i;

	if( page_otherLanguage != "N/A" ){
		page_jp = window.location.pathname;
		i = page_jp.lastIndexOf( "\/jp" ) + 1;
		page_en = page_jp.substr( 0, i );
		i = page_jp.lastIndexOf( "\/" ) + 1;
		page = page_jp.substr( i );

		if( page.indexOf( "-j" ) >= 0 ){
			if( page_otherLanguage == "" ){
				page_en = page_en + page.replace( "-j", "-e" );
			}
			else{
				page_en = page_en + page_otherLanguage + "-e.html";
			}
		}
		else{
			page_jp = page_jp + "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." );
	}
}


//――――――――――――――――――――――――――――――――――――――
// Change language to Japanese.
//――――――――――――――――――――――――――――――――――――――

function ChangeLanguage2Japanese(){

	var page_jp, page_en, page, i;

	if( page_otherLanguage != "N/A" ){
		page_en = window.location.pathname;
		i = page_en.lastIndexOf( "\/" ) + 1;
		page_jp = page_en.substr( 0, i ) + "jp\/";
		page = page_en.substr( i );

		if( page.indexOf( "-e" ) >= 0 ){
			if( page_otherLanguage == "" ){
				page_jp = page_jp + page.replace( "-e", "-j" );
			}
			else{
				page_jp = page_jp + page_otherLanguage + "-j.html";
			}
		}
		else{
			page_jp = page_jp + "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." );
	}
}


//――――――――――――――――――――――――――――――――――――――
// End of file.
//――――――――――――――――――――――――――――――――――――――
