<!--
// 定数定義
var actionName = 'a';
var moduleName = 'm';

// サブミット
function sub_do(frm, mod) {
	sub_all(frm, frm.action_org.value, mod);
}
function sub_all(frm, act, mod) {
	if(!click_chk()) return false;
	
	showLoading();
	
	frm.elements[actionName].value = act;
	frm.elements[moduleName].value = mod;
	frm.submit();
}

// ダウンロード
function sub_download(frm, mod) {
	if(mod == undefined) mod = 'download';
	frm.elements[moduleName].value = mod;
	frm.submit();
}

// キャッシュの指定を外すためのパラメータ
function param_nocache() {
	var tv = (new Date).getTime();
	return '&tv_for_nocache=' + tv;
}

// アンカータグの代わり
function sub_redirect(act, args) {
	var pars = 'a=' + act;
	if(args != undefined && args != '') {
		if(args.charAt(0) != '&') args = '&' + args;
		pars += args;
	}
	var frm = document.mainform;
	if(frm != undefined && frm.topmenu_display != undefined) pars += '&topmenu_display=' + frm.topmenu_display.value;
	pars += param_nocache();
	
	showLoading();
	
	var url = 'index.php?' + pars;
	location.href = url;
}

// ポップアップ表示
function sub_popup(window_id, pars, small) {
	var url = 'index.php?' + pars + '&popup=1' + param_nocache();
	if(document.mainform != undefined) url += '&account_id_org=' + document.mainform.account_id_org.value;
	if(small == '1') {
		return open_w2(url, window_id, 'width=450,height=550,resizable=yes,scrollbars=yes,status=yes');
	}
	return open_w2(url, window_id, 'width=800,height=720,resizable=yes,scrollbars=yes,status=yes');
}

function sub_popup_no_return(window_id, pars, small) {
	var url = 'index.php?' + pars + '&popup=1' + param_nocache();
	if(document.mainform != undefined) url += '&account_id_org=' + document.mainform.account_id_org.value;
	if(small == '1') {
		open_w2(url, window_id, 'width=450,height=550,resizable=yes,scrollbars=yes,status=yes');
	}
	open_w2(url, window_id, 'width=800,height=720,resizable=yes,scrollbars=yes,status=yes');
}

// 削除
function sub_delete(msg){
	var frm = document.mainform;
	if(sub_delete_proc(frm, 'del') == false) return false;
	sub_do(frm, 'delete');

}

function sub_delete_proc(frm, obj_name, msg){
	var ids = get_sel_ids(frm, obj_name);
	if( ids == '' ) {
		alert("削除する対象を選択してください。");
		return false;
	}
	if(msg == undefined || msg == '') msg = "削除します。\nよろしいですか？";
	if( !window.confirm(msg) ) return false;
	frm.del_ids.value = ids;
	return true;
}

function sub_admin_login(){
	var frm = document.loginform;
	frm.account_id.value = 'empty';
	frm.login_id.value = 'empty';
	frm.password.value = 'empty';
	frm.login_type.value = 'admin';
	if (!sub_all(frm, 'login/Login', '')) return false;

}

// 確認
function confirm_regist(){
	msg = "登録します。\nよろしいですか？";
	return window.confirm(msg);
}
function confirm_delete(){
	msg = "削除します。\nよろしいですか？";
	return window.confirm(msg);
}

// 絞込
function sub_filter(){
	var frm = document.mainform;
	var ids = get_sel_ids(frm, 'sel');
	if( ids == '' ) {
		alert("絞り込む対象を選択してください。");
		return false;
	}
	frm.sel_ids.value = ids;	
	sub_do(frm, 'list');

}
function sub_filter_reset(){
	var frm = document.mainform;
	frm.sel_ids.value = '';	
	sub_do(frm, 'list');

}

function get_sel_ids(frm, obj_name) {
	var ids = '';
	var elements = document.getElementsByName(obj_name);
	for(var i = 0; i < elements.length; i++) {
		if(elements[i].form != frm) continue;
		if(elements[i].checked) {
			if(ids != '') ids += ',';
			ids += elements[i].value;
		}
	}
	return ids;
}


// 一覧
function sub_list(){
	var frm = document.mainform;
	if(frm.from_date != undefined && !isDate(frm.from_date.value)) return false;
	if(frm.to_date != undefined && !isDate(frm.to_date.value)) return false;
	if(frm.from_date != undefined && frm.to_date != undefined && !checkOrder3(frm.from_date.value, frm.to_date.value, '期間')) return false;
	sub_do(frm, 'list');
	return false;
}

// ページ行切替
function sub_change_lines(lines){
	var frm = document.mainform;
	sub_change_lines_proc(frm, lines);
	frm.elements['control'].value = 'page';
	sub_list();
}
function sub_change_lines_proc(frm, lines){
	frm.elements['lines_per_page'].value = lines;
	frm.elements['page_no'].value = 1;
}

// ページ切替
function sub_change_page(page_no){
	var frm = document.mainform;
	frm.elements['page_no'].value = page_no;
	frm.elements['control'].value = 'page';
	sub_list();
}
function sub_add_page(offset, page_no, page_max){
	var frm = document.mainform;
	sub_add_page_proc(frm, offset, page_no, page_max);
	frm.elements['control'].value = 'page';
	sub_list();
}
function sub_add_page_proc(frm, offset, page_no, page_max){
	var new_no = page_no + offset;
	if(new_no < 1) new_no = 1;
	if(new_no > page_max) new_no = page_max;
	frm.elements['page_no'].value = new_no;
}

// 並べ替え
function sub_sort(sort_column, sort_order){
	var frm = document.mainform;
	sub_sort_proc(frm, sort_column, sort_order);
	frm.elements['control'].value = 'sort';
	sub_list();
}
function sub_sort_proc(frm, sort_column, sort_order){
	var org_column = frm.elements['sort_column'].value;
	var org_order = frm.elements['sort_order'].value;
	if(org_column == sort_column) {
		sort_order = (org_order == 'desc' ? 'asc' : 'desc');
	}
	frm.elements['sort_column'].value = sort_column;
	frm.elements['sort_order'].value = (!sort_order ? 'asc' : sort_order);
}

// 削除チェック
function change_check(each_name, all_id){
	var frm = document.mainform;
	change_check_proc(frm, each_name, all_id);
}
function change_check_proc(frm, each_name, all_id){
	var elements = document.getElementsByName(each_name);
	var all_checked = true;
	for(var i = 0; i < elements.length; i++) {
		if(elements[i].form != frm) continue;
		if(elements[i].checked == false) {
			all_checked = false;
			break;
		}
	}
	var objAll = getObjById(all_id);
	objAll.checked = all_checked;
}



// バナー入力
function sub_popup_banner(banner_id, campaign_id, deliver_type, from_campaign){
	var m = (banner_id > 0 ? 'modify_input' : 'regist_input');
	var pars = 'a=plan/banner/BannerList'
			+ '&m=' + m
			+ '&banner_id=' + banner_id;
	if(campaign_id != undefined) pars += '&campaign_id=' + campaign_id;
	if(deliver_type != undefined) pars += '&deliver_type=' + deliver_type;
	if(from_campaign != undefined) pars += '&from_campaign=' + from_campaign;
	sub_popup('banner_details', pars);
}

// ヘルプ表示
function sub_popup_help(){
	var pars = 'a=common/help/Help'
			+ '&m=list';
	sub_popup('help', pars);
}

// エクスポート
function sub_export(mod, export_col, report_type){
	if(export_col == undefined) export_col = '';
	if(report_type == undefined) report_type = '';
	
	var frm = document.exportform;
	frm.elements[actionName].value = 'common/report/ReportExport';
	frm.elements[moduleName].value = mod;
	if(export_col!='') frm.export_col.value = export_col;
	if(report_type!='') frm.report_type.value = report_type;
	frm.submit();	
}

// -------- エクスポート（アシスト分析）2009.05.25 hakamata -----------
function sub_export_assist(mod){

	var frm = document.exportassistform;

	frm.elements[actionName].value = 'common/report/ReportAssistExport';
	frm.elements[moduleName].value = mod;
	frm.submit();	

}

// 成約率、退会率エクスポート
function sub_ao_export(mod, export_col, report_type){
	if(export_col == undefined) export_col = '';
	if(report_type == undefined) report_type = '';
	
	var frm = document.exportform;
	frm.elements[actionName].value = 'common/report/ReportExportAgreeOut';
	frm.elements[moduleName].value = mod;
	if(export_col!='') frm.export_col.value = export_col;
	if(report_type!='') frm.report_type.value = report_type;
	frm.submit();	
}

// 印刷
function sub_print(){
	window.print();
}

// 検索条件の表示
function show_bind(type) {
	var pars = 'a=common/report/ShowBind'
			 + '&m=list'
			 + '&type=' + type;
	sub_popup('show_bind', pars);
}

// SSOログイン
function sub_sso_login(popup, target, mobile) {
	var act = 'login/SsoLogin';
	var args = 'm=login';
	args += '&target=' + target;
	args += '&mobile=' + mobile;
	
	if(popup) {
		var url = 'index.php?a=' + act + '&' + args;
		open_w2(url, 'ssologin', 'resizable=yes,scrollbars=yes,status=yes,menubar=yes,toolbar=yes,location=yes');
	} else {
		sub_redirect(act, args);
	}
}

// メッセージ表示
function show_alert_msg(msg) {
	var alerter = function() {
		alert(msg);
	}
	setTimeout(alerter, 0);
}

function sidemenu_hover(obj, isHover) {
	if(document.all) {
		var clazz = obj.className;
		if(isHover) {
			if(clazz == 'sidemenu3 sidemenu3_on') {
				obj.setAttribute('className', 'sidemenu3 sidemenu3_on_hover');
			} else if(clazz == 'sidemenu3 sidemenu3_off') {
				obj.setAttribute('className', 'sidemenu3 sidemenu3_off_hover');
			} else if(clazz == 'sidemenu4 sidemenu4_on') {
				obj.setAttribute('className', 'sidemenu4 sidemenu4_on_hover');
			} else if(clazz == 'sidemenu4 sidemenu4_off') {
				obj.setAttribute('className', 'sidemenu4 sidemenu4_off_hover');
			}
		} else {
			if(clazz == 'sidemenu3 sidemenu3_on_hover') {
				obj.setAttribute('className', 'sidemenu3 sidemenu3_on');
			} else if(clazz == 'sidemenu3 sidemenu3_off_hover') {
				obj.setAttribute('className', 'sidemenu3 sidemenu3_off');
			} else if(clazz == 'sidemenu4 sidemenu4_on_hover') {
				obj.setAttribute('className', 'sidemenu4 sidemenu4_on');
			} else if(clazz == 'sidemenu4 sidemenu4_off_hover') {
				obj.setAttribute('className', 'sidemenu4 sidemenu4_off');
			}
		}
		
	}
}

function get_chart_width() {
	// ウィンドウ幅を取得
	var width = getWindowWidth();
	if(width == 0) width = 1000;
	if(width < 400) width = 400;
	
	// メニューを表示しているならその分をひく
	if(document.mainform != undefined && document.mainform.sidemenu_display != undefined &&
		document.mainform.sidemenu_display.value != 'none')
	{
		width -= 200;
	}
	
	// チャートの幅は、その他余白を引いた分
	width -= 80;
	
	return width;
}

function get_chart_height(width, size) {
	var height = 200;
	if(size == 0) {
		// 高さは、幅の約3分の1
		height = Math.floor(width / 3.3);
		if(height < 150) height = 150;
		if(height > 220) height = 220;
	} else if(size == 1) {
		// 最大
		height = getWindowHeight();
		if(height == 0) height = 600;
		if(height < 400) height = 400;
		height -= 300;
	}
	return height;
}

var div_loading = null;
preloadImage("view/images/loading.gif");
function makeDivLoading(){

	var div = document.createElement("div");

	div.className = 'div_loading';

	div.style.height = 50 + 'px';
	div.style.width = 200 + 'px';
	
	div.appendChild(document.createTextNode("Now Loading ..."));
	div.appendChild(document.createElement("br"));
	
	var img = document.createElement("img");
	img.className = 'img_loading';
	img.setAttribute("src", 'view/images/loading.gif');
	img.setAttribute("alt", "...");
	img.setAttribute("title", "...");
	
	div.appendChild(img);
	
	return div;
}

function showLoading() {
	if(div_loading != null) return;
	
	div_loading = makeDivLoading();
	
	var wx = wy = 200;
	if(document.documentElement && document.documentElement.clientWidth != 0){
		wx=document.documentElement.clientWidth;
		wy=document.documentElement.clientHeight;
	} else	if(document.body){
		wx=document.body.clientWidth;
		wy=document.body.clientHeight;
	}	else if(document.body.innerWidth ){
		wx=screen.width;
		wy=screen.height;
	} 
	
	div_loading.style.top = (wy - 50 - parseInt(div_loading.style.height)) / 2 + document.documentElement.scrollTop + 'px';
	div_loading.style.left = (wx + 180  - parseInt(div_loading.style.width)) / 2 + document.documentElement.scrollLeft + 'px';

	document.body.appendChild(div_loading);
}

function getSelIds(frm, obj_name, noneIsAll) {
	var ids = '';
	var isAll = true;
	var elements = document.getElementsByName(obj_name);
	for(var i = 0; i < elements.length; i++) {
		if(elements[i].form != frm) continue;
		if(elements[i].checked) {
			if(ids != '') ids += ',';
			ids += elements[i].value;
		} else {
			isAll = false;
		}
	}
	
	if(noneIsAll != undefined && noneIsAll && isAll) {
		ids = '';
	}
	
	return ids;
}
//-->
