<?php
//conf include
include_once(dirname(__FILE__).'/inc/config.php');
if(!defined("W3A_CONF_READ")) return;

//header("Content-type: application/x-javascript; charset=".constant('W3A_PAGE_CHARSET'));
header("Content-type: application/x-javascript");
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
//header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: no-cache");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");

//W_PATH
$w_path = constant("W3A_W_PATH");

//TITLE
$w_title = '';
if(isset($_GET['send_title'])){
	$w_title = $_GET['send_title'];
}

//img_size
$img_size = '';
if(constant("W3A_COUNTER")) $img_size = (constant("W3A_COUNTER_TYPE") == 'img' ? '' : ' width="1" height="1" ');

$img_endtag = ' >';
if(defined('W3A_PAGE_DOCTYPE')){
	if(constant('W3A_PAGE_DOCTYPE') === 'XHTML'){
		$img_endtag = ' />';
	}
}

echo <<<JS
function createMoguraImg(){
var v_src = '{$w_path}';
var v_args = '?mode=img&amp;guid=on';
var v_ref = '';
var v_title = '{$w_title}';
var v_path;
var v_w, v_h;
//v_title = document.title;
if(document.getElementsByTagName('title')[0].text) v_title = document.getElementsByTagName('title')[0].text;
v_path = document.URL;
if(document.referrer.length) v_ref = document.referrer;
try{
	if(v_ref != parent.document.referrer && parent.document.referrer.length > 0){
		v_ref = parent.document.referrer;
	}
}catch(e){
};
try{
v_path = encodeURIComponent(v_path);
v_ref = encodeURIComponent(v_ref);
v_title = encodeURIComponent(v_title);
v_ref = v_ref.replace(/(%)/g,"_P_");
v_path = v_path.replace(/(%)/g,"_P_");
v_title = v_title.replace(/(%)/g,"_P_");
}catch(e){
};
try{
	var v_chrs;
	if(document.all){ // IE
		v_chrs = document.charset.toLowerCase();
	}else{ // NO IE
		v_chrs = document.characterSet.toLowerCase();
	}

	switch(v_chrs){
		case 'euc-jp':
			break;
		case 'utf-8':
			break;
		case 'iso-2202-jp':
			break;
		case 'shift-jis':
			break;
		default:
			v_title = '';
	}
}catch(e){
};

/* moniter */
v_w = screen.width;
v_h = screen.height;

v_args += '&amp;ref='+v_ref;
v_args += '&amp;path='+v_path;
v_args += '&amp;monitor='+v_w+'x'+v_h;
v_args += '&amp;title='+v_title;
v_args += '&amp;color='+(navigator.appName != "Netscape" ? screen.colorDepth : screen.pixelDepth);
v_args += '&amp;cookie='+(navigator.cookieEnabled ? 1 : 2);
v_args += '&amp;js=1';
document.write('<img src="' + v_src + v_args + '" alt="" {$img_size} {$img_endtag}');
};
createMoguraImg();
JS;
?>
