function $() {
  var elements = new Array();

  for (var i = 0; i < arguments.length; i++) {
    var element = arguments[i];
    if (typeof element == 'string')
      element = document.getElementById(element);

    if (arguments.length == 1)
      return element;

    elements.push(element);
  }

  return elements;
}

var Class = {
  create: function() {
    return function() {
      this.initialize.apply(this, arguments);
    }
  }
}

/* Browser Detection
----------------------------------------------------------------------------- */
var _BROWSER_IS_IE =
    (document.all
     && window.ActiveXObject
     && navigator.userAgent.toLowerCase().indexOf("msie") > -1
     && navigator.userAgent.toLowerCase().indexOf("opera") == -1);

/**
 * I hate navigator string based browser detection too, but when Opera alone
 * chokes on cookies containing double quotes...
 */
var _BROWSER_IS_OPERA = (navigator.userAgent.toLowerCase().indexOf("opera") != -1);

/* CookieManager Object
----------------------------------------------------------------------------- */
/**
 * Provides a simple interface for creating, retrieving and clearing cookies.
 */
CookieManager = Class.create();
CookieManager.prototype =
{
    /**
     * Determines if this object will use IE's proprietary userData behaviour
     * instead of cookies for storage.
     */
    userDataForIE: false,

    initialize: function(userDataForIE) {
        this.cookieShelfLife = 365;
        this.userDataForIE = userDataForIE;

        // Internet Explorer has a cookie handling bug - if the *combined size*
        // of all cookies stored for a given domain is greater than 4096 bytes,
        // document.cookie will return an empty string. Until this is fixed , we
        // will fall back on IE's proprietary userData behaviour.
        if (_BROWSER_IS_IE && this.userDataForIE) {
            this.IE_CACHE_NAME = "storage";
            if ($(this.IE_CACHE_NAME) == null) {
                var div = document.createElement("DIV");
                div.id = this.IE_CACHE_NAME;
                document.body.appendChild(div);
            }
            this.store = $(this.IE_CACHE_NAME);
            this.store.style.behavior = "url('#default#userData')";
        }
    },

    /**
     * Returns the value of a cookie with the given name, or <code>null</code>
     * if no such cookie exists.
     */
    getCookie: function(aCookieName) {
        var result = null;
        if (_BROWSER_IS_IE && this.userDataForIE) {
            this.store.load(this.IE_CACHE_NAME);
            result = this.store.getAttribute(aCookieName);
        } else {
            for (var i = 0; i < document.cookie.split('; ').length; i++) {
                var crumb = document.cookie.split('; ')[i].split('=');
                if (crumb[0] == aCookieName && crumb[1] != null) {
                    result = crumb[1];
                    break;
                }
            }
        }

        if (_BROWSER_IS_OPERA && result != null) {
            result = result.replace(/%22/g, '"');
        }
        return result;
    },

    /**
     * Sets a cookie with the given name and value.
     */
    setCookie: function(aCookieName, aCookieValue) {
        if (_BROWSER_IS_IE && this.userDataForIE) {
            this.store.setAttribute(aCookieName, aCookieValue);
            this.store.save(this.IE_CACHE_NAME);
        } else {
            if (_BROWSER_IS_OPERA) {
                aCookieValue = aCookieValue.replace(/"/g, "%22");
            }
            var date = new Date();
            date.setTime(date.getTime() + (this.cookieShelfLife * 24*60*60*1000));
            var expires = '; expires=' + date.toGMTString();
            document.cookie = aCookieName + '=' + aCookieValue + expires + '; path=/';
        }
    },

    /**
     * Clears the cookie with the given name.
     */
    clearCookie: function(aCookieName) {
        if (_BROWSER_IS_IE && this.userDataForIE) {
            this.store.load(this.IE_CACHE_NAME);
            this.store.removeAttribute(aCookieName);
            this.store.save(this.IE_CACHE_NAME);
        } else {
            document.cookie =
                aCookieName + '=;expires=Thu, 01-Jan-1970 00:00:01 GMT; path=/';
        }
    }
}

/* Sitecatalyst start */
var strPath  = location.pathname;
var strTitle = document.title;

var strPageName = strPath;	// s.pageName   
var strChannel  = "";		// s.channel   

s.eVar1	= "";
s.eVar2	= "";
s.eVar3	= "";
s.eVar4	= "";
s.eVar5	= "";
s.eVar6	= "";
s.eVar7 = "";

var blnCatalystFlg = false;	

/* error 404 */
if( strTitle.indexOf("404 Not Found",0) == 0 ) {
	s.pageType = "errorPage";
	var s_code=s.t();if(s_code)document.write(s_code);
	
/* error 400 408 500 503 */
} else if( strTitle.indexOf("400 Bad Request",0) == 0 || strTitle.indexOf("403 Error-Forbidden",0) == 0 || strTitle.indexOf("408 Request Time-out",0) == 0 || strTitle.indexOf("500 Internal Server Error",0) == 0 || strTitle.indexOf("503 Service Unavailable",0) == 0 ) {

/* popup */
} else if( strPath.indexOf("/contact/",0) == 0 ) {

/* top */
} else if( strPath.indexOf("/top.html",0) == 0 ) {
	blnCatalystFlg = true;
	strPageName = "とな芝_TOP";
	strChannel = "とな芝_TOP";
	s.events = "event4";
	
	try{
		var manager = new CookieManager();
				
		if( manager.getCookie("cookieEmail") != null && manager.getCookie("cookieEmail") != "" ) {
			manager.clearCookie("cookieEmail");
		}
	}catch(e){
	}	
	
/* special book feature */
} else if( strPath.indexOf("/special/",0) == 0 || strPath.indexOf("/book/",0) == 0 || strPath.indexOf("/feature/",0) == 0 ) {
	blnCatalystFlg = true;
	strChannel = "とな芝_特集";

/* landing */
} else if( strPath.indexOf("/promo/",0) == 0 ) {
	blnCatalystFlg = true;
	strChannel = "とな芝_ランディング";
	
/* login */
} else if( strPath.indexOf("/login/",0) == 0 ) {
	blnCatalystFlg = true;
	strChannel = "とな芝_会員登録";
	
	if( strPath.indexOf("/login/Login.jsp",0) == 0 ) {
		strPageName = "とな芝_ログイン";	
		s.events = "event5";
	} else if( strPath.indexOf("/login/LoginThanks.jsp",0) == 0 ) {
		strPageName = "とな芝_ログイン完了";
		s.events = "event6";
	} else if( strPath.indexOf("/login//Member.jsp",0) == 0 || strPath.indexOf("/login/Member.jsp",0) == 0 ) {
		strPageName = "とな芝_仮会員登録_TOP";
		s.events = "event7";
	} else if( strPath.indexOf("/login//Mail_enter.jsp",0) == 0 || strPath.indexOf("/login/Mail_enter.jsp",0) == 0 ) {
		strPageName = "とな芝_仮会員登録_メアド入力";
		s.events = "event8";
	} else if( strPath.indexOf("/login/TempRegist",0) == 0 ) {
		strPageName = "とな芝_仮会員登録メアドエラー";
		s.events = "event9";
	} else if( strPath.indexOf("/login/Mail_cfm.jsp",0) == 0 ) {
		strPageName = "とな芝_仮会員登録_メアド確認";
		s.events = "event10";
	} else if( strPath.indexOf("/login//RegistAuthAction",0) == 0 || strPath.indexOf("/login/RegistAuthAction",0) == 0 ) {
		
		strPageName = "とな芝_会員登録情報入力";
		try{
			var objParam = parseParam();
			var strMail = objParam["email"];
			s.events = "event11:" + strMail;
			
			var manager = new CookieManager();
			manager.setCookie("cookieEmail", strMail);
		}catch(e){
			s.events = "event11";
		}
		
	} else if( strPath.indexOf("/login/RegistUserConfirm",0) == 0 ) {
		strPageName = "とな芝_会員登録情報確認";
				
		try{
			var strParams = document.getElementById("paramSiteCatalyst").value;
			var strUserInfo = strParams.split(",");
			
			s.eVar1	= strUserInfo[0];	/*	性別				*/
			s.eVar2	= strUserInfo[1];	/*	生まれ年			*/
			s.eVar3	= strUserInfo[2];	/*	都道府県			*/
			s.eVar4	= strUserInfo[3];	/*	家族構成_配偶者		*/
			s.eVar5	= strUserInfo[4];	/*	家族構成_子供の数	*/
			s.eVar6	= strUserInfo[5];	/*	家族構成_同居の親	*/
			s.eVar7 = strUserInfo[6];	/*	世帯年収			*/
			
		}catch(e){
		}
		
		try{
			var manager = new CookieManager();
			var strMail = manager.getCookie("cookieEmail");
			
			if( manager.getCookie("cookieEmail") != null ) {
				s.events = "event12:" + strMail;
			} else {
				s.events = "event12";
			}
		}catch(e){
			s.events = "event12";
		}
		
		
	} else if( strPath.indexOf("/login/RegistThanks.jsp",0) == 0 ) {
		strPageName = "とな芝_会員登録完了";
		
		try{
			var manager = new CookieManager();
			var strMail = manager.getCookie("cookieEmail");
			
			if( manager.getCookie("cookieEmail") != null ) {
				s.events = "event13:" + strMail;
			} else {
				s.events = "event13";
			}
		}catch(e){
			s.events = "event13";
		}
	}

/* dynamic */
} else if( strPath.indexOf("/dynamic/",0) == 0 ) {
	blnCatalystFlg = true;
	strChannel = "とな芝_動くランキング";
	
/* market */
} else if( strPath.indexOf("/market/",0) == 0 ) {
	blnCatalystFlg = true;
	strChannel = "とな芝_相場情報";

/* ranking */
} else if( strPath.indexOf("/ranking/",0) == 0 ) {
	blnCatalystFlg = true;
	
	/* education */
	if( strPath.indexOf("/ranking/education",0) == 0 ) {
		strChannel = "とな芝_ランキング_教育";	
		
	/* life */
	} else if( strPath.indexOf("/ranking/life",0) == 0 ) {
		strChannel = "とな芝_ランキング_暮らし";
		
	/* money */
	} else if( strPath.indexOf("/ranking/money",0) == 0 ) {
			strChannel = "とな芝_ランキング_お金";

	/* enjoy */
	} else if( strPath.indexOf("/ranking/pleasure",0) == 0 ) {	
		strChannel = "とな芝_ランキング_楽しむ";
		
	/* luxury */
	} else if( strPath.indexOf("/ranking/luxury",0) == 0 ) {
		strChannel = "とな芝_ランキング_贅沢";

	/* knowledge */
	} else if( strPath.indexOf("/ranking/knowledge",0) == 0 ) {
		strChannel = "とな芝_ランキング_雑学";
	
	/* ranking */
	} else {
		strChannel = "とな芝_ランキング";
	}

/* info */
} else if( strPath.indexOf("/info/",0) == 0 ) {
	blnCatalystFlg = true;
	
	if( strPath.indexOf("/info/index.html",0) == 0 ) {
		strPageName = "とな芝_総合案内所";
	} else if( strPath.indexOf("/info/topics.html",0) == 0 ) {
		strChannel = "とな芝_新着ランキング情報";	
	}

/* research */
} else if( strPath.indexOf("/research/",0) == 0 ) {
	blnCatalystFlg = true;
	strChannel = "とな芝_クリックリサーチ";

/* request */
} else if( strPath.indexOf("/request/",0) == 0 ) {
	blnCatalystFlg = true;
	strChannel = "とな芝_リクエスト";

/* othres */
} else {
	blnCatalystFlg = true;	
}


if( blnCatalystFlg ) {
	s.pageName = strPageName;
	s.eVar49 = s.pageName;
	s.channel = strChannel;	
	var s_code=s.t();if(s_code)document.write(s_code);
}
