﻿	function createAjaxObjectTPPLogin(){
		var aoTppLogin;
		var browser = navigator.appName;
		if (browser == "Microsoft Internet Explorer"){
			aoTppLogin = new ActiveXObject("Microsoft.XMLHTTP");
			}
		else{
			aoTppLogin = new XMLHttpRequest(); 
			}
			return aoTppLogin;
	}
	
	var httpTPPLogin = createAjaxObjectTPPLogin();
	var tURL="";
	setLikeIt=0;
	
	
	function loginWindowTPP(tURLx){
		tURL=tURLx;
		openCurtain();
		document.getElementById("divTPPLogin").style.display="block";
		
		
	}
	
	function loginAndLikeThis(siteReferer,contentDiv,siteTitle,siteCMD){
		likeSiteReferer=siteReferer;
		likeContentDiv=contentDiv;
		likeSiteTitle=siteTitle;
		likeSiteCMD=siteCMD;
		setLikeIt=1;
		loginWindowTPP();
	}
	
	
	
	function tppLoginCross(un,pw){
		/*
		loginLink='http://www.trenchless-people.de/index.cfm?cmd=l&menuID=0&subcmd=login&benutzername=' + un + '&passwort=' + pw;
		xLogin=window.open(loginLink,'xLoginW','toolbar=no,status=no,menubar=no,scrollbars=no,resizable=no,left=10, top=10, width=50, height=50');
		xLogin.close();
		*/
		try{
			loginLink='http://www.trenchless-people.de/communityFiles/xLogin.cfm?cmd=l&menuID=0&subcmd=login&benutzername=' + un + '&passwort=' + pw;
			xLoginIFrame=document.getElementById("xLogin");
			xLoginIFrame.src=loginLink;
			
		}
		catch(e){alert(e);}
	}
	function tppLogoutCross(){
		/*
		loginLink='http://www.trenchless-people.de/index.cfm?cmd=l&menuID=0&subcmd=login&benutzername=' + un + '&passwort=' + pw;
		xLogin=window.open(loginLink,'xLoginW','toolbar=no,status=no,menubar=no,scrollbars=no,resizable=no,left=10, top=10, width=50, height=50');
		xLogin.close();
		*/
		try{
			logoutLink='http://www.trenchless-people.de/communityFiles/xLogin.cfm?cmd=l&menuID=0&subcmd=logout';
			xLoginIFrame=document.getElementById("xLogin");
			xLoginIFrame.src=logoutLink;
		}
		catch(e){alert(e);}
	}
		
	function tppCheckLogin(wp){
		username=document.getElementById("tppLoginName").value;
		password=document.getElementById("tppLoginPassword").value;
		httpTPPLogin.open('get', '/ajax/tppCheckLogin.cfm?u=' + username + "&p=" + password);
		httpTPPLogin.onreadystatechange = tppCheckLoginAction;
		httpTPPLogin.send(null);
	}
	function tppCheckLoginAction(){
		if (httpTPPLogin.readyState == 4){
			try{
				var response= httpTPPLogin.responseText;
				var update = new Array();
				if (response.indexOf('|' != -1)){
					update = response.split('|');
					//alert (update[0]);
					if (update[0] == 1){
						//document.getElementById("tppLoginInfo").innerHTML="Login OK";
						closeTPPLoginWindow();
						//storedTppLoginContent=tppLoginContent.innerHTML;
						//tppLoginContent.innerHTML="Click <a href='javascript:tppLogout();'>here</a> to logout...";
						document.getElementById("tppLoginPassword").text="";
						document.getElementById("tppLoginPassword").value="";
						document.getElementById("divLoginContent").style.display="none";
						document.getElementById("divLogoutContent").style.display="block";
						
						communityUserLoggedIn=1;

						tppLoginCross(username,password);
						if(setLikeIt){
							iLikeThis(likeSiteReferer,likeContentDiv,likeSiteTitle,likeSiteCMD);					
						}
						else{
							moveToComment();	
						}
						
						/*
						if (setLikeIt){
							iLikeThis(siteReferer,contentDiv,siteTitle,siteCMD);	
						}
						*/

						/*
						if(tURL != ""){
							location.href="/index.cfm?" + tURL;
						}
						else{
						
							try{
								document.getElementById("newstickerCommentArea").style.display="block";
							}
							catch(e){}
							try{
								document.getElementById("divTppEinloggenZumKommentieren").style.display="none";
							}
							catch(e){}
							moveToComment();
												
												
						}
						try{moveToComment();}
						catch(e){};
						
						try{
							document.getElementById("linkKommentierenLogin").style.display="none";
							document.getElementById("linkKommentierenMT").style.display="block";
							
						}
						catch(e){};
						*/
						
					}
					else{
						document.getElementById("tppLoginInfo").innerHTML="Fehler";
						/*
						try{
							document.getElementById("divTppKommentarBereich").style.display="none";
						}
						catch(e){}
						*/
						try{
							document.getElementById("divTppEinloggenZumKommentieren").style.display="block";
						}
						catch(e){}
						
					}
					
				}
			}
			catch(e) {alert("Fehler beim Login");}
		}
	}	
	
	function closeTPPLoginWindow(){
		document.getElementById('divTPPLogin').style.display="none";
		hideCurtain();
		}
	function lCTN(){
		loginWindowTPP();	
	}
	
	function tppLogout(){
		httpTPPLogin.open('get', '/ajax/tppLogout.cfm');
		httpTPPLogin.onreadystatechange = tppCheckLogoutAction;
		httpTPPLogin.send(null);	
	}
	function tppCheckLogoutAction(){
		if (httpTPPLogin.readyState == 4){
			try{
				var response= httpTPPLogin.responseText;
				var update = new Array();
				if (response.indexOf('|' != -1)){
					update = response.split('|');
					//alert (update[0]);
					if (update[0] == 1){
						closeTPPLoginWindow();
						communityUserLoggedIn=0;

						/*
						try{
							document.getElementById("newstickerCommentArea").style.display="none";
						}
						catch(e){}
						try{
							document.getElementById("divTppEinloggenZumKommentieren").style.display="block";
						}
						catch(e){}
						
						try{
							document.getElementById("linkKommentierenLogin").style.display="block";
							document.getElementById("linkKommentierenMT").style.display="none";
							
						}
						catch(e){};						
						*/
						location.reload();
						document.getElementById("tppLoginPassword").text="";
						document.getElementById("tppLoginPassword").value="";

						document.getElementById("divLoginContent").style.display="block";
						document.getElementById("divLogoutContent").style.display="none";
					}
				}
			}
			catch(e){alert(e);}
			tppLogoutCross();
		}
	}
	
	function moveToComment(){
	if(communityUserLoggedIn==1){
		try{
			document.getElementById("newstickerCommentArea").style.display="block";	
		}
		catch(e){};
		try{
			document.getElementById("divTppEinloggenZumKommentieren").style.display="none";	
		}
		catch(e){};
	}
		scrollCounter=0;
		scroller();
	}
	
	
	function scrollMe(){
                scrollCounter++;
                if (scrollCounter < 565){
                    window.scrollBy(0,5);
                }
	      else{clearInterval(intervalScroll);}
            }
 
	function scroller(){
	  intervalScroll = setInterval(scrollMe, 1);
	}
	
	function setTPPLoginContent(isCommunityUser){
		if (isCommunityUser){
			document.getElementById("divLoginContent").style.display="none";
			document.getElementById("divLogoutContent").style.display="block";			
		}
		else{
			document.getElementById("divLoginContent").style.display="block";
			document.getElementById("divLogoutContent").style.display="none";			
		}
	}
	
	
	/*iLikeIt*/

	function stripHTML(str){
		// remove all string within tags
		var tmp = str.replace(/(<.*['"])([^'"]*)(['"]>)/g, 
		function(x, p1, p2, p3) { return  p1 + p3;}
		);
		// now remove the tags
		return tmp.replace(/<\/?[^>]+>/gi, '');
	}
	function trim (str) {
	    return str.replace(/[\n\r]/g, '').replace(/ +/g, ' ').replace(/^\s+/g, '').replace(/\s+$/g, '');
	}
	
	function iLikeThis(siteReferer,contentDiv,siteTitle,siteCMD){
		siteTeaser=document.getElementById(contentDiv).innerHTML;
		siteTeaser=stripHTML(siteTeaser);
		siteTeaser=trim(siteTeaser);
		siteTeaser=siteTeaser.substring(0,230);


		httpTPPLogin.open('get', '/ajax/setILikeIt.cfm?siteReferer=' + encodeURIComponent(siteReferer) + '&siteTeaser=' + encodeURIComponent(siteTeaser) + '&siteCMD=' + encodeURIComponent(siteCMD) + '&siteTitle=' + encodeURIComponent(siteTitle));
		httpTPPLogin.onreadystatechange = iLikeThisAction;
		httpTPPLogin.send(null);
	}
	
	
	function iLikeThisAction(){
		if (httpTPPLogin.readyState == 4){
			var response= httpTPPLogin.responseText;
			var update = new Array();
			if (response.indexOf('|' != -1)){
				update = response.split('|');
				if (update[0] == 1){
					/*Aktion OK*/
					location.reload();
				}
				else{
					alert(update[0]);
					/*Fehler*/						
				}
				
			}
		}
	}
	function showLiker(theDiv){
		document.getElementById(theDiv).style.display="block";
		changeTimerState('off');
	}
	function hideLiker(theDiv){
		document.getElementById(theDiv).style.display="none";
		changeTimerState('on');
	}

