// 2011/06/03 modify uno
// location.href からHTMLタグを取り除く for IE
String.prototype.htmlspecialchars = function(){
  var string = this;
  var table = [
    [/&/g, '&amp;'],
    [/</g, ''],
    [/>/g, ''],
    [/"/g, ''],
    [/'/g, '']
  ];
  for (var i in table) {
    string = string.replace(table[i][0], table[i][1]);
  }
  return string;
}


 key = ('http://'+location.href.split('/')[2]+'/').htmlspecialchars();
jQuery.noConflict();
var $ = jQuery;
$(function() {
	$.ajaxSetup({scriptCharset:'utf-8'});
	v_login();
	v_current();
	v_exad();
});





/*---------------------
vpass login check
---------------------*/
function v_login() {
	var hostpath = location.href.htmlspecialchars();
	//console.log(hostpath);
	var login = (getCookie())?'<a href="http://passport.vector.co.jp/passport/passport.php?p=VP_PROC_SIGNUP_ENTRY&amp;f=RG&amp;v=' + hostpath + '">ベクターパスポート</a>&nbsp;/&nbsp;<a href="http://my.vector.co.jp/">Vアップ通知</a>&nbsp;/&nbsp;<a href="http://passport.vector.co.jp/passport/passport.php?p=VP_PROC_LOGIN_ENTRY&amp;f=LB&amp;v=' + hostpath +'">ログイン</a>':'<a href="https://passport.vector.co.jp/passport/passport.php?p=VP_PROC_MODIFY_MENU&amp;f=RG&amp;v=' + hostpath + '">登録情報変更</a>&nbsp;/&nbsp;<a href="http://my.vector.co.jp/">Vアップ通知</a>&nbsp;/&nbsp;<a href="http://passport.vector.co.jp/passport/passport.php?p=VP_PROC_LOGOUT&amp;f=RG&amp;v=' + hostpath +'">ログアウト</a><br />' + getUid() + 'でログイン中';
	$('#v_login').html(login);
};





/*---------------------
vpass cookie
---------------------*/
/*get cookie*/
function getCookie(){
	var str = document.cookie;
	return ((str.match("LOGIN=u") == null) && (str.match("LLOGIN=l") == null)) || (str.match("BASE=i") == null);
}

/*get user id*/
function getUid(){
	if(getCookie()) {
		return "ゲスト";
	} else {
		if(document.cookie.match("BASE=i") == null) return "WHO?";
		bpos = document.cookie.indexOf("BASE=i");
		bpoe = document.cookie.indexOf("%26",bpos);
		bco = document.cookie.substr(bpos+9,bpoe-bpos-9);
		return decodeURIComponent(bco);
	}
}





/*---------------------
current(global menu)
---------------------*/
function v_current() {
	$.each($('#v_header dl dd'),function() {$('a[href='+key+']',this).addClass('current');});
}




/*---------------------
exad
---------------------*/
function v_exad() {
	var sc = document.cookie;
	if(sc.indexOf("SHOPNOEX=YES")>-1 || sc.indexOf("VECNOEX=YES")>-1)$('.exad').hide();
}

