function chenge_language(){
	
	lang = $F(document.language_form['data[language]']);
	
	if( lang != "" ){
		
		location.href = "/admin/users/menu?language=" + lang;
			
	}
		
}

function smartRollover() {
	if(document.getElementsByTagName) {
		var images = document.getElementsByTagName("img");

		for(var i=0; i < images.length; i++) {

			if(images[i].getAttribute("src") != null){
				
				if(images[i].getAttribute("src").match("_off."))
				{
					images[i].onmouseover = function() {
						this.setAttribute("src", this.getAttribute("src").replace("_off.", "_on."));
					}
					images[i].onmouseout = function() {
						this.setAttribute("src", this.getAttribute("src").replace("_on.", "_off."));
					}
				}
			
			}
			
		}

		var images = document.getElementsByTagName("input");

		for(var i=0; i < images.length; i++) {
			
			if(images[i].getAttribute("src") != null){
				
				if(images[i].getAttribute("src").match("_off."))
				{
					images[i].onmouseover = function() {
						this.setAttribute("src", this.getAttribute("src").replace("_off.", "_on."));
					}
					images[i].onmouseout = function() {
						this.setAttribute("src", this.getAttribute("src").replace("_on.", "_off."));
					}
				}
			}
			
		}

	}
}


if(window.addEventListener) {
	window.addEventListener("load", smartRollover, false);
}
else if(window.attachEvent) {
	window.attachEvent("onload", smartRollover);
}


function show_link_form(val){
	
//	alert($F(obj));
	
	if(val == 99){
		Element.show( $("link_1") );
		Element.show( $("link_2") );
		Element.show( $("link_3") );
		Element.show( $("link_4") );
	}else{

		Element.hide( $("link_1") );
		Element.hide( $("link_2") );
		Element.hide( $("link_3") );
		Element.hide( $("link_4") );
	}
		
}



// show child menus
var current_child_menu = "";
var	old_current_menu = "";
var tmid = null;

function showChildMenus(id, divid, layout){

	if(tmid){
		clearTimeout(tmid);
		tmid = null;
	}

	$j('#child_menu_div').css("position","absolute");

	$('child_menu_div').innerHTML = "";
	$("child_menu_div").hide();
	if( child_menu_obj[id] ){		
		$("child_menu_div").show();

		current_child_menu = id;

		// ボタンの場所を取得
		var divPos = Ext.get(divid);
		var xpos = divPos.getLeft();
		var ypos = divPos.getTop() + divPos.getHeight() - 2; // IE6でのずれに対応

		// イレギュラー処理
		if(layout == "type11D" || layout == "type12D" || layout == "type13D" || layout == "type14D"){
			xpos -= 40;
			ypos += 13;
		}
		if(layout == "type15D" || layout == "type16D" || layout == "type17D" || layout == "type18D"){
			xpos -= 20;	
			ypos += 11;
		}

		if(layout == "type27E"){
			xpos -= 20;
			ypos -= 16;
		}

		var str = '<div id="child_menu_ul">';
		str += '<ul>';
		for(var i=0; i<child_menu_obj[id].length; i++){
			str += '<li><a href="' + child_menu_obj[id][i].pc_link + '" target="' + child_menu_obj[id][i].target + '" id=>' + child_menu_obj[id][i].title + '</a></li>';
		}
		str += "</ul>";
		str += "</div>";
		
		$('child_menu_div').innerHTML = str;
		
		$('child_menu_div').setStyle({
			left: xpos + "px",
			top: ypos + "px"
		});

		Event.observe("child_menu_ul", "mouseover", resetChildMenu);
		Event.observe("child_menu_ul", "mouseout", hideChildMenu);

	}
	
}


function resetChildMenu(){

	if(!current_child_menu){
		current_child_menu = old_current_menu;
		old_current_menu   = "";
	}

	if(tmid){
		clearTimeout(tmid);
		tmid = null;
	}
	
}

function hideChildMenu(){

	if(tmid){
		clearTimeout(tmid);
		tmid = null;
	}

	tmid = setTimeout(hideChildMenu, 100);
	
	if(current_child_menu == ""){
		$('child_menu_div').innerHTML = "";
		$("child_menu_div").hide();
		if(tmid){
			clearTimeout(tmid);
			tmid = null;
		}

	}

	old_current_menu   = current_child_menu;
	current_child_menu = "";


}



/**
 * 郵便番号ajax取得
 * 市区町村と番地の入力が同じタイプ向け
 */
function searchAddressFromZip(api_path, zip1, zip2, pref, city){

	var zip = zip1 + "-" + zip2;

	if(zip.search(/[0-9]{3}-[0-9]{4}/i) == -1){
		alert("郵便番号の書式が正しくありません。000-0000の書式でご記入ください。");
		return false;
	}
	
	new Ajax.Request(api_path + zip , {
			method: 'get',
			onComplete: displayData
		}
    );

    function displayData(httpObj){

   		if( !httpObj.responseText ){

			alert("ご指定の郵便番号が見つかりませんでした。");

   		}else{

	   		var jsonData = eval( "(" + httpObj.responseText + ")");

		   	if(jsonData.EZip.zip_code){

				// 都道府県
				for(var i=0; i<pref.options.length; i++){
					if( pref.options[i].text == jsonData.EZip.pref_name){
						pref.options[i].selected = true;
						break;
					}
				}

				// 市区町村
				city.value = jsonData.EZip.city_name + jsonData.EZip.town_name;

			}

   		}

	}

}



function printPage(){

	print();

}


function selectAll(obj){

	obj.select();

}


/**
 * チェックボックス全チェック、解除関数
 * @param obj メイン操作用チェックボックス
 * @param form フォーム名
 * @param tgt 操作対象チェックボックス名
 * @return void
 */
function checkall(obj,form,tgt){
    bool = obj.checked;
    num  = document.forms[form][tgt].length;
	
    if(num >= 2){
        for(i=0;i<num;i++){
            document.forms[form][tgt][i].checked = bool;
        }
    }else{
        document.forms[form][tgt].checked = bool;
    }
}

