﻿var childWindow0001 = null;
var childWindow0002 = null;
/*******************************************************************************
* 内容      ：アップロード共通画面」を開く
* 引数      ：UL業務区分
* 戻り値    ：なし
********************************************************************************/
function HisHotelCode_Click() {
    var HidHotelCode = document.getElementById("ctl00_ContentPlaceHolder1_Hid_HotelCode");
    var url = "../HotelTariff/Default.aspx?from=F10301_1&hotel_cd=" + HidHotelCode.value;
    childWindow0001 = window.open(url, "", "");
    window.onunload = function() {
        if (childWindow0002 != null && !childWindow0002.closed) childWindow0002.close();
    }
    return false;
}
/*******************************************************************************
* 内容      ：画面を設定
* 引数      ：なし
* 戻り値    ：var left xp
********************************************************************************/
function getLeft(e) {
    var l = e.offsetLeft;
    while (e = e.offsetParent)
        l += e.offsetLeft;
    return l;
}

/*******************************************************************************
* 内容      ：画面を設定
* 引数      ：なし
* 戻り値    ：var top xp
********************************************************************************/
function getTop(e) {
    var t = e.offsetTop;
    while (e = e.offsetParent)
        t += e.offsetTop;
    return t;
}
/*******************************************************************************
* 内容      ：アップロード共通画面」を開く
* 引数      ：UL業務区分
* 戻り値    ：なし
********************************************************************************/
function Promotion_Click(F10302URL) {
    var HidHotelCode = document.getElementById("ctl00_ContentPlaceHolder1_Hid_HotelCode");
    var url = F10302URL + HidHotelCode.value;
    childWindow0001 = window.open(url, "", "");
    window.onunload = function() {
        if (childWindow0001 != null && !childWindow0001.closed) childWindow0001.close();
        if (childWindow0002 != null && !childWindow0002.closed) childWindow0002.close();
    }
    return false;
}

function load_5() {
    if (/msie/i.test(navigator.userAgent)) {
        document.getElementById('ctl00_ContentPlaceHolder1_Ddl_CheckInYm').onpropertychange = calculateCheckoutDate;
        document.getElementById('ctl00_ContentPlaceHolder1_Ddl_CheckInDay').onpropertychange = calculateCheckoutDate;

    }
    else {
        document.addEventListener("click", calculateCheckoutDate, false);
    }

}
/*******************************************************************************
* 内容      ：GoogleMap
* 引数      ：なし
* 戻り値    ：なし
********************************************************************************/
var map;
function load() {
    try {
        var flag = document.getElementById("ctl00_ContentPlaceHolder1_Hid_PhotoFlag").value;

        if (GBrowserIsCompatible()) {
            var latitude = document.getElementById("ctl00_ContentPlaceHolder1_Hid_Latitude").value;
            var longitude = document.getElementById("ctl00_ContentPlaceHolder1_Hid_Longitude").value;
            if (latitude  == "" || longitude == "") {
                return;
            }
            var zoom = document.getElementById("ctl00_ContentPlaceHolder1_Hid_GmapsZoom").value;
            if (zoom == "") {
                zoom = "13";
            }


            map = new GMap2(document.getElementById("ctl00_ContentPlaceHolder1_map"), { size: new GSize(460, 300) });
            map.addMapType(G_PHYSICAL_MAP);
            map.setCenter(new GLatLng(parseFloat(latitude), parseFloat(longitude)), parseFloat(zoom));

            var mapControl = new GHierarchicalMapTypeControl();

            map.addControl(mapControl)
            map.addControl(new GLargeMapControl());
            map.addControl(new GScaleControl());
            if (flag == "2") {
                map.setMapType(G_SATELLITE_MAP);
            }

            var latitude1 = document.getElementById("ctl00_ContentPlaceHolder1_Hid_Latitude").value;
            var longitude1 = document.getElementById("ctl00_ContentPlaceHolder1_Hid_Longitude").value;
            var latlng = new GLatLng(parseFloat(latitude1), parseFloat(longitude1));

            var hotelIcon = new GIcon();
            hotelIcon.image = "../img/elements/hotel_red.PNG";
            hotelIcon.shadow = "../img/elements/hotel_shadow.PNG";
            hotelIcon.iconSize = new GSize(18, 22);
            hotelIcon.shadowSize = new GSize(29, 21);
            hotelIcon.iconAnchor = new GPoint(9, 34);
            hotelIcon.printImage = "../img/elements/hotel_red.PNG";
            hotelIcon.mozPrintImage = "../img/elements/hotel_red.PNG";
            
            var markerOptions = { icon: hotelIcon };
            var marker = new GMarker(latlng, markerOptions);
            map.addOverlay(marker);
        }

        GEvent.addListener(map, "moveend", function() {
            //var center = map.getCenter();
            //document.getElementById("ctl00_ContentPlaceHolder1_Hid_Latitude").value = center.lat();
            //document.getElementById("ctl00_ContentPlaceHolder1_Hid_Longitude").value = center.lng();
            //document.getElementById("ctl00_ContentPlaceHolder1_Hid_GmapsZoom").value = map.getZoom();
        });
    } catch (e) { }
}

var oldObject;
var oldGMarker;

function f_up(objLI) {
    try {
        if (oldObject != null && objLI != oldObject) {
            if (oldObject.parentNode.className == "ac") {
                oldObject.parentNode.className = "";
                map.removeOverlay(oldGMarker);
            }
        }

        var objid = objLI.id;
        var latid = objid.replace("Hyp_LandmarkName", "Hid_Latitude2");
        var lonid = objid.replace("Hyp_LandmarkName", "Hid_Longitude2");
        var latitude = document.getElementById(latid).value;
        var longitude = document.getElementById(lonid).value;

        var latitude1 = document.getElementById("ctl00_ContentPlaceHolder1_Hid_Latitude").value;
        var longitude1 = document.getElementById("ctl00_ContentPlaceHolder1_Hid_Longitude").value;


        var rectObj;
        if (parseFloat(longitude) < parseFloat(longitude1)) {
            rectObj = new GLatLngBounds(new GLatLng(parseFloat(latitude), parseFloat(longitude)), new GLatLng(parseFloat(latitude1), parseFloat(longitude1)));
        } else {
            rectObj = new GLatLngBounds(new GLatLng(parseFloat(latitude1), parseFloat(longitude1)), new GLatLng(parseFloat(latitude), parseFloat(longitude)));
        }
        var zoom = map.getBoundsZoomLevel(rectObj) - 1;
        var point = new GLatLng(parseFloat(latitude), parseFloat(longitude))

        map.setCenter(point, parseFloat(zoom));

        if (objLI.parentNode.className == "ac") {

            objLI.parentNode.className = "";
            map.removeOverlay(oldGMarker);
        } else {
            objLI.parentNode.className = "ac";

            var landmarkIcon = new GIcon();
            landmarkIcon.image = "../img/elements/landmark.PNG";
            landmarkIcon.shadow = "../img/elements/landmark_shadow.PNG";
            landmarkIcon.iconSize = new GSize(18, 22);
            landmarkIcon.shadowSize = new GSize(29, 21);
            landmarkIcon.iconAnchor = new GPoint(9, 34);
            landmarkIcon.printImage = "../img/elements/landmark.PNG";
            landmarkIcon.mozPrintImage = "../img/elements/landmark.PNG";

            var markerOptions = { icon: landmarkIcon };
            var marker = new GMarker(point, markerOptions);
            map.addOverlay(marker);

            oldGMarker = marker;
            oldObject = objLI;
        } 
    } catch (e) { }


}


/*******************************************************************************
* 内容      ：アップロード共通画面」を開く
* 引数      ：UL業務区分
* 戻り値    ：なし
********************************************************************************/
function Print_Click() {
    var HidHotelCode = document.getElementById("ctl00_ContentPlaceHolder1_Hid_HotelCode");
    var url = "../HotelPrint/" + HidHotelCode.value + ".aspx";
    childWindow0001 = window.open(url, "", "");
    window.onunload = function() {
        if (childWindow0001 != null && !childWindow0001.closed) childWindow0001.close();
        if (childWindow0002 != null && !childWindow0002.closed) childWindow0002.close();
    }
    return false;
}


/*********************************************************************
* 内容      ：チェックアウト日付の算出
* 引数      ：なし
* 戻り値    ：なし
*********************************************************************/
function calculateCheckoutDate() {
    //チェックイン（年月）を取得
    var strCheckInYmObject = document.getElementById("ctl00_ContentPlaceHolder1_Ddl_CheckInYm");
    //チェックイン（日）
    var strCheckInDayObject = document.getElementById("ctl00_ContentPlaceHolder1_Ddl_CheckInDay");
    //宿泊数を取得
    var strStayNumObject = document.getElementById("ctl00_ContentPlaceHolder1_Ddl_Stay");
    //チェックアウト年月日
    var strCheckOutDate = document.getElementById("ctl00_ContentPlaceHolder1_Lbl_CheckoutYmd");

    if (strCheckInYmObject.value == "" || strCheckInDayObject.value == "" || strStayNumObject.value == "") {
        strCheckOutDate.innerHTML = "";
    }
    else {


        var strCheckInYm = strCheckInYmObject.value;
        //チェックイン（年）
        var strCheckInYear = strCheckInYm.substring(0, 4);
        //チェックイン（月）
        var strCheckInMonth = strCheckInYm.substring(4, 6);


        var intDayLength = strCheckInDayObject.value.length;
        var strCheckInDay = strCheckInDayObject.value.substring(0, intDayLength);


        var intStayNum = strStayNumObject.value;

        if (CalDays(strCheckInYear, strCheckInMonth, strCheckInDay)) {
            strCheckOutDate.innerHTML = "";
        } else {
            //チェックアウト日付を算出
            var date = new Date();

            date.setFullYear(strCheckInYear, parseInt(strCheckInMonth, 10) - 1, strCheckInDay);
            date.setDate(date.getDate() + parseInt(intStayNum, 10));

            //チェックアウト日付を表示
            var checkoutYear = date.getFullYear();
            var checkoutMonth = date.getMonth();
            checkoutMonth = "" + (checkoutMonth + 1);
            var checkoutDay = date.getDate();
            strCheckOutDate.innerHTML = checkoutYear + "年" + checkoutMonth + "月" + checkoutDay + "日";

        }
    }

}
/*********************************************************************
* 内容      ：無効チェックイン（年月日）
* 引数      ：なし
* 戻り値    ：なし
*********************************************************************/
function CalDays(year, month, day) {
    var strFlg = false;
    switch (month) {
        case "04":
        case "06":
        case "09":
        case "11":
            if (day > 30) {
                strFlg = true;
            }
            break;
        case "02":
            if (isLeapYear(year) == false && day > 28) {
                strFlg = true;
            }
            break;
    }
    return strFlg;
}

function isLeapYear(year) {
    if ((year % 4 == 0 && year % 100 != 0) || (year % 400 == 0)) {
        return true;
    }
    else {
        return false;
    }
}

function roomInfoOnchange(objSelect) {

    for (var i = 0; i < objSelect.options.length; i++) {
        var name;
        if (i < 10) {
            name = "0" + i;
        } else {
            name = "" + i;
        }
        var objTable = document.getElementById("ctl00_ContentPlaceHolder1_RepeaterRoom_ctl" + name + "_roomInfo");
        objTable.style.display = "none";
    }

    for (var i = 0; i < objSelect.value; i++) {
        var name;
        if (i < 10) {
            name = "0" + i;
        } else {
            name = "" + i;
        }
        var objTable = document.getElementById("ctl00_ContentPlaceHolder1_RepeaterRoom_ctl" + name + "_roomInfo");
        objTable.style.display = "";
    }
}
function childInfoOnchange(objSelect) {

    var strName = objSelect.id.substring(0, 45);
    for (var i = 0; i < objSelect.options.length - 1; i++) {
        var name;
        if (i < 10) {
            name = "0" + i;
        } else {
            name = "" + i;
        }

        var objTable = document.getElementById(strName + "RepeaterAge_ctl" + name + "_age");
        objTable.style.display = "none";
    }

    for (var i = 0; i < objSelect.value; i++) {
        var name;
        if (i < 10) {
            name = "0" + i;
        } else {
            name = "" + i;
        }
        var objTable = document.getElementById(strName + "RepeaterAge_ctl" + name + "_age");
        objTable.style.display = "";
    }
}

resizeImage(".Hotel_Img", 150, 105);
resizeImage("img.thickbox", 120, 84);

// お気に入りリストに追加
function addWishList(hotelcd) {

    // お気に入りリスト呼出し
    function getWishList() {
        var wishListStr = readCookie("WishList");
        if (wishListStr) {
            return unescape(wishListStr).split(",");
        } else {
            return new Array();
        }
    }

    var wishList;
    var delWishList;

    delWishList = getWishList();
    delWishList = delHotelcd(delWishList, [hotelcd]);
    if (delWishList.length == 1) {
        wishList = delWishList;
    } else if (delWishList.length > 1) {
        wishList = unescape(delWishList).split(",");
    } else {
        wishList = new Array();
    }

    wishList.push(hotelcd);

    for (var i = 0; i < wishList.length; i++) {
        if (i > 19) {
            wishList.shift();
        }
    }

    var expire = new Date();
    expire.setTime(expire.getTime() + 1000 * 60 * 60 * 24 * 30);
    var setValue;
    setValue = "WishList" + "=" + escape(wishList.join(",")) + ";";
    setValue += " expires=" + expire.toGMTString() + ";";
    setValue += " path=" + "/;";
    document.cookie = setValue;

    doPostBack();
}
// Cookie読込み
function readCookie(key) {
    return getCookieArray()[key];
}
// Cookie書込み
function WriteCookie(key, value) {
    var _SP = '=';

    document.cookie = key + _SP + value + ";" + " path=" + "/;";
}

function delHotelcd(wishList, hotelCd) {
    for (var j = 0; j < wishList.length; j++) {
        if (wishList[j] == hotelCd) {
            wishList.splice(j, 1);

            break;
        }
    }
    return wishList;
}
// Cookieを配列に格納
function getCookieArray() {
    var _ck = document.cookie;
    var _SP1 = ';';
    var _SP2 = '=';
    var _el = _ck.split(_SP1);
    var _ary = new Object();

    for (var i = 0; i < _el.length; i++) {
        try {
            var _kv = _el[i].split(_SP2);
            var _key = _kv[0].replace(/^ /, '').replace(/ $/, '');
            var _value = _kv[1];

            _ary[_key] = _value;
        }
        catch (e) {
            alert(e.description)
        }
    }

    return _ary;
}
function doPostBack() {
    document.forms["aspnetForm"].submit();
}


/*********************************************************************
H.I.S.追加（ボタン非表示）
*********************************************************************/
/**
 * Cookie plugin
 *
 * Copyright (c) 2006 Klaus Hartl (stilbuero.de)
 * Dual licensed under the MIT and GPL licenses:
 * http://www.opensource.org/licenses/mit-license.php
 * http://www.gnu.org/licenses/gpl.html
 *
 */

/**
 * Create a cookie with the given name and value and other optional parameters.
 *
 * @example $.cookie('the_cookie', 'the_value');
 * @desc Set the value of a cookie.
 * @example $.cookie('the_cookie', 'the_value', { expires: 7, path: '/', domain: 'jquery.com', secure: true });
 * @desc Create a cookie with all available options.
 * @example $.cookie('the_cookie', 'the_value');
 * @desc Create a session cookie.
 * @example $.cookie('the_cookie', null);
 * @desc Delete a cookie by passing null as value. Keep in mind that you have to use the same path and domain
 *       used when the cookie was set.
 *
 * @param String name The name of the cookie.
 * @param String value The value of the cookie.
 * @param Object options An object literal containing key/value pairs to provide optional cookie attributes.
 * @option Number|Date expires Either an integer specifying the expiration date from now on in days or a Date object.
 *                             If a negative value is specified (e.g. a date in the past), the cookie will be deleted.
 *                             If set to null or omitted, the cookie will be a session cookie and will not be retained
 *                             when the the browser exits.
 * @option String path The value of the path atribute of the cookie (default: path of page that created the cookie).
 * @option String domain The value of the domain attribute of the cookie (default: domain of page that created the cookie).
 * @option Boolean secure If true, the secure attribute of the cookie will be set and the cookie transmission will
 *                        require a secure protocol (like HTTPS).
 * @type undefined
 *
 * @name $.cookie
 * @cat Plugins/Cookie
 * @author Klaus Hartl/klaus.hartl@stilbuero.de
 */

/**
 * Get the value of a cookie with the given name.
 *
 * @example $.cookie('the_cookie');
 * @desc Get the value of a cookie.
 *
 * @param String name The name of the cookie.
 * @return The value of the cookie.
 * @type String
 *
 * @name $.cookie
 * @cat Plugins/Cookie
 * @author Klaus Hartl/klaus.hartl@stilbuero.de
 */
jQuery.cookie = function(name, value, options) {
    if (typeof value != 'undefined') { // name and value given, set cookie
        options = options || {};
        if (value === null) {
            value = '';
            options.expires = -1;
        }
        var expires = '';
        if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) {
            var date;
            if (typeof options.expires == 'number') {
                date = new Date();
                date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));
            } else {
                date = options.expires;
            }
            expires = '; expires=' + date.toUTCString(); // use expires attribute, max-age is not supported by IE
        }
        // CAUTION: Needed to parenthesize options.path and options.domain
        // in the following expressions, otherwise they evaluate to undefined
        // in the packed version for some reason...
        var path = options.path ? '; path=' + (options.path) : '';
        var domain = options.domain ? '; domain=' + (options.domain) : '';
        var secure = options.secure ? '; secure' : '';
        document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join('');
    } else { // only name given, get cookie
        var cookieValue = null;
        if (document.cookie && document.cookie != '') {
            var cookies = document.cookie.split(';');
            for (var i = 0; i < cookies.length; i++) {
                var cookie = jQuery.trim(cookies[i]);
                // Does this cookie string begin with the name we want?
                if (cookie.substring(0, name.length + 1) == (name + '=')) {
                    cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
                    break;
                }
            }
        }
        return cookieValue;
    }
};



jQuery(function($){

// ------------------- 20100325 REVISE START

	var blackList = [
		/.*http:\/\/e\.his-j\.com\/trip\/ciao\/voyage\/.*/,
		/.*his-j\.com\/tyo\/special\/ana.*/,
		/.*his-j\.com\/tyo\/special\/flo.*/,
		/.*his-j\.com\/tyo\/tour\/2can\/whistler.*/,
		/.*his-j\.com\/tyo\/business\/pack.*/,
		/.*his-j\.com\/tyo\/business\/tour.*/,
		/.*his-j\.com\/tyo\/corp.*/,
		/.*his-j\.com\/tyo\/group.*/,
		/.*sports-his.*/,
		/.*train-his.*/,
		/.*sekaiisan-his.*/
	];

// ------------------- 20100325 REVISE END

	var ref = (document.referrer) ? document.referrer : '';

	var matched = false;

// ------------------- 20100325 REVISE START

	if(ref){
		//$('#ref').text(ref); // for test
		$.each(blackList, function(i,val){
			if(ref.match(val)){
				matched = true;
				return false;
			}
		});
	}

// ------------------- 20100325 REVISE END

	if(matched || $.cookie('isBlackListed')){
		bakeCookie();
		$('input[type=image][id$=_Imb_Yoyaku]').hide();
	}

	function bakeCookie(){
		var now = new Date();
		now.setMinutes(now.getMinutes()+10);
		var expireTime = now.toGMTString();
		$.cookie('isBlackListed', '1', { expires: expireTime, path: '/' });
	}

});



