var htContact={
	NEEDCOOKIE:true, //if true, cannot advance without "Cookie-Enabled" setting
	MES_COOKIEDISABLED:"申し訳ございません。このページをご利用頂くには、「HTTP cookie」を利用できる環境が必要です。\nプログラムの設定を変更するか、詳しくはプログラムの製造元にお問い合わせ下さい",
	COOKIE_NAME:"hotline",
	ADVANCED_PAGE:"hotline.html",
	CHECKING_PAGE:"hotline2.html",
	agreeButtonID:"htContact",
	start:function(mode){
		if(!$) return false;
		switch(mode){
			case 1:
				var valid=false;
				if(!navigator.cookieEnabled) {
					if(!htContact.NEEDCOOKIE) {
						
						valid=true;
					} else {
						alert(htContact.MES_COOKIEDISABLED);
					}
				} else {
					if(htContact.getCookie(htContact.COOKIE_NAME)) {
						htContact.deleteCookie(htContact.COOKIE_NAME);
						valid=true;
					}
				}
				if(!valid) location.href=htContact.CHECKING_PAGE;
				break;
			case 2:
				var func=function(){
					
					if($(htContact.agreeButtonID)) Event.observe($(htContact.agreeButtonID),"click",htContact.clickSubmit,false);
				}
				addLoadEvent(func);
				break;
			default: return false;
		}
	},
	clickSubmit:function(){
		if(htContact.NEEDCOOKIE && (!navigator.cookieEnabled)) {
			alert(htContact.MES_COOKIEDISABLED);
			return false;
		}
		htContact.writeCookie();
		location.href=htContact.ADVANCED_PAGE;
	},
	writeCookie:function(){
		var date = new Date();
		date.setDate(date.getDate()+1);
		var expires = "; expires="+date.toGMTString();
		document.cookie=htContact.COOKIE_NAME+"=1"+expires;
	},
	getCookie:function(_name){
	  var name = _name+"=";
	  var value;
	  var cookies = document.cookie.split(';');
	  for(var i=0;i < cookies.length;i++) {
		var ck = cookies[i];
		while (ck.charAt(0)==' ') ck = ck.substring(1,ck.length);
		if (ck.indexOf(name) == 0) {
			value=ck.substring(name.length,ck.length);
		}
	  }
	  return (value)?value:false;
	},
	deleteCookie:function(name){
		var date = new Date();
		date.setDate(date.getDate()-1);
		var expires = "; expires="+date.toGMTString();
		document.cookie=name+"=1"+expires;
	}	
}
