
function loadCookie(arg){
   if(arg){
      cookieData = document.cookie + ";";
      startPoint1 = cookieData.indexOf(arg);
      startPoint2 = cookieData.indexOf("=",startPoint1);
      endPoint = cookieData.indexOf(";",startPoint1);
      if(startPoint2 < endPoint && startPoint1 > -1){
         cookieData = cookieData.substring(eval(startPoint2 + 1),endPoint);
         cookieData = cookieData;
         return cookieData
      }
   }
   return false
}

window.onunload = function(){
	var time	= ( new Date - _wmStart );
	_wmArgObj['mode'] = "stay";
	_wmArgObj['stay'] = time;

	_wmrgcookie( time );
}

function _wmReadJsp( _wmArgStr ){
//alert( "http:\/\/" + _wmHost + "\/alog\/log_reg.php?param=1&" + _wmArgStr + "" );
	document.write("<script type='text\/javascript' src='http:\/\/" + _wmHost + "\/alog\/log_reg.php?param=1&" + _wmArgStr +"'><\/script>");
}

function _wmgetArgStr( ) {
	var _wmArg = "";
	for(_wmKey in _wmArgObj){
	   _wmArg = _wmArg + '&' + _wmKey + '=' + _wmArgObj[_wmKey] ;
	}
	return _wmArg;
}

function _wmloging(  ){
	_wmArgObj['mode']  = "loging";
	var _wmloArgStr = _wmgetArgStr( );
	_wmReadJsp( _wmloArgStr );
}

function _wmstay( time , regday ){
	_wmArgObj['mode']   = "stay";
	_wmArgObj['stay']   = time;
	_wmArgObj['regday'] = regday;
//alert( "r:" + regday );

	var _wmloArgStr = _wmgetArgStr( );
	_wmReadJsp( _wmloArgStr );
}

function _wmrgcookie( time ){
	var _wmstay=new Date();
    var local="";
	if( time == 0 ){
		_wmstay.setYear(_wmstay.getYear() - 1);
	} else {
		_wmstay.setTime(_wmstay.getTime()+1000*60*60*24);
		
		var _wmyear    = _wmstay.getFullYear();
		var _wmmonth   = _wmstay.getMonth();
		var _wmdate    = _wmstay.getDate();
		var _wmhours   = _wmstay.getHours();
		var _wmminutes = _wmstay.getMinutes();
		var _wmseconds = _wmstay.getSeconds();

		local = _wmyear + "-" + ( _wmmonth + 1 ) + "-" + ( _wmdate - 1 ) + " " ;
		local = local + _wmhours + ":" + _wmminutes + ":" + _wmseconds + "" ;

	}
	document.cookie = "staytime=" + time + "; expires=" + _wmstay.toGMTString();
	document.cookie = "stayday=" + local + "; expires=" + _wmstay.toGMTString();
}

var _wmStart  = new Date;
var _wmArgObj = new Object;

_wmArgObj['ref']   = escape(document.referrer);
_wmArgObj['url']   = escape(window.location);
_wmArgObj['page']  = escape(window.location.href);
_wmArgObj['host']  = escape(window.location.hostname);
_wmArgObj['title'] = encodeURI(document.title);

var _wmHost = window.location.hostname;

_wmloging( );

if( loadCookie("staytime") != false ) {
	_wmstay( loadCookie("staytime") , loadCookie("stayday") );
	_wmrgcookie( 0 );
}
