var cookieName = "okuribitoLang";
var wD = "＜＠＠＠＞";
var pubCookieDomain = "www.sakata-kankou.gr.jp";
var pubCookiePath   = "/";
var pubExpTime      = 30*60*1000;

function winOpen(url,ww,hh) {
	window.open(url , "" , "width=760,height=700,resizable=yes,menubar=yes,toolbar=yes,scrollbars=yes");
}

function changeFirst(pPage) {
	var wLang = getLang();
	changeDisp(pPage,wLang);
}

function changeDisp(pPage,pLang) { 
	var imgPath = '/okuribito/images/';
	var wLang = pLang;
	if (wLang == '') {wLang = '0';}
	document.getElementById('menu').src = imgPath + 'menu_contents' + wLang + '.gif';
	document.getElementById('top').src = imgPath + 'top' + wLang + '.gif';
	if (pPage == 'index') {
		document.getElementById('title_location').src = imgPath + 'title_location' + wLang + '.gif';
		document.getElementById('title_news').src = imgPath + 'title_news' + wLang + '.gif';
		document.getElementById('title_goods').src = imgPath + 'title_goods' + wLang + '.gif';
	} else if (pPage == 'contents') {
		document.getElementById('award').src = imgPath + 'title_academy' + wLang + '.gif';
		var wStyle = document.getElementById('st').value;
		if (wStyle == 'newsdetail') {
			document.getElementById('subtitle').src = imgPath + 'title_news' + wLang + '.gif';
		} else if (wStyle == 'spotdetail') {
			document.getElementById('subtitle').src = imgPath + 'title_location' + wLang + '.gif';
		} else if (wStyle == 'story') {
			document.getElementById('subtitle').src = imgPath + 'title_story' + wLang + '.gif';
		} else if (wStyle == 'goodsdetail') {
			document.getElementById('subtitle').src = imgPath + 'title_goods' + wLang + '.gif';
		} else if (wStyle == 'contact') {
			document.getElementById('subtitle').src = imgPath + 'title_contact' + wLang + '.gif';
		}
	}
}

function changeLang(pLang,pUrl) {
	var wLang = checkLang(pLang);
	setLang(wLang);
	if (pUrl == 'index') {
		document.location.href = '/okuribito/index.html';
	} else if (pUrl == 'contents') {
		document.location.href = '/cgi/okuribito/ojiinfou.cgi?st=' + document.getElementById('st').value;
	} else {
		document.location.href = '/okuribito/index.html';
	}
}

function checkLang(pLang) {
//      Lang  JA:0 EN:1 CH:2 TW:3 KR:4 FR:5
	var wLangMax = 5;
	var wLang = pLang;
	if (wLang == '') {wLang = getLang();}
	if (wLang == '') {wLang = 0;}
	if (wLang < 0 || wLang > wLangMax) {wLang = 0;}
	return(wLang);
}

function getLang() {
	var wLang = getCookie(cookieName);
	return(wLang);
}

function setLang(pLang) {
//	setCookie(cookieName,pLang,'',pubCookieDomain,pubCookiePath);
	setCookie(cookieName,pLang,'',pubCookieDomain,pubCookiePath);
//	setCookie('LANG',pLang);
}

function getCookie(pKey){
    var wCookie = document.cookie+';';
    var wCookieS = wCookie.indexOf(pKey,0);
    if(wCookieS != -1){
        wCookie = wCookie.substring(wCookieS,wCookie.length);
        wStart = wCookie.indexOf('=',0);
        wEnd = wCookie.indexOf(';',wStart);
        return(unescape(wCookie.substring(wStart+1,wEnd)));
    }
    return('');
}

function setCookie(pKey,pVal,pExp,pDomain,pPath) {
    var wExpDate = new Date();
    var wCookieExpire = '';
    var wNewCookie = '';
    wNewCookie = pKey + '=' + escape(pVal) + ';';

	//ドメイン内どこでもCookieを読めるようにdomain=とpath=を指定する
	if (pDomain != "" && pDomain != "NaN") {
		wNewCookie += "domain=" + pDomain + ";";
	}
	if (pPath != "" && pPath != "NaN") {
		wNewCookie += "path=" + pPath + ";";
	}

	if (pExp != '' && pExp != "NaN") {
		wCookieExpire = pExp;
	} else {
		//wCookieExpire = 1000*60*60*24*365*10;    // 有効期間( msec = 1000x秒x分x時間x日x年 )
		wCookieExpire = 1000*60*60;    // 有効期間( msec = 1000x秒x分x時間x日x年 )
	}
    wExpDate.setTime(wExpDate.getTime() + wCookieExpire); 
	wNewCookie += 'expires=' + wExpDate.toGMTString() + ';';

    document.cookie = wNewCookie;
}

function delCookie(key){
    var wExpDate = new Date();
    wExpDate.setYear(wExpDate.getYear()-1);
    var wNewCookie = pKey + '=;' + 'expires=' + wExpDate.toGMTString() + ';';

    document.cookie = wNewCookie;
}


