function show_wait()
{
    var arrayPageSize = this.getPageSize();
//    $('overlay').setStyle({ width: arrayPageSize[0] + 'px', height: arrayPageSize[1] + 'px' });
    var wait_window_margin_height = 15;
    var wait_window_margin_width = 20;
    $('wall').style.width = arrayPageSize[0] + "px";
    $('wall').style.height = arrayPageSize[1] + "px";
    if($('dummy_iframe'))
    {
    $('dummy_iframe').style.top = wait_window_margin_height + "px";
    $('dummy_iframe').style.height = (arrayPageSize[1] - (wait_window_margin_height * 2) - 5 ) + "px";
    $('dummy_iframe').style.left = wait_window_margin_width + "px";
    $('dummy_iframe').style.width = (arrayPageSize[0] - (wait_window_margin_width * 2) - 5 ) + "px";
    $('dummy_iframe').show();
    }
    $('wait').style.top = wait_window_margin_height + "px";
    $('wait').style.height = arrayPageSize[1] - (wait_window_margin_height * 2) + "px";
    $('wait').style.left = wait_window_margin_width + "px";
    $('wait').style.width = arrayPageSize[0] - (wait_window_margin_width * 2) + "px";
    $('wall').show();
    window.scroll(0,0);
}

function show_wait2()
{
    var arrayPageSize = this.getPageSize();
	new Insertion.Top('pageTop', '<div id="wall" style="position:absolute; height:' + arrayPageSize[1] + 'px; width:100%; top:0px; left:0px; background-color:#606060;"><div id="wait" style="position:absolute; z-index:200; background:url(/images/bg_mainbody.gif) center top repeat;">Please wait...<script type="text/javascript">new Ajax.Updater("wait", "/util/searching", { asyncronous: true, evalScripts: true });</script></div><iframe id="dummy_iframe" style="position:absolute; z-index:180; display:none;"></iframe></div>');
	show_wait();
}

function hide_wait()
{
    $('wall').hide();
}

function addSelOption(selObj, value, text)
{
    selObj.length++;
    selObj.options[selObj.length - 1].value = value;
    selObj.options[selObj.length - 1].text = text;
}

function createSelection(selObj, caption, ary)
{
    selObj.length = 0;
    addSelOption(selObj, '0', caption);
    for(var i = 0; i < ary.length; i++)
    {
        val = ary[i].split(':');
        addSelOption (selObj , val[0], val[1]);
    }
}

function initACC(area_code, country_code, city_code)
{
    var country_code_idx = 0;
    var city_code_idx = 0;
    $('area').selectedIndex = area_code;
    createSelection($('country'), '(国名を選択してください)', countries[area_code]);
    for(var i=0; i<countries[area_code].length; i++)
    {
        if(countries[area_code][i].split(':')[0]==country_code)
        {
            country_code_idx = i+1;
            break;
        }
    }
    $('country').selectedIndex = country_code_idx;
    createSelection($('city'), "(都市を選択してください)", cities[country_code]);
    for(var i=0; i<cities[country_code].length; i++)
    {
        if(cities[country_code][i].split(':')[0]==city_code)
        {
            city_code_idx = i+1;
            break;
        }
    }
    $('city').selectedIndex = city_code_idx;
}

function areaSelected(obj)
{
    var area_code = obj.value;
    if(area_code == 0)
    {
        createSelection($('country'), "(先にエリアを選択してください)", new Array());
        createSelection($('city'), "(先に国名を選択してください)", new Array());
    } else {
        createSelection($('country'), '(国名を選択してください)', countries[obj.value]);
        createSelection($('city'), "(先に国名を選択してください)", new Array());
    }
}

function countrySelected(obj)
{
    var country_code = obj.value; //$('country').value;
    if(country_code == 0)
        createSelection($('city'), "(先に国名を選択してください)", new Array());
    else
        createSelection($('city'), "(都市を選択してください)", cities[country_code]);
}

function checkinDateChanged()
{
	updateCheckoutDate();
}

function checkoutDateChanged()
{
	var current_enddate = $('checkout_date').value;
    var temp = $('checkin_date').value.split('/');
    var startdate = new Date(temp[0], temp[1]-1, temp[2]);
    temp = $('checkout_date').value.split('/');
    var enddate = new Date(temp[0], temp[1]-1, temp[2]);
    var diff = enddate - startdate;
    var stay = diff / 86400000; //1日は86400000ミリ秒
    if(stay > 0 && stay <= 10)
    {
	    $('num_nights').value = stay;
	}
	else
	{
		alert('チェックアウト日はチェックイン日の翌日から１０日間の範囲で設定してください');
		updateCheckoutDate();
	}
}

function numNightsChanged()
{
	updateCheckoutDate();
}

function numRoomsChanged()
{
	if($('num_children').value > 0 && $('room').value > 1)
	{
		alert('お子様が含まれる場合には、お手数ですが１部屋ずつご予約ください。');
		$('room').selectedIndex = 0;
	}
}

function updateCheckoutDate()
{
    var stay = parseInt($('num_nights').value);
    var temp = $('checkin_date').value.split('/');
    if(parseInt(temp[0],10) > 0 && parseInt(temp[1],10) > 0 && parseInt(temp[2],10) > 0)
    {
        var startdate = new Date(temp[0], temp[1]-1, temp[2]);
        var enddate = new Date(startdate.getFullYear(), startdate.getMonth(), startdate.getDate() + stay);
        $('checkout_date').value = enddate.getFullYear() + '/' + zp((enddate.getMonth() + 1)) + '/' + zp(enddate.getDate());
    }
    else
    {
    	$('checkout_date').value = '';
    }
}

function zp(n)
{
    if(n < 10)
        return '0' + n;
    else
        return '' + n;
}

function dp_click(item, fn, dn)
{
  $(fn).value = item.getAttribute("value");
  if(fn == 'checkin_date')
      updateCheckoutDate();
  else if(fn == 'checkout_date')
  	  checkoutDateChanged();
  $(dn).hide();
}

function ngaChanged(row)
{
	//gcc_selObj = $('num_guests_c'+row);
	gcc_selObj = $('num_children');
	var current_gcc = gcc_selObj.value;
    gcc_selObj.length = 0;
	//var gca = $('num_guests_a'+row).value;
	var gca = $('num_adults').value;
	var max_gcc = 3 - parseInt(gca);
    for(var i = 0; i <= max_gcc; i++)
    {
        addSelOption(gcc_selObj, i, i);
    }
    if(max_gcc >= current_gcc)
    {
    	gcc_selObj.selectedIndex = current_gcc;
    }
    ngcChanged(row);
}

function ngcChanged(row)
{
	//var gcc = parseInt($('num_guests_c'+row).value);
	var gcc = parseInt($('num_children').value);
	for(var i = 1; i < 4; i++)
	{
		if(i <= gcc)
			//$('age'+row+'_'+i).show();
			$('li-age'+i).show();
		else
			//$('age'+row+'_'+i).hide();
			$('li-age'+i).hide();
	}
	if(gcc > 0) numRoomsChanged();
}

function getBrowserWidth() {
        if ( window.innerWidth ) {
                return window.innerWidth;
        }
        else if ( document.documentElement && document.documentElement.clientWidth != 0 ) {
                return document.documentElement.clientWidth;
        }
        else if ( document.body ) {
                return document.body.clientWidth;
        }
        return 0;
}
function getBrowserHeight() {
        if ( window.innerHeight ) {
                return window.innerHeight;
        }
        else if ( document.documentElement && document.documentElement.clientHeight != 0 ) {
                return document.documentElement.clientHeight;
        }
        else if ( document.body ) {
                return document.body.clientHeight;
        }
        return 0;
}

function togglex(target)
{
    if($(target).style.display == 'none')
        $(target).show();
    else
        $(target).hide();
}

function show_breakdown(target)
{
	$(target).show();
}

function load(latitude,longitude,hotelname,hoteladdress) 
{
	if (GBrowserIsCompatible()) {

    var map = new GMap2(document.getElementById("gmap"));
    var point = new GLatLng(latitude, longitude);

    map.setCenter(point, 15);

		ctrlObj = new GSmallMapControl();/*小さいコントロール*/
		map.addControl(ctrlObj);

		ctrlObj1 = new GScaleControl();/*スケール*/
		map.addControl(ctrlObj1);


/*    map.addControl(new GLargeMapControl());
    map.addControl(new GMapTypeControl());  *//*マップ切り替えコントロール*/

    var marker = new GMarker(point);/*情報ウィンドウ*/
    map.addOverlay(marker);

    GEvent.addListener(marker, "mouseover", function() {
      marker.openInfoWindowHtml(hotelname + "<br />" + hoteladdress,{maxWidth:150});
    });
  }
}

function getPageSize() {
	     var xScroll, yScroll;
		
		if (window.innerHeight && window.scrollMaxY) {	
			xScroll = window.innerWidth + window.scrollMaxX;
			yScroll = window.innerHeight + window.scrollMaxY;
		} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
			xScroll = document.body.scrollWidth;
			yScroll = document.body.scrollHeight;
		} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
			xScroll = document.body.offsetWidth;
			yScroll = document.body.offsetHeight;
		}
		
		var windowWidth, windowHeight;
		
		if (self.innerHeight) {	// all except Explorer
			if(document.documentElement.clientWidth){
				windowWidth = document.documentElement.clientWidth; 
			} else {
				windowWidth = self.innerWidth;
			}
			windowHeight = self.innerHeight;
		} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
			windowWidth = document.documentElement.clientWidth;
			windowHeight = document.documentElement.clientHeight;
		} else if (document.body) { // other Explorers
			windowWidth = document.body.clientWidth;
			windowHeight = document.body.clientHeight;
		}	
		
		// for small pages with total height less then height of the viewport
		if(yScroll < windowHeight){
			pageHeight = windowHeight;
		} else { 
			pageHeight = yScroll;
		}
	
		// for small pages with total width less then width of the viewport
		if(xScroll < windowWidth){	
			pageWidth = xScroll;		
		} else {
			pageWidth = windowWidth;
		}

		return [pageWidth,pageHeight];
}
