// *************************************************

// ページの読み込み時に起動

// *************************************************



Event.observe( window, 'load', function(){

	setRollOver('roll');

	setPullDownMenu('global_navi','menu','sub-navi');

	// 以下旧サイトからの引き継ぎ

	//getid();

});







// *************************************************

// 汎用関数

// *************************************************





// eventSetter

var isIE = isIE = (document.documentElement.getAttribute("style") == document.documentElement.style);



function eventSetter(obj,eventType,func){

	if(isIE) {

		obj.setAttribute(eventType,new Function(func));

	} else {

		obj.setAttribute(eventType,func);

	}

}





// open new window

function newWindow(uri,width,height){

	var myWindow = window.open(uri, 'newWindow', 'resizable=yes,scrollbars=yes,status=0,width='+width+',height='+height);

	if (myWindow.focus!=null) {

		myWindow.focus();

	}

}





// print window

function printWindow(){

	if(document.getElementById || document.layers){

		window.print();

	}

}





// Ajax recover UTF-8 (for Safari)

function recover_utf8(text){

	if(navigator.appVersion.indexOf('KHTML') > -1){

		var esc = escape(text);

		if(esc.indexOf('%u') < 0 && esc.indexOf('%') > -1){

			text = decodeURIComponent(esc);

		}

	}

	return text;

}





// input clear

function inputClear(id,txt){

	if ($(id).value == txt) $(id).value = '';

}



// scroll to top

function scrollToTop() {

	new Effect.ScrollTo("wrapper",{duration: 0.5});

}







// *************************************************

// 画像ロールオーバー

// *************************************************



var ImgRollOver = Class.create();

ImgRollOver.prototype = {

	initialize: function(img,type){

		this.img = img;

		this.outImgSrc = img.src;

		var imgSrcArray = img.src.split('.');

		var fileType = imgSrcArray[imgSrcArray.length - 1];

		this.overImgSrc = img.src.split('.' + fileType)[0] + '_o.' + fileType;

		if(type == "img"){

			Event.observe(

				img.parentNode,

				'mouseover',

				this.mouseOver.bindAsEventListener(this)

			);

			Event.observe(

				img.parentNode,

				'mouseout',

				this.mouseOut.bindAsEventListener(this)

			);

		}else if(type == "input"){

			Event.observe(

				img,

				'mouseover',

				this.mouseOver.bindAsEventListener(this)

			);

			Event.observe(

				img,

				'mouseout',

				this.mouseOut.bindAsEventListener(this)

			);

		}

		var preImage = new Image();

		preImage.src = this.overImgSrc;

	},

	mouseOver: function(){

		this.img.src = this.overImgSrc;

	},

	mouseOut: function(){

		this.img.src = this.outImgSrc;

	}

}



function setRollOver(className){

	var imgs = document.getElementsByTagName('img');

	var inputs = document.getElementsByTagName('input');

	var preImages = new Array();

	var preInputs = new Array();

	if(imgs){

		for(var i = 0,num = imgs.length;i < num;i++){

			img = imgs[i];

			if(Element.hasClassName(img, className)){

				new ImgRollOver(img,"img");

			}

		}

	}

	if(inputs){

		for(var i = 0,num = inputs.length;i < num;i++){

			input = inputs[i];

			if(input.type == 'image' && Element.hasClassName(input, className)){

				new ImgRollOver(input,"input");

			}

		}

	}

}







// *************************************************

// プルダウンメニュー

// *************************************************



var PullDownMenu = Class.create();

PullDownMenu.prototype = {

	initialize: function(menu,subnavi){

		this.menu = menu;

		this.img = this.menu.firstChild.firstChild;

		this.outImgSrc = this.img.src;

		this.subNavi = this.menu.getElementsByClassName(subnavi)[0];

		var imgSrcArray = this.img.src.split('.');

		var fileType = imgSrcArray[imgSrcArray.length - 1];

		this.overImgSrc = this.img.src.split('.' + fileType)[0] + '_o.' + fileType;

		Event.observe(

			this.menu,

			'mouseover',

			this.mouseOver.bindAsEventListener(this)

		);

		Event.observe(

			this.menu,

			'mouseout',

			this.mouseOut.bindAsEventListener(this)

		);

		var preImage = new Image();

		preImage.src = this.overImgSrc;

	},

	mouseOver: function(){

		this.img.src = this.overImgSrc;

		this.subNavi.style.display = 'block';

	},

	mouseOut: function(){

		this.img.src = this.outImgSrc;

		this.subNavi.style.display = 'none';

	}

}



function setPullDownMenu(wrapperID,navi,subnavi){

	if($(wrapperID)){

		var gnavi = $(wrapperID);

		var menus = gnavi.getElementsByClassName(navi);

		for(var i = 0,num = menus.length;i < num;i++){

			menu = menus[i];

			new PullDownMenu(menu,subnavi);

		}

	}

}







// *************************************************

// 旧サイトからの引き継ぎ

// *************************************************



var cmanager = new CookieManager();



function getid() {

	if($('checksave')){

		if(cmanager.getCookie("saveid")!=null){

			$('mb_id').value = cmanager.getCookie("saveid");

		}

		if(cmanager.getCookie("savepw")!=null){

			$('mb_pwd').value = cmanager.getCookie("savepw");

			$('checksave').checked = true;

		}

	}

}



function saveid() {

	var expdate = new Date();

	if($('checksave')){

		if($('checksave').checked == true){

			cmanager.setCookie("c_saveid", Form.Element.getValue('mb_id'));

			cmanager.setCookie("c_savepw", Form.Element.getValue('mb_pwd'));

			cmanager.setCookie("login_statusss", "t");

		} else {

			cmanager.clearCookie("saveid");

			cmanager.clearCookie("savepw");

		}

	}

}



function clear_ck() {

	if($('checksave').checked == false){

		cmanager.clearCookie("c_saveid");

		cmanager.clearCookie("c_savepw");

	}

}



function frmhead_check(f){

    var str = Form.Element.getValue('mb_pwd');

    $('mb_pwd_real').value = str;

    str = MD5(str);

    str = $('mb_id').value + str + $('sesc').value ;

    var result_temp;

    str = MD5(str);

    $('mb_pwd').value = "";

    $('mb_pwd').value = str;       

    

    errmsg = "";

    errfld = "";



	if (errmsg) {

		alert(errmsg);

		errfld.focus();

		return false;

    }else{

    	return true;

    }

}



function pwfind(pwsendurl) {

	win2 = window.open(pwsendurl,"" ,'resizable=no width=320 height=435 left=50 top=100 ');

	win2.focus;

}



function idActive(activate) {

	win1 = window.open(activate,"activate" ,'resizable=no scrollbars=yes width=417 height=335 left=0 top=0 ');

	win1.focus;

}



function aboutusbox(aboutusbox) {

	win1 = window.open(aboutusbox,"" ,'resizable=no scrollbars=yes width=620 height=620 left=0 top=0 ');

	win1.focus;

}



function aboutmvbox(aboutusbox) {

	win1 = window.open(aboutusbox,"" ,'resizable=no scrollbars=no width=320 height=240 left=0 top=0 ');

	win1.focus;

}



function aboutusbox(aboutusbox) {

	win1 = window.open(aboutusbox,"" ,'resizable=no scrollbars=yes width=620 height=620 left=0 top=0 ');

	win1.focus;

}



function freecharge(aboutusbox) {

	win1 = window.open(aboutusbox,"" ,'resizable=no scrollbars=no width=300 height=211 left=0 top=0 ');

	win1.focus;

}



function getWindowHeight(){

   if(typeof window.innerHeight != "undefined"){

      return window.innerHeight;

   }else if(document.compatMode=='CSS1Compat'){

      return document.documentElement.clientHeight;

   }else{

      return document.body.clientHeight;

   }

}



function resizeHeight(fr,scroll) {

//	fr = typeof fr == 'string' ? document.getElementById(fr) : fr;

//	fr.setExpression('height',Content.document.body.scrollHeight+0);

	if(isIE){

		$(fr).setAttribute("height",$(fr).document.body.scrollHeight);

	}else{

//		$(fr).setAttribute("height",getWindowHeight());

		$(fr).setAttribute("height",1500);

		$(fr).setAttribute("scrolling","auto");

	}

	if(scroll != 'noscroll'){

//		new Effect.ScrollTo(fr,{duration: 0});

			new Effect.ScroolTo('wrapper',{duration: 0});

	}

}



// from body.php

function change_cursor(param){

	document.body.className = param;

}



function changeMenu1(n,img1,img2){

	eval("menuimg1_1.src='"+img1+"';");

	eval("menuimg1_2.src='"+img2+"';");

	for (i=1; i<=2; i++){

		if (i == n)	eval("menu1_"+i+".style.display='';");

		else		eval("menu1_"+i+".style.display='none';");

	}

} 



function changeMenu2(n,img1,img2){

	eval("menuimg2_1.src='"+img1+"';");

	eval("menuimg2_2.src='"+img2+"';");

	for (i=1; i<=2; i++){

		if (n == i)	eval("menu2_"+i+".style.display='';");

		else		eval("menu2_"+i+".style.display='none';");

	}

}



function MM_preloadImages() { //v3.0

  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();

    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)

    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}

}



function MM_swapImgRestore() { //v3.0

  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;

}



function MM_findObj(n, d) { //v4.01

  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {

    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}

  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];

  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);

  if(!x && d.getElementById) x=d.getElementById(n); return x;

}



function MM_swapImage() { //v3.0

  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)

   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}

}

