/**
* windowを開く
* @param:
* tar:ターゲット<a>オブジェクト
* win:ウインドウ名
* o:オプションオブジェクト
* o.width:ウインドウ幅 [デフィルト:スクリーン幅 / 2]
* o.height:ウインドウ高 [デフィルト:スクリーン高 / 2]
* o.xpos:x座標 [デフィルト:0]
* o.ypos:y座標 [デフィルト:0]
* o.menu:メニューバーの有無 [デフィルト:no]
* o.tool:ツールバーの有無 [デフィルト:no]
* o.loc:ロケーションバーの有無 [デフィルト:no]
* o.status:ステータスバーの有無 [デフィルト:yes]
* o.resize:リサイズの有無 [デフィルト:yes]
* o.scroll:スクロールバーの有無 [デフィルト:yes]
*/
function openWin(tar, win, o){
	var wo;
	var op="";
	var u = tar.href;
	var w = (win) ? win : "sub";
	if(o){
		o.width = (typeof o.width == 'undefined') ? screen.width/2 : o.width;
		o.height = (typeof o.height == 'undefined') ? screen.height/2 : o.height;
		o.xpos = (typeof o.xpos == 'undefined') ? (screen.width/2)-(o.width/2) : o.xpos;
		o.ypos = (typeof o.ypos == 'undefined') ? (screen.height/2)-(o.height/2) : o.ypos;
		o.menu = (typeof o.menu == 'undefined') ? 'no' : o.menu;
		o.tool = (typeof o.tool == 'undefined') ? 'no' : o.tool;
		o.loc = (typeof o.loc == 'undefined') ? 'no' : o.loc;
		o.status = (typeof o.status == 'undefined') ? 'yes' : o.status;
		o.resize = (typeof o.resize == 'undefined') ? 'yes' : o.resize;
		o.scroll = (typeof o.scroll == 'undefined') ? 'yes' : o.scroll;
		
		o.xpos = (o.xpos == "left") ? o.xpos=0 : (o.xpos == "right") ? screen.width - o.width : o.xpos;
		o.ypos = (o.ypos == "top") ? o.ypos=0 : (o.ypos == "bottom") ? screen.height - o.height : o.ypos;
		
		
		op += 'menubar='+o.menu+",";
		op += 'toolbar=' + o.tool + ",";
		op += 'location=' + o.loc + ",";
		op += 'status=' + o.status + ",";
		op += 'resizable=' + o.resize + ","
		op += 'scrollbars=' + o.scroll + ",";
		op += 'width=' + o.width + ',height=' + o.height + ",";
		op += 'top=' + o.ypos + ',left=' + o.xpos;
	}
	
	wo = (op.length > 0) ? window.open(u,w,op) : window.open(u,w);
	wo.focus();
	return false;
}


/**
* windowを開く(Flash用)
* @param:
* t:url
* w:window name
* o:option
*/
function openWinf(t, w, o){
	var tar = new Object();
	tar.href = t;
	if(w) win = w;
	if(o) {
		var option = new Object();
		var ao = o.split(",");
		for(i =0; i <ao.length; i++){
			var p = ao[i].indexOf("=");
			var n = ao[i].substr(0, p);
			var v = ao[i].substring(p + 1);
			switch (n){
				case "width":
					option.width = v;
					break;
				case "height":
					option.height = v
					break;
				case "xpos":
					option.xpos = v;
					break;
				case "xpos":
					option.xpos = v;
					break;
				case "ypos":
					option.ypos = v;
					break;
				case "menu":
					option.menu = v;
					break;
				case "tool":
					option.tool = v;
					break;
				case "loc":
					option.loc = v;
					break;
				case "status":
					option.status = v;
					break;
				case "resize":
					option.resize = v;
					break;
				case "scroll":
					option.scroll = v;
					break;
				default:
					//値がへん
			}
		}
	}
	
	if(w && o){
		openWin(tar, win, option);
	}else if(w){
		openWin(tar, win);
	}else{
		openWin(tar);
	}
}

/**
* 親windowを変える
* @param:
* tar:ターゲット<a>オブジェクト
* t:呼び出し元のタイプ
* code:Google Anaryticsコード
*/
function changeParURL(tar,t){
	if(t == "flash"){
		tar = {href:tar};
	}
	
	var b = CheckParWin();
	if(b){
		window.opener.focus();
		window.opener.location.href = tar.href;
	}else{
		return openWin(tar, 'main');
	}
	return false;
}

/**
* 親windowの有無を調べる
* @param:
*/
function CheckParWin(){
	var b;
	if ((navigator.userAgent.indexOf("Mac") > -1)){
		b = (window.opener) ? true : false;
	}else{
		b = (window.opener&&!window.opener.closed) ? true : false;
	}
	return b;
}


/**
* Google Anaryticsコードをコール後、windowを開く
* @param:
* t:url
* w:window name
* o:option
* code:Google Anaryticsコード
*/
function openWinfAndCode(code, t, w, o){
	pageTracker._trackPageview(code);
	if(w == 'undefined' && o == 'undefined'){
    	openWinf(t);
	}else if(o == 'undefined'){
		openWinf(t, w);
	}else{
		openWinf(t, w, o);
	}
}

/**
* Google Anaryticsコードをコール後、mailto
* @param:
* body:内容
* code:Google Anaryticsコード
*/
function mailtoAndCode(code, body){
	pageTracker._trackPageview(code);
	var id = setTimeout("mailtoFriend('" + body + "')", 200);
}


function mailtoFriend(body){
    ///location.href = "mailto:?body=" + body;
    location.href = "mailto:?body=" + escape(body);
}

