
var fIE5 = (navigator.appVersion.indexOf('MSIE 5')>=0);

function InitLayerPos(lay) {
	if(document.all) {
		lay.style.pixelLeft = lay.offsetLeft;
		lay.style.pixelTop  = lay.offsetTop;
	}
}

function SetLayerVisibility(lay, visible) {
	if(document.layers) {
		lay.visibility = (visible)? 'inherit' : 'hide';
	} else if(document.all || document.getElementById) {
		lay.style.visibility = (visible)? 'inherit' : 'hidden';
	}
}

function GetLayerFromName(name) {
	if(document.layers) {
		var s='';
		for(var i=1; i<arguments.length ;i++) {
			s+='document.layers.'+arguments[i]+'.';
		}
		return eval(s+'document.layers.'+name);
	} else if(document.all) {
		return document.all(name);
	} else if(document.getElementById) {
		return document.getElementById(name);
	}
}

function MoveToLayer(lay, x, y) {
	if(document.layers) {
		lay.moveTo(x, y);
	} else if(document.all) {
		lay.style.pixelLeft = x;
		lay.style.pixelTop = y;
	} else if(document.getElementById) {
		lay.style.left = x + 'px';
		lay.style.top = y + 'px';
	}
}

function WriteDocument(lay, str) {
	if(document.layers) {
		lay.document.open();
		lay.document.write(str);
		lay.document.close();
	} else if(document.all || document.getElementById) {
		lay.innerHTML = str;
	}
}


var selarea = null;
var isinit = false;

var e_xp = 0;
var e_yp = 0;
var c_w = 0;
var c_h = 0;

var fHokkaido = false;

function HideTip() {
	if(isinit) {
		SetLayerVisibility(selarea, false);
		MoveToLayer(selarea, 0, 0);
		selarea = null;
	}
	return false;
}

function MouseClick(e, name) {
	if(isinit) {
		if(name=='Hokkaido') {
			fHokkaido = true;
		} else {
			fHokkaido = false;
		}
		if(selarea) {
			SetLayerVisibility(selarea, false);
			MoveToLayer(selarea, 0, 0);
		}
		selarea = GetLayerFromName(name);
		if(document.layers) {
			c_w = window.innerWidth;
			c_h = window.innerHeight;
			e_xp = e.pageX;
			e_yp = e.pageY;
		} else if(document.all) {
			c_w = document.body.clientWidth + document.body.scrollLeft;
			c_h = document.body.clientHeight + document.body.scrollTop;
			e_xp = e.clientX + document.body.scrollLeft;
			e_yp = e.clientY + document.body.scrollTop;
		} else if(document.getElementById) {
			c_w = window.innerWidth;
			c_h = window.innerHeight;
			e_xp = e.clientX + window.scrollX;
			e_yp = e.clientY + window.scrollY;
		}
		MoveHotelList();
	}
	return false;
}

function MoveHotelList() {
	if(isinit && selarea) {
		MoveToLayer(selarea, 0, 0);
		var ww = c_w, wh = c_h, w = 0, h = 0, x = e_xp, y = e_yp;
		if(document.layers) {
			w = selarea.clip.width;
			h = selarea.clip.height;
		} else if(document.all || document.getElementById) {
//			ww = ww + document.body.scrollLeft;
//			wh = wh + document.body.scrollTop;
			w = selarea.offsetWidth;
			h = selarea.offsetHeight;
//			x = x + document.body.scrollLeft;
//			y = y + document.body.scrollTop;
		}
		if(ww-x-10<w) {
			if(fHokkaido) {
				if(ww<600) {
					x = 440;
				} else {
					x = 440 + (ww-600)/2;
				}
			} else {
				x = x - w;
			}
		}
		if(y+h>wh) {
			y = y - h;
		}
		MoveToLayer(selarea, x, y);
		SetLayerVisibility(selarea, true);
	}
}

function resize() {
	if(isinit && selarea) {
		var ww = c_w, wh = c_h;
		if(document.all) {
			c_w = document.body.clientWidth + document.body.scrollLeft;
			c_h = document.body.clientHeight + document.body.scrollTop;
		} else if(document.layers || document.getElementById) {
			c_w = window.innerWidth;
			c_h = window.innerHeight;
		}
		if(ww<600) {
			ww = 600;
		}
		if(c_w>600) {
			e_xp = e_xp + (c_w - ww)/2;
		}
		MoveHotelList();
	}
}

function ChangeArea(obj) {
	ChangeOption(document.search.id, obj.options[obj.selectedIndex].value);
}

function ChangeKorArea(obj) {
	ChangeOption(document.sandr.prefecture, obj.options[obj.selectedIndex].value);
}

function SubmitSearch() {
	document.search.detail.value = 'SEARCH';
	document.search.submit();
}

function SubmitDetail() {
	document.search.detail.value = 'DETAIL';
	document.search.submit();
}

function PageJump() {
	if (navigator.appName == 'Netscape') {
		var language = navigator.language;
	} else {
		var language = navigator.browserLanguage;
	}
	var theName = "language";
	theCookie = document.cookie + ";";
	start = theCookie.indexOf(theName);
	if (start != -1) {
		if (language.indexOf('ja') > -1) {
			var theValue = "ja";
			writeCookie(theName,theValue);
		} else {
			var end = theCookie.indexOf(";",start);
			var flag = theCookie.substring(start + theName.length+1, end);
			if (flag == "ko") {
				document.location.href = 'http://www.toyoko-inn.kr/index.html';
			} else if (flag == "zh") {
				document.location.href = 'http://www.toyoko-inn.com/china/index.html';
			} else if (flag == "en") {
				document.location.href = 'http://www.toyoko-inn.com/eng/index.html';
			}
		}
	} else {
		if (language.indexOf('ko') > -1) {
			var theValue = "ko";
			writeCookie(theName,theValue);
			document.location.href = 'http://www.toyoko-inn.kr/index.html';
		} else if (language.indexOf('ja') > -1) {
			var theValue = "ja";
			writeCookie(theName,theValue);
		} else if (language.indexOf('zh') > -1) {
			var theValue = "zh";
			writeCookie(theName,theValue);
			document.location.href = 'http://www.toyoko-inn.com/china/index.html';
		} else {
			var theValue = "en";
			writeCookie(theName,theValue);
			document.location.href = 'http://www.toyoko-inn.com/eng/index.html';
		}
	}
}

function languageCheck(language,ver) {
	var theName = "language";
	if (ver =='kor') {
		if (language == "japan") {
			var theValue = "ja";
			writeCookie(theName,theValue);
			document.location.href = 'http://www.toyoko-inn.com/index.html';
		} else if (language == "china") {
			var theValue = "zh";
			writeCookie(theName,theValue);
			document.location.href = 'http://www.toyoko-inn.com/china/index.html';
		} else if (language == "english") {
			var theValue = "en";
			writeCookie(theName,theValue);
			document.location.href = 'http://www.toyoko-inn.com/eng/index.html';
		}
	} else {
		if (language == "japan") {
			var theValue = "ja";
		} else if (language == "korean") {
			var theValue = "ko";
		} else if (language == "china") {
			var theValue = "zh";
		} else if (language == "english") {
			var theValue = "en";
		}
		writeCookie(theName,theValue);
		return true;
	}
}

function writeCookie(theName,theValue) {
	setDay = new Date();
	setDay.setTime(setDay.getTime() + (7*1000*60*60*24));
	expDay = setDay.toGMTString();
	document.cookie = theName + "=" + theValue + ";path=/ ;expires=" + expDay;
}

function getCookie(name) {
	var Flag = false;
	var begin,end;
	var i= 0;

	while(i<=document.cookie.length) {
		begin = i;
		end = begin + name.length;
		
		if(document.cookie.substring(begin,end) == name) {
			Flag = true;
			break;
		}
		i++;
	}
	
	if(Flag == true) {
		begin = end + 1;
		end = document.cookie.indexOf(";",begin);
		if(end < begin) {
			end = document.cookie.length;
		}
		return document.cookie.substring(begin,end);
	}
	return "";
}

function openPopup() {

	var Cookie=getCookie("pop1");
	if(Cookie != "no") {
		window.open('popup.html','pop1','width=390,height=450,toolbar=0,scrollbars=no,resizable=no,top=50,left=150');
	}

	var Cookie2=getCookie("pop2");
	if(Cookie2 != "no") {
		window.open('popup2.html','pop2','width=330,height=420,toolbar=0,scrollbars=no,resizable=no,top=50,left=550');
//		window.open('popup2.html','pop2','width=330,height=420,toolbar=0,scrollbars=no,resizable=no,top=50,left=150');	
	}
}