/**************************************************************
**
**	script.js
**	----------------------------------------------------------
**	ORIGNAL JAVASCRIPT FILE
**	----------------------------------------------------------
**	管理側 各種javascript設定
**	# SLIDE MENU MAIN
**
**************************************************************/


/************************************************
**
**	FADEIN()
**	--------------------------------------------
**	OBJECT SLIDE
**
************************************************/

(function($){
    var name_space = 'imgAnim';
    $.fn[name_space] = function(options) {
    
        var imgBox = this;
        var boxs = imgBox.find(".fadebox");
        var boxs_count;
        var index = 1;
        
        var settings = $.extend({
            "anim"     : "slow"
           ,"interval" : "4000"
        }, options);
        
        var init = function(){
            num = 1;
            boxs.each(function(){
                $(this).find("a img").attr("class", "fadebox" + num);
                if( num > 1) $(this).find("a img").attr("class", "fadebox" + num).hide();
                num++;
            });
            boxs_count = num - 1;
        };
        var fade = function(){
            $(".fadebox" + index).fadeOut( settings["anim"], function(){
                index++;
                if( index > boxs_count) index = 1;
                $(".fadebox" + index).fadeIn( settings["anim"], function(){
                    //alert("comp");
                });
            });
        };
        
        var timer = setInterval(function(){
            fade();
        }, settings["interval"]);
        
        //main
        init();
        
        //method chain
        return this;
    };
})(jQuery);





/************************************************
**
**	slide()
**	--------------------------------------------
**	OBJECT SLIDE
**
************************************************/

var timer = null;

slide = function(objID) {

	var obj = document.getElementById(objID);
	obj.style.overflow = 'hidden';
	
	/* ------------------------------------------ *
	 * up()
	/* ------------------------------------------ */

	this.up = function(obj,ori,speed) {
		var present = getElementSize(obj).oh;
		var moveValue = speed + 3;
		
		present = present-moveValue;
	
		if(present > 0) {
			obj.style.height = present + 'px';
			timer = window.setTimeout(function(){ this.up(obj,ori,speed) }, 10);
		}
	
		else {
			obj.style.height = ori + 'px';
			obj.style.display = 'none';
			timer = null;
		};
	}
	
	
	/* ------------------------------------------ *
	 * down()
	/* ------------------------------------------ */
	
	this.down = function(obj,limit,slow) {
		var present = getElementSize(obj).oh;
		var distance = limit-present;
		var moveValue = Math.max(Math.floor(distance / slow),slow);
	
		if(present < limit) {
			obj.style.height = (present+moveValue) + 'px';
			timer = setTimeout(function(){ this.down(obj,limit,slow) }, 10);
		}
		
		else {
			obj.style.height = limit + 'px';
			timer = null;
		};
	}


	/* ------------------------------------------ *
	 * start
	/* ------------------------------------------ */

	var o = getElementSize(obj);
	var slow = 3;
	var speed = 30;

	$(".menu_contents").hide("fast");

	if(obj.offsetHeight == 0) {
		obj.style.display = 'block';
		obj.style.height = 0;
		if(timer == null) this.down(obj,o.oh,slow);
	}
	
	else {
		if(timer == null) this.up(obj,o.oh,speed);
	}
	
}



/************************************************
**
**	getElementSize()
**	--------------------------------------------
**	エレメンツのサイズ取得
**
************************************************/

getElementSize = function(elm) {
	var oSize = new Object();
	var elm2 = elm.cloneNode(true);

	if(-1 == navigator.userAgent.indexOf('MSIE 5')){
		elm2.style.padding = '0';
		elm2.style.border = '0';
	}
	elm2.style.display = 'block';
	elm2.style.position = 'absolute';

	elm.parentNode.appendChild(elm2);
	oSize.oh = elm2.clientHeight;
	oSize.ow = elm2.clientWidth;
	elm.parentNode.removeChild(elm2);
	
	return oSize;
}



/************************************************
**
**	getElementsByClass()
**	--------------------------------------------
**	エレメンツのサイズ取得
**
************************************************/

getElementsByClass = function(searchClass,node,tag) {
	var classElements = new Array();
	if ( node == null )
		node = document;
	if ( tag == null )
		tag = '*';
	var els = node.getElementsByTagName(tag);
	var elsLen = els.length;
	var pattern = new RegExp('(^|\\s)'+searchClass+'(\\s|$)');
	for (i = 0, j = 0; i < elsLen; i++) {
		if ( pattern.test(els[i].className) ) {
			classElements[j] = els[i];
			j++;
		}
	}
	return classElements;
}



/************************************************
**
**	menuToggle() -> onload -> NAVOGATION用
**	--------------------------------------------
**	SLIDE～getElementsByClassの処理読み込み
**	トグル効果
**
************************************************/

function menuToggle(number) {
	var frame_number	= "menu_contents" + number;
	var target_number	= "toggle" + number;
	var target			= getElementsByClass(target_number,document,'a');
	for(i=0; i<target.length; i++){
		target[i].onclick = function(){ slide(frame_number) };
	}
};



/************************************************
**
**	contentsToggle() -> 汎用
**	--------------------------------------------
**	DISPLAY -> 選択OBJECTのトグル処理
**
************************************************/

function contentsToggle(number){
	var frame_number	= "display_frame" + number;
	var target_number	= "toggle" + number;
	var target			= getElementsByClass(target_number,document,'a');
	for(i=0; i<target.length; i++){
		target[i].onclick = function(){ slide(frame_number) };
	}
}



/************************************************
**
**	allToggle() -> 汎用
**	--------------------------------------------
**	DISPLAY -> 総てのOBJECTのトグル処理
**
************************************************/

function allToggle(){

	$(".display_hide").toggle();

}



/************************************************
**
**	changeBackGround
**	--------------------------------------------
**	SELECT TAG の背景色変更
**
************************************************/

function changeBackGround(name){

	var	name		= name;

	name.style.backgroundColor=name.options[name.selectedIndex].style.backgroundColor;

}



/************************************************
**
**	getMonthEnd()
**	--------------------------------------------
**	PHP get_month.php読み込み
**	select tag-> PHP処理 : 年月から最終日取得
**
************************************************/

function getMonthEnd(name_flag){

	var	flag		= name_flag;
	var tag_id		= "#option_day" + flag;
	var year		= document.form["year" + flag].value;
	var month		= document.form["month" + flag].value;

	$(tag_id).load("/admin/script/get_month.php",{ year:year , month:month });

}



/************************************************
**
**	getMonthEnd()
**	--------------------------------------------
**	PHP get_month_day.php読み込み
**	select tag-> PHP処理 : 年月から最終日取得
**
************************************************/

function getMonthEndSearch(name_flag){

	var	flag		= name_flag;
	var tag_id		= "#option_day" + flag;
	var year		= document.form["year" + flag].value;
	var month		= document.form["month" + flag].value;

	$(tag_id).load("/admin/script/get_month_day.php",{ year:year , month:month });

}



/************************************************
**
**	getFileContents()
**	--------------------------------------------
**	PHP get_file_contents.php読み込み
**	checkbox tag-> PHP処理 : 指定ファイル読み込み
**
************************************************/

function getFileContents(file_id,display){

	var file_id			= file_id;
	var display_frame	= "#contents" + display;
	$(display_frame).load("/admin/script/get_file.php",{ file_id:file_id });

}



/************************************************
**
**	GET CITY
**	--------------------------------------------
**	市区町村呼び出し
**
************************************************/

function getCity(pref){
	var pref_number = pref;
	$('#user_city').load("/admin/script/get_city.php",{ pref:pref_number});
}



/************************************************
**
**	showContents()
**	--------------------------------------------
**	指定表示部分の交互出し入れ
**
************************************************/

function showContents(flag){

	var display	= "#display";

	if(flag != 1){
		$(display).show();
	} else {
		$(display).hide();
	}

}



/************************************************
**
**	showHideContents()
**	--------------------------------------------
**	CONTENTS 表示/非表示
**
************************************************/

function showHideContents(flag){

	if(flag == 1){
		var display		= "#display2";
		var no_display	= "#display1";
		$(display).show();
		$(no_display).hide();
	}else if(flag == 2){
		var display		= "#display1";
		var no_display	= "#display2";
		$(display).show();
		$(no_display).hide();
	}else if(flag == 3){
		var display		= "#display1";
		var no_display	= "#display2";
		$(display).show();
		$(no_display).show();
	}else if(flag == 4){
		var display		= "#display1";
		var no_display	= "#display2";
		$(display).hide();
		$(no_display).hide();
	}else if(flag == 0){
		var display		= "#display1";
		var no_display	= "#display2";
		$(display).hide();
		$(no_display).hide();
	}

}



/************************************************
**
**	ALL CHECKED
**	--------------------------------------------
**	NAME[id]のcheckboxを全選択、解除
**
************************************************/

$(function() {
    var _flag = 0;
    $("#check_all").click(function() {
        if (_flag == 0) {
            $("input:checkbox[name=id[]]").attr("checked", "true");
            _flag = 1;
        } else {
            $("input:checkbox[name=id[]]").attr("checked", "");
            _flag = 0;
        }
    });
});



/************************************************
**
**	HIDDEN URL
**	--------------------------------------------
**	リンク先URL HIDDEN
**
************************************************/

function hiddenUrl(){
	window.status = '';
	return true;
}
if (document.layers)
document.captureEvents(Event.MOUSEOVER | Event.MOUSEOUT);
document.onmouseover	= hiddenUrl;
document.onmouseout		= hiddenUrl;



/************************************************
**
**	WINDO COPY
**	--------------------------------------------
**	FORM呼び出し -> 新規タブで複製
**
************************************************/

function windowCopy(){
	document.callform.submit();
}




/************************************************
**
**	WINDO COPY
**	--------------------------------------------
**	FORM呼び出し -> 新規タブで複製
**
************************************************/

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_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_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];}
}

