// JavaScript Document

function screen_res()
{
	return (window.screen.width + " x " + window.screen.height);
}

// Client Windows Resolution
function window_res()
{
	var clres;

    if (document.all)
        clres = document.body.clientWidth + " x " + document.body.clientHeight;
    else if (document.layers)
        clres = window.innerWidth + " x " + window.innerHeight
    else
        clres = "0";

    return (clres);
}

// BROWSER NAME VARIABLE
function browser_name ()
{
    return (navigator.appName);
}

// APPLICATION VERSION VARIABLE
function application_version ()
{
    return (navigator.appVersion);
}

// USER AGENT VARIABLE
function user_agent ()
{
    return (navigator.userAgent);
}

// USER LANGUAGE
function language ()
{
    if ( typeof ( navigator.userLanguage ) == "string" )
        return ( navigator.userLanguage );
    else if ( typeof ( navigator.language ) == "string" )
        return ( navigator.language );

    return ("");
}

// USER PLATFORM
function platform ()
{
    if ( typeof ( navigator.platform ) == "string" )
        return ( navigator.platform );

    return ("");
}

// DOCUMENT REFERRER
function referrer ()
{
    if ( self == top )
        return ( document.referrer )
    else
        return ( parent.document.referrer );
}

// JAVA ENABLED
function java_enabled ()
{
    var java_enabled;

	if (navigator.javaEnabled())    // PRESUME N2 N3 E3
        java_enabled = "Yes";
    else
        java_enabled = "No";

    return (java_enabled);
}

// Encodierung der Stats
function rawurlencode (str) { 
    len = str.length; 
    res = new String(); 
    charOrd = new Number(); 
     
    for (i = 0; i < len; i++) { 
        charOrd = str.charCodeAt(i); 
        if ((charOrd >= 65 && charOrd <= 90) || (charOrd >= 97 && charOrd <= 122) || (charOrd >= 48 && charOrd <= 57) || (charOrd == 33) || (charOrd == 36) || (charOrd == 95)) { 
            // this is alphanumeric or $-_.+!*'(), which according to RFC1738 we don't escape 
            res += str.charAt(i); 

        } 
        else { 
            res += '%'; 
            if (charOrd > 255) res += 'u'; 
            hexValStr = charOrd.toString(16); 
            if ((hexValStr.length) % 2 == 1) hexValStr = '0' + hexValStr; 
            res += hexValStr; 
        } 
    } 

    return res; 
}

// Auf Cookies testen
function cookies_enabled()
{
	var cookiecheck;
	
	cookiestring = "chkcookie=1;EXPIRES=Sunday, 03-Apr-11 23:59:59 GMT;" 
	document.cookie = cookiestring; 
	if (document.cookie) {
		cookiestring = "test=1;EXPIRES=Wednesday, 04-Apr-01 03:09:32 GMT;" 
		document.cookie = cookiestring;
		cookiecheck = "Yes";
	} else {
		cookiecheck = "No";
	}
	return (cookiecheck);
}

// Statistik im Link aufbereiten
function urlcallkitcstats(custprop)
{
	var querystr;
	
	querystr = "http://www.kirsa.de/kitcstats/kitcstats.php?";
	querystr = querystr + "browsername=" + rawurlencode(browser_name());
	querystr = querystr + "&useragent=" + rawurlencode(user_agent());
	querystr = querystr + "&lang=" + rawurlencode(language());
	querystr = querystr + "&os=" + rawurlencode(platform());
	querystr = querystr + "&java=" + rawurlencode(java_enabled());
	querystr = querystr + "&doccookies=" + rawurlencode(cookies_enabled());
	querystr = querystr + "&scrres=" + rawurlencode(screen_res());
	querystr = querystr + "&brres=" + rawurlencode(window_res());
	querystr = querystr + "&ref=" + rawurlencode(referrer());
	querystr = querystr + "&lochref=" + rawurlencode(location.href);
	querystr = querystr + "&custprop=" + rawurlencode(custprop);
	
	return (querystr);
}