/**
 * Copyright (C) 2009 TTTech Computertechnik AG. All rights reserved
 *  Schoenbrunnerstrasse 7, A--1040 Wien, Austria. office@tttech.com
 * Registration for downloading pdfs from tttech.com
 *
 * Author: cbb
 *
 * revision
 * 2009-11-27: Initial version (cookie handling, onclick event handler, getElements-function)
 * 2009-11-30: draggable form added
 * 2009-12-01: AJAX Request added
 * 2009-12-02: compatibility issues IE
 * 2009-12-04: compatibility issues IE
 * 2009-12-17: compatibility issues IE
 * 2009-12-18: links do not have to be specified by a special css class, all pdfs are protected by the form
 * 2010-03-02: change according to mpl: only specific list of pdfs and media should be handled by the form, reintroduction of detection by css-class
 * 2010-04-28: bugfix - cookie now valid for the whole domain, avoids multiple registrations
 * 2010-05-03: bugfix - IE needs exprires-attribute in cookies, max_age is not sufficient 
 *
 *
 */
		
/**
 * global variables
 */ 		
var CONST_MAX_AGE = 31536000;
/**
 * variables for testing
 */

// cookie
var TEST_MODE_COOKIE = 0;
// event handler
var TEST_MODE_EVENT_HANDLER = 0;
// initialization
var TEST_MODE_INIT = 0;
// form test
var TEST_MODE_SHOW_FORM = 0;
// creating form
var TEST_MODE_FORM = 0;

/**
 * Classes
 */

function InfoRequest(firstName, lastName, company, country, phone, email, reqDocument) {
	this.firstName = firstName;
	this.lastName = lastName;
	this.company = company;
	this.country = country;
	this.phone = phone;
	this.email = email;
	this.reqDocument = reqDocument;
}

InfoRequest.prototype.getParameter = function(reqDoc) {
	var reqstring;	
	if (!checkCookie('formShown')) {
		reqstring =  "firstname=" + this.firstName + "&lastname=" + this.lastName + "&company=" + this.company + "&country=" + this.country + "&phone=" + this.phone + "&email=" + this.email + "&document=" + this.reqDocument;
	} else {
		var firstName = document.cookie['firstname'];
		var lastName = document.cookie['lastname'];
		var company = document.cookie['company'];
		var country = document.cookie['country'];
		var phone = document.cookie['phone'];
		var email = document.cookie['email'];
		
		this.reqDocument = reqDoc;
		reqstring = "firstname=" + firstName + "&lastname=" + lastName + "&company=" + company + "&country=" + country + "&phone=" + phone + "&email=" + email + "&document=" + reqDoc; 
	}	
	return reqstring;	
}

InfoRequest.getInstance = function(firstName, lastName, company, country, phone, email, reqDocument) {
	var firstName;
	var lastName;
	var company;	
	var country;
	var phone;
	var email;
	var reqDocument;	
	
	if	(checkCookie('formShown')) {
		firstName = firstName;
		lastName = lastName;
		company = company;	
		country = country;
		phone = phone;
		email = email;
		reqDocument = reqDocument;
	} else {
	
	var inputFields = document.getElementsByTagName("input");
	var selects = document.getElementsByTagName("select");
	
	for (var i = 0; i < inputFields.length; i++) {
		var field = inputFields[i];
		var fieldname = field.name;
		switch (fieldname) {
			case "firstname":
				firstName = field.value;
				break;
			case "lastname":
				lastName = field.value;
				break;
			case "company":
				company = field.value;		
				break;
			case "phone":
				phone = field.value;
				break;
			case "email":
				email = field.value;
				break;
			case "reqDocument":
				reqDocument = field.value;
				break;
			default:
				break;
		}
		
	}	
	
	country = document.getElementById('country').options[document.getElementById('country').selectedIndex].text;
	
	}
	return new InfoRequest(firstName, lastName, company, country, phone, email, reqDocument);
} 

/**
 * globals
 */
var form_active = 0;

/**
 * indexOf: due to missing implementation in IE this function is
 * added manually
 */
function arrayIndexOf(data, _search) {
	if (Array.indexOf) {
		return data.indexOf(_search);
	} else {
		for(var i = 0; i < data.length; i++){
			if(data[i] == (_search)){
	   		return i;
	   	}
		}
		return -1;
	}
}

/**
 * set cookie
 * this function sets a property for a given maximum age
 * 
 * Example: setCookie("name", (60*60*24)) will set a cookie property
 *          "name" for the maximum age of one day
 *
 * @param property string name of the property
 * @param max_age number max life span of the cookie
 */

function setCookie(property, max_age, infoReq) {
	if (TEST_MODE_COOKIE == 1) {
		alert("Setting cookie")	
	}	
	
	if (!checkCookie(property)) {
	
		var parts = document.domain.split(".");
		var domain = "." + parts[1] + "." + parts[2];
		var bundle = " path=/; domain=" + domain + "; max-age=" + max_age + "; expires=" + getExpiresDate(); 
		
		//alert(bundle);
		
		document.cookie = "formShown=1;" + bundle;
		document.cookie = "firstname=" + infoReq.firstName + ";" + bundle;
		document.cookie = "lastname=" + infoReq.lastName + ";" + bundle;
		document.cookie = "company=" + infoReq.company + ";" + bundle;
		document.cookie = "country=" + infoReq.country + ";" + bundle;
		document.cookie = "phone=" + infoReq.phone + ";" + bundle;
		document.cookie = "email=" + infoReq.email + ";" + bundle;		
	}
}	

function readCookie(property, reqDocument) {
	var allcookies = document.cookie;
	var firstName = document.cookie['firstname'];
	var lastName = document.cookie['lastname'];
	var company = document.cookie['company'];
	var country = document.cookie['country'];
	var phone = document.cookie['phone'];
	var email = document.cookie['email'];	 
	
	var infoReq = InfoRequest.getInstance(firstName, lastName, company, country, phone, email, reqDocument);
		
	return infoReq;	
} 

function checkCookie(property) {
	var allcookies = document.cookie;
	var pos;
	
	if (TEST_MODE_COOKIE == 1) {
		alert("Cookies: " + allcookies);
	}	
	
	if (Array.indexOf) {
		pos = arrayIndexOf(allcookies, property);
	
		if (TEST_MODE_COOKIE == 1) {
			alert("Position: " + pos);
		}
	
		if (pos > -1) {
			if (TEST_MODE_COOKIE == 1) {		
				alert("Cookie set");
			}
			return 1;
		} else {
			if (TEST_MODE_COOKIE == 1) {
				alert("Cookie not set");
			}
			return 0;
		}
	} else { // IE
		var a_all_cookies = document.cookie.split( ';' );
		var a_temp_cookie = '';
		var cookie_name = '';
		var cookie_value = '';
		var b_cookie_found = false; // set boolean t/f default f

		for ( i = 0; i < a_all_cookies.length; i++ )
		{
			// now we'll split apart each name=value pair
			a_temp_cookie = a_all_cookies[i].split( '=' );

			// and trim left/right whitespace while we're at it
			cookie_name = a_temp_cookie[0].replace(/^\s+|\s+$/g, '');
			// if the extracted name matches passed check_name
			if ( cookie_name == property )
			{
				b_cookie_found = true;
				// we need to handle case where cookie has no value but exists (no = sign, that is):
				if ( a_temp_cookie.length > 1 )
				{
					cookie_value = unescape( a_temp_cookie[1].replace(/^\s+|\s+$/g, '') );
				}
				// note that in cases where cookie is initialized but no value, null is returned
				return 1;
				break;
			}
			a_temp_cookie = null;
			cookie_name = '';
		}
		if ( !b_cookie_found )
		{
			return 0;
		}
	
	}	
}

/**
 * get expires-date
 */
function getExpiresDate() {
	var currentDate = new Date();	
	
	currentDate.setDate(currentDate.getDate() + 365);
	//alert(currentDate);
	return currentDate.toUTCString();
} 


/**
 * search for specific css-class or html-tag
 * 
 * @param classname string name of the class to search
 * @param tagname string name of the tag
 * @param root string starting point of the search within the DOM tree
 */
function getElements(classname, tagname, root) {
	if (!root) root = document;
	else if (typeof root == "string") root = document.getElementById(root);
	
	if (!tagname) tagname = "*";
	
	var all = root.getElementsByTagName(tagname);	
	
	if (!classname) return all;
	
	var elements = [];
	for (var i = 0; i < all.length; i++) {
		var element = all[i];
		if (isMember(element, classname)) {
			elements.push(element);
		}	
	}
	
	return elements;
	
	// nested function
	function isMember(element, classname) {
		var classes = element.className;
		
		if (!classes) return false;					
		if (classes == classname) return true;
			
		var whitespace = /\s+/;
		if (!whitespace.test(classes)) return false;
		
		var c = classes.split(whitespace);
		for (var i; i < c.length; i++) {
			if (c[i] == classname) return true;	
		}
		
		return false;
	}
}

/**
 * function to find all links to pdf files
 */
function getLinksToPdf() {
	var elms = document.getElementsByTagName("a");
	var pattern = /.pdf$/i;
	var linksToPdf = new Array();
	
	for (var i=0; i<elms.length; i++) {
		if (elms[i].getAttribute("href")) {
			if(elms[i].getAttribute("href").match(pattern)) linksToPdf.push(elms[i]);
		}	
	}
	
	return linksToPdf;
}

/**
 * function to get all links marked with the css class tttech_dl_link 
 */
function getLinksToMarkedContent(cssClass) {
	var linksToMarkedContent = getElements(cssClass, 'a');
	
	if (linksToMarkedContent == false) {
		return new Array();
	} else {
		return linksToMarkedContent;
	}	
}

/**
 * this function adds an onclick handler to all given elements
 *
 * @param elements array array holding DOM-nodes
 */
function addOnClickHandler(elms) {
	
	if (window.addEventListener) { // DOM-Compliant
		for (var i = 0; i < elms.length; i++) {
			elms[i].addEventListener('click', showRegistrationForm, false);
		
			if (TEST_MODE_EVENT_HANDLER == 1) {
				alert("Event FF handler added.");
			}
		}
	} else if (document.attachEvent) { // IE 5 and later
		for (var i = 0; i < elms.length; i++) {
			elms[i].attachEvent("onclick", showRegistrationForm);
			
			if (TEST_MODE_EVENT_HANDLER == 1) {
				alert("Event IE handler added.");
			}
		}	
	} else {
		if (TEST_MODE_EVENT_HANDLER == 1) {
			alert("Event handler could not be added.");	
		}		
	}
}

/**
 * shows the registration-form
 *
 */
function showRegistrationForm(event) {
	
	if (TEST_MODE_SHOW_FORM == 1) {
		alert("showRegistrationForm called");	
	}	
		
	var url;

	if (event.currentTarget) { // Firefox
		url = event.currentTarget;
	} else { // IE
		url = event.srcElement.parentNode.href;
	}
	
	if (!checkCookie("formShown")) {
		// prevent following the link
			
		if(event.preventDefault) { // Firefox		
			event.preventDefault();
		} else { // IE
			event.returnValue = false;
		}
		
		if (!form_active) {	
			openForm(url);
			form_active = 1;
		}		
	} else {
		if(event.preventDefault) { // Firefox		
			event.preventDefault();
		} else { // IE
			event.returnValue = false;
		}
		
		var infoReq = readCookie("showForm", url);
		
		if (TEST_MODE_SHOW_FORM == 1) {
			alert("Cookie set, sending data");	
		}
		
		doXMLHTTPRequest(url);		
	}
}

/**
 * creates the registration form
 */
function openForm(url) {
	if (TEST_MODE_FORM == 1) {
		alert("Creating form");	
	}	
	
	// get the dimensions of the browser window
	var dim = getWindowSize();
	var pos = getScrollPosition();
	// first create a new form

	// form container	
	var container = document.createElement("div");
	// add a css class	

	// move to css sheet later
	container.style.visibility = "hidden";
	container.style.border = "1px solid black";
	container.style.width = "180px";
	container.style.height = "460px";
	container.style.position = "absolute";
	container.style.left = (dim.width/2 - 180/2) + "px";
	container.style.top = (dim.height/2 - 340/2) + pos.y + "px";
	container.style.background = "URL(/fileadmin/tttech_dl_registration/images/form_bg.png)";
	
	container.style.padding = "10px";
	container.style.zIndex = 10;
		 
	container.id = "tttech_dl_container";	
		
	// closing div
	
	var closeDiv = document.createElement("div");
	closeDiv.style.cursor = "default";
	closeDiv.style.color = "White";
	var closingCross = document.createTextNode("X");	
	
	if (window.addEventListener) { // DOM-Compliant
		closeDiv.addEventListener('mouseover', function() { this.style.color = "Black";}, false);
	} else if (document.attachEvent) { // IE 5 and later
		closeDiv.attachEvent('mouseover', function() { this.style.color = "Black";});
	}	
	
	if (window.addEventListener) { // DOM-Compliant
		closeDiv.addEventListener('mouseout', function() { this.style.color = "White";}, false);
	} else if (document.attachEvent) { // IE 5 and later
		closeDiv.attachEvent('mouseout', function() { this.style.color = "White";});
	}
	
	var sp = document.createElement("span");
	sp.onclick = closeForm;
	sp.appendChild(closingCross);
	closeDiv.appendChild(sp);
	closeDiv.style.width = "180px";
	closeDiv.style.height = "5px";	
	closeDiv.style.textAlign = "right";
		
	// additional text
	var addText = document.createElement("div");
	addText.style.marginTop = "30px";
	var addTextNode = document.createTextNode('Please fill in this form to get access to the document. Thank you. In case you wish to receive additional information, send an e-mail to products@tttech.com.');		
	addText.appendChild(addTextNode);
	
	// create form
	
	var form = document.createElement("form");
	form.setAttribute("name", "registration");

	form.className = "tttech_dl_form";
	
	// surename
	var firstname = createTextInputField("First Name*", "firstname", "tttech_dl_inputfield");
	firstname.style.marginTop = "25px";
	
	// last name
	var lastname = createTextInputField("Last Name*", "lastname", "tttech_dl_inputfield");
		
	// company
	var company = createTextInputField("Company*", "company", "tttech_dl_inputfield");
	
	// country
	countries = "Afghanistan§Albania§Algeria§American Samoa§Andorra§Angola§Anguilla§Antarctica§Antigua and Barbuda§Argentina§Armenia§Aruba§Australia§Austria§Azerbaijan§Bahamas§Bahrain§Bangladesh§Barbados§Belarus§Belgium§Belize§Benin§Bermuda§Bhutan§Bolivia§Bosnia and Herzegovina§Botswana§Bouvet Island§Brazil§British Indian Ocean territory§Brunei Darussalam§Bulgaria§Burkina Faso§Burundi§Cambodia§Cameroon§Canada§Cape Verde§Cayman Islands§Central African Republic§Chad§Chile§China§Christmas Island§Cocos (Keeling) Islands§Colombia§Comoros§Congo§Congo, Democratic Republic§Cook Islands§Costa Rica§Cote d'Ivoire (Ivory Coast)§Croatia (Hrvatska)§Cuba§Cyprus§Czech Republic§Denmark§Djibouti§Dominica§Dominican Republic§East Timor§Ecuador§Egypt§El Salvador§Equatorial Guinea§Eritrea§Estonia§Ethiopia§Falkland Islands§Faroe Islands§Fiji§Finland§France§French Guiana§French Polynesia§French Southern Territories§Gabon§Gambia§Georgia§Germany§Ghana§Gibraltar§Greece§Greenland§Grenada§Guadeloupe§Guam§Guatemala§Guinea§Guinea-Bissau§Guyana§Haiti§Heard and McDonald Islands§Honduras§Hong Kong§Hungary§Iceland§India§Indonesia§Iran§Iraq§Ireland§Israel§Italy§Jamaica§Japan§Jordan§Kazakhstan§Kenya§Kiribati§Korea (north)§Korea (south)§Kuwait§Kyrgyzstan§Lao People's Democratic Republic§Latvia§Lebanon§Lesotho§Liberia§Libyan Arab Jamahiriya§Liechtenstein§Lithuania§Luxembourg§Macao§Macedonia, Former Yugoslav Republic Of§Madagascar§Malawi§Malaysia§Maldives§Mali§Malta§Marshall Islands§Martinique§Mauritania§Mauritius§Mayotte§Mexico§Micronesia§Moldova§Monaco§Mongolia§Montenegro§Montserrat§Morocco§Mozambique§Myanmar§Namibia§Nauru§Nepal§Netherlands§Netherlands Antilles§New Caledonia§New Zealand§Nicaragua§Niger§Nigeria§Niue§Norfolk Island§Northern Mariana Islands§Norway§Oman§Pakistan§Palau§Palestinian Territories§Panama§Papua New Guinea§Paraguay§Peru§Philippines§Pitcairn§Poland§Portugal§Puerto Rico§Qatar§R&eacute;union§Romania§Russian Federation§Rwanda§Saint Helena§Saint Kitts and Nevis§Saint Lucia§Saint Pierre and Miquelon§Saint Vincent and the Grenadines§Samoa§San Marino§Sao Tome and Principe§Saudi Arabia§Senegal§Serbia§Seychelles§Sierra Leone§Singapore§Slovakia§Slovenia§Solomon Islands§Somalia§South Africa§South Georgia and the South Sandwich Islands§Spain§Sri Lanka§Sudan§Suriname§Svalbard and Jan Mayen Islands§Swaziland§Sweden§Switzerland§Syria§Taiwan§Tajikistan§Tanzania§Thailand§Togo§Tokelau§Tonga§Trinidad and Tobago§Tunisia§Turkey§Turkmenistan§Turks and Caicos Islands§Tuvalu§Uganda§Ukraine§United Arab Emirates§United Kingdom§United States of America§Uruguay§Uzbekistan§Vanuatu§Vatican City§Venezuela§Vietnam§Virgin Islands (British)§Virgin Islands (US)§Wallis and Futuna Islands§Western Sahara§Yemen§Zaire§Zambia§Zimbabwe";
	var country = createSelectWithOptions("Country*", "country", countries, "tttech_dl_inputfield");
	
	// phone
	var phone = createTextInputField("Phone", "phone", "tttech_dl_inputfield");
	
	// email
	var email = createTextInputField("Email*", "email", "tttech_dl_inputfield");
	
	// add a hidden field for the requested document
	var requestedDoc = document.createElement("input");
	requestedDoc.setAttribute("type", "hidden");
	requestedDoc.setAttribute("name", "reqDocument");
	requestedDoc.setAttribute("value", url);
	
	
	
	// add submit button
	var submitBtn = document.createElement("input");
	submitBtn.setAttribute("type", "button");
	submitBtn.setAttribute("value", "Submit");
	submitBtn.onclick = submitData;
	
	// additional information	
	
	var textContainer = document.createElement("span");
	textContainer.style.marginLeft = "10px";
	var mandatoryText = document.createTextNode("* mandatory");
	textContainer.appendChild(mandatoryText);
	
	// add closing element
	container.appendChild(closeDiv);	
	
	container.appendChild(addText);
	
	// add fields
	form.appendChild(firstname);
	form.appendChild(lastname);
	form.appendChild(company);
	form.appendChild(country);
	form.appendChild(email);
	form.appendChild(phone);	
	form.appendChild(requestedDoc);
	
	form.appendChild(submitBtn);
	form.appendChild(textContainer);
	
	// add form
	container.appendChild(form);	
	
	// add container	
	if (document.body) { // IE
		document.body.appendChild(container);
	} else {
		document.documentElement.appendChild(container);
	}
	if (TEST_MODE_FORM == 1) {
		alert("documentElement: " + document.getElementById("tttech_dl_container").id);	
	}	
	
	
	// set visible
	container.style.visibility = "visible";
	
   // make it dragable only in non ie browsers
/*
   var browser = navigator.appName;
   
   if (browser != "Microsoft Internet Explorer") {
		new Draggable("tttech_dl_container");
	}	
*/	
}

/**
 * closes the form
 */
function closeForm() {
	// XXX alert("Closing form");
	var form = document.getElementById("tttech_dl_container");
	var p = form.parentNode;
	p.removeChild(form);
	form_active = 0;
		
}

function submitData() {
	doXMLHTTPRequest('');	
}

/**
 * loads the document
 */
function loadDocument(infoReq) {
	window.open(infoReq.reqDocument);
}

/**
 * helper function to add a new textfield
 * returns a <p> containing the input field
 *
 * @param text caption for the input field
 * @param fieldname name of the input field
 * @param css_class css class of the input field
 */
function createTextInputField(text, fieldname, css_class) {
	var paragraph = document.createElement("div");
	paragraph.className = css_class;
	
	var caption = document.createTextNode(text + ": ");	
	
	var field = document.createElement("input");
	field.setAttribute("type", "text"); 
	field.setAttribute("name", fieldname)

	paragraph.appendChild(caption);
	paragraph.appendChild(field);
 
	return paragraph;
}

function createSelectWithOptions(text, fieldname, options, css_class) {
	var paragraph = document.createElement("div");
	paragraph.className = css_class;
	
	var caption = document.createTextNode(text + ": ");	
	
	var field = document.createElement("select");
	field.setAttribute("name", fieldname);
	field.setAttribute("id", fieldname);
	field.style.width = "160px";

	paragraph.appendChild(caption);
	paragraph.appendChild(field);

	 
	var c_arr;	
	c_arr = options.split('§');
	
	var option;
	var text;
	option = document.createElement("option");
	option.setAttribute("selected","");	
	field.appendChild(option);
	
	for (var i=0; i < c_arr.length; i++) {
		option = document.createElement("option");
		text = document.createTextNode(c_arr[i]);
		option.appendChild(text);
		field.appendChild(option);	
	} 
 
	return paragraph;	
}

/**
 * this function is responsible for the XMLHTTP-Request which delivers
 * all entered User-Data to the server
 *
 * server answer indicates if the notification was successful or not
 * as a result, the pdf is loaded in a seperate window 
 *
 */
function doXMLHTTPRequest(reqDoc) {
	var target_url = "http://" + document.domain + "/fileadmin/tttech_dl_registration/notification.php";
	
	var infoReq = InfoRequest.getInstance();	
	
	var params = infoReq.getParameter(reqDoc);		
	
	// check input field
	if (checkFormFields(infoReq)) {
			
		new Ajax.Request(target_url, {
			method: 'get',
			parameters: params,
			onSuccess: function(transport) {
				loadDocument(infoReq);			
				closeForm();
				setCookie("formShown", CONST_MAX_AGE, infoReq);
			
			},
			onFailure: function(transport) {
				//alert("Transmission failed.");
				// Load document even if transmission failed
				loadDocument(infoReq);			
				closeForm();
			}
		});
	
	} else {	
		// do nothing
	}					
}


/**
 * check the input fields of the form
 */
function checkFormFields(infoReq) {
	var text = '';
	var submit = true;
	if (infoReq.firstName == '') {
		text = text + "First Name is required\n";
		submit = false;
	}
	if (infoReq.lastName == '') {
		text = text + "Last Name is required\n";
		submit = false;
	}
	if (infoReq.company == '') {
		text = text + "Company is required\n";
		submit = false;
	}
	if (infoReq.country == '') {
		text = text + "Country is required\n";
		submit = false;
	}	
	if (infoReq.email == '') {	
		text = text + "Email Address is required\n";
		submit = false;			
	} else if(infoReq.email != null) {
		validRegExp = /^[^@]+@[^@]+.[a-z]{2,}$/i;
		if (infoReq.email.search(validRegExp) == -1) {
			text = text + "Email Address is not correct\n";
			submit = false;
		}
	}
	
	if (!submit) alert(text);
	return submit;
}

/**
 *
 */
function getWindowSize() {
	var dim = {'width': 0, 'height': 0 };

	if( typeof( window.innerWidth ) == 'number' ) {
		//Non-IE
		dim.width = window.innerWidth;
		dim.height = window.innerHeight;
	} else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
		//IE 6+ in 'standards compliant mode'
		dim.width = document.documentElement.clientWidth;
		dim.height = document.documentElement.clientHeight;
	} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
		//IE 4 compatible
		dim.width = document.body.clientWidth;
		dim.height = document.body.clientHeight;
	}

	return dim;	
}

function getScrollPosition() {
	var pos = {'x': 0, 'y': 0 };	
	
	
	if( typeof( window.pageYOffset ) == 'number' ) {
		//Netscape compliant
		pos.y = window.pageYOffset;
		pos.x = window.pageXOffset;
	} else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
		//DOM compliant
		pos.y = document.body.scrollTop;
		pos.x = document.body.scrollLeft;
	} else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
		//IE6 standards compliant mode
		pos.y = document.documentElement.scrollTop;
		pos.x = document.documentElement.scrollLeft;
	}
	return pos;
}

/**
 * initialize the registration system
 *
 * called by onload event 
 */
function tttech_dl_initialize() {
	//alert("Test");
	var elms = getLinksToMarkedContent('tttech_dl_mark'); 
	addOnClickHandler(elms);
	if (TEST_MODE_INIT == 1) {
		alert("Initialized");
	}	
}
 
/**
 * go
 */


