//	vcms_lpo
//	vcms_lpo[n].word = キーワード;
//	vcms_lpo[n].word_utf  = URIエンコード済キーワード(utf);
//	vcms_lpo[n].word_euc  = URIエンコード済キーワード(euc);
//	vcms_lpo[n].word_sjis = URIエンコード済キーワード(sjis);
//	vcms_lpo[n].url = ランディングページURL;
vcms_LPOJump();
function vcms_LPOJump(){
	if(vcms_lpo && vcms_lpo.length && document.referrer){
		var obj = vcms_getKeyword(document.referrer);
		switch(obj.jcode){
			case "euc":
				for(var i=0; i<vcms_lpo.length; i++){
					if(obj && obj.word && vcms_PerfectMatchingCheck(obj.word, vcms_lpo[i].word_euc)){
						location.href = vcms_lpo[i].url;
					}
				}
			break;
			case "sjis":
				for(var i=0; i<vcms_lpo.length; i++){
					if(obj && obj.word && vcms_PerfectMatchingCheck(obj.word, vcms_lpo[i].word_sjis)){
						location.href = vcms_lpo[i].url;
					}
				}
			break;
			case "utf":
			default:
				for(var i=0; i<vcms_lpo.length; i++){
					if(obj && obj.word && vcms_PerfectMatchingCheck(obj.word, vcms_lpo[i].word_utf)){
						location.href = vcms_lpo[i].url;
					}
				}
			break;
		}
	}
}
function vcms_PerfectMatchingCheck(k1,k2){
	k1 = k1.toLowerCase();
	k2 = k2.toLowerCase();
	var kA1 = k1.split("+");
	var kA2 = k2.split("+");
	if(kA1.length != kA2.length){
		return false;
	}
	var matchcount = 0;
	for(var i=0; i<kA1.length; i++){
		if(vcms_PerfectMatch(kA1[i],kA2)){
			matchcount++;
		}
	}
	if(kA1.length == matchcount){
		return true;
	}
	return false;
}
function vcms_PerfectMatch(k,kA){
	for(var i=0; i<kA.length; i++){
		if(kA[i] == k){
			return true;
		}
	}
	return false;
}
function vcms_getKeyword(requested_url){
	var wA = requested_url.split("?");
	var url = wA[0];
	var getstr = wA[1];
	if(!getstr){	return '';	}
	if(getstr == '' && !url.match(/a9\.com|\.excite\.com|technorati\.jp/)){		return '';	}
	var Aparts = getstr.split("&");
	var Pvariables = new Object();
	for(var i=0; i<Aparts.length; i++){
		var wA = Aparts[i].split("=");
		var name = wA[0];
		var value = wA[1];
		if(value != ''){
			value = value.replace(/\++/gi,"%20");
			Pvariables[name] = value;
		}
	}
	var Aurl_parts = url.split("/");
	var Aurl_parts2 = Aurl_parts[2].split(".");
	var tld = Aurl_parts2.pop();
	var word = '';
	var engine_name = '';
	var engine_url = '';
	if(url.match(/\.google\./)){
		// Google
		if(url.match(/images\.google\./)){
			var prev = Pvariables['prev'];
			prev = decodeURI(prev);
			var pA = new Array();
			if(pA = prev.match(/q=([^&]+)&/)){
				word = pA[1];
			}
		}
		else if(Pvariables['q'] != undefined){
			word = Pvariables['q'];
		}
		else if(Pvariables['as_q'] != undefined){
			word = Pvariables['as_q'];
		}
	}
	else if(url.match(/\.yahoo\./)){
		// Yahoo
		if(Pvariables['p'] != undefined){
			word = Pvariables['p'];
		}
		else if(Pvariables['key'] != undefined){
			word = Pvariables['key'];
		}
	}
	else if(url.match(/\.auone\./)){
		// au one　←　dion
		word = Pvariables['q'];
		word = word.replace(/%81@/gi,"%20");
	}
	else if(url.match(/\.excite\./)){
		if(url.match(/odn\.excite\.co\.jp/)){
			// ODN
			word = Pvariables['search'];
		}
		else if(url.match(/dion\.excite\.co\.jp/)){
			// DION
			word = Pvariables['search'];
		}
		else{
			// excite
			if(Pvariables['search']){
				word = Pvariables['search'];
			}
			else if(Pvariables['s']){
				word = Pvariables['s'];
			}
		}
		word = word.replace(/%81@/gi,"%20");
	}
	else if(url.match(/\.msn\./)){
		// MSN
		word = Pvariables['q'];
	}
	else if(url.match(/\.live\.com/)){
		// Live Search
		word = Pvariables['q'];
	}
	else if(url.match(/\.infoseek\./)){
		// infoseek
		word = Pvariables['qt'];
	}
	else if(url.match(/\.goo\.ne\.jp/)){
		// goo
		word = Pvariables['MT'];
	}
	else if(url.match(/search\.livedoor\.com/)){
		// livedoor
		word = Pvariables['q'];
	}
	else if(url.match(/ask\.[a-z]+\//)){
		// Ask
		word = Pvariables['q'];
	}
	else if(url.match(/lycos/)){
		// Lycos	→　終了？
		if(url.match(/wisenut/)){
			word = Pvariables['q'];
		}
		else{
			word = Pvariables['query'];
		}
	}
	else if(url.match(/\.fresheye\.com/)){
		// フレッシュアイ
		word = Pvariables['kw'];
		word = word.replace(/%A1%A1/gi,"%20");
	}
	else if(url.match(/search\.biglobe\.ne\.jp/)){
		// BIGLOBEサーチ
		word = Pvariables['q'];
		word = word.replace(/%A1%A1/gi,"%20");
	}
	else if(url.match(/\.netscape\.com/)){
		// Netscape Search
		if(Pvariables['query']){
			word = Pvariables['query'];
		}
		else{
			word = Pvariables['s'];
		}
		word = word.replace(/%E3%80%80/gi,"%20");
	}
	else if(url.match(/www\.overture\.com/)){
		// overtune
		word = Pvariables['Keywords'];
	}
	else if(url.match(/\.altavista\.com/)){
		// altavista
		word = Pvariables['q'];
	}
	else if(url.match(/search\.aol\.com/)){
		// AOL Search(com)
		word = Pvariables['query'];
	}
	else if(url.match(/search\.jp\.aol\.com/)){
		// AOL Search(jp)
		if(Pvariables['userQuery']){
			word = Pvariables['userQuery'];
			word = word.replace(/%81@/gi,"%20");
		}
		else{
			word = Pvariables['query'];
			word = word.replace(/%81@/gi,"%20");
		}
	}
	else if(url.match(/\.looksmart\.com/)){
		// looksmart　→　終了？
		word = Pvariables['qt'];
	}
	else if(url.match(/bach\.istc\.kobe\-u\.ac\.jp\/cgi\-bin\/metcha\.cgi/)){
		// Metcha Seearch
		word = Pvariables['q'];
		word = word.replace(/%A1%A1/gi,"%20");
	}
	else if(url.match(/\.alltheweb\.com/)){
		// alltheweb
		word = Pvariables['q'];
	}
	else if(url.match(/\.alexa\.com\/search/)){
		// Alexa
		word = Pvariables['q'];
	}
	else if(url.match(/search\.naver\.com/)){
		// NEVER
		word = Pvariables['query'];
		word = word.replace(/%A1%A1/gi,"%20");
	}
	else if(url.match(/\.baidu\.(com|jp)/)){
		// 百度
		var tldA = url.match(/\.baidu\.(com|jp)/);
		var tld = tldA[1];
		word = Pvariables['wd'];
	}
	else if(url.match(/\.mooter\.co\.jp/)){
		// Mooter
		word = Pvariables['keywords'];
	}
	else if(url.match(/\.marsflag\.com/)){
		// MARS FLAG
		word = Pvariables['phrase'];
		word = word.replace(/%E3%80%80/gi,"%20");
	}
	else if(url.match(/clusty\.jp/)){
		// Clusty
		word = Pvariables['query'];
	}
	else if(url.match(/(search|newsflash)\.nifty\.com/)){
		// nifty アット・サーチ
		if(Pvariables['Text'] != undefined){
			word = Pvariables['Text'];
		}
		else if(Pvariables['q'] != undefined){
			word = Pvariables['q'];
		}
		else if(Pvariables['key'] != undefined){
			word = Pvariables['key'];
		}
		else{
			word = Pvariables['q'];
		}
	}
	else if(url.match(/\.technorati\.jp\/search\/(.+)$/)){
		// テクノラティ
		var tldA = url.match(/\.technorati\.jp\/search\/(.+)$/);
		word = tldA[1];
		word = word.replace(/%E3%80%80/gi,"%20");
	}
	else{
		return '';
//	test ------------------------------------
		if(Pvariables['q'] != ''){
			word = Pvariables['q'];
		}
		else if(Pvariables['as_q'] != ''){
			word = Pvariables['as_q'];
		}
//	test ------------------------------------
	}


	if(word == ''){		return '';	}



	var jcode = "utf";
	if(requested_url.match(/\&(ei|ie)\=utf\-8/i)){
		word = word.replace(/%E3%80%80/gi,"%20");
		jcode = "utf";
	}
	else if(requested_url.match(/\&(ei|ie)\=utf8/i)){
		word = word.replace(/%E3%80%80/gi,"%20");
		jcode = "utf";
	}
	else if(requested_url.match(/\&(ei|ie)\=euc\-jp/i)){
		word = word.replace(/%A1%A1/gi,"%20");
		jcode = "euc";
	}
	else if(requested_url.match(/\&(ei|ie)\=(Shift_JIS|SJIS)/i)){
		word = word.replace(/%81%40/gi,"%20");
		jcode = "sjis";
	}
	else if(requested_url.match(/\.google\./)){
		word = word.replace(/%E3%80%80/gi,"%20");
		jcode = "utf";
	}


	else if(requested_url.match(/\&(cs)\=euc/i)){
		word = word.replace(/%A1%A1/gi,"%20");
		jcode = "euc";
	}
	else if(requested_url.match(/odn\.excite/)){
		jcode = "sjis";
	}
	else if(requested_url.match(/\.excite\./)){
		jcode = "sjis";
	}
	else if(requested_url.match(/\.biglobe\./)){
		jcode = "euc";
	}
//else if(requested_url.match(/jp\.aol\./)){
//	word = word.replace(/%E3%80%80/gi,"%20");
//	jcode = "utf";
//}
	else if(requested_url.match(/metcha\.cgi/)){
		jcode = "euc";
	}
	else if(requested_url.match(/search\.livedoor\./)){
		jcode = "euc";
	}
	else if(url.match(/search\.jp\.aol\.com/)){
		word = word.replace(/%E3%80%80/gi,"%20");
		jcode = "utf";
	}


	else{
		word = word.replace(/%E3%80%80/gi,"%20");
		jcode = "utf";
	}
	word = word.replace(/%20/gi,"\+");
	word = word.replace(/\++/g,"\+");
	word = word.replace(/\s+/g," ");
	word = word.replace(/^\s/,"");
	word = word.replace(/\s$/,"");
	var rA = new Object();
	rA.jcode = jcode;
	rA.word = word;
	rA.engine_name = engine_name;
	rA.engine_url = engine_url;
	return rA;
}
