//　Macintosh           　->  MacOS
//　Windows95/98/NT/2000/XP  ->　Windows
//　UNIX                  ->　UNIX
function getOSType()
{
    var uAgent  = navigator.userAgent.toUpperCase();
    if (uAgent.indexOf("MAC") >= 0) return "MacOS";
    if (uAgent.indexOf("WIN") >= 0) return "Windows";
    if (uAgent.indexOf("X11") >= 0) return "UNIX";
    return "";
}
//　Netscape Navigator ->  Netscape
//　Internet Explorer  ->　Explorer
//　Safari  ->　Safari
//　Opera  ->　Opera
function getBrowserName()
{
    var aName  = navigator.appName.toUpperCase();
    var uName = navigator.userAgent.toUpperCase();

    if (uName.indexOf("OPERA") >= 0)  return "Opera";
    if (aName.indexOf("NETSCAPE") >= 0)  return "Netscape";
    if (aName.indexOf("MICROSOFT") >= 0) return "Explorer";
    return "";
}
function getBrowserVersion()
{
    var browser = getBrowserName();
    var version = 0;
    var s = 0;
    var e = 0;
    var appVer  = navigator.appVersion;
    var uName  = navigator.userAgent.toUpperCase();
    if (browser == "Safari")
    {
        version = eval(appVer.substring(0,3)) - 4;
    }
    if (browser == "Opera")
    {
        s = uName.indexOf("OPERA ",0) + 6;
        e = uName.indexOf(" ",s);
        version = eval(uName.substring(s,e));
    }
    if (browser == "Netscape")
    {
        s = appVer.indexOf(" ",0);
        version = eval(appVer.substring(0,s));
        if (version >= 5) version++;
    }
    if (browser == "Explorer")
    {
        appVer  = navigator.userAgent;
        s = appVer.indexOf("MSIE ",0) + 5;
        e = appVer.indexOf(";",s);
        version = eval(appVer.substring(s,e));
    }
    return version;
}
function getBrowserLANG(){
  if(document.all)
    return navigator.browserLanguage;      //IE
  else if(document.layers) 
    return navigator.language;             //N4
  else if(document.getElementById) 
    return navigator.language.substr(0,2); //N6,Moz
}
function getDisplayX(){
    return screen.width;
}
function getDisplayY(){
    return screen.height;
}
function getDisplayColors(){
    return screen.colorDepth;
}
function getCookieAsArray(name)
{
    var cookie = document.cookie;
    if (cookie == "") return [];

    var start = cookie.indexOf(name + '=');
    if (start == -1) {
        var result = [];
        var regexp = new RegExp(name + "\\[[0-9]+\\]=", "i");
        var s = 0;
        var e = 0;
        while ( (s = cookie.search(regexp)) >= 0) {
            var temp = cookie.match(regexp);
            if (temp instanceof Array) {
                temp = temp[0];
            }
            e = cookie.indexOf(';', s + temp.length);
            if (e < 0) {
                e = cookie.length;
            }
            result.push(cookie.substring(s + temp.length, e));
            cookie = cookie.substring(e, cookie.length);
        }
        return result;
    } else {
        start += name.length + 1;
        var end = cookie.indexOf(';', start);
        if (end == -1) end = cookie.length;
        return [cookie.substring(start, end)];
    }
}
function setCookie(key, val){
    document.cookie = key + "=" + escape(val) + ";expires=Fri, 31-Dec-2030 23:59:59;";
}
function getCookie(key){
    var tmp = document.cookie + ";";
    var index1 = tmp.indexOf(key, 0);
    if(index1 != -1){
        tmp = tmp.substring(index1,tmp.length);
        var index2 = tmp.indexOf("=",0) + 1;
        var index3 = tmp.indexOf(";",index2);
        return(unescape(tmp.substring(index2,index3)));
    }
    return "";
}
function getValueString(intval){
    var character = new Array("0","1","2","3","4","5","6","7","8","9","a","b","c","d","e","f");
    return character[parseInt(intval)];
}
function getFormatKeta(value , keta , sinsu){
    var string = '';
    for ( i = keta ; i > 0 ; i -- ){
        if ( value / Math.pow ( sinsu , i-1 ) < 1.0 ) string += '0';
        else string += getValueString( Math.floor( value / Math.pow ( sinsu , i-1 ) ) % sinsu );
    }
    return string;
}

function getTimeString(dateObj){
    var year = getFormatKeta(dateObj.getYear(),4,10);
    var month = getFormatKeta(dateObj.getMonth() + 1,2,10);
    var date = getFormatKeta(dateObj.getDate(),2,10);
    var hour = getFormatKeta(dateObj.getHours(),2,10);
    var minute = getFormatKeta(dateObj.getMinutes(),2,10);
    var second = getFormatKeta(dateObj.getSeconds(),2,10);
    
    var strtime = year + '-' + month + '-' + date + ' ' + hour + ':' + minute + ':' + second;
    return strtime;
}
function getDateObjFromTimeString(time_string){
    //if( time_string == null ) { return new Date(); }
    if( time_string == '' ) { return new Date(); }
    var date_time = time_string.split(' ',2);
    var dates = date_time[0].split('-',3);
    if( dates.length != 3 ) return null;
    
    if( date_time.length == 2 ){
        var times = date_time[1].split(':',3);
        if( times.length != 3 ) return null;
        return new Date( parseInt(dates[0]), parseInt(dates[1])-1, parseInt(dates[2]), parseInt(times[0]), parseInt(times[1]), parseInt(times[2]) );
    } else {
        return new Date( parseInt(dates[0]), parseInt(dates[1])-1, parseInt(dates[2]) );
    }
}
function getHexString(intval, keta){
    return getFormatKeta(intval, keta, 16);
}
function protSData( id, time_visited, last_visited, first_visited, is_hourly, disp_x, disp_y, disp_color ){
    var str='';

    var test = parseInt(getDateObjFromTimeString(last_visited).getTime() / 1000);

    str += getHexString( isNaN(time_visited) ? 0 : parseInt(time_visited) , 4 );
    str += getHexString( parseInt(getDateObjFromTimeString(last_visited).getTime() / 1000) , 16 );
    str += getHexString( parseInt(getDateObjFromTimeString(first_visited).getTime() / 1000) , 16 );
    str += getHexString( is_hourly ? 1 : 0 , 2 );
    str += getHexString( parseInt(disp_x) , 4 );
    str += getHexString( parseInt(disp_y) , 4 );
    str += getHexString( parseInt(disp_color) , 4 );
    str += getHexString( parseInt('0x'+id) , 20 );
    return str;
}


function moveAna(){
    sx = document.body.clientWidth - document.images["ana_img"].width;
    document.images["ana_img"].style.left = sx;
}
function onResizeFunc(){
    location.reload();
}
if(document.layers){
    window.captureEvents(Event.RESIZE);
    window.onresize=onResizeFunc;
}
window.onresize = onResizeFunc;


var timeAcceptInterval = 0;


var id = getCookie('super_unique'); 
if( id.length == 0 || id == null ) id = 0;


var time_visited = parseInt(getCookie('time_visited'));
if( time_visited.length == 0 || isNaN(time_visited) ) time_visited = 0;


var first_visited = getCookie('first_visited');
var DateFirstVisited = first_visited.length > 0 ? getDateObjFromTimeString(first_visited) : null;


var last_visited = getCookie('last_visited');
DateNow = new Date();
var DateLastVisited = last_visited != null && last_visited.length > 0 ? getDateObjFromTimeString(last_visited) : null;


var timeSpanLastVisited = DateLastVisited != null ? ( DateNow.getTime() - DateLastVisited.getTime() ) / 1000 : 0 ;


var is_hourly = false;
if( DateLastVisited == null || getDateObjFromTimeString("2010-08-01 06:00:00").getTime() >= DateLastVisited.getTime() ) is_hourly = true;


var isAccept = ( DateLastVisited == null || timeSpanLastVisited > timeAcceptInterval ) ? true : false ;

var ref=document.referrer;
if(ref==parent.document.URL)ref=top.document.referrer;
ref=ref.replace(/"/g,'&quot;').replace(/&/g,'&amp;').replace(/</g,'&lt;').replace(/>/g,'&gt;');

function hideAnaLayer(){
    document.getElementById("anaLayer").style.display = "none";
}

function showAnaLayer(){
    document.getElementById("anaLayer").style.display = "block";
}
if( isAccept ){
    setCookie('last_visited',getTimeString(DateNow));
    setCookie('time_visited',time_visited + 1);

    if( first_visited.length == 0 ) setCookie('first_visited',getTimeString(DateNow));

    var screenX = getDisplayX();
    var screenY = getDisplayY();
    var screenC = getDisplayColors();


    var count_dat = getCookie('count_vol');
    if(count_dat==null || count_dat==""){
        setCookie('count_vol',1280610687);
    }

    var s_uni = getCookie('super_unique');
    if(s_uni==null || s_uni==""){
    }

    var query = protSData(id, time_visited, last_visited, first_visited, is_hourly, screenX, screenY, screenC, ref);

    ref=encodeURI(ref).replace(/&/g , "%26amp;");
    var url = 'http://124.108.35.41/cnt2.php?glid='+s_uni+'&countdate='+count_dat+'&uID=hhhja44&cID=480&dTP=A&qsp='+query+'&r='+ref;


    var gif = '<a href="http://etools.jp/" target="_blank"><img src="http://124.108.35.41//image/ana.gif" id="ana_img" name="ana_img" style="position:absolute; top:0px; z-index:5; right:2px; text-align:right; border-style:none;"></a>';



    document.write('<script Language="JavaScript" src="'+url+'"></script>');



    document.write(gif);}
