﻿
function createTrackingDeeplink(theAffiliLink, deeplink) {
	return theAffiliLink + escape(deeplink);
}

function myDate() {
	var d, s = "";
	d = new Date();
	s += right("00" + d.getYear(), 2);
	s += right("00" + (d.getMonth() + 1), 2);
	s += right("00" + d.getDate(), 2);
	return (s);
}

function mySubIDparamFull() {
	return "&subID=" + escape(subIDrootChunk().replace(" ", "")) + "_" + myDate();
}

function mySubIDparam(rootChunk) {
	return "&subID=" + prepareTodaySubID(rootChunk);
}

function prepareTodaySubID(rootChunk) {
	return escape(rootChunk.replace(" ", "")) + "_" + myDate();
}

function subIDrootChunk() {
	return "betreuungsinfo";
}

function right(theString, theLength) {
	var actLength = theString.length;
	if (actLength != -1) {
		theString = theString.substr(actLength - theLength);
	}
	return theString;
}

function PageQuery(q) {
	if (q.length > 1) this.q = q.substring(1, q.length);
	else this.q = null;
	this.keyValuePairs = new Array();
	if (q) {
		for (var i = 0; i < this.q.split("&").length; i++) {
			this.keyValuePairs[i] = this.q.split("&")[i];
		}
	}
	this.getKeyValuePairs = function() { return this.keyValuePairs; }
	this.getValue = function(s) {
		for (var j = 0; j < this.keyValuePairs.length; j++) {
			if (this.keyValuePairs[j].split("=")[0] == s)
				return this.keyValuePairs[j].split("=")[1];
		}
		return false;
	}
	this.getParameters = function() {
		var a = new Array(this.getLength());
		for (var j = 0; j < this.keyValuePairs.length; j++) {
			a[j] = this.keyValuePairs[j].split("=")[0];
		}
		return a;
	}
	this.getLength = function() { return this.keyValuePairs.length; }
}
function queryString(key) {
	var page = new PageQuery(window.location.search);
	return unescape(page.getValue(key));
}

function eBaySearchString() {
	//ebq = Query, ebf = friendly 
	var ebq = queryString("ebq");
	var ebf = queryString("ebf");
	if (ebq == "false") {
		if (ebf == "false") {
			ebq = "dvd%20film%0b-elektronik%0b-lcd%0b-tft";
		}
		else {
			ebq = escape(ebf);
		}
	}
	return ebq;
}

function eBayFriendlyString() {
	//ebq = Query, ebf = friendly 
	var ebf = queryString("ebf");
	var ebq = queryString("ebq");
	if (ebf == "false") {
		if (ebq == "false") {
			ebf = "Gute Filme";
		}
		else {
			ebf = ebq;
		}
	}
	return ebf;
}

// JSONscriptRequest -- a simple class for accessing Yahoo! Web Services
// using dynamically generated script tags and JSON
//
// Author: Jason Levitt
// Date: December 7th, 2005
//
// A SECURITY WARNING FROM DOUGLAS CROCKFORD:
// "The dynamic <script> tag hack suffers from a problem. It allows a page 
// to access data from any server in the web, which is really useful. 
// Unfortunately, the data is returned in the form of a script. That script 
// can deliver the data, but it runs with the same authority as scripts on 
// the base page, so it is able to steal cookies or misuse the authorization 
// of the user with the server. A rogue script can do destructive things to 
// the relationship between the user and the base server."
//
// So, be extremely cautious in your use of this script.
//

// Constructor -- pass a REST request URL to the constructor
//
function JSONscriptRequest(fullUrl) {
	// REST request path
	this.fullUrl = fullUrl;
	// Keep IE from caching requests
	this.noCacheIE = '&noCacheIE=' + (new Date()).getTime();
	// Get the DOM location to put the script tag
	this.headLoc = document.getElementsByTagName("head").item(0);
	// Generate a unique script tag id
	this.scriptId = 'JscriptId' + JSONscriptRequest.scriptCounter++;
}

// Static script ID counter
JSONscriptRequest.scriptCounter = 1;

// buildScriptTag method
//
JSONscriptRequest.prototype.buildScriptTag = function() {
	// Create the script tag
	this.scriptObj = document.createElement("script");
	// Add script object attributes
	this.scriptObj.setAttribute("type", "text/javascript");
	this.scriptObj.setAttribute("charset", "utf-8");
	this.scriptObj.setAttribute("src", this.fullUrl + this.noCacheIE);
	this.scriptObj.setAttribute("id", this.scriptId);
}

// removeScriptTag method
// 
JSONscriptRequest.prototype.removeScriptTag = function() {
	// Destroy the script tag
	this.headLoc.removeChild(this.scriptObj);
}
// addScriptTag method
//
JSONscriptRequest.prototype.addScriptTag = function() {
	// Create the script tag
	this.headLoc.appendChild(this.scriptObj);
}

//Timer
var Timer = function() {
	// Property: Frequency of elapse event of the timer in millisecond
	this.Interval = 1000;

	// Property: Whether the timer is enable or not
	this.Enable = new Boolean(false);

	// Event: Timer tick
	this.Tick;

	// Member variable: Hold interval id of the timer
	var timerId = 0;

	// Member variable: Hold instance of this class
	var thisObject;

	// Function: Start the timer
	this.Start = function() {
		this.Enable = new Boolean(true);

		thisObject = this;
		if (thisObject.Enable) {
			thisObject.timerId = setInterval(
            function() {
            	thisObject.Tick();
            }, thisObject.Interval);
		}
	};

	// Function: Stops the timer
	this.Stop = function() {
		thisObject.Enable = new Boolean(false);
		clearInterval(thisObject.timerId);
	};

};
