/**
* ブランク／nullは代替文字とします。
*
* @param target
* @param spare
* @return result
*/
function nvl(target, spare){
	var result = target;

	if(target == "" || target == null){
		result = spare;
	}
	return result;
}


/**
* ブランク／nullか判断します。
*
* @param target
* @return result
*/
function isBlankOrNull(target, spare){

	if(target == "" || target == null){
		return true;
	}
	return false;
}



var _debug = false;
/**
* RouteInfoクラス
*
* 
*/
RouteInfo = function(){}
	RouteInfo.prototype.cookieName = "routeKey";
	RouteInfo.prototype.domainName = ".cisco.com";
	
	RouteInfo.prototype.peerId = "";
	RouteInfo.prototype.keyCode = "";
	RouteInfo.prototype.refSite = "";
	RouteInfo.prototype.space = "";
	RouteInfo.prototype.creative = "";
	RouteInfo.prototype.forwardUrl = "";
	RouteInfo.prototype.cookieVersion = "1";
	
	/**
	* 初期化します。
	*
	*/
	RouteInfo.prototype.init = function(){
		this.peerId = "";
		this.keyCode = "";
		this.refSite = "";
		this.space = "";
		this.creative = "";
		this.forwardUrl = "";
		this.cookieVersion = "1";
	}
	/**
	* 画面遷移します。
	*
	*/
	RouteInfo.prototype.forwardToNextPage = function(){
		if(isBlankOrNull(this.forwardUrl) == false){
			location.replace(this.forwardUrl);
		}
	}
	/**
	* 一連のロード前処理を行ないます。
	*
	*/
	RouteInfo.prototype.prepare = function(){
	}
	/**
	* 一連のロード後処理を行ないます。
	*
	*/
	RouteInfo.prototype.invoke = function(){
	}


/**
* LandingInfoクラス
*
* 次の項目の設定が必要です。
* peerId			: PEER ID
* forwardUrl		: ランディングページURL
* (cookieVersion	: Cookie形式バージョン デフォルトで1が設定されます。)
*/
LandingInfo = function(){}
	// RouteInfoクラスを継承します。
	LandingInfo.prototype =	new RouteInfo();
	/**
	* QueryStringを読み込みます。
	*
	*/
	LandingInfo.prototype.readQueryString = function(){
		var qs = new QueryString();
		qs.parse();
		
		this.keyCode = unescape(nvl(qs.find("keycode"), ""));
		this.refSite = unescape(nvl(qs.find("referring_site"), ""));
		this.space = unescape(nvl(qs.find("space"), ""));
		this.creative = unescape(nvl(qs.find("creative"), ""));
		
		if(_debug == true){
			alert("LandingInfo : peerId|" + this.peerId + "| keyCode|" + this.keyCode + "| refSite|" + this.refSite + "| space|" + this.space + "| creative|" + this.creative + "| forwardUrl|" + this.forwardUrl + "| cookieVersion|" + this.cookieVersion + "|");
		}
	}
	/**
	* 経路をCookieに設定します。
	*
	*/
	LandingInfo.prototype.saveRoute = function(){
	
		var _cookie = new Cookie(document, this.cookieName, 1, "/", this.domainName);
		
		_cookie.JP_VERSION = this.cookieVersion;	// Cookieの形式に変更があったときの管理番号
		_cookie.JP_PEERID = this.peerId;
	
		if(isBlankOrNull(this.keyCode) == false){
			_cookie.JP_KEYCODE = this.keyCode;
		}
		if(isBlankOrNull(this.refSite) == false){
			_cookie.JP_REFERRING_SITE = this.refSite;
		}
		if(isBlankOrNull(this.space) == false){
			_cookie.JP_SPACE = this.space;
		}
		if(isBlankOrNull(this.creative) == false){
			_cookie.JP_CREATIVE = this.creative;
		}

		_cookie.store();
		
		if(_debug == true){
			alert("LandingInfo : peerId|" + this.peerId + "| keyCode|" + this.keyCode + "| refSite|" + this.refSite + "| space|" + this.space + "| creative|" + this.creative + "| forwardUrl|" + this.forwardUrl + "| cookieVersion|" + this.cookieVersion + "|");
		}
	}
	/**
	* 一連のロード前処理を行ないます。
	*
	*/
	LandingInfo.prototype.prepare = function(){
		this.readQueryString();
		this.saveRoute();
	}
	/**
	* 一連のロード後処理を行ないます。
	*
	*/
	LandingInfo.prototype.invoke = function(){
		this.forwardToNextPage();
		this.init();
	}



/**
* SurveyInfoクラス
*
* 次の項目の設定が必要です。
* peerId			: PEER ID
* defaultKeyCode	: デフォルトキーコード
* surveyCode		: サーベイコード
* (cookieVersion	: Cookie形式バージョン デフォルトで1が設定されます。)
*/
SurveyInfo = function(){}
	// RouteInfoクラスを継承します。
	SurveyInfo.prototype =	new RouteInfo();
	
	SurveyInfo.prototype.defaultKeyCode = "";
	SurveyInfo.prototype.surveyCode = "";

	/**
	* 初期化します。
	*
	*/
	SurveyInfo.prototype.init = function(){
		RouteInfo.prototype.init();
		this.defaultKeyCode = "";
		this.surveyCode = "";
	}
	/**
	* Cookieから経路を読み込みます。
	*
	*/
	SurveyInfo.prototype.loadRoute = function(){
		var version = "";
		var peerid = "";

		if(_debug == true){
			alert("SurveyInfo : peerId|" + this.peerId + "| keyCode|" + this.keyCode + "| refSite|" + this.refSite + "| space|" + this.space + "| creative|" + this.creative + "| forwardUrl|" + this.forwardUrl + "| cookieVersion|" + this.cookieVersion + "| defaultKeyCode|" + this.defaultKeyCode + "| surveyCode|" + this.surveyCode + "|");
		}
		
		var _cookie = new Cookie(document, this.cookieName);
		_cookie.load();

		if (_cookie.JP_VERSION){
			version = escape(_cookie.JP_VERSION);
		}
		if (_cookie.JP_PEERID){
			 peerid = escape(_cookie.JP_PEERID);
		}
		if (version==this.cookieVersion && peerid==this.peerId){
			if (_cookie.JP_KEYCODE){
				this.keyCode = escape(_cookie.JP_KEYCODE);
			}else{
				this.keyCode = this.defaultKeyCode;
			}
			if (_cookie.JP_REFERRING_SITE){
				this.refSite = escape(_cookie.JP_REFERRING_SITE);
			}
			if (_cookie.JP_SPACE){
				this.space = escape(_cookie.JP_SPACE);
			}
			if (_cookie.JP_CREATIVE){
				this.creative = escape(_cookie.JP_CREATIVE);
			}
		}else{
			this.keyCode = this.defaultKeyCode;
		}

		if(_debug == true){
			alert("SurveyInfo : peerId|" + this.peerId + "| keyCode|" + this.keyCode + "| refSite|" + this.refSite + "| space|" + this.space + "| creative|" + this.creative + "| forwardUrl|" + this.forwardUrl + "| cookieVersion|" + this.cookieVersion + "| defaultKeyCode|" + this.defaultKeyCode + "| surveyCode|" + this.surveyCode + "|");
		}
	}
	
	/**
	* SurveyURLを生成します。
	*
	*/
	SurveyInfo.prototype.makeSurveyUrl = function(){
		var query = "";

		query += "&keyCode=";
		query += this.keyCode;
		
		if(isBlankOrNull(this.refSite) == false){
			query += "&";
			query += escape("REFERRING SITE");
			query += "=";
			query += this.refSite;
		}
		
		if(isBlankOrNull(this.space) == false){
			query += "&";
			query += escape("SPACE");
			query += "=";
			query += this.space;
		}
		
		if(isBlankOrNull(this.creative) == false){
			query += "&";
			query += escape("CREATIVE VALUE");
			query += "=";
			query += this.creative;
		}
		
		this.forwardUrl = "https://tools.cisco.com/gdrp/coiga/showsurvey.do?surveyCode=" + this.surveyCode + query;

		if(_debug == true){
			alert("SurveyInfo : peerId|" + this.peerId + "| keyCode|" + this.keyCode + "| refSite|" + this.refSite + "| space|" + this.space + "| creative|" + this.creative + "| forwardUrl|" + this.forwardUrl + "| cookieVersion|" + this.cookieVersion + "| defaultKeyCode|" + this.defaultKeyCode + "| surveyCode|" + this.surveyCode + "|");
		}
	}	
	/**
	* 一連のロード前処理を行ないます。
	*
	*/
	SurveyInfo.prototype.prepare = function(){
		this.loadRoute();
		this.makeSurveyUrl();
	}
	/**
	* 一連のロード後処理を行ないます。
	*
	*/
	SurveyInfo.prototype.invoke = function(){
		this.forwardToNextPage();
		this.init();
	}



/**
* ThanksInfoクラス
*
* 次の項目の設定が必要です。
* peerId			: PEER ID
* forwardUrl		: 遷移先URL
* (cookieVersion	: Cookie形式バージョン デフォルトで1が設定されます。)
*/
ThanksInfo = function(){}
	// SurveyInfoクラスを継承します。
	ThanksInfo.prototype =	new SurveyInfo();

	/**
	* 一連のロード前処理を行ないます。
	*
	*/
	ThanksInfo.prototype.prepare = function(){
		this.loadRoute();
	}
	/**
	* 一連のロード後処理を行ないます。
	*
	*/
	ThanksInfo.prototype.invoke = function(){
		this.forwardToNextPage();
		this.init();
	}


/**
* ClickStreamInfoクラス
*
* 
*/
ClickStreamInfo = function(){}
	ClickStreamInfo.prototype.cookieName = "clickstream";
	ClickStreamInfo.prototype.domainName = ".cisco.com";
	
	ClickStreamInfo.prototype.peerId = "";
	ClickStreamInfo.prototype.progName = "";
	ClickStreamInfo.prototype.pType = "";
	ClickStreamInfo.prototype.ref = "";
	ClickStreamInfo.prototype.cookieVersion = "1";
	ClickStreamInfo.prototype.fr1 = "";
	ClickStreamInfo.prototype.fr2 = "";
	ClickStreamInfo.prototype.fr3 = "";
	ClickStreamInfo.prototype.paramList = new Array();
	ClickStreamInfo.prototype.enableCS = true;
	ClickStreamInfo.prototype.debug = false;

	/**
	* 初期化します。
	*
	*/
	ClickStreamInfo.prototype.init = function(){
		this.peerId = "";
		this.progName = "";
		this.pType = "";
		this.ref = "";
		this.cookieVersion = "1";
		this.fr1 = "";
		this.fr2 = "";
		this.fr3 = "";
		this.paramList.length = 0;
		this.enableCS = true;
		this.debug = false;
	}
	/**
	* ClickStreamパラメータを作成します。
	*
	*/
	ClickStreamInfo.prototype.makeClickStreamParam = function(){

		if(isBlankOrNull(this.progName) == false){
			this.paramList.push("progname=" + this.progName);
		}
		if(isBlankOrNull(this.pType) == false){
			this.paramList.push("ptype=" + this.pType);
		}
		if(isBlankOrNull(this.ref) == false){
			this.paramList.push("ref=" + this.ref);
		}
		if(isBlankOrNull(this.fr1) == false){
			this.paramList.push("fr1=" + this.fr1);
		}
		if(isBlankOrNull(this.fr2) == false){
			this.paramList.push("fr2=" + this.fr2);
		}
		if(isBlankOrNull(this.fr3) == false){
			this.paramList.push("fr3=" + this.fr3);
		}

	}
	/**
	* imgタグを生成します。
	*
	*/
	ClickStreamInfo.prototype.loadImg = function(){
		var i = 0;
		var param = "";

		if(this.enableCS == false){
			return;
		}

		this.makeClickStreamParam();

		if(this.paramList.length == 0){
			return;
		}else{
			param = "?";
		}

		for(i = 0; i < this.paramList.length; i++){
			param += this.paramList[i];

			if(i < this.paramList.length - 1){
				param += "&";
			}
		}

		var src = "";
		src += "http://www.cisco.com/web/JP/event/campaign/shared/clickstream.html";
		src += param

//		var clickstreamImg = new Image(1, 1);
//		clickstreamImg.src = src;
		
		var html = "<img src=" + src + " width=1 height=1 border=0>";
		document.write(html);
		
		if(this.debug == true){
			alert("ClickStreamInfo : imgUrl|" + src + "|");
		}
		

	}
	/**
	* 一連のロード前処理を行ないます。
	*
	*/
	ClickStreamInfo.prototype.prepare = function(){
	}
	/**
	* 一連のロード後処理を行ないます。
	*
	*/
	ClickStreamInfo.prototype.invoke = function(){
	}



/**
* CsLandingInfoクラス
*
* 次の項目の設定が必要です。
* peerId			: PEER IDまたはPEER IDがない場合、yyyyMMddHHmmss形式で指定します。
* progName			: 計測用プログラム名(半角英数字) 指定しない場合、QueryStringの値が引き継がれます。
* pType				: 計測用ページタイプ(半角英数字) 指定しない場合、QueryStringの値が引き継がれます。
* (cookieVersion	: Cookie形式バージョン デフォルトで1が設定されます。)
*/
CsLandingInfo = function(){}
	// ClickStreamInfoクラスを継承します。
	CsLandingInfo.prototype =	new ClickStreamInfo();

	/**
	* QueryStringを読み込みます。
	*
	*/
	CsLandingInfo.prototype.readQueryString = function(){
		var qs = new QueryString();
		qs.parse();
		
		if(isBlankOrNull(this.progName) == true){
			this.progName = unescape(nvl(qs.find("progname"), ""));
		}
		if(isBlankOrNull(this.pType) == true){
			this.pType = unescape(nvl(qs.find("ptype"), ""));
		}
		if(isBlankOrNull(this.ref) == true){
			this.ref = unescape(nvl(qs.find("ref"), ""));
		}
		if(isBlankOrNull(this.fr1) == true){
			this.fr1 = unescape(nvl(qs.find("fr1"), ""));
		}
		if(isBlankOrNull(this.fr2) == true){
			this.fr2 = unescape(nvl(qs.find("fr2"), ""));
		}
		if(isBlankOrNull(this.fr3) == true){
			this.fr3 = unescape(nvl(qs.find("fr3"), ""));
		}
		
		if(_debug == true){
			alert("CsLandingInfo : peerId|" + this.peerId + "| progName|" + this.progName + "| pType|" + this.pType + "| ref|" + this.ref + "| cookieVersion|" + this.cookieVersion + "| fr1|" + this.fr1 + "| fr2|" + this.fr2 + "| fr3|" + this.fr3 + "|");
		}
	}
	/**
	* 経路をCookieに設定します。
	*
	*/
	CsLandingInfo.prototype.saveRoute = function(){
	
		var _cookie = new Cookie(document, this.cookieName, 1, "/", this.domainName);
		
		_cookie.JP_CS_VERSION = this.cookieVersion;	// Cookieの形式に変更があったときの管理番号
		_cookie.JP_CS_PEERID = this.peerId;
	
		if(isBlankOrNull(this.progName) == false){
			_cookie.JP_CS_PROGNAME = this.progName;
		}
		if(isBlankOrNull(this.pType) == false){
			_cookie.JP_CS_PTYPE = this.pType;
		}
		if(isBlankOrNull(this.ref) == false){
			_cookie.JP_CS_REF = this.ref;
		}
		if(isBlankOrNull(this.fr1) == false){
			_cookie.JP_CS_FR1 = this.fr1;
		}
		if(isBlankOrNull(this.fr2) == false){
			_cookie.JP_CS_FR2 = this.fr2;
		}
		if(isBlankOrNull(this.fr3) == false){
			_cookie.JP_CS_FR3 = this.fr3;
		}
		_cookie.store();
		
		if(_debug == true){
			alert("CsLandingInfo : peerId|" + this.peerId + "| progName|" + this.progName + "| pType|" + this.pType + "| ref|" + this.ref + "| cookieVersion|" + this.cookieVersion + "| fr1|" + this.fr1 + "| fr2|" + this.fr2 + "| fr3|" + this.fr3 + "|");
		}
	}
	/**
	* 一連のロード前処理を行ないます。
	*
	*/
	CsLandingInfo.prototype.prepare = function(){
		this.readQueryString();
		this.loadImg();
		this.saveRoute();
		this.init();
	}




/**
* CsSurveyInfoクラス
*
* 次の項目の設定が必要です。
* peerId			: PEER IDまたはPEER IDがない場合、yyyyMMddHHmmss形式で指定します。
* progName			: 計測用プログラム名(半角英数字) 指定しない場合、Cookieの値が引き継がれます。
* pType				: 計測用ページタイプ(半角英数字) 指定しない場合、Cookieの値が引き継がれます。
* (cookieVersion	: Cookie形式バージョン デフォルトで1が設定されます。)
*/
CsSurveyInfo = function(){}
	// ClickStreamInfoクラスを継承します。
	CsSurveyInfo.prototype =	new ClickStreamInfo();

	/**
	* Cookieから経路を読み込みます。
	*
	*/
	CsSurveyInfo.prototype.loadRoute = function(){
		var version = "";
		var peerid = "";

		if(_debug == true){
			alert("CsSurveyInfo : peerId|" + this.peerId + "| progName|" + this.progName + "| pType|" + this.pType + "| ref|" + this.ref + "| cookieVersion|" + this.cookieVersion + "| fr1|" + this.fr1 + "| fr2|" + this.fr2 + "| fr3|" + this.fr3 + "|");
		}
		
		var _cookie = new Cookie(document, this.cookieName);
		_cookie.load();

		
		if (_cookie.JP_CS_VERSION){
			version = escape(_cookie.JP_CS_VERSION);
		}
		if (_cookie.JP_CS_PEERID){
			 peerid = escape(_cookie.JP_CS_PEERID);
		}
		if (version==this.cookieVersion && peerid==this.peerId){
			if (_cookie.JP_CS_PROGNAME){
				this.progName = nvl(this.progName, escape(_cookie.JP_CS_PROGNAME));
			}
			if (_cookie.JP_CS_PTYPE){
				this.pType = nvl(this.pType, escape(_cookie.JP_CS_PTYPE));
			}
			if (_cookie.JP_CS_REF){
				this.ref = nvl(this.ref, escape(_cookie.JP_CS_REF));
			}
			if (_cookie.JP_CS_FR1){
				this.fr1 = nvl(this.fr1, escape(_cookie.JP_CS_FR1));
			}
			if (_cookie.JP_CS_FR2){
				this.fr2 = nvl(this.fr2, escape(_cookie.JP_CS_FR2));
			}
			if (_cookie.JP_CS_FR3){
				this.fr3 = nvl(this.fr3, escape(_cookie.JP_CS_FR3));
			}
		}
		
		if(_debug == true){
			alert("CsSurveyInfo : peerId|" + this.peerId + "| progName|" + this.progName + "| pType|" + this.pType + "| ref|" + this.ref + "| cookieVersion|" + this.cookieVersion + "| fr1|" + this.fr1 + "| fr2|" + this.fr2 + "| fr3|" + this.fr3 + "|");
		}
	}
	/**
	* 一連のロード前処理を行ないます。
	*
	*/
	CsSurveyInfo.prototype.prepare = function(){
		this.loadRoute();
		this.loadImg();
		this.init();
	}




/**
* CsThanksInfoクラス
*
* 次の項目の設定が必要です。
* peerId			: PEER IDまたはPEER IDがない場合、yyyyMMddHHmmss形式で指定します。
* progName			: 計測用プログラム名(半角英数字)
* pType				: 計測用ページタイプ(半角英数字)
* (cookieVersion	: Cookie形式バージョン デフォルトで1が設定されます。)
*/
CsThanksInfo = function(){}
	// CsSurveyInfoクラスを継承します。
	CsThanksInfo.prototype =	new CsSurveyInfo();

	/**
	* 一連のロード前処理を行ないます。
	*
	*/
	CsThanksInfo.prototype.prepare = function(){
		this.loadRoute();
		this.loadImg();
		this.init();
	}


/**
* CampaignInfoクラス
*
* 次の項目の設定が必要です。
* peerId			: PEER ID
*/
CampaignInfo = function(){}
	CampaignInfo.prototype.peerId = "";
	CampaignInfo.prototype.myList = new Array();
	
	/**
	* 処理を行なうオブジェクトを追加します。
	*
	*/
	CampaignInfo.prototype.add = function(obj){
		obj.peerId = this.peerId;
		this.myList.push(obj);
	}
	/**
	* 登録順にオブジェクトのロード前処理を行ないます。
	*
	*/
	CampaignInfo.prototype.prepare = function(){
		var i = 0;
		var obj = null;
		
		for(i = 0; i<this.myList.length; i++){
			obj = this.myList[i];
			obj.prepare();
		}
	}
	/**
	* 登録順にオブジェクトのロード後処理を行ないます。
	*
	*/
	CampaignInfo.prototype.invoke = function(){
		var i = 0;
		var obj = null;
		
		for(i = 0; i<this.myList.length; i++){
			obj = this.myList[i];
			obj.invoke();
		}
	}

