/*

information{
	ファイル名 : "/js/common/common.js";
	概要 : このJSファイルは全ページ共通で使用される変数、関数が定義されています。。;
	サイト名 : DOCOMO コーポレートサイト;
	URL : http://www.nttdocomo.co.jp/;
	コピーライト : (c) NTT DOCOMO, INC. All Rights Reserved.;
}

 */




/* 1. 環境変数の設定
--------------------------------------------------------------------------	*/
var agent = navigator.userAgent.toLowerCase();
var dname = new String(document.domain);
var path = new String(location.pathname);
var win = (agent.indexOf("windows") != -1);
var mac = (agent.indexOf("mac") != -1);
var w3c = document.getElementById;
var gecko = agent.indexOf("gecko") != -1;
var opera = agent.indexOf("opera",0) != -1;
var safari = agent.indexOf("safari") != -1;
var ie = agent.indexOf("msie") != -1 && !opera;
var ie5win = (agent.indexOf("msie 5.0") != -1) && win;
var ie55win = (agent.indexOf("msie 5.5") != -1) && win;
var ie6win = (agent.indexOf("msie 6.") != -1) && win;
var ie5mac = (agent.indexOf("msie") != -1) && mac;
var ns = agent.indexOf("netscape") != -1 && !opera;
var ns6 = (agent.indexOf("netscape6/6.") != -1) && ns;




/* 2. ブラウザ別スタイルシートを設定する関数
--------------------------------------------------------------------------	*/
// 6.





/* 3. イベント追加
--------------------------------------------------------------------------	*/
function addEvent(obj, type, listener) {
	if(window.addEventListener) window.addEventListener('load',listener,false);
	else {
		var prev  = obj[type];
		obj[type] = (prev) ? function() { prev(); listener(); } : listener;
	}
}
window.addOnload = function(listener){
	addEvent(window, 'onload', listener);
}





/* 4. ポップアップウインドウ
--------------------------------------------------------------------------	*/
function openWin(url,wname,w,h,resizable,toolbar,scrollbars,location,menubar){
	if (h >= (screen.height-30)){
		h = screen.height-100;
		w += 18;
		scrollbars = 1;
	}

	if (w >= (screen.width-30)){
		w = screen.width-100;
		h += 20;
		scrollbars = 1;
	}
		
	win_set = 'width = ' + w;
	win_set += ',height = ' + h;
	win_set += ',resizable = ' + resizable;
	win_set += ',toolbar = ' + toolbar;
	win_set += ',scrollbars = ' + scrollbars;
	win_set += ',location = ' + location;
	win_set += ',menubar = ' + menubar;
	win_set += ',statusbar = 1';

	swin = window.open(url,wname,win_set);
	swin.focus();
}




/* 5. スワップイメージ
--------------------------------------------------------------------------	*/
function roll(imageName, imageState) {
	if (loaded == 1 && imageState != '') {
		tabOn = eval(imageName+"_"+imageState+".src");
		document [imageName].src = tabOn;
	}
}



/* 6. 文字可変
--------------------------------------------------------------------------	*/

if (document.images) {
	var s_off = new Image(); s_off.src = '/images/header/font_small_off.gif';
	var s_on  = new Image(); s_on.src  = '/images/header/font_small_on.gif';
	var m_off = new Image(); m_off.src = '/images/header/font_middle_off.gif';
	var m_on  = new Image(); m_on.src  = '/images/header/font_middle_on.gif';
	var b_off = new Image(); b_off.src = '/images/header/font_big_off.gif';
	var b_on  = new Image(); b_on.src  = '/images/header/font_big_on.gif';
}

/**
 * FontStyle クラス
 */
// コンストラクタ
var FontStyle = function(url,title) {
    this.url     = url;
    this.title   = title;

    this.element = null;
};
// 生成
FontStyle.prototype.create = function() {
	if ( !this.created ) {
		var sc  = document.createElement('link');
		sc.rel  = "stylesheet";
		sc.type = "text/css";
		sc.href = this.url;
		sc.title   = this.title;

		document.documentElement.childNodes[0].appendChild(sc);
		this.element = sc;

		this.enable();
	}
};
// 有効にする
FontStyle.prototype.enable = function() {
	if ( this.element != null ) {
		this.element.disabled = false;
	}
	else {
		this.create();
	}
};
// 無効にする
FontStyle.prototype.disable = function() {
	if ( this.element != null ) {
		this.element.disabled = true;
	}
};
/** FontStyle */



/**
 * FontStyle インスタンス
 */
var common_url = "http://www.nttdocomo.co.jp";
var fontStyles = new Array();
fontStyles["f_b"]      = new FontStyle(common_url + "/css/common/font_b.css", "f_b");
fontStyles["default"]  = new FontStyle(common_url + "/css/common/font.css", "default");
fontStyles["f_s"]      = new FontStyle(common_url + "/css/common/font_s.css", "f_s");


function setDcmFontStyle(f_type) {
	if(f_type == "f_s"){
		document.images["s_img"].src = s_on.src;
		document.images["m_img"].src = m_off.src;
		document.images["b_img"].src = b_off.src;
	}else if(f_type == "f_b"){
		document.images["s_img"].src = s_off.src;
		document.images["m_img"].src = m_off.src;
		document.images["b_img"].src = b_on.src;
	}else{
		// f_type == "default"
		document.images["s_img"].src = s_off.src;
		document.images["m_img"].src = m_on.src;
		document.images["b_img"].src = b_off.src;
	
	}
	setActiveStyleSheet(f_type);
}


function setActiveStyleSheet(title) {

	for ( var i in fontStyles ) {
		if (i == "f_b" || i == "default" || i == "f_s") {
			if ( i == title ) {
				fontStyles[i].enable();
			}
			else {
				fontStyles[i].disable();
			}
		}
	}

  createCookie("style", title, 365);
}

function createCookie(name,value,days) {
  if (days) {
    var date = new Date();
    date.setTime(date.getTime()+(days*24*60*60*1000));
    var expires = "; expires="+date.toGMTString();
  }
  else expires = "";
  document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
  var nameEQ = name + "=";
  var ca = document.cookie.split(';');
  for(var i=0;i < ca.length;i++) {
    var c = ca[i];
    while (c.charAt(0)==' ') c = c.substring(1,c.length);
    if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
  }
  return null;
}



/* 7. ナビゲーション周りの調整
--------------------------------------------------------------------------	*/
function setNavStyle(){
	this.w3c = document.getElementById; if (!this.w3c) return false;
	return this;
}

setNavStyle.prototype = {
	init : function(){
		NS.setCls("localnav");
	},
	
	setCls : function(id){
		NS.id = document.getElementById(id); if(!NS.id) return false;
		NS.uls = NS.id.getElementsByTagName("ul"); if(!NS.uls) return false;
		for(var i=0; i< NS.uls.length ; i++){	NS.uls[i].firstChild.setAttribute(NS.getClsAtr(),"first");	}
		NS.fixW(id);
	},
	
	fixW : function(id){
		NS.id = document.getElementById(id); if(!NS.id) return false;
		NS.lis = NS.id.getElementsByTagName("li"); if(!NS.lis) return false;
		if(ie && win && ie5win){
				for(var i=0; i< NS.lis.length ; i++){	NS.lis[i].style.width = "auto";}
		}
		if(ie55win){
			uls = NS.id.getElementsByTagName("ul");clis = uls[1].getElementsByTagName("li");
			for(var i=0; i< clis.length ; i++){clis[i].style.paddingTop = "4px";}
		}
	},
		
	getClsAtr : function(){
		cls = ie? "className" : "class";
		return cls;
	}
}


var NS = new setNavStyle();
window.addOnload(NS.init);


/* 8. SiteCatalyst パラメータ
--------------------------------------------------------------------------	*/
var s_code_param = {};
s_code_param.pageType = "";

