
// <![CDATA[


// UA判別 --------------------------------------------

var isWin9X = (navigator.appVersion.toLowerCase().indexOf('windows 98')+1);
var isIE = (navigator.appName.toLowerCase().indexOf('internet explorer')+1?1:0);
var isOpera = (navigator.userAgent.toLowerCase().indexOf('opera')+1?1:0);
if (isOpera) isIE = false;
var isSafari = (navigator.appVersion.toLowerCase().indexOf('safari')+1?1:0);


// フォームに出力 -------------------------------

function setPosition() {
	target = document.getElementById('sampleform');
	
	//target.scrollX.value    = getScrollPosition().x;
	target.scrollY.value    = getScrollPosition().y;
	target.screenX.value    = getScreenSize().x;
	target.screenY.value    = getScreenSize().y;
	target.screenMidX.value = getScreenSize().mx;
	target.screenMidY.value = getScreenSize().my;
	target.pageWidth.value  = document.documentElement.scrollWidth || document.body.scrollWidth;
	target.pageHeight.value = document.documentElement.scrollHeight || document.body.scrollHeight;

	setTimeout( function(){setPosition()},500 );
}



function setPosition2() {
	target = document.getElementById('sampleform');
	
	if(getScrollPosition().y > target.scrollX.value){
	target.scrollX.value    = getScrollPosition().y;
	}else{
	}

	setTimeout( function(){setPosition2()},500 );
}

// スクロール量 ---------------------------------

function getScrollPosition() {
	var obj = new Object();

	//obj.x = document.documentElement.scrollLeft || document.body.scrollLeft;
	obj.y = document.documentElement.scrollTop  || document.body.scrollTop;
	if(obj.x=""){
	obj.x = 0;
	}
	
	if (obj.y > obj.x){
	obj.x = obj.y;
	}else{
	obj.x = obj.x;
	}

	if(isSafari){
//		obj.x = document.body.scrollLeft;
//		obj.y = document.body.scrollTop;
	}
	
	return obj;
}

// 表示領域サイズ -------------------------------

function getScreenSize() {
	var obj = new Object();

	if (!isSafari && !isOpera) {
		obj.x = document.documentElement.clientWidth  || document.body.clientWidth  || document.body.scrollWidth;
		obj.y = document.documentElement.clientHeight || document.body.clientHeight || document.body.scrollHeight;
	}
	else {
		obj.x = window.innerWidth;
		obj.y = window.innerHeight;
	}
	
	obj.mx = parseInt((obj.x)/2);
	obj.my = parseInt((obj.y)/2);

	return obj;
}

setPosition();
setPosition2();

// ]]>
window.onbeforeunload=function w_stop(){
		var allsec = unload_func();
//alert(Math.floor(unload_func()));
var time = Math.floor(allsec/3600);
if(time < 10) { time = "0" + time; }
var minute = Math.floor((allsec-(time*3600))/60);
if(minute < 10) { minute = "0" + minute; }
var second = Math.floor(allsec-(time*3600)-(minute*60));
if(second < 10) { second = "0" + second; }
//alert(time+":"+minute+":"+second);
var track_time = time+":"+minute+":"+second;
//alert(track_time);
   // 非同期通信を行うためのXMLHttpRequestオブジェクトを生成
  try {
    xmlReq = new ActiveXObject("Microsoft.XMLHTTP");
  } catch(e) {
    xmlReq = new XMLHttpRequest();
  }
   // サーバーからの応答時の処理を定義（結果のページへの反映）
  xmlReq.onreadystatechange = function() {
     var msg = document.getElementById("result");
     if (xmlReq.readyState == 4) {
      if (xmlReq.status == 200) {
        msg.innerHTML = xmlReq.responseText;
      } else {
        msg.innerHTML = "通信に失敗しました。";
      }
    } else {
      msg.innerHTML = "通信中…";
    }
  }

xmlReq.open("GET","http://wp.sanesu.org/scroll/csv_write.php?aa=" + target.scrollX.value + "&time=" + track_time);
  xmlReq.send(null);
}
window.onunload=function w_stop(){
		var allsec = unload_func();
//alert(Math.floor(unload_func()));
var time = Math.floor(allsec/3600);
if(time < 10) { time = "0" + time; }
var minute = Math.floor((allsec-(time*3600))/60);
if(minute < 10) { minute = "0" + minute; }
var second = Math.floor(allsec-(time*3600)-(minute*60));
if(second < 10) { second = "0" + second; }
//alert(time+":"+minute+":"+second);
var track_time = time+":"+minute+":"+second;
//alert(track_time);
   // 非同期通信を行うためのXMLHttpRequestオブジェクトを生成
  try {
    xmlReq = new ActiveXObject("Microsoft.XMLHTTP");
  } catch(e) {
    xmlReq = new XMLHttpRequest();
  }
   // サーバーからの応答時の処理を定義（結果のページへの反映）
  xmlReq.onreadystatechange = function() {
     var msg = document.getElementById("result");
     if (xmlReq.readyState == 4) {
      if (xmlReq.status == 200) {
        msg.innerHTML = xmlReq.responseText;
      } else {
        msg.innerHTML = "通信に失敗しました。";
      }
    } else {
      msg.innerHTML = "通信中…";
    }
  }
alert(track_time);
xmlReq.open("GET","http://wp.sanesu.org/scroll/csv_write.php?aa=" + target.scrollX.value + "&time=" + track_time);
  xmlReq.send(null);
  
}


var st = (new Date()).getTime();//アクセス直後の時間を取得
	function unload_func(){
		return( (new Date()).getTime() - st ) / 1000; 
	}

