/*-----------------------------------------------------------------------
 * co-brandのヘッダ、フッタ出力用
 *
 * DEPENDENCIES
 *  - nv_base.js
 *  - todofuken_cd.js
 *
 * @version $Revision: 1144 $
 *-----------------------------------------------------------------------
 */

//MSN用のデータ
var MSN = {
	cp : "001",
	bgColor : "#FFFFFF"
}

var CoBrand = null;
var paramCp = NVRequest.getParameter("CP");

//以下、CPパラメータの形式が妥当であれば、オブジェクトを生成
if(paramCp && paramCp.match(/^\d{3}$/)){


/*----------------オブジェクト生成開始--------------------*/


var KEIMANA = {
	bgColor : "#FFFFFF"
}
function _CoBrand(cp){
	var self = this;
	this.undoStyleHandler = function(){self.undoStyle();};
	this.error = null;
	this.nullElement = new Object();

	//他の必要なJSと同期をとるためヘッダー部で読み込む
	document.write([

	'<script src="' + this.root + 'nv/js/' + cp + '-header.js"></script>', // get_co_header
	'<script src="' + this.root + 'nv/js/' +  cp + '-footer.js"></script>', // get_co_footer
	'<script src="' + this.root + 'public/js/site_header.js"></script>', // get_site_header
	'<script src="' + this.root + 'public/js/site_footer.js"></script>', // get_site_footer

	''].join(" \n"));
	
	this.changeStyle();
	this.changeStyleByCoBrand();
}

_CoBrand.prototype = {
	head : function(mode){
		try{
			if (!this.error) document.write(get_co_header() + get_site_header());
		}catch(e){
			this.error = "cannot write header";
			throw e;
		}
	},
	foot : function(mode){
		try{
			if (!this.error) document.write(get_site_footer() + get_co_footer());
		}catch(e){
			this.error = "cannot write footer";
			throw e;
		}
	},
	//エラー時に設定を元に戻す
	undoStyle : function(){
		if(this.error == null){
			return;
		}
		this.getStyle("header").display = "block"; 
		this.getStyle("header2").display = "block";
		this.getStyle("header4").display = "block";
		this.getStyle("header5").display = "block";
		this.getStyle("co_header").display = "block"; 
		this.getStyle("co_header2").display = "block";
		this.getStyle("co_header4").display = "block";
		this.getStyle("co_header5").display = "block";
		this.getStyle("keimanaFooter").display = "block";
		this.getStyle("footer").display = "block";
		this.getStyle("co_footer").display = "block";
		this.undoStyleByCoBrand();
	},
	getStyle : function(id){
		var obj = document.getElementById(id);
		if(obj == null){
			return this.nullElement;
		}
		return obj.style;
	}
}

//大学のみパスが違うため
if(location.pathname.indexOf("/college") == 0){
	_CoBrand.prototype.root = "/college/";
	_CoBrand.prototype.changeStyle = function(){
		document.write([

			'<style type=text/css>',
			'#co_header {display: none;}',
			'#co_header2 {display: none;}',
			'#co_header4 {display: none;}',
			'#co_header5 {display: none;}',
			'#co_footer {display: none;}',
			'#keimanaFooter {display: none;}',
			'</style>',

		''].join(" \n"));
	};

}else{
	//keimanaPartの「margin-bottom: 15px」
	//はフッタとアライアンス用iframeの隙間のために必要
	//大学はid=footer3のdivが使われているため、不要
	_CoBrand.prototype.root = "/";
	_CoBrand.prototype.changeStyle = function(){
		document.write([

			'<style type=text/css>',
			'#header {display: none;}',
			'#header2 {display: none;}',
			'#header4 {display: none;}',
			'#header5 {display: none;}',
			'#keimanaFooter {display: none;}',
			'#keimanaPart {padding-bottom: 15px;}',
			'</style>', 

		''].join(" \n"));
	}
}

//MSNの場合は背景色を変更する
if(paramCp == MSN.cp){
	_CoBrand.prototype.changeStyleByCoBrand = function(){
		document.write([
			'<style type=text/css>',
				'body {background-color: ' + MSN.bgColor + ';}',
				'#container {background-color: ' + MSN.bgColor + ';}',
				'#pageBody {background-color: ' + KEIMANA.bgColor + ';}',
				'#header3 {background-color: ' + KEIMANA.bgColor + ';}',
				'#footer3 {background-color: ' + KEIMANA.bgColor + ';}',
				'#co_header3 {background-color: ' + KEIMANA.bgColor + ';}',
				'#co_footer3 {background-color: ' + KEIMANA.bgColor + ';}',
				'#keimanaPart {background-color: ' + KEIMANA.bgColor + ';}',
			'</style>',
		''].join(" \n"));
	},
	//エラー時にはロールバック
	_CoBrand.prototype.undoStyleByCoBrand = function(){
		document.body.style.backgroundColor = null;
		this.getStyle("container").backgroundColor = null;
		this.getStyle("pageBody").backgroundColor = null;
		this.getStyle("header3").backgroundColor = null;
		this.getStyle("footer3").backgroundColor = null;
		this.getStyle("co_header3").backgroundColor = null;
		this.getStyle("co_footer3").backgroundColor = null;
		this.getStyle("keimanaPart").backgroundColor = null;
	}
}else{
	_CoBrand.prototype.changeStyleByCoBrand = function(){};
	_CoBrand.prototype.undoStyleByCoBrand = function(){};
}


CoBrand = new _CoBrand(paramCp);


/*----------------オブジェクト生成終了--------------------*/


}

