var wiredminds = {

  getlist : "",

  numberOfCalls : 0,
  wm_track_url : "",
  wm_track_alt : "",

  get_GET_value:function ( get_param_name ) {
    if (!window) { return ''; }
    if (!window.location) { return ''; }
    if (!window.location.search) { return ''; }
    var search=window.location.search.substr(1);
    var assignments=search.split('&');
    for( var i=0; i<assignments.length; i++ ) {
      var assignment_splitted=assignments[i].split('=');
      var param_name=assignment_splitted[0];
      var param_value=assignment_splitted[1];
      if (param_name == get_param_name) {
        return param_value;
      }
    }
    return '';
  },

  add_to_list : function( key, value) {
    wiredminds.getlist += '&' + key + '=' + escape(value);
  },

  //Get protocol, returns protocol string
  getProto : function () {
	var proto = 'http:';
    if ( typeof (document.location) != 'undefined') {
      if ( typeof (document.location.protocol) != 'undefined') {
        if ( document.location.protocol != 'file:') {
          proto = document.location.protocol;
        }
      }
    }
	return proto;
  },

  count_URL : function (getlist) {

    proto = wiredminds.getProto();
    var WMCT_URL=proto+'//ctsde17.wiredminds.de/track/ctin.php?'+getlist;
    //alert(WMCT_URL);

    if (document.getElementById) {
    document.getElementById('counterimg').src=WMCT_URL;
    }
    else if (document.images) {
    document.images['counterimg'].src=WMCT_URL;
    }

	wiredminds.numberOfCalls++;
  },

  countpix : function (pixcode) {
    wm_pixelcode = pixcode;
    wiredminds.count();
  },

  count_flash : function (flashArgs) {
    if ( typeof(flashArgs) != 'string') { return; }
    if ( flashArgs == '') { return; }

    if ( flashArgs.substr(0,1) == '&') { flashArgs='t2=1'+flashArgs; }

    wiredminds.count_URL(flashArgs);
  },

  internalCount : function (ext) {
	myDate = new Date();
    wiredminds.getlist="t="+myDate.getTime(); // Clear/Initialize the get list.
											  // NOTE: Clearing the getlist is a must!
											  //       Otherwise subsequent calls to count
											  //       (e.g. by using onClick="") would
											  //       append their values to the old get list.

	// First the required parameters
    if ( typeof(wm_custnum) != 'undefined') {
      wiredminds.add_to_list('custnum',wm_custnum);
    } else {
      return; // no customer number given, do nothing
    }


    // auto-detect sname, if necessary
    if ( typeof(wm_sname) == 'undefined' ) {
      wm_sname = document.location.hostname;
    }
    wiredminds.add_to_list('sname',wm_sname);

    // auto-detect page name, if necessary
    if ( typeof(wm_page_name) == 'undefined' ) {
      wm_page_name_value = document.location.pathname
    } else {
      wm_page_name_value = wm_page_name;
    }
    if (typeof(ext) == 'string') {
      wm_page_name_value+='|'+ext;
    }
    wiredminds.add_to_list('pagename',wm_page_name_value);

    // auto-detect group name, if necessary
    if ( typeof(wm_group_name) == 'undefined') {
      wm_group_name = document.location.pathname.substring(0,document.location.pathname.lastIndexOf('/'));
    }
    wiredminds.add_to_list('group',wm_group_name);


    // Then the optional parameters
    // Note: The optional parameters first get collected and added
    //       afterwards to the getlist to better control their order.
    var wm_version = "3.0";
    var wm_resolution = screen.width + "x" + screen.height;
    var wm_color_depth = navigator.appName != 'Netscape' ? screen.colorDepth : screen.pixelDepth;

    var wm_plugin_list = "";
    for( var i=0; i<navigator.plugins.length; i++ ) {
      wm_plugin_list += navigator.plugins[i].name + ';';
    }

    var wm_jv = 0;
    if (navigator.javaEnabled()) { wm_jv=1; };

    var wm_js_value = 1;
    if ((typeof wm_js) != 'undefined') { wm_js_value=wm_js; }

    var wm_ref = document.referrer;
    if( typeof( top.document ) == "object" ) { wm_ref = top.document.referrer; }

    if ((typeof wm_campaign) != 'undefined') {
      wm_camp_value = wm_campaign;
    }
    if ((typeof wm_campaign_key) != 'undefined') {
      wm_camp_value = wiredminds.get_GET_value(wm_campaign_key);
    }


    if ( typeof (wm_version) != 'undefined')     { wiredminds.add_to_list('version',wm_version); }
    if ( typeof (wm_js_value) != 'undefined')    { wiredminds.add_to_list('js',wm_js_value); }
    if ( typeof (wm_jv) != 'undefined')          { wiredminds.add_to_list('jv',wm_jv); }
    if ( typeof (wm_resolution) != 'undefined')  { wiredminds.add_to_list('resolution',wm_resolution); }
    if ( typeof (wm_color_depth) != 'undefined') { wiredminds.add_to_list('color_depth',wm_color_depth); }
    if (wiredminds.numberOfCalls == 0) {
		//Only request webcounter if it is the first call (performance issues)
		if ( typeof (wm_wc) != 'undefined')          { wiredminds.add_to_list('wc',wm_wc); }
	}
    if ( typeof (wm_camp_value) != 'undefined')  { wiredminds.add_to_list('campaign',wm_camp_value); }
    if ( typeof (wm_milestone) != 'undefined')   { wiredminds.add_to_list('milestone',wm_milestone); }
    if ( typeof (wm_sales) != 'undefined')       { wiredminds.add_to_list('sales',wm_sales); }
    if ( typeof (wm_basket) != 'undefined')      { wiredminds.add_to_list('basket',wm_basket); }
    if ( typeof (wm_connspeed) != 'undefined')   { wiredminds.add_to_list('speed',wm_connspeed); }
    if ( typeof (wm_txid) != 'undefined')        { wiredminds.add_to_list('txid',wm_txid); }
    if ( typeof (wm_pixelcode) != 'undefined')   { wiredminds.add_to_list('pixel',wm_pixelcode); }
    if ( typeof (wm_ref) != 'undefined')         { wiredminds.add_to_list('referrer',wm_ref); }
    if ( typeof (wm_ud1) != 'undefined')         { wiredminds.add_to_list('ud1',wm_ud1); }
    // The plugin list always goes last, because it can become very long and is not that required.
    if ( typeof (wm_plugin_list) != 'undefined') { wiredminds.add_to_list('plugins',wm_plugin_list); }

    wiredminds.count_URL(wiredminds.getlist);
  },

  //This function is called by the counting code and sets the default parameter for wm_track_url and wm_track_alt
  count : function ( ext ) {
	  if (typeof (wm_track_url) != 'undefined') {
		  wiredminds.wm_track_url = wm_track_url;
	  } else {
		  proto = wiredminds.getProto();
		  wiredminds.wm_track_url = proto+'//www.wiredminds.de';
	  }

	  if (typeof (wm_track_alt) != 'undefined') {
		  wiredminds.wm_track_alt = wm_track_alt;
	  } else {
		  wiredminds.wm_track_alt = 'WiredMinds eMetrics tracking with WiredMinds Enterprise Edition';
	  }
	  wiredminds.internalCount( ext );
  },

  //This function is called by the counting code and sets the default parameter for wm_track_url and wm_track_alt
  counter : function ( ext ) {
	  if (typeof (wm_track_url) != 'undefined') {
		  wiredminds.wm_track_url = wm_track_url;
	  } else {
		  proto = wiredminds.getProto();
		  wiredminds.wm_track_url = proto+'//www.hottracker.de';
	  }

	  if (typeof (wm_track_alt) != 'undefined') {
		  wiredminds.wm_track_alt = wm_track_alt;
	  } else {
		  wiredminds.wm_track_alt = 'eMetrics tracking with HotTracker';
	  }
	  wiredminds.internalCount( ext );
  }

};


function trackingWM (custnum,page_name,group_name) {
    wm_custnum=custnum;
    wm_page_name=page_name;
    wm_group_name=group_name;
    wiredminds.counter();
}
