// ------------------------------------------------------------------------
//               Copyright (C) 2005 toricoco.com
//
// http://www.toricoco.com
// mailto:misaka@toricoco.com
//                                                    最終更新 2005/07/07.
// ------------------------------------------------------------------------

// ********************************************
// サイト設定の変数定義
// ********************************************
var site_num = 0;								//サイト数
var site_sales_name = new Array();				//サイトの名称
var site_sales_address = new Array();			//サイトのアドレス
var site_sales_start = new Array();				// サイト開設日（日付）
var site_sales_division = new Array();			//制作区分（新規=new, リニューアル=renew, 営業=business）
// 売上げ --------------------------------------
var site_sales_accumulation = new Array();		//累積
var site_sales_accumulation_date = new Array(); //累積の終了日付
var site_sales_NowOnYear = new Array();			//年平均（現時点）
// アクセス ------------------------------------
var site_access_accumulation = new Array();		//累積
var site_access_accumulation_date = new Array();//累積の終了日
var site_access_NowOnDay = new Array();			//一日平均（現時点）

// PC管理 --------------------------------------
var manage_pc_num = 0;							//クライアント数
var manage_pc_name = new Array();				//クライアント名
var manage_pc_number = new Array();				//クライアントの台数

// 仕事したい度---------------------------------
var now_working = 0;							//現在の状況
var working_str = new Array();					//メッセージ


// ********************************************
// 設定
// ********************************************
site_num = 2;

site_sales_name[0] = "会社１";
site_sales_address[0] = "http://";
site_sales_start[0] = new Date(2003, 2, 1);
site_sales_division[0] = "renew";
site_sales_accumulation[0] = 60000000;
site_sales_accumulation_date[0] = new Date(2004, 11, 31);
site_sales_NowOnYear[0] = 100000000;
site_access_accumulation[0] = 2000000;
site_access_accumulation_date[0] = new Date(2005, 3, 30);
site_access_NowOnDay[0] = 2000;

site_sales_name[1] = "ネットショップ";
site_sales_address[1] = "http://";
site_sales_start[1] = new Date(2004, 0 ,1);
site_sales_division[1] = "business";
site_sales_accumulation[1] = 20000000;
site_sales_accumulation_date[1] = new Date(2004, 11, 31);
site_sales_NowOnYear[1] = 10000000;
site_access_accumulation[1] = 3000000;
site_access_accumulation_date[1] = new Date(2005, 3, 30);
site_access_NowOnDay[1] = 3000;

manage_pc_num = 2;

manage_pc_name[0] = "地元企業（非公開）";
manage_pc_number[0] = 33;

manage_pc_name[1] = "専門学校（非公開）";
manage_pc_number[1] = 250;

now_working = 1;
working_str[0] = "手に余っています";
working_str[1] = "予断を許しません";
working_str[2] = "なかなか忙しいです";
working_str[3] = "気持ち忙しいです";
working_str[4] = "バランスがとれています";
working_str[5] = "もうちょっといけます";
working_str[6] = "結構いけます";
working_str[7] = "かなりいけます";
working_str[8] = "どちらかというと暇です";
working_str[9] = "暇を持て余してます";

// 現在時刻の設定
var obj_date = new Date();				// 日付オブジェクトを取得します
//
function init_meter() {
	countSales();			// 売上げカウント
	countAccess();			// アクセスカウント
	countPC();				// PC管理台数
	countWorking();			// 仕事したい度
}

//	売上げカウント
function countSales() {
	var sales_num = 0;
	for(var i=0; i <= site_num-1; i++) {
		//累積を加算
		sales_num += site_sales_accumulation[i];
		
		// カウント開始日からの日数を秒で取得
		var sales_span = (obj_date.getTime() - site_sales_accumulation_date[i].getTime()) / (1000);
		// １秒の売り上げ
		var sales_average = site_sales_NowOnYear[i] / (365*24*60*60);
		sales_num += sales_span * sales_average;
	}
	sales_num = Math.floor((sales_num)/10000);//万単位に（切り捨て）
	sales_num = FormatNumber(sales_num);
	document.getElementById('ins_sales').innerHTML = '<span id="insd_sales"><strong>' + sales_num + '</strong>万円</span>';
}

//	アクセスカウント
function countAccess() {
	var access_num = 0;
	// アクセス数を加算
	for(var i=0; i <= site_num-1; i++) {
		//累積を加算
		access_num += site_access_accumulation[i];
		
		// カウント開始日からの日数を秒で取得
		var access_span = (obj_date.getTime() - site_access_accumulation_date[i].getTime()) / (1000);
		// １秒のアクセス数
		var access_average = site_access_NowOnDay[i] / (24*60*60);
		access_num += access_span * access_average;
	}
	access_num = Math.floor(access_num);
	access_num = FormatNumber(access_num);
	document.getElementById('ins_access').innerHTML = '<span id="insd_access"><strong>' + access_num + '</strong></span>';
}
//	PC管理台数
function countPC() {
	var number = 0;
	// 台数を加算
	for(var i=0; i <= manage_pc_num-1; i++) {
		number += manage_pc_number[i];
	}
	document.getElementById('ins_pc').innerHTML = '<span id="insd_pc"><strong>' + number + '</strong>台</span>';
}
// 仕事したい度
function countWorking() {
	str_num = now_working - 1;
	document.getElementById('ins_working').innerHTML = '<span id="insd_working"><img src="http://www.toricoco.com/include/pic/meter/sigoto' + now_working + '.gif" width="70" height="20" alt="仕事したい度:' + now_working+ ' 「' +working_str[str_num]+ '」" title="仕事したい度:' + now_working+ ' 「' +working_str[str_num]+ '」" /></span>';
}

// ********************************************
// 汎用関数
// ********************************************
function FormatNumber(num) {
    var str = "" + num; // 確実に文字列型に変換する
    var p = str.indexOf("."); // 小数点の位置を0オリジンで求める。
    if (p < 0) { // 小数点が見つからなかった時
        p = str.length; // 仮想的な小数点の位置とする
    }
    var result = str.substring(p, str.length); // 小数点の桁と小数点より右側の文字列。
    for (var i = 0; i < p; i++) { // (10 ^ i) の位について
        var c = str.substring(p - 1 - i, p - 1 - i + 1); // (10 ^ i) の位のひとつの桁の数字。
        if (c < "0" || c > "9") { // 数字以外のもの(符合など)が見つかった
            result = str.substring(0, p - i) + result; // 残りを全部付加する
            break;
        }
        if (i > 0 && i % 3 == 0) { // 3 桁ごと、ただし初回は除く
            result = "," + result; // カンマを付加する
        }
        result = c + result; // 数字を一桁追加する。
    }
    return result;
}


