function search(menu)
{
	location.href = "?group_type_id="+menu.options[menu.selectedIndex].value;
}

function zipSearch(zid1, zid2)
{
	id1 = $(zid1).value;
	id2 = $(zid2).value;
	if (id1 && id2) {
		id = id1 + id2;
		if (id.length != 7) {
			alert('郵便番号は半角数字7桁入力してください。');
			return false;
		} else if (id.match(/[^0-9]+/)) {
			alert('郵便番号は半角数字で入力してください。');
			return false;
		}	
	} else {
		alert('郵便番号を入力してください。');
		return false;
	}
	return true;
}

function updateSelect(id, id2, name, flag)
{
	var prefectureId = $(id2).value;
	
	var url = 'updateSelect/'+prefectureId;
	if (flag) {
		url = '../updateSelect/'+prefectureId;
	}
	
	var myAjax = new Ajax.Request(
    url, 
    {
        method: "get",
        onComplete: function(r) {
			var isMSIE = /*@cc_on!@*/false;
			
			if (isMSIE) {
			    $(id).outerHTML = '<div id="'+id+'"><select name="'+name+'"  id="'+id+'">' + r.responseText + '</select></div>';
			} else {
			    $(id).innerHTML = r.responseText;
			}
		}
    });	
}

function UpdateSelectRequest(id, id2, name, url)
{
	var Id = $(id2).value;
	var url = url+Id;

	var myAjax = new Ajax.Request(
    url,
	{
        method: "get",
        onComplete: function(r) {
			var isMSIE = /*@cc_on!@*/false;

			if (isMSIE) {
				$(id).outerHTML = '<select name="'+name+'"  id="'+id+'">' + r.responseText + '</select>';
			} else {
				$(id).innerHTML = r.responseText;
			}
		}
    });	
}


function updateSelectCity(id, id2, name, flag)
{
	var prefectureId = $(id2).value;
	
	var url = 'updateSelectCity/'+prefectureId;
	if (flag) {
		url = '../updateSelectCity/'+prefectureId;
	}
	
	var myAjax = new Ajax.Request(
    url, 
    {
        method: "get",
        onComplete: function(r) {
			var isMSIE = /*@cc_on!@*/false;
			
			if (isMSIE) {
			    $(id).outerHTML = '<div id="'+id+'"><select name="'+name+'"  id="'+id+'">' + r.responseText + '</select></div>';
			} else {
			    $(id).innerHTML = r.responseText;
			}
		}
    });	
}


function updateSelect2(id, id2, name, flag)
{
	var prefectureId = $(id2).value;
	
	var url = 'updateSelect/'+prefectureId;
	if (flag) {
		url = '../updateSelect/'+prefectureId;
	}
	
	var myAjax = new Ajax.Request(
    url, 
    {
        method: "get",
        onComplete: function(r) {
			var isMSIE = /*@cc_on!@*/false;
			
			if (isMSIE) {
			    $(id).outerHTML = '<div id="'+id+'"><select name="'+name+'" id="'+id+'">'+r.responseText+'</select></div>';
			} else {
			    $(id).innerHTML = r.responseText;
			}

			$('radio0').checked = false;
			$('radio1').checked = false;
			$('radio10').checked = false;
			$('radio11').checked = false;
			$('radio12').checked = false;
			$('FeatureCategoryName').value = '';
			$('list').style.display = "none";
		}
    });	
}

function updateSelect3(id, id2, name, id3, id4, id5)
{
	var isMSIE = /*@cc_on!@*/false;
	if (isMSIE) {
	    return;
	}

	var infoType = $(id2).value;
	var featureId = $(id4).value;

	var url = 'updateSelect2/'+id5+'/'+infoType+'/'+featureId;
	
	if(id5 == 1){
		$('radio10').checked = true;
		$('radio11').checked = false;
		$('radio12').checked = false;
	}
	var myAjax = new Ajax.Request(
    url, 
    {
        method: "get",
        onComplete: function(r) {
			
			if (isMSIE) {
			    $(id).outerHTML = '<div id="'+id+'">'+r.responseText+'</div>';
			} else {
			    $(id).innerHTML = r.responseText;
			}

			$('list').style.display = "block";
		}
    });	
}

tags = new Array(
 '[%img([%TEXT%]', ')%]',/* 0 */
 '[%img(', ')%]',/* 2 */
 '[%link([%TEXT%])%]', '[%/link%]',/* 4 */
 '[%link([%TEXT%]):new%]', '[%/link%]',/* 6 */
 '[%color([%TEXT%])%]', '[%/color%]',/* 8 */
 '[%bold%]', '[%/bold%]',/* 10 */
 '[%clear%]', '',/* 12 */
 '[%more%]', '\n'/* 14 */
 );
 
 
function move(move_num, area) {
    var range = document.selection.createRange();
    var move_fun = "";
    if(move_num > 0) {
        move_fun = "moveStart";
    } else {
        move_fun = "moveEnd";
    }
    range.select();
    area.focus();
}

function setval(value, id){
	obj = $(id);
	
	var selStart = '';
	var selEnd = '';
	var v = '';
	var value1 = '';
	var value2 = '';
	var s1 = '';
	var s2 = '';
	var s3 = '';
		
	var isMSIE = /*@cc_on!@*/false;
	
	if (isMSIE) {
	} else {
		var selStart = obj.selectionStart;
		var selEnd = obj.selectionEnd;
		s1 = (obj.value).substring(0, selStart);
		s2 = (obj.value).substring(selStart, selEnd);
		s3 = (obj.value).substring(selEnd);
	}

	if (value == 0 && !s2) {
		text = prompt("画像URL","http://");
		if (!text) {
			return true;
		}
		var tagsValue = tags[value];
		v = tagsValue.replace('[%TEXT%]', text);
	}

	if (value == 4 || value == 6) {
		text = prompt("リンク先URL","http://");
		if (!text) {
			return true;
		}
		var tagsValue = tags[value];
		v = tagsValue.replace('[%TEXT%]', text);
	}
	
	if (value == 8) {
		if (!s2 && !isMSIE) {
			return;
		}
		var color = '';
		color = $('colorfield4').value;
		tagsValue = tags[value];
		v = tagsValue.replace('[%TEXT%]', '#'+color);		
	}

	if (value == 14) {
		$('Separate').disabled = true;
	}
	
	value1 = (v) ? v :tags[value];
	value2 = tags[value + 1];

	if (isMSIE) {
		/*var IEValue = (v) ? v : s2;*/
		if (obj.createTextRange) {
			obj.currentPos = document.selection.createRange().duplicate();
		}
		if (obj.createTextRange && obj.currentPos.text) { 
			var currentPos = obj.currentPos; 
			currentPos.text = value1 + currentPos.text + value2;
		} else { 
			if (value != 8) {
				obj.value = obj.value + value1 + value2;
			}
		}
	
	} else {
		
		obj.value = s1 + value1 + s2 + value2 + s3;
	}	
	
}

function colorInit(flag) {
	new Control.ColorPicker("colorfield4", { "swatch" : "colorbox4" }, flag);
}

function addMedia(url) {	
	var mediapopup = window.open(url,'name',
		'status=yes,toolbar=no,scrollbars=yes,resizable=yes,width=500,height=450,top=0,left=0');

	return;
}

var timeBeforeAutoHide = 700;	// Microseconds to wait before auto hiding menu(1000 = 1 second)
var slideSpeed_out = 10;	// Steps to move sub menu at a time ( higher = faster)
var slideSpeed_in = 10;
	

var slideTimeout_out = 25;	// Microseconds between slide steps ( lower = faster)
var slideTimeout_in = 10;	// Microseconds between slide steps ( lower = faster)

var showSubOnMouseOver = true;	// false = show sub menu on click, true = show sub menu on mouse over
var fixedSubMenuWidth = false;	// Width of sub menu items - A number(width in pixels) or false when width should be dynamic

var xOffsetSubMenu = 0; 	// Offset x-position of sub menu items - use negative value if you want the sub menu to overlap main menu

var slideDirection = 'right';	// Slide to left or right ?

/* Don't change anything below here */

var activeSubMenuId = false;
var activeMainMenuItem = false;
var currentZIndex = 1000;		
var autoHideTimer = 0;
var submenuObjArray = new Array();
var okToSlideInSub = new Array();
var subPositioned = new Array();


function stopAutoHide()
{
	autoHideTimer = -1;
}

function initAutoHide()
{
	autoHideTimer = 0;
	if(autoHideTimer>=0)autoHide();
}

function autoHide()
{
	
	if(autoHideTimer>timeBeforeAutoHide)
	{
		
		if(activeMainMenuItem){
			activeMainMenuItem.className='';
			activeMainMenuItem = false;
		}
		
		if(activeSubMenuId){
			var obj = document.getElementById('subMenuDiv' + activeSubMenuId);
			showSub();
		}
	}else{
		if(autoHideTimer>=0){
			autoHideTimer+=50;
			setTimeout('autoHide()',50);
		}
	}
}	

function getTopPos(inputObj)
{		
  var returnValue = inputObj.offsetTop;
  while((inputObj = inputObj.offsetParent) != null)returnValue += inputObj.offsetTop;
  return returnValue;
}

function getLeftPos(inputObj)
{
  var returnValue = inputObj.offsetLeft;
  while((inputObj = inputObj.offsetParent) != null)returnValue += inputObj.offsetLeft;
  return returnValue;
}

/************************************************************************************************************
Tooltip
************************************************************************************************************/	
var dhtmlgoodies_tooltip = false;
var dhtmlgoodies_tooltipShadow = false;
var dhtmlgoodies_shadowSize = 4;
var dhtmlgoodies_tooltipMaxWidth = 200;
var dhtmlgoodies_tooltipMinWidth = 150;
var dhtmlgoodies_iframe = false;
/*
var tooltip_is_msie = (navigator.userAgent.indexOf('MSIE')>=0 && navigator.userAgent.indexOf('opera')==-1 && document.all)?true:false;
*/
var tooltip_is_msie = false; 
function showTooltip(e,tooltipTxt)
{
	
	var bodyWidth = Math.max(document.body.clientWidth,document.documentElement.clientWidth) - 20;

	if(!dhtmlgoodies_tooltip){
		dhtmlgoodies_tooltip = document.createElement('DIV');
		dhtmlgoodies_tooltip.id = 'dhtmlgoodies_tooltip';
		dhtmlgoodies_tooltipShadow = document.createElement('DIV');
		dhtmlgoodies_tooltipShadow.id = 'dhtmlgoodies_tooltipShadow';
		
		document.body.appendChild(dhtmlgoodies_tooltip);
		document.body.appendChild(dhtmlgoodies_tooltipShadow);	
		
		if(tooltip_is_msie){
			dhtmlgoodies_iframe = document.createElement('IFRAME');
			dhtmlgoodies_iframe.frameborder='5';
			dhtmlgoodies_iframe.style.backgroundColor='#FFFFFF';
			dhtmlgoodies_iframe.src = '#'; 	
			dhtmlgoodies_iframe.style.zIndex = 100;
			dhtmlgoodies_iframe.style.position = 'absolute';
			document.body.appendChild(dhtmlgoodies_iframe);
		}
		
	}
	
	dhtmlgoodies_tooltip.style.display='block';
	dhtmlgoodies_tooltipShadow.style.display='block';
	if(tooltip_is_msie)dhtmlgoodies_iframe.style.display='block';
	
	var st = Math.max(document.body.scrollTop,document.documentElement.scrollTop);
	if(navigator.userAgent.toLowerCase().indexOf('safari')>=0)st=0; 
	var leftPos = e.clientX + 10;
	
	dhtmlgoodies_tooltip.style.width = null;	// Reset style width if it's set 
	dhtmlgoodies_tooltip.innerHTML = '<font size="2px">'+tooltipTxt+'</font>';
	dhtmlgoodies_tooltip.style.left = leftPos + 'px';
	dhtmlgoodies_tooltip.style.top = e.clientY + 10 + st + 'px';

	
	dhtmlgoodies_tooltipShadow.style.left =  leftPos + dhtmlgoodies_shadowSize + 'px';
	dhtmlgoodies_tooltipShadow.style.top = e.clientY + 10 + st + dhtmlgoodies_shadowSize + 'px';
	
	if(dhtmlgoodies_tooltip.offsetWidth>dhtmlgoodies_tooltipMaxWidth){	/* Exceeding max width of tooltip ? */
		dhtmlgoodies_tooltip.style.width = dhtmlgoodies_tooltipMaxWidth + 'px';
	}
	
	var tooltipWidth = dhtmlgoodies_tooltip.offsetWidth;		
	if(tooltipWidth<dhtmlgoodies_tooltipMinWidth)tooltipWidth = dhtmlgoodies_tooltipMinWidth;
	
	
	dhtmlgoodies_tooltip.style.width = tooltipWidth + 'px';
	dhtmlgoodies_tooltipShadow.style.width = dhtmlgoodies_tooltip.offsetWidth + 'px';
	dhtmlgoodies_tooltipShadow.style.height = dhtmlgoodies_tooltip.offsetHeight + 'px';		
	
	if((leftPos + tooltipWidth)>bodyWidth){
		dhtmlgoodies_tooltip.style.left = (dhtmlgoodies_tooltipShadow.style.left.replace('px','') - ((leftPos + tooltipWidth)-bodyWidth)) + 'px';
		dhtmlgoodies_tooltipShadow.style.left = (dhtmlgoodies_tooltipShadow.style.left.replace('px','') - ((leftPos + tooltipWidth)-bodyWidth) + dhtmlgoodies_shadowSize) + 'px';
	}
	
	if(tooltip_is_msie){
		dhtmlgoodies_iframe.style.left = dhtmlgoodies_tooltip.style.left;
		dhtmlgoodies_iframe.style.top = dhtmlgoodies_tooltip.style.top;
		dhtmlgoodies_iframe.style.width = dhtmlgoodies_tooltip.offsetWidth + 'px';
		dhtmlgoodies_iframe.style.height = dhtmlgoodies_tooltip.offsetHeight + 'px';
	
	}
			
}

function hideTooltip()
{
	dhtmlgoodies_tooltip.style.display='none';
	dhtmlgoodies_tooltipShadow.style.display='none';		
	if(tooltip_is_msie)dhtmlgoodies_iframe.style.display='none';		
}

/************************************************************************************************************
Map
************************************************************************************************************/	
function popMap(uri, mode, latitude, longitude)
{
	var latId = mode + latitude;
	var lngId = mode + longitude;
	
	var lat = $(latId).value;
	var lng = $(lngId).value;

	if (lat.match(/^[0-9.]*$/) == null || lng.match(/^[0-9.]*$/) == null) {
	    alert("緯度、経度は半角数字と「.」で入力して下さい。");
	    return;
	}

	if (!lat || !lng) {
		lat = '26.221444';
		lng = '127.685165';
	}
	var menuPath = '';
/*
	var domain = location.hostname;
	if (domain == 'localhost') {
		menuPath = '/RIKKA';
	}
*/
	javascript:void window.open(menuPath+'/admin/'+uri+'/map/'+lat+'/'+lng+'/'+latitude+'/'+longitude,'popup','status=yes,toolbar=no,scrollbars=yes,resizable=yes,width=500,height=540,top=0,left=0');
}

/************************************************************************************************************
ON ⇔ OFF switcher
************************************************************************************************************/	
function execute(id, val) {
	var str = location.pathname;
	if (str.match("tours")) {
		var ctl = 'tours';
	} else {
		var ctl = 'spots';
	}
	
	var menuPath = '';
/*
	var domain = location.hostname;
	if (domain == 'localhost') {
		menuPath = '/RIKKA';
	}
*/	
	var a = new Ajax.Updater(
		"container"+id,
		menuPath+"/admin/"+ctl+"/updater/"+id+"/"+val,
		{
			"method": "get",
			onComplete: function(request) {
			}
		}
	);
}

/* Banner Switcher */
function execute_bnr(id, val) {
	var menuPath = '';
	var a = new Ajax.Updater(
		"container"+id,
		menuPath+"/admin/banners/updater/"+id+"/"+val,
		{
			"method": "get",
			onComplete: function(request) {
			}
		}
	);
}

function mapxml(url)
{
	var myAjax = new Ajax.Request(
    url,
	{
        method: "get",
        onComplete: function(r) {
			return r.responseText;
		}
    });	
}







